approval-md 0.4.0 → 0.4.2

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 (190) hide show
  1. package/SPEC.md +11 -0
  2. package/cli.js +72 -4
  3. package/dist/src/channels/contract.d.ts +53 -0
  4. package/dist/src/channels/contract.js +56 -0
  5. package/dist/src/channels/contract.js.map +1 -1
  6. package/dist/src/channels/tagging.d.ts +25 -0
  7. package/dist/src/channels/tagging.js +57 -5
  8. package/dist/src/channels/tagging.js.map +1 -1
  9. package/dist/src/channels/telegram-minimal.d.ts +251 -0
  10. package/dist/src/channels/telegram-minimal.js +618 -0
  11. package/dist/src/channels/telegram-minimal.js.map +1 -0
  12. package/dist/src/channels/telegram.d.ts +454 -19
  13. package/dist/src/channels/telegram.js +931 -80
  14. package/dist/src/channels/telegram.js.map +1 -1
  15. package/dist/src/cli/amend.js +8 -1
  16. package/dist/src/cli/amend.js.map +1 -1
  17. package/dist/src/cli/attest.js +2 -1
  18. package/dist/src/cli/attest.js.map +1 -1
  19. package/dist/src/cli/audit-card.d.ts +1 -1
  20. package/dist/src/cli/audit-card.js +40 -1
  21. package/dist/src/cli/audit-card.js.map +1 -1
  22. package/dist/src/cli/audit.d.ts +7 -5
  23. package/dist/src/cli/audit.js +25 -12
  24. package/dist/src/cli/audit.js.map +1 -1
  25. package/dist/src/cli/channel-telegram-webhook.d.ts +2 -0
  26. package/dist/src/cli/channel-telegram-webhook.js +7 -0
  27. package/dist/src/cli/channel-telegram-webhook.js.map +1 -1
  28. package/dist/src/cli/channel-telegram.d.ts +75 -2
  29. package/dist/src/cli/channel-telegram.js +172 -16
  30. package/dist/src/cli/channel-telegram.js.map +1 -1
  31. package/dist/src/cli/channel-web.js +2 -1
  32. package/dist/src/cli/channel-web.js.map +1 -1
  33. package/dist/src/cli/channel.js +2 -1
  34. package/dist/src/cli/channel.js.map +1 -1
  35. package/dist/src/cli/doctor.js +1 -1
  36. package/dist/src/cli/doctor.js.map +1 -1
  37. package/dist/src/cli/execute.d.ts +12 -0
  38. package/dist/src/cli/execute.js +50 -4
  39. package/dist/src/cli/execute.js.map +1 -1
  40. package/dist/src/cli/gate.js +2 -1
  41. package/dist/src/cli/gate.js.map +1 -1
  42. package/dist/src/cli/help.d.ts +1 -0
  43. package/dist/src/cli/help.js +39 -18
  44. package/dist/src/cli/help.js.map +1 -1
  45. package/dist/src/cli/hook.d.ts +121 -3
  46. package/dist/src/cli/hook.js +719 -79
  47. package/dist/src/cli/hook.js.map +1 -1
  48. package/dist/src/cli/log-checkpoint.js +2 -1
  49. package/dist/src/cli/log-checkpoint.js.map +1 -1
  50. package/dist/src/cli/log-unlock.d.ts +23 -0
  51. package/dist/src/cli/log-unlock.js +110 -0
  52. package/dist/src/cli/log-unlock.js.map +1 -0
  53. package/dist/src/cli/main.js +23 -6
  54. package/dist/src/cli/main.js.map +1 -1
  55. package/dist/src/cli/setup-common.js +2 -1
  56. package/dist/src/cli/setup-common.js.map +1 -1
  57. package/dist/src/cli/up.js +5 -0
  58. package/dist/src/cli/up.js.map +1 -1
  59. package/dist/src/cli/vault.js +2 -1
  60. package/dist/src/cli/vault.js.map +1 -1
  61. package/dist/src/cli/verb-registry.js +1 -0
  62. package/dist/src/cli/verb-registry.js.map +1 -1
  63. package/dist/src/cli/wordmark.d.ts +2 -2
  64. package/dist/src/cli/wordmark.js +2 -2
  65. package/dist/src/core/attest-bootstrap.js +2 -1
  66. package/dist/src/core/attest-bootstrap.js.map +1 -1
  67. package/dist/src/core/attest.js +5 -4
  68. package/dist/src/core/attest.js.map +1 -1
  69. package/dist/src/core/audit.d.ts +113 -9
  70. package/dist/src/core/audit.js +382 -18
  71. package/dist/src/core/audit.js.map +1 -1
  72. package/dist/src/core/budgets.d.ts +12 -0
  73. package/dist/src/core/budgets.js +54 -1
  74. package/dist/src/core/budgets.js.map +1 -1
  75. package/dist/src/core/checkpoint.js +3 -2
  76. package/dist/src/core/checkpoint.js.map +1 -1
  77. package/dist/src/core/command-class.js +6 -0
  78. package/dist/src/core/command-class.js.map +1 -1
  79. package/dist/src/core/decision-refusal.js +2 -1
  80. package/dist/src/core/decision-refusal.js.map +1 -1
  81. package/dist/src/core/delegation.d.ts +109 -0
  82. package/dist/src/core/delegation.js +244 -0
  83. package/dist/src/core/delegation.js.map +1 -0
  84. package/dist/src/core/execute.js +12 -3
  85. package/dist/src/core/execute.js.map +1 -1
  86. package/dist/src/core/gate-window.js +4 -3
  87. package/dist/src/core/gate-window.js.map +1 -1
  88. package/dist/src/core/gate.d.ts +84 -43
  89. package/dist/src/core/gate.js +114 -6
  90. package/dist/src/core/gate.js.map +1 -1
  91. package/dist/src/core/gesture-refusal.js +2 -1
  92. package/dist/src/core/gesture-refusal.js.map +1 -1
  93. package/dist/src/core/identity.d.ts +105 -0
  94. package/dist/src/core/identity.js +122 -0
  95. package/dist/src/core/identity.js.map +1 -0
  96. package/dist/src/core/log-lock.d.ts +435 -0
  97. package/dist/src/core/log-lock.js +1093 -0
  98. package/dist/src/core/log-lock.js.map +1 -0
  99. package/dist/src/core/log.d.ts +82 -3
  100. package/dist/src/core/log.js +285 -40
  101. package/dist/src/core/log.js.map +1 -1
  102. package/dist/src/core/loop.d.ts +11 -0
  103. package/dist/src/core/loop.js +63 -4
  104. package/dist/src/core/loop.js.map +1 -1
  105. package/dist/src/core/policy-diff.js +20 -1
  106. package/dist/src/core/policy-diff.js.map +1 -1
  107. package/dist/src/core/policy-explain.js +18 -2
  108. package/dist/src/core/policy-explain.js.map +1 -1
  109. package/dist/src/core/policy-load.d.ts +38 -1
  110. package/dist/src/core/policy-load.js +34 -2
  111. package/dist/src/core/policy-load.js.map +1 -1
  112. package/dist/src/core/policy-match.js +30 -5
  113. package/dist/src/core/policy-match.js.map +1 -1
  114. package/dist/src/core/policy-proposal.d.ts +17 -0
  115. package/dist/src/core/policy-proposal.js +32 -16
  116. package/dist/src/core/policy-proposal.js.map +1 -1
  117. package/dist/src/core/prompt-layout.d.ts +186 -1
  118. package/dist/src/core/prompt-layout.js +345 -3
  119. package/dist/src/core/prompt-layout.js.map +1 -1
  120. package/dist/src/core/sender-identity.d.ts +24 -1
  121. package/dist/src/core/sender-identity.js +31 -0
  122. package/dist/src/core/sender-identity.js.map +1 -1
  123. package/dist/src/core/token.js +11 -0
  124. package/dist/src/core/token.js.map +1 -1
  125. package/dist/src/core/tool-map.d.ts +125 -0
  126. package/dist/src/core/tool-map.js +179 -0
  127. package/dist/src/core/tool-map.js.map +1 -0
  128. package/dist/src/core/validate.d.ts +20 -6
  129. package/dist/src/core/validate.js +0 -0
  130. package/dist/src/core/validate.js.map +1 -1
  131. package/dist/src/daemon/git-evidence.d.ts +2 -2
  132. package/dist/src/daemon/git-evidence.js +1 -1
  133. package/dist/src/serve/archive.d.ts +8 -0
  134. package/dist/src/serve/archive.js +11 -2
  135. package/dist/src/serve/archive.js.map +1 -1
  136. package/docs/README-extended.md +15 -0
  137. package/docs/cli-reference.md +571 -28
  138. package/package.json +2 -2
  139. package/schema/event.schema.json +387 -29
  140. package/schema/fixtures/event/invalid/audit-lock-reclaimed-age-without-created.json +19 -0
  141. package/schema/fixtures/event/invalid/audit-lock-reclaimed-agent-actor.json +14 -0
  142. package/schema/fixtures/event/invalid/audit-lock-reclaimed-lockfile-path.json +14 -0
  143. package/schema/fixtures/event/invalid/audit-lock-reclaimed-operator-cleared-system-actor.json +14 -0
  144. package/schema/fixtures/event/invalid/audit-lock-reclaimed-unknown-reason.json +14 -0
  145. package/schema/fixtures/event/invalid/audit-lock-reclaimed-without-age.json +13 -0
  146. package/schema/fixtures/event/invalid/audit-reviewed-agent-actor.json +6 -1
  147. package/schema/fixtures/event/invalid/audit-reviewed-bad-payload-hash.json +21 -0
  148. package/schema/fixtures/event/invalid/audit-reviewed-loved-no-note.json +5 -0
  149. package/schema/fixtures/event/invalid/audit-reviewed-model-actor.json +20 -0
  150. package/schema/fixtures/event/invalid/audit-reviewed-no-subject-hash.json +19 -0
  151. package/schema/fixtures/event/invalid/audit-reviewed-no-subject-seq.json +19 -0
  152. package/schema/fixtures/event/invalid/audit-reviewed-no-verdict-source.json +19 -0
  153. package/schema/fixtures/event/invalid/audit-reviewed-no-verdict.json +19 -0
  154. package/schema/fixtures/event/invalid/audit-reviewed-system-actor.json +6 -1
  155. package/schema/fixtures/event/invalid/audit-reviewed-verdict-source-model.json +20 -0
  156. package/schema/fixtures/event/invalid/audit-sampled-no-policy-hash.json +14 -0
  157. package/schema/fixtures/event/invalid/execution-started-harness-tool-space.json +18 -0
  158. package/schema/fixtures/event/valid/audit-lock-reclaimed-implausible-created.json +18 -0
  159. package/schema/fixtures/event/valid/audit-lock-reclaimed-legacy.json +14 -0
  160. package/schema/fixtures/event/valid/audit-lock-reclaimed-unlock.json +19 -0
  161. package/schema/fixtures/event/valid/audit-lock-reclaimed.json +19 -0
  162. package/schema/fixtures/event/valid/audit-reviewed-reaction.json +5 -0
  163. package/schema/fixtures/event/valid/audit-reviewed.json +6 -1
  164. package/schema/fixtures/event/valid/audit-sampled.json +2 -1
  165. package/schema/fixtures/event/valid/daemon-identity.json +2 -1
  166. package/schema/fixtures/event/valid/execution-started-harness-tool.json +19 -0
  167. package/schema/fixtures/policy/invalid/delegation-advice-string.json +15 -0
  168. package/schema/fixtures/policy/invalid/delegation-class-duplicate.json +18 -0
  169. package/schema/fixtures/policy/invalid/delegation-class-wildcard.json +17 -0
  170. package/schema/fixtures/policy/invalid/delegation-daily-cap-fractional.json +15 -0
  171. package/schema/fixtures/policy/invalid/delegation-daily-cap-negative.json +15 -0
  172. package/schema/fixtures/policy/invalid/delegation-daily-cap-too-high.json +15 -0
  173. package/schema/fixtures/policy/invalid/delegation-escalate-duplicate.json +18 -0
  174. package/schema/fixtures/policy/invalid/delegation-escalate-unknown.json +17 -0
  175. package/schema/fixtures/policy/invalid/delegation-max-autonomy-alias.json +15 -0
  176. package/schema/fixtures/policy/invalid/delegation-max-autonomy-autonomous.json +15 -0
  177. package/schema/fixtures/policy/invalid/delegation-model-no-version.json +15 -0
  178. package/schema/fixtures/policy/invalid/delegation-model-provider-form.json +15 -0
  179. package/schema/fixtures/policy/invalid/delegation-null.json +7 -0
  180. package/schema/fixtures/policy/invalid/delegation-reviewer-agent.json +17 -0
  181. package/schema/fixtures/policy/invalid/delegation-reviewer-bare-id.json +17 -0
  182. package/schema/fixtures/policy/invalid/delegation-unknown-key.json +16 -0
  183. package/schema/fixtures/policy/invalid/tools-class-wildcard.json +9 -0
  184. package/schema/fixtures/policy/invalid/tools-match-double-star.json +9 -0
  185. package/schema/fixtures/policy/invalid/unmapped-tool-unknown.json +7 -0
  186. package/schema/fixtures/policy/valid/delegation-empty.json +7 -0
  187. package/schema/fixtures/policy/valid/delegation-grammar-full.json +41 -0
  188. package/schema/fixtures/policy/valid/delegation-off.json +15 -0
  189. package/schema/fixtures/policy/valid/tools-mapping.json +17 -0
  190. package/schema/policy.schema.json +178 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-lock.js","sourceRoot":"","sources":["../../../src/core/log-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,SAAS,IAAI,WAAW,EACxB,UAAU,EACV,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEpD,yFAAyF;AACzF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;GAIG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AAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO;IAC9B,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAClC,YAAY,CAAC,GAAG,EAAE;YAChB,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -62,12 +62,26 @@
62
62
  * with nothing written. Every earlier record, carrying no such field, validates
63
63
  * and verifies unchanged.
64
64
  *
65
+ * 7. **A lock whose holder is provably gone is taken back, and the log says so
66
+ * (APRV-479).** The lockfile carries its holder's record. A writer that has
67
+ * waited out its whole lock timeout judges the holder once, and only a holder
68
+ * provably gone (a dead pid in this process's own pid namespace and boot, or
69
+ * an empty lockfile ten minutes old) loses the lock: the writer claims it
70
+ * with one exclusive `link(2)`, takes it with one `rename(2)` of its own
71
+ * lockfile over the lock's path, and appends `audit.lock_reclaimed` as the
72
+ * first record under it. A live holder's lock, and any holder this process
73
+ * cannot check, is never taken; the refusal names the human verb
74
+ * `approval log unlock`. `core/log-lock.ts` holds the rules.
75
+ *
65
76
  * Determinism: `ts` is supplied by the caller. This module never reads the
66
77
  * clock, because a hash-relevant field sourced from ambient state would make
67
- * the log irreproducible. `daemon` is ambient in the same sense and is not a
68
- * counter-example: a log is reproducible per WRITER, the field says which writer,
78
+ * the log irreproducible. The one exception is the record this module writes on
79
+ * its own behalf, the `audit.lock_reclaimed` of guarantee 7: no caller authors
80
+ * it, and its `ts` is assigned at the write boundary like any audit record's.
81
+ * `daemon` is ambient in the same sense and is not a counter-example: a log is reproducible per WRITER, the field says which writer,
69
82
  * and a verifier re-derives the hash from the record's own bytes either way.
70
83
  */
84
+ import { type ReclaimNote } from "./log-lock.js";
71
85
  import { type ValidateOptions, type ValidationError } from "./validate.js";
72
86
  /** SPEC.md §8: the hash scheme identifier stamped on every v0.1 record. */
73
87
  export declare const ALG = "sha256/jcs";
@@ -163,6 +177,16 @@ export declare const GENESIS_PREV: null;
163
177
  * same reason, and a closed `source` enum so the next party to do this gains a
164
178
  * member rather than a type. `core/question-preempted.ts` states the rest.
165
179
  *
180
+ * `audit.lock_reclaimed` (APRV-479) is the nineteenth: `<log>.lock` was taken
181
+ * over from a holder that is gone (a writer killed while it held the lock, which
182
+ * nothing else would ever remove), and the record says so as the first record
183
+ * under the lock that was taken. A `system:log` actor is this writer, which
184
+ * proved the holder gone; a `human:` actor is a person's
185
+ * `approval log unlock`, which asserted it. None of the audit records above it
186
+ * fits: no gesture on a request, no question, no sweep, only the log's own
187
+ * lock. Audit tier on the same strict terms (nothing reads it to decide
188
+ * anything), and `core/log-lock.ts` states when a lock counts as gone.
189
+ *
166
190
  * `gate.path.signed_off` (APRV-338) is the sixteenth: a human's sign-off on the
167
191
  * exact bytes of one PROTECTED PATH whose edits classify `policy.edit` or a
168
192
  * `policy.edit.*` sub-class (amended SPEC.md §5.2, §8, §10.1). `human:` actor,
@@ -179,7 +203,7 @@ export declare const GENESIS_PREV: null;
179
203
  * §8 keys the write-boundary clock on that prefix, and a human who could
180
204
  * backdate a sign-off could place it before bytes they never saw.
181
205
  */
182
- export type EventType = "task.registered" | "route.proposed" | "route.accepted" | "approval.requested" | "approval.granted" | "approval.rejected" | "approval.expired" | "approval.revoked" | "approval.withdrawn" | "execution.started" | "execution.completed" | "execution.failed" | "execution.indeterminate" | "execution.reconciled" | "budget.exceeded" | "policy.updated" | "policy.proposed" | "policy.declined" | "envelope.drift" | "audit.sampled" | "audit.reviewed" | "audit.dark_session" | "audit.decision_refused" | "audit.gesture_refused" | "audit.question_preempted" | "reconciliation.required" | "reconciliation.satisfied" | "payload.pruned" | "gate.opened" | "gate.closed" | "gate.bypassed" | "gate.organ.attested" | "gate.path.signed_off" | "log.checkpoint";
206
+ export type EventType = "task.registered" | "route.proposed" | "route.accepted" | "approval.requested" | "approval.granted" | "approval.rejected" | "approval.expired" | "approval.revoked" | "approval.withdrawn" | "execution.started" | "execution.completed" | "execution.failed" | "execution.indeterminate" | "execution.reconciled" | "budget.exceeded" | "policy.updated" | "policy.proposed" | "policy.declined" | "envelope.drift" | "audit.sampled" | "audit.reviewed" | "audit.dark_session" | "audit.decision_refused" | "audit.gesture_refused" | "audit.question_preempted" | "audit.lock_reclaimed" | "reconciliation.required" | "reconciliation.satisfied" | "payload.pruned" | "gate.opened" | "gate.closed" | "gate.bypassed" | "gate.organ.attested" | "gate.path.signed_off" | "log.checkpoint";
183
207
  /**
184
208
  * Caller-supplied content of an event. Chain fields are not accepted.
185
209
  *
@@ -279,6 +303,14 @@ export interface AppendOptions extends ValidateOptions {
279
303
  */
280
304
  expectedHead?: LogHead | null;
281
305
  }
306
+ /**
307
+ * How long an append waits for `<log>.lock` before refusing `lock-timeout`, and
308
+ * how often it tries. Exported (APRV-478) so a caller that waits for the lock
309
+ * itself, on the event loop rather than in {@link acquireLock}'s synchronous
310
+ * retry, keeps the same bound and cadence as every other writer.
311
+ */
312
+ export declare const DEFAULT_LOCK_TIMEOUT_MS = 2000;
313
+ export declare const DEFAULT_LOCK_RETRY_MS = 20;
282
314
  /** How long a whole-operation lock holder waits before reporting `lock-timeout`. */
283
315
  export interface LockOptions {
284
316
  lockTimeoutMs?: number;
@@ -309,6 +341,21 @@ export declare function computeRecordHash(record: UnhashedRecord | EventRecord):
309
341
  export declare function verifyRecordHash(record: EventRecord): boolean;
310
342
  /** The stored line for a record: its canonical serialization (no newline). */
311
343
  export declare function serializeRecord(record: EventRecord): string;
344
+ /**
345
+ * Is `<logPath>.lock` present right now (APRV-478)?
346
+ *
347
+ * ADVISORY, and nothing else. It takes no lock, writes nothing, and authorizes
348
+ * nothing: the answer can be stale the instant it is returned. It exists so a
349
+ * caller that must not block its event loop (a harness hook between a grant and
350
+ * its spend, which has to stay answerable to a signal) can wait out another
351
+ * writer by sleeping on a timer, and only then make its one synchronous attempt
352
+ * (`lockTimeoutMs: 0`). That attempt is still {@link acquireLock}'s atomic
353
+ * create-or-fail, and the head is still compared under the lock, so a probe
354
+ * that said "free" and was wrong costs a refused attempt and never a shared
355
+ * `seq`. A probe that cannot stat the path answers `false`, and the attempt
356
+ * then meets the real error.
357
+ */
358
+ export declare function appendLockHeld(logPath: string): boolean;
312
359
  /**
313
360
  * Append exactly one event to `logPath`, stamping `seq`, `prev`, `alg`, and
314
361
  * `hash`.
@@ -336,6 +383,38 @@ export declare function serializeRecord(record: EventRecord): string;
336
383
  * guarantee that nobody else is appending while it works.
337
384
  */
338
385
  export declare function withAppendLock<T>(logPath: string, run: () => T, options?: LockOptions): LockedResult<T>;
386
+ /** What `approval log unlock` did. */
387
+ export type UnlockResult = {
388
+ kind: "unlocked";
389
+ record: EventRecord;
390
+ note: ReclaimNote;
391
+ }
392
+ /** There was no lockfile: nothing to do. */
393
+ | {
394
+ kind: "none";
395
+ }
396
+ /** Nothing was touched; `message` says why and what to do instead. */
397
+ | {
398
+ kind: "refused";
399
+ message: string;
400
+ }
401
+ /** The lock was taken, and the record could not be appended (nothing was). */
402
+ | {
403
+ kind: "failed";
404
+ error: AppendError;
405
+ };
406
+ /**
407
+ * `approval log unlock --pid <n|none>` (APRV-479): a human takes over a lock no
408
+ * writer reclaims (another container, another boot, a holder that cannot be
409
+ * checked), with the same claim and take a writer's reclaim uses, and records
410
+ * it as `audit.lock_reclaimed` (reason `operator-cleared`) under their own
411
+ * `human:` actor as the first
412
+ * record under the lock taken. `pid` must be the pid the lockfile names, or
413
+ * `null` for one that names no holder. Human-only: the CLI resolves the actor,
414
+ * the schema refuses an `agent:` one, and the harness hook classifies the verb
415
+ * `policy.core`.
416
+ */
417
+ export declare function unlockAppendLock(logPath: string, pid: number | null, actor: string): UnlockResult;
339
418
  /**
340
419
  * Subscribe to appends that put bytes in the file: every successful one, and
341
420
  * since APRV-440 one that wrote and then failed to confirm them durable (a
@@ -62,17 +62,32 @@
62
62
  * with nothing written. Every earlier record, carrying no such field, validates
63
63
  * and verifies unchanged.
64
64
  *
65
+ * 7. **A lock whose holder is provably gone is taken back, and the log says so
66
+ * (APRV-479).** The lockfile carries its holder's record. A writer that has
67
+ * waited out its whole lock timeout judges the holder once, and only a holder
68
+ * provably gone (a dead pid in this process's own pid namespace and boot, or
69
+ * an empty lockfile ten minutes old) loses the lock: the writer claims it
70
+ * with one exclusive `link(2)`, takes it with one `rename(2)` of its own
71
+ * lockfile over the lock's path, and appends `audit.lock_reclaimed` as the
72
+ * first record under it. A live holder's lock, and any holder this process
73
+ * cannot check, is never taken; the refusal names the human verb
74
+ * `approval log unlock`. `core/log-lock.ts` holds the rules.
75
+ *
65
76
  * Determinism: `ts` is supplied by the caller. This module never reads the
66
77
  * clock, because a hash-relevant field sourced from ambient state would make
67
- * the log irreproducible. `daemon` is ambient in the same sense and is not a
68
- * counter-example: a log is reproducible per WRITER, the field says which writer,
78
+ * the log irreproducible. The one exception is the record this module writes on
79
+ * its own behalf, the `audit.lock_reclaimed` of guarantee 7: no caller authors
80
+ * it, and its `ts` is assigned at the write boundary like any audit record's.
81
+ * `daemon` is ambient in the same sense and is not a counter-example: a log is reproducible per WRITER, the field says which writer,
69
82
  * and a verifier re-derives the hash from the record's own bytes either way.
70
83
  */
71
84
  import { createHash } from "node:crypto";
72
- import { closeSync, constants as fsConstants, fstatSync, mkdirSync, openSync, readSync, unlinkSync, } from "node:fs";
73
- import { dirname } from "node:path";
85
+ import { closeSync, constants as fsConstants, existsSync, fstatSync, mkdirSync, openSync, readSync, } from "node:fs";
86
+ import { basename, dirname } from "node:path";
74
87
  import { DAEMON_APPEND_REFUSAL_CODES, daemonStampForAppend, } from "./daemon-identity.js";
88
+ import { systemClock } from "./clock.js";
75
89
  import { canonicalize, JcsError } from "./jcs.js";
90
+ import { createLockFile, finishReclaim, guardTerminationWhileLocked, observeLock, reclaimStaleLock, releaseLockFile, settleTerminationGuards, takeLockForUnlock, } from "./log-lock.js";
76
91
  import { appendWriteLayer } from "./log-write-layer.js";
77
92
  import { validate } from "./validate.js";
78
93
  /** SPEC.md §8: the hash scheme identifier stamped on every v0.1 record. */
@@ -118,8 +133,14 @@ export const APPEND_ERROR_CODES = [
118
133
  */
119
134
  ...DAEMON_APPEND_REFUSAL_CODES,
120
135
  ];
121
- const DEFAULT_LOCK_TIMEOUT_MS = 2_000;
122
- const DEFAULT_LOCK_RETRY_MS = 20;
136
+ /**
137
+ * How long an append waits for `<log>.lock` before refusing `lock-timeout`, and
138
+ * how often it tries. Exported (APRV-478) so a caller that waits for the lock
139
+ * itself, on the event loop rather than in {@link acquireLock}'s synchronous
140
+ * retry, keeps the same bound and cadence as every other writer.
141
+ */
142
+ export const DEFAULT_LOCK_TIMEOUT_MS = 2_000;
143
+ export const DEFAULT_LOCK_RETRY_MS = 20;
123
144
  /**
124
145
  * Strip `hash` and canonicalize. Exported shape is documented on
125
146
  * {@link computeRecordHash}; kept separate so hashing and verification cannot
@@ -246,22 +267,48 @@ function directoriesToSync(logPath, firstCreatedDir) {
246
267
  }
247
268
  return dirs;
248
269
  }
270
+ /**
271
+ * How many times one wait may find, at its end, that the lock moved or that
272
+ * another writer is reclaiming it, and wait again, before it refuses.
273
+ */
274
+ const MAX_RECLAIM_ROUNDS = 3;
249
275
  /**
250
276
  * Acquire `<logPath>.lock` by `open(…, "wx")` — atomic create-or-fail, which
251
- * needs no dependency and works on every platform Node supports. Retries with
252
- * a fixed delay until `timeoutMs` elapses, then reports `lock-timeout`. A
253
- * stale lock is never stolen: silently breaking someone else's lock is how two
254
- * writers end up sharing a `seq`.
277
+ * needs no dependency and works on every platform Node supports — and write
278
+ * this process's holder record into it (APRV-479). Retries with a fixed delay
279
+ * until `timeoutMs` elapses.
280
+ *
281
+ * A lock is never stolen from a holder that may be alive: silently breaking
282
+ * someone else's lock is how two writers end up sharing a `seq`. Only once the
283
+ * whole wait has passed does the writer judge the lock, once
284
+ * ({@link reclaimStaleLock}): a holder that is provably gone loses the lock to
285
+ * one atomic claim and take, and this writer then holds it with the reclaim to
286
+ * record first; a lock that moved, or that another writer is reclaiming, sends
287
+ * it back to wait again (at most {@link MAX_RECLAIM_ROUNDS} times); anything
288
+ * else is `lock-timeout`, whose message names the holder, why its lock was
289
+ * kept, and the human command.
290
+ *
291
+ * The termination-signal guard ({@link guardTerminationWhileLocked}) is
292
+ * installed BEFORE each create, so a lockfile never exists in this process
293
+ * without it, and is released and settled at once when the create fails, so
294
+ * the wait runs without it (a signal there kills the process holding nothing).
255
295
  */
256
- function acquireLock(logPath, timeoutMs, retryMs) {
296
+ function acquireLock(logPath, timeoutMs, retryMs, op) {
257
297
  const path = `${logPath}.lock`;
258
- const deadline = Date.now() + timeoutMs;
298
+ let deadline = Date.now() + timeoutMs;
299
+ let rounds = 0;
300
+ let kept;
301
+ // The lockfile as first refused in this wait (APRV-479 R3-8): an empty one
302
+ // is taken only if it is still that file when the wait ends.
303
+ let watched;
259
304
  for (;;) {
305
+ const releaseGuard = guardTerminationWhileLocked();
260
306
  try {
261
- closeSync(openSync(path, "wx"));
262
- return { ok: true, path };
307
+ return { ok: true, own: createLockFile(path, op), releaseGuard, reclaimed: null };
263
308
  }
264
309
  catch (cause) {
310
+ releaseGuard();
311
+ settleTerminationGuards();
265
312
  const code = cause.code;
266
313
  if (code !== "EEXIST") {
267
314
  return {
@@ -269,26 +316,73 @@ function acquireLock(logPath, timeoutMs, retryMs) {
269
316
  error: { code: "io", message: `lockfile ${path} could not be created: ${errorMessage(cause)}` },
270
317
  };
271
318
  }
272
- if (Date.now() >= deadline) {
273
- return {
274
- ok: false,
275
- error: {
276
- code: "lock-timeout",
277
- message: `another writer holds ${path}; gave up after ${timeoutMs}ms`,
278
- },
279
- };
280
- }
319
+ if (watched === undefined)
320
+ watched = observeLock(logPath);
321
+ }
322
+ if (Date.now() < deadline) {
281
323
  sleepSync(retryMs);
324
+ continue;
282
325
  }
326
+ if (rounds < MAX_RECLAIM_ROUNDS) {
327
+ rounds += 1;
328
+ const outcome = reclaimStaleLock(logPath, op, {
329
+ recordValid: reclaimRecordValid,
330
+ recordContext: () => reclaimRecordContext(logPath),
331
+ watched: watched ?? null,
332
+ });
333
+ if (outcome.kind === "taken") {
334
+ return { ok: true, own: outcome.own, releaseGuard: outcome.releaseGuard, reclaimed: outcome.note };
335
+ }
336
+ kept = outcome.why;
337
+ if (outcome.kind === "retry") {
338
+ deadline = Date.now() + timeoutMs;
339
+ watched = undefined;
340
+ continue;
341
+ }
342
+ }
343
+ const holder = kept === undefined ? "" : ` (${kept})`;
344
+ return {
345
+ ok: false,
346
+ error: {
347
+ code: "lock-timeout",
348
+ // A zero timeout is a single try by request (APRV-478: a caller that
349
+ // waits for the lock on its own event loop), and "gave up after 0ms"
350
+ // would read as a writer that never tried.
351
+ message: timeoutMs <= 0
352
+ ? `another writer holds ${path}; this append tried the lock once, as its caller asked, and did not wait${holder}`
353
+ : `another writer holds ${path}; gave up after ${timeoutMs}ms${holder}`,
354
+ },
355
+ };
283
356
  }
284
357
  }
285
- function releaseLock(path) {
358
+ /**
359
+ * Is `<logPath>.lock` present right now (APRV-478)?
360
+ *
361
+ * ADVISORY, and nothing else. It takes no lock, writes nothing, and authorizes
362
+ * nothing: the answer can be stale the instant it is returned. It exists so a
363
+ * caller that must not block its event loop (a harness hook between a grant and
364
+ * its spend, which has to stay answerable to a signal) can wait out another
365
+ * writer by sleeping on a timer, and only then make its one synchronous attempt
366
+ * (`lockTimeoutMs: 0`). That attempt is still {@link acquireLock}'s atomic
367
+ * create-or-fail, and the head is still compared under the lock, so a probe
368
+ * that said "free" and was wrong costs a refused attempt and never a shared
369
+ * `seq`. A probe that cannot stat the path answers `false`, and the attempt
370
+ * then meets the real error.
371
+ */
372
+ export function appendLockHeld(logPath) {
373
+ return existsSync(`${logPath}.lock`);
374
+ }
375
+ /**
376
+ * Remove this process's own lockfile, and only it (APRV-479: a lockfile that is
377
+ * not the one this process wrote is somebody else's). Best effort: the lock is
378
+ * advisory and a failed unlink must not mask the append's own result.
379
+ */
380
+ function releaseLock(own) {
286
381
  try {
287
- unlinkSync(path);
382
+ releaseLockFile(own);
288
383
  }
289
384
  catch {
290
- // Best effort: the lock is advisory and a failed unlink must not mask the
291
- // append's own result.
385
+ // As above.
292
386
  }
293
387
  }
294
388
  /**
@@ -461,7 +555,8 @@ function readTail(logPath) {
461
555
  },
462
556
  };
463
557
  }
464
- return { ok: true, tail: { seq, hash } };
558
+ const ts = record["ts"];
559
+ return { ok: true, tail: typeof ts === "string" ? { seq, hash, ts } : { seq, hash } };
465
560
  }
466
561
  /**
467
562
  * Evaluate the compare-and-append precondition against the tail read under the
@@ -551,14 +646,14 @@ function buildRecord(input, seq, prev, daemon) {
551
646
  * guarantee that nobody else is appending while it works.
552
647
  */
553
648
  export function withAppendLock(logPath, run, options = {}) {
554
- return lockedRun(logPath, () => run(), options);
649
+ return lockedRun(logPath, () => run(), options, "hold");
555
650
  }
556
651
  /**
557
652
  * {@link withAppendLock}, also telling `run` the first directory its `mkdir`
558
653
  * created (`undefined` when the log's directory already existed), which the
559
654
  * append needs to know which directory entries are new (APRV-440).
560
655
  */
561
- function lockedRun(logPath, run, options) {
656
+ function lockedRun(logPath, run, options, op) {
562
657
  let firstCreatedDir;
563
658
  try {
564
659
  firstCreatedDir = mkdirSync(dirname(logPath), { recursive: true });
@@ -572,14 +667,147 @@ function lockedRun(logPath, run, options) {
572
667
  },
573
668
  };
574
669
  }
575
- const lock = acquireLock(logPath, options.lockTimeoutMs ?? DEFAULT_LOCK_TIMEOUT_MS, options.lockRetryMs ?? DEFAULT_LOCK_RETRY_MS);
670
+ const lock = acquireLock(logPath, options.lockTimeoutMs ?? DEFAULT_LOCK_TIMEOUT_MS, options.lockRetryMs ?? DEFAULT_LOCK_RETRY_MS, op);
576
671
  if (!lock.ok)
577
672
  return { ok: false, error: lock.error };
673
+ let reclaimWrote = false;
674
+ try {
675
+ try {
676
+ // A lock this writer took over from a dead holder is recorded first,
677
+ // before the caller reads the tail (APRV-479).
678
+ if (lock.reclaimed !== null) {
679
+ const recorded = recordReclaim(logPath, lock.reclaimed, "system:log", firstCreatedDir);
680
+ reclaimWrote = recorded.wrote;
681
+ if (!recorded.result.ok)
682
+ return { ok: false, error: recorded.result.error };
683
+ }
684
+ return { ok: true, value: run(firstCreatedDir) };
685
+ }
686
+ finally {
687
+ releaseLock(lock.own);
688
+ }
689
+ }
690
+ finally {
691
+ lock.releaseGuard();
692
+ if (reclaimWrote)
693
+ noteAppend(logPath);
694
+ }
695
+ }
696
+ /** The `audit.lock_reclaimed` payload: the lockfile's base name, the reason, the age, and the strictly parsed holder. */
697
+ function reclaimPayload(note) {
698
+ const payload = { lockfile: note.lockfile, reason: note.reason };
699
+ if (note.age_ms !== undefined)
700
+ payload["age_ms"] = note.age_ms;
701
+ if (note.holder !== undefined)
702
+ payload["holder"] = { pid: note.holder.pid, op: note.holder.op, created: note.holder.created };
703
+ return payload;
704
+ }
705
+ /**
706
+ * The write boundary's own verdict on the record a reclaim would append,
707
+ * computed before the reclaim is made: a reclaim whose record would be refused
708
+ * is not made.
709
+ */
710
+ function reclaimRecordValid(note) {
711
+ try {
712
+ const record = buildRecord({ ts: systemClock(), event: "audit.lock_reclaimed", actor: "system:log", payload: reclaimPayload(note) }, 1, GENESIS_PREV, null);
713
+ return validate("event", record).ok;
714
+ }
715
+ catch {
716
+ return false;
717
+ }
718
+ }
719
+ /**
720
+ * Whether this writer could append the reclaim record now (APRV-479 R3-3): the
721
+ * two refusals {@link recordReclaim} would meet that the schema check cannot
722
+ * see, its daemon stamp and the log's tail, both read without the lock. A
723
+ * reclaim whose record would be refused is not made: the lock stays for a
724
+ * writer that can record it, and nothing is claimed or appended. When it
725
+ * could, the last record's `ts`, which bounds the holder `created` the record
726
+ * may carry (R3-7).
727
+ */
728
+ function reclaimRecordContext(logPath) {
729
+ const stamp = daemonStampForAppend();
730
+ if (stamp.kind === "refuse")
731
+ return { ok: false, why: `its records are refused: ${stamp.code}` };
732
+ const tail = readTail(logPath);
733
+ if (!tail.ok) {
734
+ return { ok: false, why: `the log's tail refuses an append (${tail.error.code}), which a human repairs first; \`approval log verify\` shows where` };
735
+ }
736
+ const lastTs = tail.tail.ts === undefined ? Number.NaN : Date.parse(tail.tail.ts);
737
+ return { ok: true, lastTs: Number.isFinite(lastTs) ? lastTs : null };
738
+ }
739
+ /**
740
+ * The record of a lock taken over from a holder that is gone (APRV-479),
741
+ * appended as the first write under the lock that was taken: before the
742
+ * caller's own read of the tail, so the caller's compare-and-append sees it as
743
+ * the moved head it is. Written through the same path as every other record,
744
+ * with no head precondition (it decides nothing from the log) and the same
745
+ * daemon stamp. Only once it is in the log is the stale name removed; when it
746
+ * cannot be appended, nothing else is, and the stale name stays beside the lock
747
+ * as the evidence.
748
+ */
749
+ function recordReclaim(logPath, note, actor, firstCreatedDir) {
750
+ const stamp = daemonStampForAppend();
751
+ if (stamp.kind === "refuse")
752
+ return { result: fail(stamp.code, stamp.message), wrote: false };
753
+ const daemon = stamp.kind === "stamp" ? stamp.id : null;
754
+ const recorded = appendUnderLock(logPath, { ts: systemClock(), event: "audit.lock_reclaimed", actor, payload: reclaimPayload(note) }, {}, firstCreatedDir, daemon);
755
+ if (recorded.result.ok) {
756
+ finishReclaim(note);
757
+ return recorded;
758
+ }
759
+ return {
760
+ result: {
761
+ ok: false,
762
+ error: {
763
+ ...recorded.result.error,
764
+ message: `${recorded.result.error.message} (${note.lockfile} was taken over from a holder that is gone, and the record of that could not be appended, so nothing else was; ${basename(note.stale)} is left beside the lock as the evidence)`,
765
+ },
766
+ },
767
+ wrote: recorded.wrote,
768
+ };
769
+ }
770
+ /**
771
+ * `approval log unlock --pid <n|none>` (APRV-479): a human takes over a lock no
772
+ * writer reclaims (another container, another boot, a holder that cannot be
773
+ * checked), with the same claim and take a writer's reclaim uses, and records
774
+ * it as `audit.lock_reclaimed` (reason `operator-cleared`) under their own
775
+ * `human:` actor as the first
776
+ * record under the lock taken. `pid` must be the pid the lockfile names, or
777
+ * `null` for one that names no holder. Human-only: the CLI resolves the actor,
778
+ * the schema refuses an `agent:` one, and the harness hook classifies the verb
779
+ * `policy.core`.
780
+ */
781
+ export function unlockAppendLock(logPath, pid, actor) {
782
+ if (!existsSync(logPath)) {
783
+ return { kind: "refused", message: `${logPath} does not exist, so there is no log a record of the unlock could follow; remove ${basename(logPath)}.lock by hand` };
784
+ }
785
+ const context = reclaimRecordContext(logPath);
786
+ if (!context.ok) {
787
+ return { kind: "refused", message: `the record of the unlock could not be appended (${context.why}), so nothing was touched` };
788
+ }
789
+ const taken = takeLockForUnlock(logPath, pid, context.lastTs);
790
+ if (taken.kind === "none")
791
+ return { kind: "none" };
792
+ if (taken.kind === "refused")
793
+ return { kind: "refused", message: taken.why };
794
+ let wrote = false;
578
795
  try {
579
- return { ok: true, value: run(firstCreatedDir) };
796
+ try {
797
+ const recorded = recordReclaim(logPath, taken.note, actor, undefined);
798
+ wrote = recorded.wrote;
799
+ if (!recorded.result.ok)
800
+ return { kind: "failed", error: recorded.result.error };
801
+ return { kind: "unlocked", record: recorded.result.record, note: taken.note };
802
+ }
803
+ finally {
804
+ releaseLock(taken.own);
805
+ }
580
806
  }
581
807
  finally {
582
- releaseLock(lock.path);
808
+ taken.releaseGuard();
809
+ if (wrote)
810
+ noteAppend(logPath);
583
811
  }
584
812
  }
585
813
  /**
@@ -628,6 +856,28 @@ export function appendEvent(logPath, input, options = {}) {
628
856
  // confirm them durable.
629
857
  let wrote = false;
630
858
  const held = lockedRun(logPath, (firstCreatedDir) => {
859
+ const appended = appendUnderLock(logPath, input, options, firstCreatedDir, daemon);
860
+ wrote = appended.wrote;
861
+ return appended.result;
862
+ }, options, "append");
863
+ const result = held.ok ? held.value : { ok: false, error: held.error };
864
+ // After the lock is released, for every append that put bytes in the file:
865
+ // the reader cache must not serve a prefix proof anchored before this write.
866
+ if (wrote)
867
+ noteAppend(logPath);
868
+ return result;
869
+ }
870
+ /**
871
+ * One append, with `<logPath>.lock` already held by this process: read the
872
+ * tail, compare the head, build, validate, write, fsync. The body of
873
+ * {@link appendEvent}, shared with the reclaim record (APRV-479) so that record
874
+ * goes through every check any other record does. `wrote` says whether bytes
875
+ * may have reached the file, success or not.
876
+ */
877
+ function appendUnderLock(logPath, input, options, firstCreatedDir, daemon) {
878
+ let wrote = false;
879
+ const done = (result) => ({ result, wrote });
880
+ const run = () => {
631
881
  const tail = readTail(logPath);
632
882
  if (!tail.ok)
633
883
  return { ok: false, error: tail.error };
@@ -713,12 +963,7 @@ export function appendEvent(logPath, input, options = {}) {
713
963
  }
714
964
  }
715
965
  return { ok: true, record, line };
716
- }, options);
717
- const result = held.ok ? held.value : { ok: false, error: held.error };
718
- // After the lock is released, for every append that put bytes in the file:
719
- // the reader cache must not serve a prefix proof anchored before this write.
720
- if (wrote)
721
- noteAppend(logPath);
722
- return result;
966
+ };
967
+ return done(run());
723
968
  }
724
969
  //# sourceMappingURL=log.js.map