0.3.7:上朝改为手动启用,装包不再注册模式
This commit is contained in:
parent
6943989b19
commit
11a3c3e312
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -1,5 +1,15 @@
|
|||
# Changelog
|
||||
|
||||
> 版本号以 `package.json` 为准(当前 0.3.x 线);下面 0.6.x 条目沿用旧编号,保留作历史。
|
||||
|
||||
## 0.3.7 — 上朝改为手动启用
|
||||
|
||||
- 包自带的 `cordis.patch.yml` 改为空层(`[]`):装包不再往模式选择器里注册「上朝」,也不再能成为新会话的默认模式。
|
||||
- 新增 `preset.patch.yml`:想上朝时把它的 `- insert:` 段合并进 profile 的 `cordis.patch.yml`,重启后才会出现该选项。
|
||||
- 新增 `scripts/mode.mjs`(`npm run mode -- on|off|status`):带标记地写入/撤回那段 insert,可逆且幂等,不会替你选中模式。
|
||||
- `scripts/check-install.mjs` 改为校验「装包不等于开模式」:包内 patch 必须不含预设行,`preset.patch.yml` 必须能复现同一 preset id,并报告当前是否已启用。
|
||||
- README 补「启用方式」与 Git 回滚,删除已失效的 backup 目录回滚说明。
|
||||
|
||||
## 0.6.2 — 默认进入丞相
|
||||
|
||||
- 将尚未加入 Agent Team 的新会话主 Agent 直接映射为丞相(Lead)。
|
||||
|
|
|
|||
34
README.md
34
README.md
|
|
@ -2,7 +2,25 @@
|
|||
|
||||
面向 DeepSeek Harness Web GUI 的 Agent Preset,mode id 保持 `sansheng-liubu`。
|
||||
|
||||
新建“上朝”会话时,尚未加入 Agent Team 的默认主 Agent 会自动担任丞相(Lead)。用户进入模式后可直接与丞相对话,无需在 Agent 列表中手动切换;其余部门仍由丞相按流程创建。
|
||||
**本插件默认不开启。** 装上它不会往 DSH 的模式选择器里塞「上朝」,也不会成为新会话的默认模式。只有你按下面步骤显式启用、并在新建会话时主动选中「上朝」,这套流程才开始运行。
|
||||
|
||||
启用之后,尚未加入 Agent Team 的默认主 Agent 会自动担任丞相(Lead),你可以直接与丞相对话,其余部门由丞相按流程创建。
|
||||
|
||||
## 启用方式(选了才生效)
|
||||
|
||||
```powershell
|
||||
node scripts/mode.mjs status # 现在开没开
|
||||
node scripts/mode.mjs on # 让「上朝」出现在模式选择器里
|
||||
node scripts/mode.mjs off # 彻底移除这个选项
|
||||
```
|
||||
|
||||
`on` 只是把 [preset.patch.yml](preset.patch.yml) 里那段 insert 写入 `~/.dsh/profiles/desktop/cordis.patch.yml`(带标记,可原样撤回),**不会**替你选中它。执行后彻底重启 DSH,新建会话时在模式选择器里主动选「上朝」,这套流程才启动;不选就一直是普通模式。
|
||||
|
||||
`off` 把那段 insert 整段删掉,文件回到原样;已存在的会话仍保留它自己的模式记录,不会被切成别的模式。
|
||||
|
||||
包自带的 [cordis.patch.yml](cordis.patch.yml) 是空层(`[]`),这是刻意的——装包本身不产生任何行为。想手工合并也可以,规则同上:顶层保持数组,删掉 `[]` 再接那段 insert。
|
||||
|
||||
若重启后模式选择器里看不到「上朝」,把 `dsh-sansheng-liubu-mode` 也加进 `~/.dsh/profiles/desktop/package.json` 的 `dsh.profile.bundles` 再重启——预设按包名解析那支策略插件,个别部署要求它显式列出。这条不影响「默认关闭」:加进 bundles 只是让插件可加载,策略仍只在会话 preset 为 `sansheng-liubu` 时才生效。
|
||||
|
||||
## 部门职责
|
||||
|
||||
|
|
@ -39,9 +57,19 @@
|
|||
|
||||
```powershell
|
||||
node --check index.js
|
||||
node --test --test-isolation=none test/policy.test.js
|
||||
node --test --test-isolation=none test/policy.test.js panel/test/client.test.js
|
||||
node scripts/check-install.mjs
|
||||
```
|
||||
|
||||
`check-install.mjs` 会确认三件事:包自带 patch 是空层(不注册预设)、`preset.patch.yml` 能复现出同一个 preset id、以及你的 profile 当前到底有没有启用「上朝」(输出里的 `modeEnabled`)。
|
||||
|
||||
## 回滚
|
||||
|
||||
若要恢复上朝内置百炼实现,将 `backup/pre-image-gen-delegation-20261021-1546/` 中的文件复制回插件根对应位置,并重启 DSH。mode id 和 preset id 不变。
|
||||
版本历史统一走 Git,不建备份目录、不留时间戳副本:
|
||||
|
||||
```powershell
|
||||
git log --oneline # 找目标提交
|
||||
git revert <sha> # 或 git reset --hard <sha>
|
||||
```
|
||||
|
||||
回滚后重启 DSH。mode id 与 preset id 不变。
|
||||
|
|
|
|||
|
|
@ -1,14 +1,8 @@
|
|||
# 三省六部模式:作为新的 Agent Preset 出现在 DSH 新会话模式选择器中。
|
||||
- insert:
|
||||
- id: preset-sansheng-liubu
|
||||
name: '@deepseek-ai/dsh-agent-preset'
|
||||
config:
|
||||
id: sansheng-liubu
|
||||
name: 上朝
|
||||
description: 丞相统筹,中书规划、门下审核、尚书调度,工部通过 Image-gen 进行视觉创作、礼部文档、兵部代码与工具武库。
|
||||
order: 30
|
||||
plugins:
|
||||
- id: sansheng-liubu-policy
|
||||
name: dsh-sansheng-liubu-mode
|
||||
config:
|
||||
presetId: sansheng-liubu
|
||||
# 三省六部模式:默认不注册任何东西。
|
||||
#
|
||||
# 装上本包不会往 DSH 的模式选择器里塞「上朝」,也不会成为新会话的默认模式——
|
||||
# 想上朝时,把 preset.patch.yml 里的 insert 合并进
|
||||
# ~/.dsh/profiles/desktop/cordis.patch.yml
|
||||
# 再彻底重启 DSH,新会话才能在模式选择器里看到并选择「上朝」。
|
||||
# 想退出:删掉那段 insert,重启即可;已存在的会话仍保留它自己的模式记录。
|
||||
[]
|
||||
|
|
|
|||
2
index.js
2
index.js
|
|
@ -1,5 +1,5 @@
|
|||
const PRESET_ID = 'sansheng-liubu'
|
||||
export const POLICY_VERSION = '0.3.6'
|
||||
export const POLICY_VERSION = '0.3.7'
|
||||
|
||||
/**
|
||||
* 默认不强制任何 provider/model:宿主未必注册了这些适配器,强行指定会让整轮请求
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dsh-sansheng-liubu-mode",
|
||||
"version": "0.3.6",
|
||||
"version": "0.3.7",
|
||||
"private": true,
|
||||
"description": "上朝:丞相统筹的三省六部多 Agent 模式",
|
||||
"type": "module",
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
"files": [
|
||||
"index.js",
|
||||
"cordis.patch.yml",
|
||||
"preset.patch.yml",
|
||||
"icon.svg",
|
||||
"locale/*.json",
|
||||
"README.md",
|
||||
|
|
@ -31,7 +32,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "node --test --test-isolation=none test/policy.test.js panel/test/client.test.js",
|
||||
"check:install": "node scripts/check-install.mjs"
|
||||
"check:install": "node scripts/check-install.mjs",
|
||||
"mode": "node scripts/mode.mjs"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
# 可选层:只有把下面的条目合并进
|
||||
# ~/.dsh/profiles/desktop/cordis.patch.yml
|
||||
# 并彻底重启 DSH 之后,「上朝」才会出现在模式选择器里。
|
||||
# 不合并 = 永远不开;删掉 = 立即退出。
|
||||
#
|
||||
# 合并方式(PowerShell,在 profile 目录下):
|
||||
# $patch = Get-Content ~/.dsh/profiles/desktop/cordis.patch.yml -Raw
|
||||
# Get-Content ./preset.patch.yml -Raw | Add-Content ~/.dsh/profiles/desktop/cordis.patch.yml
|
||||
# 注意保持 YAML 顶层是「数组」:删掉文件里那行 `[]` 之后再把本文件内容接在末尾。
|
||||
- insert:
|
||||
- id: preset-sansheng-liubu
|
||||
name: '@deepseek-ai/dsh-agent-preset'
|
||||
config:
|
||||
id: sansheng-liubu
|
||||
name: 上朝
|
||||
description: 丞相统筹,中书规划、门下审核、尚书调度,工部通过 Image-gen 进行视觉创作、礼部文档、兵部代码与工具武库。
|
||||
order: 30
|
||||
plugins:
|
||||
- id: sansheng-liubu-policy
|
||||
name: dsh-sansheng-liubu-mode
|
||||
config:
|
||||
presetId: sansheng-liubu
|
||||
|
|
@ -7,19 +7,30 @@ import { pathToFileURL } from 'node:url'
|
|||
const profileDir = resolve(process.env.DSH_PROFILE_DIR ?? join(homedir(), '.dsh', 'profiles', 'desktop'))
|
||||
const profilePath = join(profileDir, 'package.json')
|
||||
const profile = JSON.parse(await readFile(profilePath, 'utf8'))
|
||||
const profilePatchPath = join(profileDir, 'cordis.patch.yml')
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) throw new Error(message)
|
||||
}
|
||||
|
||||
/** 去掉整行注释后剩下的 YAML 主体。 */
|
||||
function withoutComments(source) {
|
||||
return source.replace(/^\s*#.*$/gm, '').trim()
|
||||
}
|
||||
|
||||
for (const name of ['dsh-sansheng-liubu-mode', 'dsh-sansheng-liubu-panel']) {
|
||||
assert(profile.dependencies?.[name]?.startsWith('link:'), `${name} must be a link dependency`)
|
||||
assert(profile.dsh?.profile?.bundles?.includes(name), `${name} must be listed in dsh.profile.bundles`)
|
||||
}
|
||||
// 面板常驻;模式故意不要求在 bundles 里——它必须由用户显式启用。
|
||||
assert(
|
||||
profile.dsh?.profile?.bundles?.includes('dsh-sansheng-liubu-panel'),
|
||||
'panel must be listed in dsh.profile.bundles', // 面板是常驻 UI,不参与 Agent 策略
|
||||
)
|
||||
|
||||
const requireFromProfile = createRequire(join(profileDir, 'package.json'))
|
||||
const modeManifestPath = requireFromProfile.resolve('dsh-sansheng-liubu-mode/package.json')
|
||||
const panelManifestPath = requireFromProfile.resolve('dsh-sansheng-liubu-panel/package.json')
|
||||
const modeDir = dirname(modeManifestPath)
|
||||
const modeManifest = JSON.parse(await readFile(modeManifestPath, 'utf8'))
|
||||
const panelManifest = JSON.parse(await readFile(panelManifestPath, 'utf8'))
|
||||
|
||||
|
|
@ -28,10 +39,34 @@ assert(panelManifest.dsh?.bundle?.patch, 'panel package must declare dsh.bundle.
|
|||
assert(panelManifest.dsh?.client?.platform === 'web', 'panel must declare a web client')
|
||||
assert(panelManifest.dsh?.client?.inject?.length > 0, 'panel must declare client injections')
|
||||
|
||||
const mode = await import(pathToFileURL(join(dirname(modeManifestPath), modeManifest.main)).href)
|
||||
// 装包 ≠ 开模式:包自带的 patch 必须是空层,绝不能注册「上朝」预设。
|
||||
const bundlePatch = await readFile(join(modeDir, modeManifest.dsh.bundle.patch), 'utf8')
|
||||
assert(
|
||||
!/preset-sansheng-liubu/.test(bundlePatch),
|
||||
'bundle patch must not register the 上朝 preset; opting in goes through preset.patch.yml',
|
||||
)
|
||||
assert(
|
||||
['', '[]'].includes(withoutComments(bundlePatch)),
|
||||
'bundle patch must stay an empty layer so installing the mode changes nothing',
|
||||
)
|
||||
|
||||
// 可选层必须存在,并且能复现出同一个 preset id 与策略插件。
|
||||
const presetPatch = await readFile(join(modeDir, 'preset.patch.yml'), 'utf8')
|
||||
assert(/id: preset-sansheng-liubu/.test(presetPatch), 'preset.patch.yml must declare preset-sansheng-liubu')
|
||||
assert(/^\s+id: sansheng-liubu\s*$/m.test(presetPatch), 'preset.patch.yml must declare the sansheng-liubu preset id')
|
||||
assert(/name: dsh-sansheng-liubu-mode/.test(presetPatch), 'preset.patch.yml must load dsh-sansheng-liubu-mode')
|
||||
|
||||
let modeEnabled = false
|
||||
try {
|
||||
modeEnabled = /preset-sansheng-liubu/.test(await readFile(profilePatchPath, 'utf8'))
|
||||
} catch {
|
||||
// 没有 patch 文件 = 从未启用过
|
||||
}
|
||||
|
||||
const mode = await import(pathToFileURL(join(modeDir, modeManifest.main)).href)
|
||||
const panel = await import(pathToFileURL(join(dirname(panelManifestPath), panelManifest.main)).href)
|
||||
assert(typeof mode.apply === 'function', 'mode host entry must export apply')
|
||||
assert(typeof panel.apply === 'function', 'panel host entry must export apply')
|
||||
assert(typeof panel.apply === 'function', 'panel host must export apply')
|
||||
|
||||
const clientSource = await readFile(join(dirname(panelManifestPath), 'lib', 'client.js'), 'utf8')
|
||||
assert(clientSource.includes('id: "dsh-sansheng-liubu-panel"'), 'client bundle id must match the panel package name')
|
||||
|
|
@ -43,4 +78,8 @@ console.log(JSON.stringify({
|
|||
mode: modeManifestPath,
|
||||
panel: panelManifestPath,
|
||||
bundles: profile.dsh.profile.bundles.filter((name) => name.startsWith('dsh-sansheng-')),
|
||||
modeEnabled,
|
||||
hint: modeEnabled
|
||||
? '「上朝」已启用:它只是模式选择器里的一个选项,不会自动成为新会话默认。'
|
||||
: '「上朝」未启用(装包不等于开模式)。要当可选模式用:node scripts/mode.mjs on,再彻底重启 DSH。',
|
||||
}, null, 2))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/env node
|
||||
// 上朝的启用开关:只改 profile 的 cordis.patch.yml,不碰任何别的插件行。
|
||||
//
|
||||
// node scripts/mode.mjs status # 现在开没开
|
||||
// node scripts/mode.mjs on # 让「上朝」出现在模式选择器里(仍需你在新会话中点选)
|
||||
// node scripts/mode.mjs off # 彻底移除这个选项
|
||||
//
|
||||
// 改动是一段带标记的 YAML,重复执行结果一致;不开模式时 profile 里不留任何痕迹。
|
||||
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { homedir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
|
||||
const BEGIN = '# >>> 上朝 preset(scripts/mode.mjs 管理,勿手改)'
|
||||
const END = '# <<< 上朝 preset'
|
||||
const MARK = 'preset-sansheng-liubu'
|
||||
|
||||
const profileDir = resolve(process.env.DSH_PROFILE_DIR ?? join(homedir(), '.dsh', 'profiles', 'desktop'))
|
||||
const patchPath = join(profileDir, 'cordis.patch.yml')
|
||||
const presetTemplatePath = resolve(import.meta.dirname, '..', 'preset.patch.yml')
|
||||
|
||||
async function readOrEmpty(path) {
|
||||
try {
|
||||
return await readFile(path, 'utf8')
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') return ''
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/** preset.patch.yml 里真正要被合并的那几行(去掉说明注释)。 */
|
||||
async function presetBlock() {
|
||||
const template = await readOrEmpty(presetTemplatePath)
|
||||
const lines = template.split(/\r?\n/)
|
||||
const start = lines.findIndex((line) => /^- insert:/.test(line))
|
||||
if (start < 0) throw new Error(`${presetTemplatePath} 里找不到 "- insert:" 起始行`)
|
||||
return lines.slice(start).join('\n').trimEnd()
|
||||
}
|
||||
|
||||
/** 顶层若是空数组占位 `[]`,合并前要先去掉,否则 YAML 不再是单个数组。 */
|
||||
function dropEmptyRoot(text) {
|
||||
const kept = text.split(/\r?\n/).filter((line) => line.trim() !== '[]')
|
||||
return kept.join('\n').trimEnd()
|
||||
}
|
||||
|
||||
function isEnabled(text) {
|
||||
return text.includes(MARK)
|
||||
}
|
||||
|
||||
function isManaged(text) {
|
||||
return text.includes(BEGIN)
|
||||
}
|
||||
|
||||
function stripBlock(text) {
|
||||
const lines = text.split(/\r?\n/)
|
||||
const begin = lines.findIndex((line) => line.trim() === BEGIN)
|
||||
const end = lines.findIndex((line) => line.trim() === END)
|
||||
if (begin < 0 || end < begin) return null
|
||||
return [...lines.slice(0, begin), ...lines.slice(end + 1)].join('\n')
|
||||
}
|
||||
|
||||
async function status() {
|
||||
const text = await readOrEmpty(patchPath)
|
||||
return {
|
||||
profilePatch: patchPath,
|
||||
enabled: isEnabled(text),
|
||||
managed: isManaged(text),
|
||||
}
|
||||
}
|
||||
|
||||
async function enable() {
|
||||
const text = await readOrEmpty(patchPath)
|
||||
if (isEnabled(text)) return { ...(await status()), changed: false, note: '已经启用,未改动' }
|
||||
const body = dropEmptyRoot(text)
|
||||
const parts = [body, BEGIN, await presetBlock(), END].filter((part) => part !== '')
|
||||
await writeFile(patchPath, `${parts.join('\n')}\n`, 'utf8')
|
||||
return { ...(await status()), changed: true, note: '已启用;彻底重启 DSH 后,新会话可选「上朝」' }
|
||||
}
|
||||
|
||||
async function disable() {
|
||||
const text = await readOrEmpty(patchPath)
|
||||
if (!isEnabled(text)) return { ...(await status()), changed: false, note: '本来就没启用,未改动' }
|
||||
const stripped = stripBlock(text)
|
||||
if (stripped === null) {
|
||||
throw new Error(`${patchPath} 里的预设行不是本脚本写入的(缺少标记行),请手动删除后重试`)
|
||||
}
|
||||
const body = stripped.trimEnd()
|
||||
const next = body === '' ? '[]\n' : `${body}\n`
|
||||
await writeFile(patchPath, next, 'utf8')
|
||||
return { ...(await status()), changed: true, note: '已关闭;彻底重启 DSH 后生效' }
|
||||
}
|
||||
|
||||
const action = (process.argv[2] ?? 'status').toLowerCase()
|
||||
const handlers = { status, on: enable, off: disable }
|
||||
const handler = handlers[action]
|
||||
if (!handler) {
|
||||
console.error(`未知动作:${action}(可用:status / on / off)`)
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(JSON.stringify(await handler(), null, 2))
|
||||
} catch (error) {
|
||||
console.error(String(error?.message ?? error))
|
||||
process.exit(1)
|
||||
}
|
||||
Loading…
Reference in New Issue