@prettier-ai/dsh-util-workspace-path 0.1.2-alpha.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/util/workspace-path/README.md
5
+ README.md: 9f925ba09e7dd5e015cb5000490edb0234463abc
6
+ README.zh.md: 09a2449d084c2110f47037e4368c5e6c66d6a81c
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ ---
2
+ description: "Browser-safe Workspace path helpers for joining relative paths, abbreviating POSIX homes, and deriving display titles."
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # dsh-util-workspace-path
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ Browser-safe path helpers shared by Workspace-facing client and controller packages. The package joins Workspace-relative paths, abbreviates POSIX home directories for display, and derives Workspace titles from POSIX or Windows paths. It has no Cordis service or runtime state.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
17
+ - [Dev Note](#dev-note)
18
+
19
+ -----
20
+
21
+ ## Known Limitations and Deferred Work
22
+
23
+ <a id="known-limitations-and-deferred-work"></a>
24
+
25
+ - **Resolution is lexical** — it recognizes POSIX absolute paths, Windows drive paths, and UNC paths but does not access a filesystem or canonicalize `.` and `..` segments.
26
+ - **Home abbreviation is POSIX-only** — Windows paths remain unchanged because a portable browser cannot infer Windows home-path equivalence safely.
27
+
28
+
29
+ <a id="dev-note"></a>
30
+ ### Dev Note
31
+
32
+ <details>
33
+ <summary>Working context for maintainers — click to expand</summary>
34
+
35
+ None.
36
+
37
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,37 @@
1
+ ---
2
+ description: "浏览器安全的 Workspace 路径辅助函数:拼接相对路径、缩写 POSIX 主目录并生成显示标题。"
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # dsh-util-workspace-path
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ 供 Workspace 相关客户端和控制器包共享、可在浏览器使用的路径辅助函数。该包负责拼接 Workspace 相对路径、缩写用于展示的 POSIX 主目录,以及从 POSIX 或 Windows 路径提取 Workspace 标题;它不提供 Cordis service,也不持有运行时状态。
13
+
14
+ ## 目录
15
+
16
+ - [已知限制与暂缓事项](#known-limitations-and-deferred-work)
17
+ - [开发备注](#dev-note)
18
+
19
+ -----
20
+
21
+ ## 已知限制与暂缓事项
22
+
23
+ <a id="known-limitations-and-deferred-work"></a>
24
+
25
+ - **路径解析仅处理字面值**——它识别 POSIX 绝对路径、Windows 盘符路径和 UNC 路径,但不访问文件系统,也不规范化 `.` 与 `..` 路径段。
26
+ - **主目录缩写仅支持 POSIX**——Windows 路径保持不变,因为可移植浏览器无法安全推断 Windows 主目录路径等价关系。
27
+
28
+
29
+ <a id="dev-note"></a>
30
+ ### 开发备注
31
+
32
+ <details>
33
+ <summary>维护者工作上下文——点击展开</summary>
34
+
35
+ 无。
36
+
37
+ </details>
package/lib/index.js ADDED
@@ -0,0 +1,48 @@
1
+ //#region lib/types/index.js
2
+ /**
3
+ * Browser-safe Workspace path and display helpers.
4
+ * @module @prettier-ai/dsh-util-workspace-path
5
+ */
6
+ /** Whether a path uses a Windows drive or UNC prefix. */
7
+ function isWindowsStylePath(value) {
8
+ return /^[A-Za-z]:[/\\]/.test(value) || value.startsWith("\\\\");
9
+ }
10
+ /**
11
+ * Resolve a Workspace-relative path into the Host-facing spelling used by path operations.
12
+ * @param cwd - Session Workspace root, when known.
13
+ * @param path - Absolute or Workspace-relative path.
14
+ * @returns an absolute path when a Workspace root is available, otherwise the original path.
15
+ */
16
+ function resolveWorkspacePath(cwd, path) {
17
+ if (path.startsWith("/") || isWindowsStylePath(path)) return path;
18
+ if (cwd === void 0 || cwd === "") return path;
19
+ return `${cwd.replace(/[/\\]+$/, "")}/${path.replace(/^[/\\]+/, "")}`;
20
+ }
21
+ /**
22
+ * Abbreviate a POSIX home directory for display.
23
+ * @param path - Absolute or already-short display path.
24
+ * @param home - Host account home; absent skips abbreviation.
25
+ * @returns `~` or `~/…` for the POSIX home and its descendants, otherwise `path`.
26
+ */
27
+ function abbreviateHomePath(path, home) {
28
+ if (home === void 0 || home === "") return path;
29
+ if (isWindowsStylePath(path) || isWindowsStylePath(home)) return path;
30
+ const root = home.replace(/\/+$/, "");
31
+ if (root === "" || root === "/") return path;
32
+ if (path.replace(/\/+$/, "") === root) return "~";
33
+ if (path.startsWith(`${root}/`)) return `~${path.slice(root.length)}`;
34
+ return path;
35
+ }
36
+ /**
37
+ * Read the final non-empty segment of a Workspace path for display.
38
+ * Workspace-label surfaces use this helper instead of deriving another basename.
39
+ * @param path - Workspace directory path using POSIX or Windows separators.
40
+ * @returns the final segment, or an empty string for a separator-only path.
41
+ */
42
+ function workspaceTitleOf(path) {
43
+ const trimmed = path.replace(/[/\\]+$/, "");
44
+ const separator = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
45
+ return trimmed.slice(separator + 1);
46
+ }
47
+ //#endregion
48
+ export { abbreviateHomePath, resolveWorkspacePath, workspaceTitleOf };
@@ -0,0 +1,20 @@
1
+ //#region lib/types/invariant.js
2
+ /**
3
+ * Package-owned invariant companion for `@prettier-ai/dsh-util-workspace-path`.
4
+ * @module @prettier-ai/dsh-util-workspace-path/invariant
5
+ */
6
+ const PACKAGE_NAME = "@prettier-ai/dsh-util-workspace-path";
7
+ /** Cordis companion plugin name. */
8
+ const name = "workspace-path-invariant";
9
+ /** Service required before the companion can reserve package ownership. */
10
+ const inject = ["invariants"];
11
+ /** No runtime invariant: this utility owns no mutable runtime relationship. */
12
+ const install = () => {};
13
+ /**
14
+ * Register this package's invariant companion.
15
+ * @param ctx - Cordis context carrying the invariant service.
16
+ * @returns the installed registration's disposer after setup succeeds.
17
+ */
18
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
19
+ //#endregion
20
+ export { apply, inject, name };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Browser-safe Workspace path and display helpers.
3
+ * @module @prettier-ai/dsh-util-workspace-path
4
+ */
5
+ /**
6
+ * Resolve a Workspace-relative path into the Host-facing spelling used by path operations.
7
+ * @param cwd - Session Workspace root, when known.
8
+ * @param path - Absolute or Workspace-relative path.
9
+ * @returns an absolute path when a Workspace root is available, otherwise the original path.
10
+ */
11
+ export declare function resolveWorkspacePath(cwd: string | undefined, path: string): string;
12
+ /**
13
+ * Abbreviate a POSIX home directory for display.
14
+ * @param path - Absolute or already-short display path.
15
+ * @param home - Host account home; absent skips abbreviation.
16
+ * @returns `~` or `~/…` for the POSIX home and its descendants, otherwise `path`.
17
+ */
18
+ export declare function abbreviateHomePath(path: string, home?: string): string;
19
+ /**
20
+ * Read the final non-empty segment of a Workspace path for display.
21
+ * Workspace-label surfaces use this helper instead of deriving another basename.
22
+ * @param path - Workspace directory path using POSIX or Windows separators.
23
+ * @returns the final segment, or an empty string for a separator-only path.
24
+ */
25
+ export declare function workspaceTitleOf(path: string): string;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Package-owned invariant companion for `@prettier-ai/dsh-util-workspace-path`.
3
+ * @module @prettier-ai/dsh-util-workspace-path/invariant
4
+ */
5
+ import type { Context } from '@prettier-ai/cordis';
6
+ /** Cordis companion plugin name. */
7
+ export declare const name = "workspace-path-invariant";
8
+ /** Service required before the companion can reserve package ownership. */
9
+ export declare const inject: string[];
10
+ /**
11
+ * Register this package's invariant companion.
12
+ * @param ctx - Cordis context carrying the invariant service.
13
+ * @returns the installed registration's disposer after setup succeeds.
14
+ */
15
+ export declare const apply: (ctx: Context) => Promise<() => void>;
16
+ //# sourceMappingURL=invariant.d.ts.map
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@prettier-ai/dsh-util-workspace-path",
3
+ "description": "Browser-safe Workspace path and display helpers",
4
+ "version": "0.1.2-alpha.1",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/util/workspace-path"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./src/*": "./src/*",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "lib/index.js",
30
+ "lib/invariant.js",
31
+ "lib/types/**/*.d.ts"
32
+ ],
33
+ "license": "MIT",
34
+ "peerDependencies": {
35
+ "@prettier-ai/dsh-invariants": "^0.1.2-alpha.1",
36
+ "@prettier-ai/cordis": "^4.0.1"
37
+ },
38
+ "devDependencies": {
39
+ "@prettier-ai/dsh-invariants": "^0.1.2-alpha.1",
40
+ "@prettier-ai/cordis": "^4.0.1"
41
+ }
42
+ }