@morning-start/dsh-code-toolkit 0.27.1 → 0.28.0

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 (35) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/README.md +71 -10
  3. package/agents/audit/AGENT.md +171 -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 +12 -0
  12. package/agents/caption/references/evidence.md +46 -0
  13. package/agents/design/AGENT.md +214 -0
  14. package/agents/design/examples/one-page.md +55 -0
  15. package/agents/design/examples/overkill.md +56 -0
  16. package/agents/design/references/base-maps.md +110 -0
  17. package/agents/design/references/deliverables.md +71 -0
  18. package/agents/design/references/model-and-ports.md +73 -0
  19. package/agents/design/references/plan-and-batches.md +92 -0
  20. package/agents/design/references/scenario-cards.md +133 -0
  21. package/agents/design/references/self-check.md +73 -0
  22. package/agents/pua/AGENT.md +3 -0
  23. package/agents/review/AGENT.md +16 -0
  24. package/agents/scrub/AGENT.md +5 -1
  25. package/index.js +65 -4
  26. package/locale/en.json +2 -2
  27. package/locale/zh.json +2 -2
  28. package/package.json +5 -3
  29. package/src/command.js +73 -52
  30. package/src/design.js +70 -0
  31. package/src/i18n.js +50 -0
  32. package/src/identity.js +23 -0
  33. package/src/journal.js +10 -0
  34. package/src/report.js +112 -3
  35. package/src/runtime.js +21 -9
@@ -0,0 +1,133 @@
1
+ # Scenario cards
2
+
3
+ Source: adapted from the local skill `scenario-driven-product-design`
4
+ (`references/scenario-cards.md`), user-authored, no upstream licence; condensed and
5
+ retargeted at this plugin's output.
6
+
7
+ A card describes one scenario. It is not a proposal: no solution, no estimate, no
8
+ file names to edit. If a solution appears on the card, the problem stops being
9
+ visible.
10
+
11
+ ## Template
12
+
13
+ ```markdown
14
+ ### S07 — <one-line goal>
15
+ - Role / entry / permission:
16
+ - Trigger: <user action or system event>
17
+ - Precondition: <the concrete state: draft | active | paused | archived | offline>
18
+ - Main path: step → where it lands (screen / interface / event)
19
+ - Branches: 空 重 并 权 断 慢 大 旧 — only the ones that apply, each one line
20
+ - Failure form: what the person sees · did the ledger record it · can it recover · who cleans up
21
+ - Current state: wired | half | fake | broken | missing — file:line
22
+ - Acceptance: Given … When … Then … (within <limit>)
23
+ - Must not change: <the negative assertion>
24
+ ```
25
+
26
+ The negative assertion is not optional. "Saving a draft must not emit a run event"
27
+ catches a whole class of regressions that the positive acceptance never will,
28
+ because a positive test passes when the extra event is also emitted.
29
+
30
+ ## Two filled cards
31
+
32
+ ### S03 — resume a run after the app restarts
33
+
34
+ - Role: operator / entry: the run list / permission: read + retry
35
+ - Trigger: the app is started with an `in_progress` run in the ledger
36
+ - Precondition: `in_progress`, last heartbeat 4 hours old
37
+ - Main path: run list shows it as interrupted → "retry" resumes from the last
38
+ completed step → the ledger gets a new attempt row
39
+ - Branches: 断 (the child process is gone) · 旧 (a run from before the new field
40
+ exists) · 重 (retry clicked twice)
41
+ - Failure form: the row says "interrupted" with the reason and the last step; the
42
+ ledger has the attempt; retry is safe to press again; nobody cleans up manually
43
+ - Current state: `half` — `src/run/list.js:88` reads the state, no retry handler is
44
+ registered in the command table
45
+ - Acceptance: Given a ledger with a stale `in_progress` run, when the list is
46
+ opened, then the row reads "interrupted · step 3" within 2 s
47
+ - Must not change: opening the list must not write to the ledger
48
+
49
+ ### S11 — approve a plan from another role
50
+
51
+ - Role: approver / entry: the pending list / permission: approve only
52
+ - Trigger: a plan arrives in state `submitted`
53
+ - Precondition: `submitted`, owner is a different role
54
+ - Main path: pending list → open → approve → state `approved` → owner is notified
55
+ - Branches: 权 (the approver is the author) · 并 (two approvers at once) · 断 (the
56
+ owner was deleted)
57
+ - Failure form: refusal names the exit ("ask another approver") and does not change
58
+ state; no notification is sent on refusal
59
+ - Current state: `fake` — `docs/approval.md` describes it; no route and no command
60
+ exists
61
+ - Acceptance: Given a plan owned by role A, when role A tries to approve it, then
62
+ the call returns a refusal naming another approver, and the state stays `submitted`
63
+ - Must not change: a refused approval must not emit an approval event
64
+
65
+ ## The scenario list
66
+
67
+ The list is the index; the cards are the three that matter. Use these columns and
68
+ do not invent others, so two rounds can be diffed:
69
+
70
+ ```text
71
+ | ID | Role | Stage | Intent | One-line goal | Current state | Frequency | Harm | Evidence |
72
+ ```
73
+
74
+ - **Stage** is one of enter / create / run / intervene / close / look back.
75
+ - **Current state** is the five-state token, or `unconfirmed`. It is filled from
76
+ `/code-audit` — never from reading a README.
77
+ - **Frequency** and **Harm** are the two sort keys; give them a scale and keep it
78
+ (per day / per task, and data loss > deadlock > misleading > friction).
79
+ - **Evidence** is `file:line` or the event that proves the row is real. A row with
80
+ no evidence is a wish and does not enter the list.
81
+
82
+ Coverage gate, checked before ranking: at least one row per baseline group, three
83
+ per role, one per stage, three failure rows, and every row cites an entry point or
84
+ an event. Counts, not impressions — write the numbers under the table.
85
+
86
+ ## The eight baseline groups
87
+
88
+ Enumerate against these before brainstorming anything else. Each one asks a question
89
+ the product either answers or does not.
90
+
91
+ | Group | Question | A gap looks like |
92
+ | --- | --- | --- |
93
+ | First use | Empty state: is the first useful result within three steps? | Onboarding that explains instead of producing |
94
+ | Daily path | The most frequent route — where does each step land? | A step that lands in no screen, no interface, no event |
95
+ | Stuck | It is not moving: how does the person find out, and locate why? | A spinner, or a status nobody can explain |
96
+ | Adjustment | Requirements, people, or priority change mid-flight: how to back out and resume? | Only "start over" |
97
+ | Paused | Do "stopped by the user" and "declared dead by the system" look different? | One grey badge for both |
98
+ | Switching | Across projects or teams, is context lost? | The previous project's data still on screen |
99
+ | Collaboration | Handoff, assignment, comment, approval — did the message actually arrive? | A notification nobody receives |
100
+ | Quota and cost | At the limit: does the person see why and what next, or just a number? | A number with no path |
101
+
102
+ Plus three failure classes, at least one scenario each: permission refused, upstream
103
+ cancelled or dependency gone, crash and recovery.
104
+
105
+ ## The quality bar
106
+
107
+ A card is good enough when a stranger could implement it without asking what was
108
+ meant, and could tell whether you did. Concretely:
109
+
110
+ - **Every step lands somewhere.** "The user sees progress" is not a landing; "the
111
+ run row shows `step 3/7`" is.
112
+ - **The precondition is a state**, not a mood: name it in the product's own
113
+ vocabulary.
114
+ - **The branches are chosen, not listed.** Empty/double/concurrent/permission/
115
+ dependency/slow/large/old — write the ones that apply and delete the rest.
116
+ - **The failure form answers three questions**: what is shown, what was recorded,
117
+ who recovers.
118
+ - **The negative assertion is executable** by someone who was not in this
119
+ conversation.
120
+
121
+ ## Three questions that expose a slogan
122
+
123
+ 1. Where does this state come from?
124
+ 2. Where does this write land?
125
+ 3. Who cleans up after it fails?
126
+
127
+ If any answer is "the system handles it", the card is not finished.
128
+
129
+ ## How many cards
130
+
131
+ Full scenario list: every row of the grid. P0 cards: three. More than three P0
132
+ cards means the ranking has not been done; fewer means a scenario is probably
133
+ missing a failure branch.
@@ -0,0 +1,73 @@
1
+ # The delivery check
2
+
3
+ Source: adapted from the local skill `scenario-driven-product-design` (`SKILL.md`,
4
+ 「自检(交付前逐条打勾)」), user-authored, no upstream licence; retargeted at this
5
+ protocol's outputs.
6
+
7
+ Tick every line before you hand a design over. This is a gate, not a summary: an
8
+ unticked line is a finding about the design, so fix the design or write the gap into
9
+ the open-questions section. Do not tick a line you did not check.
10
+
11
+ ## Roles and boundaries
12
+
13
+ - [ ] Every role has an entry point, a write surface, a refusal surface, and an owner
14
+ for failure.
15
+ - [ ] At least one high-frequency need is **denied** by the permission matrix, with
16
+ its alternative entry point written down.
17
+ - [ ] The non-users are named: who this does not serve, and what it does not replace.
18
+
19
+ ## Capability and evidence
20
+
21
+ - [ ] Every row of the feature card has a state and an evidence cell; nothing says
22
+ "should already be implemented".
23
+ - [ ] The capability states come from `/code-audit` or are marked `unconfirmed`;
24
+ none was inferred from a README, a comment, or a test name.
25
+ - [ ] Every numeric claim in the documents came from a command's output, and every
26
+ claim about current behaviour carries `file:line`.
27
+
28
+ ## Scenarios
29
+
30
+ - [ ] The list covers the eight baseline groups and the three failure classes, and
31
+ the counts are written under the table.
32
+ - [ ] Every P0 card has all ten fields, including the boundary eight (empty,
33
+ duplicate, concurrent, permission, dependency, slow, large, old) that apply.
34
+ - [ ] Every P0 card has a negative assertion — what the action must not change.
35
+ - [ ] No card contains a solution. Solutions live in the batch table.
36
+
37
+ ## Structure (when the project has models, ports, or contracts)
38
+
39
+ - [ ] Every model field can answer where its value comes from; a field that cannot
40
+ was deleted or given a port.
41
+ - [ ] Every external dependency is either behind a port with a written admission
42
+ reason, or listed in the not-abstracting list.
43
+ - [ ] Every invariant has a failure code and a test that can go red. An invariant
44
+ with only wording is not an invariant.
45
+ - [ ] Event types and error codes exist in one catalogue, and every name used by the
46
+ documents or the code is in it.
47
+ - [ ] Every decision points at a D number; a changed decision opened a new row and
48
+ names what it supersedes.
49
+
50
+ ## Ranking and batches
51
+
52
+ - [ ] The documents say whether the order used frequency-first or harm-first, and
53
+ did not mix them.
54
+ - [ ] Batch 0 is a gate, and the gate names its scanner, allowlist, ratchet, and
55
+ cross-check.
56
+ - [ ] Every batch has acceptance, risk, and rollback, and the dependency order is in
57
+ the table.
58
+ - [ ] The not-doing table has at least three rows, each with a reason and a condition
59
+ to revisit.
60
+ - [ ] The progress table uses only the four states, and a "done" row has a commit.
61
+
62
+ ## Assumptions
63
+
64
+ - [ ] Every assumption that depends on the host or a third party is either verified
65
+ by a probe or marked **unconfirmed** and tied to the batch that needs it.
66
+ - [ ] The unconfirmed items are in their own section and none of them has migrated
67
+ into a conclusion.
68
+
69
+ ## What to do with a failed line
70
+
71
+ Say which line failed and what it would take to pass. A design delivered with three
72
+ unticked lines and those three named is usable; one delivered with all sixteen ticked
73
+ and two of them false is the failure this checklist exists to prevent.
@@ -64,3 +64,6 @@ earns you two postmortems.
64
64
  | `references/flavors.md` | the session names a corporate flavor, or you need the rhetoric for one |
65
65
  | `references/methodology.md` | you are at L3 and owe the 7-point checklist |
66
66
  | `examples/run.md` | you want the shape of a stuck turn that recovers, and one that does not |
67
+
68
+ If a reference path is unreadable, continue from this file — the core instructions are
69
+ self-sufficient.
@@ -90,6 +90,22 @@ Return **exactly one JSON object** and nothing else — no prose, no markdown fe
90
90
  - `fixed` is present only in apply mode, and only for fixes you actually made and verified. In dry-run it is absent or empty.
91
91
  - `limitations` is optional; use it for files you could not open, tests you could not run, or generated code you skipped.
92
92
 
93
+ ### When the brief says in-session
94
+
95
+ The envelope is for the isolated run. When the brief says this run is in-session,
96
+ the person reads the report in the conversation, not through the renderer — write
97
+ the same content as Markdown instead of the JSON object:
98
+
99
+ - one line of summary, and the verdict;
100
+ - one section per finding: `### [P1] <title>`, then the location as `path:line`,
101
+ then the body;
102
+ - a `## Fixed` section in apply mode: one entry per fix with its file and the
103
+ command that verified it;
104
+ - a `## Not checked` section when `limitations` is non-empty.
105
+
106
+ The JSON rules above still decide **what** goes in each part; only the format
107
+ changes. Do not send both.
108
+
93
109
  ## Honesty
94
110
 
95
111
  Zero findings is a valid, common answer. Do not manufacture findings to look thorough. Do not claim you ran a test you did not run. If the change is clean, `overall_correctness` is `"patch is correct"` and `findings` is `[]`.
@@ -70,7 +70,11 @@ When you cannot tell whether a value is live, say so in the body and set the pri
70
70
 
71
71
  ## Output
72
72
 
73
- **Dry-run** — return exactly one JSON object, no prose, no fence. Same schema the review agent uses:
73
+ **Dry-run** — return exactly one JSON object, no prose, no fence. When the brief says
74
+ this run is in-session, write the same rows as a Markdown table instead (one row per
75
+ finding: masked value, `path:line`, priority, one-line reason) — the person reads it in
76
+ the conversation and never sees the renderer. Do not send both. Same schema the review
77
+ agent uses otherwise:
74
78
 
75
79
  ```json
76
80
  {
package/index.js CHANGED
@@ -3,9 +3,11 @@ import { dirname, isAbsolute, join } from 'node:path'
3
3
  import { fileURLToPath } from 'node:url'
4
4
 
5
5
  import { outputLanguage, readHostLocale, resolveLocale, translate } from './src/i18n.js'
6
+ import { sessionKey } from './src/identity.js'
6
7
  import { Journal } from './src/journal.js'
7
8
  import { parseReport, renderReport } from './src/report.js'
8
9
  import { buildPua, flavorList, resolveFlavor } from './src/pua.js'
10
+ import { buildDesignText, resolveDesignInput } from './src/design.js'
9
11
  import { runIsolatedAgent } from './src/runtime.js'
10
12
  import { SessionCommand } from './src/command.js'
11
13
 
@@ -41,7 +43,7 @@ export function apply(ctx, config = {}) {
41
43
  if (config.reportDirectory !== undefined && !isAbsolute(config.reportDirectory)) {
42
44
  throw new Error(translate(fallbackLocale, 'error.reportDirectory'))
43
45
  }
44
- for (const key of ['reviewModel', 'simplifyModel', 'scrubModel']) {
46
+ for (const key of ['reviewModel', 'simplifyModel', 'scrubModel', 'auditModel']) {
45
47
  if (config[key] !== undefined && !String(config[key]).trim()) {
46
48
  throw new Error(translate(fallbackLocale, 'error.model'))
47
49
  }
@@ -49,6 +51,9 @@ export function apply(ctx, config = {}) {
49
51
  if (config.ledgerDirectory !== undefined && !String(config.ledgerDirectory).trim()) {
50
52
  throw new Error(translate(fallbackLocale, 'error.ledgerDirectory'))
51
53
  }
54
+ if (config.designDirectory !== undefined && !String(config.designDirectory).trim()) {
55
+ throw new Error(translate(fallbackLocale, 'error.designDirectory'))
56
+ }
52
57
 
53
58
  const journal = new Journal(config.reportDirectory ?? Journal.defaultDirectory())
54
59
  const personas = {
@@ -56,6 +61,8 @@ export function apply(ctx, config = {}) {
56
61
  review: loadPersona('review'),
57
62
  scrub: loadPersona('scrub'),
58
63
  caption: loadPersona('caption'),
64
+ audit: loadPersona('audit'),
65
+ design: loadPersona('design'),
59
66
  pua: loadPersona('pua'),
60
67
  }
61
68
 
@@ -77,6 +84,16 @@ export function apply(ctx, config = {}) {
77
84
  return cwd ? join(cwd, 'docs', 'caption') : join(ROOT, 'docs', 'caption')
78
85
  }
79
86
 
87
+ /** Where the design documents live; same rule as the caption ledger. */
88
+ const designDirectory = (cwd) => {
89
+ if (config.designDirectory) {
90
+ return isAbsolute(config.designDirectory)
91
+ ? config.designDirectory
92
+ : join(cwd ?? ROOT, config.designDirectory)
93
+ }
94
+ return cwd ? join(cwd, 'docs', 'design') : join(ROOT, 'docs', 'design')
95
+ }
96
+
80
97
  /** Everything a command needs from the plugin, in one place. */
81
98
  const host = {
82
99
  ctx,
@@ -86,6 +103,7 @@ export function apply(ctx, config = {}) {
86
103
  planMaxAgeMs: minutesToMs(config.planMaxAgeMinutes, 60, 'error.planMaxAge'),
87
104
  localeNow,
88
105
  ledgerDirectory,
106
+ designDirectory,
89
107
  translate: (locale, key) => translate(locale, key),
90
108
  deliver(agent, message) {
91
109
  try {
@@ -136,6 +154,21 @@ export function apply(ctx, config = {}) {
136
154
  structured: true,
137
155
  dryRunText: 'Report only. Change no files.',
138
156
  }, host),
157
+ new SessionCommand({
158
+ name: 'code-audit',
159
+ command: 'audit',
160
+ descriptionKey: 'cmd.audit',
161
+ hintKey: 'hint.audit',
162
+ persona: personas.audit,
163
+ model: config.auditModel,
164
+ // An audit has no apply path: the state table and its evidence are the
165
+ // whole deliverable, so the mode is fixed instead of being a flag.
166
+ forceDryRun: true,
167
+ defaultScope: 'project',
168
+ structured: true,
169
+ dryRunKey: 'mode.audit',
170
+ deliveryKey: 'audit.delivery',
171
+ }, host),
139
172
  new SessionCommand({
140
173
  name: 'code-caption',
141
174
  command: 'caption',
@@ -161,6 +194,30 @@ export function apply(ctx, config = {}) {
161
194
  receipt: (rawInput, t, installed, agent) => t(installed ? 'caption.reinstalled' : 'caption.installed')
162
195
  .replace('{dir}', ledgerDirectory(agent?.session?.header?.cwd)),
163
196
  }, host),
197
+ new SessionCommand({
198
+ name: 'code-design',
199
+ command: 'design',
200
+ kind: 'inject',
201
+ descriptionKey: 'cmd.design',
202
+ hintKey: 'hint.design',
203
+ persona: personas.design,
204
+ buildText: ({ rawInput, agent, locale, host, installed }) => {
205
+ const cwd = agent.session?.header?.cwd
206
+ const { tier, task } = resolveDesignInput(rawInput)
207
+ return buildDesignText({
208
+ tier,
209
+ task,
210
+ cwd,
211
+ directory: host.designDirectory(cwd),
212
+ personaDirectory: personas.design.directory,
213
+ persona: personas.design.text,
214
+ installed,
215
+ language: outputLanguage(locale),
216
+ })
217
+ },
218
+ receipt: (rawInput, t, installed, agent) => t(installed ? 'design.reinstalled' : 'design.installed')
219
+ .replace('{dir}', designDirectory(agent?.session?.header?.cwd)),
220
+ }, host),
164
221
  new SessionCommand({
165
222
  name: 'pua',
166
223
  kind: 'inject',
@@ -178,10 +235,13 @@ export function apply(ctx, config = {}) {
178
235
  kind: 'local',
179
236
  descriptionKey: 'cmd.status',
180
237
  run: async ({ agent, t, host: h }) => {
181
- const entry = h.running.get(agent.id)
238
+ // One identity for both the running slot and the journal record, so the
239
+ // status shown matches the key the run actually registered under.
240
+ const key = sessionKey(agent)
241
+ const entry = key ? h.running.get(key) : undefined
182
242
  if (entry) return { kind: 'success', text: `${t('status.running')}${entry.label}` }
183
243
 
184
- const record = await h.journal.read(agent.session?.id ?? agent.id).catch(() => undefined)
244
+ const record = key ? await h.journal.read(key).catch(() => undefined) : undefined
185
245
  if (!record) return { kind: 'success', text: t('status.none') }
186
246
  if (record.state === 'running') return { kind: 'success', text: t('status.interrupted') }
187
247
  if (record.state === 'submitted') {
@@ -195,7 +255,8 @@ export function apply(ctx, config = {}) {
195
255
  kind: 'local',
196
256
  descriptionKey: 'cmd.cancel',
197
257
  run: ({ agent, t, host: h }) => {
198
- const entry = h.running.get(agent.id)
258
+ const key = sessionKey(agent)
259
+ const entry = key ? h.running.get(key) : undefined
199
260
  if (!entry) return { kind: 'success', text: t('cancel.none') }
200
261
  entry.controller.abort()
201
262
  return { kind: 'success', text: t('cancel.done') }
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 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). Audit is read-only: it traces every capability from its real entry point to storage and labels it wired, half, fake, broken or missing — a capability nobody reached is unverified, never wired. 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. Design turns “what is this project missing” into scenario cards and a batched plan, writes the documents and stops for approval. 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."
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": "七条命令,空输入即可用。审查默认看未提交的改动(都提交了就看当前分支相对基线的改动),出报告并修复发现的问题,加 report 只出报告。精炼与隐私清理默认扫整个项目并直接改(加 report 只出报告)。审计只读:从真实入口追到存储,标出通/半/假/断/无五态,没有跑过入口的能力一律标未确认。caption 把难任务装进显式循环:一步一验、过程落成台账,执行中可以创建专家子 agent 分派任务。design 把「这个项目还缺什么」压成场景卡与批次方案,出文档等人批,止于方案。pua 给会话装上「失败换方法、完成要证据」的协议。加 sub 改用独立 agent。提示词按 skill 分层组织,附确定性测试与模型评测流程。"
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.1",
3
+ "version": "0.28.0",
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 and fix, behavior-preserving simplification, privacy scrubbing, a read-only capability audit, a caption loop with a ledger, scenario-driven product design, 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).",
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"
@@ -52,7 +55,6 @@
52
55
  "dsh": ">=0.2.2-rc.1 <0.3.0-0"
53
56
  },
54
57
  "dsh": {
55
- "manifestVersion": 1,
56
58
  "bundle": {
57
59
  "patch": "./cordis.patch.yml"
58
60
  }
package/src/command.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { resolveScope, scopeHasChanges, scopeInstruction, scopeLabel, selectScope, splitFlags } from './selection.js'
2
2
  import { failureMessage, reportMessage, userMessage, SOURCE_KIND } from './delivery.js'
3
3
  import { outputLanguage } from './i18n.js'
4
+ import { sessionKey } from './identity.js'
4
5
 
5
6
  /**
6
7
  * The receipt names where the task went and what it will do: the current
@@ -70,25 +71,25 @@ export class SessionCommand {
70
71
 
71
72
  // A protocol is long; injecting it twice in one session doubles the context
72
73
  // and gives the agent two copies to disagree with. Only the task is new.
73
- const sessionId = agent.session?.id ?? agent.id
74
- const previous = await host.journal.read(sessionId).catch(() => undefined)
74
+ const sessionId = sessionKey(agent)
75
+ const previous = sessionId ? await host.journal.read(sessionId).catch(() => undefined) : undefined
75
76
  const installed = previous?.command === spec.command && previous?.state === 'installed'
76
77
 
77
- await agent.steer({
78
- content: [{ type: 'text', text: spec.buildText({ rawInput, agent, locale, host, installed }) }],
79
- // Every command delivers the same way: the host sees a plugin request, not
80
- // something the person typed, so the UI folds it into one card instead of
81
- // pasting the protocol into the conversation.
82
- source: { kind: SOURCE_KIND },
83
- })
84
-
85
- await host.journal
86
- .write(sessionId, {
87
- state: 'installed',
88
- command: spec.command,
89
- at: new Date().toISOString(),
90
- })
91
- .catch(() => undefined)
78
+ // `steer` takes a complete UserMessage, not a partial `{ content, source }`:
79
+ // the host writes the message into a `user/message` session event as-is, and
80
+ // a message without its own `id` and `role` fails session-log validation on
81
+ // the next load. Build it the same way every other delivery does.
82
+ await agent.steer(userMessage(spec.buildText({ rawInput, agent, locale, host, installed })))
83
+
84
+ if (sessionId) {
85
+ await host.journal
86
+ .write(sessionId, {
87
+ state: 'installed',
88
+ command: spec.command,
89
+ at: new Date().toISOString(),
90
+ })
91
+ .catch(() => undefined)
92
+ }
92
93
 
93
94
  return {
94
95
  kind: 'success',
@@ -111,7 +112,7 @@ export class SessionCommand {
111
112
  const { host } = this
112
113
  const controller = new AbortController()
113
114
  const combined = AbortSignal.any([signal, controller.signal])
114
- const sessionId = agent.session?.id ?? agent.id
115
+ const sessionId = sessionKey(agent)
115
116
  const language = outputLanguage(locale)
116
117
  const chinese = String(locale).startsWith('zh')
117
118
 
@@ -134,7 +135,12 @@ export class SessionCommand {
134
135
  /** Run the isolated agent and deliver its report as a message. */
135
136
  startIsolated(agent, rawInput, signal, locale, t, report) {
136
137
  const { host, spec } = this
137
- const key = agent.id
138
+ // The single-flight slot and the journal record are keyed by the same
139
+ // identity: one key per session, so cancellation and status find the run
140
+ // that registered it. Without one there is nothing to key on, and inventing
141
+ // a shared key would let every unidentified session crowd into one slot.
142
+ const key = sessionKey(agent)
143
+ if (!key) return { kind: 'error', text: t('error.noIdentity') }
138
144
  const stale = host.running.get(key)
139
145
  // A run can hang on something outside its own control — an approval nobody
140
146
  // answers, a child that never reports. Past the limit the slot is released
@@ -150,7 +156,9 @@ export class SessionCommand {
150
156
  const controller = new AbortController()
151
157
  const combined = AbortSignal.any([signal, controller.signal])
152
158
  host.running.set(key, { controller, label: host.translate(locale, spec.descriptionKey), startedAt: Date.now() })
153
- const sessionId = agent.session?.id ?? agent.id
159
+ // The journal record is keyed by the same identity as the slot: one key per
160
+ // session, so a status read and a cancellation both find what the run wrote.
161
+ const sessionId = key
154
162
  const language = outputLanguage(locale)
155
163
  const chinese = String(locale).startsWith('zh')
156
164
  // The receipt is resolved before the child starts, so it can name the scope
@@ -223,20 +231,27 @@ export class SessionCommand {
223
231
  return { scope, mode, prompt, receipt }
224
232
  }
225
233
 
234
+ /**
235
+ * Write one journal record. A run with no usable identity has no record to
236
+ * write — the task still runs, but nothing to key it to is recorded.
237
+ */
238
+ async record(host, sessionId, record) {
239
+ if (!sessionId) return
240
+ await host.journal.write(sessionId, record).catch(() => undefined)
241
+ }
242
+
226
243
  /** Resolve the scope and assemble the task text (shared by both paths). */
227
244
  async prepare(agent, rawInput, combined, locale, t, sessionId, report) {
228
245
  const { host, spec } = this
229
246
  const { scope, mode, prompt } = await this.resolveTask(agent, rawInput, combined, locale, t, sessionId, report, true)
230
247
 
231
- await host.journal
232
- .write(sessionId, {
233
- state: 'submitted',
234
- command: spec.command,
235
- scope: scopeLabel(scope),
236
- mode,
237
- at: new Date().toISOString(),
238
- })
239
- .catch(() => undefined)
248
+ await this.record(host, sessionId, {
249
+ state: 'submitted',
250
+ command: spec.command,
251
+ scope: scopeLabel(scope),
252
+ mode,
253
+ at: new Date().toISOString(),
254
+ })
240
255
 
241
256
  return prompt
242
257
  }
@@ -245,15 +260,13 @@ export class SessionCommand {
245
260
  async execute(agent, { scope, mode, prompt }, combined, locale, t, sessionId) {
246
261
  const { host, spec } = this
247
262
 
248
- await host.journal
249
- .write(sessionId, {
250
- state: 'running',
251
- command: spec.command,
252
- scope: scopeLabel(scope),
253
- mode,
254
- at: new Date().toISOString(),
255
- })
256
- .catch(() => undefined)
263
+ await this.record(host, sessionId, {
264
+ state: 'running',
265
+ command: spec.command,
266
+ scope: scopeLabel(scope),
267
+ mode,
268
+ at: new Date().toISOString(),
269
+ })
257
270
 
258
271
  const raw = await host.runIsolatedAgent(agent, {
259
272
  persona: `${spec.persona.text}\n\n${outputLanguage(locale)}`,
@@ -267,16 +280,14 @@ export class SessionCommand {
267
280
  const body = spec.structured ? host.renderReport(host.parseReport(raw), t) : raw
268
281
  const text = [`> ${scopeLabel(scope)} · ${mode}`, '', body].join('\n')
269
282
 
270
- await host.journal
271
- .write(sessionId, {
272
- state: 'finished',
273
- command: spec.command,
274
- scope: scopeLabel(scope),
275
- mode,
276
- result: text,
277
- at: new Date().toISOString(),
278
- })
279
- .catch(() => undefined)
283
+ await this.record(host, sessionId, {
284
+ state: 'finished',
285
+ command: spec.command,
286
+ scope: scopeLabel(scope),
287
+ mode,
288
+ result: text,
289
+ at: new Date().toISOString(),
290
+ })
280
291
 
281
292
  return text
282
293
  }
@@ -284,15 +295,25 @@ export class SessionCommand {
284
295
  /** The task text handed to either the current agent or the child. */
285
296
  async buildPrompt({ scope, mode, cwd, locale, signal, inline, plan }) {
286
297
  const { spec } = this
298
+ const t = (key) => this.host.translate(locale, key)
287
299
  const chinese = String(locale).startsWith('zh')
300
+ // A command whose dry run is a report rather than a plan (the audit) names
301
+ // its own instruction by key, so the wording is translated with the rest of
302
+ // the chrome instead of being frozen in one language here.
303
+ const dryRunLine = spec.dryRunKey
304
+ ? t(spec.dryRunKey)
305
+ : chinese ? '只出计划,不要改任何文件。' : (spec.dryRunText ?? 'Report only. Change no files.')
288
306
  const modeLine = mode === 'dry-run'
289
- ? (chinese ? '只出计划,不要改任何文件。' : (spec.dryRunText ?? 'Report only. Change no files.'))
307
+ ? dryRunLine
290
308
  : (chinese
291
309
  ? '按计划修改,并验证行为不变;验证不通过就回退那一处改动并如实报告。'
292
310
  : 'Apply the changes, then verify that behavior is unchanged. If verification fails, revert that change and report it.')
293
- const delivery = chinese
294
- ? '你的最终回复会原样发给用户,作为这次任务的结果:写清改了什么、跑了哪条命令、输出是什么、哪些没有验证。'
295
- : 'Your final reply is delivered to the user as the result: say what changed, which command ran, what it printed, and what stayed unverified.'
311
+ const deliveryKey = spec.deliveryKey
312
+ const delivery = deliveryKey
313
+ ? t(deliveryKey)
314
+ : chinese
315
+ ? '你的最终回复会原样发给用户,作为这次任务的结果:写清改了什么、跑了哪条命令、输出是什么、哪些没有验证。'
316
+ : 'Your final reply is delivered to the user as the result: say what changed, which command ran, what it printed, and what stayed unverified.'
296
317
  const personaLine = chinese
297
318
  ? '先读参考目录下的 AGENT.md,按它的流程与判定标准执行。'
298
319
  : 'Read AGENT.md in the reference directory first and follow its process and bar.'