@fungi.computer/approvals 0.2.9 → 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/dist/ledger.d.ts CHANGED
@@ -29,6 +29,8 @@ export type ApprovalRequest = Readonly<{
29
29
  inputJson: string;
30
30
  /** The waiting call's own deadline: the record never outlives the call that asked. */
31
31
  expiresAt?: number;
32
+ /** The Agent command that asked, so cancelling it can withdraw its own cards only. */
33
+ commandId?: string;
32
34
  /** Host-only containment escalation: a general auto-approve rule cannot bypass the sandbox. */
33
35
  requireHumanApproval?: boolean;
34
36
  /** Host-attested matching command-prefix policy; independent of the general auto-approve switch. */
@@ -136,6 +138,12 @@ export declare class ApprovalLedger {
136
138
  record: ApprovalRecord;
137
139
  created: boolean;
138
140
  }> | ApprovalRefusal>;
141
+ /**
142
+ * A fresh tool identity asking for the same App write while one is still
143
+ * open joins that record: a person sees one card, never a stack of copies.
144
+ * A policy-approved record is applying inside its own call, so it is never joined.
145
+ */
146
+ private openDuplicate;
139
147
  /** A fresh tool identity cannot authorize repeating an uncertain App write. */
140
148
  private uncertainAppWrite;
141
149
  /** Answering is revision-pinned and never changes the requester's underlying grants. */
@@ -158,14 +166,61 @@ export declare class ApprovalLedger {
158
166
  selectAutoApprove(query: AutoApproveQuery): boolean;
159
167
  /** Withdraw an unclaimed call; a claimed effect must retain its outcome record. */
160
168
  withdraw(recordId: string): void;
161
- /** Native boot only: a prior owner's waiting calls no longer exist. */
169
+ /**
170
+ * Native boot of a home whose requests wait inside a live call (Oyster):
171
+ * the calls that waited died with their isolate. A Team home parks its
172
+ * requests and never calls this.
173
+ */
162
174
  withdrawWaiting(): number;
175
+ /**
176
+ * The person cancelled or deleted a Session: its unanswered requests made up
177
+ * to `before` end with it and owe the Agent no follow-up. One bounded batch;
178
+ * a caller repeats until it returns 0.
179
+ */
180
+ withdrawForSession(sessionId: string, before: number): number;
181
+ /**
182
+ * One Agent command was cancelled. A card a second command joined stays until
183
+ * every command that asked for it has been cancelled; a card only this command
184
+ * wanted ends, silently. Other Sessions' and commands' cards are untouched.
185
+ * One bounded batch; a caller repeats until it returns 0.
186
+ */
187
+ withdrawForCommand(sessionId: string, commandId: string): number;
188
+ /** The Agent is gone: every unanswered request it made ends, silently. One bounded batch. */
189
+ withdrawForAgent(agentId: string): number;
190
+ private withdrawMatching;
191
+ /**
192
+ * The requester was told this request is waiting: the home now owes it
193
+ * exactly one follow-up once the record ends. Asking again changes nothing.
194
+ */
195
+ expectDelivery(recordId: string, commandId: string | null): void;
196
+ /** Keep the App's own words for a write that failed, so a restart cannot lose them. */
197
+ recordDeliveryCause(recordId: string, cause: string): void;
198
+ /** Ended records whose follow-up is owed and due, oldest first; bounded, no side effects. */
199
+ dueDeliveries(limit: number): readonly Readonly<{
200
+ record: ApprovalRecord;
201
+ attempts: number;
202
+ cause: string | null;
203
+ }>[];
204
+ /** Earliest time a deferred follow-up is due again, or null when none waits. */
205
+ nextDeliveryAt(): number | null;
206
+ /** The follow-up reached its Session, or can never reach it; either way it is done. */
207
+ finishDelivery(recordId: string, outcome: "delivered" | "undeliverable"): void;
208
+ /** A failed attempt: try again at `nextAt`. */
209
+ deferDelivery(recordId: string, nextAt: number): void;
163
210
  /** Expire one bounded home-local quantum without a member read or an approval. */
164
211
  expirePending(): void;
165
212
  /** Earliest native wake for waiting or unfinished effects; no claim or dispatch. */
166
213
  nextWakeAt(): number | null;
167
214
  /** Bounded approved work for the native owner; selection never claims or dispatches. */
168
215
  pendingApplications(): readonly string[];
216
+ /**
217
+ * Team boot: a policy approval applies inside the call that asked, and that
218
+ * call died with its isolate, so the unclaimed record must never run alone.
219
+ * One bounded batch; a caller repeats until it returns 0.
220
+ */
221
+ withdrawPolicyApproved(): number;
222
+ /** The recorded output of an applied record, for the follow-up that reports it. */
223
+ readOutput(recordId: string): typeof Schema.Json.Type | null;
169
224
  /** Host-private display recovery; never exposed by the member-bound capability. */
170
225
  readInput(recordId: string): typeof Schema.Json.Type | null;
171
226
  /**
package/dist/ledger.js CHANGED
@@ -19,6 +19,7 @@ const decodeRecord = Schema.decodeUnknownSync(Schema.fromJsonString(ApprovalReco
19
19
  const encodeRecord = Schema.encodeSync(Schema.fromJsonString(ApprovalRecordSchema));
20
20
  const decodeRow = Schema.decodeUnknownSync(Schema.Struct({ record_json: Schema.String }));
21
21
  const decodeJson = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Json));
22
+ const decodeRecordId = Schema.decodeUnknownSync(Schema.Struct({ record_id: ApprovalRecordSchema.fields.recordId }));
22
23
  const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Json));
23
24
  const decodePayload = Schema.decodeUnknownSync(Schema.Struct({
24
25
  input_json: Schema.String,
@@ -41,6 +42,8 @@ export class ApprovalLedger {
41
42
  options.owner.sql.exec("CREATE TABLE IF NOT EXISTS approval_records (home_key TEXT NOT NULL, record_id TEXT NOT NULL, record_json TEXT NOT NULL, PRIMARY KEY (home_key, record_id))");
42
43
  options.owner.sql.exec("CREATE INDEX IF NOT EXISTS approval_records_by_state ON approval_records (home_key, json_extract(record_json, '$.state'), record_id)");
43
44
  options.owner.sql.exec("CREATE TABLE IF NOT EXISTS approval_payloads (home_key TEXT NOT NULL, record_id TEXT NOT NULL, input_json TEXT NOT NULL, output_json TEXT, PRIMARY KEY (home_key, record_id))");
45
+ options.owner.sql.exec("CREATE TABLE IF NOT EXISTS approval_commands (home_key TEXT NOT NULL, record_id TEXT NOT NULL, command_id TEXT NOT NULL, PRIMARY KEY (home_key, record_id, command_id))");
46
+ options.owner.sql.exec("CREATE TABLE IF NOT EXISTS approval_deliveries (home_key TEXT NOT NULL, record_id TEXT NOT NULL, state TEXT NOT NULL, attempts INTEGER NOT NULL, next_at INTEGER NOT NULL, cause TEXT, PRIMARY KEY (home_key, record_id))");
44
47
  }
45
48
  /** Bound control surface; null identity means membership is gone, never an impersonated key. */
46
49
  capability(host) {
@@ -216,6 +219,9 @@ export class ApprovalLedger {
216
219
  return { kind: "refused", reason: "identity-conflict" };
217
220
  return { kind: "record", record: existing, created: false };
218
221
  }
222
+ const open = this.openDuplicate(request, inputSha256);
223
+ if (open !== null)
224
+ return { kind: "record", record: open, created: false };
219
225
  const uncertain = this.uncertainAppWrite(request, inputSha256);
220
226
  if (uncertain !== null)
221
227
  return { kind: "record", record: uncertain, created: false };
@@ -260,6 +266,32 @@ export class ApprovalLedger {
260
266
  return { kind: "record", record, created: true };
261
267
  });
262
268
  }
269
+ /**
270
+ * A fresh tool identity asking for the same App write while one is still
271
+ * open joins that record: a person sees one card, never a stack of copies.
272
+ * A policy-approved record is applying inside its own call, so it is never joined.
273
+ */
274
+ openDuplicate(request, inputSha256) {
275
+ if (this.options.home.kind !== "team" ||
276
+ request.app === undefined ||
277
+ request.requester.sessionId === null)
278
+ return null;
279
+ const rows = this.options.owner.sql
280
+ .exec("SELECT record_id FROM approval_records WHERE home_key = ? AND json_extract(record_json, '$.state') IN ('requested', 'pending', 'approved', 'claimed') AND json_extract(record_json, '$.by.kind') IS NOT 'policy' AND json_extract(record_json, '$.requester.principalId') = ? AND json_extract(record_json, '$.requester.agentId') IS ? AND json_extract(record_json, '$.requester.sessionId') = ? AND json_extract(record_json, '$.module') = ? AND json_extract(record_json, '$.operation') = ? AND json_extract(record_json, '$.access') = ? AND json_extract(record_json, '$.authorityFence') = ? AND json_extract(record_json, '$.description.inputSha256') = ? ORDER BY record_id LIMIT 1", this.homeKey, request.requester.principalId, request.requester.agentId, request.requester.sessionId, request.module, request.operation, request.access, request.authorityFence, inputSha256)
281
+ .toArray();
282
+ const [row] = rows;
283
+ if (row === undefined)
284
+ return null;
285
+ // A pending record past its deadline expires on read and is not open.
286
+ const record = this.get(decodeRecordId(row).record_id);
287
+ return record !== null &&
288
+ (record.state === "pending" ||
289
+ record.state === "approved" ||
290
+ record.state === "claimed" ||
291
+ record.state === "requested")
292
+ ? record
293
+ : null;
294
+ }
263
295
  /** A fresh tool identity cannot authorize repeating an uncertain App write. */
264
296
  uncertainAppWrite(request, inputSha256) {
265
297
  if (this.options.home.kind !== "team" ||
@@ -360,7 +392,11 @@ export class ApprovalLedger {
360
392
  });
361
393
  });
362
394
  }
363
- /** Native boot only: a prior owner's waiting calls no longer exist. */
395
+ /**
396
+ * Native boot of a home whose requests wait inside a live call (Oyster):
397
+ * the calls that waited died with their isolate. A Team home parks its
398
+ * requests and never calls this.
399
+ */
364
400
  withdrawWaiting() {
365
401
  const decode = Schema.decodeUnknownSync(Schema.Struct({ record_id: ApprovalRecordSchema.fields.recordId }));
366
402
  const rows = this.options.owner.sql
@@ -370,6 +406,103 @@ export class ApprovalLedger {
370
406
  this.withdraw(decode(row).record_id);
371
407
  return rows.length;
372
408
  }
409
+ /**
410
+ * The person cancelled or deleted a Session: its unanswered requests made up
411
+ * to `before` end with it and owe the Agent no follow-up. One bounded batch;
412
+ * a caller repeats until it returns 0.
413
+ */
414
+ withdrawForSession(sessionId, before) {
415
+ return this.withdrawMatching("json_extract(record_json, '$.requester.sessionId') = ? AND json_extract(record_json, '$.requestedAt') <= ?", sessionId, before);
416
+ }
417
+ /**
418
+ * One Agent command was cancelled. A card a second command joined stays until
419
+ * every command that asked for it has been cancelled; a card only this command
420
+ * wanted ends, silently. Other Sessions' and commands' cards are untouched.
421
+ * One bounded batch; a caller repeats until it returns 0.
422
+ */
423
+ withdrawForCommand(sessionId, commandId) {
424
+ const decode = Schema.decodeUnknownSync(Schema.Struct({ record_id: ApprovalRecordSchema.fields.recordId }));
425
+ const rows = this.options.owner.sql
426
+ .exec("SELECT c.record_id AS record_id FROM approval_commands c JOIN approval_records r ON r.home_key = c.home_key AND r.record_id = c.record_id WHERE c.home_key = ? AND c.command_id = ? AND json_extract(r.record_json, '$.requester.sessionId') = ? ORDER BY c.record_id LIMIT 100", this.homeKey, commandId, sessionId)
427
+ .toArray();
428
+ for (const row of rows) {
429
+ const { record_id: recordId } = decode(row);
430
+ this.options.owner.transactionSync(() => {
431
+ this.options.owner.sql.exec("DELETE FROM approval_commands WHERE home_key = ? AND record_id = ? AND command_id = ?", this.homeKey, recordId, commandId);
432
+ const left = Schema.decodeUnknownSync(Schema.Struct({ n: Schema.Int }))(this.options.owner.sql
433
+ .exec("SELECT COUNT(*) AS n FROM approval_commands WHERE home_key = ? AND record_id = ?", this.homeKey, recordId)
434
+ .toArray()[0]).n;
435
+ if (left > 0)
436
+ return;
437
+ this.withdraw(recordId);
438
+ this.options.owner.sql.exec("UPDATE approval_deliveries SET state = 'cancelled' WHERE home_key = ? AND record_id = ? AND state = 'owed'", this.homeKey, recordId);
439
+ });
440
+ }
441
+ return rows.length;
442
+ }
443
+ /** The Agent is gone: every unanswered request it made ends, silently. One bounded batch. */
444
+ withdrawForAgent(agentId) {
445
+ return this.withdrawMatching("json_extract(record_json, '$.requester.agentId') = ?", agentId);
446
+ }
447
+ withdrawMatching(condition, ...params) {
448
+ const rows = this.options.owner.sql
449
+ .exec(`SELECT record_id FROM approval_records WHERE home_key = ? AND json_extract(record_json, '$.state') IN ('pending', 'approved') AND ${condition} ORDER BY record_id LIMIT 100`, this.homeKey, ...params)
450
+ .toArray();
451
+ for (const row of rows) {
452
+ const { record_id: recordId } = decodeRecordId(row);
453
+ this.withdraw(recordId);
454
+ this.options.owner.sql.exec("UPDATE approval_deliveries SET state = 'cancelled' WHERE home_key = ? AND record_id = ? AND state = 'owed'", this.homeKey, recordId);
455
+ }
456
+ return rows.length;
457
+ }
458
+ /**
459
+ * The requester was told this request is waiting: the home now owes it
460
+ * exactly one follow-up once the record ends. Asking again changes nothing.
461
+ */
462
+ expectDelivery(recordId, commandId) {
463
+ this.options.owner.sql.exec("INSERT OR IGNORE INTO approval_deliveries (home_key, record_id, state, attempts, next_at) VALUES (?, ?, 'owed', 0, 0)", this.homeKey, recordId);
464
+ // A second command asking for the same open card is recorded too: the card
465
+ // outlives the first command's cancel while another still wants it.
466
+ if (commandId !== null)
467
+ this.options.owner.sql.exec("INSERT OR IGNORE INTO approval_commands (home_key, record_id, command_id) VALUES (?, ?, ?)", this.homeKey, recordId, commandId);
468
+ }
469
+ /** Keep the App's own words for a write that failed, so a restart cannot lose them. */
470
+ recordDeliveryCause(recordId, cause) {
471
+ this.options.owner.sql.exec("UPDATE approval_deliveries SET cause = ? WHERE home_key = ? AND record_id = ?", cause.slice(0, 1000), this.homeKey, recordId);
472
+ }
473
+ /** Ended records whose follow-up is owed and due, oldest first; bounded, no side effects. */
474
+ dueDeliveries(limit) {
475
+ const decode = Schema.decodeUnknownSync(Schema.Struct({
476
+ record_id: ApprovalRecordSchema.fields.recordId,
477
+ attempts: Schema.Int,
478
+ cause: Schema.NullOr(Schema.String),
479
+ }));
480
+ return this.options.owner.sql
481
+ .exec("SELECT d.record_id AS record_id, d.attempts AS attempts, d.cause AS cause FROM approval_deliveries d JOIN approval_records r ON r.home_key = d.home_key AND r.record_id = d.record_id WHERE d.home_key = ? AND d.state = 'owed' AND d.next_at <= ? AND json_extract(r.record_json, '$.state') IN ('applied', 'denied', 'expired', 'outcome_unknown') ORDER BY d.record_id LIMIT ?", this.homeKey, this.options.now(), limit)
482
+ .toArray()
483
+ .flatMap((raw) => {
484
+ const row = decode(raw);
485
+ const record = this.get(row.record_id);
486
+ return record === null
487
+ ? []
488
+ : [{ record, attempts: row.attempts, cause: row.cause }];
489
+ });
490
+ }
491
+ /** Earliest time a deferred follow-up is due again, or null when none waits. */
492
+ nextDeliveryAt() {
493
+ const row = this.options.owner.sql
494
+ .exec("SELECT MIN(d.next_at) AS due FROM approval_deliveries d JOIN approval_records r ON r.home_key = d.home_key AND r.record_id = d.record_id WHERE d.home_key = ? AND d.state = 'owed' AND json_extract(r.record_json, '$.state') IN ('applied', 'denied', 'expired', 'outcome_unknown')", this.homeKey)
495
+ .toArray()[0];
496
+ return Schema.decodeUnknownSync(Schema.Struct({ due: Schema.NullOr(Schema.Int) }))(row).due;
497
+ }
498
+ /** The follow-up reached its Session, or can never reach it; either way it is done. */
499
+ finishDelivery(recordId, outcome) {
500
+ this.options.owner.sql.exec("UPDATE approval_deliveries SET state = ? WHERE home_key = ? AND record_id = ? AND state = 'owed'", outcome, this.homeKey, recordId);
501
+ }
502
+ /** A failed attempt: try again at `nextAt`. */
503
+ deferDelivery(recordId, nextAt) {
504
+ this.options.owner.sql.exec("UPDATE approval_deliveries SET attempts = attempts + 1, next_at = ? WHERE home_key = ? AND record_id = ? AND state = 'owed'", nextAt, this.homeKey, recordId);
505
+ }
373
506
  /** Expire one bounded home-local quantum without a member read or an approval. */
374
507
  expirePending() {
375
508
  const decode = Schema.decodeUnknownSync(Schema.Struct({
@@ -400,6 +533,24 @@ export class ApprovalLedger {
400
533
  .toArray()
401
534
  .map((row) => decode(row).record_id);
402
535
  }
536
+ /**
537
+ * Team boot: a policy approval applies inside the call that asked, and that
538
+ * call died with its isolate, so the unclaimed record must never run alone.
539
+ * One bounded batch; a caller repeats until it returns 0.
540
+ */
541
+ withdrawPolicyApproved() {
542
+ const rows = this.options.owner.sql
543
+ .exec("SELECT record_id FROM approval_records WHERE home_key = ? AND json_extract(record_json, '$.state') = 'approved' AND json_extract(record_json, '$.by.kind') = 'policy' ORDER BY record_id LIMIT 100", this.homeKey)
544
+ .toArray();
545
+ for (const row of rows)
546
+ this.withdraw(decodeRecordId(row).record_id);
547
+ return rows.length;
548
+ }
549
+ /** The recorded output of an applied record, for the follow-up that reports it. */
550
+ readOutput(recordId) {
551
+ const output = this.get(recordId) === null ? null : this.payload(recordId).output_json;
552
+ return output === null ? null : decodeJson(output);
553
+ }
403
554
  /** Host-private display recovery; never exposed by the member-bound capability. */
404
555
  readInput(recordId) {
405
556
  if (this.get(recordId) === null)
@@ -521,12 +521,266 @@ Withdraw an unclaimed call; a claimed effect must retain its outcome record.
521
521
  withdrawWaiting(): number;
522
522
  ```
523
523
 
524
- Native boot only: a prior owner's waiting calls no longer exist.
524
+ Native boot of a home whose requests wait inside a live call (Oyster): the calls
525
+ that waited died with their isolate. A Team home parks its requests and never
526
+ calls this.
525
527
 
526
528
  ###### Returns
527
529
 
528
530
  `number`
529
531
 
532
+ ##### withdrawForSession()
533
+
534
+ ```ts
535
+ withdrawForSession(sessionId, before): number;
536
+ ```
537
+
538
+ The person cancelled or deleted a Session: its unanswered requests made up to
539
+ `before` end with it and owe the Agent no follow-up. One bounded batch; a caller
540
+ repeats until it returns 0.
541
+
542
+ ###### Parameters
543
+
544
+ | Parameter | Type |
545
+ | ----------- | -------- |
546
+ | `sessionId` | `string` |
547
+ | `before` | `number` |
548
+
549
+ ###### Returns
550
+
551
+ `number`
552
+
553
+ ##### withdrawForCommand()
554
+
555
+ ```ts
556
+ withdrawForCommand(sessionId, commandId): number;
557
+ ```
558
+
559
+ One Agent command was cancelled. A card a second command joined stays until
560
+ every command that asked for it has been cancelled; a card only this command
561
+ wanted ends, silently. Other Sessions' and commands' cards are untouched. One
562
+ bounded batch; a caller repeats until it returns 0.
563
+
564
+ ###### Parameters
565
+
566
+ | Parameter | Type |
567
+ | ----------- | -------- |
568
+ | `sessionId` | `string` |
569
+ | `commandId` | `string` |
570
+
571
+ ###### Returns
572
+
573
+ `number`
574
+
575
+ ##### withdrawForAgent()
576
+
577
+ ```ts
578
+ withdrawForAgent(agentId): number;
579
+ ```
580
+
581
+ The Agent is gone: every unanswered request it made ends, silently. One bounded
582
+ batch.
583
+
584
+ ###### Parameters
585
+
586
+ | Parameter | Type |
587
+ | --------- | -------- |
588
+ | `agentId` | `string` |
589
+
590
+ ###### Returns
591
+
592
+ `number`
593
+
594
+ ##### expectDelivery()
595
+
596
+ ```ts
597
+ expectDelivery(recordId, commandId): void;
598
+ ```
599
+
600
+ The requester was told this request is waiting: the home now owes it exactly one
601
+ follow-up once the record ends. Asking again changes nothing.
602
+
603
+ ###### Parameters
604
+
605
+ | Parameter | Type |
606
+ | ----------- | ------------------ |
607
+ | `recordId` | `string` |
608
+ | `commandId` | `string` \| `null` |
609
+
610
+ ###### Returns
611
+
612
+ `void`
613
+
614
+ ##### recordDeliveryCause()
615
+
616
+ ```ts
617
+ recordDeliveryCause(recordId, cause): void;
618
+ ```
619
+
620
+ Keep the App's own words for a write that failed, so a restart cannot lose them.
621
+
622
+ ###### Parameters
623
+
624
+ | Parameter | Type |
625
+ | ---------- | -------- |
626
+ | `recordId` | `string` |
627
+ | `cause` | `string` |
628
+
629
+ ###### Returns
630
+
631
+ `void`
632
+
633
+ ##### dueDeliveries()
634
+
635
+ ```ts
636
+ dueDeliveries(limit): readonly Readonly<{
637
+ record: {
638
+ recordId: string;
639
+ requester: {
640
+ principalId: string;
641
+ agentId: string | null;
642
+ sessionId: string | null;
643
+ displayName: string;
644
+ };
645
+ module: string;
646
+ operation: string;
647
+ access: "write" | "external";
648
+ description: {
649
+ title: string;
650
+ app?: {
651
+ displayName: string;
652
+ operationLabel: string;
653
+ };
654
+ inputBytes: number;
655
+ inputSha256: string;
656
+ };
657
+ evidence?: readonly object[];
658
+ authorityFence: string;
659
+ reversibility: "reversible" | "irreversible-external";
660
+ state: | "pending"
661
+ | "expired"
662
+ | "denied"
663
+ | "requested"
664
+ | "approved"
665
+ | "claimed"
666
+ | "applied"
667
+ | "outcome_unknown";
668
+ by: | {
669
+ kind: "human";
670
+ memberId: string;
671
+ }
672
+ | {
673
+ kind: "policy";
674
+ }
675
+ | null;
676
+ reason: | "pending"
677
+ | "expired"
678
+ | "not-found"
679
+ | "not-eligible"
680
+ | "already-answered"
681
+ | "stale-revision"
682
+ | "declined"
683
+ | "fenced"
684
+ | "not-granted"
685
+ | "read-only"
686
+ | "not-executed"
687
+ | "in-flight"
688
+ | "outcome-unknown"
689
+ | "identity-conflict"
690
+ | null;
691
+ refusalDetail?: string;
692
+ refusalCode?: "too_large";
693
+ denialNote?: string;
694
+ requestedAt: number;
695
+ expiresAt: number;
696
+ updatedAt: number;
697
+ revision: number;
698
+ };
699
+ attempts: number;
700
+ cause: string | null;
701
+ }>[];
702
+ ```
703
+
704
+ Ended records whose follow-up is owed and due, oldest first; bounded, no side
705
+ effects.
706
+
707
+ ###### Parameters
708
+
709
+ | Parameter | Type |
710
+ | --------- | -------- |
711
+ | `limit` | `number` |
712
+
713
+ ###### Returns
714
+
715
+ readonly `Readonly`\<\{ `record`: \{ `recordId`: `string`; `requester`: \{
716
+ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \|
717
+ `null`; `displayName`: `string`; \}; `module`: `string`; `operation`: `string`;
718
+ `access`: `"write"` \| `"external"`; `description`: \{ `title`: `string`;
719
+ `app?`: \{ `displayName`: `string`; `operationLabel`: `string`; \};
720
+ `inputBytes`: `number`; `inputSha256`: `string`; \}; `evidence?`: readonly
721
+ `object`[]; `authorityFence`: `string`; `reversibility`: `"reversible"` \|
722
+ `"irreversible-external"`; `state`: \| `"pending"` \| `"expired"` \| `"denied"`
723
+ \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \|
724
+ `"outcome_unknown"`; `by`: \| \{ `kind`: `"human"`; `memberId`: `string`; \} \|
725
+ \{ `kind`: `"policy"`; \} \| `null`; `reason`: \| `"pending"` \| `"expired"` \|
726
+ `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"`
727
+ \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \|
728
+ `"not-executed"` \| `"in-flight"` \| `"outcome-unknown"` \|
729
+ `"identity-conflict"` \| `null`; `refusalDetail?`: `string`; `refusalCode?`:
730
+ `"too_large"`; `denialNote?`: `string`; `requestedAt`: `number`; `expiresAt`:
731
+ `number`; `updatedAt`: `number`; `revision`: `number`; \}; `attempts`: `number`;
732
+ `cause`: `string` \| `null`; \}\>[]
733
+
734
+ ##### nextDeliveryAt()
735
+
736
+ ```ts
737
+ nextDeliveryAt(): number | null;
738
+ ```
739
+
740
+ Earliest time a deferred follow-up is due again, or null when none waits.
741
+
742
+ ###### Returns
743
+
744
+ `number` \| `null`
745
+
746
+ ##### finishDelivery()
747
+
748
+ ```ts
749
+ finishDelivery(recordId, outcome): void;
750
+ ```
751
+
752
+ The follow-up reached its Session, or can never reach it; either way it is done.
753
+
754
+ ###### Parameters
755
+
756
+ | Parameter | Type |
757
+ | ---------- | ---------------------------------- |
758
+ | `recordId` | `string` |
759
+ | `outcome` | `"delivered"` \| `"undeliverable"` |
760
+
761
+ ###### Returns
762
+
763
+ `void`
764
+
765
+ ##### deferDelivery()
766
+
767
+ ```ts
768
+ deferDelivery(recordId, nextAt): void;
769
+ ```
770
+
771
+ A failed attempt: try again at `nextAt`.
772
+
773
+ ###### Parameters
774
+
775
+ | Parameter | Type |
776
+ | ---------- | -------- |
777
+ | `recordId` | `string` |
778
+ | `nextAt` | `number` |
779
+
780
+ ###### Returns
781
+
782
+ `void`
783
+
530
784
  ##### expirePending()
531
785
 
532
786
  ```ts
@@ -564,6 +818,38 @@ dispatches.
564
818
 
565
819
  readonly `string`[]
566
820
 
821
+ ##### withdrawPolicyApproved()
822
+
823
+ ```ts
824
+ withdrawPolicyApproved(): number;
825
+ ```
826
+
827
+ Team boot: a policy approval applies inside the call that asked, and that call
828
+ died with its isolate, so the unclaimed record must never run alone. One bounded
829
+ batch; a caller repeats until it returns 0.
830
+
831
+ ###### Returns
832
+
833
+ `number`
834
+
835
+ ##### readOutput()
836
+
837
+ ```ts
838
+ readOutput(recordId): Json;
839
+ ```
840
+
841
+ The recorded output of an applied record, for the follow-up that reports it.
842
+
843
+ ###### Parameters
844
+
845
+ | Parameter | Type |
846
+ | ---------- | -------- |
847
+ | `recordId` | `string` |
848
+
849
+ ###### Returns
850
+
851
+ `Json`
852
+
567
853
  ##### readInput()
568
854
 
569
855
  ```ts
@@ -938,6 +1224,7 @@ type ApprovalRequest = Readonly<{
938
1224
  idempotencyKey: string;
939
1225
  inputJson: string;
940
1226
  expiresAt?: number;
1227
+ commandId?: string;
941
1228
  requireHumanApproval?: boolean;
942
1229
  prefixPolicyApproved?: boolean;
943
1230
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/approvals",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Durable principal-bound approval records and auto-approve policy",
6
6
  "type": "module",