@fungi.computer/oyster 0.35.1 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/boot-host-script.js +1 -1
  2. package/dist/build/candidate-cli.mjs +50 -15
  3. package/dist/catalog-frame.js +8 -0
  4. package/dist/cloudflare.js +1 -0
  5. package/dist/embed-metafiles.js +2 -2
  6. package/dist/embed-scripts.js +1 -1
  7. package/dist/hello-app-script.js +1 -1
  8. package/dist/host.d.ts +3 -1
  9. package/dist/host.js +9 -9
  10. package/dist/internal/delivery.js +1 -1
  11. package/dist/invocation.d.ts +27 -5
  12. package/dist/invocation.js +9 -7
  13. package/dist/mcp.d.ts +3 -3
  14. package/dist/mcp.js +1 -1
  15. package/dist/page-script.js +2 -2
  16. package/dist/standalone/agent-self.d.ts +19 -0
  17. package/dist/standalone/agent-self.js +72 -0
  18. package/dist/standalone/agents.d.ts +2 -2
  19. package/dist/standalone/agents.js +30 -8
  20. package/dist/standalone/workflow-git-capture.d.ts +1 -1
  21. package/dist/standalone/workflow-git-capture.js +1 -1
  22. package/dist/standalone/workflow-host.d.ts +63 -26
  23. package/dist/standalone/workflow-host.js +21 -3
  24. package/dist/standalone/workflow-node-capture.d.ts +1 -1
  25. package/dist/standalone/workflow-node-capture.js +1 -1
  26. package/dist/standalone/workflow-trigger-host.d.ts +193 -73
  27. package/dist/standalone/workflows.d.ts +54 -24
  28. package/dist/testing/capabilities.js +2 -0
  29. package/dist/testing/worker.js +1 -0
  30. package/dist/workers-git.js +2 -1
  31. package/dist/workers.js +5 -0
  32. package/docs/api/build-contract.md +27 -27
  33. package/docs/api/build.md +51 -60
  34. package/docs/api/host.md +19 -34
  35. package/docs/api/invocation.md +135 -97
  36. package/docs/api/mcp.md +5 -5
  37. package/docs/api/workers-git.md +180 -179
  38. package/docs/api/workers.md +217 -215
  39. package/package.json +18 -18
@@ -0,0 +1,19 @@
1
+ import { type CapabilitySource } from "@fungi.computer/mycelium";
2
+ import type { AgentEntry } from "./agents.js";
3
+ import type { TenantPrincipal } from "../tenant.js";
4
+ import type { Avatar } from "@fungi.computer/sprite/avatar";
5
+ /** Expected refusals from the standalone identity owner. */
6
+ export type SelfIdentityRefusal = Readonly<{
7
+ error: "name_taken" | "not_found" | "not_granted";
8
+ }>;
9
+ /** The pinned directory's identity commands, called only as this Agent. */
10
+ export type SelfIdentityDirectory = Readonly<{
11
+ rename: (agentId: string, name: string, principal: TenantPrincipal) => AgentEntry | SelfIdentityRefusal | Promise<AgentEntry | SelfIdentityRefusal>;
12
+ setAvatar: (agentId: string, avatar: Avatar, principal: TenantPrincipal) => AgentEntry | SelfIdentityRefusal | Promise<AgentEntry | SelfIdentityRefusal>;
13
+ }>;
14
+ /** Standalone identity tools are bound to the host Agent, never a supplied target. */
15
+ export declare function createSelfSource(port: Readonly<{
16
+ agentId: string;
17
+ directory: () => Promise<SelfIdentityDirectory>;
18
+ isChannelSession: (sessionId: string) => boolean;
19
+ }>): CapabilitySource;
@@ -0,0 +1,72 @@
1
+ import { Mycelium } from "@fungi.computer/mycelium";
2
+ import { z } from "zod";
3
+ import { agentAvatarSchema } from "../agent-avatars.js";
4
+ const refusal = z.strictObject({
5
+ error: z.enum(["name_taken", "not_found", "not_granted"]),
6
+ });
7
+ /** Standalone identity tools are bound to the host Agent, never a supplied target. */
8
+ export function createSelfSource(port) {
9
+ const principal = {
10
+ actor: { kind: "agent", agentId: port.agentId },
11
+ };
12
+ return {
13
+ id: "oyster-agent-self",
14
+ acquire: ({ signal, session }) => {
15
+ signal.throwIfAborted();
16
+ const present = session !== undefined && !port.isChannelSession(session.sessionId);
17
+ return Promise.resolve({
18
+ snapshot: {
19
+ version: present ? "oyster-agent-self-v1" : "0",
20
+ modules: present
21
+ ? [
22
+ Mycelium.module({
23
+ id: "oyster-agent-self",
24
+ name: "self",
25
+ description: "Change your own Agent name and avatar.",
26
+ operations: {
27
+ rename: Mycelium.operation({
28
+ // Repeating the current value is a no-op, not permission to replay old values.
29
+ replay: "unsafe",
30
+ description: "Rename yourself. A name held by another Agent is refused.",
31
+ input: z.strictObject({
32
+ name: z.string().trim().min(1).max(256),
33
+ }),
34
+ output: z.union([
35
+ z.strictObject({
36
+ name: z.string(),
37
+ avatar: agentAvatarSchema,
38
+ }),
39
+ refusal,
40
+ ]),
41
+ execute: async ({ name }) => {
42
+ const result = await (await port.directory()).rename(port.agentId, name, principal);
43
+ return "error" in result
44
+ ? result
45
+ : { name: result.name, avatar: result.avatar };
46
+ },
47
+ }),
48
+ setAvatar: Mycelium.operation({
49
+ replay: "unsafe",
50
+ description: "Change your own avatar using the existing Avatar grammar.",
51
+ input: z.strictObject({ avatar: agentAvatarSchema }),
52
+ output: z.union([
53
+ z.strictObject({ avatar: agentAvatarSchema }),
54
+ refusal,
55
+ ]),
56
+ execute: async ({ avatar }) => {
57
+ const result = await (await port.directory()).setAvatar(port.agentId, avatar, principal);
58
+ return "error" in result
59
+ ? result
60
+ : { avatar: result.avatar };
61
+ },
62
+ }),
63
+ },
64
+ }),
65
+ ]
66
+ : [],
67
+ },
68
+ release: () => Promise.resolve(),
69
+ });
70
+ },
71
+ };
72
+ }
@@ -541,11 +541,11 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
541
541
  readCreator(agentId: string): string | null;
542
542
  /** Immutable creating Agent, distinct from the human credential owner. */
543
543
  createdBy(agentId: string): string | null;
544
- /** Owner-only rename; refuses a name already held by another Agent. */
544
+ /** An owner or the Agent itself may rename it; another Agent's name is refused. */
545
545
  rename(agentId: string, name: string, principal: TenantPrincipal): AgentEntry | Readonly<{
546
546
  error: "not_found" | "name_taken" | "not_granted";
547
547
  }>;
548
- /** Owner-only avatar change; the Agent wears it in every App and list. */
548
+ /** Owner or self avatar change; the Agent wears it in every App and list. */
549
549
  setAvatar(agentId: string, avatar: Avatar, principal: TenantPrincipal): AgentEntry | Readonly<{
550
550
  error: "not_found" | "not_granted";
551
551
  }>;
@@ -1,3 +1,5 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { createSelfSource } from "./agent-self.js";
1
3
  import { agentCodeExecutionTimeoutMs } from "@fungi.computer/computer-contract";
2
4
  import { isRetryableProviderRejection, normalizeModel, observeProviderStatus, providerDisplayNames, streamModel, } from "@fungi.computer/mule/effect";
3
5
  import { standaloneTenancy, } from "./tenancy.js";
@@ -65,7 +67,7 @@ import { AppInstanceError } from "../index.js";
65
67
  import { agentScheduleBindingArgs, appAgentScheduleListInputSchema, agentSchedulePageSchema, agentScheduleControlReceiptSchema, } from "../agent-schedules.js";
66
68
  import { readAgentSchedulePage, controlAgentSchedule, } from "@fungi.computer/shiitake-extensions/schedules/client";
67
69
  import { agentScheduleTargetSchema } from "@fungi.computer/shiitake-extensions/schedules";
68
- import { createAgentAvatarStore, } from "../agent-avatars.js";
70
+ import { agentAvatarSchema, createAgentAvatarStore, } from "../agent-avatars.js";
69
71
  import { createStarterLedger, ensureStarterAgent, seedStarterHome, } from "../starter-agent.js";
70
72
  import { agentIds, createAgentDirectory, createFleetSessions, commandSettlementSchema, DirectoryError, } from "@fungi.computer/shiitake/fleet";
71
73
  import { appToolPolicySchema, } from "../apps/index.js";
@@ -1386,6 +1388,17 @@ export class StandaloneAgentBase extends ShiitakeDO {
1386
1388
  return answer;
1387
1389
  },
1388
1390
  })),
1391
+ createSelfSource({
1392
+ agentId: this.agentName(),
1393
+ isChannelSession: (sessionId) => this.channelConversations().sessionConversation(sessionId) !==
1394
+ null,
1395
+ directory: async () => {
1396
+ const pin = await this.policyDirectory();
1397
+ if (pin === null)
1398
+ throw new Error("Agent has no pinned directory");
1399
+ return this.env.AGENT_DIRECTORY.getByName(pin.directoryName);
1400
+ },
1401
+ }),
1389
1402
  conversationAgents.control(() => this.controlDirectory()),
1390
1403
  (await this.ui()).source,
1391
1404
  standaloneWebSource(this.env),
@@ -2179,19 +2192,23 @@ export class AgentDirectory extends DurableObject {
2179
2192
  ? (this.directory.read(this.grant(), id.value)?.createdBy ?? null)
2180
2193
  : null;
2181
2194
  }
2182
- /** Owner-only rename; refuses a name already held by another Agent. */
2195
+ /** An owner or the Agent itself may rename it; another Agent's name is refused. */
2183
2196
  rename(agentId, name, principal) {
2184
- if (!oysterPrincipalIsOwner(principal))
2197
+ if (principal.actor.kind === "agent"
2198
+ ? principal.actor.agentId !== agentId
2199
+ : !oysterPrincipalIsOwner(principal))
2185
2200
  return { error: "not_granted" };
2186
2201
  const id = agentIds.agent.parse(agentId);
2187
2202
  if (!id.ok)
2188
2203
  return { error: "not_found" };
2189
2204
  return this.ctx.storage.transactionSync(() => {
2190
2205
  try {
2206
+ const previous = this.directory.read(this.grant(), id.value);
2191
2207
  const renamed = this.directory.rename(this.grant(), id.value, {
2192
2208
  name,
2193
2209
  });
2194
- this.bump();
2210
+ if (previous?.name !== renamed.name)
2211
+ this.bump();
2195
2212
  return {
2196
2213
  agentId: renamed.agentId,
2197
2214
  createdBy: renamed.createdBy,
@@ -2208,19 +2225,24 @@ export class AgentDirectory extends DurableObject {
2208
2225
  }
2209
2226
  });
2210
2227
  }
2211
- /** Owner-only avatar change; the Agent wears it in every App and list. */
2228
+ /** Owner or self avatar change; the Agent wears it in every App and list. */
2212
2229
  setAvatar(agentId, avatar, principal) {
2213
- if (!oysterPrincipalIsOwner(principal))
2230
+ if (principal.actor.kind === "agent"
2231
+ ? principal.actor.agentId !== agentId
2232
+ : !oysterPrincipalIsOwner(principal))
2214
2233
  return { error: "not_granted" };
2215
2234
  const id = agentIds.agent.parse(agentId);
2216
2235
  if (!id.ok)
2217
2236
  return { error: "not_found" };
2237
+ const chosen = agentAvatarSchema.parse(avatar);
2218
2238
  return this.ctx.storage.transactionSync(() => {
2219
2239
  const agent = this.directory.read(this.grant(), id.value);
2220
2240
  if (agent === null)
2221
2241
  return { error: "not_found" };
2222
- this.avatars.write(agent.agentId, avatar);
2223
- this.bump();
2242
+ if (!isDeepStrictEqual(this.avatars.read(agent.agentId), chosen)) {
2243
+ this.avatars.write(agent.agentId, chosen);
2244
+ this.bump();
2245
+ }
2224
2246
  return {
2225
2247
  agentId: agent.agentId,
2226
2248
  createdBy: agent.createdBy,
@@ -2,6 +2,6 @@ import type { WorkflowCeilingCapturePorts } from "@fungi.computer/braid/runtime"
2
2
  import type { StandaloneWorkflowNodeCaptureOptions } from "./workflow-node-capture.js";
3
3
  /** Installation Git only; Team-source needs its separate authoritative namespace owner. */
4
4
  export declare function createStandaloneWorkflowInstallationGitCapture(options: Readonly<{
5
- host: Pick<StandaloneWorkflowNodeCaptureOptions["host"], "auth" | "artifacts" | "installations">;
5
+ host: Pick<StandaloneWorkflowNodeCaptureOptions["host"], "tenantId" | "auth" | "artifacts" | "installations">;
6
6
  readers: Pick<StandaloneWorkflowNodeCaptureOptions["readers"], "member">;
7
7
  }>): WorkflowCeilingCapturePorts["git"];
@@ -17,7 +17,7 @@ export function createStandaloneWorkflowInstallationGitCapture(options) {
17
17
  const principal = await host.auth.resolve(actor);
18
18
  if (principal === null || !oysterPrincipalIsOwner(principal))
19
19
  return false;
20
- const caller = invocationCallerContext(principal, null);
20
+ const caller = invocationCallerContext(principal, null, host.tenantId);
21
21
  if (caller.actor.kind !== "member" ||
22
22
  caller.actor.memberId !== actor.memberId)
23
23
  return false;
@@ -2,11 +2,11 @@ import * as S from "effect/Schema";
2
2
  import { type Catalog, type DispatchResult, type NodeAdmissionResult, type NodeCall, type NodeEvent } from "@fungi.computer/braid";
3
3
  import { type OysterHost } from "../host.js";
4
4
  import { type InvocationFacts } from "../invocation.js";
5
- import type { AppMethodCallContext } from "@fungi.computer/puffball/app-method-runtime";
5
+ import { type AppMethodCallContext } from "@fungi.computer/puffball/app-method-runtime";
6
6
  import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
7
7
  import { type GraphStartRequest, type WorkflowCatalogEntry, type WorkflowRunAuthority, type WorkflowGitPassNode, type WorkflowRunDelivery } from "@fungi.computer/braid/runtime";
8
8
  import { type AppEventFact } from "@fungi.computer/puffball/app-event-facts";
9
- export type StandaloneWorkflowHost = Pick<OysterHost, "installations" | "artifacts" | "instances" | "computerId" | "git" | "capabilities" | "keys">;
9
+ export type StandaloneWorkflowHost = Pick<OysterHost, "tenantId" | "installations" | "artifacts" | "instances" | "computerId" | "git" | "capabilities" | "keys">;
10
10
  type CatalogMethodSummary = Readonly<{
11
11
  pending?: true;
12
12
  description: string;
@@ -150,6 +150,13 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
150
150
  }>;
151
151
  admitInvocation: (raw: InvocationFacts, operation: string) => Promise<{
152
152
  context: {
153
+ scope: {
154
+ kind: "team";
155
+ teamId: string;
156
+ } | {
157
+ kind: "standalone";
158
+ tenant: string;
159
+ };
153
160
  computerId: string | null;
154
161
  actor: {
155
162
  kind: "member";
@@ -572,18 +579,20 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
572
579
  };
573
580
  };
574
581
  readonly nodes: readonly ({
575
- readonly id: string;
576
- readonly kind: "code";
577
- readonly source: string;
578
- readonly input: {
582
+ readonly output: {
579
583
  readonly [x: string]: S.Json;
580
584
  };
581
- readonly output: {
585
+ readonly input: {
582
586
  readonly [x: string]: S.Json;
583
587
  };
584
588
  readonly values: {
585
589
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
586
590
  };
591
+ readonly kind: "code";
592
+ readonly id: string;
593
+ readonly source: string;
594
+ readonly title?: string | undefined;
595
+ readonly note?: string | undefined;
587
596
  } | {
588
597
  readonly values: {
589
598
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
@@ -593,6 +602,8 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
593
602
  readonly method: string;
594
603
  readonly app: string;
595
604
  readonly methodDigest: string;
605
+ readonly title?: string | undefined;
606
+ readonly note?: string | undefined;
596
607
  readonly retry?: {
597
608
  readonly attempts: number;
598
609
  } | undefined;
@@ -621,36 +632,47 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
621
632
  readonly id: string;
622
633
  readonly description?: string | undefined;
623
634
  }[] | undefined;
635
+ readonly note?: string | undefined;
624
636
  } | {
625
- readonly id: string;
626
637
  readonly kind: "condition";
638
+ readonly id: string;
627
639
  readonly test: import("@fungi.computer/braid").Predicate;
640
+ readonly title?: string | undefined;
641
+ readonly note?: string | undefined;
628
642
  } | {
629
- readonly id: string;
630
643
  readonly kind: "map";
644
+ readonly id: string;
645
+ readonly body: string;
631
646
  readonly over: {
632
647
  readonly node: string;
633
648
  readonly port: string;
634
649
  };
635
- readonly body: string;
636
650
  readonly concurrency: number;
637
651
  readonly maxItems: number;
652
+ readonly title?: string | undefined;
653
+ readonly note?: string | undefined;
638
654
  } | {
639
- readonly id: string;
640
655
  readonly kind: "repeat";
656
+ readonly id: string;
641
657
  readonly body: string;
642
- readonly maxRounds: number;
643
658
  readonly until: import("@fungi.computer/braid").Predicate;
659
+ readonly maxRounds: number;
660
+ readonly title?: string | undefined;
661
+ readonly note?: string | undefined;
644
662
  } | {
645
- readonly id: string;
646
663
  readonly kind: "wait";
664
+ readonly id: string;
647
665
  readonly for: number;
666
+ readonly title?: string | undefined;
667
+ readonly note?: string | undefined;
648
668
  } | {
649
- readonly id: string;
650
669
  readonly kind: "transform";
670
+ readonly id: string;
651
671
  readonly fields: {
652
672
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
653
673
  };
674
+ readonly title?: string | undefined;
675
+ readonly note?: string | undefined;
654
676
  })[];
655
677
  readonly edges: readonly {
656
678
  readonly from: {
@@ -669,18 +691,20 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
669
691
  readonly [x: string]: S.Json;
670
692
  };
671
693
  readonly nodes: readonly ({
672
- readonly id: string;
673
- readonly kind: "code";
674
- readonly source: string;
675
- readonly input: {
694
+ readonly output: {
676
695
  readonly [x: string]: S.Json;
677
696
  };
678
- readonly output: {
697
+ readonly input: {
679
698
  readonly [x: string]: S.Json;
680
699
  };
681
700
  readonly values: {
682
701
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
683
702
  };
703
+ readonly kind: "code";
704
+ readonly id: string;
705
+ readonly source: string;
706
+ readonly title?: string | undefined;
707
+ readonly note?: string | undefined;
684
708
  } | {
685
709
  readonly values: {
686
710
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
@@ -690,6 +714,8 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
690
714
  readonly method: string;
691
715
  readonly app: string;
692
716
  readonly methodDigest: string;
717
+ readonly title?: string | undefined;
718
+ readonly note?: string | undefined;
693
719
  readonly retry?: {
694
720
  readonly attempts: number;
695
721
  } | undefined;
@@ -718,36 +744,47 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
718
744
  readonly id: string;
719
745
  readonly description?: string | undefined;
720
746
  }[] | undefined;
747
+ readonly note?: string | undefined;
721
748
  } | {
722
- readonly id: string;
723
749
  readonly kind: "condition";
750
+ readonly id: string;
724
751
  readonly test: import("@fungi.computer/braid").Predicate;
752
+ readonly title?: string | undefined;
753
+ readonly note?: string | undefined;
725
754
  } | {
726
- readonly id: string;
727
755
  readonly kind: "map";
756
+ readonly id: string;
757
+ readonly body: string;
728
758
  readonly over: {
729
759
  readonly node: string;
730
760
  readonly port: string;
731
761
  };
732
- readonly body: string;
733
762
  readonly concurrency: number;
734
763
  readonly maxItems: number;
764
+ readonly title?: string | undefined;
765
+ readonly note?: string | undefined;
735
766
  } | {
736
- readonly id: string;
737
767
  readonly kind: "repeat";
768
+ readonly id: string;
738
769
  readonly body: string;
739
- readonly maxRounds: number;
740
770
  readonly until: import("@fungi.computer/braid").Predicate;
771
+ readonly maxRounds: number;
772
+ readonly title?: string | undefined;
773
+ readonly note?: string | undefined;
741
774
  } | {
742
- readonly id: string;
743
775
  readonly kind: "wait";
776
+ readonly id: string;
744
777
  readonly for: number;
778
+ readonly title?: string | undefined;
779
+ readonly note?: string | undefined;
745
780
  } | {
746
- readonly id: string;
747
781
  readonly kind: "transform";
782
+ readonly id: string;
748
783
  readonly fields: {
749
784
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
750
785
  };
786
+ readonly title?: string | undefined;
787
+ readonly note?: string | undefined;
751
788
  })[];
752
789
  readonly edges: readonly {
753
790
  readonly from: {
@@ -1,4 +1,6 @@
1
1
  import * as S from "effect/Schema";
2
+ import * as z from "zod/mini";
3
+ import { defaultTenant } from "../tenant.js";
2
4
  import { admitRunInput, accepts, catalogEvents, catalogMethods, catalogSchema, contentDigest, canonicalJson, parseProjection, nodeEventSchema, } from "@fungi.computer/braid";
3
5
  import { deriveDeclaredOperations, approvedBindingGrants, grantsFor, } from "../apps/index.js";
4
6
  import { pendingSchema, presentMethodName, } from "@fungi.computer/agar/backend-definition";
@@ -7,6 +9,7 @@ import { verifyRelease, } from "../host.js";
7
9
  import { APP_INVOCATION_CEILING_MS, invocationAuthorityOf, invocationFacts, invocationFactsSchema, } from "../invocation.js";
8
10
  import { AppInstanceError } from "../index.js";
9
11
  import { appCapabilityIds } from "@fungi.computer/puffball";
12
+ import { appMethodCallerSchema, } from "@fungi.computer/puffball/app-method-runtime";
10
13
  import { createGraphWorkflowRuns, createTriggerRunReservations, compileForMember, graphStartRequestSchema, preparationFromRun, planNodeCall, workflowRunContextSchema, } from "@fungi.computer/braid/runtime";
11
14
  import { appMethodCallContextSchema } from "@fungi.computer/puffball/app";
12
15
  import { appEventFactSchema, } from "@fungi.computer/puffball/app-event-facts";
@@ -97,6 +100,10 @@ const summarizedEntry = (entry) => {
97
100
  };
98
101
  /** The standalone host's installation admission, above the portable engine. */
99
102
  export function createStandaloneWorkflowHost(owner, host, options) {
103
+ // StandaloneWorkflows opens only the default tenant's durable namespace.
104
+ // A different host cannot relabel its existing stored caller attribution.
105
+ if (host.tenantId !== defaultTenant)
106
+ throw new AppInstanceError("installation_tenant_mismatch");
100
107
  const graph = createGraphWorkflowRuns(owner);
101
108
  const reservations = createTriggerRunReservations(owner);
102
109
  const store = {
@@ -115,6 +122,11 @@ export function createStandaloneWorkflowHost(owner, host, options) {
115
122
  owner.sql.exec(`CREATE TABLE IF NOT EXISTS standalone_workflow_callers (
116
123
  run_id TEXT PRIMARY KEY, caller TEXT NOT NULL
117
124
  ) STRICT`);
125
+ // Store attribution, not a second tenant authority. Reconstruct scope from
126
+ // this host's pin on every read; the persisted caller representation stays
127
+ // unchanged and cannot choose another tenant.
128
+ const storedCallerSchema = z.omit(appMethodCallerSchema, { scope: true });
129
+ const encodeCaller = (context) => JSON.stringify(storedCallerSchema.parse(context));
118
130
  const readCaller = (runId) => {
119
131
  const row = owner.sql
120
132
  .exec("SELECT caller FROM standalone_workflow_callers WHERE run_id=?", runId)
@@ -122,7 +134,10 @@ export function createStandaloneWorkflowHost(owner, host, options) {
122
134
  if (row === undefined)
123
135
  return null;
124
136
  const saved = S.decodeUnknownSync(S.Struct({ caller: S.String }))(row);
125
- return S.decodeUnknownSync(appMethodCallContextSchema)(JSON.parse(saved.caller));
137
+ return S.decodeUnknownSync(appMethodCallContextSchema)({
138
+ ...storedCallerSchema.parse(JSON.parse(saved.caller)),
139
+ scope: { kind: "standalone", tenant: host.tenantId },
140
+ });
126
141
  };
127
142
  const caller = (runId) => {
128
143
  const saved = readCaller(runId);
@@ -277,6 +292,7 @@ export function createStandaloneWorkflowHost(owner, host, options) {
277
292
  if (current.membershipVersion !== member.membershipVersion)
278
293
  throw new AppInstanceError("revoked");
279
294
  const context = {
295
+ scope: { kind: "standalone", tenant: host.tenantId },
280
296
  actor: { kind: "member", memberId: member.memberId },
281
297
  role: "owner",
282
298
  computerId: host.computerId ?? null,
@@ -451,11 +467,12 @@ export function createStandaloneWorkflowHost(owner, host, options) {
451
467
  /** Trigger runs act as the owner who armed them on their pinned Computer. */
452
468
  recordTriggerCaller(runId, memberId, computerId) {
453
469
  const context = {
470
+ scope: { kind: "standalone", tenant: host.tenantId },
454
471
  actor: { kind: "member", memberId },
455
472
  computerId,
456
473
  role: "owner",
457
474
  };
458
- owner.sql.exec("INSERT OR IGNORE INTO standalone_workflow_callers(run_id,caller) VALUES(?,?)", runId, JSON.stringify(context));
475
+ owner.sql.exec("INSERT OR IGNORE INTO standalone_workflow_callers(run_id,caller) VALUES(?,?)", runId, encodeCaller(context));
459
476
  },
460
477
  catalog,
461
478
  // Host readers use this only after admitting the live member and library.
@@ -617,6 +634,7 @@ export function createStandaloneWorkflowHost(owner, host, options) {
617
634
  if (publication !== undefined && !(await publisherGranted(current)))
618
635
  return { error: "not_granted" };
619
636
  const callContext = {
637
+ scope: { kind: "standalone", tenant: host.tenantId },
620
638
  actor: captured.actor,
621
639
  computerId: context.computerId,
622
640
  };
@@ -648,7 +666,7 @@ export function createStandaloneWorkflowHost(owner, host, options) {
648
666
  // store compares the whole stored record, source and initiator included.
649
667
  const accepted = store.startCompiled(run);
650
668
  if (accepted !== "conflict")
651
- owner.sql.exec("INSERT OR IGNORE INTO standalone_workflow_callers(run_id,caller) VALUES(?,?)", runId, JSON.stringify(callContext));
669
+ owner.sql.exec("INSERT OR IGNORE INTO standalone_workflow_callers(run_id,caller) VALUES(?,?)", runId, encodeCaller(callContext));
652
670
  return accepted;
653
671
  });
654
672
  return { kind, runId, planDigest: compiled.plan.planDigest };
@@ -3,7 +3,7 @@ import { type OysterHost } from "../host.js";
3
3
  import type { StandaloneWorkflowAuthorityReaders } from "./workflow-authority-readers.js";
4
4
  /** Live host readers and approvals; a compile catalog is deliberately not a grant port. */
5
5
  export type StandaloneWorkflowNodeCaptureOptions = Readonly<{
6
- host: Pick<OysterHost, "artifacts" | "computerId" | "capabilities"> & Readonly<{
6
+ host: Pick<OysterHost, "tenantId" | "artifacts" | "computerId" | "capabilities"> & Readonly<{
7
7
  auth: Pick<OysterHost["auth"], "resolve">;
8
8
  installations: Pick<OysterHost["installations"], "get">;
9
9
  }>;
@@ -19,7 +19,7 @@ export function createStandaloneWorkflowNodeCapture(options) {
19
19
  const principal = await host.auth.resolve(actor);
20
20
  if (principal === null || !oysterPrincipalIsOwner(principal))
21
21
  return null;
22
- const caller = invocationCallerContext(principal, target.computerId);
22
+ const caller = invocationCallerContext(principal, target.computerId, host.tenantId);
23
23
  if (caller.actor.kind !== "member" ||
24
24
  caller.actor.memberId !== actor.memberId)
25
25
  return null;