jinzd-ai-cli 0.4.72 → 0.4.73

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.
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/config/env-loader.ts
4
+ var ENV_KEY_MAP = {
5
+ claude: "AICLI_API_KEY_CLAUDE",
6
+ gemini: "AICLI_API_KEY_GEMINI",
7
+ deepseek: "AICLI_API_KEY_DEEPSEEK",
8
+ zhipu: "AICLI_API_KEY_ZHIPU",
9
+ kimi: "AICLI_API_KEY_KIMI",
10
+ openai: "AICLI_API_KEY_OPENAI",
11
+ openrouter: "AICLI_API_KEY_OPENROUTER",
12
+ "google-search": "AICLI_API_KEY_GOOGLESEARCH",
13
+ ollama: "AICLI_API_KEY_OLLAMA"
14
+ };
15
+ var EnvLoader = class {
16
+ /**
17
+ * 读取指定 provider 的 API Key 环境变量。
18
+ * 优先级:固定映射(如 AICLI_API_KEY_CLAUDE)> 动态格式(AICLI_API_KEY_<ID大写>)
19
+ * 自定义 provider 示例:id="siliconflow" → 读取 AICLI_API_KEY_SILICONFLOW
20
+ */
21
+ static getApiKey(providerId) {
22
+ const fixedEnvVar = ENV_KEY_MAP[providerId];
23
+ const dynamicEnvVar = `AICLI_API_KEY_${providerId.toUpperCase().replace(/-/g, "_")}`;
24
+ if (fixedEnvVar && fixedEnvVar !== dynamicEnvVar) {
25
+ const fixedVal = process.env[fixedEnvVar];
26
+ const dynVal = process.env[dynamicEnvVar];
27
+ if (fixedVal && dynVal && fixedVal !== dynVal) {
28
+ process.stderr.write(`[warn] env var collision: ${fixedEnvVar} and ${dynamicEnvVar} have different values for provider "${providerId}". Using ${fixedEnvVar}.
29
+ `);
30
+ }
31
+ }
32
+ if (fixedEnvVar) {
33
+ const val = process.env[fixedEnvVar];
34
+ if (val) return val;
35
+ }
36
+ return process.env[dynamicEnvVar] || void 0;
37
+ }
38
+ static getDefaultProvider() {
39
+ return process.env["AICLI_PROVIDER"] || void 0;
40
+ }
41
+ static isStreamingDisabled() {
42
+ return process.env["AICLI_NO_STREAM"] === "1";
43
+ }
44
+ /** Google Custom Search Engine ID (cx) 环境变量 */
45
+ static getGoogleSearchEngineId() {
46
+ return process.env["AICLI_GOOGLE_CX"] || void 0;
47
+ }
48
+ };
49
+
50
+ // src/core/errors.ts
51
+ var AiCliError = class extends Error {
52
+ constructor(message, options) {
53
+ super(message, options);
54
+ this.name = "AiCliError";
55
+ }
56
+ };
57
+ var ProviderError = class extends AiCliError {
58
+ constructor(providerId, message, cause) {
59
+ super(`[${providerId}] ${message}`, cause !== void 0 ? { cause } : void 0);
60
+ this.providerId = providerId;
61
+ this.name = "ProviderError";
62
+ }
63
+ };
64
+ var AuthError = class extends ProviderError {
65
+ constructor(providerId) {
66
+ super(providerId, "Invalid or missing API key. Run: ai-cli config");
67
+ this.name = "AuthError";
68
+ }
69
+ };
70
+ var RateLimitError = class extends ProviderError {
71
+ constructor(providerId) {
72
+ super(providerId, "Rate limit exceeded. Please wait before trying again.");
73
+ this.name = "RateLimitError";
74
+ }
75
+ };
76
+ var ConfigError = class extends AiCliError {
77
+ constructor(message) {
78
+ super(message);
79
+ this.name = "ConfigError";
80
+ }
81
+ };
82
+ var ProviderNotFoundError = class extends AiCliError {
83
+ constructor(providerId) {
84
+ super(
85
+ `Provider '${providerId}' is not configured. Run: ai-cli config`
86
+ );
87
+ this.name = "ProviderNotFoundError";
88
+ }
89
+ };
90
+ var ToolError = class extends AiCliError {
91
+ constructor(toolName, message, cause) {
92
+ super(`[${toolName}] ${message}`, cause !== void 0 ? { cause } : void 0);
93
+ this.toolName = toolName;
94
+ this.name = "ToolError";
95
+ }
96
+ };
97
+ var NetworkError = class extends AiCliError {
98
+ constructor(message, statusCode, cause) {
99
+ super(message, cause !== void 0 ? { cause } : void 0);
100
+ this.statusCode = statusCode;
101
+ this.name = "NetworkError";
102
+ }
103
+ };
104
+
105
+ export {
106
+ EnvLoader,
107
+ ProviderError,
108
+ AuthError,
109
+ RateLimitError,
110
+ ConfigError,
111
+ ProviderNotFoundError,
112
+ ToolError,
113
+ NetworkError
114
+ };
@@ -6,7 +6,7 @@ import { platform } from "os";
6
6
  import chalk from "chalk";
7
7
 
8
8
  // src/core/constants.ts
9
- var VERSION = "0.4.72";
9
+ var VERSION = "0.4.73";
10
10
  var APP_NAME = "ai-cli";
11
11
  var CONFIG_DIR_NAME = ".aicli";
12
12
  var CONFIG_FILE_NAME = "config.json";
@@ -2,15 +2,22 @@
2
2
  import {
3
3
  fileCheckpoints
4
4
  } from "./chunk-4BKXL7SM.js";
5
+ import {
6
+ runTestsTool
7
+ } from "./chunk-HAOCJWW2.js";
8
+ import {
9
+ EnvLoader,
10
+ NetworkError,
11
+ ToolError
12
+ } from "./chunk-2ZD3YTVM.js";
5
13
  import {
6
14
  CONFIG_DIR_NAME,
7
15
  DEFAULT_MAX_TOOL_OUTPUT_CHARS_CAP,
8
16
  MEMORY_FILE_NAME,
9
17
  SUBAGENT_ALLOWED_TOOLS,
10
18
  SUBAGENT_DEFAULT_MAX_ROUNDS,
11
- SUBAGENT_MAX_ROUNDS_LIMIT,
12
- runTestsTool
13
- } from "./chunk-73UI5AH7.js";
19
+ SUBAGENT_MAX_ROUNDS_LIMIT
20
+ } from "./chunk-T2OUKQOX.js";
14
21
 
15
22
  // src/tools/builtin/bash.ts
16
23
  import { execSync } from "child_process";
@@ -133,61 +140,6 @@ var UndoStack = class {
133
140
  };
134
141
  var undoStack = new UndoStack();
135
142
 
136
- // src/core/errors.ts
137
- var AiCliError = class extends Error {
138
- constructor(message, options) {
139
- super(message, options);
140
- this.name = "AiCliError";
141
- }
142
- };
143
- var ProviderError = class extends AiCliError {
144
- constructor(providerId, message, cause) {
145
- super(`[${providerId}] ${message}`, cause !== void 0 ? { cause } : void 0);
146
- this.providerId = providerId;
147
- this.name = "ProviderError";
148
- }
149
- };
150
- var AuthError = class extends ProviderError {
151
- constructor(providerId) {
152
- super(providerId, "Invalid or missing API key. Run: ai-cli config");
153
- this.name = "AuthError";
154
- }
155
- };
156
- var RateLimitError = class extends ProviderError {
157
- constructor(providerId) {
158
- super(providerId, "Rate limit exceeded. Please wait before trying again.");
159
- this.name = "RateLimitError";
160
- }
161
- };
162
- var ConfigError = class extends AiCliError {
163
- constructor(message) {
164
- super(message);
165
- this.name = "ConfigError";
166
- }
167
- };
168
- var ProviderNotFoundError = class extends AiCliError {
169
- constructor(providerId) {
170
- super(
171
- `Provider '${providerId}' is not configured. Run: ai-cli config`
172
- );
173
- this.name = "ProviderNotFoundError";
174
- }
175
- };
176
- var ToolError = class extends AiCliError {
177
- constructor(toolName, message, cause) {
178
- super(`[${toolName}] ${message}`, cause !== void 0 ? { cause } : void 0);
179
- this.toolName = toolName;
180
- this.name = "ToolError";
181
- }
182
- };
183
- var NetworkError = class extends AiCliError {
184
- constructor(message, statusCode, cause) {
185
- super(message, cause !== void 0 ? { cause } : void 0);
186
- this.statusCode = statusCode;
187
- this.name = "NetworkError";
188
- }
189
- };
190
-
191
143
  // src/tools/builtin/bash.ts
192
144
  var IS_WINDOWS = platform() === "win32";
193
145
  var SHELL = IS_WINDOWS ? "powershell.exe" : process.env["SHELL"] ?? "/bin/bash";
@@ -3339,53 +3291,6 @@ function renderTodoList(todos) {
3339
3291
  console.log();
3340
3292
  }
3341
3293
 
3342
- // src/config/env-loader.ts
3343
- var ENV_KEY_MAP = {
3344
- claude: "AICLI_API_KEY_CLAUDE",
3345
- gemini: "AICLI_API_KEY_GEMINI",
3346
- deepseek: "AICLI_API_KEY_DEEPSEEK",
3347
- zhipu: "AICLI_API_KEY_ZHIPU",
3348
- kimi: "AICLI_API_KEY_KIMI",
3349
- openai: "AICLI_API_KEY_OPENAI",
3350
- openrouter: "AICLI_API_KEY_OPENROUTER",
3351
- "google-search": "AICLI_API_KEY_GOOGLESEARCH",
3352
- ollama: "AICLI_API_KEY_OLLAMA"
3353
- };
3354
- var EnvLoader = class {
3355
- /**
3356
- * 读取指定 provider 的 API Key 环境变量。
3357
- * 优先级:固定映射(如 AICLI_API_KEY_CLAUDE)> 动态格式(AICLI_API_KEY_<ID大写>)
3358
- * 自定义 provider 示例:id="siliconflow" → 读取 AICLI_API_KEY_SILICONFLOW
3359
- */
3360
- static getApiKey(providerId) {
3361
- const fixedEnvVar = ENV_KEY_MAP[providerId];
3362
- const dynamicEnvVar = `AICLI_API_KEY_${providerId.toUpperCase().replace(/-/g, "_")}`;
3363
- if (fixedEnvVar && fixedEnvVar !== dynamicEnvVar) {
3364
- const fixedVal = process.env[fixedEnvVar];
3365
- const dynVal = process.env[dynamicEnvVar];
3366
- if (fixedVal && dynVal && fixedVal !== dynVal) {
3367
- process.stderr.write(`[warn] env var collision: ${fixedEnvVar} and ${dynamicEnvVar} have different values for provider "${providerId}". Using ${fixedEnvVar}.
3368
- `);
3369
- }
3370
- }
3371
- if (fixedEnvVar) {
3372
- const val = process.env[fixedEnvVar];
3373
- if (val) return val;
3374
- }
3375
- return process.env[dynamicEnvVar] || void 0;
3376
- }
3377
- static getDefaultProvider() {
3378
- return process.env["AICLI_PROVIDER"] || void 0;
3379
- }
3380
- static isStreamingDisabled() {
3381
- return process.env["AICLI_NO_STREAM"] === "1";
3382
- }
3383
- /** Google Custom Search Engine ID (cx) 环境变量 */
3384
- static getGoogleSearchEngineId() {
3385
- return process.env["AICLI_GOOGLE_CX"] || void 0;
3386
- }
3387
- };
3388
-
3389
3294
  // src/tools/builtin/google-search.ts
3390
3295
  var GOOGLE_SEARCH_API = "https://www.googleapis.com/customsearch/v1";
3391
3296
  var REQUEST_TIMEOUT_MS = 15e3;
@@ -4614,12 +4519,6 @@ var ToolRegistry = class {
4614
4519
  };
4615
4520
 
4616
4521
  export {
4617
- EnvLoader,
4618
- ProviderError,
4619
- AuthError,
4620
- RateLimitError,
4621
- ConfigError,
4622
- ProviderNotFoundError,
4623
4522
  getDangerLevel,
4624
4523
  schemaToJsonSchema,
4625
4524
  initTheme,
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ TEST_TIMEOUT
4
+ } from "./chunk-T2OUKQOX.js";
2
5
 
3
6
  // src/tools/builtin/run-tests.ts
4
7
  import { execSync } from "child_process";
@@ -6,126 +9,6 @@ import { existsSync, readFileSync, readdirSync } from "fs";
6
9
  import { join } from "path";
7
10
  import { platform } from "os";
8
11
  import chalk from "chalk";
9
-
10
- // src/core/constants.ts
11
- var VERSION = "0.4.72";
12
- var APP_NAME = "ai-cli";
13
- var CONFIG_DIR_NAME = ".aicli";
14
- var CONFIG_FILE_NAME = "config.json";
15
- var HISTORY_DIR_NAME = "history";
16
- var PLUGINS_DIR_NAME = "plugins";
17
- var SKILLS_DIR_NAME = "skills";
18
- var CUSTOM_COMMANDS_DIR_NAME = "commands";
19
- var CONTEXT_FILE_CANDIDATES = ["AICLI.md", "CLAUDE.md"];
20
- var MEMORY_FILE_NAME = "memory.md";
21
- var MEMORY_MAX_CHARS = 1e4;
22
- var DEV_STATE_FILE_NAME = "dev-state.md";
23
- var DEFAULT_MAX_TOKENS = 8192;
24
- var DEFAULT_MAX_TOOL_ROUNDS = 200;
25
- var DEFAULT_MAX_TOOL_OUTPUT_CHARS_CAP = 5e5;
26
- var MCP_TOOL_PREFIX = "mcp__";
27
- var MCP_PROJECT_CONFIG_NAME = ".mcp.json";
28
- var MCP_CONNECT_TIMEOUT = 3e4;
29
- var MCP_CALL_TIMEOUT = 6e4;
30
- var MCP_PROTOCOL_VERSION = "2024-11-05";
31
- var PLAN_MODE_READONLY_TOOLS = /* @__PURE__ */ new Set([
32
- "read_file",
33
- "list_dir",
34
- "grep_files",
35
- "glob_files",
36
- "web_fetch",
37
- "google_search",
38
- "ask_user",
39
- // 允许:可向用户澄清需求
40
- "write_todos"
41
- // 允许:可输出任务列表作为实施计划
42
- ]);
43
- var PLAN_MODE_SYSTEM_ADDON = `# \u{1F50D} Plan Mode \u2014 Read-Only Planning Mode
44
-
45
- You are currently in read-only planning (Plan) mode.
46
-
47
- **Allowed tools**: read_file \xB7 list_dir \xB7 grep_files \xB7 glob_files \xB7 web_fetch \xB7 google_search \xB7 ask_user \xB7 write_todos
48
- **Disabled tools**: bash \xB7 write_file \xB7 edit_file \xB7 run_interactive \xB7 save_last_response \xB7 save_memory and all MCP tools
49
-
50
- **Your task**:
51
- 1. Use read-only tools to thoroughly analyze the codebase, file structure, and existing implementation
52
- 2. Use ask_user to clarify any ambiguous requirements with the user
53
- 3. Develop a detailed implementation plan (you may use write_todos to present the task list), including:
54
- - List of files to be modified or created
55
- - Specific changes for each file
56
- - Execution order and dependencies
57
- - Potential risks and considerations
58
-
59
- **CRITICAL RULES**:
60
- - Do NOT attempt to call bash, write_file, edit_file, or any disabled tool \u2014 they will fail silently.
61
- - Do NOT write shell commands, SQL queries, or code in your text response as a substitute for tool calls \u2014 the user's system will misinterpret this as a pseudo-tool-call error.
62
- - If the user asks you to run commands, test connections, or modify files, respond with: "This requires execution tools. Please type \`/plan execute\` to switch to execute mode, then I can perform these operations."
63
- - Do NOT call write_todos repeatedly with the same content \u2014 call it once, then give a text response.
64
- - Focus your analysis on reading files and producing actionable plans.
65
-
66
- Once planning is complete, clearly inform the user: type \`/plan execute\` to begin executing the plan, or \`/plan exit\` to discard it.`;
67
- var SUBAGENT_DEFAULT_MAX_ROUNDS = 15;
68
- var SUBAGENT_MAX_ROUNDS_LIMIT = 30;
69
- var SUBAGENT_ALLOWED_TOOLS = /* @__PURE__ */ new Set([
70
- "bash",
71
- "read_file",
72
- "write_file",
73
- "edit_file",
74
- "list_dir",
75
- "grep_files",
76
- "glob_files",
77
- "run_interactive",
78
- "web_fetch",
79
- "google_search",
80
- "write_todos",
81
- "run_tests"
82
- ]);
83
- var CONTEXT_PRESSURE_THRESHOLD = 0.8;
84
- var TEST_TIMEOUT = 3e5;
85
- var AGENTIC_BEHAVIOR_GUIDELINE = `# Important Behavioral Guidelines
86
-
87
- **Respond appropriately to the user's intent \u2014 do NOT over-react**:
88
- - For **greetings and casual chat** (e.g., "hello", "hi", "hey", "\u4F60\u597D", "what's up"): respond naturally with a friendly greeting. Do NOT use any tools. Do NOT explore directories, read files, or start any project work. Just chat.
89
- - When the user asks you to "read", "understand", "review", "analyze", "examine", or "look at" files or a project, your task is only to **read and summarize**, then wait for the user's next instruction. Do not automatically start executing tasks described in the project.
90
- - Only begin using write/execute tools when the user **explicitly requests** an action (e.g., "generate", "create", "modify", "run", "start", etc.).
91
- - Project context files (CLAUDE.md, AICLI.md) provide background information about the project. They are NOT instructions to start working. Only use them as reference when the user asks a project-related question or task.
92
- - If you are unsure about the user's intent, use the ask_user tool to confirm with the user, rather than assuming and executing on your own.
93
- - **Do NOT abuse ask_user for redundant confirmations**: When the user has already given a clear, explicit instruction (e.g., "write lesson 142", "generate file X", "create the report"), execute it immediately. Do NOT ask "are you sure?" or request details that can be found in project documents. Repeatedly asking the user to confirm wastes their time and is extremely frustrating. Only use ask_user when critical information is genuinely missing and cannot be inferred from context files.`;
94
- function buildUserIdentityPrompt(profile) {
95
- const lines = [];
96
- const displayName = profile.nickname || profile.name;
97
- if (displayName) {
98
- lines.push(`The user's name is **${profile.name || displayName}**${profile.nickname && profile.name ? ` (prefers to be called **${profile.nickname}**)` : ""}.`);
99
- }
100
- if (profile.role) {
101
- lines.push(`Role: ${profile.role}.`);
102
- }
103
- if (profile.bio) {
104
- lines.push(`About: ${profile.bio}`);
105
- }
106
- if (profile.interests && profile.interests.length > 0) {
107
- lines.push(`Interests & expertise: ${profile.interests.join(", ")}.`);
108
- }
109
- if (profile.locale) {
110
- lines.push(`Preferred language: ${profile.locale}. Please respond in this language unless the user explicitly uses another language.`);
111
- }
112
- if (profile.extra) {
113
- lines.push(`
114
- ${profile.extra}`);
115
- }
116
- if (lines.length === 0) return null;
117
- return `# Who You're Talking To
118
-
119
- ${lines.join("\n")}
120
-
121
- Address the user personally and adapt your communication style to their background. This identity persists across all conversations and all AI providers.`;
122
- }
123
- var AUTHOR = "Jin Zhengdong";
124
- var AUTHOR_EMAIL = "zhengdong.jin@gmail.com";
125
- var DESCRIPTION = "Cross-platform REPL-style AI conversation tool with multi-provider and agentic tool calling support";
126
- var REPO_URL = "https://github.com/jinzhengdong/ai-cli";
127
-
128
- // src/tools/builtin/run-tests.ts
129
12
  var IS_WINDOWS = platform() === "win32";
130
13
  function detectNodeTestFramework(cwd, pkg) {
131
14
  const devDeps = pkg.devDependencies ?? {};
@@ -480,38 +363,6 @@ var runTestsTool = {
480
363
  };
481
364
 
482
365
  export {
483
- VERSION,
484
- APP_NAME,
485
- CONFIG_DIR_NAME,
486
- CONFIG_FILE_NAME,
487
- HISTORY_DIR_NAME,
488
- PLUGINS_DIR_NAME,
489
- SKILLS_DIR_NAME,
490
- CUSTOM_COMMANDS_DIR_NAME,
491
- CONTEXT_FILE_CANDIDATES,
492
- MEMORY_FILE_NAME,
493
- MEMORY_MAX_CHARS,
494
- DEV_STATE_FILE_NAME,
495
- DEFAULT_MAX_TOKENS,
496
- DEFAULT_MAX_TOOL_ROUNDS,
497
- DEFAULT_MAX_TOOL_OUTPUT_CHARS_CAP,
498
- MCP_TOOL_PREFIX,
499
- MCP_PROJECT_CONFIG_NAME,
500
- MCP_CONNECT_TIMEOUT,
501
- MCP_CALL_TIMEOUT,
502
- MCP_PROTOCOL_VERSION,
503
- PLAN_MODE_READONLY_TOOLS,
504
- PLAN_MODE_SYSTEM_ADDON,
505
- SUBAGENT_DEFAULT_MAX_ROUNDS,
506
- SUBAGENT_MAX_ROUNDS_LIMIT,
507
- SUBAGENT_ALLOWED_TOOLS,
508
- CONTEXT_PRESSURE_THRESHOLD,
509
- AGENTIC_BEHAVIOR_GUIDELINE,
510
- buildUserIdentityPrompt,
511
- AUTHOR,
512
- AUTHOR_EMAIL,
513
- DESCRIPTION,
514
- REPO_URL,
515
366
  executeTests,
516
367
  runTestsTool
517
368
  };