@ai-matrx/alchemy 0.9.1 → 0.10.1

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/index.d.cts CHANGED
@@ -649,6 +649,125 @@ interface ClickTarget {
649
649
  host?: unknown;
650
650
  }
651
651
 
652
+ /**
653
+ * THE ONE WRITE DOOR (Matrx Alchemy ALC-17; Applets CONTRACTS §6 "receipts through the one write door").
654
+ *
655
+ * Every write — a person's edit, a menu row, a destination send, an agent, an applet, an automation,
656
+ * an Action projected from a write target — lands through `door.write`. The door:
657
+ *
658
+ * 1. resolves the DECLARED write target (the surface's own, then its ancestors'); an undeclared
659
+ * target is refused by name;
660
+ * 2. enforces the mode: `stream` takes ops from the target's `streamOps`; ops on any other target
661
+ * need `patchable` (+ `updatesValue`); a value on a `stream` target is refused;
662
+ * 3. checks the kind (rule 10): a person's mismatch WARNS (the receipt is still applied, with a
663
+ * `warning` and a `fix`); an agent's, applet's or automation's malformed write is REFUSED;
664
+ * 4. applies the policy: manual → a person only; ask → a person's own act is the approval, anyone
665
+ * else asks through `approvals`; queued → filed through `review`; auto → applies;
666
+ * 5. applies through the handler: the mounted page's LIVE handler wins over the HEADLESS one;
667
+ * neither → refused `unapplicable` ("open <surface> to apply it");
668
+ * 6. turns stale / missing record / broken protected span into "cannot apply" with a one-click
669
+ * remedy (rule 11).
670
+ *
671
+ * Every outcome is a `Receipt` carrying the system's own sentence. `write` never throws.
672
+ *
673
+ * Who counts as a person: `person`, `menu` and `destination` (a destination send is a person's own
674
+ * click on "Send to …"). `agent`, `applet` and `automation` are not.
675
+ *
676
+ * Open-risk ruling — stream ops into an entity target: an entity write is ONE atomic save. Ops reach
677
+ * an entity target only when it is declared `patchable` (the ops are handed to the handler in one
678
+ * call and commit as one save); a non-patchable entity target refuses ops with the remedy "stream
679
+ * into the editor, then save". Op-by-op persistence into a record does not exist.
680
+ */
681
+
682
+ /** Who is writing. `menu` and `destination` are a person's own act. */
683
+ type WriteCaller = "person" | "agent" | "applet" | "automation" | "destination" | "menu";
684
+ /** One text op for a `stream` (or `patchable`) target — the WidgetHandle op set. */
685
+ interface WriteOp {
686
+ op: StreamOp;
687
+ /** The text the op inserts or replaces with. */
688
+ text?: string;
689
+ /** What `replace` / `insert_before` / `insert_after` / `patch` anchor on. */
690
+ find?: string;
691
+ }
692
+ interface WriteRequest {
693
+ surfaceName: string;
694
+ /** A write target name; `"<itemType>.<name>"` names an item's target. */
695
+ target: string;
696
+ itemType?: string;
697
+ /** Which item, by its declared identity values. Required for an item target. */
698
+ itemIdentity?: Record<string, string>;
699
+ /** A whole value. Exactly one of `value` / `ops`. */
700
+ value?: unknown;
701
+ /** Text ops (stream / patchable targets). */
702
+ ops?: readonly WriteOp[];
703
+ by: WriteCaller;
704
+ runId?: string;
705
+ }
706
+ /** What a handler receives: the request plus the declared target it resolved to. */
707
+ interface WriteApplyRequest {
708
+ surfaceName: string;
709
+ /** The surface that declares the target (an ancestor when inherited). */
710
+ declaredOn: string;
711
+ target: WriteTarget;
712
+ item?: {
713
+ itemType: string;
714
+ identity: Record<string, string>;
715
+ };
716
+ value?: unknown;
717
+ ops?: readonly WriteOp[];
718
+ by: WriteCaller;
719
+ runId?: string;
720
+ }
721
+ /** Rule 11: the three "cannot apply" signals. */
722
+ type CannotApply = "stale" | "missing-record" | "broken-span";
723
+ /**
724
+ * A handler applies the write. Return nothing (or `{ status: "applied" }`) when it landed, or a
725
+ * `cannotApply` signal; THROWING an error whose `code` is a `CannotApply` signal means the same.
726
+ */
727
+ type WriteHandlerResult = void | {
728
+ status: "applied";
729
+ sentence?: string;
730
+ } | {
731
+ status: "cannot-apply";
732
+ cannotApply: CannotApply;
733
+ sentence?: string;
734
+ remedy?: string;
735
+ };
736
+ type WriteHandler = (request: WriteApplyRequest, signal: AbortSignal) => WriteHandlerResult | Promise<WriteHandlerResult>;
737
+ /** Files a `queued` write for an organization's review. */
738
+ interface WriteReviewPort {
739
+ file(request: WriteApplyRequest): Promise<{
740
+ sentence?: string;
741
+ remedy?: string;
742
+ } | void>;
743
+ }
744
+ /** Why a write was refused. */
745
+ type WriteRefusalReason = "undeclared" | "needs_item" | "malformed" | "declaration_broken" | "manual_only" | "needs_approval" | "declined" | "no_review" | "unapplicable" | "cannot_apply" | "cancelled" | "failed";
746
+ interface WriteDoor {
747
+ write(request: WriteRequest, signal?: AbortSignal): Promise<Receipt>;
748
+ /** A feature's write handler that works with no page mounted. Refuses a second one for the same target. */
749
+ registerHeadless(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
750
+ /** A mounted page's handler; wins over the headless one while registered. Returns unregister. */
751
+ registerLive(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
752
+ }
753
+ /** The declarations the door reads: a `DeclarationRegistry` satisfies it. */
754
+ interface WriteDoorDeclarations {
755
+ get(surfaceName: string): {
756
+ writeTargets?: readonly WriteTarget[];
757
+ itemTypes?: readonly ItemType[];
758
+ } | undefined;
759
+ /** Parent chain, root first (the registry's `ancestry`). Absent = no inheritance. */
760
+ ancestry?(surfaceName: string): string[];
761
+ }
762
+ type WriteDoorPorts = Pick<AlchemyHostPorts, "diagnostics" | "kinds" | "approvals" | "review">;
763
+ declare class DuplicateWriteHandlerError extends Error {
764
+ constructor(surfaceName: string, targetName: string);
765
+ }
766
+ declare function createWriteDoor(options: {
767
+ ports: WriteDoorPorts;
768
+ declarations: WriteDoorDeclarations;
769
+ }): WriteDoor;
770
+
652
771
  /**
653
772
  * Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
654
773
  *
@@ -680,6 +799,8 @@ interface ActionError {
680
799
  message: string;
681
800
  retryable: boolean;
682
801
  diagnostic?: string;
802
+ /** Superset: the one-click remedy a write door refusal names. */
803
+ remedy?: string;
683
804
  }
684
805
  /** CONTRACTS §0 `Result<T>`. */
685
806
  type ActionResult<T = unknown> = {
@@ -736,7 +857,7 @@ type MandateRunRequest = ({
736
857
  * PP-01a `window` (host-rendered windows for a live preparation session)
737
858
  * PP-13a `transferKnobs` (organization default recipes)
738
859
  *
739
- * ALC-17 adds approvals/bodies/receipts.
860
+ * ALC-17 `door` (the one write door), `review` (queued writes)
740
861
  *
741
862
  * ── Absent-port semantics ───────────────────────────────────────────────────
742
863
  *
@@ -772,6 +893,10 @@ type MandateRunRequest = ({
772
893
  * approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
773
894
  * ("needs a person's approval"); a person's own click is the approval
774
895
  * (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
896
+ * door absent → write-target Actions dispatch to `pageActions` as before, and
897
+ * `Delivery.send` is refused with a remedy; bound → every such write goes
898
+ * through it and returns its receipt
899
+ * review absent → a write to a `queued` target is refused ("review isn't available here")
775
900
  *
776
901
  * Types only: this entry has no runtime code.
777
902
  */
@@ -925,6 +1050,10 @@ interface AlchemyHostPorts {
925
1050
  pageActions?: PageActionPort;
926
1051
  /** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
927
1052
  approvals?: ApprovalPort;
1053
+ /** `createWriteDoor(...)`: every write to a declared target lands here and returns a receipt. */
1054
+ door?: WriteDoor;
1055
+ /** Files a write to a `queued` target for an organization's review. */
1056
+ review?: WriteReviewPort;
928
1057
  }
929
1058
  interface ServerActionPort {
930
1059
  run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
@@ -1079,7 +1208,7 @@ type Notice = {
1079
1208
  sentence: string;
1080
1209
  remedy: string;
1081
1210
  };
1082
- /** A reference to a declared write target (the write door arrives in ALC-17). */
1211
+ /** A reference to a declared write target (resolved by the one write door, ALC-17). */
1083
1212
  interface WriteTargetRef {
1084
1213
  surfaceName?: string;
1085
1214
  target: string;
@@ -1154,11 +1283,17 @@ declare const sealed: unique symbol;
1154
1283
  type SealedArtifact = Artifact & {
1155
1284
  readonly [sealed]: true;
1156
1285
  };
1157
- /** Every send returns one (the write door's receipt shape, CONTRACT §2.3; the door itself is ALC-17). */
1286
+ /**
1287
+ * Every write returns one (CONTRACT §2.3; the door is `createWriteDoor`, ALC-17). An applied
1288
+ * receipt may carry a `warning` with its `fix` (rule 10: a person's kind mismatch warns, never refuses).
1289
+ * A refusal's `reason` is a `WriteRefusalReason` (`./door`).
1290
+ */
1158
1291
  type Receipt = {
1159
1292
  status: "applied";
1160
1293
  to: WriteTargetRef;
1161
1294
  sentence: string;
1295
+ warning?: string;
1296
+ fix?: string;
1162
1297
  } | {
1163
1298
  status: "queued";
1164
1299
  to: WriteTargetRef;
@@ -1182,7 +1317,7 @@ interface Delivery {
1182
1317
  html?: boolean;
1183
1318
  }): Promise<DeliveryOutcome>;
1184
1319
  download(artifact: SealedArtifact, signal: AbortSignal): Promise<DeliveryOutcome>;
1185
- /** Sends the sealed bytes through the write door (ALC-17). Without a door: refused, with a remedy. */
1320
+ /** Sends the sealed bytes through the write door (`by: "destination"`). Without a door: refused, with a remedy. */
1186
1321
  send(artifact: SealedArtifact, to: WriteTargetRef, via: "destination"): Promise<Receipt>;
1187
1322
  }
1188
1323
 
@@ -1245,19 +1380,13 @@ declare function openPreparation(source: Source | Payload, scope: TransferScope,
1245
1380
  declare function sealDraft(draft: Draft, format: string, options: FormatOptions, signal: AbortSignal, formats?: readonly FormatAdapter[]): Promise<SealedArtifact>;
1246
1381
  /**
1247
1382
  * The one delivery. `transport` defaults to the browser (clipboard + download link); a non-browser
1248
- * host binds its own (`TransportPort`). `send` needs the write door (ALC-17): without one it is
1383
+ * host binds its own (`TransportPort`). `send` goes through the one write door (ALC-17): without one it is
1249
1384
  * refused with a remedy, never faked.
1250
1385
  */
1251
1386
  declare function createDelivery(ports?: {
1252
1387
  transport?: Transport;
1253
- door?: {
1254
- apply(request: {
1255
- to: WriteTargetRef;
1256
- value: unknown;
1257
- origin: "user";
1258
- via: "destination";
1259
- }): Promise<Receipt>;
1260
- };
1388
+ /** The one write door (`createWriteDoor`). Absent → `send` is refused with a remedy. */
1389
+ door?: Pick<WriteDoor, "write">;
1261
1390
  }): Delivery;
1262
1391
 
1263
1392
  /**
@@ -1436,4 +1565,4 @@ declare function setPersonDefaultRecipe(ports: Pick<AlchemyHostPorts, "persisten
1436
1565
  [key: string]: Json;
1437
1566
  } | null): Promise<void>;
1438
1567
 
1439
- export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
1568
+ export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CannotApply, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, DuplicateWriteHandlerError, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteApplyRequest, type WriteCaller, type WriteDoor, type WriteDoorDeclarations, type WriteDoorPorts, type WriteHandler, type WriteHandlerResult, type WriteOp, type WriteRefusalReason, type WriteRequest, type WriteReviewPort, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, createWriteDoor, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
package/dist/index.d.ts CHANGED
@@ -649,6 +649,125 @@ interface ClickTarget {
649
649
  host?: unknown;
650
650
  }
651
651
 
652
+ /**
653
+ * THE ONE WRITE DOOR (Matrx Alchemy ALC-17; Applets CONTRACTS §6 "receipts through the one write door").
654
+ *
655
+ * Every write — a person's edit, a menu row, a destination send, an agent, an applet, an automation,
656
+ * an Action projected from a write target — lands through `door.write`. The door:
657
+ *
658
+ * 1. resolves the DECLARED write target (the surface's own, then its ancestors'); an undeclared
659
+ * target is refused by name;
660
+ * 2. enforces the mode: `stream` takes ops from the target's `streamOps`; ops on any other target
661
+ * need `patchable` (+ `updatesValue`); a value on a `stream` target is refused;
662
+ * 3. checks the kind (rule 10): a person's mismatch WARNS (the receipt is still applied, with a
663
+ * `warning` and a `fix`); an agent's, applet's or automation's malformed write is REFUSED;
664
+ * 4. applies the policy: manual → a person only; ask → a person's own act is the approval, anyone
665
+ * else asks through `approvals`; queued → filed through `review`; auto → applies;
666
+ * 5. applies through the handler: the mounted page's LIVE handler wins over the HEADLESS one;
667
+ * neither → refused `unapplicable` ("open <surface> to apply it");
668
+ * 6. turns stale / missing record / broken protected span into "cannot apply" with a one-click
669
+ * remedy (rule 11).
670
+ *
671
+ * Every outcome is a `Receipt` carrying the system's own sentence. `write` never throws.
672
+ *
673
+ * Who counts as a person: `person`, `menu` and `destination` (a destination send is a person's own
674
+ * click on "Send to …"). `agent`, `applet` and `automation` are not.
675
+ *
676
+ * Open-risk ruling — stream ops into an entity target: an entity write is ONE atomic save. Ops reach
677
+ * an entity target only when it is declared `patchable` (the ops are handed to the handler in one
678
+ * call and commit as one save); a non-patchable entity target refuses ops with the remedy "stream
679
+ * into the editor, then save". Op-by-op persistence into a record does not exist.
680
+ */
681
+
682
+ /** Who is writing. `menu` and `destination` are a person's own act. */
683
+ type WriteCaller = "person" | "agent" | "applet" | "automation" | "destination" | "menu";
684
+ /** One text op for a `stream` (or `patchable`) target — the WidgetHandle op set. */
685
+ interface WriteOp {
686
+ op: StreamOp;
687
+ /** The text the op inserts or replaces with. */
688
+ text?: string;
689
+ /** What `replace` / `insert_before` / `insert_after` / `patch` anchor on. */
690
+ find?: string;
691
+ }
692
+ interface WriteRequest {
693
+ surfaceName: string;
694
+ /** A write target name; `"<itemType>.<name>"` names an item's target. */
695
+ target: string;
696
+ itemType?: string;
697
+ /** Which item, by its declared identity values. Required for an item target. */
698
+ itemIdentity?: Record<string, string>;
699
+ /** A whole value. Exactly one of `value` / `ops`. */
700
+ value?: unknown;
701
+ /** Text ops (stream / patchable targets). */
702
+ ops?: readonly WriteOp[];
703
+ by: WriteCaller;
704
+ runId?: string;
705
+ }
706
+ /** What a handler receives: the request plus the declared target it resolved to. */
707
+ interface WriteApplyRequest {
708
+ surfaceName: string;
709
+ /** The surface that declares the target (an ancestor when inherited). */
710
+ declaredOn: string;
711
+ target: WriteTarget;
712
+ item?: {
713
+ itemType: string;
714
+ identity: Record<string, string>;
715
+ };
716
+ value?: unknown;
717
+ ops?: readonly WriteOp[];
718
+ by: WriteCaller;
719
+ runId?: string;
720
+ }
721
+ /** Rule 11: the three "cannot apply" signals. */
722
+ type CannotApply = "stale" | "missing-record" | "broken-span";
723
+ /**
724
+ * A handler applies the write. Return nothing (or `{ status: "applied" }`) when it landed, or a
725
+ * `cannotApply` signal; THROWING an error whose `code` is a `CannotApply` signal means the same.
726
+ */
727
+ type WriteHandlerResult = void | {
728
+ status: "applied";
729
+ sentence?: string;
730
+ } | {
731
+ status: "cannot-apply";
732
+ cannotApply: CannotApply;
733
+ sentence?: string;
734
+ remedy?: string;
735
+ };
736
+ type WriteHandler = (request: WriteApplyRequest, signal: AbortSignal) => WriteHandlerResult | Promise<WriteHandlerResult>;
737
+ /** Files a `queued` write for an organization's review. */
738
+ interface WriteReviewPort {
739
+ file(request: WriteApplyRequest): Promise<{
740
+ sentence?: string;
741
+ remedy?: string;
742
+ } | void>;
743
+ }
744
+ /** Why a write was refused. */
745
+ type WriteRefusalReason = "undeclared" | "needs_item" | "malformed" | "declaration_broken" | "manual_only" | "needs_approval" | "declined" | "no_review" | "unapplicable" | "cannot_apply" | "cancelled" | "failed";
746
+ interface WriteDoor {
747
+ write(request: WriteRequest, signal?: AbortSignal): Promise<Receipt>;
748
+ /** A feature's write handler that works with no page mounted. Refuses a second one for the same target. */
749
+ registerHeadless(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
750
+ /** A mounted page's handler; wins over the headless one while registered. Returns unregister. */
751
+ registerLive(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
752
+ }
753
+ /** The declarations the door reads: a `DeclarationRegistry` satisfies it. */
754
+ interface WriteDoorDeclarations {
755
+ get(surfaceName: string): {
756
+ writeTargets?: readonly WriteTarget[];
757
+ itemTypes?: readonly ItemType[];
758
+ } | undefined;
759
+ /** Parent chain, root first (the registry's `ancestry`). Absent = no inheritance. */
760
+ ancestry?(surfaceName: string): string[];
761
+ }
762
+ type WriteDoorPorts = Pick<AlchemyHostPorts, "diagnostics" | "kinds" | "approvals" | "review">;
763
+ declare class DuplicateWriteHandlerError extends Error {
764
+ constructor(surfaceName: string, targetName: string);
765
+ }
766
+ declare function createWriteDoor(options: {
767
+ ports: WriteDoorPorts;
768
+ declarations: WriteDoorDeclarations;
769
+ }): WriteDoor;
770
+
652
771
  /**
653
772
  * Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
654
773
  *
@@ -680,6 +799,8 @@ interface ActionError {
680
799
  message: string;
681
800
  retryable: boolean;
682
801
  diagnostic?: string;
802
+ /** Superset: the one-click remedy a write door refusal names. */
803
+ remedy?: string;
683
804
  }
684
805
  /** CONTRACTS §0 `Result<T>`. */
685
806
  type ActionResult<T = unknown> = {
@@ -736,7 +857,7 @@ type MandateRunRequest = ({
736
857
  * PP-01a `window` (host-rendered windows for a live preparation session)
737
858
  * PP-13a `transferKnobs` (organization default recipes)
738
859
  *
739
- * ALC-17 adds approvals/bodies/receipts.
860
+ * ALC-17 `door` (the one write door), `review` (queued writes)
740
861
  *
741
862
  * ── Absent-port semantics ───────────────────────────────────────────────────
742
863
  *
@@ -772,6 +893,10 @@ type MandateRunRequest = ({
772
893
  * approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
773
894
  * ("needs a person's approval"); a person's own click is the approval
774
895
  * (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
896
+ * door absent → write-target Actions dispatch to `pageActions` as before, and
897
+ * `Delivery.send` is refused with a remedy; bound → every such write goes
898
+ * through it and returns its receipt
899
+ * review absent → a write to a `queued` target is refused ("review isn't available here")
775
900
  *
776
901
  * Types only: this entry has no runtime code.
777
902
  */
@@ -925,6 +1050,10 @@ interface AlchemyHostPorts {
925
1050
  pageActions?: PageActionPort;
926
1051
  /** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
927
1052
  approvals?: ApprovalPort;
1053
+ /** `createWriteDoor(...)`: every write to a declared target lands here and returns a receipt. */
1054
+ door?: WriteDoor;
1055
+ /** Files a write to a `queued` target for an organization's review. */
1056
+ review?: WriteReviewPort;
928
1057
  }
929
1058
  interface ServerActionPort {
930
1059
  run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
@@ -1079,7 +1208,7 @@ type Notice = {
1079
1208
  sentence: string;
1080
1209
  remedy: string;
1081
1210
  };
1082
- /** A reference to a declared write target (the write door arrives in ALC-17). */
1211
+ /** A reference to a declared write target (resolved by the one write door, ALC-17). */
1083
1212
  interface WriteTargetRef {
1084
1213
  surfaceName?: string;
1085
1214
  target: string;
@@ -1154,11 +1283,17 @@ declare const sealed: unique symbol;
1154
1283
  type SealedArtifact = Artifact & {
1155
1284
  readonly [sealed]: true;
1156
1285
  };
1157
- /** Every send returns one (the write door's receipt shape, CONTRACT §2.3; the door itself is ALC-17). */
1286
+ /**
1287
+ * Every write returns one (CONTRACT §2.3; the door is `createWriteDoor`, ALC-17). An applied
1288
+ * receipt may carry a `warning` with its `fix` (rule 10: a person's kind mismatch warns, never refuses).
1289
+ * A refusal's `reason` is a `WriteRefusalReason` (`./door`).
1290
+ */
1158
1291
  type Receipt = {
1159
1292
  status: "applied";
1160
1293
  to: WriteTargetRef;
1161
1294
  sentence: string;
1295
+ warning?: string;
1296
+ fix?: string;
1162
1297
  } | {
1163
1298
  status: "queued";
1164
1299
  to: WriteTargetRef;
@@ -1182,7 +1317,7 @@ interface Delivery {
1182
1317
  html?: boolean;
1183
1318
  }): Promise<DeliveryOutcome>;
1184
1319
  download(artifact: SealedArtifact, signal: AbortSignal): Promise<DeliveryOutcome>;
1185
- /** Sends the sealed bytes through the write door (ALC-17). Without a door: refused, with a remedy. */
1320
+ /** Sends the sealed bytes through the write door (`by: "destination"`). Without a door: refused, with a remedy. */
1186
1321
  send(artifact: SealedArtifact, to: WriteTargetRef, via: "destination"): Promise<Receipt>;
1187
1322
  }
1188
1323
 
@@ -1245,19 +1380,13 @@ declare function openPreparation(source: Source | Payload, scope: TransferScope,
1245
1380
  declare function sealDraft(draft: Draft, format: string, options: FormatOptions, signal: AbortSignal, formats?: readonly FormatAdapter[]): Promise<SealedArtifact>;
1246
1381
  /**
1247
1382
  * The one delivery. `transport` defaults to the browser (clipboard + download link); a non-browser
1248
- * host binds its own (`TransportPort`). `send` needs the write door (ALC-17): without one it is
1383
+ * host binds its own (`TransportPort`). `send` goes through the one write door (ALC-17): without one it is
1249
1384
  * refused with a remedy, never faked.
1250
1385
  */
1251
1386
  declare function createDelivery(ports?: {
1252
1387
  transport?: Transport;
1253
- door?: {
1254
- apply(request: {
1255
- to: WriteTargetRef;
1256
- value: unknown;
1257
- origin: "user";
1258
- via: "destination";
1259
- }): Promise<Receipt>;
1260
- };
1388
+ /** The one write door (`createWriteDoor`). Absent → `send` is refused with a remedy. */
1389
+ door?: Pick<WriteDoor, "write">;
1261
1390
  }): Delivery;
1262
1391
 
1263
1392
  /**
@@ -1436,4 +1565,4 @@ declare function setPersonDefaultRecipe(ports: Pick<AlchemyHostPorts, "persisten
1436
1565
  [key: string]: Json;
1437
1566
  } | null): Promise<void>;
1438
1567
 
1439
- export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
1568
+ export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CannotApply, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, DuplicateWriteHandlerError, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteApplyRequest, type WriteCaller, type WriteDoor, type WriteDoorDeclarations, type WriteDoorPorts, type WriteHandler, type WriteHandlerResult, type WriteOp, type WriteRefusalReason, type WriteRequest, type WriteReviewPort, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, createWriteDoor, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };