@fungi.computer/approvals 0.0.2 → 0.2.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 CHANGED
@@ -145,12 +145,12 @@ to current grants, the authority fence, or containment.
145
145
 
146
146
  Local is an explicit ledger home with default ON, like Oyster; Team defaults
147
147
  OFF. The Local adapter supplies its native SQLite owner. Containment is owned by
148
- the Local sandbox integration, not this policy read: use a sandbox whenever one
149
- is available; its absence does not turn auto-approve OFF. An explicit
150
- requirement for sandboxed execution is a containment choice, not another
151
- approval switch. This package does not choose a Local database path, start a
152
- sandbox, display the one-time uncontained notice, or replace the runtime's
153
- current-authority check.
148
+ the Local sandbox integration, not this policy read. Sandbox escapes set
149
+ `requireHumanApproval`, so general auto-approve cannot widen a sandboxed
150
+ command. After the Local host verifies a protected direct-argv prefix rule, it
151
+ sets `prefixPolicyApproved` for that one request; the ledger records a policy
152
+ decision and applies it inline through the ordinary authority recheck. The
153
+ ledger does not parse shell text, store prefixes, or let an Agent manage them.
154
154
 
155
155
  ## Capability-attached visual evidence
156
156
 
@@ -39,6 +39,10 @@ export type PendingApproval = typeof PendingApprovalSchema.Type;
39
39
  export declare const ApprovalStateSchema: Schema.Literals<readonly ["requested", "pending", "approved", "claimed", "applied", "denied", "expired", "outcome_unknown"]>;
40
40
  /** Why a decision or apply was refused; unknown dispatch is never a denial. */
41
41
  export declare const ApprovalRefusalReasonSchema: Schema.Literals<readonly ["not-found", "not-eligible", "already-answered", "stale-revision", "expired", "declined", "fenced", "not-granted", "read-only", "pending", "in-flight", "outcome-unknown", "identity-conflict"]>;
42
+ /** Human explanation for a denied approval; distinct from the typed refusal cause. */
43
+ export declare const MAX_APPROVAL_DENIAL_NOTE_LENGTH = 512;
44
+ /** Bounded nonempty human feedback; user text, never approval authority. */
45
+ export declare const ApprovalDenialNoteSchema: Schema.String;
42
46
  /** Defensive display limits, not authority to fetch or interpret image content. */
43
47
  export declare const MAX_APPROVAL_EVIDENCE = 4;
44
48
  /** Maximum attested PNG byte length in one evidence descriptor. */
@@ -85,6 +89,7 @@ export declare const ApprovalRecordSchema: Schema.Struct<{
85
89
  readonly kind: Schema.Literal<"policy">;
86
90
  }>]>>;
87
91
  readonly reason: Schema.NullOr<Schema.Literals<readonly ["not-found", "not-eligible", "already-answered", "stale-revision", "expired", "declined", "fenced", "not-granted", "read-only", "pending", "in-flight", "outcome-unknown", "identity-conflict"]>>;
92
+ readonly denialNote: Schema.optionalKey<Schema.String>;
88
93
  readonly requestedAt: Schema.Int;
89
94
  readonly expiresAt: Schema.Int;
90
95
  readonly updatedAt: Schema.Int;
@@ -124,6 +129,7 @@ export declare const ApprovalViewSchema: Schema.Struct<{
124
129
  readonly kind: Schema.Literal<"policy">;
125
130
  }>]>>;
126
131
  readonly reason: Schema.NullOr<Schema.Literals<readonly ["not-found", "not-eligible", "already-answered", "stale-revision", "expired", "declined", "fenced", "not-granted", "read-only", "pending", "in-flight", "outcome-unknown", "identity-conflict"]>>;
132
+ readonly denialNote: Schema.optionalKey<Schema.String>;
127
133
  readonly requestedAt: Schema.Int;
128
134
  readonly expiresAt: Schema.Int;
129
135
  readonly updatedAt: Schema.Int;
@@ -147,6 +153,7 @@ export declare const ApprovalAnswerInputSchema: Schema.Struct<{
147
153
  readonly recordId: Schema.String;
148
154
  readonly decision: Schema.Literals<readonly ["approve", "deny"]>;
149
155
  readonly expectedRevision: Schema.Int;
156
+ readonly denialNote: Schema.optionalKey<Schema.String>;
150
157
  }>;
151
158
  /** Explicit policy mutation. A false rule narrows a broader true rule. */
152
159
  export declare const AutoApproveInputSchema: Schema.Struct<{
@@ -173,6 +180,7 @@ export type AutoApproveInput = typeof AutoApproveInputSchema.Type;
173
180
  export type ApprovalRefusal = Readonly<{
174
181
  kind: "refused";
175
182
  reason: typeof ApprovalRefusalReasonSchema.Type;
183
+ denialNote?: typeof ApprovalDenialNoteSchema.Type;
176
184
  }>;
177
185
  /** The member-bound capability. Host authentication supplies the actor. */
178
186
  export type Approvals = Readonly<{
package/dist/contract.js CHANGED
@@ -59,6 +59,10 @@ export const ApprovalRefusalReasonSchema = Schema.Literals([
59
59
  "outcome-unknown",
60
60
  "identity-conflict",
61
61
  ]);
62
+ /** Human explanation for a denied approval; distinct from the typed refusal cause. */
63
+ export const MAX_APPROVAL_DENIAL_NOTE_LENGTH = 512;
64
+ /** Bounded nonempty human feedback; user text, never approval authority. */
65
+ export const ApprovalDenialNoteSchema = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(MAX_APPROVAL_DENIAL_NOTE_LENGTH), Schema.isPattern(/^(?=.*\S)[^\p{Cc}\u2028\u2029]*$/u));
62
66
  /** Defensive display limits, not authority to fetch or interpret image content. */
63
67
  export const MAX_APPROVAL_EVIDENCE = 4;
64
68
  /** Maximum attested PNG byte length in one evidence descriptor. */
@@ -87,6 +91,7 @@ export const ApprovalRecordSchema = Schema.Struct({
87
91
  Schema.Struct({ kind: Schema.Literal("policy") }),
88
92
  ])),
89
93
  reason: Schema.NullOr(ApprovalRefusalReasonSchema),
94
+ denialNote: Schema.optionalKey(ApprovalDenialNoteSchema),
90
95
  requestedAt: Timestamp,
91
96
  expiresAt: Timestamp,
92
97
  updatedAt: Timestamp,
@@ -111,6 +116,7 @@ export const ApprovalAnswerInputSchema = Schema.Struct({
111
116
  recordId: Identity,
112
117
  decision: Schema.Literals(["approve", "deny"]),
113
118
  expectedRevision: Revision,
119
+ denialNote: Schema.optionalKey(ApprovalDenialNoteSchema),
114
120
  });
115
121
  /** Explicit policy mutation. A false rule narrows a broader true rule. */
116
122
  export const AutoApproveInputSchema = Schema.Struct({
@@ -0,0 +1,3 @@
1
+ import type { ApprovalRecord } from "./contract.js";
2
+ /** Host-supplied human identity; the bounded reason remains quoted user text. */
3
+ export declare function denialFeedbackOpening(record: ApprovalRecord, person: string): string | null;
@@ -0,0 +1,8 @@
1
+ /** Host-supplied human identity; the bounded reason remains quoted user text. */
2
+ export function denialFeedbackOpening(record, person) {
3
+ return record.state === "denied" &&
4
+ record.by?.kind === "human" &&
5
+ record.denialNote !== undefined
6
+ ? `Denied by ${JSON.stringify(person)}: ${JSON.stringify(record.denialNote)}`
7
+ : null;
8
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./contract.js";
2
+ export { denialFeedbackOpening } from "./denial-message.js";
2
3
  export { ApprovalLedger, ApprovalRefusalSchema, DEFAULT_APPROVAL_EXPIRY_MS, type AutoApproveQuery, type ApprovalHome, type ApprovalRequest, type ApprovalAnswerer, type ApprovalAdmission, type ApprovalRuleSetter, type ApprovalApplyHost, type ApprovalSubmitHost, type ApprovalDispatchCompletion, type ApprovalApplyResult, type ApprovalResultNotice, type ApprovalHandoffResult, } from "./ledger.js";
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./contract.js";
2
+ export { denialFeedbackOpening } from "./denial-message.js";
2
3
  export { ApprovalLedger, ApprovalRefusalSchema, DEFAULT_APPROVAL_EXPIRY_MS, } from "./ledger.js";
package/dist/ledger.d.ts CHANGED
@@ -5,6 +5,7 @@ import { type ApprovalEvidence, type ApprovalRecord, type Approvals, type Approv
5
5
  export declare const ApprovalRefusalSchema: Schema.Struct<{
6
6
  readonly kind: Schema.Literal<"refused">;
7
7
  readonly reason: Schema.Literals<readonly ["not-found", "not-eligible", "already-answered", "stale-revision", "expired", "declined", "fenced", "not-granted", "read-only", "pending", "in-flight", "outcome-unknown", "identity-conflict"]>;
8
+ readonly denialNote: Schema.optionalKey<Schema.String>;
8
9
  }>;
9
10
  /** Native owner of this ledger; the Local runtime supplies its own SQLite owner. */
10
11
  export type ApprovalHome = Readonly<{
@@ -22,6 +23,10 @@ export type ApprovalRequest = Readonly<{
22
23
  /** Persisted turn/tool identity and operation ordinal; never random on retry. */
23
24
  idempotencyKey: string;
24
25
  inputJson: string;
26
+ /** Host-only containment escalation: a general auto-approve rule cannot bypass the sandbox. */
27
+ requireHumanApproval?: boolean;
28
+ /** Host-attested matching command-prefix policy; independent of the general auto-approve switch. */
29
+ prefixPolicyApproved?: boolean;
25
30
  }>;
26
31
  /** Host-only policy read for an admitted Agent/module/access selection, not execution authority. */
27
32
  export type AutoApproveQuery = Readonly<{
@@ -172,6 +177,8 @@ export declare class ApprovalLedger {
172
177
  nextWakeAt(): number | null;
173
178
  /** Bounded approved work for the native owner; selection never claims or dispatches. */
174
179
  pendingApplications(): readonly string[];
180
+ /** Host-private display recovery; never exposed by the member-bound capability. */
181
+ readInput(recordId: string): typeof Schema.Json.Type | null;
175
182
  /** Bounded, home-local terminal notices for the native owner's work loop. */
176
183
  pendingHandoffs(): readonly string[];
177
184
  /**
@@ -196,6 +203,7 @@ export declare class ApprovalLedger {
196
203
  private finishDenied;
197
204
  /** Native host boot only: orphaned durable claims must never be redispatched. */
198
205
  recoverClaims(): readonly ApprovalRecord[];
206
+ private deniedResult;
199
207
  private payload;
200
208
  private save;
201
209
  /** Read a record from this home only; the maintained decoder owns stored JSON. */
package/dist/ledger.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import * as Schema from "effect/Schema";
2
- import { ApprovalRecordSchema, ApprovalEvidenceSchema, ApprovalRefusalReasonSchema, ApprovalGetInputSchema, ApprovalListInputSchema, ApprovalAnswerInputSchema, AutoApproveInputSchema, } from "./contract.js";
2
+ import { ApprovalRecordSchema, ApprovalEvidenceSchema, ApprovalRefusalReasonSchema, ApprovalDenialNoteSchema, ApprovalGetInputSchema, ApprovalListInputSchema, ApprovalAnswerInputSchema, AutoApproveInputSchema, } from "./contract.js";
3
3
  /** Canonical zero-effect or lifecycle refusal at a tool result boundary. */
4
4
  export const ApprovalRefusalSchema = Schema.Struct({
5
5
  kind: Schema.Literal("refused"),
6
6
  reason: ApprovalRefusalReasonSchema,
7
+ denialNote: Schema.optionalKey(ApprovalDenialNoteSchema),
7
8
  });
8
9
  const defaultAutoApprove = {
9
10
  team: false,
@@ -174,7 +175,7 @@ export class ApprovalLedger {
174
175
  return { kind: "applied", record, output: decodeJson(output) };
175
176
  }
176
177
  case "denied":
177
- return { kind: "refused", reason: record.reason ?? "declined" };
178
+ return this.deniedResult(record);
178
179
  case "expired":
179
180
  return { kind: "refused", reason: "expired" };
180
181
  case "outcome_unknown":
@@ -188,6 +189,8 @@ export class ApprovalLedger {
188
189
  async request(input, evidence) {
189
190
  // Preserve the reviewed identity, authority and payload across the digest await.
190
191
  const request = structuredClone(input);
192
+ if (request.requireHumanApproval && request.prefixPolicyApproved)
193
+ throw new Error("A human-required request cannot be policy-approved");
191
194
  const attachments = evidence === undefined
192
195
  ? {}
193
196
  : {
@@ -213,17 +216,20 @@ export class ApprovalLedger {
213
216
  if (existing !== null) {
214
217
  if (existing.description.inputSha256 !== inputSha256 ||
215
218
  existing.authorityFence !== request.authorityFence ||
219
+ (request.requireHumanApproval && existing.by?.kind === "policy") ||
216
220
  JSON.stringify(existing.evidence ?? []) !==
217
221
  JSON.stringify(attachments.evidence ?? []))
218
222
  return { kind: "refused", reason: "identity-conflict" };
219
223
  return { kind: "record", record: existing, created: false };
220
224
  }
221
225
  const now = this.options.now();
222
- const autoApproved = this.selectAutoApprove({
223
- agentId: request.requester.agentId,
224
- module: request.module,
225
- access: request.access,
226
- });
226
+ const autoApproved = request.prefixPolicyApproved === true ||
227
+ (!request.requireHumanApproval &&
228
+ this.selectAutoApprove({
229
+ agentId: request.requester.agentId,
230
+ module: request.module,
231
+ access: request.access,
232
+ }));
227
233
  const record = Schema.decodeUnknownSync(ApprovalRecordSchema, {
228
234
  onExcessProperty: "error",
229
235
  })({
@@ -264,6 +270,8 @@ export class ApprovalLedger {
264
270
  answer(input, actor) {
265
271
  if (!this.eligible(actor))
266
272
  return { kind: "refused", reason: "not-eligible" };
273
+ if (input.decision !== "deny" && input.denialNote !== undefined)
274
+ return { kind: "refused", reason: "not-eligible" };
267
275
  return this.options.owner.transactionSync(() => {
268
276
  const record = this.get(input.recordId);
269
277
  if (record === null)
@@ -282,8 +290,11 @@ export class ApprovalLedger {
282
290
  revision: record.revision + 1,
283
291
  updatedAt: this.options.now(),
284
292
  };
285
- this.save(answered);
286
- return { kind: "answered", record: answered };
293
+ const result = input.decision === "deny" && input.denialNote !== undefined
294
+ ? { ...answered, denialNote: input.denialNote }
295
+ : answered;
296
+ this.save(result);
297
+ return { kind: "answered", record: result };
287
298
  });
288
299
  }
289
300
  /** Policy changes are attributed; an Agent can never enable its own writes. */
@@ -367,6 +378,12 @@ export class ApprovalLedger {
367
378
  .toArray()
368
379
  .map((row) => decode(row).record_id);
369
380
  }
381
+ /** Host-private display recovery; never exposed by the member-bound capability. */
382
+ readInput(recordId) {
383
+ if (this.get(recordId) === null)
384
+ return null;
385
+ return decodeJson(this.payload(recordId).input_json);
386
+ }
370
387
  /** Bounded, home-local terminal notices for the native owner's work loop. */
371
388
  pendingHandoffs() {
372
389
  const decode = Schema.decodeUnknownSync(Schema.Struct({
@@ -416,7 +433,7 @@ export class ApprovalLedger {
416
433
  break;
417
434
  }
418
435
  case "denied":
419
- result = { kind: "refused", reason: record.reason ?? "declined" };
436
+ result = this.deniedResult(record);
420
437
  break;
421
438
  case "expired":
422
439
  result = { kind: "refused", reason: "expired" };
@@ -499,10 +516,7 @@ export class ApprovalLedger {
499
516
  if (record.state === "expired")
500
517
  return { kind: "refused", reason: "expired" };
501
518
  if (record.state === "denied")
502
- return {
503
- kind: "refused",
504
- reason: record.reason ?? "declined",
505
- };
519
+ return this.deniedResult(record);
506
520
  if (record.state === "claimed")
507
521
  return {
508
522
  kind: "refused",
@@ -618,6 +632,15 @@ export class ApprovalLedger {
618
632
  });
619
633
  });
620
634
  }
635
+ deniedResult(record) {
636
+ const refusal = {
637
+ kind: "refused",
638
+ reason: record.reason ?? "declined",
639
+ };
640
+ return record.denialNote === undefined
641
+ ? refusal
642
+ : { ...refusal, denialNote: record.denialNote };
643
+ }
621
644
  payload(recordId) {
622
645
  const raw = this.options.owner.sql
623
646
  .exec("SELECT input_json, output_json FROM approval_payloads WHERE home_key = ? AND record_id = ?", this.homeKey, recordId)
@@ -104,32 +104,33 @@ A retried request's current outcome, without claiming any work.
104
104
 
105
105
  ###### Parameters
106
106
 
107
- | Parameter | Type |
108
- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
109
- | `record` | \{ `recordId`: `string`; `requester`: \{ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`; \}; `module`: `string`; `operation`: `string`; `access`: `"write"` \| `"external"`; `description`: \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`: `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`: `string`; `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`: \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \| `"outcome_unknown"`; `by`: \| \{ `kind`: `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null`; `reason`: \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"` \| `null`; `requestedAt`: `number`; `expiresAt`: `number`; `updatedAt`: `number`; `revision`: `number`; \} |
110
- | `record.recordId` | `string` |
111
- | `record.requester` | \{ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`; \} |
112
- | `record.requester.principalId` | `string` |
113
- | `record.requester.agentId` | `string` \| `null` |
114
- | `record.requester.sessionId` | `string` \| `null` |
115
- | `record.requester.displayName` | `string` |
116
- | `record.module` | `string` |
117
- | `record.operation` | `string` |
118
- | `record.access` | `"write"` \| `"external"` |
119
- | `record.description` | \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`: `string`; \} |
120
- | `record.description.title` | `string` |
121
- | `record.description.inputBytes` | `number` |
122
- | `record.description.inputSha256` | `string` |
123
- | `record.evidence?` | readonly `object`[] |
124
- | `record.authorityFence` | `string` |
125
- | `record.reversibility` | `"reversible"` \| `"irreversible-external"` |
126
- | `record.state` | \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \| `"outcome_unknown"` |
127
- | `record.by` | \| \{ `kind`: `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null` |
128
- | `record.reason` | \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"` \| `null` |
129
- | `record.requestedAt` | `number` |
130
- | `record.expiresAt` | `number` |
131
- | `record.updatedAt` | `number` |
132
- | `record.revision` | `number` |
107
+ | Parameter | Type |
108
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
109
+ | `record` | \{ `recordId`: `string`; `requester`: \{ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`; \}; `module`: `string`; `operation`: `string`; `access`: `"write"` \| `"external"`; `description`: \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`: `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`: `string`; `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`: \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \| `"outcome_unknown"`; `by`: \| \{ `kind`: `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null`; `reason`: \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"` \| `null`; `denialNote?`: `string`; `requestedAt`: `number`; `expiresAt`: `number`; `updatedAt`: `number`; `revision`: `number`; \} |
110
+ | `record.recordId` | `string` |
111
+ | `record.requester` | \{ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`; \} |
112
+ | `record.requester.principalId` | `string` |
113
+ | `record.requester.agentId` | `string` \| `null` |
114
+ | `record.requester.sessionId` | `string` \| `null` |
115
+ | `record.requester.displayName` | `string` |
116
+ | `record.module` | `string` |
117
+ | `record.operation` | `string` |
118
+ | `record.access` | `"write"` \| `"external"` |
119
+ | `record.description` | \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`: `string`; \} |
120
+ | `record.description.title` | `string` |
121
+ | `record.description.inputBytes` | `number` |
122
+ | `record.description.inputSha256` | `string` |
123
+ | `record.evidence?` | readonly `object`[] |
124
+ | `record.authorityFence` | `string` |
125
+ | `record.reversibility` | `"reversible"` \| `"irreversible-external"` |
126
+ | `record.state` | \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \| `"outcome_unknown"` |
127
+ | `record.by` | \| \{ `kind`: `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null` |
128
+ | `record.reason` | \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"` \| `null` |
129
+ | `record.denialNote?` | `string` |
130
+ | `record.requestedAt` | `number` |
131
+ | `record.expiresAt` | `number` |
132
+ | `record.updatedAt` | `number` |
133
+ | `record.revision` | `number` |
133
134
 
134
135
  ###### Returns
135
136
 
@@ -156,6 +157,7 @@ request(input, evidence?): Promise<
156
157
  | "in-flight"
157
158
  | "outcome-unknown"
158
159
  | "identity-conflict";
160
+ denialNote?: string;
159
161
  }>
160
162
  | Readonly<{
161
163
  kind: "record";
@@ -208,6 +210,7 @@ request(input, evidence?): Promise<
208
210
  | "outcome-unknown"
209
211
  | "identity-conflict"
210
212
  | null;
213
+ denialNote?: string;
211
214
  requestedAt: number;
212
215
  expiresAt: number;
213
216
  updatedAt: number;
@@ -233,21 +236,22 @@ action; created says whether this call staged the record.
233
236
  `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \|
234
237
  `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \|
235
238
  `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"`;
236
- \}\> \| `Readonly`\<\{ `kind`: `"record"`; `record`: \{ `recordId`: `string`;
237
- `requester`: \{ `principalId`: `string`; `agentId`: `string` \| `null`;
238
- `sessionId`: `string` \| `null`; `displayName`: `string`; \}; `module`:
239
- `string`; `operation`: `string`; `access`: `"write"` \| `"external"`;
240
- `description`: \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`:
241
- `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`: `string`;
242
- `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`: \|
243
- `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \|
239
+ `denialNote?`: `string`; \}\> \| `Readonly`\<\{ `kind`: `"record"`; `record`: \{
240
+ `recordId`: `string`; `requester`: \{ `principalId`: `string`; `agentId`:
241
+ `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`;
242
+ \}; `module`: `string`; `operation`: `string`; `access`: `"write"` \|
243
+ `"external"`; `description`: \{ `title`: `string`; `inputBytes`: `number`;
244
+ `inputSha256`: `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`:
245
+ `string`; `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`:
246
+ \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \|
244
247
  `"claimed"` \| `"applied"` \| `"outcome_unknown"`; `by`: \| \{ `kind`:
245
248
  `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null`;
246
249
  `reason`: \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \|
247
250
  `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \|
248
251
  `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \|
249
- `"identity-conflict"` \| `null`; `requestedAt`: `number`; `expiresAt`: `number`;
250
- `updatedAt`: `number`; `revision`: `number`; \}; `created`: `boolean`; \}\>\>
252
+ `"identity-conflict"` \| `null`; `denialNote?`: `string`; `requestedAt`:
253
+ `number`; `expiresAt`: `number`; `updatedAt`: `number`; `revision`: `number`;
254
+ \}; `created`: `boolean`; \}\>\>
251
255
 
252
256
  ##### answer()
253
257
 
@@ -268,6 +272,7 @@ answer(input, actor):
268
272
  | "in-flight"
269
273
  | "outcome-unknown"
270
274
  | "identity-conflict";
275
+ denialNote?: string;
271
276
  }>
272
277
  | Readonly<{
273
278
  kind: "answered";
@@ -320,6 +325,7 @@ answer(input, actor):
320
325
  | "outcome-unknown"
321
326
  | "identity-conflict"
322
327
  | null;
328
+ denialNote?: string;
323
329
  requestedAt: number;
324
330
  expiresAt: number;
325
331
  updatedAt: number;
@@ -333,13 +339,14 @@ grants.
333
339
 
334
340
  ###### Parameters
335
341
 
336
- | Parameter | Type |
337
- | ------------------------ | ---------------------------------------------------------------------------------------------- |
338
- | `input` | \{ `recordId`: `string`; `decision`: `"approve"` \| `"deny"`; `expectedRevision`: `number`; \} |
339
- | `input.recordId` | `string` |
340
- | `input.decision` | `"approve"` \| `"deny"` |
341
- | `input.expectedRevision` | `number` |
342
- | `actor` | [`ApprovalAnswerer`](#approvalanswerer) \| `null` |
342
+ | Parameter | Type |
343
+ | ------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
344
+ | `input` | \{ `recordId`: `string`; `decision`: `"approve"` \| `"deny"`; `expectedRevision`: `number`; `denialNote?`: `string`; \} |
345
+ | `input.recordId` | `string` |
346
+ | `input.decision` | `"approve"` \| `"deny"` |
347
+ | `input.expectedRevision` | `number` |
348
+ | `input.denialNote?` | `string` |
349
+ | `actor` | [`ApprovalAnswerer`](#approvalanswerer) \| `null` |
343
350
 
344
351
  ###### Returns
345
352
 
@@ -347,21 +354,22 @@ grants.
347
354
  \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \|
348
355
  `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \|
349
356
  `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"`;
350
- \}\> \| `Readonly`\<\{ `kind`: `"answered"`; `record`: \{ `recordId`: `string`;
351
- `requester`: \{ `principalId`: `string`; `agentId`: `string` \| `null`;
352
- `sessionId`: `string` \| `null`; `displayName`: `string`; \}; `module`:
353
- `string`; `operation`: `string`; `access`: `"write"` \| `"external"`;
354
- `description`: \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`:
355
- `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`: `string`;
356
- `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`: \|
357
- `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \|
357
+ `denialNote?`: `string`; \}\> \| `Readonly`\<\{ `kind`: `"answered"`; `record`:
358
+ \{ `recordId`: `string`; `requester`: \{ `principalId`: `string`; `agentId`:
359
+ `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`;
360
+ \}; `module`: `string`; `operation`: `string`; `access`: `"write"` \|
361
+ `"external"`; `description`: \{ `title`: `string`; `inputBytes`: `number`;
362
+ `inputSha256`: `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`:
363
+ `string`; `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`:
364
+ \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \|
358
365
  `"claimed"` \| `"applied"` \| `"outcome_unknown"`; `by`: \| \{ `kind`:
359
366
  `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null`;
360
367
  `reason`: \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \|
361
368
  `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \|
362
369
  `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \|
363
- `"identity-conflict"` \| `null`; `requestedAt`: `number`; `expiresAt`: `number`;
364
- `updatedAt`: `number`; `revision`: `number`; \}; \}\>
370
+ `"identity-conflict"` \| `null`; `denialNote?`: `string`; `requestedAt`:
371
+ `number`; `expiresAt`: `number`; `updatedAt`: `number`; `revision`: `number`;
372
+ \}; \}\>
365
373
 
366
374
  ##### setAutoApprove()
367
375
 
@@ -382,6 +390,7 @@ setAutoApprove(input, setter):
382
390
  | "in-flight"
383
391
  | "outcome-unknown"
384
392
  | "identity-conflict";
393
+ denialNote?: string;
385
394
  }>
386
395
  | Readonly<{
387
396
  kind: "updated";
@@ -419,9 +428,10 @@ Policy changes are attributed; an Agent can never enable its own writes.
419
428
  \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \|
420
429
  `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \|
421
430
  `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"`;
422
- \}\> \| `Readonly`\<\{ `kind`: `"updated"`; `rule`: \{ `scope`: \{ `agentId`:
423
- `string` \| `null`; \}; `family`: \{ `module`: `string` \| `null`; `access`:
424
- `"write"` \| `"external"`; \}; `enabled`: `boolean`; \}; \}\>
431
+ `denialNote?`: `string`; \}\> \| `Readonly`\<\{ `kind`: `"updated"`; `rule`: \{
432
+ `scope`: \{ `agentId`: `string` \| `null`; \}; `family`: \{ `module`: `string`
433
+ \| `null`; `access`: `"write"` \| `"external"`; \}; `enabled`: `boolean`; \};
434
+ \}\>
425
435
 
426
436
  ##### selectAutoApprove()
427
437
 
@@ -479,6 +489,24 @@ dispatches.
479
489
 
480
490
  readonly `string`[]
481
491
 
492
+ ##### readInput()
493
+
494
+ ```ts
495
+ readInput(recordId): Json;
496
+ ```
497
+
498
+ Host-private display recovery; never exposed by the member-bound capability.
499
+
500
+ ###### Parameters
501
+
502
+ | Parameter | Type |
503
+ | ---------- | -------- |
504
+ | `recordId` | `string` |
505
+
506
+ ###### Returns
507
+
508
+ `Json`
509
+
482
510
  ##### pendingHandoffs()
483
511
 
484
512
  ```ts
@@ -617,6 +645,7 @@ get(recordId):
617
645
  | "outcome-unknown"
618
646
  | "identity-conflict"
619
647
  | null;
648
+ denialNote?: string;
620
649
  requestedAt: number;
621
650
  expiresAt: number;
622
651
  updatedAt: number;
@@ -647,8 +676,9 @@ Read a record from this home only; the maintained decoder owns stored JSON.
647
676
  `reason`: \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \|
648
677
  `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \|
649
678
  `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \|
650
- `"identity-conflict"` \| `null`; `requestedAt`: `number`; `expiresAt`: `number`;
651
- `updatedAt`: `number`; `revision`: `number`; \} \| `null`
679
+ `"identity-conflict"` \| `null`; `denialNote?`: `string`; `requestedAt`:
680
+ `number`; `expiresAt`: `number`; `updatedAt`: `number`; `revision`: `number`; \}
681
+ \| `null`
652
682
 
653
683
  ## Type Aliases
654
684
 
@@ -728,6 +758,7 @@ One per-home or per-Agent module/access rule.
728
758
  type ApprovalRefusal = Readonly<{
729
759
  kind: "refused";
730
760
  reason: typeof ApprovalRefusalReasonSchema.Type;
761
+ denialNote?: typeof ApprovalDenialNoteSchema.Type;
731
762
  }>;
732
763
  ```
733
764
 
@@ -798,6 +829,7 @@ type Approvals = Readonly<{
798
829
  | "outcome-unknown"
799
830
  | "identity-conflict"
800
831
  | null;
832
+ denialNote?: string;
801
833
  requestedAt: number;
802
834
  expiresAt: number;
803
835
  updatedAt: number;
@@ -810,6 +842,7 @@ type Approvals = Readonly<{
810
842
  | Readonly<{
811
843
  kind: "refused";
812
844
  reason: typeof ApprovalRefusalReasonSchema.Type;
845
+ denialNote?: typeof ApprovalDenialNoteSchema.Type;
813
846
  }>
814
847
  | Readonly<{
815
848
  kind: "answered";
@@ -820,6 +853,7 @@ type Approvals = Readonly<{
820
853
  | Readonly<{
821
854
  kind: "refused";
822
855
  reason: typeof ApprovalRefusalReasonSchema.Type;
856
+ denialNote?: typeof ApprovalDenialNoteSchema.Type;
823
857
  }>
824
858
  | Readonly<{
825
859
  kind: "updated";
@@ -858,6 +892,8 @@ type ApprovalRequest = Readonly<{
858
892
  authorityFence: string;
859
893
  idempotencyKey: string;
860
894
  inputJson: string;
895
+ requireHumanApproval?: boolean;
896
+ prefixPolicyApproved?: boolean;
861
897
  }>;
862
898
  ```
863
899
 
@@ -1169,6 +1205,26 @@ Why a decision or apply was refused; unknown dispatch is never a denial.
1169
1205
 
1170
1206
  ---
1171
1207
 
1208
+ ### MAX\_APPROVAL\_DENIAL\_NOTE\_LENGTH
1209
+
1210
+ ```ts
1211
+ const MAX_APPROVAL_DENIAL_NOTE_LENGTH: 512 = 512;
1212
+ ```
1213
+
1214
+ Human explanation for a denied approval; distinct from the typed refusal cause.
1215
+
1216
+ ---
1217
+
1218
+ ### ApprovalDenialNoteSchema
1219
+
1220
+ ```ts
1221
+ const ApprovalDenialNoteSchema: String;
1222
+ ```
1223
+
1224
+ Bounded nonempty human feedback; user text, never approval authority.
1225
+
1226
+ ---
1227
+
1172
1228
  ### MAX\_APPROVAL\_EVIDENCE
1173
1229
 
1174
1230
  ```ts
@@ -1282,6 +1338,7 @@ const ApprovalRecordSchema: Struct<{
1282
1338
  ]
1283
1339
  >
1284
1340
  >;
1341
+ denialNote: optionalKey<String>;
1285
1342
  requestedAt: Int;
1286
1343
  expiresAt: Int;
1287
1344
  updatedAt: Int;
@@ -1370,6 +1427,7 @@ const ApprovalViewSchema: Struct<{
1370
1427
  ]
1371
1428
  >
1372
1429
  >;
1430
+ denialNote: optionalKey<String>;
1373
1431
  requestedAt: Int;
1374
1432
  expiresAt: Int;
1375
1433
  updatedAt: Int;
@@ -1430,6 +1488,7 @@ const ApprovalAnswerInputSchema: Struct<{
1430
1488
  recordId: String;
1431
1489
  decision: Literals<readonly ["approve", "deny"]>;
1432
1490
  expectedRevision: Int;
1491
+ denialNote: optionalKey<String>;
1433
1492
  }>;
1434
1493
  ```
1435
1494
 
@@ -1478,6 +1537,7 @@ const ApprovalRefusalSchema: Struct<{
1478
1537
  "identity-conflict",
1479
1538
  ]
1480
1539
  >;
1540
+ denialNote: optionalKey<String>;
1481
1541
  }>;
1482
1542
  ```
1483
1543
 
@@ -1492,3 +1552,48 @@ const DEFAULT_APPROVAL_EXPIRY_MS: number;
1492
1552
  ```
1493
1553
 
1494
1554
  The initial owner-controlled wait duration; passing the deadline never approves.
1555
+
1556
+ ## Functions
1557
+
1558
+ ### denialFeedbackOpening()
1559
+
1560
+ ```ts
1561
+ function denialFeedbackOpening(record, person): string | null;
1562
+ ```
1563
+
1564
+ Host-supplied human identity; the bounded reason remains quoted user text.
1565
+
1566
+ #### Parameters
1567
+
1568
+ | Parameter | Type |
1569
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1570
+ | `record` | \{ `recordId`: `string`; `requester`: \{ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`; \}; `module`: `string`; `operation`: `string`; `access`: `"write"` \| `"external"`; `description`: \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`: `string`; \}; `evidence?`: readonly `object`[]; `authorityFence`: `string`; `reversibility`: `"reversible"` \| `"irreversible-external"`; `state`: \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \| `"outcome_unknown"`; `by`: \| \{ `kind`: `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null`; `reason`: \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"` \| `null`; `denialNote?`: `string`; `requestedAt`: `number`; `expiresAt`: `number`; `updatedAt`: `number`; `revision`: `number`; \} |
1571
+ | `record.recordId` | `string` |
1572
+ | `record.requester` | \{ `principalId`: `string`; `agentId`: `string` \| `null`; `sessionId`: `string` \| `null`; `displayName`: `string`; \} |
1573
+ | `record.requester.principalId` | `string` |
1574
+ | `record.requester.agentId` | `string` \| `null` |
1575
+ | `record.requester.sessionId` | `string` \| `null` |
1576
+ | `record.requester.displayName` | `string` |
1577
+ | `record.module` | `string` |
1578
+ | `record.operation` | `string` |
1579
+ | `record.access` | `"write"` \| `"external"` |
1580
+ | `record.description` | \{ `title`: `string`; `inputBytes`: `number`; `inputSha256`: `string`; \} |
1581
+ | `record.description.title` | `string` |
1582
+ | `record.description.inputBytes` | `number` |
1583
+ | `record.description.inputSha256` | `string` |
1584
+ | `record.evidence?` | readonly `object`[] |
1585
+ | `record.authorityFence` | `string` |
1586
+ | `record.reversibility` | `"reversible"` \| `"irreversible-external"` |
1587
+ | `record.state` | \| `"pending"` \| `"expired"` \| `"denied"` \| `"requested"` \| `"approved"` \| `"claimed"` \| `"applied"` \| `"outcome_unknown"` |
1588
+ | `record.by` | \| \{ `kind`: `"human"`; `memberId`: `string`; \} \| \{ `kind`: `"policy"`; \} \| `null` |
1589
+ | `record.reason` | \| `"pending"` \| `"expired"` \| `"not-found"` \| `"not-eligible"` \| `"already-answered"` \| `"stale-revision"` \| `"declined"` \| `"fenced"` \| `"not-granted"` \| `"read-only"` \| `"in-flight"` \| `"outcome-unknown"` \| `"identity-conflict"` \| `null` |
1590
+ | `record.denialNote?` | `string` |
1591
+ | `record.requestedAt` | `number` |
1592
+ | `record.expiresAt` | `number` |
1593
+ | `record.updatedAt` | `number` |
1594
+ | `record.revision` | `number` |
1595
+ | `person` | `string` |
1596
+
1597
+ #### Returns
1598
+
1599
+ `string` \| `null`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/approvals",
3
- "version": "0.0.2",
3
+ "version": "0.2.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Durable principal-bound approval records and auto-approve policy",
6
6
  "type": "module",