员工免仓库装机:bootstrap.sh(Gitea直装+取码换key一条龙)+setup-key.mjs(零仓库依赖)+README换两行装法
This commit is contained in:
1 parent
c685d7b104
commit
e5769aac79
4 files changed
+136
-2
No files matched your search
@@ -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"
|
||||
@@ -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:模型通道 + 弹匣工具面 + 团队记忆都会就位。')
|
||||
Reference in new issue
Block a user