jinzd-ai-cli 0.4.118 → 0.4.119
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.
- package/dist/{batch-AZ55FS2U.js → batch-7QSGU2F3.js} +2 -2
- package/dist/chunk-2OMBLQP6.js +186 -0
- package/dist/{chunk-W622HYR2.js → chunk-4QMGQO4P.js} +1 -1
- package/dist/{chunk-LO4MSGGO.js → chunk-BS7EUZSO.js} +1 -1
- package/dist/chunk-DIOSW6R4.js +1728 -0
- package/dist/{chunk-Z6BSKKF6.js → chunk-M36KRNHE.js} +14 -1728
- package/dist/{chunk-3YUH5CCS.js → chunk-SWOK6GDC.js} +1 -1
- package/dist/chunk-SYF3BPZK.js +166 -0
- package/dist/{chunk-267DHNV2.js → chunk-UVKO7T4I.js} +1 -1
- package/dist/{chunk-7QZOLJ2R.js → chunk-VYTV2VP7.js} +13 -64
- package/dist/{constants-H7Q7BTHA.js → constants-QVAT2SUA.js} +1 -1
- package/dist/doctor-cli-RZC5PSDE.js +171 -0
- package/dist/electron-server.js +309 -192
- package/dist/{hub-TGZYNCE6.js → hub-SODOTZRX.js} +1 -1
- package/dist/index.js +99 -26
- package/dist/{run-tests-CQME3NR3.js → run-tests-3ZLFXP7F.js} +1 -1
- package/dist/{run-tests-G22G7UMT.js → run-tests-CDY775VC.js} +2 -2
- package/dist/{server-KLAINAR5.js → server-C6Z6TVTZ.js} +47 -21
- package/dist/{server-7NVVJSNQ.js → server-HMJTQCKI.js} +10 -7
- package/dist/{task-orchestrator-BZS2GA2Q.js → task-orchestrator-SDFF4CQ7.js} +8 -5
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ConfigManager
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UVKO7T4I.js";
|
|
5
5
|
import "./chunk-2ZD3YTVM.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-BS7EUZSO.js";
|
|
7
7
|
import "./chunk-PDX44BCA.js";
|
|
8
8
|
|
|
9
9
|
// src/cli/batch.ts
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CONFIG_DIR_NAME
|
|
4
|
+
} from "./chunk-BS7EUZSO.js";
|
|
5
|
+
|
|
6
|
+
// src/diagnostics/tool-stats.ts
|
|
7
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, renameSync } from "fs";
|
|
8
|
+
import { join, dirname } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
var STATS_FILE_NAME = "tool-stats.json";
|
|
11
|
+
var STATS_VERSION = 1;
|
|
12
|
+
var FLUSH_EVERY_N = 50;
|
|
13
|
+
var state = null;
|
|
14
|
+
var dirty = false;
|
|
15
|
+
var pendingWrites = 0;
|
|
16
|
+
var configDirOverride;
|
|
17
|
+
function statsFilePath() {
|
|
18
|
+
const base = configDirOverride ?? join(homedir(), CONFIG_DIR_NAME);
|
|
19
|
+
return join(base, STATS_FILE_NAME);
|
|
20
|
+
}
|
|
21
|
+
function load() {
|
|
22
|
+
const path = statsFilePath();
|
|
23
|
+
if (!existsSync(path)) {
|
|
24
|
+
return { version: STATS_VERSION, startedAt: (/* @__PURE__ */ new Date()).toISOString(), entries: {} };
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
28
|
+
if (raw.version !== STATS_VERSION || !raw.entries) {
|
|
29
|
+
return { version: STATS_VERSION, startedAt: (/* @__PURE__ */ new Date()).toISOString(), entries: {} };
|
|
30
|
+
}
|
|
31
|
+
return raw;
|
|
32
|
+
} catch {
|
|
33
|
+
return { version: STATS_VERSION, startedAt: (/* @__PURE__ */ new Date()).toISOString(), entries: {} };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function ensureLoaded() {
|
|
37
|
+
if (state === null) state = load();
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
function recordToolCall(name, durationMs, ok, errorMessage) {
|
|
41
|
+
const s = ensureLoaded();
|
|
42
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
43
|
+
let entry = s.entries[name];
|
|
44
|
+
if (!entry) {
|
|
45
|
+
entry = {
|
|
46
|
+
name,
|
|
47
|
+
calls: 0,
|
|
48
|
+
failures: 0,
|
|
49
|
+
totalDurationMs: 0,
|
|
50
|
+
firstSeenAt: now,
|
|
51
|
+
lastUsedAt: now
|
|
52
|
+
};
|
|
53
|
+
s.entries[name] = entry;
|
|
54
|
+
}
|
|
55
|
+
entry.calls += 1;
|
|
56
|
+
entry.totalDurationMs += Math.max(0, Math.round(durationMs));
|
|
57
|
+
entry.lastUsedAt = now;
|
|
58
|
+
if (!ok) {
|
|
59
|
+
entry.failures += 1;
|
|
60
|
+
entry.lastFailureAt = now;
|
|
61
|
+
if (errorMessage) entry.lastFailureMessage = errorMessage.slice(0, 300);
|
|
62
|
+
}
|
|
63
|
+
dirty = true;
|
|
64
|
+
pendingWrites += 1;
|
|
65
|
+
if (pendingWrites >= FLUSH_EVERY_N) {
|
|
66
|
+
flush();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function runTool(tool, args, name) {
|
|
70
|
+
const start = Date.now();
|
|
71
|
+
try {
|
|
72
|
+
const result = await tool.execute(args);
|
|
73
|
+
recordToolCall(name, Date.now() - start, true);
|
|
74
|
+
return result;
|
|
75
|
+
} catch (err) {
|
|
76
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
+
recordToolCall(name, Date.now() - start, false, msg);
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function flush() {
|
|
82
|
+
if (!dirty || state === null) return;
|
|
83
|
+
const path = statsFilePath();
|
|
84
|
+
try {
|
|
85
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
86
|
+
const tmp = path + ".tmp";
|
|
87
|
+
writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
88
|
+
renameSync(tmp, path);
|
|
89
|
+
dirty = false;
|
|
90
|
+
pendingWrites = 0;
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function getStatsSnapshot() {
|
|
95
|
+
const s = ensureLoaded();
|
|
96
|
+
return Object.values(s.entries).map((e) => ({ ...e }));
|
|
97
|
+
}
|
|
98
|
+
function getTopFailingTools(limit = 5) {
|
|
99
|
+
return getStatsSnapshot().filter((e) => e.failures > 0).sort((a, b) => {
|
|
100
|
+
const rateA = a.failures / Math.max(1, a.calls);
|
|
101
|
+
const rateB = b.failures / Math.max(1, b.calls);
|
|
102
|
+
if (rateB !== rateA) return rateB - rateA;
|
|
103
|
+
return b.failures - a.failures;
|
|
104
|
+
}).slice(0, limit);
|
|
105
|
+
}
|
|
106
|
+
function getTopUsedTools(limit = 5) {
|
|
107
|
+
return getStatsSnapshot().sort((a, b) => b.calls - a.calls).slice(0, limit);
|
|
108
|
+
}
|
|
109
|
+
function resetStats() {
|
|
110
|
+
state = { version: STATS_VERSION, startedAt: (/* @__PURE__ */ new Date()).toISOString(), entries: {} };
|
|
111
|
+
dirty = true;
|
|
112
|
+
flush();
|
|
113
|
+
}
|
|
114
|
+
var exitHookInstalled = false;
|
|
115
|
+
function installFlushOnExit() {
|
|
116
|
+
if (exitHookInstalled) return;
|
|
117
|
+
exitHookInstalled = true;
|
|
118
|
+
process.on("exit", () => flush());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/tools/types.ts
|
|
122
|
+
function isFileWriteTool(name) {
|
|
123
|
+
return name === "write_file" || name === "edit_file" || name === "notebook_edit";
|
|
124
|
+
}
|
|
125
|
+
function getDangerLevel(toolName, args) {
|
|
126
|
+
if (toolName.startsWith("mcp__")) return "safe";
|
|
127
|
+
if (toolName === "bash") {
|
|
128
|
+
const cmd = String(args["command"] ?? "");
|
|
129
|
+
if (/\brm\s+[^\n]*(?:-\w*[rRfF]\w*|--recursive|--force)\b/.test(cmd)) return "destructive";
|
|
130
|
+
if (/\brm\s+\S/.test(cmd)) return "destructive";
|
|
131
|
+
if (/\brmdir\b|\bformat\b|\bmkfs\b|\bdd\s+if=|\bshred\b|\bfdisk\b|\bparted\b/.test(cmd)) return "destructive";
|
|
132
|
+
if (/\bshutdown\b|\breboot\b|\bhalt\b|\bpoweroff\b/.test(cmd)) return "destructive";
|
|
133
|
+
if (/\bkill\s+-9\b|\bkillall\b/.test(cmd)) return "destructive";
|
|
134
|
+
if (/\bRemove-Item\b|\bri\s+\S/i.test(cmd)) return "destructive";
|
|
135
|
+
if (/\brd\s+\/s\b|\brmdir\s+\/s\b/i.test(cmd)) return "destructive";
|
|
136
|
+
if (/\bdel\s+\S/.test(cmd)) return "destructive";
|
|
137
|
+
if (/\bShutdown(-Computer)?\b|\bRestart-Computer\b/i.test(cmd)) return "destructive";
|
|
138
|
+
if (/(?:^|[\s|;&])>>?\s*\S/.test(cmd)) return "write";
|
|
139
|
+
if (/\btee\b|\bcp\b|\bmv\b|\bln\s+-s/.test(cmd)) return "write";
|
|
140
|
+
if (/\bchmod\b|\bchown\b/.test(cmd)) return "write";
|
|
141
|
+
if (/\bSet-Content\b|\bOut-File\b|\bAdd-Content\b|\bCopy-Item\b|\bMove-Item\b|\bSet-ItemProperty\b|\bNew-ItemProperty\b/i.test(cmd)) return "write";
|
|
142
|
+
return "safe";
|
|
143
|
+
}
|
|
144
|
+
if (toolName === "write_file") return "write";
|
|
145
|
+
if (toolName === "edit_file") return "write";
|
|
146
|
+
if (toolName === "save_last_response") return "write";
|
|
147
|
+
if (toolName === "run_interactive") {
|
|
148
|
+
const exe = String(args["executable"] ?? "").toLowerCase();
|
|
149
|
+
if (/\b(rm|rmdir|del|format|mkfs|Remove-Item)\b/i.test(exe)) return "destructive";
|
|
150
|
+
if (/\b(bash|sh|zsh|cmd|powershell|pwsh|python|node|ruby|perl)\b/i.test(exe)) return "write";
|
|
151
|
+
return "write";
|
|
152
|
+
}
|
|
153
|
+
if (toolName === "task_create" || toolName === "task_stop") return "write";
|
|
154
|
+
if (toolName === "task_list") return "safe";
|
|
155
|
+
if (toolName === "git_commit") return "write";
|
|
156
|
+
if (toolName === "git_status" || toolName === "git_diff" || toolName === "git_log") return "safe";
|
|
157
|
+
if (toolName === "notebook_edit") return "write";
|
|
158
|
+
if (toolName === "read_file" || toolName === "list_dir" || toolName === "grep_files" || toolName === "glob_files" || toolName === "web_fetch" || toolName === "save_memory" || toolName === "ask_user" || toolName === "write_todos" || toolName === "google_search" || toolName === "spawn_agent" || toolName === "run_tests") return "safe";
|
|
159
|
+
return "write";
|
|
160
|
+
}
|
|
161
|
+
function schemaToJsonSchema(schema) {
|
|
162
|
+
const result = {
|
|
163
|
+
type: schema.type,
|
|
164
|
+
description: schema.description
|
|
165
|
+
};
|
|
166
|
+
if (schema.enum) result["enum"] = schema.enum;
|
|
167
|
+
if (schema.items) result["items"] = schemaToJsonSchema(schema.items);
|
|
168
|
+
if (schema.properties) {
|
|
169
|
+
result["properties"] = Object.fromEntries(
|
|
170
|
+
Object.entries(schema.properties).map(([k, v]) => [k, schemaToJsonSchema(v)])
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
runTool,
|
|
178
|
+
getStatsSnapshot,
|
|
179
|
+
getTopFailingTools,
|
|
180
|
+
getTopUsedTools,
|
|
181
|
+
resetStats,
|
|
182
|
+
installFlushOnExit,
|
|
183
|
+
isFileWriteTool,
|
|
184
|
+
getDangerLevel,
|
|
185
|
+
schemaToJsonSchema
|
|
186
|
+
};
|