@cjhyy/code-shell 0.1.6 → 0.1.7

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.
Files changed (154) hide show
  1. package/dist/anthropic-UBSB5AQH.js +1 -0
  2. package/dist/arena/index.js +1 -104
  3. package/dist/arena-OW55ZCHT.js +3 -0
  4. package/dist/bwrap-PVZMLHZR.js +2 -0
  5. package/dist/chunk-2NS3JMNK.js +1 -0
  6. package/dist/chunk-3QP5BQ3L.js +1 -0
  7. package/dist/chunk-B7K2OWKC.js +2 -0
  8. package/dist/chunk-EWWK56K6.js +2 -0
  9. package/dist/chunk-FU7AHZNN.js +1 -0
  10. package/dist/chunk-HIJ2XXGX.js +1 -0
  11. package/dist/chunk-KCXSARAA.js +1 -0
  12. package/dist/chunk-NFH3UQ3E.js +2 -0
  13. package/dist/chunk-NMBYBGC7.js +250 -0
  14. package/dist/chunk-NVAZJ5XS.js +2 -0
  15. package/dist/chunk-O5HFCH2U.js +1 -0
  16. package/dist/chunk-P6JSTIFM.js +1 -0
  17. package/dist/chunk-PGANL6F2.js +3 -0
  18. package/dist/chunk-Q4O2HGWS.js +251 -0
  19. package/dist/chunk-QTWU7UNA.js +5 -0
  20. package/dist/chunk-RP26WO4R.js +1 -0
  21. package/dist/chunk-SNFAPSLA.js +1 -0
  22. package/dist/chunk-T222K6IV.js +18 -0
  23. package/dist/chunk-TKJA6W36.js +3 -0
  24. package/dist/chunk-UDPUTFQT.js +2 -0
  25. package/dist/chunk-W47Z7MGS.js +33 -0
  26. package/dist/chunk-WI6FSWGU.js +1 -0
  27. package/dist/chunk-WOP6MJKW.js +1 -0
  28. package/dist/chunk-XDOWC7EG.js +4 -0
  29. package/dist/chunk-Y2NS6HPO.js +641 -0
  30. package/dist/cli/main.js +303 -22060
  31. package/dist/client-base-6ZZJJYDY.js +1 -0
  32. package/dist/compaction-ECVQVOCT.js +1 -0
  33. package/dist/devtools-SGDUOOM4.js +1 -0
  34. package/dist/engine/engine.d.ts +8 -0
  35. package/dist/export-md-U72T7NW7.js +22 -0
  36. package/dist/file-history-7FQFEQOL.js +1 -0
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +1 -347
  39. package/dist/llm/token-counter.d.ts +17 -0
  40. package/dist/manager-C3TDN6MS.js +1 -0
  41. package/dist/mcp-manager-OP4XYV53.js +1 -0
  42. package/dist/memory-BNI4WEWL.js +1 -0
  43. package/dist/model-cache-HEDXI7UJ.js +1 -0
  44. package/dist/model-fetcher-BJ64META.js +1 -0
  45. package/dist/off-7SDVMMXW.js +1 -0
  46. package/dist/openai-KEWQ54TM.js +1 -0
  47. package/dist/openrouter-models-AM6M52D6.js +1 -0
  48. package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
  49. package/dist/product/index.js +1 -21
  50. package/dist/run/index.js +1 -48
  51. package/dist/seatbelt-WBYROQT6.js +37 -0
  52. package/dist/session/session-manager.d.ts +2 -0
  53. package/dist/session-manager-AGWS5SMJ.js +1 -0
  54. package/dist/settings/schema.d.ts +72 -6
  55. package/dist/tool-summary-5UE62VU4.js +2 -0
  56. package/dist/tool-system/builtin/bash.d.ts +7 -1
  57. package/dist/tool-system/context.d.ts +7 -0
  58. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  59. package/dist/tool-system/sandbox/index.d.ts +71 -0
  60. package/dist/tool-system/sandbox/off.d.ts +2 -0
  61. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  62. package/dist/types.d.ts +4 -0
  63. package/dist/ui/components/SessionPicker.d.ts +2 -0
  64. package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
  65. package/dist/ui/components/StatusLine.d.ts +2 -2
  66. package/dist/updater-OCNU2K2Z.js +1 -0
  67. package/package.json +7 -10
  68. package/dist/anthropic-IBTI4WL2.cjs +0 -10
  69. package/dist/anthropic-PRZZKHEZ.js +0 -10
  70. package/dist/arena/index.cjs +0 -104
  71. package/dist/arena-2LTLIXOL.js +0 -261
  72. package/dist/arena-ADB7DRFI.cjs +0 -261
  73. package/dist/chunk-2YW4FPFG.cjs +0 -101
  74. package/dist/chunk-3OA5G4TM.js +0 -47
  75. package/dist/chunk-3QO25N6E.js +0 -4711
  76. package/dist/chunk-3SBSUOWZ.js +0 -447
  77. package/dist/chunk-52LGZKT3.cjs +0 -47
  78. package/dist/chunk-55XGPMAP.cjs +0 -146
  79. package/dist/chunk-6QVAYW7C.cjs +0 -438
  80. package/dist/chunk-6S4BJ65N.js +0 -113
  81. package/dist/chunk-76HYEPDM.js +0 -307
  82. package/dist/chunk-7BI3V74Y.cjs +0 -447
  83. package/dist/chunk-7EG3V4JY.cjs +0 -113
  84. package/dist/chunk-7JVTYEEC.js +0 -340
  85. package/dist/chunk-7QIM3BKD.js +0 -44
  86. package/dist/chunk-7Y6S3OCX.js +0 -438
  87. package/dist/chunk-ABRRONJ7.js +0 -107
  88. package/dist/chunk-BSW22MPA.js +0 -146
  89. package/dist/chunk-BXCY2FSE.js +0 -203
  90. package/dist/chunk-BZ5TNE7L.js +0 -5128
  91. package/dist/chunk-DDB6QOKJ.cjs +0 -1252
  92. package/dist/chunk-HEKQCI7B.cjs +0 -224
  93. package/dist/chunk-IK4EWJBP.cjs +0 -203
  94. package/dist/chunk-ILHE7XLT.cjs +0 -107
  95. package/dist/chunk-JMR33QVF.cjs +0 -169
  96. package/dist/chunk-KAQHULYN.js +0 -54
  97. package/dist/chunk-KE4EQOWA.js +0 -294
  98. package/dist/chunk-KOVYSDHZ.cjs +0 -340
  99. package/dist/chunk-KS3RYAYL.cjs +0 -45
  100. package/dist/chunk-MD32R22I.js +0 -50
  101. package/dist/chunk-MV7YI4WO.cjs +0 -293
  102. package/dist/chunk-MY5XHADU.cjs +0 -216
  103. package/dist/chunk-NUNC3VFB.cjs +0 -307
  104. package/dist/chunk-PKGRTCCY.js +0 -9092
  105. package/dist/chunk-QARL3IDQ.js +0 -1252
  106. package/dist/chunk-S754JHLR.cjs +0 -54
  107. package/dist/chunk-SFXHZSRF.js +0 -101
  108. package/dist/chunk-SIHHIQLO.js +0 -224
  109. package/dist/chunk-T6VYG46N.js +0 -105
  110. package/dist/chunk-TNLGBJYS.cjs +0 -44
  111. package/dist/chunk-TUY2T5KP.cjs +0 -105
  112. package/dist/chunk-UXOCVJJ6.cjs +0 -9092
  113. package/dist/chunk-VIAGTYYW.js +0 -169
  114. package/dist/chunk-WASS5YWB.js +0 -215
  115. package/dist/chunk-WZJV6DJC.cjs +0 -5128
  116. package/dist/chunk-YIQBXAYU.cjs +0 -264
  117. package/dist/chunk-YKIAELDZ.cjs +0 -4711
  118. package/dist/chunk-ZBPSQCPU.js +0 -264
  119. package/dist/cli/main.cjs +0 -22156
  120. package/dist/client-base-HTF236ZD.cjs +0 -9
  121. package/dist/client-base-QKRKCOWB.js +0 -9
  122. package/dist/compaction-6VU2T643.js +0 -33
  123. package/dist/compaction-OKUNTCA7.cjs +0 -33
  124. package/dist/devtools-T2NIZBJK.cjs +0 -6
  125. package/dist/devtools-YXWHOVKR.js +0 -6
  126. package/dist/export-md-RXDW6F5W.cjs +0 -135
  127. package/dist/export-md-XXKZANW5.js +0 -135
  128. package/dist/file-history-KYPE3ECT.cjs +0 -7
  129. package/dist/file-history-LF4F7X26.js +0 -7
  130. package/dist/index.cjs +0 -347
  131. package/dist/manager-D65VFAPX.js +0 -7
  132. package/dist/manager-TTF5VHJC.cjs +0 -7
  133. package/dist/mcp-manager-QMKWPBZ4.js +0 -8
  134. package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
  135. package/dist/memory-5LWZ6FI2.cjs +0 -9
  136. package/dist/memory-VIJLBAMQ.js +0 -9
  137. package/dist/model-cache-5KIYL5SL.js +0 -13
  138. package/dist/model-cache-OED3IM4R.cjs +0 -13
  139. package/dist/model-fetcher-HKGICACL.js +0 -8
  140. package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
  141. package/dist/openai-JR2WEKOF.js +0 -10
  142. package/dist/openai-YBTOET4O.cjs +0 -10
  143. package/dist/openrouter-models-H56GHBHN.js +0 -15
  144. package/dist/openrouter-models-TWUFWZ5T.cjs +0 -15
  145. package/dist/openrouter-sync-5VMGN6C2.cjs +0 -11
  146. package/dist/openrouter-sync-ALEMF5IU.js +0 -11
  147. package/dist/product/index.cjs +0 -21
  148. package/dist/run/index.cjs +0 -48
  149. package/dist/session-manager-Q22BBMD3.js +0 -8
  150. package/dist/session-manager-XODQVL3C.cjs +0 -8
  151. package/dist/tool-summary-63DPIS7G.cjs +0 -31
  152. package/dist/tool-summary-NP5CDBKG.js +0 -31
  153. package/dist/updater-I7QBW4DP.cjs +0 -17
  154. package/dist/updater-NVME5S3Z.js +0 -17
@@ -1,169 +0,0 @@
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
-
3
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
4
-
5
- // src/session/memory.ts
6
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7
- var _fs = require('fs');
8
- var _path = require('path');
9
- var _os = require('os');
10
- function resolveMemoryBaseDir(override) {
11
- if (override) return override;
12
- const fromEnv = process.env.CODE_SHELL_HOME;
13
- if (fromEnv && fromEnv.length > 0) return fromEnv;
14
- return _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell");
15
- }
16
- var MemoryManager = (_class = class {
17
-
18
-
19
-
20
- // Per-instance cache of {fileName -> {name, description}} so the
21
- // index can be rewritten without re-reading every memory file
22
- // every time a single entry is saved/deleted (the previous code
23
- // path called loadAll() on every save, giving O(N²) total I/O).
24
- // null = "not initialized yet, fall back to disk on next access."
25
- __init() {this.indexCache = null}
26
- constructor(options) {;_class.prototype.__init.call(this);
27
- const opts = typeof options === "string" ? { projectDir: options } : _nullishCoalesce(options, () => ( {}));
28
- this.baseDir = resolveMemoryBaseDir(opts.baseDir);
29
- if (opts.projectDir) {
30
- const projectHash = opts.projectDir.replace(/[/\\:]/g, "-").replace(/^-/, "");
31
- this.memoryDir = _path.join.call(void 0, this.baseDir, "projects", projectHash, "memory");
32
- } else {
33
- this.memoryDir = _path.join.call(void 0, this.baseDir, "memory");
34
- }
35
- this.indexPath = _path.join.call(void 0, this.memoryDir, "MEMORY.md");
36
- _fs.mkdirSync.call(void 0, this.memoryDir, { recursive: true });
37
- }
38
- getMemoryDir() {
39
- return this.memoryDir;
40
- }
41
- /**
42
- * Save a memory entry. Creates the file and updates the index.
43
- */
44
- save(entry) {
45
- const fileName = this.slugify(entry.name) + ".md";
46
- const filePath = _path.join.call(void 0, this.memoryDir, fileName);
47
- const content = `---
48
- name: ${entry.name}
49
- description: ${entry.description}
50
- type: ${entry.type}
51
- ---
52
-
53
- ${entry.content}
54
- `;
55
- _fs.writeFileSync.call(void 0, filePath, content, "utf-8");
56
- const cache = this.ensureIndexCache();
57
- cache.set(fileName, { name: entry.name, description: entry.description });
58
- this.writeIndex(cache);
59
- return fileName;
60
- }
61
- /**
62
- * Load all memory entries.
63
- */
64
- loadAll() {
65
- if (!_fs.existsSync.call(void 0, this.memoryDir)) return [];
66
- const files = _fs.readdirSync.call(void 0, this.memoryDir).filter(
67
- (f) => f.endsWith(".md") && f !== "MEMORY.md"
68
- );
69
- const entries = [];
70
- for (const file of files) {
71
- const entry = this.loadFile(file);
72
- if (entry) entries.push(entry);
73
- }
74
- return entries;
75
- }
76
- /**
77
- * Load a single memory file.
78
- */
79
- loadFile(fileName) {
80
- const filePath = _path.join.call(void 0, this.memoryDir, fileName);
81
- if (!_fs.existsSync.call(void 0, filePath)) return null;
82
- try {
83
- const raw = _fs.readFileSync.call(void 0, filePath, "utf-8");
84
- const frontmatterMatch = raw.match(/^---\n([\s\S]*?)\n---\n\n?([\s\S]*)$/);
85
- if (!frontmatterMatch) return null;
86
- const frontmatter = frontmatterMatch[1];
87
- const content = frontmatterMatch[2].trim();
88
- const name = _nullishCoalesce(_optionalChain([frontmatter, 'access', _ => _.match, 'call', _2 => _2(/name:\s*(.+)/), 'optionalAccess', _3 => _3[1], 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()]), () => ( fileName));
89
- const description = _nullishCoalesce(_optionalChain([frontmatter, 'access', _6 => _6.match, 'call', _7 => _7(/description:\s*(.+)/), 'optionalAccess', _8 => _8[1], 'optionalAccess', _9 => _9.trim, 'call', _10 => _10()]), () => ( ""));
90
- const type = _nullishCoalesce(_optionalChain([frontmatter, 'access', _11 => _11.match, 'call', _12 => _12(/type:\s*(.+)/), 'optionalAccess', _13 => _13[1], 'optionalAccess', _14 => _14.trim, 'call', _15 => _15()]), () => ( "project"));
91
- return { name, description, type, content, fileName };
92
- } catch (e2) {
93
- return null;
94
- }
95
- }
96
- /**
97
- * Delete a memory by name or filename.
98
- */
99
- delete(nameOrFile) {
100
- const entries = this.loadAll();
101
- const entry = entries.find(
102
- (e) => e.name === nameOrFile || e.fileName === nameOrFile
103
- );
104
- if (!entry) return false;
105
- try {
106
- _fs.unlinkSync.call(void 0, _path.join.call(void 0, this.memoryDir, entry.fileName));
107
- const cache = this.ensureIndexCache();
108
- cache.delete(entry.fileName);
109
- this.writeIndex(cache);
110
- return true;
111
- } catch (e3) {
112
- return false;
113
- }
114
- }
115
- /**
116
- * Get the MEMORY.md index content for injection into prompts.
117
- */
118
- getIndex() {
119
- if (!_fs.existsSync.call(void 0, this.indexPath)) return "";
120
- return _fs.readFileSync.call(void 0, this.indexPath, "utf-8");
121
- }
122
- /**
123
- * Build a prompt-friendly summary of all memories.
124
- */
125
- buildMemoryContext() {
126
- const entries = this.loadAll();
127
- if (entries.length === 0) return "";
128
- const lines = entries.map(
129
- (e) => `- [${e.type}] ${e.name}: ${e.description}`
130
- );
131
- return `# Persistent Memory
132
-
133
- The following memories from previous sessions may be relevant:
134
-
135
- ` + lines.join("\n") + `
136
-
137
- To read a specific memory, check ${this.memoryDir}/`;
138
- }
139
- /**
140
- * Lazy-build the in-memory index from disk on first use, then
141
- * keep it in sync incrementally via save/delete. Avoids the
142
- * O(N²) re-read of every memory file on every save.
143
- */
144
- ensureIndexCache() {
145
- if (this.indexCache !== null) return this.indexCache;
146
- const cache = /* @__PURE__ */ new Map();
147
- for (const entry of this.loadAll()) {
148
- cache.set(entry.fileName, { name: entry.name, description: entry.description });
149
- }
150
- this.indexCache = cache;
151
- return cache;
152
- }
153
- writeIndex(cache) {
154
- const lines = [];
155
- for (const [fileName, meta] of cache) {
156
- lines.push(`- [${meta.name}](${fileName}) \u2014 ${meta.description}`);
157
- }
158
- const content = lines.length > 0 ? lines.join("\n") + "\n" : "(no memories stored)\n";
159
- _fs.writeFileSync.call(void 0, this.indexPath, content, "utf-8");
160
- }
161
- slugify(text) {
162
- return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60);
163
- }
164
- }, _class);
165
-
166
-
167
-
168
-
169
- exports.resolveMemoryBaseDir = resolveMemoryBaseDir; exports.MemoryManager = MemoryManager;
@@ -1,54 +0,0 @@
1
- import {
2
- setOpenRouterSnapshot
3
- } from "./chunk-3QO25N6E.js";
4
- import {
5
- init_esm_shims
6
- } from "./chunk-MD32R22I.js";
7
-
8
- // src/data/openrouter-sync.ts
9
- init_esm_shims();
10
- var ENDPOINT = "https://openrouter.ai/api/v1/models";
11
- function priceToPerMillion(raw) {
12
- if (!raw) return 0;
13
- const n = Number(raw);
14
- return Number.isFinite(n) ? n * 1e6 : 0;
15
- }
16
- function slim(m) {
17
- return {
18
- id: m.id,
19
- name: m.name ?? m.id,
20
- created: m.created ?? 0,
21
- contextLength: m.top_provider?.context_length ?? m.context_length ?? 0,
22
- maxOutputTokens: m.top_provider?.max_completion_tokens ?? 0,
23
- inputPricePerMillion: priceToPerMillion(m.pricing?.prompt),
24
- outputPricePerMillion: priceToPerMillion(m.pricing?.completion),
25
- modalities: m.architecture?.input_modalities ?? []
26
- };
27
- }
28
- async function syncOpenRouterCatalog(timeoutMs = 15e3) {
29
- try {
30
- const res = await fetch(ENDPOINT, {
31
- headers: { Accept: "application/json" },
32
- signal: AbortSignal.timeout(timeoutMs)
33
- });
34
- if (!res.ok) {
35
- return { ok: false, count: 0, error: `HTTP ${res.status} ${res.statusText}` };
36
- }
37
- const payload = await res.json();
38
- const raw = payload.data ?? [];
39
- const models = raw.map(slim).sort((a, b) => b.created - a.created);
40
- setOpenRouterSnapshot({
41
- fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
42
- source: ENDPOINT,
43
- count: models.length,
44
- models
45
- });
46
- return { ok: true, count: models.length };
47
- } catch (err) {
48
- return { ok: false, count: 0, error: err.message };
49
- }
50
- }
51
-
52
- export {
53
- syncOpenRouterCatalog
54
- };
@@ -1,294 +0,0 @@
1
- import {
2
- __dirname,
3
- __filename,
4
- __require,
5
- init_esm_shims
6
- } from "./chunk-MD32R22I.js";
7
-
8
- // src/cli/updater.ts
9
- init_esm_shims();
10
- import { execFile, spawn } from "child_process";
11
- import { constants as fsConstants } from "fs";
12
- import { access, mkdir, readFile, stat, unlink, writeFile } from "fs/promises";
13
- import { createRequire } from "module";
14
- import { homedir } from "os";
15
- import { dirname, join, resolve } from "path";
16
- import { readFileSync } from "fs";
17
- import { fileURLToPath } from "url";
18
- import { promisify } from "util";
19
-
20
- // src/utils/semver.ts
21
- init_esm_shims();
22
- import { gte as semverGte, gt as semverGt, lt as semverLt } from "semver";
23
- function gt(a, b) {
24
- return semverGt(a, b);
25
- }
26
-
27
- // src/cli/updater.ts
28
- var execFileAsync = promisify(execFile);
29
- var PACKAGE_NAME = "@cjhyy/code-shell";
30
- var LOCK_FILE = ".update.lock";
31
- var LOCK_TIMEOUT_MS = 5 * 60 * 1e3;
32
- var NPM_VIEW_TIMEOUT_MS = 5e3;
33
- var _updateInfo;
34
- var _exitHookInstalled = false;
35
- var _disabledReason = null;
36
- function checkForUpdate(packageName = PACKAGE_NAME) {
37
- void runCheck(packageName);
38
- }
39
- function getUpdateAvailable() {
40
- return _updateInfo;
41
- }
42
- function getAutoUpdateDisabledReason() {
43
- return _disabledReason;
44
- }
45
- function scheduleAutoInstallOnExit() {
46
- if (_exitHookInstalled) return;
47
- _exitHookInstalled = true;
48
- const fire = () => {
49
- const info = _updateInfo;
50
- if (!info || !info.canAutoInstall) return;
51
- try {
52
- launchDetachedInstall(info.latestVersion);
53
- } catch {
54
- }
55
- };
56
- process.once("exit", fire);
57
- }
58
- var _cachedVersion;
59
- function getCurrentVersion() {
60
- if (_cachedVersion) return _cachedVersion;
61
- const found = resolveVersion();
62
- _cachedVersion = found;
63
- return found;
64
- }
65
- function resolveVersion() {
66
- try {
67
- const here = typeof import.meta !== "undefined" && import.meta.url ? dirname(fileURLToPath(import.meta.url)) : __dirname;
68
- let dir = here;
69
- for (let i = 0; i < 6; i++) {
70
- try {
71
- const pkg = JSON.parse(readFileSync(resolve(dir, "package.json"), "utf-8"));
72
- if (pkg && typeof pkg.version === "string") return pkg.version;
73
- } catch {
74
- }
75
- const parent = dirname(dir);
76
- if (parent === dir) break;
77
- dir = parent;
78
- }
79
- } catch {
80
- }
81
- try {
82
- const req = createRequire(import.meta.url ?? __filename);
83
- const pkg = req("../../package.json");
84
- if (pkg?.version) return pkg.version;
85
- } catch {
86
- }
87
- return "0.0.0";
88
- }
89
- async function runCheck(packageName) {
90
- const disabled = isAutoUpdaterDisabled();
91
- if (disabled) {
92
- _disabledReason = disabled;
93
- return;
94
- }
95
- _disabledReason = null;
96
- try {
97
- const currentVersion = getCurrentVersion();
98
- const latestVersion = await getLatestVersion(packageName);
99
- if (!latestVersion) return;
100
- let isNewer = false;
101
- try {
102
- isNewer = gt(latestVersion, currentVersion);
103
- } catch {
104
- isNewer = latestVersion !== currentVersion;
105
- }
106
- if (!isNewer) {
107
- _updateInfo = void 0;
108
- return;
109
- }
110
- const { hasPermissions, npmPrefix } = await checkGlobalInstallPermissions();
111
- _updateInfo = { latestVersion, canAutoInstall: hasPermissions, npmPrefix };
112
- } catch {
113
- }
114
- }
115
- async function getLatestVersion(packageName) {
116
- try {
117
- const { stdout } = await execFileAsync(
118
- "npm",
119
- ["view", `${packageName}@latest`, "version", "--prefer-online"],
120
- { cwd: homedir(), timeout: NPM_VIEW_TIMEOUT_MS }
121
- );
122
- const v = stdout.trim();
123
- return v.length > 0 ? v : null;
124
- } catch {
125
- return null;
126
- }
127
- }
128
- async function checkGlobalInstallPermissions() {
129
- let prefix = null;
130
- try {
131
- const { stdout } = await execFileAsync(
132
- "npm",
133
- ["-g", "config", "get", "prefix"],
134
- { cwd: homedir(), timeout: 5e3 }
135
- );
136
- prefix = stdout.trim();
137
- } catch {
138
- return { hasPermissions: false, npmPrefix: null };
139
- }
140
- if (!prefix) return { hasPermissions: false, npmPrefix: null };
141
- try {
142
- await access(prefix, fsConstants.W_OK);
143
- return { hasPermissions: true, npmPrefix: prefix };
144
- } catch {
145
- return { hasPermissions: false, npmPrefix: prefix };
146
- }
147
- }
148
- function userHome() {
149
- return process.env.HOME ?? homedir();
150
- }
151
- function configDir() {
152
- return join(userHome(), ".code-shell");
153
- }
154
- function getLockFilePath() {
155
- return join(configDir(), LOCK_FILE);
156
- }
157
- function getUpdateLogPath() {
158
- return join(configDir(), "update.log");
159
- }
160
- async function acquireLock() {
161
- const lockPath = getLockFilePath();
162
- try {
163
- const s = await stat(lockPath);
164
- if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS) return false;
165
- try {
166
- const recheck = await stat(lockPath);
167
- if (Date.now() - recheck.mtimeMs < LOCK_TIMEOUT_MS) return false;
168
- await unlink(lockPath);
169
- } catch (err) {
170
- if (!isENOENT(err)) return false;
171
- }
172
- } catch (err) {
173
- if (!isENOENT(err)) return false;
174
- }
175
- try {
176
- await writeFile(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
177
- return true;
178
- } catch (err) {
179
- const code = errnoCode(err);
180
- if (code === "EEXIST") return false;
181
- if (code === "ENOENT") {
182
- try {
183
- await mkdir(configDir(), { recursive: true });
184
- await writeFile(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
185
- return true;
186
- } catch {
187
- return false;
188
- }
189
- }
190
- return false;
191
- }
192
- }
193
- async function releaseLock() {
194
- const lockPath = getLockFilePath();
195
- try {
196
- const data = await readFile(lockPath, "utf8");
197
- if (data === String(process.pid)) await unlink(lockPath);
198
- } catch {
199
- }
200
- }
201
- function launchDetachedInstall(version) {
202
- const lockPath = getLockFilePath();
203
- try {
204
- try {
205
- const fs2 = __require("fs");
206
- fs2.mkdirSync(configDir(), { recursive: true });
207
- fs2.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
208
- } catch (err) {
209
- if (errnoCode(err) === "EEXIST") {
210
- try {
211
- const fs2 = __require("fs");
212
- const s = fs2.statSync(lockPath);
213
- if (Date.now() - s.mtimeMs < LOCK_TIMEOUT_MS) return;
214
- fs2.unlinkSync(lockPath);
215
- fs2.writeFileSync(lockPath, String(process.pid), { encoding: "utf8", flag: "wx" });
216
- } catch {
217
- return;
218
- }
219
- } else {
220
- return;
221
- }
222
- }
223
- } catch {
224
- return;
225
- }
226
- const fs = __require("fs");
227
- const logFd = fs.openSync(getUpdateLogPath(), "a");
228
- try {
229
- fs.writeSync(
230
- logFd,
231
- `
232
- [${(/* @__PURE__ */ new Date()).toISOString()}] code-shell auto-update: installing ${PACKAGE_NAME}@${version} (pid=${process.pid})
233
- `
234
- );
235
- } catch {
236
- }
237
- const cmd = [
238
- `npm install -g ${PACKAGE_NAME}@${shellEscape(version)}`,
239
- `; rm -f ${shellEscape(lockPath)}`
240
- ].join(" ");
241
- try {
242
- const child = spawn("sh", ["-c", cmd], {
243
- detached: true,
244
- stdio: ["ignore", logFd, logFd],
245
- cwd: homedir()
246
- });
247
- child.unref();
248
- } catch {
249
- try {
250
- fs.unlinkSync(lockPath);
251
- } catch {
252
- }
253
- }
254
- }
255
- function isAutoUpdaterDisabled() {
256
- if (process.env.NODE_ENV === "development") return "development build";
257
- if (isEnvTruthy(process.env.DISABLE_AUTOUPDATER)) return "DISABLE_AUTOUPDATER set";
258
- if (readAutoUpdatesFlagFromDisk() === false) return "settings.autoUpdates = false";
259
- return null;
260
- }
261
- function readAutoUpdatesFlagFromDisk() {
262
- const path = join(userHome(), ".code-shell", "settings.json");
263
- try {
264
- const raw = readFileSync(path, "utf8");
265
- const parsed = JSON.parse(raw);
266
- if (typeof parsed.autoUpdates === "boolean") return parsed.autoUpdates;
267
- } catch {
268
- }
269
- return void 0;
270
- }
271
- function isEnvTruthy(v) {
272
- if (!v) return false;
273
- const lower = v.toLowerCase();
274
- return lower === "1" || lower === "true" || lower === "yes" || lower === "on";
275
- }
276
- function errnoCode(err) {
277
- return typeof err === "object" && err !== null && "code" in err ? String(err.code) : void 0;
278
- }
279
- function isENOENT(err) {
280
- return errnoCode(err) === "ENOENT";
281
- }
282
- function shellEscape(s) {
283
- return `'${s.replace(/'/g, `'\\''`)}'`;
284
- }
285
- var __internal = { acquireLock, releaseLock, getLockFilePath };
286
-
287
- export {
288
- checkForUpdate,
289
- getUpdateAvailable,
290
- getAutoUpdateDisabledReason,
291
- scheduleAutoInstallOnExit,
292
- getCurrentVersion,
293
- __internal
294
- };