@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/index.js CHANGED
@@ -7,6 +7,8 @@ import { sessionKey } from './src/identity.js'
7
7
  import { Journal } from './src/journal.js'
8
8
  import { parseReport, renderReport } from './src/report.js'
9
9
  import { buildPua, flavorList, resolveFlavor } from './src/pua.js'
10
+ import { buildDesignText, resolveDesignInput } from './src/design.js'
11
+ import { listLedgers, resolveLedger, splitCaptionInput } from './src/caption.js'
10
12
  import { runIsolatedAgent } from './src/runtime.js'
11
13
  import { SessionCommand } from './src/command.js'
12
14
 
@@ -42,7 +44,7 @@ export function apply(ctx, config = {}) {
42
44
  if (config.reportDirectory !== undefined && !isAbsolute(config.reportDirectory)) {
43
45
  throw new Error(translate(fallbackLocale, 'error.reportDirectory'))
44
46
  }
45
- for (const key of ['reviewModel', 'simplifyModel', 'scrubModel']) {
47
+ for (const key of ['reviewModel', 'simplifyModel', 'scrubModel', 'auditModel']) {
46
48
  if (config[key] !== undefined && !String(config[key]).trim()) {
47
49
  throw new Error(translate(fallbackLocale, 'error.model'))
48
50
  }
@@ -50,6 +52,9 @@ export function apply(ctx, config = {}) {
50
52
  if (config.ledgerDirectory !== undefined && !String(config.ledgerDirectory).trim()) {
51
53
  throw new Error(translate(fallbackLocale, 'error.ledgerDirectory'))
52
54
  }
55
+ if (config.designDirectory !== undefined && !String(config.designDirectory).trim()) {
56
+ throw new Error(translate(fallbackLocale, 'error.designDirectory'))
57
+ }
53
58
 
54
59
  const journal = new Journal(config.reportDirectory ?? Journal.defaultDirectory())
55
60
  const personas = {
@@ -57,6 +62,8 @@ export function apply(ctx, config = {}) {
57
62
  review: loadPersona('review'),
58
63
  scrub: loadPersona('scrub'),
59
64
  caption: loadPersona('caption'),
65
+ audit: loadPersona('audit'),
66
+ design: loadPersona('design'),
60
67
  pua: loadPersona('pua'),
61
68
  }
62
69
 
@@ -78,6 +85,35 @@ export function apply(ctx, config = {}) {
78
85
  return cwd ? join(cwd, 'docs', 'caption') : join(ROOT, 'docs', 'caption')
79
86
  }
80
87
 
88
+ /** Where the design documents live; same rule as the caption ledger. */
89
+ const designDirectory = (cwd) => {
90
+ if (config.designDirectory) {
91
+ return isAbsolute(config.designDirectory)
92
+ ? config.designDirectory
93
+ : join(cwd ?? ROOT, config.designDirectory)
94
+ }
95
+ return cwd ? join(cwd, 'docs', 'design') : join(ROOT, 'docs', 'design')
96
+ }
97
+
98
+ /** One ledger as a list line: what it is, how far the plan got, whether it closed. */
99
+ const describeLedger = (ledger, t) => {
100
+ const plan = ledger.plan ?? { total: 0, done: 0, blocked: 0 }
101
+ const progress = plan.total
102
+ ? t('caption.planProgress').replace('{done}', String(plan.done)).replace('{total}', String(plan.total))
103
+ : `${ledger.entries.length}${t('caption.steps')}`
104
+ const blocked = plan.blocked ? t('caption.planBlocked').replace('{count}', String(plan.blocked)) : ''
105
+ const name = ledger.title ? `${ledger.slug} — ${ledger.title}` : ledger.slug
106
+ return `${name} · ${progress}${blocked}${ledger.closed ? t('caption.closed') : ''}`
107
+ }
108
+
109
+ /** The ledger tail a status answer appends after an injected protocol. */
110
+ const ledgerSummary = (agent, h, t) => {
111
+ const ledgers = listLedgers(h.ledgerDirectory(agent?.session?.header?.cwd))
112
+ if (!ledgers.length) return `\n\n${t('status.noLedgers')}`
113
+ const latest = ledgers[0]
114
+ return `\n\n${t('status.ledgers').replace('{count}', String(ledgers.length))}\n${describeLedger(latest, t)}`
115
+ }
116
+
81
117
  /** Everything a command needs from the plugin, in one place. */
82
118
  const host = {
83
119
  ctx,
@@ -87,6 +123,7 @@ export function apply(ctx, config = {}) {
87
123
  planMaxAgeMs: minutesToMs(config.planMaxAgeMinutes, 60, 'error.planMaxAge'),
88
124
  localeNow,
89
125
  ledgerDirectory,
126
+ designDirectory,
90
127
  translate: (locale, key) => translate(locale, key),
91
128
  deliver(agent, message) {
92
129
  try {
@@ -137,6 +174,21 @@ export function apply(ctx, config = {}) {
137
174
  structured: true,
138
175
  dryRunText: 'Report only. Change no files.',
139
176
  }, host),
177
+ new SessionCommand({
178
+ name: 'code-audit',
179
+ command: 'audit',
180
+ descriptionKey: 'cmd.audit',
181
+ hintKey: 'hint.audit',
182
+ persona: personas.audit,
183
+ model: config.auditModel,
184
+ // An audit has no apply path: the state table and its evidence are the
185
+ // whole deliverable, so the mode is fixed instead of being a flag.
186
+ forceDryRun: true,
187
+ defaultScope: 'project',
188
+ structured: true,
189
+ dryRunKey: 'mode.audit',
190
+ deliveryKey: 'audit.delivery',
191
+ }, host),
140
192
  new SessionCommand({
141
193
  name: 'code-caption',
142
194
  command: 'caption',
@@ -144,13 +196,53 @@ export function apply(ctx, config = {}) {
144
196
  descriptionKey: 'cmd.caption',
145
197
  hintKey: 'hint.caption',
146
198
  persona: personas.caption,
199
+ // A project accumulates ledgers, and "continue the current task" stops
200
+ // meaning anything once there are five of them. `list` and `resume <name>`
201
+ // read the ledger directory before anything is injected.
202
+ validate: (rawInput, t, { agent, host }) => {
203
+ const { mode, name } = splitCaptionInput(rawInput)
204
+ if (mode !== 'resume') return null
205
+ const ledgers = listLedgers(host.ledgerDirectory(agent?.session?.header?.cwd))
206
+ if (!ledgers.length) return t('caption.noLedgers')
207
+ const resolved = resolveLedger(name, ledgers)
208
+ if (resolved.ledger) return null
209
+ const names = resolved.matches ?? ledgers
210
+ const head = resolved.error === 'ambiguous'
211
+ ? t('caption.ambiguousLedger').replace('{name}', name || '—')
212
+ : t('caption.unknownLedger').replace('{name}', name || '—')
213
+ return `${head}\n${names.map((ledger) => `- ${ledger.slug}`).join('\n')}`
214
+ },
215
+ early: (rawInput, t, { agent, host }) => {
216
+ if (splitCaptionInput(rawInput).mode !== 'list') return null
217
+ const directory = host.ledgerDirectory(agent?.session?.header?.cwd)
218
+ const ledgers = listLedgers(directory)
219
+ if (!ledgers.length) return { kind: 'success', text: t('caption.listEmpty').replace('{dir}', directory) }
220
+ return {
221
+ kind: 'success',
222
+ text: [
223
+ t('caption.listHead').replace('{dir}', directory),
224
+ ...ledgers.map((ledger, index) => `${index + 1}. ${describeLedger(ledger, t)}`),
225
+ '',
226
+ t('caption.listHint'),
227
+ ].join('\n'),
228
+ }
229
+ },
147
230
  buildText: ({ rawInput, agent, locale, host, installed }) => {
148
231
  const cwd = agent.session?.header?.cwd
149
- const ledger = host.ledgerDirectory(cwd)
150
- const task = String(rawInput ?? '').trim()
151
- || '继续当前会话正在进行的任务:先读台账,再决定下一步。'
152
- const head = ['# Caption loop', '', `Task: ${task}`]
153
- if (cwd) head.push(`Working directory: ${cwd}`, `Ledger directory: ${ledger}`)
232
+ const directory = host.ledgerDirectory(cwd)
233
+ const { mode, name, task } = splitCaptionInput(rawInput)
234
+ const ledger = mode === 'resume' ? resolveLedger(name, listLedgers(directory)).ledger : undefined
235
+ const head = ['# Caption loop', '']
236
+ if (ledger) {
237
+ head.push(
238
+ `Task: continue the ledger at ${ledger.path}. Read its head and the last two entries first, then take the next step. That file is the memory of this run — do not start a new one.`,
239
+ `Ledger: ${ledger.path}`,
240
+ )
241
+ } else {
242
+ head.push(`Task: ${mode === 'task' && task ? task : '继续当前会话正在进行的任务:先读台账,再决定下一步。'}`)
243
+ }
244
+ if (cwd) head.push(`Working directory: ${cwd}`)
245
+ head.push(`Ledger directory: ${directory}`)
154
246
  head.push(`Reference directory: ${personas.caption.directory}`)
155
247
  // The protocol is already in this conversation; repeating it only adds a
156
248
  // second copy for the agent to disagree with.
@@ -159,8 +251,39 @@ export function apply(ctx, config = {}) {
159
251
  : personas.caption.text
160
252
  return [...head, '', body, '', outputLanguage(locale)].join('\n')
161
253
  },
162
- receipt: (rawInput, t, installed, agent) => t(installed ? 'caption.reinstalled' : 'caption.installed')
163
- .replace('{dir}', ledgerDirectory(agent?.session?.header?.cwd)),
254
+ receipt: (rawInput, t, installed, agent) => {
255
+ const { mode, name } = splitCaptionInput(rawInput)
256
+ const directory = ledgerDirectory(agent?.session?.header?.cwd)
257
+ if (mode === 'resume') {
258
+ const ledger = resolveLedger(name, listLedgers(directory)).ledger
259
+ return t('caption.resumed').replace('{path}', ledger?.path ?? directory)
260
+ }
261
+ return t(installed ? 'caption.reinstalled' : 'caption.installed').replace('{dir}', directory)
262
+ },
263
+ }, host),
264
+ new SessionCommand({
265
+ name: 'code-design',
266
+ command: 'design',
267
+ kind: 'inject',
268
+ descriptionKey: 'cmd.design',
269
+ hintKey: 'hint.design',
270
+ persona: personas.design,
271
+ buildText: ({ rawInput, agent, locale, host, installed }) => {
272
+ const cwd = agent.session?.header?.cwd
273
+ const { tier, task } = resolveDesignInput(rawInput)
274
+ return buildDesignText({
275
+ tier,
276
+ task,
277
+ cwd,
278
+ directory: host.designDirectory(cwd),
279
+ personaDirectory: personas.design.directory,
280
+ persona: personas.design.text,
281
+ installed,
282
+ language: outputLanguage(locale),
283
+ })
284
+ },
285
+ receipt: (rawInput, t, installed, agent) => t(installed ? 'design.reinstalled' : 'design.installed')
286
+ .replace('{dir}', designDirectory(agent?.session?.header?.cwd)),
164
287
  }, host),
165
288
  new SessionCommand({
166
289
  name: 'pua',
@@ -187,11 +310,22 @@ export function apply(ctx, config = {}) {
187
310
 
188
311
  const record = key ? await h.journal.read(key).catch(() => undefined) : undefined
189
312
  if (!record) return { kind: 'success', text: t('status.none') }
190
- if (record.state === 'running') return { kind: 'success', text: t('status.interrupted') }
313
+
314
+ // An injected protocol leaves no run behind: its record has no scope and
315
+ // no mode, and printing those fields raw produced "最近一次:undefined ·
316
+ // undefined". caption also has a ledger to point at.
317
+ const ledgers = record.command === 'caption' ? ledgerSummary(agent, h, t) : ''
318
+ if (record.state === 'running') return { kind: 'success', text: `${t('status.interrupted')}${ledgers}` }
319
+ if (record.state === 'installed') {
320
+ const text = t('status.installed').replace('{command}', record.command ?? '')
321
+ return { kind: 'success', text: `${text}${ledgers}` }
322
+ }
323
+
324
+ const run = [record.scope, record.mode].filter(Boolean).join(' · ')
191
325
  if (record.state === 'submitted') {
192
- return { kind: 'success', text: `${t('status.submitted')}${record.scope} · ${record.mode}` }
326
+ return { kind: 'success', text: `${t('status.submitted')}${run}${ledgers}` }
193
327
  }
194
- return { kind: 'success', text: `${t('status.last')}${record.scope} · ${record.mode}\n\n${record.result}` }
328
+ return { kind: 'success', text: `${t('status.last')}${run}\n\n${record.result ?? ''}${ledgers}` }
195
329
  },
196
330
  }, host),
197
331
  new SessionCommand({
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Code toolkit",
4
- "description": "Five commands that work with no arguments. Review looks at the uncommitted changes (or the branch against its base when the tree is clean), reports, and fixes what it finds — add report for the report only. Simplify and scrub cover the whole project and write by default (add report for a plan only). Caption runs a hard task through an explicit loop with a ledger, and can create expert subagents mid-run for work that splits without colliding. Pua installs a protocol for changing method and showing evidence instead of shrugging. Add sub to run in an isolated agent instead. Prompts are organised as a layered skill-style tree, with a deterministic test suite and a model evaluation loop."
4
+ "description": "Seven commands that work with no arguments: review and fix, simplify, scrub, capability audit, a caption loop with a plan and a ledger, scenario-driven design, and a PUA protocol. Add sub for an isolated agent, report for a report only."
5
5
  }
6
- }
6
+ }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "代码工具箱",
4
- "description": "五条命令,空输入即可用。审查默认看未提交的改动(都提交了就看当前分支相对基线的改动),出报告并修复发现的问题,加 report 只出报告。精炼与隐私清理默认扫整个项目并直接改(加 report 只出报告)。caption 把难任务装进显式循环:一步一验、过程落成台账,执行中可以创建专家子 agent 分派任务。pua 给会话装上「失败换方法、完成要证据」的协议。加 sub 改用独立 agent。提示词按 skill 分层组织,附确定性测试与模型评测流程。"
4
+ "description": "七条命令,空输入即可用:审查与修复、精炼、隐私清理、能力审计、caption 循环(计划清单 + 台账)、场景驱动设计、PUA 协议。加 sub 换独立 agent,加 report 只出报告。"
5
5
  }
6
- }
6
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@morning-start/dsh-code-toolkit",
3
- "version": "0.27.4",
3
+ "version": "0.28.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org"
8
8
  },
9
9
  "type": "module",
10
- "description": "Five commands for DeepSeek Harness: review and fix, behavior-preserving simplification, privacy scrubbing, a caption loop with a ledger, and a PUA protocol. Each runs in the current session by default (add sub for an isolated agent) and writes by default (add report for a report only).",
10
+ "description": "Seven commands for DeepSeek Harness: review, simplify, scrub, capability audit, caption loop, scenario-driven design, and a PUA protocol.",
11
11
  "license": "MIT",
12
12
  "icon": "./icon.svg",
13
13
  "keywords": [
@@ -20,6 +20,9 @@
20
20
  "simplify",
21
21
  "privacy",
22
22
  "secret-scan",
23
+ "capability-audit",
24
+ "product-design",
25
+ "scenario",
23
26
  "caption",
24
27
  "pua",
25
28
  "subagent"
package/src/caption.js ADDED
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Reading a caption ledger without owning its format.
3
+ *
4
+ * A ledger is Markdown written by a model: a `# Caption: …` heading, a few
5
+ * `- Field: value` lines, one `## N. title` entry per iteration, and a closing
6
+ * `## Close`. The parser is deliberately tolerant — an older ledger that lacks a
7
+ * field must still list and resume, and a heading that does not match the current
8
+ * habit must not make the file invisible. Anything unreadable degrades to the
9
+ * file name.
10
+ */
11
+
12
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
13
+ import { join } from 'node:path'
14
+
15
+ const FIELD = /^\s*-\s*(task|criteria|gate|flow|approved)\s*:\s*(.+)$/i
16
+ const ENTRY = /^##\s+(\d+)\.\s*(.+)$/
17
+ const OUTCOME = /^\s*-\s*outcome\s*:\s*([a-z][a-z -]*)/gim
18
+ const PLAN_HEADING = /^##\s+plan\b/i
19
+ const PLAN_ITEM = /^\s*-\s*\[([ xX~-])\]\s*(.+)$/
20
+
21
+ /**
22
+ * The plan block: `[ ]` open, `[x]` done, `[~]` blocked, `[-]` dropped. Only lines
23
+ * inside the `## Plan` section count, so a checklist quoted in an entry is not
24
+ * mistaken for the plan.
25
+ */
26
+ export function parsePlan(lines) {
27
+ const start = lines.findIndex((line) => PLAN_HEADING.test(line))
28
+ if (start === -1) return { total: 0, done: 0, open: 0, blocked: 0, dropped: 0, items: [] }
29
+
30
+ const items = []
31
+ for (let index = start + 1; index < lines.length; index += 1) {
32
+ if (/^##\s+\S/.test(lines[index])) break
33
+ const match = PLAN_ITEM.exec(lines[index])
34
+ if (!match) continue
35
+ const mark = match[1].toLowerCase()
36
+ items.push({
37
+ status: mark === 'x' ? 'done' : mark === '~' ? 'blocked' : mark === '-' ? 'dropped' : 'open',
38
+ text: match[2].trim(),
39
+ })
40
+ }
41
+
42
+ const count = (status) => items.filter((item) => item.status === status).length
43
+ return {
44
+ total: items.length,
45
+ done: count('done'),
46
+ open: count('open'),
47
+ blocked: count('blocked'),
48
+ dropped: count('dropped'),
49
+ items,
50
+ }
51
+ }
52
+
53
+ /** Pull the head, the entries, and the outcome counts out of one ledger. */
54
+ export function parseLedger(text) {
55
+ // A ledger written by Notepad or Set-Content can start with a BOM, which makes
56
+ // `/^#/` miss the heading and the file look like it has no title.
57
+ const source = String(text ?? '').replace(/^\uFEFF/, '')
58
+ const lines = source.split(/\r?\n/)
59
+
60
+ const heading = lines.find((line) => /^#\s+\S/.test(line)) ?? ''
61
+ const fields = {}
62
+ for (const line of lines) {
63
+ const match = FIELD.exec(line)
64
+ // First wins: the head states the contract, and a closing entry may repeat
65
+ // `- Gate:` with that run's result — listing must show the contract.
66
+ if (match && !(match[1].toLowerCase() in fields)) fields[match[1].toLowerCase()] = match[2].trim()
67
+ }
68
+
69
+ const entries = []
70
+ for (const line of lines) {
71
+ const match = ENTRY.exec(line)
72
+ if (match) entries.push({ number: Number(match[1]), title: match[2].trim() })
73
+ }
74
+
75
+ const outcomes = [...source.matchAll(OUTCOME)].map((match) => match[1].trim().toLowerCase())
76
+ return {
77
+ title: heading.replace(/^#\s+/, '').trim(),
78
+ task: fields.task ?? '',
79
+ criteria: fields.criteria ?? '',
80
+ gate: fields.gate ?? '',
81
+ flow: fields.flow ?? '',
82
+ entries,
83
+ plan: parsePlan(lines),
84
+ done: outcomes.filter((outcome) => outcome === 'done').length,
85
+ unverified: outcomes.filter((outcome) => outcome === 'unverified').length,
86
+ deadEnds: outcomes.filter((outcome) => outcome.startsWith('dead')).length,
87
+ closed: /^##\s*Close\b/im.test(source),
88
+ }
89
+ }
90
+
91
+ /** Every `*.md` in the ledger directory, most recently changed first. */
92
+ export function listLedgers(directory) {
93
+ if (!directory || !existsSync(directory)) return []
94
+ const ledgers = []
95
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
96
+ if (!entry.isFile() || !entry.name.toLowerCase().endsWith('.md')) continue
97
+ const path = join(directory, entry.name)
98
+ try {
99
+ const text = readFileSync(path, 'utf8')
100
+ ledgers.push({
101
+ slug: entry.name.replace(/\.md$/i, ''),
102
+ path,
103
+ modifiedAt: statSync(path).mtimeMs,
104
+ ...parseLedger(text),
105
+ })
106
+ } catch {
107
+ ledgers.push({ slug: entry.name.replace(/\.md$/i, ''), path, modifiedAt: 0, title: '', entries: [], closed: false })
108
+ }
109
+ }
110
+ return ledgers.sort((a, b) => b.modifiedAt - a.modifiedAt || a.slug.localeCompare(b.slug))
111
+ }
112
+
113
+ /**
114
+ * Find the ledger a person meant: exact slug, then 1-based position in the list,
115
+ * then a unique substring of the slug or the title. Ambiguity is reported rather
116
+ * than resolved by guessing.
117
+ */
118
+ export function resolveLedger(name, ledgers) {
119
+ const wanted = String(name ?? '').trim()
120
+ if (!wanted) return { error: 'missing' }
121
+
122
+ const exact = ledgers.find((ledger) => ledger.slug.toLowerCase() === wanted.toLowerCase())
123
+ if (exact) return { ledger: exact }
124
+
125
+ if (/^\d+$/.test(wanted)) {
126
+ const index = Number(wanted) - 1
127
+ if (index >= 0 && index < ledgers.length) return { ledger: ledgers[index] }
128
+ }
129
+
130
+ const needle = wanted.toLowerCase()
131
+ const matches = ledgers.filter((ledger) =>
132
+ ledger.slug.toLowerCase().includes(needle) || (ledger.title ?? '').toLowerCase().includes(needle))
133
+ if (matches.length === 1) return { ledger: matches[0] }
134
+ if (matches.length > 1) return { error: 'ambiguous', matches }
135
+ return { error: 'unknown' }
136
+ }
137
+
138
+ /**
139
+ * The first word decides the mode: `list` alone, `resume <name>`, or a task.
140
+ * `list` must be the whole input, so a task that starts with the word is not
141
+ * swallowed by mistake.
142
+ */
143
+ export function splitCaptionInput(rawInput) {
144
+ const text = String(rawInput ?? '').trim()
145
+ if (/^list$/i.test(text)) return { mode: 'list' }
146
+ const resume = /^resume\b[\s::]*([\s\S]*)$/i.exec(text)
147
+ if (resume) return { mode: 'resume', name: resume[1].trim() }
148
+ return { mode: 'task', task: text }
149
+ }
package/src/command.js CHANGED
@@ -59,12 +59,16 @@ export class SessionCommand {
59
59
  /** Put text into the session: caption's protocol, pua's flavor. */
60
60
  async inject(agent, rawInput, locale, t) {
61
61
  const { spec, host } = this
62
+ // Commands that read something before injecting (a ledger, a directory) need
63
+ // the session and the shared services; they get the same context the build
64
+ // step does, so a decision made in validate is the one buildText acts on.
65
+ const context = { agent, host, locale }
62
66
  if (spec.validate) {
63
- const failure = spec.validate(rawInput, t)
67
+ const failure = spec.validate(rawInput, t, context)
64
68
  if (failure) return { kind: 'error', text: failure }
65
69
  }
66
70
  if (spec.early) {
67
- const result = spec.early(rawInput, t)
71
+ const result = spec.early(rawInput, t, context)
68
72
  if (result) return result
69
73
  }
70
74
  if (typeof agent?.steer !== 'function') return { kind: 'error', text: t('error.noSteer') }
@@ -295,15 +299,25 @@ export class SessionCommand {
295
299
  /** The task text handed to either the current agent or the child. */
296
300
  async buildPrompt({ scope, mode, cwd, locale, signal, inline, plan }) {
297
301
  const { spec } = this
302
+ const t = (key) => this.host.translate(locale, key)
298
303
  const chinese = String(locale).startsWith('zh')
304
+ // A command whose dry run is a report rather than a plan (the audit) names
305
+ // its own instruction by key, so the wording is translated with the rest of
306
+ // the chrome instead of being frozen in one language here.
307
+ const dryRunLine = spec.dryRunKey
308
+ ? t(spec.dryRunKey)
309
+ : chinese ? '只出计划,不要改任何文件。' : (spec.dryRunText ?? 'Report only. Change no files.')
299
310
  const modeLine = mode === 'dry-run'
300
- ? (chinese ? '只出计划,不要改任何文件。' : (spec.dryRunText ?? 'Report only. Change no files.'))
311
+ ? dryRunLine
301
312
  : (chinese
302
313
  ? '按计划修改,并验证行为不变;验证不通过就回退那一处改动并如实报告。'
303
314
  : 'Apply the changes, then verify that behavior is unchanged. If verification fails, revert that change and report it.')
304
- const delivery = chinese
305
- ? '你的最终回复会原样发给用户,作为这次任务的结果:写清改了什么、跑了哪条命令、输出是什么、哪些没有验证。'
306
- : 'Your final reply is delivered to the user as the result: say what changed, which command ran, what it printed, and what stayed unverified.'
315
+ const deliveryKey = spec.deliveryKey
316
+ const delivery = deliveryKey
317
+ ? t(deliveryKey)
318
+ : chinese
319
+ ? '你的最终回复会原样发给用户,作为这次任务的结果:写清改了什么、跑了哪条命令、输出是什么、哪些没有验证。'
320
+ : 'Your final reply is delivered to the user as the result: say what changed, which command ran, what it printed, and what stayed unverified.'
307
321
  const personaLine = chinese
308
322
  ? '先读参考目录下的 AGENT.md,按它的流程与判定标准执行。'
309
323
  : 'Read AGENT.md in the reference directory first and follow its process and bar.'
package/src/design.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The design command's input and prompt.
3
+ *
4
+ * The skill this protocol comes from grades its own answer by effort: a
5
+ * thirty-minute judgement, a half-day design, a full plan. That is worth keeping,
6
+ * but not as a config option nobody reads — it is the first word of the command,
7
+ * so `/code-design quick` and `/code-design` are different sizes of answer.
8
+ *
9
+ * Only the first word is a tier: a task that happens to contain "quick" later in
10
+ * the sentence is not silently re-sized.
11
+ */
12
+
13
+ /** Tiers that can be named explicitly; `default` is what no tier means. */
14
+ export const DESIGN_TIERS = ['quick', 'full']
15
+
16
+ const DEFAULT_TIER = 'default'
17
+
18
+ const DEFAULT_TIER_BRIEF = [
19
+ 'Tier: default — a half-day design.',
20
+ 'Base maps, eight to twelve scenarios, three P0 cards, one batch table with its',
21
+ 'dependencies, and documents 01–03. Give the one-page conclusion first.',
22
+ ].join(' ')
23
+
24
+ const TIER_BRIEF = {
25
+ quick: [
26
+ 'Tier: quick — a thirty-minute judgement, one page.',
27
+ 'One document: the one-page conclusions, five scenarios with a one-line failure',
28
+ 'form each, and a batch table of at most three items. No scenario cards, no',
29
+ 'appendix. Say at the top that this is the quick tier.',
30
+ ].join(' '),
31
+ full: [
32
+ 'Tier: full — a plan someone will build from.',
33
+ 'All four base maps, every scenario, three P0 cards, the multi-angle matrix, the',
34
+ 'batch table with dependencies, the not-doing table and the progress table, plus',
35
+ 'every document that applies to this project. The one-page conclusion still comes',
36
+ 'first, and fifteen pages of appendix never replace it.',
37
+ ].join(' '),
38
+ }
39
+
40
+ /** Split the first word off as a tier when it names one. */
41
+ export function resolveDesignInput(rawInput) {
42
+ const text = String(rawInput ?? '').trim()
43
+ const match = /^(quick|full)\b[\s,:,:]*/i.exec(text)
44
+ if (match) return { tier: match[1].toLowerCase(), task: text.slice(match[0].length).trim() }
45
+ return { tier: DEFAULT_TIER, task: text }
46
+ }
47
+
48
+ /** The instruction that tells the agent how large an answer to give. */
49
+ export function tierBrief(tier) {
50
+ return TIER_BRIEF[tier] ?? DEFAULT_TIER_BRIEF
51
+ }
52
+
53
+ const DEFAULT_TASK = 'design the next step for the project in this session: read its own rules and goals first, then produce the maps and the plan.'
54
+
55
+ /**
56
+ * The text injected into the conversation: where the documents go, which tier
57
+ * this run is, and the protocol itself — unless it is already installed, in which
58
+ * case repeating 10 KB of protocol only gives the agent two copies to disagree
59
+ * with.
60
+ */
61
+ export function buildDesignText({ tier, task, cwd, directory, personaDirectory, persona, installed, language }) {
62
+ const head = ['# Scenario-driven design', '', `Task: ${task || DEFAULT_TASK}`]
63
+ if (cwd) head.push(`Working directory: ${cwd}`)
64
+ head.push(`Design directory: ${directory}`)
65
+ head.push(`Reference directory: ${personaDirectory}`)
66
+ const body = installed
67
+ ? 'The design protocol is already installed earlier in this conversation. Continue under it: re-read the documents you already wrote before adding to them, and never rewrite a settled decision without opening a new one.'
68
+ : persona
69
+ return [...head, '', tierBrief(tier), '', body, '', language].join('\n')
70
+ }