@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.
- package/CHANGELOG.md +119 -0
- package/README.md +71 -10
- package/agents/audit/AGENT.md +171 -0
- package/agents/audit/examples/fake-capability.md +54 -0
- package/agents/audit/examples/wired-clean.md +66 -0
- package/agents/audit/references/audit-passes.md +118 -0
- package/agents/audit/references/capability-states.md +96 -0
- package/agents/audit/references/evidence.md +86 -0
- package/agents/audit/references/finding-the-chain.md +80 -0
- package/agents/audit/references/output.md +66 -0
- package/agents/caption/AGENT.md +12 -0
- package/agents/caption/references/evidence.md +46 -0
- package/agents/design/AGENT.md +214 -0
- package/agents/design/examples/one-page.md +55 -0
- package/agents/design/examples/overkill.md +56 -0
- package/agents/design/references/base-maps.md +110 -0
- package/agents/design/references/deliverables.md +71 -0
- package/agents/design/references/model-and-ports.md +73 -0
- package/agents/design/references/plan-and-batches.md +92 -0
- package/agents/design/references/scenario-cards.md +133 -0
- package/agents/design/references/self-check.md +73 -0
- package/agents/pua/AGENT.md +3 -0
- package/agents/review/AGENT.md +16 -0
- package/agents/scrub/AGENT.md +5 -1
- package/index.js +65 -4
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +5 -3
- package/src/command.js +73 -52
- package/src/design.js +70 -0
- package/src/i18n.js +50 -0
- package/src/identity.js +23 -0
- package/src/journal.js +10 -0
- package/src/report.js +112 -3
- package/src/runtime.js +21 -9
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
|
+
}
|
package/src/i18n.js
CHANGED
|
@@ -28,6 +28,15 @@ const MESSAGES = {
|
|
|
28
28
|
'hint.caption': '留空即继续当前任务;或写下任务与验收判据',
|
|
29
29
|
'caption.installed': '已装入 caption 循环:台账写到 {dir},每一步都要有命令和它的结果。',
|
|
30
30
|
'caption.reinstalled': 'caption 循环已在本次会话里,只补了任务:台账 {dir},继续按循环走。',
|
|
31
|
+
'cmd.audit': '审计现有能力:从真实入口追到存储,标出通/半/假/断/无,只读',
|
|
32
|
+
'hint.audit': '留空即审整个项目;读取量大,推荐加 sub 用子 agent',
|
|
33
|
+
'mode.audit': '只出五态表与证据,不改任何文件;没有走通真实入口的能力标「未确认」,不要标「通」。',
|
|
34
|
+
'audit.delivery': '你的最终回复会原样作为审计结果发回:一条能力一行,写清状态、证据(文件:行)和链路断在哪一步,以及哪些没有验到。',
|
|
35
|
+
'cmd.design': '场景驱动的需求分析:四张底图、场景卡、批次方案,出文档等你批',
|
|
36
|
+
'hint.design': '留空即按半天深度设计;quick 只出一页结论,full 出完整方案与附录',
|
|
37
|
+
'design.installed': '已装入场景驱动设计协议:设计文档写到 {dir}。方案出完等你批,不会自己动手。',
|
|
38
|
+
'design.reinstalled': '设计协议已在本次会话里:设计文档 {dir},继续按协议推进。',
|
|
39
|
+
'error.designDirectory': 'designDirectory 不能为空。',
|
|
31
40
|
'error.noSteer': '当前宿主不支持向会话注入输入(agent.steer 不可用)。',
|
|
32
41
|
'error.noFollowup': '当前宿主不支持向会话投递任务(agent.followup 不可用)。',
|
|
33
42
|
'cmd.queued': '已交给当前会话,范围:{scope};完成后结果会作为一条消息发回。',
|
|
@@ -44,11 +53,13 @@ const MESSAGES = {
|
|
|
44
53
|
'hint.scrub': '留空即整个项目;或 --files a.js,.env / 自定义说明;加 sub 用子 agent,加 report 只出报告',
|
|
45
54
|
'hint.review': '留空即审未提交的改动(都提交了就审分支相对基线);或 --files / --branch <对比分支> / --commit <sha>;默认出报告并修复,加 report 只出报告,加 sub 用子 agent',
|
|
46
55
|
'error.noCwd': '当前会话没有工作目录。',
|
|
56
|
+
'error.noIdentity': '当前会话没有可用的会话标识,无法记录任务状态或做单飞保护。',
|
|
47
57
|
'error.noProvider': '当前宿主缺少独立上下文的原生 spawn provider,无法运行独立 agent。',
|
|
48
58
|
'error.noActivation': '当前宿主缺少原生子 agent 启动接口,请升级 DeepSeek Harness。',
|
|
49
59
|
'error.noGit': '不是 Git 仓库,或 git 不可用:',
|
|
50
60
|
'error.aborted': '操作已取消。',
|
|
51
61
|
'error.noResult': '子 agent 没有返回报告。',
|
|
62
|
+
'error.noPersona': '子 agent 没有收到 persona,运行结果不可信。',
|
|
52
63
|
'error.busy': '当前会话已有代码工具箱任务在运行,请等待或先取消。',
|
|
53
64
|
'error.noScope': '没有选中有效范围。',
|
|
54
65
|
'error.emptyScope': '没有可审查的改动:当前分支与基线一致,工作区也是干净的。试试 --branch <别的分支>、--commit <sha> 或 --files <路径>。',
|
|
@@ -67,6 +78,20 @@ const MESSAGES = {
|
|
|
67
78
|
'cancel.done': '已请求取消。',
|
|
68
79
|
'report.verdict': '结论:',
|
|
69
80
|
'report.noFindings': '没有发现需要处理的问题。',
|
|
81
|
+
'report.capabilities': '能力五态',
|
|
82
|
+
'report.capability': '能力',
|
|
83
|
+
'report.state': '状态',
|
|
84
|
+
'report.evidence': '证据',
|
|
85
|
+
'report.walk': '路径:',
|
|
86
|
+
'report.expected': '期望:',
|
|
87
|
+
'report.actual': '实际:',
|
|
88
|
+
'report.impact': '影响:',
|
|
89
|
+
'report.batch': '建议批次:',
|
|
90
|
+
'state.wired': '通',
|
|
91
|
+
'state.half': '半',
|
|
92
|
+
'state.fake': '假',
|
|
93
|
+
'state.broken': '断',
|
|
94
|
+
'state.missing': '无',
|
|
70
95
|
'report.limitation': '未覆盖:',
|
|
71
96
|
'report.fixed': '已修复',
|
|
72
97
|
'report.verifiedBy': '验证:',
|
|
@@ -81,6 +106,15 @@ const MESSAGES = {
|
|
|
81
106
|
'hint.caption': 'Leave empty to continue the current task; or state the task and its acceptance criteria',
|
|
82
107
|
'caption.installed': 'Caption loop installed: keep the ledger in {dir}, with a command and its result for every step.',
|
|
83
108
|
'caption.reinstalled': 'The caption loop is already installed in this session; only the task was added. Ledger: {dir}.',
|
|
109
|
+
'cmd.audit': 'Audit what actually exists: trace every capability to storage and mark it wired/half/fake/broken/missing; read-only',
|
|
110
|
+
'hint.audit': 'Leave empty to audit the whole project; it reads a lot, so add sub for an isolated agent',
|
|
111
|
+
'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.',
|
|
112
|
+
'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.',
|
|
113
|
+
'cmd.design': 'Scenario-driven product design: four base maps, scenario cards, a batched plan; writes docs and stops for approval',
|
|
114
|
+
'hint.design': 'Leave empty for a half-day design; quick gives one page of conclusions, full gives the whole plan and appendix',
|
|
115
|
+
'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.',
|
|
116
|
+
'design.reinstalled': 'The design protocol is already installed in this session; the documents go under {dir}. Continue under it.',
|
|
117
|
+
'error.designDirectory': 'designDirectory cannot be empty.',
|
|
84
118
|
'error.noSteer': 'This host cannot inject input into the session (agent.steer is unavailable).',
|
|
85
119
|
'error.noFollowup': 'This host cannot queue a task into the session (agent.followup is unavailable).',
|
|
86
120
|
'cmd.queued': 'Handed to this session; scope: {scope}. The result arrives as a message when the run finishes.',
|
|
@@ -97,11 +131,13 @@ const MESSAGES = {
|
|
|
97
131
|
'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',
|
|
98
132
|
'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',
|
|
99
133
|
'error.noCwd': 'This session has no working directory.',
|
|
134
|
+
'error.noIdentity': 'This session has no usable session id, so task state cannot be recorded or guarded.',
|
|
100
135
|
'error.noProvider': 'This host has no independent-context native spawn provider, so no isolated agent can run.',
|
|
101
136
|
'error.noActivation': 'This host has no native subagent activation API; upgrade DeepSeek Harness.',
|
|
102
137
|
'error.noGit': 'Not a Git repository, or git is unavailable: ',
|
|
103
138
|
'error.aborted': 'Cancelled.',
|
|
104
139
|
'error.noResult': 'The subagent returned no report.',
|
|
140
|
+
'error.noPersona': 'The subagent never received its persona, so its result cannot be trusted.',
|
|
105
141
|
'error.busy': 'A code-toolkit task is already running in this session; wait or cancel it first.',
|
|
106
142
|
'error.noScope': 'No valid scope was selected.',
|
|
107
143
|
'error.emptyScope': 'Nothing to review: the branch matches its base and the working tree is clean. Try --branch <another branch>, --commit <sha>, or --files <path>.',
|
|
@@ -120,6 +156,20 @@ const MESSAGES = {
|
|
|
120
156
|
'cancel.done': 'Cancellation requested.',
|
|
121
157
|
'report.verdict': 'Verdict: ',
|
|
122
158
|
'report.noFindings': 'No findings worth acting on.',
|
|
159
|
+
'report.capabilities': 'Capability states',
|
|
160
|
+
'report.capability': 'Capability',
|
|
161
|
+
'report.state': 'State',
|
|
162
|
+
'report.evidence': 'Evidence',
|
|
163
|
+
'report.walk': 'Path: ',
|
|
164
|
+
'report.expected': 'Expected: ',
|
|
165
|
+
'report.actual': 'Actual: ',
|
|
166
|
+
'report.impact': 'Impact: ',
|
|
167
|
+
'report.batch': 'Suggested batch: ',
|
|
168
|
+
'state.wired': 'wired',
|
|
169
|
+
'state.half': 'half',
|
|
170
|
+
'state.fake': 'fake',
|
|
171
|
+
'state.broken': 'broken',
|
|
172
|
+
'state.missing': 'missing',
|
|
123
173
|
'report.limitation': 'Not checked: ',
|
|
124
174
|
'report.fixed': 'Fixed',
|
|
125
175
|
'report.verifiedBy': 'Verified by: ',
|
package/src/identity.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one identifier a command's state is keyed by.
|
|
3
|
+
*
|
|
4
|
+
* Every piece of per-session state — the journal record, the single-flight slot,
|
|
5
|
+
* the cancellation handle — has to be found again from the same place, so there
|
|
6
|
+
* is exactly one rule for which id that is. The shell used to resolve it four
|
|
7
|
+
* times as `agent.session?.id ?? agent.id`, and the single-flight slot took
|
|
8
|
+
* `agent.id` while the journal took the session id: a session whose two ids
|
|
9
|
+
* differ would have split one run's state across two keys, so `/code-cancel`
|
|
10
|
+
* and `/code-status` would look in the place the run never wrote to.
|
|
11
|
+
*
|
|
12
|
+
* The session id wins because that is the identity the journal already names
|
|
13
|
+
* its records after; `agent.id` is the fallback for a host that gives an agent
|
|
14
|
+
* without a session. When neither is a usable string the state cannot be keyed
|
|
15
|
+
* at all, and the caller decides what that means rather than inventing a key.
|
|
16
|
+
*/
|
|
17
|
+
export function sessionKey(agent) {
|
|
18
|
+
const candidates = [agent?.session?.id, agent?.id]
|
|
19
|
+
for (const candidate of candidates) {
|
|
20
|
+
if (typeof candidate === 'string' && candidate.trim()) return candidate
|
|
21
|
+
}
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
package/src/journal.js
CHANGED
|
@@ -20,7 +20,17 @@ export class Journal {
|
|
|
20
20
|
return join(home, 'code-toolkit')
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The file one session's record lives in, named after a hash of its id.
|
|
25
|
+
*
|
|
26
|
+
* A missing or non-string id throws rather than being coerced: `createHash`
|
|
27
|
+
* rejects a non-string argument, and silently hashing `undefined` would put
|
|
28
|
+
* every unidentified session into one shared file.
|
|
29
|
+
*/
|
|
23
30
|
path(sessionId) {
|
|
31
|
+
if (typeof sessionId !== 'string' || !sessionId.trim()) {
|
|
32
|
+
throw new Error('Journal.path needs a session id')
|
|
33
|
+
}
|
|
24
34
|
return join(this.directory, `${createHash('sha256').update(sessionId).digest('hex')}.json`)
|
|
25
35
|
}
|
|
26
36
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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') : '',
|
package/src/runtime.js
CHANGED
|
@@ -23,6 +23,13 @@ const DELEGATE_TOOLS = [
|
|
|
23
23
|
* Requires the native `spawn` provider, whose `inheritsParentContext` is false:
|
|
24
24
|
* the child must read the code itself instead of inheriting this conversation.
|
|
25
25
|
* Without that, a review only sees what the main agent already believes.
|
|
26
|
+
*
|
|
27
|
+
* The persona is attached from an `agent/created` listener keyed on the child id
|
|
28
|
+
* the plugin hands the host. The listener stays up until the run is over, because
|
|
29
|
+
* the child may be created after `startActivation` resolves; if it were removed
|
|
30
|
+
* the moment the activation settled, the persona would silently never attach.
|
|
31
|
+
* When the run finishes without the listener ever firing, the child ran without
|
|
32
|
+
* a persona — which is exactly the silent failure this function refuses to allow.
|
|
26
33
|
*/
|
|
27
34
|
export async function runIsolatedAgent(ctx, parent, options) {
|
|
28
35
|
const { persona, prompt, label, signal, model, t } = options
|
|
@@ -38,9 +45,10 @@ export async function runIsolatedAgent(ctx, parent, options) {
|
|
|
38
45
|
const childId = randomUUID()
|
|
39
46
|
const deny = DELEGATE_TOOLS.filter((name) => ctx.tools.get(name, parent) !== undefined)
|
|
40
47
|
|
|
41
|
-
let
|
|
48
|
+
let injected = false
|
|
42
49
|
const stopWatching = ctx.on('agent/created', ({ agent }) => {
|
|
43
50
|
if (agent.id !== childId) return
|
|
51
|
+
injected = true
|
|
44
52
|
agent.ctx.systemPrompt.section({
|
|
45
53
|
name: PERSONA_SECTION,
|
|
46
54
|
order: agent.ctx.systemPrompt.getSectionOrder(PERSONA_SECTION),
|
|
@@ -49,6 +57,7 @@ export async function runIsolatedAgent(ctx, parent, options) {
|
|
|
49
57
|
if (deny.length) agent.ctx.tools.restrict({ deny })
|
|
50
58
|
})
|
|
51
59
|
|
|
60
|
+
let activation
|
|
52
61
|
try {
|
|
53
62
|
// 0.2.2-rc.1 takes a nested `request`; rc.2+ takes a flat spec and exposes
|
|
54
63
|
// `rootOf`. Keep both so the declared engine range stays honest.
|
|
@@ -66,11 +75,7 @@ export async function runIsolatedAgent(ctx, parent, options) {
|
|
|
66
75
|
delivery: 'caller',
|
|
67
76
|
...(flat ? request : { request }),
|
|
68
77
|
})
|
|
69
|
-
} finally {
|
|
70
|
-
stopWatching()
|
|
71
|
-
}
|
|
72
78
|
|
|
73
|
-
try {
|
|
74
79
|
const result = await activation.result
|
|
75
80
|
if (signal.aborted) throw Object.assign(new Error('aborted'), { name: 'AbortError' })
|
|
76
81
|
if (result.stopReason !== 'completed') {
|
|
@@ -83,12 +88,19 @@ export async function runIsolatedAgent(ctx, parent, options) {
|
|
|
83
88
|
.join('')
|
|
84
89
|
.trim()
|
|
85
90
|
if (!text) throw new Error(t('error.noResult'))
|
|
91
|
+
// The child may finish before its own creation event reaches this listener.
|
|
92
|
+
// A run that never saw the child is one that ran without the persona, which
|
|
93
|
+
// is a silent failure worth failing loudly instead of reporting as a report.
|
|
94
|
+
if (!injected) throw new Error(t('error.noPersona'))
|
|
86
95
|
return text
|
|
87
96
|
} finally {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
stopWatching()
|
|
98
|
+
if (activation) {
|
|
99
|
+
try {
|
|
100
|
+
await activation.dispose()
|
|
101
|
+
} catch {
|
|
102
|
+
/* the session may already be gone */
|
|
103
|
+
}
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
106
|
}
|