approval-md 0.1.0 → 0.3.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.
- package/README.md +629 -559
- package/SPEC.md +99 -24
- package/dist/src/adapters/agentmail.d.ts +426 -0
- package/dist/src/adapters/agentmail.js +2 -2
- package/dist/src/adapters/conformance.d.ts +149 -0
- package/dist/src/adapters/contract.d.ts +628 -0
- package/dist/src/adapters/contract.js +110 -16
- package/dist/src/adapters/contract.js.map +1 -1
- package/dist/src/adapters/email.d.ts +324 -0
- package/dist/src/adapters/env-passphrase.d.ts +93 -0
- package/dist/src/adapters/public.d.ts +11 -0
- package/dist/src/adapters/public.js +11 -0
- package/dist/src/adapters/public.js.map +1 -0
- package/dist/src/adapters/registry.d.ts +59 -0
- package/dist/src/adapters/registry.js +2 -1
- package/dist/src/adapters/registry.js.map +1 -1
- package/dist/src/adapters/smtp.d.ts +213 -0
- package/dist/src/adapters/vault-provider.d.ts +114 -0
- package/dist/src/adapters/vault-provider.js +3 -3
- package/dist/src/adapters/zzz.d.ts +66 -0
- package/dist/src/adapters/zzz.js +299 -0
- package/dist/src/adapters/zzz.js.map +1 -0
- package/dist/src/channels/batch.d.ts +109 -0
- package/dist/src/channels/cli.d.ts +193 -0
- package/dist/src/channels/conformance.d.ts +92 -0
- package/dist/src/channels/contract.d.ts +656 -0
- package/dist/src/channels/contract.js +200 -7
- package/dist/src/channels/contract.js.map +1 -1
- package/dist/src/channels/payload-view.d.ts +35 -0
- package/dist/src/channels/render-queue.d.ts +149 -0
- package/dist/src/channels/tagging.d.ts +196 -0
- package/dist/src/channels/telegram.d.ts +1944 -0
- package/dist/src/channels/telegram.js +218 -23
- package/dist/src/channels/telegram.js.map +1 -1
- package/dist/src/channels/web.d.ts +350 -0
- package/dist/src/channels/web.js +17 -0
- package/dist/src/channels/web.js.map +1 -1
- package/dist/src/cli/adapter.d.ts +90 -0
- package/dist/src/cli/adapter.js +25 -15
- package/dist/src/cli/adapter.js.map +1 -1
- package/dist/src/cli/amend.d.ts +59 -0
- package/dist/src/cli/amend.js +214 -30
- package/dist/src/cli/amend.js.map +1 -1
- package/dist/src/cli/args.d.ts +43 -0
- package/dist/src/cli/attest.d.ts +50 -0
- package/dist/src/cli/attest.js +134 -7
- package/dist/src/cli/attest.js.map +1 -1
- package/dist/src/cli/audit-card.d.ts +62 -0
- package/dist/src/cli/audit.d.ts +59 -0
- package/dist/src/cli/channel-telegram.d.ts +879 -0
- package/dist/src/cli/channel-telegram.js +311 -13
- package/dist/src/cli/channel-telegram.js.map +1 -1
- package/dist/src/cli/channel-web.d.ts +131 -0
- package/dist/src/cli/channel.d.ts +80 -0
- package/dist/src/cli/channel.js +9 -0
- package/dist/src/cli/channel.js.map +1 -1
- package/dist/src/cli/checkpoint-tap.d.ts +169 -0
- package/dist/src/cli/codex-bridge.d.ts +819 -0
- package/dist/src/cli/codex-bridge.js +1607 -0
- package/dist/src/cli/codex-bridge.js.map +1 -0
- package/dist/src/cli/codex.d.ts +2 -0
- package/dist/src/cli/codex.js +469 -0
- package/dist/src/cli/codex.js.map +1 -0
- package/dist/src/cli/coverage.d.ts +61 -0
- package/dist/src/cli/daemon.d.ts +120 -0
- package/dist/src/cli/daemon.js +4 -1
- package/dist/src/cli/daemon.js.map +1 -1
- package/dist/src/cli/doctor.d.ts +129 -0
- package/dist/src/cli/doctor.js +586 -17
- package/dist/src/cli/doctor.js.map +1 -1
- package/dist/src/cli/env.d.ts +65 -0
- package/dist/src/cli/execute.d.ts +202 -0
- package/dist/src/cli/execute.js +25 -2
- package/dist/src/cli/execute.js.map +1 -1
- package/dist/src/cli/exit-codes.d.ts +73 -0
- package/dist/src/cli/feedback.d.ts +60 -0
- package/dist/src/cli/gate-window.d.ts +40 -0
- package/dist/src/cli/gate.d.ts +68 -0
- package/dist/src/cli/git-scope.d.ts +190 -0
- package/dist/src/cli/gloss-attach.d.ts +85 -0
- package/dist/src/cli/gloss-codex-child.d.ts +9 -0
- package/dist/src/cli/gloss-codex.d.ts +24 -0
- package/dist/src/cli/gloss-options.d.ts +42 -0
- package/dist/src/cli/gloss.d.ts +265 -0
- package/dist/src/cli/help.d.ts +107 -0
- package/dist/src/cli/help.js +320 -93
- package/dist/src/cli/help.js.map +1 -1
- package/dist/src/cli/hook-codex.d.ts +126 -0
- package/dist/src/cli/hook-codex.js +226 -0
- package/dist/src/cli/hook-codex.js.map +1 -0
- package/dist/src/cli/hook.d.ts +787 -0
- package/dist/src/cli/hook.js +1235 -181
- package/dist/src/cli/hook.js.map +1 -1
- package/dist/src/cli/import.d.ts +35 -0
- package/dist/src/cli/import.js +1 -1
- package/dist/src/cli/import.js.map +1 -1
- package/dist/src/cli/init.d.ts +84 -0
- package/dist/src/cli/init.js +2 -2
- package/dist/src/cli/init.js.map +1 -1
- package/dist/src/cli/instructions.d.ts +23 -0
- package/dist/src/cli/journal.d.ts +41 -0
- package/dist/src/cli/log-advance.d.ts +287 -0
- package/dist/src/cli/log-advance.js +102 -11
- package/dist/src/cli/log-advance.js.map +1 -1
- package/dist/src/cli/log-anchor.d.ts +176 -0
- package/dist/src/cli/log-checkpoint.d.ts +22 -0
- package/dist/src/cli/log-sync.d.ts +243 -0
- package/dist/src/cli/log-verbs.d.ts +16 -0
- package/dist/src/cli/log-verbs.js +7 -1
- package/dist/src/cli/log-verbs.js.map +1 -1
- package/dist/src/cli/long-help.d.ts +70 -0
- package/dist/src/cli/main.d.ts +77 -0
- package/dist/src/cli/main.js +159 -7
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/mcp.d.ts +52 -0
- package/dist/src/cli/paths.d.ts +56 -0
- package/dist/src/cli/payload.d.ts +58 -0
- package/dist/src/cli/policy-apply.d.ts +195 -0
- package/dist/src/cli/policy-apply.js +573 -0
- package/dist/src/cli/policy-apply.js.map +1 -0
- package/dist/src/cli/policy.d.ts +43 -0
- package/dist/src/cli/policy.js +14 -1
- package/dist/src/cli/policy.js.map +1 -1
- package/dist/src/cli/preflight.d.ts +501 -0
- package/dist/src/cli/preflight.js +689 -45
- package/dist/src/cli/preflight.js.map +1 -1
- package/dist/src/cli/progress.d.ts +78 -0
- package/dist/src/cli/prompt.d.ts +209 -0
- package/dist/src/cli/quickstart.d.ts +46 -0
- package/dist/src/cli/quickstart.js +297 -0
- package/dist/src/cli/quickstart.js.map +1 -0
- package/dist/src/cli/records.d.ts +34 -0
- package/dist/src/cli/render.d.ts +22 -0
- package/dist/src/cli/sandbox.d.ts +51 -0
- package/dist/src/cli/sandbox.js +17 -1
- package/dist/src/cli/sandbox.js.map +1 -1
- package/dist/src/cli/scaffold.d.ts +79 -0
- package/dist/src/cli/scaffold.js +1 -1
- package/dist/src/cli/setup-adapter.d.ts +137 -0
- package/dist/src/cli/setup-adapter.js +38 -4
- package/dist/src/cli/setup-adapter.js.map +1 -1
- package/dist/src/cli/setup-channel.d.ts +126 -0
- package/dist/src/cli/setup-channel.js +28 -1
- package/dist/src/cli/setup-channel.js.map +1 -1
- package/dist/src/cli/setup-checkpoint.d.ts +57 -0
- package/dist/src/cli/setup-common.d.ts +277 -0
- package/dist/src/cli/setup-common.js +3 -2
- package/dist/src/cli/setup-common.js.map +1 -1
- package/dist/src/cli/setup-flow.d.ts +287 -0
- package/dist/src/cli/setup-service.d.ts +96 -0
- package/dist/src/cli/setup.d.ts +204 -0
- package/dist/src/cli/setup.js +94 -2
- package/dist/src/cli/setup.js.map +1 -1
- package/dist/src/cli/style.d.ts +320 -0
- package/dist/src/cli/token.d.ts +39 -0
- package/dist/src/cli/up.d.ts +155 -0
- package/dist/src/cli/up.js +119 -53
- package/dist/src/cli/up.js.map +1 -1
- package/dist/src/cli/usage.d.ts +37 -0
- package/dist/src/cli/values.d.ts +40 -0
- package/dist/src/cli/values.js +3 -4
- package/dist/src/cli/values.js.map +1 -1
- package/dist/src/cli/vault.d.ts +59 -0
- package/dist/src/cli/vault.js +2 -2
- package/dist/src/cli/vault.js.map +1 -1
- package/dist/src/cli/verb-registry.d.ts +76 -0
- package/dist/src/cli/verb-registry.js +344 -11
- package/dist/src/cli/verb-registry.js.map +1 -1
- package/dist/src/cli/wordmark.d.ts +31 -0
- package/dist/src/cli/wordmark.js +2 -2
- package/dist/src/codex/broker.d.ts +229 -0
- package/dist/src/codex/broker.js +548 -0
- package/dist/src/codex/broker.js.map +1 -0
- package/dist/src/codex/doctor.d.ts +13 -0
- package/dist/src/codex/doctor.js +41 -0
- package/dist/src/codex/doctor.js.map +1 -0
- package/dist/src/codex/manifest.d.ts +49 -0
- package/dist/src/codex/manifest.js +103 -0
- package/dist/src/codex/manifest.js.map +1 -0
- package/dist/src/codex/runner.d.ts +178 -0
- package/dist/src/codex/runner.js +231 -0
- package/dist/src/codex/runner.js.map +1 -0
- package/dist/src/codex/serve.d.ts +56 -0
- package/dist/src/codex/serve.js +98 -0
- package/dist/src/codex/serve.js.map +1 -0
- package/dist/src/codex/templates.d.ts +41 -0
- package/dist/src/codex/templates.js +319 -0
- package/dist/src/codex/templates.js.map +1 -0
- package/dist/src/codex/trust.d.ts +19 -0
- package/dist/src/codex/trust.js +183 -0
- package/dist/src/codex/trust.js.map +1 -0
- package/dist/src/codex/workspace-commit.d.ts +219 -0
- package/dist/src/codex/workspace-commit.js +549 -0
- package/dist/src/codex/workspace-commit.js.map +1 -0
- package/dist/src/codex/workspace-plan.d.ts +131 -0
- package/dist/src/codex/workspace-plan.js +561 -0
- package/dist/src/codex/workspace-plan.js.map +1 -0
- package/dist/src/core/actor.d.ts +2 -0
- package/dist/src/core/actor.js +5 -0
- package/dist/src/core/actor.js.map +1 -0
- package/dist/src/core/advance-cycle.d.ts +221 -0
- package/dist/src/core/advance-cycle.js +66 -2
- package/dist/src/core/advance-cycle.js.map +1 -1
- package/dist/src/core/agents-md.d.ts +278 -0
- package/dist/src/core/agents-md.js +33 -31
- package/dist/src/core/agents-md.js.map +1 -1
- package/dist/src/core/apply-patch.d.ts +49 -0
- package/dist/src/core/apply-patch.js +266 -0
- package/dist/src/core/apply-patch.js.map +1 -0
- package/dist/src/core/attest.d.ts +635 -0
- package/dist/src/core/attest.js +326 -4
- package/dist/src/core/attest.js.map +1 -1
- package/dist/src/core/audit.d.ts +510 -0
- package/dist/src/core/audit.js +13 -0
- package/dist/src/core/audit.js.map +1 -1
- package/dist/src/core/budgets.d.ts +238 -0
- package/dist/src/core/channel-owner.d.ts +213 -0
- package/dist/src/core/channel-owner.js +358 -0
- package/dist/src/core/channel-owner.js.map +1 -0
- package/dist/src/core/checkpoint.d.ts +500 -0
- package/dist/src/core/child-env.d.ts +88 -0
- package/dist/src/core/clock.d.ts +52 -0
- package/dist/src/core/command-class.d.ts +697 -0
- package/dist/src/core/command-class.js +713 -25
- package/dist/src/core/command-class.js.map +1 -1
- package/dist/src/core/commit-guard.d.ts +272 -0
- package/dist/src/core/commit-guard.js +424 -0
- package/dist/src/core/commit-guard.js.map +1 -0
- package/dist/src/core/coverage-sources/adapter.d.ts +40 -0
- package/dist/src/core/coverage-sources/gh.d.ts +48 -0
- package/dist/src/core/coverage-sources/git.d.ts +101 -0
- package/dist/src/core/coverage.d.ts +217 -0
- package/dist/src/core/credential-spec.d.ts +72 -0
- package/dist/src/core/daemon-actor.d.ts +45 -0
- package/dist/src/core/daemon-actor.js +54 -0
- package/dist/src/core/daemon-actor.js.map +1 -0
- package/dist/src/core/dark-session.d.ts +432 -0
- package/dist/src/core/dark-session.js +266 -82
- package/dist/src/core/dark-session.js.map +1 -1
- package/dist/src/core/decision-refusal.d.ts +206 -0
- package/dist/src/core/decision-refusal.js +24 -2
- package/dist/src/core/decision-refusal.js.map +1 -1
- package/dist/src/core/env-file.d.ts +455 -0
- package/dist/src/core/env-file.js +60 -1
- package/dist/src/core/env-file.js.map +1 -1
- package/dist/src/core/execute.d.ts +871 -0
- package/dist/src/core/execute.js +59 -8
- package/dist/src/core/execute.js.map +1 -1
- package/dist/src/core/frontmatter.d.ts +78 -0
- package/dist/src/core/gate-window.d.ts +312 -0
- package/dist/src/core/gate.d.ts +1449 -0
- package/dist/src/core/gate.js +149 -14
- package/dist/src/core/gate.js.map +1 -1
- package/dist/src/core/gesture-refusal.d.ts +166 -0
- package/dist/src/core/gesture-refusal.js +188 -0
- package/dist/src/core/gesture-refusal.js.map +1 -0
- package/dist/src/core/git-run.d.ts +73 -0
- package/dist/src/core/harness-version.d.ts +157 -0
- package/dist/src/core/harness-version.js +4 -1
- package/dist/src/core/harness-version.js.map +1 -1
- package/dist/src/core/harness-wait.d.ts +55 -0
- package/dist/src/core/head-retry.d.ts +107 -0
- package/dist/src/core/instance.d.ts +310 -0
- package/dist/src/core/instance.js +113 -0
- package/dist/src/core/instance.js.map +1 -1
- package/dist/src/core/intake-limits.d.ts +247 -0
- package/dist/src/core/jcs.d.ts +52 -0
- package/dist/src/core/journal.d.ts +144 -0
- package/dist/src/core/live-draw.d.ts +436 -0
- package/dist/src/core/log-reconcile.d.ts +89 -0
- package/dist/src/core/log-subscribe.d.ts +36 -0
- package/dist/src/core/log-subscribe.js +162 -0
- package/dist/src/core/log-subscribe.js.map +1 -0
- package/dist/src/core/log.d.ts +316 -0
- package/dist/src/core/log.js.map +1 -1
- package/dist/src/core/loop.d.ts +274 -0
- package/dist/src/core/loop.js +11 -0
- package/dist/src/core/loop.js.map +1 -1
- package/dist/src/core/md-fence.d.ts +41 -0
- package/dist/src/core/money.d.ts +147 -0
- package/dist/src/core/payload-census.d.ts +74 -0
- package/dist/src/core/payload-store.d.ts +175 -0
- package/dist/src/core/payload.d.ts +71 -0
- package/dist/src/core/policy-diff.d.ts +292 -0
- package/dist/src/core/policy-diff.js +27 -4
- package/dist/src/core/policy-diff.js.map +1 -1
- package/dist/src/core/policy-expectations.d.ts +199 -0
- package/dist/src/core/policy-explain.d.ts +160 -0
- package/dist/src/core/policy-explain.js +63 -3
- package/dist/src/core/policy-explain.js.map +1 -1
- package/dist/src/core/policy-load.d.ts +567 -0
- package/dist/src/core/policy-load.js +36 -6
- package/dist/src/core/policy-load.js.map +1 -1
- package/dist/src/core/policy-match.d.ts +324 -0
- package/dist/src/core/policy-match.js +72 -9
- package/dist/src/core/policy-match.js.map +1 -1
- package/dist/src/core/policy-proposal.d.ts +317 -0
- package/dist/src/core/policy-proposal.js +102 -2
- package/dist/src/core/policy-proposal.js.map +1 -1
- package/dist/src/core/prompt-layout.d.ts +221 -0
- package/dist/src/core/protected-path-guard.d.ts +566 -0
- package/dist/src/core/protected-path-guard.js +848 -55
- package/dist/src/core/protected-path-guard.js.map +1 -1
- package/dist/src/core/question-preempted.d.ts +141 -0
- package/dist/src/core/question-preempted.js +152 -0
- package/dist/src/core/question-preempted.js.map +1 -0
- package/dist/src/core/read-scope.d.ts +172 -0
- package/dist/src/core/read-scope.js +252 -0
- package/dist/src/core/read-scope.js.map +1 -0
- package/dist/src/core/registration.d.ts +25 -0
- package/dist/src/core/reindex.d.ts +99 -0
- package/dist/src/core/sampler.d.ts +313 -0
- package/dist/src/core/sandbox.d.ts +371 -0
- package/dist/src/core/sandbox.js +190 -1
- package/dist/src/core/sandbox.js.map +1 -1
- package/dist/src/core/seal.d.ts +165 -0
- package/dist/src/core/sender-identity.d.ts +476 -0
- package/dist/src/core/sender-identity.js +572 -0
- package/dist/src/core/sender-identity.js.map +1 -0
- package/dist/src/core/shlex.d.ts +102 -0
- package/dist/src/core/shlex.js +159 -0
- package/dist/src/core/shlex.js.map +1 -0
- package/dist/src/core/state.d.ts +505 -0
- package/dist/src/core/task-file.d.ts +185 -0
- package/dist/src/core/telegram-config.d.ts +93 -0
- package/dist/src/core/token.d.ts +409 -0
- package/dist/src/core/token.js +21 -38
- package/dist/src/core/token.js.map +1 -1
- package/dist/src/core/validate.d.ts +138 -0
- package/dist/src/core/values.d.ts +147 -0
- package/dist/src/core/values.js +36 -1
- package/dist/src/core/values.js.map +1 -1
- package/dist/src/core/vault.d.ts +291 -0
- package/dist/src/core/verified-snapshot.d.ts +204 -0
- package/dist/src/core/verify.d.ts +336 -0
- package/dist/src/core/version.d.ts +8 -0
- package/dist/src/core/wysiwys.d.ts +370 -0
- package/dist/src/daemon/advance-child.d.ts +39 -0
- package/dist/src/daemon/advance.d.ts +476 -0
- package/dist/src/daemon/advance.js +25 -4
- package/dist/src/daemon/advance.js.map +1 -1
- package/dist/src/daemon/audit.d.ts +87 -0
- package/dist/src/daemon/daemon.d.ts +1180 -0
- package/dist/src/daemon/daemon.js +9 -0
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/dark-session.d.ts +64 -0
- package/dist/src/daemon/draw-child.d.ts +36 -0
- package/dist/src/daemon/draw.d.ts +154 -0
- package/dist/src/daemon/git-evidence.d.ts +173 -0
- package/dist/src/daemon/git-evidence.js +1 -1
- package/dist/src/daemon/projection.d.ts +180 -0
- package/dist/src/daemon/prune.d.ts +207 -0
- package/dist/src/mcp/http.d.ts +113 -0
- package/dist/src/mcp/server.d.ts +265 -0
- package/dist/src/mcp/server.js +17 -1
- package/dist/src/mcp/server.js.map +1 -1
- package/docs/adapter-api.md +106 -0
- package/docs/cli-reference.md +1316 -63
- package/docs/codex-enforced-session.md +103 -0
- package/docs/codex-workspace-broker.md +118 -0
- package/package.json +14 -2
- package/schema/codex-instance.schema.json +82 -0
- package/schema/event.schema.json +539 -9
- package/schema/fixtures/codex-instance/invalid/unpinned-codex-version.json +40 -0
- package/schema/fixtures/codex-instance/valid/canonical.json +40 -0
- package/schema/fixtures/event/invalid/approval-granted-sender-hashed-false.json +20 -0
- package/schema/fixtures/event/invalid/approval-granted-sender-hashed-raw-id.json +20 -0
- package/schema/fixtures/event/invalid/audit-gesture-refused-human-actor.json +16 -0
- package/schema/fixtures/event/invalid/audit-gesture-refused-no-actor-no-sender.json +15 -0
- package/schema/fixtures/event/invalid/audit-gesture-refused-unknown-gesture.json +16 -0
- package/schema/fixtures/event/invalid/audit-question-preempted-agent-actor.json +16 -0
- package/schema/fixtures/event/invalid/audit-question-preempted-no-question-id.json +16 -0
- package/schema/fixtures/event/invalid/audit-question-preempted-unknown-source.json +15 -0
- package/schema/fixtures/event/invalid/gate-path-signed-off-absolute-path.json +14 -0
- package/schema/fixtures/event/invalid/gate-path-signed-off-agent-actor.json +14 -0
- package/schema/fixtures/event/invalid/gate-path-signed-off-missing-path.json +13 -0
- package/schema/fixtures/event/valid/approval-granted-sender-hashed.json +20 -0
- package/schema/fixtures/event/valid/audit-gesture-refused-review-note.json +21 -0
- package/schema/fixtures/event/valid/audit-gesture-refused-sender-key-unavailable.json +19 -0
- package/schema/fixtures/event/valid/audit-gesture-refused.json +19 -0
- package/schema/fixtures/event/valid/audit-question-preempted-no-verdict.json +16 -0
- package/schema/fixtures/event/valid/audit-question-preempted.json +20 -0
- package/schema/fixtures/event/valid/gate-path-signed-off.json +14 -0
- package/schema/fixtures/event/valid/harness-kind-claude-code.json +23 -0
- package/schema/fixtures/event/valid/harness-kind-codex.json +23 -0
- package/schema/fixtures/event/valid/harness-kind-cursor.json +23 -0
- package/schema/fixtures/event/valid/harness-kind-grok.json +23 -0
- package/schema/fixtures/event/valid/harness-kind-muse.json +23 -0
- package/schema/fixtures/policy/invalid/senders-half-keyed.json +20 -0
- package/schema/fixtures/policy/valid/canonical.json +1 -1
- package/schema/fixtures/policy/valid/senders-keyed.json +24 -0
- package/schema/fixtures/policy-md/valid/canonical.md +1 -1
- package/schema/fixtures/policy-md/valid/with-values.md +5 -7
- package/schema/fixtures/values/invalid/class-shaped.json +1 -1
- package/schema/fixtures/values/invalid/duplicate-entry.json +1 -1
- package/schema/fixtures/values/invalid/non-string-item.json +1 -1
- package/schema/fixtures/values/invalid/over-cap.json +1 -1
- package/schema/fixtures/values/invalid/unknown-key.json +1 -1
- package/schema/fixtures/values/invalid/version-float.json +1 -0
- package/schema/fixtures/values/invalid/version-integer.json +1 -0
- package/schema/fixtures/values/invalid/version-wrong-string.json +1 -0
- package/schema/fixtures/values/valid/empty-lists.json +2 -3
- package/schema/fixtures/values/valid/full.json +5 -7
- package/schema/fixtures/values/valid/minimal.json +1 -1
- package/schema/fixtures/values-md/invalid/schema-invalid.md +5 -3
- package/schema/fixtures/values-md/invalid/two-blocks.md +3 -3
- package/schema/fixtures/values-md/invalid/unterminated.md +2 -2
- package/schema/fixtures/values-md/invalid/version-1.md +69 -0
- package/schema/fixtures/values-md/invalid/version-unquoted.md +64 -0
- package/schema/fixtures/values-md/invalid/yaml-error.md +2 -2
- package/schema/fixtures/values-md/valid/absent.md +1 -1
- package/schema/fixtures/values-md/valid/with-values.md +5 -7
- package/schema/policy.schema.json +75 -3
- package/schema/values.schema.json +7 -11
- package/templates/codex/README.md +9 -0
- package/schema/fixtures/values/invalid/version-string.json +0 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-event git commits — SPEC.md §8's optional hardening (APRV-42).
|
|
3
|
+
*
|
|
4
|
+
* > "Optionally, the log directory is a git repo and the daemon commits per
|
|
5
|
+
* > event with its own identity, giving signed, distributed tamper evidence for
|
|
6
|
+
* > free."
|
|
7
|
+
*
|
|
8
|
+
* The chain in `events.jsonl` already detects mutation and truncation on its
|
|
9
|
+
* own. What a git repository adds is a *second, independent* record of the same
|
|
10
|
+
* bytes: a mutation that is plausible against one layer has to be plausible
|
|
11
|
+
* against the other at the same time, and the second layer is one an operator
|
|
12
|
+
* can clone, mirror, and diff from somewhere the tamperer does not control.
|
|
13
|
+
* Neither layer is trusted to police the other, which is the point of having
|
|
14
|
+
* two: `approval log verify` never consults git, and nothing here ever reads a
|
|
15
|
+
* verdict out of a commit.
|
|
16
|
+
*
|
|
17
|
+
* ## Opt-in, and only for a standalone log deployment
|
|
18
|
+
*
|
|
19
|
+
* This is off unless the operator asks for it, and refuses to turn on unless the
|
|
20
|
+
* log's own directory is a repository *root*. The two layouts do not mix:
|
|
21
|
+
*
|
|
22
|
+
* - **Standalone log deployment.** The log home (`.approval/`, or whatever
|
|
23
|
+
* directory holds the log when it is not under a `log/` folder) is its own git
|
|
24
|
+
* repository, containing the log, the payload store, and nothing else. Enable
|
|
25
|
+
* the opt-in here.
|
|
26
|
+
* - **Nested project layout** — this repository's own dogfood arrangement, where
|
|
27
|
+
* `.approval/` is committed as part of a larger project repo. Perfectly valid,
|
|
28
|
+
* and the opt-in is REFUSED for it.
|
|
29
|
+
*
|
|
30
|
+
* Why refuse the nested case rather than make it work? Because a hash chain does
|
|
31
|
+
* not survive a merge. Two branches that each append independently produce a
|
|
32
|
+
* chain that is corrupt by construction, and no merge strategy repairs the
|
|
33
|
+
* semantics. An outer repository's ordinary history operations — rebase, amend,
|
|
34
|
+
* squash, force-push, `filter-branch` — rewrite the very bytes the evidence is
|
|
35
|
+
* made of, and a daemon committing into someone else's branch would be a second
|
|
36
|
+
* writer to a history the project's humans also write. Evidence that the subject
|
|
37
|
+
* of the investigation can rewrite is not evidence. So the runtime does not try
|
|
38
|
+
* to be clever about it: own-root repository, or no git evidence at all.
|
|
39
|
+
*
|
|
40
|
+
* ## What it does, precisely
|
|
41
|
+
*
|
|
42
|
+
* After every tick in which the log moved, the daemon calls {@link
|
|
43
|
+
* GitEvidenceRecorder.commit} with the verified head it just read. The recorder
|
|
44
|
+
* stages the log file and the payload store, and commits with a message naming
|
|
45
|
+
* the head's `(seq, hash)`. Batching is **one commit per tick**, not literally
|
|
46
|
+
* one per event: ticks are the only moment the daemon has a verified head in
|
|
47
|
+
* hand, and a commit is only meaningful against a head that verified. A tick
|
|
48
|
+
* that observed three appends produces one commit naming the new head and the
|
|
49
|
+
* number of records it covers — the intermediate states are still fully
|
|
50
|
+
* recoverable from the log itself, which is the artifact being witnessed.
|
|
51
|
+
*
|
|
52
|
+
* ## What it deliberately does not do
|
|
53
|
+
*
|
|
54
|
+
* It never pushes, never fetches, never creates or moves a branch by name, never
|
|
55
|
+
* touches a remote, and never writes to any git config outside the single
|
|
56
|
+
* `git commit` invocation (identity is passed with `-c`, per command, so the
|
|
57
|
+
* operator's `user.name` is neither read into the commit nor overwritten on
|
|
58
|
+
* disk). Commits are local, to the log's own repository, authored by the daemon
|
|
59
|
+
* as itself. A failure to commit is a warning, never a stop: git evidence is
|
|
60
|
+
* hardening on top of the chain, and a daemon that halted approvals because a
|
|
61
|
+
* disk was full of git objects would have converted a redundancy into a
|
|
62
|
+
* dependency.
|
|
63
|
+
*/
|
|
64
|
+
import type { LogHead } from "../core/log.js";
|
|
65
|
+
/**
|
|
66
|
+
* The daemon's own git identity. Never the operator's: a commit that says a
|
|
67
|
+
* human made it is a false statement about who wrote the evidence, and the whole
|
|
68
|
+
* value of the second layer is that its authorship is unambiguous.
|
|
69
|
+
*
|
|
70
|
+
* The version is pinned to `package.json` by a test rather than read at runtime,
|
|
71
|
+
* because a module that resolves its own package root differs between the source
|
|
72
|
+
* tree and the build output for no benefit at all.
|
|
73
|
+
*/
|
|
74
|
+
export declare const APPROVALD_VERSION = "0.3.0";
|
|
75
|
+
/** `user.name` on every commit this module makes. */
|
|
76
|
+
export declare const GIT_EVIDENCE_AUTHOR_NAME = "approvald 0.3.0";
|
|
77
|
+
/** `user.email` on every commit: fixed, and deliberately undeliverable. */
|
|
78
|
+
export declare const GIT_EVIDENCE_AUTHOR_EMAIL = "approvald@noreply.approval.md";
|
|
79
|
+
/**
|
|
80
|
+
* Why enabling git evidence was refused. **Frozen union**, additive-only, in the
|
|
81
|
+
* same sense as every other refusal vocabulary in this codebase (SPEC.md §11.1
|
|
82
|
+
* invariant 6: refusals are machine-readable and distinct). An operator's
|
|
83
|
+
* supervisor branches on these to tell "install git" apart from "your layout is
|
|
84
|
+
* wrong", and the repair differs for every one of them.
|
|
85
|
+
*/
|
|
86
|
+
export declare const GIT_EVIDENCE_REFUSAL_CODES: readonly [
|
|
87
|
+
/** No usable `git` on PATH. The daemon runs fine without the opt-in. */
|
|
88
|
+
"git-unavailable",
|
|
89
|
+
/** The directory that would hold the evidence repository does not exist. */
|
|
90
|
+
"log-dir-missing",
|
|
91
|
+
/** It exists and is not a git repository. The repair is `git init` there. */
|
|
92
|
+
"log-dir-not-repo",
|
|
93
|
+
/**
|
|
94
|
+
* It is inside a working tree it does not own — either some outer repository
|
|
95
|
+
* tracks it, or it is a repository whose root is somewhere above. Hash chains
|
|
96
|
+
* do not survive merges and an outer history rewrites evidence.
|
|
97
|
+
*/
|
|
98
|
+
"log-dir-nested"];
|
|
99
|
+
export type GitEvidenceRefusalCode = (typeof GIT_EVIDENCE_REFUSAL_CODES)[number];
|
|
100
|
+
export interface GitEvidenceRefusal {
|
|
101
|
+
ok: false;
|
|
102
|
+
code: GitEvidenceRefusalCode;
|
|
103
|
+
message: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* One line of git-evidence output. Its own frozen shape, reported through the
|
|
107
|
+
* callback the CLI supplies, so that `daemon/daemon.ts`'s event union stays
|
|
108
|
+
* exactly as it was: the hardening layer speaks for itself and the loop's
|
|
109
|
+
* contract is untouched.
|
|
110
|
+
*/
|
|
111
|
+
export type GitEvidenceEvent = {
|
|
112
|
+
event: "git_evidence";
|
|
113
|
+
/** The abbreviated commit this tick produced. */
|
|
114
|
+
commit: string;
|
|
115
|
+
/** The verified head the commit witnesses. */
|
|
116
|
+
seq: number;
|
|
117
|
+
hash: string;
|
|
118
|
+
/**
|
|
119
|
+
* Log lines added since the commit this one builds on — the batch size.
|
|
120
|
+
* The log is append-only, so a line is a record. `null` only when git
|
|
121
|
+
* declined to say, which is a reporting gap and never a correctness one.
|
|
122
|
+
*/
|
|
123
|
+
records: number | null;
|
|
124
|
+
} | {
|
|
125
|
+
event: "git_evidence_failed";
|
|
126
|
+
/** The git invocation that failed, as a bare subcommand name. */
|
|
127
|
+
step: string;
|
|
128
|
+
message: string;
|
|
129
|
+
};
|
|
130
|
+
/** Where git-evidence output goes. Injected, so this module writes to nothing. */
|
|
131
|
+
export type GitEvidenceSink = (event: GitEvidenceEvent) => void;
|
|
132
|
+
/**
|
|
133
|
+
* The hook the daemon calls. One method, taking the verified head of the log it
|
|
134
|
+
* just read, so that the loop's edit is a single line and no scheduling
|
|
135
|
+
* knowledge leaks into this file.
|
|
136
|
+
*/
|
|
137
|
+
export interface GitEvidenceRecorder {
|
|
138
|
+
commit(head: LogHead | null): void;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The directory that must be the evidence repository's root, for a given log.
|
|
142
|
+
*
|
|
143
|
+
* The same rule `payloadStoreDirFor` uses, for the same reason: SPEC.md §9 fixes
|
|
144
|
+
* the log at `<home>/log/events.jsonl` and the payload store at
|
|
145
|
+
* `<home>/payloads/`, so the only directory that contains *both* is `<home>`.
|
|
146
|
+
* Rooting the repository at the log's immediate directory would leave every
|
|
147
|
+
* payload file outside the evidence, which is precisely where a tamperer would
|
|
148
|
+
* then work. When a caller points `--log` somewhere flatter, the log's own
|
|
149
|
+
* directory is the home and the rule still holds.
|
|
150
|
+
*/
|
|
151
|
+
export declare function evidenceRootFor(logPath: string): string;
|
|
152
|
+
export type EnableGitEvidenceResult = {
|
|
153
|
+
ok: true;
|
|
154
|
+
root: string;
|
|
155
|
+
recorder: GitEvidenceRecorder;
|
|
156
|
+
} | GitEvidenceRefusal;
|
|
157
|
+
/**
|
|
158
|
+
* Check every precondition and, when they all hold, build the recorder.
|
|
159
|
+
*
|
|
160
|
+
* Fail closed and fail *loudly*: each refusal is distinct, names the directory
|
|
161
|
+
* it judged, and states the repair. An operator who mistyped `--log` and an
|
|
162
|
+
* operator whose log lives inside a project repository need different sentences,
|
|
163
|
+
* and a single "git evidence unavailable" would have sent both of them looking
|
|
164
|
+
* in the wrong place.
|
|
165
|
+
*/
|
|
166
|
+
export declare function enableGitEvidence(logPath: string, sink: GitEvidenceSink): EnableGitEvidenceResult;
|
|
167
|
+
/**
|
|
168
|
+
* The commit message: the head's `(seq, hash)` on the subject line, so a reader
|
|
169
|
+
* of `git log --oneline` can check a commit against the chain without opening
|
|
170
|
+
* anything, and the batch size in the body so the per-tick batching is visible
|
|
171
|
+
* rather than inferred.
|
|
172
|
+
*/
|
|
173
|
+
export declare function message(head: LogHead, records: number | null): string;
|
|
@@ -75,7 +75,7 @@ import { PAYLOAD_STORE_DIRNAME } from "../core/payload-store.js";
|
|
|
75
75
|
* because a module that resolves its own package root differs between the source
|
|
76
76
|
* tree and the build output for no benefit at all.
|
|
77
77
|
*/
|
|
78
|
-
export const APPROVALD_VERSION = "0.
|
|
78
|
+
export const APPROVALD_VERSION = "0.3.0";
|
|
79
79
|
/** `user.name` on every commit this module makes. */
|
|
80
80
|
export const GIT_EVIDENCE_AUTHOR_NAME = `approvald ${APPROVALD_VERSION}`;
|
|
81
81
|
/** `user.email` on every commit: fixed, and deliberately undeliverable. */
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The daemon's pure projections (SPEC.md §6.3, §10.2).
|
|
3
|
+
*
|
|
4
|
+
* Everything the daemon *decides* lives here, and everything it *does* lives in
|
|
5
|
+
* `daemon.ts`. The split is the same one `core/loop.ts` draws for loop safety:
|
|
6
|
+
* a projection over verified records is a pure function of (records, instant,
|
|
7
|
+
* TTL), so it can be replayed, unit-tested against an injected clock, and never
|
|
8
|
+
* disagrees with itself between two callers.
|
|
9
|
+
*
|
|
10
|
+
* Nothing here reads the clock, the filesystem, or the network, and nothing
|
|
11
|
+
* here appends. Three questions are answered:
|
|
12
|
+
*
|
|
13
|
+
* 1. **What does the log say a task's envelope `state:` should be?**
|
|
14
|
+
* {@link taskEnvelopeState}. §6.3: "`state` is a projection of log events;
|
|
15
|
+
* the file is updated by the daemon after the event is appended, never the
|
|
16
|
+
* reverse." The daemon compares the file's claim against this answer, and a
|
|
17
|
+
* file that contradicts it is `envelope.drift`.
|
|
18
|
+
* 2. **Which live requests have lapsed with no `approval.expired` on record?**
|
|
19
|
+
* {@link lapsedRequests}. The gate already judges TTL lazily at decision
|
|
20
|
+
* time (a late grant is refused whether or not an expiry event exists), so
|
|
21
|
+
* the sweep changes no verdict; it makes the verdict *visible* in the log
|
|
22
|
+
* and in every projection built from it.
|
|
23
|
+
* 3. **Has this exact drift already been recorded?** {@link driftAlreadyLogged}.
|
|
24
|
+
* A watcher fires on every save and the periodic tick re-scans regardless,
|
|
25
|
+
* so without a dedupe rule one unfixed file would append an unbounded run of
|
|
26
|
+
* identical events. The rule is stated on that function.
|
|
27
|
+
*
|
|
28
|
+
* The state derivation itself is NOT reimplemented here: every action's state
|
|
29
|
+
* comes from `core/state.ts`'s `requestState`, the same derivation the gate,
|
|
30
|
+
* the token module, and the executor read. This module only rolls action states
|
|
31
|
+
* up to the task level, and that rollup is the one new rule it owns.
|
|
32
|
+
*/
|
|
33
|
+
import type { EventRecord } from "../core/log.js";
|
|
34
|
+
import { type RequestDerivation } from "../core/state.js";
|
|
35
|
+
/**
|
|
36
|
+
* The envelope's `state:` vocabulary (`envelope.schema.json`, SPEC.md §6.3).
|
|
37
|
+
*
|
|
38
|
+
* Spelled here rather than imported from the schema because the schema is data
|
|
39
|
+
* read at runtime and this is a type; `tests/daemon-projection.test.ts` pins the
|
|
40
|
+
* two against each other so they cannot drift apart.
|
|
41
|
+
*/
|
|
42
|
+
export declare const ENVELOPE_STATES: readonly ["proposed", "awaiting", "approved", "executed", "rejected", "expired", "revoked"];
|
|
43
|
+
export type EnvelopeState = (typeof ENVELOPE_STATES)[number];
|
|
44
|
+
/** Is this the envelope's `state:` value? Used to read an untrusted file. */
|
|
45
|
+
export declare function isEnvelopeState(value: unknown): value is EnvelopeState;
|
|
46
|
+
/** One declared action of a task, as the log records it, with its derived state. */
|
|
47
|
+
export interface ActionProjection {
|
|
48
|
+
actionKey: string;
|
|
49
|
+
derivation: RequestDerivation;
|
|
50
|
+
}
|
|
51
|
+
/** What the log says about one task. */
|
|
52
|
+
export interface TaskProjection {
|
|
53
|
+
task: string;
|
|
54
|
+
/** A `task.registered` record exists for this task id. */
|
|
55
|
+
registered: boolean;
|
|
56
|
+
/** The envelope `state:` the log implies (SPEC.md §6.3). */
|
|
57
|
+
state: EnvelopeState;
|
|
58
|
+
/** Every action key the latest registration declared, with its derivation. */
|
|
59
|
+
actions: ActionProjection[];
|
|
60
|
+
}
|
|
61
|
+
/** Every action key the latest `task.registered` for `task` declared, in order. */
|
|
62
|
+
export declare function registeredActionKeys(records: EventRecord[], task: string): string[];
|
|
63
|
+
/**
|
|
64
|
+
* The envelope `state:` the log implies for `task`, at instant `ts`.
|
|
65
|
+
*
|
|
66
|
+
* ## The rollup rule, stated once
|
|
67
|
+
*
|
|
68
|
+
* §6.3's lifecycle is drawn for one action; a task may declare several, so the
|
|
69
|
+
* projection needs a rule for a task whose actions disagree. It is this, in
|
|
70
|
+
* order, and the order is the point:
|
|
71
|
+
*
|
|
72
|
+
* 1. any action with a live request → **awaiting**. A human owes an answer, and
|
|
73
|
+
* that fact outranks every other, because it is the only state that asks
|
|
74
|
+
* something of a person.
|
|
75
|
+
* 2. else any granted action that has not executed → **approved**.
|
|
76
|
+
* 3. else any action with an `execution.completed` → **executed**.
|
|
77
|
+
* 4. else **revoked**, then **rejected**, then **expired** — human decisions
|
|
78
|
+
* outrank a runtime lapse, so a task with one revoked and one expired action
|
|
79
|
+
* reads as revoked, naming the decision a person actually made.
|
|
80
|
+
* 5. else **proposed**: registered (or not) and nothing has happened.
|
|
81
|
+
*
|
|
82
|
+
* A task with exactly one action — the common case — collapses to §6.3's
|
|
83
|
+
* lifecycle exactly, which is the property the rule was chosen for.
|
|
84
|
+
*
|
|
85
|
+
* An unregistered task projects to `proposed`: the log knows of no declaration,
|
|
86
|
+
* so nothing has been proposed *to the gate* yet. A file claiming `approved`
|
|
87
|
+
* for a task the log never registered therefore contradicts the log, which is
|
|
88
|
+
* exactly the reading §6.3 wants.
|
|
89
|
+
*/
|
|
90
|
+
export declare function taskEnvelopeState(records: EventRecord[], task: string, ts: string, ttlMs: number | null): TaskProjection;
|
|
91
|
+
/** One request the TTL sweep would materialise an `approval.expired` for. */
|
|
92
|
+
export interface LapsedRequest {
|
|
93
|
+
actionKey: string;
|
|
94
|
+
task: string | null;
|
|
95
|
+
/** The `ts` of the `approval.requested` that lapsed. */
|
|
96
|
+
requestedTs: string | null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Live requests whose TTL has lapsed and which carry no `approval.expired`.
|
|
100
|
+
*
|
|
101
|
+
* Idempotence is structural rather than remembered: the answer is re-derived
|
|
102
|
+
* from the verified log every sweep, and an action whose expiry has been
|
|
103
|
+
* appended no longer satisfies the predicate. Two sweeps over the same log
|
|
104
|
+
* therefore produce the same list, and a sweep that follows a successful one
|
|
105
|
+
* produces an empty list — with no state carried between them, and no way for a
|
|
106
|
+
* restarted daemon to expire something twice.
|
|
107
|
+
*
|
|
108
|
+
* `ttlMs === null` (a policy that declares no `defaults.approval_ttl`) yields no
|
|
109
|
+
* candidates at all: nothing lapses when nothing was bounded, and inventing a
|
|
110
|
+
* deadline is not the daemon's to invent.
|
|
111
|
+
*
|
|
112
|
+
* Returned in first-request order, so a sweep's appends land in a deterministic
|
|
113
|
+
* sequence.
|
|
114
|
+
*/
|
|
115
|
+
export declare function lapsedRequests(records: EventRecord[], ts: string, ttlMs: number | null): LapsedRequest[];
|
|
116
|
+
/**
|
|
117
|
+
* Why an `envelope.drift` record was written (APRV-63).
|
|
118
|
+
*
|
|
119
|
+
* `state-mismatch` is the original reading of SPEC.md §6.3: the file makes a
|
|
120
|
+
* claim about `state:` and the log implies another one. `envelope-missing` is
|
|
121
|
+
* the loss case observed live in APRV-60: the log holds a `task.registered` for
|
|
122
|
+
* the task, and the file that declared it now carries no `approval:` key at all.
|
|
123
|
+
* They are separated because they call for different human actions — one is an
|
|
124
|
+
* edit to reconcile, the other is a *deletion to restore* — and a reader who
|
|
125
|
+
* could not tell them apart would treat a lost envelope as a stale one.
|
|
126
|
+
*
|
|
127
|
+
* `reason` is absent from records written before this vocabulary existed;
|
|
128
|
+
* readers (including {@link driftAlreadyLogged}) treat absence as
|
|
129
|
+
* `state-mismatch`, which is what every such record was.
|
|
130
|
+
*/
|
|
131
|
+
export declare const DRIFT_REASONS: readonly ["state-mismatch", "envelope-missing"];
|
|
132
|
+
export type DriftReason = (typeof DRIFT_REASONS)[number];
|
|
133
|
+
export { latestRegistration } from "../core/registration.js";
|
|
134
|
+
/** The facts one `envelope.drift` record carries, and the dedupe key. */
|
|
135
|
+
export interface DriftFacts {
|
|
136
|
+
/** The `state:` the file claims, or `null` when it declares none. */
|
|
137
|
+
declaredState: string | null;
|
|
138
|
+
/** The state the log implies (SPEC.md §6.3). */
|
|
139
|
+
derivedState: EnvelopeState;
|
|
140
|
+
/**
|
|
141
|
+
* SHA-256 over the RFC 8785 form of the file's whole `approval:` envelope, or
|
|
142
|
+
* `null` when the envelope could not be canonicalized. Part of the dedupe key
|
|
143
|
+
* so that editing a file from one contradiction into a different one is a new
|
|
144
|
+
* drift and not a suppressed one.
|
|
145
|
+
*/
|
|
146
|
+
envelopeDigest: string | null;
|
|
147
|
+
/**
|
|
148
|
+
* Which kind of drift this is (APRV-63). Part of the dedupe key: a file that
|
|
149
|
+
* contradicts the log and a file that lost its envelope are different facts
|
|
150
|
+
* about the same task, and neither may suppress the other. Absent means
|
|
151
|
+
* `state-mismatch`, matching every record written before the vocabulary
|
|
152
|
+
* existed.
|
|
153
|
+
*/
|
|
154
|
+
reason?: DriftReason;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Has this exact drift already been recorded for `task`?
|
|
158
|
+
*
|
|
159
|
+
* The rule: compare against the **latest** `envelope.drift` for the task. Equal
|
|
160
|
+
* `(reason, declared_state, derived_state, envelope_sha256)` means the situation
|
|
161
|
+
* the log already describes is the situation now, so nothing is appended. Any
|
|
162
|
+
* difference
|
|
163
|
+
* — the human edited the file again, or the log moved and the derived state
|
|
164
|
+
* changed — is a new fact and is recorded.
|
|
165
|
+
*
|
|
166
|
+
* Comparing against the latest record rather than against any record is
|
|
167
|
+
* deliberate: a task that drifts, is repaired, and drifts the same way again has
|
|
168
|
+
* genuinely drifted twice, and an audit that collapsed those into one would be
|
|
169
|
+
* hiding a repetition from the person whose attention this system spends.
|
|
170
|
+
*
|
|
171
|
+
* For `envelope-missing` (APRV-63) the same rule reads as: one record per
|
|
172
|
+
* episode of loss, re-derived every tick from the file and the log rather than
|
|
173
|
+
* remembered, and a new record when the derived state moves underneath a file
|
|
174
|
+
* that is still stripped. Its limit is stated where it is felt: a file whose
|
|
175
|
+
* envelope is restored by hand *in agreement with the log* leaves no record of
|
|
176
|
+
* the restoration, so a second loss at the same derived state reads as the same
|
|
177
|
+
* episode and is not appended twice. Recording the restoration would need an
|
|
178
|
+
* event nobody has specified; detection does not invent one.
|
|
179
|
+
*/
|
|
180
|
+
export declare function driftAlreadyLogged(records: EventRecord[], task: string, facts: DriftFacts): boolean;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload retention pruning — the enforcement half of amended SPEC.md §5.2
|
|
3
|
+
* (APRV-38's vocabulary, APRV-41's daemon).
|
|
4
|
+
*
|
|
5
|
+
* > "A payload is prunable once the action it is bound to has been in a terminal
|
|
6
|
+
* > state (`executed`, `rejected`, `expired`, `revoked`) for longer than the
|
|
7
|
+
* > duration. A payload whose action is not terminal is never prunable, at any
|
|
8
|
+
* > age […]. Orphaned payloads (bytes with no recorded binding) are prunable
|
|
9
|
+
* > regardless of the key. […] Pruning is performed by the daemon and by nothing
|
|
10
|
+
* > else, and each removal appends a `payload.pruned` event, so a log states what
|
|
11
|
+
* > its store no longer holds."
|
|
12
|
+
*
|
|
13
|
+
* ## Write-ahead, always in that order
|
|
14
|
+
*
|
|
15
|
+
* For every file this module removes, the `payload.pruned` event lands in the
|
|
16
|
+
* log **first** and the `unlink` follows. The ordering is the whole design: a
|
|
17
|
+
* crash between the two leaves a file on disk that the log already says is gone,
|
|
18
|
+
* which the next tick completes by unlinking it and appending nothing further
|
|
19
|
+
* ({@link PrunePlan.completions}). The opposite order would leave the other
|
|
20
|
+
* failure — bytes deleted with no record of the deletion — which is the one
|
|
21
|
+
* outcome a store holding the material evidence of what a human approved cannot
|
|
22
|
+
* afford. Deleting evidence is acceptable; deleting it silently is not.
|
|
23
|
+
*
|
|
24
|
+
* Idempotence needs no remembered state: a hash that already carries a
|
|
25
|
+
* `payload.pruned` event is never given a second one, and the plan is re-derived
|
|
26
|
+
* from the verified log on every tick.
|
|
27
|
+
*
|
|
28
|
+
* ## Terminal time comes from the log, never from the filesystem
|
|
29
|
+
*
|
|
30
|
+
* The clock that decides whether retention has elapsed reads the timestamp of the
|
|
31
|
+
* event that made the action terminal (`execution.completed`, `approval.rejected`,
|
|
32
|
+
* `approval.revoked`, `approval.expired`). File mtimes are not evidence: they are
|
|
33
|
+
* rewritten by a copy, a checkout, a backup restore, or an `rsync`, and pruning on
|
|
34
|
+
* them would let a routine filesystem operation decide when approval evidence
|
|
35
|
+
* disappears.
|
|
36
|
+
*
|
|
37
|
+
* A **lazily** expired request (the TTL has arithmetically lapsed but no
|
|
38
|
+
* `approval.expired` record exists) is deliberately not terminal here. The
|
|
39
|
+
* daemon's own TTL sweep appends that event on the same tick; the payload becomes
|
|
40
|
+
* prunable once the log says so, and retention is then measured from the recorded
|
|
41
|
+
* moment rather than from one this module computed for itself.
|
|
42
|
+
*
|
|
43
|
+
* `execution.failed` is likewise not terminal: a failed action may be retried
|
|
44
|
+
* against the very bytes in question, and loop escalation (SPEC.md §10.2) exists
|
|
45
|
+
* precisely because failures recur.
|
|
46
|
+
*
|
|
47
|
+
* ## The orphan rule, resolved conservatively (flagged for review)
|
|
48
|
+
*
|
|
49
|
+
* §5.2 says orphaned payloads are "prunable regardless of the key", which reads
|
|
50
|
+
* as though orphans could be swept even with `payload_retention` absent. APRV-41's
|
|
51
|
+
* acceptance criteria say the absent key means no pruning at all. This module
|
|
52
|
+
* takes the strictest reading that satisfies both:
|
|
53
|
+
*
|
|
54
|
+
* - **`payload_retention` absent: the pruning subsystem does not run.** Nothing is
|
|
55
|
+
* deleted, orphan or not, and no `payload.pruned` is appended. Retention is an
|
|
56
|
+
* operator's explicit choice to forget, and an operator who never made it never
|
|
57
|
+
* asked this runtime to delete anything.
|
|
58
|
+
* - **`payload_retention` present: orphans are prunable at any age**, which is
|
|
59
|
+
* what "regardless of the key" then means — the duration governs bound payloads
|
|
60
|
+
* and does not gate residue nothing ever bound.
|
|
61
|
+
*
|
|
62
|
+
* An orphan is a file whose hash appears in **no** log record other than a
|
|
63
|
+
* `payload.pruned` (head-moved residue: the gate stored the bytes, its append was
|
|
64
|
+
* refused, and no request ever declared them). A hash mentioned by any other
|
|
65
|
+
* record is bound, and a binding this module cannot attribute to an action key is
|
|
66
|
+
* treated as live rather than as an orphan — fail closed in both directions.
|
|
67
|
+
*
|
|
68
|
+
* ## Nothing else here decides anything
|
|
69
|
+
*
|
|
70
|
+
* Which hashes the log already binds, and which it already says are pruned, is
|
|
71
|
+
* `core/payload-census.ts`'s — the same computation the reporting surfaces read,
|
|
72
|
+
* so what a reader is shown and what this module would delete can never drift
|
|
73
|
+
* apart. Approval state per action is `core/state.ts`'s `requestState`; the append is
|
|
74
|
+
* `core/log.ts`'s `appendEvent` with `expectedHead` (compare-and-append, SPEC.md
|
|
75
|
+
* §11.1 invariant 5); the unlink is `core/payload-store.ts`'s. The timestamp on
|
|
76
|
+
* every `payload.pruned` is the runtime's, read from the injected clock at the
|
|
77
|
+
* write boundary, and the actor is `system:daemon` — a party under oversight must
|
|
78
|
+
* never be able to author either.
|
|
79
|
+
*/
|
|
80
|
+
import { type Clock } from "../core/clock.js";
|
|
81
|
+
import { type EventRecord } from "../core/log.js";
|
|
82
|
+
/**
|
|
83
|
+
* SPEC.md §8 and `event.schema.json`: `payload.pruned` carries a `system:` actor.
|
|
84
|
+
* Declared here rather than imported from `daemon.ts` so the pruner has no
|
|
85
|
+
* dependency on the loop that calls it.
|
|
86
|
+
*/
|
|
87
|
+
export declare const PRUNE_ACTOR = "system:daemon";
|
|
88
|
+
/** The terminal states of amended SPEC.md §5.2, and nothing beyond them. */
|
|
89
|
+
export type TerminalState = "executed" | "rejected" | "revoked" | "expired";
|
|
90
|
+
/** Why a payload is prunable. Mirrors `payload.pruned`'s `reason`. */
|
|
91
|
+
export type PruneReason = "payload_retention" | "orphaned";
|
|
92
|
+
/** One file the plan says may go, and the evidence for saying so. */
|
|
93
|
+
export interface PruneCandidate {
|
|
94
|
+
hash: string;
|
|
95
|
+
reason: PruneReason;
|
|
96
|
+
/** The action whose terminal state released the bytes; `null` for an orphan. */
|
|
97
|
+
actionKey: string | null;
|
|
98
|
+
task: string | null;
|
|
99
|
+
terminalState: TerminalState | null;
|
|
100
|
+
/** The `ts` of the event that made it terminal; retention is measured from it. */
|
|
101
|
+
terminalTs: string | null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* What one tick would do.
|
|
105
|
+
*
|
|
106
|
+
* `completions` are hashes whose `payload.pruned` is already in the log while the
|
|
107
|
+
* file is still on disk — a crash between the append and the unlink, or a store
|
|
108
|
+
* that was restored from a backup taken before the prune. They are unlinked and
|
|
109
|
+
* **no second event is appended**: the log already states the fact.
|
|
110
|
+
*/
|
|
111
|
+
export interface PrunePlan {
|
|
112
|
+
candidates: PruneCandidate[];
|
|
113
|
+
completions: string[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* What may be pruned right now. Pure: no I/O, no clock, no policy loading.
|
|
117
|
+
*
|
|
118
|
+
* `retentionMs` is `null` when the policy declares no `payload_retention` — or
|
|
119
|
+
* when the policy could not be loaded at all, which fails closed to the same
|
|
120
|
+
* answer. Either way the plan is empty: the subsystem does not run.
|
|
121
|
+
*
|
|
122
|
+
* `nowIso` is the evaluation moment, injected. A pruner that read the clock
|
|
123
|
+
* itself could not be replayed, and retention arithmetic that cannot be replayed
|
|
124
|
+
* cannot be audited.
|
|
125
|
+
*/
|
|
126
|
+
export declare function planPrune(records: EventRecord[], presentHashes: string[], nowIso: string, retentionMs: number | null): PrunePlan;
|
|
127
|
+
/** Why a prune pass complained. Reported to the caller; never thrown. */
|
|
128
|
+
export type PruneWarningCode =
|
|
129
|
+
/** The verified read refused, so nothing was planned this pass. */
|
|
130
|
+
"log-unreadable"
|
|
131
|
+
/** A `payload.pruned` append was refused; the file stays, untouched. */
|
|
132
|
+
| "append-refused"
|
|
133
|
+
/** The event landed but the file could not be removed. The next tick retries. */
|
|
134
|
+
| "unlink-failed";
|
|
135
|
+
export interface PruneWarning {
|
|
136
|
+
code: PruneWarningCode;
|
|
137
|
+
message: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* One prune that completed: the event landed AND the bytes went (APRV-57).
|
|
141
|
+
*
|
|
142
|
+
* Reported separately from {@link PruneReport.appended} because only these carry
|
|
143
|
+
* a `seq` and only these are finished. A candidate whose append landed and whose
|
|
144
|
+
* unlink FAILED appears in `appended` and in `warnings`, never here: the store
|
|
145
|
+
* still holds the bytes, and a success line for it would say otherwise.
|
|
146
|
+
*
|
|
147
|
+
* Crash-window completions ({@link PrunePlan.completions}) are absent for the
|
|
148
|
+
* opposite reason: they append nothing, so there is no record for a `seq` to
|
|
149
|
+
* name, and the log said the file was gone on some earlier tick already.
|
|
150
|
+
*/
|
|
151
|
+
export interface PrunedRecord {
|
|
152
|
+
candidate: PruneCandidate;
|
|
153
|
+
/** `seq` of the appended `payload.pruned` record. */
|
|
154
|
+
seq: number;
|
|
155
|
+
}
|
|
156
|
+
export interface PruneReport {
|
|
157
|
+
/** `payload_retention` in milliseconds, or `null` when the subsystem is off. */
|
|
158
|
+
retentionMs: number | null;
|
|
159
|
+
/** Hashes for which a `payload.pruned` was appended this pass. */
|
|
160
|
+
appended: PruneCandidate[];
|
|
161
|
+
/** Appended-and-unlinked prunes, with the seq of each event (APRV-57). */
|
|
162
|
+
pruned: PrunedRecord[];
|
|
163
|
+
/** Hashes whose file was removed (appended-then-unlinked, plus completions). */
|
|
164
|
+
removed: string[];
|
|
165
|
+
/** Crash-window files finished without a second event. */
|
|
166
|
+
completed: string[];
|
|
167
|
+
warnings: PruneWarning[];
|
|
168
|
+
}
|
|
169
|
+
export interface PruneOptions {
|
|
170
|
+
/** The append-only log. Re-read before every append. */
|
|
171
|
+
logPath: string;
|
|
172
|
+
/** The payload store. Defaults to the store beside `logPath`. */
|
|
173
|
+
storeDir?: string;
|
|
174
|
+
/** Policy location, with `loadPolicy`'s semantics. */
|
|
175
|
+
policy: {
|
|
176
|
+
dir?: string;
|
|
177
|
+
file?: string;
|
|
178
|
+
};
|
|
179
|
+
schemaDir?: string;
|
|
180
|
+
/** The write-boundary clock (amended SPEC.md §8). Tests inject; production does not. */
|
|
181
|
+
clock?: Clock;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Read `payload_retention` from the policy in force right now.
|
|
185
|
+
*
|
|
186
|
+
* Fails closed to `null` exactly as the daemon's TTL read does: a policy that
|
|
187
|
+
* cannot be loaded declares no retention, so nothing is pruned on its behalf. An
|
|
188
|
+
* unparseable duration is likewise `null` — the schema's duration pattern makes
|
|
189
|
+
* that unreachable through a validated policy, and a retention rule this module
|
|
190
|
+
* cannot read is not one it may guess at.
|
|
191
|
+
*/
|
|
192
|
+
export declare function retentionMsOf(policy: {
|
|
193
|
+
dir?: string;
|
|
194
|
+
file?: string;
|
|
195
|
+
}, schemaDir?: string): number | null;
|
|
196
|
+
/**
|
|
197
|
+
* One pruning pass: plan, append, unlink, repeat.
|
|
198
|
+
*
|
|
199
|
+
* The log is re-read before each append rather than once for the pass, because
|
|
200
|
+
* each append moves the head the next one is compared against and because a CLI
|
|
201
|
+
* verb may have appended in between. `expectedHead` therefore always names the
|
|
202
|
+
* head the decision was made from; a `head-moved` refusal drops the candidate and
|
|
203
|
+
* the next tick re-derives it.
|
|
204
|
+
*
|
|
205
|
+
* Nothing is retried in place, and no state survives the call.
|
|
206
|
+
*/
|
|
207
|
+
export declare function prunePayloads(options: PruneOptions): PruneReport;
|