dsh-hanmo 0.0.0-stage → 1.7.7

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,3 @@
1
+ - insert:
2
+ - id: hanmo
3
+ name: 'dsh-hanmo'
Binary file
package/icon.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#1c1c21"/><rect x="10" y="12" width="16" height="40" rx="5" fill="#ededf1" opacity=".18"/><rect x="13" y="22" width="10" height="6" rx="2.5" fill="#ffffff"/><rect x="13" y="32" width="10" height="3" rx="1.5" fill="#ededf1" opacity=".55"/><rect x="13" y="39" width="10" height="3" rx="1.5" fill="#ededf1" opacity=".55"/><path d="M33 38c4-9 12-14 21-13-3 2-5 4-6 7 2 0 4 1 5 2-4 1-7 3-10 6l-7 9-1-6-6 3z" fill="#ffffff"/><path d="M42 32c2-1 4-1 6 0" stroke="#4f46e5" stroke-width="2.4" stroke-linecap="round" fill="none"/><circle cx="50" cy="28" r="1.4" fill="#1c1c21"/></svg>
package/index.js ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Host half of Hanmo. The Client module (client.js) does almost all the work in
3
+ * the browser; this half adds the one thing the browser cannot do itself: edit
4
+ * a file in the main-panel file preview and save it back.
5
+ *
6
+ * DSH's own `workspaceFiles` Remote namespace is read-only by design (and its
7
+ * paged read drops the file's own line endings), so editing goes through one
8
+ * exact Fetch route on the shared, authenticated API channel, the mechanism
9
+ * DSH's deliverables plugin uses for its own routes:
10
+ *
11
+ * GET ROUTE?sessionId=<sid>&path=<path>[&large=1]
12
+ * -> 200 text/plain: the whole file, LF line breaks, no BOM;
13
+ * its version in the `x-dsh-version` header
14
+ * -> 413 { code:'large', size } above the soft limit unless large=1
15
+ * POST ROUTE?sessionId=<sid>&path=<path>&version=<v> body: the new text
16
+ * -> { ok, version } | 409 { ok:false, code:'stale' }
17
+ *
18
+ * Size: up to SOFT_BYTES a file opens for editing directly; up to HARD_BYTES
19
+ * (DSH's own single-file read cap) after the user confirms; beyond, refused.
20
+ * The text travels as a raw body both ways (no JSON escaping of megabytes),
21
+ * and a save samples only the head of the old file for its conventions.
22
+ *
23
+ * Safety:
24
+ * - only owner peers reach an exact route (Connection's own fence), and a write
25
+ * must carry `x-dsh-edit: 1`, a header a cross-site form cannot send;
26
+ * - the path resolves against the Session's working directory and must stay
27
+ * inside it, as an existing regular file (no symlink, nothing created);
28
+ * - `version` from the GET turns the write into a compare-and-set, so a file the
29
+ * agent changed meanwhile is refused with 409 instead of being overwritten;
30
+ * - the file's line-ending style and UTF-8 BOM are kept on save.
31
+ */
32
+
33
+ const ROUTE = '/api/hanmo.edit';
34
+ const SOFT_BYTES = 4 * 1024 * 1024;
35
+ const HARD_BYTES = 32 * 1024 * 1024;
36
+ const SAMPLE_BYTES = 64 * 1024;
37
+ const BOM = '\uFEFF';
38
+
39
+ const json = (status, body) => Response.json(body, { status, headers: { 'cache-control': 'no-store' } });
40
+ const fail = (status, code, message, extra) => json(status, { ok: false, code, message, ...extra });
41
+ const mb = (n) => `${Math.round(n / 1024 / 1024)} MB`;
42
+
43
+ /** CRLF when most sampled line breaks are CRLF. */
44
+ function usesCrlf(sample) {
45
+ const crlf = sample.split('\r\n').length - 1;
46
+ const lf = sample.split('\n').length - 1 - crlf;
47
+ return crlf > 0 && crlf >= lf;
48
+ }
49
+
50
+ async function workspaceRootOf(ctx, sessionId) {
51
+ const live = ctx.sessions.get(sessionId);
52
+ let header = live && live.header;
53
+ if (!header) {
54
+ const persistence = ctx.get('sessionPersistence');
55
+ const stored = persistence ? await persistence.stat(sessionId).catch(() => undefined) : undefined;
56
+ header = stored && stored.header;
57
+ }
58
+ return header ? header.cwd || ctx.sandboxPolicy.workspaceRoot : undefined;
59
+ }
60
+
61
+ /** The addressed workspace file, or the refusal to answer with. */
62
+ async function locate(ctx, request) {
63
+ const query = new URL(request.url).searchParams;
64
+ const sessionId = query.get('sessionId');
65
+ const path = query.get('path');
66
+ if (!sessionId || !path || path.includes('\0')) return fail(400, 'bad-request', 'sessionId and path are required');
67
+ const workspaceRoot = await workspaceRootOf(ctx, sessionId);
68
+ if (!workspaceRoot) return fail(404, 'session-not-found', '找不到这个会话');
69
+ const { fs } = ctx;
70
+ const signal = request.signal;
71
+ const entry = await fs.lstat(path, { cwd: workspaceRoot }, signal);
72
+ if (!entry) return fail(404, 'not-found', '文件不存在');
73
+ if (entry.type !== 'file') return fail(422, 'not-regular-file', '只能编辑普通文件(不支持目录或符号链接)');
74
+ const root = await fs.resolve(workspaceRoot, { signal });
75
+ const target = await fs.resolve(path, { cwd: workspaceRoot, signal });
76
+ if (!fs.contains(root, target)) return fail(403, 'outside-workspace', '只能编辑工作目录内的文件');
77
+ const info = await fs.stat(target, signal);
78
+ if (!info || info.type !== 'file') return fail(422, 'not-regular-file', '只能编辑普通文件');
79
+ if (info.size > HARD_BYTES) return fail(413, 'too-large', `文件超过 ${mb(HARD_BYTES)},不支持在面板里编辑`, { size: info.size });
80
+ return { target, info, query };
81
+ }
82
+
83
+ async function handleRead(ctx, request) {
84
+ const at = await locate(ctx, request);
85
+ if (at instanceof Response) return at;
86
+ if (at.info.size > SOFT_BYTES && at.query.get('large') !== '1') {
87
+ return fail(413, 'large', `文件有 ${mb(at.info.size)}`, { size: at.info.size, soft: SOFT_BYTES });
88
+ }
89
+ let raw;
90
+ try {
91
+ raw = await ctx.fs.readText(at.target, request.signal);
92
+ } catch (error) {
93
+ if (error && error.code === 'FS_NOT_TEXT') return fail(422, 'not-text', '不是 UTF-8 文本文件,无法编辑');
94
+ throw error;
95
+ }
96
+ if (raw.includes('\0')) return fail(422, 'not-text', '不是 UTF-8 文本文件,无法编辑');
97
+ let text = raw.startsWith(BOM) ? raw.slice(1) : raw;
98
+ if (text.includes('\r')) text = text.replace(/\r\n/g, '\n');
99
+ return new Response(text, {
100
+ headers: {
101
+ 'content-type': 'text/plain; charset=utf-8',
102
+ 'cache-control': 'no-store',
103
+ 'x-dsh-version': encodeURIComponent(String(at.info.version)),
104
+ },
105
+ });
106
+ }
107
+
108
+ async function handleWrite(ctx, request) {
109
+ if (request.headers.get('x-dsh-edit') !== '1') return fail(403, 'header', 'missing x-dsh-edit header');
110
+ const at = await locate(ctx, request);
111
+ if (at instanceof Response) return at;
112
+ const version = at.query.get('version');
113
+ if (!version) return fail(400, 'bad-request', 'version is required');
114
+ const body = await request.text();
115
+ if (Buffer.byteLength(body, 'utf8') > HARD_BYTES) return fail(413, 'too-large', `内容超过 ${mb(HARD_BYTES)}`);
116
+ if (body.includes('\0')) return fail(422, 'not-text', '内容包含 NUL 字符');
117
+
118
+ // keep the file's own conventions, judged from its head only: the editor
119
+ // works in LF without a BOM
120
+ const head = await ctx.fs.readByteRange(at.target, { offset: 0, length: SAMPLE_BYTES }, request.signal);
121
+ const bom = head.length >= 3 && head[0] === 0xef && head[1] === 0xbb && head[2] === 0xbf;
122
+ const crlf = usesCrlf(new TextDecoder('utf-8').decode(head));
123
+ let content = body.startsWith(BOM) ? body.slice(1) : body;
124
+ if (content.includes('\r')) content = content.replace(/\r\n/g, '\n');
125
+ if (crlf) content = content.replace(/\n/g, '\r\n');
126
+ if (bom) content = BOM + content;
127
+
128
+ try {
129
+ const outcome = await ctx.fs.writeText(at.target, content, { kind: 'replaceIfVersion', version }, request.signal);
130
+ return json(200, { ok: true, version: outcome.version });
131
+ } catch (error) {
132
+ const code = error && error.code;
133
+ if (code === 'FS_STALE_VERSION') return fail(409, 'stale', '文件在你编辑期间已被修改');
134
+ if (code === 'FS_NOT_FOUND') return fail(404, 'not-found', '文件已不存在');
135
+ throw error;
136
+ }
137
+ }
138
+
139
+ /** Host services the edit route needs; the route lives as long as the plugin. */
140
+ export const inject = ['connection', 'fs', 'sessions', 'sandboxPolicy'];
141
+
142
+ export function apply(ctx) {
143
+ ctx.connection.fetch.register({
144
+ path: ROUTE,
145
+ methods: ['GET', 'POST'],
146
+ requestBody: 'buffered',
147
+ fetch: (request) => (request.method === 'POST' ? handleWrite(ctx, request) : handleRead(ctx, request)).catch((error) => {
148
+ if (request.signal.aborted) return fail(499, 'aborted', 'request aborted');
149
+ return fail(500, (error && error.code) || 'failed', (error && error.message) || String(error));
150
+ }),
151
+ });
152
+ }
package/locale/en.json ADDED
@@ -0,0 +1 @@
1
+ { "meta": { "title": "Hanmo", "description": "Restyles the DSH sidebar and main panel: cyan-glow outlined tiles, a comet trace on New Session, a glass composer, and a selection that slides between rows on a spring. Adds six VS Code colour themes plus sunset, sunrise, deep-sea (with sunlit water and rising bubbles), beach and afterglow sky themes, a 天色 (Daylight) theme that follows the real sky over your city, a time-of-day switch for every sky, a gradient-sky scope switch for the sidebar and the main panel, your own wallpaper (main panel only, or across the whole window), font, size and text-colour controls in the session header, and a highlighted file preview tab." } }
package/locale/zh.json ADDED
@@ -0,0 +1 @@
1
+ { "meta": { "title": "翰墨 Hanmo", "description": "重绘 DSH 侧边栏与主面板:青色微光描边卡片、「新会话」彗星光效、玻璃输入框,选中框随弹簧在行间滑动。新增六套 VS Code 配色主题与「落日」「朝阳」「深海」「沙滩」「晚霞」五套渐变天空主题(同时出现在 DSH 自带的外观设置里),以及随你所在城市真实天色变化的「天色」主题;每套天空都可打开「随时间变化」,渐变天空可分别铺到侧边栏和主面板,并支持你自己的壁纸(只覆盖主面板,或覆盖整个窗口),会话标题栏可调字体、字号与正文颜色,并提供带语法高亮的文件预览标签页。配色主题里的「DeepSeek Harness」可一键回到未安装插件时的原版外观。" } }
package/package.json CHANGED
@@ -1,6 +1,85 @@
1
1
  {
2
2
  "name": "dsh-hanmo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.7.7",
4
+ "description": "Hanmo (翰墨): an appearance plugin for the DeepSeek Harness Web UI — glowing outlined sidebar tiles, a comet-trace New Session button, six VS Code colour themes plus sunset, sunrise, deep-sea, beach and afterglow sky themes, a 天色 (Daylight) theme that follows the real sky over your city, a time-of-day switch for every sky, a user wallpaper, and sky / wallpaper scope switches, registered with DSH's theme service, font and text-colour controls, and a highlighted main-panel file preview.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "xiaonerner0821",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/xiaonerner0821/dsh-hanmo.git"
11
+ },
12
+ "homepage": "https://github.com/xiaonerner0821/dsh-hanmo#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/xiaonerner0821/dsh-hanmo/issues"
15
+ },
16
+ "keywords": [
17
+ "dsh",
18
+ "deepseek-harness",
19
+ "dsh-plugin",
20
+ "theme",
21
+ "sidebar",
22
+ "fonts",
23
+ "ui"
24
+ ],
25
+ "icon": "./icon.svg",
26
+ "exports": {
27
+ ".": "./index.js",
28
+ "./client": "./client.js",
29
+ "./locale/*.json": "./locale/*.json",
30
+ "./icon": "./icon.svg",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "index.js",
35
+ "client.js",
36
+ "client.editor.js",
37
+ "cordis.patch.yml",
38
+ "locale/*.json",
39
+ "icon.svg",
40
+ "README.md",
41
+ "README.zh-CN.md",
42
+ "docs/theme-cards.png",
43
+ "CHANGELOG.md",
44
+ "LICENSE",
45
+ "THIRD_PARTY_NOTICES.md"
46
+ ],
47
+ "scripts": {
48
+ "check": "node --check client.js && node --check index.js",
49
+ "build:fonts": "node build-fonts.mjs",
50
+ "build:editor": "node editor/build.mjs dsh-hanmo client.editor.js",
51
+ "prepublishOnly": "npm run check"
52
+ },
53
+ "devDependencies": {
54
+ "@codemirror/commands": "^6.11.1",
55
+ "@codemirror/lang-css": "^6.3.1",
56
+ "@codemirror/lang-html": "^6.4.12",
57
+ "@codemirror/lang-javascript": "^6.2.5",
58
+ "@codemirror/lang-json": "^6.0.2",
59
+ "@codemirror/lang-markdown": "^6.5.2",
60
+ "@codemirror/lang-python": "^6.2.1",
61
+ "@codemirror/lang-sql": "^6.10.0",
62
+ "@codemirror/language": "^6.13.1",
63
+ "@codemirror/legacy-modes": "^6.5.5",
64
+ "@codemirror/search": "^6.7.2",
65
+ "@codemirror/state": "^6.7.6",
66
+ "@codemirror/view": "^6.43.15",
67
+ "@lezer/highlight": "^1.2.5",
68
+ "esbuild": "^0.25.12"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public"
72
+ },
73
+ "engines": {
74
+ "dsh": "^0.2.1-rc.1",
75
+ "node": ">=20"
76
+ },
77
+ "dsh": {
78
+ "bundle": { "patch": "./cordis.patch.yml" },
79
+ "client": {
80
+ "platform": "web",
81
+ "immediately": true,
82
+ "inject": ["@deepseek-ai/dsh-client-ui-sidebar", "@deepseek-ai/dsh-client-ui-theme", "@deepseek-ai/dsh-client-ui-conversation"]
83
+ }
84
+ }
85
+ }