@qodeca/xezar 0.13.1 → 0.14.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 (250) hide show
  1. package/README.md +45 -15
  2. package/dist/agent-config/account-identity.d.ts +2 -8
  3. package/dist/agent-config/account-identity.js +54 -10
  4. package/dist/agent-config/account-identity.js.map +1 -1
  5. package/dist/agent-config/catalog.d.ts +49 -7
  6. package/dist/agent-config/catalog.js +107 -0
  7. package/dist/agent-config/catalog.js.map +1 -1
  8. package/dist/agent-config/model-settings/pi.d.ts +12 -6
  9. package/dist/agent-config/model-settings/pi.js +12 -6
  10. package/dist/agent-config/model-settings/pi.js.map +1 -1
  11. package/dist/agent-config/seed.js +10 -0
  12. package/dist/agent-config/seed.js.map +1 -1
  13. package/dist/contract/github.d.ts +15 -0
  14. package/dist/contract/index.d.ts +9 -0
  15. package/dist/contract/index.js +1527 -895
  16. package/dist/contract/mcp-api-reference.d.ts +174 -0
  17. package/dist/contract/mcp-audit.d.ts +103 -0
  18. package/dist/contract/mcp-discovery.d.ts +257 -0
  19. package/dist/contract/mcp-event-catalog.d.ts +121 -0
  20. package/dist/contract/mcp-event-catalog.test.d.ts +1 -0
  21. package/dist/contract/mcp-idempotency.d.ts +200 -0
  22. package/dist/contract/mcp-journal.d.ts +268 -0
  23. package/dist/contract/mcp-leader.d.ts +88 -0
  24. package/dist/contract/mcp-ownership.d.ts +78 -0
  25. package/dist/contract/mcp-versioning.d.ts +139 -0
  26. package/dist/contract/runs.d.ts +81 -0
  27. package/dist/core/agent-profiles.d.ts +15 -4
  28. package/dist/core/agent-profiles.js +22 -8
  29. package/dist/core/agent-profiles.js.map +1 -1
  30. package/dist/core/opencode-server-runner.js +71 -11
  31. package/dist/core/opencode-server-runner.js.map +1 -1
  32. package/dist/core/secret-redaction.d.ts +7 -1
  33. package/dist/core/secret-redaction.js +44 -10
  34. package/dist/core/secret-redaction.js.map +1 -1
  35. package/dist/index.js +138 -27
  36. package/dist/index.js.map +1 -1
  37. package/dist/machine-identity.d.ts +66 -0
  38. package/dist/machine-identity.js +96 -0
  39. package/dist/machine-identity.js.map +1 -0
  40. package/dist/mcp/adapters/claude-code.d.ts +41 -0
  41. package/dist/mcp/adapters/claude-code.js +40 -0
  42. package/dist/mcp/adapters/claude-code.js.map +1 -0
  43. package/dist/mcp/adapters/codex.d.ts +140 -0
  44. package/dist/mcp/adapters/codex.js +323 -0
  45. package/dist/mcp/adapters/codex.js.map +1 -0
  46. package/dist/mcp/adapters/opencode.d.ts +148 -0
  47. package/dist/mcp/adapters/opencode.js +528 -0
  48. package/dist/mcp/adapters/opencode.js.map +1 -0
  49. package/dist/mcp/adapters/pi-link.d.ts +102 -0
  50. package/dist/mcp/adapters/pi-link.js +235 -0
  51. package/dist/mcp/adapters/pi-link.js.map +1 -0
  52. package/dist/mcp/adapters/pi.d.ts +188 -0
  53. package/dist/mcp/adapters/pi.js +418 -0
  54. package/dist/mcp/adapters/pi.js.map +1 -0
  55. package/dist/mcp/api-reference.d.ts +26 -0
  56. package/dist/mcp/api-reference.js +133 -0
  57. package/dist/mcp/api-reference.js.map +1 -0
  58. package/dist/mcp/audit-trail.d.ts +162 -0
  59. package/dist/mcp/audit-trail.js +306 -0
  60. package/dist/mcp/audit-trail.js.map +1 -0
  61. package/dist/mcp/bridge.d.ts +81 -0
  62. package/dist/mcp/bridge.js +407 -0
  63. package/dist/mcp/bridge.js.map +1 -0
  64. package/dist/mcp/connection-file.d.ts +49 -0
  65. package/dist/mcp/connection-file.js +63 -0
  66. package/dist/mcp/connection-file.js.map +1 -0
  67. package/dist/mcp/echo-guard.d.ts +94 -0
  68. package/dist/mcp/echo-guard.js +160 -0
  69. package/dist/mcp/echo-guard.js.map +1 -0
  70. package/dist/mcp/event-catalog.d.ts +120 -0
  71. package/dist/mcp/event-catalog.js +306 -0
  72. package/dist/mcp/event-catalog.js.map +1 -0
  73. package/dist/mcp/event-controller.d.ts +230 -0
  74. package/dist/mcp/event-controller.js +596 -0
  75. package/dist/mcp/event-controller.js.map +1 -0
  76. package/dist/mcp/event-journal.d.ts +57 -0
  77. package/dist/mcp/event-journal.js +423 -0
  78. package/dist/mcp/event-journal.js.map +1 -0
  79. package/dist/mcp/index.d.ts +63 -0
  80. package/dist/mcp/index.js +386 -0
  81. package/dist/mcp/index.js.map +1 -0
  82. package/dist/mcp/ipc.d.ts +202 -0
  83. package/dist/mcp/ipc.js +206 -0
  84. package/dist/mcp/ipc.js.map +1 -0
  85. package/dist/mcp/leader-delivery.d.ts +119 -0
  86. package/dist/mcp/leader-delivery.js +450 -0
  87. package/dist/mcp/leader-delivery.js.map +1 -0
  88. package/dist/mcp/operation-receipts.d.ts +210 -0
  89. package/dist/mcp/operation-receipts.js +723 -0
  90. package/dist/mcp/operation-receipts.js.map +1 -0
  91. package/dist/mcp/project-catalogs.d.ts +23 -0
  92. package/dist/mcp/project-catalogs.js +25 -0
  93. package/dist/mcp/project-catalogs.js.map +1 -0
  94. package/dist/mcp/project-leaders.d.ts +26 -0
  95. package/dist/mcp/project-leaders.js +17 -0
  96. package/dist/mcp/project-leaders.js.map +1 -0
  97. package/dist/mcp/protocol.d.ts +50 -0
  98. package/dist/mcp/protocol.js +47 -0
  99. package/dist/mcp/protocol.js.map +1 -0
  100. package/dist/mcp/reconnect.d.ts +297 -0
  101. package/dist/mcp/reconnect.js +465 -0
  102. package/dist/mcp/reconnect.js.map +1 -0
  103. package/dist/mcp/resource-ownership.d.ts +228 -0
  104. package/dist/mcp/resource-ownership.js +390 -0
  105. package/dist/mcp/resource-ownership.js.map +1 -0
  106. package/dist/mcp/service-adapter.d.ts +16488 -0
  107. package/dist/mcp/service-adapter.js +148 -0
  108. package/dist/mcp/service-adapter.js.map +1 -0
  109. package/dist/mcp/service.d.ts +83 -0
  110. package/dist/mcp/service.js +233 -0
  111. package/dist/mcp/service.js.map +1 -0
  112. package/dist/mcp/session-binding.d.ts +105 -0
  113. package/dist/mcp/session-binding.js +163 -0
  114. package/dist/mcp/session-binding.js.map +1 -0
  115. package/dist/mcp/stale-write.d.ts +145 -0
  116. package/dist/mcp/stale-write.js +219 -0
  117. package/dist/mcp/stale-write.js.map +1 -0
  118. package/dist/mcp/tool.d.ts +48 -0
  119. package/dist/mcp/tool.js +24 -0
  120. package/dist/mcp/tool.js.map +1 -0
  121. package/dist/mcp/tools/discovery.d.ts +40 -0
  122. package/dist/mcp/tools/discovery.js +232 -0
  123. package/dist/mcp/tools/discovery.js.map +1 -0
  124. package/dist/mcp/tools/execution-control.d.ts +171 -0
  125. package/dist/mcp/tools/execution-control.js +513 -0
  126. package/dist/mcp/tools/execution-control.js.map +1 -0
  127. package/dist/mcp/tools/handoff-git.d.ts +26 -0
  128. package/dist/mcp/tools/handoff-git.js +544 -0
  129. package/dist/mcp/tools/handoff-git.js.map +1 -0
  130. package/dist/mcp/tools/index.d.ts +2 -0
  131. package/dist/mcp/tools/index.js +23 -0
  132. package/dist/mcp/tools/index.js.map +1 -0
  133. package/dist/mcp/tools/leader-events.d.ts +46 -0
  134. package/dist/mcp/tools/leader-events.js +126 -0
  135. package/dist/mcp/tools/leader-events.js.map +1 -0
  136. package/dist/mcp/tools/local-handoff.d.ts +102 -0
  137. package/dist/mcp/tools/local-handoff.js +306 -0
  138. package/dist/mcp/tools/local-handoff.js.map +1 -0
  139. package/dist/mcp/tools/project-config.d.ts +340 -0
  140. package/dist/mcp/tools/project-config.js +1075 -0
  141. package/dist/mcp/tools/project-config.js.map +1 -0
  142. package/dist/mcp/tools/results-evidence.d.ts +112 -0
  143. package/dist/mcp/tools/results-evidence.js +1045 -0
  144. package/dist/mcp/tools/results-evidence.js.map +1 -0
  145. package/dist/mcp/tools/task-create.d.ts +70 -0
  146. package/dist/mcp/tools/task-create.js +473 -0
  147. package/dist/mcp/tools/task-create.js.map +1 -0
  148. package/dist/mcp/tools/task-reads.d.ts +102 -0
  149. package/dist/mcp/tools/task-reads.js +689 -0
  150. package/dist/mcp/tools/task-reads.js.map +1 -0
  151. package/dist/mcp/tools/work-organisation.d.ts +2 -0
  152. package/dist/mcp/tools/work-organisation.js +502 -0
  153. package/dist/mcp/tools/work-organisation.js.map +1 -0
  154. package/dist/paths.d.ts +17 -7
  155. package/dist/paths.js +18 -8
  156. package/dist/paths.js.map +1 -1
  157. package/dist/runs/project-writer.js +76 -11
  158. package/dist/runs/project-writer.js.map +1 -1
  159. package/dist/runs/retention.d.ts +24 -1
  160. package/dist/runs/retention.js +62 -1
  161. package/dist/runs/retention.js.map +1 -1
  162. package/dist/server/forge/github.js +44 -0
  163. package/dist/server/forge/github.js.map +1 -1
  164. package/dist/server/forge/types.d.ts +16 -0
  165. package/dist/server/project-context.d.ts +81 -8
  166. package/dist/server/project-context.js +143 -35
  167. package/dist/server/project-context.js.map +1 -1
  168. package/dist/server/server.d.ts +1050 -53
  169. package/dist/server/server.js +326 -120
  170. package/dist/server/server.js.map +1 -1
  171. package/dist/server/validators.d.ts +26 -6
  172. package/dist/server/validators.js +17 -0
  173. package/dist/server/validators.js.map +1 -1
  174. package/dist/skills-remote.js +64 -6
  175. package/dist/skills-remote.js.map +1 -1
  176. package/dist/workflows/run.d.ts +277 -12
  177. package/dist/workflows/run.js +554 -59
  178. package/dist/workflows/run.js.map +1 -1
  179. package/dist/workspace/agent-profiles.d.ts +30 -3
  180. package/dist/workspace/agent-profiles.js +39 -4
  181. package/dist/workspace/agent-profiles.js.map +1 -1
  182. package/dist/workspace/config.js +25 -4
  183. package/dist/workspace/config.js.map +1 -1
  184. package/dist/workspace/project-owner.d.ts +210 -0
  185. package/dist/workspace/project-owner.js +518 -0
  186. package/dist/workspace/project-owner.js.map +1 -0
  187. package/package.json +5 -3
  188. package/scripts/pi-leader-extension.ts +420 -0
  189. package/scripts/sync-readme.mjs +83 -2
  190. package/web/dist/assets/{alert-dialog-BVsVcbFy.js → alert-dialog-D6rP6d39.js} +1 -1
  191. package/web/dist/assets/arrow-down-DMOfFIzW.js +1 -0
  192. package/web/dist/assets/arrow-left-C4Ec2BUg.js +1 -0
  193. package/web/dist/assets/{centered-state-Djgly6Ni.js → centered-state-B0ZqrPaa.js} +12 -12
  194. package/web/dist/assets/chevron-right-mHJ-crvn.js +1 -0
  195. package/web/dist/assets/{collapsible-DZ4D-DHG.js → collapsible-DchEHgUM.js} +1 -1
  196. package/web/dist/assets/{commit-list-B-z1JL9G.js → commit-list-BpMim1Rv.js} +1 -1
  197. package/web/dist/assets/{compare-variants-D62m4j3B.js → compare-variants-D5ItQbAq.js} +1 -1
  198. package/web/dist/assets/{diff-BKew9rQX.js → diff-HqqZ_WDR.js} +2 -2
  199. package/web/dist/assets/{diff-stat-D0mc5V6Z.js → diff-stat-NsU-3ecr.js} +1 -1
  200. package/web/dist/assets/{diff-view-xpIcuLIC.js → diff-view-B7c11Xux.js} +1 -1
  201. package/web/dist/assets/{dropdown-menu-CEQziH7X.js → dropdown-menu-CtTpnyod.js} +1 -1
  202. package/web/dist/assets/{editable-title-BCX3T2BY.js → editable-title-BXtuGQry.js} +1 -1
  203. package/web/dist/assets/{ellipsis-vertical-ByVdDc4z.js → ellipsis-vertical-MHtGZSH6.js} +1 -1
  204. package/web/dist/assets/{file-xBSB5hXO.js → file-DKLw5SOb.js} +1 -1
  205. package/web/dist/assets/{folder-CldgbZ5A.js → folder-Drw6-ufH.js} +1 -1
  206. package/web/dist/assets/{git-toolbar-DJANqg7Y.js → git-toolbar-BQH8bORV.js} +1 -1
  207. package/web/dist/assets/github-ynnpKFCJ.js +1 -0
  208. package/web/dist/assets/{image-preview-Cv5mZr0n.js → image-preview-DLhMN_R9.js} +1 -1
  209. package/web/dist/assets/index-BEsrNdXt.js +29 -0
  210. package/web/dist/assets/index-Da8DOBau.css +2 -0
  211. package/web/dist/assets/{markdown-CgEEE2ND.js → markdown-q365eN6Y.js} +1 -1
  212. package/web/dist/assets/{new-task-form-1r2bgsdD.js → new-task-form-CW-hNIWQ.js} +1 -1
  213. package/web/dist/assets/{pill-q-x22_ej.js → pill-B_TFulXa.js} +1 -1
  214. package/web/dist/assets/{project-router-VDN4jQM8.js → project-router-CLPc-ImZ.js} +1 -1
  215. package/web/dist/assets/{prompt-templates-BmZtCe-L.js → prompt-templates-CLc4RxyO.js} +1 -1
  216. package/web/dist/assets/{repo-git-btG0sdbO.js → repo-git-Is7R6-Tj.js} +1 -1
  217. package/web/dist/assets/{run-diff-vguEMJzh.js → run-diff-DHMvDlVo.js} +2 -2
  218. package/web/dist/assets/run-header-DvZJbQ8I.js +1 -0
  219. package/web/dist/assets/{search-x-QmhaAbg5.js → search-x-Ce2MMetu.js} +1 -1
  220. package/web/dist/assets/{skill-empty-hint-BrzUwByZ.js → skill-empty-hint-C_xCSvzB.js} +1 -1
  221. package/web/dist/assets/skills-CivqD4si.js +1 -0
  222. package/web/dist/assets/{sparkles-CP8QDOgX.js → sparkles-BCqPoj5g.js} +1 -1
  223. package/web/dist/assets/{square-terminal-CGypshSD.js → square-terminal-ikj5g-oK.js} +1 -1
  224. package/web/dist/assets/{tab-link-D4lFzzI1.js → tab-link-VsEjFV1Y.js} +1 -1
  225. package/web/dist/assets/{task-changes-BtZId14z.js → task-changes-CH-E81-_.js} +1 -1
  226. package/web/dist/assets/{task-commits-BoeyJXrv.js → task-commits-DqfkMFxp.js} +1 -1
  227. package/web/dist/assets/{task-files-DIy2oUnj.js → task-files-D_nkHZ_a.js} +2 -2
  228. package/web/dist/assets/task-thread-bxQompxJ.js +9 -0
  229. package/web/dist/assets/{textarea-CyBCyKIk.js → textarea-xajuW1L_.js} +1 -1
  230. package/web/dist/assets/{thread-loading-Cuq2jchC.js → thread-loading-C3JQZbIE.js} +1 -1
  231. package/web/dist/assets/{trash-2-B6Dp3ZNs.js → trash-2-hJrBhpUD.js} +1 -1
  232. package/web/dist/assets/{triangle-alert-xBya8FUp.js → triangle-alert-D1u82y1a.js} +1 -1
  233. package/web/dist/assets/{upload-D6MXEB9p.js → upload-Bn6FBZ59.js} +1 -1
  234. package/web/dist/assets/{use-desktop-CPBwzQ7M.js → use-desktop-DOIMfHfY.js} +1 -1
  235. package/web/dist/assets/{use-submit-shortcut-JTpNzU-u.js → use-submit-shortcut-Dj4DHTdE.js} +1 -1
  236. package/web/dist/assets/utils-YwBpOoRN.js +64 -0
  237. package/web/dist/assets/{workflows-DG115scU.js → workflows-CTaAKz2m.js} +3 -3
  238. package/web/dist/assets/{zoomable-image-GTYwLtkS.js → zoomable-image-C1-6P3tg.js} +1 -1
  239. package/web/dist/index.html +23 -23
  240. package/web/dist/assets/arrow-down-CYgAlZtW.js +0 -1
  241. package/web/dist/assets/arrow-left-BOqE0a3k.js +0 -1
  242. package/web/dist/assets/chevron-right-Cc9BWnbN.js +0 -1
  243. package/web/dist/assets/github-D6vK0jFn.js +0 -1
  244. package/web/dist/assets/index-CkmR6h7s.css +0 -2
  245. package/web/dist/assets/index-DVDqF4bM.js +0 -9
  246. package/web/dist/assets/refresh-cw-DcNCj2nu.js +0 -1
  247. package/web/dist/assets/run-header-DM7MiKj9.js +0 -1
  248. package/web/dist/assets/skills-DMfxQtrD.js +0 -1
  249. package/web/dist/assets/task-thread-CbMPmrWq.js +0 -9
  250. package/web/dist/assets/utils--z9hRtl3.js +0 -64
@@ -0,0 +1,57 @@
1
+ import { type McpJournalAppendInput, type McpJournalCursorRejection, type McpJournalReadInput, type McpJournalReadResult, type McpJournalRow } from '../contract/index.js';
2
+ /** A cursor refused outright — the caller maps `rejection` onto its own error answer (D-01/D-02). */
3
+ export declare class McpJournalCursorError extends Error {
4
+ readonly rejection: McpJournalCursorRejection;
5
+ constructor(error: McpJournalCursorRejection['error'], message: string);
6
+ }
7
+ export interface EventJournalOptions {
8
+ /** The project's data directory (`projectDataDir(root)`). */
9
+ dataDir: string;
10
+ /** The project's registry slug, from the trusted binding — never from a tool argument. */
11
+ projectId: string;
12
+ /** Test seam for retention ages; production uses the wall clock. */
13
+ now?: () => number;
14
+ /** Values scrubbed from every summary (F-15). Defaults to this host's secret-named env values. */
15
+ secretValues?: readonly string[];
16
+ /** Where the one-per-problem warning goes. */
17
+ warn?: (message: string) => void;
18
+ }
19
+ export declare class EventJournal {
20
+ #private;
21
+ readonly projectId: string;
22
+ readonly indexPath: string;
23
+ readonly rowsPath: string;
24
+ private constructor();
25
+ /**
26
+ * Load (or create) a project's journal. Never throws on state — only on a caller bug (an invalid
27
+ * project id, or a second live instance for the same file, which would break gapless numbering).
28
+ */
29
+ static open(opts: EventJournalOptions): EventJournal;
30
+ get epoch(): string;
31
+ get latestSeq(): number;
32
+ get oldestSeq(): number | null;
33
+ /**
34
+ * False while the journal cannot record a row: it could not be created, or its last append failed.
35
+ * An unwritable journal journals nothing, so nothing can be delivered from it either (#309 O-3).
36
+ * The next append that succeeds makes it true again.
37
+ */
38
+ get writable(): boolean;
39
+ /** The cursor at the current head — D-05 § 6.8's "journal position at acceptance". */
40
+ headCursor(): string;
41
+ /** Release this file so a later `open` (a restart, in a test) may take it. */
42
+ close(): void;
43
+ /** Live rows as they are appended — the replay reader's buffer (#105). Returns the unsubscribe. */
44
+ subscribe(listener: (row: McpJournalRow) => void): () => void;
45
+ /**
46
+ * Append one significant event. Returns the stored row, or `undefined` when it could not be made
47
+ * durable — in which case no number was spent, so the sequence stays gapless (D-05 § 6.1).
48
+ * Throws only on invalid input, which is an emitter bug.
49
+ */
50
+ append(input: McpJournalAppendInput): McpJournalRow | undefined;
51
+ /**
52
+ * Replay strictly after `cursor` (or from the oldest retained row without one), in `journalSeq`
53
+ * order, at most B-02 rows and B-01 bytes. A cursor whose rows are gone gets `cursor_too_old`
54
+ * and no rows; a malformed or foreign cursor throws `McpJournalCursorError`.
55
+ */
56
+ read(input?: McpJournalReadInput): McpJournalReadResult;
57
+ }
@@ -0,0 +1,423 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, truncateSync, writeFileSync, } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { z } from 'zod';
5
+ import { MCP_JOURNAL_CURSOR_MAX_BYTES, MCP_JOURNAL_MIN_RETENTION_DAYS, MCP_JOURNAL_PAGE_BYTES, MCP_JOURNAL_PAGE_ROWS, MCP_JOURNAL_RETAINED_ROWS, mcpJournalAppendInputSchema, mcpJournalProjectIdSchema, mcpJournalRowSchema, } from '../contract/index.js';
6
+ import { collectSecretValues, redactSecrets } from '../core/secret-redaction.js';
7
+ /**
8
+ * The per-project MCP event journal (#103): an append-only record of the significant events
9
+ * (E-01–E-06) a project leader may see, with a replay cursor. Decided by D-05 § 6 and bounded by
10
+ * D-09 § 3 — see `packages/contract/src/mcp-journal.ts` for every shape and number.
11
+ *
12
+ * WHAT THIS IS NOT. `RunStore` already keeps one NDJSON transcript per run, and
13
+ * `GET /api/v1/runs/:id/events` replays one run from it with a cursor, deduping on the run's `seq`.
14
+ * That `seq` is per RUN and may skip numbers (`emitEphemeral` allocates frames that never reach
15
+ * disk). The workspace streams replay nothing at all. This journal is a separate file with its own
16
+ * order: `journalSeq` is per PROJECT and gapless — only a durably appended row gets a number — so a
17
+ * reader holding 1..N knows nothing between them is missing. Do not "fix" it into consistency with
18
+ * the run `seq` next door; the difference is the point (D-05 § 6.1).
19
+ *
20
+ * Files, both under `<dataDir>/mcp/` (so inside `.local/`, covered by its blanket ignore rule):
21
+ * - `event-journal.json` — `{ v, projectId, epoch, createdAt }`, zod-validated, written by
22
+ * atomic tmp+rename, and only when a journal is created or recreated.
23
+ * - `event-journal.ndjson` — one row per line, appended. Rewritten (tmp+rename) only to drop rows
24
+ * retention has already evicted; surviving lines are copied byte-for-byte, numbers unchanged.
25
+ *
26
+ * Zero config: written, never required. Missing files start a fresh journal; a corrupt one starts
27
+ * fresh with ONE warning and the bad file kept beside it as `.corrupt`; an unwritable directory
28
+ * drops rows (with one warning) and never throws into the caller. A fresh journal gets a new
29
+ * `epoch`, so every cursor from the old one is answered `cursor_too_old` — never mis-resolved
30
+ * against numbers that restarted at 1.
31
+ *
32
+ * One writer per project: this process holds at most one open journal per file (enforced below),
33
+ * and the project's writer claim (#185) keeps a second xezar process off the same data directory.
34
+ */
35
+ const DAY_MS = 24 * 60 * 60 * 1_000;
36
+ const MIN_RETENTION_MS = MCP_JOURNAL_MIN_RETENTION_DAYS * DAY_MS;
37
+ const indexSchema = z.looseObject({
38
+ v: z.literal(1),
39
+ projectId: mcpJournalProjectIdSchema,
40
+ epoch: z.string().min(1).max(64),
41
+ createdAt: z.string(),
42
+ });
43
+ const cursorSchema = z.object({
44
+ v: z.literal(1),
45
+ p: z.string(),
46
+ e: z.string(),
47
+ s: z.number().int().nonnegative(),
48
+ });
49
+ /** A cursor refused outright — the caller maps `rejection` onto its own error answer (D-01/D-02). */
50
+ export class McpJournalCursorError extends Error {
51
+ rejection;
52
+ constructor(error, message) {
53
+ super(message);
54
+ this.name = 'McpJournalCursorError';
55
+ this.rejection = { error, message };
56
+ }
57
+ }
58
+ const openFiles = new Set();
59
+ export class EventJournal {
60
+ projectId;
61
+ indexPath;
62
+ rowsPath;
63
+ #epoch = '';
64
+ /** Retained rows, oldest first, consecutive `journalSeq`. */
65
+ #rows = [];
66
+ /** The stored line of each retained row, kept verbatim so a compaction never re-serializes. */
67
+ #lines = [];
68
+ #latestSeq = 0;
69
+ /** Evicted lines still physically at the head of the file. */
70
+ #evictedOnDisk = 0;
71
+ #fileBytes = 0;
72
+ #writeWarned = false;
73
+ #writable = true;
74
+ #closed = false;
75
+ #listeners = new Set();
76
+ #now;
77
+ #secretValues;
78
+ #warn;
79
+ constructor(opts) {
80
+ this.projectId = mcpJournalProjectIdSchema.parse(opts.projectId);
81
+ const dir = join(opts.dataDir, 'mcp');
82
+ this.indexPath = join(dir, 'event-journal.json');
83
+ this.rowsPath = join(dir, 'event-journal.ndjson');
84
+ this.#now = opts.now ?? Date.now;
85
+ this.#secretValues = opts.secretValues ?? collectSecretValues();
86
+ this.#warn = opts.warn ?? ((message) => console.warn(message));
87
+ }
88
+ /**
89
+ * Load (or create) a project's journal. Never throws on state — only on a caller bug (an invalid
90
+ * project id, or a second live instance for the same file, which would break gapless numbering).
91
+ */
92
+ static open(opts) {
93
+ const journal = new EventJournal(opts);
94
+ if (openFiles.has(journal.rowsPath)) {
95
+ throw new Error(`an event journal is already open for ${journal.rowsPath} — keep one per project`);
96
+ }
97
+ openFiles.add(journal.rowsPath);
98
+ journal.#load();
99
+ return journal;
100
+ }
101
+ get epoch() {
102
+ return this.#epoch;
103
+ }
104
+ get latestSeq() {
105
+ return this.#latestSeq;
106
+ }
107
+ get oldestSeq() {
108
+ return this.#rows[0]?.journalSeq ?? null;
109
+ }
110
+ /**
111
+ * False while the journal cannot record a row: it could not be created, or its last append failed.
112
+ * An unwritable journal journals nothing, so nothing can be delivered from it either (#309 O-3).
113
+ * The next append that succeeds makes it true again.
114
+ */
115
+ get writable() {
116
+ return this.#writable;
117
+ }
118
+ /** The cursor at the current head — D-05 § 6.8's "journal position at acceptance". */
119
+ headCursor() {
120
+ return this.#cursorAt(this.#latestSeq);
121
+ }
122
+ /** Release this file so a later `open` (a restart, in a test) may take it. */
123
+ close() {
124
+ if (this.#closed)
125
+ return;
126
+ this.#closed = true;
127
+ this.#listeners.clear();
128
+ openFiles.delete(this.rowsPath);
129
+ }
130
+ /** Live rows as they are appended — the replay reader's buffer (#105). Returns the unsubscribe. */
131
+ subscribe(listener) {
132
+ this.#listeners.add(listener);
133
+ return () => this.#listeners.delete(listener);
134
+ }
135
+ /**
136
+ * Append one significant event. Returns the stored row, or `undefined` when it could not be made
137
+ * durable — in which case no number was spent, so the sequence stays gapless (D-05 § 6.1).
138
+ * Throws only on invalid input, which is an emitter bug.
139
+ */
140
+ append(input) {
141
+ if (this.#closed)
142
+ throw new Error('event journal is closed');
143
+ const parsed = mcpJournalAppendInputSchema.parse(input);
144
+ const journalSeq = this.#latestSeq + 1;
145
+ const row = mcpJournalRowSchema.parse({
146
+ eventId: `${this.projectId}:${journalSeq}`,
147
+ journalSeq,
148
+ ts: new Date(this.#now()).toISOString(),
149
+ projectId: this.projectId,
150
+ category: parsed.category,
151
+ kind: parsed.kind,
152
+ subject: parsed.subject,
153
+ origin: parsed.origin,
154
+ causedBy: parsed.causedBy,
155
+ // F-15: a summary is prose an emitter composed, so it is scrubbed like transcript text is.
156
+ summary: redactSecrets(parsed.summary, this.#secretValues),
157
+ ...(parsed.source === undefined ? {} : { source: parsed.source }),
158
+ });
159
+ const line = JSON.stringify(row);
160
+ try {
161
+ appendFileSync(this.rowsPath, `${line}\n`, 'utf8');
162
+ }
163
+ catch (err) {
164
+ // A partial write must not survive as a torn line in the middle of the file.
165
+ try {
166
+ truncateSync(this.rowsPath, this.#fileBytes);
167
+ }
168
+ catch { /* the load path drops a torn tail */ }
169
+ this.#writable = false;
170
+ this.#warnWrite(err);
171
+ return undefined;
172
+ }
173
+ this.#fileBytes += Buffer.byteLength(line, 'utf8') + 1;
174
+ this.#writable = true;
175
+ this.#latestSeq = journalSeq;
176
+ const frozen = freezeRow(row);
177
+ this.#rows.push(frozen);
178
+ this.#lines.push(line);
179
+ this.#applyRetention();
180
+ for (const listener of this.#listeners) {
181
+ try {
182
+ listener(frozen);
183
+ }
184
+ catch { /* a reader's bug never undoes a durable append */ }
185
+ }
186
+ return frozen;
187
+ }
188
+ /**
189
+ * Replay strictly after `cursor` (or from the oldest retained row without one), in `journalSeq`
190
+ * order, at most B-02 rows and B-01 bytes. A cursor whose rows are gone gets `cursor_too_old`
191
+ * and no rows; a malformed or foreign cursor throws `McpJournalCursorError`.
192
+ */
193
+ read(input = {}) {
194
+ const limit = Math.min(input.limit ?? MCP_JOURNAL_PAGE_ROWS, MCP_JOURNAL_PAGE_ROWS);
195
+ const oldest = this.oldestSeq;
196
+ const firstRetained = oldest ?? this.#latestSeq + 1;
197
+ let after = firstRetained - 1;
198
+ if (input.cursor !== undefined) {
199
+ const cursor = decodeCursor(input.cursor);
200
+ // Foreign BEFORE stale: another project's cursor is refused, never told what this one holds.
201
+ if (cursor.p !== this.projectId) {
202
+ throw new McpJournalCursorError('cursor_project_mismatch', 'this cursor belongs to another project');
203
+ }
204
+ if (cursor.e !== this.#epoch || cursor.s < firstRetained - 1)
205
+ return this.#tooOld(firstRetained);
206
+ if (cursor.s > this.#latestSeq) {
207
+ throw new McpJournalCursorError('invalid_cursor', 'this cursor points past the end of the journal');
208
+ }
209
+ after = cursor.s;
210
+ }
211
+ const events = [];
212
+ let bytes = 0;
213
+ for (let i = oldest === null ? this.#rows.length : after + 1 - oldest; i < this.#rows.length; i++) {
214
+ if (events.length >= limit)
215
+ break;
216
+ const size = Buffer.byteLength(JSON.stringify(this.#rows[i]), 'utf8');
217
+ if (events.length > 0 && bytes + size > MCP_JOURNAL_PAGE_BYTES)
218
+ break;
219
+ events.push(this.#rows[i]);
220
+ bytes += size;
221
+ }
222
+ const last = events.at(-1)?.journalSeq ?? after;
223
+ return {
224
+ status: 'ok',
225
+ events,
226
+ nextCursor: this.#cursorAt(last),
227
+ hasMore: last < this.#latestSeq,
228
+ oldestSeq: oldest,
229
+ latestSeq: this.#latestSeq,
230
+ };
231
+ }
232
+ #tooOld(firstRetained) {
233
+ return {
234
+ status: 'cursor_too_old',
235
+ oldestSeq: this.oldestSeq,
236
+ latestSeq: this.#latestSeq,
237
+ resumeCursor: this.#cursorAt(firstRetained - 1),
238
+ recovery: {
239
+ required: 'current-state',
240
+ message: 'Events after this cursor are no longer retained. Read the current state first, then continue from resumeCursor.',
241
+ },
242
+ };
243
+ }
244
+ #cursorAt(seq) {
245
+ return Buffer.from(JSON.stringify({ v: 1, p: this.projectId, e: this.#epoch, s: seq }), 'utf8').toString('base64url');
246
+ }
247
+ /** B-19: evict from the head only while more than the retained count remain AND the head row is
248
+ * at least the minimum age. The retained set therefore stays one contiguous run of numbers. */
249
+ #applyRetention() {
250
+ const cutoff = this.#now() - MIN_RETENTION_MS;
251
+ let drop = 0;
252
+ while (this.#rows.length - drop > MCP_JOURNAL_RETAINED_ROWS && Date.parse(this.#rows[drop].ts) <= cutoff)
253
+ drop++;
254
+ if (drop === 0)
255
+ return;
256
+ this.#rows.splice(0, drop);
257
+ this.#lines.splice(0, drop);
258
+ this.#evictedOnDisk += drop;
259
+ // The file may hold at most B-19's count again in evicted lines before it is rewritten — so it
260
+ // never exceeds twice the retained size, and a steady stream does not rewrite it per append.
261
+ if (this.#evictedOnDisk >= MCP_JOURNAL_RETAINED_ROWS)
262
+ this.#compact();
263
+ }
264
+ #compact() {
265
+ const tmp = `${this.rowsPath}.tmp`;
266
+ const body = this.#lines.length === 0 ? '' : `${this.#lines.join('\n')}\n`;
267
+ try {
268
+ writeFileSync(tmp, body, 'utf8');
269
+ renameSync(tmp, this.rowsPath);
270
+ this.#fileBytes = Buffer.byteLength(body, 'utf8');
271
+ this.#evictedOnDisk = 0;
272
+ }
273
+ catch (err) {
274
+ // Eviction is already in effect in memory, and a reload re-derives it; only disk space waits.
275
+ this.#warnWrite(err);
276
+ }
277
+ }
278
+ #load() {
279
+ const outcome = this.#readFiles();
280
+ if (outcome.kind === 'fresh') {
281
+ if (outcome.warning !== undefined)
282
+ this.#warn(outcome.warning);
283
+ this.#startFresh();
284
+ return;
285
+ }
286
+ this.#epoch = outcome.epoch;
287
+ this.#rows = outcome.rows.map(freezeRow);
288
+ this.#lines = outcome.lines;
289
+ this.#latestSeq = outcome.rows.at(-1)?.journalSeq ?? 0;
290
+ this.#fileBytes = outcome.fileBytes;
291
+ this.#applyRetention();
292
+ if (this.#evictedOnDisk > 0)
293
+ this.#compact();
294
+ }
295
+ #readFiles() {
296
+ const hasIndex = existsSync(this.indexPath);
297
+ const hasRows = existsSync(this.rowsPath);
298
+ if (!hasIndex && !hasRows)
299
+ return { kind: 'fresh' };
300
+ const corrupt = (reason) => {
301
+ this.#setAside();
302
+ return {
303
+ kind: 'fresh',
304
+ warning: `[xez] MCP event journal for project ${this.projectId} is corrupt (${reason}) — starting a fresh journal; the old rows are kept as ${this.rowsPath}.corrupt`,
305
+ };
306
+ };
307
+ // Deleting the rows file alone is deleting history: a new epoch, not an error.
308
+ if (!hasRows)
309
+ return { kind: 'fresh' };
310
+ try {
311
+ const raw = readFileSync(this.rowsPath);
312
+ if (!hasIndex)
313
+ return raw.length === 0 ? { kind: 'fresh' } : corrupt('index file missing');
314
+ let index;
315
+ try {
316
+ const parsed = indexSchema.safeParse(JSON.parse(readFileSync(this.indexPath, 'utf8')));
317
+ if (!parsed.success)
318
+ return corrupt('index file invalid');
319
+ index = parsed.data;
320
+ }
321
+ catch {
322
+ return corrupt('index file unreadable');
323
+ }
324
+ if (index.projectId !== this.projectId)
325
+ return corrupt('index names another project');
326
+ // A torn final line is an append that never returned, so no caller ever held its number.
327
+ let body = raw;
328
+ const lastNewline = raw.lastIndexOf(0x0a);
329
+ if (lastNewline !== raw.length - 1) {
330
+ body = raw.subarray(0, lastNewline + 1);
331
+ try {
332
+ truncateSync(this.rowsPath, body.length);
333
+ }
334
+ catch { /* read-only: appends fail anyway */ }
335
+ }
336
+ const rows = [];
337
+ const lines = [];
338
+ for (const line of body.toString('utf8').split('\n')) {
339
+ if (line.trim() === '')
340
+ continue;
341
+ let value;
342
+ try {
343
+ value = JSON.parse(line);
344
+ }
345
+ catch {
346
+ return corrupt(`unparseable row after seq ${rows.at(-1)?.journalSeq ?? 0}`);
347
+ }
348
+ const parsed = mcpJournalRowSchema.safeParse(value);
349
+ if (!parsed.success)
350
+ return corrupt(`invalid row after seq ${rows.at(-1)?.journalSeq ?? 0}`);
351
+ const row = parsed.data;
352
+ const expected = rows.length === 0 ? row.journalSeq : rows.at(-1).journalSeq + 1;
353
+ if (row.journalSeq !== expected)
354
+ return corrupt(`sequence breaks at seq ${expected}`);
355
+ if (row.projectId !== this.projectId || row.eventId !== `${this.projectId}:${row.journalSeq}`) {
356
+ return corrupt(`row ${row.journalSeq} names another project`);
357
+ }
358
+ rows.push(row);
359
+ lines.push(line);
360
+ }
361
+ return { kind: 'loaded', epoch: index.epoch, rows, lines, fileBytes: body.length };
362
+ }
363
+ catch (err) {
364
+ return corrupt(err instanceof Error ? err.message : String(err));
365
+ }
366
+ }
367
+ #setAside() {
368
+ try {
369
+ if (existsSync(this.rowsPath))
370
+ renameSync(this.rowsPath, `${this.rowsPath}.corrupt`);
371
+ }
372
+ catch { /* the fresh journal overwrites it instead */ }
373
+ }
374
+ #startFresh() {
375
+ this.#epoch = randomUUID();
376
+ this.#rows = [];
377
+ this.#lines = [];
378
+ this.#latestSeq = 0;
379
+ this.#fileBytes = 0;
380
+ this.#evictedOnDisk = 0;
381
+ const tmp = `${this.indexPath}.tmp`;
382
+ try {
383
+ mkdirSync(join(this.rowsPath, '..'), { recursive: true, mode: 0o700 });
384
+ writeFileSync(this.rowsPath, '', 'utf8');
385
+ writeFileSync(tmp, `${JSON.stringify({ v: 1, projectId: this.projectId, epoch: this.#epoch, createdAt: new Date(this.#now()).toISOString() })}\n`, 'utf8');
386
+ renameSync(tmp, this.indexPath);
387
+ }
388
+ catch (err) {
389
+ this.#writable = false;
390
+ this.#warnWrite(err);
391
+ }
392
+ }
393
+ #warnWrite(err) {
394
+ if (this.#writeWarned)
395
+ return;
396
+ this.#writeWarned = true;
397
+ const message = err instanceof Error ? err.message : String(err);
398
+ this.#warn(`[xez] MCP event journal for project ${this.projectId} cannot be written (${message}) — events are not being journaled`);
399
+ }
400
+ }
401
+ function decodeCursor(cursor) {
402
+ const invalid = () => new McpJournalCursorError('invalid_cursor', 'invalid journal cursor');
403
+ if (cursor.length === 0 || cursor.length > MCP_JOURNAL_CURSOR_MAX_BYTES)
404
+ throw invalid();
405
+ let value;
406
+ try {
407
+ value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
408
+ }
409
+ catch {
410
+ throw invalid();
411
+ }
412
+ const parsed = cursorSchema.safeParse(value);
413
+ if (!parsed.success)
414
+ throw invalid();
415
+ return parsed.data;
416
+ }
417
+ function freezeRow(row) {
418
+ Object.freeze(row.subject);
419
+ if (row.source)
420
+ Object.freeze(row.source);
421
+ return Object.freeze(row);
422
+ }
423
+ //# sourceMappingURL=event-journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-journal.js","sourceRoot":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AM,CAAC,MAAM,GAAG,4BAA4B;QAAE,MAAM,OAAO,EAAE,CAAC;IACzF,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,OAAO,EAAE,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,OAAO,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED,SAAS,SAAS,CAAC,GAAkB;IACnC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,IAAI,GAAG,CAAC,MAAM;QAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { type ProviderStatus } from '../contract/index.js';
2
+ import type { RunStore } from '../runs/store.ts';
3
+ import { ProjectOwnership } from '../workspace/project-owner.ts';
4
+ import { type ServiceTarget } from './bridge.ts';
5
+ import { type WorkspaceEventSource } from './event-catalog.ts';
6
+ import type { ServiceDispatch } from './service-adapter.ts';
7
+ import { type McpServiceHandle } from './service.ts';
8
+ /**
9
+ * The MCP module's public surface (#86, D-01). `packages/xezar/src/index.ts` imports
10
+ * it LAZILY from both sides, so an ordinary `serve` that never meets an MCP client
11
+ * pays nothing for it and cannot be broken by it (N-07).
12
+ */
13
+ export { runBridge, HEALTH_TOOL, type BridgeOptions, type ServiceTarget } from './bridge.ts';
14
+ export { listenMcpSocket, type McpDoor, type McpServiceHandle, type McpServiceOptions } from './service.ts';
15
+ export { mcpSocketLocation, IPC_PROTOCOL_VERSION } from './ipc.ts';
16
+ export { SUPPORTED_PROTOCOL_VERSIONS, SERVER_CAPABILITIES, negotiateProtocolVersion } from './protocol.ts';
17
+ export { defineTool, textResult, errorResult, type McpTool, type McpToolContext, type McpToolResult } from './tool.ts';
18
+ export interface StartMcpServiceOptions {
19
+ readonly projectId: string;
20
+ readonly version: string;
21
+ /** The running app's in-process entry: every tool dispatches into the cockpit's own routes (N-02). */
22
+ readonly service?: ServiceDispatch;
23
+ /** The project's own store — the one the cockpit writes. The catalog listens to it, and
24
+ * receipts reconcile a run against it. */
25
+ readonly store?: RunStore;
26
+ /** The host-wide workspace bus: the catalog's E-06 source (`provider-status`). */
27
+ readonly workspaceEvents?: WorkspaceEventSource;
28
+ /** Provider rows as they are now — the catalog's E-06 baseline. A failure means "no baseline". */
29
+ readonly providerBaseline?: () => Promise<readonly ProviderStatus[]>;
30
+ /** Test seams, as for `listenMcpSocket`. Production uses the process's own. */
31
+ readonly ownership?: ProjectOwnership;
32
+ readonly env?: NodeJS.ProcessEnv;
33
+ readonly platform?: NodeJS.Platform;
34
+ readonly warn?: (message: string) => void;
35
+ /** Test seam: the event controller's heartbeat (#309). Production uses its 30 s. */
36
+ readonly leader?: {
37
+ readonly heartbeatMs?: number;
38
+ };
39
+ }
40
+ /**
41
+ * Service side: compose the MCP service for a registered project and open its socket (#243).
42
+ * Throws a one-line error when the socket cannot open; the cockpit turns that into one warning
43
+ * and keeps booting (N-07). Everything composed here is released by the handle's `close()`, and
44
+ * by the throw itself when the socket fails — nothing outlives either.
45
+ *
46
+ * The composition lives HERE, once, because the stdio bridge (`runMcpCommand`) executes nothing:
47
+ * it forwards every call to this socket, so both doors get exactly this behaviour.
48
+ */
49
+ export declare function startMcpService(opts: StartMcpServiceOptions): Promise<McpServiceHandle>;
50
+ /**
51
+ * `xez mcp` — spawned by an MCP client with the session's project as its working
52
+ * directory (D-01 § 4). Serves MCP on stdio until the client closes stdin.
53
+ */
54
+ export declare function runMcpCommand(opts: {
55
+ repoRoot: string;
56
+ version: string;
57
+ }): Promise<void>;
58
+ /**
59
+ * The cwd only FINDS the socket; it never becomes the authority (D-01 § 4). A read of
60
+ * the registry: the bridge registers nothing, so a directory xezar has never served
61
+ * finds no project and answers with how to fix that.
62
+ */
63
+ export declare function resolveMcpTarget(repoRoot: string): Promise<ServiceTarget>;