sigild 0.0.12 → 0.0.14

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 (133) hide show
  1. package/README.md +63 -3
  2. package/THREAT_MODEL.md +4 -0
  3. package/dist/src/audit/index.d.ts +2 -1
  4. package/dist/src/audit/index.d.ts.map +1 -1
  5. package/dist/src/audit/index.js +1 -0
  6. package/dist/src/audit/index.js.map +1 -1
  7. package/dist/src/audit/log.d.ts +52 -3
  8. package/dist/src/audit/log.d.ts.map +1 -1
  9. package/dist/src/audit/log.js +226 -40
  10. package/dist/src/audit/log.js.map +1 -1
  11. package/dist/src/bin/sigil-mcp.js +79 -9
  12. package/dist/src/bin/sigil-mcp.js.map +1 -1
  13. package/dist/src/cli/main.d.ts.map +1 -1
  14. package/dist/src/cli/main.js +35 -1
  15. package/dist/src/cli/main.js.map +1 -1
  16. package/dist/src/cli/paths.d.ts +4 -0
  17. package/dist/src/cli/paths.d.ts.map +1 -1
  18. package/dist/src/cli/paths.js +2 -0
  19. package/dist/src/cli/paths.js.map +1 -1
  20. package/dist/src/cli/portal.d.ts.map +1 -1
  21. package/dist/src/cli/portal.js +11 -1
  22. package/dist/src/cli/portal.js.map +1 -1
  23. package/dist/src/confirm/config.d.ts +19 -0
  24. package/dist/src/confirm/config.d.ts.map +1 -1
  25. package/dist/src/confirm/config.js +48 -0
  26. package/dist/src/confirm/config.js.map +1 -1
  27. package/dist/src/confirm/index.d.ts +1 -1
  28. package/dist/src/confirm/index.d.ts.map +1 -1
  29. package/dist/src/confirm/index.js.map +1 -1
  30. package/dist/src/daemon/handles.d.ts +6 -0
  31. package/dist/src/daemon/handles.d.ts.map +1 -1
  32. package/dist/src/daemon/handles.js +11 -0
  33. package/dist/src/daemon/handles.js.map +1 -1
  34. package/dist/src/daemon/index.d.ts +1 -1
  35. package/dist/src/daemon/index.d.ts.map +1 -1
  36. package/dist/src/daemon/index.js.map +1 -1
  37. package/dist/src/daemon/methods.d.ts +29 -1
  38. package/dist/src/daemon/methods.d.ts.map +1 -1
  39. package/dist/src/daemon/methods.js +293 -27
  40. package/dist/src/daemon/methods.js.map +1 -1
  41. package/dist/src/eth/abi.d.ts +82 -0
  42. package/dist/src/eth/abi.d.ts.map +1 -0
  43. package/dist/src/eth/abi.js +328 -0
  44. package/dist/src/eth/abi.js.map +1 -0
  45. package/dist/src/eth/index.d.ts +1 -0
  46. package/dist/src/eth/index.d.ts.map +1 -1
  47. package/dist/src/eth/index.js +1 -0
  48. package/dist/src/eth/index.js.map +1 -1
  49. package/dist/src/fs/index.d.ts +2 -0
  50. package/dist/src/fs/index.d.ts.map +1 -0
  51. package/dist/src/fs/index.js +2 -0
  52. package/dist/src/fs/index.js.map +1 -0
  53. package/dist/src/fs/lock.d.ts +84 -0
  54. package/dist/src/fs/lock.d.ts.map +1 -0
  55. package/dist/src/fs/lock.js +329 -0
  56. package/dist/src/fs/lock.js.map +1 -0
  57. package/dist/src/mcp/parent-watchdog.d.ts +31 -0
  58. package/dist/src/mcp/parent-watchdog.d.ts.map +1 -0
  59. package/dist/src/mcp/parent-watchdog.js +35 -0
  60. package/dist/src/mcp/parent-watchdog.js.map +1 -0
  61. package/dist/src/mcp/server.d.ts +7 -0
  62. package/dist/src/mcp/server.d.ts.map +1 -1
  63. package/dist/src/mcp/server.js +13 -2
  64. package/dist/src/mcp/server.js.map +1 -1
  65. package/dist/src/mcp/tools.d.ts.map +1 -1
  66. package/dist/src/mcp/tools.js +21 -1
  67. package/dist/src/mcp/tools.js.map +1 -1
  68. package/dist/src/policy/evaluate.d.ts.map +1 -1
  69. package/dist/src/policy/evaluate.js +69 -4
  70. package/dist/src/policy/evaluate.js.map +1 -1
  71. package/dist/src/policy/index.d.ts +2 -0
  72. package/dist/src/policy/index.d.ts.map +1 -1
  73. package/dist/src/policy/index.js +2 -0
  74. package/dist/src/policy/index.js.map +1 -1
  75. package/dist/src/policy/ledger.d.ts +84 -0
  76. package/dist/src/policy/ledger.d.ts.map +1 -0
  77. package/dist/src/policy/ledger.js +276 -0
  78. package/dist/src/policy/ledger.js.map +1 -0
  79. package/dist/src/policy/loader.d.ts.map +1 -1
  80. package/dist/src/policy/loader.js +54 -0
  81. package/dist/src/policy/loader.js.map +1 -1
  82. package/dist/src/policy/template.d.ts +2 -2
  83. package/dist/src/policy/template.d.ts.map +1 -1
  84. package/dist/src/policy/template.js +52 -0
  85. package/dist/src/policy/template.js.map +1 -1
  86. package/dist/src/policy/types.d.ts +42 -0
  87. package/dist/src/policy/types.d.ts.map +1 -1
  88. package/dist/src/policy/types.js.map +1 -1
  89. package/dist/src/policy/window.d.ts +22 -0
  90. package/dist/src/policy/window.d.ts.map +1 -0
  91. package/dist/src/policy/window.js +66 -0
  92. package/dist/src/policy/window.js.map +1 -0
  93. package/dist/src/preview/abi-dir.d.ts +50 -0
  94. package/dist/src/preview/abi-dir.d.ts.map +1 -0
  95. package/dist/src/preview/abi-dir.js +175 -0
  96. package/dist/src/preview/abi-dir.js.map +1 -0
  97. package/dist/src/preview/decode.d.ts +26 -0
  98. package/dist/src/preview/decode.d.ts.map +1 -0
  99. package/dist/src/preview/decode.js +110 -0
  100. package/dist/src/preview/decode.js.map +1 -0
  101. package/dist/src/preview/format.d.ts +45 -0
  102. package/dist/src/preview/format.d.ts.map +1 -0
  103. package/dist/src/preview/format.js +222 -0
  104. package/dist/src/preview/format.js.map +1 -0
  105. package/dist/src/preview/index.d.ts +60 -0
  106. package/dist/src/preview/index.d.ts.map +1 -0
  107. package/dist/src/preview/index.js +163 -0
  108. package/dist/src/preview/index.js.map +1 -0
  109. package/dist/src/preview/known.d.ts +74 -0
  110. package/dist/src/preview/known.d.ts.map +1 -0
  111. package/dist/src/preview/known.js +425 -0
  112. package/dist/src/preview/known.js.map +1 -0
  113. package/dist/src/preview/simulate.d.ts +156 -0
  114. package/dist/src/preview/simulate.d.ts.map +1 -0
  115. package/dist/src/preview/simulate.js +768 -0
  116. package/dist/src/preview/simulate.js.map +1 -0
  117. package/dist/src/preview/simulators.d.ts +39 -0
  118. package/dist/src/preview/simulators.d.ts.map +1 -0
  119. package/dist/src/preview/simulators.js +71 -0
  120. package/dist/src/preview/simulators.js.map +1 -0
  121. package/dist/src/preview/trust.d.ts +49 -0
  122. package/dist/src/preview/trust.d.ts.map +1 -0
  123. package/dist/src/preview/trust.js +279 -0
  124. package/dist/src/preview/trust.js.map +1 -0
  125. package/dist/src/preview/types.d.ts +69 -0
  126. package/dist/src/preview/types.d.ts.map +1 -0
  127. package/dist/src/preview/types.js +11 -0
  128. package/dist/src/preview/types.js.map +1 -0
  129. package/dist/src/preview/units.d.ts +75 -0
  130. package/dist/src/preview/units.d.ts.map +1 -0
  131. package/dist/src/preview/units.js +228 -0
  132. package/dist/src/preview/units.js.map +1 -0
  133. package/package.json +5 -5
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  `sigil` is a local signing tool and Claude Code integration that lets agentic coding tools use private keys without ever putting key material in the model's context window.
6
6
 
7
- **Status:** pre-alpha. The MCP server, CLI, unlock flow, ward hooks, policy engine (static checks), out-of-band confirmation via ntfy, Solana signing, and the JSON-RPC signing proxy (Foundry/Hardhat) all work end-to-end. Rolling-window value caps and EIP-712 domain allowlists are not yet implemented. Until they land — and until the supply-chain attestations promised for v0.1.0 ship — **do not use this with real funds yet.** Build plan lives in the [tracking issue](https://github.com/cdrn/sigil/issues/9).
7
+ **Status:** pre-alpha. The MCP server, CLI, unlock flow, ward hooks, policy engine (static checks), out-of-band confirmation via ntfy, Solana signing, and the JSON-RPC signing proxy (Foundry/Hardhat) all work end-to-end. Rolling-window value caps and EIP-712 domain allowlists shipped in 0.0.13; 0.0.14 adds a transaction preview — every EVM transaction is decoded to English and dry-run with `eth_simulateV1` before it is signed, with `require_simulation` / `sign_on_revert` policy gates. Until v0.1.0 ships — with the supply-chain attestations promised for it — **do not use this with real funds yet.** Build plan lives in the [tracking issue](https://github.com/cdrn/sigil/issues/9).
8
8
 
9
9
  ## What it is
10
10
 
@@ -16,7 +16,7 @@ One MCP server process, four bins (plus a legacy `sigild` alias), six runtime de
16
16
 
17
17
  `sigil-mcp` boots **locked**: empty in-memory handle table, no keys loaded. Sign methods return `DAEMON_LOCKED` (-32003) with a "run sigil unlock" message until you push the passphrase in from a separate terminal via `sigil unlock`. That CLI connects to a per-session Unix socket at `~/.sigil/control/<pid>.sock` (0600) that `sigil-mcp` opens at startup — and fans out to every such socket so one `sigil unlock` reaches all open windows. After unlock, signs work for the rest of the session; `sigil lock` zeroizes the table without killing the process.
18
18
 
19
- Sign methods exposed today: EIP-191 personal_sign, EIP-1559 + legacy transactions, EIP-712 typed data, plus Solana (ed25519) message + transaction signing — see [Solana support](#solana-svm) below.
19
+ Sign methods exposed today: EIP-191 personal_sign, EIP-1559 + legacy transactions, EIP-712 typed data, plus Solana (ed25519) message + transaction signing — see [Solana support](#solana-svm) below. Every EVM transaction is decoded (and optionally simulated) before it is signed, and `sigil_eth_preview_transaction` shows that preview without signing — see [Transaction preview](#transaction-preview).
20
20
 
21
21
  ## What it isn't
22
22
 
@@ -156,6 +156,8 @@ Each window still holds its own decrypted keys only for its own lifetime: closin
156
156
 
157
157
  OS-keychain integration (planned, v0.3) will make unlock zero-touch for users who set it up.
158
158
 
159
+ **After upgrading sigil, restart every Claude window's `sigil-mcp`** (reconnect the MCP server or reopen the window, then `sigil unlock` again). A running `sigil-mcp` never reloads code, and daemons from different versions must not share `~/.sigil/audit.log`: the lock protocol and the writer's chain checks are version-specific. `ps -ax | grep sigil-mcp` shows stragglers.
160
+
159
161
  ## Policy engine
160
162
 
161
163
  Once a portal is unlocked, signing authority over its key is real. To bound the blast radius of a successful prompt injection, every portal has a policy file at `~/.sigil/policy/<handle>.toml`. Two modes:
@@ -177,16 +179,74 @@ allow_contract_creation = false # deploys (to = null); when true, ever
177
179
 
178
180
  allow_message_signing = false # EIP-191 personal_sign (e.g. SIWE)
179
181
  allow_typed_data = false # EIP-712 (Permit, OpenSea — can be financial)
182
+ typed_data_verifying_contracts = [] # when allowed: domain.verifyingContract allowlist
183
+ typed_data_primary_types = [] # when allowed: primaryType allowlist ("Permit", …)
184
+ # strict mode also requires domain.chainId ∈ chain_ids
185
+
186
+ # Optional rolling-window caps on tx.value (work in permissive mode too).
187
+ max_value_per_hour_wei = "100000000000000000" # 0.1 ETH / hour
188
+ max_value_per_day_wei = "1000000000000000000" # 1 ETH / day
180
189
 
181
190
  # Optional: above this value, sigil pushes a notification to your phone and
182
191
  # waits for an approve/deny tap before signing. See "Out-of-band confirm"
183
192
  # below. Must be strictly less than max_value_wei.
184
193
  require_confirm_above_wei = "10000000000000000" # 0.01 ETH
194
+
195
+ # Optional transaction-preview gates (mode-independent; see "Transaction preview").
196
+ # require_simulation = false # true: deny any tx that couldn't be simulated
197
+ # sign_on_revert = false # true: sign even when the simulation reverts
185
198
  ```
186
199
 
187
200
  A failed rule throws `POLICY_DENIED` (-32001) back to the agent with the human-readable reason ("tx denied — value X exceeds max_value_wei Y"), and the deny is appended to the hash-chained audit log alongside allows. Denies are forensically the more interesting half — they're the prompt-injection canary.
188
201
 
189
- What's deferred to follow-up PRs (still in [#3](https://github.com/cdrn/sigil/issues/3)): rolling-window value caps (e.g. 1 ETH/day per portal), EIP-712 domain + primary-type allowlists, decoded-calldata arg checks.
202
+ **Rolling-window caps** (`max_value_per_hour_wei`, `max_value_per_day_wei`, and `svm_max_lamports_per_hour/day`) are the one rule that applies in *both* modes — a permissive "bot with an allowance" is the common case. They count native value only: `tx.value` for EVM, decoded System-Program transfers for Solana. ERC-20 / SPL transfers are calldata, not native value, and are not counted — and `require_confirm_above_wei` doesn't see them either (a token transfer has `value = 0`). Gate token movement with strict mode's `allow_to` + `allowed_selectors`; for Solana, anything sigil can't decode as a System-Program transfer is routed to confirm in strict mode, and denied outright when a lamport cap is set. Spends are recorded in a per-portal ledger at `~/.sigil/state/<handle>.ledger` (append-only JSONL, shared across windows through the same lock as the audit log, compacted automatically) and the check-and-record is atomic, so two windows can't both take the last of an allowance. The cap is checked before any confirm push (so you're not asked to approve something that would be denied anyway) and again right before signing. `sigil policy spend <handle>` shows the trailing 1h/24h totals against the caps. `sigil portal remove` deletes the ledger with the portal.
203
+
204
+ **EIP-712 allowlists** (strict mode, with `allow_typed_data = true`): `typed_data_verifying_contracts` and `typed_data_primary_types` each restrict one axis when non-empty, and the domain must carry a `chainId` that names one of `chain_ids` (strict mode refuses chain-less domains, since they can't be checked). A typed-data signature can move funds (Permit, Permit2, exchange orders), so it gets the same treatment as a transaction's destination.
205
+
206
+ Still deferred (in [#3](https://github.com/cdrn/sigil/issues/3)): decoded-calldata argument *checks* ("allow `transfer` only when `amount ≤ 100e18`"). Decoded-calldata *display* has shipped — see [Transaction preview](#transaction-preview) — along with two policy gates driven by simulation (`require_simulation`, `sign_on_revert`).
207
+
208
+ ## Transaction preview
209
+
210
+ "Show me what I'm signing." Every EVM transaction sigil signs — through the MCP tool or the JSON-RPC proxy — is first decoded to English and, when a node is configured for its chain, dry-run. An ERC-20 `approve(spender, MAX)` no longer reaches your phone as `0 ETH → 0xa0b8…`:
211
+
212
+ ```text
213
+ call: approve(spender=0x1111…1111, amount=UNLIMITED) on 0xa0b8…eb48 (USDC)
214
+ value: 0 ETH chain: 1
215
+ simulation: ok, 46,201 gas
216
+ approvals: USDC → 0x1111…1111 UNLIMITED
217
+ balance changes for 0x2278…931c: none
218
+ warnings:
219
+ - UNLIMITED approval
220
+ ```
221
+
222
+ That text goes to three places: it is returned to the agent (`preview` alongside `signed`), it is written into the hash-chained audit entry for the request (allow *and* deny), and a one-line headline — `approve UNLIMITED USDC → 0x1111…1111 | sim ok grants USDC → 0x1111…1111 UNLIMITED | ⚠ UNLIMITED approval` — plus up to three warnings is appended to the out-of-band confirm push under the policy's own summary.
223
+
224
+ **Decoding** needs no network. Built in: ERC-20 `transfer`/`approve`/`transferFrom`/`increaseAllowance`/`decreaseAllowance`; ERC-721 and ERC-1155 transfers and `setApprovalForAll`; WETH `deposit`/`withdraw`; Permit2 `approve`; Uniswap V2 router swaps, V3 `exactInputSingle`/`exactInput`/`exactOutputSingle`; Universal Router `execute`; and `multicall` (inner calls decoded one level). Warnings flag unlimited approvals, `setApprovalForAll(…, true)`, transfers/approvals to the zero address, swaps whose output goes to someone other than the portal, swaps with a zero minimum output, unknown selectors, and ETH sent with calldata sigil can't decode. For your own contracts, drop ABI files in `~/.sigil/abi/` — a bare ABI array or a Foundry/Hardhat artifact (`{"abi": [...]}`) — and calls to them render with argument names (`setFee(feeBps=30)`). Files are read once when `sigil-mcp` starts; a malformed one is skipped and named at the bottom of every preview, never fatal.
225
+
226
+ **Simulation** is opt-in. Point sigil at a node per chain in `~/.sigil/config.toml`:
227
+
228
+ ```toml
229
+ [simulate]
230
+ # timeout_ms = 15000 # per RPC call; a preview never waits more than ~3×
231
+
232
+ [simulate.rpc]
233
+ 1 = "https://eth.example/v3/KEY"
234
+ 11155111 = "https://sepolia.example"
235
+ ```
236
+
237
+ If the `[rpc]` proxy is configured, its `upstream` also serves simulation for the one chain it reports (asked via `eth_chainId` on first use). sigil calls `eth_simulateV1` with `traceTransfers` — one request that returns status, gas, revert data and every log, including native ETH movements — and derives the portal's net ETH and token balance changes, NFTs in and out, and approvals it grants; token symbols/decimals come from `symbol()`/`decimals()`. Nodes without `eth_simulateV1` get an `eth_call` + `eth_estimateGas` fallback (status and gas only; balance changes shown as unknown). Reverts are decoded (`Error("…")`, `Panic(0x11: arithmetic overflow/underflow)`, or `custom error 0x…`). Without a node for the chain the preview says `simulation: skipped`; a node that's down or slow is `unavailable` — a warning, not a failure, unless your policy says otherwise:
238
+
239
+ ```toml
240
+ # in ~/.sigil/policy/<handle>.toml — both mode-independent, both default false
241
+ require_simulation = true # deny any tx that couldn't be simulated (no RPC, node down, timeout)
242
+ sign_on_revert = false # default: a tx whose simulation reverts is denied with the reason
243
+ ```
244
+
245
+ With the defaults, a portal with no simulation node configured behaves exactly as before (plus the decoded text); once a node is configured, a tx that simulates to a revert is denied with the decoded reason unless you set `sign_on_revert = true`. A strict policy's static checks still run first — a tx they deny never reaches the node.
246
+
247
+ **`sigil_eth_preview_transaction`** takes the same `{portal, tx}` as `sigil_eth_sign_transaction` and returns the preview without signing: no policy check, no audit entry. Its description tells the agent to call it before signing anything non-trivial and to show you the result.
248
+
249
+ What the preview is *not*: proof. Event logs and token symbols are chosen by the contracts being simulated — a scam token can emit a `Transfer` it never made and call itself `USDC` — and the simulation is whatever your node says about the latest block. sigil pushes back where it can: the headline lists everything leaving the portal (and every approval it grants) before anything arriving, and never cuts those; a symbol that collides with another token in the same simulation, or claims USDC/USDT/DAI/WETH/WBTC/ETH at an address that isn't that token on the chain, is shown as `"USDC"? (0x1234…abcd)` with a warning; "wrap"/"transfer"/"swap" wording is dropped for the raw signature when the simulation shows the contract didn't do that. The simulated call carries the transaction's nonce, gas limit, fees and access list exactly as signed (a node that refuses fee fields for an underfunded sender gets one retry without them, noted in the preview); a `gasLimit` below 21000 can't be simulated and counts as unavailable. Each transaction is simulated against current state on its own, so a second tx that depends on an unbroadcast first one (approve, then swap) will simulate as a revert: broadcast the first, then sign the second. Gas is not counted in balance changes. The simulation node sees the transaction before it is signed; it is the node you chose, and the one you'd broadcast through anyway.
190
250
 
191
251
  ## Out-of-band confirm
192
252
 
package/THREAT_MODEL.md CHANGED
@@ -71,6 +71,7 @@ The policy engine (per-portal `~/.sigil/policy/<handle>.toml`) is the layer that
71
71
  - On/off toggles for personal_sign (`allow_message_signing`) and EIP-712 typed data (`allow_typed_data`).
72
72
  - Append-only hash-chained audit log records both allow AND deny decisions. Denies are the prompt-injection canary.
73
73
  - Runtime fail-closed when the policy file is missing for a portal — keys can't be used without an explicit decision.
74
+ - **Transaction preview.** Every EVM transaction is decoded (built-in ERC-20/721/1155, Permit2, Uniswap and multicall descriptions, plus user ABIs from `~/.sigil/abi/`) and, when a node is configured for its chain, dry-run with `eth_simulateV1`. The result is shown on the confirm push, returned to the agent, and recorded in the audit entry. Two opt-in policy gates act on it: `require_simulation` (deny what couldn't be simulated) and `sign_on_revert = false` (deny a simulated revert). The preview *informs* a human; it never *allows* anything the static policy would deny — static checks run first, and the simulation gates can only add denies.
74
75
  - **Solana (SVM) key reuse.** A portal's 32-byte secret doubles as an ed25519 seed, so one secret controls both an EVM (secp256k1) and a Solana (ed25519) address. This is *shared fate* by construction: compromising the secret compromises both chains. There is no known attack that combines observed ECDSA and EdDSA signatures to recover the key — both schemes are signature-secure — so reuse adds no cross-protocol weakness beyond "it is literally the same secret." SVM signing is gated by its own policy fields (`allow_svm_message_signing`, `svm_allow_to`, `svm_max_lamports`, `require_confirm_above_lamports`).
75
76
  - **SVM policy is decode-limited.** Unlike EVM, Solana hides most transaction semantics behind account indices and on-chain state. sigil only decodes **native System-Program SOL transfers** offline; everything else (SPL tokens, arbitrary programs, address-lookup-table accounts) is *not* auto-allowed — it is routed to the out-of-band confirm gate (and in strict mode with no confirm transport, denied). Auto-allow is all-or-nothing: a tx signs without a human tap only if every instruction decoded and passed policy, which closes the "hide a drain behind a recognized transfer" smuggling vector. sigil signs the serialized message bytes the caller provides; it does not fetch on-chain state.
76
77
 
@@ -110,6 +111,8 @@ Given the 2026 npm threat landscape, a compromised release of `sigil` would be c
110
111
  - The user's OS keychain (or chosen unlock mechanism) is not compromised.
111
112
  - Clock skew on the host is bounded (matters for rolling-window policy and audit timestamps).
112
113
 
114
+ - **The spend ledgers share the policy files' trust boundary.** Rolling-window caps are enforced against `~/.sigil/state/<handle>.ledger`. Unparsable content fails closed, but a *missing* ledger is an empty one: anyone who can delete it can equally edit `~/.sigil/policy/<handle>.toml` and remove the cap, so the ledger earns no protection the policy file doesn't have. The caps defend against the agent, which reaches sigil only through the signing RPC and the ward-guarded tools; they are not a defence against a principal with write access to `~/.sigil`. If your deployment gives the agent's tools a different filesystem view from the policy's, treat that as out of scope here.
115
+
113
116
  ## Known limitations
114
117
 
115
118
  - The hook-based path blocker is best-effort: it covers `Read` and `Bash`, but a sufficiently creative agent could still ask another tool to do the read. The defense in depth is that even if a key file is read, its contents are redacted by the output filter before reaching the model. And, given the unlock model, reading the encrypted keyfile alone yields nothing — the agent would also need the passphrase, which is never in its context.
@@ -119,6 +122,7 @@ Given the 2026 npm threat landscape, a compromised release of `sigil` would be c
119
122
  - **Passphrase in transit through V8 strings.** The control socket carries the passphrase base64-encoded inside a JSON message. The CLI's `Buffer` and the server's decoded `Buffer` are zeroized after use, but the intermediate JSON string sits in V8's string heap and cannot be reliably wiped. This is the same trade-off as `readPassphrase`'s internal accumulator and is considered acceptable for v0.x; mitigations would require either a custom binary framing or a fully native crypto path.
120
123
  - **Multi-window:** each `sigil-mcp` binds its own `~/.sigil/control/<pid>.sock`, and `sigil unlock`/`lock`/`status` fan out across all of them, so every open Claude window is reachable from one CLI call. Each session keeps a separate in-memory handle table and unlocks independently; the passphrase is sent (base64 in JSON, same transit caveat as above) to each live session. A window opened after an unlock starts locked until the next `sigil unlock`. Sockets orphaned by hard-killed sessions are unlinked on the next CLI call. Keys still never outlive the sessions that hold them — see [#23](https://github.com/cdrn/sigil/issues/23). The fan-out widens the control surface from one well-known socket to "every `<pid>.sock` in the directory": a hostile process running as `$USER` could plant its own listener in `~/.sigil/control/` and harvest the passphrase on the next `sigil unlock`. The `~/.sigil/` tree is 0700 so this requires same-user code execution, which is already out of scope (above); it is not a new trust boundary, only a larger surface within the existing one.
121
124
  - Out-of-band confirmation (planned, [#4](https://github.com/cdrn/sigil/issues/4)) depends on a working push channel. If the push provider is down, high-value signs are denied, not approved.
125
+ - **The transaction preview is only as honest as its inputs.** Simulation results come from the user-configured RPC node, unauthenticated: a malicious or compromised node can report a draining tx as harmless (or a fine one as reverting — a denial of service at worst, since the gates only deny). Event logs and token `symbol()`s are chosen by the contracts being simulated: a scam token can emit `Transfer` events it never performed and name itself `USDC`. Symbols and revert strings are sanitized/quoted so they can't break the push layout, but not verified. Treat the preview as strong evidence for a human, not as a security boundary; the static policy (allowlists, caps) remains the boundary. The node also sees each transaction before it is signed — the same node it would be broadcast through.
122
126
 
123
127
  ## Reporting issues
124
128
 
@@ -1,2 +1,3 @@
1
- export { type AuditDecision, type AuditEntry, type StoredAuditEntry, type ChainHead, ZERO_HASH, HASH_HEX_LEN, AuditChainError, AuditWriter, canonicalJSON, hashEntry, sealEntry, serializeEntry, parseLine, verifyChain, readHead, } from './log.js';
1
+ export { type AuditDecision, type AuditEntry, type AuditPreview, type StoredAuditEntry, type ChainHead, ZERO_HASH, HASH_HEX_LEN, AuditChainError, AuditWriter, canonicalJSON, hashEntry, sealEntry, serializeEntry, parseLine, verifyChain, readHead, type AuditWriterOpts, } from './log.js';
2
+ export { type AcquireLockOptions, AuditLockError, acquireLockSync } from '../fs/lock.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/audit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACX,QAAQ,GACT,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/audit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACX,QAAQ,EACR,KAAK,eAAe,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { ZERO_HASH, HASH_HEX_LEN, AuditChainError, AuditWriter, canonicalJSON, hashEntry, sealEntry, serializeEntry, parseLine, verifyChain, readHead, } from './log.js';
2
+ export { AuditLockError, acquireLockSync } from '../fs/lock.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/audit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACX,QAAQ,GACT,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/audit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACX,QAAQ,GAET,MAAM,UAAU,CAAC;AAClB,OAAO,EAA2B,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -1,4 +1,18 @@
1
+ import { type AcquireLockOptions } from '../fs/lock.js';
1
2
  export type AuditDecision = 'allow' | 'deny' | 'confirm_required';
3
+ /**
4
+ * What the transaction preview showed for this request (EVM transactions
5
+ * only): the full text the agent got, the one-line decoded call, the
6
+ * simulation status line, and the aggregated warnings. Recorded on allows
7
+ * AND denies so a post-incident read of the log shows what the human was
8
+ * told at the time, not a re-derivation against today's chain state.
9
+ */
10
+ export interface AuditPreview {
11
+ text: string;
12
+ decoded: string;
13
+ simulation: string;
14
+ warnings: string[];
15
+ }
2
16
  export interface AuditEntry {
3
17
  seq: number;
4
18
  ts: number;
@@ -9,6 +23,7 @@ export interface AuditEntry {
9
23
  decision: AuditDecision;
10
24
  reason?: string;
11
25
  sig?: string;
26
+ preview?: AuditPreview;
12
27
  }
13
28
  export interface StoredAuditEntry extends AuditEntry {
14
29
  hash: string;
@@ -75,13 +90,36 @@ export declare function readHead(path: string): ChainHead;
75
90
  *
76
91
  * The seq and prev_hash fields are managed by the writer; callers supply
77
92
  * everything else.
93
+ *
94
+ * Multiple processes (one sigil-mcp per Claude session) share one audit file,
95
+ * so every append serializes through the sidecar lock directory
96
+ * `<path>.lock.d` (see src/fs/lock.ts). The in-memory head is only a cache:
97
+ * under the lock, the writer checks the file's byte length and the hash of
98
+ * its last line against what it cached and, if either moved, re-reads (and
99
+ * re-verifies) the chain before computing the next entry. Without this, concurrent writers
100
+ * each extend their own stale tail and the interleaved lines fail startup
101
+ * verification with seq gaps and broken prev_hash links.
78
102
  */
103
+ export interface AuditWriterOpts {
104
+ /** Clock override for tests. Defaults to Date.now. */
105
+ now?: () => number;
106
+ lock?: AcquireLockOptions;
107
+ /**
108
+ * What to do when the file on disk fails chain verification:
109
+ * - 'throw' (default): raise AuditChainError; the caller decides.
110
+ * - 'quarantine': move the file to `<path>.corrupt-<timestamp>` (never
111
+ * overwriting an existing file), report via `warn`, and start a fresh
112
+ * chain. Nothing is deleted. sigil-mcp uses this so one damaged log
113
+ * can't lock the user out of signing until they hand-edit it.
114
+ */
115
+ onCorrupt?: 'throw' | 'quarantine';
116
+ warn?: (message: string) => void;
117
+ }
79
118
  export declare class AuditWriter {
80
119
  #private;
81
120
  readonly path: string;
82
- constructor(path: string, opts?: {
83
- now?: () => number;
84
- });
121
+ readonly lockPath: string;
122
+ constructor(path: string, opts?: AuditWriterOpts);
85
123
  get head(): ChainHead;
86
124
  append(input: {
87
125
  kind: string;
@@ -90,7 +128,18 @@ export declare class AuditWriter {
90
128
  decision: AuditDecision;
91
129
  reason?: string;
92
130
  sig?: string;
131
+ preview?: AuditPreview;
93
132
  }): StoredAuditEntry;
94
133
  close(): void;
95
134
  }
135
+ /**
136
+ * Test-only seams. `quarantineStep` is invoked before each step of
137
+ * quarantine publication and may throw to simulate that step failing;
138
+ * `tailScanMax` overrides the scan cap so the fallback path can be tested
139
+ * without writing tens of megabytes. Never set by production code.
140
+ */
141
+ export declare const _auditTestHooks: {
142
+ quarantineStep?: (step: 'fsync-evidence' | 'fsync-dir' | 'unlink') => void;
143
+ tailScanMax?: number;
144
+ };
96
145
  //# sourceMappingURL=log.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/audit/log.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,kBAAkB,CAAC;AAElE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,SAAS,QAAiB,CAAC;AACxC,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;gBACvB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAKxC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAyBpD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,gBAAgB,CAE7D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAE9D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IA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I,EAAE,MAAM,GAAG,SAAS,CAEhD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,qBAAa,WAAW;;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBASd,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,eAAoB;IAsDpD,IAAI,IAAI,IAAI,SAAS,CAEpB;IAED,MAAM,CAAC,KAAK,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,aAAa,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,YAAY,CAAC;KACxB,GAAG,gBAAgB;IA0CpB,KAAK,IAAI,IAAI;CAGd;AA8DD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE;IAC5B,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,GAAG,WAAW,GAAG,QAAQ,KAAK,IAAI,CAAC;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -1,5 +1,7 @@
1
- import { closeSync, fsyncSync, openSync, readFileSync, writeSync } from 'node:fs';
1
+ import { closeSync, fsyncSync, linkSync, openSync, readFileSync, readSync, statSync, unlinkSync, } from 'node:fs';
2
+ import { dirname } from 'node:path';
2
3
  import { keccak256 } from '../eth/keccak.js';
4
+ import { withFileLock, writeAllSync } from '../fs/lock.js';
3
5
  export const ZERO_HASH = '0'.repeat(64);
4
6
  export const HASH_HEX_LEN = 64;
5
7
  export class AuditChainError extends Error {
@@ -105,6 +107,7 @@ export function parseLine(line) {
105
107
  decision: obj['decision'],
106
108
  ...(obj['reason'] !== undefined ? { reason: obj['reason'] } : {}),
107
109
  ...(obj['sig'] !== undefined ? { sig: obj['sig'] } : {}),
110
+ ...(obj['preview'] !== undefined ? { preview: obj['preview'] } : {}),
108
111
  };
109
112
  const expected = hashEntry(rest);
110
113
  if (hash !== expected) {
@@ -151,48 +154,96 @@ export function verifyChain(buf) {
151
154
  return entries;
152
155
  }
153
156
  /**
154
- * Read the chain head from an existing audit file. Verifies the whole chain
155
- * during read. If the file does not exist or is empty, returns the genesis head.
157
+ * Read the chain head plus the byte length it was derived from. The size lets
158
+ * a writer cheaply detect (via stat) that another process appended since the
159
+ * head was read. Missing file → genesis head at size 0.
156
160
  */
157
- export function readHead(path) {
161
+ function readHeadAndSize(path) {
158
162
  let buf;
159
163
  try {
160
164
  buf = readFileSync(path);
161
165
  }
162
166
  catch (err) {
163
167
  if (err.code === 'ENOENT') {
164
- return { nextSeq: 0, prevHash: ZERO_HASH };
168
+ return { head: { nextSeq: 0, prevHash: ZERO_HASH }, size: 0 };
165
169
  }
166
170
  throw err;
167
171
  }
168
172
  const entries = verifyChain(buf);
169
173
  if (entries.length === 0) {
170
- return { nextSeq: 0, prevHash: ZERO_HASH };
174
+ return { head: { nextSeq: 0, prevHash: ZERO_HASH }, size: buf.length };
171
175
  }
172
176
  const last = entries[entries.length - 1];
173
- return { nextSeq: last.seq + 1, prevHash: last.hash };
177
+ return { head: { nextSeq: last.seq + 1, prevHash: last.hash }, size: buf.length };
174
178
  }
175
179
  /**
176
- * Append-only audit writer with fsync after every write.
177
- *
178
- * Typical use:
179
- * const w = new AuditWriter('/path/to/audit.log');
180
- * w.append({ kind: 'eth_sign_message', portal: 'evm:bot', payload, decision: 'allow', sig });
181
- * w.close();
182
- *
183
- * The seq and prev_hash fields are managed by the writer; callers supply
184
- * everything else.
180
+ * Read the chain head from an existing audit file. Verifies the whole chain
181
+ * during read. If the file does not exist or is empty, returns the genesis head.
185
182
  */
183
+ export function readHead(path) {
184
+ return readHeadAndSize(path).head;
185
+ }
186
186
  export class AuditWriter {
187
187
  path;
188
+ lockPath;
188
189
  #head;
190
+ #size;
189
191
  #closed = false;
190
- // Allow tests to inject a fixed clock. Defaults to Date.now.
191
192
  #now;
193
+ #lockOpts;
194
+ #onCorrupt;
195
+ #warn;
192
196
  constructor(path, opts = {}) {
193
197
  this.path = path;
194
- this.#head = readHead(path);
198
+ this.lockPath = `${path}.lock.d`;
195
199
  this.#now = opts.now ?? (() => Date.now());
200
+ this.#lockOpts = opts.lock ?? {};
201
+ this.#onCorrupt = opts.onCorrupt ?? 'throw';
202
+ this.#warn = opts.warn ?? ((m) => process.stderr.write(m + '\n'));
203
+ this.#head = { nextSeq: 0, prevHash: ZERO_HASH };
204
+ this.#size = -1;
205
+ // Take the lock even for the initial read so startup verification never
206
+ // observes a mid-append view of the file.
207
+ withFileLock(this.path, () => this.#syncHead(), this.#lockOpts);
208
+ }
209
+ /**
210
+ * Bring the cached head in line with the file on disk. Must be called
211
+ * under the lock. Two cheap checks decide whether the cache is current:
212
+ * the byte length, and the hash of the file's last line — a replacement
213
+ * chain of identical length (another process quarantined a torn log and
214
+ * started over, and its genesis entry happens to serialize to the same
215
+ * size) is caught by the second. Only when either differs is the whole
216
+ * chain re-read and re-verified.
217
+ */
218
+ #syncHead() {
219
+ let diskSize = 0;
220
+ try {
221
+ diskSize = statSync(this.path).size;
222
+ }
223
+ catch (err) {
224
+ if (err.code !== 'ENOENT')
225
+ throw err;
226
+ }
227
+ if (diskSize === this.#size &&
228
+ (diskSize === 0 || lastLineHash(this.path, diskSize) === this.#head.prevHash)) {
229
+ return;
230
+ }
231
+ try {
232
+ const { head, size } = readHeadAndSize(this.path);
233
+ this.#head = head;
234
+ this.#size = size;
235
+ }
236
+ catch (err) {
237
+ if (!(err instanceof AuditChainError) || this.#onCorrupt !== 'quarantine')
238
+ throw err;
239
+ const quarantined = quarantine(this.path, this.#now());
240
+ // Our own state is reset before control passes to the warn callback:
241
+ // if it throws, this writer already describes the fresh chain.
242
+ this.#head = { nextSeq: 0, prevHash: ZERO_HASH };
243
+ this.#size = 0;
244
+ this.#warn(`sigil: audit log ${this.path} failed verification (${err.message}); ` +
245
+ `moved it to ${quarantined} and started a fresh chain`);
246
+ }
196
247
  }
197
248
  get head() {
198
249
  return { ...this.#head };
@@ -200,32 +251,167 @@ export class AuditWriter {
200
251
  append(input) {
201
252
  if (this.#closed)
202
253
  throw new Error('AuditWriter is closed');
203
- const entry = {
204
- seq: this.#head.nextSeq,
205
- ts: this.#now(),
206
- prev_hash: this.#head.prevHash,
207
- kind: input.kind,
208
- portal: input.portal,
209
- payload: input.payload,
210
- decision: input.decision,
211
- ...(input.reason !== undefined ? { reason: input.reason } : {}),
212
- ...(input.sig !== undefined ? { sig: input.sig } : {}),
213
- };
214
- const stored = sealEntry(entry);
215
- const line = serializeEntry(stored);
216
- const fd = openSync(this.path, 'a', 0o600);
254
+ return withFileLock(this.path, () => {
255
+ // Another process may have appended (or replaced the chain) since we
256
+ // last looked; #syncHead re-verifies unless both the byte length and
257
+ // the last line's hash still match the cache.
258
+ this.#syncHead();
259
+ const entry = {
260
+ seq: this.#head.nextSeq,
261
+ ts: this.#now(),
262
+ prev_hash: this.#head.prevHash,
263
+ kind: input.kind,
264
+ portal: input.portal,
265
+ payload: input.payload,
266
+ decision: input.decision,
267
+ ...(input.reason !== undefined ? { reason: input.reason } : {}),
268
+ ...(input.sig !== undefined ? { sig: input.sig } : {}),
269
+ ...(input.preview !== undefined ? { preview: input.preview } : {}),
270
+ };
271
+ const stored = sealEntry(entry);
272
+ const line = serializeEntry(stored);
273
+ const fd = openSync(this.path, 'a', 0o600);
274
+ try {
275
+ writeAllSync(fd, line);
276
+ fsyncSync(fd);
277
+ }
278
+ finally {
279
+ closeSync(fd);
280
+ }
281
+ // Only now — after the bytes are durably on disk — is the cache advanced.
282
+ this.#head = { nextSeq: stored.seq + 1, prevHash: stored.hash };
283
+ this.#size += Buffer.byteLength(line, 'utf8');
284
+ return stored;
285
+ }, this.#lockOpts);
286
+ }
287
+ close() {
288
+ this.#closed = true;
289
+ }
290
+ }
291
+ /**
292
+ * Move a failed log aside as `<path>.corrupt-<iso timestamp>[-n]` without
293
+ * ever replacing an existing file, and without a crash window in which the
294
+ * evidence is on neither name. rename(2) silently overwrites its target, so
295
+ * publication goes through link(2), which fails with EEXIST if the name is
296
+ * taken. The new directory entry is then fsynced (the file's data already
297
+ * was, by the writer that produced it) before the original name is
298
+ * unlinked, and the directory is synced again afterwards. A power cut at
299
+ * any point leaves the bytes reachable under at least one name; a plain
300
+ * process crash between link and unlink leaves both, and the next writer
301
+ * simply quarantines the original again under a fresh suffix.
302
+ */
303
+ function quarantine(path, nowMs) {
304
+ const base = `${path}.corrupt-${new Date(nowMs).toISOString().replace(/[:.]/g, '-')}`;
305
+ for (let i = 0;; i++) {
306
+ const candidate = i === 0 ? base : `${base}-${i}`;
217
307
  try {
218
- writeSync(fd, line);
219
- fsyncSync(fd);
308
+ linkSync(path, candidate);
220
309
  }
221
- finally {
222
- closeSync(fd);
310
+ catch (err) {
311
+ if (err.code === 'EEXIST')
312
+ continue;
313
+ throw err;
223
314
  }
224
- this.#head = { nextSeq: stored.seq + 1, prevHash: stored.hash };
225
- return stored;
315
+ // Every step before the unlink may fail; if one does, the original is
316
+ // still in place and the error propagates (a half-published quarantine
317
+ // must not report success). The linked name, if it exists, is a
318
+ // harmless extra copy the next open re-quarantines under a suffix.
319
+ _auditTestHooks.quarantineStep?.('fsync-evidence');
320
+ fsyncFile(candidate);
321
+ _auditTestHooks.quarantineStep?.('fsync-dir');
322
+ fsyncDir(dirname(path));
323
+ _auditTestHooks.quarantineStep?.('unlink');
324
+ unlinkSync(path);
325
+ fsyncDir(dirname(path));
326
+ return candidate;
226
327
  }
227
- close() {
228
- this.#closed = true;
328
+ }
329
+ function fsyncFile(path) {
330
+ const fd = openSync(path, 'r');
331
+ try {
332
+ fsyncSync(fd);
333
+ }
334
+ finally {
335
+ closeSync(fd);
336
+ }
337
+ }
338
+ /**
339
+ * Directory entries need their own fsync to be durable (fsync(2)). A
340
+ * failure here is a durability failure and propagates; the caller must not
341
+ * remove the original name on the strength of an unconfirmed publication.
342
+ */
343
+ function fsyncDir(dir) {
344
+ const fd = openSync(dir, 'r');
345
+ try {
346
+ fsyncSync(fd);
347
+ }
348
+ finally {
349
+ closeSync(fd);
350
+ }
351
+ }
352
+ /**
353
+ * Test-only seams. `quarantineStep` is invoked before each step of
354
+ * quarantine publication and may throw to simulate that step failing;
355
+ * `tailScanMax` overrides the scan cap so the fallback path can be tested
356
+ * without writing tens of megabytes. Never set by production code.
357
+ */
358
+ export const _auditTestHooks = {};
359
+ /**
360
+ * Hash of the last newline-terminated line, read from the tail in fixed
361
+ * chunks so a large log isn't re-read on every append. Each chunk is
362
+ * scanned once as it arrives and the pieces are joined once, so a huge
363
+ * final line costs O(line), not O(line²/chunk) — this runs under the
364
+ * audit lock, and a caller-controlled payload must not be able to stall
365
+ * every other session. Lines longer than MAX_TAIL_SCAN fall back to a
366
+ * full re-verify — which bounds the *tail scan*, not the lock hold: the
367
+ * full re-verify is O(file) like every resync (see readHeadAndSize). Returns null for a file that doesn't end in a newline
368
+ * (torn) or whose last line doesn't parse — either way the caller falls
369
+ * through to readHeadAndSize.
370
+ */
371
+ const TAIL_CHUNK = 64 * 1024;
372
+ const MAX_TAIL_SCAN = 64 * 1024 * 1024;
373
+ function lastLineHash(path, size) {
374
+ if (size === 0)
375
+ return null;
376
+ const fd = openSync(path, 'r');
377
+ try {
378
+ const tail = Buffer.alloc(1);
379
+ readSync(fd, tail, 0, 1, size - 1);
380
+ if (tail[0] !== 0x0a)
381
+ return null;
382
+ // Pieces of the last line, in reverse file order, excluding the final
383
+ // newline. `lineEnd` is the offset of that newline.
384
+ const lineEnd = size - 1;
385
+ const pieces = [];
386
+ let pos = lineEnd;
387
+ let scanned = 0;
388
+ for (;;) {
389
+ if (pos === 0)
390
+ break;
391
+ const start = Math.max(0, pos - TAIL_CHUNK);
392
+ const buf = Buffer.alloc(pos - start);
393
+ readSync(fd, buf, 0, buf.length, start);
394
+ scanned += buf.length;
395
+ const nl = buf.lastIndexOf(0x0a);
396
+ if (nl !== -1) {
397
+ pieces.push(buf.subarray(nl + 1));
398
+ break;
399
+ }
400
+ pieces.push(buf);
401
+ pos = start;
402
+ if (scanned > (_auditTestHooks.tailScanMax ?? MAX_TAIL_SCAN))
403
+ return null;
404
+ }
405
+ const line = Buffer.concat(pieces.reverse()).toString('utf8');
406
+ try {
407
+ return parseLine(line).hash;
408
+ }
409
+ catch {
410
+ return null;
411
+ }
412
+ }
413
+ finally {
414
+ closeSync(fd);
229
415
  }
230
416
  }
231
417
  //# sourceMappingURL=log.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/audit/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAoB7C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,KAAK,CAAqB;IACnC,YAAY,GAAW,EAAE,KAAc;QACrC,KAAK,CAAC,oBAAoB,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,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