@memnexus-ai/mx-agent-cli 0.1.293 → 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 (215) 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__/harness-extract.test.d.ts +19 -0
  8. package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
  9. package/dist/__tests__/harness-extract.test.js +566 -0
  10. package/dist/__tests__/harness-extract.test.js.map +1 -0
  11. package/dist/__tests__/harness-wiring.test.d.ts +16 -0
  12. package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
  13. package/dist/__tests__/harness-wiring.test.js +469 -0
  14. package/dist/__tests__/harness-wiring.test.js.map +1 -0
  15. package/dist/__tests__/report-format.test.d.ts +2 -0
  16. package/dist/__tests__/report-format.test.d.ts.map +1 -0
  17. package/dist/__tests__/report-format.test.js +219 -0
  18. package/dist/__tests__/report-format.test.js.map +1 -0
  19. package/dist/__tests__/standards-injection.test.d.ts +2 -0
  20. package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
  21. package/dist/__tests__/standards-injection.test.js +157 -0
  22. package/dist/__tests__/standards-injection.test.js.map +1 -0
  23. package/dist/agent-config/hooks/auto-capture-precompact.sh +74 -4
  24. package/dist/agent-config/hooks/auto-capture-session-end.sh +106 -4
  25. package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
  26. package/dist/agent-config/hooks/observability-sync.sh +46 -9
  27. package/dist/commands/config-sync.d.ts +37 -0
  28. package/dist/commands/config-sync.d.ts.map +1 -1
  29. package/dist/commands/config-sync.js +36 -18
  30. package/dist/commands/config-sync.js.map +1 -1
  31. package/dist/commands/dashboard.d.ts.map +1 -1
  32. package/dist/commands/dashboard.js +10 -2
  33. package/dist/commands/dashboard.js.map +1 -1
  34. package/dist/commands/decision.d.ts +20 -0
  35. package/dist/commands/decision.d.ts.map +1 -0
  36. package/dist/commands/decision.js +54 -0
  37. package/dist/commands/decision.js.map +1 -0
  38. package/dist/commands/monitor.d.ts.map +1 -1
  39. package/dist/commands/monitor.js +8 -2
  40. package/dist/commands/monitor.js.map +1 -1
  41. package/dist/commands/report.d.ts +33 -0
  42. package/dist/commands/report.d.ts.map +1 -0
  43. package/dist/commands/report.js +73 -0
  44. package/dist/commands/report.js.map +1 -0
  45. package/dist/commands/start.d.ts +4 -0
  46. package/dist/commands/start.d.ts.map +1 -1
  47. package/dist/commands/start.js +6 -0
  48. package/dist/commands/start.js.map +1 -1
  49. package/dist/commands/update.d.ts +13 -1
  50. package/dist/commands/update.d.ts.map +1 -1
  51. package/dist/commands/update.js +50 -1
  52. package/dist/commands/update.js.map +1 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +67 -3
  55. package/dist/index.js.map +1 -1
  56. package/dist/lib/agent-session.d.ts +12 -0
  57. package/dist/lib/agent-session.d.ts.map +1 -1
  58. package/dist/lib/agent-session.js +183 -41
  59. package/dist/lib/agent-session.js.map +1 -1
  60. package/dist/lib/claude.d.ts +12 -0
  61. package/dist/lib/claude.d.ts.map +1 -1
  62. package/dist/lib/claude.js +29 -2
  63. package/dist/lib/claude.js.map +1 -1
  64. package/dist/lib/decision-check.d.ts +48 -0
  65. package/dist/lib/decision-check.d.ts.map +1 -0
  66. package/dist/lib/decision-check.js +149 -0
  67. package/dist/lib/decision-check.js.map +1 -0
  68. package/dist/lib/harness/console/announce.d.ts +45 -0
  69. package/dist/lib/harness/console/announce.d.ts.map +1 -0
  70. package/dist/lib/harness/console/announce.js +48 -0
  71. package/dist/lib/harness/console/announce.js.map +1 -0
  72. package/dist/lib/harness/console/announce.test.d.ts +2 -0
  73. package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
  74. package/dist/lib/harness/console/announce.test.js +104 -0
  75. package/dist/lib/harness/console/announce.test.js.map +1 -0
  76. package/dist/lib/harness/console/by-session.d.ts +50 -0
  77. package/dist/lib/harness/console/by-session.d.ts.map +1 -0
  78. package/dist/lib/harness/console/by-session.js +83 -0
  79. package/dist/lib/harness/console/by-session.js.map +1 -0
  80. package/dist/lib/harness/console/by-session.test.d.ts +2 -0
  81. package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
  82. package/dist/lib/harness/console/by-session.test.js +86 -0
  83. package/dist/lib/harness/console/by-session.test.js.map +1 -0
  84. package/dist/lib/harness/console/console.d.ts +67 -0
  85. package/dist/lib/harness/console/console.d.ts.map +1 -0
  86. package/dist/lib/harness/console/console.js +373 -0
  87. package/dist/lib/harness/console/console.js.map +1 -0
  88. package/dist/lib/harness/console/console.test.d.ts +2 -0
  89. package/dist/lib/harness/console/console.test.d.ts.map +1 -0
  90. package/dist/lib/harness/console/console.test.js +269 -0
  91. package/dist/lib/harness/console/console.test.js.map +1 -0
  92. package/dist/lib/harness/console/decision-request.d.ts +32 -0
  93. package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
  94. package/dist/lib/harness/console/decision-request.js +112 -0
  95. package/dist/lib/harness/console/decision-request.js.map +1 -0
  96. package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
  97. package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
  98. package/dist/lib/harness/console/decision-request.test.js +75 -0
  99. package/dist/lib/harness/console/decision-request.test.js.map +1 -0
  100. package/dist/lib/harness/console/fixtures.d.ts +16 -0
  101. package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
  102. package/dist/lib/harness/console/fixtures.js +49 -0
  103. package/dist/lib/harness/console/fixtures.js.map +1 -0
  104. package/dist/lib/harness/console/index.d.ts +15 -0
  105. package/dist/lib/harness/console/index.d.ts.map +1 -0
  106. package/dist/lib/harness/console/index.js +14 -0
  107. package/dist/lib/harness/console/index.js.map +1 -0
  108. package/dist/lib/harness/console/rank.d.ts +73 -0
  109. package/dist/lib/harness/console/rank.d.ts.map +1 -0
  110. package/dist/lib/harness/console/rank.js +113 -0
  111. package/dist/lib/harness/console/rank.js.map +1 -0
  112. package/dist/lib/harness/console/rank.test.d.ts +2 -0
  113. package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
  114. package/dist/lib/harness/console/rank.test.js +124 -0
  115. package/dist/lib/harness/console/rank.test.js.map +1 -0
  116. package/dist/lib/harness/console/render.d.ts +22 -0
  117. package/dist/lib/harness/console/render.d.ts.map +1 -0
  118. package/dist/lib/harness/console/render.js +65 -0
  119. package/dist/lib/harness/console/render.js.map +1 -0
  120. package/dist/lib/harness/console/render.test.d.ts +2 -0
  121. package/dist/lib/harness/console/render.test.d.ts.map +1 -0
  122. package/dist/lib/harness/console/render.test.js +96 -0
  123. package/dist/lib/harness/console/render.test.js.map +1 -0
  124. package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
  125. package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
  126. package/dist/lib/harness/console/replay-cli.test.js +96 -0
  127. package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
  128. package/dist/lib/harness/console/replay.d.ts +36 -0
  129. package/dist/lib/harness/console/replay.d.ts.map +1 -0
  130. package/dist/lib/harness/console/replay.js +59 -0
  131. package/dist/lib/harness/console/replay.js.map +1 -0
  132. package/dist/lib/harness/console/replay.test.d.ts +2 -0
  133. package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
  134. package/dist/lib/harness/console/replay.test.js +81 -0
  135. package/dist/lib/harness/console/replay.test.js.map +1 -0
  136. package/dist/lib/harness/console/turn-reader.d.ts +50 -0
  137. package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
  138. package/dist/lib/harness/console/turn-reader.js +184 -0
  139. package/dist/lib/harness/console/turn-reader.js.map +1 -0
  140. package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
  141. package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
  142. package/dist/lib/harness/console/turn-reader.test.js +108 -0
  143. package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
  144. package/dist/lib/harness/console/types.d.ts +109 -0
  145. package/dist/lib/harness/console/types.d.ts.map +1 -0
  146. package/dist/lib/harness/console/types.js +2 -0
  147. package/dist/lib/harness/console/types.js.map +1 -0
  148. package/dist/lib/harness/contract.d.ts +229 -0
  149. package/dist/lib/harness/contract.d.ts.map +1 -0
  150. package/dist/lib/harness/contract.js +22 -0
  151. package/dist/lib/harness/contract.js.map +1 -0
  152. package/dist/lib/harness/credential.d.ts +23 -0
  153. package/dist/lib/harness/credential.d.ts.map +1 -0
  154. package/dist/lib/harness/credential.js +81 -0
  155. package/dist/lib/harness/credential.js.map +1 -0
  156. package/dist/lib/harness/credential.test.d.ts +2 -0
  157. package/dist/lib/harness/credential.test.d.ts.map +1 -0
  158. package/dist/lib/harness/credential.test.js +74 -0
  159. package/dist/lib/harness/credential.test.js.map +1 -0
  160. package/dist/lib/harness/evaluate.d.ts +390 -0
  161. package/dist/lib/harness/evaluate.d.ts.map +1 -0
  162. package/dist/lib/harness/evaluate.js +988 -0
  163. package/dist/lib/harness/evaluate.js.map +1 -0
  164. package/dist/lib/harness/evaluate.test.d.ts +2 -0
  165. package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
  166. package/dist/lib/harness/evaluate.test.js +621 -0
  167. package/dist/lib/harness/evaluate.test.js.map +1 -0
  168. package/dist/lib/harness/extract.d.ts +152 -0
  169. package/dist/lib/harness/extract.d.ts.map +1 -0
  170. package/dist/lib/harness/extract.js +1601 -0
  171. package/dist/lib/harness/extract.js.map +1 -0
  172. package/dist/lib/harness/gate.d.ts +48 -0
  173. package/dist/lib/harness/gate.d.ts.map +1 -0
  174. package/dist/lib/harness/gate.js +60 -0
  175. package/dist/lib/harness/gate.js.map +1 -0
  176. package/dist/lib/harness/gate.test.d.ts +2 -0
  177. package/dist/lib/harness/gate.test.d.ts.map +1 -0
  178. package/dist/lib/harness/gate.test.js +111 -0
  179. package/dist/lib/harness/gate.test.js.map +1 -0
  180. package/dist/lib/harness/self-check.d.ts +59 -0
  181. package/dist/lib/harness/self-check.d.ts.map +1 -0
  182. package/dist/lib/harness/self-check.js +56 -0
  183. package/dist/lib/harness/self-check.js.map +1 -0
  184. package/dist/lib/harness/self-check.test.d.ts +2 -0
  185. package/dist/lib/harness/self-check.test.d.ts.map +1 -0
  186. package/dist/lib/harness/self-check.test.js +43 -0
  187. package/dist/lib/harness/self-check.test.js.map +1 -0
  188. package/dist/lib/harness/transcript.d.ts +65 -0
  189. package/dist/lib/harness/transcript.d.ts.map +1 -0
  190. package/dist/lib/harness/transcript.js +144 -0
  191. package/dist/lib/harness/transcript.js.map +1 -0
  192. package/dist/lib/harness/transcript.test.d.ts +2 -0
  193. package/dist/lib/harness/transcript.test.d.ts.map +1 -0
  194. package/dist/lib/harness/transcript.test.js +118 -0
  195. package/dist/lib/harness/transcript.test.js.map +1 -0
  196. package/dist/lib/harness-wiring.d.ts +145 -0
  197. package/dist/lib/harness-wiring.d.ts.map +1 -0
  198. package/dist/lib/harness-wiring.js +280 -0
  199. package/dist/lib/harness-wiring.js.map +1 -0
  200. package/dist/lib/report-format.d.ts +132 -0
  201. package/dist/lib/report-format.d.ts.map +1 -0
  202. package/dist/lib/report-format.js +317 -0
  203. package/dist/lib/report-format.js.map +1 -0
  204. package/dist/lib/standards.d.ts +90 -0
  205. package/dist/lib/standards.d.ts.map +1 -0
  206. package/dist/lib/standards.js +194 -0
  207. package/dist/lib/standards.js.map +1 -0
  208. package/dist/lib/terminal-ui.d.ts.map +1 -1
  209. package/dist/lib/terminal-ui.js +12 -1
  210. package/dist/lib/terminal-ui.js.map +1 -1
  211. package/dist/standards/decision-request.md +90 -0
  212. package/dist/standards/fail-loud-standard.md +495 -0
  213. package/dist/standards/report-format.md +120 -0
  214. package/dist/standards/writing-standard.md +240 -0
  215. package/package.json +3 -2
@@ -0,0 +1,219 @@
1
+ /**
2
+ * The seven-section report contract.
3
+ *
4
+ * The behaviour under test is a refusal, so most of these assert that something
5
+ * is rejected. The two that matter most are "the bare skeleton is refused" and
6
+ * "every problem is reported at once": the first stops the skeleton becoming a
7
+ * way past the check, and the second stops one fix becoming seven round trips.
8
+ */
9
+ import { describe, it, expect } from 'vitest';
10
+ import { mkdtempSync, readFileSync, writeFileSync } from 'fs';
11
+ import { tmpdir } from 'os';
12
+ import { dirname, join } from 'path';
13
+ import { fileURLToPath } from 'url';
14
+ import { REPORT_SECTIONS, ReportFormatError, checkReport, namesGoalRung, normaliseHeading, refusalMessage, renderReportSkeleton, statesEvidence, stripNonContent, } from '../lib/report-format.js';
15
+ import { runReportCheck } from '../commands/report.js';
16
+ const __dirname = dirname(fileURLToPath(import.meta.url));
17
+ const STANDARDS_DIR = join(__dirname, '..', '..', '..', 'standards');
18
+ /** Write a report to a temp file. Avoids reading fd 0 inside a test worker. */
19
+ function reportFile(content) {
20
+ const path = join(mkdtempSync(join(tmpdir(), 'mx-report-')), 'report.md');
21
+ writeFileSync(path, content);
22
+ return path;
23
+ }
24
+ /** A report that meets the contract. Sections deliberately terse. */
25
+ const GOOD = `# Report
26
+
27
+ ## 1. What I was asked
28
+ Ship the report format. Serves Level 3, stream D.
29
+
30
+ ## 2. What I did
31
+ Read the plan, wrote the standard, wired the injection.
32
+
33
+ ## 3. What I found
34
+ The guards refuse 28.6% of what they should, 502 of 1,756.
35
+ \`node evidence-tools/guard-replay/summary.mjs "$STAGE"\`
36
+
37
+ ## 4. What I am not sure about
38
+ Whether the phrase list is complete. I could not run the corpus scorer.
39
+
40
+ ## 5. What would change my mind
41
+ A run of the check against ten real reports that refuses more than one.
42
+
43
+ ## 6. What I need from you
44
+ Nothing.
45
+
46
+ ## 7. What I would do next
47
+ Wire the check into the pre-push hook.
48
+ `;
49
+ describe('the section list is the only source', () => {
50
+ it('holds seven sections numbered 1 to 7 in order', () => {
51
+ expect(REPORT_SECTIONS).toHaveLength(7);
52
+ expect(REPORT_SECTIONS.map((s) => s.index)).toEqual([1, 2, 3, 4, 5, 6, 7]);
53
+ });
54
+ it('names the same seven headings as the shipped standard, so the two cannot drift', () => {
55
+ const doc = readFileSync(join(STANDARDS_DIR, 'report-format.md'), 'utf-8');
56
+ for (const section of REPORT_SECTIONS) {
57
+ expect(doc, `report-format.md does not name section ${section.index}`).toContain(section.heading);
58
+ }
59
+ });
60
+ });
61
+ describe('the skeleton', () => {
62
+ it('writes every heading in order', () => {
63
+ const skeleton = renderReportSkeleton();
64
+ const positions = REPORT_SECTIONS.map((s) => skeleton.indexOf(s.heading));
65
+ expect(positions.every((p) => p >= 0)).toBe(true);
66
+ expect([...positions].sort((a, b) => a - b)).toEqual(positions);
67
+ });
68
+ it('is REFUSED when nothing has been answered', () => {
69
+ // The prompts are HTML comments, so an unfilled skeleton has no body text.
70
+ // Without this the skeleton would be a way to pass the check while saying
71
+ // nothing, which is the failure the format exists to stop.
72
+ const result = checkReport(renderReportSkeleton());
73
+ expect(result.ok).toBe(false);
74
+ expect(result.problems.filter((p) => p.code === 'section-empty')).toHaveLength(7);
75
+ });
76
+ it('is still refused when only the rung and the task are filled in', () => {
77
+ const result = checkReport(renderReportSkeleton({ task: 'Ship the report format.', rung: 3, title: 'Stream D' }));
78
+ expect(result.ok).toBe(false);
79
+ expect(result.problems.some((p) => p.section === 1)).toBe(false);
80
+ expect(result.problems.filter((p) => p.code === 'section-empty')).toHaveLength(6);
81
+ });
82
+ });
83
+ describe('a report that meets the contract', () => {
84
+ it('passes', () => {
85
+ const result = checkReport(GOOD);
86
+ expect(result.problems).toEqual([]);
87
+ expect(result.ok).toBe(true);
88
+ });
89
+ it('accepts Nothing as an answer to section 6', () => {
90
+ expect(checkReport(GOOD).bodies.get(6)).toBe('Nothing.');
91
+ });
92
+ });
93
+ describe('what gets refused', () => {
94
+ it('names a missing section', () => {
95
+ const result = checkReport(GOOD.replace(/## 5\. What would change my mind\n[\s\S]*?\n\n/, ''));
96
+ expect(result.ok).toBe(false);
97
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'section-missing', section: 5 }));
98
+ });
99
+ it('reports every problem at once rather than stopping at the first', () => {
100
+ const result = checkReport('## 1. What I was asked\nServes Level 2.\n');
101
+ expect(result.problems.filter((p) => p.code === 'section-missing')).toHaveLength(6);
102
+ });
103
+ it('treats a heading with no content as the same failure as a missing one', () => {
104
+ const result = checkReport(GOOD.replace('Nothing.', ''));
105
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'section-empty', section: 6 }));
106
+ });
107
+ it('names a repeated heading and keeps the first body', () => {
108
+ const result = checkReport(`${GOOD}\n## 3. What I found\nsomething else\n`);
109
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'section-repeated', section: 3 }));
110
+ expect(result.bodies.get(3)).toContain('28.6%');
111
+ });
112
+ it('names sections written out of order', () => {
113
+ const reordered = [
114
+ '## 2. What I did\nx\n',
115
+ '## 1. What I was asked\nServes Level 1.\n',
116
+ '## 3. What I found\n`ls`\n',
117
+ '## 4. What I am not sure about\nx\n',
118
+ '## 5. What would change my mind\nx\n',
119
+ '## 6. What I need from you\nNothing.\n',
120
+ '## 7. What I would do next\nx\n',
121
+ ].join('\n');
122
+ const result = checkReport(reordered);
123
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'sections-out-of-order' }));
124
+ });
125
+ it('refuses section 1 when it names no rung of the goal ladder', () => {
126
+ const result = checkReport(GOOD.replace('Serves Level 3, stream D.', 'Stream D.'));
127
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'goal-rung-missing', section: 1 }));
128
+ });
129
+ it('refuses section 3 when it states no source a reader could re-run', () => {
130
+ const result = checkReport(GOOD.replace(/## 3\. What I found\n[\s\S]*?\n\n/, '## 3. What I found\nThe guards are bad.\n\n'));
131
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'evidence-missing', section: 3 }));
132
+ });
133
+ });
134
+ describe('heading matching is tolerant about form and strict about presence', () => {
135
+ const forms = [
136
+ '## 1. What I was asked',
137
+ '# What I was asked',
138
+ '###### 1) what i was asked:',
139
+ '## **What I was asked**',
140
+ '## 1 - What I Was Asked.',
141
+ ];
142
+ for (const form of forms) {
143
+ it(`accepts ${JSON.stringify(form)}`, () => {
144
+ expect(normaliseHeading(form)).toBe('what i was asked');
145
+ });
146
+ }
147
+ it("accepts What I'm not sure about for section 4", () => {
148
+ const result = checkReport(GOOD.replace('What I am not sure about', "What I'm not sure about"));
149
+ expect(result.ok).toBe(true);
150
+ });
151
+ it('does not treat a hash inside a fenced block as a heading', () => {
152
+ const withFence = GOOD.replace('## 2. What I did\nRead the plan, wrote the standard, wired the injection.', '## 2. What I did\n```sh\n# 3. What I found\nls\n```\nRan the above.');
153
+ const result = checkReport(withFence);
154
+ expect(result.ok).toBe(true);
155
+ expect(result.bodies.get(2)).toContain('Ran the above.');
156
+ });
157
+ it('does not count text under an unrelated heading as answering a section', () => {
158
+ const result = checkReport(GOOD.replace('## 6. What I need from you\nNothing.', '## 6. What I need from you\n\n## Appendix\nlots of text here'));
159
+ expect(result.problems).toContainEqual(expect.objectContaining({ code: 'section-empty', section: 6 }));
160
+ });
161
+ });
162
+ describe('the evidence and rung predicates', () => {
163
+ it('accepts a fenced block, inline code, or a file:line reference', () => {
164
+ expect(statesEvidence('```\nls\n```')).toBe(true);
165
+ expect(statesEvidence('ran `git log --oneline`')).toBe(true);
166
+ expect(statesEvidence('see product/mx-agent-prd.md:268')).toBe(true);
167
+ });
168
+ it('rejects a bare assertion', () => {
169
+ expect(statesEvidence('The guards refuse most of what they should.')).toBe(false);
170
+ });
171
+ it('reads a rung in any of the three levels, however it is spaced', () => {
172
+ expect(namesGoalRung('Serves Level 2.')).toBe(true);
173
+ expect(namesGoalRung('serves level3')).toBe(true);
174
+ expect(namesGoalRung('LEVEL 1')).toBe(true);
175
+ });
176
+ it('rejects a section 1 that gestures at a goal without naming a rung', () => {
177
+ expect(namesGoalRung('This serves the milestone.')).toBe(false);
178
+ expect(namesGoalRung('Serves the harness work.')).toBe(false);
179
+ expect(namesGoalRung('Level 4 does not exist.')).toBe(false);
180
+ });
181
+ });
182
+ describe('stripNonContent', () => {
183
+ it('removes HTML comments, so the skeleton prompts never count as answers', () => {
184
+ expect(stripNonContent('<!-- prompt -->')).toBe('');
185
+ expect(stripNonContent('<!-- prompt -->\nreal answer')).toBe('real answer');
186
+ });
187
+ it('removes a bare list bullet left behind by a writer', () => {
188
+ expect(stripNonContent('-\n')).toBe('');
189
+ });
190
+ });
191
+ describe('the refusal', () => {
192
+ it('throws rather than exiting, so a caller keeps its recovery path', () => {
193
+ expect(() => runReportCheck({ file: reportFile('nothing here') })).toThrow(ReportFormatError);
194
+ });
195
+ it('accepts a report that meets the contract', () => {
196
+ expect(() => runReportCheck({ file: reportFile(GOOD) })).not.toThrow();
197
+ });
198
+ it('states the problems on the error, for a caller that wants them', () => {
199
+ try {
200
+ runReportCheck({ file: reportFile('nothing here') });
201
+ expect.unreachable('should have refused');
202
+ }
203
+ catch (err) {
204
+ expect(err).toBeInstanceOf(ReportFormatError);
205
+ expect(err.code).toBe('report-format-refused');
206
+ expect(err.problems.length).toBeGreaterThan(0);
207
+ }
208
+ });
209
+ it('names every section, the problem, and the command that fixes it', () => {
210
+ const message = refusalMessage(checkReport(''), 'report.md');
211
+ expect(message).toContain('Report REFUSED');
212
+ expect(message).toContain('7 of 7 sections are absent');
213
+ for (const section of REPORT_SECTIONS)
214
+ expect(message).toContain(section.heading);
215
+ expect(message).toContain('mx-agent report new');
216
+ expect(message).toContain('mx-agent-system/standards/report-format.md');
217
+ });
218
+ });
219
+ //# sourceMappingURL=report-format.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-format.test.js","sourceRoot":"","sources":["../../src/__tests__/report-format.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,E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AAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=standards-injection.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standards-injection.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/standards-injection.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The framework standards reach every conversation turn.
3
+ *
4
+ * The property under test is not that the files exist. It is that their marked
5
+ * blocks end up inside `CLAUDE.local.md`, which the runtime re-reads on every
6
+ * turn. `product/mx-agent-prd.md:268` records why that distinction decides the
7
+ * outcome: when we built a mechanism, teams followed the practice, and when we
8
+ * only wrote a rule, they stopped.
9
+ */
10
+ import { describe, it, expect } from 'vitest';
11
+ import { mkdtempSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
12
+ import { tmpdir } from 'os';
13
+ import { dirname, join } from 'path';
14
+ import { fileURLToPath } from 'url';
15
+ import { INJECTED_STANDARDS, MAX_STANDARDS_BLOCK_BYTES, getStandardsDir, readStandardBlock, resolveStandards, } from '../lib/standards.js';
16
+ import { buildClaudeLocalContent } from '../lib/claude.js';
17
+ const __dirname = dirname(fileURLToPath(import.meta.url));
18
+ const REPO_STANDARDS = join(__dirname, '..', '..', '..', 'standards');
19
+ function tempDir(prefix) {
20
+ return mkdtempSync(join(tmpdir(), prefix));
21
+ }
22
+ function worktreeOpts(standardsDir) {
23
+ const root = tempDir('mx-std-root-');
24
+ const worktree = join(root, 'wt');
25
+ mkdirSync(worktree, { recursive: true });
26
+ return {
27
+ projectRoot: root,
28
+ worktreePath: worktree,
29
+ worktreeName: 'demo',
30
+ branch: 'worktree/demo',
31
+ slot: 0,
32
+ ...(standardsDir ? { standardsDir } : {}),
33
+ };
34
+ }
35
+ describe('the shipped standards', () => {
36
+ it('resolve from the repository tree in dev', () => {
37
+ expect(getStandardsDir()).not.toBeNull();
38
+ });
39
+ it('every shipped standard produces a marked block', () => {
40
+ const resolution = resolveStandards(REPO_STANDARDS);
41
+ expect(resolution.warnings).toEqual([]);
42
+ expect(resolution.complete).toBe(true);
43
+ // Asserted against the list rather than a literal count, so adding a
44
+ // standard does not fail a test that has no opinion about how many there are.
45
+ expect(resolution.blocks).toHaveLength(INJECTED_STANDARDS.length);
46
+ expect(resolution.blocks.every((b) => b.ok)).toBe(true);
47
+ });
48
+ it('state the rules an agent has to follow', () => {
49
+ const { rendered } = resolveStandards(REPO_STANDARDS);
50
+ expect(rendered).toContain('No em dashes');
51
+ expect(rendered).toContain('A noun must be able to do the verb');
52
+ expect(rendered).toContain('Active voice');
53
+ expect(rendered).toContain('What would change my mind');
54
+ expect(rendered).toContain('What I need from you');
55
+ });
56
+ it('obey their own first rule inside the injected block', () => {
57
+ // Outside the markers the writing standard quotes an em dash, because the
58
+ // command that counts them has to contain one. Inside the markers, which is
59
+ // what every agent reads every turn, there are none.
60
+ for (const block of resolveStandards(REPO_STANDARDS).blocks) {
61
+ expect(block.content, `${block.file} has an em dash inside its marked block`).not.toContain('—');
62
+ }
63
+ });
64
+ it('stay small enough to re-send on every turn', () => {
65
+ const bytes = Buffer.byteLength(resolveStandards(REPO_STANDARDS).rendered, 'utf-8');
66
+ expect(bytes).toBeLessThan(MAX_STANDARDS_BLOCK_BYTES);
67
+ });
68
+ });
69
+ describe('the block reaches every turn', () => {
70
+ it('is written into CLAUDE.local.md', () => {
71
+ const built = buildClaudeLocalContent(worktreeOpts(REPO_STANDARDS));
72
+ expect(built.hasStandardsBlock).toBe(true);
73
+ expect(built.content).toContain('Framework standards (every-turn reinforcement)');
74
+ expect(built.content).toContain('No em dashes');
75
+ expect(built.content).toContain('What would change my mind');
76
+ });
77
+ it('says where the block came from', () => {
78
+ const built = buildClaudeLocalContent(worktreeOpts(REPO_STANDARDS));
79
+ const dim = built.diagnostics.filter((d) => d.level === 'dim').map((d) => d.message);
80
+ expect(dim.join(' ')).toContain('Framework standards injected from');
81
+ });
82
+ it('keeps the worktree isolation rules alongside it', () => {
83
+ const built = buildClaudeLocalContent(worktreeOpts(REPO_STANDARDS));
84
+ expect(built.content).toContain('Worktree Isolation Context');
85
+ });
86
+ });
87
+ describe('what happens when a standard cannot be read', () => {
88
+ it('warns and continues rather than refusing the session', () => {
89
+ const built = buildClaudeLocalContent(worktreeOpts(tempDir('mx-std-empty-')));
90
+ expect(built.hasStandardsBlock).toBe(false);
91
+ expect(built.content).toContain('Worktree Isolation Context');
92
+ const warnings = built.diagnostics.filter((d) => d.code === 'standards-injection-missing');
93
+ expect(warnings.length).toBeGreaterThan(0);
94
+ });
95
+ it('names the file, the problem and the fix', () => {
96
+ const dir = tempDir('mx-std-partial-');
97
+ writeFileSync(join(dir, 'writing-standard.md'), '# no markers here\n');
98
+ // Every other shipped standard written correctly, driven from the list, so
99
+ // the warning count stays about the one broken file rather than about how
100
+ // many standards happen to exist.
101
+ for (const { file } of INJECTED_STANDARDS) {
102
+ if (file === 'writing-standard.md')
103
+ continue;
104
+ writeFileSync(join(dir, file), '<!-- behavioral-start -->\ncontent\n<!-- behavioral-end -->\n');
105
+ }
106
+ const resolution = resolveStandards(dir);
107
+ expect(resolution.complete).toBe(false);
108
+ expect(resolution.warnings).toHaveLength(1);
109
+ expect(resolution.warnings[0]).toContain('writing-standard.md');
110
+ expect(resolution.warnings[0]).toContain('markers-missing');
111
+ expect(resolution.warnings[0]).toContain('Fix:');
112
+ });
113
+ it('still injects the standard it could read', () => {
114
+ const dir = tempDir('mx-std-partial2-');
115
+ writeFileSync(join(dir, 'writing-standard.md'), '# no markers\n');
116
+ writeFileSync(join(dir, 'report-format.md'), '<!-- behavioral-start -->\nSEVEN SECTIONS\n<!-- behavioral-end -->\n');
117
+ expect(resolveStandards(dir).rendered).toContain('SEVEN SECTIONS');
118
+ });
119
+ it('drops the whole block rather than evicting working context', () => {
120
+ const dir = tempDir('mx-std-big-');
121
+ const filler = 'x'.repeat(MAX_STANDARDS_BLOCK_BYTES);
122
+ for (const s of INJECTED_STANDARDS) {
123
+ writeFileSync(join(dir, s.file), `<!-- behavioral-start -->\n${filler}\n<!-- behavioral-end -->\n`);
124
+ }
125
+ const resolution = resolveStandards(dir);
126
+ expect(resolution.rendered).toBe('');
127
+ expect(resolution.warnings.join(' ')).toContain('re-sent on EVERY conversation turn');
128
+ });
129
+ it('reports an empty marker block rather than injecting nothing quietly', () => {
130
+ const dir = tempDir('mx-std-emptyblock-');
131
+ writeFileSync(join(dir, 'writing-standard.md'), '<!-- behavioral-start -->\n\n<!-- behavioral-end -->\n');
132
+ const block = readStandardBlock(dir, 'writing-standard.md', 'Writing standard');
133
+ expect(block.ok).toBe(false);
134
+ expect(block.problem).toBe('content-empty');
135
+ });
136
+ it('reports a missing file by name', () => {
137
+ const block = readStandardBlock(tempDir('mx-std-none-'), 'writing-standard.md', 'Writing standard');
138
+ expect(block.ok).toBe(false);
139
+ expect(block.problem).toBe('file-missing');
140
+ });
141
+ it('finds no directory rather than throwing when one does not exist', () => {
142
+ const resolution = resolveStandards(join(tempDir('mx-std-gone-'), 'absent'));
143
+ expect(resolution.complete).toBe(false);
144
+ expect(resolution.rendered).toBe('');
145
+ expect(resolution.warnings.length).toBeGreaterThan(0);
146
+ });
147
+ });
148
+ describe('the shipped files themselves', () => {
149
+ for (const standard of INJECTED_STANDARDS) {
150
+ it(`${standard.file} exists and has exactly one marker pair`, () => {
151
+ const raw = readFileSync(join(REPO_STANDARDS, standard.file), 'utf-8');
152
+ expect(raw.match(/<!-- behavioral-start -->/g)).toHaveLength(1);
153
+ expect(raw.match(/<!-- behavioral-end -->/g)).toHaveLength(1);
154
+ });
155
+ }
156
+ });
157
+ //# sourceMappingURL=standards-injection.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standards-injection.test.js","sourceRoot":"","sources":["../../src/__tests__/standards-injection.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;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IT ERR
38
38
  # Total line count (proxy for session depth)
39
39
  _TOTAL_LINES=$(wc -l < "$TRANSCRIPT_PATH" 2>/dev/null || echo "0")
40
40
 
41
- # Files modified (Write/Edit tool calls)
42
- FILES_MODIFIED=$(jq -r '
41
+ # Subagent transcripts (#5436)
42
+ #
43
+ # A subagent's tool calls are written to its own file, never to the lead's
44
+ # transcript:
45
+ #
46
+ # <project-dir>/<session-id>.jsonl the lead
47
+ # <project-dir>/<session-id>/subagents/agent-*.jsonl one per subagent
48
+ #
49
+ # Subagents made 11,627 of 12,343 repository writes (94%) across 5,713 measured
50
+ # transcripts, so a filter over the lead alone reported "Files modified: None"
51
+ # for most sessions. This hook has no since-last-save window, so every subagent
52
+ # file is in scope. The directory is absent when no subagent ran, which is
53
+ # normal and not an error.
54
+ #
55
+ # SCOPE. Only FILES_MODIFIED and GIT_COMMITS read these files. GIT_PUSHES,
56
+ # PR_CREATES and PR_MERGES below stay lead-only and therefore still undercount.
57
+ # That is deliberate: #5436 scopes this change to file paths and commit counts,
58
+ # and BASH_COMMANDS is the variable those three share, so widening it would
59
+ # change more than the issue asks for. Same one-line pattern when it is wanted.
60
+ #
61
+ # STATED CAP, not a silent one. The largest subagent count in the fleet's 301
62
+ # real sessions is 189, so 200 is above the observed range.
63
+ SUBAGENT_DIR="${TRANSCRIPT_PATH%.jsonl}/subagents"
64
+ SUBAGENT_FILES=()
65
+ if [[ -d "$SUBAGENT_DIR" ]]; then
66
+ while IFS= read -r _mx_f; do
67
+ [[ -n "$_mx_f" ]] && SUBAGENT_FILES+=("$_mx_f")
68
+ done < <(find "$SUBAGENT_DIR" -maxdepth 1 -type f -name 'agent-*.jsonl' 2>/dev/null \
69
+ | head -n "${AUTO_CAPTURE_MAX_SUBAGENTS:-200}")
70
+ fi
71
+
72
+ # `-R` with `fromjson?` skips a malformed line instead of aborting the whole
73
+ # extraction, which matters when reading many files at once. The lead's paths
74
+ # below keep plain `jq -r` and are unchanged.
75
+ SUBAGENT_WRITES=""
76
+ SUBAGENT_BASH=""
77
+ if (( ${#SUBAGENT_FILES[@]} > 0 )); then
78
+ SUBAGENT_WRITES=$(jq -R -r 'fromjson? // empty |
79
+ select(.type == "assistant") |
80
+ .message.content[]? |
81
+ select(.type == "tool_use" and (.name == "Write" or .name == "Edit")) |
82
+ .input.file_path // empty
83
+ ' "${SUBAGENT_FILES[@]}" 2>/dev/null || true)
84
+ SUBAGENT_BASH=$(jq -R -r 'fromjson? // empty |
85
+ select(.type == "assistant") |
86
+ .message.content[]? |
87
+ select(.type == "tool_use" and .name == "Bash") |
88
+ .input.command // empty
89
+ ' "${SUBAGENT_FILES[@]}" 2>/dev/null || true)
90
+ fi
91
+
92
+ # Files modified (Write/Edit tool calls), by the lead and by its subagents
93
+ LEAD_WRITES=$(jq -r '
43
94
  select(.type == "assistant") |
44
95
  .message.content[]? |
45
96
  select(.type == "tool_use" and (.name == "Write" or .name == "Edit")) |
46
97
  .input.file_path // empty
47
- ' "$TRANSCRIPT_PATH" 2>/dev/null | grep -v '^$' | sort -u | head -30)
98
+ ' "$TRANSCRIPT_PATH" 2>/dev/null | grep -v '^$' || true)
99
+
100
+ _MX_ALL_WRITES=$(printf '%s\n%s\n' "$LEAD_WRITES" "$SUBAGENT_WRITES" \
101
+ | grep -v '^$' | sort -u)
102
+
103
+ # Repository paths first, scratchpad paths after, one shared cap of 30. A fifth
104
+ # of subagent writes target a scratchpad under /tmp, and "/tmp" sorts ahead of
105
+ # "/workspace", so a plain sort would fill the list with temporary files and
106
+ # drop the repository paths this field exists to name. Nothing new is captured;
107
+ # one list is reordered and the cap is the same 30 as before.
108
+ FILES_MODIFIED=$( { printf '%s\n' "$_MX_ALL_WRITES" | grep -v '^/tmp/' || true; \
109
+ printf '%s\n' "$_MX_ALL_WRITES" | grep '^/tmp/' || true; } \
110
+ | grep -v '^$' | head -30)
48
111
 
49
112
  # Files read (Read tool calls — indicates areas of investigation)
50
113
  FILES_READ=$(jq -r '
@@ -63,7 +126,14 @@ BASH_COMMANDS=$(jq -r '
63
126
  ' "$TRANSCRIPT_PATH" 2>/dev/null | grep -v '^$' | grep -vE '^(ls|pwd|echo|cat |head |tail )' | tail -20)
64
127
 
65
128
  # Git activity
66
- GIT_COMMITS=$(echo "$BASH_COMMANDS" | grep -oE 'git commit' | wc -l | tr -d ' ')
129
+ # Commit count over the lead and its subagents (#5436). Committing is usually
130
+ # delegated, so the lead-only count read 0 for most sessions. SUBAGENT_BASH is
131
+ # counted and never saved: no command text from it reaches the memory.
132
+ GIT_COMMITS_LEAD=$(echo "$BASH_COMMANDS" | grep -oE 'git commit' | wc -l | tr -d ' ')
133
+ GIT_COMMITS_SUB=$(printf '%s\n' "$SUBAGENT_BASH" | grep -oE 'git commit' | wc -l | tr -d ' ')
134
+ [[ "$GIT_COMMITS_LEAD" =~ ^[0-9]+$ ]] || GIT_COMMITS_LEAD=0
135
+ [[ "$GIT_COMMITS_SUB" =~ ^[0-9]+$ ]] || GIT_COMMITS_SUB=0
136
+ GIT_COMMITS=$(( GIT_COMMITS_LEAD + GIT_COMMITS_SUB ))
67
137
  GIT_PUSHES=$(echo "$BASH_COMMANDS" | grep -oE 'git push' | wc -l | tr -d ' ')
68
138
  PR_CREATES=$(echo "$BASH_COMMANDS" | grep -oE 'gh pr create' | wc -l | tr -d ' ')
69
139
  PR_MERGES=$(echo "$BASH_COMMANDS" | grep -oE 'gh pr merge' | wc -l | tr -d ' ')
@@ -150,13 +150,87 @@ else
150
150
  SEGMENT=$(cat "$TRANSCRIPT_PATH")
151
151
  fi
152
152
 
153
- # Files modified in this segment
154
- FILES_MODIFIED=$(echo "$SEGMENT" | jq -r '
153
+ # ── 3a. Subagent transcripts (#5436) ─────────────────────────────────────
154
+ #
155
+ # Claude Code writes a subagent's tool calls to its own file, never to the
156
+ # lead's transcript. The layout is a sibling directory of the session file:
157
+ #
158
+ # <project-dir>/<session-id>.jsonl the lead
159
+ # <project-dir>/<session-id>/subagents/agent-*.jsonl one per subagent
160
+ #
161
+ # So a filter over the lead's transcript alone cannot see a delegated write or a
162
+ # delegated commit. Measured over 5,713 real transcripts, subagents made 11,627
163
+ # of 12,343 repository writes (94%) against the lead's 716. That is why every
164
+ # auto-captured memory written between 2026-07-11 and 2026-08-13 reported
165
+ # "Files modified: None". Committing is delegated for the same reason, so the
166
+ # commit count at section 3b read 0 in 19 of 20 sampled memories.
167
+ #
168
+ # SCOPE. Exactly two fields read these files: the Write/Edit target paths below
169
+ # and the `git commit` count in section 3b. Nothing else does. In particular the
170
+ # lead's BASH_COMMANDS still feeds PR_REFS alone, because PR_REFS saves
171
+ # `gh pr create|merge` command lines verbatim and a `--body` argument carries
172
+ # prose. Widening that to subagents would put more verbatim transcript text into
173
+ # MemNexus, which this change deliberately does not do.
174
+ #
175
+ # The directory is absent for a session that spawned no subagent. That is the
176
+ # common case and not an error.
177
+ SUBAGENT_DIR="${TRANSCRIPT_PATH%.jsonl}/subagents"
178
+ SUBAGENT_FILES=()
179
+ if [[ -d "$SUBAGENT_DIR" ]]; then
180
+ # Match the lead's since-last-save window: a subagent transcript written before
181
+ # the previous capture was already reported by that capture. On the first
182
+ # capture no state file exists and every subagent file is in scope. This also
183
+ # bounds the read, which matters because this hook fires on every Stop.
184
+ _mx_newer=()
185
+ [[ -f "$STATE_FILE" ]] && _mx_newer=(-newer "$STATE_FILE")
186
+ # STATED CAP, not a silent one. The largest subagent count in the fleet's 301
187
+ # real sessions is 189, so 200 is above the observed range. A session past the
188
+ # cap reports the first 200 files and undercounts the rest.
189
+ while IFS= read -r _mx_f; do
190
+ [[ -n "$_mx_f" ]] && SUBAGENT_FILES+=("$_mx_f")
191
+ done < <(find "$SUBAGENT_DIR" -maxdepth 1 -type f -name 'agent-*.jsonl' \
192
+ "${_mx_newer[@]}" 2>/dev/null \
193
+ | head -n "${AUTO_CAPTURE_MAX_SUBAGENTS:-200}")
194
+ fi
195
+
196
+ # `-R` with `fromjson?` skips a malformed line instead of aborting the whole
197
+ # extraction. The lead's path below keeps plain `jq -r`, which aborts; that is
198
+ # left as it was. This path reads many files at once, so one bad line in one of
199
+ # them must not empty the result. The archive holds 15 unparseable lines across
200
+ # 5,713 files, which makes that a real case rather than a hypothetical one.
201
+ SUBAGENT_WRITES=""
202
+ if (( ${#SUBAGENT_FILES[@]} > 0 )); then
203
+ SUBAGENT_WRITES=$(jq -R -r 'fromjson? // empty |
204
+ select(.type == "assistant") |
205
+ .message.content[]? |
206
+ select(.type == "tool_use" and (.name == "Write" or .name == "Edit")) |
207
+ .input.file_path // empty
208
+ ' "${SUBAGENT_FILES[@]}" 2>/dev/null || true)
209
+ fi
210
+
211
+ # Files modified in this segment, by the lead and by its subagents
212
+ LEAD_WRITES=$(echo "$SEGMENT" | jq -r '
155
213
  select(.type == "assistant") |
156
214
  .message.content[]? |
157
215
  select(.type == "tool_use" and (.name == "Write" or .name == "Edit")) |
158
216
  .input.file_path // empty
159
- ' 2>/dev/null | grep -v '^$' | sort -u | head -20)
217
+ ' 2>/dev/null | grep -v '^$' || true)
218
+
219
+ _MX_ALL_WRITES=$(printf '%s\n%s\n' "$LEAD_WRITES" "$SUBAGENT_WRITES" \
220
+ | grep -v '^$' | sort -u)
221
+
222
+ # Repository paths first, scratchpad paths after, one shared cap of 20.
223
+ #
224
+ # Ordering matters now that subagent writes are in scope. A fifth of subagent
225
+ # writes target a scratchpad under /tmp/claude-1000/<project>/<session>/, and
226
+ # "/tmp" sorts ahead of "/workspace", so a plain `sort -u | head -20` filled the
227
+ # list with temporary files and dropped every repository path. The field would
228
+ # have stopped saying "None" while still not naming the work. This reorders one
229
+ # list; it captures no path it did not already capture, and the cap is the
230
+ # same 20 as before.
231
+ FILES_MODIFIED=$( { printf '%s\n' "$_MX_ALL_WRITES" | grep -v '^/tmp/' || true; \
232
+ printf '%s\n' "$_MX_ALL_WRITES" | grep '^/tmp/' || true; } \
233
+ | grep -v '^$' | head -20)
160
234
 
161
235
  # Tool call count
162
236
  TOOL_COUNT=$(echo "$SEGMENT" | jq -r '
@@ -180,7 +254,35 @@ BASH_COMMANDS=$(echo "$SEGMENT" | jq -r '
180
254
  .input.command // empty
181
255
  ' 2>/dev/null)
182
256
 
183
- GIT_COMMITS=$(echo "$BASH_COMMANDS" | grep -cE 'git commit' 2>/dev/null || echo "0")
257
+ # ── 3b. Commit count (#5436) ─────────────────────────────────────────────
258
+ #
259
+ # The line this replaces had two defects. It counted only the lead's Bash calls,
260
+ # and committing is usually delegated, so 19 of 20 sampled memories reported 0.
261
+ # And `grep -c` prints its count AND exits 1 when nothing matches, so the old
262
+ # `|| echo "0"` fired as well and the variable became two lines. That is the
263
+ # doubled "0" every one of those memories rendered.
264
+ #
265
+ # `|| true` keeps the assignment off the ERR trap installed at the top of this
266
+ # file without adding a second line: grep has already printed its count.
267
+ #
268
+ # SUBAGENT_BASH is counted and never saved. No command text from it reaches the
269
+ # memory: PR_REFS below reads the lead's BASH_COMMANDS only.
270
+ GIT_COMMITS_LEAD=$(printf '%s\n' "$BASH_COMMANDS" | grep -cE 'git commit' 2>/dev/null || true)
271
+
272
+ SUBAGENT_BASH=""
273
+ if (( ${#SUBAGENT_FILES[@]} > 0 )); then
274
+ SUBAGENT_BASH=$(jq -R -r 'fromjson? // empty |
275
+ select(.type == "assistant") |
276
+ .message.content[]? |
277
+ select(.type == "tool_use" and .name == "Bash") |
278
+ .input.command // empty
279
+ ' "${SUBAGENT_FILES[@]}" 2>/dev/null || true)
280
+ fi
281
+ GIT_COMMITS_SUB=$(printf '%s\n' "$SUBAGENT_BASH" | grep -cE 'git commit' 2>/dev/null || true)
282
+
283
+ [[ "$GIT_COMMITS_LEAD" =~ ^[0-9]+$ ]] || GIT_COMMITS_LEAD=0
284
+ [[ "$GIT_COMMITS_SUB" =~ ^[0-9]+$ ]] || GIT_COMMITS_SUB=0
285
+ GIT_COMMITS=$(( GIT_COMMITS_LEAD + GIT_COMMITS_SUB ))
184
286
  PR_REFS=$(echo "$BASH_COMMANDS" | grep -oE 'gh pr (create|merge) [^\n]*' 2>/dev/null | head -5)
185
287
 
186
288
  # PR and issue references. Extracted in a pipeline so the raw transcript text is