@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,66 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
|
|
5
|
+
// AIDEV-NOTE: Narrow structural surface of the vendored harness-profiler
|
|
6
|
+
// renderer we actually consume. Do not widen without need.
|
|
7
|
+
export interface HpRenderer {
|
|
8
|
+
renderHtml(session: { id: string; records: readonly unknown[] }): string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// AIDEV-NOTE: `hp.js` is byte-pinned (sha256 in test/vendor.test.ts) and must
|
|
12
|
+
// never be edited — it is a vendored CJS copy. We execute it via a manual CJS
|
|
13
|
+
// wrapper instead of createRequire because the package is `"type": "module"`
|
|
14
|
+
// and Node would otherwise parse the vendored `.js` file as ESM, breaking its
|
|
15
|
+
// internal `require('fs')` calls (Node 22+ require(esm)). view.html must sit
|
|
16
|
+
// next to hp.js (renderHtml reads it from the injected __dirname). Any change
|
|
17
|
+
// goes through the re-vendoring steps in PIN.md.
|
|
18
|
+
const HP_JS_FILENAME = 'hp.js'
|
|
19
|
+
|
|
20
|
+
function loadHpFile(hpPath: string, dir: string): HpRenderer {
|
|
21
|
+
const raw = readFileSync(hpPath, 'utf8')
|
|
22
|
+
let source = raw
|
|
23
|
+
if (raw.startsWith('#!')) {
|
|
24
|
+
source = raw.slice(raw.indexOf('\n') + 1)
|
|
25
|
+
}
|
|
26
|
+
const require = createRequire(import.meta.url)
|
|
27
|
+
const module = { exports: {} as Record<string, unknown> }
|
|
28
|
+
const compiled = new Function(
|
|
29
|
+
'require',
|
|
30
|
+
'module',
|
|
31
|
+
'exports',
|
|
32
|
+
'__dirname',
|
|
33
|
+
'__filename',
|
|
34
|
+
source,
|
|
35
|
+
)
|
|
36
|
+
compiled(require, module, module.exports, dir, hpPath)
|
|
37
|
+
const hp = module.exports
|
|
38
|
+
if (
|
|
39
|
+
typeof hp !== 'object' ||
|
|
40
|
+
hp === null ||
|
|
41
|
+
typeof hp.renderHtml !== 'function'
|
|
42
|
+
) {
|
|
43
|
+
throw new Error('hp.js did not export a renderHtml function')
|
|
44
|
+
}
|
|
45
|
+
const render = hp.renderHtml as HpRenderer['renderHtml']
|
|
46
|
+
return { renderHtml: render }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function loadHpRendererFrom(dir: string): HpRenderer | null {
|
|
50
|
+
try {
|
|
51
|
+
return loadHpFile(join(dir, HP_JS_FILENAME), dir)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
let detail = String(error)
|
|
54
|
+
if (error instanceof Error) {
|
|
55
|
+
detail = error.message
|
|
56
|
+
}
|
|
57
|
+
console.warn(
|
|
58
|
+
`[pi-flow] flow-diagram: vendored harness-profiler renderer failed to load: ${detail}`,
|
|
59
|
+
)
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function loadHpRenderer(): HpRenderer | null {
|
|
65
|
+
return loadHpRendererFrom(import.meta.dirname)
|
|
66
|
+
}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
3
|
+
<title>Harness trace</title>
|
|
4
|
+
<!-- Written by harness-profiler (`hp tree --format html`). Self-contained: no network, works from file://. -->
|
|
5
|
+
<style>
|
|
6
|
+
:root { --bg:#f7f7f5; --fg:#1d2329; --muted:#66707a; --line:#dcdfe2; --panel:#fff; --track:#f1f2f0; --fresh:#8d969e;
|
|
7
|
+
--c0:#c55e5d; --c1:#2f7f86; --c2:#b07d1f; --c3:#6c58b5; --c4:#3f8a4a; --c5:#b0517f; --c6:#3d6fb3; --c7:#8a6a4f;
|
|
8
|
+
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; --sans: system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
9
|
+
@media (prefers-color-scheme: dark) { :root { --bg:#14181c; --fg:#e2e6ea; --muted:#9aa4ad; --line:#2b3238; --panel:#1b2025; --track:#20262b; --fresh:#79828a;
|
|
10
|
+
--c0:#e07d7b; --c1:#4fb0b8; --c2:#d6a542; --c3:#9b89e0; --c4:#6cc07a; --c5:#dd7fae; --c6:#6f9ee0; --c7:#c29a76; color-scheme: dark; } }
|
|
11
|
+
body { margin:0; background:var(--bg); color:var(--fg); font:14px/1.5 var(--sans); padding:24px max(16px, 3vw); }
|
|
12
|
+
h1 { font-size:18px; margin:0 0 2px; } h2 { font-size:14px; margin:22px 0 8px; }
|
|
13
|
+
.sub { color:var(--muted); font:12px var(--mono); margin-bottom:10px; }
|
|
14
|
+
.intro { max-width:760px; margin:0 0 14px; color:var(--fg); }
|
|
15
|
+
.intro summary { cursor:pointer; color:var(--muted); font-size:12px; }
|
|
16
|
+
.intro p { margin:6px 0 0; }
|
|
17
|
+
.chip { width:12px; height:12px; border-radius:3px; display:inline-block; flex:none; align-self:center; }
|
|
18
|
+
.symbols { display:flex; flex-wrap:wrap; gap:6px 20px; font-size:12px; color:var(--muted); margin:0 0 14px; }
|
|
19
|
+
.symbols span { display:inline-flex; align-items:center; gap:6px; }
|
|
20
|
+
.panel { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:12px; overflow-x:auto; }
|
|
21
|
+
svg { display:block; } svg text { font:12px var(--sans); fill:var(--fg); } svg .muted { fill:var(--muted); font-size:11px; }
|
|
22
|
+
svg .head { fill:#fff; font-weight:600; } svg .head.sub { font-weight:400; font-size:11px; fill-opacity:.9; } svg .head.chip { font-size:11px; } svg .mono { font-family:var(--mono); } svg .failtext { fill:var(--c0); font-weight:600; }
|
|
23
|
+
svg .kind { fill:var(--muted); font-weight:400; } svg .spent text { font-weight:600; } svg .spent text.kind { font-weight:400; }
|
|
24
|
+
svg .hit { cursor:pointer; } svg .hit:hover rect, svg .hit:hover path { stroke:var(--fg); stroke-width:1.5; }
|
|
25
|
+
svg .flabel { font:11px var(--sans); fill:#fff; pointer-events:none; } svg .failed rect { fill-opacity:.4; } svg .failed .flabel { fill:var(--fg); }
|
|
26
|
+
svg .spawn rect { stroke:var(--panel); stroke-width:1; }
|
|
27
|
+
.toolbar { margin:0 0 8px; display:flex; align-items:center; gap:16px; font-size:13px; color:var(--muted); }
|
|
28
|
+
.tree { font:13px/1.45 var(--mono); }
|
|
29
|
+
.row, .thead { display:grid; grid-template-columns:8ch 7ch 66px 6.5ch 7.5ch 6.5ch minmax(0, 1fr); column-gap:10px; align-items:baseline; padding:3px 6px; border-radius:4px; }
|
|
30
|
+
.row { cursor:pointer; } .row.mark { cursor:default; } .tree .muted { color:var(--muted); } .thead { color:var(--muted); font-size:12px; border-bottom:1px solid var(--line); border-radius:0; margin-bottom:2px; }
|
|
31
|
+
.num { text-align:right; color:var(--muted); } .bar { height:6px; align-self:center; display:flex; } .bar i { height:6px; border-radius:2px; }
|
|
32
|
+
.call { display:flex; gap:8px; align-items:baseline; min-width:0; }
|
|
33
|
+
.row:hover, .row.sel { background:color-mix(in srgb, var(--fg) 7%, transparent); }
|
|
34
|
+
.call > * { flex:none; } .row .words, .row .gist, .mark { color:var(--muted); } .row .fail { color:var(--c0); font-weight:600; }
|
|
35
|
+
.row .gist { flex:1 1 0; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
36
|
+
.detail { margin:2px 0 8px; padding:8px 10px; border-left:3px solid var(--line); white-space:pre-wrap; word-break:break-word; }
|
|
37
|
+
.detail b { color:var(--muted); font-weight:500; display:inline-block; min-width:64px; }
|
|
38
|
+
</style>
|
|
39
|
+
<!-- pi-flow fork: ticket header band CSS (PMR-57HF); removed on re-vendor -->
|
|
40
|
+
<style>
|
|
41
|
+
#flow-header { font:12px var(--mono); color:var(--muted); margin:0 0 12px; display:flex; flex-wrap:wrap; gap:2px 18px; }
|
|
42
|
+
#flow-header b { color:var(--fg); font-weight:500; }
|
|
43
|
+
#flow-header a { color:inherit; }
|
|
44
|
+
</style>
|
|
45
|
+
<!-- pi-flow fork: end header CSS --></head><body>
|
|
46
|
+
<h1>Session <span id="sid"></span></h1>
|
|
47
|
+
<div class="sub" id="subline"></div>
|
|
48
|
+
<!-- pi-flow fork: ticket header band (PMR-57HF); filled by renderFlowHeader() below -->
|
|
49
|
+
<div id="flow-header" hidden></div>
|
|
50
|
+
<!-- pi-flow fork: end header band -->
|
|
51
|
+
<details class="intro"><summary>How to read this</summary><p>A sequence diagram of the session. Each vertical bar is one <b>context</b>: a conversation history the model reads. A Skill or Agent call that opens a new context is a message to a new bar, and the dashed message back carries its result. A new context starts with its prompt only and gets a color of its own; one that starts with a copy of its parent's history says so and keeps the parent's color. Rows are in time order, not to scale. To save width, a column holds one context at a time: when a context ends, a later one can reuse its column, so five runs of the same skill one after another sit in one column as five bars. Such a column's header is an outline with one chip per context, in time order and in the color of its bar; a chip without a name repeats the name before it. Next to the top of a context's bar are the tokens it spent over all its model calls, each of which sends the whole history again: new input, input read from the prompt cache (far cheaper), and output. Hover for the exact numbers. Click a message to see the call's arguments and result.</p>
|
|
52
|
+
<div class="symbols" style="margin-top:8px">
|
|
53
|
+
<span><svg width="34" height="12"><line x1="0" x2="26" y1="6" y2="6" stroke="var(--c0)" stroke-width="2"/><path d="M24 1 L34 6 L24 11 z" fill="var(--c0)"/></svg>call that starts a context</span>
|
|
54
|
+
<span><svg width="34" height="12"><line x1="0" x2="32" y1="6" y2="6" stroke="var(--c0)" stroke-width="2"/><path d="M24 1 L34 6 L24 11" fill="none" stroke="var(--c0)" stroke-width="2"/></svg>one that runs in the background</span>
|
|
55
|
+
<span><svg width="34" height="12"><line x1="0" x2="30" y1="6" y2="6" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="5 4"/><path d="M26 1 L34 6 L26 11" fill="none" stroke="var(--muted)" stroke-width="1.5"/></svg>return with the result</span>
|
|
56
|
+
<span><svg width="14" height="14"><path d="M7 1 l6 6 l-6 6 l-6 -6 z" fill="var(--c0)"/></svg>skill loaded inline: its text joins this context; several in a row share one diamond, click it to list them</span>
|
|
57
|
+
<span><svg width="26" height="14"><rect x="1" y="1" width="24" height="12" fill="none" stroke="var(--fg)" stroke-width="1.5"/></svg>compacted: history replaced by a summary</span>
|
|
58
|
+
<span><svg width="10" height="16"><rect x="0" y="0" width="10" height="16" rx="2" fill="var(--c0)" fill-opacity=".85"/></svg>context at work</span>
|
|
59
|
+
</div></details>
|
|
60
|
+
|
|
61
|
+
<div class="toolbar"><label><input type="checkbox" id="all"> every tool call</label><span>Without it: skills, subagents and compactions, like <code>harness-profiler tree</code>.</span></div>
|
|
62
|
+
<div class="panel"><svg id="tl" role="img" aria-label="Sequence diagram, one lifeline per context"></svg></div>
|
|
63
|
+
<h2>Call tree</h2>
|
|
64
|
+
<div class="tree" id="tree"></div>
|
|
65
|
+
<script>
|
|
66
|
+
'use strict';
|
|
67
|
+
const D = /*DATA*/null;
|
|
68
|
+
const PALETTE = 8;
|
|
69
|
+
const SEQ_GUTTER = 130, SEQ_RIGHT = 120, SEQ_COL = 230, SEQ_HEAD = 54, SEQ_ROW = 40, CHAR_W = 6.6;
|
|
70
|
+
// A context's token counts take three text rows below its call (y to y + 40);
|
|
71
|
+
// the next row's label starts 17 px above its line, so the row after such a
|
|
72
|
+
// call moves down to y + 62 and nothing ever draws over the counts.
|
|
73
|
+
const SEQ_SPENT_ROW = 62, LABEL_PAD = 12;
|
|
74
|
+
const esc = (t) => String(t).replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[ch]));
|
|
75
|
+
const clip = (t, n) => (t.length > n ? t.slice(0, n - 1) + '…' : t);
|
|
76
|
+
// A background call with no end recorded yet has no duration to show.
|
|
77
|
+
const took = (c) => (c.running ? 'running' : dur(c.dur));
|
|
78
|
+
const dur = (ms) => (ms < 1000 ? `${ms} ms` : Math.round(ms / 100) < 100 ? `${(Math.round(ms / 100) / 10).toFixed(1)} s` : `${Math.round(ms / 1000)} s`);
|
|
79
|
+
const tok = (n) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : `${n}`) + ' tok';
|
|
80
|
+
const count = (n) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : `${n}`);
|
|
81
|
+
const modelCalls = (n) => `${n} model call${n === 1 ? '' : 's'}`;
|
|
82
|
+
const spentTip = (c) => `${c.label}: ${modelCalls(c.spent.calls)}, each sending the context's whole history again.\n`
|
|
83
|
+
+ `${c.spent.new} new input tokens (plain input and cache writes)\n${c.spent.cached} read from the prompt cache\n${c.spent.out} output tokens\n`
|
|
84
|
+
+ 'A cache read reuses work the model already did for that prefix, so it costs less than new input; output costs the most.';
|
|
85
|
+
const spentOf = (id) => (byId.get(id) || {}).spent;
|
|
86
|
+
const clock = (t) => new Date(t).toISOString().slice(11, 19);
|
|
87
|
+
const KIND_WORDS = { Skill: 'skill', Agent: 'agent' };
|
|
88
|
+
const kindWord = (tool) => KIND_WORDS[tool] || tool;
|
|
89
|
+
// The name leads and the kind follows, quieter: review (skill).
|
|
90
|
+
const label = (tool, name) => (name ? `${name} (${kindWord(tool)})` : kindWord(tool));
|
|
91
|
+
const short = (id) => (id === 'main' ? 'main' : id.slice(0, 6));
|
|
92
|
+
const byId = new Map(D.contexts.map((c) => [c.id, c]));
|
|
93
|
+
const callOf = new Map(D.calls.map((c, i) => [c.child, i]).filter(([child]) => child));
|
|
94
|
+
const order = new Map(D.contexts.map((c, i) => [c.id, i]));
|
|
95
|
+
const color = (id) => `var(--c${(byId.get(id) ? byId.get(id).hue : 0) % PALETTE})`;
|
|
96
|
+
const css = (v) => getComputedStyle(document.documentElement).getPropertyValue(v).trim();
|
|
97
|
+
const kindText = (c) => c.kind === 'root' ? 'the session itself'
|
|
98
|
+
: c.kind === 'copy' ? `starts with a copy of ${byId.get(c.parent) ? byId.get(c.parent).label : 'its parent'}'s history`
|
|
99
|
+
: c.parent ? '' : 'its parent call was not recorded';
|
|
100
|
+
const gist = (c) => [c.args && c.args !== c.name ? `(${c.args})` : '', c.result && (c.child || !c.ok) ? `-> ${c.result}` : ''].filter(Boolean).join(' ');
|
|
101
|
+
const words = (call) => {
|
|
102
|
+
if (!call.child) return call.tool === 'Skill' ? 'inline' : '';
|
|
103
|
+
const child = byId.get(call.child);
|
|
104
|
+
return `new context ${short(call.child)}${child && child.kind === 'copy' ? `, copy of ${short(call.ctx)}` : ''}${call.background ? ', background' : ''}`;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
document.getElementById('sid').textContent = D.session.slice(0, 8);
|
|
108
|
+
const starts = D.calls.map((c) => c.start).concat(D.markers.map((m) => m.at));
|
|
109
|
+
const first = Math.min(...starts);
|
|
110
|
+
document.getElementById('subline').textContent = [
|
|
111
|
+
Number.isFinite(first) ? new Date(first).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : '',
|
|
112
|
+
D.branch ? `branch ${D.branch}` : '', `${D.calls.length} calls`, `${D.contexts.length} contexts`,
|
|
113
|
+
].filter(Boolean).join(' · ');
|
|
114
|
+
|
|
115
|
+
// ---------- sequence diagram: one lifeline per context ----------
|
|
116
|
+
|
|
117
|
+
// Rows are events in time order, not to scale: a spawn is a call message to the
|
|
118
|
+
// new context's lifeline, its end a dashed return with the result. Tool calls
|
|
119
|
+
// and inline skills are self-messages; a compaction is a note on its lifeline.
|
|
120
|
+
function sequenceEvents(all) {
|
|
121
|
+
const ev = [];
|
|
122
|
+
D.calls.forEach((c, i) => {
|
|
123
|
+
if (c.child && byId.has(c.child)) {
|
|
124
|
+
ev.push({ t: c.start, k: 0, type: 'call', i, from: c.ctx, to: c.child });
|
|
125
|
+
if (!c.running) ev.push({ t: c.start + c.dur, k: 2, type: 'return', i, from: c.child, to: c.ctx });
|
|
126
|
+
} else if (c.tool === 'Skill' || all) {
|
|
127
|
+
ev.push({ t: c.start, k: 1, type: 'self', i, at: c.ctx });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
for (const m of D.markers) if (m.kind === 'compact') ev.push({ t: m.at, k: 1, type: 'note', m, at: m.ctx });
|
|
131
|
+
ev.sort((a, b) => a.t - b.t || a.k - b.k);
|
|
132
|
+
return groupInline(ev);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Inline skills loaded one after another in one context share a diamond until
|
|
136
|
+
// clicked open: their order matters less than the calls they lead to.
|
|
137
|
+
const GROUP_MIN = 3;
|
|
138
|
+
const expanded = new Set();
|
|
139
|
+
const isInline = (e) => e.type === 'self' && D.calls[e.i].tool === 'Skill';
|
|
140
|
+
function groupInline(ev) {
|
|
141
|
+
const out = [];
|
|
142
|
+
for (let k = 0; k < ev.length;) {
|
|
143
|
+
let j = k;
|
|
144
|
+
while (j < ev.length && isInline(ev[j]) && ev[j].at === ev[k].at) j += 1;
|
|
145
|
+
if (j - k >= GROUP_MIN && !expanded.has(ev[k].i)) {
|
|
146
|
+
out.push({ t: ev[k].t, type: 'group', at: ev[k].at, is: ev.slice(k, j).map((e) => e.i) });
|
|
147
|
+
k = j;
|
|
148
|
+
} else {
|
|
149
|
+
out.push(...ev.slice(k, Math.max(j, k + 1)));
|
|
150
|
+
k = Math.max(j, k + 1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// One column per context at a time: a context takes the first column right of
|
|
157
|
+
// its caller's whose last context ended before it started, so contexts that
|
|
158
|
+
// never overlap, like repeated runs of one skill, share a column.
|
|
159
|
+
function packColumns(rows, rowOf) {
|
|
160
|
+
const span = (c) => (c.id === 'main' ? [0, Infinity] : [rowOf.get(`call${callOf.get(c.id)}`) ?? 0, rowOf.get(`return${callOf.get(c.id)}`) ?? Infinity]);
|
|
161
|
+
const ends = [], col = new Map(), members = [];
|
|
162
|
+
for (const c of D.contexts) {
|
|
163
|
+
const [from, to] = span(c);
|
|
164
|
+
let k = c.id === 'main' ? 0 : (col.get(c.parent) ?? 0) + 1;
|
|
165
|
+
while (k < ends.length && ends[k] >= from) k += 1;
|
|
166
|
+
ends[k] = to; col.set(c.id, k);
|
|
167
|
+
(members[k] = members[k] || []).push(c);
|
|
168
|
+
}
|
|
169
|
+
return { col, members };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function drawSequence() {
|
|
173
|
+
const all = document.getElementById('all').checked;
|
|
174
|
+
const svg = document.getElementById('tl');
|
|
175
|
+
const rows = sequenceEvents(all);
|
|
176
|
+
const rowOf = new Map();
|
|
177
|
+
rows.forEach((e, r) => { if (e.type === 'call' || e.type === 'return') rowOf.set(`${e.type}${e.i}`, r); });
|
|
178
|
+
const { col, members } = packColumns(rows, rowOf);
|
|
179
|
+
const n = members.length;
|
|
180
|
+
const colW = Math.max(SEQ_COL, (svg.parentElement.clientWidth - 26 - SEQ_GUTTER - SEQ_RIGHT) / n);
|
|
181
|
+
const W = SEQ_GUTTER + colW * n + SEQ_RIGHT;
|
|
182
|
+
const colX = (k) => SEQ_GUTTER + colW * k + colW / 2;
|
|
183
|
+
const lx = new Map(D.contexts.map((c) => [c.id, colX(col.get(c.id))]));
|
|
184
|
+
const ys = [SEQ_HEAD + 18];
|
|
185
|
+
rows.forEach((e, r) => {
|
|
186
|
+
const spent = e.type === 'call' && (byId.get(e.to) || {}).spent;
|
|
187
|
+
ys.push(ys[r] + (spent ? SEQ_SPENT_ROW : SEQ_ROW));
|
|
188
|
+
});
|
|
189
|
+
const yOf = (r) => ys[r];
|
|
190
|
+
const height = yOf(rows.length) + 10;
|
|
191
|
+
const fits = (px) => Math.max(4, Math.floor(px / CHAR_W));
|
|
192
|
+
|
|
193
|
+
let s = `<text class="muted" x="8" y="24">time</text>`;
|
|
194
|
+
const tipOf = (c) => [`${c.label}${c.id === 'main' ? '' : ` (${short(c.id)})`}`, kindText(c)].filter(Boolean).join(': ');
|
|
195
|
+
members.forEach((list, k) => {
|
|
196
|
+
const x = colX(k), first = list[0];
|
|
197
|
+
s += `<line x1="${x}" x2="${x}" y1="${SEQ_HEAD}" y2="${height}" stroke="${css('--line')}" stroke-dasharray="4 4"/>`;
|
|
198
|
+
const box = `x="${x - colW / 2 + 8}" y="4" width="${colW - 16}" height="${SEQ_HEAD - 10}" rx="6"`;
|
|
199
|
+
if (new Set(list.map((c) => color(c.id))).size > 1) { s += sharedHeader(list, x, box); return; }
|
|
200
|
+
// One context, or copies that share their parent's color: a solid header.
|
|
201
|
+
const name = first.name || first.label;
|
|
202
|
+
const title = list.length === 1 ? name : `${name} ×${list.length}`;
|
|
203
|
+
const sub = list.length === 1
|
|
204
|
+
? (first.id === 'main' ? 'main context' : `${kindWord(first.tool)} · ${short(first.id)}${first.kind === 'copy' ? ` · copy of ${short(first.parent)}` : first.parent ? '' : ' · parent not recorded'}`)
|
|
205
|
+
: `${list.length} contexts, one after another`;
|
|
206
|
+
s += `<g><rect ${box} fill="${color(first.id)}"/>`
|
|
207
|
+
+ `<text class="head" x="${x}" y="24" text-anchor="middle">${esc(clip(title, fits(colW - 30)))}</text>`
|
|
208
|
+
+ `<text class="head sub" x="${x}" y="40" text-anchor="middle">${esc(sub)}</text>`
|
|
209
|
+
+ `<title>${esc(list.map(tipOf).join('\n'))}</title></g>`;
|
|
210
|
+
});
|
|
211
|
+
// Contexts of different colors took turns in this column, so no one color
|
|
212
|
+
// can fill its header: an outline holds a chip per context, in time order
|
|
213
|
+
// and in the color of its bar. A name is written once per run of it, and
|
|
214
|
+
// names shorten together until the row fits:
|
|
215
|
+
// validator, github => [validator] [github]
|
|
216
|
+
// validator ×3 => [validator] [] []
|
|
217
|
+
// five long names, 230 px => [wat…] [est…] [val…] [fork] [val…]
|
|
218
|
+
function sharedHeader(list, x, box) {
|
|
219
|
+
const PAD = 6, GAP = 4, avail = colW - 32;
|
|
220
|
+
const names = list.map((c, i) => { const name = c.name || c.label; return i && name === (list[i - 1].name || list[i - 1].label) ? '' : name; });
|
|
221
|
+
const bare = Math.max(2, Math.min(14, (avail - GAP * (list.length - 1)) / list.length));
|
|
222
|
+
const widths = (n) => names.map((name) => (name && n > 1 ? Math.min(name.length, n) * CHAR_W + PAD * 2 : bare));
|
|
223
|
+
const total = (n) => widths(n).reduce((a, b) => a + b, 0) + GAP * (list.length - 1);
|
|
224
|
+
let n = Math.max(...names.map((name) => name.length));
|
|
225
|
+
while (n > 1 && total(n) > avail) n -= 1;
|
|
226
|
+
let cx = x - total(n) / 2;
|
|
227
|
+
const chips = list.map((c, i) => {
|
|
228
|
+
const w = widths(n)[i], text = names[i] && n > 1 ? clip(names[i], n) : '';
|
|
229
|
+
const chip = `<g><rect x="${cx}" y="10" width="${w}" height="17" rx="3" fill="${color(c.id)}"/>`
|
|
230
|
+
+ (text ? `<text class="head chip" x="${cx + w / 2}" y="22.5" text-anchor="middle">${esc(text)}</text>` : '')
|
|
231
|
+
+ `<title>${esc(tipOf(c))}</title></g>`;
|
|
232
|
+
cx += w + GAP;
|
|
233
|
+
return chip;
|
|
234
|
+
}).join('');
|
|
235
|
+
return `<g><rect ${box} fill="none" stroke="${css('--fresh')}"/>${chips}`
|
|
236
|
+
+ `<text class="muted" x="${x}" y="41" text-anchor="middle">${list.length} contexts, one after another</text></g>`;
|
|
237
|
+
}
|
|
238
|
+
// Activation: a context is busy from the call that starts it to its return.
|
|
239
|
+
for (const c of D.contexts) {
|
|
240
|
+
const x = lx.get(c.id);
|
|
241
|
+
const call = callOf.get(c.id);
|
|
242
|
+
const y0 = c.id === 'main' ? SEQ_HEAD + 4 : yOf(rowOf.get(`call${call}`));
|
|
243
|
+
const y1 = c.id === 'main' ? height - 6 : yOf(rowOf.get(`return${call}`) ?? rows.length);
|
|
244
|
+
s += `<rect x="${x - 5}" y="${y0}" width="10" height="${Math.max(4, y1 - y0)}" fill="${color(c.id)}" fill-opacity=".85" rx="2"><title>${esc(tipOf(c) + (c.spent ? `\n${spentTip(c)}` : ''))}</title></rect>`;
|
|
245
|
+
// What the context spent sits next to the top of its bar: right of a
|
|
246
|
+
// subagent's, where the call message arrives from the left, and left of
|
|
247
|
+
// main's, which nothing else uses. Three rows, numbers right-aligned.
|
|
248
|
+
if (c.spent) {
|
|
249
|
+
const left = c.id === 'main';
|
|
250
|
+
const numX = left ? x - 64 : x + 58;
|
|
251
|
+
const parts = [['new', c.spent.new], ['cached', c.spent.cached], ['out', c.spent.out]];
|
|
252
|
+
s += `<g class="spent">${parts.map(([word, n], k) => `<text x="${numX}" y="${y0 + 10 + k * 13}" text-anchor="end">${esc(count(n))}</text>`
|
|
253
|
+
+ `<text class="kind" x="${numX + 4}" y="${y0 + 10 + k * 13}">${word}</text>`).join('')}<title>${esc(spentTip(c))}</title></g>`;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
rows.forEach((e, r) => {
|
|
257
|
+
const y = yOf(r);
|
|
258
|
+
const t = e.type === 'note' ? e.m.at : e.t;
|
|
259
|
+
s += `<text class="muted mono" x="8" y="${y + 4}">${clock(t)}</text>`;
|
|
260
|
+
if (e.type === 'note') {
|
|
261
|
+
const x = lx.get(e.at);
|
|
262
|
+
s += `<rect x="${x + 10}" y="${y - 11}" width="${Math.min(colW - 20, 170)}" height="22" fill="${css('--panel')}" stroke="${css('--fg')}" stroke-width="1.5"/>`;
|
|
263
|
+
s += `<text x="${x + 18}" y="${y + 4}">compacted (${esc(e.m.trigger || '?')})</text>`;
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (e.type === 'group') {
|
|
267
|
+
const x = lx.get(e.at) + 5;
|
|
268
|
+
const names = e.is.map((i) => D.calls[i].name || 'skill');
|
|
269
|
+
const text = `${e.is.length} skills: ${names.join(', ')}`;
|
|
270
|
+
s += `<g class="hit" data-group="${e.is[0]}"><path d="M${x + 12} ${y - 7} l7 7 l-7 7 l-7 -7 z" fill="${color(e.at)}"/>`
|
|
271
|
+
+ `<text x="${x + 26}" y="${y + 4}">${esc(clip(text, fits(x + 26 > W - colW ? W - x - 36 : colW - 40)))}</text>`
|
|
272
|
+
+ `<title>${esc(`${e.is.length} skills loaded inline, ${clock(D.calls[e.is[0]].start)} to ${clock(D.calls[e.is.at(-1)].start)}:\n${names.join('\n')}\nClick to show each one.`)}</title></g>`;
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const c = D.calls[e.i];
|
|
276
|
+
const tip = `<title>${esc(`${label(c.tool, c.name)} · ${clock(c.start)} · ${took(c)}${c.ok ? '' : ' · failed'}${c.result ? `\n-> ${c.result}` : ''}`)}</title>`;
|
|
277
|
+
if (e.type === 'self') {
|
|
278
|
+
const x = lx.get(e.at) + 5, inline = c.tool === 'Skill';
|
|
279
|
+
const name = c.name || kindWord(c.tool), kind = ` (${kindWord(c.tool)})`;
|
|
280
|
+
s += `<g class="hit" data-i="${e.i}">`
|
|
281
|
+
+ (inline ? `<path d="M${x + 12} ${y - 7} l7 7 l-7 7 l-7 -7 z" fill="${color(e.at)}"/>`
|
|
282
|
+
: `<path d="M${x} ${y - 6} h18 v12 h-14" fill="none" stroke="${css('--muted')}" marker-end="url(#head-self)"/>`)
|
|
283
|
+
+ `<text class="${c.ok ? '' : 'failtext'}" x="${x + 26}" y="${y + 4}">${esc(clip(name, fits(x + 26 > W - colW ? W - x - 36 : colW - 40) - kind.length))}<tspan class="kind">${esc(kind)}</tspan></text>${tip}</g>`;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const x0 = lx.get(e.from) + (lx.get(e.to) > lx.get(e.from) ? 5 : -5);
|
|
287
|
+
const x1 = lx.get(e.to) + (lx.get(e.to) > lx.get(e.from) ? -5 : 5);
|
|
288
|
+
const child = byId.get(c.child);
|
|
289
|
+
const isCall = e.type === 'call';
|
|
290
|
+
const stroke = isCall ? color(c.ctx) : css('--muted');
|
|
291
|
+
const span = Math.abs(x1 - x0);
|
|
292
|
+
const name = c.name || kindWord(c.tool), kind = ` (${kindWord(c.tool)})`;
|
|
293
|
+
const args = c.args && c.args !== c.name ? ` · ${c.args}` : '';
|
|
294
|
+
// Labels start a fixed distance right of the left end, the caller's lifeline,
|
|
295
|
+
const lx0 = Math.min(x0, x1) + LABEL_PAD;
|
|
296
|
+
// and stop before the first bar of another context that is at work on this row.
|
|
297
|
+
let end = Math.max(x0, x1) - 10;
|
|
298
|
+
for (const o of D.contexts) {
|
|
299
|
+
const ox = lx.get(o.id), k = callOf.get(o.id);
|
|
300
|
+
const busy = o.id === 'main' || (rowOf.get(`call${k}`) < r && r < (rowOf.get(`return${k}`) ?? rows.length));
|
|
301
|
+
if (busy && ox > lx0 && ox - 10 < end) end = ox - 10;
|
|
302
|
+
}
|
|
303
|
+
const room = fits(end - lx0);
|
|
304
|
+
const body = isCall
|
|
305
|
+
? `${esc(clip(name, room - kind.length))}<tspan class="kind">${esc(kind)}${esc(clip(args, Math.max(0, room - name.length - kind.length)))}</tspan>`
|
|
306
|
+
: esc(clip(`${c.result ? c.result : 'done'} · ${dur(c.dur)}`, room));
|
|
307
|
+
s += `<g class="hit" data-i="${e.i}"><line x1="${x0}" x2="${x1}" y1="${y}" y2="${y}" stroke="${stroke}" stroke-width="${isCall ? 2 : 1.5}"${isCall ? '' : ' stroke-dasharray="5 4"'} marker-end="url(#${isCall ? `head-${c.background ? 'open-' : ''}${child.hue % PALETTE}` : 'head-return'})"/>`
|
|
308
|
+
+ `<text class="${isCall ? 'msg' : 'msg muted'}${c.ok || isCall ? '' : ' failtext'}" x="${lx0}" y="${y - 6}">${body}</text>`
|
|
309
|
+
+ (isCall && (child.kind === 'copy' || c.background) ? `<text class="muted" x="${lx0}" y="${y + 14}">${esc(clip([child.kind === 'copy' && 'starts with a copy of this history', c.background && (c.running ? 'still running in the background' : 'runs in the background')].filter(Boolean).join(', '), room))}</text>` : '')
|
|
310
|
+
+ `${tip}</g>`;
|
|
311
|
+
});
|
|
312
|
+
// UML: a filled head is a synchronous call, an open one an asynchronous call
|
|
313
|
+
// the caller doesn't wait for.
|
|
314
|
+
const heads = Array.from({ length: PALETTE }, (_, h) => `<marker id="head-${h}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto"><path d="M0 0 L10 5 L0 10 z" fill="var(--c${h})"/></marker>`
|
|
315
|
+
+ `<marker id="head-open-${h}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto"><path d="M0 0 L10 5 L0 10" fill="none" stroke="var(--c${h})" stroke-width="1.8"/></marker>`).join('')
|
|
316
|
+
+ `<marker id="head-return" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto"><path d="M0 0 L10 5 L0 10" fill="none" stroke="${css('--muted')}" stroke-width="1.5"/></marker>`
|
|
317
|
+
+ `<marker id="head-self" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto"><path d="M0 0 L10 5 L0 10 z" fill="${css('--muted')}"/></marker>`;
|
|
318
|
+
svg.setAttribute('width', W); svg.setAttribute('height', height); svg.setAttribute('viewBox', `0 0 ${W} ${height}`);
|
|
319
|
+
svg.innerHTML = `<defs>${heads}</defs>${s}`;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ---------- tree ----------
|
|
323
|
+
|
|
324
|
+
// Same nesting as `hp tree`: a subagent's calls go under the call that started it.
|
|
325
|
+
const kids = new Map();
|
|
326
|
+
const containerKey = (ctx) => (ctx === 'main' || !D.calls.some((c) => c.child === ctx) ? `root` : ctx);
|
|
327
|
+
const items = D.calls.map((c, i) => ({ type: 'call', i, start: c.start, ctx: c.ctx }))
|
|
328
|
+
.concat(D.markers.filter((m) => m.kind === 'compact').map((m) => ({ type: 'compact', m, start: m.at, ctx: m.ctx })));
|
|
329
|
+
for (const it of items) {
|
|
330
|
+
const key = containerKey(it.ctx);
|
|
331
|
+
if (!kids.has(key)) kids.set(key, []);
|
|
332
|
+
kids.get(key).push(it);
|
|
333
|
+
}
|
|
334
|
+
for (const list of kids.values()) list.sort((a, b) => a.start - b.start);
|
|
335
|
+
|
|
336
|
+
const ctxName = (id) => (byId.get(id) ? `${byId.get(id).label}${id === 'main' ? '' : ` (${short(id)})`}` : id);
|
|
337
|
+
// An inline skill returns nothing: its text joins the caller's context, and
|
|
338
|
+
// the calls that context makes next are its work, mixed with the caller's own.
|
|
339
|
+
const resultText = (c) => (c.result ? c.result
|
|
340
|
+
: c.running ? 'none yet: it is still running'
|
|
341
|
+
: c.tool === 'Skill' && !c.child ? `none of its own: it ran inline, so its work is the calls ${ctxName(c.ctx)} makes after it`
|
|
342
|
+
: '(none recorded)');
|
|
343
|
+
// The same square-root scale as the text tree: the longest call fills the bar.
|
|
344
|
+
const barWidth = (ms, longest) => (longest && ms ? Math.max(1, Math.round(Math.sqrt(Math.min(ms, longest) / longest) * 66)) : 0);
|
|
345
|
+
|
|
346
|
+
function drawTree() {
|
|
347
|
+
const all = document.getElementById('all').checked;
|
|
348
|
+
const shownCall = (c) => all || c.tool === 'Skill' || c.tool === 'Agent';
|
|
349
|
+
const longest = Math.max(0, ...D.calls.filter(shownCall).map((c) => c.dur));
|
|
350
|
+
let h = '<div class="thead"><span>time</span><span class="num">duration</span><span></span><span class="num">new</span><span class="num">cached</span><span class="num">out</span><span>call</span></div>';
|
|
351
|
+
const walk = (key, depth) => (kids.get(key) || []).forEach((it) => {
|
|
352
|
+
const pad = depth * 22;
|
|
353
|
+
if (it.type === 'compact') {
|
|
354
|
+
h += `<div class="row mark"><span>${clock(it.m.at)}</span><span></span><span></span><span></span><span></span><span></span>`
|
|
355
|
+
+ `<span class="call" style="padding-left:${pad}px">-- ${esc(short(it.ctx))} compacted (${esc(it.m.trigger || 'unknown trigger')})</span></div>`;
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const c = D.calls[it.i];
|
|
359
|
+
const shown = shownCall(c);
|
|
360
|
+
if (shown) {
|
|
361
|
+
const spent = c.child && spentOf(c.child);
|
|
362
|
+
const hue = color(c.child && byId.has(c.child) ? c.child : c.ctx);
|
|
363
|
+
h += `<div class="row" id="r${it.i}" data-i="${it.i}"><span class="muted">${clock(c.start)}</span><span class="num">${esc(took(c))}</span>`
|
|
364
|
+
+ `<span class="bar"><i style="width:${barWidth(c.running ? 0 : c.dur, longest)}px;background:${hue}"></i></span>`
|
|
365
|
+
+ (spent ? [spent.new, spent.cached, spent.out].map((n) => `<span class="num" title="${n}">${count(n)}</span>`).join('') : '<span></span><span></span><span></span>')
|
|
366
|
+
+ `<span class="call" style="padding-left:${pad}px"><i class="chip" style="background:${hue}"></i>`
|
|
367
|
+
+ `<span><b>${esc(c.name || kindWord(c.tool))}</b>${c.name ? ` (${esc(kindWord(c.tool))})` : ''}</span>`
|
|
368
|
+
+ `<span class="words">${esc(words(c))}</span>${c.ok ? '' : '<span class="fail">failed</span>'}<span class="gist">${esc(gist(c))}</span></span></div>`;
|
|
369
|
+
h += `<div class="detail" id="d${it.i}" hidden style="margin-left:${pad + 20}px;border-color:${color(c.ctx)}">`
|
|
370
|
+
+ `<b>context</b>${esc(ctxName(c.ctx))}\n`
|
|
371
|
+
+ (c.ctxTokens ? `<b>history</b>${esc(tok(c.ctxTokens))} in the context when it made this call\n` : '')
|
|
372
|
+
+ (c.args ? `<b>args</b>${esc(c.args)}\n` : '')
|
|
373
|
+
+ `<b>result</b>${esc(resultText(c))}</div>`;
|
|
374
|
+
}
|
|
375
|
+
if (c.child) walk(c.child, depth + (shown ? 1 : 0));
|
|
376
|
+
});
|
|
377
|
+
walk('root', 0);
|
|
378
|
+
document.getElementById('tree').innerHTML = h;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function select(i, fromTimeline) {
|
|
382
|
+
if (fromTimeline && !document.getElementById(`r${i}`)) { document.getElementById('all').checked = true; drawTree(); drawSequence(); }
|
|
383
|
+
const row = document.getElementById(`r${i}`), detail = document.getElementById(`d${i}`);
|
|
384
|
+
document.querySelectorAll('.row.sel').forEach((r) => r.classList.remove('sel'));
|
|
385
|
+
row.classList.add('sel');
|
|
386
|
+
detail.hidden = fromTimeline ? false : !detail.hidden;
|
|
387
|
+
if (fromTimeline) row.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
document.getElementById('tree').addEventListener('click', (e) => { const r = e.target.closest('.row'); if (r) select(r.dataset.i, false); });
|
|
391
|
+
document.getElementById('tl').addEventListener('click', (e) => {
|
|
392
|
+
const b = e.target.closest('.hit');
|
|
393
|
+
if (b && b.dataset.group) { expanded.add(Number(b.dataset.group)); drawSequence(); } else if (b) select(b.dataset.i, true);
|
|
394
|
+
});
|
|
395
|
+
document.getElementById('all').addEventListener('change', () => { drawTree(); drawSequence(); });
|
|
396
|
+
let pending;
|
|
397
|
+
window.addEventListener('resize', () => { clearTimeout(pending); pending = setTimeout(drawSequence, 100); });
|
|
398
|
+
if (D.calls.length) drawSequence(); else document.querySelector('.panel').textContent = 'No calls recorded in this session.';
|
|
399
|
+
drawTree();
|
|
400
|
+
|
|
401
|
+
// pi-flow fork: FLOW_HEADER data slot + ticket header band render (PMR-57HF).
|
|
402
|
+
// assemble.ts replaces the literal with `<`-escaped JSON (same technique as
|
|
403
|
+
// hp.js's /*DATA*/null slot). Absent fields are skipped, never blank rows.
|
|
404
|
+
const FLOW_HEADER = /*FLOW_HEADER*/null;
|
|
405
|
+
function renderFlowHeader() {
|
|
406
|
+
if (!FLOW_HEADER) return;
|
|
407
|
+
const rows = [];
|
|
408
|
+
const add = (label, value) => { if (value) rows.push(`<div><b>${label}</b> ${value}</div>`); };
|
|
409
|
+
add('ticket', esc(FLOW_HEADER.ref));
|
|
410
|
+
add('track', esc(FLOW_HEADER.trackRef ? `${FLOW_HEADER.trackRef} (${FLOW_HEADER.mode})` : FLOW_HEADER.mode));
|
|
411
|
+
if (FLOW_HEADER.runCount) add('run', `${FLOW_HEADER.runIndex} of ${FLOW_HEADER.runCount}`);
|
|
412
|
+
if (FLOW_HEADER.phases && FLOW_HEADER.phases.length) add('phases', FLOW_HEADER.phases.map((p) => `${esc(p.phase)} ${dur(Math.round(p.seconds * 1000))}`).join(' · '));
|
|
413
|
+
if (FLOW_HEADER.commitsBySubtask && FLOW_HEADER.commitsBySubtask.length) add('commits', FLOW_HEADER.commitsBySubtask.map((c) => `${esc(c.subtask)}: ${c.commits.map(esc).join(', ')}`).join(' · '));
|
|
414
|
+
if (FLOW_HEADER.unattributed && FLOW_HEADER.unattributed.length) add('unattributed', FLOW_HEADER.unattributed.map(esc).join(', '));
|
|
415
|
+
if (FLOW_HEADER.prUrl) {
|
|
416
|
+
// pi-flow fork (PMR-BRSV): scheme allowlist — only http(s) URLs become
|
|
417
|
+
// links; anything else (e.g. a crafted javascript: journal prUrl)
|
|
418
|
+
// renders as plain text so it can never execute on click.
|
|
419
|
+
const prUrl = String(FLOW_HEADER.prUrl);
|
|
420
|
+
let prCell;
|
|
421
|
+
if (/^https?:\/\//i.test(prUrl)) {
|
|
422
|
+
prCell = `<a href="${esc(prUrl)}">${esc(prUrl)}</a>`;
|
|
423
|
+
} else {
|
|
424
|
+
prCell = esc(prUrl);
|
|
425
|
+
}
|
|
426
|
+
add('pr', prCell);
|
|
427
|
+
}
|
|
428
|
+
if (FLOW_HEADER.generatedAt) add('generated', esc(FLOW_HEADER.generatedAt));
|
|
429
|
+
if (!rows.length) return;
|
|
430
|
+
const el = document.getElementById('flow-header');
|
|
431
|
+
el.innerHTML = rows.join('');
|
|
432
|
+
el.hidden = false;
|
|
433
|
+
}
|
|
434
|
+
renderFlowHeader();
|
|
435
|
+
// pi-flow fork: end header band script
|
|
436
|
+
</script></body></html>
|
package/gates.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// AIDEV-NOTE: W76D gate for the implement phase. PURE check function over a
|
|
2
|
+
// ticket's labels — the /implement ticket wires these; shipped here with
|
|
3
|
+
// tests only. canImplement refuses tickets without 'planned'. (PMR-Z2K7:
|
|
4
|
+
// needsResearchSkip and the research-skipped durable label were removed with
|
|
5
|
+
// the research phase.)
|
|
6
|
+
|
|
7
|
+
export interface GateResult {
|
|
8
|
+
ok: boolean
|
|
9
|
+
reason?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function canImplement(labels: readonly string[]): GateResult {
|
|
13
|
+
if (labels.includes('planned')) {
|
|
14
|
+
return { ok: true }
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
ok: false,
|
|
18
|
+
reason: 'ticket has no "planned" label — run /plan first',
|
|
19
|
+
}
|
|
20
|
+
}
|