@dexto/agent-management 1.16.5 → 1.17.0-beta.5

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 (103) hide show
  1. package/dist/auth/dexto-accounts.cjs +277 -0
  2. package/dist/auth/dexto-accounts.d.ts +144 -0
  3. package/dist/auth/dexto-accounts.d.ts.map +1 -0
  4. package/dist/auth/dexto-accounts.js +230 -0
  5. package/dist/auth/dexto-cloud.cjs +51 -0
  6. package/dist/auth/dexto-cloud.d.ts +9 -0
  7. package/dist/auth/dexto-cloud.d.ts.map +1 -0
  8. package/dist/auth/dexto-cloud.js +27 -0
  9. package/dist/auth/dexto-gateway.cjs +162 -0
  10. package/dist/auth/dexto-gateway.d.ts +55 -0
  11. package/dist/auth/dexto-gateway.d.ts.map +1 -0
  12. package/dist/auth/dexto-gateway.js +133 -0
  13. package/dist/auth/dexto-mcp.cjs +77 -0
  14. package/dist/auth/dexto-mcp.d.ts +23 -0
  15. package/dist/auth/dexto-mcp.d.ts.map +1 -0
  16. package/dist/auth/dexto-mcp.js +49 -0
  17. package/dist/auth/dexto-sign-in.cjs +345 -0
  18. package/dist/auth/dexto-sign-in.d.ts +86 -0
  19. package/dist/auth/dexto-sign-in.d.ts.map +1 -0
  20. package/dist/auth/dexto-sign-in.js +314 -0
  21. package/dist/auth/index.cjs +25 -0
  22. package/dist/auth/index.d.ts +6 -0
  23. package/dist/auth/index.d.ts.map +1 -1
  24. package/dist/auth/index.js +10 -0
  25. package/dist/auth/model-auth-handlers.cjs +3 -1
  26. package/dist/auth/model-auth-handlers.d.ts +6 -1
  27. package/dist/auth/model-auth-handlers.d.ts.map +1 -1
  28. package/dist/auth/model-auth-handlers.js +6 -1
  29. package/dist/config/errors.cjs +6 -6
  30. package/dist/config/errors.js +6 -6
  31. package/dist/images/image-store.cjs +2 -4
  32. package/dist/images/image-store.d.ts.map +1 -1
  33. package/dist/images/image-store.js +2 -4
  34. package/dist/index.cjs +40 -29
  35. package/dist/index.d.ts +3 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +9 -6
  38. package/dist/installation.cjs +2 -2
  39. package/dist/installation.js +2 -2
  40. package/dist/plugins/discover-skills.cjs +5 -2
  41. package/dist/plugins/discover-skills.d.ts +6 -2
  42. package/dist/plugins/discover-skills.d.ts.map +1 -1
  43. package/dist/plugins/discover-skills.js +5 -2
  44. package/dist/plugins/errors.cjs +2 -2
  45. package/dist/plugins/errors.js +2 -2
  46. package/dist/plugins/install-plugin.cjs +2 -0
  47. package/dist/plugins/install-plugin.d.ts.map +1 -1
  48. package/dist/plugins/install-plugin.js +2 -0
  49. package/dist/plugins/local-skills.cjs +2 -0
  50. package/dist/plugins/local-skills.d.ts.map +1 -1
  51. package/dist/plugins/local-skills.js +2 -0
  52. package/dist/plugins/marketplace/error-codes.cjs +1 -0
  53. package/dist/plugins/marketplace/error-codes.d.ts +1 -0
  54. package/dist/plugins/marketplace/error-codes.d.ts.map +1 -1
  55. package/dist/plugins/marketplace/error-codes.js +1 -0
  56. package/dist/plugins/marketplace/errors.cjs +14 -4
  57. package/dist/plugins/marketplace/errors.d.ts +3 -0
  58. package/dist/plugins/marketplace/errors.d.ts.map +1 -1
  59. package/dist/plugins/marketplace/errors.js +14 -4
  60. package/dist/plugins/marketplace/install-from-marketplace.cjs +5 -0
  61. package/dist/plugins/marketplace/install-from-marketplace.d.ts.map +1 -1
  62. package/dist/plugins/marketplace/install-from-marketplace.js +7 -1
  63. package/dist/plugins/marketplace/operations.cjs +30 -6
  64. package/dist/plugins/marketplace/operations.d.ts +6 -0
  65. package/dist/plugins/marketplace/operations.d.ts.map +1 -1
  66. package/dist/plugins/marketplace/operations.js +31 -8
  67. package/dist/plugins/marketplace/schemas.cjs +2 -1
  68. package/dist/plugins/marketplace/schemas.d.ts.map +1 -1
  69. package/dist/plugins/marketplace/schemas.js +2 -1
  70. package/dist/plugins/schemas.cjs +9 -3
  71. package/dist/plugins/schemas.d.ts +5 -0
  72. package/dist/plugins/schemas.d.ts.map +1 -1
  73. package/dist/plugins/schemas.js +7 -2
  74. package/dist/preferences/errors.cjs +1 -1
  75. package/dist/preferences/errors.js +1 -1
  76. package/dist/registry/registry.cjs +9 -6
  77. package/dist/registry/registry.d.ts +0 -8
  78. package/dist/registry/registry.d.ts.map +1 -1
  79. package/dist/registry/registry.js +9 -6
  80. package/dist/resolver.cjs +1 -1
  81. package/dist/resolver.js +1 -1
  82. package/dist/tool-factories/agent-spawner/factory.cjs +1 -218
  83. package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -1
  84. package/dist/tool-factories/agent-spawner/factory.js +1 -228
  85. package/dist/tool-factories/creator-tools/factory.cjs +16 -1
  86. package/dist/tool-factories/creator-tools/factory.d.ts.map +1 -1
  87. package/dist/tool-factories/creator-tools/factory.js +16 -1
  88. package/dist/utils/api-key-store.cjs +3 -2
  89. package/dist/utils/api-key-store.d.ts.map +1 -1
  90. package/dist/utils/api-key-store.js +3 -2
  91. package/dist/utils/dexto-auth.cjs +3 -58
  92. package/dist/utils/dexto-auth.d.ts +4 -18
  93. package/dist/utils/dexto-auth.d.ts.map +1 -1
  94. package/dist/utils/dexto-auth.js +3 -57
  95. package/dist/utils/env-file.cjs +24 -2
  96. package/dist/utils/env-file.d.ts +3 -2
  97. package/dist/utils/env-file.d.ts.map +1 -1
  98. package/dist/utils/env-file.js +24 -2
  99. package/dist/utils/path.cjs +75 -11
  100. package/dist/utils/path.d.ts +14 -1
  101. package/dist/utils/path.d.ts.map +1 -1
  102. package/dist/utils/path.js +73 -10
  103. package/package.json +5 -6
@@ -16,6 +16,9 @@ import {
16
16
  } from "./user-registry.js";
17
17
  import { loadGlobalPreferences } from "../preferences/loader.js";
18
18
  let cachedRegistry = null;
19
+ function isOutsideAgentsDir(relativePath) {
20
+ return relativePath === "" || relativePath.startsWith("..") || path.isAbsolute(relativePath);
21
+ }
19
22
  class LocalAgentRegistry {
20
23
  _registry = null;
21
24
  /**
@@ -149,7 +152,7 @@ class LocalAgentRegistry {
149
152
  * @param agentId ID of the agent to install
150
153
  */
151
154
  async installAgent(agentId) {
152
- logger.info(`Installing agent: ${agentId}`);
155
+ logger.debug(`Installing agent: ${agentId}`);
153
156
  const registry = this.getRegistry();
154
157
  const agentData = registry.agents[agentId];
155
158
  if (!agentData) {
@@ -159,7 +162,7 @@ class LocalAgentRegistry {
159
162
  const globalAgentsDir = getDextoGlobalPath("agents");
160
163
  const targetDir = path.resolve(globalAgentsDir, agentId);
161
164
  const relTarget = path.relative(globalAgentsDir, targetDir);
162
- if (relTarget.startsWith("..") || path.isAbsolute(relTarget)) {
165
+ if (isOutsideAgentsDir(relTarget)) {
163
166
  throw RegistryError.installationFailed(
164
167
  agentId,
165
168
  "invalid agentId: path traversal detected"
@@ -185,7 +188,7 @@ class LocalAgentRegistry {
185
188
  throw RegistryError.installationValidationFailed(agentId, mainConfigPath);
186
189
  }
187
190
  await fs.rename(tempDir, targetDir);
188
- logger.info(`\u2713 Installed agent '${agentId}' to ${targetDir}`);
191
+ logger.debug(`\u2713 Installed agent '${agentId}' to ${targetDir}`);
189
192
  return this.resolveMainConfig(targetDir, agentId);
190
193
  } catch (error) {
191
194
  try {
@@ -219,7 +222,7 @@ class LocalAgentRegistry {
219
222
  const globalAgentsDir = getDextoGlobalPath("agents");
220
223
  const targetDir = path.resolve(globalAgentsDir, agentId);
221
224
  const relTarget = path.relative(globalAgentsDir, targetDir);
222
- if (relTarget.startsWith("..") || path.isAbsolute(relTarget)) {
225
+ if (isOutsideAgentsDir(relTarget)) {
223
226
  throw RegistryError.installationFailed(
224
227
  agentId,
225
228
  "invalid agentId: path traversal detected"
@@ -324,7 +327,7 @@ class LocalAgentRegistry {
324
327
  logger.debug(`Agent '${agentId}' not found in installed path: ${installedPath}`);
325
328
  if (this.hasAgent(agentId)) {
326
329
  if (autoInstall) {
327
- logger.info(`Installing agent '${agentId}' from registry...`);
330
+ logger.debug(`Installing agent '${agentId}' from registry...`);
328
331
  return await this.installAgent(agentId);
329
332
  } else {
330
333
  const registry2 = this.getRegistry();
@@ -376,7 +379,7 @@ class LocalAgentRegistry {
376
379
  const globalAgentsDir = getDextoGlobalPath("agents");
377
380
  const agentDir = path.resolve(globalAgentsDir, agentId);
378
381
  const relAgent = path.relative(globalAgentsDir, agentDir);
379
- if (relAgent.startsWith("..") || path.isAbsolute(relAgent)) {
382
+ if (isOutsideAgentsDir(relAgent)) {
380
383
  throw RegistryError.uninstallationFailed(
381
384
  agentId,
382
385
  "invalid agentId: path traversal detected"
package/dist/resolver.cjs CHANGED
@@ -76,7 +76,7 @@ async function resolveAgentByName(agentId, autoInstall) {
76
76
  }
77
77
  if (autoInstall) {
78
78
  try {
79
- import_core.logger.info(`Auto-installing agent '${agentId}' from bundled registry`);
79
+ import_core.logger.debug(`Auto-installing agent '${agentId}' from bundled registry`);
80
80
  const configPath = await (0, import_installation.installBundledAgent)(agentId);
81
81
  return configPath;
82
82
  } catch (error) {
package/dist/resolver.js CHANGED
@@ -49,7 +49,7 @@ async function resolveAgentByName(agentId, autoInstall) {
49
49
  }
50
50
  if (autoInstall) {
51
51
  try {
52
- logger.info(`Auto-installing agent '${agentId}' from bundled registry`);
52
+ logger.debug(`Auto-installing agent '${agentId}' from bundled registry`);
53
53
  const configPath = await installBundledAgent(agentId);
54
54
  return configPath;
55
55
  } catch (error) {
@@ -23,7 +23,6 @@ __export(factory_exports, {
23
23
  module.exports = __toCommonJS(factory_exports);
24
24
  var import_core = require("@dexto/core");
25
25
  var import_core2 = require("@dexto/core");
26
- var import_orchestration = require("@dexto/orchestration");
27
26
  var import_schemas = require("./schemas.js");
28
27
  var import_runtime = require("./runtime.js");
29
28
  var import_spawn_agent_tool = require("./spawn-agent-tool.js");
@@ -69,152 +68,10 @@ const agentSpawnerToolsFactory = {
69
68
  state.runtime.cleanup().catch(() => void 0);
70
69
  }
71
70
  state = void 0;
72
- const signalBus = new import_orchestration.SignalBus();
73
- const taskRegistry = new import_orchestration.TaskRegistry(signalBus);
74
- const conditionEngine = new import_orchestration.ConditionEngine(taskRegistry, signalBus, logger);
75
71
  const spawnerRuntime = new import_runtime.AgentSpawnerRuntime(agent, config, logger);
76
72
  updateWorkspaceRootHint(spawnerRuntime, context);
77
73
  attachTaskForker({ toolServices, taskForker: spawnerRuntime, logger });
78
- const taskSessions = /* @__PURE__ */ new Map();
79
- const taskHostRuntimeContexts = /* @__PURE__ */ new Map();
80
- const emitTasksUpdate = (sessionId) => {
81
- const tasks = taskRegistry.list({
82
- status: ["running", "completed", "failed", "cancelled"]
83
- });
84
- const scopedTasks = sessionId ? tasks.filter((task) => taskSessions.get(task.taskId) === sessionId) : tasks;
85
- const runningCount = scopedTasks.filter((task) => task.status === "running").length;
86
- agent.emit("service:event", {
87
- service: "orchestration",
88
- event: "tasks-updated",
89
- sessionId: sessionId ?? "",
90
- data: {
91
- runningCount,
92
- tasks: scopedTasks.map((task) => ({
93
- taskId: task.taskId,
94
- status: task.status,
95
- ...task.description !== void 0 && {
96
- description: task.description
97
- }
98
- }))
99
- }
100
- });
101
- };
102
- const triggerBackgroundCompletion = (taskId, sessionId, hostRuntime) => {
103
- if (!sessionId) {
104
- return;
105
- }
106
- agent.emit("tool:background-completed", {
107
- toolCallId: taskId,
108
- sessionId,
109
- ...hostRuntime !== void 0 && { hostRuntime }
110
- });
111
- const taskInfo = taskRegistry.getInfo(taskId);
112
- const resultText = (() => {
113
- if (taskInfo?.status === "failed") {
114
- return taskInfo.error ?? "Unknown error.";
115
- }
116
- if (taskInfo?.result !== void 0) {
117
- if (typeof taskInfo.result === "string") {
118
- return taskInfo.result;
119
- }
120
- try {
121
- return JSON.stringify(taskInfo.result, null, 2);
122
- } catch {
123
- return String(taskInfo.result ?? "<unserializable result>");
124
- }
125
- }
126
- return "No result available.";
127
- })();
128
- const sanitizeCdata = (value) => value.replace(/\]\]>/g, "]]]]><![CDATA[>");
129
- const safeDescription = taskInfo?.description ? sanitizeCdata(taskInfo.description) : null;
130
- const safeResultText = sanitizeCdata(resultText);
131
- const descriptionTag = safeDescription ? ` <description><![CDATA[${safeDescription}]]></description>
132
- ` : "";
133
- const statusTag = taskInfo?.status ? ` <status>${taskInfo.status}</status>
134
- ` : "";
135
- const content = [
136
- {
137
- type: "text",
138
- text: `<background-task-completion>
139
- <origin>task</origin>
140
- <note>The following response was reported by the background task (not user input).</note>
141
- <taskId>${taskId}</taskId>
142
- ` + statusTag + descriptionTag + ` <result><![CDATA[${safeResultText}]]></result>
143
- </background-task-completion>`
144
- }
145
- ];
146
- agent.isSessionBusy(sessionId).then((isBusy) => {
147
- if (isBusy) {
148
- agent.steer(sessionId, {
149
- content,
150
- kind: "background"
151
- }).catch(() => void 0);
152
- } else {
153
- agent.emit("run:invoke", {
154
- sessionId,
155
- content,
156
- source: "external",
157
- metadata: { taskId },
158
- ...hostRuntime !== void 0 && { hostRuntime }
159
- });
160
- agent.generate(content, sessionId, {
161
- ...hostRuntime !== void 0 && {
162
- executionContext: hostRuntime
163
- }
164
- }).catch(() => void 0);
165
- }
166
- }).catch(() => {
167
- });
168
- };
169
- const handleBackground = (event) => {
170
- const taskId = event.toolCallId;
171
- if (taskRegistry.has(taskId)) {
172
- return;
173
- }
174
- if (event.sessionId) {
175
- taskSessions.set(taskId, event.sessionId);
176
- }
177
- if (event.hostRuntime !== void 0) {
178
- taskHostRuntimeContexts.set(taskId, event.hostRuntime);
179
- }
180
- try {
181
- taskRegistry.register(
182
- {
183
- type: "generic",
184
- taskId,
185
- description: event.description ?? `Tool ${event.toolName}`,
186
- promise: event.promise
187
- },
188
- {
189
- ...event.timeoutMs !== void 0 && { timeout: event.timeoutMs },
190
- ...event.notifyOnComplete !== void 0 && {
191
- notify: event.notifyOnComplete
192
- }
193
- }
194
- );
195
- } catch (error) {
196
- taskSessions.delete(taskId);
197
- taskHostRuntimeContexts.delete(taskId);
198
- event.promise.catch(() => void 0);
199
- logger.warn(
200
- `Failed to register background task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
201
- { color: "yellow" }
202
- );
203
- return;
204
- }
205
- emitTasksUpdate(event.sessionId);
206
- event.promise.finally(() => {
207
- taskSessions.delete(taskId);
208
- const hostRuntime = taskHostRuntimeContexts.get(taskId);
209
- taskHostRuntimeContexts.delete(taskId);
210
- emitTasksUpdate(event.sessionId);
211
- triggerBackgroundCompletion(taskId, event.sessionId, hostRuntime);
212
- });
213
- };
214
74
  const abortController = new AbortController();
215
- agent.on("tool:background", handleBackground, {
216
- signal: abortController.signal
217
- });
218
75
  agent.on(
219
76
  "agent:stopped",
220
77
  () => {
@@ -224,14 +81,8 @@ const agentSpawnerToolsFactory = {
224
81
  { signal: abortController.signal }
225
82
  );
226
83
  const spawnAgentTool = (0, import_spawn_agent_tool.createSpawnAgentTool)(spawnerRuntime);
227
- const waitForTool = (0, import_orchestration.createWaitForTool)(conditionEngine);
228
- const checkTaskTool = (0, import_orchestration.createCheckTaskTool)(taskRegistry);
229
- const listTasksTool = (0, import_orchestration.createListTasksTool)(taskRegistry);
230
84
  const tools = {
231
- spawnAgent: spawnAgentTool,
232
- waitFor: waitForTool,
233
- checkTask: checkTaskTool,
234
- listTasks: listTasksTool
85
+ spawnAgent: spawnAgentTool
235
86
  };
236
87
  state = {
237
88
  agent,
@@ -276,74 +127,6 @@ const agentSpawnerToolsFactory = {
276
127
  return await previewFn(input, context);
277
128
  }
278
129
  }
279
- },
280
- {
281
- id: "wait_for",
282
- description: "Wait for background task(s) to complete.",
283
- inputSchema: import_orchestration.WaitForInputSchema,
284
- execute: (input, context) => ensureToolsInitialized(context).waitFor.execute(input, context),
285
- presentation: {
286
- activity: import_core.TOOL_ACTIVITY.wait,
287
- describeHeader: (input) => {
288
- const argsText = input.taskId ? (0, import_core.truncateForHeader)(input.taskId, 80) : input.taskIds && input.taskIds.length > 0 ? (0, import_core.truncateForHeader)(`${input.taskIds.length} tasks`, 80) : void 0;
289
- return (0, import_core.createLocalToolCallHeader)({
290
- title: "Wait",
291
- ...argsText ? { argsText } : {}
292
- });
293
- },
294
- preview: async (input, context) => {
295
- const tool = ensureToolsInitialized(context).waitFor;
296
- const previewFn = tool.presentation?.preview;
297
- if (!previewFn) {
298
- return null;
299
- }
300
- return await previewFn(input, context);
301
- }
302
- }
303
- },
304
- {
305
- id: "check_task",
306
- description: "Check the status of a background task.",
307
- inputSchema: import_orchestration.CheckTaskInputSchema,
308
- execute: (input, context) => ensureToolsInitialized(context).checkTask.execute(input, context),
309
- presentation: {
310
- activity: import_core.TOOL_ACTIVITY.checkTask,
311
- describeHeader: (input) => {
312
- const argsText = (0, import_core.truncateForHeader)(input.taskId, 80);
313
- return (0, import_core.createLocalToolCallHeader)({
314
- title: "Check Task",
315
- ...argsText ? { argsText } : {}
316
- });
317
- },
318
- preview: async (input, context) => {
319
- const tool = ensureToolsInitialized(context).checkTask;
320
- const previewFn = tool.presentation?.preview;
321
- if (!previewFn) {
322
- return null;
323
- }
324
- return await previewFn(input, context);
325
- }
326
- }
327
- },
328
- {
329
- id: "list_tasks",
330
- description: "List background tasks and their statuses.",
331
- inputSchema: import_orchestration.ListTasksInputSchema,
332
- execute: (input, context) => ensureToolsInitialized(context).listTasks.execute(input, context),
333
- presentation: {
334
- activity: import_core.TOOL_ACTIVITY.listTasks,
335
- describeHeader: () => (0, import_core.createLocalToolCallHeader)({
336
- title: "List Tasks"
337
- }),
338
- preview: async (input, context) => {
339
- const tool = ensureToolsInitialized(context).listTasks;
340
- const previewFn = tool.presentation?.preview;
341
- if (!previewFn) {
342
- return null;
343
- }
344
- return await previewFn(input, context);
345
- }
346
- }
347
130
  }
348
131
  ];
349
132
  }
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAmBvD,OAAO,EAGH,KAAK,kBAAkB,EAE1B,MAAM,cAAc,CAAC;AAkCtB,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,kBAAkB,CAmYpE,CAAC"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/agent-spawner/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,OAAO,EAGH,KAAK,kBAAkB,EAE1B,MAAM,cAAc,CAAC;AA+BtB,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,kBAAkB,CA4HpE,CAAC"}
@@ -1,16 +1,5 @@
1
1
  import { TOOL_ACTIVITY, createLocalToolCallHeader, truncateForHeader } from "@dexto/core";
2
2
  import { ToolError } from "@dexto/core";
3
- import {
4
- ConditionEngine,
5
- SignalBus,
6
- TaskRegistry,
7
- createCheckTaskTool,
8
- createListTasksTool,
9
- createWaitForTool,
10
- WaitForInputSchema,
11
- CheckTaskInputSchema,
12
- ListTasksInputSchema
13
- } from "@dexto/orchestration";
14
3
  import {
15
4
  AgentSpawnerConfigSchema,
16
5
  SpawnAgentInputSchema
@@ -59,152 +48,10 @@ const agentSpawnerToolsFactory = {
59
48
  state.runtime.cleanup().catch(() => void 0);
60
49
  }
61
50
  state = void 0;
62
- const signalBus = new SignalBus();
63
- const taskRegistry = new TaskRegistry(signalBus);
64
- const conditionEngine = new ConditionEngine(taskRegistry, signalBus, logger);
65
51
  const spawnerRuntime = new AgentSpawnerRuntime(agent, config, logger);
66
52
  updateWorkspaceRootHint(spawnerRuntime, context);
67
53
  attachTaskForker({ toolServices, taskForker: spawnerRuntime, logger });
68
- const taskSessions = /* @__PURE__ */ new Map();
69
- const taskHostRuntimeContexts = /* @__PURE__ */ new Map();
70
- const emitTasksUpdate = (sessionId) => {
71
- const tasks = taskRegistry.list({
72
- status: ["running", "completed", "failed", "cancelled"]
73
- });
74
- const scopedTasks = sessionId ? tasks.filter((task) => taskSessions.get(task.taskId) === sessionId) : tasks;
75
- const runningCount = scopedTasks.filter((task) => task.status === "running").length;
76
- agent.emit("service:event", {
77
- service: "orchestration",
78
- event: "tasks-updated",
79
- sessionId: sessionId ?? "",
80
- data: {
81
- runningCount,
82
- tasks: scopedTasks.map((task) => ({
83
- taskId: task.taskId,
84
- status: task.status,
85
- ...task.description !== void 0 && {
86
- description: task.description
87
- }
88
- }))
89
- }
90
- });
91
- };
92
- const triggerBackgroundCompletion = (taskId, sessionId, hostRuntime) => {
93
- if (!sessionId) {
94
- return;
95
- }
96
- agent.emit("tool:background-completed", {
97
- toolCallId: taskId,
98
- sessionId,
99
- ...hostRuntime !== void 0 && { hostRuntime }
100
- });
101
- const taskInfo = taskRegistry.getInfo(taskId);
102
- const resultText = (() => {
103
- if (taskInfo?.status === "failed") {
104
- return taskInfo.error ?? "Unknown error.";
105
- }
106
- if (taskInfo?.result !== void 0) {
107
- if (typeof taskInfo.result === "string") {
108
- return taskInfo.result;
109
- }
110
- try {
111
- return JSON.stringify(taskInfo.result, null, 2);
112
- } catch {
113
- return String(taskInfo.result ?? "<unserializable result>");
114
- }
115
- }
116
- return "No result available.";
117
- })();
118
- const sanitizeCdata = (value) => value.replace(/\]\]>/g, "]]]]><![CDATA[>");
119
- const safeDescription = taskInfo?.description ? sanitizeCdata(taskInfo.description) : null;
120
- const safeResultText = sanitizeCdata(resultText);
121
- const descriptionTag = safeDescription ? ` <description><![CDATA[${safeDescription}]]></description>
122
- ` : "";
123
- const statusTag = taskInfo?.status ? ` <status>${taskInfo.status}</status>
124
- ` : "";
125
- const content = [
126
- {
127
- type: "text",
128
- text: `<background-task-completion>
129
- <origin>task</origin>
130
- <note>The following response was reported by the background task (not user input).</note>
131
- <taskId>${taskId}</taskId>
132
- ` + statusTag + descriptionTag + ` <result><![CDATA[${safeResultText}]]></result>
133
- </background-task-completion>`
134
- }
135
- ];
136
- agent.isSessionBusy(sessionId).then((isBusy) => {
137
- if (isBusy) {
138
- agent.steer(sessionId, {
139
- content,
140
- kind: "background"
141
- }).catch(() => void 0);
142
- } else {
143
- agent.emit("run:invoke", {
144
- sessionId,
145
- content,
146
- source: "external",
147
- metadata: { taskId },
148
- ...hostRuntime !== void 0 && { hostRuntime }
149
- });
150
- agent.generate(content, sessionId, {
151
- ...hostRuntime !== void 0 && {
152
- executionContext: hostRuntime
153
- }
154
- }).catch(() => void 0);
155
- }
156
- }).catch(() => {
157
- });
158
- };
159
- const handleBackground = (event) => {
160
- const taskId = event.toolCallId;
161
- if (taskRegistry.has(taskId)) {
162
- return;
163
- }
164
- if (event.sessionId) {
165
- taskSessions.set(taskId, event.sessionId);
166
- }
167
- if (event.hostRuntime !== void 0) {
168
- taskHostRuntimeContexts.set(taskId, event.hostRuntime);
169
- }
170
- try {
171
- taskRegistry.register(
172
- {
173
- type: "generic",
174
- taskId,
175
- description: event.description ?? `Tool ${event.toolName}`,
176
- promise: event.promise
177
- },
178
- {
179
- ...event.timeoutMs !== void 0 && { timeout: event.timeoutMs },
180
- ...event.notifyOnComplete !== void 0 && {
181
- notify: event.notifyOnComplete
182
- }
183
- }
184
- );
185
- } catch (error) {
186
- taskSessions.delete(taskId);
187
- taskHostRuntimeContexts.delete(taskId);
188
- event.promise.catch(() => void 0);
189
- logger.warn(
190
- `Failed to register background task ${taskId}: ${error instanceof Error ? error.message : String(error)}`,
191
- { color: "yellow" }
192
- );
193
- return;
194
- }
195
- emitTasksUpdate(event.sessionId);
196
- event.promise.finally(() => {
197
- taskSessions.delete(taskId);
198
- const hostRuntime = taskHostRuntimeContexts.get(taskId);
199
- taskHostRuntimeContexts.delete(taskId);
200
- emitTasksUpdate(event.sessionId);
201
- triggerBackgroundCompletion(taskId, event.sessionId, hostRuntime);
202
- });
203
- };
204
54
  const abortController = new AbortController();
205
- agent.on("tool:background", handleBackground, {
206
- signal: abortController.signal
207
- });
208
55
  agent.on(
209
56
  "agent:stopped",
210
57
  () => {
@@ -214,14 +61,8 @@ const agentSpawnerToolsFactory = {
214
61
  { signal: abortController.signal }
215
62
  );
216
63
  const spawnAgentTool = createSpawnAgentTool(spawnerRuntime);
217
- const waitForTool = createWaitForTool(conditionEngine);
218
- const checkTaskTool = createCheckTaskTool(taskRegistry);
219
- const listTasksTool = createListTasksTool(taskRegistry);
220
64
  const tools = {
221
- spawnAgent: spawnAgentTool,
222
- waitFor: waitForTool,
223
- checkTask: checkTaskTool,
224
- listTasks: listTasksTool
65
+ spawnAgent: spawnAgentTool
225
66
  };
226
67
  state = {
227
68
  agent,
@@ -266,74 +107,6 @@ const agentSpawnerToolsFactory = {
266
107
  return await previewFn(input, context);
267
108
  }
268
109
  }
269
- },
270
- {
271
- id: "wait_for",
272
- description: "Wait for background task(s) to complete.",
273
- inputSchema: WaitForInputSchema,
274
- execute: (input, context) => ensureToolsInitialized(context).waitFor.execute(input, context),
275
- presentation: {
276
- activity: TOOL_ACTIVITY.wait,
277
- describeHeader: (input) => {
278
- const argsText = input.taskId ? truncateForHeader(input.taskId, 80) : input.taskIds && input.taskIds.length > 0 ? truncateForHeader(`${input.taskIds.length} tasks`, 80) : void 0;
279
- return createLocalToolCallHeader({
280
- title: "Wait",
281
- ...argsText ? { argsText } : {}
282
- });
283
- },
284
- preview: async (input, context) => {
285
- const tool = ensureToolsInitialized(context).waitFor;
286
- const previewFn = tool.presentation?.preview;
287
- if (!previewFn) {
288
- return null;
289
- }
290
- return await previewFn(input, context);
291
- }
292
- }
293
- },
294
- {
295
- id: "check_task",
296
- description: "Check the status of a background task.",
297
- inputSchema: CheckTaskInputSchema,
298
- execute: (input, context) => ensureToolsInitialized(context).checkTask.execute(input, context),
299
- presentation: {
300
- activity: TOOL_ACTIVITY.checkTask,
301
- describeHeader: (input) => {
302
- const argsText = truncateForHeader(input.taskId, 80);
303
- return createLocalToolCallHeader({
304
- title: "Check Task",
305
- ...argsText ? { argsText } : {}
306
- });
307
- },
308
- preview: async (input, context) => {
309
- const tool = ensureToolsInitialized(context).checkTask;
310
- const previewFn = tool.presentation?.preview;
311
- if (!previewFn) {
312
- return null;
313
- }
314
- return await previewFn(input, context);
315
- }
316
- }
317
- },
318
- {
319
- id: "list_tasks",
320
- description: "List background tasks and their statuses.",
321
- inputSchema: ListTasksInputSchema,
322
- execute: (input, context) => ensureToolsInitialized(context).listTasks.execute(input, context),
323
- presentation: {
324
- activity: TOOL_ACTIVITY.listTasks,
325
- describeHeader: () => createLocalToolCallHeader({
326
- title: "List Tasks"
327
- }),
328
- preview: async (input, context) => {
329
- const tool = ensureToolsInitialized(context).listTasks;
330
- const previewFn = tool.presentation?.preview;
331
- if (!previewFn) {
332
- return null;
333
- }
334
- return await previewFn(input, context);
335
- }
336
- }
337
110
  }
338
111
  ];
339
112
  }
@@ -36,6 +36,7 @@ var import_node_path = __toESM(require("node:path"), 1);
36
36
  var import_core = require("@dexto/core");
37
37
  var import_discover_skills = require("../../plugins/discover-skills.js");
38
38
  var import_skill_markdown = require("../../plugins/skill-markdown.js");
39
+ var import_path = require("../../utils/path.js");
39
40
  var import_schemas = require("./schemas.js");
40
41
  var import_zod = require("zod");
41
42
  const SkillCreateInputSchema = import_zod.z.object({
@@ -150,6 +151,18 @@ async function resolveExistingSkillLocation(input, context, toolId) {
150
151
  skillFile: import_node_path.default.join(skillDir, "SKILL.md")
151
152
  };
152
153
  }
154
+ async function assertSkillWritesStayInside(baseDir, skillDir, skillFile, toolId) {
155
+ if (await pathExists(skillDir) && !await (0, import_path.resolvesInside)(baseDir, skillDir)) {
156
+ throw import_core.ToolError.validationFailed(
157
+ toolId,
158
+ "skill directory resolves outside the skills root"
159
+ );
160
+ }
161
+ const fileStat = await import_node_fs.promises.lstat(skillFile).catch(() => void 0);
162
+ if (fileStat?.isSymbolicLink()) {
163
+ throw import_core.ToolError.validationFailed(toolId, "SKILL.md is a link and cannot be written");
164
+ }
165
+ }
153
166
  function ensurePathWithinBase(baseDir, targetDir, toolId) {
154
167
  const resolvedBase = import_node_path.default.resolve(baseDir);
155
168
  const resolvedTarget = import_node_path.default.resolve(targetDir);
@@ -250,6 +263,7 @@ const creatorToolsFactory = {
250
263
  const skillDir = import_node_path.default.join(baseDir, skillId);
251
264
  ensurePathWithinBase(baseDir, skillDir, "skill_create");
252
265
  const skillFile = import_node_path.default.join(skillDir, "SKILL.md");
266
+ await assertSkillWritesStayInside(baseDir, skillDir, skillFile, "skill_create");
253
267
  const exists = await pathExists(skillFile);
254
268
  if (exists && !resolvedInput.overwrite) {
255
269
  throw import_core.ToolError.validationFailed(
@@ -293,11 +307,12 @@ const creatorToolsFactory = {
293
307
  context: "skill_update",
294
308
  hint: "Use kebab-case skill ids (e.g., release-notes)"
295
309
  });
296
- const { scope, skillFile } = await resolveExistingSkillLocation(
310
+ const { baseDir, scope, skillDir, skillFile } = await resolveExistingSkillLocation(
297
311
  input,
298
312
  context,
299
313
  "skill_update"
300
314
  );
315
+ await assertSkillWritesStayInside(baseDir, skillDir, skillFile, "skill_update");
301
316
  const exists = await pathExists(skillFile);
302
317
  if (!exists) {
303
318
  throw import_core.ToolError.validationFailed(
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/creator-tools/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAevD,OAAO,EAIH,KAAK,kBAAkB,EAC1B,MAAM,cAAc,CAAC;AA0VtB,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,kBAAkB,CA2S/D,CAAC"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/creator-tools/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAgBvD,OAAO,EAIH,KAAK,kBAAkB,EAC1B,MAAM,cAAc,CAAC;AAgXtB,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,kBAAkB,CA6S/D,CAAC"}