harnery 0.5.0 → 0.7.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 (176) hide show
  1. package/README.md +16 -6
  2. package/dist/commander.d.ts +29 -0
  3. package/dist/commander.d.ts.map +1 -1
  4. package/dist/commander.js +4 -0
  5. package/dist/commands/agents.d.ts.map +1 -1
  6. package/dist/commands/agents.js +94 -33
  7. package/dist/commands/browse-ai.js +1 -1
  8. package/dist/commands/browse.d.ts.map +1 -1
  9. package/dist/commands/browse.js +41 -9
  10. package/dist/commands/cookies.js +1 -1
  11. package/dist/commands/decision.d.ts +4 -0
  12. package/dist/commands/decision.d.ts.map +1 -0
  13. package/dist/commands/decision.js +354 -0
  14. package/dist/commands/deinit.d.ts.map +1 -1
  15. package/dist/commands/deinit.js +4 -0
  16. package/dist/commands/devtools.d.ts +4 -0
  17. package/dist/commands/devtools.d.ts.map +1 -0
  18. package/dist/commands/devtools.js +239 -0
  19. package/dist/commands/docs.d.ts.map +1 -1
  20. package/dist/commands/docs.js +74 -2
  21. package/dist/commands/doctor.js +12 -4
  22. package/dist/commands/env.d.ts.map +1 -1
  23. package/dist/commands/env.js +3 -63
  24. package/dist/commands/fetch.js +1 -1
  25. package/dist/commands/init.d.ts +1 -0
  26. package/dist/commands/init.d.ts.map +1 -1
  27. package/dist/commands/init.js +54 -14
  28. package/dist/commands/scratch.js +1 -1
  29. package/dist/commands/tunnel.d.ts.map +1 -1
  30. package/dist/commands/tunnel.js +273 -62
  31. package/dist/commands/web-fetch.js +1 -1
  32. package/dist/core/agents/coord-client.d.ts.map +1 -1
  33. package/dist/core/agents/coord-client.js +32 -8
  34. package/dist/core/agents/events/consume.d.ts +25 -2
  35. package/dist/core/agents/events/consume.d.ts.map +1 -1
  36. package/dist/core/agents/events/consume.js +55 -7
  37. package/dist/core/agents/events/emit.d.ts +2 -1
  38. package/dist/core/agents/events/emit.d.ts.map +1 -1
  39. package/dist/core/agents/events/emit.js +6 -1
  40. package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -1
  41. package/dist/core/agents/rules/claim-conflict.js +16 -5
  42. package/dist/core/agents/state/scratch.d.ts +1 -1
  43. package/dist/core/agents/state/scratch.js +2 -2
  44. package/dist/core/config.d.ts +10 -0
  45. package/dist/core/config.d.ts.map +1 -1
  46. package/dist/core/config.js +13 -0
  47. package/dist/core/hooks/cli.js +3 -3
  48. package/dist/core/hooks/effects/index.d.ts +11 -7
  49. package/dist/core/hooks/effects/index.d.ts.map +1 -1
  50. package/dist/core/hooks/effects/index.js +15 -17
  51. package/dist/core/hooks/events/emit.d.ts.map +1 -1
  52. package/dist/core/hooks/events/emit.js +4 -0
  53. package/dist/core/hooks/events/rotate.d.ts +43 -0
  54. package/dist/core/hooks/events/rotate.d.ts.map +1 -0
  55. package/dist/core/hooks/events/rotate.js +142 -0
  56. package/dist/core/hooks/harness/events.d.ts +11 -1
  57. package/dist/core/hooks/harness/events.d.ts.map +1 -1
  58. package/dist/core/hooks/harness/events.js +22 -3
  59. package/dist/core/hooks/harness/wiring.d.ts +8 -0
  60. package/dist/core/hooks/harness/wiring.d.ts.map +1 -1
  61. package/dist/core/hooks/harness/wiring.js +34 -5
  62. package/dist/core/scratch/index.d.ts.map +1 -0
  63. package/dist/{lib → core}/scratch/index.js +2 -2
  64. package/dist/lib/agent-browser/client.js +1 -1
  65. package/dist/lib/browser/client.d.ts +14 -0
  66. package/dist/lib/browser/client.d.ts.map +1 -1
  67. package/dist/lib/browser/client.js +20 -0
  68. package/dist/lib/browser/index.d.ts +1 -0
  69. package/dist/lib/browser/index.d.ts.map +1 -1
  70. package/dist/lib/browser/runts.d.ts +44 -0
  71. package/dist/lib/browser/runts.d.ts.map +1 -0
  72. package/dist/lib/browser/runts.js +193 -0
  73. package/dist/lib/completion/walk.js +1 -1
  74. package/dist/lib/cookies/client.d.ts +1 -1
  75. package/dist/lib/cookies/client.d.ts.map +1 -1
  76. package/dist/lib/cookies/client.js +1 -1
  77. package/dist/lib/decision/index.d.ts +212 -0
  78. package/dist/lib/decision/index.d.ts.map +1 -0
  79. package/dist/lib/decision/index.js +523 -0
  80. package/dist/lib/devtools.d.ts +178 -0
  81. package/dist/lib/devtools.d.ts.map +1 -0
  82. package/dist/lib/devtools.js +1328 -0
  83. package/dist/lib/docs-frontmatter-migrate.d.ts +33 -0
  84. package/dist/lib/docs-frontmatter-migrate.d.ts.map +1 -0
  85. package/dist/lib/docs-frontmatter-migrate.js +364 -0
  86. package/dist/lib/docs-frontmatter.d.ts +33 -0
  87. package/dist/lib/docs-frontmatter.d.ts.map +1 -0
  88. package/dist/lib/docs-frontmatter.js +130 -0
  89. package/dist/lib/docs-index.d.ts +1 -0
  90. package/dist/lib/docs-index.d.ts.map +1 -1
  91. package/dist/lib/docs-index.js +4 -5
  92. package/dist/lib/docs-lint.d.ts +3 -0
  93. package/dist/lib/docs-lint.d.ts.map +1 -1
  94. package/dist/lib/docs-lint.js +67 -12
  95. package/dist/lib/docs-meta.d.ts +14 -0
  96. package/dist/lib/docs-meta.d.ts.map +1 -0
  97. package/dist/lib/docs-meta.js +34 -0
  98. package/dist/lib/docs-sweep.d.ts +12 -0
  99. package/dist/lib/docs-sweep.d.ts.map +1 -1
  100. package/dist/lib/docs-sweep.js +98 -103
  101. package/dist/lib/format.js +2 -2
  102. package/dist/lib/http/index.d.ts +1 -0
  103. package/dist/lib/http/index.d.ts.map +1 -1
  104. package/dist/lib/http/index.js +1 -0
  105. package/dist/lib/http/request.d.ts +77 -0
  106. package/dist/lib/http/request.d.ts.map +1 -0
  107. package/dist/lib/http/request.js +105 -0
  108. package/dist/lib/instructions/apply.d.ts +63 -0
  109. package/dist/lib/instructions/apply.d.ts.map +1 -0
  110. package/dist/lib/instructions/apply.js +255 -0
  111. package/dist/lib/instructions/splice.d.ts +73 -0
  112. package/dist/lib/instructions/splice.d.ts.map +1 -0
  113. package/dist/lib/instructions/splice.js +118 -0
  114. package/dist/lib/instructions/templates.d.ts +45 -0
  115. package/dist/lib/instructions/templates.d.ts.map +1 -0
  116. package/dist/lib/instructions/templates.js +258 -0
  117. package/dist/lib/tunnel/gate.d.ts +1 -0
  118. package/dist/lib/tunnel/gate.d.ts.map +1 -1
  119. package/dist/lib/tunnel/gate.js +15 -10
  120. package/dist/lib/tunnel/state.d.ts +11 -1
  121. package/dist/lib/tunnel/state.d.ts.map +1 -1
  122. package/dist/lib/tunnel/state.js +8 -3
  123. package/package.json +9 -6
  124. package/src/commander.ts +35 -0
  125. package/src/commands/agents.ts +97 -29
  126. package/src/commands/browse-ai.ts +1 -1
  127. package/src/commands/browse.ts +63 -8
  128. package/src/commands/cookies.ts +1 -1
  129. package/src/commands/decision.ts +438 -0
  130. package/src/commands/deinit.ts +5 -0
  131. package/src/commands/devtools.ts +284 -0
  132. package/src/commands/docs.ts +86 -2
  133. package/src/commands/doctor.ts +13 -4
  134. package/src/commands/env.ts +11 -77
  135. package/src/commands/fetch.ts +1 -1
  136. package/src/commands/init.ts +66 -15
  137. package/src/commands/scratch.ts +1 -1
  138. package/src/commands/tunnel.ts +316 -65
  139. package/src/commands/web-fetch.ts +1 -1
  140. package/src/core/agents/coord-client.ts +34 -7
  141. package/src/core/agents/events/consume.ts +65 -7
  142. package/src/core/agents/events/emit.ts +7 -1
  143. package/src/core/agents/rules/claim-conflict.ts +17 -6
  144. package/src/core/agents/state/scratch.ts +2 -2
  145. package/src/core/config.ts +15 -1
  146. package/src/core/hooks/cli.ts +3 -3
  147. package/src/core/hooks/effects/index.ts +23 -16
  148. package/src/core/hooks/events/emit.ts +5 -0
  149. package/src/core/hooks/events/rotate.ts +151 -0
  150. package/src/core/hooks/harness/events.ts +30 -3
  151. package/src/core/hooks/harness/wiring.ts +46 -5
  152. package/src/{lib → core}/scratch/index.ts +2 -2
  153. package/src/lib/agent-browser/client.ts +1 -1
  154. package/src/lib/browser/client.ts +28 -0
  155. package/src/lib/browser/index.ts +4 -0
  156. package/src/lib/browser/runts.ts +218 -0
  157. package/src/lib/completion/walk.ts +1 -1
  158. package/src/lib/cookies/client.ts +2 -2
  159. package/src/lib/decision/index.ts +685 -0
  160. package/src/lib/devtools.ts +1653 -0
  161. package/src/lib/docs-frontmatter-migrate.ts +427 -0
  162. package/src/lib/docs-frontmatter.ts +151 -0
  163. package/src/lib/docs-index.ts +4 -5
  164. package/src/lib/docs-lint.ts +61 -11
  165. package/src/lib/docs-meta.ts +44 -0
  166. package/src/lib/docs-sweep.ts +104 -102
  167. package/src/lib/format.ts +2 -2
  168. package/src/lib/http/index.ts +1 -0
  169. package/src/lib/http/request.ts +154 -0
  170. package/src/lib/instructions/apply.ts +318 -0
  171. package/src/lib/instructions/splice.ts +148 -0
  172. package/src/lib/instructions/templates.ts +295 -0
  173. package/src/lib/tunnel/gate.ts +15 -10
  174. package/src/lib/tunnel/state.ts +19 -4
  175. package/dist/lib/scratch/index.d.ts.map +0 -1
  176. /package/dist/{lib → core}/scratch/index.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"consume.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/events/consume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAmBH,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,oEAAo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,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,aAAa,CAuDrF;AAgBD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAWtC;AAiDD,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS3D;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAQpE"}
@@ -11,8 +11,12 @@
11
11
  * with a bounded **tail read** (reading only the last `tailBytes` of the file
12
12
  * and locating the cursor there) which turns an O(file-size) read into
13
13
  * O(window). If the cursor is older than the window (a long-idle system, or a
14
- * cursor that's been rotated out) we fall back to a full read. The fallback is
15
- * always correct, just slower, so undersizing the window can never lose events.
14
+ * cursor that's been rotated out) we fall back to a wider read that is itself
15
+ * capped (`fallbackCapBytes`): the stream is an append-only ledger that grows
16
+ * without bound, so a whole-file `readFileSync` throws V8's max-string-length
17
+ * error ("Cannot create a string longer than 0x1fffffe8 characters") once it
18
+ * passes ~512MB, which would abort the projection. Events older than the cap are
19
+ * stale for coord-state purposes, so a bounded replay is the correct fallback.
16
20
  *
17
21
  * Idempotency: projectors are idempotent by `event_id`. The
18
22
  * cursor file makes this cheap (we never replay an already-projected event by
@@ -25,6 +29,11 @@ import { coordEnv } from "../../../lib/env.js";
25
29
  const STREAM_REL = ".harnery/events.ndjson";
26
30
  const CURSOR_REL = ".harnery/.events-cursor";
27
31
  const DEFAULT_TAIL_BYTES = 2 * 1024 * 1024; // 2 MiB, thousands of events of headroom
32
+ /** Cap for the fall-through read when the cursor misses the tail window. Well
33
+ * under V8's ~512MB max string length so it never throws on the unbounded
34
+ * ledger; comfortably larger than any realistic cursor drift (the global cursor
35
+ * advances on every agent's turn.stop, so it sits near EOF in practice). */
36
+ const DEFAULT_FALLBACK_CAP_BYTES = 64 * 1024 * 1024; // 64 MiB
28
37
  /**
29
38
  * Read all events after the persisted cursor, in chronological (file) order.
30
39
  */
@@ -54,8 +63,19 @@ export function consumeSince(coordRoot, opts = {}) {
54
63
  }
55
64
  // Cursor older than the tail window → fall through to a full read.
56
65
  }
57
- // Full read: first run, replayAll, small file, or cursor not found in tail.
58
- const all = parseLines(readFileSync(streamPath, "utf8"));
66
+ // Bounded fall-through: first run, replayAll, small file, or cursor not found
67
+ // in the tail. This must NEVER read the whole file: the stream grows without
68
+ // bound and a >512MB readFileSync throws V8's max-string-length error, which
69
+ // would abort the projection. Read at most `cap` bytes from the tail; when we
70
+ // start mid-file, drop the (likely partial) first line.
71
+ const cap = resolveFallbackCap(opts.fallbackCapBytes);
72
+ const readBytes = Math.min(fileSize, cap);
73
+ let text = readTailUtf8(streamPath, fileSize, readBytes);
74
+ if (readBytes < fileSize) {
75
+ const firstNl = text.indexOf("\n");
76
+ text = firstNl >= 0 ? text.slice(firstNl + 1) : "";
77
+ }
78
+ const all = parseLines(text);
59
79
  const parsed = eventsAfterCursor(all, cursor);
60
80
  if (parsed.foundCursor) {
61
81
  return {
@@ -64,11 +84,18 @@ export function consumeSince(coordRoot, opts = {}) {
64
84
  streamBytes: fileSize,
65
85
  };
66
86
  }
67
- // The cursor names an event that's been rotated out of the file, so replay
68
- // everything (safer than silent state drift; the projector is idempotent by
69
- // event_id).
87
+ // The cursor names an event older than the capped window (or rotated out), so
88
+ // replay what the window holds (safer than silent state drift; the projector
89
+ // is idempotent by event_id). lastEventId null keeps the cursor put.
70
90
  return { events: all, lastEventId: null, streamBytes: fileSize };
71
91
  }
92
+ function resolveFallbackCap(override) {
93
+ if (override !== undefined && override > 0)
94
+ return override;
95
+ const env = coordEnv("AGENT_COORD_FALLBACK_CAP_BYTES");
96
+ const n = env ? Number(env) : Number.NaN;
97
+ return Number.isFinite(n) && n > 0 ? n : DEFAULT_FALLBACK_CAP_BYTES;
98
+ }
72
99
  function resolveTailBytes(override) {
73
100
  if (override !== undefined && override > 0)
74
101
  return override;
@@ -76,6 +103,27 @@ function resolveTailBytes(override) {
76
103
  const n = env ? Number(env) : Number.NaN;
77
104
  return Number.isFinite(n) && n > 0 ? n : DEFAULT_TAIL_BYTES;
78
105
  }
106
+ /**
107
+ * Read at most `capBytes` from the tail of the event stream as UTF-8, dropping
108
+ * the (partial) leading line when the file is larger than the cap. Shared
109
+ * bounded reader for CLI consumers (`agents trace` / `agents health`) that must
110
+ * never `readFileSync` the whole unbounded ledger — a >512MB read throws V8's
111
+ * max-string-length error. `truncated` is true when older bytes were skipped, so
112
+ * callers can surface the cap rather than silently under-reporting.
113
+ */
114
+ export function readStreamTailBounded(streamPath, capBytes) {
115
+ if (!existsSync(streamPath))
116
+ return { text: "", truncated: false };
117
+ const fileSize = statSync(streamPath).size;
118
+ const readBytes = Math.min(fileSize, capBytes);
119
+ let text = readTailUtf8(streamPath, fileSize, readBytes);
120
+ const truncated = readBytes < fileSize;
121
+ if (truncated) {
122
+ const nl = text.indexOf("\n");
123
+ text = nl >= 0 ? text.slice(nl + 1) : "";
124
+ }
125
+ return { text, truncated };
126
+ }
79
127
  /** Read the trailing `windowBytes` of a file as UTF-8 without loading the rest. */
80
128
  function readTailUtf8(streamPath, fileSize, windowBytes) {
81
129
  const start = Math.max(0, fileSize - windowBytes);
@@ -5,7 +5,8 @@
5
5
  * event/schema types).
6
6
  *
7
7
  * Phase 4: agent-coord uses this from CLI handlers (state.task_set,
8
- * state.status_checked, state.scratch_append, council.*, presence.*).
8
+ * state.status_checked, state.scratch_append, council.*, decision.*,
9
+ * presence.*).
9
10
  */
10
11
  declare const SCHEMA_VERSION: 1;
11
12
  export type Harness = "claude-code" | "cursor" | "codex";
@@ -1 +1 @@
1
- {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/events/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,QAAA,MAAM,cAAc,EAAG,CAAU,CAAC;AAKlC,MAAM,MAAM,OAAO,GAAG,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC;AACzD,MAAM,MAAM,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvE,MAAM,WAAW,QAAQ;IACvB,cAAc,EAAE,OAAO,cAAc,CAAC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B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AI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,CAexD;AAED,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,QAAQ,CA4BlE"}
@@ -5,10 +5,12 @@
5
5
  * event/schema types).
6
6
  *
7
7
  * Phase 4: agent-coord uses this from CLI handlers (state.task_set,
8
- * state.status_checked, state.scratch_append, council.*, presence.*).
8
+ * state.status_checked, state.scratch_append, council.*, decision.*,
9
+ * presence.*).
9
10
  */
10
11
  import { appendFileSync, closeSync, mkdirSync, openSync } from "node:fs";
11
12
  import { dirname, join } from "node:path";
13
+ import { maybeRotateEventStream } from "../../hooks/events/rotate.js";
12
14
  import { ulid } from "./ulid.js";
13
15
  const SCHEMA_VERSION = 1;
14
16
  const STREAM_FILE = ".harnery/events.ndjson";
@@ -34,6 +36,9 @@ export function emit(coordRoot, input) {
34
36
  const envelope = buildEnvelope(input);
35
37
  const streamPath = join(coordRoot, STREAM_FILE);
36
38
  const lockPath = join(coordRoot, LOCK_FILE);
39
+ // Size-triggered rotation (shared with the agent-hooks emitter): roll the
40
+ // active file to a dated archive when it crosses the cap. Fail-soft.
41
+ maybeRotateEventStream(coordRoot);
37
42
  ensureDir(dirname(streamPath));
38
43
  ensureFile(lockPath);
39
44
  let line = `${JSON.stringify(envelope)}\n`;
@@ -1 +1 @@
1
- {"version":3,"file":"claim-conflict.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/rules/claim-conflict.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAeF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,aAAa,CAyFjF"}
1
+ {"version":3,"file":"claim-conflict.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/rules/claim-conflict.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAeF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,aAAa,CAoGjF"}
@@ -58,10 +58,21 @@ export function evaluateClaim(coordRoot, req) {
58
58
  }
59
59
  // Ordering check: if we hold any claim with path < req.path, fine.
60
60
  // Otherwise the new claim would create a backward-edge in the dependency
61
- // graph and risk deadlock. Only applies when there are OTHER fresh peers:
62
- // single-agent flow can't deadlock with itself, and the rule otherwise
63
- // forces release-and-reacquire cycles on every reverse-order edit pair.
64
- const hasFreshPeers = otherPeers.some((p) => isFresh(p.last_heartbeat) && p.files_touched.length > 0);
61
+ // graph and risk deadlock. Only applies when a fresh peer genuinely CONTENDS
62
+ // with us — i.e. holds a path that also sits in our own footprint (held
63
+ // claims ∪ the path we're now requesting). A wait-for cycle is a
64
+ // strongly-connected set of agents linked by shared files; if no fresh peer
65
+ // shares any file with our footprint, we're in a disjoint component of the
66
+ // resource graph and cannot be part of any cycle, so sorted-order acquisition
67
+ // buys nothing and the block is pure false-positive friction. Sharing a file
68
+ // is the necessary condition for a cycle through this agent, so this narrowing
69
+ // leaves the deadlock-prevention invariant intact for genuine contention while
70
+ // removing the dominant real-world cost — a peer editing unrelated files
71
+ // walling off every backward-order edit. (Single-agent flow can't deadlock
72
+ // with itself and never arms, since there are no other peers to contend.)
73
+ const myFootprint = new Set(myPeer?.files_touched ?? []);
74
+ myFootprint.add(req.path);
75
+ const hasContendingPeer = otherPeers.some((p) => isFresh(p.last_heartbeat) && p.files_touched.some((f) => myFootprint.has(f)));
65
76
  // Re-editing a path already in our own files_touched acquires no new lock
66
77
  // edge, so it can't create a circular wait — the ordering rule must not block
67
78
  // it. Without this exemption, an agent that edits a higher-sorting file and
@@ -70,7 +81,7 @@ export function evaluateClaim(coordRoot, req) {
70
81
  // both agent-Gibson holding README.md and agent-Ophelia holding AGENTS.md were
71
82
  // blocked re-editing those held files after touching a higher path, 2026-07-03).
72
83
  const alreadyHeld = myPeer?.files_touched.includes(req.path) ?? false;
73
- if (hasFreshPeers && myPeer && myPeer.files_touched.length > 0 && !alreadyHeld) {
84
+ if (hasContendingPeer && myPeer && myPeer.files_touched.length > 0 && !alreadyHeld) {
74
85
  // Only ACTIVE (uncommitted) edits should constrain lock ordering. A claim on
75
86
  // a committed-clean file is a finished edit, not a held lock, so it must not
76
87
  // wall off a lower-sorted acquisition. Without this, a long session
@@ -16,7 +16,7 @@ export declare function appendScratch(coordRoot: string, instanceId: string, cat
16
16
  };
17
17
  /**
18
18
  * Replace the scratchpad with new body, archiving prior contents and
19
- * appending an "(edited via UI by Ryan)" audit-marker note.
19
+ * appending an "(edited via UI by the operator)" audit-marker note.
20
20
  */
21
21
  export declare function editScratchpad(coordRoot: string, instanceId: string, newBody: string, summary: string): {
22
22
  ok: boolean;
@@ -58,7 +58,7 @@ export function appendScratch(coordRoot, instanceId, category, body) {
58
58
  }
59
59
  /**
60
60
  * Replace the scratchpad with new body, archiving prior contents and
61
- * appending an "(edited via UI by Ryan)" audit-marker note.
61
+ * appending an "(edited via UI by the operator)" audit-marker note.
62
62
  */
63
63
  export function editScratchpad(coordRoot, instanceId, newBody, summary) {
64
64
  if (typeof newBody !== "string") {
@@ -82,7 +82,7 @@ export function editScratchpad(coordRoot, instanceId, newBody, summary) {
82
82
  prior += "\n";
83
83
  }
84
84
  const summaryText = summary && summary.length > 0 ? summary : "(no summary)";
85
- const auditMarker = `## [${ts}] note (edited via UI by Ryan)\n` +
85
+ const auditMarker = `## [${ts}] note (edited via UI by the operator)\n` +
86
86
  `${summaryText}\n` +
87
87
  `Pre-edit archived at .harnery/scratch/archived/${instanceId}-${archiveSuffix}.md\n\n`;
88
88
  atomicWriteText(target, prior + auditMarker + newBody + (newBody.endsWith("\n") ? "" : "\n"));
@@ -26,6 +26,16 @@ export declare function stripJsonComments(input: string): string;
26
26
  * `coordRoot` is resolved via `findCoordRoot()` when not passed.
27
27
  */
28
28
  export declare function resolveBinName(coordRoot?: string | null): string;
29
+ /**
30
+ * The binName explicitly pinned in `<projectRoot>/.harnery/config.jsonc`, or
31
+ * null when absent. Unlike `resolveBinName()` this ignores `HARNERY_BIN` and
32
+ * never falls back to the default — it answers "did someone deliberately pin
33
+ * a name for THIS project?". `init` uses it so a re-run from a different host
34
+ * CLI can't silently re-stamp its own name over a committed pin (the harnery
35
+ * repo itself pins `"harn"` while living embedded in a host monorepo whose
36
+ * CLI would otherwise stamp the host's name into public, committed surfaces).
37
+ */
38
+ export declare function pinnedBinName(projectRoot: string): string | null;
29
39
  /**
30
40
  * The host's git-hook (re)install command, for the "commit guard not wired"
31
41
  * nudge. Returns the configured `hooksSetupHint` (e.g. "scripts/setup-hooks.sh")
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,oFAAoF;AACpF,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAgBvC,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqCvD;AAyBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAShE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAK9E"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,oFAAoF;AACpF,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAgBvC,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqCvD;AAyBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAShE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAK9E"}
@@ -106,6 +106,19 @@ export function resolveBinName(coordRoot) {
106
106
  }
107
107
  return DEFAULT_BIN_NAME;
108
108
  }
109
+ /**
110
+ * The binName explicitly pinned in `<projectRoot>/.harnery/config.jsonc`, or
111
+ * null when absent. Unlike `resolveBinName()` this ignores `HARNERY_BIN` and
112
+ * never falls back to the default — it answers "did someone deliberately pin
113
+ * a name for THIS project?". `init` uses it so a re-run from a different host
114
+ * CLI can't silently re-stamp its own name over a committed pin (the harnery
115
+ * repo itself pins `"harn"` while living embedded in a host monorepo whose
116
+ * CLI would otherwise stamp the host's name into public, committed surfaces).
117
+ */
118
+ export function pinnedBinName(projectRoot) {
119
+ const binName = readConfig(projectRoot).binName;
120
+ return typeof binName === "string" && binName.trim() ? binName.trim() : null;
121
+ }
109
122
  /**
110
123
  * The host's git-hook (re)install command, for the "commit guard not wired"
111
124
  * nudge. Returns the configured `hooksSetupHint` (e.g. "scripts/setup-hooks.sh")
@@ -26,7 +26,7 @@ import { consumeSince, writeCursor } from "../agents/events/consume.js";
26
26
  import { evaluateStopHook } from "../agents/rules/stop-hook.js";
27
27
  import { projectHeartbeats } from "../agents/state/heartbeat-projector.js";
28
28
  import { shellMutationPaths } from "../agents/state/shell-mutation.js";
29
- import { captureImages, detectPresence, imageJanitor, playSound, resetSoundCounters, runTurnSummary, scratchArchive, scratchJanitor, scratchRecoveryCue, soundForEvent, syncClaudeSessions, } from "./effects/index.js";
29
+ import { captureImages, detectPresence, imageJanitor, playSound, resetSoundCounters, runSessionSyncExtension, runTurnSummary, scratchArchive, scratchJanitor, scratchRecoveryCue, soundForEvent, } from "./effects/index.js";
30
30
  import { emit } from "./events/emit.js";
31
31
  import { canonicalize } from "./guard-path.js";
32
32
  import { detectHarness } from "./harness/detect.js";
@@ -441,7 +441,7 @@ async function main() {
441
441
  // session-telemetry sync (via HARNERY_CLAUDE_SESSIONS_FORCE=1).
442
442
  if (harness === "claude-code") {
443
443
  scratchArchive(coordRoot, owner.instance_id);
444
- syncClaudeSessions(coordRoot, true);
444
+ runSessionSyncExtension(coordRoot, true);
445
445
  }
446
446
  }
447
447
  // Phase 8: SubagentStart: sync-project to create the subagent heartbeat,
@@ -528,7 +528,7 @@ async function main() {
528
528
  // CC effects: rate-limited session-telemetry sync + turn-summary Haiku
529
529
  // auto-summary.
530
530
  if (harness === "claude-code") {
531
- syncClaudeSessions(coordRoot, false);
531
+ runSessionSyncExtension(coordRoot, false);
532
532
  runTurnSummary(coordRoot, owner.instance_id, sessionId, payload?.transcript_path);
533
533
  }
534
534
  // Master-state heartbeat projection. Drains events.ndjson since the last
@@ -37,14 +37,18 @@ export declare function scratchRecoveryCue(repoRoot: string): string;
37
37
  /** Archive the ending agent's scratchpad. Fire-and-forget. */
38
38
  export declare function scratchArchive(repoRoot: string, owner: string): void;
39
39
  /**
40
- * Sync Claude Code session JSONL → BigQuery (`harn claude-sessions sync`). Lives
41
- * in the host CLI (parses Claude Code's own ~/.claude/projects/**\/*.jsonl), so harnery
42
- * shells out to the harn binary rather than importing it. Detached + unref'd so a
43
- * slow BigQuery round-trip never blocks the hook. Stop-path syncs are rate-
44
- * limited inside `harn claude-sessions sync`; SessionEnd forces via env. Caller
45
- * gates to the claude-code harness.
40
+ * Fire the optional host session-sync extension on turn stop / session end.
41
+ * harnery core has no session-telemetry sink of its own; a host that wants one
42
+ * drops an executable at
43
+ * `scripts/hooks/harness/claude_code/extensions/session-sync.sh` under the coord
44
+ * root, and core runs it detached + unref'd so a slow sink never blocks the
45
+ * hook. `force` arrives as argv $1 ("1" on session end, "0" on turn stop) so the
46
+ * host can rate-limit the stop path and force-flush on end. No-op when the
47
+ * script is absent, so a plain public install spawns nothing. Mirrors
48
+ * `runTurnSummary`'s extension-script pattern. Caller gates to the claude-code
49
+ * harness.
46
50
  */
47
- export declare function syncClaudeSessions(repoRoot: string, force: boolean): void;
51
+ export declare function runSessionSyncExtension(repoRoot: string, force: boolean): void;
48
52
  /**
49
53
  * Fire the turn-summary extension (Haiku auto-summary of the turn → heartbeat
50
54
  * `turn_summary`). Detached + unref'd; it makes an Anthropic API call and must
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/hooks/effects/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,aAAa,EAA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M,oBAAoB,CAAC;AAEjE;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,SAAI,GACX,IAAI,CAYN;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAW3F;AAOD,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAYrD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAa3D;AAED,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAYpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAqB9E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,IAAI,CAqBN;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAa1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOnD"}
@@ -110,26 +110,24 @@ export function scratchArchive(repoRoot, owner) {
110
110
  }
111
111
  }
112
112
  /**
113
- * Sync Claude Code session JSONL → BigQuery (`harn claude-sessions sync`). Lives
114
- * in the host CLI (parses Claude Code's own ~/.claude/projects/**\/*.jsonl), so harnery
115
- * shells out to the harn binary rather than importing it. Detached + unref'd so a
116
- * slow BigQuery round-trip never blocks the hook. Stop-path syncs are rate-
117
- * limited inside `harn claude-sessions sync`; SessionEnd forces via env. Caller
118
- * gates to the claude-code harness.
113
+ * Fire the optional host session-sync extension on turn stop / session end.
114
+ * harnery core has no session-telemetry sink of its own; a host that wants one
115
+ * drops an executable at
116
+ * `scripts/hooks/harness/claude_code/extensions/session-sync.sh` under the coord
117
+ * root, and core runs it detached + unref'd so a slow sink never blocks the
118
+ * hook. `force` arrives as argv $1 ("1" on session end, "0" on turn stop) so the
119
+ * host can rate-limit the stop path and force-flush on end. No-op when the
120
+ * script is absent, so a plain public install spawns nothing. Mirrors
121
+ * `runTurnSummary`'s extension-script pattern. Caller gates to the claude-code
122
+ * harness.
119
123
  */
120
- export function syncClaudeSessions(repoRoot, force) {
124
+ export function runSessionSyncExtension(repoRoot, force) {
121
125
  try {
122
- const bin = join(repoRoot, "bin", "bp");
123
- if (!existsSync(bin))
126
+ const script = join(repoRoot, "scripts", "hooks", "harness", "claude_code", "extensions", "session-sync.sh");
127
+ if (!existsSync(script))
124
128
  return;
125
- const env = {
126
- ...process.env,
127
- HARNERY_OUTPUT_SESSION_TEE: "0",
128
- };
129
- if (force)
130
- env.HARNERY_CLAUDE_SESSIONS_FORCE = "1";
131
- const child = spawn("bash", [bin, "claude-sessions", "sync", "--quiet"], {
132
- env,
129
+ const child = spawn("bash", [script, force ? "1" : "0"], {
130
+ env: { ...process.env, HARNERY_OUTPUT_SESSION_TEE: "0" },
133
131
  detached: true,
134
132
  stdio: "ignore",
135
133
  });
@@ -1 +1 @@
1
- {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../../src/core/hooks/events/emit.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,OAAO,EAEZ,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AAQrB,MAAM,WAAW,SAAS,CAAC,KAAK,SAAS,SAAS,EAAE,KAAK;IACvD,UAAU,EAAE,KA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CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,SAAS,EAAE,KAAK,EAC1D,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,GAC7B,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAe7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,SAAS,SAAS,EAAE,KAAK,EACjD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,GAC7B,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAyC7B"}
@@ -1,5 +1,6 @@
1
1
  import { appendFileSync, closeSync, mkdirSync, openSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
+ import { maybeRotateEventStream } from "./rotate.js";
3
4
  import { SCHEMA_VERSION, } from "./schema.js";
4
5
  import { ulid } from "./ulid.js";
5
6
  const LOCK_FILE = ".harnery/events.ndjson.lock";
@@ -40,6 +41,9 @@ export function emit(coordRoot, input) {
40
41
  const envelope = buildEnvelope(input);
41
42
  const streamPath = join(coordRoot, STREAM_FILE);
42
43
  const lockPath = join(coordRoot, LOCK_FILE);
44
+ // Size-triggered rotation: roll the active file to a dated archive when it
45
+ // crosses the cap, so this append lands in a bounded fresh file. Fail-soft.
46
+ maybeRotateEventStream(coordRoot);
43
47
  ensureDir(dirname(streamPath));
44
48
  ensureFile(lockPath);
45
49
  let line = `${JSON.stringify(envelope)}\n`;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Size-triggered rotation for the canonical event stream
3
+ * `.harnery/events.ndjson`.
4
+ *
5
+ * The stream is a deliberately-immutable, append-only ledger. Left unbounded it
6
+ * grows past V8's ~512MB max string length, at which point any code that does a
7
+ * whole-file `readFileSync` throws ("Cannot create a string longer than
8
+ * 0x1fffffe8 characters"). Rather than police every current + future reader,
9
+ * we bound the *active* file: once it crosses a byte cap we rename it to a dated
10
+ * archive (`events-YYYY-MM-DD.ndjson`) and start a fresh active file. Archives
11
+ * are kept — the audit trail is preserved, just spread across files that readers
12
+ * glob newest-first.
13
+ *
14
+ * Both independent append paths (agent-hooks `hooks/events/emit.ts` and
15
+ * agent-coord `agents/events/emit.ts`) call `maybeRotateEventStream` before
16
+ * appending, so a roll is triggered continuously, not only at session
17
+ * boundaries.
18
+ *
19
+ * Concurrency: many short-lived hook processes append at once. The rename itself
20
+ * is atomic — a concurrent appender opening the path by name lands its line in
21
+ * whichever inode the name currently resolves to (old archive or new active
22
+ * file), never nowhere. The only hazard is two processes both renaming (the
23
+ * second would move the fresh empty file to a second archive name), which an
24
+ * `O_EXCL` roll-lock prevents.
25
+ *
26
+ * Design + rationale: harnery ADR 0009; decision docket
27
+ * `should-harnery-adopt-a-retention-2026-07-07-ed07`.
28
+ */
29
+ /** Archive glob prefix. Readers enumerate `events-*.ndjson` newest-first.
30
+ * The pre-existing manual `events-legacy.ndjson` matches and is picked up for
31
+ * free. Kept in sync with the reader-side pattern in web/lib/coord-reader.ts. */
32
+ export declare const ARCHIVE_PREFIX = "events-";
33
+ export declare const ARCHIVE_SUFFIX = ".ndjson";
34
+ /**
35
+ * Roll `events.ndjson` to a dated archive when it exceeds the byte cap. Cheap
36
+ * no-op (a single `statSync`) below the cap. Fail-soft: any error is swallowed
37
+ * so a rotation problem can never break the append that triggered it.
38
+ *
39
+ * `nowMs` is injectable for the stale-lock check in tests; production leaves it
40
+ * unset (the roll date always comes from the file's mtime, never `nowMs`).
41
+ */
42
+ export declare function maybeRotateEventStream(coordRoot: string, nowMs?: number): boolean;
43
+ //# sourceMappingURL=rotate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotate.d.ts","sourceRoot":"","sources":["../../../../src/core/hooks/events/rotate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAyBH;;iFAEiF;AACjF,eAAO,MAAM,cAAc,YAAY,CAAC;AACxC,eAAO,MAAM,cAAc,YAAY,CAAC;AA6BxC;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAmCjF"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Size-triggered rotation for the canonical event stream
3
+ * `.harnery/events.ndjson`.
4
+ *
5
+ * The stream is a deliberately-immutable, append-only ledger. Left unbounded it
6
+ * grows past V8's ~512MB max string length, at which point any code that does a
7
+ * whole-file `readFileSync` throws ("Cannot create a string longer than
8
+ * 0x1fffffe8 characters"). Rather than police every current + future reader,
9
+ * we bound the *active* file: once it crosses a byte cap we rename it to a dated
10
+ * archive (`events-YYYY-MM-DD.ndjson`) and start a fresh active file. Archives
11
+ * are kept — the audit trail is preserved, just spread across files that readers
12
+ * glob newest-first.
13
+ *
14
+ * Both independent append paths (agent-hooks `hooks/events/emit.ts` and
15
+ * agent-coord `agents/events/emit.ts`) call `maybeRotateEventStream` before
16
+ * appending, so a roll is triggered continuously, not only at session
17
+ * boundaries.
18
+ *
19
+ * Concurrency: many short-lived hook processes append at once. The rename itself
20
+ * is atomic — a concurrent appender opening the path by name lands its line in
21
+ * whichever inode the name currently resolves to (old archive or new active
22
+ * file), never nowhere. The only hazard is two processes both renaming (the
23
+ * second would move the fresh empty file to a second archive name), which an
24
+ * `O_EXCL` roll-lock prevents.
25
+ *
26
+ * Design + rationale: harnery ADR 0009; decision docket
27
+ * `should-harnery-adopt-a-retention-2026-07-07-ed07`.
28
+ */
29
+ import { closeSync, existsSync, mkdirSync, openSync, renameSync, statSync, unlinkSync, } from "node:fs";
30
+ import { dirname, join } from "node:path";
31
+ import { coordEnv } from "../../../lib/env.js";
32
+ const STREAM_FILE = ".harnery/events.ndjson";
33
+ const ROLL_LOCK_FILE = ".harnery/events.ndjson.roll.lock";
34
+ /** Default active-file cap: 256 MiB — half of V8's ~512MB string cliff, so even
35
+ * a reader that loads the whole active file whole stays clear of the limit. */
36
+ const DEFAULT_ROLL_BYTES = 256 * 1024 * 1024;
37
+ /** A roll-lock older than this is treated as abandoned (a crashed roller) and
38
+ * stolen. Rolls are sub-millisecond, so 60s is orders of magnitude of slack. */
39
+ const STALE_LOCK_MS = 60_000;
40
+ /** Archive glob prefix. Readers enumerate `events-*.ndjson` newest-first.
41
+ * The pre-existing manual `events-legacy.ndjson` matches and is picked up for
42
+ * free. Kept in sync with the reader-side pattern in web/lib/coord-reader.ts. */
43
+ export const ARCHIVE_PREFIX = "events-";
44
+ export const ARCHIVE_SUFFIX = ".ndjson";
45
+ function resolveRollBytes() {
46
+ const env = coordEnv("EVENTS_ROLL_BYTES");
47
+ const n = env ? Number(env) : Number.NaN;
48
+ return Number.isFinite(n) && n > 0 ? n : DEFAULT_ROLL_BYTES;
49
+ }
50
+ /** `YYYY-MM-DD` (UTC) from a millisecond timestamp. Uses the file's own mtime
51
+ * rather than `Date.now()` so it's deterministic and independent of the harness
52
+ * runtime's clock surface. */
53
+ function utcDateStamp(mtimeMs) {
54
+ const d = new Date(mtimeMs);
55
+ const y = d.getUTCFullYear();
56
+ const mo = String(d.getUTCMonth() + 1).padStart(2, "0");
57
+ const day = String(d.getUTCDate()).padStart(2, "0");
58
+ return `${y}-${mo}-${day}`;
59
+ }
60
+ /** First non-colliding `events-<stamp>[.N].ndjson` path under `coordDir`. */
61
+ function archivePathFor(coordDir, stamp) {
62
+ const base = join(coordDir, `${ARCHIVE_PREFIX}${stamp}${ARCHIVE_SUFFIX}`);
63
+ if (!existsSync(base))
64
+ return base;
65
+ for (let n = 1;; n++) {
66
+ const cand = join(coordDir, `${ARCHIVE_PREFIX}${stamp}.${n}${ARCHIVE_SUFFIX}`);
67
+ if (!existsSync(cand))
68
+ return cand;
69
+ }
70
+ }
71
+ /**
72
+ * Roll `events.ndjson` to a dated archive when it exceeds the byte cap. Cheap
73
+ * no-op (a single `statSync`) below the cap. Fail-soft: any error is swallowed
74
+ * so a rotation problem can never break the append that triggered it.
75
+ *
76
+ * `nowMs` is injectable for the stale-lock check in tests; production leaves it
77
+ * unset (the roll date always comes from the file's mtime, never `nowMs`).
78
+ */
79
+ export function maybeRotateEventStream(coordRoot, nowMs) {
80
+ try {
81
+ const streamPath = join(coordRoot, STREAM_FILE);
82
+ if (!existsSync(streamPath))
83
+ return false;
84
+ const cap = resolveRollBytes();
85
+ let st = statSync(streamPath);
86
+ if (st.size < cap)
87
+ return false;
88
+ const coordDir = dirname(streamPath);
89
+ const lockPath = join(coordRoot, ROLL_LOCK_FILE);
90
+ mkdirSync(coordDir, { recursive: true });
91
+ if (!acquireRollLock(lockPath, nowMs))
92
+ return false; // another roller active
93
+ try {
94
+ // Re-check under the lock: a concurrent process may have just rolled.
95
+ if (!existsSync(streamPath))
96
+ return false;
97
+ st = statSync(streamPath);
98
+ if (st.size < cap)
99
+ return false;
100
+ const archive = archivePathFor(coordDir, utcDateStamp(st.mtimeMs));
101
+ renameSync(streamPath, archive);
102
+ // Recreate an empty active file so the very next append (and any reader's
103
+ // existsSync) sees a valid, present stream.
104
+ closeSync(openSync(streamPath, "a"));
105
+ return true;
106
+ }
107
+ finally {
108
+ try {
109
+ unlinkSync(lockPath);
110
+ }
111
+ catch {
112
+ /* best-effort */
113
+ }
114
+ }
115
+ }
116
+ catch {
117
+ return false; // fail-soft: never break the caller's append
118
+ }
119
+ }
120
+ /** Create the roll-lock with O_EXCL. Returns true on acquisition. On collision,
121
+ * steals a stale lock (crashed roller) once, else returns false. */
122
+ function acquireRollLock(lockPath, nowMs) {
123
+ try {
124
+ closeSync(openSync(lockPath, "wx"));
125
+ return true;
126
+ }
127
+ catch {
128
+ // Exists: steal if abandoned.
129
+ try {
130
+ const age = (nowMs ?? Date.now()) - statSync(lockPath).mtimeMs;
131
+ if (age > STALE_LOCK_MS) {
132
+ unlinkSync(lockPath);
133
+ closeSync(openSync(lockPath, "wx"));
134
+ return true;
135
+ }
136
+ }
137
+ catch {
138
+ /* lost the steal race — someone else holds it */
139
+ }
140
+ return false;
141
+ }
142
+ }
@@ -30,6 +30,12 @@ export interface HarnessSpec {
30
30
  entryShape: HookEntryShape;
31
31
  /** When set, ensure this top-level `version` key in the file (Cursor requires `1`). */
32
32
  rootVersion?: number;
33
+ /** Harness-owned entries from older specs that `init` should remove during migration. */
34
+ legacyEvents?: HookEvent[];
35
+ /** Strict top-level settings keys accepted by this harness, when its parser is closed. */
36
+ allowedTopLevelKeys?: string[];
37
+ /** Strict hook event keys accepted by this harness, including events harnery does not wire. */
38
+ allowedEventKeys?: string[];
33
39
  }
34
40
  /** Claude Code: `.claude/settings.json`. */
35
41
  export declare const CLAUDE_CODE_EVENTS: HookEvent[];
@@ -38,8 +44,12 @@ export declare const CLAUDE_CODE_EVENTS: HookEvent[];
38
44
  * no `StopFailure` event, but a distinct `beforeShellExecution` (shell-mutation warn).
39
45
  */
40
46
  export declare const CURSOR_EVENTS: HookEvent[];
41
- /** Codex: `.codex/hooks.json`. PascalCase keys + the same entry shape as Claude Code. */
47
+ /** Codex events that harnery uses from the current native lifecycle surface. */
42
48
  export declare const CODEX_EVENTS: HookEvent[];
49
+ /** Entries written by harnery before Codex adopted a strict native hook schema. */
50
+ export declare const LEGACY_CODEX_EVENTS: HookEvent[];
51
+ /** Every hook key accepted by Codex 0.144, including events harnery does not consume. */
52
+ export declare const CODEX_ALLOWED_EVENT_KEYS: string[];
43
53
  /** Every supported harness, fully wireable by `harn init`. */
44
54
  export declare const HARNESS_SPECS: Record<HarnessId, HarnessSpec>;
45
55
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../../src/core/hooks/harness/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,SAAS;IACxB,6FAA6F;IAC7F,WAAW,EAAE,MAAM,CAAC;IACpB,s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