@zerowall/dsh-claude-coderun 0.1.0-preview.1 → 0.1.0-preview.3
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 -113
- 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/projection.d.ts +2 -3
- 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 +5 -5
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
|
|
|
@@ -100,23 +101,21 @@ import { 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,35 @@ 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
|
-
`--registry=${
|
|
312
|
+
`--registry=${this.#registry}`,
|
|
280
313
|
`--store-dir=${this.storeDir}`
|
|
281
314
|
], {
|
|
282
315
|
cwd: candidate,
|
|
283
316
|
env: this.#buildInstallEnvironment(join(candidate, ".npmrc")),
|
|
284
|
-
windowsHide: true
|
|
317
|
+
windowsHide: true,
|
|
318
|
+
signal: this.#signal,
|
|
319
|
+
timeoutMs: 3e5
|
|
285
320
|
});
|
|
286
|
-
if (result.code !== 0) throw new
|
|
321
|
+
if (result.code !== 0) throw new ClaudeInstallError(`Claude Code installation failed (pnpm exited ${result.code}).`);
|
|
287
322
|
const packageRoot = join(candidate, "node_modules", "@anthropic-ai", "claude-code");
|
|
288
323
|
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 ${
|
|
324
|
+
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !== this.#version) {
|
|
325
|
+
throw new Error(`Installed Claude Code package did not match the pinned ${this.#version} release.`);
|
|
291
326
|
}
|
|
292
327
|
const relativeCli = this.#resolveCliRelative(packageJson);
|
|
293
328
|
const executablePath = resolve(packageRoot, relativeCli);
|
|
@@ -300,6 +335,7 @@ var ClaudeRuntimeManager = class {
|
|
|
300
335
|
const generationReal = await this.#fs.realpath(candidate);
|
|
301
336
|
const packageReal = await this.#verifyRealPathInside(generationReal, packageRoot, "Installed Claude Code package", "directory");
|
|
302
337
|
await this.#verifyRealPathInside(packageReal, executablePath, "Installed Claude Code executable", "file", true);
|
|
338
|
+
this.#onPhase?.("verifying");
|
|
303
339
|
const javascriptCli = /\.[cm]?js$/iu.test(executablePath);
|
|
304
340
|
const probe = await this.#run(
|
|
305
341
|
javascriptCli ? this.#pnpm.executable : executablePath,
|
|
@@ -307,18 +343,21 @@ var ClaudeRuntimeManager = class {
|
|
|
307
343
|
{
|
|
308
344
|
cwd: candidate,
|
|
309
345
|
env: this.getCliEnvironment(),
|
|
310
|
-
windowsHide: true
|
|
346
|
+
windowsHide: true,
|
|
347
|
+
signal: this.#signal,
|
|
348
|
+
timeoutMs: 15e3
|
|
311
349
|
}
|
|
312
350
|
);
|
|
313
|
-
if (probe.code !== 0 || probe.stdout?.trim() !== `${
|
|
351
|
+
if (probe.code !== 0 || probe.stdout?.trim() !== `${this.#version} (Claude Code)`) {
|
|
314
352
|
throw new Error("Installed Claude Code CLI failed its pinned version health check.");
|
|
315
353
|
}
|
|
316
354
|
const previous = prior?.current ?? prior?.previous ?? null;
|
|
317
355
|
const next = {
|
|
318
356
|
schema: 1,
|
|
319
|
-
current: { id, version:
|
|
357
|
+
current: { id, version: this.#version, executable: relative(active, executablePath) },
|
|
320
358
|
previous
|
|
321
359
|
};
|
|
360
|
+
this.#signal?.throwIfAborted();
|
|
322
361
|
await this.#writeState(next);
|
|
323
362
|
promoted = true;
|
|
324
363
|
return this.status();
|
|
@@ -374,7 +413,7 @@ var ClaudeRuntimeManager = class {
|
|
|
374
413
|
const packageRoot = join(generationRoot, "node_modules", "@anthropic-ai", "claude-code");
|
|
375
414
|
await this.#verifyRealPathInside(generationRoot, packageRoot, "Retained Claude Code package", "directory");
|
|
376
415
|
const packageJson = JSON.parse(String(await this.#fs.readFile(join(packageRoot, "package.json"), "utf8")));
|
|
377
|
-
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !==
|
|
416
|
+
if (packageJson.name !== CLAUDE_CODE_PACKAGE || packageJson.version !== this.#version) continue;
|
|
378
417
|
const executablePath = resolve(packageRoot, this.#resolveCliRelative(packageJson));
|
|
379
418
|
if (!isInside(packageRoot, executablePath) || !await this.#exists(executablePath)) continue;
|
|
380
419
|
const packageReal = await this.#fs.realpath(packageRoot);
|
|
@@ -389,14 +428,14 @@ var ClaudeRuntimeManager = class {
|
|
|
389
428
|
windowsHide: true
|
|
390
429
|
}
|
|
391
430
|
);
|
|
392
|
-
if (probe.code !== 0 || probe.stdout?.trim() !== `${
|
|
393
|
-
healthy.push({ id, version:
|
|
431
|
+
if (probe.code !== 0 || probe.stdout?.trim() !== `${this.#version} (Claude Code)`) continue;
|
|
432
|
+
healthy.push({ id, version: this.#version, executable: relative(generationRoot, executablePath) });
|
|
394
433
|
if (healthy.length === 2) break;
|
|
395
434
|
} catch {
|
|
396
435
|
}
|
|
397
436
|
}
|
|
398
437
|
if (!healthy.length) {
|
|
399
|
-
throw new Error(`Claude Code's active executable is missing, and no retained managed generation passed the ${
|
|
438
|
+
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
439
|
}
|
|
401
440
|
await this.#writeState({ schema: 1, current: healthy[0], previous: healthy[1] ?? null });
|
|
402
441
|
return this.status();
|
|
@@ -476,7 +515,7 @@ var ClaudeRuntimeManager = class {
|
|
|
476
515
|
}
|
|
477
516
|
env[key] = value;
|
|
478
517
|
}
|
|
479
|
-
env.npm_config_registry =
|
|
518
|
+
env.npm_config_registry = this.#registry;
|
|
480
519
|
env.PNPM_HOME = join(this.dataDir, "pnpm-home");
|
|
481
520
|
return env;
|
|
482
521
|
}
|
|
@@ -566,7 +605,7 @@ var ClaudeRuntimeManager = class {
|
|
|
566
605
|
throw error;
|
|
567
606
|
}
|
|
568
607
|
const state = JSON.parse(text);
|
|
569
|
-
const validGeneration = (entry) => Boolean(entry && safeId.test(entry.id) && entry.version ===
|
|
608
|
+
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
609
|
if (state.schema !== 1 || !validGeneration(state.current) || state.previous !== null && !validGeneration(state.previous)) {
|
|
571
610
|
throw new Error("Claude Code runtime state is invalid.");
|
|
572
611
|
}
|
|
@@ -687,11 +726,82 @@ var ClaudeRuntimeManager = class {
|
|
|
687
726
|
}
|
|
688
727
|
};
|
|
689
728
|
|
|
729
|
+
// src/host/installer.ts
|
|
730
|
+
import { spawn } from "node:child_process";
|
|
731
|
+
import { join as join2 } from "node:path";
|
|
732
|
+
var runInstaller = (command, args, options) => new Promise((resolve4, reject) => {
|
|
733
|
+
const { timeoutMs = 3e5, signal, ...spawnOptions } = options;
|
|
734
|
+
if (signal?.aborted) {
|
|
735
|
+
reject(new Error("Claude Code preparation was canceled."));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
const versionProbe = args.at(-1) === "--version";
|
|
739
|
+
let stdout = "";
|
|
740
|
+
let failure;
|
|
741
|
+
let stopping;
|
|
742
|
+
let closed = false;
|
|
743
|
+
const child = spawn(command, args, { ...spawnOptions, detached: process.platform !== "win32", env: {
|
|
744
|
+
...options.env,
|
|
745
|
+
...process.versions.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {}
|
|
746
|
+
}, stdio: ["ignore", "pipe", "pipe"] });
|
|
747
|
+
const stop = (message) => {
|
|
748
|
+
if (closed || stopping) return;
|
|
749
|
+
failure = new Error(message);
|
|
750
|
+
stopping = new Promise((done) => {
|
|
751
|
+
if (!child.pid) {
|
|
752
|
+
done();
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (process.platform === "win32") {
|
|
756
|
+
const killer = spawn(join2(process.env.SystemRoot ?? process.env.WINDIR ?? "", "System32", "taskkill.exe"), ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
757
|
+
killer.once("error", () => {
|
|
758
|
+
child.kill();
|
|
759
|
+
done();
|
|
760
|
+
});
|
|
761
|
+
killer.once("close", (code) => {
|
|
762
|
+
if (code !== 0) child.kill();
|
|
763
|
+
done();
|
|
764
|
+
});
|
|
765
|
+
} else {
|
|
766
|
+
try {
|
|
767
|
+
process.kill(-child.pid, "SIGKILL");
|
|
768
|
+
} catch (error) {
|
|
769
|
+
if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) failure = new Error("Claude Code process cleanup failed.");
|
|
770
|
+
}
|
|
771
|
+
done();
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
const abort = () => stop("Claude Code preparation was canceled.");
|
|
776
|
+
const deadline = setTimeout(() => stop("Claude Code preparation timed out. Check the network and retry."), timeoutMs);
|
|
777
|
+
deadline.unref();
|
|
778
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
779
|
+
if (signal?.aborted) abort();
|
|
780
|
+
child.stdout?.setEncoding("utf8");
|
|
781
|
+
child.stdout?.on("data", (data) => {
|
|
782
|
+
if (versionProbe) stdout = (stdout + data).slice(0, 4096);
|
|
783
|
+
});
|
|
784
|
+
child.stderr?.resume();
|
|
785
|
+
child.once("error", () => {
|
|
786
|
+
failure ??= new Error("Claude Code process could not start. Repair the application installation.");
|
|
787
|
+
});
|
|
788
|
+
child.once("close", () => {
|
|
789
|
+
closed = true;
|
|
790
|
+
clearTimeout(deadline);
|
|
791
|
+
signal?.removeEventListener("abort", abort);
|
|
792
|
+
});
|
|
793
|
+
child.once("close", async (code) => {
|
|
794
|
+
await stopping;
|
|
795
|
+
if (failure) reject(failure);
|
|
796
|
+
else resolve4({ code: code ?? -1, ...versionProbe ? { stdout } : {} });
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
|
|
690
800
|
// src/host/mcp-launcher.ts
|
|
691
801
|
import { createHash } from "node:crypto";
|
|
692
802
|
import { constants } from "node:fs";
|
|
693
803
|
import { access, mkdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
694
|
-
import { delimiter, extname, isAbsolute as isAbsolute2, join as
|
|
804
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
695
805
|
var launcherSource = `'use strict';
|
|
696
806
|
const { spawn } = require('node:child_process');
|
|
697
807
|
const { readFileSync } = require('node:fs');
|
|
@@ -768,7 +878,7 @@ async function resolveNativeFromPath(command, searchPath) {
|
|
|
768
878
|
if (!isAbsolute2(directory)) continue;
|
|
769
879
|
for (const suffix of extensions) {
|
|
770
880
|
try {
|
|
771
|
-
const candidate = await realpath(
|
|
881
|
+
const candidate = await realpath(join3(directory, `${command}${suffix}`));
|
|
772
882
|
if (!(await stat(candidate)).isFile()) continue;
|
|
773
883
|
if (process.platform !== "win32") await access(candidate, constants.X_OK);
|
|
774
884
|
return candidate;
|
|
@@ -780,11 +890,11 @@ async function resolveNativeFromPath(command, searchPath) {
|
|
|
780
890
|
}
|
|
781
891
|
async function writeClaudeMcpLaunchers(projection, options) {
|
|
782
892
|
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 =
|
|
893
|
+
const root = join3(options.root, "mcp-launchers");
|
|
784
894
|
const wrapped = projection.servers.some((server) => server.type === "stdio" && server.launcher);
|
|
785
895
|
if (wrapped) {
|
|
786
896
|
await mkdir(root, { recursive: true, mode: 448 });
|
|
787
|
-
await writeFile(
|
|
897
|
+
await writeFile(join3(root, "launch.cjs"), launcherSource, { mode: 384 });
|
|
788
898
|
}
|
|
789
899
|
const servers = [];
|
|
790
900
|
const skipped = [];
|
|
@@ -803,7 +913,7 @@ async function writeClaudeMcpLaunchers(projection, options) {
|
|
|
803
913
|
skipped.push({ serverName: server.serverName, reason: "unsupported-launch" });
|
|
804
914
|
continue;
|
|
805
915
|
}
|
|
806
|
-
const specPath =
|
|
916
|
+
const specPath = join3(root, `${createHash("sha256").update(server.serverName).digest("hex")}.json`);
|
|
807
917
|
const env = Object.fromEntries(Object.entries(server.env ?? {}).map(([target, placeholder]) => {
|
|
808
918
|
const match = /^\$\{(ZW_CLAUDE_MCP_[A-F0-9]{20})\}$/u.exec(placeholder);
|
|
809
919
|
if (!match) throw new Error("Claude MCP launcher credential placeholder is invalid.");
|
|
@@ -820,7 +930,7 @@ async function writeClaudeMcpLaunchers(projection, options) {
|
|
|
820
930
|
serverName: server.serverName,
|
|
821
931
|
type: "stdio",
|
|
822
932
|
command: options.executable,
|
|
823
|
-
args: [
|
|
933
|
+
args: [join3(root, "launch.cjs"), specPath],
|
|
824
934
|
...server.env || options.electron ? { env: { ...server.env, ...options.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {} } } : {}
|
|
825
935
|
});
|
|
826
936
|
}
|
|
@@ -1304,7 +1414,7 @@ var CLAUDE_MODE_BY_SANDBOX = {
|
|
|
1304
1414
|
// src/host/session-binding.ts
|
|
1305
1415
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
1306
1416
|
import { lstat, mkdir as mkdir2, readFile, readdir, rename, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
1307
|
-
import { join as
|
|
1417
|
+
import { join as join4 } from "node:path";
|
|
1308
1418
|
import { createReadStream } from "node:fs";
|
|
1309
1419
|
import { createInterface } from "node:readline";
|
|
1310
1420
|
var ClaudeSessionBindings = class {
|
|
@@ -1313,7 +1423,7 @@ var ClaudeSessionBindings = class {
|
|
|
1313
1423
|
}
|
|
1314
1424
|
configDir;
|
|
1315
1425
|
file(id) {
|
|
1316
|
-
return
|
|
1426
|
+
return join4(this.configDir, "bindings", `${createHash3("sha256").update(id).digest("hex")}.json`);
|
|
1317
1427
|
}
|
|
1318
1428
|
async load(id, cwd) {
|
|
1319
1429
|
let previous;
|
|
@@ -1361,7 +1471,7 @@ var ClaudeSessionBindings = class {
|
|
|
1361
1471
|
}
|
|
1362
1472
|
async save(id, binding) {
|
|
1363
1473
|
const file = this.file(id), temporary = `${file}.${randomUUID2()}.tmp`;
|
|
1364
|
-
await mkdir2(
|
|
1474
|
+
await mkdir2(join4(this.configDir, "bindings"), { recursive: true, mode: 448 });
|
|
1365
1475
|
await writeFile2(temporary, JSON.stringify(binding), { mode: 384, flag: "wx" });
|
|
1366
1476
|
try {
|
|
1367
1477
|
await rename(temporary, file);
|
|
@@ -1370,18 +1480,18 @@ var ClaudeSessionBindings = class {
|
|
|
1370
1480
|
}
|
|
1371
1481
|
}
|
|
1372
1482
|
async transcript(nativeId) {
|
|
1373
|
-
const root =
|
|
1483
|
+
const root = join4(this.configDir, "projects");
|
|
1374
1484
|
const directories = await readdir(root, { withFileTypes: true }).catch((error) => {
|
|
1375
1485
|
if (error.code === "ENOENT") return [];
|
|
1376
1486
|
throw error;
|
|
1377
1487
|
});
|
|
1378
1488
|
for (const directory of directories) {
|
|
1379
1489
|
if (!directory.isDirectory() || directory.isSymbolicLink()) continue;
|
|
1380
|
-
const info = await lstat(
|
|
1490
|
+
const info = await lstat(join4(root, directory.name, `${nativeId}.jsonl`)).catch((error) => {
|
|
1381
1491
|
if (error.code === "ENOENT") return void 0;
|
|
1382
1492
|
throw error;
|
|
1383
1493
|
});
|
|
1384
|
-
if (info?.isFile() && !info.isSymbolicLink() && info.size > 0) return
|
|
1494
|
+
if (info?.isFile() && !info.isSymbolicLink() && info.size > 0) return join4(root, directory.name, `${nativeId}.jsonl`);
|
|
1385
1495
|
}
|
|
1386
1496
|
return void 0;
|
|
1387
1497
|
}
|
|
@@ -1480,25 +1590,25 @@ function createHostToolBridge(agent, schemas, signal, source, state = { conclude
|
|
|
1480
1590
|
previousClose?.();
|
|
1481
1591
|
};
|
|
1482
1592
|
signal.addEventListener("abort", dispose, { once: true });
|
|
1483
|
-
server.instance.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: currentSchemas().map((
|
|
1484
|
-
name:
|
|
1485
|
-
description:
|
|
1486
|
-
inputSchema:
|
|
1593
|
+
server.instance.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: currentSchemas().map((schema2) => ({
|
|
1594
|
+
name: schema2.name,
|
|
1595
|
+
description: schema2.description,
|
|
1596
|
+
inputSchema: schema2.parameters
|
|
1487
1597
|
})) }));
|
|
1488
1598
|
let queue = Promise.resolve();
|
|
1489
1599
|
state.drain = () => queue;
|
|
1490
1600
|
server.instance.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
1491
1601
|
const previous = queue;
|
|
1492
1602
|
let release;
|
|
1493
|
-
queue = new Promise((
|
|
1494
|
-
release =
|
|
1603
|
+
queue = new Promise((resolve4) => {
|
|
1604
|
+
release = resolve4;
|
|
1495
1605
|
});
|
|
1496
1606
|
await previous;
|
|
1497
1607
|
try {
|
|
1498
1608
|
signal.throwIfAborted();
|
|
1499
1609
|
extra.signal.throwIfAborted();
|
|
1500
1610
|
if (state.concluded) return { content: [{ type: "text", text: "The Host concluded this turn; no further operation was executed." }], isError: true };
|
|
1501
|
-
if (!currentSchemas().some((
|
|
1611
|
+
if (!currentSchemas().some((schema2) => schema2.name === request.params.name)) throw new Error("Tool is not visible in this conversation.");
|
|
1502
1612
|
const callId = ToolCallId2(`claude-host-${randomUUID3()}`);
|
|
1503
1613
|
const lifetime = AbortSignal.any([signal, extra.signal]);
|
|
1504
1614
|
const tools = agent.ctx.get("tools");
|
|
@@ -2215,22 +2325,6 @@ function contextUsageView(value, detail) {
|
|
|
2215
2325
|
...safeApiUsage ? { apiUsage: safeApiUsage } : {}
|
|
2216
2326
|
};
|
|
2217
2327
|
}
|
|
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
2328
|
var CLAUDE_SETTINGS_DEFAULTS = {
|
|
2235
2329
|
outputStyle: "Default",
|
|
2236
2330
|
permissionSelector: "plugin",
|
|
@@ -2284,8 +2378,9 @@ function validateNativeSettings(value) {
|
|
|
2284
2378
|
}
|
|
2285
2379
|
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
2380
|
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) {
|
|
2381
|
+
constructor(ctx, config = {}) {
|
|
2288
2382
|
super(ctx, "zerowallClaudeCode");
|
|
2383
|
+
this.config = config;
|
|
2289
2384
|
__runInitializers(_init, 5, this);
|
|
2290
2385
|
__publicField(this, "manager");
|
|
2291
2386
|
__publicField(this, "secrets");
|
|
@@ -2295,7 +2390,19 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2295
2390
|
__publicField(this, "mutation", false);
|
|
2296
2391
|
__publicField(this, "chatAgents", /* @__PURE__ */ new Map());
|
|
2297
2392
|
__publicField(this, "processReservations", 0);
|
|
2393
|
+
__publicField(this, "runtimeInitialization");
|
|
2394
|
+
__publicField(this, "preparation");
|
|
2395
|
+
__publicField(this, "installAbort", new AbortController());
|
|
2396
|
+
__publicField(this, "readiness", "checking");
|
|
2397
|
+
__publicField(this, "runtimeDiagnostic");
|
|
2398
|
+
__publicField(this, "autoSuppressed", false);
|
|
2399
|
+
__publicField(this, "disposed", false);
|
|
2400
|
+
__publicField(this, "preparationRevision", 0);
|
|
2298
2401
|
this.secrets = new SecretBrokerClient(ctx.credentials);
|
|
2402
|
+
this.runtimeInitialization = this.initializeRuntime().catch(() => {
|
|
2403
|
+
this.readiness = "failed";
|
|
2404
|
+
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";
|
|
2405
|
+
});
|
|
2299
2406
|
ctx.sessionProjections.register(claudeMetricsProjection);
|
|
2300
2407
|
ctx.inject(["subagents"], (scope) => {
|
|
2301
2408
|
const subagents = scope.get("subagents");
|
|
@@ -2318,7 +2425,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2318
2425
|
});
|
|
2319
2426
|
});
|
|
2320
2427
|
ctx.on("agent/request", async ({ agent }, next) => {
|
|
2321
|
-
const
|
|
2428
|
+
const config2 = await next();
|
|
2322
2429
|
const projections = ctx.get("sessionProjections");
|
|
2323
2430
|
if (projections.stateOf(agent.session, "agentPreset") === "claude") {
|
|
2324
2431
|
const permission2 = await this.permissionView(agent);
|
|
@@ -2330,7 +2437,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2330
2437
|
}
|
|
2331
2438
|
this.chatAgents.set(agent.id, agent);
|
|
2332
2439
|
} else this.chatAgents.delete(agent.id);
|
|
2333
|
-
return
|
|
2440
|
+
return config2;
|
|
2334
2441
|
});
|
|
2335
2442
|
ctx.on("agent/status", ({ agent, status }) => {
|
|
2336
2443
|
if (status === "idle") this.chatAgents.delete(agent.id);
|
|
@@ -2356,6 +2463,10 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2356
2463
|
}, options);
|
|
2357
2464
|
});
|
|
2358
2465
|
ctx.effect(() => async () => {
|
|
2466
|
+
this.disposed = true;
|
|
2467
|
+
this.installAbort.abort();
|
|
2468
|
+
await this.runtimeInitialization;
|
|
2469
|
+
await this.preparation?.catch(() => void 0);
|
|
2359
2470
|
await Promise.allSettled([...this.sessions.values()].map(async (state) => {
|
|
2360
2471
|
state.preparing?.abort();
|
|
2361
2472
|
state.turn?.cancel.abort();
|
|
@@ -2366,8 +2477,12 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2366
2477
|
this.chatAgents.clear();
|
|
2367
2478
|
}, "claude-code: terminate plugin-owned processes");
|
|
2368
2479
|
}
|
|
2480
|
+
config;
|
|
2369
2481
|
desktop() {
|
|
2370
|
-
return Boolean(process.env.
|
|
2482
|
+
return Boolean(process.env.ZEROWALL_DESKTOP_RUNTIME_ROOT && isAbsolute4(process.env.ZEROWALL_DESKTOP_RUNTIME_ROOT));
|
|
2483
|
+
}
|
|
2484
|
+
runtimeRoot() {
|
|
2485
|
+
return resolve3(this.config.runtimeRoot ?? process.env.ZEROWALL_CLAUDE_RUNTIME_ROOT ?? join5(resolveDshHome(), "zerowall", "claude-code", "runtime"));
|
|
2371
2486
|
}
|
|
2372
2487
|
anyRunning() {
|
|
2373
2488
|
return [...this.sessions.values()].some((state) => state.busy || state.turn?.view.running === true);
|
|
@@ -2378,10 +2493,15 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2378
2493
|
runtime() {
|
|
2379
2494
|
if (!this.desktop()) throw new Error("Claude Code \u5B89\u88C5\u4E0E\u8FD0\u884C\u4EC5\u9002\u7528\u4E8E ZeroWall Desktop\u3002");
|
|
2380
2495
|
if (!this.manager) {
|
|
2381
|
-
const resourcesPath = process.resourcesPath ?? join4(dirname(process.execPath), "resources");
|
|
2382
2496
|
this.manager = new ClaudeRuntimeManager({
|
|
2383
|
-
dataDir:
|
|
2384
|
-
pnpm: resolveBundledPnpmRuntime(
|
|
2497
|
+
dataDir: this.runtimeRoot(),
|
|
2498
|
+
pnpm: resolveBundledPnpmRuntime(),
|
|
2499
|
+
version: this.config.version,
|
|
2500
|
+
registry: this.config.registry,
|
|
2501
|
+
signal: this.installAbort.signal,
|
|
2502
|
+
onPhase: (phase) => {
|
|
2503
|
+
this.readiness = phase;
|
|
2504
|
+
},
|
|
2385
2505
|
run: runInstaller
|
|
2386
2506
|
});
|
|
2387
2507
|
}
|
|
@@ -2399,16 +2519,16 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2399
2519
|
if (this.sessionOccupied(owner)) return;
|
|
2400
2520
|
const waiters = owner.availableWaiters;
|
|
2401
2521
|
delete owner.availableWaiters;
|
|
2402
|
-
for (const
|
|
2522
|
+
for (const resolve4 of waiters ?? []) resolve4();
|
|
2403
2523
|
}
|
|
2404
2524
|
async waitForSessionAvailable(owner, signal) {
|
|
2405
2525
|
while (this.sessionOccupied(owner)) {
|
|
2406
2526
|
if (signal?.aborted) throw new Error("Claude Code request was canceled.");
|
|
2407
|
-
await new Promise((
|
|
2527
|
+
await new Promise((resolve4, reject) => {
|
|
2408
2528
|
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
2409
2529
|
const ready = () => {
|
|
2410
2530
|
cleanup();
|
|
2411
|
-
|
|
2531
|
+
resolve4();
|
|
2412
2532
|
};
|
|
2413
2533
|
const abort = () => {
|
|
2414
2534
|
owner.availableWaiters?.delete(ready);
|
|
@@ -2422,26 +2542,28 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2422
2542
|
}
|
|
2423
2543
|
}
|
|
2424
2544
|
async statusSnapshot(running) {
|
|
2425
|
-
if (!this.desktop()) return { desktop: false, installed: false, rollbackAvailable: false, running: false };
|
|
2545
|
+
if (!this.desktop()) return { desktop: false, installed: false, readiness: "unsupported", rollbackAvailable: false, running: false };
|
|
2426
2546
|
try {
|
|
2427
|
-
const status = await this.runtime().
|
|
2547
|
+
const status = await this.runtime().inspect();
|
|
2428
2548
|
return {
|
|
2429
2549
|
desktop: true,
|
|
2430
2550
|
installed: status.installed,
|
|
2431
|
-
readiness: status.installed ? "
|
|
2551
|
+
readiness: this.preparation ? this.readiness : status.installed ? "ready" : this.readiness === "failed" ? "failed" : "missing",
|
|
2552
|
+
...this.runtimeDiagnostic ? { diagnostic: this.runtimeDiagnostic, errorCategory: "installation" } : {},
|
|
2432
2553
|
...status.version ? { version: status.version } : {},
|
|
2433
2554
|
...status.executablePath ? { executablePath: status.executablePath } : {},
|
|
2434
2555
|
rollbackAvailable: Boolean(status.previousVersion),
|
|
2435
2556
|
running
|
|
2436
2557
|
};
|
|
2437
|
-
} catch
|
|
2558
|
+
} catch {
|
|
2438
2559
|
return {
|
|
2439
2560
|
desktop: true,
|
|
2440
2561
|
installed: false,
|
|
2441
|
-
readiness: "
|
|
2562
|
+
readiness: "failed",
|
|
2563
|
+
errorCategory: "runtime",
|
|
2442
2564
|
rollbackAvailable: false,
|
|
2443
2565
|
running,
|
|
2444
|
-
diagnostic:
|
|
2566
|
+
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
2567
|
};
|
|
2446
2568
|
}
|
|
2447
2569
|
}
|
|
@@ -2457,8 +2579,8 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2457
2579
|
try {
|
|
2458
2580
|
const root = this.runtime().configDir;
|
|
2459
2581
|
const [native, plugin] = await Promise.all([
|
|
2460
|
-
this.readSettingsDocument(
|
|
2461
|
-
this.readSettingsDocument(
|
|
2582
|
+
this.readSettingsDocument(join5(root, "settings.json")),
|
|
2583
|
+
this.readSettingsDocument(join5(root, "plugin-settings.json"))
|
|
2462
2584
|
]);
|
|
2463
2585
|
return { ...CLAUDE_SETTINGS_DEFAULTS, ...knownNativeSettings({ ...plugin, ...native }) };
|
|
2464
2586
|
} catch {
|
|
@@ -2474,8 +2596,8 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2474
2596
|
const rootInfo = await lstat2(this.runtime().configDir);
|
|
2475
2597
|
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) throw new Error("Claude Code settings directory is not a regular directory.");
|
|
2476
2598
|
await chmod(this.runtime().configDir, 448);
|
|
2477
|
-
const nativePath =
|
|
2478
|
-
const pluginPath =
|
|
2599
|
+
const nativePath = join5(this.runtime().configDir, "settings.json");
|
|
2600
|
+
const pluginPath = join5(this.runtime().configDir, "plugin-settings.json");
|
|
2479
2601
|
const [native, plugin] = await Promise.all([this.readSettingsDocument(nativePath), this.readSettingsDocument(pluginPath)]);
|
|
2480
2602
|
if (next.outputStyle !== void 0) {
|
|
2481
2603
|
if (next.outputStyle === "Default") delete native.outputStyle;
|
|
@@ -2561,7 +2683,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2561
2683
|
async outputStyleOptions() {
|
|
2562
2684
|
const builtIns = ["Default", "Proactive", "Concise", "Explanatory", "Learning"].map((value) => ({ value, label: value, source: "built-in" }));
|
|
2563
2685
|
const names = new Set(builtIns.map((item) => item.value));
|
|
2564
|
-
const root = this.desktop() ?
|
|
2686
|
+
const root = this.desktop() ? join5(this.runtime().configDir, "output-styles") : "";
|
|
2565
2687
|
const user = [];
|
|
2566
2688
|
try {
|
|
2567
2689
|
for (const entry of root ? (await readdir2(root, { withFileTypes: true })).slice(0, 256) : []) {
|
|
@@ -2569,7 +2691,7 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2569
2691
|
const fallback = entry.name.slice(0, -3);
|
|
2570
2692
|
let value = fallback;
|
|
2571
2693
|
try {
|
|
2572
|
-
const path =
|
|
2694
|
+
const path = join5(root, entry.name);
|
|
2573
2695
|
const info = await lstat2(path);
|
|
2574
2696
|
if (info.isFile() && !info.isSymbolicLink() && info.size <= 64 * 1024) {
|
|
2575
2697
|
const text = await readFile2(path, "utf8");
|
|
@@ -2775,19 +2897,91 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2775
2897
|
async settingsUninstall() {
|
|
2776
2898
|
return this.changeRuntime("uninstall");
|
|
2777
2899
|
}
|
|
2900
|
+
async initializeRuntime() {
|
|
2901
|
+
if (!this.desktop()) {
|
|
2902
|
+
this.readiness = "unsupported";
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
try {
|
|
2906
|
+
this.autoSuppressed = JSON.parse(await readFile2(join5(this.runtimeRoot(), "auto-install.json"), "utf8")).disabled === true;
|
|
2907
|
+
} catch (error) {
|
|
2908
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
2909
|
+
}
|
|
2910
|
+
if (this.config.autoInstall !== false && !this.autoSuppressed) await this.ensurePrepared(false);
|
|
2911
|
+
else this.readiness = "missing";
|
|
2912
|
+
}
|
|
2913
|
+
ensurePrepared(force) {
|
|
2914
|
+
if (this.preparation) return this.preparation;
|
|
2915
|
+
const task = (async () => {
|
|
2916
|
+
if (this.disposed) throw new Error("Claude runtime is shutting down.");
|
|
2917
|
+
this.readiness = "checking";
|
|
2918
|
+
this.runtimeDiagnostic = void 0;
|
|
2919
|
+
const runtime = this.runtime();
|
|
2920
|
+
if (!force) {
|
|
2921
|
+
try {
|
|
2922
|
+
if ((await runtime.inspect()).installed) {
|
|
2923
|
+
this.readiness = "ready";
|
|
2924
|
+
return;
|
|
2925
|
+
}
|
|
2926
|
+
} catch (error) {
|
|
2927
|
+
if (this.installAbort.signal.aborted) throw error;
|
|
2928
|
+
}
|
|
2929
|
+
if (this.config.autoInstall === false || this.autoSuppressed) throw new Error("Claude Code is not ready. Install it from plugin settings.");
|
|
2930
|
+
}
|
|
2931
|
+
if ([...this.sessions.values()].some((state) => state.turn?.view.running)) throw new Error("Stop Claude Code before repairing the installation.");
|
|
2932
|
+
this.preparationRevision++;
|
|
2933
|
+
for (let attempt = 0; ; attempt++) {
|
|
2934
|
+
try {
|
|
2935
|
+
await runtime.installOrUpdate();
|
|
2936
|
+
break;
|
|
2937
|
+
} catch (error) {
|
|
2938
|
+
if (!(error instanceof ClaudeInstallError) || attempt >= 1 || this.installAbort.signal.aborted) throw error;
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
this.readiness = "ready";
|
|
2942
|
+
})();
|
|
2943
|
+
this.preparation = task;
|
|
2944
|
+
void task.catch(() => {
|
|
2945
|
+
this.readiness = "failed";
|
|
2946
|
+
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";
|
|
2947
|
+
}).finally(() => {
|
|
2948
|
+
if (this.preparation === task) this.preparation = void 0;
|
|
2949
|
+
});
|
|
2950
|
+
return task;
|
|
2951
|
+
}
|
|
2778
2952
|
async changeRuntime(operation, agent) {
|
|
2779
|
-
|
|
2953
|
+
const revision = this.preparationRevision;
|
|
2954
|
+
const preparing = this.preparation;
|
|
2955
|
+
await this.runtimeInitialization;
|
|
2956
|
+
if (operation === "install" && (this.preparationRevision > revision || preparing) && this.readiness === "ready") return this.statusSnapshot(this.anyRunning());
|
|
2957
|
+
if (operation === "install" && this.preparation) {
|
|
2958
|
+
await this.preparation;
|
|
2959
|
+
return this.statusSnapshot(this.anyRunning());
|
|
2960
|
+
}
|
|
2961
|
+
if (this.mutation || this.preparation || this.anyRunning()) throw new Error("\u8BF7\u5148\u505C\u6B62 Claude Code\uFF0C\u518D\u7BA1\u7406\u5B89\u88C5\u3002");
|
|
2780
2962
|
this.mutation = true;
|
|
2781
2963
|
try {
|
|
2782
2964
|
const runtime = this.runtime();
|
|
2783
|
-
if (operation === "install")
|
|
2784
|
-
|
|
2785
|
-
|
|
2965
|
+
if (operation === "install") {
|
|
2966
|
+
await this.ensurePrepared(true);
|
|
2967
|
+
await mkdir3(this.runtimeRoot(), { recursive: true });
|
|
2968
|
+
await this.writeSettingsDocument(join5(this.runtimeRoot(), "auto-install.json"), { disabled: false });
|
|
2969
|
+
this.autoSuppressed = false;
|
|
2970
|
+
} else if (operation === "rollback") {
|
|
2971
|
+
await runtime.rollback();
|
|
2972
|
+
this.readiness = "ready";
|
|
2973
|
+
} else {
|
|
2974
|
+
await mkdir3(this.runtimeRoot(), { recursive: true });
|
|
2975
|
+
await this.writeSettingsDocument(join5(this.runtimeRoot(), "auto-install.json"), { disabled: true });
|
|
2976
|
+
this.autoSuppressed = true;
|
|
2786
2977
|
await runtime.uninstall();
|
|
2787
2978
|
this.sessions.clear();
|
|
2979
|
+
this.readiness = "missing";
|
|
2788
2980
|
}
|
|
2981
|
+
this.runtimeDiagnostic = void 0;
|
|
2789
2982
|
return await this.statusSnapshot(agent === void 0 ? this.anyRunning() : this.owner(agent).busy || Boolean(this.owner(agent).turn?.view.running));
|
|
2790
|
-
} catch {
|
|
2983
|
+
} catch (error) {
|
|
2984
|
+
if (!this.desktop()) throw error;
|
|
2791
2985
|
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
2986
|
} finally {
|
|
2793
2987
|
this.mutation = false;
|
|
@@ -2878,6 +3072,8 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2878
3072
|
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
3073
|
this.processReservations += 1;
|
|
2880
3074
|
reserved = true;
|
|
3075
|
+
await this.runtimeInitialization;
|
|
3076
|
+
await this.ensurePrepared(false);
|
|
2881
3077
|
const runtime = this.runtime();
|
|
2882
3078
|
const executable = await runtime.getExecutablePath();
|
|
2883
3079
|
if (!executable) throw new Error("\u8BF7\u5148\u5B89\u88C5 Claude Code\u3002");
|
|
@@ -2901,16 +3097,16 @@ var ClaudeCodeService = class extends (_a = TypertRemoteService, _status_dec = [
|
|
|
2901
3097
|
return stored ?? (await credentials.resolve(credentialRef(reference)))?.value;
|
|
2902
3098
|
});
|
|
2903
3099
|
cancel.signal.throwIfAborted();
|
|
2904
|
-
projectionRoot =
|
|
3100
|
+
projectionRoot = join5(runtime.configDir, "sessions", createHash4("sha256").update(agent.id).digest("hex"), "projection");
|
|
2905
3101
|
await rm2(projectionRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
2906
3102
|
await mkdir3(projectionRoot, { recursive: true, mode: 448 });
|
|
2907
|
-
const skillRoot =
|
|
3103
|
+
const skillRoot = join5(projectionRoot, "skills");
|
|
2908
3104
|
for (const skill of skills.skills) {
|
|
2909
3105
|
const resource = skill.resourceBase;
|
|
2910
3106
|
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 =
|
|
3107
|
+
const dir = join5(skillRoot, skill.name);
|
|
2912
3108
|
await mkdir3(dir, { recursive: true, mode: 448 });
|
|
2913
|
-
await writeFile3(
|
|
3109
|
+
await writeFile3(join5(dir, "SKILL.md"), `---
|
|
2914
3110
|
name: ${skill.name}
|
|
2915
3111
|
description: ${JSON.stringify(skill.description)}
|
|
2916
3112
|
disable-model-invocation: ${!skill.invocation.modelInvocable}
|
|
@@ -2920,7 +3116,7 @@ ${hint}
|
|
|
2920
3116
|
|
|
2921
3117
|
${skill.content}`, { mode: 384 });
|
|
2922
3118
|
}
|
|
2923
|
-
const mcpPath =
|
|
3119
|
+
const mcpPath = join5(projectionRoot, "mcp.json");
|
|
2924
3120
|
const searchPath = Object.entries(process.env).find(([key]) => key.toUpperCase() === "PATH")?.[1];
|
|
2925
3121
|
const { servers: mcpServers, skipped: launchSkipped } = await writeClaudeMcpLaunchers(mcp, {
|
|
2926
3122
|
root: projectionRoot,
|
|
@@ -2929,9 +3125,9 @@ ${skill.content}`, { mode: 384 });
|
|
|
2929
3125
|
...searchPath ? { searchPath } : {}
|
|
2930
3126
|
});
|
|
2931
3127
|
await writeFile3(mcpPath, JSON.stringify({ mcpServers: Object.fromEntries(mcpServers.map(({ serverName, ...config }) => [serverName, config])) }), { mode: 384 });
|
|
2932
|
-
const pluginMeta =
|
|
3128
|
+
const pluginMeta = join5(projectionRoot, ".claude-plugin");
|
|
2933
3129
|
await mkdir3(pluginMeta, { mode: 448 });
|
|
2934
|
-
await writeFile3(
|
|
3130
|
+
await writeFile3(join5(pluginMeta, "plugin.json"), JSON.stringify({ name: "zerowall-session-skills", version: "0.1.0" }), { mode: 384 });
|
|
2935
3131
|
const environmentService = this.ctx.get("zerowallEnvironment");
|
|
2936
3132
|
const configuredEnvironment = {};
|
|
2937
3133
|
for (const { name: name2 } of await environmentService.listVariables()) {
|
|
@@ -3003,10 +3199,12 @@ ${skill.content}`, { mode: 384 });
|
|
|
3003
3199
|
);
|
|
3004
3200
|
if (bridgeState.drain) turn.drainBridge = bridgeState.drain;
|
|
3005
3201
|
const mcpService = this.ctx.get("zerowallMcp");
|
|
3006
|
-
const skillService = this.ctx.get("zerowallCapabilities");
|
|
3007
3202
|
const mcpRuntime = await mcpService?.list().catch(() => []) ?? [];
|
|
3008
|
-
const
|
|
3009
|
-
|
|
3203
|
+
const skillRegistry = bridgeAgent.ctx.get("skills");
|
|
3204
|
+
if (!skillRegistry) throw new Error("The Skills registry is unavailable.");
|
|
3205
|
+
const skillInventory = await skillRegistry.inventory({ cwd });
|
|
3206
|
+
const disabled = skillInventory.entries.filter((entry) => entry.effective && !entry.enabled).map((entry) => entry.skill.name);
|
|
3207
|
+
turn.view.resources = resourceStatus(skills, projects.listMcpServers(), schemas, mcpRuntime, disabled);
|
|
3010
3208
|
turn.view.mcp = turn.view.resources.filter((row2) => row2.kind === "mcp" && row2.state === "synced").length;
|
|
3011
3209
|
turn.diagnostics = turn.safe.fork();
|
|
3012
3210
|
const inputId = randomUUID4();
|
|
@@ -3415,7 +3613,7 @@ ${skill.content}`, { mode: 384 });
|
|
|
3415
3613
|
turn.diagnostics.finish();
|
|
3416
3614
|
const detail = stripVTControlCharacters(turn.diagnostics.snapshot()).slice(-32e3);
|
|
3417
3615
|
const category = claudeFailureCategory(detail);
|
|
3418
|
-
const root =
|
|
3616
|
+
const root = join5(this.runtime().configDir, "diagnostics");
|
|
3419
3617
|
turn.view.diagnostic = { id: turn.view.id, category };
|
|
3420
3618
|
const diagnostic = {
|
|
3421
3619
|
id: turn.view.id,
|
|
@@ -3428,7 +3626,7 @@ ${skill.content}`, { mode: 384 });
|
|
|
3428
3626
|
permission: turn.view.permission,
|
|
3429
3627
|
detail
|
|
3430
3628
|
};
|
|
3431
|
-
await mkdir3(root, { recursive: true, mode: 448 }).then(() => this.writeSettingsDocument(
|
|
3629
|
+
await mkdir3(root, { recursive: true, mode: 448 }).then(() => this.writeSettingsDocument(join5(root, `${diagnostic.id}.json`), diagnostic)).catch(() => {
|
|
3432
3630
|
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`;
|
|
3433
3631
|
});
|
|
3434
3632
|
}
|
|
@@ -3739,12 +3937,14 @@ var ClaudeCodeSubagentProvider = class {
|
|
|
3739
3937
|
return this.startRun(request);
|
|
3740
3938
|
}
|
|
3741
3939
|
};
|
|
3742
|
-
|
|
3743
|
-
|
|
3940
|
+
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) });
|
|
3941
|
+
function apply(ctx, config = {}) {
|
|
3942
|
+
ctx.plugin(ClaudeCodeService, config);
|
|
3744
3943
|
}
|
|
3745
|
-
var index_default = { name, inject, apply };
|
|
3944
|
+
var index_default = { name, inject, Config, apply };
|
|
3746
3945
|
export {
|
|
3747
3946
|
ClaudeCodeService,
|
|
3947
|
+
Config,
|
|
3748
3948
|
apply,
|
|
3749
3949
|
index_default as default,
|
|
3750
3950
|
inject,
|