@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,91 @@
|
|
|
1
|
+
// AIDEV-NOTE: shared label+metadata transition helper for /spec-review
|
|
2
|
+
// (PMR-MR36), designed for reuse by the follow-up flows (PMR-SE93, PMR-EZHA).
|
|
3
|
+
// Approving a spec pins plan-state=approved and moves it to todo so the plan
|
|
4
|
+
// implementation phase picks it up. The `plan` label is added ONLY for
|
|
5
|
+
// non-oneshot tickets: a oneshot-confirmed ticket with the plan label would
|
|
6
|
+
// misroute /implement onto the plan route with no children and no tree. aven
|
|
7
|
+
// edit errors print "Error: ..." possibly with exit 0 — failure detection is
|
|
8
|
+
// by output text ("updated <REF>" must appear on success), loud error result
|
|
9
|
+
// carries aven's raw output.
|
|
10
|
+
|
|
11
|
+
import type { AvenRunner } from '../aven/client.ts'
|
|
12
|
+
import { escapeRegExp } from './escape-regexp.ts'
|
|
13
|
+
|
|
14
|
+
export type ApproveResult =
|
|
15
|
+
| { kind: 'ok'; ref: string }
|
|
16
|
+
| { kind: 'error'; reason: string }
|
|
17
|
+
|
|
18
|
+
// AIDEV-NOTE: labels read via `aven show <ref> --json`; any failure (aven
|
|
19
|
+
// down, bad JSON) keeps the legacy `--label plan` behavior — the oneshot
|
|
20
|
+
// check is an omission optimization, not a new failure mode.
|
|
21
|
+
async function readLabels(
|
|
22
|
+
aven: AvenRunner,
|
|
23
|
+
ref: string,
|
|
24
|
+
workspace: string | undefined,
|
|
25
|
+
): Promise<string[] | null> {
|
|
26
|
+
const args = ['show', ref, '--json']
|
|
27
|
+
if (workspace !== undefined) {
|
|
28
|
+
args.push('--workspace', workspace)
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const { stdout, stderr } = await aven(args)
|
|
32
|
+
const failed =
|
|
33
|
+
/^(Error:|error\s)/m.test(stdout) || /^(Error:|error\s)/m.test(stderr)
|
|
34
|
+
if (failed) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
const parsed: unknown = JSON.parse(stdout)
|
|
38
|
+
if (
|
|
39
|
+
typeof parsed === 'object' &&
|
|
40
|
+
parsed !== null &&
|
|
41
|
+
Array.isArray((parsed as { labels?: unknown }).labels)
|
|
42
|
+
) {
|
|
43
|
+
return (parsed as { labels: unknown[] }).labels.filter(
|
|
44
|
+
(l): l is string => typeof l === 'string',
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
return null
|
|
48
|
+
} catch {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function approveSpec(
|
|
54
|
+
aven: AvenRunner,
|
|
55
|
+
ref: string,
|
|
56
|
+
opts: { workspace?: string } = {},
|
|
57
|
+
): Promise<ApproveResult> {
|
|
58
|
+
const labels = await readLabels(aven, ref, opts.workspace)
|
|
59
|
+
const isOneshot = labels?.includes('oneshot') === true
|
|
60
|
+
const args = ['edit', ref, '--metadata', 'plan-state=approved']
|
|
61
|
+
if (!isOneshot) {
|
|
62
|
+
args.push('--label', 'plan')
|
|
63
|
+
}
|
|
64
|
+
args.push('--status', 'todo')
|
|
65
|
+
if (opts.workspace !== undefined) {
|
|
66
|
+
args.push('--workspace', opts.workspace)
|
|
67
|
+
}
|
|
68
|
+
let stdout = ''
|
|
69
|
+
let stderr = ''
|
|
70
|
+
try {
|
|
71
|
+
const out = await aven(args)
|
|
72
|
+
stdout = out.stdout
|
|
73
|
+
stderr = out.stderr
|
|
74
|
+
} catch (error) {
|
|
75
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
76
|
+
return { kind: 'error', reason: `aven edit ${ref} failed: ${msg}` }
|
|
77
|
+
}
|
|
78
|
+
const updated = new RegExp(`^updated ${escapeRegExp(ref)}(\\s|$)`, 'm').test(
|
|
79
|
+
stdout,
|
|
80
|
+
)
|
|
81
|
+
if (!updated) {
|
|
82
|
+
const raw = [stdout.trim(), stderr.trim()]
|
|
83
|
+
.filter((s) => s !== '')
|
|
84
|
+
.join('\n')
|
|
85
|
+
return {
|
|
86
|
+
kind: 'error',
|
|
87
|
+
reason: `aven edit ${ref} did not report success: ${raw.slice(0, 300)}`,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { kind: 'ok', ref }
|
|
91
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// AIDEV-NOTE: argument parser for /spec-review (PMR-MR36). Pure module —
|
|
2
|
+
// tested without ctx. Bare invocation is the main path (picker over all
|
|
3
|
+
// specs in plan-state=review); `help` prints usage; `--workspace <name>` is
|
|
4
|
+
// the escape hatch for specs living in another aven workspace.
|
|
5
|
+
|
|
6
|
+
export type SpecReviewArgs =
|
|
7
|
+
| { kind: 'help' }
|
|
8
|
+
| { kind: 'ok'; workspace?: string }
|
|
9
|
+
|
|
10
|
+
export function parseSpecReviewArgs(args: string): SpecReviewArgs {
|
|
11
|
+
const parts = args
|
|
12
|
+
.trim()
|
|
13
|
+
.split(/\s+/)
|
|
14
|
+
.filter((p) => p !== '')
|
|
15
|
+
if (parts.length === 0) return { kind: 'ok' }
|
|
16
|
+
if (parts[0] === 'help') return { kind: 'help' }
|
|
17
|
+
if (parts[0] === '--workspace' && parts.length === 2) {
|
|
18
|
+
return { kind: 'ok', workspace: parts[1] }
|
|
19
|
+
}
|
|
20
|
+
return { kind: 'help' }
|
|
21
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// AIDEV-NOTE: aven query half of /spec-review (PMR-MR36). aven prints errors
|
|
2
|
+
// (unknown-metadata-field, unknown-ref, "error " prefixed lines) WITH EXIT 0,
|
|
3
|
+
// so every failure is detected by stdout text — never by exit code. Loud
|
|
4
|
+
// failure = an 'error' result carrying aven's raw output; never throw across
|
|
5
|
+
// the module boundary, never swallow. `aven list --json` omits metadata
|
|
6
|
+
// entirely on aven 0.1.39, so plan-path is read from `aven show <ref> --full`
|
|
7
|
+
// human text, trusting only `metadata field_id=... key=<k>` / value<<EOF
|
|
8
|
+
// blocks (description text may contain the words "plan-path").
|
|
9
|
+
|
|
10
|
+
import type { AvenRunner } from '../aven/client.ts'
|
|
11
|
+
import { escapeRegExp } from './escape-regexp.ts'
|
|
12
|
+
|
|
13
|
+
export interface SpecInReview {
|
|
14
|
+
ref: string
|
|
15
|
+
title: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type SpecListResult =
|
|
19
|
+
| { kind: 'ok'; specs: SpecInReview[] }
|
|
20
|
+
| { kind: 'error'; reason: string }
|
|
21
|
+
|
|
22
|
+
export type PlanPathResult =
|
|
23
|
+
| {
|
|
24
|
+
kind: 'found'
|
|
25
|
+
planPath: string
|
|
26
|
+
planState: string | null
|
|
27
|
+
}
|
|
28
|
+
| { kind: 'none' }
|
|
29
|
+
| { kind: 'error'; reason: string }
|
|
30
|
+
|
|
31
|
+
// AIDEV-NOTE: conservative extension of flow/jira-ref.ts detection. aven can
|
|
32
|
+
// fail with exit 0; classify by text and fail loud. unknown-metadata-field is
|
|
33
|
+
// NOT special-cased here: for plan-state=review the field should exist by the
|
|
34
|
+
// time /spec-review runs, so treat it as a real error rather than "empty".
|
|
35
|
+
// AIDEV-NOTE: exported for readPlanState (flow loop's awaiting-approval gate,
|
|
36
|
+
// PMR-W60H) — same parsing path, one metadata contract.
|
|
37
|
+
export function avenErrorText(stdout: string, stderr: string): string | null {
|
|
38
|
+
const lines = [...stdout.split('\n'), ...stderr.split('\n')]
|
|
39
|
+
const bad = lines.find((line) => /^(Error:|error\s)/.test(line.trim()))
|
|
40
|
+
if (bad !== undefined) {
|
|
41
|
+
return [stdout.trim(), stderr.trim()].filter((s) => s !== '').join('\n')
|
|
42
|
+
}
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function listSpecsInReview(
|
|
47
|
+
aven: AvenRunner,
|
|
48
|
+
opts: { project: string; workspace?: string },
|
|
49
|
+
): Promise<SpecListResult> {
|
|
50
|
+
const args = [
|
|
51
|
+
'list',
|
|
52
|
+
'--project',
|
|
53
|
+
opts.project,
|
|
54
|
+
'--metadata',
|
|
55
|
+
'plan-state=review',
|
|
56
|
+
'--open',
|
|
57
|
+
'--json',
|
|
58
|
+
]
|
|
59
|
+
if (opts.workspace !== undefined) {
|
|
60
|
+
args.push('--workspace', opts.workspace)
|
|
61
|
+
}
|
|
62
|
+
let stdout = ''
|
|
63
|
+
let stderr = ''
|
|
64
|
+
try {
|
|
65
|
+
const out = await aven(args)
|
|
66
|
+
stdout = out.stdout
|
|
67
|
+
stderr = out.stderr
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
70
|
+
return { kind: 'error', reason: `aven list failed: ${msg}` }
|
|
71
|
+
}
|
|
72
|
+
const failure = avenErrorText(stdout, stderr)
|
|
73
|
+
if (failure !== null) {
|
|
74
|
+
return { kind: 'error', reason: `aven list failed: ${failure}` }
|
|
75
|
+
}
|
|
76
|
+
let parsed: unknown
|
|
77
|
+
try {
|
|
78
|
+
parsed = JSON.parse(stdout)
|
|
79
|
+
} catch {
|
|
80
|
+
return {
|
|
81
|
+
kind: 'error',
|
|
82
|
+
reason: `aven list returned bad JSON: ${stdout.slice(0, 120)}`,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!Array.isArray(parsed)) {
|
|
86
|
+
return { kind: 'error', reason: 'aven list JSON was not an array' }
|
|
87
|
+
}
|
|
88
|
+
const specs: SpecInReview[] = parsed.flatMap((entry) => {
|
|
89
|
+
if (typeof entry !== 'object' || entry === null) return []
|
|
90
|
+
const ref = (entry as { ref?: unknown }).ref
|
|
91
|
+
if (typeof ref !== 'string' || ref === '') return []
|
|
92
|
+
const rawTitle = (entry as { title?: unknown }).title
|
|
93
|
+
const title = typeof rawTitle === 'string' ? rawTitle : ref
|
|
94
|
+
return [{ ref, title }]
|
|
95
|
+
})
|
|
96
|
+
return { kind: 'ok', specs }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// AIDEV-NOTE: only trust `metadata field_id=... key=<k>` blocks followed by a
|
|
100
|
+
// value<<EOF ... EOF heredoc; anything else in the output (including a
|
|
101
|
+
// description mentioning "plan-path") is ignored.
|
|
102
|
+
export function parseMetadataBlock(text: string, key: string): string | null {
|
|
103
|
+
const re = new RegExp(
|
|
104
|
+
`^metadata field_id=\\S+ key=${escapeRegExp(key)}$\\n^value<<EOF$\\n([\\s\\S]*?)\\n^EOF$`,
|
|
105
|
+
'm',
|
|
106
|
+
)
|
|
107
|
+
const match = re.exec(text)
|
|
108
|
+
if (match === null) return null
|
|
109
|
+
return match[1] ?? null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function readPlanPath(
|
|
113
|
+
aven: AvenRunner,
|
|
114
|
+
ref: string,
|
|
115
|
+
opts: { workspace?: string } = {},
|
|
116
|
+
): Promise<PlanPathResult> {
|
|
117
|
+
const args = ['show', ref, '--full']
|
|
118
|
+
// AIDEV-NOTE: PMR-MR36 fix round — the workspace must ride along with the
|
|
119
|
+
// per-ref query, or a cross-workspace pick resolves its plan path against
|
|
120
|
+
// the cwd-inferred workspace and fails.
|
|
121
|
+
if (opts.workspace !== undefined) {
|
|
122
|
+
args.push('--workspace', opts.workspace)
|
|
123
|
+
}
|
|
124
|
+
let stdout = ''
|
|
125
|
+
let stderr = ''
|
|
126
|
+
try {
|
|
127
|
+
const out = await aven(args)
|
|
128
|
+
stdout = out.stdout
|
|
129
|
+
stderr = out.stderr
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
132
|
+
return { kind: 'error', reason: `aven show failed: ${msg}` }
|
|
133
|
+
}
|
|
134
|
+
const failure = avenErrorText(stdout, stderr)
|
|
135
|
+
if (failure !== null) {
|
|
136
|
+
return { kind: 'error', reason: `aven show ${ref} failed: ${failure}` }
|
|
137
|
+
}
|
|
138
|
+
const planPath = parseMetadataBlock(stdout, 'plan-path')
|
|
139
|
+
if (planPath === null) return { kind: 'none' }
|
|
140
|
+
const planState = parseMetadataBlock(stdout, 'plan-state')
|
|
141
|
+
return { kind: 'found', planPath, planState }
|
|
142
|
+
}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// AIDEV-NOTE: PMR-T22H — /spec-review and /spec-publish command handlers,
|
|
2
|
+
// moved out of index.ts unchanged. /spec-review (PMR-MR36): ctx.ui.select is
|
|
3
|
+
// modal and blocks the handler, so the picker collects a BATCH and ONE
|
|
4
|
+
// combined sendUserMessage lands after the handler returns — review prompts
|
|
5
|
+
// never interleave. Repo name = basename of the git toplevel for the aven
|
|
6
|
+
// project lookup only; /spec-publish derives its publish `repo` from
|
|
7
|
+
// getRepoName (origin remote name) so the notes-root boundary matches the
|
|
8
|
+
// resolver-produced plan path in worktrees (PMR-HHS8 fix round 2).
|
|
9
|
+
// Approval is never done here: the injected prompt makes the session the
|
|
10
|
+
// reviewer and gates approval on the user's explicit "approve <REF>".
|
|
11
|
+
// PMR-DMHH: approval itself is recorded by the human via `/flow answer <ref>
|
|
12
|
+
// approve` (the receipt is the gate) — every picked ref is marked awaiting
|
|
13
|
+
// spec approval after the combined send, so recording the answer wakes this
|
|
14
|
+
// session (marker + wake), no spoken follow-up required.
|
|
15
|
+
// /spec-publish (PMR-MR36 subtask PMR-2D2X): shared publish for /spec-review
|
|
16
|
+
// approvals and feature-plan-aven sessions. Resolution + task text are pure
|
|
17
|
+
// (publish.ts); the actual git work runs in a subagent worker — push failure
|
|
18
|
+
// never rolls back an approval, it only notifies.
|
|
19
|
+
import { existsSync } from 'node:fs'
|
|
20
|
+
import path from 'node:path'
|
|
21
|
+
import type {
|
|
22
|
+
AgentToolResult,
|
|
23
|
+
ExtensionAPI,
|
|
24
|
+
ExtensionContext,
|
|
25
|
+
} from '@earendil-works/pi-coding-agent'
|
|
26
|
+
import { Type } from 'typebox'
|
|
27
|
+
import {
|
|
28
|
+
avenExec,
|
|
29
|
+
avenOverrideArg,
|
|
30
|
+
resolveSpecWorkspace,
|
|
31
|
+
} from '../aven/client.ts'
|
|
32
|
+
import { markAwaitingSpecApproval } from '../flow/awaiting-approval.ts'
|
|
33
|
+
import { getRepoName } from '../plan-tools/helpers.ts'
|
|
34
|
+
import { toolResult } from '../tools/result.ts'
|
|
35
|
+
import { parseSpecReviewArgs } from './args.ts'
|
|
36
|
+
import { listSpecsInReview, readPlanPath } from './aven-spec.ts'
|
|
37
|
+
import { openFileInPane } from './open-in-pane.ts'
|
|
38
|
+
import { pickSpecs } from './picker.ts'
|
|
39
|
+
import { buildReviewPrompt } from './prompt.ts'
|
|
40
|
+
import {
|
|
41
|
+
buildPublishWorkerTask,
|
|
42
|
+
isPublishSuccess,
|
|
43
|
+
resolvePublishRoot,
|
|
44
|
+
spawnPublishWorker,
|
|
45
|
+
} from './publish.ts'
|
|
46
|
+
import { parseSpecPublishArgs } from './publish-args.ts'
|
|
47
|
+
|
|
48
|
+
async function gitToplevel(pi: ExtensionAPI): Promise<string> {
|
|
49
|
+
const out = await pi.exec('git', ['rev-parse', '--show-toplevel'], {})
|
|
50
|
+
return out.stdout.trim()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SpecPublishOutcome {
|
|
54
|
+
ok: boolean
|
|
55
|
+
text: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// AIDEV-NOTE: PMR-44XX — shared publish path for /spec-publish and the
|
|
59
|
+
// spec_publish tool: same workspace pin, plan-path validation, root
|
|
60
|
+
// resolution, worker task, and PUBLISH OK gate. Validation errors carry the
|
|
61
|
+
// caller's prefix; worker outcomes stay verbatim for the existing command UI.
|
|
62
|
+
async function runSpecPublish(
|
|
63
|
+
pi: ExtensionAPI,
|
|
64
|
+
ctx: ExtensionContext,
|
|
65
|
+
params: { ref: string; workspace?: string },
|
|
66
|
+
errorPrefix: string,
|
|
67
|
+
signal?: AbortSignal,
|
|
68
|
+
): Promise<SpecPublishOutcome> {
|
|
69
|
+
function failure(text: string): SpecPublishOutcome {
|
|
70
|
+
return { ok: false, text: `${errorPrefix}: ${text}` }
|
|
71
|
+
}
|
|
72
|
+
let toplevel = ''
|
|
73
|
+
try {
|
|
74
|
+
toplevel = await gitToplevel(pi)
|
|
75
|
+
} catch (error) {
|
|
76
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
77
|
+
return failure(`not a git repo (${msg})`)
|
|
78
|
+
}
|
|
79
|
+
// AIDEV-NOTE: PMR-MR36 fix round — the plan-path query must run in
|
|
80
|
+
// the same workspace the ref lives in (flag > config override > per-ref
|
|
81
|
+
// resolution); a resolution failure stops the publish, never falls
|
|
82
|
+
// back to the cwd-inferred workspace silently.
|
|
83
|
+
let workspace: string | undefined
|
|
84
|
+
try {
|
|
85
|
+
workspace = await resolveSpecWorkspace(params.workspace, params.ref)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
88
|
+
return failure(msg)
|
|
89
|
+
}
|
|
90
|
+
const plan = await readPlanPath(avenExec, params.ref, { workspace })
|
|
91
|
+
if (plan.kind === 'error') {
|
|
92
|
+
return failure(plan.reason)
|
|
93
|
+
}
|
|
94
|
+
if (plan.kind === 'none') {
|
|
95
|
+
return failure(`${params.ref} has no plan-path metadata`)
|
|
96
|
+
}
|
|
97
|
+
if (!existsSync(plan.planPath)) {
|
|
98
|
+
return failure(`plan file missing: ${plan.planPath}`)
|
|
99
|
+
}
|
|
100
|
+
// AIDEV-NOTE: PMR-HHS8 fix round 2 — the publish `repo` MUST come from
|
|
101
|
+
// getRepoName (origin remote name, toplevel basename only as fallback), the
|
|
102
|
+
// SAME source the plan-path resolvers use. path.basename(toplevel) is the
|
|
103
|
+
// worktree dir name in a herdr worktree (e.g. `blog-monetize-oss` for the
|
|
104
|
+
// `blog` repo), so resolvePublishRoot's `<root>/<repo>/` boundary check
|
|
105
|
+
// would not match the resolver-produced plan path and would silently
|
|
106
|
+
// downgrade to the project-repo fallback — the worker then `git add`s a file
|
|
107
|
+
// outside that repo (exit 128) and reports a bogus "notes root was unset".
|
|
108
|
+
// Pinned by test/spec-publish-tool.test.ts. The aven `project` lookup in the
|
|
109
|
+
// /spec-review handler below stays on path.basename(toplevel): that is aven
|
|
110
|
+
// project naming, not notes-root layout.
|
|
111
|
+
const publishRepo = await getRepoName(pi)
|
|
112
|
+
const resolved = resolvePublishRoot({
|
|
113
|
+
repo: publishRepo,
|
|
114
|
+
planPath: plan.planPath,
|
|
115
|
+
toplevel,
|
|
116
|
+
})
|
|
117
|
+
if (resolved.kind === 'error') {
|
|
118
|
+
return failure(resolved.reason)
|
|
119
|
+
}
|
|
120
|
+
const outcome = await spawnPublishWorker(ctx, {
|
|
121
|
+
ref: params.ref,
|
|
122
|
+
repo: publishRepo,
|
|
123
|
+
root: resolved.root,
|
|
124
|
+
planFile: resolved.planFile,
|
|
125
|
+
name: `spec-publish: ${params.ref}`,
|
|
126
|
+
prefix: errorPrefix,
|
|
127
|
+
signal,
|
|
128
|
+
cwd: toplevel,
|
|
129
|
+
task: buildPublishWorkerTask({
|
|
130
|
+
ref: params.ref,
|
|
131
|
+
repo: publishRepo,
|
|
132
|
+
root: resolved.root,
|
|
133
|
+
planFile: resolved.planFile,
|
|
134
|
+
isFallback: resolved.isFallback,
|
|
135
|
+
}),
|
|
136
|
+
})
|
|
137
|
+
// AIDEV-NOTE: success requires the PUBLISH OK marker from the worker
|
|
138
|
+
// contract — exit-0 alone was a false positive (PMR-MR36 fix round);
|
|
139
|
+
// exit-0 without the marker is a warning, not a success.
|
|
140
|
+
return { ok: isPublishSuccess(outcome), text: outcome }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// AIDEV-NOTE: PMR-44XX — result mapping for the spec_publish tool: only a
|
|
144
|
+
// PUBLISH OK outcome is a success; everything else (validation failure,
|
|
145
|
+
// worker failure, spawn/manual-fallback output) is a loud tool error.
|
|
146
|
+
export function specPublishToolResult(
|
|
147
|
+
result: SpecPublishOutcome,
|
|
148
|
+
): AgentToolResult<{ ok: boolean; reason: string }> {
|
|
149
|
+
if (result.ok) {
|
|
150
|
+
return toolResult(result.text, { ok: true, reason: '' })
|
|
151
|
+
}
|
|
152
|
+
return toolResult(
|
|
153
|
+
result.text,
|
|
154
|
+
{ ok: false, reason: result.text },
|
|
155
|
+
{ isError: true },
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function registerSpecCommands(pi: ExtensionAPI): void {
|
|
160
|
+
pi.registerCommand('spec-review', {
|
|
161
|
+
description:
|
|
162
|
+
'Review specs in plan-state=review. Usage: /spec-review [--workspace <name>]',
|
|
163
|
+
handler: async (args, ctx) => {
|
|
164
|
+
const parsed = parseSpecReviewArgs(args)
|
|
165
|
+
if (parsed.kind === 'help') {
|
|
166
|
+
ctx.ui.notify(
|
|
167
|
+
'Usage: /spec-review [--workspace <name>] | /spec-review help',
|
|
168
|
+
'info',
|
|
169
|
+
)
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
let toplevel = ''
|
|
173
|
+
try {
|
|
174
|
+
toplevel = await gitToplevel(pi)
|
|
175
|
+
} catch (error) {
|
|
176
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
177
|
+
ctx.ui.notify(`/spec-review: not a git repo (${msg})`, 'warning')
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
const project = path.basename(toplevel)
|
|
181
|
+
// AIDEV-NOTE: PMR-MR36 fix round — the same resolved workspace feeds
|
|
182
|
+
// both the list and every per-pick readPlanPath. The list has no ref
|
|
183
|
+
// yet, so only the flag and the config override apply there; per-ref
|
|
184
|
+
// resolution joins at the per-pick readPlanPath.
|
|
185
|
+
const override = await avenOverrideArg()
|
|
186
|
+
const listWorkspace = parsed.workspace ?? override[1]
|
|
187
|
+
const listed = await listSpecsInReview(avenExec, {
|
|
188
|
+
project,
|
|
189
|
+
workspace: listWorkspace,
|
|
190
|
+
})
|
|
191
|
+
if (listed.kind === 'error') {
|
|
192
|
+
ctx.ui.notify(`/spec-review: ${listed.reason}`, 'warning')
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
if (listed.specs.length === 0) {
|
|
196
|
+
ctx.ui.notify('no specs awaiting review', 'info')
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
const outcome = await pickSpecs({
|
|
200
|
+
specs: listed.specs,
|
|
201
|
+
select: (title, options) => ctx.ui.select(title, options),
|
|
202
|
+
resolvePlanPath: async (ref) => {
|
|
203
|
+
let workspace: string | undefined
|
|
204
|
+
try {
|
|
205
|
+
workspace = await resolveSpecWorkspace(parsed.workspace, ref)
|
|
206
|
+
} catch (error) {
|
|
207
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
208
|
+
return { ok: false, reason: `${ref}: ${msg}` }
|
|
209
|
+
}
|
|
210
|
+
const plan = await readPlanPath(avenExec, ref, { workspace })
|
|
211
|
+
if (plan.kind === 'error') return { ok: false, reason: plan.reason }
|
|
212
|
+
if (plan.kind === 'none') {
|
|
213
|
+
return {
|
|
214
|
+
ok: false,
|
|
215
|
+
reason: `${ref}: no plan-path metadata — skipped`,
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (!existsSync(plan.planPath)) {
|
|
219
|
+
return {
|
|
220
|
+
ok: false,
|
|
221
|
+
reason: `${ref}: plan file missing: ${plan.planPath}`,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return { ok: true, planPath: plan.planPath }
|
|
225
|
+
},
|
|
226
|
+
onPicked: async (spec) => {
|
|
227
|
+
const pane = await openFileInPane(pi, spec.planPath)
|
|
228
|
+
if (!pane.details.ok) {
|
|
229
|
+
const text = pane.content.map((c) => c.text).join('\n')
|
|
230
|
+
ctx.ui.notify(`/spec-review: ${text}`, 'warning')
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
onSkipped: (spec, reason) => {
|
|
234
|
+
ctx.ui.notify(
|
|
235
|
+
`/spec-review skipped ${spec.ref}: ${reason}`,
|
|
236
|
+
'warning',
|
|
237
|
+
)
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
if (outcome.kind === 'error') {
|
|
241
|
+
ctx.ui.notify(`/spec-review: ${outcome.reason}`, 'warning')
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
if (outcome.picked.length === 0) {
|
|
245
|
+
ctx.ui.notify('no specs selected for review', 'info')
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
pi.sendUserMessage(buildReviewPrompt(outcome.picked))
|
|
249
|
+
// AIDEV-NOTE: PMR-DMHH — every reviewed ref arms the standalone
|
|
250
|
+
// awaiting marker; a later `/flow answer <ref> approve` for any of
|
|
251
|
+
// them plain-wakes this session (receipt-gated, human-only). Marked
|
|
252
|
+
// after the combined send so a send throw never arms a ref whose
|
|
253
|
+
// review prompt never landed; the single combined send above is
|
|
254
|
+
// untouched (review prompts never interleave).
|
|
255
|
+
for (const spec of outcome.picked) {
|
|
256
|
+
markAwaitingSpecApproval(spec.ref)
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
pi.registerCommand('spec-publish', {
|
|
262
|
+
description:
|
|
263
|
+
'Publish an approved spec plan. Usage: /spec-publish <REF> [--workspace <name>]',
|
|
264
|
+
handler: async (args, ctx) => {
|
|
265
|
+
const parsed = parseSpecPublishArgs(args)
|
|
266
|
+
if (parsed.kind === 'help') {
|
|
267
|
+
ctx.ui.notify(
|
|
268
|
+
'Usage: /spec-publish <REF> [--workspace <name>] | /spec-publish help',
|
|
269
|
+
'info',
|
|
270
|
+
)
|
|
271
|
+
return
|
|
272
|
+
}
|
|
273
|
+
const result = await runSpecPublish(pi, ctx, parsed, '/spec-publish')
|
|
274
|
+
let severity: 'info' | 'warning' = 'info'
|
|
275
|
+
if (!result.ok) severity = 'warning'
|
|
276
|
+
ctx.ui.notify(result.text, severity)
|
|
277
|
+
},
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
// AIDEV-NOTE: PMR-44XX — agent-callable form of /spec-publish. Both
|
|
281
|
+
// entrypoints share runSpecPublish (same resolution, same worker, same
|
|
282
|
+
// PUBLISH OK gate); only the result shaping differs (notify vs tool error).
|
|
283
|
+
pi.registerTool({
|
|
284
|
+
name: 'spec_publish',
|
|
285
|
+
label: 'spec publish',
|
|
286
|
+
description:
|
|
287
|
+
'Publish an approved spec plan (agent-callable /spec-publish): resolves the aven workspace and plan-path metadata, verifies the plan file, resolves the publish root (PERSONAL_FEATURES / LLM_NOTES_ROOT / project-repo fallback), and spawns a git publish worker (fetch, pull --ff-only, add ONLY the plan file, commit, push).',
|
|
288
|
+
promptSnippet:
|
|
289
|
+
'Publish an approved spec plan — call after spec_approve instead of running the /spec-publish command.',
|
|
290
|
+
promptGuidelines: [
|
|
291
|
+
'Only call spec_publish for a ref the user asked to publish (normally right after spec_approve returns ok).',
|
|
292
|
+
'On a tool error, report the reason to the user — never retry with raw git commands in the notes repo.',
|
|
293
|
+
],
|
|
294
|
+
parameters: Type.Object({
|
|
295
|
+
ref: Type.String({ description: 'Aven ticket ref, e.g. PMR-ABC1' }),
|
|
296
|
+
workspace: Type.Optional(
|
|
297
|
+
Type.String({
|
|
298
|
+
description:
|
|
299
|
+
'Aven workspace name — only when the spec lives outside the default workspace; normally omitted (config/per-ref resolution applies)',
|
|
300
|
+
}),
|
|
301
|
+
),
|
|
302
|
+
}),
|
|
303
|
+
async execute(
|
|
304
|
+
_toolCallId: string,
|
|
305
|
+
params: { ref: string; workspace?: string },
|
|
306
|
+
signal: AbortSignal | undefined,
|
|
307
|
+
_onUpdate: unknown,
|
|
308
|
+
ctx: ExtensionContext,
|
|
309
|
+
): Promise<AgentToolResult<{ ok: boolean; reason: string }>> {
|
|
310
|
+
return specPublishToolResult(
|
|
311
|
+
await runSpecPublish(pi, ctx, params, 'spec_publish', signal),
|
|
312
|
+
)
|
|
313
|
+
},
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
// AIDEV-NOTE: PMR-XCA9 — /review-spec moved from pi-planning's
|
|
317
|
+
// plan-tools/index.ts when the package was absorbed into pi-flow.
|
|
318
|
+
pi.registerCommand('review-spec', {
|
|
319
|
+
description: 'Open a spec/plan file with nvim in a herdr review pane',
|
|
320
|
+
handler: async (args, ctx) => {
|
|
321
|
+
const path = args.trim()
|
|
322
|
+
if (!path) {
|
|
323
|
+
ctx.ui.notify('Usage: /review-spec <path>', 'warning')
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const result = await openFileInPane(pi, path)
|
|
328
|
+
const text = result.content[0]?.text ?? ''
|
|
329
|
+
if (result.details.ok) {
|
|
330
|
+
ctx.ui.notify(text, 'info')
|
|
331
|
+
} else {
|
|
332
|
+
ctx.ui.notify(text, 'error')
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
})
|
|
336
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// AIDEV-NOTE: escape user-influenced strings before RegExp interpolation so
|
|
2
|
+
// metacharacters stay literal. Standard idiom; kept local to pi-flow (no
|
|
3
|
+
// cross-package imports allowed).
|
|
4
|
+
|
|
5
|
+
export function escapeRegExp(value: string): string {
|
|
6
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
7
|
+
}
|