员工免仓库装机:bootstrap.sh(Gitea直装+取码换key一条龙)+setup-key.mjs(零仓库依赖)+README换两行装法

This commit is contained in:
zzxsmile committed 2026-11-11 22:19:17 +08:00
1 parent c685d7b104
commit e5769aac79
4 files changed
+136 -2

No files matched your search

+13 -2
View File
@@ -14,14 +14,25 @@ DeepSeek Harness 插件 · 四道菜团队中台。
## 装(新同事) ## 装(新同事)
一条命令(2026-11-11 起插件从 Gitea 直装,无需本地仓库):
```bash ```bash
node ~/Documents/Essay_AI/Essay_system/dsh-markmag/scripts/setup-account.mjs bash <(curl -fsSL https://brain.sidaocai.cn/git/sidaocai/dsh-markmag/raw/branch/main/scripts/bootstrap.sh)
``` ```
一条命令做完:装插件 → 部署弹匣端 → 打开浏览器取一次性码 → 换回你自己的 key。 它做两件事:从 Gitea 装插件(profile 默认 desktop)→ 打开浏览器取一次性码,你粘回来,key 自动写进 DSH 凭据。
只装插件不换 key(key 已有):
```bash
dsh plugin --profile desktop add https://brain.sidaocai.cn/git/sidaocai/dsh-markmag.git
```
然后重启 DSH。 然后重启 DSH。
> 维护者本机(有本地仓库 + 老桌面 profile)仍可用全量版:
> `node ~/Documents/Essay_AI/Essay_system/dsh-markmag/scripts/setup-account.mjs`
## 更新(已装过) ## 更新(已装过)
```bash ```bash
+1
View File
@@ -44,6 +44,7 @@
"files": [ "files": [
"src", "src",
"dist", "dist",
"scripts",
"cordis.patch.yml", "cordis.patch.yml",
"README.md", "README.md",
"LICENSE", "LICENSE",
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# 员工一键接入(2026-11-11):装插件(Gitea)+ 取码换 key。
#
# 跑法(员工唯一要记的一条;bash <(...) 保住终端输入,取码时还要粘码):
# bash <(curl -fsSL https://brain.sidaocai.cn/git/sidaocai/dsh-markmag/raw/branch/main/scripts/bootstrap.sh)
#
# 可选环境变量:DSH_CLI(CLI 路径)、PROFILE(默认 desktop)、DSH_REPO(自建源)
set -euo pipefail
DSH_CLI="${DSH_CLI:-/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh}"
PROFILE="${1:-${PROFILE:-desktop}}"
DSH_REPO="${DSH_REPO:-https://brain.sidaocai.cn/git/sidaocai/dsh-markmag.git}"
if [ ! -x "$DSH_CLI" ]; then
echo "✗ 没找到 DSH 命令行($DSH_CLI)。先装 DeepSeek Harness 桌面端,或用 DSH_CLI= 指路径。"
exit 1
fi
echo "[1/2] 安装弹匣插件 → profile: $PROFILE"
"$DSH_CLI" plugin --profile "$PROFILE" add "$DSH_REPO"
echo "[2/2] 取码换 key(浏览器会自动打开)"
PKG="$HOME/.dsh/profiles/$PROFILE/node_modules/@sidaocai/dsh-markmag/scripts/setup-key.mjs"
if [ ! -f "$PKG" ]; then
# 包内没带脚本(旧版本插件)时,直接从 Gitea raw 拉最新
curl -fsSL "$DSH_REPO/raw/branch/main/scripts/setup-key.mjs" -o /tmp/dsh-setup-key.mjs
PKG=/tmp/dsh-setup-key.mjs
fi
exec node "$PKG"
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env node
/**
* 员工接 key(免仓库版,2026-11-11):打开弹匣取码页 → 粘 8 位码 → key 写进 DSH 凭据。
*
* 前提:DSH 插件已装(bootstrap.sh 第一步 / dsh plugin add <Gitea 地址>)。
* 本文件零仓库依赖——装在包里随插件分发,也可被 bootstrap.sh 从 Gitea raw 直接拉起。
* 中间只需要做一件事:把浏览器页面上的 8 位码粘进来。
*/
import fs from 'node:fs'
import { homedir } from 'node:os'
import { join } from 'node:path'
import { execSync } from 'node:child_process'
import { createInterface } from 'node:readline/promises'
const CRED = join(homedir(), '.dsh/.credentials.yaml')
const MARKMAG = 'https://brain.sidaocai.cn/markmag'
const LINK_PAGE = MARKMAG + '/api/dsh/link'
const REF = 'MARKMAG_TEAM_KEY'
const rl = createInterface({ input: process.stdin, output: process.stdout })
console.log('接通你的团队 AI key:')
console.log(' 1. 打开弹匣取码页(没登录会先跳钉钉扫码,登完再开一次)')
console.log(' 2. 把页面上的 8 位码粘到这里')
console.log(' 3. key 自动写进 DSH 凭据,完成')
try {
execSync('open "' + LINK_PAGE + '"')
console.log('\n浏览器已打开:' + LINK_PAGE)
} catch {
console.log('\n请手动打开:' + LINK_PAGE)
}
const code = (await rl.question('\n把页面上的 8 位码粘进来:')).trim().toUpperCase()
rl.close()
if (!/^[A-Z0-9]{8}$/.test(code)) {
console.error('✗ 码格式不对(应该 8 位字母数字)')
process.exit(1)
}
let data
try {
const res = await fetch(MARKMAG + '/api/dsh/link-exchange', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ code }),
signal: AbortSignal.timeout(20000),
})
data = await res.json()
} catch (e) {
console.error('✗ 连不上弹匣:' + (e.name === 'TimeoutError' ? '超时' : e.message))
process.exit(1)
}
if (!data.ok) {
console.error('✗ ' + (data.err || '换 key 失败') + '(码 5 分钟过期,重新打开页面取一个)')
process.exit(1)
}
const key = data.user_key || ''
if (!key.startsWith('sk-mem-')) {
console.error('✗ 返回的 key 形状不对,拒绝写入')
process.exit(1)
}
if (!fs.existsSync(CRED)) {
console.error('✗ 没找到 ' + CRED + '(DSH 至少启动过一次才会生成)')
process.exit(1)
}
fs.copyFileSync(CRED, CRED + '.bak-' + Date.now())
function setCred(text, name, value) {
const re = new RegExp('^(\\s+)' + name + ':\\s*.*$', 'm')
if (re.test(text)) return text.replace(re, '$1' + name + ': ' + value)
if (/^refs:\s*$/m.test(text)) return text.replace(/^refs:\s*$/m, 'refs:\n ' + name + ': ' + value)
return text.trimEnd() + '\nrefs:\n ' + name + ': ' + value + '\n'
}
let cred = fs.readFileSync(CRED, 'utf8')
cred = setCred(cred, REF, key)
const toolToken = data.tool_token || ''
if (toolToken) cred = setCred(cred, 'MARKMAG_TOOL_TOKEN', toolToken)
fs.writeFileSync(CRED, cred, { mode: 0o600 })
const after = fs.readFileSync(CRED, 'utf8')
const ok =
new RegExp('^\\s+' + REF + ':\\s*sk-mem-', 'm').test(after) &&
(!toolToken || /^\s+MARKMAG_TOOL_TOKEN:\s*\S+/m.test(after))
console.log('\n' + (ok ? '✓ 完成' : '✗ 写入后自检失败') + ' ' + JSON.stringify({
member: data.name || '?',
model: data.model || '?',
modelKey: true,
toolToken: toolToken ? true : '未返回',
}))
console.log('\n以后不用再做这一步了。重启 DSH:模型通道 + 弹匣工具面 + 团队记忆都会就位。')