@mgiles/perk 2.3.0 → 3.1.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 (145) hide show
  1. package/README.md +1 -1
  2. package/extension/adapters/planAdapterPlannotator.ts +135 -91
  3. package/extension/adapters/planAdapterTombell.ts +5 -3
  4. package/extension/doors/address.ts +235 -37
  5. package/extension/doors/annotationPush.ts +924 -0
  6. package/extension/doors/auditWaveTools.ts +352 -0
  7. package/extension/doors/ciExecutor.ts +220 -55
  8. package/extension/doors/commitCompact.ts +98 -10
  9. package/extension/doors/draftReviewWaveTools.ts +412 -0
  10. package/extension/doors/dreamWaveTools.ts +475 -0
  11. package/extension/doors/harvestWaveTools.ts +279 -0
  12. package/extension/doors/land.ts +1 -0
  13. package/extension/doors/learn.ts +24 -6
  14. package/extension/doors/learnFactory.ts +33 -7
  15. package/extension/doors/lifecycleGates.ts +1 -1
  16. package/extension/doors/objectiveReviewBrowser.ts +537 -0
  17. package/extension/doors/objectiveStack.ts +1143 -0
  18. package/extension/doors/planReviewBrowser.ts +475 -0
  19. package/extension/doors/plannotatorHandoff.ts +120 -49
  20. package/extension/doors/prReview.ts +180 -63
  21. package/extension/doors/prReviewBrowser.ts +31 -23
  22. package/extension/doors/prReviewDynamic.ts +57 -30
  23. package/extension/doors/prReviewTerminal.ts +6 -11
  24. package/extension/doors/reviewWaveTools.ts +397 -0
  25. package/extension/doors/selfcheck.ts +1 -1
  26. package/extension/doors/submit.ts +82 -7
  27. package/extension/factories/gistAuthor.ts +4 -4
  28. package/extension/factories/gistDraft.ts +1 -1
  29. package/extension/factories/gistSave.ts +2 -2
  30. package/extension/factories/objective.ts +7 -7
  31. package/extension/factories/objectiveAuthor.ts +5 -4
  32. package/extension/factories/objectiveDraft.ts +153 -30
  33. package/extension/factories/objectiveDreamReport.ts +347 -0
  34. package/extension/factories/objectivePlan.ts +163 -9
  35. package/extension/factories/objectiveSave.ts +90 -2
  36. package/extension/factories/planMode.ts +5 -3
  37. package/extension/factories/planReview.ts +304 -46
  38. package/extension/factories/planTitle.ts +27 -9
  39. package/extension/hunkFeedback/inbox.ts +389 -0
  40. package/extension/hunkFeedback/perkFeedback.ts +364 -0
  41. package/extension/hunkFeedback/receiver.ts +296 -0
  42. package/extension/hunkFeedback/store.ts +533 -0
  43. package/extension/index.ts +169 -57
  44. package/extension/substrate/agentScratch.ts +171 -0
  45. package/extension/substrate/bindingDelivery.ts +9 -11
  46. package/extension/substrate/cache.ts +166 -23
  47. package/extension/substrate/coldDoor.ts +2 -3
  48. package/extension/substrate/command.ts +9 -6
  49. package/extension/substrate/config.ts +41 -12
  50. package/extension/substrate/git.ts +95 -2
  51. package/extension/substrate/providers.ts +4 -33
  52. package/extension/substrate/resources.ts +11 -0
  53. package/extension/substrate/result.ts +16 -7
  54. package/extension/substrate/sessionData.ts +8 -6
  55. package/extension/substrate/sessionPointers.ts +4 -5
  56. package/extension/substrate/structuredOutput.ts +78 -19
  57. package/extension/substrate/toolGating.ts +179 -23
  58. package/extension/substrate/workflowState.ts +50 -2
  59. package/extension/surfaces/footerProvider.ts +6 -6
  60. package/extension/surfaces/report.ts +38 -12
  61. package/extension/surfaces/surfaces.ts +213 -275
  62. package/extension/vendor/btw/btw.ts +94 -17
  63. package/extension/waves/adversarialReviewWave.ts +181 -0
  64. package/extension/waves/auditWave.ts +312 -0
  65. package/extension/waves/draftReviewWave.ts +205 -0
  66. package/extension/waves/dreamReducerWave.ts +700 -0
  67. package/extension/waves/dreamReport.ts +1494 -0
  68. package/extension/waves/dreamWave.ts +927 -0
  69. package/extension/waves/harvestWave.ts +399 -0
  70. package/extension/waves/memoryAdapter.ts +14 -1
  71. package/extension/waves/objectiveExplorerWave.ts +120 -0
  72. package/extension/waves/ponytail.ts +104 -0
  73. package/extension/waves/prReviewDynamicWave.ts +383 -72
  74. package/extension/waves/prReviewWave.ts +175 -25
  75. package/extension/waves/reportWave.ts +503 -107
  76. package/extension/waves/reviewClassifierWave.ts +109 -0
  77. package/extension/waves/rpcAdapter.ts +65 -2
  78. package/extension/worker/readOnlySession.ts +4 -5
  79. package/extension/worker/worker.ts +71 -93
  80. package/extension/workerMain.ts +4 -6
  81. package/package.json +18 -5
  82. package/prompts/README.md +19 -0
  83. package/prompts/_fixtures/live.yaml +115 -65
  84. package/prompts/commit-and-compact-continuation.md +13 -0
  85. package/prompts/common/resume-advisory.md +1 -0
  86. package/prompts/contexts/adapters/plannotator-gist.md +13 -0
  87. package/prompts/contexts/adapters/plannotator-objective.md +8 -3
  88. package/prompts/contexts/adapters/plannotator-plan.md +8 -3
  89. package/prompts/contexts/gist-authoring.md +6 -20
  90. package/prompts/contexts/objective-authoring.md +6 -18
  91. package/prompts/stages/address/action.md +3 -14
  92. package/prompts/stages/address/preview.md +2 -13
  93. package/prompts/stages/audit.md +18 -0
  94. package/prompts/stages/conflict-resolution.md +1 -1
  95. package/prompts/stages/gist-author/seed.md +4 -4
  96. package/prompts/stages/gist-save.md +1 -1
  97. package/prompts/stages/implement.md +3 -1
  98. package/prompts/stages/learn-code.md +1 -1
  99. package/prompts/stages/learn-docs.md +2 -2
  100. package/prompts/stages/learn-dream.md +10 -0
  101. package/prompts/stages/learn-harvest.md +15 -0
  102. package/prompts/stages/learn-orchestrate.md +1 -1
  103. package/prompts/stages/objective-author/adopt.md +5 -3
  104. package/prompts/stages/objective-author/file.md +5 -4
  105. package/prompts/stages/objective-author/seed.md +5 -4
  106. package/prompts/stages/objective-land.md +7 -0
  107. package/prompts/stages/objective-plan/guidance.md +2 -13
  108. package/prompts/stages/objective-plan/seed.md +5 -12
  109. package/prompts/stages/objective-recover.md +8 -0
  110. package/prompts/stages/objective-replan.md +4 -2
  111. package/prompts/stages/objective-review-browser.md +9 -0
  112. package/prompts/stages/objective-sync.md +6 -0
  113. package/prompts/stages/plan-from/adopt.md +2 -2
  114. package/prompts/stages/plan-from/file.md +2 -2
  115. package/prompts/stages/plan-review-browser.md +9 -0
  116. package/prompts/stages/pr-review-browser/active.md +6 -14
  117. package/prompts/stages/pr-review-browser/foreign.md +6 -14
  118. package/prompts/stages/pr-review-dynamic.md +6 -6
  119. package/prompts/stages/pr-review-terminal/active.md +7 -15
  120. package/prompts/stages/pr-review-terminal/foreign.md +7 -15
  121. package/prompts/stages/pr-review-terminal/local.md +1 -1
  122. package/prompts/stages/pr-review.md +5 -5
  123. package/prompts/stages/replan.md +3 -3
  124. package/shared/README.md +2 -2
  125. package/shared/bindings.yaml +15 -0
  126. package/shared/contracts-history.md +11 -0
  127. package/shared/contracts.md +5373 -281
  128. package/shared/providers.yaml +27 -60
  129. package/shared/registry.yaml +42 -18
  130. package/shared/schemas/inputs/review-post-batch.schema.json +14 -1
  131. package/shared/schemas/outputs/objective-doctor.schema.json +487 -0
  132. package/shared/schemas/outputs/objective-stack-land.schema.json +732 -0
  133. package/shared/schemas/outputs/objective-stack-recover.schema.json +397 -0
  134. package/shared/schemas/outputs/objective-stack-status.schema.json +577 -0
  135. package/shared/schemas/outputs/objective-stack-sync.schema.json +184 -0
  136. package/shared/schemas/outputs/plan-save.schema.json +12 -0
  137. package/shared/schemas/outputs/pr-land.schema.json +3 -3
  138. package/shared/schemas/outputs/pr-submit.schema.json +177 -1
  139. package/extension/adapters/todoAdapterJuicesharp.ts +0 -102
  140. package/extension/checkpoints/checkpoints.ts +0 -550
  141. package/extension/checkpoints/planSteps.ts +0 -108
  142. package/extension/doors/askUser.ts +0 -198
  143. package/prompts/common/output-schemas/objective-explorer.md +0 -36
  144. package/prompts/common/output-schemas/review-classifier.md +0 -47
  145. package/prompts/contexts/adapters/juicesharp-todo.md +0 -7
@@ -0,0 +1,205 @@
1
+ // The draft-review `WaveSpec`-building entrypoint over the shared report-wave runner — the
2
+ // draft-review doors' (/plan-review-browser, /objective-review-browser) vocabulary as tested
3
+ // code (sibling of `adversarialReviewWave.ts`): the four settled angles plus the custom lane,
4
+ // the per-lane completion-report schema, and the lane/task composition are module-owned here,
5
+ // launched NON-BLOCKING via `startReportWave` so the parent can return from the launch and hold
6
+ // the model-held `subagent_wait` relay loop open while the children stream finding batches.
7
+ //
8
+ // CONSUMED by the `/plan-review-browser` and `/objective-review-browser` doors via the
9
+ // `start_draft_review_wave` / `collect_draft_review_wave` tool pair
10
+ // (`extension/doors/draftReviewWaveTools.ts`) — `draftType` parameterizes the lane tasks.
11
+ //
12
+ // ZERO retries — deliberate: the doors' contract is honest incompleteness surfaced to the human
13
+ // during triage (an `ok: false` lane is reported, never papered over), so the pr-review
14
+ // bounded-retry policy does not carry over.
15
+ //
16
+ // The surface handle (URL/port) is STRUCTURALLY UNREPRESENTABLE: `buildDraftReviewLanes` has no
17
+ // URL parameter at all, so the children can never learn the review surface — enforced by
18
+ // construction, pinned by the suite. There is likewise NO `directive` parameter: the PR doors'
19
+ // focus-note semantics deliberately do not carry over — the custom lane IS the draft doors'
20
+ // user-input channel.
21
+ //
22
+ // The finding rows are deliberately identical to `annotationPush.ts`'s `PlanFinding` shape
23
+ // (`{phrase, severity, confidence, body}`), so draft reports feed `push_annotations` plan-mode
24
+ // without reshaping; the `agents/draft-reviewer.md` def completes via the `structured_output`
25
+ // tool this wave's `outputSchema` injects per lane.
26
+
27
+ import { PONYTAIL_CORE_SKILL } from "./ponytail.ts";
28
+ import {
29
+ type ReportWaveStart,
30
+ startReportWave,
31
+ type WaveAdapter,
32
+ type WaveLane,
33
+ type WaveSpec,
34
+ } from "./reportWave.ts";
35
+
36
+ /** The four-slug settled draft-review angle allowlist (the custom lane rides separately). */
37
+ export type DraftReviewAngle = "grounding" | "scope" | "decision-completeness" | "risk";
38
+
39
+ /**
40
+ * The per-angle lane-task opener (`Angle: <slug>.`) — the same task shape the
41
+ * `perk.draft-reviewer` agent def is written against (the angle rubric lives in the agent def,
42
+ * never in the task).
43
+ */
44
+ export const DRAFT_REVIEW_ANGLES: Readonly<Record<DraftReviewAngle, string>> = {
45
+ grounding: "Angle: grounding.",
46
+ scope: "Angle: scope.",
47
+ "decision-completeness": "Angle: decision-completeness.",
48
+ risk: "Angle: risk.",
49
+ };
50
+
51
+ /** Narrow an unknown slug onto the angle union (own-property check — no prototype hits). */
52
+ export function isDraftReviewAngle(value: string): value is DraftReviewAngle {
53
+ return Object.hasOwn(DRAFT_REVIEW_ANGLES, value);
54
+ }
55
+
56
+ /**
57
+ * The per-lane completion-report schema the wave enforces as its `outputSchema` — the engine
58
+ * injects a `structured_output` tool into each lane and fails any lane whose report is missing
59
+ * or schema-invalid. Closed shapes, `{angle, summary, findings, fyi}` all required, and
60
+ * DELIBERATELY NO VERDICT FIELD — the human adjudicates every finding in the browser, so there
61
+ * is no clean/actionable derivation to make consistent (the `ADVERSARIAL_REVIEW_REPORT_SCHEMA`
62
+ * rationale). The `angle` enum includes `custom` (the custom lane echoes it). Finding rows are
63
+ * the forward-bound plan-mode `PlanFinding` shape (`annotationPush.ts`'s `PLAN_FINDING_KEYS`):
64
+ * `phrase` is required-nullable (the byte-exact draft span, or `null` for a global finding),
65
+ * and the severity/confidence enums match the agent def's triage tags. The `phrase` string arm
66
+ * requires a non-whitespace character (`pattern` applies only to string instances, so `null`
67
+ * still passes): plan-mode `push_annotations` rejects empty/whitespace-only phrases wholesale,
68
+ * so the schema refuses them at the source instead of letting an engine-valid report fail the
69
+ * downstream decode.
70
+ */
71
+ export const DRAFT_REVIEW_REPORT_SCHEMA = {
72
+ type: "object",
73
+ additionalProperties: false,
74
+ required: ["angle", "summary", "findings", "fyi"],
75
+ properties: {
76
+ angle: {
77
+ type: "string",
78
+ enum: ["grounding", "scope", "decision-completeness", "risk", "custom", "ponytail"],
79
+ },
80
+ summary: { type: "string" },
81
+ findings: {
82
+ type: "array",
83
+ items: {
84
+ type: "object",
85
+ additionalProperties: false,
86
+ required: ["phrase", "severity", "confidence", "body"],
87
+ properties: {
88
+ phrase: { type: ["string", "null"], pattern: "\\S" },
89
+ severity: { type: "string", enum: ["critical", "major", "minor"] },
90
+ confidence: { type: "string", enum: ["high", "medium", "low"] },
91
+ body: { type: "string" },
92
+ },
93
+ },
94
+ },
95
+ fyi: {
96
+ type: "array",
97
+ items: { type: "string" },
98
+ },
99
+ },
100
+ };
101
+
102
+ /** The stable lane key/label (and push source slug) of the custom lane. */
103
+ const CUSTOM_LANE_KEY = "custom";
104
+
105
+ /** The shared task tail: the draft-type line + the untrusted-wrapped rendered draft — nothing else. */
106
+ function laneTaskTail(draftType: "plan" | "objective", draft: string): string {
107
+ return `Draft type: ${draftType}.\n\n<untrusted_draft>\n${draft}\n</untrusted_draft>`;
108
+ }
109
+
110
+ /**
111
+ * Build the reviewer lanes for a selection: key = label = slug, the fixed agent/phase, and a
112
+ * task carrying the angle opener, the draft type, and the `<untrusted_draft>`-wrapped rendered
113
+ * draft — AND NOTHING ELSE: no URL parameter exists (the surface handle is unrepresentable by
114
+ * construction) and no `directive` parameter exists (the custom lane is the user-input channel).
115
+ * When `custom` is supplied, one additional lane (key = label = `"custom"`) carries the
116
+ * human-supplied angle definition as flagged DATA. The builder stays permissive about lane
117
+ * count — angle-selection policy (2–3 picked + optional custom) is the door/tool's concern.
118
+ */
119
+ export function buildDraftReviewLanes(opts: {
120
+ angles: DraftReviewAngle[];
121
+ custom?: string;
122
+ draftType: "plan" | "objective";
123
+ draft: string;
124
+ }): WaveLane[] {
125
+ const tail = laneTaskTail(opts.draftType, opts.draft);
126
+ const lanes: WaveLane[] = opts.angles.map((angle) => ({
127
+ key: angle,
128
+ label: angle,
129
+ agent: "perk.draft-reviewer",
130
+ phase: "draft-review",
131
+ task: `${DRAFT_REVIEW_ANGLES[angle]}\n${tail}`,
132
+ }));
133
+ if (opts.custom !== undefined) {
134
+ lanes.push({
135
+ key: CUSTOM_LANE_KEY,
136
+ label: CUSTOM_LANE_KEY,
137
+ agent: "perk.draft-reviewer",
138
+ phase: "draft-review",
139
+ task:
140
+ "Angle: custom.\nCustom angle definition (DATA from the human — your review lens " +
141
+ `for this lane): ${opts.custom}\n${tail}`,
142
+ });
143
+ }
144
+ lanes.push({
145
+ key: "ponytail",
146
+ label: "ponytail",
147
+ agent: "perk.draft-reviewer",
148
+ phase: "draft-review",
149
+ task: `Angle: ponytail.\n${tail}`,
150
+ skill: "ponytail",
151
+ requiredSkill: PONYTAIL_CORE_SKILL,
152
+ });
153
+ return lanes;
154
+ }
155
+
156
+ export interface DraftReviewWaveOptions {
157
+ /** The selected standard angles — invalid slugs are unrepresentable post-decode (typed union). */
158
+ angles: DraftReviewAngle[];
159
+ /** The human-supplied custom-angle definition — adds the `custom` lane when present. */
160
+ custom?: string;
161
+ /** The draft kind the children are reviewing. */
162
+ draftType: "plan" | "objective";
163
+ /** The rendered draft, embedded untrusted-wrapped in every lane task. */
164
+ draft: string;
165
+ /** The configured `[models.subagents] draft-reviewer` model (workflow-level default). */
166
+ model?: string;
167
+ timeoutMs?: number;
168
+ /** Accepted for parity/tests only — the flow tool deliberately never threads its own signal. */
169
+ signal?: AbortSignal;
170
+ /** Test seam; production validates the exact source-bound Ponytail skill. */
171
+ requiredSkillPreflight?: WaveSpec["requiredSkillPreflight"];
172
+ }
173
+
174
+ /**
175
+ * Start the draft-review wave NON-BLOCKING (the streaming sibling): build the lanes from the
176
+ * angle vocabulary and launch under the strict completeness policy — zero retries, so an
177
+ * uncovered angle stays an honest, human-visible incompleteness. Returns the `startReportWave`
178
+ * outcome: the run handle + never-rejecting `result` on success, or the normalized launch
179
+ * failure.
180
+ */
181
+ export async function startDraftReviewWave(
182
+ adapter: WaveAdapter,
183
+ opts: DraftReviewWaveOptions,
184
+ ): Promise<ReportWaveStart> {
185
+ return await startReportWave(
186
+ adapter,
187
+ {
188
+ flow: "draft-review",
189
+ lanes: buildDraftReviewLanes({
190
+ angles: opts.angles,
191
+ draftType: opts.draftType,
192
+ draft: opts.draft,
193
+ ...(opts.custom !== undefined ? { custom: opts.custom } : {}),
194
+ }),
195
+ outputSchema: DRAFT_REVIEW_REPORT_SCHEMA,
196
+ completeness: "strict",
197
+ ...(opts.model !== undefined ? { model: opts.model } : {}),
198
+ ...(opts.timeoutMs !== undefined ? { timeoutMs: opts.timeoutMs } : {}),
199
+ ...(opts.requiredSkillPreflight !== undefined
200
+ ? { requiredSkillPreflight: opts.requiredSkillPreflight }
201
+ : {}),
202
+ },
203
+ opts.signal,
204
+ );
205
+ }