glove-foundry 0.6.1 → 0.7.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.
@@ -1,14 +1,27 @@
1
1
  import {
2
+ DURABLE_SEGMENT,
3
+ EMPTY_CAPABILITY_REGISTRY,
2
4
  EMPTY_NATIVE_REGISTRY,
5
+ FOUNDRY_AGENT_APPLICATION_BRAND,
6
+ FOUNDRY_CORE_COMMAND_DIRECTORY_ENV,
3
7
  FOUNDRY_LAYER_BRAND,
8
+ FOUNDRY_MCP_BRAND,
9
+ FOUNDRY_MEMORY_BRAND,
10
+ FOUNDRY_SHARED_TOOL_BRAND,
4
11
  FOUNDRY_SUBSCRIBER_BRAND,
5
12
  bindFileIdentity,
13
+ composeDurableAgent,
14
+ createFoundryCoreCommandRequest,
6
15
  defineAgentFromModule,
16
+ defineSharedTool,
17
+ durableRoute,
7
18
  fileDefinitionKey,
8
19
  fileDefinitionLabel,
9
20
  fileIdentified,
10
- internalAgentName
11
- } from "./chunk-K2EU63MB.js";
21
+ installationKey,
22
+ internalAgentName,
23
+ waitForFoundryCoreCommandResult
24
+ } from "./chunk-64UBLGYM.js";
12
25
 
13
26
  // src/application.ts
14
27
  var FOUNDRY_APPLICATION_BRAND = /* @__PURE__ */ Symbol.for(
@@ -48,369 +61,6 @@ var EMPTY_FOUNDRY_APPLICATION = defineApplication({
48
61
  name: "Glove Foundry"
49
62
  });
50
63
 
51
- // src/capabilities.ts
52
- import { Effect } from "effect";
53
- import { mountMcp } from "glove-mcp";
54
- import {
55
- useContext,
56
- useEpisodicCurator,
57
- useEpisodicReader,
58
- useMemoryCurator,
59
- useMemoryReader,
60
- useResourcesCurator,
61
- useResourcesReader
62
- } from "glove-memory/tools";
63
- var FOUNDRY_SHARED_TOOL_BRAND = /* @__PURE__ */ Symbol.for(
64
- "glove-foundry-shared-tool"
65
- );
66
- var FOUNDRY_AGENT_APPLICATION_BRAND = /* @__PURE__ */ Symbol.for(
67
- "glove-foundry-agent-application"
68
- );
69
- var FOUNDRY_MCP_BRAND = /* @__PURE__ */ Symbol.for("glove-foundry-mcp");
70
- var FOUNDRY_MEMORY_BRAND = /* @__PURE__ */ Symbol.for("glove-foundry-memory");
71
- function install(capability, ...configuration) {
72
- const config = configuration[0];
73
- const selection = configuration[1];
74
- const kind = FOUNDRY_SHARED_TOOL_BRAND in capability ? "tool" : FOUNDRY_AGENT_APPLICATION_BRAND in capability ? "application" : "mcp";
75
- const installation = {
76
- kind,
77
- ...config !== void 0 ? { config } : {}
78
- };
79
- Object.defineProperty(installation, "id", {
80
- enumerable: true,
81
- get: () => capability.id
82
- });
83
- if (selection?.account) {
84
- Object.defineProperty(installation, "accountId", {
85
- enumerable: true,
86
- get: () => selection.account.id
87
- });
88
- }
89
- return Object.freeze(installation);
90
- }
91
- function installationKey(installation) {
92
- return `${installation.kind}:${installation.id}`;
93
- }
94
- function assertCapabilityId(id2, label) {
95
- if (!/^[a-z][a-z0-9-]*(?:\/[a-z][a-z0-9-]*)*$/.test(id2)) {
96
- throw new Error(
97
- `Invalid Foundry ${label} id "${id2}". Use lowercase path segments containing letters, digits, and hyphens.`
98
- );
99
- }
100
- }
101
- function decodeCapabilityConfig(definition, installation) {
102
- if (!definition.config) return installation.config;
103
- const parsed = definition.config.safeParse(installation.config ?? {});
104
- if (!parsed.success) {
105
- throw new Error(
106
- `Invalid config for ${installation.kind} "${definition.id}": ${parsed.error.message}`
107
- );
108
- }
109
- return parsed.data;
110
- }
111
- function defineSharedTool(options) {
112
- if (options.id) assertCapabilityId(options.id, "shared tool");
113
- const { id: id2, ...definition } = options;
114
- return Object.freeze(fileIdentified({
115
- ...definition,
116
- [FOUNDRY_SHARED_TOOL_BRAND]: true
117
- }, "tool", id2));
118
- }
119
- function defineAgentApplication(options) {
120
- if (options.id) assertCapabilityId(options.id, "agent application");
121
- const label = options.id ?? "<application file route>";
122
- const inbound = Object.freeze([...options.inbound ?? []]);
123
- const outbound = Object.freeze([...options.outbound ?? []]);
124
- for (const transmission of inbound) {
125
- if (!transmission.inbound) {
126
- throw new Error(
127
- `Application "${label}" declares an outbound-only transmission as inbound.`
128
- );
129
- }
130
- }
131
- for (const transmission of outbound) {
132
- if (!transmission.outbound) {
133
- throw new Error(
134
- `Application "${label}" declares an inbound-only transmission as outbound.`
135
- );
136
- }
137
- }
138
- const transmissionDefinitions = /* @__PURE__ */ new Map();
139
- for (const transmission of [
140
- ...options.transmissions ?? [],
141
- ...inbound,
142
- ...outbound
143
- ]) {
144
- const key = fileDefinitionKey(transmission);
145
- const existing = transmissionDefinitions.get(key);
146
- if (!existing) transmissionDefinitions.set(key, transmission);
147
- }
148
- const transmissions = Object.freeze([...transmissionDefinitions.values()]);
149
- const connections = Object.freeze([...options.connections ?? []]);
150
- const connectionIds = /* @__PURE__ */ new Set();
151
- for (const connection of connections) {
152
- const connectionKey = fileDefinitionKey(connection);
153
- if (connectionIds.has(connectionKey)) {
154
- throw new Error(`Application "${label}" contains the same connection more than once.`);
155
- }
156
- connectionIds.add(connectionKey);
157
- for (const transmission of connection.transmissions) {
158
- if (!transmissionDefinitions.has(fileDefinitionKey(transmission))) {
159
- throw new Error(
160
- `Application "${label}" contains a connection for a transmission it does not own.`
161
- );
162
- }
163
- }
164
- }
165
- const { id: id2, ...definition } = options;
166
- return Object.freeze(fileIdentified({
167
- ...definition,
168
- inbound,
169
- outbound,
170
- transmissions,
171
- connections,
172
- [FOUNDRY_AGENT_APPLICATION_BRAND]: true
173
- }, "application", id2));
174
- }
175
- var defineApp = defineAgentApplication;
176
- function identifyMcpEntry(entry, id2) {
177
- if (entry.transport) return { ...entry, id: id2 };
178
- return { ...entry, id: id2, url: entry.url };
179
- }
180
- function defineMcp(options) {
181
- if (options.id) assertCapabilityId(options.id, "MCP");
182
- const { id: id2, ...definition } = options;
183
- return Object.freeze(fileIdentified({
184
- ...definition,
185
- [FOUNDRY_MCP_BRAND]: true
186
- }, "mcp", id2));
187
- }
188
- function defineMemory(options) {
189
- if (options.id) assertCapabilityId(options.id, "memory profile");
190
- if (!options.entity && !options.episodic && !options.resources && !options.context && !options.mount) {
191
- throw new Error(`Foundry memory profile "${options.id ?? "<file route>"}" is empty.`);
192
- }
193
- const { id: id2, ...definition } = options;
194
- return Object.freeze(fileIdentified({
195
- ...definition,
196
- [FOUNDRY_MEMORY_BRAND]: true
197
- }, "memory", id2));
198
- }
199
- var EMPTY_CAPABILITY_REGISTRY = Object.freeze({
200
- tools: Object.freeze([]),
201
- applications: Object.freeze([]),
202
- mcp: Object.freeze([]),
203
- memory: Object.freeze([])
204
- });
205
- function inboxMethods(store) {
206
- return typeof store.getInboxItems === "function" && typeof store.addInboxItem === "function" && typeof store.updateInboxItem === "function" && typeof store.getResolvedInboxItems === "function";
207
- }
208
- function isInboxCapableStore(store) {
209
- return inboxMethods(store);
210
- }
211
- function indexRegistry(values, kind) {
212
- const result = /* @__PURE__ */ new Map();
213
- for (const value of values) {
214
- if (result.has(value.id)) {
215
- throw new Error(`Duplicate Foundry ${kind} id "${value.id}".`);
216
- }
217
- result.set(value.id, value);
218
- }
219
- return result;
220
- }
221
- function mountMemory(profile, context) {
222
- return Effect.gen(function* () {
223
- if (profile.entity) {
224
- const adapter = yield* profile.entity.adapter(context);
225
- const options = profile.entity.tools ? { tools: profile.entity.tools } : void 0;
226
- if ((profile.entity.access ?? "reader") === "curator") {
227
- useMemoryCurator(context.glove, adapter, options);
228
- } else {
229
- useMemoryReader(context.glove, adapter, options);
230
- }
231
- }
232
- if (profile.episodic) {
233
- const adapter = yield* profile.episodic.adapter(context);
234
- const options = profile.episodic.tools ? { tools: profile.episodic.tools } : void 0;
235
- if ((profile.episodic.access ?? "reader") === "curator") {
236
- useEpisodicCurator(context.glove, adapter, options);
237
- } else {
238
- useEpisodicReader(context.glove, adapter, options);
239
- }
240
- }
241
- if (profile.resources) {
242
- const adapter = yield* profile.resources.adapter(context);
243
- const options = profile.resources.tools ? { tools: profile.resources.tools } : void 0;
244
- if ((profile.resources.access ?? "reader") === "curator") {
245
- useResourcesCurator(context.glove, adapter, options);
246
- } else {
247
- useResourcesReader(context.glove, adapter, options);
248
- }
249
- }
250
- if (profile.context) {
251
- const adapter = yield* profile.context.adapter(context);
252
- useContext(
253
- context.glove,
254
- adapter,
255
- profile.context.tools ? { tools: profile.context.tools } : void 0
256
- );
257
- }
258
- if (profile.mount) yield* profile.mount(context);
259
- });
260
- }
261
- function configureMemory(profile, config) {
262
- return Object.freeze({ profile, config });
263
- }
264
- function mountAgentDefinitionMemory(options) {
265
- return Effect.gen(function* () {
266
- const memory = indexRegistry(options.registry.memory, "memory profile");
267
- const seen = /* @__PURE__ */ new Set();
268
- for (const selection of options.memory) {
269
- const reference = "profile" in selection ? selection.profile : selection;
270
- const profile = memory.get(reference.id);
271
- if (!profile) {
272
- throw new Error(`Unknown agent memory profile "${reference.id}".`);
273
- }
274
- if (seen.has(`memory:${profile.id}`)) {
275
- throw new Error(`Duplicate agent memory profile "${profile.id}".`);
276
- }
277
- seen.add(`memory:${profile.id}`);
278
- const config = typeof selection === "object" && "profile" in selection ? selection.config : void 0;
279
- const capability = {
280
- kind: "memory",
281
- id: profile.id,
282
- ...config !== void 0 ? { config } : {}
283
- };
284
- const context = {
285
- ...options.context,
286
- surface: { kind: "memory", id: profile.id },
287
- config: decodeCapabilityConfig(profile, capability)
288
- };
289
- yield* mountMemory(profile, context);
290
- options.context.emit({
291
- type: "foundry.definition.memory.mounted",
292
- data: { id: profile.id }
293
- });
294
- }
295
- });
296
- }
297
- function installRegistry(options) {
298
- return Effect.gen(function* () {
299
- const tools = indexRegistry(options.registry.tools, "shared tool");
300
- const applications = indexRegistry(
301
- options.registry.applications,
302
- "agent application"
303
- );
304
- const mcp = indexRegistry(options.registry.mcp, "MCP");
305
- const seen = /* @__PURE__ */ new Set();
306
- const installedMcp = [];
307
- const installed = [];
308
- for (const installation of options.installations) {
309
- assertCapabilityId(installation.id, installation.kind);
310
- if (installation.config && typeof installation.config === "object" && Object.prototype.hasOwnProperty.call(installation.config, "accountId")) {
311
- throw new Error(
312
- `Installation config for ${installation.kind} "${installation.id}" cannot contain accountId. Select a persisted account on the installation, or pass { account } as install()'s third argument in code.`
313
- );
314
- }
315
- const key = installationKey(installation);
316
- if (seen.has(key)) continue;
317
- seen.add(key);
318
- const definition = installation.kind === "tool" ? tools.get(installation.id) : installation.kind === "application" ? applications.get(installation.id) : mcp.get(installation.id);
319
- if (!definition) {
320
- throw new Error(
321
- `Agent "${options.context.agentId}" requests unknown ${installation.kind} "${installation.id}".`
322
- );
323
- }
324
- const config = decodeCapabilityConfig(
325
- definition,
326
- installation
327
- );
328
- const context = {
329
- ...options.context,
330
- installation,
331
- config,
332
- ...installation.accountId ? {
333
- accountId: installation.accountId,
334
- ...options.accountSessions ? {
335
- withAccountSession: (operation, use) => options.accountSessions.withSession({
336
- accountId: installation.accountId,
337
- operation,
338
- agentId: options.context.agentId,
339
- conversationId: options.context.conversationId,
340
- workspaceId: options.context.workspaceId
341
- }, use)
342
- } : {}
343
- } : {}
344
- };
345
- if (installation.kind === "tool") {
346
- const shared = definition;
347
- const tool = shared.tool ?? (yield* shared.create(context));
348
- options.context.glove.fold(tool);
349
- } else if (installation.kind === "application") {
350
- const { glove: _glove, store: _store, ...headlessContext } = context;
351
- const application = definition;
352
- const contribution = application.install ? yield* application.install(headlessContext) : void 0;
353
- for (const tool of contribution?.tools ?? []) options.context.glove.fold(tool);
354
- } else {
355
- const mcpDefinition = definition;
356
- const headlessContext = (() => {
357
- const { glove: _glove, store: _store, ...headless } = context;
358
- return headless;
359
- })();
360
- const source = typeof mcpDefinition.entry === "function" ? mcpDefinition.entry(headlessContext) : mcpDefinition.entry;
361
- const entry = Effect.isEffect(source) ? yield* source : source instanceof Promise ? yield* Effect.tryPromise({ try: () => source, catch: (cause) => cause }) : source;
362
- installedMcp.push({
363
- definition: mcpDefinition,
364
- installation,
365
- config,
366
- entry: identifyMcpEntry(entry, mcpDefinition.id)
367
- });
368
- }
369
- installed.push(installation);
370
- options.context.emit({
371
- type: "foundry.installation.completed",
372
- data: { kind: installation.kind, id: installation.id }
373
- });
374
- }
375
- if (installedMcp.length > 0) {
376
- if (!options.mcpAdapter) {
377
- throw new Error(
378
- `Agent "${options.context.agentId}" installs MCP capabilities but the application does not define mcpAdapter.`
379
- );
380
- }
381
- const adapter = yield* options.mcpAdapter({
382
- ...options.context,
383
- installed: installedMcp.map(({ definition }) => definition),
384
- resolved: installedMcp
385
- });
386
- const selectedIds = new Set(installedMcp.map(({ definition }) => definition.id));
387
- const scopedAdapter = {
388
- identifier: adapter.identifier,
389
- getActive: async () => [...selectedIds],
390
- activate: (id2) => adapter.activate(id2),
391
- deactivate: (id2) => adapter.deactivate(id2),
392
- ...adapter.getAccessToken ? { getAccessToken: (id2) => adapter.getAccessToken(id2) } : {},
393
- ...adapter.getAuthHeaders ? { getAuthHeaders: (id2) => adapter.getAuthHeaders(id2) } : {},
394
- ...adapter.getStdioEnvironment ? { getStdioEnvironment: (id2) => adapter.getStdioEnvironment(id2) } : {}
395
- };
396
- yield* Effect.tryPromise({
397
- try: () => mountMcp(options.context.glove, {
398
- adapter: scopedAdapter,
399
- entries: installedMcp.map(({ entry }) => entry),
400
- ambiguityPolicy: { type: "auto-pick-best" }
401
- }),
402
- catch: (cause) => cause
403
- });
404
- }
405
- return Object.freeze(installed);
406
- });
407
- }
408
- function isFoundryCapability(value) {
409
- if (!value || typeof value !== "object") return false;
410
- const object = value;
411
- return object[FOUNDRY_SHARED_TOOL_BRAND] === true || object[FOUNDRY_AGENT_APPLICATION_BRAND] === true || object[FOUNDRY_MCP_BRAND] === true || object[FOUNDRY_MEMORY_BRAND] === true;
412
- }
413
-
414
64
  // src/composition.ts
415
65
  var composedToolBodies = /* @__PURE__ */ new WeakMap();
416
66
  function isToolBody(value) {
@@ -1055,6 +705,21 @@ async function discoverAgents(options) {
1055
705
  executionName: internalAgentName(route)
1056
706
  });
1057
707
  }
708
+ const expand = (entry, ancestors) => {
709
+ for (const [name, selection] of Object.entries(entry.definition.durableSubagents ?? {})) {
710
+ if (ancestors.has(selection.agent)) throw new Error(`Cyclic durable subagents at "${entry.route}/${name}".`);
711
+ const route = durableRoute(entry.route, name);
712
+ if (seen.has(route)) throw new Error(`Durable subagent route "${route}" conflicts with an existing agent.`);
713
+ seen.set(route, entry.filePath);
714
+ const child = { ...entry, route, definition: composeDurableAgent(entry.definition, name, selection), executionName: internalAgentName(route) };
715
+ discovered.push(child);
716
+ expand(child, /* @__PURE__ */ new Set([...ancestors, selection.agent]));
717
+ }
718
+ };
719
+ for (const entry of [...discovered]) {
720
+ if (entry.route.includes(DURABLE_SEGMENT)) throw new Error(`The route segment "workers" is reserved for durable subagents.`);
721
+ expand(entry, /* @__PURE__ */ new Set([entry.definition]));
722
+ }
1058
723
  return discovered;
1059
724
  }
1060
725
  function createManifest(agents) {
@@ -1083,6 +748,7 @@ function createManifest(agents) {
1083
748
  subagents: (typeof definition.subagents === "function" ? [] : definition.subagents ?? []).map(
1084
749
  (subagent) => subagent.name
1085
750
  ),
751
+ durableSubagents: Object.entries(definition.durableSubagents ?? {}).map(([name, child]) => ({ name, definitionId: durableRoute(route, name), ...child.description ? { description: child.description } : {} })),
1086
752
  memory: (typeof definition.memory === "function" ? [] : definition.memory ?? []).map(
1087
753
  (selection) => {
1088
754
  const profile = "profile" in selection ? selection.profile : selection;
@@ -1134,7 +800,7 @@ function createManifest(agents) {
1134
800
 
1135
801
  // src/primitives.ts
1136
802
  import { randomUUID } from "node:crypto";
1137
- import { Effect as Effect3 } from "effect";
803
+ import { Effect as Effect2 } from "effect";
1138
804
  function toGloveMessage(input) {
1139
805
  if (typeof input === "string") {
1140
806
  return freezeGloveMessage({ sender: "user", text: input });
@@ -1171,6 +837,7 @@ var MemoryFoundryDataAdapter = class {
1171
837
  agentsByProvisioningKey = /* @__PURE__ */ new Map();
1172
838
  subscriptions = /* @__PURE__ */ new Map();
1173
839
  inboundDeliveries = /* @__PURE__ */ new Map();
840
+ events = /* @__PURE__ */ new Map();
1174
841
  pendingInbound = /* @__PURE__ */ new Map();
1175
842
  activations = /* @__PURE__ */ new Map();
1176
843
  conversations = /* @__PURE__ */ new Map();
@@ -1207,13 +874,13 @@ var MemoryFoundryDataAdapter = class {
1207
874
  this.pendingSubscriptions = [];
1208
875
  }
1209
876
  getAgent(id2) {
1210
- return Effect3.sync(() => {
877
+ return Effect2.sync(() => {
1211
878
  this.materializeSeeds();
1212
879
  return this.agents.get(id2) ?? null;
1213
880
  });
1214
881
  }
1215
882
  putAgent(agent) {
1216
- return Effect3.sync(() => {
883
+ return Effect2.sync(() => {
1217
884
  this.materializeSeeds();
1218
885
  const reconstructed = reconstructAgentInstance(agent);
1219
886
  const prior = this.agents.get(agent.id);
@@ -1227,16 +894,17 @@ var MemoryFoundryDataAdapter = class {
1227
894
  });
1228
895
  }
1229
896
  listAgents(definitionId) {
1230
- return Effect3.sync(() => {
897
+ return Effect2.sync(() => {
1231
898
  this.materializeSeeds();
1232
899
  return [...this.agents.values()].filter((item) => !definitionId || item.definitionId === definitionId);
1233
900
  });
1234
901
  }
1235
902
  provisionAgent(input) {
1236
- return Effect3.sync(() => {
903
+ return Effect2.sync(() => {
1237
904
  this.materializeSeeds();
1238
905
  const existingId = this.agentsByProvisioningKey.get(input.provisioningKey);
1239
906
  if (existingId) return this.agents.get(existingId);
907
+ if (input.id && this.agents.has(input.id)) throw new Error(`Agent instance "${input.id}" already exists with another provisioning key.`);
1240
908
  const created = createAgentInstance(input.definitionId, {
1241
909
  ...input,
1242
910
  id: input.id ?? `agent_${randomUUID()}`
@@ -1246,35 +914,55 @@ var MemoryFoundryDataAdapter = class {
1246
914
  return created;
1247
915
  });
1248
916
  }
917
+ purgeAgentData(agentId) {
918
+ return Effect2.sync(() => {
919
+ this.materializeSeeds();
920
+ const agent = this.agents.get(agentId);
921
+ if (!agent?.durableSubagent || agent.durableSubagent.status !== "archived") throw new Error("Only archived durable workers can be purged.");
922
+ const conversationIds = new Set([...this.conversations.values()].filter((item) => item.agentId === agentId).map((item) => item.id));
923
+ for (const [id2, item] of this.events) if (item.target.agentId === agentId) this.events.delete(id2);
924
+ for (const [id2, item] of this.pendingInbound) if (item.request.agentId === agentId) this.pendingInbound.delete(id2);
925
+ for (const [id2, item] of this.activations) if (item.agentId === agentId) this.activations.delete(id2);
926
+ for (const id2 of conversationIds) this.conversations.delete(id2);
927
+ for (const [id2, item] of this.inbox) if (item.agentId === agentId || conversationIds.has(item.conversationId ?? "")) this.inbox.delete(id2);
928
+ for (const [id2, item] of this.tasks) if (item.agentId === agentId || conversationIds.has(item.conversationId ?? "")) this.tasks.delete(id2);
929
+ for (let i = this.environment.length - 1; i >= 0; i--) {
930
+ const item = this.environment[i];
931
+ if (item.scope !== "workspace" && (item.agentId === agentId || conversationIds.has(item.conversationId ?? ""))) this.environment.splice(i, 1);
932
+ }
933
+ for (const key of this.workingEnvironments.keys()) if (key.split("\0")[3] === agentId) this.workingEnvironments.delete(key);
934
+ this.agents.set(agentId, reconstructAgentInstance({ ...agent, context: {}, installations: [], playbooks: [], durableSubagent: { ...agent.durableSubagent, status: "purged" }, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }));
935
+ });
936
+ }
1249
937
  getPlaybookSubscription(id2) {
1250
- return Effect3.sync(() => {
938
+ return Effect2.sync(() => {
1251
939
  this.materializeSeeds();
1252
940
  return this.subscriptions.get(id2) ?? null;
1253
941
  });
1254
942
  }
1255
943
  putPlaybookSubscription(subscription) {
1256
- return Effect3.sync(() => {
944
+ return Effect2.sync(() => {
1257
945
  this.materializeSeeds();
1258
946
  this.subscriptions.set(subscription.id, reconstructPlaybookSubscription(subscription));
1259
947
  });
1260
948
  }
1261
949
  deletePlaybookSubscription(id2) {
1262
- return Effect3.sync(() => {
950
+ return Effect2.sync(() => {
1263
951
  this.materializeSeeds();
1264
952
  return this.subscriptions.delete(id2);
1265
953
  });
1266
954
  }
1267
955
  listPlaybookSubscriptions(workspaceId) {
1268
- return Effect3.sync(() => {
956
+ return Effect2.sync(() => {
1269
957
  this.materializeSeeds();
1270
958
  return [...this.subscriptions.values()].filter((item) => !workspaceId || item.workspaceId === workspaceId);
1271
959
  });
1272
960
  }
1273
961
  getInboundDelivery(key) {
1274
- return Effect3.succeed(this.inboundDeliveries.get(key) ?? null);
962
+ return Effect2.succeed(this.inboundDeliveries.get(key) ?? null);
1275
963
  }
1276
964
  claimInboundDelivery(key) {
1277
- return Effect3.sync(() => {
965
+ return Effect2.sync(() => {
1278
966
  if (this.inboundDeliveries.has(key)) return false;
1279
967
  this.inboundDeliveries.set(key, Object.freeze({
1280
968
  key,
@@ -1286,7 +974,7 @@ var MemoryFoundryDataAdapter = class {
1286
974
  });
1287
975
  }
1288
976
  completeInboundDelivery(key, runIds) {
1289
- return Effect3.sync(() => {
977
+ return Effect2.sync(() => {
1290
978
  const prior = this.inboundDeliveries.get(key);
1291
979
  if (!prior) throw new Error(`Inbound delivery claim "${key}" does not exist.`);
1292
980
  this.inboundDeliveries.set(key, Object.freeze({
@@ -1298,59 +986,75 @@ var MemoryFoundryDataAdapter = class {
1298
986
  });
1299
987
  }
1300
988
  releaseInboundDelivery(key) {
1301
- return Effect3.sync(() => {
989
+ return Effect2.sync(() => {
1302
990
  if (this.inboundDeliveries.get(key)?.status === "pending") {
1303
991
  this.inboundDeliveries.delete(key);
1304
992
  }
1305
993
  });
1306
994
  }
995
+ claimEvent(record) {
996
+ return Effect2.sync(() => {
997
+ if (this.agents.get(record.target.agentId)?.durableSubagent?.status === "purged") throw new Error("Cannot deliver an event to a purged worker.");
998
+ if (this.events.has(record.id)) return false;
999
+ this.events.set(record.id, structuredClone(record));
1000
+ return true;
1001
+ });
1002
+ }
1003
+ putEvent(record) {
1004
+ return Effect2.sync(() => {
1005
+ if (this.agents.get(record.target.agentId)?.durableSubagent?.status !== "purged") this.events.set(record.id, structuredClone(record));
1006
+ });
1007
+ }
1008
+ listEvents() {
1009
+ return Effect2.sync(() => [...this.events.values()].map((record) => structuredClone(record)));
1010
+ }
1307
1011
  putPendingInbound(record) {
1308
- return Effect3.sync(() => {
1012
+ return Effect2.sync(() => {
1309
1013
  this.pendingInbound.set(record.id, structuredClone(record));
1310
1014
  });
1311
1015
  }
1312
1016
  deletePendingInbound(id2) {
1313
- return Effect3.sync(() => {
1017
+ return Effect2.sync(() => {
1314
1018
  this.pendingInbound.delete(id2);
1315
1019
  });
1316
1020
  }
1317
1021
  listPendingInbound() {
1318
- return Effect3.sync(() => [...this.pendingInbound.values()].map((record) => structuredClone(record)));
1022
+ return Effect2.sync(() => [...this.pendingInbound.values()].map((record) => structuredClone(record)));
1319
1023
  }
1320
1024
  getActivation(id2) {
1321
- return Effect3.succeed(this.activations.get(id2) ?? null);
1025
+ return Effect2.succeed(this.activations.get(id2) ?? null);
1322
1026
  }
1323
1027
  putActivation(activation) {
1324
- return Effect3.sync(() => {
1028
+ return Effect2.sync(() => {
1325
1029
  this.activations.set(activation.id, reconstructActivation(activation));
1326
1030
  });
1327
1031
  }
1328
1032
  listActivations(workspaceId) {
1329
- return Effect3.succeed(
1033
+ return Effect2.succeed(
1330
1034
  [...this.activations.values()].filter((item) => !workspaceId || item.workspaceId === workspaceId)
1331
1035
  );
1332
1036
  }
1333
1037
  getConversation(id2) {
1334
- return Effect3.succeed(this.conversations.get(id2) ?? null);
1038
+ return Effect2.succeed(this.conversations.get(id2) ?? null);
1335
1039
  }
1336
1040
  putConversation(conversation) {
1337
- return Effect3.sync(() => {
1041
+ return Effect2.sync(() => {
1338
1042
  this.conversations.set(conversation.id, Object.freeze({ ...conversation }));
1339
1043
  });
1340
1044
  }
1341
1045
  listConversations(agentId) {
1342
- return Effect3.succeed([...this.conversations.values()].filter((item) => item.agentId === agentId));
1046
+ return Effect2.succeed([...this.conversations.values()].filter((item) => item.agentId === agentId));
1343
1047
  }
1344
1048
  getWorkspaceEntry(workspaceId, key) {
1345
- return Effect3.succeed(this.workspace.get(`${workspaceId}:${key}`) ?? null);
1049
+ return Effect2.succeed(this.workspace.get(`${workspaceId}:${key}`) ?? null);
1346
1050
  }
1347
1051
  putWorkspaceEntry(entry) {
1348
- return Effect3.sync(() => {
1052
+ return Effect2.sync(() => {
1349
1053
  this.workspace.set(`${entry.workspaceId}:${entry.key}`, Object.freeze({ ...entry }));
1350
1054
  });
1351
1055
  }
1352
1056
  compareAndSetWorkspaceEntry(entry, expectedUpdatedAt) {
1353
- return Effect3.sync(() => {
1057
+ return Effect2.sync(() => {
1354
1058
  const key = `${entry.workspaceId}:${entry.key}`;
1355
1059
  const current = this.workspace.get(key);
1356
1060
  if ((current?.updatedAt ?? null) !== expectedUpdatedAt) return false;
@@ -1362,16 +1066,16 @@ var MemoryFoundryDataAdapter = class {
1362
1066
  });
1363
1067
  }
1364
1068
  listWorkspaceEntries(workspaceId) {
1365
- return Effect3.succeed([...this.workspace.values()].filter((item) => item.workspaceId === workspaceId));
1069
+ return Effect2.succeed([...this.workspace.values()].filter((item) => item.workspaceId === workspaceId));
1366
1070
  }
1367
1071
  getWorkingEnvironmentSnapshot(owner) {
1368
- return Effect3.sync(() => {
1072
+ return Effect2.sync(() => {
1369
1073
  const snapshot = this.workingEnvironments.get(workingEnvironmentOwnerKey(owner));
1370
1074
  return snapshot ? structuredClone(snapshot) : null;
1371
1075
  });
1372
1076
  }
1373
1077
  putWorkingEnvironmentSnapshot(owner, snapshot) {
1374
- return Effect3.sync(() => {
1078
+ return Effect2.sync(() => {
1375
1079
  this.workingEnvironments.set(
1376
1080
  workingEnvironmentOwnerKey(owner),
1377
1081
  structuredClone(snapshot)
@@ -1379,23 +1083,23 @@ var MemoryFoundryDataAdapter = class {
1379
1083
  });
1380
1084
  }
1381
1085
  putInboxItem(item) {
1382
- return Effect3.sync(() => {
1086
+ return Effect2.sync(() => {
1383
1087
  this.inbox.set(item.id, Object.freeze({ ...item }));
1384
1088
  });
1385
1089
  }
1386
1090
  listInboxItems(workspaceId) {
1387
- return Effect3.succeed([...this.inbox.values()].filter((item) => item.workspaceId === workspaceId));
1091
+ return Effect2.succeed([...this.inbox.values()].filter((item) => item.workspaceId === workspaceId));
1388
1092
  }
1389
1093
  putTask(task) {
1390
- return Effect3.sync(() => {
1094
+ return Effect2.sync(() => {
1391
1095
  this.tasks.set(task.id, Object.freeze({ ...task }));
1392
1096
  });
1393
1097
  }
1394
1098
  listTasks(workspaceId) {
1395
- return Effect3.succeed([...this.tasks.values()].filter((item) => item.workspaceId === workspaceId));
1099
+ return Effect2.succeed([...this.tasks.values()].filter((item) => item.workspaceId === workspaceId));
1396
1100
  }
1397
1101
  listEnvironment(scope) {
1398
- return Effect3.succeed(this.environment.filter(
1102
+ return Effect2.succeed(this.environment.filter(
1399
1103
  (item) => item.workspaceId === scope.workspaceId && (item.scope === "workspace" || item.scope === "agent" && item.agentId === scope.agentId || item.scope === "conversation" && item.conversationId === scope.conversationId)
1400
1104
  ));
1401
1105
  }
@@ -1421,6 +1125,7 @@ function createAgentInstance(definitionId, options = {}, provisioningKey) {
1421
1125
  return reconstructAgentInstance({
1422
1126
  id: options.id ?? `agent_${randomUUID()}`,
1423
1127
  definitionId,
1128
+ ...options.durableSubagent ? { durableSubagent: options.durableSubagent } : {},
1424
1129
  workspaceId: options.workspaceId ?? "default",
1425
1130
  ...provisioningKey ? { provisioningKey } : {},
1426
1131
  context: options.context ?? {},
@@ -1450,6 +1155,7 @@ function defineAgentInstance(definition, options = {}) {
1450
1155
  function reconstructAgentInstance(agent) {
1451
1156
  return Object.freeze({
1452
1157
  ...agent,
1158
+ ...agent.durableSubagent ? { durableSubagent: Object.freeze({ ...agent.durableSubagent }) } : {},
1453
1159
  context: freezeInstanceData(structuredClone(agent.context)),
1454
1160
  installations: normalizeAgentInstallations(agent.installations),
1455
1161
  playbooks: Object.freeze(agent.playbooks.map(reconstructPlaybook))
@@ -1550,189 +1256,8 @@ function agentScheduleRevision(schedule) {
1550
1256
 
1551
1257
  // src/core-tools.ts
1552
1258
  import { randomUUID as randomUUID2 } from "node:crypto";
1553
- import { Effect as Effect4, JSONSchema as JSONSchema2, Schema as Schema2 } from "effect";
1259
+ import { Effect as Effect3, JSONSchema as JSONSchema2, Schema as Schema2 } from "effect";
1554
1260
  import { z } from "zod";
1555
-
1556
- // src/core-command-result.ts
1557
- import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
1558
- import { join } from "node:path";
1559
- var FOUNDRY_CORE_COMMAND_DIRECTORY_ENV = "GLOVE_FOUNDRY_CORE_COMMAND_DIRECTORY";
1560
- var REQUEST_SUFFIX = ".request.json";
1561
- var CLAIM_SUFFIX = ".claim";
1562
- var CANCELLATION_SUFFIX = ".cancellation.json";
1563
- var RESULT_SUFFIX = ".result.json";
1564
- var COMMAND_ID = /^command_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1565
- function commandPath(directory, id2, suffix) {
1566
- if (!COMMAND_ID.test(id2)) throw new Error("Invalid Foundry core command id.");
1567
- return join(directory, `${id2}${suffix}`);
1568
- }
1569
- async function readJson(path) {
1570
- try {
1571
- return JSON.parse(await readFile(path, "utf8"));
1572
- } catch (cause) {
1573
- if (cause.code === "ENOENT") return null;
1574
- throw cause;
1575
- }
1576
- }
1577
- function requestRecord(value) {
1578
- if (!value || typeof value !== "object") return null;
1579
- const item = value;
1580
- const valid = typeof item.id === "string" && COMMAND_ID.test(item.id) && typeof item.runId === "string" && item.type === "transmit" && typeof item.requestedAt === "string" && typeof item.expiresAt === "string";
1581
- if (!valid) return null;
1582
- if (item.command !== void 0) {
1583
- const command = item.command;
1584
- if (!command || typeof command !== "object" || command.type !== "transmit" || command.id !== item.id || typeof command.definitionId !== "string" || typeof command.agentId !== "string" || typeof command.conversationId !== "string" || typeof command.workspaceId !== "string" || typeof command.routeId !== "string" || !("payload" in command)) return null;
1585
- }
1586
- return item;
1587
- }
1588
- function resultRecord(value) {
1589
- if (!value || typeof value !== "object") return null;
1590
- const item = value;
1591
- if (typeof item.id !== "string" || !COMMAND_ID.test(item.id) || typeof item.resolvedAt !== "string") return null;
1592
- if (item.status === "success") return item;
1593
- return item.status === "error" && typeof item.error === "string" ? item : null;
1594
- }
1595
- function cancellationRecord(value) {
1596
- if (!value || typeof value !== "object") return null;
1597
- const item = value;
1598
- return typeof item.id === "string" && COMMAND_ID.test(item.id) && (item.status === "cancelled" || item.status === "expired") && typeof item.cancelledAt === "string" ? item : null;
1599
- }
1600
- function jsonValue(value) {
1601
- if (value === void 0) return void 0;
1602
- return JSON.parse(JSON.stringify(value));
1603
- }
1604
- async function createFoundryCoreCommandRequest(directory, input) {
1605
- await mkdir(directory, { recursive: true, mode: 448 });
1606
- const requestedAt = /* @__PURE__ */ new Date();
1607
- const timeoutMs = Math.min(Math.max(input.timeoutMs ?? 3e5, 1e3), 6e5);
1608
- const request = Object.freeze({
1609
- id: input.id,
1610
- runId: input.runId,
1611
- type: input.type,
1612
- requestedAt: requestedAt.toISOString(),
1613
- expiresAt: new Date(requestedAt.getTime() + timeoutMs).toISOString(),
1614
- ...input.command ? { command: jsonValue(input.command) } : {}
1615
- });
1616
- await writeFile(
1617
- commandPath(directory, request.id, REQUEST_SUFFIX),
1618
- `${JSON.stringify(request)}
1619
- `,
1620
- { encoding: "utf8", flag: "wx", mode: 384 }
1621
- );
1622
- return request;
1623
- }
1624
- async function getFoundryCoreCommandRequest(directory, id2) {
1625
- return requestRecord(await readJson(commandPath(directory, id2, REQUEST_SUFFIX)));
1626
- }
1627
- async function claimFoundryCoreCommandRequest(directory, id2) {
1628
- try {
1629
- await writeFile(
1630
- commandPath(directory, id2, CLAIM_SUFFIX),
1631
- `${(/* @__PURE__ */ new Date()).toISOString()}
1632
- `,
1633
- { encoding: "utf8", flag: "wx", mode: 384 }
1634
- );
1635
- return true;
1636
- } catch (cause) {
1637
- if (cause.code === "EEXIST") return false;
1638
- throw cause;
1639
- }
1640
- }
1641
- async function settleFoundryCoreCommandRequest(directory, id2, outcome) {
1642
- const result = outcome.status === "success" ? Object.freeze({
1643
- id: id2,
1644
- status: "success",
1645
- ...outcome.output !== void 0 ? { output: jsonValue(outcome.output) } : {},
1646
- resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
1647
- }) : Object.freeze({
1648
- id: id2,
1649
- status: "error",
1650
- error: outcome.error,
1651
- resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
1652
- });
1653
- try {
1654
- await writeFile(
1655
- commandPath(directory, id2, RESULT_SUFFIX),
1656
- `${JSON.stringify(result)}
1657
- `,
1658
- { encoding: "utf8", flag: "wx", mode: 384 }
1659
- );
1660
- } catch (cause) {
1661
- if (cause.code !== "EEXIST") throw cause;
1662
- }
1663
- }
1664
- async function cancelFoundryCoreCommandRequest(directory, id2, status) {
1665
- const cancellation = Object.freeze({
1666
- id: id2,
1667
- status,
1668
- cancelledAt: (/* @__PURE__ */ new Date()).toISOString()
1669
- });
1670
- try {
1671
- await writeFile(
1672
- commandPath(directory, id2, CANCELLATION_SUFFIX),
1673
- `${JSON.stringify(cancellation)}
1674
- `,
1675
- { encoding: "utf8", flag: "wx", mode: 384 }
1676
- );
1677
- } catch (cause) {
1678
- if (cause.code !== "EEXIST") throw cause;
1679
- }
1680
- }
1681
- async function monitorFoundryCoreCommandRequest(directory, request, delivery, stopped) {
1682
- while (!stopped.aborted && !delivery.signal.aborted) {
1683
- const cancellation = cancellationRecord(
1684
- await readJson(commandPath(directory, request.id, CANCELLATION_SUFFIX))
1685
- );
1686
- if (cancellation) {
1687
- delivery.abort(new Error(
1688
- cancellation.status === "cancelled" ? "Foundry transmission call was cancelled." : "Foundry transmission call timed out."
1689
- ));
1690
- return;
1691
- }
1692
- if (Date.parse(request.expiresAt) <= Date.now()) {
1693
- delivery.abort(new Error("Foundry transmission call timed out."));
1694
- return;
1695
- }
1696
- await new Promise((resolveWait) => setTimeout(resolveWait, 50));
1697
- }
1698
- }
1699
- async function waitForFoundryCoreCommandResult(directory, request, signal, options = {}) {
1700
- for (; ; ) {
1701
- const result = resultRecord(
1702
- await readJson(commandPath(directory, request.id, RESULT_SUFFIX))
1703
- );
1704
- if (result) {
1705
- if (options.cleanup) await cleanupFoundryCoreCommandRequest(directory, request.id);
1706
- if (result.status === "error") throw new Error(result.error);
1707
- return result.output;
1708
- }
1709
- if (signal.aborted) {
1710
- await cancelFoundryCoreCommandRequest(directory, request.id, "cancelled");
1711
- throw new Error("Foundry transmission call was cancelled.");
1712
- }
1713
- if (Date.parse(request.expiresAt) <= Date.now()) {
1714
- await cancelFoundryCoreCommandRequest(directory, request.id, "expired");
1715
- throw new Error("Foundry transmission call timed out.");
1716
- }
1717
- await new Promise((resolveWait) => setTimeout(resolveWait, 50));
1718
- }
1719
- }
1720
- async function cleanupFoundryCoreCommandRequest(directory, id2) {
1721
- await Promise.all([
1722
- REQUEST_SUFFIX,
1723
- CLAIM_SUFFIX,
1724
- RESULT_SUFFIX,
1725
- CANCELLATION_SUFFIX
1726
- ].map(async (suffix) => {
1727
- try {
1728
- await unlink(commandPath(directory, id2, suffix));
1729
- } catch (cause) {
1730
- if (cause.code !== "ENOENT") throw cause;
1731
- }
1732
- }));
1733
- }
1734
-
1735
- // src/core-tools.ts
1736
1261
  var FOUNDRY_CORE_COMMAND_EVENT = "foundry.core.command";
1737
1262
  function commandId() {
1738
1263
  return `command_${randomUUID2()}`;
@@ -1795,6 +1320,7 @@ function createInstalledApplicationTransmissionTools(context, applications, inst
1795
1320
  for (const application of applications) {
1796
1321
  if (!installed.has(application.id)) continue;
1797
1322
  for (const transmission of application.transmissions ?? []) {
1323
+ if (application.restrictions && !application.restrictions.transmissions?.includes(transmission.id)) continue;
1798
1324
  if (!transmission.outbound) continue;
1799
1325
  const routeIds = [...new Set(
1800
1326
  playbooks.filter(
@@ -1910,7 +1436,7 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
1910
1436
  };
1911
1437
  const scheduleView = async () => {
1912
1438
  const records = new Map(
1913
- [...context.activations, ...await Effect4.runPromise(context.data.listActivations(context.workspaceId))].filter((item) => item.kind === "scheduled" && item.agentId === context.agentId).map((item) => [item.id, item])
1439
+ [...context.activations, ...await Effect3.runPromise(context.data.listActivations(context.workspaceId))].filter((item) => item.kind === "scheduled" && item.agentId === context.agentId).map((item) => [item.id, item])
1914
1440
  );
1915
1441
  const now = (/* @__PURE__ */ new Date()).toISOString();
1916
1442
  for (const desired of desiredSchedules) {
@@ -2228,7 +1754,7 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2228
1754
  description: "List the conversations owned by this runtime agent instance.",
2229
1755
  inputSchema: z.object({}),
2230
1756
  async do() {
2231
- return { status: "success", data: await Effect4.runPromise(context.data.listConversations(context.agentId)) };
1757
+ return { status: "success", data: await Effect3.runPromise(context.data.listConversations(context.agentId)) };
2232
1758
  }
2233
1759
  },
2234
1760
  {
@@ -2241,12 +1767,12 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2241
1767
  ]),
2242
1768
  async do(input) {
2243
1769
  if (input.action === "get") {
2244
- return { status: "success", data: await Effect4.runPromise(context.data.getWorkspaceEntry(context.workspaceId, input.key)) };
1770
+ return { status: "success", data: await Effect3.runPromise(context.data.getWorkspaceEntry(context.workspaceId, input.key)) };
2245
1771
  }
2246
1772
  if (input.action === "list") {
2247
- return { status: "success", data: await Effect4.runPromise(context.data.listWorkspaceEntries(context.workspaceId)) };
1773
+ return { status: "success", data: await Effect3.runPromise(context.data.listWorkspaceEntries(context.workspaceId)) };
2248
1774
  }
2249
- await Effect4.runPromise(context.data.putWorkspaceEntry({
1775
+ await Effect3.runPromise(context.data.putWorkspaceEntry({
2250
1776
  workspaceId: context.workspaceId,
2251
1777
  key: input.key,
2252
1778
  value: input.value,
@@ -2275,13 +1801,13 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2275
1801
  ]),
2276
1802
  async do(input) {
2277
1803
  if (input.action === "list") {
2278
- return { status: "success", data: await Effect4.runPromise(context.data.listInboxItems(context.workspaceId)) };
1804
+ return { status: "success", data: await Effect3.runPromise(context.data.listInboxItems(context.workspaceId)) };
2279
1805
  }
2280
1806
  if (input.action === "update") {
2281
- const current = (await Effect4.runPromise(context.data.listInboxItems(context.workspaceId))).find((item3) => item3.id === input.itemId);
1807
+ const current = (await Effect3.runPromise(context.data.listInboxItems(context.workspaceId))).find((item3) => item3.id === input.itemId);
2282
1808
  if (!current) return { status: "error", data: null, error: `Shared inbox item "${input.itemId}" was not found.` };
2283
1809
  const item2 = { ...current, status: input.status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
2284
- await Effect4.runPromise(context.data.putInboxItem(item2));
1810
+ await Effect3.runPromise(context.data.putInboxItem(item2));
2285
1811
  return { status: "success", data: item2 };
2286
1812
  }
2287
1813
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -2296,7 +1822,7 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2296
1822
  createdAt: now,
2297
1823
  updatedAt: now
2298
1824
  };
2299
- await Effect4.runPromise(context.data.putInboxItem(item));
1825
+ await Effect3.runPromise(context.data.putInboxItem(item));
2300
1826
  return { status: "success", data: item };
2301
1827
  }
2302
1828
  },
@@ -2314,13 +1840,13 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2314
1840
  ]),
2315
1841
  async do(input) {
2316
1842
  if (input.action === "list") {
2317
- return { status: "success", data: await Effect4.runPromise(context.data.listTasks(context.workspaceId)) };
1843
+ return { status: "success", data: await Effect3.runPromise(context.data.listTasks(context.workspaceId)) };
2318
1844
  }
2319
1845
  if (input.action === "update") {
2320
- const current = (await Effect4.runPromise(context.data.listTasks(context.workspaceId))).find((task3) => task3.id === input.taskId);
1846
+ const current = (await Effect3.runPromise(context.data.listTasks(context.workspaceId))).find((task3) => task3.id === input.taskId);
2321
1847
  if (!current) return { status: "error", data: null, error: `Task "${input.taskId}" was not found.` };
2322
1848
  const task2 = { ...current, status: input.status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
2323
- await Effect4.runPromise(context.data.putTask(task2));
1849
+ await Effect3.runPromise(context.data.putTask(task2));
2324
1850
  return { status: "success", data: task2 };
2325
1851
  }
2326
1852
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -2335,7 +1861,7 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2335
1861
  createdAt: now,
2336
1862
  updatedAt: now
2337
1863
  };
2338
- await Effect4.runPromise(context.data.putTask(task));
1864
+ await Effect3.runPromise(context.data.putTask(task));
2339
1865
  return { status: "success", data: task };
2340
1866
  }
2341
1867
  },
@@ -2346,7 +1872,7 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2346
1872
  async do() {
2347
1873
  return {
2348
1874
  status: "success",
2349
- data: await Effect4.runPromise(context.data.listEnvironment({
1875
+ data: await Effect3.runPromise(context.data.listEnvironment({
2350
1876
  workspaceId: context.workspaceId,
2351
1877
  agentId: context.agentId,
2352
1878
  conversationId: context.conversationId
@@ -2359,19 +1885,19 @@ function createFoundryCoreTools(context, desiredSchedules = []) {
2359
1885
 
2360
1886
  // src/approval.ts
2361
1887
  import { randomUUID as randomUUID3 } from "node:crypto";
2362
- import { mkdir as mkdir2, readFile as readFile2, readdir as readdir2, writeFile as writeFile2 } from "node:fs/promises";
2363
- import { join as join2 } from "node:path";
1888
+ import { mkdir, readFile, readdir as readdir2, writeFile } from "node:fs/promises";
1889
+ import { join } from "node:path";
2364
1890
  import {
2365
1891
  Displaymanager,
2366
1892
  permissionKey
2367
1893
  } from "glove-core";
2368
1894
  var FOUNDRY_APPROVAL_DIRECTORY_ENV = "GLOVE_FOUNDRY_APPROVAL_DIRECTORY";
2369
- var REQUEST_SUFFIX2 = ".request.json";
1895
+ var REQUEST_SUFFIX = ".request.json";
2370
1896
  var RESOLUTION_SUFFIX = ".resolution.json";
2371
1897
  var APPROVAL_ID = /^approval_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
2372
1898
  function approvalPath(directory, id2, suffix) {
2373
1899
  if (!APPROVAL_ID.test(id2)) throw new Error("Invalid Foundry approval id.");
2374
- return join2(directory, `${id2}${suffix}`);
1900
+ return join(directory, `${id2}${suffix}`);
2375
1901
  }
2376
1902
  function serializable(value) {
2377
1903
  try {
@@ -2380,15 +1906,15 @@ function serializable(value) {
2380
1906
  return String(value);
2381
1907
  }
2382
1908
  }
2383
- async function readJson2(path) {
1909
+ async function readJson(path) {
2384
1910
  try {
2385
- return JSON.parse(await readFile2(path, "utf8"));
1911
+ return JSON.parse(await readFile(path, "utf8"));
2386
1912
  } catch (cause) {
2387
1913
  if (cause.code === "ENOENT") return null;
2388
1914
  throw cause;
2389
1915
  }
2390
1916
  }
2391
- function requestRecord2(value) {
1917
+ function requestRecord(value) {
2392
1918
  if (!value || typeof value !== "object") return null;
2393
1919
  const item = value;
2394
1920
  return typeof item.id === "string" && APPROVAL_ID.test(item.id) && typeof item.runId === "string" && typeof item.definitionId === "string" && typeof item.agentId === "string" && typeof item.conversationId === "string" && typeof item.workspaceId === "string" && typeof item.toolName === "string" && typeof item.requestedAt === "string" && typeof item.expiresAt === "string" ? item : null;
@@ -2401,7 +1927,7 @@ function resolutionRecord(value) {
2401
1927
  async function writeResolution(directory, id2, status, rejectExisting = false) {
2402
1928
  const resolution = Object.freeze({ id: id2, status, resolvedAt: (/* @__PURE__ */ new Date()).toISOString() });
2403
1929
  try {
2404
- await writeFile2(
1930
+ await writeFile(
2405
1931
  approvalPath(directory, id2, RESOLUTION_SUFFIX),
2406
1932
  `${JSON.stringify(resolution)}
2407
1933
  `,
@@ -2411,7 +1937,7 @@ async function writeResolution(directory, id2, status, rejectExisting = false) {
2411
1937
  } catch (cause) {
2412
1938
  if (cause.code !== "EEXIST") throw cause;
2413
1939
  const existing = resolutionRecord(
2414
- await readJson2(approvalPath(directory, id2, RESOLUTION_SUFFIX))
1940
+ await readJson(approvalPath(directory, id2, RESOLUTION_SUFFIX))
2415
1941
  );
2416
1942
  if (!existing) throw new Error(`Foundry approval "${id2}" has an invalid resolution.`);
2417
1943
  if (rejectExisting) {
@@ -2421,7 +1947,7 @@ async function writeResolution(directory, id2, status, rejectExisting = false) {
2421
1947
  }
2422
1948
  }
2423
1949
  async function createFoundryApproval(directory, input) {
2424
- await mkdir2(directory, { recursive: true, mode: 448 });
1950
+ await mkdir(directory, { recursive: true, mode: 448 });
2425
1951
  const requestedAt = /* @__PURE__ */ new Date();
2426
1952
  const timeoutMs = Math.min(Math.max(input.timeoutMs ?? 3e5, 1e3), 6e5);
2427
1953
  const request = Object.freeze({
@@ -2436,8 +1962,8 @@ async function createFoundryApproval(directory, input) {
2436
1962
  requestedAt: requestedAt.toISOString(),
2437
1963
  expiresAt: new Date(requestedAt.getTime() + timeoutMs).toISOString()
2438
1964
  });
2439
- await writeFile2(
2440
- approvalPath(directory, request.id, REQUEST_SUFFIX2),
1965
+ await writeFile(
1966
+ approvalPath(directory, request.id, REQUEST_SUFFIX),
2441
1967
  `${JSON.stringify(request)}
2442
1968
  `,
2443
1969
  { encoding: "utf8", flag: "wx", mode: 384 }
@@ -2453,11 +1979,11 @@ async function listFoundryApprovals(directory, filter = {}) {
2453
1979
  throw cause;
2454
1980
  }
2455
1981
  const approvals = [];
2456
- for (const name of names.filter((item) => item.endsWith(REQUEST_SUFFIX2)).sort()) {
2457
- const request = requestRecord2(await readJson2(join2(directory, name)));
1982
+ for (const name of names.filter((item) => item.endsWith(REQUEST_SUFFIX)).sort()) {
1983
+ const request = requestRecord(await readJson(join(directory, name)));
2458
1984
  if (!request) continue;
2459
1985
  const resolution = resolutionRecord(
2460
- await readJson2(approvalPath(directory, request.id, RESOLUTION_SUFFIX))
1986
+ await readJson(approvalPath(directory, request.id, RESOLUTION_SUFFIX))
2461
1987
  );
2462
1988
  const status = resolution?.status ?? (Date.parse(request.expiresAt) <= Date.now() ? "expired" : "pending");
2463
1989
  const approval = Object.freeze({
@@ -2472,7 +1998,7 @@ async function listFoundryApprovals(directory, filter = {}) {
2472
1998
  return approvals.sort((a, b) => a.requestedAt.localeCompare(b.requestedAt));
2473
1999
  }
2474
2000
  async function resolveFoundryApproval(directory, id2, decision) {
2475
- const request = requestRecord2(await readJson2(approvalPath(directory, id2, REQUEST_SUFFIX2)));
2001
+ const request = requestRecord(await readJson(approvalPath(directory, id2, REQUEST_SUFFIX)));
2476
2002
  if (!request) throw new Error(`Foundry approval "${id2}" was not found.`);
2477
2003
  const current = (await listFoundryApprovals(directory)).find((item) => item.id === id2);
2478
2004
  if (!current || current.status !== "pending") {
@@ -2489,7 +2015,7 @@ async function resolveFoundryApproval(directory, id2, decision) {
2489
2015
  async function waitForResolution(directory, approval, signal) {
2490
2016
  for (; ; ) {
2491
2017
  const resolved = resolutionRecord(
2492
- await readJson2(approvalPath(directory, approval.id, RESOLUTION_SUFFIX))
2018
+ await readJson(approvalPath(directory, approval.id, RESOLUTION_SUFFIX))
2493
2019
  );
2494
2020
  if (resolved) return resolved;
2495
2021
  if (signal.aborted) return writeResolution(directory, approval.id, "cancelled");
@@ -2573,23 +2099,6 @@ export {
2573
2099
  isFoundryApplication,
2574
2100
  defineApplication,
2575
2101
  EMPTY_FOUNDRY_APPLICATION,
2576
- FOUNDRY_SHARED_TOOL_BRAND,
2577
- FOUNDRY_AGENT_APPLICATION_BRAND,
2578
- FOUNDRY_MCP_BRAND,
2579
- FOUNDRY_MEMORY_BRAND,
2580
- install,
2581
- installationKey,
2582
- defineSharedTool,
2583
- defineAgentApplication,
2584
- defineApp,
2585
- defineMcp,
2586
- defineMemory,
2587
- EMPTY_CAPABILITY_REGISTRY,
2588
- isInboxCapableStore,
2589
- configureMemory,
2590
- mountAgentDefinitionMemory,
2591
- installRegistry,
2592
- isFoundryCapability,
2593
2102
  composeAgent,
2594
2103
  EMPTY_AGENT_COMPOSITION,
2595
2104
  FOUNDRY_CONNECTION_BRAND,
@@ -2633,11 +2142,6 @@ export {
2633
2142
  isFoundrySchedule,
2634
2143
  agentScheduleActivationId,
2635
2144
  agentScheduleRevision,
2636
- FOUNDRY_CORE_COMMAND_DIRECTORY_ENV,
2637
- getFoundryCoreCommandRequest,
2638
- claimFoundryCoreCommandRequest,
2639
- settleFoundryCoreCommandRequest,
2640
- monitorFoundryCoreCommandRequest,
2641
2145
  FOUNDRY_CORE_COMMAND_EVENT,
2642
2146
  installedApplicationTransmissionToolName,
2643
2147
  createInstalledApplicationTransmissionTools,