@cjhyy/code-shell 0.1.0-alpha.3 → 0.1.6
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/CHANGELOG.md +107 -0
- package/dist/anthropic-IBTI4WL2.cjs +10 -0
- package/dist/anthropic-PRZZKHEZ.js +10 -0
- package/dist/arena/index.cjs +7 -6
- package/dist/arena/index.js +6 -5
- package/dist/arena/model-presets.d.ts +10 -1
- package/dist/{arena-ENHBHB2W.js → arena-2LTLIXOL.js} +9 -7
- package/dist/{arena-HHDYYVHJ.cjs → arena-ADB7DRFI.cjs} +25 -23
- package/dist/{chunk-EL2RL5DG.cjs → chunk-2YW4FPFG.cjs} +2 -2
- package/dist/chunk-3OA5G4TM.js +47 -0
- package/dist/{chunk-FPFTIKEJ.js → chunk-3QO25N6E.js} +131 -173
- package/dist/chunk-3SBSUOWZ.js +447 -0
- package/dist/chunk-52LGZKT3.cjs +47 -0
- package/dist/{chunk-KOGV6PDQ.cjs → chunk-55XGPMAP.cjs} +44 -9
- package/dist/{chunk-YD7XTI7T.cjs → chunk-6QVAYW7C.cjs} +116 -28
- package/dist/{chunk-SCDKLTN3.js → chunk-6S4BJ65N.js} +5 -4
- package/dist/{chunk-ZLPJJZUW.js → chunk-76HYEPDM.js} +2 -2
- package/dist/chunk-7BI3V74Y.cjs +447 -0
- package/dist/{chunk-GZBD6QRS.cjs → chunk-7EG3V4JY.cjs} +13 -12
- package/dist/{chunk-LMEKCQX4.js → chunk-7JVTYEEC.js} +6 -6
- package/dist/{chunk-SW3L7HIM.js → chunk-7QIM3BKD.js} +2 -2
- package/dist/{chunk-5C5HIOML.js → chunk-7Y6S3OCX.js} +109 -21
- package/dist/{chunk-REFCCVDM.js → chunk-ABRRONJ7.js} +2 -2
- package/dist/{chunk-F5BS3GUC.js → chunk-BSW22MPA.js} +39 -4
- package/dist/{chunk-ZRVPCXI7.js → chunk-BXCY2FSE.js} +2 -1
- package/dist/{chunk-Y7TSCDF6.js → chunk-BZ5TNE7L.js} +347 -6
- package/dist/{chunk-X2DNIMPC.cjs → chunk-DDB6QOKJ.cjs} +32 -32
- package/dist/{chunk-C7C7ZZY4.cjs → chunk-HEKQCI7B.cjs} +10 -10
- package/dist/{chunk-JHNCK7JP.cjs → chunk-IK4EWJBP.cjs} +4 -3
- package/dist/{chunk-3CAZIWUA.cjs → chunk-ILHE7XLT.cjs} +9 -9
- package/dist/{chunk-M2QI5X3X.cjs → chunk-JMR33QVF.cjs} +2 -2
- package/dist/{chunk-TDXBHD24.js → chunk-KAQHULYN.js} +2 -2
- package/dist/chunk-KE4EQOWA.js +294 -0
- package/dist/{chunk-YAFCN7ZW.cjs → chunk-KOVYSDHZ.cjs} +15 -15
- package/dist/{chunk-IJSHQGMP.cjs → chunk-KS3RYAYL.cjs} +4 -4
- package/dist/{chunk-DI7RDLOS.js → chunk-MD32R22I.js} +7 -4
- package/dist/chunk-MV7YI4WO.cjs +293 -0
- package/dist/chunk-MY5XHADU.cjs +216 -0
- package/dist/{chunk-OP57WUWQ.cjs → chunk-NUNC3VFB.cjs} +6 -6
- package/dist/{chunk-ID6EJUHP.js → chunk-PKGRTCCY.js} +1307 -212
- package/dist/{chunk-OUC2DFA7.js → chunk-QARL3IDQ.js} +3 -3
- package/dist/{chunk-VIPLU4RY.cjs → chunk-S754JHLR.cjs} +4 -4
- package/dist/{chunk-FUOKLKR2.js → chunk-SFXHZSRF.js} +1 -1
- package/dist/{chunk-2EUAE7AY.js → chunk-SIHHIQLO.js} +2 -2
- package/dist/{chunk-SK62UVS6.js → chunk-T6VYG46N.js} +1 -1
- package/dist/{chunk-JHXNOB5G.cjs → chunk-TNLGBJYS.cjs} +6 -6
- package/dist/{chunk-3QR52LL5.cjs → chunk-TUY2T5KP.cjs} +2 -2
- package/dist/{chunk-VWFET3MG.cjs → chunk-UXOCVJJ6.cjs} +1519 -424
- package/dist/{chunk-I57ZD5IQ.js → chunk-VIAGTYYW.js} +1 -1
- package/dist/chunk-WASS5YWB.js +215 -0
- package/dist/{chunk-HOXQLX5R.cjs → chunk-WZJV6DJC.cjs} +444 -103
- package/dist/{chunk-BUJ5KYCI.cjs → chunk-YIQBXAYU.cjs} +13 -13
- package/dist/{chunk-BF4LXLQV.cjs → chunk-YKIAELDZ.cjs} +132 -174
- package/dist/{chunk-M2SVOKC6.js → chunk-ZBPSQCPU.js} +6 -6
- package/dist/cli/commands/builtin/export-md.d.ts +19 -0
- package/dist/cli/commands/builtin/init/detect.d.ts +25 -0
- package/dist/cli/commands/builtin/init/index.d.ts +19 -0
- package/dist/cli/main.cjs +2372 -1453
- package/dist/cli/main.js +2502 -1583
- package/dist/cli/migrate-models.d.ts +45 -0
- package/dist/cli/onboarding.d.ts +110 -5
- package/dist/cli/updater.d.ts +59 -4
- package/dist/client-base-HTF236ZD.cjs +9 -0
- package/dist/client-base-QKRKCOWB.js +9 -0
- package/dist/{compaction-YNWCEF7B.js → compaction-6VU2T643.js} +4 -2
- package/dist/compaction-OKUNTCA7.cjs +33 -0
- package/dist/context/compaction.d.ts +35 -3
- package/dist/context/manager.d.ts +40 -3
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/devtools-T2NIZBJK.cjs +6 -0
- package/dist/{devtools-IRQQPIRY.js → devtools-YXWHOVKR.js} +1 -1
- package/dist/engine/engine.d.ts +47 -0
- package/dist/engine/turn-loop.d.ts +6 -0
- package/dist/export-md-RXDW6F5W.cjs +135 -0
- package/dist/export-md-XXKZANW5.js +135 -0
- package/dist/file-history-KYPE3ECT.cjs +7 -0
- package/dist/file-history-LF4F7X26.js +7 -0
- package/dist/index.cjs +42 -22
- package/dist/index.d.ts +5 -2
- package/dist/index.js +38 -18
- package/dist/llm/client-base.d.ts +1 -1
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-pool.d.ts +13 -0
- package/dist/llm/provider-catalog.d.ts +30 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/types.d.ts +8 -0
- package/dist/logging/session-recorder.d.ts +77 -0
- package/dist/manager-D65VFAPX.js +7 -0
- package/dist/manager-TTF5VHJC.cjs +7 -0
- package/dist/mcp-manager-QMKWPBZ4.js +8 -0
- package/dist/mcp-manager-Z3OKI74O.cjs +8 -0
- package/dist/memory-5LWZ6FI2.cjs +9 -0
- package/dist/{memory-EPFDBPII.js → memory-VIJLBAMQ.js} +2 -2
- package/dist/model-cache-5KIYL5SL.js +13 -0
- package/dist/model-cache-OED3IM4R.cjs +13 -0
- package/dist/model-fetcher-HKGICACL.js +8 -0
- package/dist/model-fetcher-UR6WJOQP.cjs +8 -0
- package/dist/openai-JR2WEKOF.js +10 -0
- package/dist/openai-YBTOET4O.cjs +10 -0
- package/dist/{openrouter-models-2FM3H4SQ.js → openrouter-models-H56GHBHN.js} +2 -2
- package/dist/openrouter-models-TWUFWZ5T.cjs +15 -0
- package/dist/openrouter-sync-5VMGN6C2.cjs +11 -0
- package/dist/{openrouter-sync-SO3AWEAM.js → openrouter-sync-ALEMF5IU.js} +3 -3
- package/dist/product/index.cjs +17 -15
- package/dist/product/index.js +16 -14
- package/dist/protocol/server.d.ts +3 -1
- package/dist/protocol/types.d.ts +36 -2
- package/dist/run/index.cjs +17 -15
- package/dist/run/index.js +16 -14
- package/dist/services/index.d.ts +0 -1
- package/dist/session-manager-Q22BBMD3.js +8 -0
- package/dist/session-manager-XODQVL3C.cjs +8 -0
- package/dist/settings/schema.d.ts +267 -42
- package/dist/{tool-summary-RYNR4DDB.cjs → tool-summary-63DPIS7G.cjs} +4 -4
- package/dist/{tool-summary-2RUFL5QK.js → tool-summary-NP5CDBKG.js} +2 -2
- package/dist/tool-system/builtin/ask-user.d.ts +9 -1
- package/dist/tool-system/context.d.ts +31 -2
- package/dist/tool-system/executor.d.ts +4 -0
- package/dist/tool-system/investigation-guard.d.ts +46 -0
- package/dist/types.d.ts +13 -2
- package/dist/ui/components/AskUserPrompt.d.ts +8 -1
- package/dist/ui/components/DiffLine.d.ts +33 -0
- package/dist/ui/components/ModelManager.d.ts +34 -1
- package/dist/ui/components/OnboardingPrompt.d.ts +10 -1
- package/dist/ui/components/ProviderModelFlow.d.ts +58 -0
- package/dist/ui/components/UpdateBanner.d.ts +1 -0
- package/dist/updater-I7QBW4DP.cjs +17 -0
- package/dist/updater-NVME5S3Z.js +17 -0
- package/dist/utils/semver.d.ts +1 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/package.json +2 -1
- package/skills-builtin/codeshell-help.md +135 -0
- package/dist/anthropic-P5VETAFI.cjs +0 -10
- package/dist/anthropic-W2GU3D76.js +0 -10
- package/dist/chunk-75E4BBFC.js +0 -224
- package/dist/chunk-FV2ARONZ.cjs +0 -224
- package/dist/client-base-TOVE25FA.js +0 -9
- package/dist/client-base-VDDIADAC.cjs +0 -9
- package/dist/compaction-D3KV2NWY.cjs +0 -31
- package/dist/devtools-WTC3NFNE.cjs +0 -6
- package/dist/file-history-HZWO2WQ5.js +0 -7
- package/dist/file-history-UQQILIY7.cjs +0 -7
- package/dist/manager-FWLOVEEK.cjs +0 -7
- package/dist/manager-GEXJLOIS.js +0 -7
- package/dist/mcp-manager-37GQLFGX.js +0 -8
- package/dist/mcp-manager-U77NEXBY.cjs +0 -8
- package/dist/memory-ADGOWADP.cjs +0 -9
- package/dist/openai-RXU5URYI.js +0 -10
- package/dist/openai-SQW4H2K4.cjs +0 -10
- package/dist/openrouter-models-PLCWZZYE.cjs +0 -15
- package/dist/openrouter-sync-K2WK3A2A.cjs +0 -11
- package/dist/services/compact.d.ts +0 -56
- package/dist/session-manager-HRSKENKB.cjs +0 -8
- package/dist/session-manager-NEKFEHF3.js +0 -8
- package/dist/updater-J7L7R6BY.cjs +0 -185
- package/dist/updater-LDBNYCAO.js +0 -185
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
6
|
+
|
|
7
|
+
// src/cli/updater.ts
|
|
8
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
9
|
+
var _child_process = require('child_process');
|
|
10
|
+
var _fs = require('fs');
|
|
11
|
+
var _promises = require('fs/promises');
|
|
12
|
+
var _module = require('module');
|
|
13
|
+
var _os = require('os');
|
|
14
|
+
var _path = require('path');
|
|
15
|
+
|
|
16
|
+
var _url = require('url');
|
|
17
|
+
var _util = require('util');
|
|
18
|
+
|
|
19
|
+
// src/utils/semver.ts
|
|
20
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
21
|
+
var _semver = require('semver');
|
|
22
|
+
function gt(a, b) {
|
|
23
|
+
return _semver.gt.call(void 0, a, b);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/cli/updater.ts
|
|
27
|
+
var execFileAsync = _util.promisify.call(void 0, _child_process.execFile);
|
|
28
|
+
var PACKAGE_NAME = "@cjhyy/code-shell";
|
|
29
|
+
var LOCK_FILE = ".update.lock";
|
|
30
|
+
var LOCK_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
31
|
+
var NPM_VIEW_TIMEOUT_MS = 5e3;
|
|
32
|
+
var _updateInfo;
|
|
33
|
+
var _exitHookInstalled = false;
|
|
34
|
+
var _disabledReason = null;
|
|
35
|
+
function checkForUpdate(packageName = PACKAGE_NAME) {
|
|
36
|
+
void runCheck(packageName);
|
|
37
|
+
}
|
|
38
|
+
function getUpdateAvailable() {
|
|
39
|
+
return _updateInfo;
|
|
40
|
+
}
|
|
41
|
+
function getAutoUpdateDisabledReason() {
|
|
42
|
+
return _disabledReason;
|
|
43
|
+
}
|
|
44
|
+
function scheduleAutoInstallOnExit() {
|
|
45
|
+
if (_exitHookInstalled) return;
|
|
46
|
+
_exitHookInstalled = true;
|
|
47
|
+
const fire = () => {
|
|
48
|
+
const info = _updateInfo;
|
|
49
|
+
if (!info || !info.canAutoInstall) return;
|
|
50
|
+
try {
|
|
51
|
+
launchDetachedInstall(info.latestVersion);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
process.once("exit", fire);
|
|
56
|
+
}
|
|
57
|
+
var _cachedVersion;
|
|
58
|
+
function getCurrentVersion() {
|
|
59
|
+
if (_cachedVersion) return _cachedVersion;
|
|
60
|
+
const found = resolveVersion();
|
|
61
|
+
_cachedVersion = found;
|
|
62
|
+
return found;
|
|
63
|
+
}
|
|
64
|
+
function resolveVersion() {
|
|
65
|
+
try {
|
|
66
|
+
const here = typeof import.meta !== "undefined" && _chunkKS3RYAYLcjs.importMetaUrl ? _path.dirname.call(void 0, _url.fileURLToPath.call(void 0, _chunkKS3RYAYLcjs.importMetaUrl)) : __dirname;
|
|
67
|
+
let dir = here;
|
|
68
|
+
for (let i = 0; i < 6; i++) {
|
|
69
|
+
try {
|
|
70
|
+
const pkg = JSON.parse(_fs.readFileSync.call(void 0, _path.resolve.call(void 0, dir, "package.json"), "utf-8"));
|
|
71
|
+
if (pkg && typeof pkg.version === "string") return pkg.version;
|
|
72
|
+
} catch (e2) {
|
|
73
|
+
}
|
|
74
|
+
const parent = _path.dirname.call(void 0, dir);
|
|
75
|
+
if (parent === dir) break;
|
|
76
|
+
dir = parent;
|
|
77
|
+
}
|
|
78
|
+
} catch (e3) {
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const req = _module.createRequire.call(void 0, _nullishCoalesce(_chunkKS3RYAYLcjs.importMetaUrl, () => ( __filename)));
|
|
82
|
+
const pkg = req("../../package.json");
|
|
83
|
+
if (_optionalChain([pkg, 'optionalAccess', _ => _.version])) return pkg.version;
|
|
84
|
+
} catch (e4) {
|
|
85
|
+
}
|
|
86
|
+
return "0.0.0";
|
|
87
|
+
}
|
|
88
|
+
async function runCheck(packageName) {
|
|
89
|
+
const disabled = isAutoUpdaterDisabled();
|
|
90
|
+
if (disabled) {
|
|
91
|
+
_disabledReason = disabled;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
_disabledReason = null;
|
|
95
|
+
try {
|
|
96
|
+
const currentVersion = getCurrentVersion();
|
|
97
|
+
const latestVersion = await getLatestVersion(packageName);
|
|
98
|
+
if (!latestVersion) return;
|
|
99
|
+
let isNewer = false;
|
|
100
|
+
try {
|
|
101
|
+
isNewer = gt(latestVersion, currentVersion);
|
|
102
|
+
} catch (e5) {
|
|
103
|
+
isNewer = latestVersion !== currentVersion;
|
|
104
|
+
}
|
|
105
|
+
if (!isNewer) {
|
|
106
|
+
_updateInfo = void 0;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const { hasPermissions, npmPrefix } = await checkGlobalInstallPermissions();
|
|
110
|
+
_updateInfo = { latestVersion, canAutoInstall: hasPermissions, npmPrefix };
|
|
111
|
+
} catch (e6) {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function getLatestVersion(packageName) {
|
|
115
|
+
try {
|
|
116
|
+
const { stdout } = await execFileAsync(
|
|
117
|
+
"npm",
|
|
118
|
+
["view", `${packageName}@latest`, "version", "--prefer-online"],
|
|
119
|
+
{ cwd: _os.homedir.call(void 0, ), timeout: NPM_VIEW_TIMEOUT_MS }
|
|
120
|
+
);
|
|
121
|
+
const v = stdout.trim();
|
|
122
|
+
return v.length > 0 ? v : null;
|
|
123
|
+
} catch (e7) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function checkGlobalInstallPermissions() {
|
|
128
|
+
let prefix = null;
|
|
129
|
+
try {
|
|
130
|
+
const { stdout } = await execFileAsync(
|
|
131
|
+
"npm",
|
|
132
|
+
["-g", "config", "get", "prefix"],
|
|
133
|
+
{ cwd: _os.homedir.call(void 0, ), timeout: 5e3 }
|
|
134
|
+
);
|
|
135
|
+
prefix = stdout.trim();
|
|
136
|
+
} catch (e8) {
|
|
137
|
+
return { hasPermissions: false, npmPrefix: null };
|
|
138
|
+
}
|
|
139
|
+
if (!prefix) return { hasPermissions: false, npmPrefix: null };
|
|
140
|
+
try {
|
|
141
|
+
await _promises.access.call(void 0, prefix, _fs.constants.W_OK);
|
|
142
|
+
return { hasPermissions: true, npmPrefix: prefix };
|
|
143
|
+
} catch (e9) {
|
|
144
|
+
return { hasPermissions: false, npmPrefix: prefix };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function userHome() {
|
|
148
|
+
return _nullishCoalesce(process.env.HOME, () => ( _os.homedir.call(void 0, )));
|
|
149
|
+
}
|
|
150
|
+
function configDir() {
|
|
151
|
+
return _path.join.call(void 0, userHome(), ".code-shell");
|
|
152
|
+
}
|
|
153
|
+
function getLockFilePath() {
|
|
154
|
+
return _path.join.call(void 0, configDir(), LOCK_FILE);
|
|
155
|
+
}
|
|
156
|
+
function getUpdateLogPath() {
|
|
157
|
+
return _path.join.call(void 0, configDir(), "update.log");
|
|
158
|
+
}
|
|
159
|
+
async function acquireLock() {
|
|
160
|
+
const lockPath = getLockFilePath();
|
|
161
|
+
try {
|
|
162
|
+
const s = await _promises.stat.call(void 0, lockPath);
|
|
163
|
+
if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS) return false;
|
|
164
|
+
try {
|
|
165
|
+
const recheck = await _promises.stat.call(void 0, lockPath);
|
|
166
|
+
if (Date.now() - recheck.mtimeMs < LOCK_TIMEOUT_MS) return false;
|
|
167
|
+
await _promises.unlink.call(void 0, lockPath);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (!isENOENT(err)) return false;
|
|
170
|
+
}
|
|
171
|
+
} catch (err) {
|
|
172
|
+
if (!isENOENT(err)) return false;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
await _promises.writeFile.call(void 0, lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
|
|
176
|
+
return true;
|
|
177
|
+
} catch (err) {
|
|
178
|
+
const code = errnoCode(err);
|
|
179
|
+
if (code === "EEXIST") return false;
|
|
180
|
+
if (code === "ENOENT") {
|
|
181
|
+
try {
|
|
182
|
+
await _promises.mkdir.call(void 0, configDir(), { recursive: true });
|
|
183
|
+
await _promises.writeFile.call(void 0, lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
|
|
184
|
+
return true;
|
|
185
|
+
} catch (e10) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function releaseLock() {
|
|
193
|
+
const lockPath = getLockFilePath();
|
|
194
|
+
try {
|
|
195
|
+
const data = await _promises.readFile.call(void 0, lockPath, "utf8");
|
|
196
|
+
if (data === String(process.pid)) await _promises.unlink.call(void 0, lockPath);
|
|
197
|
+
} catch (e11) {
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function launchDetachedInstall(version) {
|
|
201
|
+
const lockPath = getLockFilePath();
|
|
202
|
+
try {
|
|
203
|
+
try {
|
|
204
|
+
const fs2 = _chunkKS3RYAYLcjs.__require.call(void 0, "fs");
|
|
205
|
+
fs2.mkdirSync(configDir(), { recursive: true });
|
|
206
|
+
fs2.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
|
|
207
|
+
} catch (err) {
|
|
208
|
+
if (errnoCode(err) === "EEXIST") {
|
|
209
|
+
try {
|
|
210
|
+
const fs2 = _chunkKS3RYAYLcjs.__require.call(void 0, "fs");
|
|
211
|
+
const s = fs2.statSync(lockPath);
|
|
212
|
+
if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS) return;
|
|
213
|
+
fs2.unlinkSync(lockPath);
|
|
214
|
+
fs2.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
|
|
215
|
+
} catch (e12) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} catch (e13) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const fs = _chunkKS3RYAYLcjs.__require.call(void 0, "fs");
|
|
226
|
+
const logFd = fs.openSync(getUpdateLogPath(), "a");
|
|
227
|
+
try {
|
|
228
|
+
fs.writeSync(
|
|
229
|
+
logFd,
|
|
230
|
+
`
|
|
231
|
+
[${(/* @__PURE__ */ new Date()).toISOString()}] code-shell auto-update: installing ${PACKAGE_NAME}@${version} (pid=${process.pid})
|
|
232
|
+
`
|
|
233
|
+
);
|
|
234
|
+
} catch (e14) {
|
|
235
|
+
}
|
|
236
|
+
const cmd = [
|
|
237
|
+
`npm install -g ${PACKAGE_NAME}@${shellEscape(version)}`,
|
|
238
|
+
`; rm -f ${shellEscape(lockPath)}`
|
|
239
|
+
].join(" ");
|
|
240
|
+
try {
|
|
241
|
+
const child = _child_process.spawn.call(void 0, "sh", ["-c", cmd], {
|
|
242
|
+
detached: true,
|
|
243
|
+
stdio: ["ignore", logFd, logFd],
|
|
244
|
+
cwd: _os.homedir.call(void 0, )
|
|
245
|
+
});
|
|
246
|
+
child.unref();
|
|
247
|
+
} catch (e15) {
|
|
248
|
+
try {
|
|
249
|
+
fs.unlinkSync(lockPath);
|
|
250
|
+
} catch (e16) {
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function isAutoUpdaterDisabled() {
|
|
255
|
+
if (process.env.NODE_ENV === "development") return "development build";
|
|
256
|
+
if (isEnvTruthy(process.env.DISABLE_AUTOUPDATER)) return "DISABLE_AUTOUPDATER set";
|
|
257
|
+
if (readAutoUpdatesFlagFromDisk() === false) return "settings.autoUpdates = false";
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
function readAutoUpdatesFlagFromDisk() {
|
|
261
|
+
const path = _path.join.call(void 0, userHome(), ".code-shell", "settings.json");
|
|
262
|
+
try {
|
|
263
|
+
const raw = _fs.readFileSync.call(void 0, path, "utf8");
|
|
264
|
+
const parsed = JSON.parse(raw);
|
|
265
|
+
if (typeof parsed.autoUpdates === "boolean") return parsed.autoUpdates;
|
|
266
|
+
} catch (e17) {
|
|
267
|
+
}
|
|
268
|
+
return void 0;
|
|
269
|
+
}
|
|
270
|
+
function isEnvTruthy(v) {
|
|
271
|
+
if (!v) return false;
|
|
272
|
+
const lower = v.toLowerCase();
|
|
273
|
+
return lower === "1" || lower === "true" || lower === "yes" || lower === "on";
|
|
274
|
+
}
|
|
275
|
+
function errnoCode(err) {
|
|
276
|
+
return typeof err === "object" && err !== null && "code" in err ? String(err.code) : void 0;
|
|
277
|
+
}
|
|
278
|
+
function isENOENT(err) {
|
|
279
|
+
return errnoCode(err) === "ENOENT";
|
|
280
|
+
}
|
|
281
|
+
function shellEscape(s) {
|
|
282
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
283
|
+
}
|
|
284
|
+
var __internal = { acquireLock, releaseLock, getLockFilePath };
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
exports.checkForUpdate = checkForUpdate; exports.getUpdateAvailable = getUpdateAvailable; exports.getAutoUpdateDisabledReason = getAutoUpdateDisabledReason; exports.scheduleAutoInstallOnExit = scheduleAutoInstallOnExit; exports.getCurrentVersion = getCurrentVersion; exports.__internal = __internal;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk52LGZKT3cjs = require('./chunk-52LGZKT3.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
10
|
+
|
|
11
|
+
// src/llm/model-fetcher.ts
|
|
12
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
13
|
+
var _fs = require('fs');
|
|
14
|
+
var _url = require('url');
|
|
15
|
+
var _path = require('path');
|
|
16
|
+
|
|
17
|
+
// src/llm/provider-kinds.ts
|
|
18
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
19
|
+
var NON_CHAT_PATTERNS = /(?:^|[-_/])(?:embed(?:ding)?|whisper|tts|audio|image|dall-?e|moderation|rerank|guard|vision-only)(?:$|[-_/])/i;
|
|
20
|
+
var isChatLike = (id) => !NON_CHAT_PATTERNS.test(id);
|
|
21
|
+
var bearer = (k) => k ? { Authorization: `Bearer ${k}` } : {};
|
|
22
|
+
var PROVIDER_KINDS = {
|
|
23
|
+
openai: {
|
|
24
|
+
label: "OpenAI",
|
|
25
|
+
defaultBaseUrl: "https://api.openai.com/v1",
|
|
26
|
+
modelsPath: "/models",
|
|
27
|
+
protocol: "openai-compat",
|
|
28
|
+
authHeader: bearer,
|
|
29
|
+
chatFilter: isChatLike
|
|
30
|
+
},
|
|
31
|
+
anthropic: {
|
|
32
|
+
label: "Anthropic",
|
|
33
|
+
defaultBaseUrl: "https://api.anthropic.com/v1",
|
|
34
|
+
modelsPath: "/models",
|
|
35
|
+
protocol: "anthropic-style",
|
|
36
|
+
authHeader: (k) => k ? { "x-api-key": k, "anthropic-version": "2023-06-01" } : { "anthropic-version": "2023-06-01" },
|
|
37
|
+
chatFilter: isChatLike
|
|
38
|
+
},
|
|
39
|
+
deepseek: {
|
|
40
|
+
label: "DeepSeek",
|
|
41
|
+
defaultBaseUrl: "https://api.deepseek.com/v1",
|
|
42
|
+
modelsPath: "/models",
|
|
43
|
+
protocol: "openai-compat",
|
|
44
|
+
authHeader: bearer,
|
|
45
|
+
chatFilter: isChatLike
|
|
46
|
+
},
|
|
47
|
+
xai: {
|
|
48
|
+
label: "xAI (Grok)",
|
|
49
|
+
defaultBaseUrl: "https://api.x.ai/v1",
|
|
50
|
+
modelsPath: "/models",
|
|
51
|
+
protocol: "openai-compat",
|
|
52
|
+
authHeader: bearer,
|
|
53
|
+
chatFilter: isChatLike
|
|
54
|
+
},
|
|
55
|
+
mistral: {
|
|
56
|
+
label: "Mistral",
|
|
57
|
+
defaultBaseUrl: "https://api.mistral.ai/v1",
|
|
58
|
+
modelsPath: "/models",
|
|
59
|
+
protocol: "openai-compat",
|
|
60
|
+
authHeader: bearer,
|
|
61
|
+
chatFilter: isChatLike
|
|
62
|
+
},
|
|
63
|
+
groq: {
|
|
64
|
+
label: "Groq",
|
|
65
|
+
defaultBaseUrl: "https://api.groq.com/openai/v1",
|
|
66
|
+
modelsPath: "/models",
|
|
67
|
+
protocol: "openai-compat",
|
|
68
|
+
authHeader: bearer,
|
|
69
|
+
chatFilter: isChatLike
|
|
70
|
+
},
|
|
71
|
+
google: {
|
|
72
|
+
label: "Google Gemini",
|
|
73
|
+
defaultBaseUrl: "https://generativelanguage.googleapis.com/v1beta",
|
|
74
|
+
modelsPath: "/models",
|
|
75
|
+
protocol: "gemini",
|
|
76
|
+
authHeader: () => ({}),
|
|
77
|
+
authQuery: (k) => k ? { key: k } : {},
|
|
78
|
+
chatFilter: (id) => isChatLike(id) && /gemini/i.test(id)
|
|
79
|
+
},
|
|
80
|
+
openrouter: {
|
|
81
|
+
label: "OpenRouter",
|
|
82
|
+
defaultBaseUrl: "https://openrouter.ai/api/v1",
|
|
83
|
+
modelsPath: "/models",
|
|
84
|
+
protocol: "openai-compat",
|
|
85
|
+
authHeader: bearer,
|
|
86
|
+
chatFilter: isChatLike
|
|
87
|
+
},
|
|
88
|
+
ollama: {
|
|
89
|
+
label: "Ollama (local)",
|
|
90
|
+
defaultBaseUrl: "http://localhost:11434",
|
|
91
|
+
modelsPath: "/api/tags",
|
|
92
|
+
protocol: "ollama",
|
|
93
|
+
authHeader: () => ({}),
|
|
94
|
+
chatFilter: isChatLike
|
|
95
|
+
},
|
|
96
|
+
custom: {
|
|
97
|
+
label: "Custom",
|
|
98
|
+
defaultBaseUrl: "",
|
|
99
|
+
modelsPath: "/models",
|
|
100
|
+
protocol: "openai-compat",
|
|
101
|
+
authHeader: bearer,
|
|
102
|
+
chatFilter: isChatLike
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function getKindMeta(kind) {
|
|
106
|
+
return _nullishCoalesce(PROVIDER_KINDS[kind], () => ( PROVIDER_KINDS.custom));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/llm/model-fetcher.ts
|
|
110
|
+
var HERE = _path.dirname.call(void 0, _url.fileURLToPath.call(void 0, _chunkKS3RYAYLcjs.importMetaUrl));
|
|
111
|
+
var OPENROUTER_SNAPSHOT = _path.join.call(void 0, HERE, "..", "data", "openrouter-models.json");
|
|
112
|
+
async function fetchModelList(provider, opts) {
|
|
113
|
+
const meta = getKindMeta(provider.kind);
|
|
114
|
+
if (!opts.refresh) {
|
|
115
|
+
const cached = _chunk52LGZKT3cjs.readCache.call(void 0, opts.cacheDir, provider.key);
|
|
116
|
+
if (cached && !_chunk52LGZKT3cjs.isStale.call(void 0, cached)) return { ...cached, fromCache: true };
|
|
117
|
+
}
|
|
118
|
+
if (provider.kind === "openrouter") {
|
|
119
|
+
return loadOpenRouterSnapshot(provider.key, opts.cacheDir);
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const path = _nullishCoalesce(provider.modelsPath, () => ( meta.modelsPath));
|
|
123
|
+
const url = new URL(joinUrl(provider.baseUrl, path));
|
|
124
|
+
const headers = meta.authHeader(_nullishCoalesce(provider.apiKey, () => ( "")));
|
|
125
|
+
if (meta.authQuery) {
|
|
126
|
+
const q = meta.authQuery(_nullishCoalesce(provider.apiKey, () => ( "")));
|
|
127
|
+
for (const [k, v] of Object.entries(q)) url.searchParams.set(k, v);
|
|
128
|
+
}
|
|
129
|
+
const res = await fetch(url.toString(), {
|
|
130
|
+
headers: { Accept: "application/json", ...headers },
|
|
131
|
+
signal: AbortSignal.timeout(_nullishCoalesce(opts.timeoutMs, () => ( 2e4)))
|
|
132
|
+
});
|
|
133
|
+
if (!res.ok) {
|
|
134
|
+
return errorResult(provider.key, opts.cacheDir, `HTTP ${res.status}`);
|
|
135
|
+
}
|
|
136
|
+
const payload = await res.json();
|
|
137
|
+
const raw = normalize(payload, meta.protocol);
|
|
138
|
+
const filtered = raw.filter((m) => meta.chatFilter(m.id));
|
|
139
|
+
const file = _chunk52LGZKT3cjs.writeCache.call(void 0, opts.cacheDir, provider.key, filtered);
|
|
140
|
+
return file;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
const msg = err.message || String(err);
|
|
143
|
+
return errorResult(provider.key, opts.cacheDir, msg);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function normalize(payload, protocol) {
|
|
147
|
+
switch (protocol) {
|
|
148
|
+
case "ollama": {
|
|
149
|
+
const p = payload;
|
|
150
|
+
return (_nullishCoalesce(p.models, () => ( []))).map((m) => ({ id: m.name, contextLength: 0, maxOutputTokens: 0 }));
|
|
151
|
+
}
|
|
152
|
+
case "anthropic-style": {
|
|
153
|
+
const p = payload;
|
|
154
|
+
return (_nullishCoalesce(p.data, () => ( []))).map((m) => ({
|
|
155
|
+
id: m.id,
|
|
156
|
+
contextLength: _nullishCoalesce(m.context_window, () => ( 2e5)),
|
|
157
|
+
maxOutputTokens: _nullishCoalesce(m.max_output_tokens, () => ( 0))
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
case "gemini": {
|
|
161
|
+
const p = payload;
|
|
162
|
+
return (_nullishCoalesce(p.models, () => ( []))).map((m) => ({
|
|
163
|
+
id: m.name.replace(/^models\//, ""),
|
|
164
|
+
contextLength: _nullishCoalesce(m.inputTokenLimit, () => ( 0)),
|
|
165
|
+
maxOutputTokens: _nullishCoalesce(m.outputTokenLimit, () => ( 0))
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
case "openai-compat": {
|
|
169
|
+
const p = payload;
|
|
170
|
+
return (_nullishCoalesce(p.data, () => ( []))).map((m) => ({
|
|
171
|
+
id: m.id,
|
|
172
|
+
contextLength: _nullishCoalesce(_nullishCoalesce(m.context_window, () => ( m.context_length)), () => ( 0)),
|
|
173
|
+
maxOutputTokens: _nullishCoalesce(m.max_completion_tokens, () => ( 0))
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const _exhaustive = protocol;
|
|
178
|
+
return _exhaustive;
|
|
179
|
+
}
|
|
180
|
+
function loadOpenRouterSnapshot(providerKey, cacheDir) {
|
|
181
|
+
if (!_fs.existsSync.call(void 0, OPENROUTER_SNAPSHOT)) {
|
|
182
|
+
return errorResult(providerKey, cacheDir, "openrouter snapshot missing");
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const snapshot = JSON.parse(
|
|
186
|
+
_fs.readFileSync.call(void 0, OPENROUTER_SNAPSHOT, "utf-8")
|
|
187
|
+
);
|
|
188
|
+
const models = (_nullishCoalesce(snapshot.models, () => ( []))).map((m) => ({
|
|
189
|
+
id: m.id,
|
|
190
|
+
contextLength: _nullishCoalesce(m.contextLength, () => ( 0)),
|
|
191
|
+
maxOutputTokens: _nullishCoalesce(m.maxOutputTokens, () => ( 0))
|
|
192
|
+
}));
|
|
193
|
+
return _chunk52LGZKT3cjs.writeCache.call(void 0, cacheDir, providerKey, models);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
return errorResult(providerKey, cacheDir, err.message);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function errorResult(providerKey, cacheDir, error) {
|
|
199
|
+
const stale = _chunk52LGZKT3cjs.readCache.call(void 0, cacheDir, providerKey);
|
|
200
|
+
if (stale) return { ...stale, error, fromCache: true };
|
|
201
|
+
return {
|
|
202
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
203
|
+
providerKey,
|
|
204
|
+
models: [],
|
|
205
|
+
error
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function joinUrl(base, path) {
|
|
209
|
+
if (!base) return path;
|
|
210
|
+
return `${base.replace(/\/$/, "")}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
exports.PROVIDER_KINDS = PROVIDER_KINDS; exports.fetchModelList = fetchModelList;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk2YW4FPFGcjs = require('./chunk-2YW4FPFG.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
7
7
|
|
|
8
8
|
// src/session/session-manager.ts
|
|
9
|
-
|
|
9
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
10
10
|
var _fs = require('fs');
|
|
11
11
|
var _path = require('path');
|
|
12
12
|
var _os = require('os');
|
|
13
13
|
var _nanoid = require('nanoid');
|
|
14
14
|
|
|
15
15
|
// src/session/transcript.ts
|
|
16
|
-
|
|
16
|
+
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
@@ -218,11 +218,11 @@ var SessionManager = class {
|
|
|
218
218
|
resume(sessionId) {
|
|
219
219
|
const sessionDir = _path.join.call(void 0, this.sessionsDir, sessionId);
|
|
220
220
|
if (!_fs.existsSync.call(void 0, sessionDir)) {
|
|
221
|
-
throw new (0,
|
|
221
|
+
throw new (0, _chunk2YW4FPFGcjs.SessionError)(`Session not found: ${sessionId}`);
|
|
222
222
|
}
|
|
223
223
|
const stateFile = _path.join.call(void 0, sessionDir, "state.json");
|
|
224
224
|
if (!_fs.existsSync.call(void 0, stateFile)) {
|
|
225
|
-
throw new (0,
|
|
225
|
+
throw new (0, _chunk2YW4FPFGcjs.SessionError)(`Session state file not found: ${sessionId}`);
|
|
226
226
|
}
|
|
227
227
|
const state = JSON.parse(_fs.readFileSync.call(void 0, stateFile, "utf-8"));
|
|
228
228
|
const transcriptFile = _path.join.call(void 0, sessionDir, "transcript.jsonl");
|