@morning-start/dsh-code-toolkit 0.27.4 → 0.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.md +111 -11
  3. package/agents/audit/AGENT.md +137 -0
  4. package/agents/audit/examples/fake-capability.md +54 -0
  5. package/agents/audit/examples/wired-clean.md +66 -0
  6. package/agents/audit/references/audit-passes.md +118 -0
  7. package/agents/audit/references/capability-states.md +96 -0
  8. package/agents/audit/references/evidence.md +86 -0
  9. package/agents/audit/references/finding-the-chain.md +80 -0
  10. package/agents/audit/references/output.md +66 -0
  11. package/agents/caption/AGENT.md +112 -135
  12. package/agents/caption/examples/loop.md +12 -0
  13. package/agents/caption/references/evidence.md +46 -0
  14. package/agents/caption/references/flows.md +6 -2
  15. package/agents/caption/references/loop.md +57 -1
  16. package/agents/design/AGENT.md +158 -0
  17. package/agents/design/examples/one-page.md +55 -0
  18. package/agents/design/examples/overkill.md +56 -0
  19. package/agents/design/references/base-maps.md +110 -0
  20. package/agents/design/references/deliverables.md +71 -0
  21. package/agents/design/references/model-and-ports.md +73 -0
  22. package/agents/design/references/plan-and-batches.md +92 -0
  23. package/agents/design/references/scenario-cards.md +133 -0
  24. package/agents/design/references/self-check.md +73 -0
  25. package/agents/pua/AGENT.md +3 -0
  26. package/agents/review/AGENT.md +52 -52
  27. package/agents/scrub/AGENT.md +64 -67
  28. package/agents/simplify/AGENT.md +70 -101
  29. package/index.js +145 -11
  30. package/locale/en.json +2 -2
  31. package/locale/zh.json +2 -2
  32. package/package.json +5 -2
  33. package/src/caption.js +149 -0
  34. package/src/command.js +20 -6
  35. package/src/design.js +70 -0
  36. package/src/i18n.js +98 -24
  37. package/src/report.js +112 -3
package/src/i18n.js CHANGED
@@ -21,28 +21,48 @@ const LANGUAGE_NAMES = {
21
21
 
22
22
  const MESSAGES = {
23
23
  zh: {
24
- 'cmd.simplify': '简化代码:功能逐位不变,默认直接改整个项目',
25
- 'cmd.review': '审查代码改动:默认出报告并修复发现的问题,加 report 只出报告',
26
- 'cmd.scrub': '清理隐私信息:密钥、密码、账号、本机路径,默认直接改',
27
- 'cmd.caption': '把难任务装进 caption 循环:一步一验,过程落成台账',
28
- 'hint.caption': '留空即继续当前任务;或写下任务与验收判据',
24
+ 'cmd.simplify': '简化代码,功能不变',
25
+ 'cmd.review': '审查改动并修复问题',
26
+ 'cmd.scrub': '清理密钥与隐私信息',
27
+ 'cmd.caption': '按计划清单跑到完成,过程落台账',
28
+ 'hint.caption': '留空继续当前任务;list 列台账,resume <名字> 接续',
29
29
  'caption.installed': '已装入 caption 循环:台账写到 {dir},每一步都要有命令和它的结果。',
30
30
  'caption.reinstalled': 'caption 循环已在本次会话里,只补了任务:台账 {dir},继续按循环走。',
31
+ 'caption.steps': ' 步',
32
+ 'caption.planProgress': '计划 {done}/{total}',
33
+ 'caption.planBlocked': ' · {count} 项受阻',
34
+ 'caption.closed': ' · 已收口',
35
+ 'caption.listHead': '台账目录:{dir}',
36
+ 'caption.listHint': '用 /code-caption resume <序号|名字> 继续一份。',
37
+ 'caption.listEmpty': '台账目录 {dir} 还是空的:第一次运行会创建。',
38
+ 'caption.noLedgers': '还没有任何台账:先跑一次 /code-caption <任务>。',
39
+ 'caption.unknownLedger': '没有找到台账「{name}」,现有:',
40
+ 'caption.ambiguousLedger': '「{name}」匹配到多份台账,请用序号或完整名字:',
41
+ 'caption.resumed': '已接续台账:{path}。先读头部和最后两条,再走下一步。',
42
+ 'cmd.audit': '审计能力是否真的通(只读)',
43
+ 'hint.audit': '留空即整个项目;加 sub 用隔离子 agent(推荐)',
44
+ 'mode.audit': '只出五态表与证据,不改任何文件;没有走通真实入口的能力标「未确认」,不要标「通」。',
45
+ 'audit.delivery': '你的最终回复会原样作为审计结果发回:一条能力一行,写清状态、证据(文件:行)和链路断在哪一步,以及哪些没有验到。',
46
+ 'cmd.design': '把需求拆成场景与批次方案',
47
+ 'hint.design': '留空按半天设计;quick 一页,full 完整方案',
48
+ 'design.installed': '已装入场景驱动设计协议:设计文档写到 {dir}。方案出完等你批,不会自己动手。',
49
+ 'design.reinstalled': '设计协议已在本次会话里:设计文档 {dir},继续按协议推进。',
50
+ 'error.designDirectory': 'designDirectory 不能为空。',
31
51
  'error.noSteer': '当前宿主不支持向会话注入输入(agent.steer 不可用)。',
32
52
  'error.noFollowup': '当前宿主不支持向会话投递任务(agent.followup 不可用)。',
33
53
  'cmd.queued': '已交给当前会话,范围:{scope};完成后结果会作为一条消息发回。',
34
54
  'cmd.queuedSub': '已交给独立子 agent,范围:{scope};完成后结果会作为一条消息发回。',
35
55
  'cmd.queuedPlan': '已请它先出方案,范围:{scope},不改任何文件;方案回来后你确认,再执行。',
36
56
  'cmd.queuedPlanSub': '已请独立子 agent 先出方案,范围:{scope},不改任何文件;方案回来后你确认,再执行。',
37
- 'cmd.pua': '给当前会话装上 PUA 协议:失败就换方法、拿证据、别敷衍',
38
- 'hint.pua': '留空用默认风味;或 list / alibaba / huawei / musk 等',
57
+ 'cmd.pua': '装上「不许敷衍」的协议',
58
+ 'hint.pua': '留空用默认风味;list 查看全部',
39
59
  'pua.installed': '已装上 PUA 协议({flavor}):同类尝试失败两次就换方法,说完成必须给出命令和输出。',
40
60
  'pua.list': '可用风味:',
41
- 'cmd.status': '查看代码工具箱任务状态或最近结果',
42
- 'cmd.cancel': '取消当前代码工具箱任务',
43
- 'hint.scope': '留空即整个项目(当前分支);或 --files a.js,b.js / --branch main(对比哪个分支,默认基线)/ --commit <sha> / 自定义说明;加 sub 用子 agent,加 report 只出报告',
44
- 'hint.scrub': '留空即整个项目;或 --files a.js,.env / 自定义说明;加 sub 用子 agent,加 report 只出报告',
45
- 'hint.review': '留空即审未提交的改动(都提交了就审分支相对基线);或 --files / --branch <对比分支> / --commit <sha>;默认出报告并修复,加 report 只出报告,加 sub 用子 agent',
61
+ 'cmd.status': '查看任务状态或最近结果',
62
+ 'cmd.cancel': '取消正在跑的任务',
63
+ 'hint.scope': '留空即整个项目;--files a.js,b.js;sub 隔离,report 只出计划',
64
+ 'hint.scrub': '留空即整个项目;--files <路径>;sub 隔离,report 只出报告',
65
+ 'hint.review': '留空审未提交改动;--files/--branch/--commit;sub 隔离,report 只出报告',
46
66
  'error.noCwd': '当前会话没有工作目录。',
47
67
  'error.noIdentity': '当前会话没有可用的会话标识,无法记录任务状态或做单飞保护。',
48
68
  'error.noProvider': '当前宿主缺少独立上下文的原生 spawn provider,无法运行独立 agent。',
@@ -65,10 +85,27 @@ const MESSAGES = {
65
85
  'status.last': '最近一次:',
66
86
  'status.interrupted': '上次任务有启动记录但没有完成报告,可以重新运行。',
67
87
  'status.submitted': '已提交到当前会话,结果在会话里:',
88
+ 'status.installed': '已装入 {command} 协议,没有后台任务在跑。',
89
+ 'status.ledgers': '台账 {count} 份,最近一份:',
90
+ 'status.noLedgers': '台账:还没有。',
68
91
  'cancel.none': '没有正在运行的代码工具箱任务。',
69
92
  'cancel.done': '已请求取消。',
70
93
  'report.verdict': '结论:',
71
94
  'report.noFindings': '没有发现需要处理的问题。',
95
+ 'report.capabilities': '能力五态',
96
+ 'report.capability': '能力',
97
+ 'report.state': '状态',
98
+ 'report.evidence': '证据',
99
+ 'report.walk': '路径:',
100
+ 'report.expected': '期望:',
101
+ 'report.actual': '实际:',
102
+ 'report.impact': '影响:',
103
+ 'report.batch': '建议批次:',
104
+ 'state.wired': '通',
105
+ 'state.half': '半',
106
+ 'state.fake': '假',
107
+ 'state.broken': '断',
108
+ 'state.missing': '无',
72
109
  'report.limitation': '未覆盖:',
73
110
  'report.fixed': '已修复',
74
111
  'report.verifiedBy': '验证:',
@@ -76,28 +113,48 @@ const MESSAGES = {
76
113
  'mode.apply': 'apply(已改文件)',
77
114
  },
78
115
  en: {
79
- 'cmd.simplify': 'Simplify code without changing behavior; writes the whole project by default',
80
- 'cmd.review': 'Review a change and fix what it finds; add report for the report only',
81
- 'cmd.scrub': 'Find and redact secrets, credentials, and personal data; writes by default',
82
- 'cmd.caption': 'Run a hard task through the caption loop: one step, one proof, a ledger',
83
- 'hint.caption': 'Leave empty to continue the current task; or state the task and its acceptance criteria',
116
+ 'cmd.simplify': 'Simplify code without changing behavior',
117
+ 'cmd.review': 'Review a change and fix what it finds',
118
+ 'cmd.scrub': 'Remove secrets and personal data',
119
+ 'cmd.caption': 'Work a plan to completion, with a ledger',
120
+ 'hint.caption': 'Empty continues the current task; list shows ledgers, resume <name> continues one',
84
121
  'caption.installed': 'Caption loop installed: keep the ledger in {dir}, with a command and its result for every step.',
85
122
  'caption.reinstalled': 'The caption loop is already installed in this session; only the task was added. Ledger: {dir}.',
123
+ 'caption.steps': ' steps',
124
+ 'caption.planProgress': 'plan {done}/{total}',
125
+ 'caption.planBlocked': ' · {count} blocked',
126
+ 'caption.closed': ' · closed',
127
+ 'caption.listHead': 'Ledger directory: {dir}',
128
+ 'caption.listHint': 'Continue one with /code-caption resume <number|name>.',
129
+ 'caption.listEmpty': 'The ledger directory {dir} is empty; the first run creates one.',
130
+ 'caption.noLedgers': 'No ledgers yet — run /code-caption <task> first.',
131
+ 'caption.unknownLedger': 'No ledger named "{name}". Existing:',
132
+ 'caption.ambiguousLedger': '"{name}" matches several ledgers; use the number or the full name:',
133
+ 'caption.resumed': 'Continuing the ledger at {path}. Read its head and the last two entries first, then take the next step.',
134
+ 'cmd.audit': 'Audit whether a capability is really wired (read-only)',
135
+ 'hint.audit': 'Empty = whole project; add sub to run in an isolated agent (recommended)',
136
+ 'mode.audit': 'Report the five-state table and its evidence only. Change no files, and mark a capability you did not reach through its real entry point as unverified — never wired.',
137
+ 'audit.delivery': 'Your final reply is delivered as the audit result: one capability per row, with its state, its evidence (file:line), which link of the chain is missing, and what you could not verify.',
138
+ 'cmd.design': 'Turn a need into scenarios and a batched plan',
139
+ 'hint.design': 'Empty = half-day design; quick = one page, full = the whole plan',
140
+ 'design.installed': 'Scenario-driven design protocol installed: write the design documents under {dir}. It stops when the plan is ready and waits for approval — it never starts building by itself.',
141
+ 'design.reinstalled': 'The design protocol is already installed in this session; the documents go under {dir}. Continue under it.',
142
+ 'error.designDirectory': 'designDirectory cannot be empty.',
86
143
  'error.noSteer': 'This host cannot inject input into the session (agent.steer is unavailable).',
87
144
  'error.noFollowup': 'This host cannot queue a task into the session (agent.followup is unavailable).',
88
145
  'cmd.queued': 'Handed to this session; scope: {scope}. The result arrives as a message when the run finishes.',
89
146
  'cmd.queuedSub': 'Handed to an isolated agent; scope: {scope}. The result arrives as a message when the run finishes.',
90
147
  'cmd.queuedPlan': 'Asked for a plan first; scope: {scope}, no files will change. Confirm it when it arrives, then run the command again to execute.',
91
148
  'cmd.queuedPlanSub': 'Asked the isolated agent for a plan first; scope: {scope}, no files will change. Confirm it when it arrives, then run the command again to execute.',
92
- 'cmd.pua': 'Install the PUA protocol in this session: change method, bring evidence, stop shrugging',
93
- 'hint.pua': 'Leave empty for the default flavor; or list / alibaba / huawei / musk',
149
+ 'cmd.pua': 'Install the no-shrugging protocol',
150
+ 'hint.pua': 'Empty uses the default flavor; list shows them all',
94
151
  'pua.installed': 'PUA protocol installed ({flavor}): two failures of the same kind mean change the method, and "done" needs a command and its output.',
95
152
  'pua.list': 'Available flavors:',
96
- 'cmd.status': 'Show code-toolkit task status or the latest result',
97
- 'cmd.cancel': 'Cancel the running code-toolkit task',
98
- 'hint.scope': 'Leave empty for the whole project on the current branch; or --files a.js,b.js / --branch main (which branch to compare against; the base by default) / --commit <sha> / custom instructions; add sub for a subagent, report for a plan only',
99
- 'hint.scrub': 'Leave empty for the whole project; or --files a.js,.env / custom instructions; add sub for a subagent, report for a plan only',
100
- 'hint.review': 'Leave empty to review the uncommitted work (or the branch against its base when clean); or --files / --branch <ref> / --commit <sha>; fixes what it finds by default — add report for the report only, sub for a subagent',
153
+ 'cmd.status': 'Show task status or the latest result',
154
+ 'cmd.cancel': 'Cancel the running task',
155
+ 'hint.scope': 'Empty = whole project; --files a.js,b.js; sub isolates, report = plan only',
156
+ 'hint.scrub': 'Empty = whole project; --files <path>; sub isolates, report only',
157
+ 'hint.review': 'Empty = uncommitted work; --files/--branch/--commit; sub isolates, report only',
101
158
  'error.noCwd': 'This session has no working directory.',
102
159
  'error.noIdentity': 'This session has no usable session id, so task state cannot be recorded or guarded.',
103
160
  'error.noProvider': 'This host has no independent-context native spawn provider, so no isolated agent can run.',
@@ -120,10 +177,27 @@ const MESSAGES = {
120
177
  'status.last': 'Last run: ',
121
178
  'status.interrupted': 'The previous run started but never finished; run it again.',
122
179
  'status.submitted': 'Submitted to this session; the result is in the conversation: ',
180
+ 'status.installed': 'Installed: the {command} protocol; nothing is running in the background.',
181
+ 'status.ledgers': '{count} ledger(s), most recent:',
182
+ 'status.noLedgers': 'Ledgers: none yet.',
123
183
  'cancel.none': 'No code-toolkit task is running.',
124
184
  'cancel.done': 'Cancellation requested.',
125
185
  'report.verdict': 'Verdict: ',
126
186
  'report.noFindings': 'No findings worth acting on.',
187
+ 'report.capabilities': 'Capability states',
188
+ 'report.capability': 'Capability',
189
+ 'report.state': 'State',
190
+ 'report.evidence': 'Evidence',
191
+ 'report.walk': 'Path: ',
192
+ 'report.expected': 'Expected: ',
193
+ 'report.actual': 'Actual: ',
194
+ 'report.impact': 'Impact: ',
195
+ 'report.batch': 'Suggested batch: ',
196
+ 'state.wired': 'wired',
197
+ 'state.half': 'half',
198
+ 'state.fake': 'fake',
199
+ 'state.broken': 'broken',
200
+ 'state.missing': 'missing',
127
201
  'report.limitation': 'Not checked: ',
128
202
  'report.fixed': 'Fixed',
129
203
  'report.verifiedBy': 'Verified by: ',
package/src/report.js CHANGED
@@ -13,6 +13,41 @@ function findingList(value) {
13
13
  return value && typeof value === 'object' ? [value] : []
14
14
  }
15
15
 
16
+ /**
17
+ * The audit's closed set. A capability is in exactly one of these five states,
18
+ * and the token is the machine-readable half of the contract: the prose around
19
+ * it may be in any language, the token may not. Aliases are accepted on input
20
+ * because a model that writes Chinese will eventually write 通 instead of
21
+ * `wired`; accepting it costs nothing, guessing at a sixth state would.
22
+ */
23
+ const CAPABILITY_STATES = ['wired', 'half', 'fake', 'broken', 'missing']
24
+
25
+ const STATE_ALIASES = {
26
+ wired: 'wired',
27
+ 通: 'wired',
28
+ half: 'half',
29
+ 半: 'half',
30
+ fake: 'fake',
31
+ 假: 'fake',
32
+ broken: 'broken',
33
+ 断: 'broken',
34
+ missing: 'missing',
35
+ 无: 'missing',
36
+ }
37
+
38
+ const STATE_LABELS = {
39
+ wired: 'state.wired',
40
+ half: 'state.half',
41
+ fake: 'state.fake',
42
+ broken: 'state.broken',
43
+ missing: 'state.missing',
44
+ }
45
+
46
+ function stateOf(value) {
47
+ const token = textOf(value).toLowerCase()
48
+ return STATE_ALIASES[token] ?? STATE_ALIASES[textOf(value)] ?? null
49
+ }
50
+
16
51
  function priorityOf(value) {
17
52
  if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 3) return value
18
53
  if (typeof value !== 'string') return null
@@ -69,7 +104,37 @@ function decode(raw) {
69
104
  })
70
105
 
71
106
  const summary = textOf(value.overall_explanation)
72
- if (!summary && !findings.length) return undefined
107
+
108
+ // The audit's table. A row needs a state from the closed set; a row without
109
+ // one is dropped rather than guessed, because an unstated state is exactly
110
+ // the claim an audit exists to refuse.
111
+ const capabilities = Array.isArray(value.capabilities)
112
+ ? value.capabilities.flatMap((item) => {
113
+ if (!item || typeof item !== 'object') return []
114
+ const capability = textOf(item.capability) || textOf(item.name)
115
+ const state = stateOf(item.state)
116
+ if (!capability || !state) return []
117
+ const evidence = item.evidence && typeof item.evidence === 'object' ? item.evidence : {}
118
+ const lines = linesOf(evidence.line_range) ?? linesOf(evidence.line) ?? linesOf(item.line)
119
+ const batch = Number.isInteger(item.batch) ? item.batch : Number.isInteger(item.suggested_batch) ? item.suggested_batch : undefined
120
+ return [{
121
+ id: textOf(item.id),
122
+ capability,
123
+ state,
124
+ path: textOf(evidence.file) || textOf(evidence.path) || textOf(item.file),
125
+ start: lines?.start ?? 0,
126
+ end: lines?.end ?? 0,
127
+ walk: textOf(item.path) || textOf(item.walk),
128
+ expected: textOf(item.expected),
129
+ actual: textOf(item.actual),
130
+ impact: textOf(item.impact),
131
+ ...(batch === undefined ? {} : { batch }),
132
+ note: textOf(item.note) || textOf(item.body),
133
+ }]
134
+ })
135
+ : []
136
+
137
+ if (!summary && !findings.length && !capabilities.length) return undefined
73
138
 
74
139
  const limitations = Array.isArray(value.limitations)
75
140
  ? value.limitations.filter((item) => typeof item === 'string' && item.trim()).map((item) => item.trim())
@@ -91,6 +156,7 @@ function decode(raw) {
91
156
 
92
157
  return {
93
158
  findings,
159
+ capabilities,
94
160
  fixed,
95
161
  summary,
96
162
  limitations,
@@ -110,7 +176,11 @@ function objectsIn(raw) {
110
176
  if (raw[i] !== '{') continue
111
177
  const slice = objectAt(raw, i)
112
178
  if (!slice) continue
113
- if (slice.includes('"findings"') && slice.includes('"overall_')) found.push(slice)
179
+ // A review report carries findings; an audit report carries the capability
180
+ // table and may have no findings at all. Both are reports; prose is not.
181
+ if (slice.includes('"overall_') && (slice.includes('"findings"') || slice.includes('"capabilities"'))) {
182
+ found.push(slice)
183
+ }
114
184
  i += slice.length - 1
115
185
  }
116
186
  return found
@@ -178,6 +248,43 @@ function renderFix(fix, t) {
178
248
  return [`### ${fix.title}`, location, fix.change, verified].filter(Boolean).join('\n\n')
179
249
  }
180
250
 
251
+ /**
252
+ * The audit's table plus one detail block per actionable row: the walk, what was
253
+ * expected, what happened, and what the person cannot do. The state token becomes
254
+ * a translated label; everything else is the agent's own words.
255
+ */
256
+ function renderCapabilities(capabilities, t) {
257
+ const label = (state) => t(STATE_LABELS[state] ?? state)
258
+ const header = `| ${t('report.capability')} | ${t('report.state')} | ${t('report.evidence')} |`
259
+ const rows = capabilities.map((item) => {
260
+ const where = item.path ? fileLink(item.path, item.start, item.end) : ''
261
+ const name = item.id ? `${item.id} ${item.capability}` : item.capability
262
+ return `| ${name} | ${label(item.state)} | ${where} |`
263
+ })
264
+ const details = capabilities
265
+ .filter((item) => item.walk || item.expected || item.actual || item.impact || item.batch !== undefined || item.note)
266
+ .map((item) => {
267
+ const head = `### ${item.id ? `${item.id} · ` : ''}${item.capability} (${label(item.state)})`
268
+ const lines = [
269
+ item.walk ? `${t('report.walk')}${item.walk}` : '',
270
+ item.expected ? `${t('report.expected')}${item.expected}` : '',
271
+ item.actual ? `${t('report.actual')}${item.actual}` : '',
272
+ item.impact ? `${t('report.impact')}${item.impact}` : '',
273
+ item.batch !== undefined ? `${t('report.batch')}${item.batch}` : '',
274
+ item.note,
275
+ ].filter(Boolean)
276
+ return [head, ...lines].join('\n')
277
+ })
278
+ return [
279
+ `## ${t('report.capabilities')}`,
280
+ '',
281
+ header,
282
+ '| --- | --- | --- |',
283
+ ...rows,
284
+ ...(details.length ? ['', ...details] : []),
285
+ ].join('\n')
286
+ }
287
+
181
288
  /**
182
289
  * Render a parsed report as Markdown. `t` translates the few chrome labels;
183
290
  * finding text is never translated — it is the agent's own words.
@@ -186,13 +293,15 @@ export function renderReport(report, t) {
186
293
  if (report.format === 'text') return report.summary
187
294
 
188
295
  const limits = report.limitations.map((item) => `- ${t('report.limitation')}${item}`)
189
- const empty = !report.findings.length ? t('report.noFindings') : ''
296
+ const capabilities = report.capabilities ?? []
297
+ const empty = !report.findings.length && !capabilities.length ? t('report.noFindings') : ''
190
298
  const fixed = report.fixed ?? []
191
299
 
192
300
  return [
193
301
  report.summary,
194
302
  report.correctness ? `${t('report.verdict')}${report.correctness}` : '',
195
303
  empty,
304
+ capabilities.length ? renderCapabilities(capabilities, t) : '',
196
305
  ...report.findings.map(renderFinding),
197
306
  fixed.length ? `## ${t('report.fixed')}\n\n${fixed.map((fix) => renderFix(fix, t)).join('\n\n')}` : '',
198
307
  limits.length ? limits.join('\n') : '',