jinzd-ai-cli 0.2.18 → 0.2.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.
@@ -8,7 +8,7 @@ import { platform } from "os";
8
8
  import chalk from "chalk";
9
9
 
10
10
  // src/core/constants.ts
11
- var VERSION = "0.2.16";
11
+ var VERSION = "0.2.20";
12
12
  var APP_NAME = "ai-cli";
13
13
  var CONFIG_DIR_NAME = ".aicli";
14
14
  var CONFIG_FILE_NAME = "config.json";
@@ -16,7 +16,7 @@ import {
16
16
  SUBAGENT_MAX_ROUNDS_LIMIT,
17
17
  VERSION,
18
18
  runTestsTool
19
- } from "./chunk-OF77GVOC.js";
19
+ } from "./chunk-4QML7RKK.js";
20
20
 
21
21
  // src/config/config-manager.ts
22
22
  import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
@@ -4540,11 +4540,23 @@ function formatResults(query, data, requested) {
4540
4540
  }
4541
4541
 
4542
4542
  // src/tools/truncate.ts
4543
- var MAX_TOOL_OUTPUT_CHARS = 12e3;
4544
- function truncateOutput(content, toolName) {
4545
- if (content.length <= MAX_TOOL_OUTPUT_CHARS) return content;
4546
- const keepHead = Math.floor(MAX_TOOL_OUTPUT_CHARS * 0.7);
4547
- const keepTail = Math.floor(MAX_TOOL_OUTPUT_CHARS * 0.2);
4543
+ var DEFAULT_MAX_TOOL_OUTPUT_CHARS = 12e3;
4544
+ function getMaxOutputChars(contextWindow) {
4545
+ if (!contextWindow || contextWindow <= 0) return DEFAULT_MAX_TOOL_OUTPUT_CHARS;
4546
+ return Math.max(DEFAULT_MAX_TOOL_OUTPUT_CHARS, Math.min(Math.floor(contextWindow / 4), 12e4));
4547
+ }
4548
+ var activeMaxChars = DEFAULT_MAX_TOOL_OUTPUT_CHARS;
4549
+ function setContextWindow(contextWindow) {
4550
+ activeMaxChars = getMaxOutputChars(contextWindow);
4551
+ }
4552
+ function getActiveMaxChars() {
4553
+ return activeMaxChars;
4554
+ }
4555
+ function truncateOutput(content, toolName, maxChars) {
4556
+ const limit = maxChars ?? activeMaxChars;
4557
+ if (content.length <= limit) return content;
4558
+ const keepHead = Math.floor(limit * 0.7);
4559
+ const keepTail = Math.floor(limit * 0.2);
4548
4560
  const omitted = content.length - keepHead - keepTail;
4549
4561
  const lines = content.split("\n").length;
4550
4562
  const head = content.slice(0, keepHead);
@@ -5979,7 +5991,8 @@ export {
5979
5991
  lastResponseStore,
5980
5992
  askUserContext,
5981
5993
  googleSearchContext,
5982
- MAX_TOOL_OUTPUT_CHARS,
5994
+ setContextWindow,
5995
+ getActiveMaxChars,
5983
5996
  truncateOutput,
5984
5997
  spawnAgentContext,
5985
5998
  ToolRegistry,
package/dist/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  import {
3
3
  ConfigManager,
4
4
  HALLUCINATION_CORRECTION_MESSAGE,
5
- MAX_TOOL_OUTPUT_CHARS,
6
5
  McpManager,
7
6
  ProviderRegistry,
8
7
  SNAPSHOT_PROMPT,
@@ -15,6 +14,7 @@ import {
15
14
  clearDevState,
16
15
  detectsHallucinatedFileOp,
17
16
  formatGitContextForPrompt,
17
+ getActiveMaxChars,
18
18
  getContentText,
19
19
  getDangerLevel,
20
20
  getGitContext,
@@ -30,12 +30,13 @@ import {
30
30
  runHook,
31
31
  saveDevState,
32
32
  sessionHasMeaningfulContent,
33
+ setContextWindow,
33
34
  setupProxy,
34
35
  spawnAgentContext,
35
36
  theme,
36
37
  truncateOutput,
37
38
  undoStack
38
- } from "./chunk-LXBTSYBY.js";
39
+ } from "./chunk-MSI2PNQB.js";
39
40
  import {
40
41
  AGENTIC_BEHAVIOR_GUIDELINE,
41
42
  AUTHOR,
@@ -55,7 +56,7 @@ import {
55
56
  REPO_URL,
56
57
  SKILLS_DIR_NAME,
57
58
  VERSION
58
- } from "./chunk-OF77GVOC.js";
59
+ } from "./chunk-4QML7RKK.js";
59
60
 
60
61
  // src/index.ts
61
62
  import { program } from "commander";
@@ -1904,7 +1905,7 @@ ${hint}` : "")
1904
1905
  description: "Run project tests and show structured report",
1905
1906
  usage: "/test [command|filter]",
1906
1907
  async execute(args, _ctx) {
1907
- const { executeTests } = await import("./run-tests-WINPQJ3Z.js");
1908
+ const { executeTests } = await import("./run-tests-U7MLQNUL.js");
1908
1909
  const argStr = args.join(" ").trim();
1909
1910
  let testArgs = {};
1910
1911
  if (argStr) {
@@ -2835,7 +2836,7 @@ var ToolExecutor = class {
2835
2836
  const moreLines = lines.length > maxLines ? theme.dim(`
2836
2837
  ... (${lines.length - maxLines} more lines)`) : "";
2837
2838
  const truncatedNote = wasTruncated ? theme.warning(`
2838
- \u26A1 Output truncated to ${MAX_TOOL_OUTPUT_CHARS} chars before sending to AI`) : "";
2839
+ \u26A1 Output truncated to ${getActiveMaxChars()} chars before sending to AI`) : "";
2839
2840
  console.log(theme.toolResult("\u2713 Result: ") + theme.dim(preview) + moreLines + truncatedNote);
2840
2841
  }
2841
2842
  console.log();
@@ -4034,6 +4035,7 @@ Session '${this.resumeSessionId}' not found.
4034
4035
  const welcomeProvider = this.providers.get(this.currentProvider);
4035
4036
  const welcomeModelInfo = welcomeProvider?.info.models.find((m) => m.id === this.currentModel);
4036
4037
  this.renderer.printWelcome(this.currentProvider, this.currentModel, welcomeModelInfo?.contextWindow);
4038
+ if (welcomeModelInfo?.contextWindow) setContextWindow(welcomeModelInfo.contextWindow);
4037
4039
  if (this.resumeSessionId) {
4038
4040
  const session = this.sessions.current;
4039
4041
  process.stdout.write(
@@ -5310,6 +5312,8 @@ Tip: You can continue the conversation by asking the AI to proceed.`
5310
5312
  setProvider: (id, model) => {
5311
5313
  this.currentProvider = id;
5312
5314
  this.currentModel = model ?? this.config.get("defaultModels")[id] ?? this.providers.get(id).info.defaultModel;
5315
+ const ctxWin = this.getContextWindowSize();
5316
+ if (ctxWin > 0) setContextWindow(ctxWin);
5313
5317
  this.refreshPrompt();
5314
5318
  this.events.emit("provider.switch", {
5315
5319
  providerId: id,
@@ -5507,7 +5511,7 @@ program.command("web").description("Start Web UI server with browser-based chat
5507
5511
  console.error("Error: Invalid port number. Must be between 1 and 65535.");
5508
5512
  process.exit(1);
5509
5513
  }
5510
- const { startWebServer } = await import("./server-YQKOLA5A.js");
5514
+ const { startWebServer } = await import("./server-5RJZNTPH.js");
5511
5515
  await startWebServer({ port, host: options.host });
5512
5516
  });
5513
5517
  program.command("user [action] [username]").description("Manage Web UI users (list | create <name> | delete <name> | reset-password <name> | migrate <name>)").action(async (action, username) => {
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  executeTests,
4
4
  runTestsTool
5
- } from "./chunk-OF77GVOC.js";
5
+ } from "./chunk-4QML7RKK.js";
6
6
  export {
7
7
  executeTests,
8
8
  runTestsTool
@@ -20,10 +20,11 @@ import {
20
20
  loadDevState,
21
21
  renderDiff,
22
22
  runHook,
23
+ setContextWindow,
23
24
  setupProxy,
24
25
  spawnAgentContext,
25
26
  truncateOutput
26
- } from "./chunk-LXBTSYBY.js";
27
+ } from "./chunk-MSI2PNQB.js";
27
28
  import {
28
29
  AGENTIC_BEHAVIOR_GUIDELINE,
29
30
  CONTEXT_FILE_CANDIDATES,
@@ -35,7 +36,7 @@ import {
35
36
  PLAN_MODE_SYSTEM_ADDON,
36
37
  SKILLS_DIR_NAME,
37
38
  VERSION
38
- } from "./chunk-OF77GVOC.js";
39
+ } from "./chunk-4QML7RKK.js";
39
40
  import {
40
41
  AuthManager
41
42
  } from "./chunk-CPLT6CD3.js";
@@ -452,6 +453,7 @@ var SessionHandler = class {
452
453
  this.currentModel = "";
453
454
  }
454
455
  }
456
+ this.updateContextWindow();
455
457
  this.activeSystemPrompt = this.loadContextFiles();
456
458
  const hooks = this.config.get("hooks");
457
459
  const permissionRules = this.config.get("permissionRules");
@@ -530,6 +532,15 @@ var SessionHandler = class {
530
532
  this.pendingAskUser.clear();
531
533
  this.saveIfNeeded();
532
534
  }
535
+ /** 根据当前模型 context window 更新工具输出截断上限 */
536
+ updateContextWindow() {
537
+ try {
538
+ const provider = this.providers.get(this.currentProvider);
539
+ const modelInfo = provider?.info.models.find((m) => m.id === this.currentModel);
540
+ if (modelInfo?.contextWindow) setContextWindow(modelInfo.contextWindow);
541
+ } catch {
542
+ }
543
+ }
533
544
  /** Save session only if it exists and has messages (never persist empty "Untitled" sessions). */
534
545
  saveIfNeeded() {
535
546
  if (this.sessions.current && this.sessions.current.messages.length > 0) {
@@ -877,6 +888,7 @@ ${summaryResult.content}`,
877
888
  }
878
889
  this.currentProvider = id;
879
890
  this.currentModel = p.info.defaultModel;
891
+ this.updateContextWindow();
880
892
  this.send({ type: "info", message: `Switched to provider: ${id} (${this.currentModel})` });
881
893
  this.sendStatus();
882
894
  break;
@@ -894,6 +906,7 @@ ${summaryResult.content}`,
894
906
  return;
895
907
  }
896
908
  this.currentModel = modelId;
909
+ this.updateContextWindow();
897
910
  this.send({ type: "info", message: `Switched to model: ${modelId}` });
898
911
  this.sendStatus();
899
912
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jinzd-ai-cli",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "Cross-platform REPL-style AI CLI with multi-provider support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",