approval-md 0.2.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.
Files changed (235) hide show
  1. package/README.md +63 -24
  2. package/SPEC.md +57 -11
  3. package/dist/src/channels/contract.d.ts +34 -1
  4. package/dist/src/channels/contract.js +200 -7
  5. package/dist/src/channels/contract.js.map +1 -1
  6. package/dist/src/channels/telegram.d.ts +123 -11
  7. package/dist/src/channels/telegram.js +218 -23
  8. package/dist/src/channels/telegram.js.map +1 -1
  9. package/dist/src/channels/web.d.ts +9 -0
  10. package/dist/src/channels/web.js +17 -0
  11. package/dist/src/channels/web.js.map +1 -1
  12. package/dist/src/cli/amend.js +214 -30
  13. package/dist/src/cli/amend.js.map +1 -1
  14. package/dist/src/cli/attest.d.ts +9 -0
  15. package/dist/src/cli/attest.js +134 -7
  16. package/dist/src/cli/attest.js.map +1 -1
  17. package/dist/src/cli/channel-telegram.d.ts +99 -26
  18. package/dist/src/cli/channel-telegram.js +311 -13
  19. package/dist/src/cli/channel-telegram.js.map +1 -1
  20. package/dist/src/cli/channel.d.ts +9 -0
  21. package/dist/src/cli/channel.js +9 -0
  22. package/dist/src/cli/channel.js.map +1 -1
  23. package/dist/src/cli/codex-bridge.d.ts +819 -0
  24. package/dist/src/cli/codex-bridge.js +1607 -0
  25. package/dist/src/cli/codex-bridge.js.map +1 -0
  26. package/dist/src/cli/codex.d.ts +1 -1
  27. package/dist/src/cli/codex.js +304 -7
  28. package/dist/src/cli/codex.js.map +1 -1
  29. package/dist/src/cli/daemon.js +4 -1
  30. package/dist/src/cli/daemon.js.map +1 -1
  31. package/dist/src/cli/doctor.js +467 -12
  32. package/dist/src/cli/doctor.js.map +1 -1
  33. package/dist/src/cli/execute.js +25 -2
  34. package/dist/src/cli/execute.js.map +1 -1
  35. package/dist/src/cli/help.d.ts +6 -2
  36. package/dist/src/cli/help.js +165 -60
  37. package/dist/src/cli/help.js.map +1 -1
  38. package/dist/src/cli/hook-codex.d.ts +49 -1
  39. package/dist/src/cli/hook-codex.js +60 -1
  40. package/dist/src/cli/hook-codex.js.map +1 -1
  41. package/dist/src/cli/hook.d.ts +459 -3
  42. package/dist/src/cli/hook.js +1062 -114
  43. package/dist/src/cli/hook.js.map +1 -1
  44. package/dist/src/cli/import.js +1 -1
  45. package/dist/src/cli/import.js.map +1 -1
  46. package/dist/src/cli/main.js +5 -3
  47. package/dist/src/cli/main.js.map +1 -1
  48. package/dist/src/cli/policy-apply.d.ts +195 -0
  49. package/dist/src/cli/policy-apply.js +573 -0
  50. package/dist/src/cli/policy-apply.js.map +1 -0
  51. package/dist/src/cli/policy.js +14 -1
  52. package/dist/src/cli/policy.js.map +1 -1
  53. package/dist/src/cli/preflight.d.ts +151 -13
  54. package/dist/src/cli/preflight.js +398 -41
  55. package/dist/src/cli/preflight.js.map +1 -1
  56. package/dist/src/cli/sandbox.js +17 -1
  57. package/dist/src/cli/sandbox.js.map +1 -1
  58. package/dist/src/cli/scaffold.d.ts +1 -1
  59. package/dist/src/cli/scaffold.js +1 -1
  60. package/dist/src/cli/setup-channel.d.ts +9 -0
  61. package/dist/src/cli/setup-channel.js +28 -1
  62. package/dist/src/cli/setup-channel.js.map +1 -1
  63. package/dist/src/cli/setup-common.d.ts +3 -1
  64. package/dist/src/cli/setup-common.js +3 -2
  65. package/dist/src/cli/setup-common.js.map +1 -1
  66. package/dist/src/cli/setup.d.ts +2 -0
  67. package/dist/src/cli/setup.js +94 -2
  68. package/dist/src/cli/setup.js.map +1 -1
  69. package/dist/src/cli/up.js +115 -51
  70. package/dist/src/cli/up.js.map +1 -1
  71. package/dist/src/cli/values.js +3 -4
  72. package/dist/src/cli/values.js.map +1 -1
  73. package/dist/src/cli/verb-registry.js +174 -9
  74. package/dist/src/cli/verb-registry.js.map +1 -1
  75. package/dist/src/cli/wordmark.d.ts +2 -2
  76. package/dist/src/cli/wordmark.js +2 -2
  77. package/dist/src/codex/broker.d.ts +229 -0
  78. package/dist/src/codex/broker.js +548 -0
  79. package/dist/src/codex/broker.js.map +1 -0
  80. package/dist/src/codex/runner.d.ts +178 -0
  81. package/dist/src/codex/runner.js +231 -0
  82. package/dist/src/codex/runner.js.map +1 -0
  83. package/dist/src/codex/serve.d.ts +56 -0
  84. package/dist/src/codex/serve.js +98 -0
  85. package/dist/src/codex/serve.js.map +1 -0
  86. package/dist/src/codex/workspace-commit.d.ts +219 -0
  87. package/dist/src/codex/workspace-commit.js +549 -0
  88. package/dist/src/codex/workspace-commit.js.map +1 -0
  89. package/dist/src/core/advance-cycle.d.ts +51 -0
  90. package/dist/src/core/advance-cycle.js +66 -2
  91. package/dist/src/core/advance-cycle.js.map +1 -1
  92. package/dist/src/core/agents-md.d.ts +20 -18
  93. package/dist/src/core/agents-md.js +33 -31
  94. package/dist/src/core/agents-md.js.map +1 -1
  95. package/dist/src/core/attest.d.ts +215 -0
  96. package/dist/src/core/attest.js +317 -7
  97. package/dist/src/core/attest.js.map +1 -1
  98. package/dist/src/core/audit.d.ts +18 -0
  99. package/dist/src/core/audit.js +13 -0
  100. package/dist/src/core/audit.js.map +1 -1
  101. package/dist/src/core/channel-owner.d.ts +213 -0
  102. package/dist/src/core/channel-owner.js +358 -0
  103. package/dist/src/core/channel-owner.js.map +1 -0
  104. package/dist/src/core/command-class.d.ts +154 -0
  105. package/dist/src/core/command-class.js +673 -20
  106. package/dist/src/core/command-class.js.map +1 -1
  107. package/dist/src/core/commit-guard.d.ts +272 -0
  108. package/dist/src/core/commit-guard.js +424 -0
  109. package/dist/src/core/commit-guard.js.map +1 -0
  110. package/dist/src/core/daemon-actor.d.ts +45 -0
  111. package/dist/src/core/daemon-actor.js +54 -0
  112. package/dist/src/core/daemon-actor.js.map +1 -0
  113. package/dist/src/core/dark-session.d.ts +109 -8
  114. package/dist/src/core/dark-session.js +266 -82
  115. package/dist/src/core/dark-session.js.map +1 -1
  116. package/dist/src/core/decision-refusal.d.ts +23 -2
  117. package/dist/src/core/decision-refusal.js +24 -2
  118. package/dist/src/core/decision-refusal.js.map +1 -1
  119. package/dist/src/core/env-file.d.ts +5 -0
  120. package/dist/src/core/env-file.js +60 -1
  121. package/dist/src/core/env-file.js.map +1 -1
  122. package/dist/src/core/execute.d.ts +15 -2
  123. package/dist/src/core/execute.js +15 -2
  124. package/dist/src/core/execute.js.map +1 -1
  125. package/dist/src/core/gate.d.ts +86 -1
  126. package/dist/src/core/gate.js +81 -1
  127. package/dist/src/core/gate.js.map +1 -1
  128. package/dist/src/core/gesture-refusal.d.ts +166 -0
  129. package/dist/src/core/gesture-refusal.js +188 -0
  130. package/dist/src/core/gesture-refusal.js.map +1 -0
  131. package/dist/src/core/harness-version.d.ts +1 -1
  132. package/dist/src/core/harness-version.js +3 -1
  133. package/dist/src/core/harness-version.js.map +1 -1
  134. package/dist/src/core/instance.d.ts +59 -2
  135. package/dist/src/core/instance.js +113 -0
  136. package/dist/src/core/instance.js.map +1 -1
  137. package/dist/src/core/log.d.ts +39 -1
  138. package/dist/src/core/log.js.map +1 -1
  139. package/dist/src/core/policy-explain.d.ts +10 -0
  140. package/dist/src/core/policy-explain.js +32 -0
  141. package/dist/src/core/policy-explain.js.map +1 -1
  142. package/dist/src/core/policy-load.d.ts +41 -1
  143. package/dist/src/core/policy-load.js +21 -3
  144. package/dist/src/core/policy-load.js.map +1 -1
  145. package/dist/src/core/policy-match.d.ts +43 -0
  146. package/dist/src/core/policy-match.js +52 -0
  147. package/dist/src/core/policy-match.js.map +1 -1
  148. package/dist/src/core/policy-proposal.d.ts +52 -0
  149. package/dist/src/core/policy-proposal.js +102 -2
  150. package/dist/src/core/policy-proposal.js.map +1 -1
  151. package/dist/src/core/protected-path-guard.d.ts +117 -4
  152. package/dist/src/core/protected-path-guard.js +362 -48
  153. package/dist/src/core/protected-path-guard.js.map +1 -1
  154. package/dist/src/core/question-preempted.d.ts +141 -0
  155. package/dist/src/core/question-preempted.js +152 -0
  156. package/dist/src/core/question-preempted.js.map +1 -0
  157. package/dist/src/core/read-scope.d.ts +172 -0
  158. package/dist/src/core/read-scope.js +252 -0
  159. package/dist/src/core/read-scope.js.map +1 -0
  160. package/dist/src/core/sandbox.d.ts +81 -0
  161. package/dist/src/core/sandbox.js +190 -1
  162. package/dist/src/core/sandbox.js.map +1 -1
  163. package/dist/src/core/sender-identity.d.ts +476 -0
  164. package/dist/src/core/sender-identity.js +572 -0
  165. package/dist/src/core/sender-identity.js.map +1 -0
  166. package/dist/src/core/shlex.d.ts +102 -0
  167. package/dist/src/core/shlex.js +159 -0
  168. package/dist/src/core/shlex.js.map +1 -0
  169. package/dist/src/core/values.d.ts +18 -8
  170. package/dist/src/core/values.js +36 -1
  171. package/dist/src/core/values.js.map +1 -1
  172. package/dist/src/daemon/advance.d.ts +10 -0
  173. package/dist/src/daemon/advance.js +25 -4
  174. package/dist/src/daemon/advance.js.map +1 -1
  175. package/dist/src/daemon/daemon.js +9 -0
  176. package/dist/src/daemon/daemon.js.map +1 -1
  177. package/dist/src/daemon/git-evidence.d.ts +2 -2
  178. package/dist/src/daemon/git-evidence.js +1 -1
  179. package/dist/src/mcp/server.js +8 -0
  180. package/dist/src/mcp/server.js.map +1 -1
  181. package/docs/cli-reference.md +932 -32
  182. package/docs/codex-enforced-session.md +75 -2
  183. package/docs/codex-workspace-broker.md +118 -0
  184. package/package.json +3 -1
  185. package/schema/event.schema.json +538 -9
  186. package/schema/fixtures/event/invalid/approval-granted-sender-hashed-false.json +20 -0
  187. package/schema/fixtures/event/invalid/approval-granted-sender-hashed-raw-id.json +20 -0
  188. package/schema/fixtures/event/invalid/audit-gesture-refused-human-actor.json +16 -0
  189. package/schema/fixtures/event/invalid/audit-gesture-refused-no-actor-no-sender.json +15 -0
  190. package/schema/fixtures/event/invalid/audit-gesture-refused-unknown-gesture.json +16 -0
  191. package/schema/fixtures/event/invalid/audit-question-preempted-agent-actor.json +16 -0
  192. package/schema/fixtures/event/invalid/audit-question-preempted-no-question-id.json +16 -0
  193. package/schema/fixtures/event/invalid/audit-question-preempted-unknown-source.json +15 -0
  194. package/schema/fixtures/event/invalid/gate-path-signed-off-absolute-path.json +14 -0
  195. package/schema/fixtures/event/invalid/gate-path-signed-off-agent-actor.json +14 -0
  196. package/schema/fixtures/event/invalid/gate-path-signed-off-missing-path.json +13 -0
  197. package/schema/fixtures/event/valid/approval-granted-sender-hashed.json +20 -0
  198. package/schema/fixtures/event/valid/audit-gesture-refused-review-note.json +21 -0
  199. package/schema/fixtures/event/valid/audit-gesture-refused-sender-key-unavailable.json +19 -0
  200. package/schema/fixtures/event/valid/audit-gesture-refused.json +19 -0
  201. package/schema/fixtures/event/valid/audit-question-preempted-no-verdict.json +16 -0
  202. package/schema/fixtures/event/valid/audit-question-preempted.json +20 -0
  203. package/schema/fixtures/event/valid/gate-path-signed-off.json +14 -0
  204. package/schema/fixtures/event/valid/harness-kind-claude-code.json +23 -0
  205. package/schema/fixtures/event/valid/harness-kind-codex.json +23 -0
  206. package/schema/fixtures/event/valid/harness-kind-cursor.json +23 -0
  207. package/schema/fixtures/event/valid/harness-kind-grok.json +23 -0
  208. package/schema/fixtures/event/valid/harness-kind-muse.json +23 -0
  209. package/schema/fixtures/policy/invalid/senders-half-keyed.json +20 -0
  210. package/schema/fixtures/policy/valid/canonical.json +1 -1
  211. package/schema/fixtures/policy/valid/senders-keyed.json +24 -0
  212. package/schema/fixtures/policy-md/valid/canonical.md +1 -1
  213. package/schema/fixtures/policy-md/valid/with-values.md +5 -7
  214. package/schema/fixtures/values/invalid/class-shaped.json +1 -1
  215. package/schema/fixtures/values/invalid/duplicate-entry.json +1 -1
  216. package/schema/fixtures/values/invalid/non-string-item.json +1 -1
  217. package/schema/fixtures/values/invalid/over-cap.json +1 -1
  218. package/schema/fixtures/values/invalid/unknown-key.json +1 -1
  219. package/schema/fixtures/values/invalid/version-float.json +1 -0
  220. package/schema/fixtures/values/invalid/version-integer.json +1 -0
  221. package/schema/fixtures/values/invalid/version-wrong-string.json +1 -0
  222. package/schema/fixtures/values/valid/empty-lists.json +2 -3
  223. package/schema/fixtures/values/valid/full.json +5 -7
  224. package/schema/fixtures/values/valid/minimal.json +1 -1
  225. package/schema/fixtures/values-md/invalid/schema-invalid.md +5 -3
  226. package/schema/fixtures/values-md/invalid/two-blocks.md +3 -3
  227. package/schema/fixtures/values-md/invalid/unterminated.md +2 -2
  228. package/schema/fixtures/values-md/invalid/version-1.md +69 -0
  229. package/schema/fixtures/values-md/invalid/version-unquoted.md +64 -0
  230. package/schema/fixtures/values-md/invalid/yaml-error.md +2 -2
  231. package/schema/fixtures/values-md/valid/absent.md +1 -1
  232. package/schema/fixtures/values-md/valid/with-values.md +5 -7
  233. package/schema/policy.schema.json +54 -2
  234. package/schema/values.schema.json +7 -11
  235. package/schema/fixtures/values/invalid/version-string.json +0 -1
@@ -51,6 +51,7 @@
51
51
  import type { AttestationStatus } from "../core/attest.js";
52
52
  import type { BudgetVerdict } from "../core/budgets.js";
53
53
  import { type DecideOptions, type GateRefusal } from "../core/gate.js";
54
+ import { type ChannelDecisionRefusalCode, type ChannelSender } from "../core/sender-identity.js";
54
55
  import type { EventRecord } from "../core/log.js";
55
56
  import type { Autonomy } from "../core/policy-load.js";
56
57
  import type { Provenance } from "../core/policy-match.js";
@@ -450,6 +451,27 @@ export declare function batchDeliveryIdOf(record: EventRecord): DeliveryId | nul
450
451
  /** A human gesture, as reported by a channel. Never an authorization. */
451
452
  export interface ChannelDecision {
452
453
  action_key: string;
454
+ /**
455
+ * The sender the channel's own transport authenticated for THIS gesture
456
+ * (APRV-324, `design/channel-sender-identity.md` §3.2).
457
+ *
458
+ * The design put this on {@link ChannelActorOptions}; it lives here instead,
459
+ * because the sender is a property of one tap and that object is a property of
460
+ * the listener. `onDecision` registers one handler for the process, and the
461
+ * only thing that varies per gesture is this value — a per-listener field
462
+ * could not carry it, and giving each listener a mutable slot to stash it in
463
+ * would be exactly the channel-held state SPEC.md §10.3 forbids.
464
+ *
465
+ * It is an OBSERVATION and never an assertion of authority. The channel does
466
+ * not resolve it, cannot choose the actor with it, and must read it from the
467
+ * transport's own attribution: Telegram's `callback_query.from.id`, and
468
+ * nothing a message body, a callback payload or a username says (§11.1
469
+ * invariant 4). A channel that authenticates nobody — the web page, the
470
+ * terminal — sets nothing here, and a `sender` field arriving in one of their
471
+ * request bodies is ignored rather than honoured, because a surface that
472
+ * cannot authenticate a person must not be able to claim one.
473
+ */
474
+ sender?: ChannelSender;
453
475
  /**
454
476
  * What the human did. `revoke` is deliberately absent: withdrawing a standing
455
477
  * authorization is a considered act performed against the log through the
@@ -471,6 +493,17 @@ export interface ChannelDecision {
471
493
  * {@link recordChannelDecision} in {@link ChannelDecisionResult.token}, never in
472
494
  * this value. A channel learns that a grant landed, not how to spend it.
473
495
  */
496
+ /**
497
+ * A refusal made by the decision SURFACE, before the gate is called
498
+ * (APRV-324). Its codes are {@link CHANNEL_DECISION_REFUSAL_CODES}, a union of
499
+ * its own: `decide` cannot emit them, and folding them into the gate's
500
+ * vocabulary would tell a second implementation that its gate must.
501
+ */
502
+ export interface ChannelDecisionRefusal {
503
+ ok: false;
504
+ code: ChannelDecisionRefusalCode;
505
+ message: string;
506
+ }
474
507
  export type DecisionOutcome = {
475
508
  ok: true;
476
509
  action_key: string;
@@ -489,7 +522,7 @@ export type DecisionOutcome = {
489
522
  * whose token was never this surface's to hold.
490
523
  */
491
524
  tokenIssued: boolean;
492
- } | GateRefusal;
525
+ } | GateRefusal | ChannelDecisionRefusal;
493
526
  /** A channel's self-report. `detail` explains a `false`; SPEC.md §10.2 polls it. */
494
527
  export interface ChannelHealth {
495
528
  ok: boolean;
@@ -49,8 +49,11 @@
49
49
  * `channels/conformance.ts`.
50
50
  */
51
51
  import { recordRefusedDecision } from "../core/decision-refusal.js";
52
- import { decide } from "../core/gate.js";
53
- import { attestationKeySha256, decideAttestation, isAttestationActionKey, openProposalFor, proposalPolicyPath, } from "../core/policy-proposal.js";
52
+ import { decide, readGatePolicy, } from "../core/gate.js";
53
+ import { actorForSender, isChannelDecisionRefusalCode, mapsSendersFor, recordedSenderFor, senderKeyFrom, senderRefusalLine, sendersDiffer, } from "../core/sender-identity.js";
54
+ import { attestationKeySha256, decideAttestation, inForcePolicyText, isAttestationActionKey, openProposalFor, proposalPolicyPath, } from "../core/policy-proposal.js";
55
+ import { payloadStoreDirFor } from "../core/payload-store.js";
56
+ import { loadPolicyText } from "../core/policy-load.js";
54
57
  import { readVerifiedRecords } from "../core/state.js";
55
58
  import { tick } from "../core/clock.js";
56
59
  // ---------------------------------------------------------------------------
@@ -125,6 +128,13 @@ export const GLOSS_UNVERIFIED_SUFFIX = "(model, unverified)";
125
128
  * The wording of the first three is APRV-206's, moved here unchanged.
126
129
  */
127
130
  export function refusedDecisionLine(code) {
131
+ // APRV-324. The two the surface itself makes, worded where they are defined
132
+ // so one rule about what a refusal may disclose covers every channel: they
133
+ // name the code and nothing about the mapping — not who is mapped, not how
134
+ // many are, and not the id that was seen. The id is on the record, where an
135
+ // operator reads it deliberately; a chat is read by everyone in it.
136
+ if (isChannelDecisionRefusalCode(code))
137
+ return senderRefusalLine(code);
128
138
  if (code === "already-decided") {
129
139
  return "Already decided — the first answer stands; nothing was recorded.";
130
140
  }
@@ -137,6 +147,14 @@ export function refusedDecisionLine(code) {
137
147
  }
138
148
  if (code === "expired")
139
149
  return "Expired — the approval window has closed.";
150
+ // APRV-324 follow-up. The gate has always been able to return this; what
151
+ // changed is that a checkpoint signature and a review can too, because the
152
+ // sender mapping they resolve against is only in force once a human has
153
+ // attested the file it is written in. One sentence, every surface, and it
154
+ // names the repair rather than the check.
155
+ if (code === "policy-not-attested") {
156
+ return "Not recorded — APPROVAL.md has changed and nobody has attested it yet, so its rules are not in force. Re-attest it, or do this from a terminal.";
157
+ }
140
158
  // APRV-235, and the reason this helper exists. The distinction the line has to
141
159
  // carry is that nothing is wrong with the ACTION: the policy was re-attested
142
160
  // after the question was asked, so the rules on the approver's screen are not
@@ -340,7 +358,42 @@ export function recordChannelDecision(logPath, decision, actorOptions, gateOptio
340
358
  if (decision.batchDeliveryId !== undefined) {
341
359
  options.batchDeliveryId = decision.batchDeliveryId;
342
360
  }
343
- const result = decide(logPath, decision.action_key, decision.decision, actorOptions.actor, options);
361
+ // APRV-324. Every surface names itself on the record it writes, so a reader
362
+ // of a grant can tell a tap on a phone from a line typed into a terminal. The
363
+ // fallback matches `noteRefusedDecision`'s below.
364
+ options.channel = actorOptions.channel ?? "cli";
365
+ // APRV-324, and before anything is decided: the actor a decision is recorded
366
+ // under is chosen HERE, from the sender the transport authenticated and the
367
+ // mapping the operator attested, and the gate's own authorization logic is
368
+ // untouched by it. `namesApprover` and `actor-not-approver` then run exactly
369
+ // as they always have, over an identity that is better evidenced.
370
+ const resolution = actorForSender(readGatePolicy(gateOptions), actorOptions.actor, decision.sender,
371
+ // APRV-370. The operator's sender key, where the policy's mapping is keyed.
372
+ // `null` when it is unset, which is a REFUSAL of the whole channel rather
373
+ // than a fallback to the raw comparison; `sender-key-unavailable` carries
374
+ // the reasoning.
375
+ senderKeyFrom());
376
+ if (!resolution.ok) {
377
+ const refusal = {
378
+ ok: false,
379
+ code: resolution.code,
380
+ message: `decision on ${decision.action_key} refused: ${resolution.message}`,
381
+ };
382
+ // The refusal is the record. Nothing is decided, no token is minted, and
383
+ // the one append is the audit-tier statement that somebody tapped from an
384
+ // account this policy names nobody for — carrying the observed id, because
385
+ // an operator investigating who tried needs the number, and a transport
386
+ // account id is not a credential.
387
+ noteRefusedDecision(logPath, decision, { ...actorOptions, actor: null }, gateOptions, refusal, { sender: resolution.sender });
388
+ return { outcome: refusal };
389
+ }
390
+ const actor = resolution.actor;
391
+ if (resolution.sender !== undefined) {
392
+ options.sender = resolution.sender;
393
+ if (resolution.source !== undefined)
394
+ options.senderSource = resolution.source;
395
+ }
396
+ const result = decide(logPath, decision.action_key, decision.decision, actor, options);
344
397
  if (!result.ok) {
345
398
  // APRV-235. A human tapped and the gate would not take it. The gate itself
346
399
  // appends nothing on a refusal, by design; this surface knows something the
@@ -351,7 +404,24 @@ export function recordChannelDecision(logPath, decision, actorOptions, gateOptio
351
404
  // Best effort, deliberately last, and it changes nothing about what the
352
405
  // channel is handed back: the decision has already been refused, and a
353
406
  // failed audit append must not turn one refusal into two.
354
- noteRefusedDecision(logPath, decision, actorOptions, gateOptions, result);
407
+ noteRefusedDecision(logPath, decision, { ...actorOptions, actor }, gateOptions, result,
408
+ // APRV-324, and §11.1 invariant 9 is the reason for the exception. A
409
+ // `class-human-only` refusal says the policy does not transact in this
410
+ // class at all, so the runtime records no identity resolution for it: a
411
+ // refusal record naming the account a human-only tap came from would read
412
+ // afterwards as a class this gate resolves senders for. Every other
413
+ // refusal names the account, because the attention it accounts for was
414
+ // spent by whoever holds it.
415
+ // APRV-370: `resolution.sender`, never `decision.sender`. The resolution
416
+ // carries the sender in the form the record takes, which under a keyed
417
+ // mapping is the digest; writing the observed id here would put the raw
418
+ // account back in the log on exactly the refusals nobody looks at.
419
+ result.code === "class-human-only" || resolution.sender === undefined
420
+ ? {}
421
+ : {
422
+ sender: resolution.sender,
423
+ ...(resolution.source === undefined ? {} : { senderSource: resolution.source }),
424
+ });
355
425
  return { outcome: result };
356
426
  }
357
427
  const outcome = {
@@ -375,7 +445,7 @@ export function recordChannelDecision(logPath, decision, actorOptions, gateOptio
375
445
  * answer away from the human who is waiting for it. What a failure costs is the
376
446
  * record, which is exactly what the caller had before this existed.
377
447
  */
378
- function noteRefusedDecision(logPath, decision, actorOptions, gateOptions, refusal) {
448
+ function noteRefusedDecision(logPath, decision, actorOptions, gateOptions, refusal, sender = {}) {
379
449
  try {
380
450
  recordRefusedDecision(logPath, {
381
451
  actionKey: decision.action_key,
@@ -385,10 +455,13 @@ function noteRefusedDecision(logPath, decision, actorOptions, gateOptions, refus
385
455
  // local process, which is what a decision that reached the runtime
386
456
  // through no channel at all came through.
387
457
  channel: actorOptions.channel ?? "cli",
458
+ ...sender,
388
459
  }, {
389
460
  code: refusal.code,
390
461
  message: refusal.message,
391
- ...(refusal.drift === undefined ? {} : { drift: refusal.drift }),
462
+ // A surface-side refusal has made no policy comparison, so it carries no
463
+ // hashes; `in` rather than a cast, so the narrowing is the type system's.
464
+ ...("drift" in refusal && refusal.drift !== undefined ? { drift: refusal.drift } : {}),
392
465
  }, gateOptions);
393
466
  }
394
467
  catch {
@@ -437,6 +510,103 @@ function listenerPolicyPath(options) {
437
510
  return policy.file;
438
511
  return policy.dir === undefined ? null : proposalPolicyPath(policy.dir);
439
512
  }
513
+ /**
514
+ * Who may attest, from a phone, and under whose rules (APRV-324 follow-up,
515
+ * amended SPEC.md §10.3).
516
+ *
517
+ * ## Why this is not the decision rule
518
+ *
519
+ * A decision is resolved against the policy in force, and so is this — but for
520
+ * an attestation the two candidate policies are different documents, and the
521
+ * difference is the whole problem. The tap answers a prompt about the LIVE
522
+ * file, which is the amendment; the amendment may add, remove or repoint the
523
+ * `senders` mapping itself. Resolving against the proposed file would let
524
+ * whoever edited it name their own account as the approver of their own edit,
525
+ * which is a gate that authorizes its own widening. So the oracle is the policy
526
+ * IN FORCE — the bytes the latest attestation names — and never the bytes being
527
+ * attested.
528
+ *
529
+ * ## The ladder
530
+ *
531
+ * 1. **No sender.** The terminal and the web page, which authenticate nobody.
532
+ * Unchanged, and this is the path that keeps a repository recoverable: a
533
+ * `policy.core` edit happens at a terminal anyway, so no mapping, however
534
+ * broken, can strand the repair.
535
+ * 2. **In-force bytes recovered, and the amendment changes the mapping.** Only
536
+ * an account the IN-FORCE policy maps may answer. Where the policy in force
537
+ * maps nobody on this channel, nobody qualifies and the answer is
538
+ * `attest-requires-terminal`: an amendment that introduces the identity
539
+ * system cannot be signed for by the identity system it introduces.
540
+ * 3. **In-force bytes recovered, mapping unchanged.** The ordinary rule, run
541
+ * against the policy in force: mapped answers, unmapped is refused.
542
+ * 4. **In-force bytes NOT recovered.** They frequently are not — an attestation
543
+ * records only a digest, and a terminal attestation stores nothing
544
+ * ({@link inForcePolicyText} says so in full). Then the runtime cannot tell
545
+ * whether this amendment touches the mapping, so it refuses
546
+ * `attest-requires-terminal` whenever the PROPOSED policy maps senders for
547
+ * this channel, and otherwise behaves exactly as it did before this rule.
548
+ *
549
+ * The residual, stated rather than hidden: in case 4 an amendment that REMOVES
550
+ * a mapping is indistinguishable from a policy that never had one, so it falls
551
+ * to the pre-mapping behaviour. Closing that would need the in-force bytes,
552
+ * which is case 2; and reaching it requires an attacker who can already write
553
+ * `APPROVAL.md`, whom SPEC.md §11 already places inside the trust boundary.
554
+ */
555
+ function resolveAttestationSender(logPath, records, decision, actorOptions, gateOptions, policyPath) {
556
+ const sender = decision.sender;
557
+ if (sender === undefined)
558
+ return { ok: true, actor: actorOptions.actor };
559
+ // APRV-370. Resolved ONCE for this whole ladder: the operator's sender key,
560
+ // and with it the form the refusals below record the account in. The form
561
+ // follows the FILE and the mapping follows the ATTESTATION
562
+ // (`recordedSenderFor` carries the reasoning), so a refusal that never
563
+ // reaches the in-force mapping still honours the disclosure preference the
564
+ // operator wrote down, and grants nobody anything by doing so.
565
+ const key = senderKeyFrom();
566
+ const proposed = readGatePolicy(gateOptions);
567
+ // The same store `proposeAttestation` wrote the policy text to, resolved the
568
+ // same way, so the bytes a prompt displayed and the bytes this reads back are
569
+ // never two different files.
570
+ const inForce = inForcePolicyText(records, gateOptions.payloadStoreDir ?? payloadStoreDirFor(logPath));
571
+ if (!inForce.ok) {
572
+ if (!mapsSendersFor(proposed.ok ? proposed.policy.approvers : undefined, sender.channel)) {
573
+ return { ok: true, actor: actorOptions.actor };
574
+ }
575
+ return {
576
+ ok: false,
577
+ code: "attest-requires-terminal",
578
+ sender: recordedSenderFor(proposed, sender, key),
579
+ message: `the policy being attested maps ${sender.channel} senders and the policy IN FORCE cannot be read to check who may sign for that: ${inForce.reason}. Resolving this tap against the file it is attesting would let whoever wrote that file name the account that approves it, so nothing was attested. Attest from a terminal, which authenticates no sender and is where a policy.core edit happens anyway.`,
580
+ };
581
+ }
582
+ const before = loadPolicyText(policyPath ?? "APPROVAL.md", inForce.text, gateOptions.schemaDir === undefined ? {} : { schemaDir: gateOptions.schemaDir });
583
+ if (sendersDiffer(before, proposed)) {
584
+ if (!mapsSendersFor(before.ok ? before.policy.approvers : undefined, sender.channel)) {
585
+ return {
586
+ ok: false,
587
+ code: "attest-requires-terminal",
588
+ sender: recordedSenderFor(before, sender, key),
589
+ message: `this amendment changes the sender mapping, and the policy in force maps no ${sender.channel} sender, so there is no account it could recognize as entitled to sign for that change. An amendment that introduces the identity system cannot be signed for by the identity system it introduces. Nothing was attested; attest from a terminal.`,
590
+ };
591
+ }
592
+ const resolution = actorForSender(before, actorOptions.actor, sender, key);
593
+ if (!resolution.ok)
594
+ return resolution;
595
+ // A mapped account under the policy in force. Belt and braces on the mode
596
+ // the ladder above already excluded: an amendment that changes the mapping
597
+ // is never answered on the configured identity.
598
+ if (resolution.sender === undefined) {
599
+ return {
600
+ ok: false,
601
+ code: "attest-requires-terminal",
602
+ sender: recordedSenderFor(before, sender, key),
603
+ message: `this amendment changes the sender mapping and this tap resolved to no account under the policy in force. Nothing was attested; attest from a terminal.`,
604
+ };
605
+ }
606
+ return resolution;
607
+ }
608
+ return actorForSender(before, actorOptions.actor, sender, key);
609
+ }
440
610
  export function recordAttestationDecision(logPath, decision, actorOptions, gateOptions = {}) {
441
611
  const sha256 = attestationKeySha256(decision.action_key);
442
612
  if (sha256 === null) {
@@ -477,7 +647,30 @@ export function recordAttestationDecision(logPath, decision, actorOptions, gateO
477
647
  const policyPath = listenerPolicyPath(gateOptions);
478
648
  if (policyPath !== null)
479
649
  options.policyPath = policyPath;
480
- const result = decideAttestation(logPath, proposal.seq, decision.decision === "grant" ? "attest" : "decline", actorOptions.actor, options);
650
+ // APRV-324 follow-up. The privileged gesture, resolved last and most
651
+ // carefully: an attestation decides which rules are in force, and the rules
652
+ // it can decide include the sender mapping itself.
653
+ const resolved = resolveAttestationSender(logPath, read.records, decision, actorOptions, gateOptions, policyPath);
654
+ if (!resolved.ok) {
655
+ const refusal = {
656
+ ok: false,
657
+ code: resolved.code,
658
+ message: `attestation of ${sha256} refused: ${resolved.message}`,
659
+ };
660
+ // The same audit-tier record a refused decision writes, and it fits without
661
+ // straining: the attestation prompt HAS an action key the log carries
662
+ // (`policy.attest:<sha256>`), and the gesture IS one of the two decision
663
+ // words this event's payload admits, because that is exactly how a tap on a
664
+ // prompt is routed to `attest` or `decline` above.
665
+ noteRefusedDecision(logPath, decision, { ...actorOptions, actor: null }, gateOptions, refusal, { sender: resolved.sender });
666
+ return { outcome: refusal };
667
+ }
668
+ if (resolved.sender !== undefined) {
669
+ options.sender = resolved.sender;
670
+ if (resolved.source !== undefined)
671
+ options.senderSource = resolved.source;
672
+ }
673
+ const result = decideAttestation(logPath, proposal.seq, decision.decision === "grant" ? "attest" : "decline", resolved.actor, options);
481
674
  if (!result.ok)
482
675
  return { outcome: result };
483
676
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../../src/channels/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAwC,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,mBAAmB,EAAqB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,yDAAyD;IACzD,KAAK;IACL,0FAA0F;IAC1F,cAAc;IACd,sDAAsD;IACtD,SAAS;IACT,kEAAkE;IAClE,aAAa;IACb;;;;OAIG;IACH,aAAa;IACb,4EAA4E;IAC5E,iB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AW,EAAE,KAAK;SACnB;KACF,CAAC;AACJ,CAAC"}
@@ -40,16 +40,35 @@
40
40
  * > flag); the trust boundary is the local machine, and anyone who can set that
41
41
  * > configuration and write to the log is inside it.
42
42
  *
43
- * This channel does **not** authenticate the person who tapped the button. It
44
- * checks that the callback arrived from the configured chat id, and the
45
- * decision is then recorded against the human actor the *runtime* was
46
- * configured with (`APPROVAL_HUMAN` / `--as`), not against anything the
47
- * callback carried. So the guarantee is "someone with access to the configured
48
- * chat, on a runtime configured by someone with local control, tapped Approve"
49
- * — not "alice tapped Approve". Anyone in that chat can approve as the
50
- * configured actor. Use a private chat with the bot, and treat the chat's
51
- * membership as part of the trust boundary. Cryptographic identity is future
52
- * work and is not a v0.1 claim.
43
+ * What this channel authenticates, exactly: that the callback arrived **from
44
+ * the configured chat id**, and which **Telegram account** the Bot API
45
+ * attributes the tap to (`callback_query.from.id`). It authenticates no
46
+ * person, because no transport can: an account id is evidence about an
47
+ * account.
48
+ *
49
+ * What is done with the second fact is the operator's to decide, and since
50
+ * APRV-324 there are two settings:
51
+ *
52
+ * - **No `senders` block in the policy.** Nothing changes from every build
53
+ * before it. The decision is recorded against the human actor the *runtime*
54
+ * was configured with (`APPROVAL_HUMAN` / `--as`), so the guarantee is
55
+ * "someone with access to the configured chat, on a runtime configured by
56
+ * someone with local control, tapped Approve" — not "alice tapped Approve".
57
+ * Anyone in that chat can approve as the configured actor. Use a private chat
58
+ * with the bot, and treat the chat's membership as part of the trust
59
+ * boundary.
60
+ * - **A `senders` block mapping account ids to approvers.** The decision is
61
+ * recorded against the person the operator attested that account to, and a
62
+ * tap from an account the policy does not name is REFUSED rather than
63
+ * recorded under the listener's identity. The guarantee becomes "the account
64
+ * the operator attested to alice tapped Approve", which is a statement about
65
+ * Telegram's session handling and the operator's assertion, and still not a
66
+ * proof of personhood. Cryptographic identity is future work and is not a
67
+ * v0.1 claim.
68
+ *
69
+ * The channel itself resolves nothing either way. It reports the account it
70
+ * saw; `channels/contract.ts` resolves it against the attested policy, and
71
+ * `core/gate.ts` decides. See `design/channel-sender-identity.md`.
53
72
  *
54
73
  * ## Formatting: HTML, not MarkdownV2 — a deliberate choice
55
74
  *
@@ -183,6 +202,7 @@
183
202
  * and the log is not opened.
184
203
  */
185
204
  import type { ChannelBatch, ChannelDecision, ChannelHealth, ChannelRequest, DecisionOutcome, DeliveryId, RenderedRequest, TaggedField, TestableChannel } from "./contract.js";
205
+ import type { ChannelSender } from "../core/sender-identity.js";
186
206
  import { type Reaction, type ReviewVerdict } from "../core/audit.js";
187
207
  import { type PromptLayout } from "../core/prompt-layout.js";
188
208
  export { TELEGRAM_CHAT_ENV, TELEGRAM_TOKEN_ENV, telegramChatEnvFor, telegramTokenEnvFor, } from "../core/telegram-config.js";
@@ -556,6 +576,13 @@ export type CheckpointTapHandler = (tap: {
556
576
  seq: number;
557
577
  hash: string;
558
578
  };
579
+ /**
580
+ * The account the transport authenticated (APRV-324 follow-up), when it
581
+ * authenticated one. The channel resolves nothing: the runtime's handler
582
+ * asks the attested policy who this is, refuses an account it does not name,
583
+ * and signs as the person it does.
584
+ */
585
+ sender?: ChannelSender;
559
586
  }) => CheckpointTapResponse | Promise<CheckpointTapResponse>;
560
587
  export declare const TELEGRAM_COMMANDS: readonly ["queue", "skip", "next"];
561
588
  export type TelegramCommand = (typeof TELEGRAM_COMMANDS)[number];
@@ -904,6 +931,30 @@ export declare function parseCheckpointCallback(data: unknown): {
904
931
  sign: boolean;
905
932
  nonce: string;
906
933
  } | null;
934
+ /**
935
+ * The account the Bot API attributes a callback to (APRV-324, amended SPEC.md
936
+ * §10.3).
937
+ *
938
+ * `callback_query.from.id` and nothing else. Telegram assembles the `from`
939
+ * object itself, from the session the tap arrived on, which is why it is the
940
+ * one field on an update this channel treats as evidence about a person. Three
941
+ * neighbours are deliberately not read:
942
+ *
943
+ * - **`from.username`.** Mutable and reusable, so a mapping keyed on it would
944
+ * hand an identity over with a handle. Never a key here and never recorded
945
+ * (`core/sender-identity.ts` states the argument in full).
946
+ * - **`message.from`.** The author of the message the button sits on — this bot
947
+ * — rather than the person who pressed it.
948
+ * - **`data`, and any text.** What the sender says about themselves, which
949
+ * §11.1 invariant 4 says may raise scrutiny and never lower it. A callback
950
+ * whose payload names a user id names it about itself; the id here comes from
951
+ * the transport, and the two disagreeing changes nothing.
952
+ *
953
+ * `undefined` when the update carries no usable id: a sender this channel could
954
+ * not read is not a sender it may guess at, and the decision then travels with
955
+ * none, which the contract reads as today's configured attribution.
956
+ */
957
+ export declare function senderOf(query: Record<string, unknown>, channel: string): ChannelSender | undefined;
907
958
  interface ParsedCallback {
908
959
  decision: "grant" | "reject";
909
960
  /** `all` for a digest's "all" button; `one` for every per-request button. */
@@ -978,6 +1029,18 @@ export interface ReviewTap {
978
1029
  reaction?: Reaction;
979
1030
  /** The human's words, when a note prompt collected any. */
980
1031
  note?: string;
1032
+ /**
1033
+ * The account the transport authenticated (APRV-324 follow-up), when it
1034
+ * authenticated one.
1035
+ *
1036
+ * A review confers no authority, which is why it took the paragraph above so
1037
+ * long to stop being true. It is still recorded as a HUMAN's observation and
1038
+ * `approval feedback` presents it to agents as human-authored guidance, so a
1039
+ * review attributed to the wrong person is guidance in somebody else's name.
1040
+ * The channel resolves nothing; the runtime's handler asks the attested
1041
+ * policy, refuses an account it does not name, and records the one it does.
1042
+ */
1043
+ sender?: ChannelSender;
981
1044
  }
982
1045
  /** What the runtime did with a review tap, as it reports it back. */
983
1046
  export interface ReviewTapResponse {
@@ -1051,11 +1114,20 @@ export interface ReviewCardState {
1051
1114
  headline: string;
1052
1115
  lines: string[];
1053
1116
  } | null;
1054
- /** The outstanding note prompt, and what its reply will record. */
1117
+ /**
1118
+ * The outstanding note prompt, and what its reply will record.
1119
+ *
1120
+ * `sender` is the account that asked for the prompt (APRV-324 follow-up),
1121
+ * when the transport authenticated one. A ForceReply prompt is addressed to
1122
+ * the person who tapped, and the words it collects are recorded as theirs, so
1123
+ * a reply from a different account is not the answer to this question: it is
1124
+ * left unrecorded and the prompt stays live for whoever armed it.
1125
+ */
1055
1126
  awaitingNote: {
1056
1127
  promptId: DeliveryId;
1057
1128
  verdict: ReviewVerdict;
1058
1129
  reaction: Reaction;
1130
+ sender?: ChannelSender;
1059
1131
  } | null;
1060
1132
  /** When this process delivered the card, on {@link TelegramConfig.now}'s clock. */
1061
1133
  deliveredAtMs: number;
@@ -1161,6 +1233,17 @@ export declare class TelegramApiError extends Error {
1161
1233
  * that goes unreported.
1162
1234
  */
1163
1235
  export declare function isMessageNotModified(cause: unknown): boolean;
1236
+ /**
1237
+ * Whether a failed poll is the Bot API saying another process holds this bot
1238
+ * (APRV-390).
1239
+ *
1240
+ * It is the one poll failure that is not transient and not the network's
1241
+ * fault: retrying it forever produces an identical line every few seconds and
1242
+ * never recovers, because the other poller is not going to stop. {@link
1243
+ * TelegramChannel.listen} reports it once, with whatever the caller knows
1244
+ * about who the other process is, and then stops repeating itself.
1245
+ */
1246
+ export declare function isPollConflict(cause: unknown): boolean;
1164
1247
  /** What one `pollOnce()` did, for tests and for programmatic drivers. */
1165
1248
  export interface TelegramPollResult {
1166
1249
  /** Updates received in this batch. */
@@ -1206,6 +1289,17 @@ export interface TelegramListenOptions {
1206
1289
  * failure mode this loop exists to rule out.
1207
1290
  */
1208
1291
  beforePoll?: () => Promise<void>;
1292
+ /**
1293
+ * What the caller knows about who else might be polling this bot (APRV-390).
1294
+ *
1295
+ * Consulted only when a poll fails with the Bot API's 409, and appended to
1296
+ * the one line that failure produces. The CLI builds it from the per-machine
1297
+ * ownership registry (`core/channel-owner.ts`), so this class keeps no
1298
+ * knowledge of instances, directories or files — it asks the question and
1299
+ * prints the caller's answer, the same arrangement {@link
1300
+ * TelegramConfig.describeAction} uses for the log.
1301
+ */
1302
+ conflictAdvice?: () => string | null;
1209
1303
  }
1210
1304
  /**
1211
1305
  * What {@link TelegramChannel.notifyBatch} did with a set (APRV-115).
@@ -1563,6 +1657,24 @@ export declare class TelegramChannel implements TestableChannel {
1563
1657
  * HTML-mode message is.
1564
1658
  */
1565
1659
  announce(lines: string[]): Promise<DeliveryId>;
1660
+ /**
1661
+ * Which bot this token is, from one `getMe` (APRV-390).
1662
+ *
1663
+ * `getMe` is the only Bot API call that answers it, and it is the call
1664
+ * `approval doctor` and `approval setup channel telegram` already make for
1665
+ * the same reason: it mutates nothing, sends nothing, and acknowledges
1666
+ * nothing. In particular it is NOT `getUpdates`, so asking who this bot is
1667
+ * consumes no update and steals no pending tap from a listener that is
1668
+ * already running — which matters here above all, because the answer is
1669
+ * what decides whether this process is allowed to poll at all.
1670
+ *
1671
+ * Throws {@link TelegramApiError} like every other call; the caller decides
1672
+ * whether an unreachable Bot API is a refusal or a shrug.
1673
+ */
1674
+ identify(): Promise<{
1675
+ id: string;
1676
+ username: string;
1677
+ }>;
1566
1678
  /**
1567
1679
  * Long-poll `getUpdates` until {@link stop} is called (or one batch, with
1568
1680
  * `once`).