@memnexus-ai/mx-agent-cli 0.1.292 → 0.1.294-next.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 (242) hide show
  1. package/dist/__tests__/config-sync.test.js +54 -1
  2. package/dist/__tests__/config-sync.test.js.map +1 -1
  3. package/dist/__tests__/decision-check.test.d.ts +2 -0
  4. package/dist/__tests__/decision-check.test.d.ts.map +1 -0
  5. package/dist/__tests__/decision-check.test.js +105 -0
  6. package/dist/__tests__/decision-check.test.js.map +1 -0
  7. package/dist/__tests__/doctor-framework-version.test.d.ts +2 -0
  8. package/dist/__tests__/doctor-framework-version.test.d.ts.map +1 -0
  9. package/dist/__tests__/doctor-framework-version.test.js +146 -0
  10. package/dist/__tests__/doctor-framework-version.test.js.map +1 -0
  11. package/dist/__tests__/harness-extract.test.d.ts +19 -0
  12. package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
  13. package/dist/__tests__/harness-extract.test.js +566 -0
  14. package/dist/__tests__/harness-extract.test.js.map +1 -0
  15. package/dist/__tests__/harness-wiring.test.d.ts +16 -0
  16. package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
  17. package/dist/__tests__/harness-wiring.test.js +469 -0
  18. package/dist/__tests__/harness-wiring.test.js.map +1 -0
  19. package/dist/__tests__/mx-agent-cli-pin-validation.test.d.ts +2 -0
  20. package/dist/__tests__/mx-agent-cli-pin-validation.test.d.ts.map +1 -0
  21. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +256 -0
  22. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -0
  23. package/dist/__tests__/mx-agent-cli-version-pin.test.d.ts +2 -0
  24. package/dist/__tests__/mx-agent-cli-version-pin.test.d.ts.map +1 -0
  25. package/dist/__tests__/mx-agent-cli-version-pin.test.js +290 -0
  26. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -0
  27. package/dist/__tests__/report-format.test.d.ts +2 -0
  28. package/dist/__tests__/report-format.test.d.ts.map +1 -0
  29. package/dist/__tests__/report-format.test.js +219 -0
  30. package/dist/__tests__/report-format.test.js.map +1 -0
  31. package/dist/__tests__/standards-injection.test.d.ts +2 -0
  32. package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
  33. package/dist/__tests__/standards-injection.test.js +157 -0
  34. package/dist/__tests__/standards-injection.test.js.map +1 -0
  35. package/dist/agent-config/hooks/auto-capture-precompact.sh +74 -4
  36. package/dist/agent-config/hooks/auto-capture-session-end.sh +106 -4
  37. package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
  38. package/dist/agent-config/hooks/observability-sync.sh +46 -9
  39. package/dist/commands/config-sync.d.ts +37 -0
  40. package/dist/commands/config-sync.d.ts.map +1 -1
  41. package/dist/commands/config-sync.js +36 -18
  42. package/dist/commands/config-sync.js.map +1 -1
  43. package/dist/commands/dashboard.d.ts.map +1 -1
  44. package/dist/commands/dashboard.js +10 -2
  45. package/dist/commands/dashboard.js.map +1 -1
  46. package/dist/commands/decision.d.ts +20 -0
  47. package/dist/commands/decision.d.ts.map +1 -0
  48. package/dist/commands/decision.js +54 -0
  49. package/dist/commands/decision.js.map +1 -0
  50. package/dist/commands/doctor.d.ts +18 -0
  51. package/dist/commands/doctor.d.ts.map +1 -1
  52. package/dist/commands/doctor.js +41 -0
  53. package/dist/commands/doctor.js.map +1 -1
  54. package/dist/commands/monitor.d.ts.map +1 -1
  55. package/dist/commands/monitor.js +8 -2
  56. package/dist/commands/monitor.js.map +1 -1
  57. package/dist/commands/new.d.ts.map +1 -1
  58. package/dist/commands/new.js +15 -1
  59. package/dist/commands/new.js.map +1 -1
  60. package/dist/commands/report.d.ts +33 -0
  61. package/dist/commands/report.d.ts.map +1 -0
  62. package/dist/commands/report.js +73 -0
  63. package/dist/commands/report.js.map +1 -0
  64. package/dist/commands/start.d.ts +4 -0
  65. package/dist/commands/start.d.ts.map +1 -1
  66. package/dist/commands/start.js +6 -0
  67. package/dist/commands/start.js.map +1 -1
  68. package/dist/commands/update.d.ts +13 -1
  69. package/dist/commands/update.d.ts.map +1 -1
  70. package/dist/commands/update.js +50 -1
  71. package/dist/commands/update.js.map +1 -1
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +67 -3
  74. package/dist/index.js.map +1 -1
  75. package/dist/lib/agent-session.d.ts +12 -0
  76. package/dist/lib/agent-session.d.ts.map +1 -1
  77. package/dist/lib/agent-session.js +183 -41
  78. package/dist/lib/agent-session.js.map +1 -1
  79. package/dist/lib/claude.d.ts +12 -0
  80. package/dist/lib/claude.d.ts.map +1 -1
  81. package/dist/lib/claude.js +29 -2
  82. package/dist/lib/claude.js.map +1 -1
  83. package/dist/lib/decision-check.d.ts +48 -0
  84. package/dist/lib/decision-check.d.ts.map +1 -0
  85. package/dist/lib/decision-check.js +149 -0
  86. package/dist/lib/decision-check.js.map +1 -0
  87. package/dist/lib/framework-version.d.ts +144 -0
  88. package/dist/lib/framework-version.d.ts.map +1 -0
  89. package/dist/lib/framework-version.js +270 -0
  90. package/dist/lib/framework-version.js.map +1 -0
  91. package/dist/lib/harness/console/announce.d.ts +45 -0
  92. package/dist/lib/harness/console/announce.d.ts.map +1 -0
  93. package/dist/lib/harness/console/announce.js +48 -0
  94. package/dist/lib/harness/console/announce.js.map +1 -0
  95. package/dist/lib/harness/console/announce.test.d.ts +2 -0
  96. package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
  97. package/dist/lib/harness/console/announce.test.js +104 -0
  98. package/dist/lib/harness/console/announce.test.js.map +1 -0
  99. package/dist/lib/harness/console/by-session.d.ts +50 -0
  100. package/dist/lib/harness/console/by-session.d.ts.map +1 -0
  101. package/dist/lib/harness/console/by-session.js +83 -0
  102. package/dist/lib/harness/console/by-session.js.map +1 -0
  103. package/dist/lib/harness/console/by-session.test.d.ts +2 -0
  104. package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
  105. package/dist/lib/harness/console/by-session.test.js +86 -0
  106. package/dist/lib/harness/console/by-session.test.js.map +1 -0
  107. package/dist/lib/harness/console/console.d.ts +67 -0
  108. package/dist/lib/harness/console/console.d.ts.map +1 -0
  109. package/dist/lib/harness/console/console.js +373 -0
  110. package/dist/lib/harness/console/console.js.map +1 -0
  111. package/dist/lib/harness/console/console.test.d.ts +2 -0
  112. package/dist/lib/harness/console/console.test.d.ts.map +1 -0
  113. package/dist/lib/harness/console/console.test.js +269 -0
  114. package/dist/lib/harness/console/console.test.js.map +1 -0
  115. package/dist/lib/harness/console/decision-request.d.ts +32 -0
  116. package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
  117. package/dist/lib/harness/console/decision-request.js +112 -0
  118. package/dist/lib/harness/console/decision-request.js.map +1 -0
  119. package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
  120. package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
  121. package/dist/lib/harness/console/decision-request.test.js +75 -0
  122. package/dist/lib/harness/console/decision-request.test.js.map +1 -0
  123. package/dist/lib/harness/console/fixtures.d.ts +16 -0
  124. package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
  125. package/dist/lib/harness/console/fixtures.js +49 -0
  126. package/dist/lib/harness/console/fixtures.js.map +1 -0
  127. package/dist/lib/harness/console/index.d.ts +15 -0
  128. package/dist/lib/harness/console/index.d.ts.map +1 -0
  129. package/dist/lib/harness/console/index.js +14 -0
  130. package/dist/lib/harness/console/index.js.map +1 -0
  131. package/dist/lib/harness/console/rank.d.ts +73 -0
  132. package/dist/lib/harness/console/rank.d.ts.map +1 -0
  133. package/dist/lib/harness/console/rank.js +113 -0
  134. package/dist/lib/harness/console/rank.js.map +1 -0
  135. package/dist/lib/harness/console/rank.test.d.ts +2 -0
  136. package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
  137. package/dist/lib/harness/console/rank.test.js +124 -0
  138. package/dist/lib/harness/console/rank.test.js.map +1 -0
  139. package/dist/lib/harness/console/render.d.ts +22 -0
  140. package/dist/lib/harness/console/render.d.ts.map +1 -0
  141. package/dist/lib/harness/console/render.js +65 -0
  142. package/dist/lib/harness/console/render.js.map +1 -0
  143. package/dist/lib/harness/console/render.test.d.ts +2 -0
  144. package/dist/lib/harness/console/render.test.d.ts.map +1 -0
  145. package/dist/lib/harness/console/render.test.js +96 -0
  146. package/dist/lib/harness/console/render.test.js.map +1 -0
  147. package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
  148. package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
  149. package/dist/lib/harness/console/replay-cli.test.js +96 -0
  150. package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
  151. package/dist/lib/harness/console/replay.d.ts +36 -0
  152. package/dist/lib/harness/console/replay.d.ts.map +1 -0
  153. package/dist/lib/harness/console/replay.js +59 -0
  154. package/dist/lib/harness/console/replay.js.map +1 -0
  155. package/dist/lib/harness/console/replay.test.d.ts +2 -0
  156. package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
  157. package/dist/lib/harness/console/replay.test.js +81 -0
  158. package/dist/lib/harness/console/replay.test.js.map +1 -0
  159. package/dist/lib/harness/console/turn-reader.d.ts +50 -0
  160. package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
  161. package/dist/lib/harness/console/turn-reader.js +184 -0
  162. package/dist/lib/harness/console/turn-reader.js.map +1 -0
  163. package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
  164. package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
  165. package/dist/lib/harness/console/turn-reader.test.js +108 -0
  166. package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
  167. package/dist/lib/harness/console/types.d.ts +109 -0
  168. package/dist/lib/harness/console/types.d.ts.map +1 -0
  169. package/dist/lib/harness/console/types.js +2 -0
  170. package/dist/lib/harness/console/types.js.map +1 -0
  171. package/dist/lib/harness/contract.d.ts +229 -0
  172. package/dist/lib/harness/contract.d.ts.map +1 -0
  173. package/dist/lib/harness/contract.js +22 -0
  174. package/dist/lib/harness/contract.js.map +1 -0
  175. package/dist/lib/harness/credential.d.ts +23 -0
  176. package/dist/lib/harness/credential.d.ts.map +1 -0
  177. package/dist/lib/harness/credential.js +81 -0
  178. package/dist/lib/harness/credential.js.map +1 -0
  179. package/dist/lib/harness/credential.test.d.ts +2 -0
  180. package/dist/lib/harness/credential.test.d.ts.map +1 -0
  181. package/dist/lib/harness/credential.test.js +74 -0
  182. package/dist/lib/harness/credential.test.js.map +1 -0
  183. package/dist/lib/harness/evaluate.d.ts +390 -0
  184. package/dist/lib/harness/evaluate.d.ts.map +1 -0
  185. package/dist/lib/harness/evaluate.js +988 -0
  186. package/dist/lib/harness/evaluate.js.map +1 -0
  187. package/dist/lib/harness/evaluate.test.d.ts +2 -0
  188. package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
  189. package/dist/lib/harness/evaluate.test.js +621 -0
  190. package/dist/lib/harness/evaluate.test.js.map +1 -0
  191. package/dist/lib/harness/extract.d.ts +152 -0
  192. package/dist/lib/harness/extract.d.ts.map +1 -0
  193. package/dist/lib/harness/extract.js +1601 -0
  194. package/dist/lib/harness/extract.js.map +1 -0
  195. package/dist/lib/harness/gate.d.ts +48 -0
  196. package/dist/lib/harness/gate.d.ts.map +1 -0
  197. package/dist/lib/harness/gate.js +60 -0
  198. package/dist/lib/harness/gate.js.map +1 -0
  199. package/dist/lib/harness/gate.test.d.ts +2 -0
  200. package/dist/lib/harness/gate.test.d.ts.map +1 -0
  201. package/dist/lib/harness/gate.test.js +111 -0
  202. package/dist/lib/harness/gate.test.js.map +1 -0
  203. package/dist/lib/harness/self-check.d.ts +59 -0
  204. package/dist/lib/harness/self-check.d.ts.map +1 -0
  205. package/dist/lib/harness/self-check.js +56 -0
  206. package/dist/lib/harness/self-check.js.map +1 -0
  207. package/dist/lib/harness/self-check.test.d.ts +2 -0
  208. package/dist/lib/harness/self-check.test.d.ts.map +1 -0
  209. package/dist/lib/harness/self-check.test.js +43 -0
  210. package/dist/lib/harness/self-check.test.js.map +1 -0
  211. package/dist/lib/harness/transcript.d.ts +65 -0
  212. package/dist/lib/harness/transcript.d.ts.map +1 -0
  213. package/dist/lib/harness/transcript.js +144 -0
  214. package/dist/lib/harness/transcript.js.map +1 -0
  215. package/dist/lib/harness/transcript.test.d.ts +2 -0
  216. package/dist/lib/harness/transcript.test.d.ts.map +1 -0
  217. package/dist/lib/harness/transcript.test.js +118 -0
  218. package/dist/lib/harness/transcript.test.js.map +1 -0
  219. package/dist/lib/harness-wiring.d.ts +145 -0
  220. package/dist/lib/harness-wiring.d.ts.map +1 -0
  221. package/dist/lib/harness-wiring.js +280 -0
  222. package/dist/lib/harness-wiring.js.map +1 -0
  223. package/dist/lib/report-format.d.ts +132 -0
  224. package/dist/lib/report-format.d.ts.map +1 -0
  225. package/dist/lib/report-format.js +317 -0
  226. package/dist/lib/report-format.js.map +1 -0
  227. package/dist/lib/standards.d.ts +90 -0
  228. package/dist/lib/standards.d.ts.map +1 -0
  229. package/dist/lib/standards.js +194 -0
  230. package/dist/lib/standards.js.map +1 -0
  231. package/dist/lib/templates.d.ts +26 -0
  232. package/dist/lib/templates.d.ts.map +1 -1
  233. package/dist/lib/templates.js +81 -3
  234. package/dist/lib/templates.js.map +1 -1
  235. package/dist/lib/terminal-ui.d.ts.map +1 -1
  236. package/dist/lib/terminal-ui.js +12 -1
  237. package/dist/lib/terminal-ui.js.map +1 -1
  238. package/dist/standards/decision-request.md +90 -0
  239. package/dist/standards/fail-loud-standard.md +495 -0
  240. package/dist/standards/report-format.md +120 -0
  241. package/dist/standards/writing-standard.md +240 -0
  242. package/package.json +3 -2
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The project directory name Claude Code derives from a working directory.
3
+ *
4
+ * Every character outside `[A-Za-z0-9]` becomes a hyphen. Verified against
5
+ * three observed slugs on two platforms:
6
+ *
7
+ * /home/harry/probe-transcript/wt -home-harry-probe-transcript-wt
8
+ * C:\Users\harry\...\probeA-wt C--Users-harry-...-probeA-wt
9
+ * \\wsl.localhost\Ubuntu\home\harry\... --wsl-localhost-Ubuntu-home-harry-...
10
+ *
11
+ * The leading double hyphen on the UNC form is the two backslashes, which is
12
+ * why the POC project directories look the way they do.
13
+ */
14
+ export declare function slugForCwd(cwd: string): string;
15
+ export interface TranscriptLocation {
16
+ /** The configuration directory in force, honouring CLAUDE_CONFIG_DIR. */
17
+ configDir: string;
18
+ /** `<configDir>/projects/<slug>`. Created by the runtime at session start. */
19
+ projectDir: string;
20
+ /** `<projectDir>/<sessionId>.jsonl`, or null while the session id is unknown. */
21
+ path: string | null;
22
+ slug: string;
23
+ }
24
+ export interface LocateOptions {
25
+ cwd: string;
26
+ /** From the SDK `init` message. Absent before the first message arrives. */
27
+ sessionId?: string | null;
28
+ env?: NodeJS.ProcessEnv;
29
+ /** Overridable for tests. */
30
+ home?: string;
31
+ }
32
+ /**
33
+ * Resolves where the runtime will write this session's transcript.
34
+ *
35
+ * `CLAUDE_CONFIG_DIR` wins over the home directory, which was verified by
36
+ * running a session with it set and finding the transcript under it rather than
37
+ * under `~/.claude`.
38
+ */
39
+ export declare function locateTranscript(opts: LocateOptions): TranscriptLocation;
40
+ export type TranscriptStatus = 'present' | 'absent' | 'unreadable';
41
+ export interface TranscriptCheck {
42
+ status: TranscriptStatus;
43
+ /** The file the check looked for. Null when the session id was never seen. */
44
+ path: string | null;
45
+ bytes: number;
46
+ /** Parseable JSON lines. A transcript of zero records is reported as absent. */
47
+ records: number;
48
+ /** Why, in the operator's terms. Always set for `absent` and `unreadable`. */
49
+ detail: string;
50
+ }
51
+ /**
52
+ * Confirms the transcript exists and holds records.
53
+ *
54
+ * Counting records rather than bytes is deliberate. A file that exists and
55
+ * parses to nothing is the failure this check is for, and a byte count would
56
+ * report it as healthy.
57
+ */
58
+ export declare function verifyTranscript(loc: TranscriptLocation): TranscriptCheck;
59
+ /**
60
+ * One line for the operator and for the console, naming the file rather than
61
+ * the directory, so the next person can run the archive reader on it without
62
+ * working out the slug.
63
+ */
64
+ export declare function declareTranscript(check: TranscriptCheck): string;
65
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../../src/lib/harness/transcript.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,UAAU,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,kBAAkB,CAYxE;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEnE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,eAAe,CA6DzE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAIhE"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Where this session's transcript is, and whether it is actually there.
3
+ *
4
+ * The premise this module was built for turned out to be false, and the check
5
+ * is worth keeping anyway. POC-3 and POC-3b ran nine sessions through the SDK
6
+ * and every one of them wrote a transcript to the standard location: all nine
7
+ * `session_id` values the supervisors logged appear as `<id>.jsonl` filenames
8
+ * under `~/.claude/projects/<slug>/`, 11 files and 878 records read by
9
+ * `evidence-tools/transcripts/report.mjs`. The earlier reading of zero files
10
+ * came from `find <dir>` where the directory name begins with `--`, which
11
+ * `find` takes as options. That is lesson L4 in `.mx-agent/lessons.md` a second
12
+ * time: the tool did not run, and the failure looked like a result.
13
+ *
14
+ * So the harness does not need to emit a transcript. It needs to say where the
15
+ * transcript is and prove the file exists, because the alternative is asking
16
+ * this question again in three months with another broken command.
17
+ *
18
+ * Three outcomes, kept separate on purpose: `present`, `absent`, and
19
+ * `unreadable`. A check that cannot run is not a check that passed.
20
+ */
21
+ import { existsSync, readFileSync, statSync } from 'fs';
22
+ import { homedir } from 'os';
23
+ import { join } from 'path';
24
+ /**
25
+ * The project directory name Claude Code derives from a working directory.
26
+ *
27
+ * Every character outside `[A-Za-z0-9]` becomes a hyphen. Verified against
28
+ * three observed slugs on two platforms:
29
+ *
30
+ * /home/harry/probe-transcript/wt -home-harry-probe-transcript-wt
31
+ * C:\Users\harry\...\probeA-wt C--Users-harry-...-probeA-wt
32
+ * \\wsl.localhost\Ubuntu\home\harry\... --wsl-localhost-Ubuntu-home-harry-...
33
+ *
34
+ * The leading double hyphen on the UNC form is the two backslashes, which is
35
+ * why the POC project directories look the way they do.
36
+ */
37
+ export function slugForCwd(cwd) {
38
+ return cwd.replace(/[^A-Za-z0-9]/g, '-');
39
+ }
40
+ /**
41
+ * Resolves where the runtime will write this session's transcript.
42
+ *
43
+ * `CLAUDE_CONFIG_DIR` wins over the home directory, which was verified by
44
+ * running a session with it set and finding the transcript under it rather than
45
+ * under `~/.claude`.
46
+ */
47
+ export function locateTranscript(opts) {
48
+ const env = opts.env ?? process.env;
49
+ const configured = (env.CLAUDE_CONFIG_DIR ?? '').trim();
50
+ const configDir = configured !== '' ? configured : join(opts.home ?? homedir(), '.claude');
51
+ const slug = slugForCwd(opts.cwd);
52
+ const projectDir = join(configDir, 'projects', slug);
53
+ return {
54
+ configDir,
55
+ projectDir,
56
+ slug,
57
+ path: opts.sessionId ? join(projectDir, `${opts.sessionId}.jsonl`) : null,
58
+ };
59
+ }
60
+ /**
61
+ * Confirms the transcript exists and holds records.
62
+ *
63
+ * Counting records rather than bytes is deliberate. A file that exists and
64
+ * parses to nothing is the failure this check is for, and a byte count would
65
+ * report it as healthy.
66
+ */
67
+ export function verifyTranscript(loc) {
68
+ if (!loc.path) {
69
+ return {
70
+ status: 'unreadable',
71
+ path: null,
72
+ bytes: 0,
73
+ records: 0,
74
+ detail: 'the session never reported a session id, so there is no transcript path to check',
75
+ };
76
+ }
77
+ if (!existsSync(loc.path)) {
78
+ return {
79
+ status: 'absent',
80
+ path: loc.path,
81
+ bytes: 0,
82
+ records: 0,
83
+ detail: `no file at ${loc.path}`,
84
+ };
85
+ }
86
+ let bytes = 0;
87
+ let text;
88
+ try {
89
+ bytes = statSync(loc.path).size;
90
+ text = readFileSync(loc.path, 'utf-8');
91
+ }
92
+ catch (err) {
93
+ return {
94
+ status: 'unreadable',
95
+ path: loc.path,
96
+ bytes,
97
+ records: 0,
98
+ detail: `the file exists and could not be read: ${err.message}`,
99
+ };
100
+ }
101
+ let records = 0;
102
+ let unparseable = 0;
103
+ for (const line of text.split('\n')) {
104
+ if (line.trim() === '')
105
+ continue;
106
+ try {
107
+ JSON.parse(line);
108
+ records += 1;
109
+ }
110
+ catch {
111
+ unparseable += 1;
112
+ }
113
+ }
114
+ if (records === 0) {
115
+ return {
116
+ status: 'absent',
117
+ path: loc.path,
118
+ bytes,
119
+ records: 0,
120
+ detail: `${loc.path} exists at ${bytes} bytes and holds no parseable record`,
121
+ };
122
+ }
123
+ const note = unparseable > 0 ? `, ${unparseable} unparseable` : '';
124
+ return {
125
+ status: 'present',
126
+ path: loc.path,
127
+ bytes,
128
+ records,
129
+ detail: `${records} records, ${bytes} bytes${note}`,
130
+ };
131
+ }
132
+ /**
133
+ * One line for the operator and for the console, naming the file rather than
134
+ * the directory, so the next person can run the archive reader on it without
135
+ * working out the slug.
136
+ */
137
+ export function declareTranscript(check) {
138
+ if (check.status === 'present')
139
+ return `transcript ${check.path} (${check.detail})`;
140
+ if (check.status === 'absent')
141
+ return `transcript MISSING: ${check.detail}`;
142
+ return `transcript NOT CHECKED: ${check.detail}`;
143
+ }
144
+ //# sourceMappingURL=transcript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../../src/lib/harness/transcript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC;AAqBD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACpC,MAAM,UAAU,GAAG,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,MAAM,SAAS,GAAG,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC3F,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,MA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 -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transcript.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.test.d.ts","sourceRoot":"","sources":["../../../src/lib/harness/transcript.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,118 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { mkdtempSync, writeFileSync, mkdirSync, rmSync, readFileSync } from 'fs';
3
+ import { tmpdir } from 'os';
4
+ import { join } from 'path';
5
+ import { slugForCwd, locateTranscript, verifyTranscript, declareTranscript } from './transcript.js';
6
+ const SESSION_SOURCE = readFileSync(join(__dirname, '..', 'agent-session.ts'), 'utf-8');
7
+ describe('slugForCwd', () => {
8
+ // The three observed slugs, from sessions run on 2026-08-18 and from the
9
+ // POC-3 project directories that already existed.
10
+ it('matches the slug a POSIX cwd produced', () => {
11
+ expect(slugForCwd('/home/harry/probe-transcript/wt')).toBe('-home-harry-probe-transcript-wt');
12
+ });
13
+ it('matches the slug a Windows cwd produced', () => {
14
+ expect(slugForCwd('C:\\Users\\harry\\probeA-wt')).toBe('C--Users-harry-probeA-wt');
15
+ });
16
+ it('matches the slug a UNC cwd produced, which is the POC-3 shape', () => {
17
+ expect(slugForCwd('\\\\wsl.localhost\\Ubuntu\\home\\harry\\poc3-wt\\s1')).toBe('--wsl-localhost-Ubuntu-home-harry-poc3-wt-s1');
18
+ });
19
+ it('replaces every character outside A-Za-z0-9', () => {
20
+ expect(slugForCwd('a.b_c d:e')).toBe('a-b-c-d-e');
21
+ });
22
+ });
23
+ describe('locateTranscript', () => {
24
+ it('honours CLAUDE_CONFIG_DIR over the home directory', () => {
25
+ const loc = locateTranscript({
26
+ cwd: '/w/t',
27
+ sessionId: 'abc',
28
+ env: { CLAUDE_CONFIG_DIR: '/cfg' },
29
+ home: '/home/nobody',
30
+ });
31
+ expect(loc.configDir).toBe('/cfg');
32
+ expect(loc.path).toBe(join('/cfg', 'projects', '-w-t', 'abc.jsonl'));
33
+ });
34
+ it('falls back to the home directory when the variable is unset or blank', () => {
35
+ const loc = locateTranscript({ cwd: '/w/t', sessionId: 'abc', env: {}, home: '/home/h' });
36
+ expect(loc.configDir).toBe(join('/home/h', '.claude'));
37
+ const blank = locateTranscript({
38
+ cwd: '/w/t',
39
+ sessionId: 'abc',
40
+ env: { CLAUDE_CONFIG_DIR: ' ' },
41
+ home: '/home/h',
42
+ });
43
+ expect(blank.configDir).toBe(join('/home/h', '.claude'));
44
+ });
45
+ it('reports no path while the session id is unknown', () => {
46
+ const loc = locateTranscript({ cwd: '/w/t', env: {}, home: '/home/h' });
47
+ expect(loc.path).toBeNull();
48
+ expect(loc.projectDir).toContain('-w-t');
49
+ });
50
+ });
51
+ describe('verifyTranscript keeps present, absent and unreadable apart', () => {
52
+ const root = mkdtempSync(join(tmpdir(), 'mx-transcript-'));
53
+ const project = join(root, 'projects', '-w-t');
54
+ mkdirSync(project, { recursive: true });
55
+ const loc = (sessionId) => locateTranscript({ cwd: '/w/t', sessionId, env: { CLAUDE_CONFIG_DIR: root } });
56
+ it('reports present and counts records', () => {
57
+ writeFileSync(join(project, 'good.jsonl'), '{"type":"user"}\n{"type":"assistant"}\n');
58
+ const check = verifyTranscript(loc('good'));
59
+ expect(check.status).toBe('present');
60
+ expect(check.records).toBe(2);
61
+ expect(declareTranscript(check)).toContain('good.jsonl');
62
+ });
63
+ it('counts unparseable lines without discarding the record count', () => {
64
+ writeFileSync(join(project, 'mixed.jsonl'), '{"a":1}\nnot json\n{"b":2}\n');
65
+ const check = verifyTranscript(loc('mixed'));
66
+ expect(check.status).toBe('present');
67
+ expect(check.records).toBe(2);
68
+ expect(check.detail).toContain('1 unparseable');
69
+ });
70
+ it('reports absent when the file is not there', () => {
71
+ const check = verifyTranscript(loc('missing'));
72
+ expect(check.status).toBe('absent');
73
+ expect(declareTranscript(check)).toContain('MISSING');
74
+ });
75
+ it('reports absent for a file that exists and parses to nothing', () => {
76
+ // The failure this check exists for. A byte count would call this healthy.
77
+ writeFileSync(join(project, 'empty.jsonl'), '\n\n');
78
+ const check = verifyTranscript(loc('empty'));
79
+ expect(check.status).toBe('absent');
80
+ expect(check.bytes).toBeGreaterThan(0);
81
+ expect(check.records).toBe(0);
82
+ });
83
+ it('reports unreadable rather than absent when there is no session id', () => {
84
+ const check = verifyTranscript(loc(null));
85
+ expect(check.status).toBe('unreadable');
86
+ expect(check.path).toBeNull();
87
+ expect(declareTranscript(check)).toContain('NOT CHECKED');
88
+ });
89
+ it('never reports a could-not-run as a pass', () => {
90
+ for (const check of [verifyTranscript(loc(null)), verifyTranscript(loc('missing'))]) {
91
+ expect(check.status).not.toBe('present');
92
+ }
93
+ rmSync(root, { recursive: true, force: true });
94
+ });
95
+ });
96
+ describe('the session declares its transcript and checks it afterwards', () => {
97
+ it('locates the transcript when the runtime names the session', () => {
98
+ expect(SESSION_SOURCE).toContain('locateTranscript({');
99
+ expect(SESSION_SOURCE).toContain('[harness] transcript ');
100
+ });
101
+ it('declares the path before the file exists rather than searching for it later', () => {
102
+ // The declaration sits inside the branch that captures session_id, which is
103
+ // the first message of the session.
104
+ const initBlock = SESSION_SOURCE.slice(SESSION_SOURCE.indexOf('if (sys.session_id) {'), SESSION_SOURCE.indexOf('if (sys.subtype === \'init\' && sys.model)'));
105
+ expect(initBlock).toContain('locateTranscript');
106
+ });
107
+ it('verifies at session end, and says so when the transcript is not there', () => {
108
+ expect(SESSION_SOURCE).toContain('verifyTranscript(transcriptLocation)');
109
+ expect(SESSION_SOURCE).toContain("check.status === 'present'");
110
+ // A missing transcript is reported in yellow beside the callback-probe
111
+ // warning, not swallowed.
112
+ expect(SESSION_SOURCE).toMatch(/chalk\.yellow\([\s\S]{0,120}declareTranscript/);
113
+ });
114
+ it('reports could-not-locate separately from absent', () => {
115
+ expect(SESSION_SOURCE).toContain('never reported a session id');
116
+ });
117
+ });
118
+ //# sourceMappingURL=transcript.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.test.js","sourceRoot":"","sources":["../../../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c,CAAC,OAAO,CAAC,4CAA4C,CAAC,CACrE,CAAC;QACF,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uEAAuE,EAAE,GAAG,EAAE;QAC/E,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,sCAAsC,CAAC,CAAC;QACzE,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QAC/D,uEAAuE;QACvE,0BAA0B;QAC1B,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,+CAA+C,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Connects the harness to a live session.
3
+ *
4
+ * `agent-session.ts` drives an Agent SDK loop and owns terminal input, the
5
+ * message bus and the resume cycle. This file owns everything between a tool
6
+ * call and a permission result, so that the session file holds no policy and
7
+ * this file holds no SDK.
8
+ *
9
+ * What it composes, all of which existed and none of which ran:
10
+ *
11
+ * credential.ts refuses to start a session that would bill as metered
12
+ * self-check.ts refuses to start when the callback would be shadowed, and
13
+ * proves afterwards that it fired
14
+ * evaluate.ts compiles the rules and decides
15
+ * extract.ts turns a tool call into what it would touch
16
+ * gate.ts joins them and fails closed
17
+ *
18
+ * Three decisions this file makes, each with the measurement behind it.
19
+ *
20
+ * **It replaces `checkWorktreeGuard`.** That function refused 28.6% of the
21
+ * commands it exists to refuse (`docs/guard-coverage.md`). Through this path
22
+ * the same 2,043 commands produce 50.1% (`scripts/gate-coverage.mjs`).
23
+ *
24
+ * **A session-level observe mode exists and is not the default.** Observe
25
+ * records the decision and runs the call. It is at the session edge rather than
26
+ * in the ruleset because flipping `mode` on a `RuleSource` contradicts that
27
+ * rule's own examples and the compiler refuses the ruleset.
28
+ *
29
+ * **`ask` asks.** `gate.ts` maps `ask` to deny because no rule may become an
30
+ * allow through nobody being present. This session has a person at a terminal,
31
+ * so the effect reaches them as a question. With no terminal it stays a deny.
32
+ */
33
+ import type { Attributes, CredentialCheck, Decision, EventSink, Principal, Rule } from './harness/contract.js';
34
+ import { type GateResult } from './harness/gate.js';
35
+ import { type CompiledEvaluator, type PolicyContext, type RuleSource } from './harness/evaluate.js';
36
+ import { ProbeSelfCheck } from './harness/self-check.js';
37
+ /** The surface a permission callback is. Rules that name no other surface can
38
+ * only run here, and rules that do not name this one never reach it. */
39
+ export declare const SESSION_SURFACE: "permission-callback";
40
+ export type HarnessMode = 'enforce' | 'observe';
41
+ /** Files that define policy. The rules refuse to compile when this list does
42
+ * not cover the paths their own examples name, which is how a wrong context is
43
+ * found at startup rather than by a rule silently never firing. */
44
+ export declare function governingRulePaths(repoRoot: string, worktreeRoot: string): string[];
45
+ export declare function policyContext(repoRoot: string, worktreeRoot: string, testGuardedPaths?: string[], scratchRoots?: string[]): PolicyContext;
46
+ /**
47
+ * The rules this surface can enforce.
48
+ *
49
+ * A rule that names only `integration-lane` is not a rule this session is
50
+ * failing to run, it is a rule for a component that is not built. Selecting by
51
+ * surface keeps that distinction, and it also keeps the compiler from refusing
52
+ * the whole ruleset over a rule whose path token a project left empty.
53
+ */
54
+ export declare function rulesForSurface(rules?: RuleSource[]): RuleSource[];
55
+ export interface StartupInput {
56
+ repoRoot: string;
57
+ worktreeRoot: string;
58
+ env?: NodeJS.ProcessEnv;
59
+ /** Set by --allow-metered. Without it a metered credential refuses to start. */
60
+ allowMetered?: boolean;
61
+ /** The `permissionMode` about to be passed to the runtime, if any. */
62
+ permissionMode?: string;
63
+ /** Whether the session is supplying a `canUseTool` callback. */
64
+ canUseToolSupplied: boolean;
65
+ rules?: RuleSource[];
66
+ testGuardedPaths?: string[];
67
+ /** Where this session may write outside its worktree. Defaults to the fleet's
68
+ * `/tmp` and `/var/tmp`. A root containing the worktree is dropped, because
69
+ * it would exempt every write the boundary rule binds. */
70
+ scratchRoots?: string[];
71
+ credentialsFile?: string;
72
+ }
73
+ export interface StartupOutcome {
74
+ ok: boolean;
75
+ /** Lines to print, in order. Present whether or not the session may start. */
76
+ lines: string[];
77
+ credential: CredentialCheck;
78
+ /** Absent when `ok` is false. */
79
+ evaluator?: CompiledEvaluator;
80
+ /** Rules held that this surface cannot enforce, named rather than dropped. */
81
+ notEnforcedHere: Rule[];
82
+ }
83
+ /**
84
+ * Everything that has to be true before the first tool call.
85
+ *
86
+ * All three checks run even when the first one fails, so the operator sees
87
+ * every reason at once instead of fixing them one session at a time.
88
+ */
89
+ export declare function prepareHarness(input: StartupInput): StartupOutcome;
90
+ /** The third argument the SDK passes to `canUseTool`. Named here so this file
91
+ * does not import the SDK, which keeps it testable with no SDK present. */
92
+ export interface CallMetadata {
93
+ /** Unique per tool call within an assistant message. */
94
+ toolUseID?: string;
95
+ /** Present when a delegated agent is acting. */
96
+ agentID?: string;
97
+ }
98
+ export interface SessionGateOptions {
99
+ evaluator: CompiledEvaluator;
100
+ team: string;
101
+ /** The role this session runs as, from the team's roleguide. */
102
+ role: string;
103
+ /** Returns the SDK session id, which is not known until the first system
104
+ * message. Read per call rather than captured, so early calls are not
105
+ * recorded against an empty session. */
106
+ sessionId: () => string;
107
+ worktreeRoot: string;
108
+ cwd?: string;
109
+ mode: HarnessMode;
110
+ sink?: EventSink;
111
+ /** Asks a person. Returns true to allow. Absent means nobody can answer, and
112
+ * the call stays refused. */
113
+ askOperator?: (decision: Decision, attrs: Attributes) => Promise<boolean>;
114
+ now?: () => string;
115
+ }
116
+ export interface SessionGate {
117
+ /** Proves the callback fired, for the dynamic half of the self-check. */
118
+ probe: ProbeSelfCheck;
119
+ decide(toolName: string, input: Record<string, unknown>, meta?: CallMetadata): Promise<GateResult>;
120
+ /** Counts, for the end-of-session line. */
121
+ stats(): {
122
+ calls: number;
123
+ denied: number;
124
+ asked: number;
125
+ observed: number;
126
+ };
127
+ }
128
+ /**
129
+ * A subagent's role is not disclosed by the runtime, so it is recorded as
130
+ * `subagent` rather than as the session's role. A rule bound to a role must not
131
+ * match a principal whose role nobody stated.
132
+ */
133
+ export declare function principalFor(opts: {
134
+ team: string;
135
+ role: string;
136
+ sessionId: string;
137
+ }, meta?: CallMetadata): Principal;
138
+ export declare function createSessionGate(opts: SessionGateOptions): SessionGate;
139
+ /** Prints every decision that is not a plain allow. An allow is the common case
140
+ * and printing it would bury the refusals. */
141
+ export declare function terminalSink(mode: HarnessMode, write?: (s: string) => void): EventSink;
142
+ /** Sends one event to several sinks. A sink that throws does not stop the rest,
143
+ * because a reporting failure must not become a permission decision. */
144
+ export declare function fanOut(...sinks: (EventSink | undefined)[]): EventSink;
145
+ //# sourceMappingURL=harness-wiring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-wiring.d.ts","sourceRoot":"","sources":["../../src/lib/harness-wiring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,KAAK,EACV,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAgB,SAAS,EAAE,IAAI,EAChF,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAEL,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAC5D,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAA0B,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGjF;yEACyE;AACzE,eAAO,MAAM,eAAe,EAAG,qBAA8B,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AAEhD;;oEAEoE;AACpE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EA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