@zmskco/dsh-notebook 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The plugin's write boundary.
3
+ *
4
+ * Every write this plugin makes — from the panel, and from the model going
5
+ * through the same store — goes through `ctx.fs` with an explicit policy. That
6
+ * matters because `fs-sandbox` otherwise calls `ctx.sandboxPolicy.resolve()` with
7
+ * **no session**: a call with no policy of its own is judged against the
8
+ * *deployment* fallback, `defaultMode` plus `workspaceRoot` (whose own default is
9
+ * wherever dsh was launched), never against the workspace it is actually writing
10
+ * to.
11
+ *
12
+ * So {@link storyWritePolicy} states the boundary per call: the resolved root,
13
+ * which is the calling Session's own workspace. Nothing is widened by that — the
14
+ * boundary the plugin stamps is the boundary the Session already has — and
15
+ * `fs-sandbox` still re-canonicalizes the target and enforces containment against
16
+ * it, which is the check that actually stops a path escaping.
17
+ *
18
+ * The **mode** is not invented either: it comes from `resolve({ session })`, the
19
+ * same call `fs-sandbox` makes, so a Session the operator has switched to
20
+ * `danger-full-access` (or a deployment still under `read-only`) behaves here
21
+ * exactly as it does for the model's own `write`/`edit` and `pwsh`.
22
+ *
23
+ * What is left to report is therefore a single arrangement: a `read-only`
24
+ * deployment, where nothing may write at all — the panel and the model's tools
25
+ * alike, because they are the same boundary.
26
+ *
27
+ * @module notebook/story/sandbox
28
+ */
29
+ import { homedir } from 'node:os';
30
+ import { join } from 'node:path';
31
+ /**
32
+ * The mode one call runs under, resolved exactly as `fs-sandbox` resolves it.
33
+ *
34
+ * A Session carries its own mode log (`sandbox/mode`), so the panel must ask
35
+ * about the Session rather than read `defaultMode`: the operator can switch a
36
+ * Session to `danger-full-access` while the deployment stays `read-only`, and a
37
+ * panel disagreeing with the tools about that is a lie in the UI.
38
+ * @param policy - the sandbox policy service.
39
+ * @param session - the calling Session, when the caller named one.
40
+ * @returns the effective mode for that call.
41
+ */
42
+ export function callMode(policy, session) {
43
+ return policy.resolve(session === undefined ? {} : { session }).mode;
44
+ }
45
+ /**
46
+ * The policy to stamp on every write of one root.
47
+ *
48
+ * The mode is the caller's own; the boundary is the directory the notes actually
49
+ * live in, which is that Session's workspace.
50
+ * @param rootDir - the resolved absolute root for this call.
51
+ * @param policy - the sandbox policy service, when the profile has one.
52
+ * @param session - the calling Session, when the caller named one.
53
+ * @returns the per-call policy, or `undefined` when nothing confines this
54
+ * profile's writes and there is therefore nothing to stamp.
55
+ */
56
+ export function storyWritePolicy(rootDir, policy, session) {
57
+ if (policy === undefined)
58
+ return undefined;
59
+ return { mode: callMode(policy, session), workspaceRoot: rootDir };
60
+ }
61
+ /**
62
+ * Decide whether a write to `rootDir` should be expected to work.
63
+ *
64
+ * Advisory only: the caller reports this and uses it to explain a failure, but
65
+ * still attempts the write, because refusing a write that would have succeeded
66
+ * is worse than a warning that turns out to be unnecessary.
67
+ * @param rootDir - the resolved absolute root for this call.
68
+ * @param policy - the sandbox policy service, when this profile has one.
69
+ * @param session - the calling Session, when the caller named one.
70
+ * @returns the assessment shown in the panel and used to explain failures.
71
+ */
72
+ export function assessWriteAccess(rootDir, policy, session) {
73
+ if (policy === undefined)
74
+ return { writable: true };
75
+ const mode = callMode(policy, session);
76
+ if (mode === 'read-only')
77
+ return { writable: false, mode, workspaceRoot: rootDir, reason: 'read-only' };
78
+ return { writable: true, mode, workspaceRoot: rootDir };
79
+ }
80
+ /** The profile patch file a user edits to change the sandbox mode. */
81
+ export function profilePatchPath() {
82
+ const home = process.env.DSH_HOME?.trim();
83
+ const profile = process.env.DSH_PROFILE?.trim() || 'web';
84
+ const base = home !== undefined && home.length > 0 ? home : join(homedir(), '.dsh');
85
+ return join(base, 'profiles', profile, 'cordis.patch.yml');
86
+ }
87
+ /**
88
+ * Explain a read-only deployment and give the exact edit that lifts it.
89
+ *
90
+ * The mode is the only knob that can be turned from here — the root follows the
91
+ * calling Session, so the remedy for a *read-only* deployment is a mode change,
92
+ * not a directory move. The YAML is spelled out rather than described because
93
+ * `config` in a Loader patch is replaced wholesale, never deep-merged — an entry
94
+ * that set only `mode` would reset `workspaceRoot` to `process.cwd()`.
95
+ * @param rootDir - the root the refused call resolved to.
96
+ * @param access - the assessment for that root.
97
+ * @returns a multi-line message suitable for the panel and for a tool result.
98
+ */
99
+ export function writeAccessGuidance(rootDir, access) {
100
+ if (access.reason !== 'read-only')
101
+ return null;
102
+ const patch = profilePatchPath();
103
+ return [
104
+ `目录 ${rootDir} 不可写:当前部署的文件策略是 read-only,插件的每一次写入都会被拒绝。`,
105
+ '',
106
+ `在 ${patch} 里放行(config 是整体替换,所以要连 mode 一起写):`,
107
+ '',
108
+ ' - id: sandbox-policy',
109
+ ' config:',
110
+ " mode: !!js process.env.DSH_PERMISSION_MODE ?? 'workspace-write'",
111
+ ` workspaceRoot: ${access.workspaceRoot ?? rootDir}`,
112
+ ].join('\n');
113
+ }
@@ -0,0 +1,32 @@
1
+ import { ProjectStore } from './project.js';
2
+ import { storyWritePolicy } from './sandbox.js';
3
+ /** Workspaces kept as live stores; beyond this the oldest is dropped. */
4
+ const MAX_CACHED_WORKSPACES = 8;
5
+ /** One store per (workspace, sandbox mode). */
6
+ const cache = new Map();
7
+ /**
8
+ * Build (or reuse) the store that treats one workspace as its root.
9
+ *
10
+ * Cached per (directory, sandbox mode): the mode can be switched while the plugin
11
+ * serves a Session, and a store holds the policy it was stamped with, so a second
12
+ * entry costs one listing.
13
+ * @param deps - filesystem, sandbox policy, logger.
14
+ * @param session - the calling Session, for the write policy.
15
+ * @param dir - the workspace directory, as resolved for this call.
16
+ * @returns a store whose root is `dir` and whose only project is that directory.
17
+ */
18
+ export function workspaceStore(deps, session, dir) {
19
+ const write = storyWritePolicy(dir, deps.policy, session);
20
+ const key = `${dir}\u0000${write?.mode ?? ''}`;
21
+ let store = cache.get(key);
22
+ if (store === undefined) {
23
+ store = new ProjectStore(deps.fs, dir, deps.log, write);
24
+ cache.set(key, store);
25
+ if (cache.size > MAX_CACHED_WORKSPACES) {
26
+ const oldest = cache.keys().next().value;
27
+ if (oldest !== undefined)
28
+ cache.delete(oldest);
29
+ }
30
+ }
31
+ return store;
32
+ }
package/lib/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Domain and wire types shared by both halves.
3
+ *
4
+ * The Client half imports these with `import type`, which esbuild erases, so
5
+ * this module carries no runtime edge between the halves.
6
+ */
7
+ export {};
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Notebook",
4
+ "description": "A markdown notebook for the workspace: file tree, WYSIWYG editing, autosave and an embedded AI chat."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "笔记本",
4
+ "description": "工作区里的 markdown 笔记本:目录树、所见即所得编辑、自动保存与内嵌 AI 对话。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,93 @@
1
- {
2
- "name": "@zmskco/dsh-notebook",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@zmskco/dsh-notebook",
3
+ "version": "0.2.0",
4
+ "description": "笔记本 (Notebook) — a markdown notebook for the DeepSeek Harness workspace: file tree, WYSIWYG editor, autosave and an embedded AI chat.",
5
+ "icon": "./icon.png",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zmskco/dsh-notebook.git"
9
+ },
10
+ "homepage": "https://github.com/zmskco/dsh-notebook#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/zmskco/dsh-notebook/issues"
13
+ },
14
+ "type": "module",
15
+ "license": "MIT",
16
+ "main": "lib/index.js",
17
+ "exports": {
18
+ ".": "./lib/index.js",
19
+ "./client": "./lib/client.js",
20
+ "./locale/*.json": "./locale/*.json",
21
+ "./icon": "./icon.png",
22
+ "./icon.png": "./icon.png",
23
+ "./cordis.patch.yml": "./cordis.patch.yml",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "files": [
27
+ "lib/index.js",
28
+ "lib/client.js",
29
+ "lib/**/*.js",
30
+ "cordis.patch.yml",
31
+ "locale/*.json",
32
+ "icon.png",
33
+ "assets/material-icons/LICENSE.txt",
34
+ "assets/material-icons/NOTICE.md",
35
+ "LICENSE",
36
+ "README.md"
37
+ ],
38
+ "keywords": [
39
+ "dsh",
40
+ "deepseek-harness",
41
+ "cordis",
42
+ "bundle",
43
+ "notebook",
44
+ "markdown",
45
+ "editor"
46
+ ],
47
+ "engines": {
48
+ "node": ">=20",
49
+ "dsh": "^0.2.2-alpha.2"
50
+ },
51
+ "dsh": {
52
+ "bundle": {
53
+ "patch": "./cordis.patch.yml"
54
+ },
55
+ "client": {
56
+ "platform": "web",
57
+ "immediately": true
58
+ }
59
+ },
60
+ "scripts": {
61
+ "build": "npm run build:host && npm run build:client && npm run check:client",
62
+ "build:host": "tsc -p tsconfig.host.json",
63
+ "build:client": "tsdown",
64
+ "check:client": "node scripts/check-client.mjs",
65
+ "check:sandbox": "node scripts/check-sandbox.mjs",
66
+ "smoke": "node scripts/smoke-host.mjs",
67
+ "test": "npm run typecheck && npm run check:sandbox && npm run smoke",
68
+ "vendor:icons": "node scripts/vendor-material-icons.mjs",
69
+ "watch:client": "tsdown --watch",
70
+ "watch:host": "tsc -p tsconfig.host.json --watch --preserveWatchOutput",
71
+ "typecheck": "tsc -p tsconfig.host.json --noEmit && tsc -p tsconfig.json",
72
+ "prepublishOnly": "npm run build && npm test",
73
+ "pack:check": "npm pack --dry-run"
74
+ },
75
+ "devDependencies": {
76
+ "@types/node": "^22.10.0",
77
+ "@types/react": "^18.3.0",
78
+ "prosemirror-commands": "^1.7.2",
79
+ "prosemirror-history": "^1.5.1",
80
+ "prosemirror-inputrules": "^1.5.1",
81
+ "prosemirror-keymap": "^1.2.3",
82
+ "prosemirror-model": "^1.25.12",
83
+ "prosemirror-schema-basic": "^1.2.5",
84
+ "prosemirror-schema-list": "^1.5.1",
85
+ "prosemirror-state": "^1.4.4",
86
+ "prosemirror-view": "^1.42.8",
87
+ "tsdown": "^0.22.2",
88
+ "typescript": "^5.7.0"
89
+ },
90
+ "publishConfig": {
91
+ "access": "public"
92
+ }
93
+ }