@indigoai-us/hq-cli 5.345.247 → 5.345.248

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 (239) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
  3. package/contracts/host-canary-release.json +14 -0
  4. package/dist/command-catalog.generated.d.ts +1113 -0
  5. package/dist/command-catalog.generated.js +1370 -0
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/lanes-hold.js +7 -7
  9. package/dist/commands/lanes-resume.js +2 -2
  10. package/dist/commands/lanes-review.js +1 -1
  11. package/dist/commands/lanes-session-start.d.ts +1 -1
  12. package/dist/commands/lanes-session-start.js +3 -3
  13. package/dist/commands/lanes-shared.d.ts +1 -1
  14. package/dist/commands/lanes.d.ts +2 -2
  15. package/dist/commands/lanes.js +50 -50
  16. package/dist/commands/mesh.d.ts +25 -0
  17. package/dist/commands/mesh.js +48 -8
  18. package/dist/commands/ontology-graph.d.ts +62 -0
  19. package/dist/commands/ontology-graph.js +439 -0
  20. package/dist/index.js +1 -1
  21. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  22. package/dist/lanes-monitor-check-argv.js +1 -1
  23. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  24. package/dist/lanes-monitor-check-fast.js +1 -1
  25. package/dist/lanes-session-start-argv.d.ts +1 -1
  26. package/dist/lanes-session-start-argv.js +1 -1
  27. package/dist/lib/capacity/sign-in.d.ts +1 -1
  28. package/dist/lib/capacity/sign-in.js +1 -1
  29. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  30. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  31. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  32. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  33. package/dist/lib/daemon/merge-sections.js +7 -7
  34. package/dist/lib/daemon/remote-control-pools.js +1 -1
  35. package/dist/lib/daemon/run.js +1 -1
  36. package/dist/lib/daemon/state-file.d.ts +1 -1
  37. package/dist/lib/daemon/state-file.js +1 -1
  38. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  39. package/dist/lib/flag-snapshot-file.js +118 -48
  40. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  41. package/dist/lib/hook-engine/canary-gate.js +138 -6
  42. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  43. package/dist/lib/hot-channels/graph-context.js +377 -0
  44. package/dist/lib/hot-channels/signals-pass.js +27 -1
  45. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  46. package/dist/lib/lanes/claude-credential.js +1 -1
  47. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  48. package/dist/lib/lanes/delivery-core.js +1 -1
  49. package/dist/lib/lanes/delivery.d.ts +10 -10
  50. package/dist/lib/lanes/delivery.js +8 -8
  51. package/dist/lib/lanes/dropbox.d.ts +1 -1
  52. package/dist/lib/lanes/dropbox.js +1 -1
  53. package/dist/lib/lanes/hooks-install.js +2 -2
  54. package/dist/lib/lanes/index.d.ts +1 -1
  55. package/dist/lib/lanes/index.js +1 -1
  56. package/dist/lib/lanes/monitor.js +1 -1
  57. package/dist/lib/lanes/quota-notice.js +1 -1
  58. package/dist/lib/lanes/quota.d.ts +1 -1
  59. package/dist/lib/lanes/quota.js +1 -1
  60. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  61. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  62. package/dist/lib/lanes/spawn.d.ts +4 -4
  63. package/dist/lib/lanes/spawn.js +5 -5
  64. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  65. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  66. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  67. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  68. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  69. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  70. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  71. package/dist/lib/mesh/live/daemon/run.js +35 -2
  72. package/dist/lib/mesh/live/direct-drain.js +1 -1
  73. package/dist/lib/mesh/live/emit.d.ts +3 -0
  74. package/dist/lib/mesh/live/emit.js +32 -9
  75. package/dist/lib/mesh/live/flush.d.ts +3 -0
  76. package/dist/lib/mesh/live/flush.js +115 -32
  77. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  78. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  79. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  80. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  81. package/dist/lib/mesh/live/spool.d.ts +17 -2
  82. package/dist/lib/mesh/live/spool.js +22 -6
  83. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  84. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  85. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  86. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  87. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  88. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  89. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  90. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  91. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  92. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  93. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  94. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  95. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  96. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  97. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  98. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  99. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  100. package/dist/lib/ontology-graph/lint/index.js +176 -0
  101. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  102. package/dist/lib/ontology-graph/model/files.js +89 -0
  103. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  104. package/dist/lib/ontology-graph/model/index.js +100 -0
  105. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  106. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  107. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  108. package/dist/lib/ontology-graph/model/pass.js +958 -0
  109. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  110. package/dist/lib/ontology-graph/model/runner.js +160 -0
  111. package/dist/lib/ontology-graph/model/step.d.ts +195 -0
  112. package/dist/lib/ontology-graph/model/step.js +523 -0
  113. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  114. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  115. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  116. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  117. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  118. package/dist/lib/ontology-graph/org/compare.js +239 -0
  119. package/dist/lib/ontology-graph/org/derive.d.ts +65 -0
  120. package/dist/lib/ontology-graph/org/derive.js +352 -0
  121. package/dist/lib/ontology-graph/org/index.d.ts +73 -0
  122. package/dist/lib/ontology-graph/org/index.js +513 -0
  123. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  124. package/dist/lib/ontology-graph/org/load.js +476 -0
  125. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  126. package/dist/lib/ontology-graph/org/role.js +268 -0
  127. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  128. package/dist/lib/ontology-graph/org/structure.js +437 -0
  129. package/dist/lib/ontology-graph/org/text.d.ts +95 -0
  130. package/dist/lib/ontology-graph/org/text.js +315 -0
  131. package/dist/lib/ontology-graph/org/types.d.ts +452 -0
  132. package/dist/lib/ontology-graph/org/types.js +80 -0
  133. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  134. package/dist/lib/ontology-graph/pages/index.js +193 -0
  135. package/dist/lib/ontology-graph/pages/render.d.ts +142 -0
  136. package/dist/lib/ontology-graph/pages/render.js +682 -0
  137. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  138. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  139. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  140. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  141. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  142. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  143. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  144. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  145. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  146. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  147. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  148. package/dist/lib/ontology-graph/read/brief.js +251 -0
  149. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  150. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  151. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  152. package/dist/lib/ontology-graph/read/index.js +792 -0
  153. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  154. package/dist/lib/ontology-graph/read/member.js +34 -0
  155. package/dist/lib/ontology-graph/read/names.d.ts +44 -0
  156. package/dist/lib/ontology-graph/read/names.js +292 -0
  157. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  158. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  159. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  160. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  161. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  162. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  163. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  164. package/dist/lib/ontology-graph/replay/config.js +105 -0
  165. package/dist/lib/ontology-graph/replay/engine.d.ts +100 -0
  166. package/dist/lib/ontology-graph/replay/engine.js +1174 -0
  167. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  168. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  169. package/dist/lib/ontology-graph/replay/index.d.ts +90 -0
  170. package/dist/lib/ontology-graph/replay/index.js +220 -0
  171. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  172. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  173. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  174. package/dist/lib/ontology-graph/replay/member.js +65 -0
  175. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  176. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  177. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  178. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  179. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  180. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  181. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  182. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  183. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  184. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  185. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  186. package/dist/lib/ontology-graph/replay/util.js +256 -0
  187. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  188. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  189. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  190. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  191. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  192. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  193. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  194. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  195. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  196. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  197. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  198. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  199. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  200. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  201. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  202. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  203. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  204. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  205. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  206. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  207. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  208. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  209. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  210. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  211. package/dist/lib/ontology-graph/schema/authority.d.ts +73 -0
  212. package/dist/lib/ontology-graph/schema/authority.js +157 -0
  213. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  214. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  215. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  216. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  217. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  218. package/dist/lib/ontology-graph/schema/index.js +10 -0
  219. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  220. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  221. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  222. package/dist/lib/ontology-graph/store/files.js +207 -0
  223. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  224. package/dist/lib/ontology-graph/store/fs.js +101 -0
  225. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  226. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  227. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  228. package/dist/lib/ontology-graph/store/index.js +15 -0
  229. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  230. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  231. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  232. package/dist/lib/ontology-graph/store/paths.js +232 -0
  233. package/dist/lib/ontology-graph/types.d.ts +1183 -0
  234. package/dist/lib/ontology-graph/types.js +131 -0
  235. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  236. package/dist/utils/frontmatter.d.ts +14 -0
  237. package/dist/utils/frontmatter.js +18 -0
  238. package/dist/utils/interactive-caller.js +1 -1
  239. package/package.json +8 -8
@@ -0,0 +1,39 @@
1
+ export interface TranscriptExtract {
2
+ sessionId: string;
3
+ file: string;
4
+ size: number;
5
+ mtimeMs: number;
6
+ firstAt: string;
7
+ lastAt: string;
8
+ gitBranch: string;
9
+ /** User prompts in order, each cut to the configured length. */
10
+ prompts: string[];
11
+ /** The last assistant text of the session. */
12
+ final: string;
13
+ /** Working directories the user typed prompts in, distinct, in order. */
14
+ cwds: string[];
15
+ /**
16
+ * Company scopes the session names (a `companies/<slug>` path in a working
17
+ * directory or a prompt, a `--company` flag, `bind company <slug>`), read from
18
+ * the whole of every typed prompt and the final message. The reader drops a
19
+ * session that names a company other than the one being replayed (C7).
20
+ */
21
+ companies: string[];
22
+ /**
23
+ * The company scopes the user typed: the same as `companies` without what
24
+ * only the assistant's final message names. Only these can tie a session to
25
+ * a company; the assistant citing a company's file is not the user working
26
+ * for that company.
27
+ */
28
+ typedCompanies: string[];
29
+ }
30
+ export interface ReadTranscriptsOptions {
31
+ maxPrompts: number;
32
+ maxChars: number;
33
+ cacheFile: string | null;
34
+ writeCache: boolean;
35
+ }
36
+ export declare function extractTranscript(file: string, maxPrompts: number, maxChars: number): TranscriptExtract | null;
37
+ /** Extracts for the top-level `*.jsonl` files of a transcript folder, sorted by session id. */
38
+ export declare function readTranscripts(dir: string, options: ReadTranscriptsOptions): TranscriptExtract[];
39
+ //# sourceMappingURL=transcripts.d.ts.map
@@ -0,0 +1,224 @@
1
+ /**
2
+ * WP-B: the cheap extract of Claude Code session transcripts. Only the user's
3
+ * own prompts and the final assistant message are kept; tool calls, tool
4
+ * results, thinking and subagent files are never parsed.
5
+ *
6
+ * Transcripts are large (gigabytes in total). A file is read once in 4 MB
7
+ * chunks, lines are tested as bytes, and only the few candidate lines are
8
+ * decoded. The extract is cached by file size and mtime.
9
+ */
10
+ import * as fs from "node:fs";
11
+ import * as path from "node:path";
12
+ import { companyScopesIn } from "./rules.js";
13
+ import { asList, asRecord, asString, listFiles, oneLine } from "./util.js";
14
+ const CHUNK = 4 * 1024 * 1024;
15
+ const MAX_LINE = 1024 * 1024;
16
+ const USER_MARK = Buffer.from('"type":"user"');
17
+ const ASSISTANT_MARK = Buffer.from('"type":"assistant"');
18
+ const TEXT_MARK = Buffer.from('"type":"text"');
19
+ const TOOL_RESULT_MARK = Buffer.from('"tool_result"');
20
+ const SIDECHAIN_MARK = Buffer.from('"isSidechain":true');
21
+ function messageText(message) {
22
+ const content = asRecord(message).content;
23
+ if (typeof content === "string")
24
+ return content;
25
+ return asList(content)
26
+ .map((part) => asRecord(part))
27
+ .filter((part) => part.type === "text")
28
+ .map((part) => asString(part.text))
29
+ .join("\n");
30
+ }
31
+ /** Injected context and command wrappers are not something the user typed. */
32
+ function isTypedPrompt(text) {
33
+ const trimmed = text.trim();
34
+ if (trimmed === "")
35
+ return false;
36
+ if (trimmed.startsWith("<") || trimmed.startsWith("[Request interrupted"))
37
+ return false;
38
+ if (trimmed.startsWith("Caveat:") || trimmed.startsWith("This session is being continued"))
39
+ return false;
40
+ return true;
41
+ }
42
+ export function extractTranscript(file, maxPrompts, maxChars) {
43
+ let stat;
44
+ try {
45
+ stat = fs.statSync(file);
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ const extract = {
51
+ sessionId: path.basename(file, ".jsonl"),
52
+ file,
53
+ size: stat.size,
54
+ mtimeMs: Math.floor(stat.mtimeMs),
55
+ firstAt: "",
56
+ lastAt: "",
57
+ gitBranch: "",
58
+ prompts: [],
59
+ final: "",
60
+ cwds: [],
61
+ companies: [],
62
+ typedCompanies: [],
63
+ };
64
+ let lastAssistant = null;
65
+ const scopes = new Set();
66
+ const handle = (line) => {
67
+ if (line.length === 0 || line.length > MAX_LINE || line.includes(SIDECHAIN_MARK))
68
+ return;
69
+ if (line.includes(USER_MARK)) {
70
+ if (line.includes(TOOL_RESULT_MARK))
71
+ return;
72
+ let row;
73
+ try {
74
+ row = asRecord(JSON.parse(line.toString("utf8")));
75
+ }
76
+ catch {
77
+ return;
78
+ }
79
+ if (row.type !== "user" || row.isMeta === true)
80
+ return;
81
+ const text = messageText(row.message);
82
+ if (!isTypedPrompt(text))
83
+ return;
84
+ const at = asString(row.timestamp);
85
+ if (at) {
86
+ if (!extract.firstAt)
87
+ extract.firstAt = at;
88
+ extract.lastAt = at;
89
+ }
90
+ if (!extract.gitBranch)
91
+ extract.gitBranch = asString(row.gitBranch);
92
+ const cwd = asString(row.cwd);
93
+ if (cwd && !extract.cwds.includes(cwd) && extract.cwds.length < 24)
94
+ extract.cwds.push(cwd);
95
+ for (const scope of companyScopesIn(`${cwd}\n${text}`))
96
+ scopes.add(scope);
97
+ if (extract.prompts.length < maxPrompts)
98
+ extract.prompts.push(oneLine(text, maxChars));
99
+ }
100
+ else if (line.includes(ASSISTANT_MARK) && line.includes(TEXT_MARK)) {
101
+ lastAssistant = Buffer.from(line);
102
+ }
103
+ };
104
+ const fd = fs.openSync(file, "r");
105
+ try {
106
+ const buffer = Buffer.allocUnsafe(CHUNK);
107
+ let carry = [];
108
+ let carryBytes = 0;
109
+ let position = 0;
110
+ for (;;) {
111
+ const read = fs.readSync(fd, buffer, 0, CHUNK, position);
112
+ if (read <= 0)
113
+ break;
114
+ position += read;
115
+ let start = 0;
116
+ for (;;) {
117
+ const end = buffer.indexOf(10, start);
118
+ if (end < 0 || end >= read)
119
+ break;
120
+ if (carry.length > 0) {
121
+ // A line longer than MAX_LINE is a tool result; skip it without joining the pieces.
122
+ if (carryBytes + (end - start) <= MAX_LINE)
123
+ handle(Buffer.concat([...carry, buffer.subarray(start, end)]));
124
+ carry = [];
125
+ carryBytes = 0;
126
+ }
127
+ else {
128
+ handle(buffer.subarray(start, end));
129
+ }
130
+ start = end + 1;
131
+ }
132
+ if (start < read) {
133
+ if (carryBytes <= MAX_LINE)
134
+ carry.push(Buffer.from(buffer.subarray(start, read)));
135
+ carryBytes += read - start;
136
+ }
137
+ }
138
+ if (carry.length > 0 && carryBytes <= MAX_LINE)
139
+ handle(Buffer.concat(carry));
140
+ }
141
+ finally {
142
+ fs.closeSync(fd);
143
+ }
144
+ if (extract.prompts.length === 0 || !extract.firstAt)
145
+ return null;
146
+ extract.typedCompanies = [...scopes].sort();
147
+ if (lastAssistant) {
148
+ try {
149
+ const row = asRecord(JSON.parse(lastAssistant.toString("utf8")));
150
+ const final = messageText(row.message);
151
+ for (const scope of companyScopesIn(final))
152
+ scopes.add(scope);
153
+ extract.final = oneLine(final, maxChars * 2);
154
+ }
155
+ catch {
156
+ extract.final = "";
157
+ }
158
+ }
159
+ extract.companies = [...scopes].sort();
160
+ return extract;
161
+ }
162
+ /** Extracts for the top-level `*.jsonl` files of a transcript folder, sorted by session id. */
163
+ export function readTranscripts(dir, options) {
164
+ const cache = new Map();
165
+ if (options.cacheFile) {
166
+ try {
167
+ for (const line of fs.readFileSync(options.cacheFile, "utf8").split("\n")) {
168
+ if (line.trim() === "")
169
+ continue;
170
+ try {
171
+ const row = JSON.parse(line);
172
+ if (typeof row.sessionId === "string")
173
+ cache.set(row.sessionId, row);
174
+ }
175
+ catch {
176
+ // a torn line is ignored
177
+ }
178
+ }
179
+ }
180
+ catch {
181
+ // no cache yet
182
+ }
183
+ }
184
+ const extracts = [];
185
+ const fresh = [];
186
+ let changed = false;
187
+ for (const name of listFiles(dir, ".jsonl")) {
188
+ const file = path.join(dir, name);
189
+ const sessionId = name.replace(/\.jsonl$/, "");
190
+ let stat;
191
+ try {
192
+ stat = fs.statSync(file);
193
+ }
194
+ catch {
195
+ continue;
196
+ }
197
+ const cached = cache.get(sessionId);
198
+ // A line written before the extract carried `cwds`, `companies` and `typedCompanies` is read again.
199
+ if (cached && cached.size === stat.size && cached.mtimeMs === Math.floor(stat.mtimeMs) && Array.isArray(cached.cwds) && Array.isArray(cached.companies) && Array.isArray(cached.typedCompanies)) {
200
+ fresh.push(cached);
201
+ if (!cached.empty)
202
+ extracts.push({ ...cached, file });
203
+ continue;
204
+ }
205
+ changed = true;
206
+ const extract = extractTranscript(file, options.maxPrompts, options.maxChars);
207
+ if (extract) {
208
+ extracts.push(extract);
209
+ const { file: _file, ...line } = extract;
210
+ fresh.push(line);
211
+ }
212
+ else {
213
+ fresh.push({ sessionId, size: stat.size, mtimeMs: Math.floor(stat.mtimeMs), firstAt: "", lastAt: "", gitBranch: "", prompts: [], final: "", cwds: [], companies: [], typedCompanies: [], empty: true });
214
+ }
215
+ }
216
+ if (options.cacheFile && options.writeCache && changed) {
217
+ fs.mkdirSync(path.dirname(options.cacheFile), { recursive: true });
218
+ const temp = `${options.cacheFile}.tmp-${process.pid}`;
219
+ fs.writeFileSync(temp, fresh.map((line) => JSON.stringify(line)).join("\n") + (fresh.length > 0 ? "\n" : ""));
220
+ fs.renameSync(temp, options.cacheFile);
221
+ }
222
+ return extracts;
223
+ }
224
+ //# sourceMappingURL=transcripts.js.map
@@ -0,0 +1,55 @@
1
+ /**
2
+ * WP-B helpers: frontmatter, dates, one-line text, folder listing. No graph
3
+ * knowledge here. Everything is synchronous and reads each file once.
4
+ */
5
+ import * as fs from "node:fs";
6
+ import type { IsoDate } from "../types.js";
7
+ /** A synced conflict file or a Finder-style duplicate ("board 2.json", "x 3"). */
8
+ export declare function isCopyName(name: string): boolean;
9
+ /**
10
+ * The UTC calendar day of a date-like value: `2026-06-25`, an ISO timestamp
11
+ * with or without an offset, `20261019T131952Z`, epoch seconds or milliseconds,
12
+ * or a Date. Null when it is not a real day.
13
+ */
14
+ export declare function toDay(value: unknown): IsoDate | null;
15
+ /** First usable day among the candidates. */
16
+ export declare function firstDay(...values: unknown[]): IsoDate | null;
17
+ export declare function mtimeDay(file: string): IsoDate | null;
18
+ export declare function addDays(day: IsoDate, count: number): IsoDate;
19
+ /** Collapses whitespace, strips markdown emphasis markers, cuts at `max` characters. */
20
+ export declare function oneLine(text: unknown, max?: number): string;
21
+ export declare function asString(value: unknown): string;
22
+ export declare function asRecord(value: unknown): Record<string, unknown>;
23
+ export declare function asList(value: unknown): unknown[];
24
+ export declare function stringList(value: unknown): string[];
25
+ export interface SplitDocument {
26
+ frontmatter: Record<string, unknown>;
27
+ body: string;
28
+ /** False when the YAML block did not parse; the frontmatter is then empty. */
29
+ parsed: boolean;
30
+ }
31
+ /** Splits `---` frontmatter from the body. Timestamps stay strings (YAML core schema). */
32
+ export declare function splitFrontmatter(text: string): SplitDocument;
33
+ /**
34
+ * Reads only the start of a file, enough for its frontmatter. Falls back to
35
+ * the whole file when the closing `---` is past the first 16 KB.
36
+ */
37
+ export declare function readFrontmatterOnly(file: string): SplitDocument;
38
+ /**
39
+ * The value of one top-level scalar frontmatter key, read from the first 4 KB
40
+ * without parsing the block and without touching the body. Used for the
41
+ * ownership check on personal files: nothing else of the file is read.
42
+ */
43
+ export declare function probeFrontmatterKey(file: string, key: string): string | null;
44
+ export declare function readJsonFile(file: string): unknown;
45
+ export declare function readYamlFile(file: string): Record<string, unknown>;
46
+ /** Sorted entry names of a folder; empty when it is missing. Hidden entries and copies are left out. */
47
+ export declare function listDir(dir: string): fs.Dirent[];
48
+ export declare function listFiles(dir: string, suffix: string): string[];
49
+ export declare function listFolders(dir: string): string[];
50
+ /** Every file under `dir` with the suffix, as paths relative to `dir` with forward slashes, sorted. */
51
+ export declare function walkFiles(dir: string, suffix: string, maxDepth?: number): string[];
52
+ export declare function byCodeUnit(a: string, b: string): number;
53
+ /** Title-cases a slug: `hq-cli` becomes `Hq Cli`. Used only to ask the resolver about an old ref. */
54
+ export declare function nameFromSlug(slug: string): string;
55
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,256 @@
1
+ /**
2
+ * WP-B helpers: frontmatter, dates, one-line text, folder listing. No graph
3
+ * knowledge here. Everything is synchronous and reads each file once.
4
+ */
5
+ import * as fs from "node:fs";
6
+ import * as path from "node:path";
7
+ import yaml from "js-yaml";
8
+ const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
9
+ const COMPACT_STAMP = /^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})Z?)?$/;
10
+ /** A synced conflict file or a Finder-style duplicate ("board 2.json", "x 3"). */
11
+ export function isCopyName(name) {
12
+ if (name.includes(".conflict-"))
13
+ return true;
14
+ if (name.endsWith(".__hqpo"))
15
+ return true;
16
+ return / \d+(\.[A-Za-z0-9.]+)?$/.test(name);
17
+ }
18
+ function validDay(day) {
19
+ if (!ISO_DAY.test(day))
20
+ return null;
21
+ const date = new Date(`${day}T00:00:00Z`);
22
+ if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== day)
23
+ return null;
24
+ const year = Number(day.slice(0, 4));
25
+ return year >= 2000 && year <= 2100 ? day : null;
26
+ }
27
+ /**
28
+ * The UTC calendar day of a date-like value: `2026-06-25`, an ISO timestamp
29
+ * with or without an offset, `20261019T131952Z`, epoch seconds or milliseconds,
30
+ * or a Date. Null when it is not a real day.
31
+ */
32
+ export function toDay(value) {
33
+ if (value === null || value === undefined)
34
+ return null;
35
+ if (value instanceof Date)
36
+ return Number.isNaN(value.getTime()) ? null : validDay(value.toISOString().slice(0, 10));
37
+ if (typeof value === "number") {
38
+ if (!Number.isFinite(value) || value <= 0)
39
+ return null;
40
+ const ms = value < 1e11 ? value * 1000 : value;
41
+ return validDay(new Date(ms).toISOString().slice(0, 10));
42
+ }
43
+ if (typeof value !== "string")
44
+ return null;
45
+ const text = value.trim().replace(/^["']|["']$/g, "");
46
+ if (text === "")
47
+ return null;
48
+ if (ISO_DAY.test(text))
49
+ return validDay(text);
50
+ const compact = COMPACT_STAMP.exec(text);
51
+ if (compact)
52
+ return validDay(`${compact[1]}-${compact[2]}-${compact[3]}`);
53
+ if (/^\d{4}-\d{2}-\d{2}[T ]/.test(text)) {
54
+ const hasZone = /(Z|[+-]\d{2}:?\d{2})$/.test(text);
55
+ const parsed = Date.parse(hasZone ? text.replace(" ", "T") : `${text.replace(" ", "T")}Z`);
56
+ if (Number.isNaN(parsed))
57
+ return validDay(text.slice(0, 10));
58
+ return validDay(new Date(parsed).toISOString().slice(0, 10));
59
+ }
60
+ return null;
61
+ }
62
+ /** First usable day among the candidates. */
63
+ export function firstDay(...values) {
64
+ for (const value of values) {
65
+ const day = toDay(value);
66
+ if (day)
67
+ return day;
68
+ }
69
+ return null;
70
+ }
71
+ export function mtimeDay(file) {
72
+ try {
73
+ return toDay(fs.statSync(file).mtime);
74
+ }
75
+ catch {
76
+ return null;
77
+ }
78
+ }
79
+ export function addDays(day, count) {
80
+ const date = new Date(`${day}T00:00:00Z`);
81
+ date.setUTCDate(date.getUTCDate() + count);
82
+ return date.toISOString().slice(0, 10);
83
+ }
84
+ /** Collapses whitespace, strips markdown emphasis markers, cuts at `max` characters. */
85
+ export function oneLine(text, max = 200) {
86
+ if (typeof text !== "string")
87
+ return "";
88
+ const flat = text.replace(/[\r\n\t]+/g, " ").replace(/\s{2,}/g, " ").replace(/\*\*/g, "").trim();
89
+ if (flat.length <= max)
90
+ return flat;
91
+ return `${flat.slice(0, max - 1).trimEnd()}…`;
92
+ }
93
+ export function asString(value) {
94
+ return typeof value === "string" ? value.trim() : typeof value === "number" ? String(value) : "";
95
+ }
96
+ export function asRecord(value) {
97
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
98
+ }
99
+ export function asList(value) {
100
+ return Array.isArray(value) ? value : value === null || value === undefined || value === "" ? [] : [value];
101
+ }
102
+ export function stringList(value) {
103
+ return asList(value).map(asString).filter((entry) => entry !== "");
104
+ }
105
+ /** Splits `---` frontmatter from the body. Timestamps stay strings (YAML core schema). */
106
+ export function splitFrontmatter(text) {
107
+ if (!text.startsWith("---"))
108
+ return { frontmatter: {}, body: text, parsed: true };
109
+ const firstBreak = text.indexOf("\n");
110
+ if (firstBreak < 0 || text.slice(0, firstBreak).trim() !== "---")
111
+ return { frontmatter: {}, body: text, parsed: true };
112
+ const close = /\n---[ \t]*(\r?\n|$)/.exec(text.slice(firstBreak));
113
+ if (!close)
114
+ return { frontmatter: {}, body: text, parsed: false };
115
+ const block = text.slice(firstBreak + 1, firstBreak + close.index + 1);
116
+ const body = text.slice(firstBreak + close.index + close[0].length);
117
+ try {
118
+ const loaded = yaml.load(block, { schema: yaml.CORE_SCHEMA });
119
+ return { frontmatter: asRecord(loaded), body, parsed: true };
120
+ }
121
+ catch {
122
+ return { frontmatter: {}, body, parsed: false };
123
+ }
124
+ }
125
+ const HEAD_BYTES = 16 * 1024;
126
+ /**
127
+ * Reads only the start of a file, enough for its frontmatter. Falls back to
128
+ * the whole file when the closing `---` is past the first 16 KB.
129
+ */
130
+ export function readFrontmatterOnly(file) {
131
+ let head;
132
+ let size;
133
+ const fd = fs.openSync(file, "r");
134
+ try {
135
+ size = fs.fstatSync(fd).size;
136
+ const buffer = Buffer.allocUnsafe(Math.min(HEAD_BYTES, size));
137
+ const read = fs.readSync(fd, buffer, 0, buffer.length, 0);
138
+ head = buffer.toString("utf8", 0, read);
139
+ }
140
+ finally {
141
+ fs.closeSync(fd);
142
+ }
143
+ if (!head.startsWith("---"))
144
+ return { frontmatter: {}, body: "", parsed: true };
145
+ if (size > HEAD_BYTES && !/\n---[ \t]*(\r?\n|$)/.test(head.slice(3))) {
146
+ return splitFrontmatter(fs.readFileSync(file, "utf8"));
147
+ }
148
+ return splitFrontmatter(head);
149
+ }
150
+ /**
151
+ * The value of one top-level scalar frontmatter key, read from the first 4 KB
152
+ * without parsing the block and without touching the body. Used for the
153
+ * ownership check on personal files: nothing else of the file is read.
154
+ */
155
+ export function probeFrontmatterKey(file, key) {
156
+ let head;
157
+ const fd = fs.openSync(file, "r");
158
+ try {
159
+ const buffer = Buffer.allocUnsafe(4096);
160
+ const read = fs.readSync(fd, buffer, 0, buffer.length, 0);
161
+ head = buffer.toString("utf8", 0, read);
162
+ }
163
+ finally {
164
+ fs.closeSync(fd);
165
+ }
166
+ if (!head.startsWith("---"))
167
+ return null;
168
+ const end = head.indexOf("\n---", 3);
169
+ const block = end < 0 ? head : head.slice(0, end);
170
+ const match = new RegExp(`^${key}:[ \\t]*(.*)$`, "m").exec(block);
171
+ if (!match)
172
+ return null;
173
+ const value = match[1].trim().replace(/^["']|["']$/g, "");
174
+ return value === "" || value === "null" || value === "~" ? null : value;
175
+ }
176
+ export function readJsonFile(file) {
177
+ try {
178
+ return JSON.parse(fs.readFileSync(file, "utf8"));
179
+ }
180
+ catch {
181
+ return null;
182
+ }
183
+ }
184
+ export function readYamlFile(file) {
185
+ try {
186
+ return asRecord(yaml.load(fs.readFileSync(file, "utf8"), { schema: yaml.CORE_SCHEMA }));
187
+ }
188
+ catch {
189
+ return {};
190
+ }
191
+ }
192
+ /** Sorted entry names of a folder; empty when it is missing. Hidden entries and copies are left out. */
193
+ export function listDir(dir) {
194
+ let entries;
195
+ try {
196
+ entries = fs.readdirSync(dir, { withFileTypes: true });
197
+ }
198
+ catch {
199
+ return [];
200
+ }
201
+ return entries
202
+ .filter((entry) => !entry.name.startsWith(".") && !isCopyName(entry.name))
203
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
204
+ }
205
+ function isDirectory(dir, entry) {
206
+ if (entry.isDirectory())
207
+ return true;
208
+ if (!entry.isSymbolicLink())
209
+ return false;
210
+ try {
211
+ return fs.statSync(path.join(dir, entry.name)).isDirectory();
212
+ }
213
+ catch {
214
+ return false;
215
+ }
216
+ }
217
+ export function listFiles(dir, suffix) {
218
+ return listDir(dir)
219
+ .filter((entry) => !isDirectory(dir, entry) && entry.name.endsWith(suffix))
220
+ .map((entry) => entry.name);
221
+ }
222
+ export function listFolders(dir) {
223
+ return listDir(dir)
224
+ .filter((entry) => isDirectory(dir, entry))
225
+ .map((entry) => entry.name);
226
+ }
227
+ /** Every file under `dir` with the suffix, as paths relative to `dir` with forward slashes, sorted. */
228
+ export function walkFiles(dir, suffix, maxDepth = 8) {
229
+ const found = [];
230
+ const visit = (current, relative, depth) => {
231
+ for (const entry of listDir(current)) {
232
+ const rel = relative ? `${relative}/${entry.name}` : entry.name;
233
+ if (entry.isDirectory()) {
234
+ if (depth < maxDepth && entry.name !== "node_modules")
235
+ visit(path.join(current, entry.name), rel, depth + 1);
236
+ }
237
+ else if (entry.name.endsWith(suffix)) {
238
+ found.push(rel);
239
+ }
240
+ }
241
+ };
242
+ visit(dir, "", 0);
243
+ return found;
244
+ }
245
+ export function byCodeUnit(a, b) {
246
+ return a < b ? -1 : a > b ? 1 : 0;
247
+ }
248
+ /** Title-cases a slug: `hq-cli` becomes `Hq Cli`. Used only to ask the resolver about an old ref. */
249
+ export function nameFromSlug(slug) {
250
+ return slug
251
+ .split(/[-_.]+/)
252
+ .filter((part) => part !== "")
253
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
254
+ .join(" ");
255
+ }
256
+ //# sourceMappingURL=util.js.map