@tpsdev-ai/agent 0.7.0 → 0.9.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 (134) hide show
  1. package/bun.lock +27 -15
  2. package/bunfig.toml +17 -0
  3. package/dist/bin.js +4 -3
  4. package/dist/bin.js.map +1 -1
  5. package/dist/config.d.ts +8 -1
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +38 -3
  8. package/dist/config.js.map +1 -1
  9. package/dist/home.d.ts +3 -0
  10. package/dist/home.d.ts.map +1 -0
  11. package/dist/home.js +18 -0
  12. package/dist/home.js.map +1 -0
  13. package/dist/index.d.ts +16 -3
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +12 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/io/flair.d.ts +1 -10
  18. package/dist/io/flair.d.ts.map +1 -1
  19. package/dist/io/flair.js +29 -28
  20. package/dist/io/flair.js.map +1 -1
  21. package/dist/io/mail.d.ts +184 -30
  22. package/dist/io/mail.d.ts.map +1 -1
  23. package/dist/io/mail.js +944 -185
  24. package/dist/io/mail.js.map +1 -1
  25. package/dist/lib/agent-keys.d.ts +106 -0
  26. package/dist/lib/agent-keys.d.ts.map +1 -0
  27. package/dist/lib/agent-keys.js +298 -0
  28. package/dist/lib/agent-keys.js.map +1 -0
  29. package/dist/lib/bridge-identity.d.ts +10 -0
  30. package/dist/lib/bridge-identity.d.ts.map +1 -0
  31. package/dist/lib/bridge-identity.js +56 -0
  32. package/dist/lib/bridge-identity.js.map +1 -0
  33. package/dist/lib/mail-lock-namespace.d.ts +19 -0
  34. package/dist/lib/mail-lock-namespace.d.ts.map +1 -0
  35. package/dist/lib/mail-lock-namespace.js +58 -0
  36. package/dist/lib/mail-lock-namespace.js.map +1 -0
  37. package/dist/lib/mail-lock.d.ts +81 -0
  38. package/dist/lib/mail-lock.d.ts.map +1 -0
  39. package/dist/lib/mail-lock.js +319 -0
  40. package/dist/lib/mail-lock.js.map +1 -0
  41. package/dist/lib/mailbox-filename.d.ts +2 -0
  42. package/dist/lib/mailbox-filename.d.ts.map +1 -0
  43. package/dist/lib/mailbox-filename.js +4 -0
  44. package/dist/lib/mailbox-filename.js.map +1 -0
  45. package/dist/lib/mailbox-policy.d.ts +245 -0
  46. package/dist/lib/mailbox-policy.d.ts.map +1 -0
  47. package/dist/lib/mailbox-policy.js +949 -0
  48. package/dist/lib/mailbox-policy.js.map +1 -0
  49. package/dist/lib/public-key.d.ts +6 -0
  50. package/dist/lib/public-key.d.ts.map +1 -0
  51. package/dist/lib/public-key.js +45 -0
  52. package/dist/lib/public-key.js.map +1 -0
  53. package/dist/lib/registry-key.d.ts +2 -0
  54. package/dist/lib/registry-key.d.ts.map +1 -0
  55. package/dist/lib/registry-key.js +10 -0
  56. package/dist/lib/registry-key.js.map +1 -0
  57. package/dist/lib/relay-lock.d.ts +7 -0
  58. package/dist/lib/relay-lock.d.ts.map +1 -0
  59. package/dist/lib/relay-lock.js +19 -0
  60. package/dist/lib/relay-lock.js.map +1 -0
  61. package/dist/lib/signEnvelope.d.ts +12 -0
  62. package/dist/lib/signEnvelope.d.ts.map +1 -1
  63. package/dist/lib/signEnvelope.js.map +1 -1
  64. package/dist/lib/signing-key.d.ts +2 -0
  65. package/dist/lib/signing-key.d.ts.map +1 -0
  66. package/dist/lib/signing-key.js +9 -0
  67. package/dist/lib/signing-key.js.map +1 -0
  68. package/dist/lib/topic-recipient.d.ts +2 -0
  69. package/dist/lib/topic-recipient.d.ts.map +1 -0
  70. package/dist/lib/topic-recipient.js +2 -0
  71. package/dist/lib/topic-recipient.js.map +1 -0
  72. package/dist/llm/provider.d.ts.map +1 -1
  73. package/dist/llm/provider.js +9 -7
  74. package/dist/llm/provider.js.map +1 -1
  75. package/dist/runtime/agent.d.ts.map +1 -1
  76. package/dist/runtime/agent.js +32 -25
  77. package/dist/runtime/agent.js.map +1 -1
  78. package/dist/runtime/event-loop.d.ts +21 -2
  79. package/dist/runtime/event-loop.d.ts.map +1 -1
  80. package/dist/runtime/event-loop.js +199 -54
  81. package/dist/runtime/event-loop.js.map +1 -1
  82. package/dist/runtime/types.d.ts +11 -0
  83. package/dist/runtime/types.d.ts.map +1 -1
  84. package/dist/runtime/types.js +13 -1
  85. package/dist/runtime/types.js.map +1 -1
  86. package/package.json +3 -4
  87. package/src/bin.ts +4 -3
  88. package/src/config.ts +46 -3
  89. package/src/home.ts +18 -0
  90. package/src/index.ts +33 -2
  91. package/src/io/flair.ts +23 -28
  92. package/src/io/mail.ts +1007 -200
  93. package/src/lib/agent-keys.ts +308 -0
  94. package/src/lib/bridge-identity.ts +49 -0
  95. package/src/lib/mail-lock-namespace.ts +64 -0
  96. package/src/lib/mail-lock.ts +337 -0
  97. package/src/lib/mailbox-filename.ts +3 -0
  98. package/src/lib/mailbox-policy.ts +1085 -0
  99. package/src/lib/public-key.ts +49 -0
  100. package/src/lib/registry-key.ts +8 -0
  101. package/src/lib/relay-lock.ts +20 -0
  102. package/src/lib/signEnvelope.ts +12 -0
  103. package/src/lib/signing-key.ts +8 -0
  104. package/src/lib/topic-recipient.ts +1 -0
  105. package/src/llm/provider.ts +9 -7
  106. package/src/runtime/agent.ts +30 -27
  107. package/src/runtime/event-loop.ts +221 -68
  108. package/src/runtime/types.ts +14 -0
  109. package/test/config.test.ts +85 -2
  110. package/test/core-loop.test.ts +6 -4
  111. package/test/governance.test.ts +4 -1
  112. package/test/helpers/event-loop-child.mjs +50 -0
  113. package/test/helpers/mail-delivery-worker.mjs +16 -0
  114. package/test/helpers/mail-kill-child.mjs +104 -0
  115. package/test/helpers/signed-relay-record.ts +31 -0
  116. package/test/home-per-call.test.ts +72 -0
  117. package/test/io.test.ts +81 -14
  118. package/test/mail-client-lock-namespace.test.ts +155 -0
  119. package/test/mail-client-repoint-root.test.ts +368 -0
  120. package/test/mail-delivery-at-least-once.test.ts +1238 -0
  121. package/test/mail-event-loop-delivery.test.ts +769 -0
  122. package/test/mail-intent-phases.test.ts +304 -0
  123. package/test/mail-interrupted-recovery.test.ts +393 -0
  124. package/test/mail-lock-pid-state.test.ts +238 -0
  125. package/test/mail-lock.test.ts +96 -0
  126. package/test/mail-partial-flair.test.ts +102 -0
  127. package/test/mail-placement-replay.test.ts +116 -0
  128. package/test/mail-promote-guard.test.ts +305 -21
  129. package/test/mail-relay-reservation.test.ts +60 -0
  130. package/test/mailbox-filename.test.ts +16 -0
  131. package/test/public-key.test.ts +108 -0
  132. package/test/runtime-key-encoding.test.ts +105 -0
  133. package/test/runtime-pending-key.test.ts +117 -0
  134. package/test/security/mail-trust.test.ts +406 -109
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail-lock-namespace.d.ts","sourceRoot":"","sources":["../../src/lib/mail-lock-namespace.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,6EAA6E;AAC7E,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEzF;AAED,sFAAsF;AACtF,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAGrG;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGhE"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * mail-lock-namespace.ts — the derivation of the relay lock roots that CLI relay
3
+ * acceptance and the agent MailClient coordinate on (cli#616).
4
+ *
5
+ * CLI relay acceptance takes its acceptance stripe from the process mail root
6
+ * (`TPS_MAIL_DIR`); its recipient mailbox locks come from the selected mailbox
7
+ * and scan roots, which can be branch-office mailboxes outside that root.
8
+ * MailClient derives its stripe and mailbox paths from one resolved mail-root
9
+ * string per operation, also resolving the mailbox directory beneath it.
10
+ *
11
+ * The relay stripe is a cooperative lock among MailClients that resolve the
12
+ * same canonical path. The OS follows same-user filesystem changes to that
13
+ * path during an operation; the stripe does not exclude them.
14
+ *
15
+ * Mailbox lock roots come from here only for acceptance and
16
+ * MailClient: acceptance uses canonicalMailboxRoot; MailClient derives its
17
+ * promotion and recovery lock paths from the canonical mailbox string resolved
18
+ * once per operation (cli#636). The CLI's other mailbox lock sites use the
19
+ * mailbox root path as given.
20
+ */
21
+ import { createHash } from "node:crypto";
22
+ import { mkdirSync, realpathSync } from "node:fs";
23
+ import { homedir } from "node:os";
24
+ import { join } from "node:path";
25
+ export const RELAY_ACCEPT_LOCK_STRIPES = 64;
26
+ /** The process mail root, unresolved: `TPS_MAIL_DIR`, else `~/.tps/mail`. */
27
+ export function configuredMailRoot() {
28
+ return process.env.TPS_MAIL_DIR || join(process.env.HOME || homedir(), ".tps", "mail");
29
+ }
30
+ /**
31
+ * The canonical mail root for lock derivation: the resolved real path of
32
+ * `mailRoot`, with symlinks and `.`/`..` segments resolved. A root that does not
33
+ * exist yet is created first, then resolved, so a store made here resolves the
34
+ * same way for a later process that reaches it by another path.
35
+ */
36
+ export function canonicalMailRoot(mailRoot) {
37
+ mkdirSync(mailRoot, { recursive: true, mode: 0o700 });
38
+ return realpathSync(mailRoot);
39
+ }
40
+ /** The acceptance-stripe lock root for one relayed delivery, under `mailRoot`. */
41
+ export function acceptanceLockRoot(mailRoot, branchId, id) {
42
+ return acceptanceLockRootFromSnapshot(canonicalMailRoot(mailRoot), branchId, id);
43
+ }
44
+ /** Derive a stripe path from a canonical mail-root string without resolving again. */
45
+ export function acceptanceLockRootFromSnapshot(mailRoot, branchId, id) {
46
+ const stripe = createHash("sha256").update(branchId).update("\0").update(id).digest()[0] % RELAY_ACCEPT_LOCK_STRIPES;
47
+ return join(mailRoot, ".relay-accept-locks", String(stripe));
48
+ }
49
+ /** The mailbox lock root for `agentId`, under `mailRoot`. */
50
+ export function mailboxLockRoot(mailRoot, agentId) {
51
+ return join(canonicalMailRoot(mailRoot), agentId);
52
+ }
53
+ /** The resolved real path of a mailbox directory, created first if absent. */
54
+ export function canonicalMailboxRoot(mailboxRoot) {
55
+ mkdirSync(mailboxRoot, { recursive: true, mode: 0o700 });
56
+ return realpathSync(mailboxRoot);
57
+ }
58
+ //# sourceMappingURL=mail-lock-namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail-lock-namespace.js","sourceRoot":"","sources":["../../src/lib/mail-lock-namespace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,6EAA6E;AAC7E,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAU;IAC/E,OAAO,8BAA8B,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AACnF,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,8BAA8B,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAU;IAC3F,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAE,GAAG,yBAAyB,CAAC;IACtH,OAAO,IAAI,CAAC,QAAQ,EAAE,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,OAAe;IAC/D,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAAC,WAAmB;IACtD,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,OAAO,YAAY,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * mail-lock.ts — a small inter-process lock for maildir mutation.
3
+ *
4
+ * Moved from the CLI for use by both first-delivery paths.
5
+ *
6
+ * Why it exists: the replay ledger is read-modify-written (prune) and appended,
7
+ * and the promotion moves files; without mutual exclusion, two concurrent
8
+ * promotions can both pass the replay gate before either records the id, and an
9
+ * append can land between a prune's read and its rename and be lost. The lock
10
+ * must span the whole replay-check → promotion-commit/rollback critical section,
11
+ * including the ledger prune and append.
12
+ *
13
+ * Properties:
14
+ * - normal acquisition publishes a populated lock directory by rename;
15
+ * - ownership uses pid and process start time when readable; a live pid with
16
+ * an unverifiable token is retained;
17
+ * - acquisition and stale reclamation share an atomic claim;
18
+ * - a stranded claim requires operator recovery;
19
+ * - release checks the acquisition nonce;
20
+ * - nested (re)acquisition in one process fails loudly rather than deadlocking;
21
+ * - an unreadable owner, or one whose pid is not an integer in 1..2147483647,
22
+ * can cause a contention timeout returning null; other filesystem errors may throw.
23
+ *
24
+ * The critical section a holder runs must be SYNCHRONOUS (no await while held):
25
+ * the in-process reentrancy guard tracks a plain set, and an await inside the
26
+ * critical section would let a second concurrent acquisition see the set
27
+ * populated and mistake concurrency for nesting.
28
+ */
29
+ export declare const MAIL_LOCK_DIR = ".mail-lock";
30
+ export interface MailLock {
31
+ /** Release the lock. Ownership-checked; safe to call once. */
32
+ release(): void;
33
+ }
34
+ /** The lock directory for a mailbox root. */
35
+ export declare function mailLockPath(root: string): string;
36
+ /**
37
+ * A stable per-process identity token — its kernel birth time — or null only
38
+ * when it cannot be read at all.
39
+ *
40
+ * Two sources, so it is portable: `/proc/<pid>/stat` (Linux; field 22 is
41
+ * starttime), and `ps -o lstart= -p <pid>` (Darwin and Linux). Without the
42
+ * fallback the token is always null on Darwin, and owner identity degrades to
43
+ * pid alone — exactly the pid-reuse confusion this token exists to prevent.
44
+ */
45
+ export declare function processStartToken(pid: number): string | null;
46
+ export type PidState = "alive" | "gone" | "invalid";
47
+ /** The classifier's integer-and-positive precheck: an integer of at least 1.
48
+ * pidState can still classify a larger integer as invalid after process.kill
49
+ * rejects it as an argument (PID_ARGUMENT_ERRORS). */
50
+ export declare function isValidPid(pid: number): boolean;
51
+ /**
52
+ * Probe a recorded pid with `process.kill(pid, 0)`. "invalid": not an integer
53
+ * of at least 1 (0 and negative pids do not name one process), or a pid
54
+ * process.kill rejects as an argument. "gone": ESRCH, or on Linux a pid whose
55
+ * `/proc/<pid>/stat` state is `Z` (exited but not reaped). "alive": the probe
56
+ * succeeds or fails with any other error, EPERM (permission denied) included;
57
+ * an unreadable stat file keeps "alive".
58
+ */
59
+ export declare function pidState(pid: number, readStat?: (pid: number) => string[] | null): PidState;
60
+ /** How pidState classifies an error thrown by `process.kill(pid, 0)`. */
61
+ export declare function pidStateFromProbeError(error: unknown): PidState;
62
+ /**
63
+ * cli#617 slice (b): is the process named by (pid, start token) provably gone?
64
+ * The same rule a lock owner is reclaimed by: the pid is gone, or it is alive
65
+ * with a different start token from the same source. A live pid whose identity
66
+ * cannot be checked is NOT gone.
67
+ */
68
+ export declare function processIsGone(pid: number, startToken: string | null): boolean;
69
+ /**
70
+ * Acquire the mailbox lock, polling until `timeoutMs`. Returns null on timeout
71
+ * (caller must not proceed). Throws on nested acquisition for the same root.
72
+ */
73
+ export declare function acquireMailLock(root: string, opts?: {
74
+ timeoutMs?: number;
75
+ pollMs?: number;
76
+ }): Promise<MailLock | null>;
77
+ export declare function acquireMailLockSync(root: string, opts?: {
78
+ timeoutMs?: number;
79
+ pollMs?: number;
80
+ }): MailLock | null;
81
+ //# sourceMappingURL=mail-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail-lock.d.ts","sourceRoot":"","sources":["../../src/lib/mail-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,eAAO,MAAM,aAAa,eAAe,CAAC;AAM1C,MAAM,WAAW,QAAQ;IACvB,8DAA8D;IAC9D,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAmB5D;AAKD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAEpD;;uDAEuD;AACvD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,GAAG,IAAyB,GAAG,QAAQ,CAS/G;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAK/D;AAmDD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAE7E;AA2BD;;;GAGG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACjD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAO1B;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACjD,QAAQ,GAAG,IAAI,CAQjB"}
@@ -0,0 +1,319 @@
1
+ /**
2
+ * mail-lock.ts — a small inter-process lock for maildir mutation.
3
+ *
4
+ * Moved from the CLI for use by both first-delivery paths.
5
+ *
6
+ * Why it exists: the replay ledger is read-modify-written (prune) and appended,
7
+ * and the promotion moves files; without mutual exclusion, two concurrent
8
+ * promotions can both pass the replay gate before either records the id, and an
9
+ * append can land between a prune's read and its rename and be lost. The lock
10
+ * must span the whole replay-check → promotion-commit/rollback critical section,
11
+ * including the ledger prune and append.
12
+ *
13
+ * Properties:
14
+ * - normal acquisition publishes a populated lock directory by rename;
15
+ * - ownership uses pid and process start time when readable; a live pid with
16
+ * an unverifiable token is retained;
17
+ * - acquisition and stale reclamation share an atomic claim;
18
+ * - a stranded claim requires operator recovery;
19
+ * - release checks the acquisition nonce;
20
+ * - nested (re)acquisition in one process fails loudly rather than deadlocking;
21
+ * - an unreadable owner, or one whose pid is not an integer in 1..2147483647,
22
+ * can cause a contention timeout returning null; other filesystem errors may throw.
23
+ *
24
+ * The critical section a holder runs must be SYNCHRONOUS (no await while held):
25
+ * the in-process reentrancy guard tracks a plain set, and an await inside the
26
+ * critical section would let a second concurrent acquisition see the set
27
+ * populated and mistake concurrency for nesting.
28
+ */
29
+ import { lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
30
+ import { execFileSync } from "node:child_process";
31
+ import { randomBytes } from "node:crypto";
32
+ import { join } from "node:path";
33
+ export const MAIL_LOCK_DIR = ".mail-lock";
34
+ const OWNER_FILE = "owner.json";
35
+ const TEMP_PREFIX = `${MAIL_LOCK_DIR}.tmp.`;
36
+ // Best-effort cleanup of old build-temps; age does not prove inactivity.
37
+ const TEMP_MAX_AGE_MS = 10 * 60 * 1000;
38
+ /** The lock directory for a mailbox root. */
39
+ export function mailLockPath(root) {
40
+ return join(root, MAIL_LOCK_DIR);
41
+ }
42
+ /** Roots currently held by THIS process (reentrancy guard). */
43
+ const heldByThisProcess = new Set();
44
+ /**
45
+ * Fields of `/proc/<pid>/stat` after the `comm` field (2), or null when the
46
+ * file is unreadable or contains no ')'; a truncated line yields fewer fields,
47
+ * which callers treat as absent. `comm` may contain spaces and parentheses,
48
+ * so the fields are split after the LAST ')'. fields[0] is field 3 (state);
49
+ * starttime is field 22 → fields[19].
50
+ */
51
+ function readProcStatFields(pid) {
52
+ try {
53
+ const stat = readFileSync(`/proc/${pid}/stat`, "utf-8");
54
+ const rparen = stat.lastIndexOf(")");
55
+ if (rparen === -1)
56
+ return null;
57
+ return stat.slice(rparen + 2).split(" ");
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /**
64
+ * A stable per-process identity token — its kernel birth time — or null only
65
+ * when it cannot be read at all.
66
+ *
67
+ * Two sources, so it is portable: `/proc/<pid>/stat` (Linux; field 22 is
68
+ * starttime), and `ps -o lstart= -p <pid>` (Darwin and Linux). Without the
69
+ * fallback the token is always null on Darwin, and owner identity degrades to
70
+ * pid alone — exactly the pid-reuse confusion this token exists to prevent.
71
+ */
72
+ export function processStartToken(pid) {
73
+ const fields = readProcStatFields(pid);
74
+ if (fields) {
75
+ const token = fields[19];
76
+ if (token)
77
+ return `proc:${token}`;
78
+ }
79
+ // Portable fallback — `lstart` is a stable per-process birth time string.
80
+ try {
81
+ const out = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
82
+ encoding: "utf-8",
83
+ timeout: 2000,
84
+ stdio: ["ignore", "pipe", "ignore"],
85
+ });
86
+ const token = out.trim();
87
+ if (token)
88
+ return `ps:${token}`;
89
+ }
90
+ catch {
91
+ /* unreadable */
92
+ }
93
+ return null;
94
+ }
95
+ /** Error codes taken as process.kill rejecting its argument; Bun and Node raise ERR_INVALID_ARG_TYPE for a pid above 2147483647. */
96
+ const PID_ARGUMENT_ERRORS = new Set(["ERR_INVALID_ARG_TYPE", "ERR_OUT_OF_RANGE", "EINVAL", "ERANGE"]);
97
+ /** The classifier's integer-and-positive precheck: an integer of at least 1.
98
+ * pidState can still classify a larger integer as invalid after process.kill
99
+ * rejects it as an argument (PID_ARGUMENT_ERRORS). */
100
+ export function isValidPid(pid) {
101
+ return Number.isInteger(pid) && pid >= 1;
102
+ }
103
+ /**
104
+ * Probe a recorded pid with `process.kill(pid, 0)`. "invalid": not an integer
105
+ * of at least 1 (0 and negative pids do not name one process), or a pid
106
+ * process.kill rejects as an argument. "gone": ESRCH, or on Linux a pid whose
107
+ * `/proc/<pid>/stat` state is `Z` (exited but not reaped). "alive": the probe
108
+ * succeeds or fails with any other error, EPERM (permission denied) included;
109
+ * an unreadable stat file keeps "alive".
110
+ */
111
+ export function pidState(pid, readStat = readProcStatFields) {
112
+ if (!isValidPid(pid))
113
+ return "invalid";
114
+ try {
115
+ process.kill(pid, 0);
116
+ if (process.platform === "linux" && readStat(pid)?.[0] === "Z")
117
+ return "gone";
118
+ return "alive";
119
+ }
120
+ catch (error) {
121
+ return pidStateFromProbeError(error);
122
+ }
123
+ }
124
+ /** How pidState classifies an error thrown by `process.kill(pid, 0)`. */
125
+ export function pidStateFromProbeError(error) {
126
+ const code = typeof error === "object" && error !== null ? error.code : undefined;
127
+ if (code === "ESRCH")
128
+ return "gone";
129
+ if (typeof code === "string" && PID_ARGUMENT_ERRORS.has(code))
130
+ return "invalid";
131
+ return "alive";
132
+ }
133
+ /** The source component of a birth token (`proc:` / `ps:`), or the whole string. */
134
+ function tokenSource(token) {
135
+ const i = token.indexOf(":");
136
+ return i === -1 ? token : token.slice(0, i);
137
+ }
138
+ function readOwner(lockDir) {
139
+ try {
140
+ return JSON.parse(readFileSync(join(lockDir, OWNER_FILE), "utf-8"));
141
+ }
142
+ catch {
143
+ return null;
144
+ }
145
+ }
146
+ /**
147
+ * Classify a lock's owner.
148
+ *
149
+ * "dead" — pid gone, or pid alive with a DIFFERENT token FROM THE SAME SOURCE.
150
+ * A token from a different source (`proc:` vs `ps:`) for the same live process
151
+ * is "unverifiable", NOT dead — treating it as dead would break a live owner's
152
+ * lock (two owners), the race this lock exists to prevent. Everything
153
+ * unverifiable is neither broken on age nor mistaken for dead.
154
+ */
155
+ function ownerState(owner, resolveToken = processStartToken) {
156
+ if (!owner || typeof owner.pid !== "number")
157
+ return "unverifiable";
158
+ // An invalid pid is handled as an unreadable owner record is.
159
+ const pid = pidState(owner.pid);
160
+ if (pid === "invalid")
161
+ return "unverifiable";
162
+ if (pid === "gone")
163
+ return "dead";
164
+ const token = resolveToken(owner.pid);
165
+ if (token !== null && typeof owner.startToken === "string") {
166
+ if (tokenSource(token) !== tokenSource(owner.startToken))
167
+ return "unverifiable";
168
+ return token === owner.startToken ? "alive" : "dead";
169
+ }
170
+ // pid is alive and we cannot disprove it — never break.
171
+ return "unverifiable";
172
+ }
173
+ /**
174
+ * cli#617 slice (b): is the process named by (pid, start token) provably gone?
175
+ * The same rule a lock owner is reclaimed by: the pid is gone, or it is alive
176
+ * with a different start token from the same source. A live pid whose identity
177
+ * cannot be checked is NOT gone.
178
+ */
179
+ export function processIsGone(pid, startToken) {
180
+ return ownerState({ pid, startToken }) === "dead";
181
+ }
182
+ async function sleep(ms) {
183
+ await new Promise((r) => setTimeout(r, ms));
184
+ }
185
+ /** Attempt to reap old lock build-temps. */
186
+ function reapStrandedLockTemps(root) {
187
+ let names;
188
+ try {
189
+ names = readdirSync(root);
190
+ }
191
+ catch {
192
+ return;
193
+ }
194
+ const cutoff = Date.now() - TEMP_MAX_AGE_MS;
195
+ for (const name of names) {
196
+ if (!name.startsWith(TEMP_PREFIX))
197
+ continue;
198
+ const p = join(root, name);
199
+ try {
200
+ if (statSync(p).mtimeMs > cutoff)
201
+ continue; // may be an in-flight build
202
+ rmSync(p, { recursive: true, force: true });
203
+ }
204
+ catch {
205
+ /* best effort */
206
+ }
207
+ }
208
+ }
209
+ /**
210
+ * Acquire the mailbox lock, polling until `timeoutMs`. Returns null on timeout
211
+ * (caller must not proceed). Throws on nested acquisition for the same root.
212
+ */
213
+ export async function acquireMailLock(root, opts = {}) {
214
+ const attempt = mailLockAttempts(root, opts);
215
+ for (;;) {
216
+ const step = attempt.next();
217
+ if (step.done)
218
+ return step.value;
219
+ await sleep(step.value);
220
+ }
221
+ }
222
+ export function acquireMailLockSync(root, opts = {}) {
223
+ const attempt = mailLockAttempts(root, opts);
224
+ const wait = new Int32Array(new SharedArrayBuffer(4));
225
+ for (;;) {
226
+ const step = attempt.next();
227
+ if (step.done)
228
+ return step.value;
229
+ Atomics.wait(wait, 0, 0, step.value);
230
+ }
231
+ }
232
+ function* mailLockAttempts(root, opts) {
233
+ // `pollMs` overrides the default retry interval of 2 ms.
234
+ const { timeoutMs = 2000, pollMs = 2 } = opts;
235
+ const lockDir = mailLockPath(root);
236
+ if (heldByThisProcess.has(lockDir)) {
237
+ throw new Error(`mail lock already held by this process for ${root} (nested acquisition)`);
238
+ }
239
+ mkdirSync(root, { recursive: true });
240
+ reapStrandedLockTemps(root);
241
+ const deadline = Date.now() + timeoutMs;
242
+ const myToken = processStartToken(process.pid);
243
+ const nonce = randomBytes(16).toString("hex");
244
+ const claimDir = join(root, `${MAIL_LOCK_DIR}.claim`);
245
+ const makeLock = () => {
246
+ let released = false;
247
+ return {
248
+ release: () => {
249
+ if (released)
250
+ return;
251
+ released = true;
252
+ releaseMailLock(lockDir, nonce);
253
+ },
254
+ };
255
+ };
256
+ for (;;) {
257
+ let claimed = false;
258
+ try {
259
+ try {
260
+ mkdirSync(claimDir);
261
+ claimed = true;
262
+ }
263
+ catch (err) {
264
+ if (err?.code !== "EEXIST")
265
+ throw err;
266
+ }
267
+ if (claimed) {
268
+ if (heldByThisProcess.has(lockDir))
269
+ throw new Error(`mail lock already held by this process for ${root}`);
270
+ let lockExists = true;
271
+ try {
272
+ lstatSync(lockDir);
273
+ }
274
+ catch (err) {
275
+ if (err?.code !== "ENOENT")
276
+ throw err;
277
+ lockExists = false;
278
+ }
279
+ if (lockExists && ownerState(readOwner(lockDir)) === "dead") {
280
+ rmSync(lockDir, { recursive: true });
281
+ lockExists = false;
282
+ }
283
+ if (!lockExists) {
284
+ const tmpDir = join(root, `${TEMP_PREFIX}${process.pid}.${nonce}`);
285
+ try {
286
+ mkdirSync(tmpDir);
287
+ writeFileSync(join(tmpDir, OWNER_FILE), JSON.stringify({ pid: process.pid, startToken: myToken, nonce }), "utf-8");
288
+ renameSync(tmpDir, lockDir);
289
+ heldByThisProcess.add(lockDir);
290
+ return makeLock();
291
+ }
292
+ finally {
293
+ rmSync(tmpDir, { recursive: true, force: true });
294
+ }
295
+ }
296
+ }
297
+ }
298
+ finally {
299
+ if (claimed)
300
+ rmSync(claimDir, { recursive: true });
301
+ }
302
+ if (Date.now() >= deadline)
303
+ return null;
304
+ yield pollMs;
305
+ }
306
+ }
307
+ function releaseMailLock(lockDir, nonce) {
308
+ heldByThisProcess.delete(lockDir);
309
+ const owner = readOwner(lockDir);
310
+ if (owner && owner.pid === process.pid && owner.nonce === nonce) {
311
+ try {
312
+ rmSync(lockDir, { recursive: true, force: true });
313
+ }
314
+ catch {
315
+ /* best effort */
316
+ }
317
+ }
318
+ }
319
+ //# sourceMappingURL=mail-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail-lock.js","sourceRoot":"","sources":["../../src/lib/mail-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACvH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAC1C,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,WAAW,GAAG,GAAG,aAAa,OAAO,CAAC;AAC5C,yEAAyE;AACzE,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAOvC,6CAA6C;AAC7C,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACnC,CAAC;AAED,+DAA+D;AAC/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE5C;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,YAAY,CAAC,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,CAAC,CAAC;YAAE,OAAO,I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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailbox-filename.d.ts","sourceRoot":"","sources":["../../src/lib/mailbox-filename.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D"}
@@ -0,0 +1,4 @@
1
+ export function isMailboxMessageFile(name) {
2
+ return !name.startsWith(".") && name.endsWith(".json") && !name.includes("/") && !name.includes("\\");
3
+ }
4
+ //# sourceMappingURL=mailbox-filename.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailbox-filename.js","sourceRoot":"","sources":["../../src/lib/mailbox-filename.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACxG,CAAC"}