peaks-loop 4.1.12 → 4.1.14
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +118 -0
- package/dist/cli/commands/_register.js +2 -0
- package/dist/cli/commands/batch-commands.d.ts +6 -0
- package/dist/cli/commands/batch-commands.js +70 -0
- package/dist/cli/commands/batch-diagnose-command.d.ts +10 -0
- package/dist/cli/commands/batch-diagnose-command.js +196 -0
- package/dist/cli/commands/batch-diagnose-envelope.d.ts +25 -0
- package/dist/cli/commands/batch-diagnose-envelope.js +60 -0
- package/dist/cli/commands/batch-diagnose-record.d.ts +21 -0
- package/dist/cli/commands/batch-diagnose-record.js +51 -0
- package/dist/cli/commands/batch-item-input.d.ts +59 -0
- package/dist/cli/commands/batch-item-input.js +113 -0
- package/dist/cli/commands/batch-report-command.d.ts +22 -0
- package/dist/cli/commands/batch-report-command.js +199 -0
- package/dist/cli/commands/code-gate-command.d.ts +18 -0
- package/dist/cli/commands/code-gate-command.js +95 -32
- package/dist/cli/commands/core/skill-context-verdict.d.ts +16 -1
- package/dist/cli/commands/core/skill-context-verdict.js +38 -8
- package/dist/cli/commands/lint-commands.js +8 -0
- package/dist/cli/commands/lint-rules-command.d.ts +14 -0
- package/dist/cli/commands/lint-rules-command.js +44 -0
- package/dist/services/batch/batch-active-batch.d.ts +55 -0
- package/dist/services/batch/batch-active-batch.js +127 -0
- package/dist/services/batch/batch-context-reminder.d.ts +85 -0
- package/dist/services/batch/batch-context-reminder.js +201 -0
- package/dist/services/batch/batch-diagnosis-finding.d.ts +25 -0
- package/dist/services/batch/batch-diagnosis-finding.js +227 -0
- package/dist/services/batch/batch-diagnosis-report-store.d.ts +49 -0
- package/dist/services/batch/batch-diagnosis-report-store.js +133 -0
- package/dist/services/batch/batch-diagnosis-summary.d.ts +31 -0
- package/dist/services/batch/batch-diagnosis-summary.js +129 -0
- package/dist/services/batch/batch-diagnosis.d.ts +36 -0
- package/dist/services/batch/batch-diagnosis.js +107 -0
- package/dist/services/batch/batch-entry.d.ts +22 -0
- package/dist/services/batch/batch-entry.js +42 -0
- package/dist/services/batch/batch-fix-agent.d.ts +39 -0
- package/dist/services/batch/batch-fix-agent.js +126 -0
- package/dist/services/batch/batch-fix-types.d.ts +85 -0
- package/dist/services/batch/batch-fix-types.js +11 -0
- package/dist/services/batch/batch-fix.d.ts +15 -0
- package/dist/services/batch/batch-fix.js +229 -0
- package/dist/services/batch/batch-phase-advance.d.ts +45 -0
- package/dist/services/batch/batch-phase-advance.js +105 -0
- package/dist/services/batch/batch-progress-store.d.ts +52 -0
- package/dist/services/batch/batch-progress-store.js +219 -0
- package/dist/services/batch/batch-progress-types.d.ts +79 -0
- package/dist/services/batch/batch-progress-types.js +10 -0
- package/dist/services/batch/batch-recovery.d.ts +5 -0
- package/dist/services/batch/batch-recovery.js +24 -0
- package/dist/services/batch/batch-verify.d.ts +93 -0
- package/dist/services/batch/batch-verify.js +216 -0
- package/dist/services/code/auto-compact-decision.d.ts +17 -0
- package/dist/services/code/auto-compact-decision.js +6 -0
- package/dist/services/code/auto-compact-orchestrator.js +6 -0
- package/dist/services/code/batch-compaction-point.d.ts +45 -0
- package/dist/services/code/batch-compaction-point.js +99 -0
- package/dist/services/context/context-schema.d.ts +1 -1
- package/dist/services/hooks/pre-tool-code-gate.d.ts +33 -1
- package/dist/services/hooks/pre-tool-code-gate.js +67 -6
- package/dist/services/lint/curated-rule-reader.d.ts +37 -0
- package/dist/services/lint/curated-rule-reader.js +179 -0
- package/dist/services/lint/project-lint-declarations.d.ts +27 -0
- package/dist/services/lint/project-lint-declarations.js +217 -0
- package/dist/services/lint/project-lint-tool-detection.d.ts +14 -0
- package/dist/services/lint/project-lint-tool-detection.js +208 -0
- package/dist/services/lint/project-lint-tool-rules.d.ts +19 -0
- package/dist/services/lint/project-lint-tool-rules.js +199 -0
- package/dist/services/lint/rule-pre-read-types.d.ts +66 -0
- package/dist/services/lint/rule-pre-read-types.js +22 -0
- package/dist/services/lint/rule-pre-read.d.ts +20 -0
- package/dist/services/lint/rule-pre-read.js +145 -0
- package/dist/services/skill/skill-search-service.d.ts +3 -3
- package/package.json +5 -5
- package/skills/peaks-code/references/micro-cycle.md +13 -1
- package/skills/peaks-race-code/SKILL.md +40 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// src/services/batch/batch-diagnosis.ts
|
|
2
|
+
//
|
|
3
|
+
// The batch's diagnosis phase: the read-only prompt one diagnostician
|
|
4
|
+
// receives, and the topology the batch's MEASURED file sets produce.
|
|
5
|
+
//
|
|
6
|
+
// WHY THE FILE SETS ARE NORMALIZED HERE, NOT IN THE PLANNER. The wave
|
|
7
|
+
// planner (`planFileOverlapWaves`) matches a file by EXACT STRING EQUALITY —
|
|
8
|
+
// it dedupes and sorts, and nothing else. On a Windows host a
|
|
9
|
+
// backslash-spelled path and the same path spelled with forward slashes are
|
|
10
|
+
// two different strings to it, so two items that touch the SAME file look
|
|
11
|
+
// disjoint, land in the same wave, and two agents edit one file at once.
|
|
12
|
+
// `normalizeFileSet` is the one place that decides what a file set is, so
|
|
13
|
+
// the normalization happens HERE — on the way in — and the planner keeps
|
|
14
|
+
// its one job.
|
|
15
|
+
//
|
|
16
|
+
// WHY THE DIAGNOSIS IS READ-ONLY, MECHANICALLY. The file set a
|
|
17
|
+
// diagnostician reports is the only input the topology step has. A
|
|
18
|
+
// diagnostician that also wrote files would be reporting a guess about
|
|
19
|
+
// what it changed, and the whole measurement premise of the batch would
|
|
20
|
+
// be gone. So the prohibition is in the prompt the agent receives, not
|
|
21
|
+
// only in this file's comment.
|
|
22
|
+
//
|
|
23
|
+
// WHY THE PROMPT REUSES THE SHARED DISPATCH PREFIX. Every dispatched
|
|
24
|
+
// sub-agent gets the same governance prefix — the test-tool rule, the
|
|
25
|
+
// worktree-governance refusal, the lifecycle rules, the report cap, the
|
|
26
|
+
// fact-forcing gate. A diagnostician is a dispatched sub-agent like any
|
|
27
|
+
// other, so it gets that prefix from the one composer that owns it
|
|
28
|
+
// (`buildDispatchSystemPrompt`) rather than from a second hand-rolled copy
|
|
29
|
+
// that could drift away from it.
|
|
30
|
+
import { buildDispatchSystemPrompt } from '../context/build-dispatch-system-prompt.js';
|
|
31
|
+
import { planFileOverlapWaves } from '../dispatch/file-overlap-wave-planner.js';
|
|
32
|
+
import { normalizeFileSet } from './batch-progress-store.js';
|
|
33
|
+
/**
|
|
34
|
+
* The memory block a pure prompt builder carries.
|
|
35
|
+
*
|
|
36
|
+
* `buildDispatchSystemPrompt` takes a pre-fetched memory block, and the
|
|
37
|
+
* memory preflight is asynchronous I/O that belongs to the dispatch site,
|
|
38
|
+
* not to a pure prompt builder. The unavailable shape is the honest one
|
|
39
|
+
* here: this prompt carries no project memory block, and the composer
|
|
40
|
+
* renders its own "no block" form.
|
|
41
|
+
*/
|
|
42
|
+
const NO_MEMORY_BLOCK = { available: false };
|
|
43
|
+
/**
|
|
44
|
+
* Plan the batch's waves from the file sets its items MEASURED.
|
|
45
|
+
*
|
|
46
|
+
* @param items - The batch's items, each carrying the file set its
|
|
47
|
+
* diagnosis reported.
|
|
48
|
+
* @returns The wave plan: items with disjoint file sets share a wave, and
|
|
49
|
+
* an item that collides with an earlier one is deferred behind it with
|
|
50
|
+
* the colliding file named.
|
|
51
|
+
*/
|
|
52
|
+
export function planBatchTopology(items) {
|
|
53
|
+
const descriptors = items.map((item) => ({
|
|
54
|
+
id: item.id,
|
|
55
|
+
files: normalizeFileSet(item.files)
|
|
56
|
+
}));
|
|
57
|
+
return planFileOverlapWaves(descriptors);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the read-only prompt one diagnostician receives.
|
|
61
|
+
*
|
|
62
|
+
* The prompt asks for exactly the four outputs the batch pipeline
|
|
63
|
+
* consumes — the root cause, the files it expects to change, the risk
|
|
64
|
+
* surface it hit, and a fix sketch — and forbids the three write tools, so
|
|
65
|
+
* the file set it reports is a MEASUREMENT rather than a guess.
|
|
66
|
+
*
|
|
67
|
+
* @param item - The one item to diagnose.
|
|
68
|
+
* @returns The composed prompt, ready to be a sub-agent's dispatch body.
|
|
69
|
+
*/
|
|
70
|
+
export function buildDiagnosisPrompt(item) {
|
|
71
|
+
const taskBody = [
|
|
72
|
+
`## Batch diagnosis — ${item.label}`,
|
|
73
|
+
'',
|
|
74
|
+
`- Item id: \`${item.id}\``,
|
|
75
|
+
`- Reported symptom: ${item.symptom}`,
|
|
76
|
+
'',
|
|
77
|
+
'You are diagnosing ONE item of a batch. Other agents are diagnosing the',
|
|
78
|
+
'others in parallel, on the same tree.',
|
|
79
|
+
'',
|
|
80
|
+
'This phase is read-only (只读). You MUST NOT use Edit, Write, or MultiEdit,',
|
|
81
|
+
'and you MUST NOT run any command that changes a file. Read, grep, list and',
|
|
82
|
+
'read-only commands only.',
|
|
83
|
+
'',
|
|
84
|
+
'Report exactly four things, in this order:',
|
|
85
|
+
'',
|
|
86
|
+
'1. **Root cause (根因)** — why the reported symptom happens, in a sentence',
|
|
87
|
+
' or two.',
|
|
88
|
+
'2. **Expected files (预计文件集)** — the repo-relative paths a fix would',
|
|
89
|
+
' have to touch, one per line, POSIX separators. This list is the only',
|
|
90
|
+
" input the batch's scheduling step has, so a path you are unsure about",
|
|
91
|
+
' belongs IN the list: an item scheduled wrongly is the defect this',
|
|
92
|
+
' phase exists to prevent.',
|
|
93
|
+
'3. **Risk surface hit (风险面命中)** — the number of the risk surface (1-7)',
|
|
94
|
+
" from the fast-lane norm's list (`peaks-code/references/fast-lane-norm.md`",
|
|
95
|
+
' §2) that this item touches, or `none`. If you cannot read that list, say',
|
|
96
|
+
' `unknown` rather than guessing a number.',
|
|
97
|
+
'4. **Fix sketch (修复草图)** — what the fix would look like, in a few',
|
|
98
|
+
' sentences. The sketch only; do not apply it.',
|
|
99
|
+
'',
|
|
100
|
+
'Do not fix anything. The fix is a later phase, run against your report.'
|
|
101
|
+
].join('\n');
|
|
102
|
+
return buildDispatchSystemPrompt({
|
|
103
|
+
taskTitle: 'rd',
|
|
104
|
+
taskBody,
|
|
105
|
+
memoryBlock: NO_MEMORY_BLOCK
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a batch of independent items engages the batch machinery.
|
|
3
|
+
*
|
|
4
|
+
* `single` means: take today's path — no diagnosis fan-out, no rule
|
|
5
|
+
* pre-read, no topology step. `batch` means: the batch machinery may
|
|
6
|
+
* engage.
|
|
7
|
+
*/
|
|
8
|
+
export type BatchMode = 'single' | 'batch';
|
|
9
|
+
/**
|
|
10
|
+
* The number of items at which the batch machinery engages.
|
|
11
|
+
*
|
|
12
|
+
* Two, because one item is the single-task lane's own case and the batch
|
|
13
|
+
* exists for the case where setup is amortized over more than one.
|
|
14
|
+
*/
|
|
15
|
+
export declare const BATCH_MODE_MIN_ITEMS = 2;
|
|
16
|
+
/**
|
|
17
|
+
* Decide which path a batch of independent items takes.
|
|
18
|
+
*
|
|
19
|
+
* @param itemCount - How many independent items the user handed over.
|
|
20
|
+
* @returns `single` for zero or one item, `batch` for two or more.
|
|
21
|
+
*/
|
|
22
|
+
export declare function decideBatchMode(itemCount: number): BatchMode;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/services/batch/batch-entry.ts
|
|
2
|
+
//
|
|
3
|
+
// The batch-mode entry decision: how many independent items make a batch.
|
|
4
|
+
//
|
|
5
|
+
// WHY THIS DECISION IS ITS OWN MODULE. Batch mode is an ADDITION to the
|
|
6
|
+
// race lane, never a substitute for it. The lane's single-task path is
|
|
7
|
+
// unchanged by a batch, and the only thing that decides whether a request
|
|
8
|
+
// takes it is how many independent items the user handed over. So the
|
|
9
|
+
// decision is isolated here: one function, one boundary, and every caller
|
|
10
|
+
// asks the same question the same way.
|
|
11
|
+
//
|
|
12
|
+
// THE BOUNDARY IS TWO, NOT ONE. One item is not a batch. The batch
|
|
13
|
+
// machinery — the parallel read-only diagnosis fan-out, the rule pre-read,
|
|
14
|
+
// the topology step — all exist to amortize setup across several
|
|
15
|
+
// independent items. Applied to one item they cost what they save and
|
|
16
|
+
// change the single-task lane's behaviour, which is the one thing the
|
|
17
|
+
// batch mode is forbidden from doing. So one item reads "single" and
|
|
18
|
+
// takes exactly the path it takes today.
|
|
19
|
+
//
|
|
20
|
+
// WHY THE COUNT IS NOT THE ONLY INPUT. This function counts ITEMS, and the
|
|
21
|
+
// caller is the one that has already established that the items are
|
|
22
|
+
// mutually independent. A batch of items that share a file is still a
|
|
23
|
+
// batch here: the topology step (see `batch-diagnosis.ts`) is what decides
|
|
24
|
+
// that two of them may not run at the same time, and folding that
|
|
25
|
+
// judgement in here would make the entry decision depend on the topology
|
|
26
|
+
// the entry decision exists to gate.
|
|
27
|
+
/**
|
|
28
|
+
* The number of items at which the batch machinery engages.
|
|
29
|
+
*
|
|
30
|
+
* Two, because one item is the single-task lane's own case and the batch
|
|
31
|
+
* exists for the case where setup is amortized over more than one.
|
|
32
|
+
*/
|
|
33
|
+
export const BATCH_MODE_MIN_ITEMS = 2;
|
|
34
|
+
/**
|
|
35
|
+
* Decide which path a batch of independent items takes.
|
|
36
|
+
*
|
|
37
|
+
* @param itemCount - How many independent items the user handed over.
|
|
38
|
+
* @returns `single` for zero or one item, `batch` for two or more.
|
|
39
|
+
*/
|
|
40
|
+
export function decideBatchMode(itemCount) {
|
|
41
|
+
return itemCount >= BATCH_MODE_MIN_ITEMS ? 'batch' : 'single';
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BatchItem } from './batch-progress-types.js';
|
|
2
|
+
import type { BatchFixDependencies, BatchFixDiagnosis } from './batch-fix-types.js';
|
|
3
|
+
/** The role the fix sub-agents are dispatched as: the lane's own RD role. */
|
|
4
|
+
export declare const FIX_ROLE = "rd";
|
|
5
|
+
/** Where the batch's record lives. */
|
|
6
|
+
export interface BatchFixContext {
|
|
7
|
+
readonly projectRoot: string;
|
|
8
|
+
readonly sessionId: string;
|
|
9
|
+
readonly batchId: string;
|
|
10
|
+
}
|
|
11
|
+
/** Everything one dispatched agent needs. */
|
|
12
|
+
export interface FixFrame {
|
|
13
|
+
readonly context: BatchFixContext;
|
|
14
|
+
readonly deps: BatchFixDependencies;
|
|
15
|
+
readonly diagnoses: Readonly<Record<string, BatchFixDiagnosis>>;
|
|
16
|
+
readonly rules: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/** One item, with the wave and the rid it was scheduled under. */
|
|
19
|
+
export interface ScheduledFix {
|
|
20
|
+
readonly item: BatchItem;
|
|
21
|
+
readonly waveIndex: number;
|
|
22
|
+
readonly rid: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the prompt one fix sub-agent receives.
|
|
26
|
+
*
|
|
27
|
+
* The prompt carries the ONE item's diagnosis and the rule list, and the
|
|
28
|
+
* shared governance prefix comes from the one composer that owns it — a
|
|
29
|
+
* second hand-rolled copy of the prefix would drift away from it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildFixPrompt(item: BatchItem, diagnosis: BatchFixDiagnosis, rules: readonly string[], rid: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Derive one agent's rid from the batch's rid and the item's id.
|
|
34
|
+
*
|
|
35
|
+
* The rid becomes a worktree branch name, so two agents may never share one.
|
|
36
|
+
* The item's id is sanitized into rid characters, and a collision (two ids
|
|
37
|
+
* that differ only in characters a rid cannot carry) is broken with a counter.
|
|
38
|
+
*/
|
|
39
|
+
export declare function deriveAgentRid(baseRid: string, itemId: string, used: Set<string>): string;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// src/services/batch/batch-fix-agent.ts
|
|
2
|
+
//
|
|
3
|
+
// The agent-facing half of the batch's fix phase: the prompt one fix
|
|
4
|
+
// sub-agent receives, and the request id that agent is dispatched under.
|
|
5
|
+
//
|
|
6
|
+
// WHY THE PROMPT IS BUILT HERE AND NOT IN THE PHASE. The phase's job is
|
|
7
|
+
// ORDER: dispatch, test, flip. The prompt's job is CONTENT: the one item's
|
|
8
|
+
// diagnosis, the rules that apply to its files, and the shared governance
|
|
9
|
+
// prefix. Splitting them keeps each file one thing, and it is the same split
|
|
10
|
+
// the batch record already makes (`batch-progress-types.ts` beside
|
|
11
|
+
// `batch-progress-store.ts`).
|
|
12
|
+
//
|
|
13
|
+
// WHY THE AGENT'S PROMPT IS BUILT FROM THE DIAGNOSIS, NOT FROM THE TREE. A
|
|
14
|
+
// fix agent does not re-read the repository: the diagnosis phase already
|
|
15
|
+
// measured the root cause and the file set, and a second look would produce a
|
|
16
|
+
// second answer to the same question.
|
|
17
|
+
//
|
|
18
|
+
// WHY THE RID IS DERIVED FROM THE ITEM. The worktree branch name is derived
|
|
19
|
+
// from the rid, so two agents sharing a rid would make `git worktree add -b`
|
|
20
|
+
// fail. The derivation therefore ends in the item's id, and a collision is
|
|
21
|
+
// broken with a counter so two items that differ only in characters a rid
|
|
22
|
+
// cannot carry still get two rids.
|
|
23
|
+
import { buildDispatchSystemPrompt } from '../context/build-dispatch-system-prompt.js';
|
|
24
|
+
/** The role the fix sub-agents are dispatched as: the lane's own RD role. */
|
|
25
|
+
export const FIX_ROLE = 'rd';
|
|
26
|
+
/**
|
|
27
|
+
* The memory block a pure prompt builder carries.
|
|
28
|
+
*
|
|
29
|
+
* `buildDispatchSystemPrompt` takes a pre-fetched memory block, and the
|
|
30
|
+
* memory preflight is asynchronous I/O that belongs to the dispatch site, not
|
|
31
|
+
* to a pure prompt builder. This prompt carries no project memory block, and
|
|
32
|
+
* the composer renders its own "no block" form.
|
|
33
|
+
*/
|
|
34
|
+
const NO_MEMORY_BLOCK = { available: false };
|
|
35
|
+
/**
|
|
36
|
+
* Build the prompt one fix sub-agent receives.
|
|
37
|
+
*
|
|
38
|
+
* The prompt carries the ONE item's diagnosis and the rule list, and the
|
|
39
|
+
* shared governance prefix comes from the one composer that owns it — a
|
|
40
|
+
* second hand-rolled copy of the prefix would drift away from it.
|
|
41
|
+
*/
|
|
42
|
+
export function buildFixPrompt(item, diagnosis, rules, rid) {
|
|
43
|
+
const taskBody = [
|
|
44
|
+
`## Batch fix — ${item.label}`,
|
|
45
|
+
'',
|
|
46
|
+
`- Item id: \`${item.id}\``,
|
|
47
|
+
`- Your request id: \`${rid}\``,
|
|
48
|
+
'',
|
|
49
|
+
'You are fixing ONE item of a batch. Other agents are fixing the other',
|
|
50
|
+
'items in parallel, each on its own worktree.',
|
|
51
|
+
'',
|
|
52
|
+
...renderDiagnosis(diagnosis),
|
|
53
|
+
'',
|
|
54
|
+
'## Rules that apply to the files above',
|
|
55
|
+
'',
|
|
56
|
+
...renderRules(rules),
|
|
57
|
+
'',
|
|
58
|
+
...renderBoundaries()
|
|
59
|
+
].join('\n');
|
|
60
|
+
return buildDispatchSystemPrompt({
|
|
61
|
+
taskTitle: FIX_ROLE,
|
|
62
|
+
taskBody,
|
|
63
|
+
memoryBlock: NO_MEMORY_BLOCK
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** The diagnosis block: the answer the fix agent must not go looking for again. */
|
|
67
|
+
function renderDiagnosis(diagnosis) {
|
|
68
|
+
const files = diagnosis.files.length > 0
|
|
69
|
+
? diagnosis.files.map((file) => `\`${file}\``).join(', ')
|
|
70
|
+
: '(no file was reported)';
|
|
71
|
+
return [
|
|
72
|
+
'## The diagnosis (authoritative — do not re-read the repository)',
|
|
73
|
+
'',
|
|
74
|
+
`**Root cause (根因)**: ${diagnosis.rootCause}`,
|
|
75
|
+
'',
|
|
76
|
+
`**Expected files (预计文件集)**: ${files}`,
|
|
77
|
+
'',
|
|
78
|
+
`**Risk surface hit (风险面命中)**: ${diagnosis.riskSurface ?? 'none'}`,
|
|
79
|
+
'',
|
|
80
|
+
`**Fix sketch (修复草图)**: ${diagnosis.fixSketch}`,
|
|
81
|
+
'',
|
|
82
|
+
'The diagnosis above IS the answer to the reported symptom. Do NOT',
|
|
83
|
+
're-diagnose it and do NOT re-scan the repository to look for the cause',
|
|
84
|
+
'again — your job is to apply the fix it names.'
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
/** The rule list, or the honest note that none was pre-read. */
|
|
88
|
+
function renderRules(rules) {
|
|
89
|
+
if (rules.length === 0)
|
|
90
|
+
return ['- (no rule list was pre-read for this batch)'];
|
|
91
|
+
return rules.map((rule) => `- ${rule}`);
|
|
92
|
+
}
|
|
93
|
+
/** The two things a fix agent must not do. */
|
|
94
|
+
function renderBoundaries() {
|
|
95
|
+
return [
|
|
96
|
+
'## What you must not do',
|
|
97
|
+
'',
|
|
98
|
+
'- Do NOT `git merge`, `git pull`, `git rebase` or release a worktree — the parent session owns the merge.',
|
|
99
|
+
'- Do NOT run the whole test suite; your scoped test is run for you right after you finish.',
|
|
100
|
+
'',
|
|
101
|
+
'Report what you changed, and the test file your fix is scoped to.'
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Derive one agent's rid from the batch's rid and the item's id.
|
|
106
|
+
*
|
|
107
|
+
* The rid becomes a worktree branch name, so two agents may never share one.
|
|
108
|
+
* The item's id is sanitized into rid characters, and a collision (two ids
|
|
109
|
+
* that differ only in characters a rid cannot carry) is broken with a counter.
|
|
110
|
+
*/
|
|
111
|
+
export function deriveAgentRid(baseRid, itemId, used) {
|
|
112
|
+
const root = `${sanitizeRidPart(baseRid)}-fix-${sanitizeRidPart(itemId)}`;
|
|
113
|
+
let candidate = root;
|
|
114
|
+
let counter = 2;
|
|
115
|
+
while (used.has(candidate)) {
|
|
116
|
+
candidate = `${root}-${counter}`;
|
|
117
|
+
counter += 1;
|
|
118
|
+
}
|
|
119
|
+
used.add(candidate);
|
|
120
|
+
return candidate;
|
|
121
|
+
}
|
|
122
|
+
/** The characters a request id may carry, reduced to what a rid accepts. */
|
|
123
|
+
function sanitizeRidPart(raw) {
|
|
124
|
+
const cleaned = raw.replace(/[^A-Za-z0-9._-]/g, '-');
|
|
125
|
+
return cleaned.length > 0 ? cleaned : 'item';
|
|
126
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { BatchItem, BatchItemStatus } from './batch-progress-types.js';
|
|
2
|
+
/** What one diagnostician reported about one item. */
|
|
3
|
+
export interface BatchFixDiagnosis {
|
|
4
|
+
/** Why the reported symptom happens. */
|
|
5
|
+
readonly rootCause: string;
|
|
6
|
+
/** The repo-relative paths the fix is expected to touch. */
|
|
7
|
+
readonly files: readonly string[];
|
|
8
|
+
/** The risk surface number the diagnosis hit, when one was reported. */
|
|
9
|
+
readonly riskSurface?: number;
|
|
10
|
+
/** What the fix would look like. */
|
|
11
|
+
readonly fixSketch: string;
|
|
12
|
+
}
|
|
13
|
+
/** The descriptor one fix sub-agent is dispatched with. */
|
|
14
|
+
export interface BatchFixAgentSpec {
|
|
15
|
+
/** The request id this agent owns. Distinct per item, so worktrees do not collide. */
|
|
16
|
+
readonly rid: string;
|
|
17
|
+
readonly role: string;
|
|
18
|
+
readonly itemId: string;
|
|
19
|
+
readonly waveIndex: number;
|
|
20
|
+
/**
|
|
21
|
+
* The text `peaks worktree spawn --purpose` names this agent's worktree by.
|
|
22
|
+
*
|
|
23
|
+
* It is in the spec because the plan's isolation rule is one spawn per
|
|
24
|
+
* agent, and the spawn takes exactly these three values.
|
|
25
|
+
*/
|
|
26
|
+
readonly purpose: string;
|
|
27
|
+
/** The full dispatch prompt, governance prefix included. */
|
|
28
|
+
readonly prompt: string;
|
|
29
|
+
}
|
|
30
|
+
/** What one fix sub-agent reported back. */
|
|
31
|
+
export interface BatchFixAgentOutcome {
|
|
32
|
+
readonly ok: boolean;
|
|
33
|
+
readonly summary: string;
|
|
34
|
+
/** The test file the fix is scoped to, when the agent named one. */
|
|
35
|
+
readonly scopedTestPath?: string;
|
|
36
|
+
}
|
|
37
|
+
/** The verdict of one item's scoped test. */
|
|
38
|
+
export interface BatchFixScopedTest {
|
|
39
|
+
readonly ok: boolean;
|
|
40
|
+
/** The command that was run, for the report and for the failure text. */
|
|
41
|
+
readonly command: string;
|
|
42
|
+
readonly detail?: string;
|
|
43
|
+
}
|
|
44
|
+
/** What the scoped test is run against. */
|
|
45
|
+
export interface BatchFixScopedTestInput {
|
|
46
|
+
readonly item: BatchItem;
|
|
47
|
+
readonly outcome: BatchFixAgentOutcome;
|
|
48
|
+
}
|
|
49
|
+
/** The two effects the caller wires in. */
|
|
50
|
+
export interface BatchFixDependencies {
|
|
51
|
+
/** Dispatch one fix sub-agent and resolve with what it reported. */
|
|
52
|
+
readonly dispatchFixAgent: (spec: BatchFixAgentSpec) => Promise<BatchFixAgentOutcome> | BatchFixAgentOutcome;
|
|
53
|
+
/** Run one item's scoped test and resolve with its verdict. */
|
|
54
|
+
readonly runScopedTest: (input: BatchFixScopedTestInput) => Promise<BatchFixScopedTest> | BatchFixScopedTest;
|
|
55
|
+
}
|
|
56
|
+
/** What the fix phase needs to know. */
|
|
57
|
+
export interface BatchFixOptions {
|
|
58
|
+
readonly projectRoot: string;
|
|
59
|
+
readonly sessionId: string;
|
|
60
|
+
readonly batchId: string;
|
|
61
|
+
/** The batch's request id; every agent's rid is derived from it. */
|
|
62
|
+
readonly rid: string;
|
|
63
|
+
/** The batch's items. Only the `diagnosed` ones are fixed. */
|
|
64
|
+
readonly items: readonly BatchItem[];
|
|
65
|
+
/** Each item's diagnosis, keyed by item id. */
|
|
66
|
+
readonly diagnoses: Readonly<Record<string, BatchFixDiagnosis>>;
|
|
67
|
+
/** The rules that apply to the files being fixed (the pre-read's output). */
|
|
68
|
+
readonly rules: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** What one item's fix produced. */
|
|
71
|
+
export interface BatchFixItemResult {
|
|
72
|
+
readonly itemId: string;
|
|
73
|
+
readonly waveIndex: number;
|
|
74
|
+
readonly rid: string;
|
|
75
|
+
/** `fixed` only when the fix and its scoped test both succeeded. */
|
|
76
|
+
readonly status: BatchItemStatus;
|
|
77
|
+
readonly fix: BatchFixAgentOutcome;
|
|
78
|
+
readonly scopedTest: BatchFixScopedTest;
|
|
79
|
+
}
|
|
80
|
+
/** What the fix phase produced. */
|
|
81
|
+
export interface BatchFixResult {
|
|
82
|
+
readonly results: readonly BatchFixItemResult[];
|
|
83
|
+
/** Items with no recorded diagnosis, so no fix agent could be dispatched. */
|
|
84
|
+
readonly undiagnosable: readonly string[];
|
|
85
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/services/batch/batch-fix-types.ts
|
|
2
|
+
//
|
|
3
|
+
// The vocabulary of the batch's fix phase: what a diagnosis says, what a fix
|
|
4
|
+
// agent is dispatched with, what it reports, and what the scoped test
|
|
5
|
+
// answers.
|
|
6
|
+
//
|
|
7
|
+
// WHY A SEPARATE MODULE. The fix phase touches the filesystem (the batch
|
|
8
|
+
// record) and the names here are the pure data the phase trades. Keeping the
|
|
9
|
+
// names here means the contract can be read — and typed — without importing
|
|
10
|
+
// any I/O, which is the same split the batch progress record already makes.
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BatchFixDependencies, BatchFixOptions, BatchFixResult } from './batch-fix-types.js';
|
|
2
|
+
export type { BatchFixAgentOutcome, BatchFixAgentSpec, BatchFixDependencies, BatchFixDiagnosis, BatchFixItemResult, BatchFixOptions, BatchFixResult, BatchFixScopedTest, BatchFixScopedTestInput } from './batch-fix-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fix every diagnosed item of a batch, one scoped test at a time.
|
|
5
|
+
*
|
|
6
|
+
* The waves are the unit of parallelism: the agents of one wave are
|
|
7
|
+
* dispatched together, and the wave after it starts only when the previous
|
|
8
|
+
* wave's items have been tested. The scoped test of an item runs before that
|
|
9
|
+
* item's status flips, and a red test leaves the item `diagnosed`.
|
|
10
|
+
*
|
|
11
|
+
* @param options - The batch, its items, their diagnoses and the rule list.
|
|
12
|
+
* @param deps - The dispatch and the scoped-test runner.
|
|
13
|
+
* @returns One result per fixed item, and the items that had no diagnosis.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runBatchFix(options: BatchFixOptions, deps: BatchFixDependencies): Promise<BatchFixResult>;
|