@dybai/dsh-editor 0.8.0 → 0.11.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.
@@ -13,9 +13,14 @@
13
13
  * - `settings` — the editor's behavior toggles (record key = setting name,
14
14
  * value = `{ value, updatedAt }`), written by the status-bar settings
15
15
  * panel; unknown-to-this-build keys are never read, so newer clients may
16
- * store more settings than this build knows.
16
+ * store more settings than this build knows;
17
+ * - `wrap_overrides` — the per-file-type word-wrap overrides (spec §6; record
18
+ * key = a glob matching `/^\*\.[a-z0-9]{1,16}$/`, value = `{ enabled,
19
+ * updatedAt }`), written by the settings center's word-wrap section; an
20
+ * empty set means "no overrides", so the client falls back to the global
21
+ * `wordWrap` setting.
17
22
  *
18
- * All tables share ONE monotonic `updatedAt` stamp carried by the unit's
23
+ * All four tables share ONE monotonic `updatedAt` stamp carried by the unit's
19
24
  * global singleton, round-tripped for compare-and-set updates.
20
25
  *
21
26
  * The module imports NOTHING on purpose: `kv` is a `StorageBackend` KvFacet
@@ -28,7 +33,8 @@
28
33
  * - the unit opens lazily on first use and the open is memoized (concurrent
29
34
  * callers share one `open` promise; a rejecting open forgets the memo so a
30
35
  * later call retries);
31
- * - every mutating call (`setModePreferences`, `setKeymap`) runs inside ONE
36
+ * - every mutating call (`setModePreferences`, `setKeymap`, `setSettings`,
37
+ * `setWrapOverrides`) runs inside ONE
32
38
  * internal write chain (promise queue) that serializes writes — the KV unit
33
39
  * does NOT serialize writes itself, and each write must read fresh state,
34
40
  * diff records, and restamp the global as one uninterrupted critical
@@ -37,11 +43,12 @@
37
43
  * honestly observe a write that settled a beat earlier.
38
44
  *
39
45
  * Shared CAS token: the unit's global `updatedAt` is the compare-and-set
40
- * guard for BOTH tables. A `setKeymap` write restamps the token, so a
46
+ * guard for ALL FOUR tables. A `setKeymap` write restamps the token, so a
41
47
  * concurrent `setModePreferences` carrying the older token fails its CAS with
42
- * `mode-preferences/conflict` (and symmetrically `keymap/conflict`) — the
43
- * client refetches and retries. That is intentional: one unit, one stamp, no
44
- * cross-table lost updates.
48
+ * `mode-preferences/conflict` (and symmetrically `keymap/conflict`,
49
+ * `settings/conflict`, `wrap-overrides/conflict`) — the client refetches and
50
+ * retries. That is intentional: one unit, one stamp, no cross-table lost
51
+ * updates.
45
52
  *
46
53
  * Failure policy: fail loud. A backend whose medium rejects (`loadAll` on an
47
54
  * unmounted backend, a closed unit) propagates that rejection to the caller.
@@ -56,11 +63,30 @@
56
63
  * the earlier `dsh-editor` / `modeAssociations` spellings were rejected by
57
64
  * `open()`, so NO data was ever persisted under them and this unit starts
58
65
  * fresh at version 1 with no migration surface.
66
+ *
67
+ * Versioning / appending the `wrap_overrides` table (0.11.0, spec §12):
68
+ * `version` is the ON-DISK FORMAT version, not a table-set schema version.
69
+ * The `json` backend validates only unit/table names
70
+ * (`dsh-storage-json/lib/index.js`, `validateDescriptor` ~L662), then compares
71
+ * the stored stamp with `descriptor.version` / `compatibleVersions`
72
+ * (`parse` ~L106; this descriptor uses the default `single` layout, so the
73
+ * whole-unit path applies). A table ABSENT from the stored document reads as
74
+ * an empty table, never an error (`parse` ~L113-117: `records === undefined`
75
+ * → `new Map()`), and the next write serializes every declared table
76
+ * (`serialize` ~L76-88) from the preserved state (`openSingleUnit` ~L191-196).
77
+ * Conclusion: appending a table at the SAME version 1 is accepted, `version`
78
+ * needs NO increment, and the existing three tables' records are preserved
79
+ * (verified against the live medium `%USERPROFILE%\.dsh\storages\dsh_editor.json`,
80
+ * stamped `version: 1`). Bumping `version` here would instead make `open()`
81
+ * reject that file with `version-mismatch` unless `compatibleVersions` vouched
82
+ * for it. Caveat: the table list is the read projection — a pre-0.11.0 build
83
+ * ignores `wrap_overrides`, and its next whole-unit write drops that table, so
84
+ * downgrading across 0.11.0 loses only the overrides.
59
85
  */
60
86
  const UNIT_DESCRIPTOR = Object.freeze({
61
87
  name: 'dsh_editor',
62
88
  version: 1,
63
- tables: Object.freeze(['mode_associations', 'keymap', 'settings']),
89
+ tables: Object.freeze(['mode_associations', 'keymap', 'settings', 'wrap_overrides']),
64
90
  hasGlobal: true
65
91
  });
66
92
 
@@ -70,9 +96,17 @@ const TABLE = 'mode_associations';
70
96
  const KEYMAP_TABLE = 'keymap';
71
97
  /** Table whose records are the behavior toggles: record key = setting name. */
72
98
  const SETTINGS_TABLE = 'settings';
99
+ /** Table whose records are the word-wrap overrides: record key = glob. */
100
+ const WRAP_OVERRIDES_TABLE = 'wrap_overrides';
73
101
 
74
- /** Setting names this build knows; unknown keys in a payload are rejected. */
75
- const SETTINGS_KEYS = new Set(['autoReloadClean', 'highlightActiveLine', 'showLineNumbers']);
102
+ /**
103
+ * Setting names this build knows; unknown keys in a payload are rejected.
104
+ * A KNOWN key absent from storage is never invented here — `getSettings`
105
+ * reports only the records actually stored, so the client can tell "unset"
106
+ * (e.g. `wordWrap`, which then falls back to its builtin per-file default)
107
+ * from an explicitly stored value.
108
+ */
109
+ const SETTINGS_KEYS = new Set(['autoReloadClean', 'highlightActiveLine', 'showLineNumbers', 'scrollBeyondLastLine', 'wordWrap']);
76
110
 
77
111
  /** Keymap action ids the editor framework owns (spec §6; `gotoLine` v0.6.0). */
78
112
  const KEYMAP_ACTIONS = new Set(['save', 'saveAll', 'deleteLines', 'gotoLine']);
@@ -80,6 +114,8 @@ const KEYMAP_ACTIONS = new Set(['save', 'saveAll', 'deleteLines', 'gotoLine']);
80
114
  const KEYMAP_CODE_RE = /^(Key[A-Z]|Digit[0-9])$/;
81
115
  /** Abstract modifier vocabulary for a keymap binding. */
82
116
  const KEYMAP_MODIFIERS = new Set(['primary', 'control', 'alt', 'shift', 'meta']);
117
+ /** Storable record-key shape for a word-wrap override: `*.` + 1-16 [a-z0-9] (spec §6). */
118
+ const WRAP_OVERRIDE_GLOB_RE = /^\*\.[a-z0-9]{1,16}$/;
83
119
 
84
120
  /**
85
121
  * Build the plain-Error stand-in for a DOMException AbortError; the storage
@@ -205,6 +241,30 @@ function isValidSettings(settings) {
205
241
  return true;
206
242
  }
207
243
 
244
+ /**
245
+ * Validate the word-wrap overrides payload: an array (an EMPTY array is valid
246
+ * — the full-set replace then deletes every record, i.e. resets to "no
247
+ * overrides") of `{ glob: /^\*\.[a-z0-9]{1,16}$/, enabled: boolean }`. A
248
+ * duplicated glob is rejected instead of letting the last entry win: one glob
249
+ * maps to exactly one override, so a duplicate is a client bug that would
250
+ * otherwise persist an arbitrary winner. Extra properties are tolerated (only
251
+ * the contract fields are read).
252
+ * @param overrides - the caller's payload.
253
+ * @returns whether the payload is storable.
254
+ */
255
+ function isValidWrapOverrides(overrides) {
256
+ if (!Array.isArray(overrides)) return false;
257
+ const globs = new Set();
258
+ for (const entry of overrides) {
259
+ if (entry === null || typeof entry !== 'object') return false;
260
+ if (typeof entry.glob !== 'string' || !WRAP_OVERRIDE_GLOB_RE.test(entry.glob)) return false;
261
+ if (globs.has(entry.glob)) return false; // duplicate glob
262
+ globs.add(entry.glob);
263
+ if (typeof entry.enabled !== 'boolean') return false;
264
+ }
265
+ return true;
266
+ }
267
+
208
268
  /**
209
269
  * Build the mode-preferences service.
210
270
  * @param kv - a `StorageBackend` KvFacet (`open(descriptor)` → `KvUnit`).
@@ -457,6 +517,75 @@ export function createPreferencesService({ kv, now }) {
457
517
  });
458
518
  },
459
519
 
520
+ /**
521
+ * Read the stored per-file-type word-wrap overrides (spec §6).
522
+ * @param signal - caller cancellation (last parameter, SRC convention).
523
+ * @returns `{ overrides: [{ glob, enabled }] sorted by glob, updatedAt }`
524
+ * — `overrides` is empty before the first successful set (the client
525
+ * then falls back to the global `wordWrap` setting); `updatedAt` is the
526
+ * SHARED token (see the module doc).
527
+ */
528
+ async getWrapOverrides(signal) {
529
+ throwIfAborted(signal);
530
+ const unit = await openUnit();
531
+ const snapshot = await unit.loadAll();
532
+ throwIfAborted(signal);
533
+ const records = tableOf(snapshot, WRAP_OVERRIDES_TABLE);
534
+ const overrides = Object.keys(records)
535
+ .filter((glob) => {
536
+ const value = records[glob];
537
+ return value !== null && typeof value === 'object' && typeof value.enabled === 'boolean';
538
+ })
539
+ .sort()
540
+ .map((glob) => ({ glob, enabled: records[glob].enabled }));
541
+ return { overrides, updatedAt: globalUpdatedAt(snapshot.global) };
542
+ },
543
+
544
+ /**
545
+ * Replace the complete word-wrap override set (records absent from the
546
+ * array are deleted; `[]` resets to "no overrides"), restamping the
547
+ * unit's SHARED global `updatedAt` — which invalidates any pending
548
+ * associations / keymap / settings CAS against the older token.
549
+ * @param overrides - the complete new set
550
+ * (`[{ glob: /^\*\.[a-z0-9]{1,16}$/, enabled: boolean }]`, unique
551
+ * globs); validated before the write chain, so an invalid payload never
552
+ * touches storage.
553
+ * @param expectedUpdatedAt - compare-and-set guard against the SHARED
554
+ * token: when provided and not equal to the storage's current
555
+ * `updatedAt`, the write rejects with `wrap-overrides/conflict` and
556
+ * storage is untouched. Omit (or pass `undefined`) to write
557
+ * unconditionally.
558
+ * @param signal - caller cancellation (last parameter, SRC convention).
559
+ * @returns `{ updatedAt }` of the settled write.
560
+ */
561
+ async setWrapOverrides(overrides, expectedUpdatedAt, signal) {
562
+ if (!isValidWrapOverrides(overrides)) {
563
+ throw codedError('wrap-overrides/invalid');
564
+ }
565
+ throwIfAborted(signal);
566
+ return enqueue(async () => {
567
+ throwIfAborted(signal);
568
+ const unit = await openUnit();
569
+ const snapshot = await unit.loadAll();
570
+ const records = tableOf(snapshot, WRAP_OVERRIDES_TABLE);
571
+ const currentUpdatedAt = globalUpdatedAt(snapshot.global);
572
+ if (expectedUpdatedAt !== undefined && expectedUpdatedAt !== currentUpdatedAt) {
573
+ throw codedError('wrap-overrides/conflict');
574
+ }
575
+ const existingKeys = Object.keys(records);
576
+ if (existingKeys.length > 0) {
577
+ await unit.deleteRecords(WRAP_OVERRIDES_TABLE, existingKeys);
578
+ }
579
+ const updatedAt = now();
580
+ for (const { glob, enabled } of overrides) {
581
+ await unit.putRecord(WRAP_OVERRIDES_TABLE, glob, { enabled, updatedAt });
582
+ }
583
+ await unit.setGlobal({ updatedAt });
584
+ throwIfAborted(signal);
585
+ return { updatedAt };
586
+ });
587
+ },
588
+
460
589
  /**
461
590
  * Drain the write chain, close the unit when one was opened, and forget
462
591
  * the open so a later call reopens lazily. Idempotent; wired into the
package/index.js CHANGED
@@ -8,7 +8,8 @@
8
8
  * discovery claim `dshEditor/writeFile`, `dshEditor/getModePreferences`,
9
9
  * `dshEditor/setModePreferences`, `dshEditor/getKeymap`,
10
10
  * `dshEditor/setKeymap`, `dshEditor/getSettings`,
11
- * `dshEditor/setSettings` and `dshEditor/appendLogs` (the client log
11
+ * `dshEditor/setSettings`, `dshEditor/getWrapOverrides`,
12
+ * `dshEditor/setWrapOverrides` and `dshEditor/appendLogs` (the client log
12
13
  * channel's flush endpoint), so no generated Typert artifacts are needed.
13
14
  *
14
15
  * Deliberately imports no `@deepseek-ai/*` package: every capability comes
@@ -16,7 +17,7 @@
16
17
  * so the bundle loads under any profile node_modules layout. The service
17
18
  * bodies live in `host/write-service.js`, `host/preferences-service.js` and
18
19
  * `host/log-service.js` and are composed here onto one prototype that
19
- * carries all eight Remote markers; the log service's exporter is also
20
+ * carries all ten Remote markers; the log service's exporter is also
20
21
  * registered on `ctx.logger` inside the effect so this plugin's own Host
21
22
  * records persist through the same chain.
22
23
  *
@@ -145,7 +146,7 @@ export function apply(ctx) {
145
146
  error: console.error.bind(console)
146
147
  }
147
148
  });
148
- // One wire service: exactly the eight Remote-marked methods on one
149
+ // One wire service: exactly the ten Remote-marked methods on one
149
150
  // prototype, each delegating to its factory's closure.
150
151
  const service = Object.create({
151
152
  writeFile: files.writeFile,
@@ -155,6 +156,8 @@ export function apply(ctx) {
155
156
  setKeymap: preferences.setKeymap,
156
157
  getSettings: preferences.getSettings,
157
158
  setSettings: preferences.setSettings,
159
+ getWrapOverrides: preferences.getWrapOverrides,
160
+ setWrapOverrides: preferences.setWrapOverrides,
158
161
  appendLogs: (entries) => logService.appendEntries(entries)
159
162
  });
160
163
  const prototype = Object.getPrototypeOf(service);
@@ -189,6 +192,14 @@ export function apply(ctx) {
189
192
  method: 'setSettings',
190
193
  invocation: Object.freeze({ kind: 'direct' })
191
194
  }),
195
+ Object.freeze({
196
+ method: 'getWrapOverrides',
197
+ invocation: Object.freeze({ kind: 'direct' })
198
+ }),
199
+ Object.freeze({
200
+ method: 'setWrapOverrides',
201
+ invocation: Object.freeze({ kind: 'direct' })
202
+ }),
192
203
  Object.freeze({
193
204
  method: 'appendLogs',
194
205
  invocation: Object.freeze({ kind: 'direct' })
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
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), jump to a line with Ctrl+G, with stale-version conflict prompts and reload; external modifications and deletions are detected and surfaced."
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 in the settings center opened from the status-bar gear), jump to a line with Ctrl+G, with stale-version conflict prompts and reload; external modifications and deletions are detected and surfaced."
5
5
  },
6
6
  "action": {
7
7
  "save": "Save",
@@ -50,7 +50,6 @@
50
50
  "conflict": "Mode preferences changed elsewhere; reloaded, please retry."
51
51
  },
52
52
  "keymap": {
53
- "buttonTitle": "Editor shortcuts",
54
53
  "save": "Save",
55
54
  "saveAll": "Save all",
56
55
  "deleteLines": "Delete lines",
@@ -97,11 +96,31 @@
97
96
  "highlightActiveLineNote": "The built-in plain-text mode always honors this; other editor modes may declare support via their descriptor.",
98
97
  "showLineNumbers": "Show line numbers",
99
98
  "showLineNumbersTitle": "Draw the line-number column beside the content",
99
+ "scrollBeyondLastLine": "Scroll past last line",
100
+ "scrollBeyondLastLineTitle": "Keep scrollable blank space past the end of content so the last line can scroll to the top of the viewport",
101
+ "wordWrap": "Word wrap",
102
+ "wordWrapTitle": "Wrap overly long lines within the editor width",
100
103
  "on": "On",
101
104
  "off": "Off",
102
105
  "writeFailed": "Failed to save settings",
103
106
  "conflict": "Settings changed elsewhere; reloaded, please retry."
104
107
  },
108
+ "settingsCenter": {
109
+ "title": "Editor settings",
110
+ "close": "Close",
111
+ "section": {
112
+ "appearance": "Appearance",
113
+ "behavior": "Behavior",
114
+ "wrap": "Word wrap",
115
+ "keymap": "Shortcuts"
116
+ },
117
+ "wordWrapGlobalNote": "When unset, the per-extension default applies (md-like files wrap)",
118
+ "wrapOverrideLabel": "Word wrap for this type",
119
+ "wrapOverrideFollow": "Follow global",
120
+ "wrapOverrideOn": "Force on",
121
+ "wrapOverrideOff": "Force off",
122
+ "wrapOverrideNoExtension": "(no extension)"
123
+ },
105
124
  "status": {
106
125
  "lines": "lines",
107
126
  "chars": "chars"
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "文件编辑器",
4
- "description": "让分栏里的文本文件可以直接编辑:打开文件就地修改并保存到磁盘(Ctrl+S,可在状态栏键盘图标中改键),Ctrl+G 跳转到指定行,带版本冲突提示与重新加载;文件被外部修改或删除时主动提示。"
4
+ "description": "让分栏里的文本文件可以直接编辑:打开文件就地修改并保存到磁盘(Ctrl+S,可在状态栏齿轮打开的设置中心里改键),Ctrl+G 跳转到指定行,带版本冲突提示与重新加载;文件被外部修改或删除时主动提示。"
5
5
  },
6
6
  "action": {
7
7
  "save": "保存",
@@ -50,7 +50,6 @@
50
50
  "conflict": "模式偏好已被其他位置修改,已重新读取,请重试。"
51
51
  },
52
52
  "keymap": {
53
- "buttonTitle": "编辑器快捷键",
54
53
  "save": "保存",
55
54
  "saveAll": "保存全部",
56
55
  "deleteLines": "删行",
@@ -97,11 +96,31 @@
97
96
  "highlightActiveLineNote": "内置纯文本模式始终支持;其他编辑模式可经描述符 activeLine 声明遵循同一开关。",
98
97
  "showLineNumbers": "显示行号",
99
98
  "showLineNumbersTitle": "在内容左侧显示行号列",
99
+ "scrollBeyondLastLine": "滚动越过最后一行",
100
+ "scrollBeyondLastLineTitle": "在内容末尾之后保留可滚动空白,最后一行可滚动到视口顶部",
101
+ "wordWrap": "自动换行",
102
+ "wordWrapTitle": "过长的行在编辑区宽度内自动折行显示",
100
103
  "on": "开",
101
104
  "off": "关",
102
105
  "writeFailed": "保存设置失败",
103
106
  "conflict": "设置已被其他位置修改,已重新读取,请重试。"
104
107
  },
108
+ "settingsCenter": {
109
+ "title": "编辑器设置",
110
+ "close": "关闭",
111
+ "section": {
112
+ "appearance": "外观",
113
+ "behavior": "行为",
114
+ "wrap": "换行",
115
+ "keymap": "快捷键"
116
+ },
117
+ "wordWrapGlobalNote": "未设置时按扩展名默认(md 系开)",
118
+ "wrapOverrideLabel": "本类型换行",
119
+ "wrapOverrideFollow": "跟随全局",
120
+ "wrapOverrideOn": "强制开",
121
+ "wrapOverrideOff": "强制关",
122
+ "wrapOverrideNoExtension": "(无扩展名)"
123
+ },
105
124
  "status": {
106
125
  "lines": "行",
107
126
  "chars": "字符"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dybai/dsh-editor",
3
- "version": "0.8.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test index.test.js src/**/*.test.js host/**/*.test.js",