@strayl/agent 0.1.24 → 0.1.26

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 (2) hide show
  1. package/dist/agent.js +76 -9
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -6805,7 +6805,7 @@ var MODEL_LIMITS = {
6805
6805
  "anthropic/claude-sonnet-4.6": { maxTokens: 1e5, maxInputTokens: 9e5 }
6806
6806
  };
6807
6807
  var DEFAULT_LIMITS = { maxTokens: 1e5, maxInputTokens: 28e4 };
6808
- var SUBAGENT_MODEL = "x-ai/grok-4.1-fast";
6808
+ var SUBAGENT_MODEL = "gemini-3-flash-preview";
6809
6809
  var SUMMARIZATION_MODEL = "google/gemini-2.5-flash-lite";
6810
6810
  function resolveModel(tier) {
6811
6811
  return MODEL_MAP[tier] ?? tier;
@@ -7274,7 +7274,7 @@ Incorporate the new messages below:
7274
7274
  - Be concise but maximize recall \u2014 lost details cannot be recovered
7275
7275
 
7276
7276
  Output the complete updated summary, not a diff.`;
7277
- async function summarizeMessages(messages, existingSummary, _parentClient) {
7277
+ async function summarizeMessages(messages, existingSummary, _parentClient, onUsage) {
7278
7278
  const sumClient = new LLMClient({
7279
7279
  modelTier: SUMMARIZATION_MODEL,
7280
7280
  env: process.env
@@ -7288,6 +7288,7 @@ async function summarizeMessages(messages, existingSummary, _parentClient) {
7288
7288
  let result = "";
7289
7289
  for await (const chunk of sumClient.stream(sumMessages, [])) {
7290
7290
  if (chunk.type === "text") result += chunk.text;
7291
+ if (chunk.type === "usage" && onUsage) onUsage(chunk);
7291
7292
  }
7292
7293
  return result;
7293
7294
  }
@@ -7477,7 +7478,7 @@ var ContextManager = class {
7477
7478
  }
7478
7479
  }
7479
7480
  async createSummary(client) {
7480
- return summarizeMessages(this.msgs, this.existingSummary, client);
7481
+ return summarizeMessages(this.msgs, this.existingSummary, client, (usage) => this.recordUsage(usage));
7481
7482
  }
7482
7483
  replaceSummarizedMessages(summary, emitter) {
7483
7484
  const KEEP = 8;
@@ -11894,7 +11895,10 @@ var lsTool = {
11894
11895
  };
11895
11896
  try {
11896
11897
  const stat = await fs3.stat(entryPath);
11897
- if (!entry.isDirectory()) item.size = stat.size;
11898
+ if (stat.isDirectory()) {
11899
+ item.type = "dir";
11900
+ }
11901
+ if (!stat.isDirectory()) item.size = stat.size;
11898
11902
  item.modified = stat.mtime.toISOString();
11899
11903
  } catch {
11900
11904
  }
@@ -12189,8 +12193,10 @@ var AVAILABLE_TOOLS = {
12189
12193
  var SubAgentManager = class {
12190
12194
  running = /* @__PURE__ */ new Map();
12191
12195
  emitter;
12192
- constructor(emitter) {
12196
+ onUsage;
12197
+ constructor(emitter, onUsage) {
12193
12198
  this.emitter = emitter;
12199
+ this.onUsage = onUsage;
12194
12200
  }
12195
12201
  spawn(config) {
12196
12202
  const id = `sa_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
@@ -12244,6 +12250,11 @@ var SubAgentManager = class {
12244
12250
  function: { name: chunk.name, arguments: chunk.arguments }
12245
12251
  });
12246
12252
  break;
12253
+ case "usage":
12254
+ if (this.onUsage) {
12255
+ this.onUsage(chunk);
12256
+ }
12257
+ break;
12247
12258
  }
12248
12259
  }
12249
12260
  const assistantMsg = { role: "assistant", content: text || null };
@@ -13532,7 +13543,7 @@ async function runAgent(config) {
13532
13543
  const registry = new ToolRegistry();
13533
13544
  const hitl = new HITLManager(config.hitlDir);
13534
13545
  await hitl.init();
13535
- const subAgentManager = new SubAgentManager(emitter);
13546
+ const subAgentManager = new SubAgentManager(emitter, (usage) => context.recordUsage(usage));
13536
13547
  const todoManager = new TodoManager(emitter);
13537
13548
  const checkpoints = new CheckpointManager(config.workDir, config.sessionId);
13538
13549
  await checkpoints.init();
@@ -13770,12 +13781,68 @@ ${IMPLEMENTATION_MODE_PROMPT2}`);
13770
13781
  emitter.emit({ type: "debug", message: `[LOOP] Tool calls: ${completedToolCalls.map((tc) => tc.function.name).join(", ")}` });
13771
13782
  hasUsedTools = true;
13772
13783
  nudgedToContinue = false;
13773
- for (const tc of completedToolCalls) {
13784
+ let tci = 0;
13785
+ while (tci < completedToolCalls.length) {
13774
13786
  if (stdin.isCancelled()) {
13775
- context.addToolResult(tc.id, tc.function.name, JSON.stringify({ error: "Cancelled by user." }));
13776
- emitter.emit({ type: "tool-result", id: tc.id, name: tc.function.name, output: "Cancelled by user.", error: "Cancelled by user." });
13787
+ for (let r = tci; r < completedToolCalls.length; r++) {
13788
+ const rem = completedToolCalls[r];
13789
+ context.addToolResult(rem.id, rem.function.name, JSON.stringify({ error: "Cancelled by user." }));
13790
+ emitter.emit({ type: "tool-result", id: rem.id, name: rem.function.name, output: "Cancelled by user.", error: "Cancelled by user." });
13791
+ }
13777
13792
  break;
13778
13793
  }
13794
+ if (completedToolCalls[tci].function.name === "task") {
13795
+ const taskBatch = [];
13796
+ while (tci < completedToolCalls.length && completedToolCalls[tci].function.name === "task") {
13797
+ taskBatch.push(completedToolCalls[tci]);
13798
+ tci++;
13799
+ }
13800
+ if (taskBatch.length === 1) {
13801
+ const tc2 = taskBatch[0];
13802
+ let parsedArgs2;
13803
+ try {
13804
+ parsedArgs2 = JSON.parse(tc2.function.arguments);
13805
+ } catch {
13806
+ parsedArgs2 = {};
13807
+ }
13808
+ const activity2 = toolToActivity(tc2.function.name, parsedArgs2);
13809
+ if (activity2) emitter.emit({ type: "activity", ...activity2 });
13810
+ emitter.emit({ type: "tool-call-start", id: tc2.id, name: tc2.function.name, args: parsedArgs2 });
13811
+ const toolCtx2 = { emitter, workDir: config.workDir, env: config.env, sessionId: config.sessionId, toolCallId: tc2.id };
13812
+ const modifiedTc2 = { ...tc2, function: { ...tc2.function, arguments: JSON.stringify(parsedArgs2) } };
13813
+ const result2 = await executeTool(registry, modifiedTc2, toolCtx2, middleware);
13814
+ emitter.emit({ type: "tool-result", id: tc2.id, name: tc2.function.name, output: result2 });
13815
+ context.addToolResult(tc2.id, tc2.function.name, result2);
13816
+ } else {
13817
+ emitter.emit({ type: "debug", message: `[PARALLEL] Spawning ${taskBatch.length} task calls in parallel` });
13818
+ const prepared = taskBatch.map((tc2) => {
13819
+ let parsedArgs2;
13820
+ try {
13821
+ parsedArgs2 = JSON.parse(tc2.function.arguments);
13822
+ } catch {
13823
+ parsedArgs2 = {};
13824
+ }
13825
+ const activity2 = toolToActivity(tc2.function.name, parsedArgs2);
13826
+ if (activity2) emitter.emit({ type: "activity", ...activity2 });
13827
+ emitter.emit({ type: "tool-call-start", id: tc2.id, name: tc2.function.name, args: parsedArgs2 });
13828
+ return { tc: tc2, parsedArgs: parsedArgs2 };
13829
+ });
13830
+ const results = await Promise.all(prepared.map(async ({ tc: tc2, parsedArgs: parsedArgs2 }) => {
13831
+ const toolCtx2 = { emitter, workDir: config.workDir, env: config.env, sessionId: config.sessionId, toolCallId: tc2.id };
13832
+ const modifiedTc2 = { ...tc2, function: { ...tc2.function, arguments: JSON.stringify(parsedArgs2) } };
13833
+ const result2 = await executeTool(registry, modifiedTc2, toolCtx2, middleware);
13834
+ return { tc: tc2, result: result2 };
13835
+ }));
13836
+ for (const { tc: tc2, result: result2 } of results) {
13837
+ emitter.emit({ type: "tool-result", id: tc2.id, name: tc2.function.name, output: result2 });
13838
+ context.addToolResult(tc2.id, tc2.function.name, result2);
13839
+ }
13840
+ emitter.emit({ type: "debug", message: `[PARALLEL] All ${taskBatch.length} tasks completed` });
13841
+ }
13842
+ continue;
13843
+ }
13844
+ const tc = completedToolCalls[tci];
13845
+ tci++;
13779
13846
  let parsedArgs;
13780
13847
  try {
13781
13848
  parsedArgs = JSON.parse(tc.function.arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strayl/agent",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"