@norman-else/dsh-claude 0.1.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-installer-DUVN1J6P.mjs","names":[],"sources":["../src/executable.ts","../src/preset-installer.ts"],"sourcesContent":["import { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { redactText } from './events.ts'\n\nconst VERSION_PATTERN = /(?:Claude Code\\s+)?v?(\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?)/i\nconst MAX_PROBE_STDOUT = 64 * 1024\nconst MAX_PROBE_STDERR = 8 * 1024\n\nexport type ExecutableRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\nexport class ClaudeExecutableNotFoundError extends Error {\n readonly searched: readonly string[]\n\n constructor(searched: readonly string[], options?: ErrorOptions) {\n super(`Claude Code executable not found. Searched: ${searched.join(', ')}`, options)\n this.name = 'ClaudeExecutableNotFoundError'\n this.searched = [...searched]\n }\n}\n\nexport interface ClaudeExecutableResolution {\n path: string\n searched: readonly string[]\n}\n\nexport interface ClaudeDoctorReport {\n executable: {\n status: 'found' | 'missing'\n path?: string\n searched: readonly string[]\n }\n version: {\n status: 'ok' | 'error' | 'not-run'\n value?: string\n message?: string\n }\n authentication: {\n status: 'signed-in' | 'signed-out' | 'unknown' | 'not-run'\n method?: string\n provider?: string\n subscription?: string\n message?: string\n }\n handshake: 'not-run' | 'ok' | 'error'\n}\n\nfunction fallbackCandidates(): string[] {\n if (process.platform !== 'darwin') return []\n return [\n join(homedir(), '.local', 'bin', 'claude'),\n '/opt/homebrew/bin/claude',\n '/usr/local/bin/claude',\n ]\n}\n\nfunction abortError(error: unknown): boolean {\n return error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')\n}\n\nexport async function resolveClaudeExecutable(\n runtime: ExecutableRuntime,\n configuredPath?: string,\n signal?: AbortSignal,\n): Promise<ClaudeExecutableResolution> {\n const searched: string[] = []\n const candidates = configuredPath === undefined\n ? ['claude', ...fallbackCandidates()]\n : [configuredPath]\n if (configuredPath !== undefined && !configuredPath.startsWith('/')) {\n throw new Error(`Claude Code executable path must be absolute: ${configuredPath}`)\n }\n\n let lastError: unknown\n for (const candidate of candidates) {\n if (searched.includes(candidate)) continue\n searched.push(candidate)\n try {\n const path = await runtime.resolveExecutable(candidate, undefined, signal)\n return { path, searched }\n } catch (error) {\n if (abortError(error) || signal?.aborted === true) throw error\n lastError = error\n }\n }\n throw new ClaudeExecutableNotFoundError(searched, lastError === undefined ? undefined : { cause: lastError })\n}\n\ninterface CollectedCommand {\n exitCode: number | null\n signal: NodeJS.Signals | null\n stdout: string\n stderr: string\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CollectedCommand> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0).text ?? ''\n const stderr = handle.collected.stderr?.readFrom(0).text ?? ''\n return { ...outcome, stdout, stderr }\n}\n\nasync function runProbe(\n runtime: ExecutableRuntime,\n executable: string,\n args: readonly string[],\n cwd: string,\n signal?: AbortSignal,\n): Promise<CollectedCommand> {\n return collect(runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes: MAX_PROBE_STDOUT },\n stderr: { maxBytes: MAX_PROBE_STDERR },\n },\n graceMs: 2_000,\n ...(signal === undefined ? {} : { signal }),\n env: {},\n }))\n}\n\nexport function parseClaudeVersion(output: string): string | undefined {\n return VERSION_PATTERN.exec(output)?.[1]\n}\n\nexport async function probeClaudeVersion(\n runtime: ExecutableRuntime,\n executable: string,\n cwd: string,\n signal?: AbortSignal,\n): Promise<string> {\n const result = await runProbe(runtime, executable, ['--version'], cwd, signal)\n const version = parseClaudeVersion(`${result.stdout}\\n${result.stderr}`)\n if (result.exitCode !== 0 || version === undefined) {\n throw new Error(`Claude Code version probe failed (${result.exitCode ?? result.signal ?? 'unknown exit'})`)\n }\n return version\n}\n\nexport async function probeClaudeAuthentication(\n runtime: ExecutableRuntime,\n executable: string,\n cwd: string,\n signal?: AbortSignal,\n): Promise<ClaudeDoctorReport['authentication']> {\n const result = await runProbe(runtime, executable, ['auth', 'status', '--json'], cwd, signal)\n if (result.exitCode !== 0) {\n return { status: 'unknown', message: 'Claude authentication status command failed' }\n }\n try {\n const value = JSON.parse(result.stdout) as Record<string, unknown>\n const report: ClaudeDoctorReport['authentication'] = {\n status: value.loggedIn === true ? 'signed-in' : value.loggedIn === false ? 'signed-out' : 'unknown',\n }\n if (typeof value.authMethod === 'string') report.method = redactText(value.authMethod, 100)\n if (typeof value.apiProvider === 'string') report.provider = redactText(value.apiProvider, 100)\n if (typeof value.subscriptionType === 'string') report.subscription = redactText(value.subscriptionType, 100)\n return report\n } catch {\n return { status: 'unknown', message: 'Claude authentication status was not valid JSON' }\n }\n}\n\nexport async function runClaudeDoctor(\n runtime: ExecutableRuntime,\n options: { configuredPath?: string; cwd: string; signal?: AbortSignal },\n): Promise<ClaudeDoctorReport> {\n let resolution: ClaudeExecutableResolution\n try {\n resolution = await resolveClaudeExecutable(runtime, options.configuredPath, options.signal)\n } catch (error) {\n if (error instanceof ClaudeExecutableNotFoundError) {\n return {\n executable: { status: 'missing', searched: error.searched },\n version: { status: 'not-run' },\n authentication: { status: 'not-run' },\n handshake: 'not-run',\n }\n }\n throw error\n }\n\n const report: ClaudeDoctorReport = {\n executable: { status: 'found', path: resolution.path, searched: resolution.searched },\n version: { status: 'not-run' },\n authentication: { status: 'not-run' },\n handshake: 'not-run',\n }\n try {\n report.version = {\n status: 'ok',\n value: await probeClaudeVersion(runtime, resolution.path, options.cwd, options.signal),\n }\n } catch (error) {\n report.version = {\n status: 'error',\n message: error instanceof Error ? error.message : 'Version probe failed',\n }\n }\n try {\n report.authentication = await probeClaudeAuthentication(runtime, resolution.path, options.cwd, options.signal)\n } catch (error) {\n report.authentication = {\n status: 'unknown',\n message: error instanceof Error ? error.message : 'Authentication probe failed',\n }\n }\n return report\n}\n","import { randomUUID } from 'node:crypto'\nimport { link, lstat, mkdir, readFile, readdir, rm, rmdir, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport { CLAUDE_CODE_PRESET_ID, LEGACY_CLAUDE_CODE_PRESET_ID } from './constants.ts'\n\nexport const MANAGED_PRESET_FILES = ['agent.cordis.yml', 'preset.yml'] as const\n\n/** Package specifier kept in the shipped template. DSH Desktop's resolver hook\n * only rewrites bare specifiers issued by the root include; preset subtrees\n * resolve through Node's internal loader with an unrelated base and cannot\n * find linked packages. The installer therefore substitutes the absolute\n * built entry path, which the preset tree imports directly as a file URL. */\nconst PRESET_ROUTE_PACKAGE_SPECIFIER = '@norman-else/dsh-claude/preset-route'\n\nexport class ManagedPresetConflictError extends Error {\n readonly path: string\n\n constructor(path: string) {\n super(`dsh-claude: refusing to overwrite user-modified preset file ${path}`)\n this.name = 'ManagedPresetConflictError'\n this.path = path\n }\n}\n\nexport interface ManagedPresetPaths {\n sourceDir: string\n targetDir: string\n legacyTargetDir?: string\n}\n\nexport function defaultManagedPresetPaths(dshHome?: string): ManagedPresetPaths {\n const packageRoot = fileURLToPath(new URL('../', import.meta.url))\n return {\n sourceDir: join(packageRoot, 'preset'),\n targetDir: dshHome === undefined\n ? dshHomePath('.agent-presets', CLAUDE_CODE_PRESET_ID)\n : join(dshHome, '.agent-presets', CLAUDE_CODE_PRESET_ID),\n legacyTargetDir: dshHome === undefined\n ? dshHomePath('.agent-presets', LEGACY_CLAUDE_CODE_PRESET_ID)\n : join(dshHome, '.agent-presets', LEGACY_CLAUDE_CODE_PRESET_ID),\n }\n}\n\ninterface ManagedContent {\n file: string\n /** Content this installer version writes. */\n content: string\n /** Older installer-written contents that may be silently upgraded/removed. */\n legacy: readonly string[]\n /** Legacy detection for contents that predate the current template. */\n isLegacy(current: string): boolean\n}\n\nasync function managedContents(paths: ManagedPresetPaths): Promise<ManagedContent[]> {\n const routeEntry = join(paths.sourceDir, '..', 'lib', 'preset-route.mjs')\n return await Promise.all(MANAGED_PRESET_FILES.map(async (file): Promise<ManagedContent> => {\n const source = await readFile(join(paths.sourceDir, file), 'utf8')\n const nameRow = `name: ${PRESET_ROUTE_PACKAGE_SPECIFIER}`\n if (file !== 'agent.cordis.yml' || !source.includes(nameRow)) {\n return { file, content: source, legacy: [], isLegacy: () => false }\n }\n return {\n file,\n content: source.replace(nameRow, `name: ${routeEntry}`),\n legacy: [source],\n // Any earlier installer generation wrote this same entry id with the\n // route reference in either supported form (bare package specifier or\n // absolute built-module path); treat those as safe to upgrade regardless\n // of comment or field drift in the template.\n isLegacy: current =>\n current.includes('id: claude-code-route')\n && (current.includes(nameRow) || current.includes('lib/preset-route.mjs')),\n }\n }))\n}\n\nasync function readIfPresent(path: string): Promise<string | undefined> {\n try {\n return await readFile(path, 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined\n throw error\n }\n}\n\nasync function atomicWrite(path: string, content: string): Promise<boolean> {\n await mkdir(dirname(path), { recursive: true })\n const temporary = `${path}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, content, { encoding: 'utf8', mode: 0o600, flag: 'wx' })\n try {\n await link(temporary, path)\n return true\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error\n if (await readIfPresent(path) === content) return false\n throw new ManagedPresetConflictError(path)\n }\n } finally {\n await rm(temporary, { force: true })\n }\n}\n\nexport async function ensureManagedPreset(paths = defaultManagedPresetPaths()): Promise<'installed' | 'unchanged'> {\n await assertSafeTargetDirectory(paths.targetDir)\n const expected = await managedContents(paths)\n let changed = false\n for (const { file, content, legacy, isLegacy } of expected) {\n const target = join(paths.targetDir, file)\n const current = await readIfPresent(target)\n if (current === content) continue\n if (current !== undefined) {\n // Upgrade installer-written legacy content in place; never touch user edits.\n if (!legacy.includes(current) && !isLegacy(current)) throw new ManagedPresetConflictError(target)\n await rm(target)\n }\n changed = await atomicWrite(target, content) || changed\n }\n if (paths.legacyTargetDir !== undefined) {\n changed = await removeLegacyManagedPreset(paths.legacyTargetDir) || changed\n }\n return changed ? 'installed' : 'unchanged'\n}\n\nasync function removeLegacyManagedPreset(targetDir: string): Promise<boolean> {\n await assertSafeTargetDirectory(targetDir)\n const agent = await readIfPresent(join(targetDir, 'agent.cordis.yml'))\n const preset = await readIfPresent(join(targetDir, 'preset.yml'))\n if (agent === undefined && preset === undefined) return false\n\n // Only migrate the prior installer-owned template. Any user edit leaves the\n // complete legacy preset untouched so existing sessions remain recoverable.\n const managedAgent = agent !== undefined\n && agent.includes('id: claude-code-route')\n && (agent.includes('dsh-claude-code/preset-route') || agent.includes('lib/preset-route.mjs'))\n const managedPreset = preset !== undefined\n && preset.includes('Managed by dsh-claude-code')\n && preset.includes('name: Claude Code')\n if (!managedAgent || !managedPreset) return false\n\n await rm(join(targetDir, 'agent.cordis.yml'))\n await rm(join(targetDir, 'preset.yml'))\n if ((await readdir(targetDir)).length === 0) await rmdir(targetDir)\n return true\n}\n\n/** Reject a target directory that is a symlink (or occupies the path as a file)\n * so the managed preset never writes through an attacker-controlled link. */\nasync function assertSafeTargetDirectory(targetDir: string): Promise<void> {\n try {\n const stat = await lstat(targetDir)\n if (!stat.isDirectory() || stat.isSymbolicLink()) {\n throw new ManagedPresetConflictError(targetDir)\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return\n throw error\n }\n}\n\nexport async function removeManagedPreset(paths = defaultManagedPresetPaths()): Promise<'removed' | 'absent'> {\n await assertSafeTargetDirectory(paths.targetDir)\n const expected = await managedContents(paths)\n let removed = false\n for (const { file, content, legacy, isLegacy } of expected) {\n const target = join(paths.targetDir, file)\n const current = await readIfPresent(target)\n if (current === undefined) continue\n if (current !== content && !legacy.includes(current) && !isLegacy(current)) throw new ManagedPresetConflictError(target)\n await rm(target)\n removed = true\n }\n try {\n if ((await readdir(paths.targetDir)).length === 0) await rmdir(paths.targetDir)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n }\n return removed ? 'removed' : 'absent'\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,kBAAkB;AACxB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AAIzB,IAAa,gCAAb,cAAmD,MAAM;CACvD;CAEA,YAAY,UAA6B,SAAwB;EAC/D,MAAM,+CAA+C,SAAS,KAAK,IAAI,KAAK,OAAO;EACnF,KAAK,OAAO;EACZ,KAAK,WAAW,CAAC,GAAG,QAAQ;CAC9B;AACF;AA4BA,SAAS,qBAA+B;CACtC,IAAI,QAAQ,aAAa,UAAU,OAAO,CAAC;CAC3C,OAAO;EACL,KAAK,QAAQ,GAAG,UAAU,OAAO,QAAQ;EACzC;EACA;CACF;AACF;AAEA,SAAS,WAAW,OAAyB;CAC3C,OAAO,iBAAiB,UAAU,MAAM,SAAS,gBAAgB,MAAM,SAAS;AAClF;AAEA,eAAsB,wBACpB,SACA,gBACA,QACqC;CACrC,MAAM,WAAqB,CAAC;CAC5B,MAAM,aAAa,mBAAmB,KAAA,IAClC,CAAC,UAAU,GAAG,mBAAmB,CAAC,IAClC,CAAC,cAAc;CACnB,IAAI,mBAAmB,KAAA,KAAa,CAAC,eAAe,WAAW,GAAG,GAChE,MAAM,IAAI,MAAM,iDAAiD,gBAAgB;CAGnF,IAAI;CACJ,KAAK,MAAM,aAAa,YAAY;EAClC,IAAI,SAAS,SAAS,SAAS,GAAG;EAClC,SAAS,KAAK,SAAS;EACvB,IAAI;GAEF,OAAO;IAAE,MAAA,MADU,QAAQ,kBAAkB,WAAW,KAAA,GAAW,MAAM;IAC1D;GAAS;EAC1B,SAAS,OAAO;GACd,IAAI,WAAW,KAAK,KAAK,QAAQ,YAAY,MAAM,MAAM;GACzD,YAAY;EACd;CACF;CACA,MAAM,IAAI,8BAA8B,UAAU,cAAc,KAAA,IAAY,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AI,2BAA2B,MAAM;EACvH,MAAM,GAAG,MAAM;EACf,UAAU;CACZ;CACA,IAAI;EACF,KAAK,MAAM,QAAQ,MAAM,SAAS,EAAA,CAAG,WAAW,GAAG,MAAM,MAAM,MAAM,SAAS;CAChF,SAAS,OAAO;EACd,IAAK,MAAgC,SAAS,UAAU,MAAM;CAChE;CACA,OAAO,UAAU,YAAY;AAC/B"}
@@ -0,0 +1,11 @@
1
+ import { Context } from "@deepseek-ai/cordis";
2
+ //#region src/preset-route.d.ts
3
+ declare const name = "claude-code-preset-route";
4
+ declare const inject: string[];
5
+ interface Config {
6
+ model?: string;
7
+ }
8
+ declare function apply(ctx: Context, config?: Config): void;
9
+ //#endregion
10
+ export { Config, apply, inject, name };
11
+ //# sourceMappingURL=preset-route.d.mts.map
@@ -0,0 +1,24 @@
1
+ import { p as CLAUDE_CODE_PROVIDER } from "./events-qlmU1KrH.mjs";
2
+ import { i as CLAUDE_COMMANDS_SERVICE, n as claudePresenterDefinitions } from "./presenters-DbfG-9KQ.mjs";
3
+ //#region src/preset-route.ts
4
+ const name = "claude-code-preset-route";
5
+ const inject = ["tools", "commands"];
6
+ function apply(ctx, config = {}) {
7
+ ctx.on("agent/request", async (_payload, next) => {
8
+ const upstream = await next();
9
+ return {
10
+ ...upstream,
11
+ provider: CLAUDE_CODE_PROVIDER,
12
+ model: config.model ?? upstream.model ?? "default"
13
+ };
14
+ });
15
+ ctx.provide(CLAUDE_COMMANDS_SERVICE, {
16
+ list: (agent) => ctx.commands.list(agent),
17
+ register: (definition) => ctx.commands.register(definition)
18
+ });
19
+ for (const definition of claudePresenterDefinitions()) ctx.effect(() => ctx.tools.register(definition), `dsh-claude: ${definition.name} presentation`);
20
+ }
21
+ //#endregion
22
+ export { apply, inject, name };
23
+
24
+ //# sourceMappingURL=preset-route.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-route.mjs","names":[],"sources":["../src/preset-route.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-commands'\nimport type {} from '@deepseek-ai/dsh-tools'\nimport { CLAUDE_CODE_PROVIDER } from './constants.ts'\nimport { CLAUDE_COMMANDS_SERVICE } from './command-bridge.ts'\nimport { claudePresenterDefinitions } from './presenters.ts'\n\nexport const name = 'claude-code-preset-route'\nexport const inject = ['tools', 'commands']\n\nexport interface Config {\n model?: string\n}\n\nexport function apply(ctx: Context, config: Config = {}): void {\n ctx.on('agent/request', async (_payload, next) => {\n const upstream = await next()\n return {\n ...upstream,\n provider: CLAUDE_CODE_PROVIDER,\n model: config.model ?? upstream.model ?? 'default',\n }\n })\n // Provide this agent-scope commands service so the host-side command\n // bridge can register Claude's catalog into exactly this agent's scope\n // layer. The preset row isolates the service per entry (per session); the\n // host reads it via serviceForAgent(ctx, agent, CLAUDE_COMMANDS_SERVICE).\n ctx.provide(CLAUDE_COMMANDS_SERVICE, {\n list: agent => ctx.commands.list(agent as never),\n register: definition => ctx.commands.register(definition),\n })\n // Presentation-only tool mirrors, scoped to this preset's agents: they let\n // the host compute native render intents for the mirrored Claude tool\n // events. Claude Code owns execution; the stub `execute` never runs.\n for (const definition of claudePresenterDefinitions()) {\n ctx.effect(() => ctx.tools.register(definition), `dsh-claude: ${definition.name} presentation`)\n }\n}\n"],"mappings":";;;AAQA,MAAa,OAAO;AACpB,MAAa,SAAS,CAAC,SAAS,UAAU;AAM1C,SAAgB,MAAM,KAAc,SAAiB,CAAC,GAAS;CAC7D,IAAI,GAAG,iBAAiB,OAAO,UAAU,SAAS;EAChD,MAAM,WAAW,MAAM,KAAK;EAC5B,OAAO;GACL,GAAG;GACH,UAAU;GACV,OAAO,OAAO,SAAS,SAAS,SAAS;EAC3C;CACF,CAAC;CAKD,IAAI,QAAQ,yBAAyB;EACnC,OAAM,UAAS,IAAI,SAAS,KAAK,KAAc;EAC/C,WAAU,eAAc,IAAI,SAAS,SAAS,UAAU;CAC1D,CAAC;CAID,KAAK,MAAM,cAAc,2BAA2B,GAClD,IAAI,aAAa,IAAI,MAAM,SAAS,UAAU,GAAG,eAAe,WAAW,KAAK,cAAc;AAElG"}
package/package.json ADDED
@@ -0,0 +1,124 @@
1
+ {
2
+ "name": "@norman-else/dsh-claude",
3
+ "description": "Run the local Claude Code CLI as a first-class main conversation inside DeepSeek Harness",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "main": "lib/index.mjs",
7
+ "types": "lib/index.d.mts",
8
+ "bin": {
9
+ "dsh-claude": "lib/bin.mjs"
10
+ },
11
+ "scripts": {
12
+ "build": "tsdown",
13
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.client.json",
14
+ "test": "vitest run",
15
+ "check": "pnpm run typecheck && pnpm run test && pnpm run build",
16
+ "prepack": "pnpm run build"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./lib/index.d.mts",
21
+ "default": "./lib/index.mjs"
22
+ },
23
+ "./preset-route": {
24
+ "types": "./lib/preset-route.d.mts",
25
+ "default": "./lib/preset-route.mjs"
26
+ },
27
+ "./client": "./lib/client.js",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "lib",
32
+ "preset",
33
+ "cordis.patch.yml",
34
+ "README.md",
35
+ "INSTALL.md",
36
+ "LICENSE"
37
+ ],
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/Norman-else/dsh-claude.git"
42
+ },
43
+ "homepage": "https://github.com/Norman-else/dsh-claude#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/Norman-else/dsh-claude/issues"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "engines": {
51
+ "node": ">=20"
52
+ },
53
+ "dsh": {
54
+ "bundle": {
55
+ "patch": "./cordis.patch.yml"
56
+ },
57
+ "client": {
58
+ "inject": [
59
+ "@deepseek-ai/dsh-client-runtime",
60
+ "@deepseek-ai/dsh-client-ui-conversation",
61
+ "@deepseek-ai/dsh-client-ui-primitives",
62
+ "@deepseek-ai/dsh-client-ui-settings",
63
+ "@deepseek-ai/dsh-client-ui-slots",
64
+ "@deepseek-ai/dsh-client-locale"
65
+ ],
66
+ "platform": "web"
67
+ }
68
+ },
69
+ "dependencies": {
70
+ "@anthropic-ai/claude-agent-sdk": "0.3.233"
71
+ },
72
+ "peerDependencies": {
73
+ "@deepseek-ai/cordis": "^4.0.1",
74
+ "@deepseek-ai/dsh-agent": "*",
75
+ "@deepseek-ai/dsh-agent-presets": "*",
76
+ "@deepseek-ai/dsh-brand": "*",
77
+ "@deepseek-ai/dsh-client-locale": "*",
78
+ "@deepseek-ai/dsh-client-runtime": "*",
79
+ "@deepseek-ai/dsh-client-ui-conversation": "*",
80
+ "@deepseek-ai/dsh-client-ui-primitives": "*",
81
+ "@deepseek-ai/dsh-client-ui-settings": "*",
82
+ "@deepseek-ai/dsh-client-ui-slots": "*",
83
+ "@deepseek-ai/dsh-commands": "*",
84
+ "@deepseek-ai/dsh-home-paths": "*",
85
+ "@deepseek-ai/dsh-host-webserver": "*",
86
+ "@deepseek-ai/dsh-llm": "*",
87
+ "@deepseek-ai/dsh-session": "*",
88
+ "@deepseek-ai/dsh-subprocess": "*",
89
+ "@deepseek-ai/dsh-tools": "*",
90
+ "@deepseek-ai/dsh-user-approval": "*",
91
+ "@deepseek-ai/schemastery": "^3.18.1",
92
+ "react": "^18.2.0",
93
+ "react-dom": "^18.2.0"
94
+ },
95
+ "devDependencies": {
96
+ "@deepseek-ai/cordis": "4.0.1",
97
+ "@deepseek-ai/dsh-agent": "0.1.0-rc.6",
98
+ "@deepseek-ai/dsh-agent-presets": "0.1.0-rc.6",
99
+ "@deepseek-ai/dsh-brand": "0.1.0-rc.6",
100
+ "@deepseek-ai/dsh-client-locale": "0.1.0-rc.6",
101
+ "@deepseek-ai/dsh-client-runtime": "0.1.0-rc.6",
102
+ "@deepseek-ai/dsh-client-ui-conversation": "0.1.0-rc.6",
103
+ "@deepseek-ai/dsh-client-ui-primitives": "0.1.0-rc.6",
104
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.6",
105
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.6",
106
+ "@deepseek-ai/dsh-commands": "0.1.0-rc.6",
107
+ "@deepseek-ai/dsh-home-paths": "0.1.0-rc.6",
108
+ "@deepseek-ai/dsh-host-webserver": "0.1.0-rc.6",
109
+ "@deepseek-ai/dsh-llm": "0.1.0-rc.6",
110
+ "@deepseek-ai/dsh-session": "0.1.0-rc.6",
111
+ "@deepseek-ai/dsh-subprocess": "0.1.0-rc.6",
112
+ "@deepseek-ai/dsh-tools": "0.1.0-rc.6",
113
+ "@deepseek-ai/dsh-user-approval": "0.1.0-rc.6",
114
+ "@deepseek-ai/schemastery": "3.18.1",
115
+ "@types/node": "^22.20.0",
116
+ "@types/react": "~18.3.1",
117
+ "@types/react-dom": "~18.3.0",
118
+ "react": "18.2.0",
119
+ "react-dom": "18.2.0",
120
+ "tsdown": "^0.22.2",
121
+ "typescript": "^5.9.3",
122
+ "vitest": "^4.1.8"
123
+ }
124
+ }
@@ -0,0 +1,14 @@
1
+ # Managed by dsh-claude. Claude Code owns the inner agent loop and tools;
2
+ # this preset contributes only the request-route override.
3
+ # Template: the installer rewrites `name` to the absolute path of the built
4
+ # lib/preset-route.mjs, because preset subtrees cannot resolve bare package
5
+ # specifiers for linked profiles (DSH Desktop's resolver hook only covers the
6
+ # root include).
7
+ - id: claude-code-route
8
+ name: @norman-else/dsh-claude/preset-route
9
+ # Entry-local isolate realm: each session's preset mount gets its own
10
+ # claudeCommands service instance (keeps mountPreset's leaked-service check
11
+ # happy and prevents cross-session collisions). The host reads it through
12
+ # dsh-agent-presets' serviceForAgent().
13
+ isolate:
14
+ claudeCommands: true
@@ -0,0 +1,4 @@
1
+ # Managed by dsh-claude. Do not edit; copy this preset under a new id to customize it.
2
+ name: Claude
3
+ description: Use the local Claude Code as the complete agent runtime inside DSH.
4
+ order: 10