@cuylabs/agent-core 0.11.0 → 0.12.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 (58) hide show
  1. package/dist/{chunk-CMYN2RCB.js → chunk-33UIM3QS.js} +13 -7
  2. package/dist/{chunk-SPILYYDF.js → chunk-BERMUFZA.js} +22 -5
  3. package/dist/{chunk-TOTDGK3P.js → chunk-CSR75JVC.js} +4 -5
  4. package/dist/{chunk-ICZ66572.js → chunk-CZ5XOVDV.js} +40 -9
  5. package/dist/{chunk-2O4MCSQS.js → chunk-FYC33XFI.js} +31 -10
  6. package/dist/{chunk-WBPOZ7CL.js → chunk-JNN3RUIL.js} +86 -36
  7. package/dist/{chunk-SSFBF3US.js → chunk-JPBFAQNS.js} +7 -12
  8. package/dist/{chunk-5FMSGQVX.js → chunk-JZRLCTSD.js} +8 -2
  9. package/dist/{chunk-V4RFNEET.js → chunk-MLTJHUVG.js} +34 -16
  10. package/dist/{chunk-QAL3OMI3.js → chunk-MO3N6M32.js} +4 -1
  11. package/dist/{chunk-5NVVNXPQ.js → chunk-QEE5CBPM.js} +5 -2
  12. package/dist/{chunk-MXAP4UG6.js → chunk-QJV5XPPS.js} +238 -86
  13. package/dist/{chunk-T4UIX5D7.js → chunk-S6AKEPAX.js} +9 -3
  14. package/dist/{chunk-N3VX7FEE.js → chunk-STDJYXYK.js} +1 -4
  15. package/dist/{chunk-6HZBHFOL.js → chunk-TPZ37IWI.js} +10 -1
  16. package/dist/{chunk-NDZWXCBZ.js → chunk-TZ4VA4VX.js} +33 -11
  17. package/dist/{chunk-GFTW23FV.js → chunk-UECLINZM.js} +4 -2
  18. package/dist/chunk-US7S4FYW.js +610 -0
  19. package/dist/{chunk-RN6WZEUF.js → chunk-WI5JFEAI.js} +71 -36
  20. package/dist/dispatch/index.d.ts +5 -3
  21. package/dist/dispatch/index.js +3 -3
  22. package/dist/execution/index.d.ts +6 -4
  23. package/dist/execution/index.js +7 -7
  24. package/dist/index.d.ts +8 -5
  25. package/dist/index.js +117 -114
  26. package/dist/inference/errors/index.js +1 -1
  27. package/dist/inference/index.d.ts +6 -4
  28. package/dist/inference/index.js +6 -6
  29. package/dist/{instance-DzPiv6EK.d.ts → instance-CP24g3Le.d.ts} +1 -1
  30. package/dist/logger/index.js +1 -1
  31. package/dist/mcp/index.d.ts +116 -3
  32. package/dist/mcp/index.js +6 -2
  33. package/dist/middleware/index.d.ts +5 -3
  34. package/dist/middleware/index.js +3 -3
  35. package/dist/{model-messages-CJfwfzGe.d.ts → model-messages-B_MCHyiX.d.ts} +1 -1
  36. package/dist/models/index.js +2 -2
  37. package/dist/models/reasoning/index.js +2 -2
  38. package/dist/plugin/index.d.ts +4 -2
  39. package/dist/plugin/index.js +1 -1
  40. package/dist/profiles/index.d.ts +4 -2
  41. package/dist/profiles/index.js +1 -1
  42. package/dist/prompt/index.d.ts +5 -3
  43. package/dist/prompt/index.js +2 -2
  44. package/dist/safety/index.d.ts +5 -3
  45. package/dist/safety/index.js +1 -1
  46. package/dist/skill/index.d.ts +5 -3
  47. package/dist/skill/index.js +2 -2
  48. package/dist/storage/index.d.ts +5 -3
  49. package/dist/storage/index.js +1 -1
  50. package/dist/subagents/index.d.ts +4 -2
  51. package/dist/subagents/index.js +4 -4
  52. package/dist/team/index.d.ts +5 -3
  53. package/dist/team/index.js +1 -1
  54. package/dist/tool/index.d.ts +5 -3
  55. package/dist/tool/index.js +2 -2
  56. package/dist/{types-Bj_J8u_W.d.ts → types-DMjoFKKv.d.ts} +55 -7
  57. package/package.json +1 -6
  58. package/dist/chunk-ROTGCYDW.js +0 -221
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  executeAgentToolCall,
3
3
  snapshotScope
4
- } from "./chunk-5NVVNXPQ.js";
4
+ } from "./chunk-QEE5CBPM.js";
5
5
  import {
6
6
  LLMError,
7
7
  isRetryable
8
- } from "./chunk-N3VX7FEE.js";
8
+ } from "./chunk-STDJYXYK.js";
9
9
  import {
10
10
  buildReasoningOptionsSync,
11
11
  supportsReasoningSync
12
- } from "./chunk-RN6WZEUF.js";
12
+ } from "./chunk-WI5JFEAI.js";
13
13
  import {
14
14
  DEFAULT_MAX_STEPS,
15
15
  DEFAULT_MAX_TOKENS,
@@ -17,7 +17,7 @@ import {
17
17
  } from "./chunk-CJI7PVS2.js";
18
18
  import {
19
19
  formatApprovalDeniedReason
20
- } from "./chunk-V4RFNEET.js";
20
+ } from "./chunk-MLTJHUVG.js";
21
21
 
22
22
  // src/inference/toolset.ts
23
23
  import { tool, zodSchema } from "ai";
@@ -27,8 +27,10 @@ async function buildToolSet(options) {
27
27
  for (const [id, info] of Object.entries(options.tools)) {
28
28
  const initialized = await info.init({ cwd: options.cwd });
29
29
  const sdkPassthrough = {};
30
- if (initialized.title !== void 0) sdkPassthrough.title = initialized.title;
31
- if (initialized.strict !== void 0) sdkPassthrough.strict = initialized.strict;
30
+ if (initialized.title !== void 0)
31
+ sdkPassthrough.title = initialized.title;
32
+ if (initialized.strict !== void 0)
33
+ sdkPassthrough.strict = initialized.strict;
32
34
  if (initialized.inputExamples !== void 0) {
33
35
  sdkPassthrough.inputExamples = initialized.inputExamples;
34
36
  }
@@ -605,7 +607,11 @@ function convertAgentMessagesToModelMessages(messages) {
605
607
  }
606
608
  ]
607
609
  },
608
- ...message.metadata?.approvalCorrection ? [buildApprovalCorrectionPrompt(message.metadata.approvalCorrection)] : []
610
+ ...message.metadata?.approvalCorrection ? [
611
+ buildApprovalCorrectionPrompt(
612
+ message.metadata.approvalCorrection
613
+ )
614
+ ] : []
609
615
  ];
610
616
  case "system":
611
617
  return [{ role: "system", content: message.content }];
@@ -158,7 +158,14 @@ async function collectFiles(dirPath, baseDir, type, resources, maxDepth = 3, cur
158
158
  absolutePath: fullPath
159
159
  });
160
160
  } else if (entry.isDirectory()) {
161
- await collectFiles(fullPath, baseDir, type, resources, maxDepth, currentDepth + 1);
161
+ await collectFiles(
162
+ fullPath,
163
+ baseDir,
164
+ type,
165
+ resources,
166
+ maxDepth,
167
+ currentDepth + 1
168
+ );
162
169
  }
163
170
  }
164
171
  } catch {
@@ -197,7 +204,9 @@ function deduplicateSkills(skills) {
197
204
  byName.set(skill.name, skill);
198
205
  }
199
206
  }
200
- return Array.from(byName.values()).sort((a, b) => a.name.localeCompare(b.name));
207
+ return Array.from(byName.values()).sort(
208
+ (a, b) => a.name.localeCompare(b.name)
209
+ );
201
210
  }
202
211
 
203
212
  // src/skill/discovery/fs.ts
@@ -256,7 +265,9 @@ async function scanRoot(root, maxDepth, maxFileSize = DEFAULT_SKILL_MAX_SIZE) {
256
265
  dirsScanned++;
257
266
  try {
258
267
  const entries = await readdir2(dirPath, { withFileTypes: true });
259
- const hasSkillFile = entries.some((entry) => entry.isFile() && entry.name === SKILL_FILENAME);
268
+ const hasSkillFile = entries.some(
269
+ (entry) => entry.isFile() && entry.name === SKILL_FILENAME
270
+ );
260
271
  if (hasSkillFile) {
261
272
  const filePath = join4(dirPath, SKILL_FILENAME);
262
273
  const metadata = await loadSkillMetadata(
@@ -304,7 +315,11 @@ async function discoverSkills(cwd, config) {
304
315
  if (config?.roots) {
305
316
  for (const root of config.roots) {
306
317
  const absRoot = resolve2(resolvedCwd, root);
307
- roots.push({ path: absRoot, scope: "global", source: { type: "local", root: absRoot } });
318
+ roots.push({
319
+ path: absRoot,
320
+ scope: "global",
321
+ source: { type: "local", root: absRoot }
322
+ });
308
323
  }
309
324
  }
310
325
  const home = homedir();
@@ -490,7 +505,9 @@ var SkillRegistry = class {
490
505
  lines.push(` <description>${skill.description}</description>`);
491
506
  lines.push(` <file>${skill.filePath}</file>`);
492
507
  if (skill.dependencies && skill.dependencies.length > 0) {
493
- lines.push(` <depends-on>${skill.dependencies.join(", ")}</depends-on>`);
508
+ lines.push(
509
+ ` <depends-on>${skill.dependencies.join(", ")}</depends-on>`
510
+ );
494
511
  }
495
512
  lines.push("</skill>");
496
513
  }
@@ -16,7 +16,9 @@ ${skillList}
16
16
 
17
17
  Only load a skill when the current task clearly matches its description. Skills provide detailed workflows, reference material, and scripts.`,
18
18
  parameters: z.object({
19
- name: z.string().describe("The name of the skill to load (must match one of the available skills)")
19
+ name: z.string().describe(
20
+ "The name of the skill to load (must match one of the available skills)"
21
+ )
20
22
  }),
21
23
  execute: async ({ name }) => {
22
24
  const content = await registry.loadContent(name);
@@ -78,10 +80,7 @@ function createSkillResourceTool(registry) {
78
80
  }
79
81
  function createSkillTools(registry) {
80
82
  if (registry.size === 0) return [];
81
- return [
82
- createSkillTool(registry),
83
- createSkillResourceTool(registry)
84
- ];
83
+ return [createSkillTool(registry), createSkillResourceTool(registry)];
85
84
  }
86
85
 
87
86
  export {
@@ -44,7 +44,8 @@ function serializeMessage(message) {
44
44
  if ("tokens" in message) serialized.tokens = message.tokens;
45
45
  if ("cost" in message) serialized.cost = message.cost;
46
46
  if ("error" in message) serialized.error = message.error;
47
- if ("toolCalls" in message && message.toolCalls) serialized.toolCalls = message.toolCalls;
47
+ if ("toolCalls" in message && message.toolCalls)
48
+ serialized.toolCalls = message.toolCalls;
48
49
  }
49
50
  if (message.role === "tool") {
50
51
  if ("toolCallId" in message) serialized.toolCallId = message.toolCallId;
@@ -163,7 +164,9 @@ function getLeafId(entries) {
163
164
  const hasChildren = /* @__PURE__ */ new Set();
164
165
  for (const children of childMap.values()) {
165
166
  for (const child of children) {
166
- const entry = entries.find((e) => e.type !== "header" && e.id === child);
167
+ const entry = entries.find(
168
+ (e) => e.type !== "header" && e.id === child
169
+ );
167
170
  if (entry && entry.type !== "header") {
168
171
  const parentId = entry.parentId;
169
172
  if (parentId) hasChildren.add(parentId);
@@ -281,7 +284,15 @@ var MemoryStorage = class {
281
284
  };
282
285
 
283
286
  // src/storage/file/helpers.ts
284
- import { appendFile, mkdir, readFile, readdir, stat, unlink, writeFile } from "fs/promises";
287
+ import {
288
+ appendFile,
289
+ mkdir,
290
+ readFile,
291
+ readdir,
292
+ stat,
293
+ unlink,
294
+ writeFile
295
+ } from "fs/promises";
285
296
  import { existsSync } from "fs";
286
297
  import { basename, join } from "path";
287
298
  async function ensureStorageDirectory(directory) {
@@ -391,7 +402,10 @@ var FileStorage = class {
391
402
  if (this.useCache && this.cache.has(sessionId)) {
392
403
  return this.cache.get(sessionId);
393
404
  }
394
- const entries = await loadEntriesFromDisk(this.getPath(sessionId), sessionId);
405
+ const entries = await loadEntriesFromDisk(
406
+ this.getPath(sessionId),
407
+ sessionId
408
+ );
395
409
  if (this.useCache) {
396
410
  this.cache.set(sessionId, entries);
397
411
  }
@@ -448,9 +462,15 @@ var FileStorage = class {
448
462
  async list() {
449
463
  await this.ensureDir();
450
464
  const infos = [];
451
- for (const sessionId of await listSessionIds(this.directory, this.extension)) {
465
+ for (const sessionId of await listSessionIds(
466
+ this.directory,
467
+ this.extension
468
+ )) {
452
469
  try {
453
- const info = extractSessionInfo(await this.getEntries(sessionId), this.getPath(sessionId));
470
+ const info = extractSessionInfo(
471
+ await this.getEntries(sessionId),
472
+ this.getPath(sessionId)
473
+ );
454
474
  if (info) {
455
475
  infos.push(info);
456
476
  }
@@ -490,7 +510,10 @@ function getDataDir(appName = "cuylabs") {
490
510
  return join2(homedir(), `.${appName}`);
491
511
  }
492
512
  if (platform === "win32") {
493
- return join2(process.env.APPDATA || join2(homedir(), "AppData", "Roaming"), appName);
513
+ return join2(
514
+ process.env.APPDATA || join2(homedir(), "AppData", "Roaming"),
515
+ appName
516
+ );
494
517
  }
495
518
  const xdgData = process.env.XDG_DATA_HOME || join2(homedir(), ".local", "share");
496
519
  return join2(xdgData, appName);
@@ -575,7 +598,11 @@ var SessionManager = class {
575
598
  if (!this.currentSessionId) {
576
599
  throw new Error("No session loaded");
577
600
  }
578
- const entry = createMessageEntry(message, this.currentLeafId, this.idsCache);
601
+ const entry = createMessageEntry(
602
+ message,
603
+ this.currentLeafId,
604
+ this.idsCache
605
+ );
579
606
  await this.storage.append(this.currentSessionId, entry);
580
607
  this.entriesCache.push(entry);
581
608
  this.idsCache.add(entry.id);
@@ -690,7 +717,11 @@ var SessionManager = class {
690
717
  if (!this.currentSessionId) {
691
718
  throw new Error("No session loaded");
692
719
  }
693
- const entry = createMetadataEntry(updates, this.currentLeafId, this.idsCache);
720
+ const entry = createMetadataEntry(
721
+ updates,
722
+ this.currentLeafId,
723
+ this.idsCache
724
+ );
694
725
  await this.storage.append(this.currentSessionId, entry);
695
726
  this.entriesCache.push(entry);
696
727
  this.idsCache.add(entry.id);
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Profiles
3
- } from "./chunk-6HZBHFOL.js";
3
+ } from "./chunk-TPZ37IWI.js";
4
4
  import {
5
5
  createLocalDispatchRuntime
6
- } from "./chunk-SSFBF3US.js";
6
+ } from "./chunk-JPBFAQNS.js";
7
7
  import {
8
8
  Tool
9
9
  } from "./chunk-Q742PSH3.js";
@@ -168,7 +168,9 @@ Guidelines:
168
168
  }
169
169
  function toCompletedResult(record) {
170
170
  if (!record.result || !record.sessionId) {
171
- throw new Error(`Dispatch "${record.id}" did not produce a completed result.`);
171
+ throw new Error(
172
+ `Dispatch "${record.id}" did not produce a completed result.`
173
+ );
172
174
  }
173
175
  return {
174
176
  response: record.result.response,
@@ -200,7 +202,9 @@ function formatTerminalFailure(record) {
200
202
  );
201
203
  }
202
204
  return formatWaitErrorResult(
203
- new Error(`Subagent "${record.id}" is in unexpected state "${record.status}".`)
205
+ new Error(
206
+ `Subagent "${record.id}" is in unexpected state "${record.status}".`
207
+ )
204
208
  );
205
209
  }
206
210
  function createInvokeAgentTool(runtime, roles, options) {
@@ -238,7 +242,11 @@ function createInvokeAgentTool(runtime, roles, options) {
238
242
  );
239
243
  }
240
244
  if (isAsync) {
241
- return formatAsyncSpawnedResult(started.id, role.name, started.sessionId);
245
+ return formatAsyncSpawnedResult(
246
+ started.id,
247
+ role.name,
248
+ started.sessionId
249
+ );
242
250
  }
243
251
  try {
244
252
  const finished = await waitForTerminalDispatch(runtime, started.id);
@@ -377,7 +385,9 @@ function getConfiguredSubAgents(agent) {
377
385
  return installedSubAgents.get(agent)?.config;
378
386
  }
379
387
  function getInstalledSubAgentBackend(agent) {
380
- const backend = installedSubAgents.get(agent)?.backend;
388
+ const backend = installedSubAgents.get(
389
+ agent
390
+ )?.backend;
381
391
  return backend && backend !== "uninstalled" ? backend : void 0;
382
392
  }
383
393
  function clearInstalledSubAgents(agent) {
@@ -517,7 +527,9 @@ function parseSubAgentToolSpec(raw) {
517
527
  if (parts.length === 0) {
518
528
  return { mode: "inherit" };
519
529
  }
520
- const hasModified = parts.some((part) => part.startsWith("+") || part.startsWith("-"));
530
+ const hasModified = parts.some(
531
+ (part) => part.startsWith("+") || part.startsWith("-")
532
+ );
521
533
  if (hasModified) {
522
534
  return {
523
535
  mode: "modifiers",
@@ -553,7 +565,10 @@ function toSubAgentRole(parsed, resolvers = {}) {
553
565
  const toolSpec = parseSubAgentToolSpec(frontmatter.tools);
554
566
  if (toolSpec.mode === "explicit" || toolSpec.mode === "modifiers") {
555
567
  resolvedProfile = {
556
- ...resolvedProfile ?? { name: "custom", description: "Markdown-defined role" }
568
+ ...resolvedProfile ?? {
569
+ name: "custom",
570
+ description: "Markdown-defined role"
571
+ }
557
572
  };
558
573
  if (toolSpec.mode === "explicit") {
559
574
  resolvedProfile.allowTools = toolSpec.patterns;
@@ -643,7 +658,10 @@ function loadRoleDir(dir, source, resolvers, errors, onRole) {
643
658
  const content = readFileSync(filePath, "utf-8");
644
659
  const parsed = parseMarkdownSubAgentRole(content, filePath);
645
660
  if (!parsed) {
646
- errors.push({ path: filePath, error: "Missing required frontmatter (name, description)" });
661
+ errors.push({
662
+ path: filePath,
663
+ error: "Missing required frontmatter (name, description)"
664
+ });
647
665
  continue;
648
666
  }
649
667
  const role = toSubAgentRole(parsed, resolvers);
@@ -668,7 +686,10 @@ function loadRoleFile(filePath, source, resolvers, errors, onRole) {
668
686
  const content = readFileSync(filePath, "utf-8");
669
687
  const parsed = parseMarkdownSubAgentRole(content, filePath);
670
688
  if (!parsed) {
671
- errors.push({ path: filePath, error: "Missing required frontmatter (name, description)" });
689
+ errors.push({
690
+ path: filePath,
691
+ error: "Missing required frontmatter (name, description)"
692
+ });
672
693
  return null;
673
694
  }
674
695
  const role = toSubAgentRole(parsed, resolvers);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Inference,
3
3
  buildModelCallContext
4
- } from "./chunk-CMYN2RCB.js";
4
+ } from "./chunk-33UIM3QS.js";
5
5
  import {
6
6
  PRUNE_PROTECTED_TOOLS,
7
7
  accumulateUsage,
@@ -10,10 +10,10 @@ import {
10
10
  snapshotScope,
11
11
  streamWithinScope,
12
12
  withinScope
13
- } from "./chunk-5NVVNXPQ.js";
13
+ } from "./chunk-QEE5CBPM.js";
14
14
  import {
15
15
  LLMError
16
- } from "./chunk-N3VX7FEE.js";
16
+ } from "./chunk-STDJYXYK.js";
17
17
  import {
18
18
  extractModelId,
19
19
  extractProvider
@@ -23,7 +23,7 @@ import {
23
23
  } from "./chunk-FII65CN7.js";
24
24
  import {
25
25
  silentLogger
26
- } from "./chunk-T4UIX5D7.js";
26
+ } from "./chunk-S6AKEPAX.js";
27
27
 
28
28
  // src/execution/task/observer.ts
29
29
  function defaultAgentTaskCheckpointStrategy(input) {
@@ -321,13 +321,21 @@ function createAgentTaskRunner(agent, options = {}) {
321
321
  event,
322
322
  createdAt: turnState.updatedAt
323
323
  };
324
- await notifyObservers(baseObservers, async (observer) => {
325
- await observer.onCheckpoint?.(checkpoint);
326
- }, log);
324
+ await notifyObservers(
325
+ baseObservers,
326
+ async (observer) => {
327
+ await observer.onCheckpoint?.(checkpoint);
328
+ },
329
+ log
330
+ );
327
331
  };
328
- await notifyObservers(baseObservers, async (observer) => {
329
- await observer.onTaskStart?.(run, createSnapshot());
330
- }, log);
332
+ await notifyObservers(
333
+ baseObservers,
334
+ async (observer) => {
335
+ await observer.onTaskStart?.(run, createSnapshot());
336
+ },
337
+ log
338
+ );
331
339
  await emitCheckpoint("task-start");
332
340
  const activateCtx = baseObservers.find((o) => o.activateContext)?.activateContext?.bind(void 0, sessionId, executionId);
333
341
  try {
@@ -341,9 +349,13 @@ function createAgentTaskRunner(agent, options = {}) {
341
349
  toolCalls.push({ name: event.toolName, result: event.result });
342
350
  }
343
351
  const snapshot = createSnapshot();
344
- await notifyObservers(baseObservers, async (observer) => {
345
- await observer.onTaskEvent?.(run, event, snapshot);
346
- }, log);
352
+ await notifyObservers(
353
+ baseObservers,
354
+ async (observer) => {
355
+ await observer.onTaskEvent?.(run, event, snapshot);
356
+ },
357
+ log
358
+ );
347
359
  const checkpointReason = checkpointStrategy({
348
360
  run,
349
361
  event,
@@ -368,16 +380,28 @@ function createAgentTaskRunner(agent, options = {}) {
368
380
  usage: { ...turnState.usage },
369
381
  toolCalls
370
382
  };
371
- await notifyObservers(baseObservers, async (observer) => {
372
- await observer.onTaskComplete?.(run, result, createSnapshot());
373
- }, log);
383
+ await notifyObservers(
384
+ baseObservers,
385
+ async (observer) => {
386
+ await observer.onTaskComplete?.(run, result, createSnapshot());
387
+ },
388
+ log
389
+ );
374
390
  return result;
375
391
  } catch (error) {
376
392
  const normalizedError = error instanceof Error ? error : new Error(String(error));
377
393
  turnState = failAgentTurnState(turnState, normalizedError, nowIso());
378
- await notifyObservers(baseObservers, async (observer) => {
379
- await observer.onTaskError?.(run, normalizedError, createSnapshot());
380
- }, log);
394
+ await notifyObservers(
395
+ baseObservers,
396
+ async (observer) => {
397
+ await observer.onTaskError?.(
398
+ run,
399
+ normalizedError,
400
+ createSnapshot()
401
+ );
402
+ },
403
+ log
404
+ );
381
405
  await emitCheckpoint("task-error");
382
406
  throw normalizedError;
383
407
  }
@@ -744,18 +768,36 @@ async function pruneContext(messages, options = {}) {
744
768
  let summary;
745
769
  const initialTokens = estimateConversationTokens(currentMessages);
746
770
  if (!shouldPruneContext(initialTokens, limits)) {
747
- return { messages: currentMessages, removedCount: 0, tokensRemoved: 0, summarized: false };
771
+ return {
772
+ messages: currentMessages,
773
+ removedCount: 0,
774
+ tokensRemoved: 0,
775
+ summarized: false
776
+ };
748
777
  }
749
- const prunedMessages = pruneToolResults(currentMessages, limits.protectedTokens);
778
+ const prunedMessages = pruneToolResults(
779
+ currentMessages,
780
+ limits.protectedTokens
781
+ );
750
782
  const afterPruneTokens = estimateConversationTokens(prunedMessages);
751
783
  tokensRemoved = initialTokens - afterPruneTokens;
752
784
  currentMessages = prunedMessages;
753
785
  if (!isContextOverflowing(afterPruneTokens, limits)) {
754
- return { messages: currentMessages, removedCount: 0, tokensRemoved, summarized: false };
786
+ return {
787
+ messages: currentMessages,
788
+ removedCount: 0,
789
+ tokensRemoved,
790
+ summarized: false
791
+ };
755
792
  }
756
793
  const cutIndex = findCutPoint(currentMessages, limits.protectedTokens);
757
794
  if (cutIndex === 0) {
758
- return { messages: currentMessages, removedCount: 0, tokensRemoved, summarized: false };
795
+ return {
796
+ messages: currentMessages,
797
+ removedCount: 0,
798
+ tokensRemoved,
799
+ summarized: false
800
+ };
759
801
  }
760
802
  const toSummarize = currentMessages.slice(0, cutIndex);
761
803
  const toKeep = currentMessages.slice(cutIndex);
@@ -779,7 +821,13 @@ ${summary}`,
779
821
  } else {
780
822
  currentMessages = toKeep;
781
823
  }
782
- return { messages: currentMessages, removedCount, tokensRemoved, summarized, summary };
824
+ return {
825
+ messages: currentMessages,
826
+ removedCount,
827
+ tokensRemoved,
828
+ summarized,
829
+ summary
830
+ };
783
831
  }
784
832
 
785
833
  // src/agent/context/manager.ts
@@ -1453,11 +1501,7 @@ async function runToolBatch(options) {
1453
1501
  let safe = false;
1454
1502
  let initialized;
1455
1503
  try {
1456
- const result = await isParallelSafe(
1457
- tool,
1458
- toolCall.args,
1459
- options.cwd
1460
- );
1504
+ const result = await isParallelSafe(tool, toolCall.args, options.cwd);
1461
1505
  safe = result.safe;
1462
1506
  initialized = result.initialized;
1463
1507
  } catch {
@@ -1586,7 +1630,11 @@ function cloneAgentWorkflowTurnState(state) {
1586
1630
  ...state,
1587
1631
  systemPrompts: [...state.systemPrompts],
1588
1632
  messages: state.messages.map(cloneMessageSnapshot),
1589
- ...state.pendingInput ? { pendingInput: cloneMessageSnapshot(state.pendingInput) } : {},
1633
+ ...state.pendingInput ? {
1634
+ pendingInput: cloneMessageSnapshot(
1635
+ state.pendingInput
1636
+ )
1637
+ } : {},
1590
1638
  ...state.usage ? { usage: cloneUsage(state.usage) } : {},
1591
1639
  ...state.turnState ? { turnState: structuredClone(state.turnState) } : {},
1592
1640
  ...state.lastModelStep ? { lastModelStep: structuredClone(state.lastModelStep) } : {},
@@ -1612,12 +1660,14 @@ function applyWorkflowInterventions(state, interventions, updatedAt) {
1612
1660
  if (interventions.length === 0) {
1613
1661
  return state;
1614
1662
  }
1615
- const injected = interventions.map((intervention) => ({
1616
- id: intervention.id,
1617
- role: "user",
1618
- createdAt: intervention.createdAt,
1619
- content: intervention.message
1620
- }));
1663
+ const injected = interventions.map(
1664
+ (intervention) => ({
1665
+ id: intervention.id,
1666
+ role: "user",
1667
+ createdAt: intervention.createdAt,
1668
+ content: intervention.message
1669
+ })
1670
+ );
1621
1671
  return {
1622
1672
  ...state,
1623
1673
  messages: [...state.messages, ...injected],
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  buildEntryPath,
6
6
  deserializeMessage
7
- } from "./chunk-ICZ66572.js";
7
+ } from "./chunk-CZ5XOVDV.js";
8
8
 
9
9
  // src/agent/session.ts
10
10
  async function ensureSessionLoaded(options) {
@@ -25,7 +25,9 @@ async function repairOrphanedToolCalls(sessions) {
25
25
  for (const message of messages) {
26
26
  if (message.role === "assistant" && message.toolCalls) {
27
27
  for (const toolCall of message.toolCalls) {
28
- pendingCallIds.set(toolCall.toolCallId, { toolName: toolCall.toolName });
28
+ pendingCallIds.set(toolCall.toolCallId, {
29
+ toolName: toolCall.toolName
30
+ });
29
31
  }
30
32
  }
31
33
  if (message.role === "tool" && message.toolCallId) {
@@ -60,10 +62,7 @@ function getVisibleSessionMessages(sessions) {
60
62
  if (!leafId) {
61
63
  return [];
62
64
  }
63
- const path = buildEntryPath(
64
- sessions.getEntries(),
65
- leafId
66
- );
65
+ const path = buildEntryPath(sessions.getEntries(), leafId);
67
66
  const visible = [];
68
67
  let skipUntilId;
69
68
  for (const entry of path) {
@@ -520,9 +519,7 @@ function createLocalDispatchRuntime(options) {
520
519
  if (active.record.status === "running" && options2?.waitMs) {
521
520
  await Promise.race([
522
521
  active.promise,
523
- new Promise(
524
- (resolve) => setTimeout(resolve, options2.waitMs)
525
- )
522
+ new Promise((resolve) => setTimeout(resolve, options2.waitMs))
526
523
  ]);
527
524
  }
528
525
  return { ...active.record };
@@ -563,9 +560,7 @@ function createLocalDispatchRuntime(options) {
563
560
  let records = [...dispatches.values()].map((d) => ({ ...d.record }));
564
561
  if (options2?.status) {
565
562
  const statuses = Array.isArray(options2.status) ? options2.status : [options2.status];
566
- records = records.filter(
567
- (r) => statuses.includes(r.status)
568
- );
563
+ records = records.filter((r) => statuses.includes(r.status));
569
564
  }
570
565
  if (options2?.targetType) {
571
566
  records = records.filter((r) => r.targetType === options2.targetType);
@@ -137,7 +137,10 @@ function createDispatchTaskExecutor(options) {
137
137
  const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
138
138
  return async (input) => {
139
139
  const targetName = options.resolveTargetName?.(input) ?? input.runtime.member.role;
140
- const target = requireTarget(targets, ensureNonEmpty(targetName, "targetName"));
140
+ const target = requireTarget(
141
+ targets,
142
+ ensureNonEmpty(targetName, "targetName")
143
+ );
141
144
  const startedAt = now();
142
145
  const dispatchId = input.task.runId ?? input.task.id;
143
146
  const startResult = await target.start({
@@ -237,7 +240,10 @@ function createDispatchExternalTaskControl(options) {
237
240
  const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
238
241
  function resolveRecord(task, runtime) {
239
242
  const targetName = options.resolveTargetName?.({ task, runtime }) ?? runtime.role.name;
240
- const target = requireTarget(targets, ensureNonEmpty(targetName, "targetName"));
243
+ const target = requireTarget(
244
+ targets,
245
+ ensureNonEmpty(targetName, "targetName")
246
+ );
241
247
  const dispatchId = task.runId ?? task.id;
242
248
  const startedAt = now();
243
249
  const record = options.createRecord?.({