@dybai/dsh-editor 0.0.0-stage → 0.4.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.
package/index.js ADDED
@@ -0,0 +1,182 @@
1
+ /**
2
+ * @dybai/dsh-editor — Host half.
3
+ *
4
+ * Provides the `dshEditor` workspace + preferences service that the browser
5
+ * editor calls through its Typert Remote namespace. The service is registered
6
+ * with `ctx.provide` in source mode: a visible `typertRemote` binding plus a
7
+ * Remote marker on the prototype make the Typert Gateway's conservative SRC
8
+ * discovery claim `dshEditor/writeFile`, `dshEditor/getModePreferences`,
9
+ * `dshEditor/setModePreferences`, `dshEditor/getKeymap`,
10
+ * `dshEditor/setKeymap`, `dshEditor/getSettings` and
11
+ * `dshEditor/setSettings`, so no generated Typert artifacts are needed.
12
+ *
13
+ * Deliberately imports no `@deepseek-ai/*` package: every capability comes
14
+ * from the Cordis context (`fs`, `sandboxPolicy`, `sessions`, `storage`), so
15
+ * the bundle loads under any profile node_modules layout. The service bodies
16
+ * live in `host/write-service.js` and `host/preferences-service.js` and are
17
+ * composed here onto one prototype that carries all five Remote markers.
18
+ *
19
+ * @module @dybai/dsh-editor
20
+ */
21
+
22
+ import { createFileService } from './host/write-service.js';
23
+ import { createPreferencesService } from './host/preferences-service.js';
24
+
25
+ /** Cordis service key and wire namespace of the editor Host service. */
26
+ const SERVICE_KEY = 'dshEditor';
27
+ /** Fallback prototype key carrying Remote markers when live discovery fails. */
28
+ const REMOTE_DESCRIPTOR_FALLBACK = '@deepseek-ai/dsh-typert-protocol/remote-methods';
29
+
30
+ /** Host services this plugin requires; the plugin parks until they are live. */
31
+ export const inject = ['fs', 'sandboxPolicy', 'sessions', 'storage'];
32
+
33
+ /**
34
+ * Discover the prototype property name that carries Remote method markers by
35
+ * reading one live remote service's prototype chain, so the marker stays
36
+ * honest across upstream key renames. Falls back to the known literal. The
37
+ * anchors are OTHER services' keys on purpose: discovery reads their
38
+ * prototypes, so it is unaffected by this plugin's own `dshEditor` rename.
39
+ * @param hostCtx - the plugin's Host context.
40
+ * @returns the descriptor property key to define on the service prototype.
41
+ */
42
+ function remoteMarkerKey(hostCtx) {
43
+ for (const serviceKey of ['workspaceFiles', 'directoryPickerController', 'terminalController']) {
44
+ const service = hostCtx.get(serviceKey);
45
+ if (service === undefined || service === null || typeof service !== 'object') continue;
46
+ let prototype = Object.getPrototypeOf(service);
47
+ while (prototype !== null && prototype !== Object.prototype) {
48
+ for (const name of Object.getOwnPropertyNames(prototype)) {
49
+ let value;
50
+ try {
51
+ value = Object.getOwnPropertyDescriptor(prototype, name)?.value;
52
+ } catch {
53
+ continue;
54
+ }
55
+ if (
56
+ value !== null &&
57
+ typeof value === 'object' &&
58
+ value.version === 1 &&
59
+ Array.isArray(value.methods) &&
60
+ value.methods.every(
61
+ (marker) => marker !== null && typeof marker === 'object' && typeof marker.method === 'string'
62
+ )
63
+ ) {
64
+ return name;
65
+ }
66
+ }
67
+ prototype = Object.getPrototypeOf(prototype);
68
+ }
69
+ }
70
+ return REMOTE_DESCRIPTOR_FALLBACK;
71
+ }
72
+
73
+ /**
74
+ * Resolve the KV facet the mode-preference store persists through: the
75
+ * storage hub's `json` backend (the storage hub names its backend registry
76
+ * `backend`; `backends` is accepted for forward compatibility).
77
+ * @param storage - the storage hub service (`ctx.storage`).
78
+ * @returns the json backend's KvFacet.
79
+ */
80
+ function resolveKvFacet(storage) {
81
+ if (storage === undefined || storage === null || typeof storage !== 'object') {
82
+ throw new Error('dsh-editor: the storage hub service is unavailable, so mode preferences cannot persist');
83
+ }
84
+ const registry = storage.backends ?? storage.backend;
85
+ if (registry === undefined || typeof registry.get !== 'function') {
86
+ throw new Error('dsh-editor: the storage hub exposes no backend registry, so the json storage backend cannot be resolved');
87
+ }
88
+ let backend;
89
+ try {
90
+ backend = registry.get('json');
91
+ } catch (error) {
92
+ throw new Error(`dsh-editor: resolving the json storage backend failed: ${error?.message ?? String(error)}`);
93
+ }
94
+ const kv = backend === undefined || backend === null ? undefined : backend.kv;
95
+ if (kv === undefined || typeof kv.open !== 'function') {
96
+ throw new Error('dsh-editor: the json storage backend exposes no kv facet, so mode preferences cannot persist');
97
+ }
98
+ return kv;
99
+ }
100
+
101
+ /**
102
+ * Plugin entry: registers the editor Host service (workspace write + mode
103
+ * preferences) for this fiber's lifetime.
104
+ * @param ctx - the plugin's Host context.
105
+ * @returns the effect disposer cordis owns.
106
+ */
107
+ export function apply(ctx) {
108
+ const fs = ctx.get('fs');
109
+ if (fs === undefined || typeof fs.resolve !== 'function' || typeof fs.writeText !== 'function') {
110
+ throw new Error('dsh-editor: the Host filesystem service with resolve/writeText is unavailable');
111
+ }
112
+ const sandboxPolicy = ctx.get('sandboxPolicy');
113
+ if (sandboxPolicy === undefined || typeof sandboxPolicy.resolve !== 'function') {
114
+ throw new Error('dsh-editor: the sandbox-policy service with resolve is unavailable');
115
+ }
116
+ const sessions = ctx.get('sessions');
117
+ if (sessions === undefined || typeof sessions.get !== 'function') {
118
+ throw new Error('dsh-editor: the session registry with get is unavailable');
119
+ }
120
+ const kv = resolveKvFacet(ctx.get('storage'));
121
+
122
+ const files = createFileService(fs, sandboxPolicy, sessions);
123
+ const preferences = createPreferencesService({ kv, now: Date.now });
124
+ // One wire service: exactly the seven Remote-marked methods on one
125
+ // prototype, each delegating to its factory's closure.
126
+ const service = Object.create({
127
+ writeFile: files.writeFile,
128
+ getModePreferences: preferences.getModePreferences,
129
+ setModePreferences: preferences.setModePreferences,
130
+ getKeymap: preferences.getKeymap,
131
+ setKeymap: preferences.setKeymap,
132
+ getSettings: preferences.getSettings,
133
+ setSettings: preferences.setSettings
134
+ });
135
+ const prototype = Object.getPrototypeOf(service);
136
+ const markerKey = remoteMarkerKey(ctx);
137
+ Object.defineProperty(prototype, markerKey, {
138
+ configurable: true,
139
+ value: Object.freeze({
140
+ version: 1,
141
+ methods: Object.freeze([
142
+ Object.freeze({ method: 'writeFile', invocation: Object.freeze({ kind: 'direct' }) }),
143
+ Object.freeze({
144
+ method: 'getModePreferences',
145
+ invocation: Object.freeze({ kind: 'direct' })
146
+ }),
147
+ Object.freeze({
148
+ method: 'setModePreferences',
149
+ invocation: Object.freeze({ kind: 'direct' })
150
+ }),
151
+ Object.freeze({
152
+ method: 'getKeymap',
153
+ invocation: Object.freeze({ kind: 'direct' })
154
+ }),
155
+ Object.freeze({
156
+ method: 'setKeymap',
157
+ invocation: Object.freeze({ kind: 'direct' })
158
+ }),
159
+ Object.freeze({
160
+ method: 'getSettings',
161
+ invocation: Object.freeze({ kind: 'direct' })
162
+ }),
163
+ Object.freeze({
164
+ method: 'setSettings',
165
+ invocation: Object.freeze({ kind: 'direct' })
166
+ })
167
+ ])
168
+ })
169
+ });
170
+ service.typertRemote = Object.freeze({ service, serviceKey: SERVICE_KEY, namespace: SERVICE_KEY });
171
+
172
+ return ctx.effect(() => {
173
+ const disposeProvide = ctx.provide(SERVICE_KEY, service);
174
+ return () => {
175
+ disposeProvide();
176
+ // Release the KV unit so a fiber restart never trips the storage
177
+ // contract's "same unit opened twice" rejection; failure here must
178
+ // not break disposal.
179
+ preferences.close().catch(() => {});
180
+ };
181
+ }, 'dsh-editor: workspace file-write and preference services');
182
+ }
package/locale/en.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "meta": {
3
+ "title": "File editor",
4
+ "description": "Makes text files in the side pane editable: open a file, edit it in place, and save back to disk with Ctrl+S (rebindable from the status-bar keyboard icon), with stale-version conflict prompts and reload; external modifications and deletions are detected and surfaced."
5
+ },
6
+ "action": {
7
+ "save": "Save",
8
+ "saveTitle": "Save to disk ({combo})",
9
+ "edit": "Edit this file",
10
+ "editTitle": "Open this file in the editor (keeps the read-only preview)",
11
+ "reload": "Reload",
12
+ "reloadTitle": "Reload the file from disk",
13
+ "reloadDiscard": "Reload and discard local changes",
14
+ "saveAnyway": "Save anyway (overwrite on disk)",
15
+ "recreateConfirm": "Confirm recreate",
16
+ "recreateConfirmTitle": "The file is deleted: click again to recreate it with the current content"
17
+ },
18
+ "state": {
19
+ "dirty": "Unsaved changes",
20
+ "saved": "Saved",
21
+ "saving": "Saving…",
22
+ "loading": "Loading…"
23
+ },
24
+ "error": {
25
+ "unsupported": "This file cannot be edited here.",
26
+ "loadFailed": "Failed to load the file",
27
+ "saveFailed": "Save failed",
28
+ "notText": "This file is not valid UTF-8 text and cannot be edited.",
29
+ "tooLarge": "This file is larger than 4 MB and cannot be edited here."
30
+ },
31
+ "conflict": {
32
+ "banner": "The file changed on disk since it was loaded. Reloading discards local changes; saving anyway overwrites the file on disk."
33
+ },
34
+ "cmd": {
35
+ "modeMenu": "Choose editor mode"
36
+ },
37
+ "mode": {
38
+ "plain": "Plain text",
39
+ "none": "Default",
40
+ "indicatorTitle": "Editor mode (click to change)",
41
+ "transient": "Once",
42
+ "transientTitle": "Open with this mode this time (not persisted)",
43
+ "setDefault": "Set as default",
44
+ "setDefaultTitle": "Open files matching this mode with it by default",
45
+ "reset": "Restore defaults",
46
+ "resetTitle": "Clear the associations matching this file and fall back to ranking",
47
+ "loading": "Loading mode preferences…",
48
+ "loadFailed": "Failed to load mode preferences",
49
+ "writeFailed": "Failed to save mode preferences",
50
+ "conflict": "Mode preferences changed elsewhere; reloaded, please retry."
51
+ },
52
+ "keymap": {
53
+ "buttonTitle": "Editor shortcuts",
54
+ "save": "Save",
55
+ "saveAll": "Save all",
56
+ "deleteLines": "Delete lines",
57
+ "record": "Record",
58
+ "recording": "Press the new combo… (Esc to cancel)",
59
+ "reset": "Restore defaults",
60
+ "resetTitle": "Restore the default keys (Ctrl+S / Ctrl+Shift+S / Ctrl+D)",
61
+ "duplicate": "That combo is already used by another action; pick another one.",
62
+ "reserved": "This combination is reserved by the browser (e.g. close/new tab) and cannot be recorded",
63
+ "reservedHint": "Browser-reserved combos (Ctrl/⌘+W, T, N, Q, …) cannot be recorded",
64
+ "writeFailed": "Failed to save shortcuts",
65
+ "conflict": "Shortcuts changed elsewhere; reloaded, please retry."
66
+ },
67
+ "external": {
68
+ "modified": "The file was modified externally. Reload it?",
69
+ "deleted": "The file was deleted externally. Close this tab?",
70
+ "reload": "Reload",
71
+ "reloadTitle": "Discard local changes and reload the file from disk",
72
+ "dismiss": "Keep mine",
73
+ "dismissTitle": "Keep the local changes and ignore the new disk content (saving will surface the conflict)",
74
+ "suppress": "Stop asking",
75
+ "suppressTitle": "Stop asking about external changes in this tab (saving still surfaces the conflict)",
76
+ "closeTab": "Close tab",
77
+ "closeTabTitle": "Close this tab whose file was deleted",
78
+ "keep": "Keep",
79
+ "keepTitle": "Keep the tab and keep editing (saving recreates the file)"
80
+ },
81
+ "settings": {
82
+ "buttonTitle": "Editor settings",
83
+ "autoReloadClean": "Auto-reload clean files",
84
+ "autoReloadCleanTitle": "When a file without unsaved changes is modified externally, reload it silently instead of asking",
85
+ "highlightActiveLine": "Highlight active line",
86
+ "highlightActiveLineTitle": "Draw a highlight band behind the caret line (or every line the selection touches)",
87
+ "highlightActiveLineNote": "The built-in plain-text mode always honors this; other editor modes may declare support via their descriptor.",
88
+ "on": "On",
89
+ "off": "Off",
90
+ "writeFailed": "Failed to save settings",
91
+ "conflict": "Settings changed elsewhere; reloaded, please retry."
92
+ },
93
+ "status": {
94
+ "lines": "lines",
95
+ "chars": "chars"
96
+ }
97
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "meta": {
3
+ "title": "文件编辑器",
4
+ "description": "让分栏里的文本文件可以直接编辑:打开文件就地修改并保存到磁盘(Ctrl+S,可在状态栏键盘图标中改键),带版本冲突提示与重新加载;文件被外部修改或删除时主动提示。"
5
+ },
6
+ "action": {
7
+ "save": "保存",
8
+ "saveTitle": "保存到磁盘({combo})",
9
+ "edit": "编辑此文件",
10
+ "editTitle": "在编辑器中打开此文件(保留只读预览)",
11
+ "reload": "重新加载",
12
+ "reloadTitle": "从磁盘重新加载该文件",
13
+ "reloadDiscard": "重新加载并丢弃本地修改",
14
+ "saveAnyway": "仍要保存(覆盖磁盘)",
15
+ "recreateConfirm": "确认重建",
16
+ "recreateConfirmTitle": "文件已被删除:再次点击将以当前内容重新创建该文件"
17
+ },
18
+ "state": {
19
+ "dirty": "未保存",
20
+ "saved": "已保存",
21
+ "saving": "正在保存…",
22
+ "loading": "正在加载…"
23
+ },
24
+ "error": {
25
+ "unsupported": "此文件无法在这里编辑。",
26
+ "loadFailed": "加载文件失败",
27
+ "saveFailed": "保存失败",
28
+ "notText": "此文件不是有效的 UTF-8 文本,无法编辑。",
29
+ "tooLarge": "文件超过 4 MB,无法在此编辑。"
30
+ },
31
+ "conflict": {
32
+ "banner": "文件在加载后被修改过。重新加载会丢弃本地修改;仍要保存会覆盖磁盘上的文件。"
33
+ },
34
+ "cmd": {
35
+ "modeMenu": "选择编辑器模式"
36
+ },
37
+ "mode": {
38
+ "plain": "纯文本",
39
+ "none": "默认",
40
+ "indicatorTitle": "编辑器模式(点击切换)",
41
+ "transient": "本次",
42
+ "transientTitle": "本次用此模式打开(不持久化)",
43
+ "setDefault": "设为默认",
44
+ "setDefaultTitle": "把此模式匹配的文件设为默认用该模式打开",
45
+ "reset": "恢复默认",
46
+ "resetTitle": "清除命中此文件的关联,恢复按排序解析",
47
+ "loading": "正在读取模式偏好…",
48
+ "loadFailed": "读取模式偏好失败",
49
+ "writeFailed": "保存模式偏好失败",
50
+ "conflict": "模式偏好已被其他位置修改,已重新读取,请重试。"
51
+ },
52
+ "keymap": {
53
+ "buttonTitle": "编辑器快捷键",
54
+ "save": "保存",
55
+ "saveAll": "保存全部",
56
+ "deleteLines": "删行",
57
+ "record": "录制",
58
+ "recording": "按下新组合…(Esc 取消)",
59
+ "reset": "恢复默认",
60
+ "resetTitle": "把三个动作的键位恢复为默认(Ctrl+S / Ctrl+Shift+S / Ctrl+D)",
61
+ "duplicate": "该组合已被其他动作占用,请换一个组合。",
62
+ "reserved": "该组合被浏览器保留(如关闭/新建标签页),无法录制",
63
+ "reservedHint": "浏览器保留组合(Ctrl/⌘+W、T、N、Q 等)无法录制",
64
+ "writeFailed": "保存快捷键失败",
65
+ "conflict": "快捷键已被其他位置修改,已重新读取,请重试。"
66
+ },
67
+ "external": {
68
+ "modified": "文件已被外部修改。是否重新加载?",
69
+ "deleted": "文件已被外部删除。是否关闭页签?",
70
+ "reload": "重新加载",
71
+ "reloadTitle": "丢弃本地修改,从磁盘重新加载",
72
+ "dismiss": "放弃更新",
73
+ "dismissTitle": "保留本地修改,忽略磁盘上的新内容(保存时将提示冲突)",
74
+ "suppress": "不再询问",
75
+ "suppressTitle": "本页签内不再询问外部修改(保存时仍会提示冲突)",
76
+ "closeTab": "关闭页签",
77
+ "closeTabTitle": "关闭这个文件已被删除的页签",
78
+ "keep": "保留",
79
+ "keepTitle": "保留页签继续编辑(保存将重新创建文件)"
80
+ },
81
+ "settings": {
82
+ "buttonTitle": "编辑器设置",
83
+ "autoReloadClean": "干净文件自动重载",
84
+ "autoReloadCleanTitle": "没有未保存修改的文件被外部修改时,直接重新载入而不询问",
85
+ "highlightActiveLine": "高亮光标所在行",
86
+ "highlightActiveLineTitle": "在光标(或选区触及)的行背后绘制高亮色带",
87
+ "highlightActiveLineNote": "内置纯文本模式始终支持;其他编辑模式可经描述符 activeLine 声明遵循同一开关。",
88
+ "on": "开",
89
+ "off": "关",
90
+ "writeFailed": "保存设置失败",
91
+ "conflict": "设置已被其他位置修改,已重新读取,请重试。"
92
+ },
93
+ "status": {
94
+ "lines": "行",
95
+ "chars": "字符"
96
+ }
97
+ }
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@dybai/dsh-editor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "test": "node --test src/**/*.test.js host/**/*.test.js",
7
+ "build": "node scripts/build.mjs"
8
+ },
9
+ "description": "Edit workspace text files in place: an extension tab type takes over session file addresses with a save/reload editor backed by a Host file-write service",
10
+ "exports": {
11
+ ".": "./index.js",
12
+ "./client": "./client.js",
13
+ "./locale/*.json": "./locale/*.json",
14
+ "./icon": "./icon.svg"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "host/write-service.js",
19
+ "host/preferences-service.js",
20
+ "client.js",
21
+ "cordis.patch.yml",
22
+ "locale/en.json",
23
+ "locale/zh.json",
24
+ "icon.svg",
25
+ "README.md"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/dybai/dsh-editor.git"
30
+ },
31
+ "license": "MIT",
32
+ "engines": {
33
+ "dsh": ">=0.2.1-rc.5"
34
+ },
35
+ "keywords": ["dsh", "deepseek-harness", "editor", "file-edit", "sidebar-right"],
36
+ "dsh": {
37
+ "bundle": { "patch": "./cordis.patch.yml" },
38
+ "client": {
39
+ "platform": "web",
40
+ "immediately": true,
41
+ "inject": [
42
+ "@deepseek-ai/dsh-api-remotes",
43
+ "@deepseek-ai/dsh-client-ui-sidebar-right"
44
+ ]
45
+ }
46
+ }
47
+ }