Files
STM32F4-Base/.dsh/plugins/dsh-plugin-subagent-roles/lib/settings.js
T
wandering1 9e538d2809
CI / 静态门禁 (pre-commit) (push) Failing after 43s
CI / 主机侧单测 (MSVC) (push) Failing after 24s
feat(dsh): 门禁账本插件接入 + 角色绑定跨重启还原
二、门禁与唤醒(新插件 dsh-plugin-team-ledger 0.2.0)
宿主 Agent Teams 缺两块能力,补在独立仓
D:/Code/AI/dsh-plugin-team-ledger:

- 状态存放:<工作区>/.dsh/team/gate.jsonl 追加账本,记验收
  清单、实测证据、认领历史,跨重启存活;canonical JSON +
  fsync,坏尾行截断恢复。
- 唤醒模型:门禁推进后按事件计划唤醒下一责任人,借活体
  Lead 作 caller 走宿主 sendMessage;无定时器;30 分钟滑动
  窗口限 4 次防复活风暴。
- 验收独立性由机器强制:执行人/历史认领者不能 accept,
  checklist 逐项 passed=true 缺一不可。
- team_member_revive(Lead 专用):成员模型路由死亡后的
  复活通道——可换 provider/model,再经 subagents.sendMessage
  冷恢复唤醒,绕过宿主 roster 的 phase=active 门禁。

二、角色绑定跨重启还原(roles fork 0.5.2)
persona 与工具白名单只有运行中 agent 的内存态,宿主重启后
冷恢复的成员既无 persona 也无白名单——实测出现 doc-writer
成员带全量工具面(qq_*/ImageGen),属静默权限放大。改为
注入成功时持久化 childId -> {roleId, cwd} 到
~/.dsh/role-inject-bindings.json,并在 agent/created 时重放。
追加 team_member_rebind 补绑定,覆盖 0.5.2 之前已存在的成员。

三、配套
- .dsh/roles 八个角色白名单加入门禁工具;AGENTS.md 委派策略
  补门禁/复活/重绑三套操作口径。
- docs/环境与部署/子Agent角色自动注入实现说明.md 新增
  §5.1,记录绑定机制、存量成员缺口与「成员自省不可全信」的
  台架教训。
2026-11-16 00:42:51 +08:00

110 lines
4.9 KiB
JavaScript

/**
* Retunable row policy: trim rules and the tool-call budget.
*
* DSH 0.2.1 removed plugin-registered settings namespaces (`settings.register`),
* so there is no user layer to watch: the ROW CONFIG is the whole policy and the
* plugin-manager config page edits exactly that row. The readers below keep the
* same shape the rest of the plugin already consumes, which is why the switch is
* a deletion rather than a rewrite.
*
* `SettingsSchema` survives as the single declaration of the retunable subset:
* the row Config is the storage, and tests pin the config page's field list
* against this schema so a knob cannot silently fall out of the GUI.
*/
import z from '@deepseek-ai/schemastery'
import { TOOL_CALL_BUDGET_MODES } from './roles.js'
import { LOG_PREFIX } from './tool.js'
import { DEFAULT_CHILD_NAMES } from './trim.js'
/** The three trim postures, shared by the row config and the settings schema. */
export const TRIM_MODES = Object.freeze(['off', 'tools', 'full'])
/** Settings schema for one row (mirrors the retunable subset of the row config). */
export const SettingsSchema = z.object({
childPromptTrim: z.union([...TRIM_MODES]).default('full'),
childPromptTrimNames: z.array(z.string()).default([...DEFAULT_CHILD_NAMES]),
defaultMaxToolCalls: z.natural().default(0),
maxToolCallsHardCap: z.natural().default(0),
onToolCallBudget: z.union([...TOOL_CALL_BUDGET_MODES]).default('wrap-up'),
graceToolCalls: z.natural().default(1),
})
/**
* The settings namespace (and Settings card key) for one row.
*
* Namespaces are lowercase-hyphenated, so a renamed tool — the way a profile
* mounts a second row — is slugged rather than used verbatim. The default row
* keeps the stable `subagent-roles` name the browser half binds to.
* @param toolName - the configured delegation tool name.
* @returns the namespace for this row.
*/
export function settingsNamespaceFor(toolName) {
const name = toolName ?? 'subagent_role'
if (name === 'subagent_role') return 'subagent-roles'
const slug = String(name).toLowerCase().replaceAll(/[^a-z0-9]+/g, '-').replaceAll(/^-+|-+$/g, '')
return slug.length === 0 ? 'subagent-roles' : `subagent-roles-${slug}`
}
/** Normalize one resolved settings/config section into a trim policy. */
export function trimPolicyFrom(values) {
const mode = TRIM_MODES.includes(values?.childPromptTrim) ? values.childPromptTrim : 'full'
const names = Array.isArray(values?.childPromptTrimNames)
? values.childPromptTrimNames.filter((name) => typeof name === 'string')
: [...DEFAULT_CHILD_NAMES]
return { mode, dropNames: new Set(names) }
}
/**
* Normalize one resolved settings/config section into the budget defaults a role
* file may omit.
*
* The output uses the DELEGATION-facing names (`maxToolCalls`), while the input
* uses the config/schema names (`defaultMaxToolCalls`): the settings key is the
* row's default, and calling it `maxToolCalls` next to a role file's own
* `maxToolCalls` would be ambiguous about which one wins.
* @param values - the resolved settings section (or the row config as `base`).
* @returns the normalized defaults.
*/
export function budgetDefaultsFrom(values) {
const count = (value, fallback) => (Number.isSafeInteger(value) && value >= 0 ? value : fallback)
return {
maxToolCalls: count(values?.defaultMaxToolCalls, 0),
maxToolCallsHardCap: count(values?.maxToolCallsHardCap, 0),
onToolCallBudget: TOOL_CALL_BUDGET_MODES.includes(values?.onToolCallBudget) ? values.onToolCallBudget : 'wrap-up',
graceToolCalls: count(values?.graceToolCalls, 1),
}
}
/**
* Build the policy source a row reads.
*
* In 0.2.1 the row config is the only storage: the plugin manager edits the
* config schema, and a change restarts the row, so there is no watch to keep.
* The returned shape is unchanged for the rest of the plugin.
* @param options - the plugin `ctx` and the row `config`.
* @returns `read()` for the trim policy, `readBudgetDefaults()` for the budget,
* and a no-op disposer kept for the caller's effect.
*/
export function createTrimPolicySource(options) {
const { ctx, config } = options
const base = {
childPromptTrim: config.childPromptTrim ?? 'full',
childPromptTrimNames: [...(config.childPromptTrimNames ?? DEFAULT_CHILD_NAMES)],
defaultMaxToolCalls: config.defaultMaxToolCalls ?? 0,
maxToolCallsHardCap: config.maxToolCallsHardCap ?? 0,
onToolCallBudget: config.onToolCallBudget ?? 'wrap-up',
graceToolCalls: config.graceToolCalls ?? 1,
}
const current = { trim: trimPolicyFrom(base), budget: budgetDefaultsFrom(base) }
ctx.logger?.info?.(`[${LOG_PREFIX}] trim and tool-call budget follow the plugin row config; edit them from the Plugins page`)
return {
/** The trim policy to apply to the next assembly. */
read: () => current.trim,
/** The budget defaults to apply to the next delegation. */
readBudgetDefaults: () => current.budget,
/** Nothing to detach: the row config owns the values. */
dispose: () => {},
}
}