dsh-worktree-switch 0.2.1 → 0.3.1
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/LICENSE +21 -0
- package/README.md +42 -15
- package/cordis.patch.yml +8 -0
- package/lib/client.js +87 -18
- package/lib/index.d.ts +2 -0
- package/lib/index.js +412 -38
- package/lib/index.js.map +1 -1
- package/package.json +56 -55
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/host/git.ts","../src/host/naming.ts","../src/host/handlers.ts","../src/host/routes.ts","../src/index.ts"],"sourcesContent":["/**\n * Unconfined Git calls behind the plugin's user-initiated verbs.\n *\n * Creation goes through `ctx.worktrees` (the harness service), which runs its\n * own Git under the calling session's sandbox policy. The list, status, and\n * discard verbs here belong to a person clicking in the UI rather than to a\n * model turn: they inspect and delete the copies the user can see, from a path\n * the same UI just listed. They therefore spawn Git directly, the same way the\n * installed `dsh-worktree-space` plugin does, instead of borrowing a session's\n * policy for an operation no session asked for.\n * @module dsh-worktree-switch/host/git\n */\n\nimport { realpath } from 'node:fs/promises'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-subprocess'\n\n/** Whole-command deadline for one Git call. */\nexport const GIT_TIMEOUT_MS = 20_000\n\n/** Per-stream capture cap; worktree listings and status lines are small. */\nconst MAX_OUTPUT_BYTES = 1_048_576\n\n/**\n * Clear inherited repository selectors and config so the command reads the\n * checkout named by `cwd`, never one inherited from the Host's environment.\n * One entry per key: `undefined` removes the variable for the child.\n */\nconst GIT_ENV: NodeJS.ProcessEnv = Object.fromEntries([\n 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY',\n 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT',\n 'GIT_CEILING_DIRECTORIES', 'GIT_PREFIX', 'GIT_SHALLOW_FILE', 'GIT_GRAFT_FILE',\n 'GIT_REPLACE_REF_BASE', 'GIT_ATTR_SOURCE',\n].map(key => [key, undefined]))\n\n/** One bounded Git invocation's captured result. */\nexport interface GitResult {\n /** Captured stdout. */\n readonly stdout: string\n /** Captured stderr. */\n readonly stderr: string\n /** Process exit status. */\n readonly exitCode: number\n}\n\n/** A Git invocation that exited with a status the caller did not allow. */\nexport class GitFailure extends Error {\n /**\n * @param args - arguments after the executable, for diagnostics.\n * @param result - the captured outcome.\n */\n constructor(readonly args: readonly string[], readonly result: GitResult) {\n const detail = result.stderr.trim() === '' ? result.stdout.trim() : result.stderr.trim()\n super(`git ${args.join(' ')} failed (exit ${result.exitCode})${detail === '' ? '' : `: ${detail}`}`)\n this.name = 'GitFailure'\n }\n}\n\n/** Options for {@link runGit}. */\nexport interface GitOptions {\n /** Caller cancellation, combined with the command deadline. */\n readonly signal?: AbortSignal | undefined\n /** Exit statuses that are not failures; defaults to `[0]`. */\n readonly allowedExitCodes?: readonly number[] | undefined\n /** Override for {@link GIT_TIMEOUT_MS}. */\n readonly timeoutMs?: number | undefined\n}\n\n/**\n * Run one Git command without a shell and await its termination.\n * @param ctx - Host context carrying the subprocess provider.\n * @param cwd - absolute directory the command runs in.\n * @param args - arguments after the executable.\n * @param options - cancellation, accepted exit statuses, and deadline.\n * @returns captured stdout, stderr, and exit status.\n * @throws {GitFailure} when the exit status is not allowed or the command was killed.\n */\nexport async function runGit(\n ctx: Context,\n cwd: string,\n args: readonly string[],\n options: GitOptions = {},\n): Promise<GitResult> {\n const deadline = AbortSignal.timeout(options.timeoutMs ?? GIT_TIMEOUT_MS)\n const signal = options.signal === undefined ? deadline : AbortSignal.any([options.signal, deadline])\n const allowed = options.allowedExitCodes ?? [0]\n const program = await ctx.subprocess.resolveExecutable('git', undefined, signal)\n const argv = [program, '-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', ...args]\n const child = ctx.subprocess.spawn({\n argv,\n cwd,\n env: {\n ...GIT_ENV,\n GIT_TERMINAL_PROMPT: '0',\n GIT_LFS_SKIP_SMUDGE: '1',\n GIT_NO_LAZY_FETCH: '1',\n },\n signal,\n graceMs: 1_500,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes: MAX_OUTPUT_BYTES },\n stderr: { maxBytes: MAX_OUTPUT_BYTES },\n },\n })\n try {\n const outcome = await child.done\n const stdout = child.collected.stdout?.readFrom(0).text ?? ''\n const stderr = child.collected.stderr?.readFrom(0).text ?? ''\n const result: GitResult = { stdout, stderr, exitCode: outcome.exitCode ?? -1 }\n if (outcome.exitCode === null || !allowed.includes(outcome.exitCode)) throw new GitFailure(args, result)\n return result\n } finally {\n child.terminate()\n await child.waitForExit()\n }\n}\n\n/**\n * Resolve the repository root that contains `directory`.\n * @param ctx - Host context carrying the subprocess provider.\n * @param directory - absolute directory inside (or at) the checkout.\n * @param signal - caller cancellation.\n * @returns the canonical top-level directory Git reports.\n * @throws {GitFailure} when the directory is not inside a Git working tree.\n */\nexport async function repositoryRoot(ctx: Context, directory: string, signal?: AbortSignal): Promise<string> {\n const result = await runGit(ctx, directory, ['rev-parse', '--show-toplevel'], {\n signal,\n allowedExitCodes: [0, 128],\n })\n if (result.exitCode !== 0) throw new GitFailure(['rev-parse', '--show-toplevel'], result)\n return result.stdout.replace(/\\r?\\n$/, '')\n}\n\n/**\n * Resolve symlinks in a path that exists, falling back to the path as given.\n * @param path - absolute path.\n * @returns the canonical spelling when the path exists.\n */\nexport async function canonicalPath(path: string): Promise<string> {\n try {\n return await realpath(path)\n } catch {\n return path\n }\n}\n\n/** One checkout reported by `git worktree list --porcelain`. */\nexport interface WorktreeRecord {\n /** Absolute checkout directory. */\n readonly path: string\n /** Branch the checkout has checked out, when it has one. */\n readonly branch?: string | undefined\n}\n\n/**\n * Parse `git worktree list --porcelain` output into its records.\n * @param stdout - the command's stdout.\n * @returns one record per reported checkout, in Git's order.\n */\nexport function parseWorktreeList(stdout: string): WorktreeRecord[] {\n const records: WorktreeRecord[] = []\n let path: string | undefined\n let branch: string | undefined\n const flush = (): void => {\n if (path === undefined) return\n records.push(branch === undefined ? { path } : { path, branch })\n path = undefined\n branch = undefined\n }\n for (const line of stdout.split('\\n')) {\n if (line === '') {\n flush()\n continue\n }\n if (line.startsWith('worktree ')) path = line.slice('worktree '.length)\n else if (line.startsWith('branch refs/heads/')) branch = line.slice('branch refs/heads/'.length)\n }\n flush()\n return records\n}\n\n/**\n * List the worktree checkouts of one repository.\n * @param ctx - Host context carrying the subprocess provider.\n * @param root - repository root the command runs in.\n * @param signal - caller cancellation.\n * @returns every checkout Git reports for the repository.\n */\nexport async function listWorktreeRecords(\n ctx: Context,\n root: string,\n signal?: AbortSignal,\n): Promise<WorktreeRecord[]> {\n const result = await runGit(ctx, root, ['worktree', 'list', '--porcelain'], { signal })\n return parseWorktreeList(result.stdout)\n}\n\n/**\n * Count the changed and untracked files of one checkout.\n * @param ctx - Host context carrying the subprocess provider.\n * @param directory - checkout directory to inspect.\n * @param signal - caller cancellation.\n * @returns the number of `git status --porcelain` entries.\n */\nexport async function changedFileCount(\n ctx: Context,\n directory: string,\n signal?: AbortSignal,\n): Promise<number> {\n const result = await runGit(ctx, directory, ['status', '--porcelain', '--untracked-files=normal'], {\n signal,\n })\n return result.stdout.split('\\n').filter(line => line.trim() !== '').length\n}\n","/**\n * Names for the copy a session gets: lowercase words and a short suffix, so a\n * branch, a directory, a `git branch` row and this plugin's UI all read the\n * same. No prefix: the pool path already says where it lives.\n * @module dsh-worktree-switch/host/naming\n */\n\n/** First word of a generated name. */\nconst ADJECTIVES = [\n 'amber', 'brisk', 'calm', 'clever', 'crisp', 'eager', 'faint', 'fresh',\n 'gentle', 'happy', 'hollow', 'kind', 'lively', 'mellow', 'nimble', 'polite',\n 'quiet', 'rapid', 'ready', 'silent', 'soft', 'solid', 'steady', 'sunny',\n 'swift', 'tidy', 'vivid', 'warm', 'wise', 'young',\n] as const\n\n/** Second word of a generated name. */\nconst NOUNS = [\n 'anchor', 'atlas', 'badger', 'birch', 'brook', 'cedar', 'comet', 'coral',\n 'delta', 'ember', 'fern', 'field', 'finch', 'glade', 'harbor', 'heron',\n 'island', 'lark', 'ledge', 'maple', 'meadow', 'otter', 'pebble', 'pine',\n 'quartz', 'river', 'shore', 'stone', 'trail', 'willow',\n] as const\n\n/**\n * Generate one candidate worktree name.\n * @param random - uniform source in `[0, 1)`; injectable for deterministic tests.\n * @returns a lowercase, hyphen-joined branch-safe name such as `quiet-harbor-3fa9`.\n */\nexport function worktreeName(random: () => number = Math.random): string {\n const pick = (values: readonly string[]): string => {\n const index = Math.min(values.length - 1, Math.floor(random() * values.length))\n return values[index] ?? values[0] ?? 'copy'\n }\n const suffix = Math.min(0xffff, Math.floor(random() * 0x10000)).toString(16).padStart(4, '0')\n return `${pick(ADJECTIVES)}-${pick(NOUNS)}-${suffix}`\n}\n\n/** A pool entry name is exactly one path segment, as `git worktree` names it. */\nconst NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/\n\n/**\n * Validate a worktree name received from the browser before it reaches Git.\n * @param value - candidate name.\n * @returns true for one plain path segment that Git also accepts as a branch.\n */\nexport function isWorktreeName(value: string): boolean {\n return NAME_PATTERN.test(value) && !value.endsWith('.lock')\n}\n","/**\n * The plugin's host Remote face: the four verbs the browser half can call,\n * expressed against a live session and the checkouts on disk.\n *\n * This module is the seam the host tests drive directly. Everything below it —\n * Git, the worktree service, the sandbox policy it applies, and session\n * working-directory publication — belongs to the harness and is exercised by\n * its own tests.\n * @module dsh-worktree-switch/host/handlers\n */\n\nimport { lstat, stat } from 'node:fs/promises'\nimport { basename, isAbsolute, relative, resolve } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type { SessionId } from '@deepseek-ai/dsh-session'\nimport type {} from '@deepseek-ai/dsh-api-session-controller'\nimport type {} from '@deepseek-ai/dsh-experimental-worktree'\nimport type {} from '@deepseek-ai/dsh-working-directory'\nimport type {\n DiscardValue,\n ListValue,\n PrepareValue,\n StatusValue,\n WorktreeItem,\n WorktreeRef,\n} from '../types.ts'\nimport {\n canonicalPath,\n changedFileCount,\n GitFailure,\n listWorktreeRecords,\n repositoryRoot,\n runGit,\n} from './git.ts'\nimport { isWorktreeName, worktreeName } from './naming.ts'\n\n/** Attempts at a fresh name before a creation failure becomes an error. */\nconst CREATE_ATTEMPTS = 3\n\nexport type {\n DiscardValue,\n ListValue,\n PrepareValue,\n StatusValue,\n WorktreeItem,\n WorktreeRef,\n} from '../types.ts'\n\n/** A failed verb, carrying the stable code the browser half switches on. */\nexport class WorktreeToggleError extends Error {\n /**\n * @param code - stable failure code.\n * @param message - human-readable explanation.\n * @param details - extra machine-readable facts.\n */\n constructor(\n readonly code: string,\n message: string,\n readonly details: Readonly<Record<string, unknown>> = {},\n ) {\n super(message)\n this.name = 'WorktreeToggleError'\n }\n}\n\n/** Row config the verbs read. */\nexport interface WorktreeToggleOptions {\n /** Default for a project nothing has remembered yet. */\n readonly defaultEnabled: boolean\n}\n\n/** The host face the route layer exposes over the Connection fetch bridge. */\nexport interface WorktreeToggle {\n /**\n * Report whether the session's project can be isolated, and in what.\n * @param request - the calling session.\n * @param signal - caller cancellation.\n * @returns the status payload; `supported: false` is a normal answer.\n */\n status(request: { readonly sessionId: string }, signal?: AbortSignal): Promise<StatusValue>\n /**\n * Put the session into a fresh copy, creating it when necessary.\n * @param request - the calling session.\n * @param signal - caller cancellation.\n * @returns the created or already-present copy.\n * @throws {WorktreeToggleError} when the project cannot host a copy or Git refused.\n */\n prepare(request: { readonly sessionId: string }, signal?: AbortSignal): Promise<PrepareValue>\n /**\n * List the copies under one project's pool.\n * @param request - any directory inside the project.\n * @param signal - caller cancellation.\n * @returns the pool contents, or `supported: false` for a non-repository path.\n */\n list(request: { readonly path: string }, signal?: AbortSignal): Promise<ListValue>\n /**\n * Delete one copy and its branch.\n * @param request - a directory inside the project, and the copy's name.\n * @param signal - caller cancellation.\n * @returns the removed copy's identity.\n * @throws {WorktreeToggleError} when the copy is missing, dirty, or Git refused.\n */\n discard(\n request: { readonly path: string; readonly name: string },\n signal?: AbortSignal,\n ): Promise<DiscardValue>\n}\n\n/** Normalize a browser-supplied path before any filesystem work. */\nfunction absolutePath(value: string): string {\n const trimmed = value.trim()\n if (trimmed === '') throw new WorktreeToggleError('bad-request', 'a project path is required')\n return resolve(trimmed)\n}\n\n/**\n * The copy a session already runs in.\n *\n * A linked worktree is recognised from the checkout itself — its `.git` is a\n * file pointing back at the source repository, not a directory — rather than\n * from any configured pool path. The pool belongs to the harness worktree\n * service, so this plugin never needs a second copy of that setting: moving the\n * pool in the service's row config keeps every verb working.\n * @param current - the session's committed working directory.\n * @param repositoryRoot - canonical root of the project's repository.\n * @returns the copy's identity, or null when the directory is not one.\n */\nasync function worktreeAt(current: string, repositoryRoot: string): Promise<WorktreeRef | null> {\n const path = await canonicalPath(current)\n if (path === repositoryRoot) return null\n const inside = relative(repositoryRoot, path)\n if (inside === '' || inside.startsWith('..') || isAbsolute(inside)) return null\n const name = basename(path)\n if (!isWorktreeName(name)) return null\n try {\n if (!(await lstat(`${path}/.git`)).isFile()) return null\n } catch {\n return null\n }\n return { name, path, branch: name }\n}\n\n/**\n * Build the host face.\n * @param ctx - Host context with `agents`, `worktrees`, `workingDirectory`, and `subprocess`.\n * @param options - resolved row config.\n * @returns the four verbs.\n */\nexport function createWorktreeToggle(ctx: Context, options: WorktreeToggleOptions): WorktreeToggle {\n /** One in-flight preparation per session, so a double mount cannot create twice. */\n const pending = new Map<string, Promise<PrepareValue>>()\n\n const sessionOf = async (sessionId: string, signal?: AbortSignal): Promise<Agent> => {\n signal?.throwIfAborted()\n if (sessionId === '') throw new WorktreeToggleError('bad-request', 'a session id is required')\n const controller = ctx.get('sessionController')\n if (controller !== undefined) {\n const resolved = await controller.resolveAgent(sessionId as SessionId)\n if ('error' in resolved) {\n throw new WorktreeToggleError(resolved.error.code, resolved.error.message, {\n sessionId,\n })\n }\n return resolved.agent\n }\n const agent = ctx.agents.get(sessionId as SessionId)\n if (agent === undefined) {\n throw new WorktreeToggleError('session-not-found', `no live agent for session ${sessionId}`, {\n sessionId,\n })\n }\n return agent\n }\n\n /**\n * Resolve the canonical root of the repository that contains a directory.\n * Git reports the spelling of the path it was given; the worktree service\n * publishes canonical paths, so both halves must agree on one spelling.\n * @param directory - absolute directory inside the project.\n * @param signal - caller cancellation.\n * @returns the canonical repository root.\n */\n const repositoryOf = async (directory: string, signal?: AbortSignal): Promise<string> =>\n canonicalPath(await repositoryRoot(ctx, directory, signal))\n\n const status = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<StatusValue> => {\n const agent = await sessionOf(request.sessionId, signal)\n // The immutable creation directory is the project anchor; the committed\n // working directory may already be a copy this session entered.\n const startDirectory = agent.session.header.cwd ?? ctx.workingDirectory.get(agent.session)\n let root: string\n try {\n root = await repositoryOf(startDirectory, signal)\n } catch (error) {\n if (error instanceof GitFailure) {\n return { supported: false, reason: 'not-a-git-repository', defaultEnabled: options.defaultEnabled }\n }\n throw error\n }\n const current = ctx.workingDirectory.get(agent.session)\n signal?.throwIfAborted()\n const sourceDirty = await changedFileCount(ctx, root, signal)\n return {\n supported: true,\n repositoryRoot: root,\n sessionWorktree: await worktreeAt(current, root),\n sourceDirty,\n defaultEnabled: options.defaultEnabled,\n }\n }\n\n const prepareOnce = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<PrepareValue> => {\n const agent = await sessionOf(request.sessionId, signal)\n const current = await status(request, signal)\n if (!current.supported) {\n throw new WorktreeToggleError(\n 'not-a-git-repository',\n 'the session project is not inside a Git working tree',\n )\n }\n if (current.sessionWorktree !== null) {\n return {\n state: 'existing',\n worktree: current.sessionWorktree,\n repositoryRoot: current.repositoryRoot,\n sourceDirty: current.sourceDirty,\n }\n }\n // Status anchors on the immutable creation directory, while the worktree\n // service creates relative to the session's CURRENT directory. Refuse to\n // create when the two name different repositories: a copy in the wrong\n // project would look like success and be worse than no copy.\n const working = ctx.workingDirectory.get(agent.session)\n const workingProject = await repositoryOf(working, signal)\n if (workingProject !== current.repositoryRoot) {\n throw new WorktreeToggleError(\n 'session-moved',\n `this session now works in ${workingProject}, not in its project ${current.repositoryRoot}`,\n { repositoryRoot: current.repositoryRoot, workingProject },\n )\n }\n let lastFailure: unknown\n for (let attempt = 0; attempt < CREATE_ATTEMPTS; attempt += 1) {\n signal?.throwIfAborted()\n const name = worktreeName()\n try {\n const created = await ctx.worktrees.create(agent, { name, from: 'HEAD' }, signal)\n return {\n state: 'created',\n worktree: { name: created.branch, path: created.path, branch: created.branch },\n repositoryRoot: created.repositoryRoot,\n sourceDirty: current.sourceDirty,\n }\n } catch (error) {\n lastFailure = error\n const message = error instanceof Error ? error.message : String(error)\n // A name collision is the one failure a fresh name can fix. Everything\n // else (no commits yet, branch or path exists, Git missing) is reported\n // as-is: the caller must not be told \"created\" after a silent retry.\n if (!/already exists|worktree branch already exists|worktree path already exists/i.test(message)) {\n throw new WorktreeToggleError('worktree-create-failed', message, { name })\n }\n }\n }\n throw new WorktreeToggleError(\n 'worktree-create-failed',\n `could not allocate a free worktree name after ${CREATE_ATTEMPTS} attempts`,\n { cause: lastFailure instanceof Error ? lastFailure.message : String(lastFailure) },\n )\n }\n\n const prepare = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<PrepareValue> => {\n const running = pending.get(request.sessionId)\n if (running !== undefined) return running\n const operation = prepareOnce(request, signal)\n pending.set(request.sessionId, operation)\n try {\n return await operation\n } finally {\n if (pending.get(request.sessionId) === operation) pending.delete(request.sessionId)\n }\n }\n\n const list = async (\n request: { readonly path: string },\n signal?: AbortSignal,\n ): Promise<ListValue> => {\n const directory = absolutePath(request.path)\n let root: string\n try {\n root = await repositoryOf(directory, signal)\n } catch (error) {\n if (error instanceof GitFailure) return { supported: false, reason: 'not-a-git-repository' }\n throw error\n }\n const records = await listWorktreeRecords(ctx, root, signal)\n const items: WorktreeItem[] = []\n for (const record of records) {\n signal?.throwIfAborted()\n const path = await canonicalPath(record.path)\n // The repository's own checkout is the source, never a copy.\n if (path === root) continue\n const name = basename(path)\n if (!isWorktreeName(name)) continue\n const branch = record.branch ?? name\n let createdAt = 0\n let prunable = true\n try {\n const info = await stat(path)\n createdAt = Math.trunc(info.birthtimeMs > 0 ? info.birthtimeMs : info.mtimeMs)\n prunable = false\n } catch {\n // The checkout directory is gone; Git still lists it until pruned.\n }\n const changedFiles = prunable ? 0 : await changedFileCount(ctx, path, signal)\n items.push({ name, path, branch, createdAt, changedFiles, prunable })\n }\n items.sort((left, right) => right.createdAt - left.createdAt || left.name.localeCompare(right.name))\n return { supported: true, repositoryRoot: root, items }\n }\n\n const discard = async (\n request: { readonly path: string; readonly name: string },\n signal?: AbortSignal,\n ): Promise<DiscardValue> => {\n const directory = absolutePath(request.path)\n if (!isWorktreeName(request.name)) {\n throw new WorktreeToggleError('worktree-name-invalid', `not a worktree name: ${request.name}`)\n }\n const root = await repositoryOf(directory, signal)\n const listed = await list({ path: directory }, signal)\n if (!listed.supported) {\n throw new WorktreeToggleError('not-a-git-repository', 'the project is not inside a Git working tree')\n }\n const item = listed.items.find(entry => entry.name === request.name)\n if (item === undefined) {\n throw new WorktreeToggleError(\n 'worktree-not-found',\n `no worktree named ${request.name} in ${root}`,\n { name: request.name, repositoryRoot: root },\n )\n }\n if (item.changedFiles > 0) {\n throw new WorktreeToggleError(\n 'worktree-dirty',\n `${item.name} has ${item.changedFiles} uncommitted change(s); commit or discard them first`,\n { name: item.name, changedFiles: item.changedFiles },\n )\n }\n if (item.prunable) {\n await runGit(ctx, root, ['worktree', 'prune'], { signal })\n } else {\n const removed = await runGit(ctx, root, ['worktree', 'remove', item.path], {\n signal,\n allowedExitCodes: [0, 128],\n })\n if (removed.exitCode !== 0) {\n throw new WorktreeToggleError(\n 'worktree-remove-failed',\n new GitFailure(['worktree', 'remove', item.path], removed).message,\n { name: item.name, path: item.path },\n )\n }\n }\n const deleted = await runGit(ctx, root, ['branch', '-D', '--', item.branch], {\n signal,\n allowedExitCodes: [0, 1],\n })\n // Status 1 with \"not found\" is the branch already being gone (removed by\n // hand between the read and the click); that is not a failed discard.\n const branchGone = deleted.exitCode === 1 && /not found/i.test(deleted.stderr)\n if (deleted.exitCode !== 0 && !branchGone) {\n throw new WorktreeToggleError(\n 'worktree-remove-failed',\n new GitFailure(['branch', '-D', item.branch], deleted).message,\n { name: item.name, branch: item.branch },\n )\n }\n return { removed: true, name: item.name, branch: item.branch, path: item.path }\n }\n\n return { status, prepare, list, discard }\n}\n","/**\n * The Connection fetch bridge: four exact POST routes on the shared `/api`\n * channel, one per verb, speaking the `client-request` / `server-response`\n * envelope the browser's `connection.rpc.call` already implements.\n *\n * Exact routes are the only shape an out-of-tree plugin can claim: `/api` is\n * the one logical channel the API Gateway owns, so `rpc.handle` refuses it and\n * a second `rpc.intercept` throws. Every route below answers owner peers only,\n * which is what the local Web GUI is.\n * @module dsh-worktree-switch/host/routes\n */\n\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { ConnectionRpcResult } from '@deepseek-ai/dsh-client-connection'\nimport type {} from '@deepseek-ai/dsh-client-connection'\nimport type { DiscardValue, ListValue, PrepareValue, StatusValue, WorktreeToggle } from './handlers.ts'\nimport { WorktreeToggleError } from './handlers.ts'\n\n/** Absolute prefix every route below lives under. */\nexport const API_PREFIX = '/api/dsh-worktree-switch'\n\n/** Plugin id; the wire method prefix and the package name are the same string. */\nexport const PLUGIN_ID = 'dsh-worktree-switch'\n\n/** One route per verb. */\nexport const ENDPOINTS = ['status', 'prepare', 'list', 'discard'] as const\n\n/** A verb this route table serves. */\nexport type Endpoint = (typeof ENDPOINTS)[number]\n\n/** A decoded client request. */\ninterface ClientRequest {\n readonly rpcId: string\n readonly method: string\n readonly payload: Record<string, unknown>\n}\n\n/** A payload object with the named string field, or the failure to send back. */\nfunction requiredString(\n payload: Record<string, unknown>,\n field: string,\n): { readonly value: string } | { readonly failure: WorktreeToggleError } {\n const value = payload[field]\n if (typeof value !== 'string' || value.trim() === '') {\n return {\n failure: new WorktreeToggleError('bad-request', `payload.${field} must be a non-empty string`),\n }\n }\n return { value }\n}\n\n/**\n * Decode the browser's `client-request` envelope.\n * @param body - parsed JSON body.\n * @returns the request, or null when the envelope is malformed.\n */\nexport function readClientRequest(body: unknown): ClientRequest | null {\n if (body === null || typeof body !== 'object' || Array.isArray(body)) return null\n const record = body as Record<string, unknown>\n if (record.type !== 'client-request') return null\n const { rpcId, method } = record\n if (typeof rpcId !== 'string' || rpcId === '') return null\n if (typeof method !== 'string' || method === '') return null\n const payload = record.payload\n return {\n rpcId,\n method,\n payload: payload !== null && typeof payload === 'object' && !Array.isArray(payload)\n ? payload as Record<string, unknown>\n : {},\n }\n}\n\n/** A successful result. */\nfunction ok<T>(value: T): ConnectionRpcResult<T> {\n return { ok: true, value }\n}\n\n/** A failed result carrying the stable code. */\nfunction fail(code: string, message: string, details: Record<string, unknown> = {}): ConnectionRpcResult<never> {\n return { ok: false, error: { code, message, details } }\n}\n\n/**\n * Dispatch one decoded verb.\n * @param toggle - the host face.\n * @param endpoint - the verb.\n * @param payload - its decoded payload.\n * @param signal - request cancellation.\n * @returns the wire result.\n */\nexport async function dispatch(\n toggle: WorktreeToggle,\n endpoint: Endpoint,\n payload: Record<string, unknown>,\n signal: AbortSignal,\n): Promise<ConnectionRpcResult<StatusValue | PrepareValue | ListValue | DiscardValue>> {\n try {\n if (endpoint === 'status') {\n const sessionId = requiredString(payload, 'sessionId')\n if ('failure' in sessionId) throw sessionId.failure\n return ok(await toggle.status({ sessionId: sessionId.value }, signal))\n }\n if (endpoint === 'prepare') {\n const sessionId = requiredString(payload, 'sessionId')\n if ('failure' in sessionId) throw sessionId.failure\n return ok(await toggle.prepare({ sessionId: sessionId.value }, signal))\n }\n if (endpoint === 'list') {\n const path = requiredString(payload, 'path')\n if ('failure' in path) throw path.failure\n return ok(await toggle.list({ path: path.value }, signal))\n }\n const path = requiredString(payload, 'path')\n if ('failure' in path) throw path.failure\n const name = requiredString(payload, 'name')\n if ('failure' in name) throw name.failure\n return ok(await toggle.discard({ path: path.value, name: name.value }, signal))\n } catch (error) {\n if (error instanceof WorktreeToggleError) return fail(error.code, error.message, { ...error.details })\n return fail('internal', error instanceof Error ? error.message : String(error))\n }\n}\n\n/**\n * Register one exact route per verb on the shared `/api` channel.\n * @param ctx - Host context carrying `connection`.\n * @param toggle - the host face the routes call.\n */\nexport function registerWorktreeRoutes(ctx: Context, toggle: WorktreeToggle): void {\n for (const endpoint of ENDPOINTS) {\n ctx.effect(() => ctx.connection.fetch.register({\n path: `${API_PREFIX}/${endpoint}`,\n methods: ['POST'],\n requestBody: 'buffered',\n async fetch(request) {\n const contentType = request.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase()\n if (contentType !== 'application/json') {\n return new Response('content type must be application/json', { status: 415 })\n }\n let body: unknown\n try {\n body = await request.json()\n } catch {\n return new Response('body is not JSON', { status: 400 })\n }\n const message = readClientRequest(body)\n if (message === null) return new Response('invalid client-request message', { status: 400 })\n if (message.method !== `${PLUGIN_ID}/${endpoint}`) {\n return Response.json({\n type: 'server-response',\n rpcId: message.rpcId,\n result: fail('bad-request', 'RPC method does not match endpoint'),\n })\n }\n const result = await dispatch(toggle, endpoint, message.payload, request.signal)\n return Response.json({ type: 'server-response', rpcId: message.rpcId, result })\n },\n }), `${PLUGIN_ID} ${endpoint} route`)\n }\n}\n","/**\n * Host half of the Worktree switch.\n *\n * It mounts no service itself: the bundle patch inserts the harness worktree\n * service (`@deepseek-ai/dsh-experimental-worktree`, which provides\n * `ctx.worktrees`) and this plugin's own row. This plugin exposes four verbs\n * over the Connection fetch bridge and drives that service for creation; the\n * browser half renders the switch and the panel.\n * @module dsh-worktree-switch\n */\n\nimport type { Context } from '@deepseek-ai/cordis'\nimport Schema from '@deepseek-ai/schemastery'\nimport type {} from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-experimental-worktree'\nimport type {} from '@deepseek-ai/dsh-subprocess'\nimport type {} from '@deepseek-ai/dsh-working-directory'\nimport { createWorktreeToggle } from './host/handlers.ts'\nimport { registerWorktreeRoutes } from './host/routes.ts'\n\n/** Plugin id: package name, bundle row id, browser module id. */\nexport const name = 'dsh-worktree-switch'\n\n/**\n * Services this plugin cannot work without.\n *\n * `worktrees` is provided by the row this bundle's patch inserts next to its\n * own, so Cordis holds this plugin until that row has mounted.\n */\nexport const inject = ['agents', 'connection', 'subprocess', 'worktrees', 'workingDirectory']\n\n/** Row config accepted from `cordis.patch.yml`. */\nexport interface Config {\n /** Default for a project the user has never switched either way. */\n defaultEnabled: boolean\n}\n\n/** Schemastery schema for {@link Config}. */\nexport const Config: Schema<Config> = Schema.object({\n defaultEnabled: Schema.boolean()\n .default(true)\n .description('Start a new session in a worktree copy until the user turns the switch off for that project.'),\n})\n\n/**\n * Mount the host half.\n * @param ctx - Host context.\n * @param config - validated row config.\n */\nexport function apply(ctx: Context, config: Config): void {\n const toggle = createWorktreeToggle(ctx, { defaultEnabled: config.defaultEnabled })\n registerWorktreeRoutes(ctx, toggle)\n}\n"],"mappings":";;;;AAqBA,MAAM,mBAAmB;;;;;;AAOzB,MAAM,UAA6B,OAAO,YAAY;CACpD;CAAW;CAAiB;CAAkB;CAAkB;CAChE;CAAoC;CAAc;CAAyB;CAC3E;CAA2B;CAAc;CAAoB;CAC7D;CAAwB;AAC1B,CAAC,CAAC,KAAI,QAAO,CAAC,KAAK,KAAA,CAAS,CAAC,CAAC;;AAa9B,IAAa,aAAb,cAAgC,MAAM;CAKf;CAAkC;;;;;CAAvD,YAAY,MAAkC,QAA4B;EACxE,MAAM,SAAS,OAAO,OAAO,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,IAAI,OAAO,OAAO,KAAK;EACvF,MAAM,OAAO,KAAK,KAAK,GAAG,EAAE,gBAAgB,OAAO,SAAS,GAAG,WAAW,KAAK,KAAK,KAAK,UAA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S,QAAQ,UAAU,QAAQ,SAAS,QAAQ,MAAM;GAC/E,OAAO,SAAS,KAAK;IAAE,MAAM;IAAmB,OAAO,QAAQ;IAAO;GAAO,CAAC;EAChF;CACF,CAAC,GAAG,GAAG,UAAU,GAAG,SAAS,OAAO;AAExC;;;AC3IA,MAAa,OAAO;;;;;;;AAQpB,MAAa,SAAS;CAAC;CAAU;CAAc;CAAc;CAAa;AAAkB;;AAS5F,MAAa,SAAyB,OAAO,OAAO,EAClD,gBAAgB,OAAO,QAAQ,CAAC,CAC7B,QAAQ,IAAI,CAAC,CACb,YAAY,8FAA8F,EAC/G,CAAC;;;;;;AAOD,SAAgB,MAAM,KAAc,QAAsB;CAExD,uBAAuB,KADR,qBAAqB,KAAK,EAAE,gBAAgB,OAAO,eAAe,CACrD,CAAM;AACpC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/host/paths.ts","../src/host/guard.ts","../src/host/git.ts","../src/host/naming.ts","../src/host/handlers.ts","../src/host/routes.ts","../src/host/scope.ts","../src/index.ts"],"sourcesContent":["/**\n * Path predicates the host half shares between the verbs, the scope hint, and\n * the working-directory watcher.\n * @module dsh-worktree-switch/host/paths\n */\n\nimport { isAbsolute, relative } from 'node:path'\n\n/**\n * Whether one absolute directory is the path itself or an ancestor of it.\n * @param directory - candidate ancestor.\n * @param path - absolute path to test.\n * @returns true when `path` is `directory` or lives below it.\n */\nexport function contains(directory: string, path: string): boolean {\n const inside = relative(directory, path)\n return inside === '' || (!inside.startsWith('..') && !isAbsolute(inside))\n}\n","/**\n * The source-checkout guard: while a session runs in a worktree copy, shell\n * commands that would run Git against the project checkout are refused before\n * dispatch.\n *\n * The prompt context (`worktree-switch:scope`) explains where the workspace\n * is, but it cannot stop a model that still reaches for the checkout it can\n * see — and the sandbox deliberately grants writes there. This guard is the\n * enforcement half that needs no harness change: `tools/pre-execute` can deny\n * one call, and the model reads the reason as that call's error result.\n *\n * The pattern is deliberately narrow. Only a shell call that mentions `git`\n * is considered, and only when it names the project checkout either as an\n * explicit `workdir` or as a literal absolute path in the command text.\n * `cd ..`-style relative escapes and shell variables are not resolved; the\n * guard is a net, not the sandbox boundary.\n * @module dsh-worktree-switch/host/guard\n */\n\nimport { isAbsolute, resolve } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { PreToolDecision, ToolExecution } from '@deepseek-ai/dsh-tools'\nimport type { SessionScope } from '../types.ts'\nimport { contains } from './paths.ts'\nimport type { SessionScopeRegistry } from './scope.ts'\n\n/** Tool names whose `command` argument is executed by a shell. */\nconst SHELL_TOOLS = new Set(['bash'])\n\n/** The arguments the guard reads from one shell call. */\ninterface ShellArguments {\n /** Command text as the model wrote it. */\n readonly command: string\n /** Explicit working directory, when the call carried one. */\n readonly workdir?: string\n}\n\n/**\n * Read a shell call's command and explicit directory, if this is one.\n * @param exec - the pending tool call.\n * @returns the fields the guard needs, or null for every other tool.\n */\nfunction shellArguments(exec: ToolExecution): ShellArguments | null {\n if (!SHELL_TOOLS.has(exec.name)) return null\n if (exec.arguments === null || typeof exec.arguments !== 'object') return null\n const args = exec.arguments as Record<string, unknown>\n const command = args['command']\n if (typeof command !== 'string' || command.trim() === '') return null\n const workdir = args['workdir']\n const explicit = typeof workdir === 'string' && workdir.trim() !== '' ? workdir : undefined\n return explicit === undefined ? { command } : { command, workdir: explicit }\n}\n\n/**\n * The model-facing denial for one shell command.\n * @param command - shell command text as the model wrote it.\n * @param workdir - explicit working directory, when the call carried one.\n * @param cwd - the session's committed working directory.\n * @param scope - the copy the session runs in.\n * @returns the denial reason, or null when the call may run.\n */\nexport function sourceCheckoutDenial(\n command: string,\n workdir: string | undefined,\n cwd: string,\n scope: SessionScope,\n): string | null {\n // Non-Git commands are out of scope: this guard is about the checkout's Git\n // state, not about every write the sandbox already allows.\n if (!/\\bgit\\b/.test(command)) return null\n const checkout = scope.worktree.path\n const project = scope.repositoryRoot\n if (workdir !== undefined) {\n const target = isAbsolute(workdir) ? workdir : resolve(cwd, workdir)\n if (contains(project, target) && !contains(checkout, target)) return denial(scope)\n }\n // The copy lives inside the project, so mention of the copy path must not\n // count as naming the checkout; strip it before looking for the project.\n if (command.split(checkout).join('').includes(project)) return denial(scope)\n return null\n}\n\n/** The one explanation every denial carries, including the way to get main. */\nfunction denial(scope: SessionScope): string {\n return `Denied: this session runs in the worktree copy ${JSON.stringify(scope.worktree.path)}, so Git commands targeting the project checkout ${JSON.stringify(scope.repositoryRoot)} are blocked. Run Git in the current working directory instead; to bring main's latest into this copy, use \\`git fetch origin main\\` and then \\`git merge origin/main\\` (or \\`git rebase origin/main\\`).`\n}\n\n/**\n * Refuse shell calls that run Git against the project checkout while the\n * session is inside a copy.\n *\n * The registry is the same one the prompt context reads, so the guard is\n * active exactly while the model has been told it is in a copy.\n * @param ctx - host context carrying `workingDirectory` and the tool runtime.\n * @param registry - sessions' confirmed copies.\n */\nexport function installSourceCheckoutGuard(ctx: Context, registry: SessionScopeRegistry): void {\n ctx.on('tools/pre-execute', async (exec, next): Promise<PreToolDecision> => {\n const agent = exec.agent\n if (agent === undefined) return next()\n const scope = registry.get(String(agent.session.id))\n if (scope === null) return next()\n const args = shellArguments(exec)\n if (args === null) return next()\n const denial = sourceCheckoutDenial(args.command, args.workdir, ctx.workingDirectory.get(agent.session), scope)\n return denial === null ? next() : { kind: 'deny', reason: denial }\n })\n}\n","/**\n * Unconfined Git calls behind the plugin's user-initiated verbs.\n *\n * Creation goes through `ctx.worktrees` (the harness service), which runs its\n * own Git under the calling session's sandbox policy. The list, status, and\n * discard verbs here belong to a person clicking in the UI rather than to a\n * model turn: they inspect and delete the copies the user can see, from a path\n * the same UI just listed. They therefore spawn Git directly, the same way the\n * installed `dsh-worktree-space` plugin does, instead of borrowing a session's\n * policy for an operation no session asked for.\n * @module dsh-worktree-switch/host/git\n */\n\nimport { realpath } from 'node:fs/promises'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-subprocess'\n\n/** Whole-command deadline for one Git call. */\nexport const GIT_TIMEOUT_MS = 20_000\n\n/** Per-stream capture cap; worktree listings and status lines are small. */\nconst MAX_OUTPUT_BYTES = 1_048_576\n\n/**\n * Clear inherited repository selectors and config so the command reads the\n * checkout named by `cwd`, never one inherited from the Host's environment.\n * One entry per key: `undefined` removes the variable for the child.\n */\nconst GIT_ENV: NodeJS.ProcessEnv = Object.fromEntries([\n 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY',\n 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT',\n 'GIT_CEILING_DIRECTORIES', 'GIT_PREFIX', 'GIT_SHALLOW_FILE', 'GIT_GRAFT_FILE',\n 'GIT_REPLACE_REF_BASE', 'GIT_ATTR_SOURCE',\n].map(key => [key, undefined]))\n\n/** One bounded Git invocation's captured result. */\nexport interface GitResult {\n /** Captured stdout. */\n readonly stdout: string\n /** Captured stderr. */\n readonly stderr: string\n /** Process exit status. */\n readonly exitCode: number\n}\n\n/** A Git invocation that exited with a status the caller did not allow. */\nexport class GitFailure extends Error {\n /**\n * @param args - arguments after the executable, for diagnostics.\n * @param result - the captured outcome.\n */\n constructor(readonly args: readonly string[], readonly result: GitResult) {\n const detail = result.stderr.trim() === '' ? result.stdout.trim() : result.stderr.trim()\n super(`git ${args.join(' ')} failed (exit ${result.exitCode})${detail === '' ? '' : `: ${detail}`}`)\n this.name = 'GitFailure'\n }\n}\n\n/** Options for {@link runGit}. */\nexport interface GitOptions {\n /** Caller cancellation, combined with the command deadline. */\n readonly signal?: AbortSignal | undefined\n /** Exit statuses that are not failures; defaults to `[0]`. */\n readonly allowedExitCodes?: readonly number[] | undefined\n /** Override for {@link GIT_TIMEOUT_MS}. */\n readonly timeoutMs?: number | undefined\n}\n\n/**\n * Run one Git command without a shell and await its termination.\n * @param ctx - Host context carrying the subprocess provider.\n * @param cwd - absolute directory the command runs in.\n * @param args - arguments after the executable.\n * @param options - cancellation, accepted exit statuses, and deadline.\n * @returns captured stdout, stderr, and exit status.\n * @throws {GitFailure} when the exit status is not allowed or the command was killed.\n */\nexport async function runGit(\n ctx: Context,\n cwd: string,\n args: readonly string[],\n options: GitOptions = {},\n): Promise<GitResult> {\n const deadline = AbortSignal.timeout(options.timeoutMs ?? GIT_TIMEOUT_MS)\n const signal = options.signal === undefined ? deadline : AbortSignal.any([options.signal, deadline])\n const allowed = options.allowedExitCodes ?? [0]\n const program = await ctx.subprocess.resolveExecutable('git', undefined, signal)\n const argv = [program, '-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', ...args]\n const child = ctx.subprocess.spawn({\n argv,\n cwd,\n env: {\n ...GIT_ENV,\n GIT_TERMINAL_PROMPT: '0',\n GIT_LFS_SKIP_SMUDGE: '1',\n GIT_NO_LAZY_FETCH: '1',\n },\n signal,\n graceMs: 1_500,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes: MAX_OUTPUT_BYTES },\n stderr: { maxBytes: MAX_OUTPUT_BYTES },\n },\n })\n try {\n const outcome = await child.done\n const stdout = child.collected.stdout?.readFrom(0).text ?? ''\n const stderr = child.collected.stderr?.readFrom(0).text ?? ''\n const result: GitResult = { stdout, stderr, exitCode: outcome.exitCode ?? -1 }\n if (outcome.exitCode === null || !allowed.includes(outcome.exitCode)) throw new GitFailure(args, result)\n return result\n } finally {\n child.terminate()\n await child.waitForExit()\n }\n}\n\n/**\n * Resolve the repository root that contains `directory`.\n * @param ctx - Host context carrying the subprocess provider.\n * @param directory - absolute directory inside (or at) the checkout.\n * @param signal - caller cancellation.\n * @returns the canonical top-level directory Git reports.\n * @throws {GitFailure} when the directory is not inside a Git working tree.\n */\nexport async function repositoryRoot(ctx: Context, directory: string, signal?: AbortSignal): Promise<string> {\n const result = await runGit(ctx, directory, ['rev-parse', '--show-toplevel'], {\n signal,\n allowedExitCodes: [0, 128],\n })\n if (result.exitCode !== 0) throw new GitFailure(['rev-parse', '--show-toplevel'], result)\n return result.stdout.replace(/\\r?\\n$/, '')\n}\n\n/**\n * Resolve symlinks in a path that exists, falling back to the path as given.\n * @param path - absolute path.\n * @returns the canonical spelling when the path exists.\n */\nexport async function canonicalPath(path: string): Promise<string> {\n try {\n return await realpath(path)\n } catch {\n return path\n }\n}\n\n/** One checkout reported by `git worktree list --porcelain`. */\nexport interface WorktreeRecord {\n /** Absolute checkout directory. */\n readonly path: string\n /** Branch the checkout has checked out, when it has one. */\n readonly branch?: string | undefined\n}\n\n/**\n * Parse `git worktree list --porcelain` output into its records.\n * @param stdout - the command's stdout.\n * @returns one record per reported checkout, in Git's order.\n */\nexport function parseWorktreeList(stdout: string): WorktreeRecord[] {\n const records: WorktreeRecord[] = []\n let path: string | undefined\n let branch: string | undefined\n const flush = (): void => {\n if (path === undefined) return\n records.push(branch === undefined ? { path } : { path, branch })\n path = undefined\n branch = undefined\n }\n for (const line of stdout.split('\\n')) {\n if (line === '') {\n flush()\n continue\n }\n if (line.startsWith('worktree ')) path = line.slice('worktree '.length)\n else if (line.startsWith('branch refs/heads/')) branch = line.slice('branch refs/heads/'.length)\n }\n flush()\n return records\n}\n\n/**\n * List the worktree checkouts of one repository.\n * @param ctx - Host context carrying the subprocess provider.\n * @param root - repository root the command runs in.\n * @param signal - caller cancellation.\n * @returns every checkout Git reports for the repository.\n */\nexport async function listWorktreeRecords(\n ctx: Context,\n root: string,\n signal?: AbortSignal,\n): Promise<WorktreeRecord[]> {\n const result = await runGit(ctx, root, ['worktree', 'list', '--porcelain'], { signal })\n return parseWorktreeList(result.stdout)\n}\n\n/**\n * Count the changed and untracked files of one checkout.\n * @param ctx - Host context carrying the subprocess provider.\n * @param directory - checkout directory to inspect.\n * @param signal - caller cancellation.\n * @returns the number of `git status --porcelain` entries.\n */\nexport async function changedFileCount(\n ctx: Context,\n directory: string,\n signal?: AbortSignal,\n): Promise<number> {\n const result = await runGit(ctx, directory, ['status', '--porcelain', '--untracked-files=normal'], {\n signal,\n })\n return result.stdout.split('\\n').filter(line => line.trim() !== '').length\n}\n","/**\n * Names for the copy a session gets: lowercase words and a short suffix, so a\n * branch, a directory, a `git branch` row and this plugin's UI all read the\n * same. No prefix: the pool path already says where it lives.\n * @module dsh-worktree-switch/host/naming\n */\n\n/** First word of a generated name. */\nconst ADJECTIVES = [\n 'amber', 'brisk', 'calm', 'clever', 'crisp', 'eager', 'faint', 'fresh',\n 'gentle', 'happy', 'hollow', 'kind', 'lively', 'mellow', 'nimble', 'polite',\n 'quiet', 'rapid', 'ready', 'silent', 'soft', 'solid', 'steady', 'sunny',\n 'swift', 'tidy', 'vivid', 'warm', 'wise', 'young',\n] as const\n\n/** Second word of a generated name. */\nconst NOUNS = [\n 'anchor', 'atlas', 'badger', 'birch', 'brook', 'cedar', 'comet', 'coral',\n 'delta', 'ember', 'fern', 'field', 'finch', 'glade', 'harbor', 'heron',\n 'island', 'lark', 'ledge', 'maple', 'meadow', 'otter', 'pebble', 'pine',\n 'quartz', 'river', 'shore', 'stone', 'trail', 'willow',\n] as const\n\n/**\n * Generate one candidate worktree name.\n * @param random - uniform source in `[0, 1)`; injectable for deterministic tests.\n * @returns a lowercase, hyphen-joined branch-safe name such as `quiet-harbor-3fa9`.\n */\nexport function worktreeName(random: () => number = Math.random): string {\n const pick = (values: readonly string[]): string => {\n const index = Math.min(values.length - 1, Math.floor(random() * values.length))\n return values[index] ?? values[0] ?? 'copy'\n }\n const suffix = Math.min(0xffff, Math.floor(random() * 0x10000)).toString(16).padStart(4, '0')\n return `${pick(ADJECTIVES)}-${pick(NOUNS)}-${suffix}`\n}\n\n/** A pool entry name is exactly one path segment, as `git worktree` names it. */\nconst NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/\n\n/**\n * Validate a worktree name received from the browser before it reaches Git.\n * @param value - candidate name.\n * @returns true for one plain path segment that Git also accepts as a branch.\n */\nexport function isWorktreeName(value: string): boolean {\n return NAME_PATTERN.test(value) && !value.endsWith('.lock')\n}\n","/**\n * The plugin's host Remote face: the five verbs the browser half can call,\n * expressed against a live session and the checkouts on disk.\n *\n * This module is the seam the host tests drive directly. Everything below it —\n * Git, the worktree service, the sandbox policy it applies, and session\n * working-directory publication — belongs to the harness and is exercised by\n * its own tests.\n * @module dsh-worktree-switch/host/handlers\n */\n\nimport { lstat, stat } from 'node:fs/promises'\nimport { basename, dirname, isAbsolute, relative, resolve } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type { SessionId } from '@deepseek-ai/dsh-session'\nimport type {} from '@deepseek-ai/dsh-api-session-controller'\nimport type {} from '@deepseek-ai/dsh-experimental-worktree'\nimport type {} from '@deepseek-ai/dsh-working-directory'\nimport type {\n DiscardValue,\n ListValue,\n PrepareValue,\n ReleaseValue,\n SessionScope,\n StatusValue,\n WorktreeItem,\n WorktreeRef,\n} from '../types.ts'\nimport {\n canonicalPath,\n changedFileCount,\n GitFailure,\n listWorktreeRecords,\n repositoryRoot,\n runGit,\n} from './git.ts'\nimport { isWorktreeName, worktreeName } from './naming.ts'\nimport { contains } from './paths.ts'\n\n/** Attempts at a fresh name before a creation failure becomes an error. */\nconst CREATE_ATTEMPTS = 3\n\nexport type {\n DiscardValue,\n ListValue,\n PrepareValue,\n ReleaseValue,\n SessionScope,\n StatusValue,\n WorktreeItem,\n WorktreeRef,\n} from '../types.ts'\n\n/** A failed verb, carrying the stable code the browser half switches on. */\nexport class WorktreeToggleError extends Error {\n /**\n * @param code - stable failure code.\n * @param message - human-readable explanation.\n * @param details - extra machine-readable facts.\n */\n constructor(\n readonly code: string,\n message: string,\n readonly details: Readonly<Record<string, unknown>> = {},\n ) {\n super(message)\n this.name = 'WorktreeToggleError'\n }\n}\n\n/** Row config the verbs read. */\nexport interface WorktreeToggleOptions {\n /** Default for a project nothing has remembered yet. */\n readonly defaultEnabled: boolean\n /**\n * Report what each verb learned about the session's copy, so the model-facing\n * scope hint can follow it without a second Git walk.\n * @param sessionId - wire session identity.\n * @param scope - the confirmed copy, or null when the session is not in one.\n */\n readonly onScope?: (sessionId: string, scope: SessionScope | null) => void\n}\n\n/** The host face the route layer exposes over the Connection fetch bridge. */\nexport interface WorktreeToggle {\n /**\n * Report whether the session's project can be isolated, and in what.\n * @param request - the calling session.\n * @param signal - caller cancellation.\n * @returns the status payload; `supported: false` is a normal answer.\n */\n status(request: { readonly sessionId: string }, signal?: AbortSignal): Promise<StatusValue>\n /**\n * Put the session into a fresh copy, creating it when necessary.\n * @param request - the calling session.\n * @param signal - caller cancellation.\n * @returns the created or already-present copy.\n * @throws {WorktreeToggleError} when the project cannot host a copy or Git refused.\n */\n prepare(request: { readonly sessionId: string }, signal?: AbortSignal): Promise<PrepareValue>\n /**\n * Put the session back in its project directory, undoing a copy the switch\n * created for it when it never became the conversation's workspace.\n * @param request - the calling session.\n * @param signal - caller cancellation.\n * @returns the directory the session now runs in, the copy removed, and the\n * copy left on disk when deleting it was not safe.\n * @throws {WorktreeToggleError} when the project cannot be resolved or the\n * session could not be moved back.\n */\n release(request: { readonly sessionId: string }, signal?: AbortSignal): Promise<ReleaseValue>\n /**\n * List the copies under one project's pool.\n * @param request - any directory inside the project.\n * @param signal - caller cancellation.\n * @returns the pool contents, or `supported: false` for a non-repository path.\n */\n list(request: { readonly path: string }, signal?: AbortSignal): Promise<ListValue>\n /**\n * Delete one copy and its branch.\n * @param request - a directory inside the project, and the copy's name.\n * @param signal - caller cancellation.\n * @returns the removed copy's identity.\n * @throws {WorktreeToggleError} when the copy is missing, dirty, or Git refused.\n */\n discard(\n request: { readonly path: string; readonly name: string },\n signal?: AbortSignal,\n ): Promise<DiscardValue>\n}\n\n/** Normalize a browser-supplied path before any filesystem work. */\nfunction absolutePath(value: string): string {\n const trimmed = value.trim()\n if (trimmed === '') throw new WorktreeToggleError('bad-request', 'a project path is required')\n return resolve(trimmed)\n}\n\n/**\n * The copy a session already runs in.\n *\n * A linked worktree is recognised from the checkout itself — its `.git` is a\n * file pointing back at the source repository, not a directory — rather than\n * from any configured pool path. The pool belongs to the harness worktree\n * service, so this plugin never needs a second copy of that setting: moving the\n * pool in the service's row config keeps every verb working.\n * @param current - the session's committed working directory.\n * @param repositoryRoot - canonical root of the project's repository.\n * @returns the copy's identity, or null when the directory is not one.\n */\nasync function worktreeAt(current: string, repositoryRoot: string): Promise<WorktreeRef | null> {\n const path = await canonicalPath(current)\n if (path === repositoryRoot) return null\n const inside = relative(repositoryRoot, path)\n if (inside === '' || inside.startsWith('..') || isAbsolute(inside)) return null\n const name = basename(path)\n if (!isWorktreeName(name)) return null\n try {\n if (!(await lstat(`${path}/.git`)).isFile()) return null\n } catch {\n return null\n }\n return { name, path, branch: name }\n}\n\n/**\n * Resolve the canonical root of the repository that contains a directory.\n * Git reports the spelling of the path it was given; the worktree service\n * publishes canonical paths, so both halves must agree on one spelling.\n * @param ctx - host context carrying `subprocess`.\n * @param directory - absolute directory inside the project.\n * @param signal - caller cancellation.\n * @returns the canonical repository root.\n */\nasync function repositoryOf(ctx: Context, directory: string, signal?: AbortSignal): Promise<string> {\n return canonicalPath(await repositoryRoot(ctx, directory, signal))\n}\n\n/**\n * Re-derive the copy one session runs in from its committed directory.\n *\n * A copy's root is the only linked checkout whose name matches the pool\n * convention, but a session may have changed into a directory *inside* the copy,\n * so ancestors are probed from the committed directory up to the project\n * anchor.\n * @param ctx - host context carrying `workingDirectory` and `subprocess`.\n * @param agent - live session owner.\n * @param signal - caller cancellation.\n * @returns the copy and project root, or null when the session is not in one.\n */\nexport async function detectSessionScope(\n ctx: Context,\n agent: Agent,\n signal?: AbortSignal,\n): Promise<SessionScope | null> {\n const current = ctx.workingDirectory.get(agent.session)\n const anchor = agent.session.header.cwd ?? current\n if (current === anchor || !contains(anchor, current)) return null\n let root: string\n try {\n root = await repositoryOf(ctx, anchor, signal)\n } catch {\n return null\n }\n signal?.throwIfAborted()\n let probe = current\n for (;;) {\n const copy = await worktreeAt(probe, root)\n if (copy !== null) return { worktree: copy, repositoryRoot: root }\n const parent = dirname(probe)\n if (probe === root || probe === anchor || parent === probe) return null\n probe = parent\n }\n}\n\n/**\n * Build the host face.\n * @param ctx - Host context with `agents`, `worktrees`, `workingDirectory`, and `subprocess`.\n * @param options - resolved row config.\n * @returns the five verbs.\n */\nexport function createWorktreeToggle(ctx: Context, options: WorktreeToggleOptions): WorktreeToggle {\n /** One in-flight preparation per session, so a double mount cannot create twice. */\n const pending = new Map<string, Promise<PrepareValue>>()\n /**\n * Copies this host instance created for a session, by session id. Turning the\n * switch off may only delete what the switch itself just made: a copy that\n * existed before this instance started is left for the panel's explicit\n * discard, because it may carry work the switch never saw.\n */\n const createdBySession = new Map<string, WorktreeRef>()\n\n const sessionOf = async (sessionId: string, signal?: AbortSignal): Promise<Agent> => {\n signal?.throwIfAborted()\n if (sessionId === '') throw new WorktreeToggleError('bad-request', 'a session id is required')\n const controller = ctx.get('sessionController')\n if (controller !== undefined) {\n const resolved = await controller.resolveAgent(sessionId as SessionId)\n if ('error' in resolved) {\n throw new WorktreeToggleError(resolved.error.code, resolved.error.message, {\n sessionId,\n })\n }\n return resolved.agent\n }\n const agent = ctx.agents.get(sessionId as SessionId)\n if (agent === undefined) {\n throw new WorktreeToggleError('session-not-found', `no live agent for session ${sessionId}`, {\n sessionId,\n })\n }\n return agent\n }\n\n const status = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<StatusValue> => {\n const agent = await sessionOf(request.sessionId, signal)\n // The immutable creation directory is the project anchor; the committed\n // working directory may already be a copy this session entered.\n const startDirectory = agent.session.header.cwd ?? ctx.workingDirectory.get(agent.session)\n let root: string\n try {\n root = await repositoryOf(ctx, startDirectory, signal)\n } catch (error) {\n if (error instanceof GitFailure) {\n return { supported: false, reason: 'not-a-git-repository', defaultEnabled: options.defaultEnabled }\n }\n throw error\n }\n const current = ctx.workingDirectory.get(agent.session)\n signal?.throwIfAborted()\n const sourceDirty = await changedFileCount(ctx, root, signal)\n const copy = await worktreeAt(current, root)\n options.onScope?.(request.sessionId, copy === null ? null : { worktree: copy, repositoryRoot: root })\n return {\n supported: true,\n repositoryRoot: root,\n sessionWorktree: copy,\n sourceDirty,\n defaultEnabled: options.defaultEnabled,\n }\n }\n\n const prepareOnce = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<PrepareValue> => {\n const agent = await sessionOf(request.sessionId, signal)\n const current = await status(request, signal)\n if (!current.supported) {\n throw new WorktreeToggleError(\n 'not-a-git-repository',\n 'the session project is not inside a Git working tree',\n )\n }\n if (current.sessionWorktree !== null) {\n options.onScope?.(request.sessionId, {\n worktree: current.sessionWorktree,\n repositoryRoot: current.repositoryRoot,\n })\n return {\n state: 'existing',\n worktree: current.sessionWorktree,\n repositoryRoot: current.repositoryRoot,\n sourceDirty: current.sourceDirty,\n }\n }\n // Status anchors on the immutable creation directory, while the worktree\n // service creates relative to the session's CURRENT directory. Refuse to\n // create when the two name different repositories: a copy in the wrong\n // project would look like success and be worse than no copy.\n const working = ctx.workingDirectory.get(agent.session)\n const workingProject = await repositoryOf(ctx, working, signal)\n if (workingProject !== current.repositoryRoot) {\n throw new WorktreeToggleError(\n 'session-moved',\n `this session now works in ${workingProject}, not in its project ${current.repositoryRoot}`,\n { repositoryRoot: current.repositoryRoot, workingProject },\n )\n }\n let lastFailure: unknown\n for (let attempt = 0; attempt < CREATE_ATTEMPTS; attempt += 1) {\n signal?.throwIfAborted()\n const name = worktreeName()\n try {\n const created = await ctx.worktrees.create(agent, { name, from: 'HEAD' }, signal)\n const worktree: WorktreeRef = { name: created.branch, path: created.path, branch: created.branch }\n createdBySession.set(request.sessionId, worktree)\n options.onScope?.(request.sessionId, { worktree, repositoryRoot: created.repositoryRoot })\n return {\n state: 'created',\n worktree,\n repositoryRoot: created.repositoryRoot,\n sourceDirty: current.sourceDirty,\n }\n } catch (error) {\n lastFailure = error\n const message = error instanceof Error ? error.message : String(error)\n // A name collision is the one failure a fresh name can fix. Everything\n // else (no commits yet, branch or path exists, Git missing) is reported\n // as-is: the caller must not be told \"created\" after a silent retry.\n if (!/already exists|worktree branch already exists|worktree path already exists/i.test(message)) {\n throw new WorktreeToggleError('worktree-create-failed', message, { name })\n }\n }\n }\n throw new WorktreeToggleError(\n 'worktree-create-failed',\n `could not allocate a free worktree name after ${CREATE_ATTEMPTS} attempts`,\n { cause: lastFailure instanceof Error ? lastFailure.message : String(lastFailure) },\n )\n }\n\n const prepare = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<PrepareValue> => {\n const running = pending.get(request.sessionId)\n if (running !== undefined) return running\n const operation = prepareOnce(request, signal)\n pending.set(request.sessionId, operation)\n try {\n return await operation\n } finally {\n if (pending.get(request.sessionId) === operation) pending.delete(request.sessionId)\n }\n }\n\n const list = async (\n request: { readonly path: string },\n signal?: AbortSignal,\n ): Promise<ListValue> => {\n const directory = absolutePath(request.path)\n let root: string\n try {\n root = await repositoryOf(ctx, directory, signal)\n } catch (error) {\n if (error instanceof GitFailure) return { supported: false, reason: 'not-a-git-repository' }\n throw error\n }\n const records = await listWorktreeRecords(ctx, root, signal)\n const items: WorktreeItem[] = []\n for (const record of records) {\n signal?.throwIfAborted()\n const path = await canonicalPath(record.path)\n // The repository's own checkout is the source, never a copy.\n if (path === root) continue\n const name = basename(path)\n if (!isWorktreeName(name)) continue\n const branch = record.branch ?? name\n let createdAt = 0\n let prunable = true\n try {\n const info = await stat(path)\n createdAt = Math.trunc(info.birthtimeMs > 0 ? info.birthtimeMs : info.mtimeMs)\n prunable = false\n } catch {\n // The checkout directory is gone; Git still lists it until pruned.\n }\n const changedFiles = prunable ? 0 : await changedFileCount(ctx, path, signal)\n items.push({ name, path, branch, createdAt, changedFiles, prunable })\n }\n items.sort((left, right) => right.createdAt - left.createdAt || left.name.localeCompare(right.name))\n return { supported: true, repositoryRoot: root, items }\n }\n\n /**\n * Delete one clean copy and its branch. Both the panel's discard and the\n * switch's own undo go through here, so the dirty guard has one home.\n * @param root - canonical repository root.\n * @param name - copy name; already validated by the caller.\n * @param signal - caller cancellation.\n * @returns the removed copy's identity.\n */\n const removeCopy = async (root: string, name: string, signal?: AbortSignal): Promise<DiscardValue> => {\n const listed = await list({ path: root }, signal)\n if (!listed.supported) {\n throw new WorktreeToggleError('not-a-git-repository', 'the project is not inside a Git working tree')\n }\n const item = listed.items.find(entry => entry.name === name)\n if (item === undefined) {\n throw new WorktreeToggleError(\n 'worktree-not-found',\n `no worktree named ${name} in ${root}`,\n { name, repositoryRoot: root },\n )\n }\n if (item.changedFiles > 0) {\n throw new WorktreeToggleError(\n 'worktree-dirty',\n `${item.name} has ${item.changedFiles} uncommitted change(s); commit or discard them first`,\n { name: item.name, changedFiles: item.changedFiles },\n )\n }\n if (item.prunable) {\n await runGit(ctx, root, ['worktree', 'prune'], { signal })\n } else {\n const removed = await runGit(ctx, root, ['worktree', 'remove', item.path], {\n signal,\n allowedExitCodes: [0, 128],\n })\n if (removed.exitCode !== 0) {\n throw new WorktreeToggleError(\n 'worktree-remove-failed',\n new GitFailure(['worktree', 'remove', item.path], removed).message,\n { name: item.name, path: item.path },\n )\n }\n }\n const deleted = await runGit(ctx, root, ['branch', '-D', '--', item.branch], {\n signal,\n allowedExitCodes: [0, 1],\n })\n // Status 1 with \"not found\" is the branch already being gone (removed by\n // hand between the read and the click); that is not a failed discard.\n const branchGone = deleted.exitCode === 1 && /not found/i.test(deleted.stderr)\n if (deleted.exitCode !== 0 && !branchGone) {\n throw new WorktreeToggleError(\n 'worktree-remove-failed',\n new GitFailure(['branch', '-D', item.branch], deleted).message,\n { name: item.name, branch: item.branch },\n )\n }\n for (const [sessionId, copy] of createdBySession) {\n if (copy.path === item.path) createdBySession.delete(sessionId)\n }\n return { removed: true, name: item.name, branch: item.branch, path: item.path }\n }\n\n const discard = async (\n request: { readonly path: string; readonly name: string },\n signal?: AbortSignal,\n ): Promise<DiscardValue> => {\n const directory = absolutePath(request.path)\n if (!isWorktreeName(request.name)) {\n throw new WorktreeToggleError('worktree-name-invalid', `not a worktree name: ${request.name}`)\n }\n const root = await repositoryOf(ctx, directory, signal)\n return await removeCopy(root, request.name, signal)\n }\n\n const release = async (\n request: { readonly sessionId: string },\n signal?: AbortSignal,\n ): Promise<ReleaseValue> => {\n // A create may still be in flight for this session: undo after it settles,\n // so a switch turned off mid-creation cannot race the copy into existence.\n const running = pending.get(request.sessionId)\n if (running !== undefined) {\n try {\n await running\n } catch {\n // Creation failed and already moved nothing; there is nothing to undo.\n }\n }\n signal?.throwIfAborted()\n const agent = await sessionOf(request.sessionId, signal)\n const current = ctx.workingDirectory.get(agent.session)\n // The immutable creation directory anchors the project, exactly as status\n // does: the committed directory may already be a copy this session entered.\n const anchor = agent.session.header.cwd ?? current\n let root: string\n try {\n root = await repositoryOf(ctx, anchor, signal)\n } catch (error) {\n if (error instanceof GitFailure) {\n throw new WorktreeToggleError(\n 'not-a-git-repository',\n 'the session project is not inside a Git working tree',\n )\n }\n throw error\n }\n const listed = await list({ path: anchor }, signal)\n if (!listed.supported) return { directory: current, removed: null, kept: null }\n const path = await canonicalPath(current)\n const item = listed.items.find(entry => contains(entry.path, path))\n if (item === undefined) {\n options.onScope?.(request.sessionId, null)\n return { directory: current, removed: null, kept: null }\n }\n const copy: WorktreeRef = { name: item.name, path: item.path, branch: item.branch }\n signal?.throwIfAborted()\n let directory: string\n try {\n directory = await ctx.workingDirectory.set(agent, anchor, signal)\n } catch (error) {\n throw new WorktreeToggleError(\n 'release-failed',\n `could not move the session back to ${anchor}: ${error instanceof Error ? error.message : String(error)}`,\n { name: copy.name, path: copy.path },\n )\n }\n options.onScope?.(request.sessionId, null)\n const mine = createdBySession.get(request.sessionId)\n if (mine === undefined || mine.path !== copy.path) {\n // Not the switch's own copy: leave it, the panel can discard it by hand.\n return { directory, removed: null, kept: copy }\n }\n try {\n const removed = await removeCopy(root, copy.name, signal)\n return {\n directory,\n removed: { name: removed.name, path: removed.path, branch: removed.branch },\n kept: null,\n }\n } catch (error) {\n if (signal?.aborted === true) throw error\n // Dirty or refused by Git: the session is still back in the project, so\n // the switch keeps its promise; the copy stays for the panel to handle.\n return { directory, removed: null, kept: copy }\n }\n }\n\n return { status, prepare, release, list, discard }\n}\n","/**\n * The Connection fetch bridge: five exact POST routes on the shared `/api`\n * channel, one per verb, speaking the `client-request` / `server-response`\n * envelope the browser's `connection.rpc.call` already implements.\n *\n * Exact routes are the only shape an out-of-tree plugin can claim: `/api` is\n * the one logical channel the API Gateway owns, so `rpc.handle` refuses it and\n * a second `rpc.intercept` throws. Every route below answers owner peers only,\n * which is what the local Web GUI is.\n * @module dsh-worktree-switch/host/routes\n */\n\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { ConnectionRpcResult } from '@deepseek-ai/dsh-client-connection'\nimport type {} from '@deepseek-ai/dsh-client-connection'\nimport type { DiscardValue, ListValue, PrepareValue, ReleaseValue, StatusValue, WorktreeToggle } from './handlers.ts'\nimport { WorktreeToggleError } from './handlers.ts'\n\n/** Absolute prefix every route below lives under. */\nexport const API_PREFIX = '/api/dsh-worktree-switch'\n\n/** Plugin id; the wire method prefix and the package name are the same string. */\nexport const PLUGIN_ID = 'dsh-worktree-switch'\n\n/** One route per verb. */\nexport const ENDPOINTS = ['status', 'prepare', 'release', 'list', 'discard'] as const\n\n/** A verb this route table serves. */\nexport type Endpoint = (typeof ENDPOINTS)[number]\n\n/** A decoded client request. */\ninterface ClientRequest {\n readonly rpcId: string\n readonly method: string\n readonly payload: Record<string, unknown>\n}\n\n/** A payload object with the named string field, or the failure to send back. */\nfunction requiredString(\n payload: Record<string, unknown>,\n field: string,\n): { readonly value: string } | { readonly failure: WorktreeToggleError } {\n const value = payload[field]\n if (typeof value !== 'string' || value.trim() === '') {\n return {\n failure: new WorktreeToggleError('bad-request', `payload.${field} must be a non-empty string`),\n }\n }\n return { value }\n}\n\n/**\n * Decode the browser's `client-request` envelope.\n * @param body - parsed JSON body.\n * @returns the request, or null when the envelope is malformed.\n */\nexport function readClientRequest(body: unknown): ClientRequest | null {\n if (body === null || typeof body !== 'object' || Array.isArray(body)) return null\n const record = body as Record<string, unknown>\n if (record.type !== 'client-request') return null\n const { rpcId, method } = record\n if (typeof rpcId !== 'string' || rpcId === '') return null\n if (typeof method !== 'string' || method === '') return null\n const payload = record.payload\n return {\n rpcId,\n method,\n payload: payload !== null && typeof payload === 'object' && !Array.isArray(payload)\n ? payload as Record<string, unknown>\n : {},\n }\n}\n\n/** A successful result. */\nfunction ok<T>(value: T): ConnectionRpcResult<T> {\n return { ok: true, value }\n}\n\n/** A failed result carrying the stable code. */\nfunction fail(code: string, message: string, details: Record<string, unknown> = {}): ConnectionRpcResult<never> {\n return { ok: false, error: { code, message, details } }\n}\n\n/**\n * Dispatch one decoded verb.\n * @param toggle - the host face.\n * @param endpoint - the verb.\n * @param payload - its decoded payload.\n * @param signal - request cancellation.\n * @returns the wire result.\n */\nexport async function dispatch(\n toggle: WorktreeToggle,\n endpoint: Endpoint,\n payload: Record<string, unknown>,\n signal: AbortSignal,\n): Promise<ConnectionRpcResult<StatusValue | PrepareValue | ReleaseValue | ListValue | DiscardValue>> {\n try {\n if (endpoint === 'status') {\n const sessionId = requiredString(payload, 'sessionId')\n if ('failure' in sessionId) throw sessionId.failure\n return ok(await toggle.status({ sessionId: sessionId.value }, signal))\n }\n if (endpoint === 'prepare') {\n const sessionId = requiredString(payload, 'sessionId')\n if ('failure' in sessionId) throw sessionId.failure\n return ok(await toggle.prepare({ sessionId: sessionId.value }, signal))\n }\n if (endpoint === 'release') {\n const sessionId = requiredString(payload, 'sessionId')\n if ('failure' in sessionId) throw sessionId.failure\n return ok(await toggle.release({ sessionId: sessionId.value }, signal))\n }\n if (endpoint === 'list') {\n const path = requiredString(payload, 'path')\n if ('failure' in path) throw path.failure\n return ok(await toggle.list({ path: path.value }, signal))\n }\n const path = requiredString(payload, 'path')\n if ('failure' in path) throw path.failure\n const name = requiredString(payload, 'name')\n if ('failure' in name) throw name.failure\n return ok(await toggle.discard({ path: path.value, name: name.value }, signal))\n } catch (error) {\n if (error instanceof WorktreeToggleError) return fail(error.code, error.message, { ...error.details })\n return fail('internal', error instanceof Error ? error.message : String(error))\n }\n}\n\n/**\n * Register one exact route per verb on the shared `/api` channel.\n * @param ctx - Host context carrying `connection`.\n * @param toggle - the host face the routes call.\n */\nexport function registerWorktreeRoutes(ctx: Context, toggle: WorktreeToggle): void {\n for (const endpoint of ENDPOINTS) {\n ctx.effect(() => ctx.connection.fetch.register({\n path: `${API_PREFIX}/${endpoint}`,\n methods: ['POST'],\n requestBody: 'buffered',\n async fetch(request) {\n const contentType = request.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase()\n if (contentType !== 'application/json') {\n return new Response('content type must be application/json', { status: 415 })\n }\n let body: unknown\n try {\n body = await request.json()\n } catch {\n return new Response('body is not JSON', { status: 400 })\n }\n const message = readClientRequest(body)\n if (message === null) return new Response('invalid client-request message', { status: 400 })\n if (message.method !== `${PLUGIN_ID}/${endpoint}`) {\n return Response.json({\n type: 'server-response',\n rpcId: message.rpcId,\n result: fail('bad-request', 'RPC method does not match endpoint'),\n })\n }\n const result = await dispatch(toggle, endpoint, message.payload, request.signal)\n return Response.json({ type: 'server-response', rpcId: message.rpcId, result })\n },\n }), `${PLUGIN_ID} ${endpoint} route`)\n }\n}\n","/**\n * The copy a session is confirmed to run in, plus the one line the model reads\n * about it.\n *\n * The working-directory service already tells the model *where* it is. This\n * module answers the question that line does not: which checkout is the\n * session's workspace and which one is merely the project it was copied from.\n * The registry is fed by three sources — the switch verbs, `agent/created`\n * (resume), and `working-directory/change` (any `cd`) — so the line is never\n * stale, and it drops out entirely once the session leaves the copy.\n * @module dsh-worktree-switch/host/scope\n */\n\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-system-prompt'\nimport type { SessionScope } from '../types.ts'\nimport { contains } from './paths.ts'\n\n/** Sessions whose confirmed copy the prompt context reads. */\nexport class SessionScopeRegistry {\n private readonly scopes = new Map<string, SessionScope>()\n\n /**\n * Read one session's confirmed scope, without any filesystem work.\n * @param sessionId - wire session identity.\n * @returns the known copy, or null.\n */\n get(sessionId: string): SessionScope | null {\n return this.scopes.get(sessionId) ?? null\n }\n\n /**\n * Record that a session now runs in a copy.\n * @param sessionId - wire session identity.\n * @param scope - the confirmed copy and its project root.\n */\n remember(sessionId: string, scope: SessionScope): void {\n this.scopes.set(sessionId, scope)\n }\n\n /**\n * Drop a session's scope; a session with no entry gets no hint.\n * @param sessionId - wire session identity.\n */\n forget(sessionId: string): void {\n this.scopes.delete(sessionId)\n }\n\n /** Drop every entry; the plugin dropping its context drops its hints with it. */\n clear(): void {\n this.scopes.clear()\n }\n}\n\n/**\n * The model-facing line describing a worktree session's workspace.\n * @param scope - the session's confirmed copy.\n * @returns one sentence pair, JSON-quoted so paths survive the prompt.\n */\nexport function scopeHint(scope: SessionScope): string {\n return `This session is a linked Git worktree checkout at ${JSON.stringify(scope.worktree.path)} of the project ${JSON.stringify(scope.repositoryRoot)}. Run Git commands and file edits from the current working directory; the project checkout is the source, not this session's workspace.`\n}\n\n/** What the installer needs from the host half that owns Git. */\nexport interface WorktreeScopeWiring {\n /** Shared registry the prompt context reads. */\n readonly registry: SessionScopeRegistry\n /**\n * Re-derive one session's copy from its committed directory.\n * @param agent - live session owner.\n * @param signal - cancellation.\n * @returns the confirmed copy, or null when the session is not in one.\n */\n detect(agent: Agent, signal?: AbortSignal): Promise<SessionScope | null>\n}\n\n/**\n * Register the worktree scope as dynamic prompt context and keep it fresh.\n *\n * The context is `required`, so it survives compositions that suppress\n * optional runtime context, and it renders from the registry synchronously —\n * the expensive Git detection happens on session creation and directory\n * changes, never at request time.\n * @param ctx - host context carrying `systemPrompt`, `agents`, and `workingDirectory`.\n * @param wiring - registry plus the Git-backed detector.\n */\nexport function installWorktreeScope(ctx: Context, wiring: WorktreeScopeWiring): void {\n const { registry, detect } = wiring\n\n ctx.inject(['systemPrompt'], (scoped: Context) => {\n scoped.systemPrompt.context({\n name: 'worktree-switch:scope',\n order: scoped.systemPrompt.getContextOrder('WORKING_DIRECTORY') + 5,\n interpolate: false,\n required: true,\n text: (assembly) => {\n const agent = assembly.agent\n if (agent === undefined) return ''\n const sessionId = String(agent.session.id)\n const current = ctx.workingDirectory.get(agent.session)\n const scope = registry.get(sessionId)\n if (scope !== null && contains(scope.worktree.path, current)) return scopeHint(scope)\n // The committed directory is the authority: a session that left the\n // copy must not keep the line.\n if (scope !== null) registry.forget(sessionId)\n const anchor = agent.session.header.cwd ?? current\n // A session still at its creation directory is in no copy; only a\n // directory change inside the project is worth a Git look, and only\n // once per distinct directory value.\n if (current === anchor || !contains(anchor, current)) return ''\n if (lastChecked.get(sessionId) === current) return ''\n void refresh(agent, current)\n return ''\n },\n })\n })\n\n const inFlight = new Set<string>()\n /** The directory value each session was last inspected at, hit or miss. */\n const lastChecked = new Map<string, string>()\n\n /** Re-derive one live agent's scope, remembering or forgetting it. */\n const refresh = async (agent: Agent, current: string = ctx.workingDirectory.get(agent.session)): Promise<void> => {\n const sessionId = String(agent.session.id)\n const anchor = agent.session.header.cwd ?? current\n // Cheap reject before any Git work: a copy is always inside the project,\n // and a session still at its creation directory is in no copy.\n if (current === anchor || !contains(anchor, current)) {\n registry.forget(sessionId)\n return\n }\n if (inFlight.has(sessionId)) return\n inFlight.add(sessionId)\n lastChecked.set(sessionId, current)\n try {\n const found = await detect(agent)\n if (found === null) registry.forget(sessionId)\n else registry.remember(sessionId, found)\n } catch {\n registry.forget(sessionId)\n } finally {\n inFlight.delete(sessionId)\n }\n }\n\n // A resumed session enters no verb, so creation is where it is recognised; an\n // ordinary new session sits at its creation directory and stops at the cheap\n // check. The hook is serial, so the first request already sees the line.\n ctx.on('agent/created', async ({ agent }) => {\n await refresh(agent)\n return undefined\n })\n}\n\n","/**\n * Host half of the Worktree switch.\n *\n * It mounts no service itself: the bundle patch inserts the harness worktree\n * service (`@deepseek-ai/dsh-experimental-worktree`, which provides\n * `ctx.worktrees`) and this plugin's own row. This plugin exposes five verbs\n * over the Connection fetch bridge and drives that service for creation; it\n * also contributes one model-facing context line while a session runs in a\n * copy, and the browser half renders the switch and the panel.\n * @module dsh-worktree-switch\n */\n\nimport type { Context } from '@deepseek-ai/cordis'\nimport Schema from '@deepseek-ai/schemastery'\nimport type {} from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-experimental-worktree'\nimport type {} from '@deepseek-ai/dsh-subprocess'\nimport type {} from '@deepseek-ai/dsh-working-directory'\nimport { installSourceCheckoutGuard } from './host/guard.ts'\nimport { createWorktreeToggle, detectSessionScope } from './host/handlers.ts'\nimport { registerWorktreeRoutes } from './host/routes.ts'\nimport { installWorktreeScope, SessionScopeRegistry } from './host/scope.ts'\n\n/** Plugin id: package name, bundle row id, browser module id. */\nexport const name = 'dsh-worktree-switch'\n\n/**\n * Services this plugin cannot work without.\n *\n * `worktrees` is provided by the row this bundle's patch inserts next to its\n * own, so Cordis holds this plugin until that row has mounted.\n */\nexport const inject = ['agents', 'connection', 'subprocess', 'worktrees', 'workingDirectory']\n\n/** Row config accepted from `cordis.patch.yml`. */\nexport interface Config {\n /** Default for a project the user has never switched either way. */\n defaultEnabled: boolean\n /** Refuse shell commands that run Git against the project checkout while the session is in a copy. */\n guardSourceCheckout: boolean\n}\n\n/** Schemastery schema for {@link Config}. */\nexport const Config: Schema<Config> = Schema.object({\n defaultEnabled: Schema.boolean()\n .default(true)\n .description('Start a new session in a worktree copy until the user turns the switch off for that project.'),\n guardSourceCheckout: Schema.boolean()\n .default(true)\n .description('While a session is in a copy, deny shell commands that run Git against the project checkout.'),\n})\n\n/**\n * Mount the host half.\n * @param ctx - Host context.\n * @param config - validated row config.\n */\nexport function apply(ctx: Context, config: Config): void {\n const scopes = new SessionScopeRegistry()\n const toggle = createWorktreeToggle(ctx, {\n defaultEnabled: config.defaultEnabled,\n onScope: (sessionId, scope) => {\n if (scope === null) scopes.forget(sessionId)\n else scopes.remember(sessionId, scope)\n },\n })\n installWorktreeScope(ctx, {\n registry: scopes,\n detect: (agent, signal) => detectSessionScope(ctx, agent, signal),\n })\n if (config.guardSourceCheckout) installSourceCheckoutGuard(ctx, scopes)\n registerWorktreeRoutes(ctx, toggle)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,SAAS,WAAmB,MAAuB;CACjE,MAAM,SAAS,SAAS,WAAW,IAAI;CACvC,OAAO,WAAW,MAAO,CAAC,OAAO,WAAW,IAAI,KAAK,CAAC,WAAW,MAAM;AACzE;;;;;;;;;;;;;;;;;;;;;ACUA,MAAM,8BAAc,IAAI,IAAI,CAAC,MAAM,CAAC;;;;;;AAepC,SAAS,eAAe,MAA4C;CAClE,IAAI,CAAC,YAAY,IAAI,KAAK,IAAI,GAAG,OAAO;CACxC,IAAI,KAAK,cAAc,QAAQ,OAAO,KAAK,cAAc,UAAU,OAAO;CAC1E,MAAM,OAAO,KAAK;CAClB,MAAM,UAAU,KAAK;CACrB,IAAI,OAAO,YAAY,YAAY,QAAQ,KAAK,MAAM,IAAI,OAAO;CACjE,MAAM,UAAU,KAAK;CACrB,MAAM,WAAW,OAAO,YAAY,YAAY,QAAQ,KAAK,MAAM,KAAK,UAAU,KAAA;CAClF,OAAO,aAAa,KAAA,IAAY,EAAE,QAAQ,IAAI;EAAE;EAAS,SAAS;CAAS;AAC7E;;;;;;;;;AAUA,SAAgB,qBACd,SACA,SACA,KACA,OACe;CAGf,IAAI,CAAC,UAAU,KAAK,OAAO,GAAG,OAAO;CACrC,MAAM,WAAW,MAAM,SAAS;CAChC,MAAM,UAAU,MAAM;CACtB,IAAI,YAAY,KAAA,GAAW;EACzB,MAAM,SAAS,WAAW,OAAO,IAAI,UAAU,QAAQ,KAAK,OAAO;EACnE,IAAI,SAAS,SAAS,MAAM,KAAK,CAAC,SAAS,UAAU,MAAM,GAAG,OAAO,OAAO,KAAK;CACnF;CAGA,IAAI,QAAQ,MAAM,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,OA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C3B,UAAU;GACR,SAAS,OAAO,SAAS;EAC3B;CACF;CAKA,IAAI,GAAG,iBAAiB,OAAO,EAAE,YAAY;EAC3C,MAAM,QAAQ,KAAK;CAErB,CAAC;AACH;;;ACjIA,MAAa,OAAO;;;;;;;AAQpB,MAAa,SAAS;CAAC;CAAU;CAAc;CAAc;CAAa;AAAkB;;AAW5F,MAAa,SAAyB,OAAO,OAAO;CAClD,gBAAgB,OAAO,QAAQ,CAAC,CAC7B,QAAQ,IAAI,CAAC,CACb,YAAY,8FAA8F;CAC7G,qBAAqB,OAAO,QAAQ,CAAC,CAClC,QAAQ,IAAI,CAAC,CACb,YAAY,8FAA8F;AAC/G,CAAC;;;;;;AAOD,SAAgB,MAAM,KAAc,QAAsB;CACxD,MAAM,SAAS,IAAI,qBAAqB;CACxC,MAAM,SAAS,qBAAqB,KAAK;EACvC,gBAAgB,OAAO;EACvB,UAAU,WAAW,UAAU;GAC7B,IAAI,UAAU,MAAM,OAAO,OAAO,SAAS;QACtC,OAAO,SAAS,WAAW,KAAK;EACvC;CACF,CAAC;CACD,qBAAqB,KAAK;EACxB,UAAU;EACV,SAAS,OAAO,WAAW,mBAAmB,KAAK,OAAO,MAAM;CAClE,CAAC;CACD,IAAI,OAAO,qBAAqB,2BAA2B,KAAK,MAAM;CACtE,uBAAuB,KAAK,MAAM;AACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-worktree-switch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A New Session switch that puts the conversation into a throwaway Git worktree under the project's worktree pool (`<project>/.dsh/worktrees` by default), plus a panel to inspect and discard the copies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": "^22.19.0 || >=24.0.0",
|
|
37
|
-
"dsh": ">=0.2.
|
|
37
|
+
"dsh": ">=0.2.2-rc.1 <0.2.3-0"
|
|
38
38
|
},
|
|
39
39
|
"dsh": {
|
|
40
40
|
"manifestVersion": 1,
|
|
@@ -58,53 +58,55 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@deepseek-ai/cordis": "^4.0
|
|
62
|
-
"@deepseek-ai/dsh-api-session-controller": ">=0.2.
|
|
63
|
-
"@deepseek-ai/dsh-api-workspace-controller": ">=0.2.
|
|
64
|
-
"@deepseek-ai/dsh-client-connection": ">=0.2.
|
|
65
|
-
"@deepseek-ai/dsh-client-locale": ">=0.2.
|
|
66
|
-
"@deepseek-ai/dsh-client-store": ">=0.2.
|
|
67
|
-
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-layout": ">=0.2.
|
|
69
|
-
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.
|
|
70
|
-
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-session": ">=0.2.
|
|
72
|
-
"@deepseek-ai/dsh-client-ui-sidebar": ">=0.2.
|
|
73
|
-
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.
|
|
74
|
-
"@deepseek-ai/dsh-client-ui-workspace": ">=0.2.
|
|
75
|
-
"@deepseek-ai/dsh-experimental-worktree": ">=0.2.
|
|
76
|
-
"@deepseek-ai/
|
|
61
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
62
|
+
"@deepseek-ai/dsh-api-session-controller": ">=0.2.2-rc.1 <0.2.3-0",
|
|
63
|
+
"@deepseek-ai/dsh-api-workspace-controller": ">=0.2.2-rc.1 <0.2.3-0",
|
|
64
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.1 <0.2.3-0",
|
|
65
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-rc.1 <0.2.3-0",
|
|
66
|
+
"@deepseek-ai/dsh-client-store": ">=0.2.2-rc.1 <0.2.3-0",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.2-rc.1 <0.2.3-0",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-layout": ">=0.2.2-rc.1 <0.2.3-0",
|
|
69
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.1 <0.2.3-0",
|
|
70
|
+
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.2-rc.1 <0.2.3-0",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-session": ">=0.2.2-rc.1 <0.2.3-0",
|
|
72
|
+
"@deepseek-ai/dsh-client-ui-sidebar": ">=0.2.2-rc.1 <0.2.3-0",
|
|
73
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.2-rc.1 <0.2.3-0",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-workspace": ">=0.2.2-rc.1 <0.2.3-0",
|
|
75
|
+
"@deepseek-ai/dsh-experimental-worktree": ">=0.2.2-rc.1 <0.2.3-0",
|
|
76
|
+
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.2.3-0",
|
|
77
|
+
"@deepseek-ai/schemastery": "^3.19.0"
|
|
77
78
|
},
|
|
78
79
|
"devDependencies": {
|
|
79
|
-
"@deepseek-ai/cordis": "4.0
|
|
80
|
-
"@deepseek-ai/dsh-agent": "0.2.
|
|
81
|
-
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.
|
|
82
|
-
"@deepseek-ai/dsh-api-session-controller": "0.2.
|
|
83
|
-
"@deepseek-ai/dsh-api-workspace-controller": "0.2.
|
|
84
|
-
"@deepseek-ai/dsh-client-connection": "0.2.
|
|
85
|
-
"@deepseek-ai/dsh-client-locale": "0.2.
|
|
86
|
-
"@deepseek-ai/dsh-client-store": "0.2.
|
|
87
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.
|
|
88
|
-
"@deepseek-ai/dsh-client-ui-layout": "0.2.
|
|
89
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.2.
|
|
90
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.
|
|
91
|
-
"@deepseek-ai/dsh-client-ui-session": "0.2.
|
|
92
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.
|
|
93
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.
|
|
94
|
-
"@deepseek-ai/dsh-client-ui-workspace": "0.2.
|
|
95
|
-
"@deepseek-ai/dsh-experimental-worktree": "0.2.
|
|
96
|
-
"@deepseek-ai/dsh-fs": "0.2.
|
|
97
|
-
"@deepseek-ai/dsh-fs-local": "0.2.
|
|
98
|
-
"@deepseek-ai/dsh-sandbox": "0.2.
|
|
99
|
-
"@deepseek-ai/dsh-sandbox-local": "0.2.
|
|
100
|
-
"@deepseek-ai/dsh-sandbox-policy": "0.2.
|
|
101
|
-
"@deepseek-ai/dsh-session": "0.2.
|
|
102
|
-
"@deepseek-ai/dsh-session-projection": "0.2.
|
|
103
|
-
"@deepseek-ai/dsh-subprocess": "0.2.
|
|
104
|
-
"@deepseek-ai/dsh-subprocess-local": "0.2.
|
|
105
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.
|
|
106
|
-
"@deepseek-ai/dsh-
|
|
107
|
-
"@deepseek-ai/
|
|
80
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
81
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.1",
|
|
82
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.1",
|
|
83
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.1",
|
|
84
|
+
"@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.1",
|
|
87
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.1",
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.1",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.1",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.1",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.1",
|
|
92
|
+
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.1",
|
|
93
|
+
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.1",
|
|
94
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.1",
|
|
95
|
+
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.1",
|
|
96
|
+
"@deepseek-ai/dsh-experimental-worktree": "0.2.2-rc.1",
|
|
97
|
+
"@deepseek-ai/dsh-fs": "0.2.2-rc.1",
|
|
98
|
+
"@deepseek-ai/dsh-fs-local": "0.2.2-rc.1",
|
|
99
|
+
"@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
|
|
100
|
+
"@deepseek-ai/dsh-sandbox-local": "0.2.2-rc.1",
|
|
101
|
+
"@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.1",
|
|
102
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.1",
|
|
103
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
|
|
104
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.1",
|
|
105
|
+
"@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.1",
|
|
106
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
107
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
108
|
+
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.1",
|
|
109
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
108
110
|
"@testing-library/react": "^16.3.3",
|
|
109
111
|
"@types/node": "^26.6.6",
|
|
110
112
|
"@types/react": "~18.3.1",
|
|
@@ -118,18 +120,17 @@
|
|
|
118
120
|
"vitest": "^5.0.5",
|
|
119
121
|
"zustand": "~4.5.7"
|
|
120
122
|
},
|
|
121
|
-
"scripts": {
|
|
122
|
-
"build": "tsdown",
|
|
123
|
-
"watch": "tsdown --watch",
|
|
124
|
-
"typecheck": "tsc --noEmit",
|
|
125
|
-
"test": "vitest run",
|
|
126
|
-
"prepare": "tsdown"
|
|
127
|
-
},
|
|
128
123
|
"author": "mxn404",
|
|
129
124
|
"homepage": "https://github.com/mxn404/deepseek-plugins/tree/main/packages/dsh-worktree-switch",
|
|
130
125
|
"repository": {
|
|
131
126
|
"type": "git",
|
|
132
127
|
"url": "git+https://github.com/mxn404/deepseek-plugins.git",
|
|
133
128
|
"directory": "packages/dsh-worktree-switch"
|
|
129
|
+
},
|
|
130
|
+
"scripts": {
|
|
131
|
+
"build": "tsdown",
|
|
132
|
+
"watch": "tsdown --watch",
|
|
133
|
+
"typecheck": "tsc --noEmit",
|
|
134
|
+
"test": "vitest run"
|
|
134
135
|
}
|
|
135
|
-
}
|
|
136
|
+
}
|