@strayl/agent 0.1.20 → 0.1.22

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 +24 -1
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -12380,6 +12380,10 @@ var StdinListener = class {
12380
12380
  isCancelled() {
12381
12381
  return this.cancelled;
12382
12382
  }
12383
+ /** Put commands back at the front of the queue (for re-queuing unhandled commands) */
12384
+ requeue(...cmds) {
12385
+ this.queue.unshift(...cmds);
12386
+ }
12383
12387
  stop() {
12384
12388
  this.rl?.close();
12385
12389
  this.rl = null;
@@ -13563,6 +13567,7 @@ async function runAgent(config) {
13563
13567
  const maxIterations = config.maxIterations ?? 200;
13564
13568
  let consecutiveLLMErrors = 0;
13565
13569
  const MAX_CONSECUTIVE_LLM_ERRORS = 5;
13570
+ let nudgedToContinue = false;
13566
13571
  if (config.restoreCheckpoint) {
13567
13572
  const cp = config.restoreCheckpoint;
13568
13573
  context.restoreMessages(cp.messages);
@@ -13581,6 +13586,7 @@ ${config.previousSummary}`);
13581
13586
  }
13582
13587
  while (iteration < maxIterations) {
13583
13588
  iteration++;
13589
+ emitter.emit({ type: "debug", message: `[LOOP] iteration=${iteration}/${maxIterations} mode=${currentMode} nudgedToContinue=${nudgedToContinue}` });
13584
13590
  for (const cmd of stdin.drain()) {
13585
13591
  switch (cmd.type) {
13586
13592
  case "inject":
@@ -13749,8 +13755,18 @@ ${IMPLEMENTATION_MODE_PROMPT2}`);
13749
13755
  });
13750
13756
  }
13751
13757
  if (completedToolCalls.length === 0) {
13758
+ emitter.emit({ type: "debug", message: `[LOOP] No tool calls. textLen=${assistantText.length} nudgedToContinue=${nudgedToContinue} text="${assistantText.slice(0, 200)}"` });
13759
+ if (!nudgedToContinue) {
13760
+ nudgedToContinue = true;
13761
+ emitter.emit({ type: "debug", message: `[LOOP] Sending nudge to continue...` });
13762
+ context.addUser("[System: You responded with text but did not call any tools. If you are done, respond with your final message. Otherwise, use your tools to continue working.]");
13763
+ continue;
13764
+ }
13765
+ emitter.emit({ type: "debug", message: `[LOOP] Already nudged, breaking loop. Agent will terminate.` });
13752
13766
  break;
13753
13767
  }
13768
+ emitter.emit({ type: "debug", message: `[LOOP] Tool calls: ${completedToolCalls.map((tc) => tc.function.name).join(", ")}` });
13769
+ nudgedToContinue = false;
13754
13770
  for (const tc of completedToolCalls) {
13755
13771
  if (stdin.isCancelled()) {
13756
13772
  context.addToolResult(tc.id, tc.function.name, JSON.stringify({ error: "Cancelled by user." }));
@@ -13770,12 +13786,15 @@ ${IMPLEMENTATION_MODE_PROMPT2}`);
13770
13786
  emitter.emit({ type: "tool-call-start", id: tc.id, name: tc.function.name, args: parsedArgs });
13771
13787
  const toolDef = registry.get(tc.function.name);
13772
13788
  if (toolDef?.hitl) {
13789
+ emitter.emit({ type: "debug", message: `[HITL] Requesting HITL for tool=${tc.function.name} safeId=${hitl.safeId(tc.id)}` });
13773
13790
  emitter.emit({ type: "hitl-request", id: tc.id, safe_id: hitl.safeId(tc.id), tool: tc.function.name, args: parsedArgs });
13774
13791
  const response = await hitl.waitForResponse(tc.id, async () => {
13775
13792
  for (const cmd of stdin.drain()) {
13776
13793
  if (cmd.type === "hitl-response") {
13777
13794
  await hitl.writeResponse(cmd.id, { decision: cmd.decision, data: cmd.data });
13778
13795
  } else if (cmd.type === "cancel") {
13796
+ } else {
13797
+ stdin.requeue(cmd);
13779
13798
  }
13780
13799
  }
13781
13800
  });
@@ -13788,7 +13807,9 @@ ${IMPLEMENTATION_MODE_PROMPT2}`);
13788
13807
  if (response.decision === "edit" && response.data && typeof response.data === "object") {
13789
13808
  parsedArgs = { ...parsedArgs, ...response.data };
13790
13809
  }
13810
+ emitter.emit({ type: "debug", message: `[HITL] Got response: decision=${response.decision} dataKeys=${response.data ? Object.keys(response.data).join(",") : "none"}` });
13791
13811
  emitter.emit({ type: "hitl-response", id: tc.id, decision: response.decision, data: response.data });
13812
+ nudgedToContinue = false;
13792
13813
  }
13793
13814
  const toolCtx = {
13794
13815
  emitter,
@@ -13824,10 +13845,12 @@ ${PLAN_MODE_SYSTEM_PROMPT2}`);
13824
13845
  });
13825
13846
  }
13826
13847
  stdin.stop();
13848
+ const exitReason = iteration >= maxIterations ? "max_iterations" : "complete";
13849
+ emitter.emit({ type: "debug", message: `[SESSION-END] reason=${exitReason} iteration=${iteration}/${maxIterations} mode=${currentMode}` });
13827
13850
  emitter.emit({
13828
13851
  type: "session-end",
13829
13852
  usage: context.totalUsage(),
13830
- exit_reason: iteration >= maxIterations ? "max_iterations" : "complete"
13853
+ exit_reason: exitReason
13831
13854
  });
13832
13855
  }
13833
13856
  function toolToActivity(name, args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strayl/agent",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"