@feigi/fleet-ctl 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,605 @@
1
+ // The member-telemetry adapter (#1342, ruled on #1302). ONE per-member
2
+ // record shape, TWO readers a tree walk chooses by content, never by
3
+ // caller-supplied config: board.mjs (the live spend panel) and
4
+ // member-outcomes.mjs (the scraper) build on the primitives here rather than
5
+ // each inlining a transcript layout, so the fold-back arithmetic, the cwd
6
+ // encoder and the ticket/PR extraction each live in exactly one place.
7
+ //
8
+ // The record: harness, session, role, agent, model, thinking,
9
+ // subagent_type, tokens_in, tokens_cache_create, tokens_cache_read,
10
+ // tokens_out, cost, wall_s, turns, ticket, pr. `harness` is set by whichever
11
+ // reader produced the row — structural, decided by which root the transcript
12
+ // lives under, before any byte is parsed. `cost` is real (`usage.cost.total`
13
+ // — no pricing table exists in this repo, and inventing one is not this
14
+ // module's business.
15
+ //
16
+ // `thinking` is the harness-written level, blank when a hole is visible
17
+ // (#1302's ruling on "auto"). `subagent_type` (#1066) is what the member was
18
+ // DISPATCHED AS — the agent DEFINITION the dispatch named, never the
19
+ // member's own name: it is the only field that separates a deliberate
20
+ // alternate-tier pair from two members whose models already happened to
21
+ // differ, and both readers keep it because it is derived rather than
22
+ // authored and survives a regeneration. `""` is NOT the hole use; it means
23
+ // the dispatch named no agent definition, the ordinary shape of an untyped
24
+ // `task` call.
25
+ import { readdirSync, readFileSync, realpathSync } from "node:fs";
26
+ import { join, basename, relative, isAbsolute, sep } from "node:path";
27
+
28
+ import { classifyRole, CANONICAL_MEMBER_NAME_PREFIXES } from "./compute-spend.mjs";
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // cwd encoder
32
+ // ---------------------------------------------------------------------------
33
+
34
+ // `realpath` is an injectable seam, not a design nicety: the production
35
+ // default resolves the LIVE filesystem, but a directory a transcript reads
36
+ // may no longer exist by the time anything reads it — a scratch dir cleaned
37
+ // up weeks later, say — and `fs.realpathSync` throws ENOENT on a path it
38
+ // cannot see. Verifying the encoder against a historical transcript, for one
39
+ // callers who need to encode a cwd that is not guaranteed to exist — every
40
+ // caller but board.mjs's own live panel — pass their own resolver.
41
+ //
42
+ // Encodes the way the fleet's own tooling reads it back: every
43
+ // non-alphanumeric character with `-`, so `-Users-x-claude` decodes to
44
+ // `/Users/x/.claude`, not `-Users-x.claude`. Home-relative paths become
45
+ // `~/...`-style (`-` under $HOME) joined by `-` with DOTS PRESERVED
46
+ // (`.claude` -> `-.claude`); non-home paths are realpath-resolved (so `/tmp/x`,
47
+ // a symlink to `/private/tmp/x` on macOS, encodes under the resolved name)
48
+ // and double-dash-wrapped. Both forms are measured against real
49
+ // `~/.omp/agent/sessions/*` directory names in member-record.test.mjs - a
50
+ // `~/dev/fleet-plugin`, `--private-tmp-fx685-scratch--` all exist on disk
51
+ // today.
52
+ export function encodeProjectDir(cwd, { home = process.env.HOME, realpath = realpathSync } = {}) {
53
+ const rel = relative(home, cwd);
54
+ const isHome = !rel.startsWith("..") && !isAbsolute(rel);
55
+ if (isHome) return "-" + rel.split(sep).filter(Boolean).join("-");
56
+ const resolved = realpath(cwd);
57
+ return "--" + resolved.split(sep).filter(Boolean).join("-") + "--";
58
+ }
59
+
60
+ // ---------------------------------------------------------------------------
61
+ // Ticket/PR extraction and model normalisation
62
+ // ---------------------------------------------------------------------------
63
+ // Moved here from member-outcomes.mjs (which re-exports both for the callers
64
+ // and tests that already import them from there) so member-record.mjs, the
65
+ // lower-level module, does not depend upward on either script it feeds.
66
+ // ---------------------------------------------------------------------------
67
+
68
+ // `<synthetic>` is not a model — it is the harness labelling a turn it
69
+ // generated itself, and mapping it to anything would invent a data point.
70
+ //
71
+ // The `[1m]` strip is DEFENSIVE, not load-bearing: it guards a
72
+ // context-window variant spelling (`claude-opus-5[1m]`) this scraper has
73
+ // never actually read from a transcript's `message.model`, where measurement
74
+ // found ZERO bracketed spellings across every file. It fires only if the
75
+ // model spelling ever changes to carry one.
76
+ export function normalizeModel(raw) {
77
+ const s = String(raw ?? "").trim();
78
+ if (!s || s === "<synthetic>") return null;
79
+ return s.replace(/\[[^\]]*\]$/, "");
80
+ }
81
+
82
+ // A member's name is the only place its unit of work is recorded — there is
83
+ // no dispatch sidecar at all (see ompMemberRecord). The one exception is a
84
+ // PR the member OPENED (#2209): an `impl-<ticket>` name can never carry it,
85
+ // so ompMemberRecord reads it off the member's own `gh pr create` result
86
+ // (createdPrNumbers) — this function still answers `pr: ""` for that name.
87
+ //
88
+ // FOUR finisher spellings are live on disk, measured 2026-08-27 across every
89
+ // transcript: finisher-pr-<n>, finish-pr-<n>, finisher-<n>, finish-<n>. All
90
+ // four book a PR, and matching only the first cost 120 of 283 finisher
91
+ // members their join key to tier-outcomes.tsv. The fix-pr-<n> and
92
+ // review-pr-<n> families share the first pattern only because the infix is
93
+ // the same — they are NOT finisher spellings. `finisher-pr-<n>` is the
94
+ // canonical name run-team now fixes (#326); the other three stay matched
95
+ // because the runs that used them are already in the record.
96
+ //
97
+ // merge-bot-<n> is deliberately excluded: its number is a per-run dispatch
98
+ // counter, never a PR, and booking it as a pr would join the row to an
99
+ // unrelated PR's verdict. A single trailing lowercase letter is a retry
100
+ // suffix (-b, -c and -d all observed) and is stripped first, because a
101
+ // re-dispatched member works the same unit. A trailing `-v<n>` (`-v2`,
102
+ // `-v10`, ...) is a DIFFERENT spelling of the same re-dispatch, used when a
103
+ // controller re-dispatches a finisher/reviewer against a PR whose head moved
104
+ // after label (#1482, measured: ~67% of one finisher's tokens fell through
105
+ // to a blank pr column under the old letter-only regex); it is stripped for
106
+ // the same reason, not because it looks like a second-ticket suffix — no
107
+ // naming convention in this repo otherwise uses a literal `-v` + digits
108
+ // tail.
109
+ //
110
+ // The NUMERIC suffix on a TICKET-shaped name (`impl-137-2`) looks like the
111
+ // same retry spelling and is deliberately NOT stripped there. The one real
112
+ // instance on disk describes itself as "Implement 137+138+139 set" — a
113
+ // multi-ticket batch that no single `ticket` value represents. Blank is the
114
+ // honest answer; booking it to 137 would join the row to two tickets it did
115
+ // not do.
116
+ //
117
+ // A PR-shaped name's numeric suffix is a DIFFERENT case: `fix-pr-<n>`,
118
+ // `review-pr-<n>`, `finisher-pr-<n>` and `resolve-pr-<n>` carry exactly ONE
119
+ // number, the PR itself, so a second trailing `-\d+` cannot be a second
120
+ // ticket the way `impl-<ticket>-<n>`'s can — there is only ever one PR per
121
+ // such name. A trailing `-\d+` there (`finisher-pr-1440-2`, `fix-pr-1281-2`)
122
+ // is the same re-dispatch retry the letter and `-v<n>` suffixes above
123
+ // already cover, and is now stripped for PR-shaped names only (#1482,
124
+ // measured: 476,202 cache-create tokens across 7 real rows fell through to a
125
+ // blank pr column this way — more than the 37,580 the `-v<n>` fix above
126
+ // addressed). The ticket-shaped `impl-<ticket>-<n>` family above is
127
+ // untouched: its second-ticket ambiguity is real, and a PR-shaped name's is
128
+ // not.
129
+ //
130
+ // `resolve` joins the `-pr-` alternation for #1250: `resolve-pr-<n>` is a
131
+ // controller-dispatched conflict/rebase resolver against an already-open PR
132
+ // (measured session descriptions: "Resolve conflict on PR 1232", "Rebase
133
+ // and resolve conflicts for PR #1310") — the same shape as `fix-pr-<n>`'s
134
+ // applier and `review-pr-<n>`'s reviewer, just not a name run-team's own
135
+ // naming convention fixes, so it stays out of the canonical list in
136
+ // SKILL.md/member-lifecycle.md the same way `finish-<n>`/`finisher-<n>` do.
137
+ // Unrecognised, a `resolve-pr-<n>` member fell through to `{ticket:"",
138
+ // pr:""}`, losing its join key into tier-outcomes.tsv exactly the way an
139
+ // unmatched finisher spelling once did (#1072).
140
+ export function parseMemberName(name) {
141
+ const s = String(name ?? "").trim().replace(/-(?:[a-z]|v\d+)$/, "");
142
+ let m = /^(?:fix|review|finish(?:er)?|resolve)-pr-(\d+)(?:-\d+)?$/.exec(s);
143
+ if (m) return { ticket: "", pr: m[1] };
144
+ m = /^finish(?:er)?-(\d+)$/.exec(s);
145
+ if (m) return { ticket: "", pr: m[1] };
146
+ m = /^impl-(\d+)$/.exec(s);
147
+ if (m) return { ticket: m[1], pr: "" };
148
+ return { ticket: "", pr: "" };
149
+ }
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // transcript reader
153
+ // ---------------------------------------------------------------------------
154
+
155
+ // An omp transcript line carries no `sessionId`/`parentUuid` — session id
156
+ // lives in the DIRECTORY name, never per line; omp's envelope is
157
+ // `{type,id,parentId,timestamp,message}`. That is the structural signature
158
+ // this reader refuses on if it is ever absent — a validation CHECK inside
159
+ // this reader, per #1302's ruling: every root this module is ever handed is
160
+ // an omp `~/.omp/agent/sessions/**` tree, so a line failing this shape
161
+ // signals a corrupted or foreign file, not a harness to dispatch to.
162
+ //
163
+ // Both halves of that signature are checked, not just the blocklist half: a
164
+ // line carrying neither Claude's keys NOR omp's own `type` field (e.g. a
165
+ // foreign/corrupted `{"foo":"bar"}`) used to sail past the blocklist-only
166
+ // check below and fold into a fabricated all-null/zero member record instead
167
+ // of the refusal this comment already promised. `type` is the one envelope
168
+ // field foldOmpTranscript's own loop dispatches every branch on below, so
169
+ // requiring it costs nothing a real omp line does not already carry.
170
+ function assertOmpShaped(d, filePath) {
171
+ const shaped =
172
+ d !== null &&
173
+ typeof d === "object" &&
174
+ typeof d.type === "string" &&
175
+ d.type !== "" &&
176
+ !Object.prototype.hasOwnProperty.call(d, "sessionId") &&
177
+ !Object.prototype.hasOwnProperty.call(d, "parentUuid");
178
+ if (!shaped) {
179
+ throw new Error(`member-record: not an omp-shaped transcript line, refusing to parse it: ${filePath}`);
180
+ }
181
+ }
182
+
183
+ // `openedPrs` (#2209) is every PR number the member's OWN `gh pr create`
184
+ // printed — the source of `pr` for a member whose name carries none, which is
185
+ // every implementer (`impl-<ticket>` names a ticket, never a PR). Chosen over
186
+ // the ledger's `impl-<N>=PR#M` settle token because that token is written by a
187
+ // live run only: a regeneration over past sessions has the transcript and
188
+ // nothing else, and this module stays pure over transcripts. Measured
189
+ // 2026-09-29 across every real `~/.omp/agent/sessions/**/*.jsonl`: 443
190
+ // transcripts printed a created PR from a `bash` toolCall whose result held
191
+ // gh's stdout — the URL on a line of its own — then omp's "Wall time"
192
+ // trailer. A create is also sometimes run via `eval` instead of `bash` —
193
+ // measured on impl-1113 (a Python subprocess, `gh pr create` printing PR
194
+ // #1535) — and stays blank there too: `eval` is not read, because a cell
195
+ // that only READS transcripts (or `gh pr view`s) prints the very same URLs.
196
+ //
197
+ // Three filters keep a URL that is NOT a PR this member opened out:
198
+ // - the CALL must invoke `gh pr create` — first in the command, after a
199
+ // shell separator (`;`, `&`, `|`, `(`, newline) or an `if`/`then`/`do`/`!`
200
+ // keyword, optionally through `rtk`/`env`/`command`/`timeout <n>`, a
201
+ // `NAME=value` prefix, or a path-qualified `.../gh` — a `gh pr view`/
202
+ // `gh pr list` result prints bare PR URLs too, and `gh pr create` quoted
203
+ // as text is no invocation (measured false-miss shapes: #2213 review);
204
+ // - the URL must be a LINE of its own, the shape gh prints, never a URL
205
+ // inside prose;
206
+ // - a URL right after gh's "... already exists:" refusal is skipped: that PR
207
+ // was opened by someone else for the same branch.
208
+ // `isError` is deliberately NOT a filter: a create chained before a failing
209
+ // command (`gh pr create ... && gh pr edit --add-label x`) exits non-zero
210
+ // having still opened the PR it printed.
211
+ //
212
+ // This is a text heuristic, not a shell parser, so it can also count a URL
213
+ // that is NOT the member's own opened PR: it does not know quoting, so a
214
+ // separator character reused inside a quoted string right before the
215
+ // literal text `gh pr create` (e.g. `echo "a; gh pr create"`) reads as an
216
+ // invocation too; a `--dry-run` create still counts a URL it merely
217
+ // previews; a `gh pr create` mentioned earlier in the same multi-line
218
+ // command (a heredoc body, a failed retry) can pair with an unrelated
219
+ // later URL in the result; and a `create || gh pr view` fallback's own
220
+ // `view` copy of an "already exists:" URL is not caught by the one-line-back
221
+ // skip above. Measured 0 real occurrences of any of these across the whole
222
+ // local `~/.omp/agent/sessions/**/*.jsonl` corpus and every filled `pr` in
223
+ // the committed TSV (#2213 review); accepted as known gaps rather than
224
+ // hand-rolling shell-quote/heredoc awareness into a single regex.
225
+ const GH_PR_CREATE_RE =
226
+ /(?:^|[;&|(\n]|\b(?:if|then|do|!)\s)\s*(?:(?:env|command|rtk|timeout\s+\S+)\s+|[A-Za-z_]\w*=\S*\s+)*(?:\S*\/)?gh\s+pr\s+create\b/;
227
+ function createdPrNumbers(text) {
228
+ const out = [];
229
+ const lines = text.split("\n");
230
+ for (let i = 0; i < lines.length; i++) {
231
+ const m = /^https?:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/pull\/(\d+)\s*$/.exec(lines[i]);
232
+ if (m && !(i > 0 && /already exists:\s*$/.test(lines[i - 1]))) out.push(m[1]);
233
+ }
234
+ return out;
235
+ }
236
+
237
+ // Folds one omp subagent transcript into per-turn totals. One
238
+ // `message.usage` per assistant turn already (no cross-line fold-back
239
+ // needed), a real per-turn dollar cost at `usage.cost.total`, and the
240
+ // declared thinking level on its own `thinking_level_change` event rather
241
+ // than repeated per line. Measured 2026-09-08/09 against real
242
+ // `~/.omp/agent/sessions/**/*.jsonl` files:
243
+ // {"type":"session",...,"cwd":"/Users/chris/dev/fleet-plugin"}
244
+ // {"type":"thinking_level_change",...,"thinkingLevel":"high","configured":null}
245
+ // {"type":"message","message":{"role":"assistant","model":"claude-sonnet-5",
246
+ // "usage":{"input":2,"output":201,"cacheRead":0,"cacheWrite":31319,
247
+ // "totalTokens":31522,"cost":{"input":4e-6,"output":0.00201,
248
+ // "cacheRead":0,"cacheWrite":0.0783,"total":0.0803}}}}
249
+ //
250
+ // `thinking` reads the harness-WRITTEN level, never the frontmatter — that
251
+ // is what makes #1298's declared-vs-resolved comparison possible (#1302's
252
+ // ruling). It stays `null` here (ompMemberRecord turns that into the
253
+ // record's `-`) when no `thinking_level_change` line exists, rather than
254
+ // guessing the default: a member that is not a fleet definition genuinely
255
+ // has no recorded level, and the hole must stay visible.
256
+ //
257
+ // `session_init.task` is the closest thing to a dispatch sidecar this
258
+ // module has — there is no separate description file at all.
259
+ // ompMemberRecord below uses it, together with the transcript's own nesting
260
+ // depth AND the AgentId itself, as REAL classifyRole() signals. A
261
+ // canonically-stemmed AgentId (`impl-<n>`, `fix-pr-<n>`, `finisher-<n>`,
262
+ // `review-pr-<n>`, `merge-bot-<n>`) IS matched against classifyRole, as
263
+ // `memberName`, per #1506; only a non-canonical AgentId — a generated word
264
+ // pair that names nothing — is still never matched.
265
+ //
266
+ // `resolvedModelIdentity` (#1345) is `session_init`'s OWN field, written at
267
+ // DISPATCH — before the member's first assistant turn exists, which is what
268
+ // makes it different from `model` above: a member still working folds to
269
+ // `model: null` (no assistant turn yet) but already carries
270
+ // `resolvedModelIdentity` (measured `anthropic/claude-opus-5` (61),
271
+ // `anthropic/claude-sonnet-5` (103), `anthropic/claude-haiku-4-5` (68)
272
+ // across real `~/.omp/agent/sessions/**` — always provider-prefixed, never a
273
+ // bare alias). `model` itself is left untouched by this addition: board.mjs
274
+ // and member-outcomes.mjs read `model` for cost/spend attribution, where the
275
+ // per-turn value (which can in principle change mid-run) is the fact they
276
+ // want, not the dispatch-time identity.
277
+ //
278
+ // `agent` (#1066) is `session_init`'s dispatch-time record of WHICH AGENT
279
+ // DEFINITION this member is. Measured 2026-09-12 across real
280
+ // `~/.omp/agent/sessions/**`: present on every one of the 1,191 transcripts
281
+ // carrying a `session_init` line (`fleet-implementer` 51,
282
+ // `fleet-implementer-alt` 17, the default `task` 220, plus the review
283
+ // fan-out's own definitions), absent only where the line itself is.
284
+ //
285
+ // `entries` (#1717) is the per-agent tool stream compute-spend.mjs's
286
+ // attributeTools reads: `assistant`/`result` entries. Measured 2026-09-26
287
+ // across 5,085 real `~/.omp/agent/sessions/**/*.jsonl` files, the call is a
288
+ // block on the assistant message and the result a line of its own:
289
+ // {"type":"message","message":{"role":"assistant","stopReason":"toolUse",
290
+ // "content":[{"type":"toolCall","id":"toolu_01JV…","name":"bash",
291
+ // "arguments":{…},"intent":"…"}],"usage":{…}}}
292
+ // {"type":"message","message":{"role":"toolResult","toolCallId":"toolu_01JV…",
293
+ // "toolName":"bash","content":[{"type":"text","text":"…"}],"details":{…},
294
+ // "isError":false,"timestamp":1790415990525}}
295
+ // All 176,056 `toolCall` blocks carried `id` and `name`; the ~29-call gap
296
+ // against the 176,027 results below is orphan calls whose result never
297
+ // landed (aborted before the tool replied) — attributeTools still counts
298
+ // them under their own name via `calls++`, only `resultChars`/`cacheWrite`
299
+ // stay at 0. Each of the 176,027 results sat on its own line, so parallel
300
+ // calls arrive as consecutive `toolResult` lines, which attributeTools
301
+ // accumulates into one batch (run lengths 2 through 14 matched the
302
+ // calls-per-turn counts to within one).
303
+ //
304
+ // A result's `chars` sums its text blocks' lengths (`content` was an array
305
+ // every time: 179,380 text blocks, 14 image blocks — an unmeasured
306
+ // non-array `content` folds to 0 blocks and `chars: 0`). A non-text block
307
+ // (an image) counts at its JSON length. `prunedAt` (194) holds a
308
+ // placeholder such as "[Uneventful result elided]" instead of the output,
309
+ // so its `chars` is the placeholder's length.
310
+ //
311
+ // The result line names its tool (`toolName`), but the stream stays
312
+ // id-only, so a result whose id no `toolCall` block carries books as
313
+ // `unknown`. Measured, that is a turn aborted mid-stream (2 results): the
314
+ // tool's "not executed" result is written first, then the assistant message
315
+ // persists with empty content, so the call never lands. That aborted
316
+ // message is still an `assistant` entry, as is every line `turns` counts.
317
+ // 142 aborted or errored turns followed a result batch. When one never
318
+ // reached the API its usage is all zero, and attributeTools books the batch
319
+ // before it at 0.
320
+ //
321
+ // `openedPrs` (#2209) folds the `bash` calls that invoke `gh pr create`
322
+ // against their own results, via createdPrNumbers above — distinct PR
323
+ // numbers in first-seen order.
324
+ export function foldOmpTranscript(jsonlText, filePath) {
325
+ let model = null, thinking = null, task = null, resolvedModelIdentity = null, agent = null;
326
+ let firstTs = null, lastTs = null;
327
+ let input = 0, cacheWrite = 0, cacheRead = 0, output = 0, cost = 0, turns = 0;
328
+ let sawCost = false;
329
+ let malformedNonLastLines = 0;
330
+ const entries = [];
331
+ const createCallIds = new Set();
332
+ const openedPrs = new Set();
333
+ const lines = String(jsonlText ?? "").split("\n");
334
+ for (let i = 0; i < lines.length; i++) {
335
+ const raw = lines[i];
336
+ if (!raw.trim()) continue;
337
+ let d;
338
+ // A torn tail (transcript read mid-write) is dropped, and costs at most
339
+ // that one turn either way. A MIDDLE line failing the same parse is not
340
+ // a live write in progress — it is lost data, and (#1717) it can desync
341
+ // a toolCall from its toolResult, not just a turn's totals, so it is
342
+ // counted, never for the last line.
343
+ try { d = JSON.parse(raw); }
344
+ catch { if (i !== lines.length - 1) malformedNonLastLines++; continue; }
345
+ assertOmpShaped(d, filePath);
346
+ if (typeof d.timestamp === "string") { firstTs ??= d.timestamp; lastTs = d.timestamp; }
347
+ if (d.type === "thinking_level_change" && typeof d.thinkingLevel === "string") thinking = d.thinkingLevel;
348
+ if (d.type === "session_init") {
349
+ if (typeof d.task === "string") task = d.task;
350
+ if (typeof d.resolvedModelIdentity === "string") resolvedModelIdentity = d.resolvedModelIdentity;
351
+ if (typeof d.agent === "string") agent = d.agent;
352
+ }
353
+ const m = d.message;
354
+ if (d.type === "message" && m?.role === "assistant") {
355
+ const blocks = Array.isArray(m.content) ? m.content : [];
356
+ for (const c of blocks) {
357
+ if (c?.type === "toolCall" && c.name === "bash" && typeof c.arguments?.command === "string"
358
+ && GH_PR_CREATE_RE.test(c.arguments.command)) createCallIds.add(c.id);
359
+ }
360
+ if (m.usage) {
361
+ const u = m.usage;
362
+ if (typeof m.model === "string" && m.model) model = m.model;
363
+ const cw = Number(u.cacheWrite ?? 0);
364
+ input += Number(u.input ?? 0);
365
+ cacheWrite += cw;
366
+ cacheRead += Number(u.cacheRead ?? 0);
367
+ output += Number(u.output ?? 0);
368
+ if (u.cost && typeof u.cost.total === "number") { cost += u.cost.total; sawCost = true; }
369
+ turns++;
370
+ entries.push({
371
+ kind: "assistant", cacheWrite: cw,
372
+ tools: blocks.filter((c) => c?.type === "toolCall").map((c) => ({ id: c.id, name: c.name })),
373
+ });
374
+ }
375
+ } else if (d.type === "message" && m?.role === "toolResult") {
376
+ const blocks = Array.isArray(m.content) ? m.content : [];
377
+ const chars = blocks.reduce(
378
+ (n, b) => n + (b?.type === "text" && typeof b.text === "string" ? b.text.length : JSON.stringify(b).length), 0);
379
+ entries.push({ kind: "result", results: [{ id: m.toolCallId, chars }] });
380
+ if (createCallIds.has(m.toolCallId)) {
381
+ const text = blocks.map((b) => (b?.type === "text" && typeof b.text === "string" ? b.text : "")).join("\n");
382
+ for (const n of createdPrNumbers(text)) openedPrs.add(n);
383
+ }
384
+ }
385
+ }
386
+ const span = firstTs && lastTs ? (Date.parse(lastTs) - Date.parse(firstTs)) / 1000 : 0;
387
+ return {
388
+ model, thinking, task, resolvedModelIdentity, agent,
389
+ input, cacheWrite, cacheRead, output,
390
+ cost: sawCost ? cost : null,
391
+ turns,
392
+ wallS: Number.isFinite(span) ? Math.round(span) : 0,
393
+ entries,
394
+ malformedNonLastLines,
395
+ openedPrs: [...openedPrs],
396
+ };
397
+ }
398
+
399
+ // One member record from one omp transcript's fold. `member` is the AgentId
400
+ // (the filename stem, e.g. `InstallVerifySearch`) — there is no separate
401
+ // display name, so `ticket`/`pr` extraction runs against it directly — except
402
+ // a `pr` the name cannot carry, read off the fold's `openedPrs` (#2209).
403
+ //
404
+ // `role` is NEVER guessed off the bare AgentId ALONE — a generated CamelCase
405
+ // word pair names nothing classifyRole can read. FOUR real signals exist:
406
+ // `session_init.agent` (the agent DEFINITION the dispatch named),
407
+ // `session_init.task` (the dispatch prompt, when present), `spawnDepth` (the
408
+ // transcript's own nesting depth, supplied by readOmpSession from the walk —
409
+ // a fact about where the file lives, not a guess about what it is), and —
410
+ // per #1506's ruling below — the AgentId itself, handed to classifyRole as
411
+ // `memberName`. Depth matters on its own: classifyRole checks depth BEFORE
412
+ // any text match, specifically so a nested member whose task happens to
413
+ // read like a reviewer's ("Review PR 1353 correctness") still books as the
414
+ // fan-out specialist it structurally is, not a reviewer. None present
415
+ // yields `"-"` — the same visible-hole spelling as `thinking`, never a
416
+ // default like "other", which only makes sense where a real dispatch record
417
+ // backs it.
418
+ //
419
+ // `agent` reaches classifyRole as its `agentDefinition` (#1486, #1505). It
420
+ // is the same value the `subagent_type` column below already records, and
421
+ // withholding it here made classifyRole's FIRST branch — the one whose
422
+ // comment says memory-system work must "never land in review spend" —
423
+ // structurally unreachable, leaving every row's role decided by
424
+ // dispatch-prompt prose alone. Measured 2026-09-16 before the fix: 50
425
+ // omp/memory-proxy rows, not one of them `role=memory`, and a single
426
+ // definition (`fleet-review-verifier`) split across four buckets on nothing
427
+ // but how each prompt happened to read.
428
+ //
429
+ // #1506's gap: `memberName` used to be left unset here on the theory that
430
+ // the AgentId genuinely is not a name — a generated CamelCase word pair
431
+ // (`InstallVerifySearch`) names nothing the classifier can read. True for
432
+ // the ordinary case, but false for members dispatched under run-team's own
433
+ // naming convention: `impl-<n>`, `fix-pr-<n>`, `finisher-<n>`, `finish-<n>`,
434
+ // `review-pr-<n>` and `merge-bot-<n>` ARE the dispatch name — exactly why
435
+ // `parseMemberName` runs against this same stem below. Those members are
436
+ // dispatched under the generic default `task` definition (`folded.agent` is
437
+ // `undefined`), so the definition-based fix above cannot reach them, and
438
+ // they fall through to prose classification of `folded.task` alone.
439
+ // Measured against docs/metrics/member-outcomes.tsv (#1506): 478 omp rows
440
+ // carry such an AgentId, 52 of them booked `other` for want of this signal —
441
+ // 31 `fix-pr-*`, 9 `impl-*` and 12 `merge-bot-*` members whose dispatch
442
+ // prompt never happens to name the role.
443
+ //
444
+ // RULED: pass the AgentId unconditionally — NOT gated on looking
445
+ // name-shaped first. Every name-driven branch in classifyRole is
446
+ // hyphen-anchored (`^impl-`, `review-pr-`, `fix-pr-`, `^finish-`) or a
447
+ // multi-word phrase ("implement ticket", "review pr"), so a stray generated
448
+ // word pair cannot coincidentally satisfy one; the one bare-word pattern,
449
+ // `finisher`, carries that risk today and has not fired on the 4,574
450
+ // sidecars measured for #1505. `OMP_CANONICAL_STEM_RE` below exists only to
451
+ // widen `hasRoleSignal` itself: a canonically-named member whose transcript
452
+ // predates #1343 (no `session_init` line at all, so neither `task` nor
453
+ // `agent` exist) still holds a readable identity and must not fall back to
454
+ // the "-" hole. Measured 2026-09-16: zero such rows on disk today, but the
455
+ // gate exists so the design does not assume that stays true forever. Built
456
+ // from `CANONICAL_MEMBER_NAME_PREFIXES` (compute-spend.mjs) rather than its
457
+ // own copy of the prefix list, so the two cannot drift apart.
458
+ //
459
+ // REJECTED: dispatching these roles under real agent definitions instead
460
+ // (the issue's other named approach) — a controller/dispatch-convention
461
+ // change, out of scope for a classifier fix, and unlike this one it cannot
462
+ // repair the 478 historical rows already on disk.
463
+ const OMP_CANONICAL_STEM_RE = new RegExp(`^(?:${CANONICAL_MEMBER_NAME_PREFIXES})-`);
464
+ export function ompMemberRecord(folded, agentStem, spawnDepth = 0) {
465
+ if (!folded.model) return null; // no assistant turn — not a real member transcript
466
+ const member = agentStem;
467
+ const { ticket, pr: namedPr } = parseMemberName(member);
468
+ // A name-carried PR (`fix-pr-<n>`, `finisher-<n>`, ...) is the member's unit
469
+ // of work by construction and wins. Otherwise (#2209) the one PR its own
470
+ // `gh pr create` printed; none, or more than one (measured: impl-1578 opened
471
+ // its real PR plus a throwaway probe PR), stays blank — never a guess.
472
+ // `folded.openedPrs` is `foldOmpTranscript`'s own unconditional return
473
+ // shape (always an array, never absent), so no `?.` is needed here.
474
+ const pr = namedPr || (folded.openedPrs.length === 1 ? folded.openedPrs[0] : "");
475
+ const hasRoleSignal = spawnDepth >= 1 || typeof folded.task === "string" || typeof folded.agent === "string"
476
+ || OMP_CANONICAL_STEM_RE.test(member);
477
+ const role = hasRoleSignal
478
+ ? classifyRole({ agentDefinition: folded.agent, memberName: member, description: folded.task, spawnDepth })
479
+ : "-";
480
+ return {
481
+ harness: "omp",
482
+ role,
483
+ member,
484
+ model: folded.model,
485
+ // Additive only (#1345) — `model` above stays the per-turn value
486
+ // board.mjs/member-outcomes.mjs already key cost/spend attribution on;
487
+ // this is the dispatch-time identity `session_init` wrote before any
488
+ // turn existed, `null` when the transcript predates #1343 or carries no
489
+ // `session_init` line at all (never guessed).
490
+ resolvedModelIdentity: folded.resolvedModelIdentity ?? null,
491
+ thinking: folded.thinking ?? "-",
492
+ // The dispatch record's own agent definition, `""` when the transcript
493
+ // carries no `session_init` line to read one from.
494
+ subagent_type: folded.agent ?? "",
495
+ tokens_in: folded.input, tokens_cache_create: folded.cacheWrite,
496
+ tokens_cache_read: folded.cacheRead, tokens_out: folded.output,
497
+ cost: folded.cost,
498
+ wall_s: folded.wallS, turns: folded.turns,
499
+ ticket, pr,
500
+ };
501
+ }
502
+
503
+ // ompMemberRecord straight from the transcript text. board.mjs's live spend
504
+ // panel calls the two halves itself instead, because it needs the fold's tool
505
+ // stream (#1717) beside the record, and folding the file twice for it would
506
+ // parse every transcript twice on every tick.
507
+ export function readOmpMember(jsonlText, filePath, agentStem, spawnDepth = 0) {
508
+ return ompMemberRecord(foldOmpTranscript(jsonlText, filePath), agentStem, spawnDepth);
509
+ }
510
+
511
+ // One omp session directory's member transcripts, as the walk both readers of
512
+ // that directory need it: readOmpSession below, and board.mjs's live spend
513
+ // panel (#1716), which folds each file itself so it can keep its own
514
+ // per-transcript skip tally. RECURSIVE: a member can itself dispatch further
515
+ // members (measured on disk — a research session's `Facts1303/` held seven
516
+ // more `.jsonl` files one level down), and `agent` is the path-relative stem
517
+ // so those nest instead of colliding. `spawnDepth` is read straight off
518
+ // that path — one `/` per nesting level — and handed to ompMemberRecord as a
519
+ // real fact about the walk, not a guess about the member.
520
+ //
521
+ // Throws when the directory itself cannot be listed; the caller decides what
522
+ // that means.
523
+ export function ompSessionTranscripts(sessionDir) {
524
+ return readdirSync(sessionDir, { recursive: true })
525
+ .filter((f) => f.endsWith(".jsonl"))
526
+ .map((f) => ({
527
+ file: join(sessionDir, f),
528
+ agent: f.replace(/\.jsonl$/, ""),
529
+ spawnDepth: (f.match(/[\\/]/g) ?? []).length,
530
+ }));
531
+ }
532
+
533
+ // Walks one omp session directory into records, via the walk above.
534
+ //
535
+ // Deliberately NOT wrapped in a blanket try/catch around readOmpMember: the
536
+ // wrong-shape refusal (assertOmpShaped, inside foldOmpTranscript) must
537
+ // propagate all the way out of readMembers, uncaught, per #1342's acceptance
538
+ // criterion. Only the directory listing and the raw file read are given the
539
+ // ordinary per-member tolerance.
540
+ export function readOmpSession(sessionDir) {
541
+ let transcripts;
542
+ try { transcripts = ompSessionTranscripts(sessionDir); }
543
+ catch { return []; }
544
+ const session = basename(sessionDir);
545
+ const rows = [];
546
+ for (const { file, agent, spawnDepth } of transcripts) {
547
+ let text;
548
+ try { text = readFileSync(file, "utf8"); }
549
+ catch { continue; }
550
+ const rec = readOmpMember(text, file, agent, spawnDepth); // may throw — see comment above
551
+ if (!rec) continue;
552
+ rows.push({ ...rec, session, agent });
553
+ }
554
+ return rows;
555
+ }
556
+
557
+ // An omp session directory is identified STRICTLY by name — `<ISO>_<uuid>`,
558
+ // e.g. `2026-09-08T13-13-27-300Z_01a08126-…` — never by holding `.jsonl`
559
+ // files directly. That second test used to be a shortcut, and it fired one
560
+ // level too high on the real tree: `~/.omp/agent/sessions/-dev-fleet-plugin/`
561
+ // holds the project's MAIN-session transcripts as plain files SIBLING to the
562
+ // per-session directories, so `findOmpSessionDirs` recursing from the
563
+ // encoded-cwd dir hit the `.jsonl` test there first, returned the whole
564
+ // project as "one session", stamped every row `session=-dev-fleet-plugin`
565
+ // instead of the `<ISO>_<uuid>` name #1302 rules the row key on, and booked
566
+ // the controller's own top-level transcripts as members. Name-only matching
567
+ // costs nothing a real fixture needs: every fixture in this repo already
568
+ // names its session dir in the real shape.
569
+ const OMP_SESSION_DIR_RE = /^\d{4}-\d{2}-\d{2}T[\d-]+Z_[0-9a-f-]+$/i;
570
+
571
+ // Exposed for callers that already hold one EXPLICIT directory rather than a
572
+ // tree to search — member-outcomes.mjs's CLI, so the pattern is defined once.
573
+ export function isOmpSessionDirName(name) {
574
+ return OMP_SESSION_DIR_RE.test(name);
575
+ }
576
+
577
+ function findOmpSessionDirs(root) {
578
+ if (OMP_SESSION_DIR_RE.test(basename(root))) return [root];
579
+ let ents;
580
+ try { ents = readdirSync(root, { withFileTypes: true }); }
581
+ catch { return []; }
582
+ const found = [];
583
+ for (const e of ents) if (e.isDirectory()) found.push(...findOmpSessionDirs(join(root, e.name)));
584
+ return found;
585
+ }
586
+
587
+ // ---------------------------------------------------------------------------
588
+ // readMembers — the one entry point
589
+ // ---------------------------------------------------------------------------
590
+
591
+ // The adapter's public entry point. A root that resolves to no session
592
+ // directory anywhere is refused rather than silently skipped: silently
593
+ // returning no rows for a typo'd path is the blackout #1302's ruling exists
594
+ // to prevent.
595
+ export function readMembers(roots) {
596
+ const rows = [];
597
+ for (const root of [].concat(roots ?? [])) {
598
+ const dirs = findOmpSessionDirs(root);
599
+ if (dirs.length === 0) {
600
+ throw new Error(`member-record: no omp session directory found anywhere under this root, refusing to silently contribute nothing: ${root}`);
601
+ }
602
+ for (const dir of dirs) rows.push(...readOmpSession(dir));
603
+ }
604
+ return rows;
605
+ }