From e5769aac798db22ef49a1d766d1d4f1cb52cb483 Mon Sep 17 00:00:00 2001 From: zzxsmile <523954578@qq.com> Date: Wed, 11 Nov 2026 22:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=98=E5=B7=A5=E5=85=8D=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E8=A3=85=E6=9C=BA=EF=BC=9Abootstrap.sh(Gitea=E7=9B=B4=E8=A3=85?= =?UTF-8?q?+=E5=8F=96=E7=A0=81=E6=8D=A2key=E4=B8=80=E6=9D=A1=E9=BE=99)+set?= =?UTF-8?q?up-key.mjs(=E9=9B=B6=E4=BB=93=E5=BA=93=E4=BE=9D=E8=B5=96)+READM?= =?UTF-8?q?E=E6=8D=A2=E4=B8=A4=E8=A1=8C=E8=A3=85=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 ++++++- package.json | 1 + scripts/bootstrap.sh | 29 ++++++++++++++ scripts/setup-key.mjs | 93 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 scripts/bootstrap.sh create mode 100644 scripts/setup-key.mjs diff --git a/README.md b/README.md index dd56fa6..36b9610 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,25 @@ DeepSeek Harness 插件 · 四道菜团队中台。 ## 装(新同事) +一条命令(2026-11-11 起插件从 Gitea 直装,无需本地仓库): + ```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。 +> 维护者本机(有本地仓库 + 老桌面 profile)仍可用全量版: +> `node ~/Documents/Essay_AI/Essay_system/dsh-markmag/scripts/setup-account.mjs` + ## 更新(已装过) ```bash diff --git a/package.json b/package.json index fadaab3..1abd52d 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "files": [ "src", "dist", + "scripts", "cordis.patch.yml", "README.md", "LICENSE", diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100644 index 0000000..78e8c36 --- /dev/null +++ b/scripts/bootstrap.sh @@ -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" diff --git a/scripts/setup-key.mjs b/scripts/setup-key.mjs new file mode 100644 index 0000000..89a0f48 --- /dev/null +++ b/scripts/setup-key.mjs @@ -0,0 +1,93 @@ +#!/usr/bin/env node +/** + * 员工接 key(免仓库版,2026-11-11):打开弹匣取码页 → 粘 8 位码 → key 写进 DSH 凭据。 + * + * 前提:DSH 插件已装(bootstrap.sh 第一步 / dsh plugin add )。 + * 本文件零仓库依赖——装在包里随插件分发,也可被 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:模型通道 + 弹匣工具面 + 团队记忆都会就位。')