@gtheys/pi-flow 0.0.0-stage → 0.2.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/README.md +833 -2
- package/adhoc/tracker.ts +360 -0
- package/aven/client.ts +996 -0
- package/aven/status.ts +395 -0
- package/brainstorm/args.ts +24 -0
- package/brainstorm/artifact.ts +67 -0
- package/brainstorm/paths.ts +43 -0
- package/brainstorm/prompt.ts +172 -0
- package/brainstorm/refs.ts +41 -0
- package/config.schema.json +161 -0
- package/config.ts +577 -0
- package/feedback/args.ts +21 -0
- package/feedback/prompt.ts +177 -0
- package/feedback/triage.ts +88 -0
- package/flow/agent-role.ts +46 -0
- package/flow/answer-wake.ts +212 -0
- package/flow/answer.ts +183 -0
- package/flow/args.ts +48 -0
- package/flow/ask-emitter.ts +331 -0
- package/flow/attribution.ts +145 -0
- package/flow/aven-resolve-exec.ts +95 -0
- package/flow/aven-resolve.ts +80 -0
- package/flow/awaiting-approval.ts +32 -0
- package/flow/binding-heal.ts +68 -0
- package/flow/cost-autopush.ts +162 -0
- package/flow/cost-command.ts +122 -0
- package/flow/cost-rows-journal.ts +296 -0
- package/flow/cost-rows-push.ts +112 -0
- package/flow/cost-rows-rows.ts +209 -0
- package/flow/cost-rows.ts +228 -0
- package/flow/cost.ts +173 -0
- package/flow/durable-refs.ts +287 -0
- package/flow/effect-gate.ts +137 -0
- package/flow/ensure-labels.ts +44 -0
- package/flow/frame.ts +172 -0
- package/flow/gates.ts +211 -0
- package/flow/jira-ref.ts +212 -0
- package/flow/label-gate.ts +149 -0
- package/flow/land-gate.ts +98 -0
- package/flow/lifecycle-policy.ts +162 -0
- package/flow/live-wait.ts +52 -0
- package/flow/liveness.ts +408 -0
- package/flow/loop-deps.ts +210 -0
- package/flow/loop-settle.ts +531 -0
- package/flow/loop.ts +437 -0
- package/flow/orchestrate.ts +45 -0
- package/flow/phase-command.ts +287 -0
- package/flow/phase-emoji.ts +13 -0
- package/flow/phase-prompts.ts +251 -0
- package/flow/picker.ts +307 -0
- package/flow/push.ts +475 -0
- package/flow/reconcile-command.ts +253 -0
- package/flow/reconcile-deps.ts +329 -0
- package/flow/reconcile.ts +738 -0
- package/flow/ref-kind.ts +80 -0
- package/flow/resume-picker.ts +222 -0
- package/flow/resume.ts +116 -0
- package/flow/run-health.ts +252 -0
- package/flow/run-liveness.ts +33 -0
- package/flow/state-metrics.ts +559 -0
- package/flow/status.ts +105 -0
- package/flow/step-output.ts +416 -0
- package/flow/steps.ts +73 -0
- package/flow/terminal-purge.ts +281 -0
- package/flow/turn-generation.ts +19 -0
- package/flow/v2-emission.ts +381 -0
- package/flow/v2-resume.ts +100 -0
- package/flow/vocabulary.ts +261 -0
- package/flow/widget.ts +448 -0
- package/flow/worktree-context.ts +136 -0
- package/flow-diagram/assemble.ts +27 -0
- package/flow-diagram/command.ts +252 -0
- package/flow-diagram/translate.ts +862 -0
- package/flow-diagram/vendor/harness-profiler/LICENSE +21 -0
- package/flow-diagram/vendor/harness-profiler/PIN.md +64 -0
- package/flow-diagram/vendor/harness-profiler/hp.js +960 -0
- package/flow-diagram/vendor/harness-profiler/load.ts +66 -0
- package/flow-diagram/vendor/harness-profiler/view.html +436 -0
- package/gates.ts +20 -0
- package/herdr/sync.ts +355 -0
- package/herdr/viewer.ts +432 -0
- package/implement/args.ts +21 -0
- package/implement/prompt.ts +98 -0
- package/implement/retry.ts +57 -0
- package/implement/routing.ts +31 -0
- package/index.ts +3206 -0
- package/mode-profile.ts +56 -0
- package/package.json +205 -4
- package/phase-state.ts +18 -0
- package/plan/args.ts +20 -0
- package/plan/prompt.ts +251 -0
- package/plan/size-check.ts +46 -0
- package/plan-tools/helpers.ts +177 -0
- package/plan-tools/jira-branch-tool.ts +54 -0
- package/plan-tools/jira-branch.ts +109 -0
- package/plan-tools/jira-issue.ts +85 -0
- package/plan-tools/resolve-feature-path.ts +30 -0
- package/plan-tools/resolve-notes-path.ts +37 -0
- package/plan-tools/resolve-spec-path.ts +31 -0
- package/pr-quality/index.ts +908 -0
- package/review/LICENSE +19 -0
- package/review/deviation.ts +252 -0
- package/review/review.ts +3053 -0
- package/review/sem-guidance.d.mts +8 -0
- package/review/sem-guidance.mjs +89 -0
- package/review/verdict.ts +13 -0
- package/run-state.ts +2046 -0
- package/run-title.ts +91 -0
- package/server/consumer.ts +146 -0
- package/server/daemon.ts +1094 -0
- package/server/lifecycle.ts +679 -0
- package/server/pending.ts +267 -0
- package/server/staleness.ts +320 -0
- package/server/writer.ts +86 -0
- package/shared/diff-base.ts +138 -0
- package/shared/flow-base.ts +210 -0
- package/shared/sonarqube-utils.ts +415 -0
- package/shared/stable-range.ts +102 -0
- package/slugify.ts +13 -0
- package/sonarqube/sonarqube.ts +821 -0
- package/spec-review/approve.ts +91 -0
- package/spec-review/args.ts +21 -0
- package/spec-review/aven-spec.ts +142 -0
- package/spec-review/commands.ts +336 -0
- package/spec-review/escape-regexp.ts +7 -0
- package/spec-review/open-in-pane.ts +166 -0
- package/spec-review/picker.ts +74 -0
- package/spec-review/prompt.ts +72 -0
- package/spec-review/publish-args.ts +33 -0
- package/spec-review/publish.ts +210 -0
- package/telemetry/attributes.ts +118 -0
- package/telemetry/content.ts +140 -0
- package/telemetry/dispatch.ts +521 -0
- package/telemetry/exporter.ts +124 -0
- package/telemetry/index.ts +776 -0
- package/telemetry/loki.ts +224 -0
- package/tools/code-review-parse.ts +518 -0
- package/tools/code-review.ts +312 -0
- package/tools/deviation.ts +737 -0
- package/tools/flow-submit.ts +302 -0
- package/tools/land.ts +608 -0
- package/tools/phase-complete.ts +476 -0
- package/tools/result.ts +18 -0
- package/tools/review-deps.ts +44 -0
- package/tools/run-attempt.ts +312 -0
- package/tools/spec-approve.ts +265 -0
- package/validate/args.ts +22 -0
- package/validate/deviation-gate.ts +229 -0
- package/validate/gate-target.ts +371 -0
- package/validate/gate.ts +79 -0
- package/validate/paths.ts +20 -0
- package/validate/personal.ts +104 -0
- package/validate/prompt.ts +525 -0
- package/validate/review-gate.ts +134 -0
- package/validate/subtask-range.ts +113 -0
- package/work-mode.ts +19 -0
- package/worktree/bootstrap.ts +243 -0
- package/worktree/branch.ts +168 -0
- package/worktree/herdr.ts +447 -0
- package/worktree/index.ts +1447 -0
- package/worktree/orphan.ts +384 -0
- package/worktree/remove-guards.ts +99 -0
- package/worktree/residue.ts +216 -0
- package/worktree/sweep.ts +526 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// AIDEV-NOTE: PMR-T8ZG — the ad-hoc human code-review tool (PMR-3ZY1),
|
|
2
|
+
// standalone since PMR-V31Z 7.2: no flow phase calls it and a verdict
|
|
3
|
+
// recorded here carries no run-journal authority — it is a human-review
|
|
4
|
+
// utility whose verdict lands as an aven note on the ref. One core shared by
|
|
5
|
+
// the /code-review command (which sends the ad-hoc prompt) and the
|
|
6
|
+
// agent-callable code_review tool: resolve the ref's worktree (binding ->
|
|
7
|
+
// aven note -> herdr list, every hit verified — never open tuicr on the
|
|
8
|
+
// wrong tree), open tuicr in a focused herdr tab, then ask the human
|
|
9
|
+
// pass/fail via the ask_user_question EXTENSION tool. Pass records a dated
|
|
10
|
+
// aven note; fail records the tuicr findings as an aven note and routes
|
|
11
|
+
// back to /implement. No receipt and no in-session marker is written:
|
|
12
|
+
// PMR-V31Z 7.2 deleted both (their last readers — the deleted personal
|
|
13
|
+
// merge gate and the deleted /flow answer review gate — died in phases 4
|
|
14
|
+
// and 7.1).
|
|
15
|
+
// The tool's I/O seams (ReviewDeps) are injected so tests assert the exact
|
|
16
|
+
// exec sequences.
|
|
17
|
+
// AIDEV-NOTE: PMR-R5VB phase 4 — the agent-attested fallback (PMR-3ZY1
|
|
18
|
+
// decision 4, the outcome="pass" parameter) was REMOVED: fail closed. The
|
|
19
|
+
// blocking ask_user_question ask is the ONLY pass route; when the ask
|
|
20
|
+
// extension is absent the tool returns an isError refusal — a pass recorded
|
|
21
|
+
// from the agent's word alone is not allowed, and no code path here records
|
|
22
|
+
// a verdict outside that blocking ask.
|
|
23
|
+
import type {
|
|
24
|
+
AgentToolResult,
|
|
25
|
+
ExtensionAPI,
|
|
26
|
+
ExtensionToolContext,
|
|
27
|
+
} from '@earendil-works/pi-coding-agent'
|
|
28
|
+
import { Type } from 'typebox'
|
|
29
|
+
import { writeAvenNote } from '../aven/client.ts'
|
|
30
|
+
import { healFlowBinding } from '../flow/binding-heal.ts'
|
|
31
|
+
import type { FlowRunEvent } from '../run-state.ts'
|
|
32
|
+
import type { EventWriter } from '../server/writer.ts'
|
|
33
|
+
import type { WorkMode } from '../work-mode.ts'
|
|
34
|
+
import {
|
|
35
|
+
openTuicrReview,
|
|
36
|
+
parseAskAnswer,
|
|
37
|
+
pickLatestSessionSlug,
|
|
38
|
+
routeReviewFail,
|
|
39
|
+
routeReviewPass,
|
|
40
|
+
} from './code-review-parse.ts'
|
|
41
|
+
import { deriveGateMode } from './deviation.ts'
|
|
42
|
+
import { toolResult } from './result.ts'
|
|
43
|
+
import { productionReviewDeps } from './review-deps.ts'
|
|
44
|
+
|
|
45
|
+
export { buildCodeReviewGatePrompt } from './code-review-parse.ts'
|
|
46
|
+
|
|
47
|
+
export function registerCodeReviewTool(
|
|
48
|
+
pi: ExtensionAPI,
|
|
49
|
+
// AIDEV-NOTE: PMR-ZV9Y 2.2 — mode-aware writer (server/writer.ts) for the
|
|
50
|
+
// v2 state-machine emissions journaled below. Optional by construction:
|
|
51
|
+
// no writer (the pre-2.2 harnesses and callers) = no v2 events, and every
|
|
52
|
+
// write is wrapped so a journal failure can NEVER fail the ask (ISC-A-5).
|
|
53
|
+
writer?: EventWriter,
|
|
54
|
+
): void {
|
|
55
|
+
// AIDEV-NOTE: PMR-ZV9Y 2.2 — v2 state-machine emissions for the human
|
|
56
|
+
// code-review ask (plan phase-2 mapping row "code-review ask/answer"). The
|
|
57
|
+
// blocking ask is the wait, so the pair BEFORE it is
|
|
58
|
+
// state-change{waiting_human, code_review_pending} +
|
|
59
|
+
// step-start{validate.code-review}, and the pair when the human answers
|
|
60
|
+
// (PASS or FAIL — both end the wait) is step-stop{validate.code-review} +
|
|
61
|
+
// state-change{running}. They ride the injected mode-aware writer seam
|
|
62
|
+
// (server/writer.ts) — never a second writer, and never loop internals.
|
|
63
|
+
// Optional by construction: no writer (the pre-2.2 harnesses and callers)
|
|
64
|
+
// = no v2 events, and every write is wrapped so a journal failure can
|
|
65
|
+
// NEVER fail the ask (ISC-A-5).
|
|
66
|
+
// `openReviewSteps` is the idempotent pairing guard — the tool-local twin of
|
|
67
|
+
// 2.1's specApprovalStepOpen: an unclear answer makes the agent re-ask and
|
|
68
|
+
// RE-CALL code_review for the same ref while the wait is still live, and the
|
|
69
|
+
// second call must not journal a second pending pair (nor a later answer
|
|
70
|
+
// pair without an open step). Per-ref Set because one session can review
|
|
71
|
+
// several refs; in-process state only, so a restarted process re-opens the
|
|
72
|
+
// step on its next ask (a duplicated start is honest evidence, an orphan
|
|
73
|
+
// stop would not be).
|
|
74
|
+
const openReviewSteps = new Set<string>()
|
|
75
|
+
const journalV2 = async (event: FlowRunEvent): Promise<void> => {
|
|
76
|
+
if (writer === undefined) return
|
|
77
|
+
try {
|
|
78
|
+
await writer.record(event)
|
|
79
|
+
} catch {
|
|
80
|
+
// best-effort — a v2 journal failure never fails the gate
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const openReviewGate = async (ref: string): Promise<void> => {
|
|
84
|
+
if (openReviewSteps.has(ref)) return
|
|
85
|
+
openReviewSteps.add(ref)
|
|
86
|
+
await journalV2({
|
|
87
|
+
kind: 'state-change',
|
|
88
|
+
at: new Date().toISOString(),
|
|
89
|
+
ref,
|
|
90
|
+
state: 'waiting_human',
|
|
91
|
+
reason: 'code_review_pending',
|
|
92
|
+
})
|
|
93
|
+
await journalV2({
|
|
94
|
+
kind: 'step-start',
|
|
95
|
+
at: new Date().toISOString(),
|
|
96
|
+
ref,
|
|
97
|
+
phase: 'validate',
|
|
98
|
+
step: 'validate.code-review',
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
const closeReviewGate = async (ref: string): Promise<void> => {
|
|
102
|
+
if (!openReviewSteps.has(ref)) return
|
|
103
|
+
openReviewSteps.delete(ref)
|
|
104
|
+
await journalV2({
|
|
105
|
+
kind: 'step-stop',
|
|
106
|
+
at: new Date().toISOString(),
|
|
107
|
+
ref,
|
|
108
|
+
phase: 'validate',
|
|
109
|
+
step: 'validate.code-review',
|
|
110
|
+
})
|
|
111
|
+
await journalV2({
|
|
112
|
+
kind: 'state-change',
|
|
113
|
+
at: new Date().toISOString(),
|
|
114
|
+
ref,
|
|
115
|
+
state: 'running',
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
pi.registerTool({
|
|
119
|
+
name: 'code_review',
|
|
120
|
+
label: 'ad-hoc code review',
|
|
121
|
+
description:
|
|
122
|
+
"Ad-hoc human code review: resolves the ref's worktree, opens tuicr (branch-scope diff) in a focused herdr tab for the human, then asks them pass/fail and records the verdict as an aven note on the ref. A fail routes back to /implement.",
|
|
123
|
+
promptSnippet:
|
|
124
|
+
"Ad-hoc human code review — call when the human asks for a reviewed pass/fail on a ref's diff.",
|
|
125
|
+
promptGuidelines: [
|
|
126
|
+
"Call code_review with the ref when the human wants a reviewed pass/fail verdict on that ref's worktree diff.",
|
|
127
|
+
'A failure result names what broke and the manual tuicr command — fix the cause or open it manually, then re-call.',
|
|
128
|
+
'When ask_user_question is unavailable, code_review fails closed — no verdict is recorded; re-call once the ask surface is available.',
|
|
129
|
+
],
|
|
130
|
+
parameters: Type.Object({
|
|
131
|
+
ref: Type.String({ description: 'Aven ticket ref, e.g. PMR-ABC1' }),
|
|
132
|
+
}),
|
|
133
|
+
async execute(
|
|
134
|
+
_toolCallId: string,
|
|
135
|
+
params: { ref: string },
|
|
136
|
+
_signal: AbortSignal,
|
|
137
|
+
_onUpdate: unknown,
|
|
138
|
+
ctx: ExtensionToolContext,
|
|
139
|
+
): Promise<AgentToolResult<{ ok: boolean; reason: string }>> {
|
|
140
|
+
// AIDEV-NOTE: PMR-R5VB phase 4 — the ask availability check that fed
|
|
141
|
+
// the removed agent-attested fallback is gone; ask_user_question is
|
|
142
|
+
// re-looked-up below the tuicr open.
|
|
143
|
+
|
|
144
|
+
const deps = productionReviewDeps(pi, ctx.cwd)
|
|
145
|
+
// AIDEV-NOTE: PMR-DRKH — heal-first: the module binding dies on a pi
|
|
146
|
+
// reload (PMR-PJM0), so the resolve doubles as a re-arm. Failure keeps
|
|
147
|
+
// the refusal prefix verbatim (existing regexes are substring matches)
|
|
148
|
+
// and appends only the recovery line.
|
|
149
|
+
const heal = await healFlowBinding(params.ref, deps)
|
|
150
|
+
if (!heal.ok) {
|
|
151
|
+
return toolResult(
|
|
152
|
+
`code_review refused: ${heal.reason}\nRecovery: run ${heal.recovery} to re-arm the flow binding, then re-call.`,
|
|
153
|
+
{ ok: false, reason: heal.reason },
|
|
154
|
+
{ isError: true },
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
const worktree = heal.worktree
|
|
158
|
+
|
|
159
|
+
// AIDEV-NOTE: PMR-5NZB/PMR-K74M — the opener's range policy is
|
|
160
|
+
// mode-keyed (personal: stable-range integrity refusal; work:
|
|
161
|
+
// recorded sha, no probe), so derive the mode from the RESOLVED
|
|
162
|
+
// review worktree through the deviation gate's seam — never the
|
|
163
|
+
// session cwd. A derivation failure is fail-closed: no pane opens on
|
|
164
|
+
// an unclassified tree.
|
|
165
|
+
let mode: WorkMode
|
|
166
|
+
try {
|
|
167
|
+
mode = await deriveGateMode(deps.exec, worktree.path)
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const reason = error instanceof Error ? error.message : String(error)
|
|
170
|
+
return toolResult(
|
|
171
|
+
`code_review: cannot derive the flow mode — ${reason}. The tuicr pane was NOT opened. Fix the pi-flow config and re-call.`,
|
|
172
|
+
{ ok: false, reason: 'mode derivation failed' },
|
|
173
|
+
{ isError: true },
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const open = await openTuicrReview(params.ref, worktree.path, mode, deps)
|
|
178
|
+
if (open.ok) {
|
|
179
|
+
ctx.ui.notify(
|
|
180
|
+
`Opened tuicr for ${params.ref} in a herdr tab. Manual fallback: ${open.command}`,
|
|
181
|
+
'info',
|
|
182
|
+
)
|
|
183
|
+
} else {
|
|
184
|
+
return toolResult(
|
|
185
|
+
`code_review: tuicr open failed — ${open.reason}\nOpen it manually: ${open.command}\nThen re-call code_review (ref="${params.ref}"); the gate ask proceeds on re-call.`,
|
|
186
|
+
{ ok: false, reason: open.reason },
|
|
187
|
+
{ isError: true },
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const askTool = ctx.tools.find((t) => t.name === 'ask_user_question')
|
|
192
|
+
if (askTool === undefined) {
|
|
193
|
+
// AIDEV-NOTE: PMR-R5VB phase 4 — fail closed. The old agent-attested
|
|
194
|
+
// fallback (re-call with outcome="pass") is gone; a pass recorded
|
|
195
|
+
// here would rest on the agent's word alone. PMR-V31Z 7.2: there is
|
|
196
|
+
// no durable fallback route either — the tool itself records the
|
|
197
|
+
// verdict through the blocking ask, so without the ask surface no
|
|
198
|
+
// verdict is recorded this session. The pane stays open for the
|
|
199
|
+
// human either way.
|
|
200
|
+
return toolResult(
|
|
201
|
+
`code_review: ask_user_question is unavailable — recording a pass here would be agent-attested, which is not allowed, and the tool itself records the verdict only through the blocking ask. No verdict is recorded this session.\ntuicr is open for ${params.ref} in a herdr tab (${worktree.path}, ${worktree.branch || 'branch unverified'}). Re-call code_review once ask_user_question is available.`,
|
|
202
|
+
{ ok: false, reason: 'ask extension unavailable' },
|
|
203
|
+
{ isError: true },
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// AIDEV-NOTE: PMR-ZV9Y 2.2 — journal the wait BEFORE it blocks: the
|
|
208
|
+
// daemon-side projection and (PMR-ZV9Y 4.3) the telemetry fan-out must
|
|
209
|
+
// see waiting_human{code_review_pending} while the ask is open, or a run
|
|
210
|
+
// parked on this gate is invisible to the Waiting-on-me queue.
|
|
211
|
+
await openReviewGate(params.ref)
|
|
212
|
+
const askResult = await ctx.executeTool('ask_user_question', {
|
|
213
|
+
question: `Human code review of ${params.ref}: pass or fail?`,
|
|
214
|
+
details: `tuicr is open in a herdr tab (${worktree.path}). Review the diff (branch scope), then answer.`,
|
|
215
|
+
options: [
|
|
216
|
+
{ label: 'pass (Recommended)', value: 'pass' },
|
|
217
|
+
{ label: 'fail', value: 'fail' },
|
|
218
|
+
],
|
|
219
|
+
})
|
|
220
|
+
const answerText = askResult.result.content
|
|
221
|
+
.map((c) => (c.type === 'text' ? c.text : ''))
|
|
222
|
+
.join('\n')
|
|
223
|
+
const answer = parseAskAnswer(answerText)
|
|
224
|
+
if (answer === null) {
|
|
225
|
+
return toolResult(
|
|
226
|
+
// AIDEV-NOTE: PMR-G68P — updated for PMR-R5VB phase 4: the
|
|
227
|
+
// outcome param no longer exists at all, so this branch simply
|
|
228
|
+
// re-asks and routes back through the blocking gate; there is no
|
|
229
|
+
// fallback to point the agent at.
|
|
230
|
+
`code_review: the human's answer was unclear ("${answerText.slice(0, 200)}") — ask the human a plain pass/fail question again via ask_user_question, then re-call code_review with ref="${params.ref}" to record their answer.`,
|
|
231
|
+
{ ok: false, reason: 'unclear answer' },
|
|
232
|
+
{ isError: true },
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
if (answer === 'pass') {
|
|
236
|
+
const routing = routeReviewPass(params.ref, new Date().toISOString())
|
|
237
|
+
// AIDEV-NOTE: PMR-ZV9Y 2.2 — the answer-side pair closes the wait the
|
|
238
|
+
// openReviewGate pair opened; the verdict itself is the aven note
|
|
239
|
+
// below (PMR-V31Z 7.2: no receipt, no in-session marker — their last
|
|
240
|
+
// readers died with the deleted personal merge gate and the deleted
|
|
241
|
+
// /flow answer review gate).
|
|
242
|
+
await closeReviewGate(params.ref)
|
|
243
|
+
const noted = await writeAvenNote(params.ref, routing.avenNote)
|
|
244
|
+
return toolResult(
|
|
245
|
+
`${routing.message}${noted ? '' : '\n(warning: the aven note write failed — record it manually)'}`,
|
|
246
|
+
{ ok: true, reason: '' },
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Fail: read the findings from the persisted tuicr session.
|
|
251
|
+
// AIDEV-NOTE: PMR-ZV9Y 2.2 — a FAIL is still an answer: the wait ends
|
|
252
|
+
// here too (the run routes back to /implement), so close the step before
|
|
253
|
+
// the findings plumbing runs and a note-write failure cannot strand it.
|
|
254
|
+
await closeReviewGate(params.ref)
|
|
255
|
+
let comments = ''
|
|
256
|
+
let listResult = { code: 0, stdout: '', stderr: '' }
|
|
257
|
+
try {
|
|
258
|
+
listResult = await pi.exec(
|
|
259
|
+
'tuicr',
|
|
260
|
+
['review', 'list', '--repo', worktree.path],
|
|
261
|
+
{ cwd: worktree.path },
|
|
262
|
+
)
|
|
263
|
+
const slug = pickLatestSessionSlug(listResult.stdout)
|
|
264
|
+
if (listResult.code === 0 && slug !== null) {
|
|
265
|
+
const commentsResult = await pi.exec(
|
|
266
|
+
'tuicr',
|
|
267
|
+
['review', 'comments', '--session', slug, '--repo', worktree.path],
|
|
268
|
+
{ cwd: worktree.path },
|
|
269
|
+
)
|
|
270
|
+
if (commentsResult.code === 0) {
|
|
271
|
+
comments = commentsResult.stdout
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
} catch {
|
|
275
|
+
// fall through to the free-text fallback below
|
|
276
|
+
}
|
|
277
|
+
const routing = routeReviewFail(params.ref, comments)
|
|
278
|
+
if (routing.freeTextFallback) {
|
|
279
|
+
const described = await ctx.executeTool('ask_user_question', {
|
|
280
|
+
question: `What should the findings note for ${params.ref} say?`,
|
|
281
|
+
details:
|
|
282
|
+
'The tuicr session has no recorded comments. Describe the findings to record.',
|
|
283
|
+
})
|
|
284
|
+
const text = described.result.content
|
|
285
|
+
.map((c) => (c.type === 'text' ? c.text : ''))
|
|
286
|
+
.join('\n')
|
|
287
|
+
const cleaned = text.replace(/^User (answered|selected): ?/i, '').trim()
|
|
288
|
+
if (cleaned.length > 0) {
|
|
289
|
+
const noted = await writeAvenNote(params.ref, cleaned)
|
|
290
|
+
return toolResult(
|
|
291
|
+
`code_review: human FAIL for ${params.ref} — findings recorded as an aven note. Route back to /implement ${params.ref} (retry budget applies). STOP.${noted ? '' : '\n(warning: the aven note write failed — record it manually)'}`,
|
|
292
|
+
{ ok: false, reason: 'human fail' },
|
|
293
|
+
{ isError: true },
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
return toolResult(
|
|
297
|
+
routing.message,
|
|
298
|
+
{ ok: false, reason: 'human fail' },
|
|
299
|
+
{
|
|
300
|
+
isError: true,
|
|
301
|
+
},
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
const noted = await writeAvenNote(params.ref, routing.avenNote)
|
|
305
|
+
return toolResult(
|
|
306
|
+
`${routing.message}${noted ? '' : '\n(warning: the aven note write failed — record it manually)'}`,
|
|
307
|
+
{ ok: false, reason: 'human fail' },
|
|
308
|
+
{ isError: true },
|
|
309
|
+
)
|
|
310
|
+
},
|
|
311
|
+
})
|
|
312
|
+
}
|