@zerowall/dsh-claude-coderun 0.1.0-preview.2 → 0.1.0-preview.4
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/README.i18n.yaml +4 -4
- package/README.md +3 -1
- package/README.zh.md +3 -1
- package/lib/client.js +85 -58
- package/lib/index.js +313 -112
- package/lib/typert.host.js +65 -57
- package/lib/typert.remote-client.d.ts.map +1 -1
- package/lib/typert.remote-client.js +64 -56
- package/lib/types/client/locales.d.ts +10 -0
- package/lib/types/host/index.d.ts +43 -2
- package/lib/types/host/installer.d.ts +3 -0
- package/lib/types/host/runtime.d.ts +15 -5
- package/lib/types/shared/types.d.ts +2 -1
- package/package.json +7 -5
- package/zerowall.plugin.json +1 -1
package/lib/index.js
CHANGED
|
@@ -48,6 +48,8 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
48
48
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
49
49
|
|
|
50
50
|
// src/host/index.ts
|
|
51
|
+
import schema from "@deepseek-ai/schemastery";
|
|
52
|
+
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
51
53
|
import { appendPluginRecord } from "@deepseek-ai/dsh-session";
|
|
52
54
|
|
|
53
55
|
// src/shared/records.ts
|
|
@@ -85,10 +87,9 @@ import { createToolResultMessage as createToolResultMessage3, isAgentLoopRequest
|
|
|
85
87
|
import { NO_START_CAPABILITIES, assertUsableCwd, settleRunResult, subprocessRunHandle } from "@deepseek-ai/dsh-subagent";
|
|
86
88
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
87
89
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
88
|
-
import { spawn } from "node:child_process";
|
|
89
90
|
import { createHash as createHash4, randomUUID as randomUUID4 } from "node:crypto";
|
|
90
91
|
import { chmod, lstat as lstat2, mkdir as mkdir3, readdir as readdir2, readFile as readFile2, rename as rename2, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
|
|
91
|
-
import {
|
|
92
|
+
import { isAbsolute as isAbsolute4, join as join5, resolve as resolve3 } from "node:path";
|
|
92
93
|
import { stripVTControlCharacters } from "node:util";
|
|
93
94
|
import { SecretBrokerClient } from "@zerowall/dsh-plugin-ai-cloud/secrets";
|
|
94
95
|
|
|
@@ -96,27 +97,25 @@ import { SecretBrokerClient } from "@zerowall/dsh-plugin-ai-cloud/secrets";
|
|
|
96
97
|
import { randomUUID } from "node:crypto";
|
|
97
98
|
import { existsSync as nodeExistsSync } from "node:fs";
|
|
98
99
|
import * as nodeFs from "node:fs/promises";
|
|
99
|
-
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
100
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
100
101
|
var CLAUDE_CODE_PACKAGE = "@anthropic-ai/claude-code";
|
|
101
102
|
var CLAUDE_CODE_VERSION = "2.1.309";
|
|
102
103
|
var CLAUDE_CODE_REGISTRY = "https://registry.npmmirror.com";
|
|
104
|
+
var ClaudeInstallError = class extends Error {
|
|
105
|
+
};
|
|
103
106
|
function resolveBundledPnpmRuntime(options = {}) {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
107
|
+
const env = process.env;
|
|
108
|
+
const runtimeRoot = options.runtimeRoot ?? env.ZEROWALL_DESKTOP_RUNTIME_ROOT;
|
|
109
|
+
const pnpmEntry = options.pnpmEntry ?? env.ZEROWALL_DESKTOP_PNPM_ENTRY;
|
|
110
|
+
const executable = options.executable ?? env.DSH_DESKTOP_NODE_EXECUTABLE;
|
|
106
111
|
const exists = options.existsSync ?? nodeExistsSync;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (!pnpmPath) {
|
|
115
|
-
throw new Error(electron ? "ZeroWall bundled pnpm is unavailable under process.resourcesPath/commands/pnpm." : "ZeroWall bundled pnpm is unavailable in the development runtime paths.");
|
|
116
|
-
}
|
|
117
|
-
const executable = resolve(options.executable ?? process.execPath);
|
|
118
|
-
if (!isAbsolute(executable)) throw new Error("ZeroWall bundled Node/Electron executable must be an absolute path.");
|
|
119
|
-
return { executable, pnpmPath: resolve(pnpmPath) };
|
|
112
|
+
if (!runtimeRoot || !pnpmEntry || !executable || ![runtimeRoot, pnpmEntry, executable].every(isAbsolute)) {
|
|
113
|
+
throw new Error("Desktop runtime locations are unavailable. Launch the installed ZeroWall Desktop application.");
|
|
114
|
+
}
|
|
115
|
+
if (!isInside(runtimeRoot, pnpmEntry) || !exists(pnpmEntry) || !exists(executable)) {
|
|
116
|
+
throw new Error("Desktop bundled Node or pnpm is missing. Repair the application installation.");
|
|
117
|
+
}
|
|
118
|
+
return { executable: resolve(executable), pnpmPath: resolve(pnpmEntry) };
|
|
120
119
|
}
|
|
121
120
|
var safeId = /^[a-zA-Z0-9_-]{1,80}$/u;
|
|
122
121
|
var lockNonce = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
@@ -203,7 +202,16 @@ var ClaudeRuntimeManager = class {
|
|
|
203
202
|
#createId;
|
|
204
203
|
#processProbe;
|
|
205
204
|
#busy = false;
|
|
205
|
+
#version;
|
|
206
|
+
#registry;
|
|
207
|
+
#signal;
|
|
208
|
+
#onPhase;
|
|
206
209
|
constructor(options) {
|
|
210
|
+
this.#version = options.version ?? CLAUDE_CODE_VERSION;
|
|
211
|
+
this.#registry = options.registry ?? CLAUDE_CODE_REGISTRY;
|
|
212
|
+
if (!/^\d+\.\d+\.\d+$/.test(this.#version) || new URL(this.#registry).protocol !== "https:") throw new Error("Claude runtime requires an exact version and HTTPS npm registry.");
|
|
213
|
+
this.#signal = options.signal;
|
|
214
|
+
this.#onPhase = options.onPhase;
|
|
207
215
|
this.dataDir = resolve(options.dataDir);
|
|
208
216
|
this.configDir = join(this.dataDir, "config");
|
|
209
217
|
this.homeDir = join(this.dataDir, "home");
|
|
@@ -229,13 +237,13 @@ var ClaudeRuntimeManager = class {
|
|
|
229
237
|
const versionsRoot = join(this.dataDir, "versions");
|
|
230
238
|
await this.#verifyRealPathInside(this.dataDir, versionsRoot, "Claude Code versions directory", "directory", true);
|
|
231
239
|
const activePath = this.#generationPath(state.current.id);
|
|
232
|
-
if (!await this.#exists(activePath)) return
|
|
240
|
+
if (!await this.#exists(activePath)) return { installed: false, ...state.previous ? { previousVersion: state.previous.version } : {} };
|
|
233
241
|
await this.#verifyRealPathInside(versionsRoot, activePath, "Active Claude Code generation", "directory", true);
|
|
234
242
|
const executablePath = resolve(activePath, state.current.executable);
|
|
235
243
|
if (!isInside(activePath, executablePath) || !isAbsolute(executablePath)) {
|
|
236
244
|
throw new Error("Claude Code runtime state contains an invalid executable path.");
|
|
237
245
|
}
|
|
238
|
-
if (!await this.#exists(executablePath)) return
|
|
246
|
+
if (!await this.#exists(executablePath)) return { installed: false, ...state.previous ? { previousVersion: state.previous.version } : {} };
|
|
239
247
|
await this.#verifyRealPathInside(activePath, executablePath, "Claude Code runtime executable", "file", true);
|
|
240
248
|
return {
|
|
241
249
|
installed: true,
|
|
@@ -244,8 +252,32 @@ var ClaudeRuntimeManager = class {
|
|
|
244
252
|
...state.previous ? { previousVersion: state.previous.version } : {}
|
|
245
253
|
};
|
|
246
254
|
}
|
|
255
|
+
/** Verify the active executable without downloading or changing activation state. */
|
|
256
|
+
async inspect() {
|
|
257
|
+
const status = await this.status();
|
|
258
|
+
if (!status.installed || !status.executablePath) return status;
|
|
259
|
+
const javascript = /\.[cm]?js$/iu.test(status.executablePath);
|
|
260
|
+
const probe = await this.#run(
|
|
261
|
+
javascript ? this.#pnpm.executable : status.executablePath,
|
|
262
|
+
javascript ? [status.executablePath, "--version"] : ["--version"],
|
|
263
|
+
{
|
|
264
|
+
cwd: this.dataDir,
|
|
265
|
+
env: this.getCliEnvironment(),
|
|
266
|
+
windowsHide: true,
|
|
267
|
+
signal: this.#signal,
|
|
268
|
+
timeoutMs: 15e3
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
if (probe.code !== 0 || probe.stdout?.trim() !== `${status.version} (Claude Code)`) throw new Error("Claude Code version verification failed. Repair the managed installation.");
|
|
272
|
+
return status;
|
|
273
|
+
}
|
|
274
|
+
/** Explicitly repair an activation pointer using a retained, verified generation. */
|
|
275
|
+
async recover() {
|
|
276
|
+
return this.#recoverMissingGeneration();
|
|
277
|
+
}
|
|
247
278
|
/** Install the pinned CLI into a private candidate and atomically activate it. */
|
|
248
279
|
async installOrUpdate() {
|
|
280
|
+
this.#onPhase?.("installing");
|
|
249
281
|
return this.#withMutation(async () => {
|
|
250
282
|
await this.#ensurePrivateDirectories();
|
|
251
283
|
const prior = await this.#readState();
|
|
@@ -262,32 +294,36 @@ var ClaudeRuntimeManager = class {
|
|
|
262
294
|
name: "zerowall-claude-code-runtime",
|
|
263
295
|
private: true,
|
|
264
296
|
version: "1.0.0",
|
|
265
|
-
dependencies: { [CLAUDE_CODE_PACKAGE]:
|
|
297
|
+
dependencies: { [CLAUDE_CODE_PACKAGE]: this.#version }
|
|
266
298
|
}, null, 2), { mode: 384 });
|
|
267
|
-
await this.#fs.writeFile(join(candidate, ".npmrc"), `registry=${
|
|
299
|
+
await this.#fs.writeFile(join(candidate, ".npmrc"), `registry=${this.#registry}
|
|
268
300
|
`, { mode: 384 });
|
|
269
301
|
await this.#fs.writeFile(join(candidate, "pnpm-workspace.yaml"), [
|
|
270
302
|
"packages: []",
|
|
271
303
|
"strictDepBuilds: true",
|
|
272
304
|
"allowBuilds:",
|
|
273
|
-
` '${CLAUDE_CODE_PACKAGE}@${
|
|
305
|
+
` '${CLAUDE_CODE_PACKAGE}@${this.#version}': true`,
|
|
274
306
|
""
|
|
275
307
|
].join("\n"), { mode: 384 });
|
|
276
308
|
const result = await this.#run(this.#pnpm.executable, [
|
|
309
|
+
"--expose-internals",
|
|
277
310
|
this.#pnpm.pnpmPath,
|
|
278
311
|
"install",
|
|
279
|
-
|
|
312
|
+
"--node-linker=hoisted",
|
|
313
|
+
`--registry=${this.#registry}`,
|
|
280
314
|
`--store-dir=${this.storeDir}`
|
|
281
315
|
], {
|
|
282
316
|
cwd: candidate,
|
|
283
317
|
env: this.#buildInstallEnvironment(join(candidate, ".npmrc")),
|
|
284
|
-
windowsHide: true
|
|
318
|
+
windowsHide: true,
|
|
319
|
+
signal: this.#signal,
|
|
320
|
+
timeoutMs: 3e5
|
|
285
321
|
});
|
|
286
|
-
if (result.code !== 0) throw new
|
|
322
|
+
if (result.code !== 0) throw new ClaudeInstallError(`Claude Code installation failed (pnpm exited ${result.code}).`);
|
|
287
323
|
const packageRoot = join(candidate, "node_modules", "@anthropic-ai", "claude-code");
|
|
288
324
|
const packageJson = JSON.parse(String(await this.#fs.readFile(join(packageRoot, "package.json"), "utf8")));
|
|
289
|
-
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !==
|
|
290
|
-
throw new Error(`Installed Claude Code package did not match the pinned ${
|
|
325
|
+
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !== this.#version) {
|
|
326
|
+
throw new Error(`Installed Claude Code package did not match the pinned ${this.#version} release.`);
|
|
291
327
|
}
|
|
292
328
|
const relativeCli = this.#resolveCliRelative(packageJson);
|
|
293
329
|
const executablePath = resolve(packageRoot, relativeCli);
|
|
@@ -300,6 +336,7 @@ var ClaudeRuntimeManager = class {
|
|
|
300
336
|
const generationReal = await this.#fs.realpath(candidate);
|
|
301
337
|
const packageReal = await this.#verifyRealPathInside(generationReal, packageRoot, "Installed Claude Code package", "directory");
|
|
302
338
|
await this.#verifyRealPathInside(packageReal, executablePath, "Installed Claude Code executable", "file", true);
|
|
339
|
+
this.#onPhase?.("verifying");
|
|
303
340
|
const javascriptCli = /\.[cm]?js$/iu.test(executablePath);
|
|
304
341
|
const probe = await this.#run(
|
|
305
342
|
javascriptCli ? this.#pnpm.executable : executablePath,
|
|
@@ -307,18 +344,21 @@ var ClaudeRuntimeManager = class {
|
|
|
307
344
|
{
|
|
308
345
|
cwd: candidate,
|
|
309
346
|
env: this.getCliEnvironment(),
|
|
310
|
-
windowsHide: true
|
|
347
|
+
windowsHide: true,
|
|
348
|
+
signal: this.#signal,
|
|
349
|
+
timeoutMs: 15e3
|
|
311
350
|
}
|
|
312
351
|
);
|
|
313
|
-
if (probe.code !== 0 || probe.stdout?.trim() !== `${
|
|
352
|
+
if (probe.code !== 0 || probe.stdout?.trim() !== `${this.#version} (Claude Code)`) {
|
|
314
353
|
throw new Error("Installed Claude Code CLI failed its pinned version health check.");
|
|
315
354
|
}
|
|
316
355
|
const previous = prior?.current ?? prior?.previous ?? null;
|
|
317
356
|
const next = {
|
|
318
357
|
schema: 1,
|
|
319
|
-
current: { id, version:
|
|
358
|
+
current: { id, version: this.#version, executable: relative(active, executablePath) },
|
|
320
359
|
previous
|
|
321
360
|
};
|
|
361
|
+
this.#signal?.throwIfAborted();
|
|
322
362
|
await this.#writeState(next);
|
|
323
363
|
promoted = true;
|
|
324
364
|
return this.status();
|
|
@@ -374,7 +414,7 @@ var ClaudeRuntimeManager = class {
|
|
|
374
414
|
const packageRoot = join(generationRoot, "node_modules", "@anthropic-ai", "claude-code");
|
|
375
415
|
await this.#verifyRealPathInside(generationRoot, packageRoot, "Retained Claude Code package", "directory");
|
|
376
416
|
const packageJson = JSON.parse(String(await this.#fs.readFile(join(packageRoot, "package.json"), "utf8")));
|
|
377
|
-
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !==
|
|
417
|
+
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !== this.#version) continue;
|
|
378
418
|
const executablePath = resolve(packageRoot, this.#resolveCliRelative(packageJson));
|
|
379
419
|
if (!isInside(packageRoot, executablePath) || !await this.#exists(executablePath)) continue;
|
|
380
420
|
const packageReal = await this.#fs.realpath(packageRoot);
|
|
@@ -389,14 +429,14 @@ var ClaudeRuntimeManager = class {
|
|
|
389
429
|
windowsHide: true
|
|
390
430
|
}
|
|
391
431
|
);
|
|
392
|
-
if (probe.code !== 0 || probe.stdout?.trim() !== `${
|
|
393
|
-
healthy.push({ id, version:
|
|
432
|
+
if (probe.code !== 0 || probe.stdout?.trim() !== `${this.#version} (Claude Code)`) continue;
|
|
433
|
+
healthy.push({ id, version: this.#version, executable: relative(generationRoot, executablePath) });
|
|
394
434
|
if (healthy.length === 2) break;
|
|
395
435
|
} catch {
|
|
396
436
|
}
|
|
397
437
|
}
|
|
398
438
|
if (!healthy.length) {
|
|
399
|
-
throw new Error(`Claude Code's active executable is missing, and no retained managed generation passed the ${
|
|
439
|
+
throw new Error(`Claude Code's active executable is missing, and no retained managed generation passed the ${this.#version} health check. Reinstall Claude Code from plugin settings.`);
|
|
400
440
|
}
|
|
401
441
|
await this.#writeState({ schema: 1, current: healthy[0], previous: healthy[1] ?? null });
|
|
402
442
|
return this.status();
|
|
@@ -476,12 +516,14 @@ var ClaudeRuntimeManager = class {
|
|
|
476
516
|
}
|
|
477
517
|
env[key] = value;
|
|
478
518
|
}
|
|
479
|
-
env.npm_config_registry =
|
|
519
|
+
env.npm_config_registry = this.#registry;
|
|
480
520
|
env.PNPM_HOME = join(this.dataDir, "pnpm-home");
|
|
481
521
|
return env;
|
|
482
522
|
}
|
|
483
523
|
#buildInstallEnvironment(userConfigFile) {
|
|
484
|
-
|
|
524
|
+
const env = this.#buildEnvironment({ npm_config_userconfig: userConfigFile });
|
|
525
|
+
env.PATH = [dirname(this.#pnpm.executable), env.PATH].filter(Boolean).join(this.#platform === "win32" ? ";" : ":");
|
|
526
|
+
return env;
|
|
485
527
|
}
|
|
486
528
|
#resolveCliRelative(packageJson) {
|
|
487
529
|
if (this.#platform === "win32") return join("bin", "claude.exe");
|
|
@@ -566,7 +608,7 @@ var ClaudeRuntimeManager = class {
|
|
|
566
608
|
throw error;
|
|
567
609
|
}
|
|
568
610
|
const state = JSON.parse(text);
|
|
569
|
-
const validGeneration = (entry) => Boolean(entry && safeId.test(entry.id) && entry.version ===
|
|
611
|
+
const validGeneration = (entry) => Boolean(entry && safeId.test(entry.id) && entry.version === this.#version && typeof entry.executable === "string" && entry.executable.length > 0 && !isAbsolute(entry.executable) && !entry.executable.split(/[\\/]/u).includes(".."));
|
|
570
612
|
if (state.schema !== 1 || !validGeneration(state.current) || state.previous !== null && !validGeneration(state.previous)) {
|
|
571
613
|
throw new Error("Claude Code runtime state is invalid.");
|
|
572
614
|
}
|
|
@@ -687,11 +729,82 @@ var ClaudeRuntimeManager = class {
|
|
|
687
729
|
}
|
|
688
730
|
};
|
|
689
731
|
|
|
732
|
+
// src/host/installer.ts
|
|
733
|
+
import { spawn } from "node:child_process";
|
|
734
|
+
import { join as join2 } from "node:path";
|
|
735
|
+
var runInstaller = (command, args, options) => new Promise((resolve4, reject) => {
|
|
736
|
+
const { timeoutMs = 3e5, signal, ...spawnOptions } = options;
|
|
737
|
+
if (signal?.aborted) {
|
|
738
|
+
reject(new Error("Claude Code preparation was canceled."));
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const versionProbe = args.at(-1) === "--version";
|
|
742
|
+
let stdout = "";
|
|
743
|
+
let failure;
|
|
744
|
+
let stopping;
|
|
745
|
+
let closed = false;
|
|
746
|
+
const child = spawn(command, args, { ...spawnOptions, detached: process.platform !== "win32", env: {
|
|
747
|
+
...options.env,
|
|
748
|
+
...process.versions.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {}
|
|
749
|
+
}, stdio: ["ignore", "pipe", "pipe"] });
|
|
750
|
+
const stop = (message) => {
|
|
751
|
+
if (closed || stopping) return;
|
|
752
|
+
failure = new Error(message);
|
|
753
|
+
stopping = new Promise((done) => {
|
|
754
|
+
if (!child.pid) {
|
|
755
|
+
done();
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (process.platform === "win32") {
|
|
759
|
+
const killer = spawn(join2(process.env.SystemRoot ?? process.env.WINDIR ?? "", "System32", "taskkill.exe"), ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
760
|
+
killer.once("error", () => {
|
|
761
|
+
child.kill();
|
|
762
|
+
done();
|
|
763
|
+
});
|
|
764
|
+
killer.once("close", (code) => {
|
|
765
|
+
if (code !== 0) child.kill();
|
|
766
|
+
done();
|
|
767
|
+
});
|
|
768
|
+
} else {
|
|
769
|
+
try {
|
|
770
|
+
process.kill(-child.pid, "SIGKILL");
|
|
771
|
+
} catch (error) {
|
|
772
|
+
if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) failure = new Error("Claude Code process cleanup failed.");
|
|
773
|
+
}
|
|
774
|
+
done();
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
};
|
|
778
|
+
const abort = () => stop("Claude Code preparation was canceled.");
|
|
779
|
+
const deadline = setTimeout(() => stop("Claude Code preparation timed out. Check the network and retry."), timeoutMs);
|
|
780
|
+
deadline.unref();
|
|
781
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
782
|
+
if (signal?.aborted) abort();
|
|
783
|
+
child.stdout?.setEncoding("utf8");
|
|
784
|
+
child.stdout?.on("data", (data) => {
|
|
785
|
+
if (versionProbe) stdout = (stdout + data).slice(0, 4096);
|
|
786
|
+
});
|
|
787
|
+
child.stderr?.resume();
|
|
788
|
+
child.once("error", () => {
|
|
789
|
+
failure ??= new Error("Claude Code process could not start. Repair the application installation.");
|
|
790
|
+
});
|
|
791
|
+
child.once("close", () => {
|
|
792
|
+
closed = true;
|
|
793
|
+
clearTimeout(deadline);
|
|
794
|
+
signal?.removeEventListener("abort", abort);
|
|
795
|
+
});
|
|
796
|
+
child.once("close", async (code) => {
|
|
797
|
+
await stopping;
|
|
798
|
+
if (failure) reject(failure);
|
|
799
|
+
else resolve4({ code: code ?? -1, ...versionProbe ? { stdout } : {} });
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
|
|
690
803
|
// src/host/mcp-launcher.ts
|
|
691
804
|
import { createHash } from "node:crypto";
|
|
692
805
|
import { constants } from "node:fs";
|
|
693
806
|
import { access, mkdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
694
|
-
import { delimiter, extname, isAbsolute as isAbsolute2, join as
|
|
807
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
695
808
|
var launcherSource = `'use strict';
|
|
696
809
|
const { spawn } = require('node:child_process');
|
|
697
810
|
const { readFileSync } = require('node:fs');
|
|
@@ -768,7 +881,7 @@ async function resolveNativeFromPath(command, searchPath) {
|
|
|
768
881
|
if (!isAbsolute2(directory)) continue;
|
|
769
882
|
for (const suffix of extensions) {
|
|
770
883
|
try {
|
|
771
|
-
const candidate = await realpath(
|
|
884
|
+
const candidate = await realpath(join3(directory, `${command}${suffix}`));
|
|
772
885
|
if (!(await stat(candidate)).isFile()) continue;
|
|
773
886
|
if (process.platform !== "win32") await access(candidate, constants.X_OK);
|
|
774
887
|
return candidate;
|
|
@@ -780,11 +893,11 @@ async function resolveNativeFromPath(command, searchPath) {
|
|
|
780
893
|
}
|
|
781
894
|
async function writeClaudeMcpLaunchers(projection, options) {
|
|
782
895
|
if (!isAbsolute2(options.root) || !isAbsolute2(options.executable) || options.root.includes("\0") || options.executable.includes("\0")) throw new Error("Invalid MCP launcher runtime.");
|
|
783
|
-
const root =
|
|
896
|
+
const root = join3(options.root, "mcp-launchers");
|
|
784
897
|
const wrapped = projection.servers.some((server) => server.type === "stdio" && server.launcher);
|
|
785
898
|
if (wrapped) {
|
|
786
899
|
await mkdir(root, { recursive: true, mode: 448 });
|
|
787
|
-
await writeFile(
|
|
900
|
+
await writeFile(join3(root, "launch.cjs"), launcherSource, { mode: 384 });
|
|
788
901
|
}
|
|
789
902
|
const servers = [];
|
|
790
903
|
const skipped = [];
|
|
@@ -803,7 +916,7 @@ async function writeClaudeMcpLaunchers(projection, options) {
|
|
|
803
916
|
skipped.push({ serverName: server.serverName, reason: "unsupported-launch" });
|
|
804
917
|
continue;
|
|
805
918
|
}
|
|
806
|
-
const specPath =
|
|
919
|
+
const specPath = join3(root, `${createHash("sha256").update(server.serverName).digest("hex")}.json`);
|
|
807
920
|
const env = Object.fromEntries(Object.entries(server.env ?? {}).map(([target, placeholder]) => {
|
|
808
921
|
const match = /^\$\{(ZW_CLAUDE_MCP_[A-F0-9]{20})\}$/u.exec(placeholder);
|
|
809
922
|
if (!match) throw new Error("Claude MCP launcher credential placeholder is invalid.");
|
|
@@ -820,7 +933,7 @@ async function writeClaudeMcpLaunchers(projection, options) {
|
|
|
820
933
|
serverName: server.serverName,
|
|
821
934
|
type: "stdio",
|
|
822
935
|
command: options.executable,
|
|
823
|
-
args: [
|
|
936
|
+
args: [join3(root, "launch.cjs"), specPath],
|
|
824
937
|
...server.env || options.electron ? { env: { ...server.env, ...options.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {} } } : {}
|
|
825
938
|
});
|
|
826
939
|
}
|
|
@@ -1304,7 +1417,7 @@ var CLAUDE_MODE_BY_SANDBOX = {
|
|
|
1304
1417
|
// src/host/session-binding.ts
|
|
1305
1418
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
1306
1419
|
import { lstat, mkdir as mkdir2, readFile, readdir, rename, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
1307
|
-
import { join as
|
|
1420
|
+
import { join as join4 } from "node:path";
|
|
1308
1421
|
import { createReadStream } from "node:fs";
|
|
1309
1422
|
import { createInterface } from "node:readline";
|
|
1310
1423
|
var ClaudeSessionBindings = class {
|
|
@@ -1313,7 +1426,7 @@ var ClaudeSessionBindings = class {
|
|
|
1313
1426
|
}
|
|
1314
1427
|
configDir;
|
|
1315
1428
|
file(id) {
|
|
1316
|
-
return
|
|
1429
|
+
return join4(this.configDir, "bindings", `${createHash3("sha256").update(id).digest("hex")}.json`);
|
|
1317
1430
|
}
|
|
1318
1431
|
async load(id, cwd) {
|
|
1319
1432
|
let previous;
|
|
@@ -1361,7 +1474,7 @@ var ClaudeSessionBindings = class {
|
|
|
1361
1474
|
}
|
|
1362
1475
|
async save(id, binding) {
|
|
1363
1476
|
const file = this.file(id), temporary = `${file}.${randomUUID2()}.tmp`;
|
|
1364
|
-
await mkdir2(
|
|
1477
|
+
await mkdir2(join4(this.configDir, "bindings"), { recursive: true, mode: 448 });
|
|
1365
1478
|
await writeFile2(temporary, JSON.stringify(binding), { mode: 384, flag: "wx" });
|
|
1366
1479
|
try {
|
|
1367
1480
|
await rename(temporary, file);
|
|
@@ -1370,18 +1483,18 @@ var ClaudeSessionBindings = class {
|
|
|
1370
1483
|
}
|
|
1371
1484
|
}
|
|
1372
1485
|
async transcript(nativeId) {
|
|
1373
|
-
const root =
|
|
1486
|
+
const root = join4(this.configDir, "projects");
|
|
1374
1487
|
const directories = await readdir(root, { withFileTypes: true }).catch((error) => {
|
|
1375
1488
|
if (error.code === "ENOENT") return [];
|
|
1376
1489
|
throw error;
|
|
1377
1490
|
});
|
|
1378
1491
|
for (const directory of directories) {
|
|
1379
1492
|
if (!directory.isDirectory() || directory.isSymbolicLink()) continue;
|
|
1380
|
-
const info = await lstat(
|
|
1493
|
+
const info = await lstat(join4(root, directory.name, `${nativeId}.jsonl`)).catch((error) => {
|
|
1381
1494
|
if (error.code === "ENOENT") return void 0;
|
|
1382
1495
|
throw error;
|
|
1383
1496
|
});
|
|
1384
|
-
if (info?.isFile() && !info.isSymbolicLink() && info.size > 0) return
|
|
1497
|
+
if (info?.isFile() && !info.isSymbolicLink() && info.size > 0) return join4(root, directory.name, `${nativeId}.jsonl`);
|
|
1385
1498
|
}
|
|
1386
1499
|
return void 0;
|
|
1387
1500
|
}
|
|
@@ -1480,25 +1593,25 @@ function createHostToolBridge(agent, schemas, signal, source, state = { conclude
|
|
|
1480
1593
|
previousClose?.();
|
|
1481
1594
|
};
|
|
1482
1595
|
signal.addEventListener("abort", dispose, { once: true });
|
|
1483
|
-
server.instance.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: currentSchemas().map((
|
|
1484
|
-
name:
|
|
1485
|
-
description:
|
|
1486
|
-
inputSchema:
|
|
1596
|
+
server.instance.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: currentSchemas().map((schema2) => ({
|
|
1597
|
+
name: schema2.name,
|
|
1598
|
+
description: schema2.description,
|
|
1599
|
+
inputSchema: schema2.parameters
|
|
1487
1600
|
})) }));
|
|
1488
1601
|
let queue = Promise.resolve();
|
|
1489
1602
|
state.drain = () => queue;
|
|
1490
1603
|
server.instance.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
1491
1604
|
const previous = queue;
|
|
1492
1605
|
let release;
|
|
1493
|
-
queue = new Promise((
|
|
1494
|
-
release =
|
|
1606
|
+
queue = new Promise((resolve4) => {
|
|
1607
|
+
release = resolve4;
|
|
1495
1608
|
});
|
|
1496
1609
|
await previous;
|
|
1497
1610
|
try {
|
|
1498
1611
|
signal.throwIfAborted();
|
|
1499
1612
|
extra.signal.throwIfAborted();
|
|
1500
1613
|
if (state.concluded) return { content: [{ type: "text", text: "The Host concluded this turn; no further operation was executed." }], isError: true };
|
|
1501
|
-
if (!currentSchemas().some((
|
|
1614
|
+
if (!currentSchemas().some((schema2) => schema2.name === request.params.name)) throw new Error("Tool is not visible in this conversation.");
|
|
1502
1615
|
const callId = ToolCallId2(`claude-host-${randomUUID3()}`);
|
|
1503
1616
|
const lifetime = AbortSignal.any([signal, extra.signal]);
|
|
1504
1617
|
const tools = agent.ctx.get("tools");
|
|
@@ -2215,22 +2328,6 @@ function contextUsageView(value, detail) {
|
|
|
2215
2328
|
...safeApiUsage ? { apiUsage: safeApiUsage } : {}
|
|
2216
2329
|
};
|
|
2217
2330
|
}
|
|
2218
|
-
var runInstaller = (command, args, options) => new Promise((resolve3, reject) => {
|
|
2219
|
-
const versionProbe = args.at(-1) === "--version";
|
|
2220
|
-
let stdout = "";
|
|
2221
|
-
const child = spawn(command, args, { ...options, env: {
|
|
2222
|
-
...options.env,
|
|
2223
|
-
...process.versions.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {}
|
|
2224
|
-
}, stdio: ["ignore", "pipe", "pipe"] });
|
|
2225
|
-
child.stdout?.setEncoding("utf8");
|
|
2226
|
-
child.stdout?.on("data", (data) => {
|
|
2227
|
-
if (versionProbe) stdout = (stdout + data).slice(0, 4096);
|
|
2228
|
-
});
|
|
2229
|
-
child.stderr?.on("data", () => {
|
|
2230
|
-
});
|
|
2231
|
-
child.once("error", () => reject(new Error("Claude Code \u5B89\u88C5\u8FDB\u7A0B\u65E0\u6CD5\u542F\u52A8\u3002")));
|
|
2232
|
-
child.once("close", (code) => resolve3({ code: code ?? -1, ...versionProbe ? { stdout } : {} }));
|
|
2233
|
-
});
|
|
2234
2331
|
var CLAUDE_SETTINGS_DEFAULTS = {
|
|
2235
2332
|
outputStyle: "Default",
|
|
2236
2333
|
permissionSelector: "plugin",
|
|
@@ -2284,8 +2381,9 @@ function validateNativeSettings(value) {
|
|
|
2284
2381
|
}
|
|
2285
2382
|
var _clear_dec, _stop_dec, _readTranscript_dec, _read_dec, _cliSetPermissionMode_dec, _cliSetModel_dec, _contextUsage_dec, _permissionSet_dec, _permissionView_dec, _settingsUninstall_dec, _settingsRollback_dec, _settingsInstall_dec, _uninstall_dec, _rollback_dec, _install_dec, _settingsGlobalUpdate_dec, _settingsGlobalGet_dec, _settingsUpdate_dec, _settingsGet_dec, _settingsStatus_dec, _status_dec, _a, _init;
|
|
2286
2383
|
var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [Remote], _settingsStatus_dec = [Remote("settingsStatus")], _settingsGet_dec = [Remote("settingsGet")], _settingsUpdate_dec = [Remote("settingsUpdate")], _settingsGlobalGet_dec = [Remote("settingsGlobalGet")], _settingsGlobalUpdate_dec = [Remote("settingsGlobalUpdate")], _install_dec = [Remote("installCli")], _rollback_dec = [Remote], _uninstall_dec = [Remote], _settingsInstall_dec = [Remote("settingsInstall")], _settingsRollback_dec = [Remote("settingsRollback")], _settingsUninstall_dec = [Remote("settingsUninstall")], _permissionView_dec = [Remote], _permissionSet_dec = [Remote], _contextUsage_dec = [Remote("contextUsage")], _cliSetModel_dec = [Remote("cliSetModel")], _cliSetPermissionMode_dec = [Remote("cliSetPermissionMode")], _read_dec = [Remote], _readTranscript_dec = [Remote], _stop_dec = [Remote], _clear_dec = [Remote], _a) {
|
|
2287
|
-
constructor(ctx) {
|
|
2384
|
+
constructor(ctx, config = {}) {
|
|
2288
2385
|
super(ctx, "zerowallClaudeCode");
|
|
2386
|
+
this.config = config;
|
|
2289
2387
|
__runInitializers(_init, 5, this);
|
|
2290
2388
|
__publicField(this, "manager");
|
|
2291
2389
|
__publicField(this, "secrets");
|
|
@@ -2295,7 +2393,19 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2295
2393
|
__publicField(this, "mutation", false);
|
|
2296
2394
|
__publicField(this, "chatAgents", /* @__PURE__ */ new Map());
|
|
2297
2395
|
__publicField(this, "processReservations", 0);
|
|
2396
|
+
__publicField(this, "runtimeInitialization");
|
|
2397
|
+
__publicField(this, "preparation");
|
|
2398
|
+
__publicField(this, "installAbort", new AbortController());
|
|
2399
|
+
__publicField(this, "readiness", "checking");
|
|
2400
|
+
__publicField(this, "runtimeDiagnostic");
|
|
2401
|
+
__publicField(this, "autoSuppressed", false);
|
|
2402
|
+
__publicField(this, "disposed", false);
|
|
2403
|
+
__publicField(this, "preparationRevision", 0);
|
|
2298
2404
|
this.secrets = new SecretBrokerClient(ctx.credentials);
|
|
2405
|
+
this.runtimeInitialization = this.initializeRuntime().catch(() => {
|
|
2406
|
+
this.readiness = "failed";
|
|
2407
|
+
this.runtimeDiagnostic = "Claude Code \u81EA\u52A8\u51C6\u5907\u5931\u8D25\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u3001\u955C\u50CF\u548C\u5E94\u7528\u8FD0\u884C\u6587\u4EF6\uFF0C\u7136\u540E\u5728\u63D2\u4EF6\u8BBE\u7F6E\u4E2D\u91CD\u8BD5\u3002";
|
|
2408
|
+
});
|
|
2299
2409
|
ctx.sessionProjections.register(claudeMetricsProjection);
|
|
2300
2410
|
ctx.inject(["subagents"], (scope) => {
|
|
2301
2411
|
const subagents = scope.get("subagents");
|
|
@@ -2318,7 +2428,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2318
2428
|
});
|
|
2319
2429
|
});
|
|
2320
2430
|
ctx.on("agent/request", async ({ agent }, next) => {
|
|
2321
|
-
const
|
|
2431
|
+
const config2 = await next();
|
|
2322
2432
|
const projections = ctx.get("sessionProjections");
|
|
2323
2433
|
if (projections.stateOf(agent.session, "agentPreset") === "claude") {
|
|
2324
2434
|
const permission2 = await this.permissionView(agent);
|
|
@@ -2330,7 +2440,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2330
2440
|
}
|
|
2331
2441
|
this.chatAgents.set(agent.id, agent);
|
|
2332
2442
|
} else this.chatAgents.delete(agent.id);
|
|
2333
|
-
return
|
|
2443
|
+
return config2;
|
|
2334
2444
|
});
|
|
2335
2445
|
ctx.on("agent/status", ({ agent, status }) => {
|
|
2336
2446
|
if (status === "idle") this.chatAgents.delete(agent.id);
|
|
@@ -2356,6 +2466,10 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2356
2466
|
}, options);
|
|
2357
2467
|
});
|
|
2358
2468
|
ctx.effect(() => async () => {
|
|
2469
|
+
this.disposed = true;
|
|
2470
|
+
this.installAbort.abort();
|
|
2471
|
+
await this.runtimeInitialization;
|
|
2472
|
+
await this.preparation?.catch(() => void 0);
|
|
2359
2473
|
await Promise.allSettled([...this.sessions.values()].map(async (state) => {
|
|
2360
2474
|
state.preparing?.abort();
|
|
2361
2475
|
state.turn?.cancel.abort();
|
|
@@ -2366,8 +2480,12 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2366
2480
|
this.chatAgents.clear();
|
|
2367
2481
|
}, "claude-code: terminate plugin-owned processes");
|
|
2368
2482
|
}
|
|
2483
|
+
config;
|
|
2369
2484
|
desktop() {
|
|
2370
|
-
return Boolean(process.env.
|
|
2485
|
+
return Boolean(process.env.ZEROWALL_DESKTOP_RUNTIME_ROOT && isAbsolute4(process.env.ZEROWALL_DESKTOP_RUNTIME_ROOT));
|
|
2486
|
+
}
|
|
2487
|
+
runtimeRoot() {
|
|
2488
|
+
return resolve3(this.config.runtimeRoot ?? process.env.ZEROWALL_CLAUDE_RUNTIME_ROOT ?? join5(resolveDshHome(), "zerowall", "claude-code", "runtime"));
|
|
2371
2489
|
}
|
|
2372
2490
|
anyRunning() {
|
|
2373
2491
|
return [...this.sessions.values()].some((state) => state.busy || state.turn?.view.running === true);
|
|
@@ -2378,10 +2496,15 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2378
2496
|
runtime() {
|
|
2379
2497
|
if (!this.desktop()) throw new Error("Claude Code \u5B89\u88C5\u4E0E\u8FD0\u884C\u4EC5\u9002\u7528\u4E8E ZeroWall Desktop\u3002");
|
|
2380
2498
|
if (!this.manager) {
|
|
2381
|
-
const resourcesPath = process.resourcesPath ?? join4(dirname(process.execPath), "resources");
|
|
2382
2499
|
this.manager = new ClaudeRuntimeManager({
|
|
2383
|
-
dataDir:
|
|
2384
|
-
pnpm: resolveBundledPnpmRuntime(
|
|
2500
|
+
dataDir: this.runtimeRoot(),
|
|
2501
|
+
pnpm: resolveBundledPnpmRuntime(),
|
|
2502
|
+
version: this.config.version,
|
|
2503
|
+
registry: this.config.registry,
|
|
2504
|
+
signal: this.installAbort.signal,
|
|
2505
|
+
onPhase: (phase) => {
|
|
2506
|
+
this.readiness = phase;
|
|
2507
|
+
},
|
|
2385
2508
|
run: runInstaller
|
|
2386
2509
|
});
|
|
2387
2510
|
}
|
|
@@ -2399,16 +2522,16 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2399
2522
|
if (this.sessionOccupied(owner)) return;
|
|
2400
2523
|
const waiters = owner.availableWaiters;
|
|
2401
2524
|
delete owner.availableWaiters;
|
|
2402
|
-
for (const
|
|
2525
|
+
for (const resolve4 of waiters ?? []) resolve4();
|
|
2403
2526
|
}
|
|
2404
2527
|
async waitForSessionAvailable(owner, signal) {
|
|
2405
2528
|
while (this.sessionOccupied(owner)) {
|
|
2406
2529
|
if (signal?.aborted) throw new Error("Claude Code request was canceled.");
|
|
2407
|
-
await new Promise((
|
|
2530
|
+
await new Promise((resolve4, reject) => {
|
|
2408
2531
|
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
2409
2532
|
const ready = () => {
|
|
2410
2533
|
cleanup();
|
|
2411
|
-
|
|
2534
|
+
resolve4();
|
|
2412
2535
|
};
|
|
2413
2536
|
const abort = () => {
|
|
2414
2537
|
owner.availableWaiters?.delete(ready);
|
|
@@ -2422,26 +2545,28 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2422
2545
|
}
|
|
2423
2546
|
}
|
|
2424
2547
|
async statusSnapshot(running) {
|
|
2425
|
-
if (!this.desktop()) return { desktop: false, installed: false, rollbackAvailable: false, running: false };
|
|
2548
|
+
if (!this.desktop()) return { desktop: false, installed: false, readiness: "unsupported", rollbackAvailable: false, running: false };
|
|
2426
2549
|
try {
|
|
2427
|
-
const status = await this.runtime().
|
|
2550
|
+
const status = await this.runtime().inspect();
|
|
2428
2551
|
return {
|
|
2429
2552
|
desktop: true,
|
|
2430
2553
|
installed: status.installed,
|
|
2431
|
-
readiness: status.installed ? "
|
|
2554
|
+
readiness: this.preparation ? this.readiness : status.installed ? "ready" : this.readiness === "failed" ? "failed" : "missing",
|
|
2555
|
+
...this.runtimeDiagnostic ? { diagnostic: this.runtimeDiagnostic, errorCategory: "installation" } : {},
|
|
2432
2556
|
...status.version ? { version: status.version } : {},
|
|
2433
2557
|
...status.executablePath ? { executablePath: status.executablePath } : {},
|
|
2434
2558
|
rollbackAvailable: Boolean(status.previousVersion),
|
|
2435
2559
|
running
|
|
2436
2560
|
};
|
|
2437
|
-
} catch
|
|
2561
|
+
} catch {
|
|
2438
2562
|
return {
|
|
2439
2563
|
desktop: true,
|
|
2440
2564
|
installed: false,
|
|
2441
|
-
readiness: "
|
|
2565
|
+
readiness: "failed",
|
|
2566
|
+
errorCategory: "runtime",
|
|
2442
2567
|
rollbackAvailable: false,
|
|
2443
2568
|
running,
|
|
2444
|
-
diagnostic:
|
|
2569
|
+
diagnostic: "Claude Code \u8FD0\u884C\u6587\u4EF6\u7F3A\u5931\u6216\u7248\u672C\u68C0\u6D4B\u5931\u8D25\u3002\u8BF7\u4F7F\u7528\u63D2\u4EF6\u4E2D\u7684\u4FEE\u590D\u529F\u80FD\uFF1B\u82E5\u5185\u7F6E Node \u6216 pnpm \u7F3A\u5931\uFF0C\u8BF7\u4FEE\u590D\u5E94\u7528\u5B89\u88C5\u3002"
|
|
2445
2570
|
};
|
|
2446
2571
|
}
|
|
2447
2572
|
}
|
|
@@ -2457,8 +2582,8 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2457
2582
|
try {
|
|
2458
2583
|
const root = this.runtime().configDir;
|
|
2459
2584
|
const [native, plugin] = await Promise.all([
|
|
2460
|
-
this.readSettingsDocument(
|
|
2461
|
-
this.readSettingsDocument(
|
|
2585
|
+
this.readSettingsDocument(join5(root, "settings.json")),
|
|
2586
|
+
this.readSettingsDocument(join5(root, "plugin-settings.json"))
|
|
2462
2587
|
]);
|
|
2463
2588
|
return { ...CLAUDE_SETTINGS_DEFAULTS, ...knownNativeSettings({ ...plugin, ...native }) };
|
|
2464
2589
|
} catch {
|
|
@@ -2474,8 +2599,8 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2474
2599
|
const rootInfo = await lstat2(this.runtime().configDir);
|
|
2475
2600
|
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) throw new Error("Claude Code settings directory is not a regular directory.");
|
|
2476
2601
|
await chmod(this.runtime().configDir, 448);
|
|
2477
|
-
const nativePath =
|
|
2478
|
-
const pluginPath =
|
|
2602
|
+
const nativePath = join5(this.runtime().configDir, "settings.json");
|
|
2603
|
+
const pluginPath = join5(this.runtime().configDir, "plugin-settings.json");
|
|
2479
2604
|
const [native, plugin] = await Promise.all([this.readSettingsDocument(nativePath), this.readSettingsDocument(pluginPath)]);
|
|
2480
2605
|
if (next.outputStyle !== void 0) {
|
|
2481
2606
|
if (next.outputStyle === "Default") delete native.outputStyle;
|
|
@@ -2561,7 +2686,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2561
2686
|
async outputStyleOptions() {
|
|
2562
2687
|
const builtIns = ["Default", "Proactive", "Concise", "Explanatory", "Learning"].map((value) => ({ value, label: value, source: "built-in" }));
|
|
2563
2688
|
const names = new Set(builtIns.map((item) => item.value));
|
|
2564
|
-
const root = this.desktop() ?
|
|
2689
|
+
const root = this.desktop() ? join5(this.runtime().configDir, "output-styles") : "";
|
|
2565
2690
|
const user = [];
|
|
2566
2691
|
try {
|
|
2567
2692
|
for (const entry of root ? (await readdir2(root, { withFileTypes: true })).slice(0, 256) : []) {
|
|
@@ -2569,7 +2694,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2569
2694
|
const fallback = entry.name.slice(0, -3);
|
|
2570
2695
|
let value = fallback;
|
|
2571
2696
|
try {
|
|
2572
|
-
const path =
|
|
2697
|
+
const path = join5(root, entry.name);
|
|
2573
2698
|
const info = await lstat2(path);
|
|
2574
2699
|
if (info.isFile() && !info.isSymbolicLink() && info.size <= 64 * 1024) {
|
|
2575
2700
|
const text = await readFile2(path, "utf8");
|
|
@@ -2775,19 +2900,91 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2775
2900
|
async settingsUninstall() {
|
|
2776
2901
|
return this.changeRuntime("uninstall");
|
|
2777
2902
|
}
|
|
2903
|
+
async initializeRuntime() {
|
|
2904
|
+
if (!this.desktop()) {
|
|
2905
|
+
this.readiness = "unsupported";
|
|
2906
|
+
return;
|
|
2907
|
+
}
|
|
2908
|
+
try {
|
|
2909
|
+
this.autoSuppressed = JSON.parse(await readFile2(join5(this.runtimeRoot(), "auto-install.json"), "utf8")).disabled === true;
|
|
2910
|
+
} catch (error) {
|
|
2911
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
2912
|
+
}
|
|
2913
|
+
if (this.config.autoInstall !== false && !this.autoSuppressed) await this.ensurePrepared(false);
|
|
2914
|
+
else this.readiness = "missing";
|
|
2915
|
+
}
|
|
2916
|
+
ensurePrepared(force) {
|
|
2917
|
+
if (this.preparation) return this.preparation;
|
|
2918
|
+
const task = (async () => {
|
|
2919
|
+
if (this.disposed) throw new Error("Claude runtime is shutting down.");
|
|
2920
|
+
this.readiness = "checking";
|
|
2921
|
+
this.runtimeDiagnostic = void 0;
|
|
2922
|
+
const runtime = this.runtime();
|
|
2923
|
+
if (!force) {
|
|
2924
|
+
try {
|
|
2925
|
+
if ((await runtime.inspect()).installed) {
|
|
2926
|
+
this.readiness = "ready";
|
|
2927
|
+
return;
|
|
2928
|
+
}
|
|
2929
|
+
} catch (error) {
|
|
2930
|
+
if (this.installAbort.signal.aborted) throw error;
|
|
2931
|
+
}
|
|
2932
|
+
if (this.config.autoInstall === false || this.autoSuppressed) throw new Error("Claude Code is not ready. Install it from plugin settings.");
|
|
2933
|
+
}
|
|
2934
|
+
if ([...this.sessions.values()].some((state) => state.turn?.view.running)) throw new Error("Stop Claude Code before repairing the installation.");
|
|
2935
|
+
this.preparationRevision++;
|
|
2936
|
+
for (let attempt = 0; ; attempt++) {
|
|
2937
|
+
try {
|
|
2938
|
+
await runtime.installOrUpdate();
|
|
2939
|
+
break;
|
|
2940
|
+
} catch (error) {
|
|
2941
|
+
if (!(error instanceof ClaudeInstallError) || attempt >= 1 || this.installAbort.signal.aborted) throw error;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
this.readiness = "ready";
|
|
2945
|
+
})();
|
|
2946
|
+
this.preparation = task;
|
|
2947
|
+
void task.catch(() => {
|
|
2948
|
+
this.readiness = "failed";
|
|
2949
|
+
this.runtimeDiagnostic = "Claude Code \u5B89\u88C5\u6216\u7248\u672C\u6821\u9A8C\u5931\u8D25\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u53CA\u63D2\u4EF6\u955C\u50CF\u914D\u7F6E\u540E\u91CD\u8BD5\u3002";
|
|
2950
|
+
}).finally(() => {
|
|
2951
|
+
if (this.preparation === task) this.preparation = void 0;
|
|
2952
|
+
});
|
|
2953
|
+
return task;
|
|
2954
|
+
}
|
|
2778
2955
|
async changeRuntime(operation, agent) {
|
|
2779
|
-
|
|
2956
|
+
const revision = this.preparationRevision;
|
|
2957
|
+
const preparing = this.preparation;
|
|
2958
|
+
await this.runtimeInitialization;
|
|
2959
|
+
if (operation === "install" && (this.preparationRevision > revision || preparing) && this.readiness === "ready") return this.statusSnapshot(this.anyRunning());
|
|
2960
|
+
if (operation === "install" && this.preparation) {
|
|
2961
|
+
await this.preparation;
|
|
2962
|
+
return this.statusSnapshot(this.anyRunning());
|
|
2963
|
+
}
|
|
2964
|
+
if (this.mutation || this.preparation || this.anyRunning()) throw new Error("\u8BF7\u5148\u505C\u6B62 Claude Code\uFF0C\u518D\u7BA1\u7406\u5B89\u88C5\u3002");
|
|
2780
2965
|
this.mutation = true;
|
|
2781
2966
|
try {
|
|
2782
2967
|
const runtime = this.runtime();
|
|
2783
|
-
if (operation === "install")
|
|
2784
|
-
|
|
2785
|
-
|
|
2968
|
+
if (operation === "install") {
|
|
2969
|
+
await this.ensurePrepared(true);
|
|
2970
|
+
await mkdir3(this.runtimeRoot(), { recursive: true });
|
|
2971
|
+
await this.writeSettingsDocument(join5(this.runtimeRoot(), "auto-install.json"), { disabled: false });
|
|
2972
|
+
this.autoSuppressed = false;
|
|
2973
|
+
} else if (operation === "rollback") {
|
|
2974
|
+
await runtime.rollback();
|
|
2975
|
+
this.readiness = "ready";
|
|
2976
|
+
} else {
|
|
2977
|
+
await mkdir3(this.runtimeRoot(), { recursive: true });
|
|
2978
|
+
await this.writeSettingsDocument(join5(this.runtimeRoot(), "auto-install.json"), { disabled: true });
|
|
2979
|
+
this.autoSuppressed = true;
|
|
2786
2980
|
await runtime.uninstall();
|
|
2787
2981
|
this.sessions.clear();
|
|
2982
|
+
this.readiness = "missing";
|
|
2788
2983
|
}
|
|
2984
|
+
this.runtimeDiagnostic = void 0;
|
|
2789
2985
|
return await this.statusSnapshot(agent === void 0 ? this.anyRunning() : this.owner(agent).busy || Boolean(this.owner(agent).turn?.view.running));
|
|
2790
|
-
} catch {
|
|
2986
|
+
} catch (error) {
|
|
2987
|
+
if (!this.desktop()) throw error;
|
|
2791
2988
|
throw new Error("Claude Code \u5B89\u88C5\u7BA1\u7406\u672A\u5B8C\u6210\uFF1B\u73B0\u6709\u6709\u6548\u5B89\u88C5\u4F1A\u88AB\u4FDD\u7559\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
2792
2989
|
} finally {
|
|
2793
2990
|
this.mutation = false;
|
|
@@ -2878,6 +3075,8 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2878
3075
|
if (this.processReservations >= (nativeSettings.maxProcesses ?? 4)) throw new Error("Claude Code \u5DF2\u8FBE\u5230\u6700\u5927\u5E76\u53D1\u8FDB\u7A0B\u6570\uFF0C\u8BF7\u7B49\u5F85\u5176\u4ED6\u4EFB\u52A1\u5B8C\u6210\u3002");
|
|
2879
3076
|
this.processReservations += 1;
|
|
2880
3077
|
reserved = true;
|
|
3078
|
+
await this.runtimeInitialization;
|
|
3079
|
+
await this.ensurePrepared(false);
|
|
2881
3080
|
const runtime = this.runtime();
|
|
2882
3081
|
const executable = await runtime.getExecutablePath();
|
|
2883
3082
|
if (!executable) throw new Error("\u8BF7\u5148\u5B89\u88C5 Claude Code\u3002");
|
|
@@ -2901,16 +3100,16 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2901
3100
|
return stored ?? (await credentials.resolve(credentialRef(reference)))?.value;
|
|
2902
3101
|
});
|
|
2903
3102
|
cancel.signal.throwIfAborted();
|
|
2904
|
-
projectionRoot =
|
|
3103
|
+
projectionRoot = join5(runtime.configDir, "sessions", createHash4("sha256").update(agent.id).digest("hex"), "projection");
|
|
2905
3104
|
await rm2(projectionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
2906
3105
|
await mkdir3(projectionRoot, { recursive: true, mode: 448 });
|
|
2907
|
-
const skillRoot =
|
|
3106
|
+
const skillRoot = join5(projectionRoot, "skills");
|
|
2908
3107
|
for (const skill of skills.skills) {
|
|
2909
3108
|
const resource = skill.resourceBase;
|
|
2910
3109
|
const hint = resource?.kind === "directory" ? `Resolve every relative skill resource path against this original base directory: ${resource.path}.` : resource?.kind === "url" ? `Resolve every relative skill resource URL against this original base URL: ${resource.url}.` : resource?.kind === "opaque" ? `Original skill resources: ${resource.description}` : "";
|
|
2911
|
-
const dir =
|
|
3110
|
+
const dir = join5(skillRoot, skill.name);
|
|
2912
3111
|
await mkdir3(dir, { recursive: true, mode: 448 });
|
|
2913
|
-
await writeFile3(
|
|
3112
|
+
await writeFile3(join5(dir, "SKILL.md"), `---
|
|
2914
3113
|
name: ${skill.name}
|
|
2915
3114
|
description: ${JSON.stringify(skill.description)}
|
|
2916
3115
|
disable-model-invocation: ${!skill.invocation.modelInvocable}
|
|
@@ -2920,7 +3119,7 @@ ${hint}
|
|
|
2920
3119
|
|
|
2921
3120
|
${skill.content}`, { mode: 384 });
|
|
2922
3121
|
}
|
|
2923
|
-
const mcpPath =
|
|
3122
|
+
const mcpPath = join5(projectionRoot, "mcp.json");
|
|
2924
3123
|
const searchPath = Object.entries(process.env).find(([key]) => key.toUpperCase() === "PATH")?.[1];
|
|
2925
3124
|
const { servers: mcpServers, skipped: launchSkipped } = await writeClaudeMcpLaunchers(mcp, {
|
|
2926
3125
|
root: projectionRoot,
|
|
@@ -2929,9 +3128,9 @@ ${skill.content}`, { mode: 384 });
|
|
|
2929
3128
|
...searchPath ? { searchPath } : {}
|
|
2930
3129
|
});
|
|
2931
3130
|
await writeFile3(mcpPath, JSON.stringify({ mcpServers: Object.fromEntries(mcpServers.map(({ serverName, ...config }) => [serverName, config])) }), { mode: 384 });
|
|
2932
|
-
const pluginMeta =
|
|
3131
|
+
const pluginMeta = join5(projectionRoot, ".claude-plugin");
|
|
2933
3132
|
await mkdir3(pluginMeta, { mode: 448 });
|
|
2934
|
-
await writeFile3(
|
|
3133
|
+
await writeFile3(join5(pluginMeta, "plugin.json"), JSON.stringify({ name: "zerowall-session-skills", version: "0.1.0" }), { mode: 384 });
|
|
2935
3134
|
const environmentService = this.ctx.get("zerowallEnvironment");
|
|
2936
3135
|
const configuredEnvironment = {};
|
|
2937
3136
|
for (const { name: name2 } of await environmentService.listVariables()) {
|
|
@@ -3417,7 +3616,7 @@ ${skill.content}`, { mode: 384 });
|
|
|
3417
3616
|
turn.diagnostics.finish();
|
|
3418
3617
|
const detail = stripVTControlCharacters(turn.diagnostics.snapshot()).slice(-32e3);
|
|
3419
3618
|
const category = claudeFailureCategory(detail);
|
|
3420
|
-
const root =
|
|
3619
|
+
const root = join5(this.runtime().configDir, "diagnostics");
|
|
3421
3620
|
turn.view.diagnostic = { id: turn.view.id, category };
|
|
3422
3621
|
const diagnostic = {
|
|
3423
3622
|
id: turn.view.id,
|
|
@@ -3430,7 +3629,7 @@ ${skill.content}`, { mode: 384 });
|
|
|
3430
3629
|
permission: turn.view.permission,
|
|
3431
3630
|
detail
|
|
3432
3631
|
};
|
|
3433
|
-
await mkdir3(root, { recursive: true, mode: 448 }).then(() => this.writeSettingsDocument(
|
|
3632
|
+
await mkdir3(root, { recursive: true, mode: 448 }).then(() => this.writeSettingsDocument(join5(root, `${diagnostic.id}.json`), diagnostic)).catch(() => {
|
|
3434
3633
|
turn.view.message = `${turn.view.message ?? "Claude \u6267\u884C\u5931\u8D25\u3002"} \u8BCA\u65AD\u6587\u4EF6\u65E0\u6CD5\u5199\u5165\uFF0C\u8BF7\u68C0\u67E5\u6570\u636E\u76EE\u5F55\u6743\u9650\u3002`;
|
|
3435
3634
|
});
|
|
3436
3635
|
}
|
|
@@ -3741,12 +3940,14 @@ var ClaudeCodeSubagentProvider = class {
|
|
|
3741
3940
|
return this.startRun(request);
|
|
3742
3941
|
}
|
|
3743
3942
|
};
|
|
3744
|
-
|
|
3745
|
-
|
|
3943
|
+
var Config = schema.object({ runtimeRoot: schema.string(), version: schema.string().default("2.1.309"), registry: schema.string().default("https://registry.npmmirror.com"), autoInstall: schema.boolean().default(true) });
|
|
3944
|
+
function apply(ctx, config = {}) {
|
|
3945
|
+
ctx.plugin(ClaudeCodeService, config);
|
|
3746
3946
|
}
|
|
3747
|
-
var index_default = { name, inject, apply };
|
|
3947
|
+
var index_default = { name, inject, Config, apply };
|
|
3748
3948
|
export {
|
|
3749
3949
|
ClaudeCodeService,
|
|
3950
|
+
Config,
|
|
3750
3951
|
apply,
|
|
3751
3952
|
index_default as default,
|
|
3752
3953
|
inject,
|