9e538d2809
二、门禁与唤醒(新插件 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,记录绑定机制、存量成员缺口与「成员自省不可全信」的
台架教训。
56 lines
2.7 KiB
JavaScript
56 lines
2.7 KiB
JavaScript
/**
|
|
* The role catalog line — the ONLY role text that ever reaches a delegating
|
|
* agent's context. Role personas stay on disk until a delegation needs them.
|
|
*
|
|
* Kept deliberately small: one framing line naming the delegation tool, plus
|
|
* one `- id (displayName): description` line per role with the description
|
|
* capped. Every extra line here is re-sent on every request of every agent that
|
|
* sees the catalog, so the catalog spends its budget on routing information
|
|
* only.
|
|
*/
|
|
|
|
/** Default per-role description cap inside the catalog line. */
|
|
const DEFAULT_DESCRIPTION_MAX_LENGTH = 160
|
|
|
|
/**
|
|
* Collapse whitespace and truncate one description for a catalog line.
|
|
* @param value - the raw description.
|
|
* @param maxLength - the cap in characters.
|
|
* @returns the normalized, capped text.
|
|
*/
|
|
export function catalogDescription(value, maxLength = DEFAULT_DESCRIPTION_MAX_LENGTH) {
|
|
const normalized = String(value ?? '').replaceAll(/\s+/g, ' ').trim()
|
|
if (normalized.length <= maxLength) return normalized
|
|
return `${normalized.slice(0, Math.max(0, maxLength - 3))}...`
|
|
}
|
|
|
|
/**
|
|
* Render the role catalog section text.
|
|
* @param roles - the merged role records.
|
|
* @param options - `toolName` (the configured delegation tool name) and
|
|
* `descriptionMaxLength`.
|
|
* @returns the section text, or '' when there are no roles (the section is
|
|
* then dropped by the prompt registry and costs nothing).
|
|
*/
|
|
export function renderRoleCatalog(roles, options = {}) {
|
|
const list = Array.isArray(roles) ? roles : []
|
|
if (list.length === 0) return ''
|
|
const descriptionMaxLength = options.descriptionMaxLength ?? DEFAULT_DESCRIPTION_MAX_LENGTH
|
|
// The framing line must name the CONFIGURED tool: a renamed tool would
|
|
// otherwise send the model after a name that does not exist. The global role
|
|
// directory is described generically because `dshHome` is configurable.
|
|
const toolName = options.toolName ?? 'subagent_role'
|
|
const lines = [
|
|
`Roles come from role files: \`.dsh/roles\` in this project, plus a global \`roles/\` directory. Delegate with \`${toolName}\`, not the generic \`subagent\`: only it applies the role persona and tool policy.`,
|
|
]
|
|
for (const role of list) {
|
|
const named = role.displayName !== undefined && role.displayName !== role.id
|
|
// Collapse whitespace: a display name with a newline would break the
|
|
// one-line-per-role invariant of the catalog.
|
|
const label = named ? ` (${String(role.displayName).replaceAll(/\s+/g, ' ').trim()})` : ''
|
|
const extra = role.whenToUse !== undefined ? ` ${catalogDescription(role.whenToUse, descriptionMaxLength)}` : ''
|
|
lines.push(`- \`${role.id}\`${label}: ${catalogDescription(role.description, descriptionMaxLength)}${extra}`)
|
|
}
|
|
return lines.join('\n')
|
|
}
|