@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,252 @@
|
|
|
1
|
+
// AIDEV-NOTE (PMR-PVT5 4.1): /flow-diagram command registration, mirroring
|
|
2
|
+
// flow/cost-command.ts. All data access is injected (FlowDiagramDeps) so the
|
|
3
|
+
// handler is testable purely; index.ts (4.2) owns the real dep wiring and
|
|
4
|
+
// filename/open side effects. Every degradation step aborts with a single
|
|
5
|
+
// warning notify — the written file path is always the deliverable.
|
|
6
|
+
|
|
7
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent'
|
|
8
|
+
import type { AssignmentRecord } from '@gtheys/pi-interactive-subagents'
|
|
9
|
+
import {
|
|
10
|
+
collectMainSessionFiles,
|
|
11
|
+
collectSpawnNotes,
|
|
12
|
+
parseSessionEntries,
|
|
13
|
+
} from '../flow/cost.ts'
|
|
14
|
+
import { parseRefKind } from '../flow/ref-kind.ts'
|
|
15
|
+
import { isValidRef } from '../herdr/viewer.ts'
|
|
16
|
+
import type { FlowRunEvent } from '../run-state.ts'
|
|
17
|
+
import { renderDiagramHtml } from './assemble.ts'
|
|
18
|
+
import { buildDiagram, selectSegment } from './translate.ts'
|
|
19
|
+
import type { HpRenderer } from './vendor/harness-profiler/load.ts'
|
|
20
|
+
|
|
21
|
+
export interface FlowDiagramDeps {
|
|
22
|
+
/** Journal events for a ref; null when no journal exists. */
|
|
23
|
+
readRunEvents: (ref: string) => Promise<FlowRunEvent[] | null>
|
|
24
|
+
/** Durable assignment records (subagents data dir). */
|
|
25
|
+
listAssignmentRecords: () => AssignmentRecord[]
|
|
26
|
+
/** Raw session jsonl body, or null when unreadable (counted, not fatal). */
|
|
27
|
+
readSessionFile: (file: string) => string | null
|
|
28
|
+
/** Vendored renderer; null aborts the command (fail-graceful load). */
|
|
29
|
+
loadRenderer: () => HpRenderer | null
|
|
30
|
+
/**
|
|
31
|
+
* Write the self-contained HTML as
|
|
32
|
+
* `pi-flow/diagrams/<ref>.run<k>.<YYYYMMDD-HHmmss>.html` under the agent
|
|
33
|
+
* dir; resolves the written file path.
|
|
34
|
+
*/
|
|
35
|
+
writeDiagram: (ref: string, runIndex: number, html: string) => Promise<string>
|
|
36
|
+
/** Best-effort open (xdg-open/open fallback); false = user opens by hand. */
|
|
37
|
+
openDiagram: (path: string) => Promise<boolean>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ParsedDiagramArgs =
|
|
41
|
+
| { kind: 'ok'; ref: string; run: number | null }
|
|
42
|
+
| { kind: 'help' }
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Filename stamp for diagram files: local-time `YYYYMMDD-HHmmss`. Pure so
|
|
46
|
+
* index.ts can reuse it in the writeDiagram wiring and tests can pin it.
|
|
47
|
+
*/
|
|
48
|
+
export function diagramStamp(ms: number): string {
|
|
49
|
+
const d = new Date(ms)
|
|
50
|
+
const pad = (n: number): string => String(n).padStart(2, '0')
|
|
51
|
+
const date = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}`
|
|
52
|
+
const time = `${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`
|
|
53
|
+
return `${date}-${time}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* First token = ref (aven:/jira: prefix stripped via parseRefKind), optional
|
|
58
|
+
* second token = 1-based positive-integer run selector; anything else = help.
|
|
59
|
+
*/
|
|
60
|
+
export function parseDiagramArgs(args: string): ParsedDiagramArgs {
|
|
61
|
+
const tokens = args
|
|
62
|
+
.trim()
|
|
63
|
+
.split(/\s+/)
|
|
64
|
+
.filter((t) => t.length > 0)
|
|
65
|
+
if (tokens.length === 0 || tokens.length > 2) return { kind: 'help' }
|
|
66
|
+
const kinded = parseRefKind(tokens[0] as string)
|
|
67
|
+
let ref: string
|
|
68
|
+
if (kinded.kind === 'jira') {
|
|
69
|
+
ref = kinded.jiraId
|
|
70
|
+
} else {
|
|
71
|
+
ref = kinded.ref
|
|
72
|
+
}
|
|
73
|
+
if (tokens.length === 1) {
|
|
74
|
+
return { kind: 'ok', ref, run: null }
|
|
75
|
+
}
|
|
76
|
+
const runToken = tokens[1] as string
|
|
77
|
+
if (!/^\d+$/.test(runToken)) return { kind: 'help' }
|
|
78
|
+
const run = Number.parseInt(runToken, 10)
|
|
79
|
+
if (run < 1) return { kind: 'help' }
|
|
80
|
+
return { kind: 'ok', ref, run }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* AIDEV-NOTE (PMR-PVT5): degradation seam. Ordering — help, invalid ref,
|
|
85
|
+
* renderer, journal, session reads, translate, write, open. Session files
|
|
86
|
+
* that fail to read are counted and summarized in ONE info notify (never one
|
|
87
|
+
* per file); a missing session only means that lane lacks token totals.
|
|
88
|
+
* AIDEV-NOTE (PMR-GPQJ): `events` is the SELECTED run segment, not the whole
|
|
89
|
+
* journal — reads and the unreadable count stay scoped to that run.
|
|
90
|
+
*/
|
|
91
|
+
async function collectSessionEntries(
|
|
92
|
+
ref: string,
|
|
93
|
+
segment: readonly FlowRunEvent[],
|
|
94
|
+
deps: FlowDiagramDeps,
|
|
95
|
+
notify: (message: string, level: 'info' | 'warning') => void,
|
|
96
|
+
): Promise<Map<string, readonly unknown[]>> {
|
|
97
|
+
const wanted = new Set<string>()
|
|
98
|
+
for (const file of collectMainSessionFiles(segment)) wanted.add(file)
|
|
99
|
+
const notes = collectSpawnNotes(segment)
|
|
100
|
+
for (const note of notes) {
|
|
101
|
+
if (note.sessionFile !== null) wanted.add(note.sessionFile)
|
|
102
|
+
}
|
|
103
|
+
const byChild = new Map<string, AssignmentRecord>()
|
|
104
|
+
for (const record of deps.listAssignmentRecords()) {
|
|
105
|
+
byChild.set(record.childId, record)
|
|
106
|
+
}
|
|
107
|
+
for (const note of notes) {
|
|
108
|
+
if (note.sessionFile !== null) continue
|
|
109
|
+
const record = byChild.get(note.childId)
|
|
110
|
+
if (record !== undefined && record.sessionFile.length > 0) {
|
|
111
|
+
wanted.add(record.sessionFile)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const entries = new Map<string, readonly unknown[]>()
|
|
115
|
+
let misses = 0
|
|
116
|
+
for (const file of wanted) {
|
|
117
|
+
const raw = deps.readSessionFile(file)
|
|
118
|
+
if (raw === null) {
|
|
119
|
+
misses += 1
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
entries.set(file, parseSessionEntries(raw))
|
|
123
|
+
}
|
|
124
|
+
if (misses > 0) {
|
|
125
|
+
notify(
|
|
126
|
+
`/flow-diagram ${ref}: ${misses} session files unreadable — lanes may lack token totals.`,
|
|
127
|
+
'info',
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
return entries
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function runFlowDiagram(
|
|
134
|
+
ref: string,
|
|
135
|
+
run: number | null,
|
|
136
|
+
deps: FlowDiagramDeps,
|
|
137
|
+
notify: (message: string, level: 'info' | 'warning') => void,
|
|
138
|
+
): Promise<void> {
|
|
139
|
+
const renderer = deps.loadRenderer()
|
|
140
|
+
if (renderer === null) {
|
|
141
|
+
notify(
|
|
142
|
+
`/flow-diagram ${ref}: harness-profiler renderer failed to load — aborting.`,
|
|
143
|
+
'warning',
|
|
144
|
+
)
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
const events = await deps.readRunEvents(ref)
|
|
148
|
+
if (events === null) {
|
|
149
|
+
notify(
|
|
150
|
+
`/flow-diagram ${ref}: no run journal found — nothing to diagram.`,
|
|
151
|
+
'warning',
|
|
152
|
+
)
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
// AIDEV-NOTE (PMR-GPQJ): select the run segment BEFORE collecting session
|
|
156
|
+
// entries so only the selected run's session files are read and the
|
|
157
|
+
// unreadable summary counts that subset (multi-run journals previously
|
|
158
|
+
// read every run's files journal-wide).
|
|
159
|
+
const selection = selectSegment(events, run)
|
|
160
|
+
if (selection.kind === 'out-of-range') {
|
|
161
|
+
notify(
|
|
162
|
+
`/flow-diagram ${ref}: run ${run} out of range — journal has ${selection.runCount} run(s).`,
|
|
163
|
+
'warning',
|
|
164
|
+
)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
if (selection.kind === 'no-records') {
|
|
168
|
+
notify(
|
|
169
|
+
`/flow-diagram ${ref}: nothing to diagram — no run segments or records in the journal.`,
|
|
170
|
+
'warning',
|
|
171
|
+
)
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
const sessionEntriesByFile = await collectSessionEntries(
|
|
175
|
+
ref,
|
|
176
|
+
selection.segment,
|
|
177
|
+
deps,
|
|
178
|
+
notify,
|
|
179
|
+
)
|
|
180
|
+
const result = buildDiagram(
|
|
181
|
+
ref,
|
|
182
|
+
run,
|
|
183
|
+
events,
|
|
184
|
+
deps.listAssignmentRecords(),
|
|
185
|
+
sessionEntriesByFile,
|
|
186
|
+
)
|
|
187
|
+
if (result.kind === 'out-of-range') {
|
|
188
|
+
notify(
|
|
189
|
+
`/flow-diagram ${ref}: run ${run} out of range — journal has ${result.runCount} run(s).`,
|
|
190
|
+
'warning',
|
|
191
|
+
)
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
if (result.kind === 'no-records') {
|
|
195
|
+
notify(
|
|
196
|
+
`/flow-diagram ${ref}: nothing to diagram — no run segments or records in the journal.`,
|
|
197
|
+
'warning',
|
|
198
|
+
)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
// AIDEV-NOTE (PMR-9CHQ): skipped-record degradation is ONE summary
|
|
202
|
+
// warning (same style as the unreadable-session seam), never a throw.
|
|
203
|
+
if (result.warnings.length > 0) {
|
|
204
|
+
notify(
|
|
205
|
+
`/flow-diagram ${ref}: ${result.warnings.length} record(s) skipped — unparseable or missing timestamps.`,
|
|
206
|
+
'warning',
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
const html = renderDiagramHtml(
|
|
210
|
+
renderer,
|
|
211
|
+
result.header,
|
|
212
|
+
result.records,
|
|
213
|
+
`${ref} run ${result.header.runIndex}`,
|
|
214
|
+
)
|
|
215
|
+
const path = await deps.writeDiagram(ref, result.header.runIndex, html)
|
|
216
|
+
const opened = await deps.openDiagram(path)
|
|
217
|
+
if (opened) {
|
|
218
|
+
notify(`/flow-diagram ${ref}: diagram written to ${path}`, 'info')
|
|
219
|
+
} else {
|
|
220
|
+
notify(`/flow-diagram ${ref}: open failed — diagram at ${path}`, 'warning')
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function registerFlowDiagramCommand(
|
|
225
|
+
pi: ExtensionAPI,
|
|
226
|
+
deps: FlowDiagramDeps,
|
|
227
|
+
): void {
|
|
228
|
+
pi.registerCommand('flow-diagram', {
|
|
229
|
+
description:
|
|
230
|
+
'Render the per-ticket flow timeline as a self-contained HTML sequence diagram. Usage: /flow-diagram <ref> [run]',
|
|
231
|
+
handler: async (args, ctx) => {
|
|
232
|
+
const parsed = parseDiagramArgs(args)
|
|
233
|
+
if (parsed.kind === 'help') {
|
|
234
|
+
ctx.ui.notify(
|
|
235
|
+
'Usage: /flow-diagram <ref> [run] — render the per-ticket flow timeline as a self-contained HTML sequence diagram.',
|
|
236
|
+
'info',
|
|
237
|
+
)
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
if (!isValidRef(parsed.ref)) {
|
|
241
|
+
ctx.ui.notify(
|
|
242
|
+
`/flow-diagram ${parsed.ref}: invalid ref (must match [A-Za-z0-9][A-Za-z0-9._-]{0,99}) — aborting.`,
|
|
243
|
+
'warning',
|
|
244
|
+
)
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
await runFlowDiagram(parsed.ref, parsed.run, deps, (message, level) => {
|
|
248
|
+
ctx.ui.notify(message, level)
|
|
249
|
+
})
|
|
250
|
+
},
|
|
251
|
+
})
|
|
252
|
+
}
|