agent-sh 0.12.18 → 0.12.20

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.
@@ -1527,6 +1527,7 @@ export class AgentLoop {
1527
1527
  messages,
1528
1528
  tools: apiTools,
1529
1529
  model: this.currentModel,
1530
+ max_tokens: this.currentMode.maxTokens ?? 65536,
1530
1531
  ...this.reasoningParams(),
1531
1532
  };
1532
1533
  this.bus.emit("llm:request", requestParams);
@@ -59,6 +59,9 @@ export declare class ConversationState {
59
59
  private hasOpenToolCalls;
60
60
  private flushPendingNotes;
61
61
  getMessages(): ChatCompletionMessageParam[];
62
+ /** Drop tool messages with no matching preceding tool_call — strict
63
+ * providers (DeepSeek) 400, and compaction can leave such orphans. */
64
+ private dropOrphanToolMessages;
62
65
  /**
63
66
  * If a stream was interrupted mid-tool-execution, an assistant message
64
67
  * with tool_calls can land in history without matching tool results.
@@ -163,7 +163,24 @@ export class ConversationState {
163
163
  this.invalidateMessagesCache();
164
164
  }
165
165
  getMessages() {
166
- return this.normalizeReasoningConsistency(this.stubDanglingToolCalls(this.messages));
166
+ return this.normalizeReasoningConsistency(this.stubDanglingToolCalls(this.dropOrphanToolMessages(this.messages)));
167
+ }
168
+ /** Drop tool messages with no matching preceding tool_call — strict
169
+ * providers (DeepSeek) 400, and compaction can leave such orphans. */
170
+ dropOrphanToolMessages(messages) {
171
+ const knownIds = new Set();
172
+ const result = [];
173
+ for (const msg of messages) {
174
+ if (msg.role === "assistant" && "tool_calls" in msg && msg.tool_calls) {
175
+ for (const tc of msg.tool_calls)
176
+ knownIds.add(tc.id);
177
+ }
178
+ if (msg.role === "tool" && !knownIds.has(msg.tool_call_id)) {
179
+ continue;
180
+ }
181
+ result.push(msg);
182
+ }
183
+ return result;
167
184
  }
168
185
  /**
169
186
  * If a stream was interrupted mid-tool-execution, an assistant message
@@ -582,19 +599,23 @@ export class ConversationState {
582
599
  slimTurn(messages) {
583
600
  const MAX_RESULT_LEN = 1500;
584
601
  const result = [];
585
- const readOnlyToolIds = new Set();
602
+ const droppedToolIds = new Set();
586
603
  for (const msg of messages) {
587
604
  if (msg.role === "assistant" && "tool_calls" in msg && msg.tool_calls) {
588
605
  const kept = msg.tool_calls.filter((tc) => {
589
606
  if (!("function" in tc))
590
607
  return true;
591
608
  if (READ_ONLY_TOOLS.has(tc.function.name)) {
592
- readOnlyToolIds.add(tc.id);
609
+ droppedToolIds.add(tc.id);
593
610
  return false;
594
611
  }
595
612
  return true;
596
613
  });
597
614
  if (kept.length === 0) {
615
+ // No content + no tool_calls is malformed (DeepSeek 400); drop the husk.
616
+ const text = typeof msg.content === "string" ? msg.content.trim() : "";
617
+ if (!text)
618
+ continue;
598
619
  const { tool_calls: _, ...rest } = msg;
599
620
  result.push(rest);
600
621
  }
@@ -604,7 +625,7 @@ export class ConversationState {
604
625
  continue;
605
626
  }
606
627
  if (msg.role === "tool") {
607
- if (readOnlyToolIds.has(msg.tool_call_id))
628
+ if (droppedToolIds.has(msg.tool_call_id))
608
629
  continue;
609
630
  const content = typeof msg.content === "string" ? msg.content : "";
610
631
  if (content.length > MAX_RESULT_LEN) {
@@ -69,6 +69,7 @@ export interface ShellEvents {
69
69
  messages: unknown[];
70
70
  tools?: unknown;
71
71
  model?: string;
72
+ max_tokens?: number;
72
73
  reasoning_effort?: string;
73
74
  };
74
75
  "llm:chunk": {
@@ -318,6 +319,7 @@ export interface ShellEvents {
318
319
  id: string;
319
320
  reasoning?: boolean;
320
321
  contextWindow?: number;
322
+ maxTokens?: number;
321
323
  echoReasoning?: boolean;
322
324
  })[];
323
325
  /** Provider supports the reasoning_effort parameter. Default: true. */
@@ -36,6 +36,7 @@ export default function agentBackend(ctx) {
36
36
  provider: id,
37
37
  providerConfig: { apiKey: p.apiKey, baseURL: p.baseURL },
38
38
  contextWindow: mc?.contextWindow ?? p.contextWindow,
39
+ maxTokens: mc?.maxTokens ?? (mc?.contextWindow ? Math.min(Math.floor(mc.contextWindow * 0.4), 65536) : undefined),
39
40
  reasoning: mc?.reasoning,
40
41
  supportsReasoningEffort: p.supportsReasoningEffort,
41
42
  echoReasoning: mc?.echoReasoning,
@@ -149,7 +150,7 @@ export default function agentBackend(ctx) {
149
150
  }
150
151
  else {
151
152
  modelIds.push(m.id);
152
- caps.set(m.id, { reasoning: m.reasoning, contextWindow: m.contextWindow, echoReasoning: m.echoReasoning });
153
+ caps.set(m.id, { reasoning: m.reasoning, contextWindow: m.contextWindow, maxTokens: m.maxTokens, echoReasoning: m.echoReasoning });
153
154
  }
154
155
  }
155
156
  providerRegistry.set(p.id, {
@@ -169,6 +170,7 @@ export default function agentBackend(ctx) {
169
170
  provider: p.id,
170
171
  providerConfig: { apiKey: p.apiKey ?? "", baseURL: p.baseURL },
171
172
  contextWindow: mc?.contextWindow,
173
+ maxTokens: mc?.maxTokens,
172
174
  reasoning: mc?.reasoning,
173
175
  supportsReasoningEffort: p.supportsReasoningEffort,
174
176
  echoReasoning: mc?.echoReasoning,
@@ -212,6 +214,7 @@ export default function agentBackend(ctx) {
212
214
  provider: name,
213
215
  providerConfig: { apiKey: p.apiKey, baseURL: p.baseURL },
214
216
  contextWindow: mc?.contextWindow ?? p.contextWindow,
217
+ maxTokens: mc?.maxTokens ?? (mc?.contextWindow ? Math.min(Math.floor(mc.contextWindow * 0.4), 65536) : undefined),
215
218
  reasoning: mc?.reasoning,
216
219
  supportsReasoningEffort: p.supportsReasoningEffort,
217
220
  echoReasoning: mc?.echoReasoning,
@@ -654,26 +654,16 @@ export default function activate(ctx) {
654
654
  return [];
655
655
  const boxW = Math.min(120, width - 2);
656
656
  const contentW = boxW - 4;
657
- let body;
658
- if (diff.isNewFile) {
659
- const lines = diff.hunks.flatMap(h => h.lines.map(l => l.text));
660
- const preview = getSettings().newFilePreviewLines;
661
- const head = lines.slice(0, preview);
662
- const truncated = head.map(l => l.length > contentW ? l.slice(0, contentW - 1) + "…" : l);
663
- const more = lines.length > preview
664
- ? [`${p.dim}… ${lines.length - preview} more lines${p.reset}`]
665
- : [];
666
- body = ["", ...truncated, ...more, ""];
667
- }
668
- else {
669
- const diffLines = renderDiff(diff, {
670
- width: contentW,
671
- filePath,
672
- maxLines: getSettings().diffMaxLines,
673
- trueColor: true,
674
- });
675
- body = diffLines.length > 1 ? ["", ...diffLines.slice(1), ""] : diffLines;
676
- }
657
+ const maxLines = diff.isNewFile
658
+ ? getSettings().newFilePreviewLines
659
+ : getSettings().diffMaxLines;
660
+ const diffLines = renderDiff(diff, {
661
+ width: contentW,
662
+ filePath,
663
+ maxLines,
664
+ trueColor: true,
665
+ });
666
+ const body = diffLines.length > 1 ? ["", ...diffLines.slice(1), ""] : diffLines;
677
667
  return renderBoxFrame(body, {
678
668
  width: boxW,
679
669
  style: "rounded",
@@ -9,6 +9,8 @@ export interface ModelCapabilityConfig {
9
9
  reasoning?: boolean;
10
10
  /** Context window size in tokens for this specific model. */
11
11
  contextWindow?: number;
12
+ /** Max output tokens for this model. */
13
+ maxTokens?: number;
12
14
  /** Echo reasoning_content back on assistant turns. Required by DeepSeek. */
13
15
  echoReasoning?: boolean;
14
16
  }
@@ -148,6 +150,7 @@ export interface ResolvedProvider {
148
150
  modelCapabilities?: Map<string, {
149
151
  reasoning?: boolean;
150
152
  contextWindow?: number;
153
+ maxTokens?: number;
151
154
  echoReasoning?: boolean;
152
155
  }>;
153
156
  /** Borrow another registered provider's reasoning request shape by id. */
package/dist/settings.js CHANGED
@@ -148,8 +148,8 @@ export function resolveProvider(name) {
148
148
  }
149
149
  else {
150
150
  modelIds.push(m.id);
151
- if (m.reasoning !== undefined || m.contextWindow !== undefined || m.echoReasoning !== undefined) {
152
- caps.set(m.id, { reasoning: m.reasoning, contextWindow: m.contextWindow, echoReasoning: m.echoReasoning });
151
+ if (m.reasoning !== undefined || m.contextWindow !== undefined || m.maxTokens !== undefined || m.echoReasoning !== undefined) {
152
+ caps.set(m.id, { reasoning: m.reasoning, contextWindow: m.contextWindow, maxTokens: m.maxTokens, echoReasoning: m.echoReasoning });
153
153
  }
154
154
  }
155
155
  }
package/dist/types.d.ts CHANGED
@@ -41,6 +41,8 @@ export interface AgentMode {
41
41
  };
42
42
  /** Context window size in tokens (for usage display). */
43
43
  contextWindow?: number;
44
+ /** Max output tokens for this mode. */
45
+ maxTokens?: number;
44
46
  /** Model supports reasoning/thinking tokens. */
45
47
  reasoning?: boolean;
46
48
  /** Provider supports the reasoning_effort parameter. */
@@ -44,7 +44,7 @@ export class LlmClient {
44
44
  model: opts.model ?? this.model,
45
45
  messages: opts.messages,
46
46
  tools: opts.tools?.length ? opts.tools : undefined,
47
- max_tokens: opts.max_tokens ?? 8192,
47
+ max_tokens: opts.max_tokens ?? 65536,
48
48
  stream: true,
49
49
  stream_options: { include_usage: true },
50
50
  ...(opts.reasoning_effort
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-sh",
3
- "version": "0.12.18",
3
+ "version": "0.12.20",
4
4
  "description": "A shell-first terminal where AI is one keystroke away",
5
5
  "type": "module",
6
6
  "main": "dist/core.js",