diff --git a/docs/config-catalog.md b/docs/config-catalog.md index 7a775425b4..d4ad8d2dbc 100644 --- a/docs/config-catalog.md +++ b/docs/config-catalog.md @@ -1507,7 +1507,7 @@ export type PaidTranslationProvider = 'deepseek-account' | 'deepseek-official' ## `@deepseek-ai/dsh-experimental-worktree` - `inject`: `workingDirectory` · `fs` · `subprocess` · `sandbox` · `sandboxPolicy` -- `source`: [`packages/experimental/worktree/src/index.ts:21`](../packages/experimental/worktree/src/index.ts) +- `source`: [`packages/experimental/worktree/src/index.ts:24`](../packages/experimental/worktree/src/index.ts) ```ts config-catalog /** Worktree location, generated names, executables, and subprocess resource limits. */ @@ -4842,7 +4842,7 @@ export interface Config { ## `@deepseek-ai/dsh-working-directory` - `inject`: `fs` · `sessionProjections` · `systemPrompt` -- `source`: [`packages/session/working-directory/src/index.ts:58`](../packages/session/working-directory/src/index.ts) +- `source`: [`packages/session/working-directory/src/index.ts:59`](../packages/session/working-directory/src/index.ts) ```ts config-catalog /** Deployment default for Sessions without an original project directory. */ diff --git a/docs/config-catalog.zh.md b/docs/config-catalog.zh.md index f55feb6b61..bf0bdb7868 100644 --- a/docs/config-catalog.zh.md +++ b/docs/config-catalog.zh.md @@ -1509,7 +1509,7 @@ export type PaidTranslationProvider = 'deepseek-account' | 'deepseek-official' ## `@deepseek-ai/dsh-experimental-worktree` - `inject`: `workingDirectory` · `fs` · `subprocess` · `sandbox` · `sandboxPolicy` -- `source`: [`packages/experimental/worktree/src/index.ts:21`](../packages/experimental/worktree/src/index.ts) +- `source`: [`packages/experimental/worktree/src/index.ts:24`](../packages/experimental/worktree/src/index.ts) ```ts config-catalog /** Worktree location, generated names, executables, and subprocess resource limits. */ @@ -4844,7 +4844,7 @@ export interface Config { ## `@deepseek-ai/dsh-working-directory` - `inject`: `fs` · `sessionProjections` · `systemPrompt` -- `source`: [`packages/session/working-directory/src/index.ts:58`](../packages/session/working-directory/src/index.ts) +- `source`: [`packages/session/working-directory/src/index.ts:59`](../packages/session/working-directory/src/index.ts) ```ts config-catalog /** Deployment default for Sessions without an original project directory. */ diff --git a/docs/persistence-catalog.i18n.yaml b/docs/persistence-catalog.i18n.yaml index 1d71215aa6..015797cd4d 100644 --- a/docs/persistence-catalog.i18n.yaml +++ b/docs/persistence-catalog.i18n.yaml @@ -300,8 +300,8 @@ en: e8dd0cebbb930eb7 zh: e8dd0cebbb930eb7 /session-persistence-event-catalog/events/working-directory/working-directory-change-log-only: - en: 075369b880bd304b - zh: 0eca94dbaf5d9090 + en: bdfcb912ecdcf00d + zh: 525303d732b7a59b /session-persistence-event-catalog/events/workspace: en: 63ee1a85e4b59ae3 zh: 63ee1a85e4b59ae3 @@ -1428,8 +1428,8 @@ en: 874fb1c541bbca1d zh: 1aa7e89654cd041a /session-persistence-event-catalog/resolved-persistence-types/anchor-cwd: - en: 4c7cc91c89725a3f - zh: 5c91de8c4713cc89 + en: 0575d5a02ed571b4 + zh: 35408927e76e368a /session-persistence-event-catalog/resolved-persistence-types/args-commandid-name-source: en: a117573a5d58cb3c zh: d5ad59e17a3a815d @@ -1914,8 +1914,8 @@ en: 0b74295f7c5c8f11 zh: 5f1213cec87f6be0 /session-persistence-event-catalog/resolved-persistence-types/kind-working-directory: - en: 1a6c0842d549a5f9 - zh: cde31cc53cbcab66 + en: 71df7e1042865e6e + zh: a6ff4987ada523be /session-persistence-event-catalog/resolved-persistence-types/max-tokens-messages-model-thinking: en: 3216b23c131d0070 zh: 73ca171c6014f16e diff --git a/docs/persistence-catalog.md b/docs/persistence-catalog.md index 05fc1899e8..2f46d03fe8 100644 --- a/docs/persistence-catalog.md +++ b/docs/persistence-catalog.md @@ -1334,7 +1334,7 @@ Source: [`packages/web/web-search-deepseek/src/provider.ts:89`](../packages/web/ } ``` -Source: [`packages/session/working-directory/src/index.ts:36`](../packages/session/working-directory/src/index.ts) +Source: [`packages/session/working-directory/src/index.ts:37`](../packages/session/working-directory/src/index.ts) ### `workspace/*` @@ -5891,7 +5891,7 @@ Sources: [`packages/subagent/tool-subagent/src/model-selection-state.ts:17`](../ SHA-256: `40a4c38943f2e5ee0eaa0ea48238ec425e7900022a4b08e57c8335f0fd6eb435` -Sources: [`packages/session/working-directory/src/index.ts:36`](../packages/session/working-directory/src/index.ts) +Sources: [`packages/session/working-directory/src/index.ts:37`](../packages/session/working-directory/src/index.ts) | Property | Presence | Type | |---|---|---| @@ -7890,7 +7890,7 @@ Sources: [`packages/experimental/webhook/src/types.ts:74`](../packages/experimen SHA-256: `2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5` -Sources: [`packages/session/working-directory/src/index.ts:29`](../packages/session/working-directory/src/index.ts) +Sources: [`packages/session/working-directory/src/index.ts:30`](../packages/session/working-directory/src/index.ts) | Property | Presence | Type | |---|---|---| diff --git a/docs/persistence-catalog.zh.md b/docs/persistence-catalog.zh.md index 32f090b1e5..4d2c1176d5 100644 --- a/docs/persistence-catalog.zh.md +++ b/docs/persistence-catalog.zh.md @@ -1336,7 +1336,7 @@ export type SessionEvent = { } ``` -来源:[`packages/session/working-directory/src/index.ts:36`](../packages/session/working-directory/src/index.ts) +来源:[`packages/session/working-directory/src/index.ts:37`](../packages/session/working-directory/src/index.ts) ### `workspace/*` @@ -5893,7 +5893,7 @@ SHA-256: `0d47a8f3d847243c4488e755ad4cab7a04ac5d4621b9c81865524cf3f4d8536f` SHA-256: `40a4c38943f2e5ee0eaa0ea48238ec425e7900022a4b08e57c8335f0fd6eb435` -来源:[`packages/session/working-directory/src/index.ts:36`](../packages/session/working-directory/src/index.ts) +来源:[`packages/session/working-directory/src/index.ts:37`](../packages/session/working-directory/src/index.ts) | 属性 | 存在性 | 类型 | |---|---|---| @@ -7892,7 +7892,7 @@ SHA-256: `9edc162949abf93bd5ff049191b345454ba104f583937ce5580fb50f067d2b94` SHA-256: `2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5` -来源:[`packages/session/working-directory/src/index.ts:29`](../packages/session/working-directory/src/index.ts) +来源:[`packages/session/working-directory/src/index.ts:30`](../packages/session/working-directory/src/index.ts) | 属性 | 存在性 | 类型 | |---|---|---| diff --git a/docs/persistence-schema.json b/docs/persistence-schema.json index f133ad7cea..68fdfc20a6 100644 --- a/docs/persistence-schema.json +++ b/docs/persistence-schema.json @@ -156,7 +156,7 @@ {"digest":"2142e391b9ccb60d487afcf373ce74db98d952f69e8289eddb352a7e16e996c5","names":[],"sources":[]}, {"digest":"2152caf1a71e588e4df2358a806dea24936c1c47131134f01a12939d12cdc0c0","names":["packages/team/agent-team/src/types.ts#TeamMessageSource"],"sources":["packages/team/agent-team/src/types.ts:117"]}, {"digest":"21fb6a90d5068f6a0003b7ab316ed2f56342477146a65c00db0f13c4d8df667d","names":[],"sources":[]}, - {"digest":"2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5","names":[],"sources":["packages/session/working-directory/src/index.ts:29"]}, + {"digest":"2235d957bf4b7c6cf959231d480f0ba1f3a6d72d82981493fb6c7c963021d3d5","names":[],"sources":["packages/session/working-directory/src/index.ts:30"]}, {"digest":"224aa11d4d5f88c450822d01b99e6ca5e3a9c7f26a5ede10bae33384a09ef4dc","names":[],"sources":[]}, {"digest":"234142ee4f996f38cc9fa3b8b3e3de29b03c9aefe5ebf6c224eddd564505aa85","names":[],"sources":[]}, {"digest":"237c004c73b6b288246816e0d7fde16e09c63a47aa3b1227383d7afe58666163","names":[],"sources":[]}, @@ -228,7 +228,7 @@ {"digest":"3f74ba74acd10644c1ed6947a411d8088bd2cfac74f61bb8540f96d68e31f004","names":[],"sources":[]}, {"digest":"3fdf9582c3b5597df104d32d97dab6c6ee3a93794f3034ec6ada6272404ea27f","names":["packages/schedule/schedule/src/types.ts#LegacyAfterScheduleRecord"],"sources":["packages/schedule/schedule/src/types.ts:161"]}, {"digest":"408927267422a7b2beb6df354ff7c1406d929a5646554f48adf85eb8372f811c","names":[],"sources":[]}, - {"digest":"40a4c38943f2e5ee0eaa0ea48238ec425e7900022a4b08e57c8335f0fd6eb435","names":[],"sources":["packages/session/working-directory/src/index.ts:36"]}, + {"digest":"40a4c38943f2e5ee0eaa0ea48238ec425e7900022a4b08e57c8335f0fd6eb435","names":[],"sources":["packages/session/working-directory/src/index.ts:37"]}, {"digest":"4208123b50df5006b181481ab45fcf1cde807b88d3fd4d340090bc2e202fac41","names":[],"sources":[]}, {"digest":"42e0916e0dda5f6d1e7bb05d8514717147c036a79c9f36085683469516c1fd3f","names":[],"sources":[]}, {"digest":"4312134fc6f9cad507c31390bd3d147535492dd77621ec517c5e85f853d53a03","names":[],"sources":[]}, diff --git a/packages/experimental/client-ui-forge/package.json b/packages/experimental/client-ui-forge/package.json index 79828c9006..20708bdc79 100644 --- a/packages/experimental/client-ui-forge/package.json +++ b/packages/experimental/client-ui-forge/package.json @@ -64,12 +64,13 @@ "@deepseek-ai/dsh-fs": "workspace:*" }, "dependencies": { - "@deepseek-ai/schemastery": "workspace:~", - "@deepseek-ai/dsh-util-values": "workspace:*", - "diff": "^9.0.0", - "zod": "^4.4.3", + "@deepseek-ai/dsh-storage-domain": "workspace:*", "@deepseek-ai/dsh-typert-protocol": "workspace:*", - "@deepseek-ai/dsh-storage-domain": "workspace:*" + "@deepseek-ai/dsh-util-values": "workspace:*", + "@deepseek-ai/dsh-util-workspace-path": "workspace:*", + "@deepseek-ai/schemastery": "workspace:~", + "diff": "^9.0.0", + "zod": "^4.4.3" }, "devDependencies": { "@deepseek-ai/cordis": "workspace:~", @@ -102,7 +103,6 @@ "@deepseek-ai/dsh-subprocess": "workspace:*", "@deepseek-ai/dsh-subprocess-local": "workspace:*", "@deepseek-ai/dsh-system-prompt": "workspace:*", - "@deepseek-ai/dsh-util-workspace-path": "workspace:*", "@deepseek-ai/dsh-working-directory": "workspace:*", "@testing-library/react": "^16.3.3", "clsx": "^2.1.1", diff --git a/packages/experimental/client-ui-forge/src/index.ts b/packages/experimental/client-ui-forge/src/index.ts index 80d3d5f915..f347640ed9 100644 --- a/packages/experimental/client-ui-forge/src/index.ts +++ b/packages/experimental/client-ui-forge/src/index.ts @@ -27,7 +27,8 @@ import type { Config, ForgeBranches, ForgeChangeRequestDiff, ForgeChangeRequestStatesFrame, ForgeLocalDiff, ForgeLocalScope, ForgeMissingWorktree, ForgePanelState, ForgeSessionWorktree, ForgeWorktreeState, } from './types.ts' -import { within } from '@deepseek-ai/dsh-working-directory' +import { within } from '@deepseek-ai/dsh-util-workspace-path' +import type {} from '@deepseek-ai/dsh-working-directory' import { forgeWorktreeProjection, messageOf, WORKTREE_RECORD, WorktreeCreations } from './worktree.ts' import type { HeldWork } from './worktree.ts' diff --git a/packages/experimental/client-ui-forge/src/panel.ts b/packages/experimental/client-ui-forge/src/panel.ts index ec64d82ce5..ab9d3b95fd 100644 --- a/packages/experimental/client-ui-forge/src/panel.ts +++ b/packages/experimental/client-ui-forge/src/panel.ts @@ -18,7 +18,7 @@ import type { ForgeCheckoutState, ForgeLocalChanges, ForgeMissingWorktree, ForgePanelChangeRequest, ForgePanelState, ForgePanelWorktree, ForgeWorktreeBlocker, ForgeWorktreeState, } from './types.ts' -import { within } from '@deepseek-ai/dsh-working-directory' +import { within } from '@deepseek-ai/dsh-util-workspace-path' import { WORKTREE_RECORD } from './worktree.ts' import type { WorktreeCreations } from './worktree.ts' diff --git a/packages/experimental/client-ui-forge/src/worktree.ts b/packages/experimental/client-ui-forge/src/worktree.ts index a7a4a638c5..2ec5500a3a 100644 --- a/packages/experimental/client-ui-forge/src/worktree.ts +++ b/packages/experimental/client-ui-forge/src/worktree.ts @@ -8,7 +8,7 @@ import { appendPluginRecord, pluginRecordOf } from '@deepseek-ai/dsh-session' import type { Session, SessionEvent } from '@deepseek-ai/dsh-session' import type { ProjectionDefinition, ProjectionHandle } from '@deepseek-ai/dsh-session-projection' import { assertNever } from '@deepseek-ai/dsh-util-values' -import { within } from '@deepseek-ai/dsh-working-directory' +import { within } from '@deepseek-ai/dsh-util-workspace-path' import { z } from 'zod' import type { ForgeMissingWorktree, ForgeSessionWorktree, ForgeWorktreeCreation, ForgeWorktreeFailure, ForgeWorktreeRestoration, ForgeWorktreeState, diff --git a/packages/experimental/client-ui-forge/tsconfig.host.json b/packages/experimental/client-ui-forge/tsconfig.host.json index 13474f6353..fed6f213a5 100644 --- a/packages/experimental/client-ui-forge/tsconfig.host.json +++ b/packages/experimental/client-ui-forge/tsconfig.host.json @@ -75,6 +75,9 @@ { "path": "../forge-session" }, + { + "path": "../../util/workspace-path" + }, { "path": "../worktree" } diff --git a/packages/session/working-directory/package.json b/packages/session/working-directory/package.json index 295968e6ee..408790d2a9 100644 --- a/packages/session/working-directory/package.json +++ b/packages/session/working-directory/package.json @@ -54,6 +54,7 @@ "@deepseek-ai/dsh-tools": "workspace:*" }, "dependencies": { + "@deepseek-ai/dsh-util-workspace-path": "workspace:*", "@deepseek-ai/schemastery": "workspace:~", "zod": "^4.4.3" } diff --git a/packages/session/working-directory/src/index.ts b/packages/session/working-directory/src/index.ts index 16531daee5..9023a7dc0f 100644 --- a/packages/session/working-directory/src/index.ts +++ b/packages/session/working-directory/src/index.ts @@ -3,7 +3,7 @@ * @module @deepseek-ai/dsh-working-directory */ -import { isAbsolute, relative, sep } from 'node:path' +import { isAbsolute } from 'node:path' import { Context, Service } from '@deepseek-ai/cordis' import z from '@deepseek-ai/schemastery' import { z as zod } from 'zod' @@ -13,6 +13,7 @@ import { createUserMessage } from '@deepseek-ai/dsh-llm' import type { Session } from '@deepseek-ai/dsh-session' import type { ProjectionHandle } from '@deepseek-ai/dsh-session-projection' import type {} from '@deepseek-ai/dsh-system-prompt' +import { within } from '@deepseek-ai/dsh-util-workspace-path' declare module '@deepseek-ai/cordis' { interface Context { @@ -88,18 +89,6 @@ interface WorkspaceRootState { anchors: string[] } -/** - * Whether `path` is `root` or lies below it. Both paths are canonical absolute - * paths of one execution world; the test is lexical and never touches the filesystem. - * @param root - canonical absolute directory. - * @param path - canonical absolute path to test. - * @returns true for `root` itself and every path below it. - */ -export function within(root: string, path: string): boolean { - const rest = relative(root, path) - return rest === '' || (rest !== '..' && !rest.startsWith(`..${sep}`) && !isAbsolute(rest)) -} - /** The longest anchor containing `path`, or undefined when none does. */ function anchorContaining(anchors: readonly string[], path: string): string | undefined { let selected: string | undefined diff --git a/packages/session/working-directory/tests/workspace-root.spec.ts b/packages/session/working-directory/tests/workspace-root.spec.ts index bde3b6f912..cf602e3f9e 100644 --- a/packages/session/working-directory/tests/workspace-root.spec.ts +++ b/packages/session/working-directory/tests/workspace-root.spec.ts @@ -5,7 +5,7 @@ import { join } from 'node:path' import { Context } from '@deepseek-ai/cordis' import { describe, expect, it } from 'vitest' import LocalFileSystem from '@deepseek-ai/dsh-fs-local' -import WorkingDirectory, { within } from '@deepseek-ai/dsh-working-directory' +import WorkingDirectory from '@deepseek-ai/dsh-working-directory' import { mountAgentLoopTestDependencies, mountAgentLoopTestHarness } from '@deepseek-ai/dsh-agent-loop-testkit' import { SessionId } from '@deepseek-ai/dsh-session' import { renderContextSnapshot } from '@deepseek-ai/dsh-system-prompt' @@ -190,12 +190,4 @@ describe('Session workspace roots', () => { expect(f.ctx.workingDirectory.rootOf(agent.session)).toBe(f.worktree) expect(f.ctx.workingDirectory.anchorsOf(agent.session)).toEqual([f.worktree]) }) - - it('tests containment lexically on canonical absolute paths', () => { - expect(within('/repo', '/repo')).toBe(true) - expect(within('/repo', '/repo/src')).toBe(true) - expect(within('/repo', '/repo-sibling')).toBe(false) - expect(within('/repo', '/')).toBe(false) - expect(within('/repo/src', '/repo')).toBe(false) - }) }) diff --git a/packages/session/working-directory/tsconfig.json b/packages/session/working-directory/tsconfig.json index 6d24c1126a..556e157fa6 100644 --- a/packages/session/working-directory/tsconfig.json +++ b/packages/session/working-directory/tsconfig.json @@ -29,6 +29,9 @@ { "path": "../../core/system-prompt" }, + { + "path": "../../util/workspace-path" + }, { "path": "../../../vendor/schemastery" } diff --git a/packages/subagent/subagent/package.json b/packages/subagent/subagent/package.json index be7a0f59ca..22b377f47e 100644 --- a/packages/subagent/subagent/package.json +++ b/packages/subagent/subagent/package.json @@ -49,6 +49,7 @@ "@deepseek-ai/dsh-brand": "workspace:*", "@deepseek-ai/dsh-chunked-list": "workspace:*", "@deepseek-ai/dsh-util-values": "workspace:*", + "@deepseek-ai/dsh-util-workspace-path": "workspace:*", "@deepseek-ai/schemastery": "workspace:~", "zod": "4.4.3" }, diff --git a/packages/subagent/subagent/src/manager.ts b/packages/subagent/subagent/src/manager.ts index fc7d3d63ba..2b2a5f3af5 100644 --- a/packages/subagent/subagent/src/manager.ts +++ b/packages/subagent/subagent/src/manager.ts @@ -9,7 +9,7 @@ import { randomUUID } from 'node:crypto' import { isAbsolute, resolve } from 'node:path' import type {} from '@deepseek-ai/dsh-fs' -import { within } from '@deepseek-ai/dsh-working-directory' +import { within } from '@deepseek-ai/dsh-util-workspace-path' import type { Context } from '@deepseek-ai/cordis' import type { Agent, AgentOptions, CreateAgentOptions } from '@deepseek-ai/dsh-agent' import { brandString } from '@deepseek-ai/dsh-brand' diff --git a/packages/subagent/subagent/tests/working-directory-fixture.ts b/packages/subagent/subagent/tests/working-directory-fixture.ts index 91536aed44..3d643fea4c 100644 --- a/packages/subagent/subagent/tests/working-directory-fixture.ts +++ b/packages/subagent/subagent/tests/working-directory-fixture.ts @@ -2,7 +2,7 @@ import { Context, Service } from '@deepseek-ai/cordis' import { resolve } from 'node:path' import type { Agent } from '@deepseek-ai/dsh-agent' import type { Session } from '@deepseek-ai/dsh-session' -import { within } from '@deepseek-ai/dsh-working-directory' +import { within } from '@deepseek-ai/dsh-util-workspace-path' import type { RelocateOptions, RelocatedDirectories } from '@deepseek-ai/dsh-working-directory' /** Directory selection for orchestration fixtures whose paths are symbolic and whose logs exclude context providers. */ diff --git a/packages/subagent/subagent/tsconfig.json b/packages/subagent/subagent/tsconfig.json index aacaa3a1e4..fdd232c349 100644 --- a/packages/subagent/subagent/tsconfig.json +++ b/packages/subagent/subagent/tsconfig.json @@ -74,6 +74,9 @@ { "path": "../../fs/fs" }, + { + "path": "../../util/workspace-path" + }, { "path": "../../session/working-directory" } diff --git a/packages/util/workspace-path/README.i18n.yaml b/packages/util/workspace-path/README.i18n.yaml index 4a509fafe9..3967dac186 100644 --- a/packages/util/workspace-path/README.i18n.yaml +++ b/packages/util/workspace-path/README.i18n.yaml @@ -9,8 +9,8 @@ en: 328c592b68c88e44 zh: 7a2f03def21b86fe /dsh-util-workspace-path/summary: - en: ffdecddc9c4957ad - zh: 33cf84892aa5e669 + en: b8f56e9975dc450a + zh: 9275a864664230ca /dsh-util-workspace-path/table-of-contents: en: e8236aa6cbcb7dca zh: 500e57982344c0fa diff --git a/packages/util/workspace-path/README.md b/packages/util/workspace-path/README.md index c6b9b1c762..b4d7f1c31c 100644 --- a/packages/util/workspace-path/README.md +++ b/packages/util/workspace-path/README.md @@ -9,7 +9,7 @@ English | [中文](README.zh.md) ## Summary -Browser-safe path helpers shared by Workspace-facing client and controller packages. The package joins Workspace-relative paths, abbreviates POSIX home directories for display, derives Workspace titles from POSIX or Windows paths, splits a path into its directories and final segment for display, and owns the `dsh-resource://file/…` address grammar that names a workspace file across the Sidebar and the resource model. `relativizeToCwd` removes the workspace prefix for display while preserving paths outside that directory. It has no Cordis service or runtime state. +Browser-safe path helpers shared by Workspace-facing client and controller packages. The package joins Workspace-relative paths, abbreviates POSIX home directories for display, derives Workspace titles from POSIX or Windows paths, splits a path into its directories and final segment for display, and owns the `dsh-resource://file/…` address grammar that names a workspace file across the Sidebar and the resource model. `relativizeToCwd` removes the workspace prefix for display while preserving paths outside that directory. `within` tests lexically whether one canonical absolute path is another or lies below it. It has no Cordis service or runtime state. ## Table of Contents diff --git a/packages/util/workspace-path/README.zh.md b/packages/util/workspace-path/README.zh.md index 3bf54cf264..01fcb48f56 100644 --- a/packages/util/workspace-path/README.zh.md +++ b/packages/util/workspace-path/README.zh.md @@ -9,7 +9,7 @@ kind: "package-library" ## 概述 -供 Workspace 相关客户端和控制器包共享、可在浏览器使用的路径辅助函数。该包负责拼接 Workspace 相对路径、缩写用于展示的 POSIX 主目录、从 POSIX 或 Windows 路径提取 Workspace 标题、把路径拆成目录部分与末段供展示,并拥有在 Sidebar 与资源模型之间命名工作区文件的 `dsh-resource://file/…` 地址语法。`relativizeToCwd` 在显示时省略工作区前缀,并保留该目录以外的路径。它不提供 Cordis service,也不持有运行时状态。 +供 Workspace 相关客户端和控制器包共享、可在浏览器使用的路径辅助函数。该包负责拼接 Workspace 相对路径、缩写用于展示的 POSIX 主目录、从 POSIX 或 Windows 路径提取 Workspace 标题、把路径拆成目录部分与末段供展示,并拥有在 Sidebar 与资源模型之间命名工作区文件的 `dsh-resource://file/…` 地址语法。`relativizeToCwd` 在显示时省略工作区前缀,并保留该目录以外的路径。`within` 以词法判断一个规范绝对路径是否等于另一个路径或位于其下。它不提供 Cordis service,也不持有运行时状态。 ## 目录 diff --git a/packages/util/workspace-path/src/index.ts b/packages/util/workspace-path/src/index.ts index 61f39e6a29..c9c2e2b48a 100644 --- a/packages/util/workspace-path/src/index.ts +++ b/packages/util/workspace-path/src/index.ts @@ -18,6 +18,25 @@ export function isAbsoluteWorkspacePath(path: string): boolean { return path.startsWith('/') || isWindowsStylePath(path) } +/** + * Whether `path` is `root` or lies below it. Both are canonical absolute paths of one execution + * world in the same spelling, so the test is lexical and never touches the filesystem: the path + * equals the directory or continues it past a separator. Windows spellings compare + * case-insensitively, as their filesystems do. + * @param root - canonical absolute directory. + * @param path - canonical absolute path to test. + * @returns true for `root` itself and every path below it. + */ +export function within(root: string, path: string): boolean { + const windows = isWindowsStylePath(root) + const separator = windows && root.includes('\\') ? '\\' : '/' + const base = windows ? root.toLowerCase() : root + const candidate = windows ? path.toLowerCase() : path + const directory = base.length > 1 && base.endsWith(separator) ? base.slice(0, -1) : base + const prefix = directory.endsWith(separator) ? directory : directory + separator + return candidate === directory || candidate.startsWith(prefix) +} + /** * Resolve a Workspace-relative path into the Host-facing spelling used by path operations. * @param cwd - Session Workspace root, when known. diff --git a/packages/util/workspace-path/tests/within.spec.ts b/packages/util/workspace-path/tests/within.spec.ts new file mode 100644 index 0000000000..543f6d36ef --- /dev/null +++ b/packages/util/workspace-path/tests/within.spec.ts @@ -0,0 +1,29 @@ +import { describe, expect, it } from 'vitest' +import { within } from '@deepseek-ai/dsh-util-workspace-path' + +describe('within', () => { + it('tests containment lexically on canonical POSIX paths', () => { + expect(within('/repo', '/repo')).toBe(true) + expect(within('/repo', '/repo/src')).toBe(true) + expect(within('/repo', '/repo-sibling')).toBe(false) + expect(within('/repo', '/')).toBe(false) + expect(within('/repo/src', '/repo')).toBe(false) + }) + + it('treats the filesystem root and a trailing separator as the same directory', () => { + expect(within('/', '/')).toBe(true) + expect(within('/', '/repo')).toBe(true) + expect(within('/repo/', '/repo')).toBe(true) + expect(within('/repo/', '/repo/src')).toBe(true) + expect(within('/repo/', '/repo-sibling')).toBe(false) + }) + + it('compares Windows spellings case-insensitively with their own separator', () => { + expect(within('C:\\repo', 'c:\\Repo\\src')).toBe(true) + expect(within('C:\\repo', 'C:\\repo-sibling')).toBe(false) + expect(within('C:\\', 'C:\\repo')).toBe(true) + expect(within('C:/repo', 'C:/repo/src')).toBe(true) + expect(within('C:/repo', 'C:/repo-sibling')).toBe(false) + expect(within('\\\\server\\share', '\\\\server\\share\\dir')).toBe(true) + }) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ffcdc240f9..fbea32696f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9125,6 +9125,9 @@ importers: '@deepseek-ai/dsh-util-values': specifier: workspace:* version: link:../../util/values + '@deepseek-ai/dsh-util-workspace-path': + specifier: workspace:* + version: link:../../util/workspace-path '@deepseek-ai/schemastery': specifier: link:../../../vendor/schemastery version: link:../../../vendor/schemastery @@ -9237,9 +9240,6 @@ importers: '@deepseek-ai/dsh-timeout': specifier: workspace:* version: link:../../util/timeout - '@deepseek-ai/dsh-util-workspace-path': - specifier: workspace:* - version: link:../../util/workspace-path '@deepseek-ai/dsh-working-directory': specifier: workspace:* version: link:../../session/working-directory @@ -15077,6 +15077,9 @@ importers: packages/session/working-directory: dependencies: + '@deepseek-ai/dsh-util-workspace-path': + specifier: workspace:* + version: link:../../util/workspace-path '@deepseek-ai/schemastery': specifier: link:../../../vendor/schemastery version: link:../../../vendor/schemastery @@ -16190,6 +16193,9 @@ importers: '@deepseek-ai/dsh-util-values': specifier: workspace:* version: link:../../util/values + '@deepseek-ai/dsh-util-workspace-path': + specifier: workspace:* + version: link:../../util/workspace-path '@deepseek-ai/schemastery': specifier: link:../../../vendor/schemastery version: link:../../../vendor/schemastery diff --git a/scripts/package-dependency-policy.ts b/scripts/package-dependency-policy.ts index f8b76fa650..a65a529b47 100644 --- a/scripts/package-dependency-policy.ts +++ b/scripts/package-dependency-policy.ts @@ -42,6 +42,7 @@ const DUPLICATE_SAFE_PACKAGES: readonly string[] = [ '@deepseek-ai/dsh-util-code-language', '@deepseek-ai/dsh-util-crypto', '@deepseek-ai/dsh-util-values', + '@deepseek-ai/dsh-util-workspace-path', ] /** diff --git a/scripts/verify-package-dependencies.spec.ts b/scripts/verify-package-dependencies.spec.ts index 195b71c6fd..b474e98fcd 100644 --- a/scripts/verify-package-dependencies.spec.ts +++ b/scripts/verify-package-dependencies.spec.ts @@ -236,6 +236,7 @@ describe('package dependency scope', () => { '@deepseek-ai/dsh-util-code-language', '@deepseek-ai/dsh-util-crypto', '@deepseek-ai/dsh-util-values', + '@deepseek-ai/dsh-util-workspace-path', ]) expect(PACKAGE_DEPENDENCY_POLICY.safeHostDependencyExports['@deepseek-ai/dsh-deque']).toEqual(['Deque']) expect(PACKAGE_DEPENDENCY_POLICY.safeHostDependencyExports['@deepseek-ai/schemastery']).toEqual(['default'])