@chenhw7/dsh-memory 0.9.2 → 0.10.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.
Files changed (77) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +88 -70
  3. package/README.zh.md +87 -69
  4. package/cordis.patch.yml +17 -8
  5. package/lib/client/index.js +2169 -2168
  6. package/lib/context/index.d.ts +35 -124
  7. package/lib/context/index.d.ts.map +1 -1
  8. package/lib/context/index.js +75 -201
  9. package/lib/context/index.js.map +1 -1
  10. package/lib/context/settings.d.ts +67 -0
  11. package/lib/context/settings.d.ts.map +1 -0
  12. package/lib/context/settings.js +69 -0
  13. package/lib/context/settings.js.map +1 -0
  14. package/lib/identity/index.d.ts +29 -8
  15. package/lib/identity/index.d.ts.map +1 -1
  16. package/lib/identity/index.js +31 -37
  17. package/lib/identity/index.js.map +1 -1
  18. package/lib/identity/settings.d.ts +26 -12
  19. package/lib/identity/settings.d.ts.map +1 -1
  20. package/lib/identity/settings.js +29 -13
  21. package/lib/identity/settings.js.map +1 -1
  22. package/lib/index.d.ts +12 -0
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +1 -0
  25. package/lib/index.js.map +1 -1
  26. package/lib/notes/index.d.ts +35 -4
  27. package/lib/notes/index.d.ts.map +1 -1
  28. package/lib/notes/index.js +26 -31
  29. package/lib/notes/index.js.map +1 -1
  30. package/lib/notes/settings.d.ts +30 -10
  31. package/lib/notes/settings.d.ts.map +1 -1
  32. package/lib/notes/settings.js +29 -9
  33. package/lib/notes/settings.js.map +1 -1
  34. package/lib/remote/index.d.ts +7 -7
  35. package/lib/remote/index.d.ts.map +1 -1
  36. package/lib/review/accumulator.d.ts.map +1 -1
  37. package/lib/review/accumulator.js +8 -12
  38. package/lib/review/accumulator.js.map +1 -1
  39. package/lib/review/consolidate.d.ts.map +1 -1
  40. package/lib/review/consolidate.js +2 -1
  41. package/lib/review/consolidate.js.map +1 -1
  42. package/lib/review/extract.d.ts.map +1 -1
  43. package/lib/review/extract.js +2 -1
  44. package/lib/review/extract.js.map +1 -1
  45. package/lib/review/index.d.ts +40 -4
  46. package/lib/review/index.d.ts.map +1 -1
  47. package/lib/review/index.js +83 -66
  48. package/lib/review/index.js.map +1 -1
  49. package/lib/review/sweep.d.ts.map +1 -1
  50. package/lib/review/sweep.js +2 -1
  51. package/lib/review/sweep.js.map +1 -1
  52. package/lib/sources.d.ts +37 -0
  53. package/lib/sources.d.ts.map +1 -0
  54. package/lib/sources.js +16 -0
  55. package/lib/sources.js.map +1 -0
  56. package/lib/store/index.d.ts +37 -15
  57. package/lib/store/index.d.ts.map +1 -1
  58. package/lib/store/index.js +20 -8
  59. package/lib/store/index.js.map +1 -1
  60. package/lib/store/settings.d.ts +84 -0
  61. package/lib/store/settings.d.ts.map +1 -0
  62. package/lib/store/settings.js +77 -0
  63. package/lib/store/settings.js.map +1 -0
  64. package/lib/store/sqlite.d.ts +6 -0
  65. package/lib/store/sqlite.d.ts.map +1 -1
  66. package/lib/store/sqlite.js +7 -0
  67. package/lib/store/sqlite.js.map +1 -1
  68. package/lib/tool/index.d.ts +10 -10
  69. package/lib/tool/index.d.ts.map +1 -1
  70. package/lib/tool/index.js +29 -60
  71. package/lib/tool/index.js.map +1 -1
  72. package/lib/types.d.ts +2 -2
  73. package/package.json +47 -47
  74. package/lib/invariant.d.ts +0 -27
  75. package/lib/invariant.d.ts.map +0 -1
  76. package/lib/invariant.js +0 -42
  77. package/lib/invariant.js.map +0 -1
@@ -33,233 +33,503 @@ __export(index_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(index_exports);
35
35
 
36
- // src/client/MemoryPluginCard.tsx
36
+ // src/client/MemorySection.tsx
37
37
  var import_react = require("react");
38
- var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
39
-
40
- // src/client/card-styles.ts
41
- var RULES = `
42
- /* \u2500\u2500 Card shell (port of PluginCard.module.css) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
43
- .dsm-c-card {
44
- list-style: none;
45
- border: 1px solid var(--dsw-alias-border-l2);
46
- border-radius: 12px;
47
- background: var(--dsw-alias-bg-layer-3);
48
- transition: border-color .16s, background .16s;
49
- }
50
- .dsm-c-card:hover {
51
- border-color: var(--dsw-alias-label-dimmed);
52
- }
53
- .dsm-c-card-open {
54
- background: var(--dsw-alias-bg-layer-2);
55
- border-color: var(--dsw-alias-label-dimmed);
56
- }
57
- .dsm-c-header {
58
- width: 100%;
59
- appearance: none;
60
- border: 0;
61
- background: none;
62
- font: inherit;
63
- color: inherit;
64
- text-align: left;
65
- cursor: pointer;
66
- display: flex;
67
- align-items: center;
68
- gap: 12px;
69
- padding: 14px 16px;
70
- border-radius: 12px;
71
- }
72
- .dsm-c-header:focus-visible {
73
- outline: 2px solid var(--dsw-alias-brand-primary);
74
- outline-offset: -2px;
75
- }
76
- .dsm-c-head-text {
77
- flex: 1;
78
- min-width: 0;
79
- display: flex;
80
- flex-direction: column;
81
- gap: 4px;
82
- }
83
- .dsm-c-name {
84
- font-size: 15px;
85
- font-weight: 600;
86
- line-height: 1.4;
87
- color: var(--dsw-alias-label-primary);
88
- }
89
- .dsm-c-description {
90
- font-size: 13px;
91
- line-height: 1.5;
92
- color: var(--dsw-alias-label-tertiary);
93
- }
94
- .dsm-c-pending {
95
- flex: none;
96
- border-radius: 999px;
97
- padding: 1px 8px;
98
- font-size: 11px;
99
- line-height: 17px;
100
- font-weight: 500;
101
- white-space: nowrap;
102
- background: var(--dsw-alias-bg-module-platform);
103
- color: var(--dsw-alias-label-secondary);
104
- }
105
- .dsm-c-chevron {
106
- flex: none;
107
- color: var(--dsw-alias-label-tertiary);
108
- transition: transform .16s;
109
- }
110
- .dsm-c-chevron-open {
111
- transform: rotate(180deg);
112
- }
113
- .dsm-c-body {
114
- border-top: 1px solid var(--dsw-alias-border-l2);
115
- margin: 0 16px;
116
- padding-bottom: 8px;
117
- }
118
- .dsm-c-read-only {
119
- margin: 12px 0 0;
120
- font-size: 12px;
121
- line-height: 1.5;
122
- color: var(--dsw-alias-label-tertiary);
123
- }
124
- .dsm-c-footer {
125
- display: flex;
126
- align-items: center;
127
- justify-content: flex-end;
128
- gap: 8px;
129
- padding: 12px 0 4px;
130
- border-top: 1px solid var(--dsw-alias-border-l2);
131
- }
132
- .dsm-c-failed {
133
- flex: 1;
134
- min-width: 0;
135
- margin: 0;
136
- font-size: 12px;
137
- line-height: 1.5;
138
- color: var(--dsw-alias-label-error);
139
- }
140
- .dsm-c-discard,
141
- .dsm-c-save {
142
- appearance: none;
143
- border: 1px solid transparent;
144
- border-radius: 8px;
145
- padding: 5px 14px;
146
- font: inherit;
147
- font-size: 13px;
148
- line-height: 1.5;
149
- cursor: pointer;
150
- }
151
- .dsm-c-discard {
152
- border-color: var(--dsw-alias-border-l2);
153
- background: none;
154
- color: var(--dsw-alias-label-secondary);
155
- }
156
- .dsm-c-discard:hover:not(:disabled) {
157
- color: var(--dsw-alias-label-primary);
158
- border-color: var(--dsw-alias-label-dimmed);
159
- }
160
- .dsm-c-save {
161
- background: var(--dsw-alias-label-primary);
162
- color: var(--dsw-alias-bg-layer-3);
163
- }
164
- .dsm-c-discard:disabled,
165
- .dsm-c-save:disabled {
166
- opacity: 0.4;
167
- cursor: default;
168
- }
169
- .dsm-c-discard:focus-visible,
170
- .dsm-c-save:focus-visible {
171
- outline: 2px solid var(--dsw-alias-brand-primary);
172
- outline-offset: 1px;
173
- }
174
-
175
- /* \u2500\u2500 Fields (port of fields.module.css) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
176
- .dsm-c-field {
177
- display: flex;
178
- flex-direction: column;
179
- gap: 6px;
180
- padding: 12px 0;
181
- }
182
- .dsm-c-field + .dsm-c-field {
183
- border-top: 1px solid var(--dsw-alias-border-l2);
184
- }
185
- .dsm-c-head {
186
- display: flex;
187
- align-items: center;
188
- gap: 8px;
189
- }
190
- .dsm-c-label {
191
- flex: 1;
192
- min-width: 0;
193
- font-size: 13px;
194
- font-weight: 500;
195
- line-height: 1.5;
196
- color: var(--dsw-alias-label-primary);
197
- }
198
- .dsm-c-badges {
199
- display: inline-flex;
200
- align-items: center;
201
- gap: 8px;
202
- }
203
- .dsm-c-badge {
204
- border-radius: 999px;
205
- padding: 1px 8px;
206
- font-size: 11px;
207
- line-height: 17px;
208
- white-space: nowrap;
209
- font-weight: 500;
210
- background: var(--dsw-alias-bg-module-platform);
211
- color: var(--dsw-alias-label-secondary);
212
- }
213
- .dsm-c-badge-muted {
214
- border-radius: 999px;
215
- padding: 1px 8px;
216
- font-size: 11px;
217
- line-height: 17px;
218
- white-space: nowrap;
219
- color: var(--dsw-alias-label-tertiary);
220
- }
221
- .dsm-c-reset {
222
- border: none;
223
- background: none;
224
- padding: 0;
225
- font: inherit;
226
- font-size: 12px;
227
- line-height: 1.5;
228
- color: var(--dsw-alias-label-secondary);
229
- cursor: pointer;
230
- }
231
- .dsm-c-reset:hover:not(:disabled) {
232
- color: var(--dsw-alias-label-primary);
233
- }
234
- .dsm-c-reset:disabled {
235
- cursor: default;
236
- }
237
38
 
238
- /* Shared input control look (fields.module.css .input). */
239
- .dsm-c-input {
240
- height: 34px;
241
- padding: 0 12px;
242
- border: 1px solid var(--dsw-alias-border-l2);
243
- border-radius: 8px;
244
- background: var(--dsw-alias-bg-layer-3);
245
- font: inherit;
246
- font-size: 13px;
247
- line-height: 1.5;
248
- color: var(--dsw-alias-label-primary);
249
- }
250
- .dsm-c-input:focus-visible {
251
- outline: none;
252
- border-color: var(--dsw-alias-brand-primary);
39
+ // src/client/memory-section-store.ts
40
+ var import_dsh_client_store = require("@deepseek-ai/dsh-client-store");
41
+ var MEMORY_BATCH_SIZE = 50;
42
+ var MEMORY_CATEGORIES = [
43
+ "failure",
44
+ "correction",
45
+ "insight",
46
+ "preference",
47
+ "convention",
48
+ "tool-quirk",
49
+ "procedure"
50
+ ];
51
+ var CATEGORY_LABEL_KEYS = {
52
+ failure: "catFailure",
53
+ correction: "catCorrection",
54
+ insight: "catInsight",
55
+ preference: "catPreference",
56
+ convention: "catConvention",
57
+ "tool-quirk": "catToolQuirk",
58
+ procedure: "catProcedure"
59
+ };
60
+ var INITIAL = {
61
+ status: "idle",
62
+ error: null,
63
+ health: null,
64
+ projects: [],
65
+ entries: [],
66
+ total: 0,
67
+ loadingMore: false,
68
+ scope: "all",
69
+ projectName: null,
70
+ query: "",
71
+ categories: [],
72
+ pending: [],
73
+ actionError: null
74
+ };
75
+ function projectSelectable(scope) {
76
+ return scope === "all" || scope === "project";
253
77
  }
254
- .dsm-c-input:disabled {
255
- color: var(--dsw-alias-label-tertiary);
78
+ var MemorySectionController = class {
79
+ /**
80
+ * @param api - the mounted `memoryRemote` namespace face; undefined on a
81
+ * deployment too old to serve it — loads then fail into the page's error
82
+ * state instead of breaking the settings panel.
83
+ */
84
+ constructor(api) {
85
+ this.api = api;
86
+ }
87
+ api;
88
+ /** Page snapshot the renderer subscribes to. */
89
+ store = (0, import_dsh_client_store.createSnapshotStore)(INITIAL);
90
+ /** Guards against overlapping loads painting partial results. */
91
+ seq = 0;
92
+ /**
93
+ * Full match set behind the active query/chips, cached between local
94
+ * reveals; null whenever plain browsing applies. See {@link fetchFirstBatch}.
95
+ */
96
+ matches = null;
97
+ set(patch) {
98
+ this.store.set({ ...this.store.getSnapshot(), ...patch });
99
+ }
100
+ /** Wire scope for the current filter, or undefined for "all". */
101
+ wireScope() {
102
+ const { scope } = this.store.getSnapshot();
103
+ return scope === "all" ? void 0 : scope;
104
+ }
105
+ /**
106
+ * Shared wire filter fields (scope + workspace) from the current snapshot.
107
+ */
108
+ wireFilters() {
109
+ const snapshot = this.store.getSnapshot();
110
+ const scope = this.wireScope();
111
+ return {
112
+ ...scope !== void 0 ? { scope } : {},
113
+ ...snapshot.projectName !== null && snapshot.projectName !== "" ? { projectName: snapshot.projectName } : {}
114
+ };
115
+ }
116
+ requireApi() {
117
+ if (this.api === void 0) throw new Error("the memory remote namespace is not mounted on this connection");
118
+ return this.api;
119
+ }
120
+ /**
121
+ * Fetch the first batch under the committed filters. Plain browsing pages
122
+ * remotely; an active query or chip set pulls the whole match set once
123
+ * (search has no offset on the wire), caches it for local reveals, and
124
+ * unions multi-chip selections client-side (the wire takes one category).
125
+ */
126
+ async fetchFirstBatch() {
127
+ const snapshot = this.store.getSnapshot();
128
+ const trimmed = snapshot.query.trim();
129
+ if (trimmed !== "" || snapshot.categories.length > 0) {
130
+ const response2 = await this.requireApi().search({
131
+ ...this.wireFilters(),
132
+ ...trimmed !== "" ? { query: trimmed } : {},
133
+ limit: 0
134
+ });
135
+ if (!response2.result.ok) throw new Error(response2.result.error.message);
136
+ const selected = snapshot.categories;
137
+ const matches = selected.length === 0 ? [...response2.result.value.entries] : response2.result.value.entries.filter(
138
+ (entry) => entry.category !== void 0 && selected.includes(entry.category)
139
+ );
140
+ this.matches = matches;
141
+ return { entries: matches.slice(0, MEMORY_BATCH_SIZE), total: matches.length };
142
+ }
143
+ this.matches = null;
144
+ const response = await this.requireApi().list({
145
+ ...this.wireFilters(),
146
+ limit: MEMORY_BATCH_SIZE,
147
+ offset: 0
148
+ });
149
+ if (!response.result.ok) throw new Error(response.result.error.message);
150
+ return { entries: response.result.value.entries, total: response.result.value.total };
151
+ }
152
+ /**
153
+ * Full load: health dashboard, workspace roster, current page, and the
154
+ * pending-review queue. Used on section open, manual retry, and connection
155
+ * recovery.
156
+ * @returns once the snapshot reflects the host.
157
+ */
158
+ async load() {
159
+ const ticket = ++this.seq;
160
+ if (this.store.getSnapshot().status === "idle") this.set({ status: "loading" });
161
+ try {
162
+ const api = this.requireApi();
163
+ const [health, projects, batch] = await Promise.all([
164
+ api.health(),
165
+ api.projects(),
166
+ this.fetchFirstBatch()
167
+ ]);
168
+ if (!health.result.ok) throw new Error(health.result.error.message);
169
+ if (!projects.result.ok) throw new Error(projects.result.error.message);
170
+ const pendingRows = typeof api.suggestList !== "function" ? [] : await api.suggestList().then(
171
+ (response) => response.result.ok ? response.result.value.suggestions : [],
172
+ () => []
173
+ );
174
+ if (ticket !== this.seq) return;
175
+ this.set({
176
+ status: "ready",
177
+ error: null,
178
+ health: health.result.value,
179
+ projects: projects.result.value.projects,
180
+ entries: batch.entries,
181
+ total: batch.total,
182
+ pending: pendingRows
183
+ });
184
+ } catch (error) {
185
+ if (ticket !== this.seq) return;
186
+ this.set({ status: "error", error: messageOf(error) });
187
+ }
188
+ }
189
+ /**
190
+ * Re-fetch the first batch (filters changed). Resets the accumulated list;
191
+ * keeps the dashboard and status untouched, and a failure surfaces as
192
+ * page-level error text while the previous rows stay visible.
193
+ */
194
+ async reload() {
195
+ const ticket = ++this.seq;
196
+ try {
197
+ const batch = await this.fetchFirstBatch();
198
+ if (ticket !== this.seq) return;
199
+ this.set({ status: "ready", error: null, entries: batch.entries, total: batch.total, loadingMore: false });
200
+ } catch (error) {
201
+ if (ticket !== this.seq) return;
202
+ this.set({ error: messageOf(error), loadingMore: false });
203
+ }
204
+ }
205
+ /** Switch the scope filter; the workspace pick cannot outlive its scope. */
206
+ setScope(scope) {
207
+ if (this.store.getSnapshot().scope === scope) return;
208
+ this.set({ scope, projectName: null });
209
+ void this.reload();
210
+ }
211
+ /**
212
+ * Pick one workspace (or null/'' for all). Only honored where it means
213
+ * something — see {@link projectSelectable}.
214
+ */
215
+ setProject(projectName) {
216
+ if (!projectSelectable(this.store.getSnapshot().scope)) return;
217
+ const next = projectName === "" ? null : projectName;
218
+ if (this.store.getSnapshot().projectName === next) return;
219
+ this.set({ projectName: next });
220
+ void this.reload();
221
+ }
222
+ /** Commit a search text (already debounced upstream); empty clears it. */
223
+ commitQuery(query) {
224
+ if (this.store.getSnapshot().query === query) return;
225
+ this.set({ query });
226
+ void this.reload();
227
+ }
228
+ /** Flip one category chip. */
229
+ toggleCategory(category) {
230
+ const selected = this.store.getSnapshot().categories;
231
+ const next = selected.includes(category) ? selected.filter((c) => c !== category) : [...selected, category];
232
+ this.set({ categories: next });
233
+ void this.reload();
234
+ }
235
+ /**
236
+ * Append the next chunk to the visible list. Plain browsing issues one
237
+ * remote batch; an active search reveals more of the cached full match
238
+ * set without touching the network. No-op while everything is already
239
+ * shown or another append is in flight.
240
+ */
241
+ async loadMore() {
242
+ const snapshot = this.store.getSnapshot();
243
+ if (snapshot.status !== "ready" || snapshot.loadingMore) return;
244
+ if (snapshot.entries.length >= snapshot.total) return;
245
+ if (snapshot.query.trim() === "" && snapshot.categories.length === 0) {
246
+ const ticket = ++this.seq;
247
+ this.set({ loadingMore: true });
248
+ try {
249
+ const response = await this.requireApi().list({
250
+ ...this.wireFilters(),
251
+ limit: MEMORY_BATCH_SIZE,
252
+ offset: snapshot.entries.length
253
+ });
254
+ if (!response.result.ok) throw new Error(response.result.error.message);
255
+ if (ticket !== this.seq) return;
256
+ const current = this.store.getSnapshot();
257
+ const seen = new Set(current.entries.map((entry) => entry.id));
258
+ const appended = response.result.value.entries.filter((entry) => !seen.has(entry.id));
259
+ this.set({
260
+ entries: [...current.entries, ...appended],
261
+ total: response.result.value.total,
262
+ loadingMore: false
263
+ });
264
+ } catch (error) {
265
+ if (ticket !== this.seq) return;
266
+ this.set({ error: messageOf(error), loadingMore: false });
267
+ }
268
+ return;
269
+ }
270
+ const matches = this.matches;
271
+ if (matches === null) {
272
+ await this.reload();
273
+ return;
274
+ }
275
+ this.set({ entries: matches.slice(0, snapshot.entries.length + MEMORY_BATCH_SIZE) });
276
+ }
277
+ // ─── Write path (phase 2): edit / delete / pin / archive / review queue ───
278
+ /**
279
+ * Run one row action against the host, then refresh the affected surfaces.
280
+ * Failures land in `actionError` (inline, previous rows stay visible); a
281
+ * success clears any stale error and repaints from the host's answer.
282
+ */
283
+ async act(run) {
284
+ try {
285
+ const outcome = await run(this.requireApi());
286
+ if (!outcome.ok) {
287
+ this.set({ actionError: outcome.message ?? "action failed" });
288
+ return false;
289
+ }
290
+ this.set({ actionError: null });
291
+ return true;
292
+ } catch (error) {
293
+ this.set({ actionError: messageOf(error) });
294
+ return false;
295
+ }
296
+ }
297
+ /** Save human edits to one entry ("edit lands in KV", store single truth). */
298
+ async saveEntryEdits(id, edits) {
299
+ return this.act(async (api) => {
300
+ const response = await api.update({
301
+ id,
302
+ ...edits.content !== void 0 ? { content: edits.content } : {},
303
+ ...edits.category !== void 0 ? { category: edits.category ?? "" } : {},
304
+ ...edits.summary !== void 0 ? { summary: edits.summary ?? "" } : {}
305
+ });
306
+ if (!response.result.ok) return { ok: false, message: response.result.error.message };
307
+ if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "entry vanished before it could be saved" };
308
+ await this.refreshAfterMutation();
309
+ return { ok: true };
310
+ });
311
+ }
312
+ /**
313
+ * Fetch one entry's unredacted content through the break-glass `getRaw`
314
+ * RPC (audit-logged server-side). Returns undefined when the entry is gone
315
+ * or the read fails — the editor keeps the redacted draft either way.
316
+ */
317
+ async loadRawContent(id) {
318
+ try {
319
+ const response = await this.requireApi().getRaw({ id });
320
+ if (!response.result.ok) return void 0;
321
+ return response.result.value.entry?.content;
322
+ } catch {
323
+ return void 0;
324
+ }
325
+ }
326
+ /** Delete one entry after the component-level confirmation. */
327
+ async deleteEntry(id) {
328
+ return this.act(async (api) => {
329
+ const response = await api.removeEntry({ id });
330
+ if (!response.result.ok) return { ok: false, message: response.result.error.message };
331
+ if (!response.result.value.removed) return { ok: false, message: response.result.value.error ?? "entry was already gone" };
332
+ await this.refreshAfterMutation();
333
+ return { ok: true };
334
+ });
335
+ }
336
+ /** Toggle one entry's pin. */
337
+ async togglePin(entry) {
338
+ return this.act(async (api) => {
339
+ const response = await api.pin({ id: entry.id, pinned: entry.pinned !== true });
340
+ if (!response.result.ok) return { ok: false, message: response.result.error.message };
341
+ if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "entry was already gone" };
342
+ await this.refreshAfterMutation();
343
+ return { ok: true };
344
+ });
345
+ }
346
+ /** Toggle one entry's dormancy stamp (P1-7 archive semantics). */
347
+ async toggleArchive(entry) {
348
+ return this.act(async (api) => {
349
+ const response = await api.archive({ id: entry.id, archived: entry.staleSince === void 0 });
350
+ if (!response.result.ok) return { ok: false, message: response.result.error.message };
351
+ if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "entry was already gone" };
352
+ await this.refreshAfterMutation();
353
+ return { ok: true };
354
+ });
355
+ }
356
+ /** Re-fetch the pending queue plus whatever list surfaces are live. */
357
+ async refreshPending() {
358
+ try {
359
+ const response = await this.requireApi().suggestList();
360
+ if (response.result.ok) this.set({ pending: response.result.value.suggestions });
361
+ } catch {
362
+ }
363
+ }
364
+ /**
365
+ * Adopt one pending proposal — optionally with "edit before adopt" tweaks.
366
+ * Refreshes the queue AND the entry list (adoption may create or rewrite an
367
+ * entry under the active filters).
368
+ */
369
+ async adoptSuggestion(id, edits) {
370
+ const done = await this.act(async (api) => {
371
+ const response = await api.suggestAdopt({
372
+ id,
373
+ ...edits?.content !== void 0 && edits.content.trim() !== "" ? { content: edits.content } : {},
374
+ ...edits?.category !== void 0 && edits.category !== "" ? { category: edits.category } : {}
375
+ });
376
+ if (!response.result.ok) return { ok: false, message: response.result.error.message };
377
+ if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "proposal was already decided" };
378
+ return { ok: true };
379
+ });
380
+ if (done) {
381
+ this.set({ pending: this.store.getSnapshot().pending.filter((s) => s.id !== id), actionError: null });
382
+ await this.reload();
383
+ }
384
+ return done;
385
+ }
386
+ /** Reject one pending proposal. */
387
+ async rejectSuggestion(id) {
388
+ const done = await this.act(async (api) => {
389
+ const response = await api.suggestReject({ id });
390
+ if (!response.result.ok) return { ok: false, message: response.result.error.message };
391
+ return response.result.value.rejected ? { ok: true } : { ok: false, message: response.result.value.error ?? "proposal was already decided" };
392
+ });
393
+ if (done) this.set({ pending: this.store.getSnapshot().pending.filter((s) => s.id !== id), actionError: null });
394
+ return done;
395
+ }
396
+ /** Post-mutation repaint: health numbers + the visible list + the queue. */
397
+ async refreshAfterMutation() {
398
+ void this.refreshPending();
399
+ try {
400
+ const [health] = await Promise.all([this.requireApi().health()]);
401
+ if (health.result.ok) this.set({ health: health.result.value });
402
+ } catch {
403
+ }
404
+ await this.reload();
405
+ }
406
+ };
407
+ function messageOf(error) {
408
+ return error instanceof Error ? error.message : String(error);
409
+ }
410
+
411
+ // src/client/section-styles.ts
412
+ var RULES = `
413
+ .dsm-s-section {
414
+ display: flex;
415
+ flex-direction: column;
416
+ gap: 16px;
417
+ }
418
+ .dsm-s-title {
419
+ margin: 0;
420
+ font-size: 15px;
421
+ font-weight: 600;
422
+ line-height: 1.4;
423
+ color: var(--dsw-alias-label-primary);
424
+ }
425
+ .dsm-s-intro {
426
+ margin: 0;
427
+ font-size: 13px;
428
+ line-height: 1.5;
429
+ color: var(--dsw-alias-label-tertiary);
430
+ }
431
+
432
+ /* \u2500\u2500 Health dashboard bar \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
433
+ .dsm-s-dash {
434
+ display: flex;
435
+ flex-wrap: wrap;
436
+ align-items: stretch;
437
+ gap: 8px;
438
+ }
439
+ .dsm-s-stat {
440
+ display: flex;
441
+ flex-direction: column;
442
+ justify-content: center;
443
+ gap: 2px;
444
+ min-width: 88px;
445
+ padding: 10px 14px;
446
+ border: 1px solid var(--dsw-alias-border-l2);
447
+ border-radius: 12px;
448
+ background: var(--dsw-alias-bg-layer-3);
449
+ }
450
+ .dsm-s-stat-value {
451
+ font-size: 18px;
452
+ font-weight: 600;
453
+ line-height: 1.3;
454
+ color: var(--dsw-alias-label-primary);
455
+ }
456
+ .dsm-s-stat-value-muted {
457
+ color: var(--dsw-alias-label-secondary);
458
+ }
459
+ .dsm-s-stat-label {
460
+ font-size: 12px;
461
+ line-height: 1.5;
462
+ color: var(--dsw-alias-label-tertiary);
463
+ }
464
+ .dsm-s-stat-stale {
465
+ cursor: help;
466
+ }
467
+
468
+ /* \u2500\u2500 Toolbar \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
469
+ .dsm-s-toolbar {
470
+ display: flex;
471
+ flex-direction: column;
472
+ gap: 10px;
473
+ }
474
+ .dsm-s-toolbar-row {
475
+ display: flex;
476
+ flex-wrap: wrap;
477
+ align-items: center;
478
+ gap: 8px;
479
+ }
480
+ .dsm-s-toolbar-label {
481
+ font-size: 12px;
482
+ font-weight: 500;
483
+ line-height: 1.5;
484
+ color: var(--dsw-alias-label-tertiary);
485
+ }
486
+ /* Segmented scope switch and section tabs share one visual language. */
487
+ .dsm-s-seg,
488
+ .dsm-s-tabs {
489
+ display: inline-flex;
490
+ padding: 2px;
491
+ border: 1px solid var(--dsw-alias-border-l2);
492
+ border-radius: 8px;
493
+ background: var(--dsw-alias-bg-layer-3);
494
+ }
495
+ .dsm-s-seg-btn,
496
+ .dsm-s-tab-btn {
497
+ appearance: none;
498
+ border: 0;
499
+ background: none;
500
+ padding: 4px 12px;
501
+ border-radius: 6px;
502
+ font: inherit;
503
+ font-size: 13px;
504
+ line-height: 1.5;
505
+ color: var(--dsw-alias-label-secondary);
506
+ cursor: pointer;
507
+ }
508
+ .dsm-s-seg-btn:hover:not([aria-pressed="true"]),
509
+ .dsm-s-tab-btn:hover:not([aria-selected="true"]) {
510
+ color: var(--dsw-alias-label-primary);
511
+ }
512
+ .dsm-s-seg-btn[aria-pressed="true"],
513
+ .dsm-s-tab-btn[aria-selected="true"] {
514
+ background: var(--dsw-alias-brand-primary);
515
+ color: var(--dsw-alias-bg-layer-3);
516
+ }
517
+ .dsm-s-tab-btn[aria-selected="true"] {
256
518
  cursor: default;
257
519
  }
258
- /* inputInvalid mirrors .input with an error border (composes: input in host). */
259
- .dsm-c-input-invalid {
520
+ .dsm-s-seg-btn:focus-visible,
521
+ .dsm-s-tab-btn:focus-visible {
522
+ outline: 2px solid var(--dsw-alias-brand-primary);
523
+ outline-offset: -2px;
524
+ }
525
+ /* Search box mirrors the shared .input control look. */
526
+ .dsm-s-input {
527
+ flex: 1;
528
+ min-width: 200px;
529
+ max-width: 360px;
260
530
  height: 34px;
261
531
  padding: 0 12px;
262
- border: 1px solid var(--dsw-alias-label-error);
532
+ border: 1px solid var(--dsw-alias-border-l2);
263
533
  border-radius: 8px;
264
534
  background: var(--dsw-alias-bg-layer-3);
265
535
  font: inherit;
@@ -267,46 +537,240 @@ var RULES = `
267
537
  line-height: 1.5;
268
538
  color: var(--dsw-alias-label-primary);
269
539
  }
270
- .dsm-c-input-invalid:focus-visible {
540
+ .dsm-s-input:focus-visible {
271
541
  outline: none;
272
- border-color: var(--dsw-alias-label-error);
542
+ border-color: var(--dsw-alias-brand-primary);
543
+ }
544
+ /* Workspace selector mirrors the shared .select control look. */
545
+ .dsm-s-select {
546
+ max-width: 260px;
547
+ height: 34px;
548
+ padding: 0 28px 0 12px;
549
+ border: 1px solid var(--dsw-alias-border-l2);
550
+ border-radius: 8px;
551
+ background-color: var(--dsw-alias-bg-layer-3);
552
+ font: inherit;
553
+ font-size: 13px;
554
+ line-height: 1.5;
555
+ color: var(--dsw-alias-label-primary);
556
+ cursor: pointer;
557
+ appearance: none;
558
+ -webkit-appearance: none;
559
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5l4 4 4-4' stroke='%237a7a7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
560
+ background-repeat: no-repeat;
561
+ background-position: right 10px center;
562
+ }
563
+ .dsm-s-select:focus-visible {
564
+ outline: none;
565
+ border-color: var(--dsw-alias-brand-primary);
566
+ }
567
+ .dsm-s-select:disabled {
568
+ color: var(--dsw-alias-label-tertiary);
569
+ cursor: default;
570
+ }
571
+ /* Category chips. */
572
+ .dsm-s-chip {
573
+ appearance: none;
574
+ border: 1px solid var(--dsw-alias-border-l2);
575
+ border-radius: 999px;
576
+ background: var(--dsw-alias-bg-layer-3);
577
+ padding: 3px 12px;
578
+ font: inherit;
579
+ font-size: 12px;
580
+ line-height: 1.5;
581
+ color: var(--dsw-alias-label-secondary);
582
+ cursor: pointer;
583
+ }
584
+ .dsm-s-chip:hover {
585
+ color: var(--dsw-alias-label-primary);
586
+ border-color: var(--dsw-alias-label-dimmed);
587
+ }
588
+ .dsm-s-chip[aria-pressed="true"] {
589
+ background: var(--dsw-alias-bg-module-platform);
590
+ border-color: var(--dsw-alias-brand-primary);
591
+ color: var(--dsw-alias-label-primary);
592
+ }
593
+ .dsm-s-chip:focus-visible {
594
+ outline: 2px solid var(--dsw-alias-brand-primary);
595
+ outline-offset: 1px;
596
+ }
597
+
598
+ /* \u2500\u2500 Entry list \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
599
+ .dsm-s-list {
600
+ list-style: none;
601
+ margin: 0;
602
+ padding: 0;
603
+ display: flex;
604
+ flex-direction: column;
605
+ gap: 8px;
606
+ }
607
+ .dsm-s-row {
608
+ display: flex;
609
+ flex-direction: column;
610
+ gap: 6px;
611
+ padding: 12px 14px;
612
+ border: 1px solid var(--dsw-alias-border-l2);
613
+ border-radius: 12px;
614
+ background: var(--dsw-alias-bg-layer-3);
615
+ }
616
+ .dsm-s-row-stale {
617
+ opacity: 0.62;
618
+ }
619
+ .dsm-s-badges {
620
+ display: inline-flex;
621
+ align-items: center;
622
+ flex-wrap: wrap;
623
+ gap: 6px;
624
+ }
625
+ .dsm-s-badge {
626
+ border-radius: 999px;
627
+ padding: 1px 8px;
628
+ font-size: 11px;
629
+ line-height: 17px;
630
+ white-space: nowrap;
631
+ font-weight: 500;
632
+ background: var(--dsw-alias-bg-module-platform);
633
+ color: var(--dsw-alias-label-secondary);
634
+ }
635
+ .dsm-s-badge-pinned,
636
+ .dsm-s-badge-stale {
637
+ background: none;
638
+ padding-left: 0;
639
+ }
640
+ .dsm-s-project {
641
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
642
+ font-size: 11px;
643
+ line-height: 17px;
644
+ color: var(--dsw-alias-label-tertiary);
645
+ }
646
+ .dsm-s-content {
647
+ margin: 0;
648
+ font-size: 13px;
649
+ line-height: 1.55;
650
+ color: var(--dsw-alias-label-primary);
651
+ white-space: pre-wrap;
652
+ word-break: break-word;
653
+ cursor: pointer;
654
+ display: -webkit-box;
655
+ -webkit-box-orient: vertical;
656
+ -webkit-line-clamp: 2;
657
+ overflow: hidden;
658
+ }
659
+ .dsm-s-content-open {
660
+ display: block;
661
+ -webkit-line-clamp: none;
662
+ overflow: visible;
663
+ cursor: text;
664
+ }
665
+ .dsm-s-meta {
666
+ display: flex;
667
+ flex-wrap: wrap;
668
+ gap: 4px 14px;
669
+ margin: 0;
670
+ font-size: 11px;
671
+ line-height: 1.5;
672
+ color: var(--dsw-alias-label-tertiary);
673
+ }
674
+
675
+ /* \u2500\u2500 Lazy-load footer / empty / error \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
676
+ .dsm-s-more {
677
+ display: flex;
678
+ flex-direction: column;
679
+ align-items: center;
680
+ gap: 8px;
681
+ }
682
+ .dsm-s-count {
683
+ margin: 0;
684
+ font-size: 12px;
685
+ line-height: 1.5;
686
+ color: var(--dsw-alias-label-tertiary);
687
+ }
688
+ .dsm-s-sentinel {
689
+ width: 100%;
690
+ height: 1px;
691
+ }
692
+ .dsm-s-more-btn {
693
+ appearance: none;
694
+ border: 1px solid var(--dsw-alias-border-l2);
695
+ border-radius: 8px;
696
+ background: var(--dsw-alias-bg-layer-3);
697
+ padding: 4px 12px;
698
+ font: inherit;
699
+ font-size: 13px;
700
+ line-height: 1.5;
701
+ color: var(--dsw-alias-label-secondary);
702
+ cursor: pointer;
703
+ }
704
+ .dsm-s-more-btn:hover:not(:disabled) {
705
+ color: var(--dsw-alias-label-primary);
706
+ border-color: var(--dsw-alias-label-dimmed);
707
+ }
708
+ .dsm-s-more-btn:disabled {
709
+ opacity: 0.4;
710
+ cursor: default;
273
711
  }
274
- .dsm-c-input-invalid:disabled {
712
+ .dsm-s-empty {
713
+ margin: 24px 0;
714
+ text-align: center;
715
+ font-size: 13px;
716
+ line-height: 1.6;
275
717
  color: var(--dsw-alias-label-tertiary);
276
- cursor: default;
718
+ }
719
+ .dsm-s-error {
720
+ margin: 0;
721
+ font-size: 12px;
722
+ line-height: 1.5;
723
+ color: var(--dsw-alias-label-error);
277
724
  }
278
725
 
279
- /* select mirrors .input; native arrow kept via appearance. */
280
- .dsm-c-select {
281
- height: 34px;
282
- padding: 0 28px 0 12px;
726
+ /* \u2500\u2500 Phase-2 write path: row actions / editor / review queue \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
727
+ .dsm-s-actions {
728
+ display: flex;
729
+ flex-wrap: wrap;
730
+ align-items: center;
731
+ gap: 6px;
732
+ }
733
+ .dsm-s-action-btn {
734
+ appearance: none;
283
735
  border: 1px solid var(--dsw-alias-border-l2);
284
736
  border-radius: 8px;
285
737
  background: var(--dsw-alias-bg-layer-3);
738
+ padding: 2px 10px;
286
739
  font: inherit;
287
- font-size: 13px;
288
- line-height: 1.5;
289
- color: var(--dsw-alias-label-primary);
740
+ font-size: 12px;
741
+ line-height: 20px;
742
+ color: var(--dsw-alias-label-secondary);
290
743
  cursor: pointer;
291
- appearance: none;
292
- -webkit-appearance: none;
293
- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5l4 4 4-4' stroke='%237a7a7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
294
- background-repeat: no-repeat;
295
- background-position: right 10px center;
296
744
  }
297
- .dsm-c-select:focus-visible {
298
- outline: none;
299
- border-color: var(--dsw-alias-brand-primary);
745
+ .dsm-s-action-btn:hover:not(:disabled) {
746
+ color: var(--dsw-alias-label-primary);
747
+ border-color: var(--dsw-alias-label-dimmed);
300
748
  }
301
- .dsm-c-select:disabled {
302
- color: var(--dsw-alias-label-tertiary);
749
+ .dsm-s-action-btn:disabled {
750
+ opacity: 0.45;
303
751
  cursor: default;
304
752
  }
305
-
306
- /* textarea mirrors .input borders, multi-line sizing. */
307
- .dsm-c-textarea {
308
- min-height: 80px;
309
- padding: 8px 12px;
753
+ .dsm-s-action-btn:focus-visible {
754
+ outline: 2px solid var(--dsw-alias-brand-primary);
755
+ outline-offset: -2px;
756
+ }
757
+ .dsm-s-action-btn-danger {
758
+ color: var(--dsw-alias-label-error);
759
+ }
760
+ .dsm-s-badge-hits {
761
+ background: var(--dsw-alias-brand-primary);
762
+ color: var(--dsw-alias-bg-layer-3);
763
+ }
764
+ .dsm-s-edit-form {
765
+ display: flex;
766
+ flex-direction: column;
767
+ gap: 8px;
768
+ }
769
+ .dsm-s-textarea,
770
+ .dsm-s-field {
771
+ width: 100%;
772
+ box-sizing: border-box;
773
+ padding: 6px 12px;
310
774
  border: 1px solid var(--dsw-alias-border-l2);
311
775
  border-radius: 8px;
312
776
  background: var(--dsw-alias-bg-layer-3);
@@ -314,1041 +778,933 @@ var RULES = `
314
778
  font-size: 13px;
315
779
  line-height: 1.5;
316
780
  color: var(--dsw-alias-label-primary);
781
+ }
782
+ .dsm-s-textarea {
783
+ min-height: 64px;
317
784
  resize: vertical;
318
785
  }
319
- .dsm-c-textarea:focus-visible {
786
+ .dsm-s-textarea:focus-visible,
787
+ .dsm-s-field:focus-visible {
320
788
  outline: none;
321
789
  border-color: var(--dsw-alias-brand-primary);
322
790
  }
323
- .dsm-c-textarea:disabled {
324
- color: var(--dsw-alias-label-tertiary);
325
- cursor: default;
326
- }
327
-
328
- /* A checkbox row: the box and its label sit on the head line so the override
329
- badge + reset stay right-aligned exactly as the text fields do. */
330
- .dsm-c-check-row {
791
+ .dsm-s-form-row {
331
792
  display: flex;
793
+ flex-wrap: wrap;
332
794
  align-items: center;
333
795
  gap: 8px;
334
- flex: 1;
335
- min-width: 0;
336
796
  }
337
- .dsm-c-checkbox {
338
- flex: none;
339
- width: 16px;
340
- height: 16px;
797
+ .dsm-s-review-head {
341
798
  margin: 0;
342
- accent-color: var(--dsw-alias-brand-primary);
343
- cursor: pointer;
344
- }
345
- .dsm-c-checkbox:disabled {
346
- cursor: default;
347
- }
348
- .dsm-c-check-label {
349
799
  font-size: 13px;
350
800
  font-weight: 500;
351
801
  line-height: 1.5;
352
- color: var(--dsw-alias-label-primary);
353
- cursor: pointer;
354
- }
355
- .dsm-c-check-label:disabled,
356
- .dsm-c-checkbox:disabled + .dsm-c-check-label {
357
- color: var(--dsw-alias-label-tertiary);
358
- cursor: default;
359
- }
360
-
361
- .dsm-c-invalid {
362
- margin: 0;
363
- font-size: 12px;
364
- line-height: 1.5;
365
- color: var(--dsw-alias-label-error);
366
- }
367
- .dsm-c-hint {
368
- margin: 0;
369
- font-size: 12px;
370
- line-height: 1.5;
371
- color: var(--dsw-alias-label-tertiary);
802
+ color: var(--dsw-alias-label-secondary);
372
803
  }
373
804
  `;
805
+ var cls = {
806
+ section: "dsm-s-section",
807
+ title: "dsm-s-title",
808
+ intro: "dsm-s-intro",
809
+ dash: "dsm-s-dash",
810
+ stat: "dsm-s-stat",
811
+ statValue: "dsm-s-stat-value",
812
+ statValueMuted: "dsm-s-stat-value-muted",
813
+ statLabel: "dsm-s-stat-label",
814
+ statStale: "dsm-s-stat-stale",
815
+ toolbar: "dsm-s-toolbar",
816
+ toolbarRow: "dsm-s-toolbar-row",
817
+ toolbarLabel: "dsm-s-toolbar-label",
818
+ seg: "dsm-s-seg",
819
+ segBtn: "dsm-s-seg-btn",
820
+ tabs: "dsm-s-tabs",
821
+ tabBtn: "dsm-s-tab-btn",
822
+ input: "dsm-s-input",
823
+ select: "dsm-s-select",
824
+ chip: "dsm-s-chip",
825
+ list: "dsm-s-list",
826
+ row: "dsm-s-row",
827
+ rowStale: "dsm-s-row-stale",
828
+ badges: "dsm-s-badges",
829
+ badge: "dsm-s-badge",
830
+ badgePinned: "dsm-s-badge-pinned",
831
+ badgeStale: "dsm-s-badge-stale",
832
+ project: "dsm-s-project",
833
+ content: "dsm-s-content",
834
+ contentOpen: "dsm-s-content-open",
835
+ meta: "dsm-s-meta",
836
+ more: "dsm-s-more",
837
+ count: "dsm-s-count",
838
+ sentinel: "dsm-s-sentinel",
839
+ moreBtn: "dsm-s-more-btn",
840
+ empty: "dsm-s-empty",
841
+ error: "dsm-s-error",
842
+ actions: "dsm-s-actions",
843
+ actionBtn: "dsm-s-action-btn",
844
+ actionBtnDanger: "dsm-s-action-btn-danger",
845
+ badgeHits: "dsm-s-badge-hits",
846
+ editForm: "dsm-s-edit-form",
847
+ textarea: "dsm-s-textarea",
848
+ field: "dsm-s-field",
849
+ formRow: "dsm-s-form-row",
850
+ reviewHead: "dsm-s-review-head"
851
+ };
374
852
  var injected = false;
375
853
  function inject() {
376
854
  if (injected || typeof document === "undefined") return;
377
855
  const style = document.createElement("style");
378
- style.setAttribute("data-dsh-memory", "plugin-card");
856
+ style.setAttribute("data-dsh-memory", "section");
379
857
  style.textContent = RULES;
380
858
  document.head.appendChild(style);
381
859
  injected = true;
382
860
  }
383
- var cls = {
384
- // Card shell (PluginCard.module.css).
385
- card: "dsm-c-card",
386
- cardOpen: "dsm-c-card-open",
387
- header: "dsm-c-header",
388
- headText: "dsm-c-head-text",
389
- name: "dsm-c-name",
390
- description: "dsm-c-description",
391
- pending: "dsm-c-pending",
392
- chevron: "dsm-c-chevron",
393
- chevronOpen: "dsm-c-chevron-open",
394
- body: "dsm-c-body",
395
- readOnly: "dsm-c-read-only",
396
- footer: "dsm-c-footer",
397
- failed: "dsm-c-failed",
398
- discard: "dsm-c-discard",
399
- save: "dsm-c-save",
400
- // Fields (fields.module.css).
401
- field: "dsm-c-field",
402
- head: "dsm-c-head",
403
- label: "dsm-c-label",
404
- badges: "dsm-c-badges",
405
- badge: "dsm-c-badge",
406
- reset: "dsm-c-reset",
407
- input: "dsm-c-input",
408
- inputInvalid: "dsm-c-input-invalid",
409
- badgeMuted: "dsm-c-badge-muted",
410
- select: "dsm-c-select",
411
- textarea: "dsm-c-textarea",
412
- checkRow: "dsm-c-check-row",
413
- checkbox: "dsm-c-checkbox",
414
- checkLabel: "dsm-c-check-label",
415
- invalid: "dsm-c-invalid",
416
- hint: "dsm-c-hint"
417
- };
418
861
  var css = (inject(), cls);
419
862
 
420
- // src/client/fields.tsx
421
- var import_jsx_runtime = require("react/jsx-runtime");
422
- function FieldHead(props) {
423
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.head, children: [
424
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: css.label, htmlFor: props.id, children: props.label }),
425
- props.overridden ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.badges, children: [
426
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: props.overriddenLabel }),
427
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })
428
- ] }) : null
429
- ] });
430
- }
431
- function SelectField(props) {
432
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.field, children: [
433
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldHead, { ...props }),
434
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
435
- "select",
436
- {
437
- id: props.id,
438
- className: css.select,
439
- value: props.value,
440
- disabled: props.disabled,
441
- onChange: (e) => props.onChange(e.target.value),
442
- children: props.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: o.value, children: o.label }, o.value))
443
- }
444
- ),
445
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.hint, children: props.hint })
446
- ] });
447
- }
448
- function TextField(props) {
449
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.field, children: [
450
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldHead, { ...props }),
451
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
452
- "input",
453
- {
454
- id: props.id,
455
- className: css.input,
456
- type: "text",
457
- value: props.value,
458
- disabled: props.disabled,
459
- onChange: (e) => props.onChange(e.target.value)
460
- }
461
- ),
462
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.hint, children: props.hint })
463
- ] });
464
- }
465
- function NumberField(props) {
466
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.field, children: [
467
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldHead, { ...props }),
468
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
469
- "input",
470
- {
471
- id: props.id,
472
- className: props.invalid ? css.inputInvalid : css.input,
473
- type: "text",
474
- inputMode: "numeric",
475
- ...props.invalid ? { "aria-invalid": true } : {},
476
- value: String(props.value),
477
- disabled: props.disabled,
478
- onChange: (e) => props.onChange(e.target.value)
479
- }
480
- ),
481
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: props.invalid ? css.invalid : css.hint, children: props.invalid ? props.invalidLabel : props.hint })
482
- ] });
863
+ // src/client/MemorySection.tsx
864
+ var import_jsx_runtime = require("react/jsx-runtime");
865
+ var SCOPES = [
866
+ { value: "all", labelKey: "scopeAll" },
867
+ { value: "global", labelKey: "scopeGlobal" },
868
+ { value: "project", labelKey: "scopeProject" },
869
+ { value: "user", labelKey: "scopeUser" }
870
+ ];
871
+ function formatTs(ts, fallback) {
872
+ return ts === void 0 || ts === null ? fallback : new Date(ts).toLocaleString();
483
873
  }
484
- function CheckboxField(props) {
485
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.field, children: [
486
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.head, children: [
487
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.checkRow, children: [
488
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
489
- "input",
490
- {
491
- id: props.id,
492
- type: "checkbox",
493
- className: css.checkbox,
494
- checked: props.checked,
495
- disabled: props.disabled,
496
- onChange: (e) => props.onChange(e.target.checked)
497
- }
498
- ),
499
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: css.checkLabel, htmlFor: props.id, children: props.label })
500
- ] }),
501
- props.overridden ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.badges, children: [
502
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: props.overriddenLabel }),
503
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })
504
- ] }) : null
505
- ] }),
506
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.hint, children: props.hint })
507
- ] });
874
+ var NO_CATEGORY = "";
875
+ function emptyKeyOf(state) {
876
+ if (state.query.trim() !== "" || state.categories.length > 0) return "emptyFiltered";
877
+ if (state.scope === "global") return "emptyGlobal";
878
+ if (state.scope === "user") return "emptyUser";
879
+ if (state.scope === "project") return "emptyProject";
880
+ return "emptyAll";
508
881
  }
509
- function TextareaField(props) {
510
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.field, children: [
511
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldHead, { ...props }),
882
+ function EntryEditor(props) {
883
+ const { entry, translate, loadRaw, onSave, onCancel } = props;
884
+ const [draftContent, setDraftContent] = (0, import_react.useState)(entry.content);
885
+ (0, import_react.useEffect)(() => {
886
+ let alive = true;
887
+ loadRaw(entry.id).then((raw) => {
888
+ if (alive && raw !== void 0) setDraftContent(raw);
889
+ }).catch(() => {
890
+ });
891
+ return () => {
892
+ alive = false;
893
+ };
894
+ }, [entry.id, loadRaw]);
895
+ const [draftCategory, setDraftCategory] = (0, import_react.useState)(entry.category ?? NO_CATEGORY);
896
+ const [draftSummary, setDraftSummary] = (0, import_react.useState)(entry.summary ?? "");
897
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.editForm, children: [
512
898
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
513
899
  "textarea",
514
900
  {
515
- id: props.id,
516
901
  className: css.textarea,
517
- value: props.value,
518
- disabled: props.disabled,
519
- rows: 4,
520
- onChange: (e) => props.onChange(e.target.value)
521
- }
522
- ),
523
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.hint, children: props.hint })
524
- ] });
525
- }
526
-
527
- // src/client/MemoryPluginCard.tsx
528
- var import_jsx_runtime2 = require("react/jsx-runtime");
529
- var MODES = ["digest", "policy-only", "full", "index", "custom", "off"];
530
- var DEFAULTS = {
531
- memoryMode: "digest",
532
- memoryPolicyCustomText: "",
533
- memoryCharLimit: 5e3,
534
- memoryDigestCharLimit: 800,
535
- memoryMaxEntries: 20,
536
- maxSearchResults: 50,
537
- decayDays: 30
538
- };
539
- var NUMERIC_FIELDS = ["memoryCharLimit", "memoryDigestCharLimit", "memoryMaxEntries", "maxSearchResults", "decayDays"];
540
- function isOverridden(snap, field) {
541
- const user = snap.user;
542
- if (user === void 0 || user === null || typeof user !== "object") return false;
543
- return Object.prototype.hasOwnProperty.call(user, field);
544
- }
545
- function MemoryPluginCard(props) {
546
- const snap = props.useMemory((s) => s);
547
- const t = props.t;
548
- const [open, setOpen] = (0, import_react.useState)(false);
549
- const committed = snap.value ?? {};
550
- const [draft, setDraft] = (0, import_react.useState)({ ...DEFAULTS, ...committed });
551
- const [saving, setSaving] = (0, import_react.useState)(false);
552
- const [failed, setFailed] = (0, import_react.useState)(false);
553
- (0, import_react.useEffect)(() => {
554
- setDraft({ ...DEFAULTS, ...committed });
555
- setFailed(false);
556
- }, [committed]);
557
- const edit = (field, value) => {
558
- setFailed(false);
559
- setDraft((prev) => ({ ...prev, [field]: value }));
560
- };
561
- const numericInvalid = (field) => {
562
- const v = draft[field];
563
- if (v === void 0 || v === null) return false;
564
- const n = Number(v);
565
- return !Number.isFinite(n) || n < 0;
566
- };
567
- const dirty = JSON.stringify(draft) !== JSON.stringify({ ...DEFAULTS, ...committed });
568
- const invalid = NUMERIC_FIELDS.some(numericInvalid);
569
- const disabled = !snap.writable;
570
- const blocked = !dirty || invalid || saving;
571
- if (snap.status !== "ready") return null;
572
- const save = async () => {
573
- setSaving(true);
574
- setFailed(false);
575
- try {
576
- const ops = [];
577
- for (const key of Object.keys(DEFAULTS)) {
578
- if (draft[key] === committed[key]) continue;
579
- const value = draft[key];
580
- ops.push(value === void 0 ? props.unset(key) : props.set(key, value));
581
- }
582
- await Promise.all(ops);
583
- } catch {
584
- setFailed(true);
585
- } finally {
586
- setSaving(false);
587
- }
588
- };
589
- const discard = () => {
590
- setDraft({ ...DEFAULTS, ...committed });
591
- setFailed(false);
592
- };
593
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { className: `${css.card}${open ? ` ${css.cardOpen}` : ""}`, children: [
594
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
595
- "button",
596
- {
597
- type: "button",
598
- className: css.header,
599
- "aria-expanded": open,
600
- "aria-label": `${t(open ? "collapse" : "expand")}: ${t("cardTitle")}`,
601
- onClick: () => {
602
- setOpen(!open);
603
- },
604
- children: [
605
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: css.headText, children: [
606
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.name, children: t("cardTitle") }),
607
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.description, children: t("cardDescription") })
608
- ] }),
609
- dirty ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.pending, children: t("unsaved") }) : null,
610
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives.IconChevronDownOutline14, { className: `${css.chevron}${open ? ` ${css.chevronOpen}` : ""}` })
611
- ]
902
+ "aria-label": translate("editContent"),
903
+ value: draftContent,
904
+ onChange: (event) => {
905
+ setDraftContent(event.target.value);
906
+ }
612
907
  }
613
908
  ),
614
- open ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.body, children: [
615
- !snap.writable ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.readOnly, role: "status", children: t("readOnly") }) : null,
616
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
617
- SelectField,
618
- {
619
- id: "dsh-memory-mode",
620
- label: t("memoryMode"),
621
- hint: t("memoryModeHint"),
622
- overridden: isOverridden(snap, "memoryMode"),
623
- overriddenLabel: t("overridden"),
624
- resetLabel: t("reset"),
625
- disabled,
626
- value: draft.memoryMode ?? "digest",
627
- options: MODES.map((m) => ({ value: m, label: m })),
628
- onChange: (v) => edit("memoryMode", v),
629
- onReset: () => {
630
- void props.unset("memoryMode");
631
- edit("memoryMode", void 0);
632
- }
633
- }
634
- ),
635
- draft.memoryMode === "custom" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
636
- TextareaField,
637
- {
638
- id: "dsh-memory-custom-policy",
639
- label: t("customPolicy"),
640
- hint: t("customPolicyHint"),
641
- overridden: isOverridden(snap, "memoryPolicyCustomText"),
642
- overriddenLabel: t("overridden"),
643
- resetLabel: t("reset"),
644
- disabled,
645
- value: draft.memoryPolicyCustomText ?? "",
646
- onChange: (v) => edit("memoryPolicyCustomText", v),
647
- onReset: () => {
648
- void props.unset("memoryPolicyCustomText");
649
- edit("memoryPolicyCustomText", void 0);
650
- }
651
- }
652
- ) : null,
653
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
654
- NumberField,
655
- {
656
- id: "dsh-memory-char-limit",
657
- label: t("charLimit"),
658
- hint: t("charLimitHint"),
659
- overridden: isOverridden(snap, "memoryCharLimit"),
660
- overriddenLabel: t("overridden"),
661
- resetLabel: t("reset"),
662
- invalidLabel: t("invalidNumber"),
663
- invalid: numericInvalid("memoryCharLimit"),
664
- disabled,
665
- value: draft.memoryCharLimit ?? "",
666
- onChange: (v) => edit("memoryCharLimit", v === "" ? void 0 : Number(v)),
667
- onReset: () => {
668
- void props.unset("memoryCharLimit");
669
- edit("memoryCharLimit", void 0);
670
- }
671
- }
672
- ),
673
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
674
- NumberField,
675
- {
676
- id: "dsh-memory-digest-char-limit",
677
- label: t("digestCharLimit"),
678
- hint: t("digestCharLimitHint"),
679
- overridden: isOverridden(snap, "memoryDigestCharLimit"),
680
- overriddenLabel: t("overridden"),
681
- resetLabel: t("reset"),
682
- invalidLabel: t("invalidNumber"),
683
- invalid: numericInvalid("memoryDigestCharLimit"),
684
- disabled,
685
- value: draft.memoryDigestCharLimit ?? "",
686
- onChange: (v) => edit("memoryDigestCharLimit", v === "" ? void 0 : Number(v)),
687
- onReset: () => {
688
- void props.unset("memoryDigestCharLimit");
689
- edit("memoryDigestCharLimit", void 0);
690
- }
691
- }
692
- ),
693
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
694
- NumberField,
909
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.formRow, children: [
910
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
911
+ "select",
695
912
  {
696
- id: "dsh-memory-max-entries",
697
- label: t("memoryMaxEntries"),
698
- hint: t("memoryMaxEntriesHint"),
699
- overridden: isOverridden(snap, "memoryMaxEntries"),
700
- overriddenLabel: t("overridden"),
701
- resetLabel: t("reset"),
702
- invalidLabel: t("invalidNumber"),
703
- invalid: numericInvalid("memoryMaxEntries"),
704
- disabled,
705
- value: draft.memoryMaxEntries ?? "",
706
- onChange: (v) => edit("memoryMaxEntries", v === "" ? void 0 : Number(v)),
707
- onReset: () => {
708
- void props.unset("memoryMaxEntries");
709
- edit("memoryMaxEntries", void 0);
710
- }
913
+ className: css.select,
914
+ "aria-label": translate("editCategory"),
915
+ value: draftCategory,
916
+ onChange: (event) => {
917
+ setDraftCategory(event.target.value);
918
+ },
919
+ children: [
920
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: NO_CATEGORY, children: translate("noCategory") }),
921
+ MEMORY_CATEGORIES.map((category) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: category, children: translate(CATEGORY_LABEL_KEYS[category] ?? category) }, category))
922
+ ]
711
923
  }
712
924
  ),
713
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
714
- NumberField,
925
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
926
+ "input",
715
927
  {
716
- id: "dsh-memory-max-search",
717
- label: t("maxSearchResults"),
718
- hint: t("maxSearchResultsHint"),
719
- overridden: isOverridden(snap, "maxSearchResults"),
720
- overriddenLabel: t("overridden"),
721
- resetLabel: t("reset"),
722
- invalidLabel: t("invalidNumber"),
723
- invalid: numericInvalid("maxSearchResults"),
724
- disabled,
725
- value: draft.maxSearchResults ?? "",
726
- onChange: (v) => edit("maxSearchResults", v === "" ? void 0 : Number(v)),
727
- onReset: () => {
728
- void props.unset("maxSearchResults");
729
- edit("maxSearchResults", void 0);
928
+ className: css.field,
929
+ type: "text",
930
+ "aria-label": translate("editSummary"),
931
+ placeholder: translate("editSummaryPlaceholder"),
932
+ value: draftSummary,
933
+ onChange: (event) => {
934
+ setDraftSummary(event.target.value);
730
935
  }
731
936
  }
732
- ),
733
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
734
- NumberField,
937
+ )
938
+ ] }),
939
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.actions, children: [
940
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
941
+ "button",
735
942
  {
736
- id: "dsh-memory-decay-days",
737
- label: t("decayDays"),
738
- hint: t("decayDaysHint"),
739
- overridden: isOverridden(snap, "decayDays"),
740
- overriddenLabel: t("overridden"),
741
- resetLabel: t("reset"),
742
- invalidLabel: t("invalidNumber"),
743
- invalid: numericInvalid("decayDays"),
744
- disabled,
745
- value: draft.decayDays ?? "",
746
- onChange: (v) => edit("decayDays", v === "" ? void 0 : Number(v)),
747
- onReset: () => {
748
- void props.unset("decayDays");
749
- edit("decayDays", void 0);
750
- }
943
+ type: "button",
944
+ className: css.actionBtn,
945
+ disabled: draftContent.trim() === "",
946
+ onClick: () => {
947
+ onSave({
948
+ content: draftContent,
949
+ // '' selects "none": pass null so the controller clears the field;
950
+ // an untouched pick passes the current value through.
951
+ category: draftCategory === NO_CATEGORY ? null : draftCategory,
952
+ summary: draftSummary
953
+ });
954
+ },
955
+ children: translate("saveEdits")
751
956
  }
752
957
  ),
753
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.footer, children: [
754
- failed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.failed, role: "status", children: t("saveFailed") }) : null,
755
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: css.discard, disabled: !dirty || saving, onClick: discard, children: t("discard") }),
756
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: css.save, disabled: blocked, onClick: () => void save(), children: t(saving ? "saving" : "save") })
757
- ] })
758
- ] }) : null
958
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.actionBtn, onClick: onCancel, children: translate("cancelEdits") })
959
+ ] })
759
960
  ] });
760
961
  }
761
-
762
- // src/client/MemorySection.tsx
763
- var import_react2 = require("react");
764
-
765
- // src/client/memory-section-store.ts
766
- var import_dsh_client_store = require("@deepseek-ai/dsh-client-store");
767
- var MEMORY_BATCH_SIZE = 50;
768
- var MEMORY_CATEGORIES = [
769
- "failure",
770
- "correction",
771
- "insight",
772
- "preference",
773
- "convention",
774
- "tool-quirk",
775
- "procedure"
776
- ];
777
- var CATEGORY_LABEL_KEYS = {
778
- failure: "catFailure",
779
- correction: "catCorrection",
780
- insight: "catInsight",
781
- preference: "catPreference",
782
- convention: "catConvention",
783
- "tool-quirk": "catToolQuirk",
784
- procedure: "catProcedure"
785
- };
786
- var INITIAL = {
787
- status: "idle",
788
- error: null,
789
- health: null,
790
- projects: [],
791
- entries: [],
792
- total: 0,
793
- loadingMore: false,
794
- scope: "all",
795
- projectName: null,
796
- query: "",
797
- categories: [],
798
- pending: [],
799
- actionError: null
800
- };
801
- function projectSelectable(scope) {
802
- return scope === "all" || scope === "project";
803
- }
804
- var MemorySectionController = class {
805
- /**
806
- * @param api - the mounted `memoryRemote` namespace face; undefined on a
807
- * deployment too old to serve it — loads then fail into the page's error
808
- * state instead of breaking the settings panel.
809
- */
810
- constructor(api) {
811
- this.api = api;
812
- }
813
- api;
814
- /** Page snapshot the renderer subscribes to. */
815
- store = (0, import_dsh_client_store.createSnapshotStore)(INITIAL);
816
- /** Guards against overlapping loads painting partial results. */
817
- seq = 0;
818
- /**
819
- * Full match set behind the active query/chips, cached between local
820
- * reveals; null whenever plain browsing applies. See {@link fetchFirstBatch}.
821
- */
822
- matches = null;
823
- set(patch) {
824
- this.store.set({ ...this.store.getSnapshot(), ...patch });
825
- }
826
- /** Wire scope for the current filter, or undefined for "all". */
827
- wireScope() {
828
- const { scope } = this.store.getSnapshot();
829
- return scope === "all" ? void 0 : scope;
830
- }
831
- /**
832
- * Shared wire filter fields (scope + workspace) from the current snapshot.
833
- */
834
- wireFilters() {
835
- const snapshot = this.store.getSnapshot();
836
- const scope = this.wireScope();
837
- return {
838
- ...scope !== void 0 ? { scope } : {},
839
- ...snapshot.projectName !== null && snapshot.projectName !== "" ? { projectName: snapshot.projectName } : {}
840
- };
841
- }
842
- requireApi() {
843
- if (this.api === void 0) throw new Error("the memory remote namespace is not mounted on this connection");
844
- return this.api;
845
- }
846
- /**
847
- * Fetch the first batch under the committed filters. Plain browsing pages
848
- * remotely; an active query or chip set pulls the whole match set once
849
- * (search has no offset on the wire), caches it for local reveals, and
850
- * unions multi-chip selections client-side (the wire takes one category).
851
- */
852
- async fetchFirstBatch() {
853
- const snapshot = this.store.getSnapshot();
854
- const trimmed = snapshot.query.trim();
855
- if (trimmed !== "" || snapshot.categories.length > 0) {
856
- const response2 = await this.requireApi().search({
857
- ...this.wireFilters(),
858
- ...trimmed !== "" ? { query: trimmed } : {},
859
- limit: 0
860
- });
861
- if (!response2.result.ok) throw new Error(response2.result.error.message);
862
- const selected = snapshot.categories;
863
- const matches = selected.length === 0 ? [...response2.result.value.entries] : response2.result.value.entries.filter(
864
- (entry) => entry.category !== void 0 && selected.includes(entry.category)
865
- );
866
- this.matches = matches;
867
- return { entries: matches.slice(0, MEMORY_BATCH_SIZE), total: matches.length };
868
- }
869
- this.matches = null;
870
- const response = await this.requireApi().list({
871
- ...this.wireFilters(),
872
- limit: MEMORY_BATCH_SIZE,
873
- offset: 0
874
- });
875
- if (!response.result.ok) throw new Error(response.result.error.message);
876
- return { entries: response.result.value.entries, total: response.result.value.total };
877
- }
878
- /**
879
- * Full load: health dashboard, workspace roster, current page, and the
880
- * pending-review queue. Used on section open, manual retry, and connection
881
- * recovery.
882
- * @returns once the snapshot reflects the host.
883
- */
884
- async load() {
885
- const ticket = ++this.seq;
886
- if (this.store.getSnapshot().status === "idle") this.set({ status: "loading" });
887
- try {
888
- const api = this.requireApi();
889
- const [health, projects, batch] = await Promise.all([
890
- api.health(),
891
- api.projects(),
892
- this.fetchFirstBatch()
893
- ]);
894
- if (!health.result.ok) throw new Error(health.result.error.message);
895
- if (!projects.result.ok) throw new Error(projects.result.error.message);
896
- const pendingRows = typeof api.suggestList !== "function" ? [] : await api.suggestList().then(
897
- (response) => response.result.ok ? response.result.value.suggestions : [],
898
- () => []
899
- );
900
- if (ticket !== this.seq) return;
901
- this.set({
902
- status: "ready",
903
- error: null,
904
- health: health.result.value,
905
- projects: projects.result.value.projects,
906
- entries: batch.entries,
907
- total: batch.total,
908
- pending: pendingRows
909
- });
910
- } catch (error) {
911
- if (ticket !== this.seq) return;
912
- this.set({ status: "error", error: messageOf(error) });
913
- }
914
- }
915
- /**
916
- * Re-fetch the first batch (filters changed). Resets the accumulated list;
917
- * keeps the dashboard and status untouched, and a failure surfaces as
918
- * page-level error text while the previous rows stay visible.
919
- */
920
- async reload() {
921
- const ticket = ++this.seq;
922
- try {
923
- const batch = await this.fetchFirstBatch();
924
- if (ticket !== this.seq) return;
925
- this.set({ status: "ready", error: null, entries: batch.entries, total: batch.total, loadingMore: false });
926
- } catch (error) {
927
- if (ticket !== this.seq) return;
928
- this.set({ error: messageOf(error), loadingMore: false });
929
- }
930
- }
931
- /** Switch the scope filter; the workspace pick cannot outlive its scope. */
932
- setScope(scope) {
933
- if (this.store.getSnapshot().scope === scope) return;
934
- this.set({ scope, projectName: null });
935
- void this.reload();
936
- }
937
- /**
938
- * Pick one workspace (or null/'' for all). Only honored where it means
939
- * something — see {@link projectSelectable}.
940
- */
941
- setProject(projectName) {
942
- if (!projectSelectable(this.store.getSnapshot().scope)) return;
943
- const next = projectName === "" ? null : projectName;
944
- if (this.store.getSnapshot().projectName === next) return;
945
- this.set({ projectName: next });
946
- void this.reload();
947
- }
948
- /** Commit a search text (already debounced upstream); empty clears it. */
949
- commitQuery(query) {
950
- if (this.store.getSnapshot().query === query) return;
951
- this.set({ query });
952
- void this.reload();
953
- }
954
- /** Flip one category chip. */
955
- toggleCategory(category) {
956
- const selected = this.store.getSnapshot().categories;
957
- const next = selected.includes(category) ? selected.filter((c) => c !== category) : [...selected, category];
958
- this.set({ categories: next });
959
- void this.reload();
960
- }
961
- /**
962
- * Append the next chunk to the visible list. Plain browsing issues one
963
- * remote batch; an active search reveals more of the cached full match
964
- * set without touching the network. No-op while everything is already
965
- * shown or another append is in flight.
966
- */
967
- async loadMore() {
968
- const snapshot = this.store.getSnapshot();
969
- if (snapshot.status !== "ready" || snapshot.loadingMore) return;
970
- if (snapshot.entries.length >= snapshot.total) return;
971
- if (snapshot.query.trim() === "" && snapshot.categories.length === 0) {
972
- const ticket = ++this.seq;
973
- this.set({ loadingMore: true });
974
- try {
975
- const response = await this.requireApi().list({
976
- ...this.wireFilters(),
977
- limit: MEMORY_BATCH_SIZE,
978
- offset: snapshot.entries.length
979
- });
980
- if (!response.result.ok) throw new Error(response.result.error.message);
981
- if (ticket !== this.seq) return;
982
- const current = this.store.getSnapshot();
983
- const seen = new Set(current.entries.map((entry) => entry.id));
984
- const appended = response.result.value.entries.filter((entry) => !seen.has(entry.id));
985
- this.set({
986
- entries: [...current.entries, ...appended],
987
- total: response.result.value.total,
988
- loadingMore: false
989
- });
990
- } catch (error) {
991
- if (ticket !== this.seq) return;
992
- this.set({ error: messageOf(error), loadingMore: false });
962
+ function EntryRow(props) {
963
+ const { entry, expanded, staleLabel, staleHint, pinnedLabel, neverRecalledLabel, scopeLabels, translate, onToggle, loadRaw, onSaveEdits, onDelete, onTogglePin, onToggleArchive } = props;
964
+ const category = entry.category;
965
+ const projectName = entry.projectName;
966
+ const isStale = entry.staleSince !== void 0;
967
+ const isPinned = entry.pinned === true;
968
+ const [editing, setEditing] = (0, import_react.useState)(false);
969
+ const [confirmingDelete, setConfirmingDelete] = (0, import_react.useState)(false);
970
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: isStale ? `${css.row} ${css.rowStale}` : css.row, children: [
971
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.badges, children: [
972
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: scopeLabels[entry.scope] }),
973
+ category === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: translate(CATEGORY_LABEL_KEYS[category] ?? category) }),
974
+ projectName === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.project, children: projectName }),
975
+ isPinned ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${css.badge} ${css.badgePinned}`, children: `\u{1F4CC} ${pinnedLabel}` }) : null,
976
+ isStale ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${css.badge} ${css.badgeStale}`, title: staleHint, "aria-label": staleHint, children: `\u{1F634} ${staleLabel}` }) : null
977
+ ] }),
978
+ editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
979
+ EntryEditor,
980
+ {
981
+ entry,
982
+ translate,
983
+ loadRaw,
984
+ onSave: (edits) => {
985
+ setEditing(false);
986
+ onSaveEdits(edits);
987
+ },
988
+ onCancel: () => {
989
+ setEditing(false);
990
+ }
993
991
  }
994
- return;
995
- }
996
- const matches = this.matches;
997
- if (matches === null) {
998
- await this.reload();
999
- return;
1000
- }
1001
- this.set({ entries: matches.slice(0, snapshot.entries.length + MEMORY_BATCH_SIZE) });
1002
- }
1003
- // ─── Write path (phase 2): edit / delete / pin / archive / review queue ───
1004
- /**
1005
- * Run one row action against the host, then refresh the affected surfaces.
1006
- * Failures land in `actionError` (inline, previous rows stay visible); a
1007
- * success clears any stale error and repaints from the host's answer.
1008
- */
1009
- async act(run) {
1010
- try {
1011
- const outcome = await run(this.requireApi());
1012
- if (!outcome.ok) {
1013
- this.set({ actionError: outcome.message ?? "action failed" });
1014
- return false;
992
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
993
+ "button",
994
+ {
995
+ type: "button",
996
+ className: expanded ? `${css.content} ${css.contentOpen}` : css.content,
997
+ "aria-expanded": expanded,
998
+ onClick: onToggle,
999
+ children: entry.content
1015
1000
  }
1016
- this.set({ actionError: null });
1017
- return true;
1018
- } catch (error) {
1019
- this.set({ actionError: messageOf(error) });
1020
- return false;
1021
- }
1022
- }
1023
- /** Save human edits to one entry ("edit lands in KV", store single truth). */
1024
- async saveEntryEdits(id, edits) {
1025
- return this.act(async (api) => {
1026
- const response = await api.update({
1027
- id,
1028
- ...edits.content !== void 0 ? { content: edits.content } : {},
1029
- ...edits.category !== void 0 ? { category: edits.category ?? "" } : {},
1030
- ...edits.summary !== void 0 ? { summary: edits.summary ?? "" } : {}
1031
- });
1032
- if (!response.result.ok) return { ok: false, message: response.result.error.message };
1033
- if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "entry vanished before it could be saved" };
1034
- await this.refreshAfterMutation();
1035
- return { ok: true };
1036
- });
1037
- }
1038
- /**
1039
- * Fetch one entry's unredacted content through the break-glass `getRaw`
1040
- * RPC (audit-logged server-side). Returns undefined when the entry is gone
1041
- * or the read fails — the editor keeps the redacted draft either way.
1042
- */
1043
- async loadRawContent(id) {
1044
- try {
1045
- const response = await this.requireApi().getRaw({ id });
1046
- if (!response.result.ok) return void 0;
1047
- return response.result.value.entry?.content;
1048
- } catch {
1049
- return void 0;
1050
- }
1051
- }
1052
- /** Delete one entry after the component-level confirmation. */
1053
- async deleteEntry(id) {
1054
- return this.act(async (api) => {
1055
- const response = await api.removeEntry({ id });
1056
- if (!response.result.ok) return { ok: false, message: response.result.error.message };
1057
- if (!response.result.value.removed) return { ok: false, message: response.result.value.error ?? "entry was already gone" };
1058
- await this.refreshAfterMutation();
1059
- return { ok: true };
1060
- });
1061
- }
1062
- /** Toggle one entry's pin. */
1063
- async togglePin(entry) {
1064
- return this.act(async (api) => {
1065
- const response = await api.pin({ id: entry.id, pinned: entry.pinned !== true });
1066
- if (!response.result.ok) return { ok: false, message: response.result.error.message };
1067
- if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "entry was already gone" };
1068
- await this.refreshAfterMutation();
1069
- return { ok: true };
1070
- });
1071
- }
1072
- /** Toggle one entry's dormancy stamp (P1-7 archive semantics). */
1073
- async toggleArchive(entry) {
1074
- return this.act(async (api) => {
1075
- const response = await api.archive({ id: entry.id, archived: entry.staleSince === void 0 });
1076
- if (!response.result.ok) return { ok: false, message: response.result.error.message };
1077
- if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "entry was already gone" };
1078
- await this.refreshAfterMutation();
1079
- return { ok: true };
1080
- });
1081
- }
1082
- /** Re-fetch the pending queue plus whatever list surfaces are live. */
1083
- async refreshPending() {
1084
- try {
1085
- const response = await this.requireApi().suggestList();
1086
- if (response.result.ok) this.set({ pending: response.result.value.suggestions });
1087
- } catch {
1088
- }
1089
- }
1090
- /**
1091
- * Adopt one pending proposal — optionally with "edit before adopt" tweaks.
1092
- * Refreshes the queue AND the entry list (adoption may create or rewrite an
1093
- * entry under the active filters).
1094
- */
1095
- async adoptSuggestion(id, edits) {
1096
- const done = await this.act(async (api) => {
1097
- const response = await api.suggestAdopt({
1098
- id,
1099
- ...edits?.content !== void 0 && edits.content.trim() !== "" ? { content: edits.content } : {},
1100
- ...edits?.category !== void 0 && edits.category !== "" ? { category: edits.category } : {}
1101
- });
1102
- if (!response.result.ok) return { ok: false, message: response.result.error.message };
1103
- if (!response.result.value.found) return { ok: false, message: response.result.value.error ?? "proposal was already decided" };
1104
- return { ok: true };
1001
+ ),
1002
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: css.meta, children: [
1003
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: `${translate("metaCreated")} ${formatTs(entry.createdAt, "\u2014")}` }),
1004
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: `${translate("metaUpdated")} ${formatTs(entry.updatedAt, "\u2014")}` }),
1005
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: entry.lastRecalledAt === void 0 ? `${translate("metaRecalled")} ${neverRecalledLabel}` : `${translate("metaRecalled")} ${formatTs(entry.lastRecalledAt, neverRecalledLabel)}` })
1006
+ ] }),
1007
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.actions, children: [
1008
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1009
+ "button",
1010
+ {
1011
+ type: "button",
1012
+ className: css.actionBtn,
1013
+ onClick: () => {
1014
+ setEditing((current) => !current);
1015
+ setConfirmingDelete(false);
1016
+ },
1017
+ children: editing ? translate("cancelEdits") : translate("editAction")
1018
+ }
1019
+ ),
1020
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.actionBtn, onClick: onTogglePin, children: isPinned ? translate("unpinAction") : translate("pinAction") }),
1021
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.actionBtn, onClick: onToggleArchive, children: isStale ? translate("unarchiveAction") : translate("archiveAction") }),
1022
+ confirmingDelete ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1023
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1024
+ "button",
1025
+ {
1026
+ type: "button",
1027
+ className: `${css.actionBtn} ${css.actionBtnDanger}`,
1028
+ onClick: () => {
1029
+ setConfirmingDelete(false);
1030
+ onDelete();
1031
+ },
1032
+ children: translate("confirmDelete")
1033
+ }
1034
+ ),
1035
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1036
+ "button",
1037
+ {
1038
+ type: "button",
1039
+ className: css.actionBtn,
1040
+ onClick: () => {
1041
+ setConfirmingDelete(false);
1042
+ },
1043
+ children: translate("cancelDelete")
1044
+ }
1045
+ )
1046
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1047
+ "button",
1048
+ {
1049
+ type: "button",
1050
+ className: `${css.actionBtn} ${css.actionBtnDanger}`,
1051
+ onClick: () => {
1052
+ setConfirmingDelete(true);
1053
+ },
1054
+ children: translate("deleteAction")
1055
+ }
1056
+ )
1057
+ ] })
1058
+ ] });
1059
+ }
1060
+ function SuggestionRow(props) {
1061
+ const { suggestion, scopeLabels, translate, onAdopt, onReject } = props;
1062
+ const [editing, setEditing] = (0, import_react.useState)(false);
1063
+ const [draftContent, setDraftContent] = (0, import_react.useState)(suggestion.content);
1064
+ const category = suggestion.category;
1065
+ const projectName = suggestion.projectName;
1066
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: css.row, children: [
1067
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.badges, children: [
1068
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: scopeLabels[suggestion.scope] }),
1069
+ category === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: translate(CATEGORY_LABEL_KEYS[category] ?? category) }),
1070
+ projectName === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.project, children: projectName }),
1071
+ suggestion.hits > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${css.badge} ${css.badgeHits}`, children: translate("hitsBadge").replace("{hits}", String(suggestion.hits)) }) : null,
1072
+ suggestion.targetEntryId !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.badge, children: translate("updateProposalBadge") }) : null
1073
+ ] }),
1074
+ editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.editForm, children: [
1075
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1076
+ "textarea",
1077
+ {
1078
+ className: css.textarea,
1079
+ "aria-label": translate("editProposalContent"),
1080
+ value: draftContent,
1081
+ onChange: (event) => {
1082
+ setDraftContent(event.target.value);
1083
+ }
1084
+ }
1085
+ ),
1086
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.actions, children: [
1087
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1088
+ "button",
1089
+ {
1090
+ type: "button",
1091
+ className: css.actionBtn,
1092
+ disabled: draftContent.trim() === "",
1093
+ onClick: () => {
1094
+ onAdopt({ content: draftContent });
1095
+ },
1096
+ children: translate("saveAdopt")
1097
+ }
1098
+ ),
1099
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.actionBtn, onClick: () => {
1100
+ onAdopt(void 0);
1101
+ }, children: translate("adoptAsIs") })
1102
+ ] })
1103
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: `${css.content} ${css.contentOpen}`, onClick: () => {
1104
+ setEditing(true);
1105
+ }, children: suggestion.content }),
1106
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: css.meta, children: [
1107
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: `${translate("metaSeen")} ${formatTs(suggestion.lastSeenAt, "\u2014")}` }),
1108
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: `${translate("metaFirstSeen")} ${formatTs(suggestion.firstSeenAt, "\u2014")}` })
1109
+ ] }),
1110
+ !editing ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.actions, children: [
1111
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.actionBtn, onClick: () => {
1112
+ setEditing(true);
1113
+ }, children: translate("editAndAdopt") }),
1114
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.actionBtn, onClick: () => {
1115
+ onAdopt(void 0);
1116
+ }, children: translate("adoptAction") }),
1117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: `${css.actionBtn} ${css.actionBtnDanger}`, onClick: onReject, children: translate("rejectAction") })
1118
+ ] }) : null
1119
+ ] });
1120
+ }
1121
+ function MemorySection(props) {
1122
+ const { useMemorySection, t, load } = props;
1123
+ const state = useMemorySection((snapshot) => snapshot);
1124
+ (0, import_react.useEffect)(() => {
1125
+ void load();
1126
+ }, [load]);
1127
+ const [tab, setTab] = (0, import_react.useState)("overview");
1128
+ const [searchText, setSearchText] = (0, import_react.useState)(state.query);
1129
+ (0, import_react.useEffect)(() => {
1130
+ const timer = setTimeout(() => {
1131
+ props.commitQuery(searchText);
1132
+ }, 300);
1133
+ return () => {
1134
+ clearTimeout(timer);
1135
+ };
1136
+ }, [searchText]);
1137
+ const [expandedIds, setExpandedIds] = (0, import_react.useState)(/* @__PURE__ */ new Set());
1138
+ const toggleExpanded = (id) => {
1139
+ setExpandedIds((previous) => {
1140
+ const next = new Set(previous);
1141
+ if (next.has(id)) next.delete(id);
1142
+ else next.add(id);
1143
+ return next;
1105
1144
  });
1106
- if (done) {
1107
- this.set({ pending: this.store.getSnapshot().pending.filter((s) => s.id !== id), actionError: null });
1108
- await this.reload();
1109
- }
1110
- return done;
1145
+ };
1146
+ const scopeLabels = {
1147
+ global: t("dashGlobal"),
1148
+ project: t("dashProject"),
1149
+ user: t("dashUser")
1150
+ };
1151
+ const workspaceEnabled = state.scope === "all" || state.scope === "project";
1152
+ const total = state.total;
1153
+ const shown = state.entries.length;
1154
+ const hasMore = shown < total;
1155
+ const loadMoreRef = (0, import_react.useRef)(props.loadMore);
1156
+ loadMoreRef.current = props.loadMore;
1157
+ const sentinelRef = (0, import_react.useRef)(null);
1158
+ (0, import_react.useEffect)(() => {
1159
+ const element = sentinelRef.current;
1160
+ if (element === null || tab !== "manage") return;
1161
+ if (typeof IntersectionObserver === "undefined") return;
1162
+ const observer = new IntersectionObserver(
1163
+ (entries) => {
1164
+ if (entries.some((entry) => entry.isIntersecting)) loadMoreRef.current();
1165
+ },
1166
+ { rootMargin: "240px" }
1167
+ );
1168
+ observer.observe(element);
1169
+ return () => {
1170
+ observer.disconnect();
1171
+ };
1172
+ }, [tab, state.status, shown, total]);
1173
+ if (state.status === "error") {
1174
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.section, children: [
1175
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: css.title, children: t("nav") }),
1176
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.error, role: "alert", children: `${t("loadFailed")} ${state.error ?? ""}` }),
1177
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: css.moreBtn, onClick: () => {
1178
+ void load();
1179
+ }, children: t("retry") })
1180
+ ] });
1111
1181
  }
1112
- /** Reject one pending proposal. */
1113
- async rejectSuggestion(id) {
1114
- const done = await this.act(async (api) => {
1115
- const response = await api.suggestReject({ id });
1116
- if (!response.result.ok) return { ok: false, message: response.result.error.message };
1117
- return response.result.value.rejected ? { ok: true } : { ok: false, message: response.result.value.error ?? "proposal was already decided" };
1118
- });
1119
- if (done) this.set({ pending: this.store.getSnapshot().pending.filter((s) => s.id !== id), actionError: null });
1120
- return done;
1182
+ if (state.status === "loading" || state.status === "idle") {
1183
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.section, children: [
1184
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: css.title, children: t("nav") }),
1185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.intro, children: t("loading") })
1186
+ ] });
1121
1187
  }
1122
- /** Post-mutation repaint: health numbers + the visible list + the queue. */
1123
- async refreshAfterMutation() {
1124
- void this.refreshPending();
1125
- try {
1126
- const [health] = await Promise.all([this.requireApi().health()]);
1127
- if (health.result.ok) this.set({ health: health.result.value });
1128
- } catch {
1129
- }
1130
- await this.reload();
1188
+ const health = state.health;
1189
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.section, children: [
1190
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: css.title, children: t("nav") }),
1191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.intro, children: t("sectionIntro") }),
1192
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.tabs, role: "tablist", "aria-label": t("nav"), children: [
1193
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1194
+ "button",
1195
+ {
1196
+ type: "button",
1197
+ role: "tab",
1198
+ className: css.tabBtn,
1199
+ "aria-selected": tab === "overview",
1200
+ onClick: () => {
1201
+ setTab("overview");
1202
+ },
1203
+ children: t("tabOverview")
1204
+ }
1205
+ ),
1206
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1207
+ "button",
1208
+ {
1209
+ type: "button",
1210
+ role: "tab",
1211
+ className: css.tabBtn,
1212
+ "aria-selected": tab === "review",
1213
+ onClick: () => {
1214
+ setTab("review");
1215
+ },
1216
+ children: state.pending.length > 0 ? t("tabReviewWithCount").replace("{count}", String(state.pending.length)) : t("tabReview")
1217
+ }
1218
+ ),
1219
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1220
+ "button",
1221
+ {
1222
+ type: "button",
1223
+ role: "tab",
1224
+ className: css.tabBtn,
1225
+ "aria-selected": tab === "manage",
1226
+ onClick: () => {
1227
+ setTab("manage");
1228
+ },
1229
+ children: t("tabManage")
1230
+ }
1231
+ )
1232
+ ] }),
1233
+ tab === "overview" ? health === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.dash, children: [
1234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1235
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statValue, children: health.totalEntries }),
1236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("dashTotal") })
1237
+ ] }),
1238
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1239
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statValue, children: health.byScope.global }),
1240
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("scopeGlobal") })
1241
+ ] }),
1242
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1243
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statValue, children: health.byScope.user }),
1244
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("scopeUser") })
1245
+ ] }),
1246
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1247
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statValue, children: health.byScope.project }),
1248
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("scopeProject") })
1249
+ ] }),
1250
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1251
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statValue, children: health.pinned }),
1252
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("dashPinned") })
1253
+ ] }),
1254
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: `${css.stat} ${css.statStale}`, title: t("dashStaleHint"), children: [
1255
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${css.statValue}${(health.stale ?? 0) > 0 ? "" : ` ${css.statValueMuted}`}`, children: health.stale ?? 0 }),
1256
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("dashStale") })
1257
+ ] }),
1258
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1259
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statValue, children: health.auditRecords }),
1260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("dashAudit") })
1261
+ ] }),
1262
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${css.statValue} ${css.statValueMuted}`, children: formatTs(health.lastActivityTs, t("dashLastActivityNever")) }),
1264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("dashLastActivity") })
1265
+ ] }),
1266
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: css.stat, children: [
1267
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `${css.statValue} ${css.statValueMuted}`, children: formatTs(health.lastExtractionTs, t("dashLastActivityNever")) }),
1268
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.statLabel, children: t("dashLastExtraction") })
1269
+ ] })
1270
+ ] }) : null,
1271
+ tab === "review" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1272
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.reviewHead, children: t("reviewIntro") }),
1273
+ state.actionError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.error, role: "alert", children: state.actionError }),
1274
+ state.pending.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.empty, children: t("reviewEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: css.list, children: state.pending.map((suggestion) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1275
+ SuggestionRow,
1276
+ {
1277
+ suggestion,
1278
+ scopeLabels,
1279
+ translate: t,
1280
+ onAdopt: (edits) => {
1281
+ void props.adoptSuggestion(suggestion.id, edits);
1282
+ },
1283
+ onReject: () => {
1284
+ void props.rejectSuggestion(suggestion.id);
1285
+ }
1286
+ },
1287
+ suggestion.id
1288
+ )) })
1289
+ ] }) : null,
1290
+ tab === "manage" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1291
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.toolbar, children: [
1292
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.toolbarRow, children: [
1293
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.toolbarLabel, children: t("searchLabel") }),
1294
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: css.seg, role: "group", "aria-label": t("nav"), children: SCOPES.map(({ value, labelKey }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1295
+ "button",
1296
+ {
1297
+ type: "button",
1298
+ className: css.segBtn,
1299
+ "aria-pressed": state.scope === value,
1300
+ onClick: () => {
1301
+ props.setScope(value);
1302
+ },
1303
+ children: t(labelKey)
1304
+ },
1305
+ value
1306
+ )) }),
1307
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1308
+ "select",
1309
+ {
1310
+ className: css.select,
1311
+ "aria-label": t("workspaceLabel"),
1312
+ disabled: !workspaceEnabled,
1313
+ value: state.projectName ?? "",
1314
+ onChange: (event) => {
1315
+ props.setProject(event.target.value);
1316
+ },
1317
+ children: [
1318
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("workspaceAll") }),
1319
+ state.projects.map((name) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: name, children: name }, name))
1320
+ ]
1321
+ }
1322
+ ),
1323
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1324
+ "input",
1325
+ {
1326
+ type: "search",
1327
+ className: css.input,
1328
+ "aria-label": t("searchLabel"),
1329
+ placeholder: t("searchPlaceholder"),
1330
+ value: searchText,
1331
+ onChange: (event) => {
1332
+ setSearchText(event.target.value);
1333
+ }
1334
+ }
1335
+ )
1336
+ ] }),
1337
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.toolbarRow, children: [
1338
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: css.toolbarLabel, children: t("categoryLabel") }),
1339
+ MEMORY_CATEGORIES.map((category) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1340
+ "button",
1341
+ {
1342
+ type: "button",
1343
+ className: css.chip,
1344
+ "aria-pressed": state.categories.includes(category),
1345
+ onClick: () => {
1346
+ props.toggleCategory(category);
1347
+ },
1348
+ children: translateCategory(category, t)
1349
+ },
1350
+ category
1351
+ ))
1352
+ ] })
1353
+ ] }),
1354
+ state.error === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.error, role: "alert", children: state.error }),
1355
+ state.actionError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.error, role: "alert", children: state.actionError }),
1356
+ total === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.empty, children: t(emptyKeyOf(state)) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1357
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: css.list, children: state.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1358
+ EntryRow,
1359
+ {
1360
+ entry,
1361
+ expanded: expandedIds.has(entry.id),
1362
+ staleLabel: t("staleMark"),
1363
+ staleHint: t("staleHint"),
1364
+ pinnedLabel: t("pinnedBadge"),
1365
+ neverRecalledLabel: t("neverRecalled"),
1366
+ scopeLabels,
1367
+ translate: t,
1368
+ onToggle: () => {
1369
+ toggleExpanded(entry.id);
1370
+ },
1371
+ loadRaw: props.loadRawContent,
1372
+ onSaveEdits: (edits) => {
1373
+ void props.saveEntryEdits(entry.id, edits);
1374
+ },
1375
+ onDelete: () => {
1376
+ void props.deleteEntry(entry.id);
1377
+ },
1378
+ onTogglePin: () => {
1379
+ void props.togglePin(entry);
1380
+ },
1381
+ onToggleArchive: () => {
1382
+ void props.toggleArchive(entry);
1383
+ }
1384
+ },
1385
+ entry.id
1386
+ )) }),
1387
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: css.more, children: [
1388
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: css.count, children: t("shownCount").replace("{shown}", String(shown)).replace("{total}", String(total)) }),
1389
+ hasMore ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1390
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: sentinelRef, className: css.sentinel, "aria-hidden": "true" }),
1391
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1392
+ "button",
1393
+ {
1394
+ type: "button",
1395
+ className: css.moreBtn,
1396
+ disabled: state.loadingMore,
1397
+ onClick: () => {
1398
+ props.loadMore();
1399
+ },
1400
+ children: state.loadingMore ? t("loading") : t("loadMore")
1401
+ }
1402
+ )
1403
+ ] }) : null
1404
+ ] })
1405
+ ] })
1406
+ ] }) : null
1407
+ ] });
1408
+ }
1409
+ function translateCategory(category, t) {
1410
+ const key = CATEGORY_LABEL_KEYS[category];
1411
+ return key === void 0 ? category : t(key);
1412
+ }
1413
+
1414
+ // src/client/IdentitySection.tsx
1415
+ var import_react2 = require("react");
1416
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1417
+ var KINDS = [
1418
+ { kind: "soul", titleKey: "identitySoulTitle", emptyKey: "identitySoulEmpty", file: "SOUL.md" },
1419
+ { kind: "user", titleKey: "identityUserTitle", emptyKey: "identityUserEmpty", file: "USER.md" }
1420
+ ];
1421
+ function formatTs2(ts) {
1422
+ return new Date(ts).toLocaleString();
1423
+ }
1424
+ function sourceLabel(source, translate) {
1425
+ if (source === "seed") return translate("identitySourceSeed");
1426
+ if (source === "ui") return translate("identitySourceUi");
1427
+ return translate("identitySourceTool");
1428
+ }
1429
+ function exportDocument(file, content) {
1430
+ if (typeof Blob === "undefined" || typeof URL.createObjectURL !== "function") return;
1431
+ const blob = new Blob([content], { type: "text/markdown" });
1432
+ const url = URL.createObjectURL(blob);
1433
+ const anchor = document.createElement("a");
1434
+ anchor.href = url;
1435
+ anchor.download = file;
1436
+ anchor.click();
1437
+ URL.revokeObjectURL(url);
1438
+ }
1439
+ function DocumentPanel(props) {
1440
+ const { kind, file, title, emptyHint, record, history, translate, onRevert } = props;
1441
+ const [confirmingVersion, setConfirmingVersion] = (0, import_react2.useState)(null);
1442
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.row, "data-testid": `identity-panel-${kind}`, children: [
1443
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.reviewHead, children: [
1444
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.title, children: title }),
1445
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.badges, children: record !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1446
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.badge, children: translate("identityCurrentVersion").replace("{version}", String(record.version)) }),
1447
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1448
+ "button",
1449
+ {
1450
+ type: "button",
1451
+ className: css.moreBtn,
1452
+ onClick: () => {
1453
+ exportDocument(file, record.content);
1454
+ },
1455
+ children: translate("identityExport")
1456
+ }
1457
+ )
1458
+ ] }) : null })
1459
+ ] }),
1460
+ record === null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.empty, children: emptyHint }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1461
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { className: `${css.content} ${css.contentOpen}`, children: record.content }),
1462
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.list, children: [
1463
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: css.meta, children: translate("identityHistoryTitle") }),
1464
+ history.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.empty, children: translate("identityEmptyHistory") }) : history.map((snapshot) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.row, children: [
1465
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.content, children: `v${snapshot.version} \xB7 ${formatTs2(snapshot.ts)} \xB7 ${sourceLabel(snapshot.source, translate)}` }),
1466
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: css.actions, children: confirmingVersion === snapshot.version ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1467
+ "button",
1468
+ {
1469
+ type: "button",
1470
+ className: css.actionBtnDanger,
1471
+ onClick: () => {
1472
+ setConfirmingVersion(null);
1473
+ void onRevert(kind, snapshot.version);
1474
+ },
1475
+ children: translate("identityRevertConfirm")
1476
+ }
1477
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1478
+ "button",
1479
+ {
1480
+ type: "button",
1481
+ className: css.actionBtn,
1482
+ onClick: () => {
1483
+ setConfirmingVersion(snapshot.version);
1484
+ },
1485
+ children: translate("identityRevertBtn")
1486
+ }
1487
+ ) })
1488
+ ] }, `${kind}-${snapshot.version}`))
1489
+ ] })
1490
+ ] })
1491
+ ] });
1492
+ }
1493
+ function IdentitySection(props) {
1494
+ const { useIdentitySection, t, load } = props;
1495
+ const state = useIdentitySection((snapshot) => snapshot);
1496
+ (0, import_react2.useEffect)(() => {
1497
+ void load();
1498
+ }, [load]);
1499
+ if (state.status === "error") {
1500
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.section, children: [
1501
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: css.title, children: t("identityNav") }),
1502
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.error, role: "alert", children: `${t("loadFailed")} ${state.error ?? ""}` }),
1503
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: css.moreBtn, onClick: () => {
1504
+ void load();
1505
+ }, children: t("retry") })
1506
+ ] });
1131
1507
  }
1132
- };
1133
- function messageOf(error) {
1134
- return error instanceof Error ? error.message : String(error);
1508
+ if (state.status === "loading" || state.status === "idle") {
1509
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.section, children: [
1510
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: css.title, children: t("identityNav") }),
1511
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.intro, children: t("loading") })
1512
+ ] });
1513
+ }
1514
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: css.section, children: [
1515
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { className: css.title, children: t("identityNav") }),
1516
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.intro, children: t("identitySectionIntro") }),
1517
+ state.actionError !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: css.error, role: "alert", children: state.actionError }) : null,
1518
+ KINDS.map(({ kind, titleKey, emptyKey, file }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1519
+ DocumentPanel,
1520
+ {
1521
+ kind,
1522
+ file,
1523
+ title: t(titleKey),
1524
+ emptyHint: t(emptyKey),
1525
+ record: kind === "soul" ? state.soul : state.user,
1526
+ history: state.history[kind],
1527
+ translate: t,
1528
+ onRevert: (revertKind, version) => props.revert(revertKind, version)
1529
+ },
1530
+ kind
1531
+ ))
1532
+ ] });
1135
1533
  }
1136
1534
 
1137
- // src/client/section-styles.ts
1535
+ // src/client/card-styles.ts
1138
1536
  var RULES2 = `
1139
- .dsm-s-section {
1537
+ /* \u2500\u2500 Page list: the settings page's stack of sections \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1538
+ .dsm-c-page-list {
1539
+ list-style: none;
1540
+ margin: 0;
1541
+ padding: 0;
1140
1542
  display: flex;
1141
1543
  flex-direction: column;
1142
- gap: 16px;
1544
+ gap: 12px;
1143
1545
  }
1144
- .dsm-s-title {
1145
- margin: 0;
1546
+ /* \u2500\u2500 Card shell (port of PluginCard.module.css) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1547
+ .dsm-c-card {
1548
+ list-style: none;
1549
+ border: 1px solid var(--dsw-alias-border-l2);
1550
+ border-radius: 12px;
1551
+ background: var(--dsw-alias-bg-layer-3);
1552
+ transition: border-color .16s, background .16s;
1553
+ }
1554
+ .dsm-c-card:hover {
1555
+ border-color: var(--dsw-alias-label-dimmed);
1556
+ }
1557
+ .dsm-c-card-open {
1558
+ background: var(--dsw-alias-bg-layer-2);
1559
+ border-color: var(--dsw-alias-label-dimmed);
1560
+ }
1561
+ .dsm-c-header {
1562
+ width: 100%;
1563
+ appearance: none;
1564
+ border: 0;
1565
+ background: none;
1566
+ font: inherit;
1567
+ color: inherit;
1568
+ text-align: left;
1569
+ cursor: pointer;
1570
+ display: flex;
1571
+ align-items: center;
1572
+ gap: 12px;
1573
+ padding: 14px 16px;
1574
+ border-radius: 12px;
1575
+ }
1576
+ .dsm-c-header:focus-visible {
1577
+ outline: 2px solid var(--dsw-alias-brand-primary);
1578
+ outline-offset: -2px;
1579
+ }
1580
+ .dsm-c-head-text {
1581
+ flex: 1;
1582
+ min-width: 0;
1583
+ display: flex;
1584
+ flex-direction: column;
1585
+ gap: 4px;
1586
+ }
1587
+ .dsm-c-name {
1146
1588
  font-size: 15px;
1147
1589
  font-weight: 600;
1148
1590
  line-height: 1.4;
1149
1591
  color: var(--dsw-alias-label-primary);
1150
1592
  }
1151
- .dsm-s-intro {
1152
- margin: 0;
1593
+ .dsm-c-description {
1153
1594
  font-size: 13px;
1154
1595
  line-height: 1.5;
1155
1596
  color: var(--dsw-alias-label-tertiary);
1156
1597
  }
1157
-
1158
- /* \u2500\u2500 Health dashboard bar \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1159
- .dsm-s-dash {
1160
- display: flex;
1161
- flex-wrap: wrap;
1162
- align-items: stretch;
1163
- gap: 8px;
1598
+ .dsm-c-pending {
1599
+ flex: none;
1600
+ border-radius: 999px;
1601
+ padding: 1px 8px;
1602
+ font-size: 11px;
1603
+ line-height: 17px;
1604
+ font-weight: 500;
1605
+ white-space: nowrap;
1606
+ background: var(--dsw-alias-bg-module-platform);
1607
+ color: var(--dsw-alias-label-secondary);
1164
1608
  }
1165
- .dsm-s-stat {
1166
- display: flex;
1167
- flex-direction: column;
1168
- justify-content: center;
1169
- gap: 2px;
1170
- min-width: 88px;
1171
- padding: 10px 14px;
1172
- border: 1px solid var(--dsw-alias-border-l2);
1173
- border-radius: 12px;
1174
- background: var(--dsw-alias-bg-layer-3);
1609
+ .dsm-c-chevron {
1610
+ flex: none;
1611
+ color: var(--dsw-alias-label-tertiary);
1612
+ transition: transform .16s;
1175
1613
  }
1176
- .dsm-s-stat-value {
1177
- font-size: 18px;
1178
- font-weight: 600;
1179
- line-height: 1.3;
1180
- color: var(--dsw-alias-label-primary);
1614
+ .dsm-c-chevron-open {
1615
+ transform: rotate(180deg);
1181
1616
  }
1182
- .dsm-s-stat-value-muted {
1183
- color: var(--dsw-alias-label-secondary);
1617
+ .dsm-c-body {
1618
+ border-top: 1px solid var(--dsw-alias-border-l2);
1619
+ margin: 0 16px;
1620
+ padding-bottom: 8px;
1184
1621
  }
1185
- .dsm-s-stat-label {
1622
+ .dsm-c-read-only {
1623
+ margin: 12px 0 0;
1186
1624
  font-size: 12px;
1187
1625
  line-height: 1.5;
1188
1626
  color: var(--dsw-alias-label-tertiary);
1189
1627
  }
1190
- .dsm-s-stat-stale {
1191
- cursor: help;
1192
- }
1193
-
1194
- /* \u2500\u2500 Toolbar \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1195
- .dsm-s-toolbar {
1196
- display: flex;
1197
- flex-direction: column;
1198
- gap: 10px;
1199
- }
1200
- .dsm-s-toolbar-row {
1628
+ .dsm-c-footer {
1201
1629
  display: flex;
1202
- flex-wrap: wrap;
1203
1630
  align-items: center;
1631
+ justify-content: flex-end;
1204
1632
  gap: 8px;
1633
+ padding: 12px 0 4px;
1634
+ border-top: 1px solid var(--dsw-alias-border-l2);
1205
1635
  }
1206
- .dsm-s-toolbar-label {
1636
+ .dsm-c-failed {
1637
+ flex: 1;
1638
+ min-width: 0;
1639
+ margin: 0;
1207
1640
  font-size: 12px;
1208
- font-weight: 500;
1209
1641
  line-height: 1.5;
1210
- color: var(--dsw-alias-label-tertiary);
1211
- }
1212
- /* Segmented scope switch and section tabs share one visual language. */
1213
- .dsm-s-seg,
1214
- .dsm-s-tabs {
1215
- display: inline-flex;
1216
- padding: 2px;
1217
- border: 1px solid var(--dsw-alias-border-l2);
1218
- border-radius: 8px;
1219
- background: var(--dsw-alias-bg-layer-3);
1642
+ color: var(--dsw-alias-label-error);
1220
1643
  }
1221
- .dsm-s-seg-btn,
1222
- .dsm-s-tab-btn {
1644
+ .dsm-c-discard,
1645
+ .dsm-c-save {
1223
1646
  appearance: none;
1224
- border: 0;
1225
- background: none;
1226
- padding: 4px 12px;
1227
- border-radius: 6px;
1228
- font: inherit;
1229
- font-size: 13px;
1230
- line-height: 1.5;
1231
- color: var(--dsw-alias-label-secondary);
1232
- cursor: pointer;
1233
- }
1234
- .dsm-s-seg-btn:hover:not([aria-pressed="true"]),
1235
- .dsm-s-tab-btn:hover:not([aria-selected="true"]) {
1236
- color: var(--dsw-alias-label-primary);
1237
- }
1238
- .dsm-s-seg-btn[aria-pressed="true"],
1239
- .dsm-s-tab-btn[aria-selected="true"] {
1240
- background: var(--dsw-alias-brand-primary);
1241
- color: var(--dsw-alias-bg-layer-3);
1242
- }
1243
- .dsm-s-tab-btn[aria-selected="true"] {
1244
- cursor: default;
1245
- }
1246
- .dsm-s-seg-btn:focus-visible,
1247
- .dsm-s-tab-btn:focus-visible {
1248
- outline: 2px solid var(--dsw-alias-brand-primary);
1249
- outline-offset: -2px;
1250
- }
1251
- /* Search box mirrors the shared .input control look. */
1252
- .dsm-s-input {
1253
- flex: 1;
1254
- min-width: 200px;
1255
- max-width: 360px;
1256
- height: 34px;
1257
- padding: 0 12px;
1258
- border: 1px solid var(--dsw-alias-border-l2);
1259
- border-radius: 8px;
1260
- background: var(--dsw-alias-bg-layer-3);
1261
- font: inherit;
1262
- font-size: 13px;
1263
- line-height: 1.5;
1264
- color: var(--dsw-alias-label-primary);
1265
- }
1266
- .dsm-s-input:focus-visible {
1267
- outline: none;
1268
- border-color: var(--dsw-alias-brand-primary);
1269
- }
1270
- /* Workspace selector mirrors the shared .select control look. */
1271
- .dsm-s-select {
1272
- max-width: 260px;
1273
- height: 34px;
1274
- padding: 0 28px 0 12px;
1275
- border: 1px solid var(--dsw-alias-border-l2);
1647
+ border: 1px solid transparent;
1276
1648
  border-radius: 8px;
1277
- background-color: var(--dsw-alias-bg-layer-3);
1649
+ padding: 5px 14px;
1278
1650
  font: inherit;
1279
1651
  font-size: 13px;
1280
1652
  line-height: 1.5;
1281
- color: var(--dsw-alias-label-primary);
1282
1653
  cursor: pointer;
1283
- appearance: none;
1284
- -webkit-appearance: none;
1285
- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5l4 4 4-4' stroke='%237a7a7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
1286
- background-repeat: no-repeat;
1287
- background-position: right 10px center;
1288
- }
1289
- .dsm-s-select:focus-visible {
1290
- outline: none;
1291
- border-color: var(--dsw-alias-brand-primary);
1292
1654
  }
1293
- .dsm-s-select:disabled {
1294
- color: var(--dsw-alias-label-tertiary);
1295
- cursor: default;
1296
- }
1297
- /* Category chips. */
1298
- .dsm-s-chip {
1299
- appearance: none;
1300
- border: 1px solid var(--dsw-alias-border-l2);
1301
- border-radius: 999px;
1302
- background: var(--dsw-alias-bg-layer-3);
1303
- padding: 3px 12px;
1304
- font: inherit;
1305
- font-size: 12px;
1306
- line-height: 1.5;
1655
+ .dsm-c-discard {
1656
+ border-color: var(--dsw-alias-border-l2);
1657
+ background: none;
1307
1658
  color: var(--dsw-alias-label-secondary);
1308
- cursor: pointer;
1309
1659
  }
1310
- .dsm-s-chip:hover {
1660
+ .dsm-c-discard:hover:not(:disabled) {
1311
1661
  color: var(--dsw-alias-label-primary);
1312
1662
  border-color: var(--dsw-alias-label-dimmed);
1313
1663
  }
1314
- .dsm-s-chip[aria-pressed="true"] {
1315
- background: var(--dsw-alias-bg-module-platform);
1316
- border-color: var(--dsw-alias-brand-primary);
1317
- color: var(--dsw-alias-label-primary);
1664
+ .dsm-c-save {
1665
+ background: var(--dsw-alias-label-primary);
1666
+ color: var(--dsw-alias-bg-layer-3);
1667
+ }
1668
+ .dsm-c-discard:disabled,
1669
+ .dsm-c-save:disabled {
1670
+ opacity: 0.4;
1671
+ cursor: default;
1318
1672
  }
1319
- .dsm-s-chip:focus-visible {
1673
+ .dsm-c-discard:focus-visible,
1674
+ .dsm-c-save:focus-visible {
1320
1675
  outline: 2px solid var(--dsw-alias-brand-primary);
1321
1676
  outline-offset: 1px;
1322
1677
  }
1323
1678
 
1324
- /* \u2500\u2500 Entry list \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1325
- .dsm-s-list {
1326
- list-style: none;
1327
- margin: 0;
1328
- padding: 0;
1679
+ /* \u2500\u2500 Fields (port of fields.module.css) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1680
+ .dsm-c-field {
1329
1681
  display: flex;
1330
1682
  flex-direction: column;
1331
- gap: 8px;
1683
+ gap: 6px;
1684
+ padding: 12px 0;
1332
1685
  }
1333
- .dsm-s-row {
1686
+ .dsm-c-field + .dsm-c-field {
1687
+ border-top: 1px solid var(--dsw-alias-border-l2);
1688
+ }
1689
+ .dsm-c-head {
1334
1690
  display: flex;
1335
- flex-direction: column;
1336
- gap: 6px;
1337
- padding: 12px 14px;
1338
- border: 1px solid var(--dsw-alias-border-l2);
1339
- border-radius: 12px;
1340
- background: var(--dsw-alias-bg-layer-3);
1691
+ align-items: center;
1692
+ gap: 8px;
1341
1693
  }
1342
- .dsm-s-row-stale {
1343
- opacity: 0.62;
1694
+ .dsm-c-label {
1695
+ flex: 1;
1696
+ min-width: 0;
1697
+ font-size: 13px;
1698
+ font-weight: 500;
1699
+ line-height: 1.5;
1700
+ color: var(--dsw-alias-label-primary);
1344
1701
  }
1345
- .dsm-s-badges {
1702
+ .dsm-c-badges {
1346
1703
  display: inline-flex;
1347
1704
  align-items: center;
1348
- flex-wrap: wrap;
1349
- gap: 6px;
1705
+ gap: 8px;
1350
1706
  }
1351
- .dsm-s-badge {
1707
+ .dsm-c-badge {
1352
1708
  border-radius: 999px;
1353
1709
  padding: 1px 8px;
1354
1710
  font-size: 11px;
@@ -1358,145 +1714,103 @@ var RULES2 = `
1358
1714
  background: var(--dsw-alias-bg-module-platform);
1359
1715
  color: var(--dsw-alias-label-secondary);
1360
1716
  }
1361
- .dsm-s-badge-pinned,
1362
- .dsm-s-badge-stale {
1363
- background: none;
1364
- padding-left: 0;
1365
- }
1366
- .dsm-s-project {
1367
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1717
+ .dsm-c-badge-muted {
1718
+ border-radius: 999px;
1719
+ padding: 1px 8px;
1368
1720
  font-size: 11px;
1369
1721
  line-height: 17px;
1722
+ white-space: nowrap;
1370
1723
  color: var(--dsw-alias-label-tertiary);
1371
1724
  }
1372
- .dsm-s-content {
1373
- margin: 0;
1374
- font-size: 13px;
1375
- line-height: 1.55;
1376
- color: var(--dsw-alias-label-primary);
1377
- white-space: pre-wrap;
1378
- word-break: break-word;
1725
+ .dsm-c-reset {
1726
+ border: none;
1727
+ background: none;
1728
+ padding: 0;
1729
+ font: inherit;
1730
+ font-size: 12px;
1731
+ line-height: 1.5;
1732
+ color: var(--dsw-alias-label-secondary);
1379
1733
  cursor: pointer;
1380
- display: -webkit-box;
1381
- -webkit-box-orient: vertical;
1382
- -webkit-line-clamp: 2;
1383
- overflow: hidden;
1384
1734
  }
1385
- .dsm-s-content-open {
1386
- display: block;
1387
- -webkit-line-clamp: none;
1388
- overflow: visible;
1389
- cursor: text;
1735
+ .dsm-c-reset:hover:not(:disabled) {
1736
+ color: var(--dsw-alias-label-primary);
1390
1737
  }
1391
- .dsm-s-meta {
1392
- display: flex;
1393
- flex-wrap: wrap;
1394
- gap: 4px 14px;
1395
- margin: 0;
1396
- font-size: 11px;
1397
- line-height: 1.5;
1398
- color: var(--dsw-alias-label-tertiary);
1738
+ .dsm-c-reset:disabled {
1739
+ cursor: default;
1399
1740
  }
1400
1741
 
1401
- /* \u2500\u2500 Lazy-load footer / empty / error \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1402
- .dsm-s-more {
1403
- display: flex;
1404
- flex-direction: column;
1405
- align-items: center;
1406
- gap: 8px;
1407
- }
1408
- .dsm-s-count {
1409
- margin: 0;
1410
- font-size: 12px;
1411
- line-height: 1.5;
1412
- color: var(--dsw-alias-label-tertiary);
1413
- }
1414
- .dsm-s-sentinel {
1415
- width: 100%;
1416
- height: 1px;
1417
- }
1418
- .dsm-s-more-btn {
1419
- appearance: none;
1742
+ /* Shared input control look (fields.module.css .input). */
1743
+ .dsm-c-input {
1744
+ height: 34px;
1745
+ padding: 0 12px;
1420
1746
  border: 1px solid var(--dsw-alias-border-l2);
1421
1747
  border-radius: 8px;
1422
1748
  background: var(--dsw-alias-bg-layer-3);
1423
- padding: 4px 12px;
1424
1749
  font: inherit;
1425
1750
  font-size: 13px;
1426
1751
  line-height: 1.5;
1427
- color: var(--dsw-alias-label-secondary);
1428
- cursor: pointer;
1429
- }
1430
- .dsm-s-more-btn:hover:not(:disabled) {
1431
1752
  color: var(--dsw-alias-label-primary);
1432
- border-color: var(--dsw-alias-label-dimmed);
1433
1753
  }
1434
- .dsm-s-more-btn:disabled {
1435
- opacity: 0.4;
1436
- cursor: default;
1754
+ .dsm-c-input:focus-visible {
1755
+ outline: none;
1756
+ border-color: var(--dsw-alias-brand-primary);
1437
1757
  }
1438
- .dsm-s-empty {
1439
- margin: 24px 0;
1440
- text-align: center;
1441
- font-size: 13px;
1442
- line-height: 1.6;
1758
+ .dsm-c-input:disabled {
1443
1759
  color: var(--dsw-alias-label-tertiary);
1760
+ cursor: default;
1444
1761
  }
1445
- .dsm-s-error {
1446
- margin: 0;
1447
- font-size: 12px;
1762
+ /* inputInvalid mirrors .input with an error border (composes: input in host). */
1763
+ .dsm-c-input-invalid {
1764
+ height: 34px;
1765
+ padding: 0 12px;
1766
+ border: 1px solid var(--dsw-alias-label-error);
1767
+ border-radius: 8px;
1768
+ background: var(--dsw-alias-bg-layer-3);
1769
+ font: inherit;
1770
+ font-size: 13px;
1448
1771
  line-height: 1.5;
1449
- color: var(--dsw-alias-label-error);
1772
+ color: var(--dsw-alias-label-primary);
1450
1773
  }
1451
-
1452
- /* \u2500\u2500 Phase-2 write path: row actions / editor / review queue \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
1453
- .dsm-s-actions {
1454
- display: flex;
1455
- flex-wrap: wrap;
1456
- align-items: center;
1457
- gap: 6px;
1774
+ .dsm-c-input-invalid:focus-visible {
1775
+ outline: none;
1776
+ border-color: var(--dsw-alias-label-error);
1458
1777
  }
1459
- .dsm-s-action-btn {
1460
- appearance: none;
1778
+ .dsm-c-input-invalid:disabled {
1779
+ color: var(--dsw-alias-label-tertiary);
1780
+ cursor: default;
1781
+ }
1782
+
1783
+ /* select mirrors .input; native arrow kept via appearance. */
1784
+ .dsm-c-select {
1785
+ height: 34px;
1786
+ padding: 0 28px 0 12px;
1461
1787
  border: 1px solid var(--dsw-alias-border-l2);
1462
1788
  border-radius: 8px;
1463
1789
  background: var(--dsw-alias-bg-layer-3);
1464
- padding: 2px 10px;
1465
1790
  font: inherit;
1466
- font-size: 12px;
1467
- line-height: 20px;
1468
- color: var(--dsw-alias-label-secondary);
1791
+ font-size: 13px;
1792
+ line-height: 1.5;
1793
+ color: var(--dsw-alias-label-primary);
1469
1794
  cursor: pointer;
1795
+ appearance: none;
1796
+ -webkit-appearance: none;
1797
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5l4 4 4-4' stroke='%237a7a7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
1798
+ background-repeat: no-repeat;
1799
+ background-position: right 10px center;
1470
1800
  }
1471
- .dsm-s-action-btn:hover:not(:disabled) {
1472
- color: var(--dsw-alias-label-primary);
1473
- border-color: var(--dsw-alias-label-dimmed);
1801
+ .dsm-c-select:focus-visible {
1802
+ outline: none;
1803
+ border-color: var(--dsw-alias-brand-primary);
1474
1804
  }
1475
- .dsm-s-action-btn:disabled {
1476
- opacity: 0.45;
1805
+ .dsm-c-select:disabled {
1806
+ color: var(--dsw-alias-label-tertiary);
1477
1807
  cursor: default;
1478
1808
  }
1479
- .dsm-s-action-btn:focus-visible {
1480
- outline: 2px solid var(--dsw-alias-brand-primary);
1481
- outline-offset: -2px;
1482
- }
1483
- .dsm-s-action-btn-danger {
1484
- color: var(--dsw-alias-label-error);
1485
- }
1486
- .dsm-s-badge-hits {
1487
- background: var(--dsw-alias-brand-primary);
1488
- color: var(--dsw-alias-bg-layer-3);
1489
- }
1490
- .dsm-s-edit-form {
1491
- display: flex;
1492
- flex-direction: column;
1493
- gap: 8px;
1494
- }
1495
- .dsm-s-textarea,
1496
- .dsm-s-field {
1497
- width: 100%;
1498
- box-sizing: border-box;
1499
- padding: 6px 12px;
1809
+
1810
+ /* textarea mirrors .input borders, multi-line sizing. */
1811
+ .dsm-c-textarea {
1812
+ min-height: 80px;
1813
+ padding: 8px 12px;
1500
1814
  border: 1px solid var(--dsw-alias-border-l2);
1501
1815
  border-radius: 8px;
1502
1816
  background: var(--dsw-alias-bg-layer-3);
@@ -1504,785 +1818,486 @@ var RULES2 = `
1504
1818
  font-size: 13px;
1505
1819
  line-height: 1.5;
1506
1820
  color: var(--dsw-alias-label-primary);
1507
- }
1508
- .dsm-s-textarea {
1509
- min-height: 64px;
1510
1821
  resize: vertical;
1511
1822
  }
1512
- .dsm-s-textarea:focus-visible,
1513
- .dsm-s-field:focus-visible {
1823
+ .dsm-c-textarea:focus-visible {
1514
1824
  outline: none;
1515
1825
  border-color: var(--dsw-alias-brand-primary);
1516
1826
  }
1517
- .dsm-s-form-row {
1518
- display: flex;
1519
- flex-wrap: wrap;
1520
- align-items: center;
1521
- gap: 8px;
1827
+ .dsm-c-textarea:disabled {
1828
+ color: var(--dsw-alias-label-tertiary);
1829
+ cursor: default;
1830
+ }
1831
+
1832
+ /* A checkbox row: the box and its label sit on the head line so the override
1833
+ badge + reset stay right-aligned exactly as the text fields do. */
1834
+ .dsm-c-check-row {
1835
+ display: flex;
1836
+ align-items: center;
1837
+ gap: 8px;
1838
+ flex: 1;
1839
+ min-width: 0;
1840
+ }
1841
+ .dsm-c-checkbox {
1842
+ flex: none;
1843
+ width: 16px;
1844
+ height: 16px;
1845
+ margin: 0;
1846
+ accent-color: var(--dsw-alias-brand-primary);
1847
+ cursor: pointer;
1848
+ }
1849
+ .dsm-c-checkbox:disabled {
1850
+ cursor: default;
1851
+ }
1852
+ .dsm-c-check-label {
1853
+ font-size: 13px;
1854
+ font-weight: 500;
1855
+ line-height: 1.5;
1856
+ color: var(--dsw-alias-label-primary);
1857
+ cursor: pointer;
1858
+ }
1859
+ .dsm-c-check-label:disabled,
1860
+ .dsm-c-checkbox:disabled + .dsm-c-check-label {
1861
+ color: var(--dsw-alias-label-tertiary);
1862
+ cursor: default;
1863
+ }
1864
+
1865
+ .dsm-c-invalid {
1866
+ margin: 0;
1867
+ font-size: 12px;
1868
+ line-height: 1.5;
1869
+ color: var(--dsw-alias-label-error);
1522
1870
  }
1523
- .dsm-s-review-head {
1871
+ .dsm-c-hint {
1524
1872
  margin: 0;
1525
- font-size: 13px;
1526
- font-weight: 500;
1873
+ font-size: 12px;
1527
1874
  line-height: 1.5;
1528
- color: var(--dsw-alias-label-secondary);
1875
+ color: var(--dsw-alias-label-tertiary);
1529
1876
  }
1530
1877
  `;
1531
- var cls2 = {
1532
- section: "dsm-s-section",
1533
- title: "dsm-s-title",
1534
- intro: "dsm-s-intro",
1535
- dash: "dsm-s-dash",
1536
- stat: "dsm-s-stat",
1537
- statValue: "dsm-s-stat-value",
1538
- statValueMuted: "dsm-s-stat-value-muted",
1539
- statLabel: "dsm-s-stat-label",
1540
- statStale: "dsm-s-stat-stale",
1541
- toolbar: "dsm-s-toolbar",
1542
- toolbarRow: "dsm-s-toolbar-row",
1543
- toolbarLabel: "dsm-s-toolbar-label",
1544
- seg: "dsm-s-seg",
1545
- segBtn: "dsm-s-seg-btn",
1546
- tabs: "dsm-s-tabs",
1547
- tabBtn: "dsm-s-tab-btn",
1548
- input: "dsm-s-input",
1549
- select: "dsm-s-select",
1550
- chip: "dsm-s-chip",
1551
- list: "dsm-s-list",
1552
- row: "dsm-s-row",
1553
- rowStale: "dsm-s-row-stale",
1554
- badges: "dsm-s-badges",
1555
- badge: "dsm-s-badge",
1556
- badgePinned: "dsm-s-badge-pinned",
1557
- badgeStale: "dsm-s-badge-stale",
1558
- project: "dsm-s-project",
1559
- content: "dsm-s-content",
1560
- contentOpen: "dsm-s-content-open",
1561
- meta: "dsm-s-meta",
1562
- more: "dsm-s-more",
1563
- count: "dsm-s-count",
1564
- sentinel: "dsm-s-sentinel",
1565
- moreBtn: "dsm-s-more-btn",
1566
- empty: "dsm-s-empty",
1567
- error: "dsm-s-error",
1568
- actions: "dsm-s-actions",
1569
- actionBtn: "dsm-s-action-btn",
1570
- actionBtnDanger: "dsm-s-action-btn-danger",
1571
- badgeHits: "dsm-s-badge-hits",
1572
- editForm: "dsm-s-edit-form",
1573
- textarea: "dsm-s-textarea",
1574
- field: "dsm-s-field",
1575
- formRow: "dsm-s-form-row",
1576
- reviewHead: "dsm-s-review-head"
1577
- };
1578
1878
  var injected2 = false;
1579
1879
  function inject2() {
1580
1880
  if (injected2 || typeof document === "undefined") return;
1581
1881
  const style = document.createElement("style");
1582
- style.setAttribute("data-dsh-memory", "section");
1882
+ style.setAttribute("data-dsh-memory", "plugin-card");
1583
1883
  style.textContent = RULES2;
1584
1884
  document.head.appendChild(style);
1585
1885
  injected2 = true;
1586
1886
  }
1887
+ var cls2 = {
1888
+ // Page list.
1889
+ pageList: "dsm-c-page-list",
1890
+ // Card shell (PluginCard.module.css).
1891
+ card: "dsm-c-card",
1892
+ cardOpen: "dsm-c-card-open",
1893
+ header: "dsm-c-header",
1894
+ headText: "dsm-c-head-text",
1895
+ name: "dsm-c-name",
1896
+ description: "dsm-c-description",
1897
+ pending: "dsm-c-pending",
1898
+ chevron: "dsm-c-chevron",
1899
+ chevronOpen: "dsm-c-chevron-open",
1900
+ body: "dsm-c-body",
1901
+ readOnly: "dsm-c-read-only",
1902
+ footer: "dsm-c-footer",
1903
+ failed: "dsm-c-failed",
1904
+ discard: "dsm-c-discard",
1905
+ save: "dsm-c-save",
1906
+ // Fields (fields.module.css).
1907
+ field: "dsm-c-field",
1908
+ head: "dsm-c-head",
1909
+ label: "dsm-c-label",
1910
+ badges: "dsm-c-badges",
1911
+ badge: "dsm-c-badge",
1912
+ reset: "dsm-c-reset",
1913
+ input: "dsm-c-input",
1914
+ inputInvalid: "dsm-c-input-invalid",
1915
+ badgeMuted: "dsm-c-badge-muted",
1916
+ select: "dsm-c-select",
1917
+ textarea: "dsm-c-textarea",
1918
+ checkRow: "dsm-c-check-row",
1919
+ checkbox: "dsm-c-checkbox",
1920
+ checkLabel: "dsm-c-check-label",
1921
+ invalid: "dsm-c-invalid",
1922
+ hint: "dsm-c-hint"
1923
+ };
1587
1924
  var css2 = (inject2(), cls2);
1588
1925
 
1589
- // src/client/MemorySection.tsx
1926
+ // src/client/MemoryPluginCard.tsx
1927
+ var import_react4 = require("react");
1928
+ var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
1929
+
1930
+ // src/client/fields.tsx
1590
1931
  var import_jsx_runtime3 = require("react/jsx-runtime");
1591
- var SCOPES = [
1592
- { value: "all", labelKey: "scopeAll" },
1593
- { value: "global", labelKey: "scopeGlobal" },
1594
- { value: "project", labelKey: "scopeProject" },
1595
- { value: "user", labelKey: "scopeUser" }
1596
- ];
1597
- function formatTs(ts, fallback) {
1598
- return ts === void 0 || ts === null ? fallback : new Date(ts).toLocaleString();
1932
+ function FieldHead(props) {
1933
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.head, children: [
1934
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { className: css2.label, htmlFor: props.id, children: props.label }),
1935
+ props.overridden ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.badges, children: [
1936
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: props.overriddenLabel }),
1937
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })
1938
+ ] }) : null
1939
+ ] });
1599
1940
  }
1600
- var NO_CATEGORY = "";
1601
- function emptyKeyOf(state) {
1602
- if (state.query.trim() !== "" || state.categories.length > 0) return "emptyFiltered";
1603
- if (state.scope === "global") return "emptyGlobal";
1604
- if (state.scope === "user") return "emptyUser";
1605
- if (state.scope === "project") return "emptyProject";
1606
- return "emptyAll";
1941
+ function SelectField(props) {
1942
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.field, children: [
1943
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldHead, { ...props }),
1944
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1945
+ "select",
1946
+ {
1947
+ id: props.id,
1948
+ className: css2.select,
1949
+ value: props.value,
1950
+ disabled: props.disabled,
1951
+ onChange: (e) => props.onChange(e.target.value),
1952
+ children: props.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: o.value, children: o.label }, o.value))
1953
+ }
1954
+ ),
1955
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.hint, children: props.hint })
1956
+ ] });
1607
1957
  }
1608
- function EntryEditor(props) {
1609
- const { entry, translate, loadRaw, onSave, onCancel } = props;
1610
- const [draftContent, setDraftContent] = (0, import_react2.useState)(entry.content);
1611
- (0, import_react2.useEffect)(() => {
1612
- let alive = true;
1613
- loadRaw(entry.id).then((raw) => {
1614
- if (alive && raw !== void 0) setDraftContent(raw);
1615
- }).catch(() => {
1616
- });
1617
- return () => {
1618
- alive = false;
1619
- };
1620
- }, [entry.id, loadRaw]);
1621
- const [draftCategory, setDraftCategory] = (0, import_react2.useState)(entry.category ?? NO_CATEGORY);
1622
- const [draftSummary, setDraftSummary] = (0, import_react2.useState)(entry.summary ?? "");
1623
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.editForm, children: [
1958
+ function TextField(props) {
1959
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.field, children: [
1960
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldHead, { ...props }),
1624
1961
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1625
- "textarea",
1962
+ "input",
1626
1963
  {
1627
- className: css2.textarea,
1628
- "aria-label": translate("editContent"),
1629
- value: draftContent,
1630
- onChange: (event) => {
1631
- setDraftContent(event.target.value);
1632
- }
1964
+ id: props.id,
1965
+ className: css2.input,
1966
+ type: "text",
1967
+ value: props.value,
1968
+ disabled: props.disabled,
1969
+ onChange: (e) => props.onChange(e.target.value)
1633
1970
  }
1634
1971
  ),
1635
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.formRow, children: [
1636
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1637
- "select",
1638
- {
1639
- className: css2.select,
1640
- "aria-label": translate("editCategory"),
1641
- value: draftCategory,
1642
- onChange: (event) => {
1643
- setDraftCategory(event.target.value);
1644
- },
1645
- children: [
1646
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: NO_CATEGORY, children: translate("noCategory") }),
1647
- MEMORY_CATEGORIES.map((category) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: category, children: translate(CATEGORY_LABEL_KEYS[category] ?? category) }, category))
1648
- ]
1649
- }
1650
- ),
1651
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1652
- "input",
1653
- {
1654
- className: css2.field,
1655
- type: "text",
1656
- "aria-label": translate("editSummary"),
1657
- placeholder: translate("editSummaryPlaceholder"),
1658
- value: draftSummary,
1659
- onChange: (event) => {
1660
- setDraftSummary(event.target.value);
1972
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.hint, children: props.hint })
1973
+ ] });
1974
+ }
1975
+ function NumberField(props) {
1976
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.field, children: [
1977
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldHead, { ...props }),
1978
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1979
+ "input",
1980
+ {
1981
+ id: props.id,
1982
+ className: props.invalid ? css2.inputInvalid : css2.input,
1983
+ type: "text",
1984
+ inputMode: "numeric",
1985
+ ...props.invalid ? { "aria-invalid": true } : {},
1986
+ value: String(props.value),
1987
+ disabled: props.disabled,
1988
+ onChange: (e) => props.onChange(e.target.value)
1989
+ }
1990
+ ),
1991
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: props.invalid ? css2.invalid : css2.hint, children: props.invalid ? props.invalidLabel : props.hint })
1992
+ ] });
1993
+ }
1994
+ function CheckboxField(props) {
1995
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.field, children: [
1996
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.head, children: [
1997
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.checkRow, children: [
1998
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1999
+ "input",
2000
+ {
2001
+ id: props.id,
2002
+ type: "checkbox",
2003
+ className: css2.checkbox,
2004
+ checked: props.checked,
2005
+ disabled: props.disabled,
2006
+ onChange: (e) => props.onChange(e.target.checked)
1661
2007
  }
1662
- }
1663
- )
2008
+ ),
2009
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { className: css2.checkLabel, htmlFor: props.id, children: props.label })
2010
+ ] }),
2011
+ props.overridden ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.badges, children: [
2012
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: props.overriddenLabel }),
2013
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.reset, disabled: props.disabled, onClick: props.onReset, children: props.resetLabel })
2014
+ ] }) : null
1664
2015
  ] }),
1665
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.actions, children: [
1666
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1667
- "button",
1668
- {
1669
- type: "button",
1670
- className: css2.actionBtn,
1671
- disabled: draftContent.trim() === "",
1672
- onClick: () => {
1673
- onSave({
1674
- content: draftContent,
1675
- // '' selects "none": pass null so the controller clears the field;
1676
- // an untouched pick passes the current value through.
1677
- category: draftCategory === NO_CATEGORY ? null : draftCategory,
1678
- summary: draftSummary
1679
- });
1680
- },
1681
- children: translate("saveEdits")
1682
- }
1683
- ),
1684
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.actionBtn, onClick: onCancel, children: translate("cancelEdits") })
1685
- ] })
2016
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.hint, children: props.hint })
1686
2017
  ] });
1687
2018
  }
1688
- function EntryRow(props) {
1689
- const { entry, expanded, staleLabel, staleHint, pinnedLabel, neverRecalledLabel, scopeLabels, translate, onToggle, loadRaw, onSaveEdits, onDelete, onTogglePin, onToggleArchive } = props;
1690
- const category = entry.category;
1691
- const projectName = entry.projectName;
1692
- const isStale = entry.staleSince !== void 0;
1693
- const isPinned = entry.pinned === true;
1694
- const [editing, setEditing] = (0, import_react2.useState)(false);
1695
- const [confirmingDelete, setConfirmingDelete] = (0, import_react2.useState)(false);
1696
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: isStale ? `${css2.row} ${css2.rowStale}` : css2.row, children: [
1697
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.badges, children: [
1698
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: scopeLabels[entry.scope] }),
1699
- category === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: translate(CATEGORY_LABEL_KEYS[category] ?? category) }),
1700
- projectName === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.project, children: projectName }),
1701
- isPinned ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${css2.badge} ${css2.badgePinned}`, children: `\u{1F4CC} ${pinnedLabel}` }) : null,
1702
- isStale ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${css2.badge} ${css2.badgeStale}`, title: staleHint, "aria-label": staleHint, children: `\u{1F634} ${staleLabel}` }) : null
1703
- ] }),
1704
- editing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1705
- EntryEditor,
2019
+ function TextareaField(props) {
2020
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.field, children: [
2021
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldHead, { ...props }),
2022
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2023
+ "textarea",
1706
2024
  {
1707
- entry,
1708
- translate,
1709
- loadRaw,
1710
- onSave: (edits) => {
1711
- setEditing(false);
1712
- onSaveEdits(edits);
1713
- },
1714
- onCancel: () => {
1715
- setEditing(false);
1716
- }
2025
+ id: props.id,
2026
+ className: css2.textarea,
2027
+ value: props.value,
2028
+ disabled: props.disabled,
2029
+ rows: 4,
2030
+ onChange: (e) => props.onChange(e.target.value)
1717
2031
  }
1718
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2032
+ ),
2033
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.hint, children: props.hint })
2034
+ ] });
2035
+ }
2036
+
2037
+ // src/client/form.ts
2038
+ var import_react3 = require("react");
2039
+ function useFormSnapshot(form) {
2040
+ return (0, import_react3.useSyncExternalStore)(
2041
+ (listener) => form.subscribe(listener),
2042
+ () => form.getSnapshot()
2043
+ );
2044
+ }
2045
+ function isOverridden(snapshot, field) {
2046
+ const user = snapshot.user;
2047
+ if (user === void 0 || user === null || typeof user !== "object") return false;
2048
+ return Object.prototype.hasOwnProperty.call(user, field);
2049
+ }
2050
+ async function submitSection(form, draft, committed) {
2051
+ const ops = [];
2052
+ for (const key of Object.keys(draft)) {
2053
+ if (draft[key] === committed[key]) continue;
2054
+ const value = draft[key];
2055
+ ops.push(value === void 0 ? { op: "unset", path: [key] } : { op: "set", path: [key], value });
2056
+ }
2057
+ if (ops.length === 0) return true;
2058
+ return form.mutate(ops, form.getSnapshot().revision);
2059
+ }
2060
+
2061
+ // src/client/MemoryPluginCard.tsx
2062
+ var import_jsx_runtime4 = require("react/jsx-runtime");
2063
+ var MODES = ["digest", "policy-only", "full", "index", "custom", "off"];
2064
+ var DEFAULTS = {
2065
+ memoryMode: "digest",
2066
+ memoryPolicyCustomText: "",
2067
+ memoryCharLimit: 5e3,
2068
+ memoryDigestCharLimit: 800,
2069
+ memoryMaxEntries: 20,
2070
+ maxSearchResults: 50,
2071
+ decayDays: 30
2072
+ };
2073
+ var NUMERIC_FIELDS = ["memoryCharLimit", "memoryDigestCharLimit", "memoryMaxEntries", "maxSearchResults", "decayDays"];
2074
+ function MemorySection2(props) {
2075
+ const snap = useFormSnapshot(props.form);
2076
+ const t = props.t;
2077
+ const [open, setOpen] = (0, import_react4.useState)(false);
2078
+ const committed = snap.value ?? {};
2079
+ const [draft, setDraft] = (0, import_react4.useState)({ ...DEFAULTS, ...committed });
2080
+ const [saving, setSaving] = (0, import_react4.useState)(false);
2081
+ const [failed, setFailed] = (0, import_react4.useState)(false);
2082
+ (0, import_react4.useEffect)(() => {
2083
+ setDraft({ ...DEFAULTS, ...committed });
2084
+ setFailed(false);
2085
+ }, [committed]);
2086
+ const edit = (field, value) => {
2087
+ setFailed(false);
2088
+ setDraft((prev) => ({ ...prev, [field]: value }));
2089
+ };
2090
+ const numericInvalid = (field) => {
2091
+ const v = draft[field];
2092
+ if (v === void 0 || v === null) return false;
2093
+ const n = Number(v);
2094
+ return !Number.isFinite(n) || n < 0;
2095
+ };
2096
+ const dirty = JSON.stringify(draft) !== JSON.stringify({ ...DEFAULTS, ...committed });
2097
+ const invalid = NUMERIC_FIELDS.some(numericInvalid);
2098
+ const disabled = !snap.writable;
2099
+ const blocked = !dirty || invalid || saving;
2100
+ if (snap.status !== "ready") return null;
2101
+ const save = async () => {
2102
+ setSaving(true);
2103
+ setFailed(false);
2104
+ try {
2105
+ const accepted = await submitSection(props.form, draft, committed);
2106
+ if (!accepted) setFailed(true);
2107
+ } catch {
2108
+ setFailed(true);
2109
+ } finally {
2110
+ setSaving(false);
2111
+ }
2112
+ };
2113
+ const discard = () => {
2114
+ setDraft({ ...DEFAULTS, ...committed });
2115
+ setFailed(false);
2116
+ };
2117
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("li", { className: `${css2.card}${open ? ` ${css2.cardOpen}` : ""}`, children: [
2118
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1719
2119
  "button",
1720
2120
  {
1721
2121
  type: "button",
1722
- className: expanded ? `${css2.content} ${css2.contentOpen}` : css2.content,
1723
- "aria-expanded": expanded,
1724
- onClick: onToggle,
1725
- children: entry.content
2122
+ className: css2.header,
2123
+ "aria-expanded": open,
2124
+ "aria-label": `${t(open ? "collapse" : "expand")}: ${t("cardTitle")}`,
2125
+ onClick: () => {
2126
+ setOpen(!open);
2127
+ },
2128
+ children: [
2129
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: css2.headText, children: [
2130
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.name, children: t("cardTitle") }),
2131
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.description, children: t("cardDescription") })
2132
+ ] }),
2133
+ dirty ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.pending, children: t("unsaved") }) : null,
2134
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives.IconChevronDownOutlineMedium, { className: `${css2.chevron}${open ? ` ${css2.chevronOpen}` : ""}` })
2135
+ ]
1726
2136
  }
1727
2137
  ),
1728
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: css2.meta, children: [
1729
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: `${translate("metaCreated")} ${formatTs(entry.createdAt, "\u2014")}` }),
1730
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: `${translate("metaUpdated")} ${formatTs(entry.updatedAt, "\u2014")}` }),
1731
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: entry.lastRecalledAt === void 0 ? `${translate("metaRecalled")} ${neverRecalledLabel}` : `${translate("metaRecalled")} ${formatTs(entry.lastRecalledAt, neverRecalledLabel)}` })
1732
- ] }),
1733
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.actions, children: [
1734
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1735
- "button",
2138
+ open ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.body, children: [
2139
+ !snap.writable ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.readOnly, role: "status", children: t("readOnly") }) : null,
2140
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2141
+ SelectField,
1736
2142
  {
1737
- type: "button",
1738
- className: css2.actionBtn,
1739
- onClick: () => {
1740
- setEditing((current) => !current);
1741
- setConfirmingDelete(false);
1742
- },
1743
- children: editing ? translate("cancelEdits") : translate("editAction")
1744
- }
1745
- ),
1746
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.actionBtn, onClick: onTogglePin, children: isPinned ? translate("unpinAction") : translate("pinAction") }),
1747
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.actionBtn, onClick: onToggleArchive, children: isStale ? translate("unarchiveAction") : translate("archiveAction") }),
1748
- confirmingDelete ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1749
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1750
- "button",
1751
- {
1752
- type: "button",
1753
- className: `${css2.actionBtn} ${css2.actionBtnDanger}`,
1754
- onClick: () => {
1755
- setConfirmingDelete(false);
1756
- onDelete();
1757
- },
1758
- children: translate("confirmDelete")
1759
- }
1760
- ),
1761
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1762
- "button",
1763
- {
1764
- type: "button",
1765
- className: css2.actionBtn,
1766
- onClick: () => {
1767
- setConfirmingDelete(false);
1768
- },
1769
- children: translate("cancelDelete")
2143
+ id: "dsh-memory-mode",
2144
+ label: t("memoryMode"),
2145
+ hint: t("memoryModeHint"),
2146
+ overridden: isOverridden(snap, "memoryMode"),
2147
+ overriddenLabel: t("overridden"),
2148
+ resetLabel: t("reset"),
2149
+ disabled,
2150
+ value: draft.memoryMode ?? "digest",
2151
+ options: MODES.map((m) => ({ value: m, label: m })),
2152
+ onChange: (v) => edit("memoryMode", v),
2153
+ onReset: () => {
2154
+ void props.form.unset("memoryMode");
2155
+ edit("memoryMode", void 0);
1770
2156
  }
1771
- )
1772
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1773
- "button",
1774
- {
1775
- type: "button",
1776
- className: `${css2.actionBtn} ${css2.actionBtnDanger}`,
1777
- onClick: () => {
1778
- setConfirmingDelete(true);
1779
- },
1780
- children: translate("deleteAction")
1781
2157
  }
1782
- )
1783
- ] })
1784
- ] });
1785
- }
1786
- function SuggestionRow(props) {
1787
- const { suggestion, scopeLabels, translate, onAdopt, onReject } = props;
1788
- const [editing, setEditing] = (0, import_react2.useState)(false);
1789
- const [draftContent, setDraftContent] = (0, import_react2.useState)(suggestion.content);
1790
- const category = suggestion.category;
1791
- const projectName = suggestion.projectName;
1792
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: css2.row, children: [
1793
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.badges, children: [
1794
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: scopeLabels[suggestion.scope] }),
1795
- category === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: translate(CATEGORY_LABEL_KEYS[category] ?? category) }),
1796
- projectName === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.project, children: projectName }),
1797
- suggestion.hits > 1 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${css2.badge} ${css2.badgeHits}`, children: translate("hitsBadge").replace("{hits}", String(suggestion.hits)) }) : null,
1798
- suggestion.targetEntryId !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.badge, children: translate("updateProposalBadge") }) : null
1799
- ] }),
1800
- editing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.editForm, children: [
1801
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1802
- "textarea",
2158
+ ),
2159
+ draft.memoryMode === "custom" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2160
+ TextareaField,
1803
2161
  {
1804
- className: css2.textarea,
1805
- "aria-label": translate("editProposalContent"),
1806
- value: draftContent,
1807
- onChange: (event) => {
1808
- setDraftContent(event.target.value);
2162
+ id: "dsh-memory-custom-policy",
2163
+ label: t("customPolicy"),
2164
+ hint: t("customPolicyHint"),
2165
+ overridden: isOverridden(snap, "memoryPolicyCustomText"),
2166
+ overriddenLabel: t("overridden"),
2167
+ resetLabel: t("reset"),
2168
+ disabled,
2169
+ value: draft.memoryPolicyCustomText ?? "",
2170
+ onChange: (v) => edit("memoryPolicyCustomText", v),
2171
+ onReset: () => {
2172
+ void props.form.unset("memoryPolicyCustomText");
2173
+ edit("memoryPolicyCustomText", void 0);
1809
2174
  }
1810
2175
  }
1811
- ),
1812
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.actions, children: [
1813
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1814
- "button",
1815
- {
1816
- type: "button",
1817
- className: css2.actionBtn,
1818
- disabled: draftContent.trim() === "",
1819
- onClick: () => {
1820
- onAdopt({ content: draftContent });
1821
- },
1822
- children: translate("saveAdopt")
1823
- }
1824
- ),
1825
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.actionBtn, onClick: () => {
1826
- onAdopt(void 0);
1827
- }, children: translate("adoptAsIs") })
1828
- ] })
1829
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: `${css2.content} ${css2.contentOpen}`, onClick: () => {
1830
- setEditing(true);
1831
- }, children: suggestion.content }),
1832
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: css2.meta, children: [
1833
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: `${translate("metaSeen")} ${formatTs(suggestion.lastSeenAt, "\u2014")}` }),
1834
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: `${translate("metaFirstSeen")} ${formatTs(suggestion.firstSeenAt, "\u2014")}` })
1835
- ] }),
1836
- !editing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.actions, children: [
1837
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.actionBtn, onClick: () => {
1838
- setEditing(true);
1839
- }, children: translate("editAndAdopt") }),
1840
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.actionBtn, onClick: () => {
1841
- onAdopt(void 0);
1842
- }, children: translate("adoptAction") }),
1843
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: `${css2.actionBtn} ${css2.actionBtnDanger}`, onClick: onReject, children: translate("rejectAction") })
1844
- ] }) : null
1845
- ] });
1846
- }
1847
- function MemorySection(props) {
1848
- const { useMemorySection, t, load } = props;
1849
- const state = useMemorySection((snapshot) => snapshot);
1850
- (0, import_react2.useEffect)(() => {
1851
- void load();
1852
- }, [load]);
1853
- const [tab, setTab] = (0, import_react2.useState)("overview");
1854
- const [searchText, setSearchText] = (0, import_react2.useState)(state.query);
1855
- (0, import_react2.useEffect)(() => {
1856
- const timer = setTimeout(() => {
1857
- props.commitQuery(searchText);
1858
- }, 300);
1859
- return () => {
1860
- clearTimeout(timer);
1861
- };
1862
- }, [searchText]);
1863
- const [expandedIds, setExpandedIds] = (0, import_react2.useState)(/* @__PURE__ */ new Set());
1864
- const toggleExpanded = (id) => {
1865
- setExpandedIds((previous) => {
1866
- const next = new Set(previous);
1867
- if (next.has(id)) next.delete(id);
1868
- else next.add(id);
1869
- return next;
1870
- });
1871
- };
1872
- const scopeLabels = {
1873
- global: t("dashGlobal"),
1874
- project: t("dashProject"),
1875
- user: t("dashUser")
1876
- };
1877
- const workspaceEnabled = state.scope === "all" || state.scope === "project";
1878
- const total = state.total;
1879
- const shown = state.entries.length;
1880
- const hasMore = shown < total;
1881
- const loadMoreRef = (0, import_react2.useRef)(props.loadMore);
1882
- loadMoreRef.current = props.loadMore;
1883
- const sentinelRef = (0, import_react2.useRef)(null);
1884
- (0, import_react2.useEffect)(() => {
1885
- const element = sentinelRef.current;
1886
- if (element === null || tab !== "manage") return;
1887
- if (typeof IntersectionObserver === "undefined") return;
1888
- const observer = new IntersectionObserver(
1889
- (entries) => {
1890
- if (entries.some((entry) => entry.isIntersecting)) loadMoreRef.current();
1891
- },
1892
- { rootMargin: "240px" }
1893
- );
1894
- observer.observe(element);
1895
- return () => {
1896
- observer.disconnect();
1897
- };
1898
- }, [tab, state.status, shown, total]);
1899
- if (state.status === "error") {
1900
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.section, children: [
1901
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { className: css2.title, children: t("nav") }),
1902
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.error, role: "alert", children: `${t("loadFailed")} ${state.error ?? ""}` }),
1903
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: css2.moreBtn, onClick: () => {
1904
- void load();
1905
- }, children: t("retry") })
1906
- ] });
1907
- }
1908
- if (state.status === "loading" || state.status === "idle") {
1909
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.section, children: [
1910
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { className: css2.title, children: t("nav") }),
1911
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.intro, children: t("loading") })
1912
- ] });
1913
- }
1914
- const health = state.health;
1915
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.section, children: [
1916
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { className: css2.title, children: t("nav") }),
1917
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.intro, children: t("sectionIntro") }),
1918
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.tabs, role: "tablist", "aria-label": t("nav"), children: [
1919
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1920
- "button",
2176
+ ) : null,
2177
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2178
+ NumberField,
1921
2179
  {
1922
- type: "button",
1923
- role: "tab",
1924
- className: css2.tabBtn,
1925
- "aria-selected": tab === "overview",
1926
- onClick: () => {
1927
- setTab("overview");
1928
- },
1929
- children: t("tabOverview")
2180
+ id: "dsh-memory-char-limit",
2181
+ label: t("charLimit"),
2182
+ hint: t("charLimitHint"),
2183
+ overridden: isOverridden(snap, "memoryCharLimit"),
2184
+ overriddenLabel: t("overridden"),
2185
+ resetLabel: t("reset"),
2186
+ invalidLabel: t("invalidNumber"),
2187
+ invalid: numericInvalid("memoryCharLimit"),
2188
+ disabled,
2189
+ value: draft.memoryCharLimit ?? "",
2190
+ onChange: (v) => edit("memoryCharLimit", v === "" ? void 0 : Number(v)),
2191
+ onReset: () => {
2192
+ void props.form.unset("memoryCharLimit");
2193
+ edit("memoryCharLimit", void 0);
2194
+ }
1930
2195
  }
1931
2196
  ),
1932
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1933
- "button",
2197
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2198
+ NumberField,
1934
2199
  {
1935
- type: "button",
1936
- role: "tab",
1937
- className: css2.tabBtn,
1938
- "aria-selected": tab === "review",
1939
- onClick: () => {
1940
- setTab("review");
1941
- },
1942
- children: state.pending.length > 0 ? t("tabReviewWithCount").replace("{count}", String(state.pending.length)) : t("tabReview")
2200
+ id: "dsh-memory-digest-char-limit",
2201
+ label: t("digestCharLimit"),
2202
+ hint: t("digestCharLimitHint"),
2203
+ overridden: isOverridden(snap, "memoryDigestCharLimit"),
2204
+ overriddenLabel: t("overridden"),
2205
+ resetLabel: t("reset"),
2206
+ invalidLabel: t("invalidNumber"),
2207
+ invalid: numericInvalid("memoryDigestCharLimit"),
2208
+ disabled,
2209
+ value: draft.memoryDigestCharLimit ?? "",
2210
+ onChange: (v) => edit("memoryDigestCharLimit", v === "" ? void 0 : Number(v)),
2211
+ onReset: () => {
2212
+ void props.form.unset("memoryDigestCharLimit");
2213
+ edit("memoryDigestCharLimit", void 0);
2214
+ }
1943
2215
  }
1944
2216
  ),
1945
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1946
- "button",
2217
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2218
+ NumberField,
1947
2219
  {
1948
- type: "button",
1949
- role: "tab",
1950
- className: css2.tabBtn,
1951
- "aria-selected": tab === "manage",
1952
- onClick: () => {
1953
- setTab("manage");
1954
- },
1955
- children: t("tabManage")
2220
+ id: "dsh-memory-max-entries",
2221
+ label: t("memoryMaxEntries"),
2222
+ hint: t("memoryMaxEntriesHint"),
2223
+ overridden: isOverridden(snap, "memoryMaxEntries"),
2224
+ overriddenLabel: t("overridden"),
2225
+ resetLabel: t("reset"),
2226
+ invalidLabel: t("invalidNumber"),
2227
+ invalid: numericInvalid("memoryMaxEntries"),
2228
+ disabled,
2229
+ value: draft.memoryMaxEntries ?? "",
2230
+ onChange: (v) => edit("memoryMaxEntries", v === "" ? void 0 : Number(v)),
2231
+ onReset: () => {
2232
+ void props.form.unset("memoryMaxEntries");
2233
+ edit("memoryMaxEntries", void 0);
2234
+ }
1956
2235
  }
1957
- )
1958
- ] }),
1959
- tab === "overview" ? health === null ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.dash, children: [
1960
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1961
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statValue, children: health.totalEntries }),
1962
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("dashTotal") })
1963
- ] }),
1964
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1965
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statValue, children: health.byScope.global }),
1966
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("scopeGlobal") })
1967
- ] }),
1968
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1969
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statValue, children: health.byScope.user }),
1970
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("scopeUser") })
1971
- ] }),
1972
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1973
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statValue, children: health.byScope.project }),
1974
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("scopeProject") })
1975
- ] }),
1976
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1977
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statValue, children: health.pinned }),
1978
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("dashPinned") })
1979
- ] }),
1980
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: `${css2.stat} ${css2.statStale}`, title: t("dashStaleHint"), children: [
1981
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${css2.statValue}${(health.stale ?? 0) > 0 ? "" : ` ${css2.statValueMuted}`}`, children: health.stale ?? 0 }),
1982
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("dashStale") })
1983
- ] }),
1984
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1985
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statValue, children: health.auditRecords }),
1986
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("dashAudit") })
1987
- ] }),
1988
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1989
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${css2.statValue} ${css2.statValueMuted}`, children: formatTs(health.lastActivityTs, t("dashLastActivityNever")) }),
1990
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("dashLastActivity") })
1991
- ] }),
1992
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: css2.stat, children: [
1993
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: `${css2.statValue} ${css2.statValueMuted}`, children: formatTs(health.lastExtractionTs, t("dashLastActivityNever")) }),
1994
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.statLabel, children: t("dashLastExtraction") })
1995
- ] })
1996
- ] }) : null,
1997
- tab === "review" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1998
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.reviewHead, children: t("reviewIntro") }),
1999
- state.actionError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.error, role: "alert", children: state.actionError }),
2000
- state.pending.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.empty, children: t("reviewEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: css2.list, children: state.pending.map((suggestion) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2001
- SuggestionRow,
2236
+ ),
2237
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2238
+ NumberField,
2002
2239
  {
2003
- suggestion,
2004
- scopeLabels,
2005
- translate: t,
2006
- onAdopt: (edits) => {
2007
- void props.adoptSuggestion(suggestion.id, edits);
2008
- },
2009
- onReject: () => {
2010
- void props.rejectSuggestion(suggestion.id);
2011
- }
2012
- },
2013
- suggestion.id
2014
- )) })
2015
- ] }) : null,
2016
- tab === "manage" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
2017
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.toolbar, children: [
2018
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.toolbarRow, children: [
2019
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.toolbarLabel, children: t("searchLabel") }),
2020
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: css2.seg, role: "group", "aria-label": t("nav"), children: SCOPES.map(({ value, labelKey }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2021
- "button",
2022
- {
2023
- type: "button",
2024
- className: css2.segBtn,
2025
- "aria-pressed": state.scope === value,
2026
- onClick: () => {
2027
- props.setScope(value);
2028
- },
2029
- children: t(labelKey)
2030
- },
2031
- value
2032
- )) }),
2033
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
2034
- "select",
2035
- {
2036
- className: css2.select,
2037
- "aria-label": t("workspaceLabel"),
2038
- disabled: !workspaceEnabled,
2039
- value: state.projectName ?? "",
2040
- onChange: (event) => {
2041
- props.setProject(event.target.value);
2042
- },
2043
- children: [
2044
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: t("workspaceAll") }),
2045
- state.projects.map((name) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: name, children: name }, name))
2046
- ]
2047
- }
2048
- ),
2049
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2050
- "input",
2051
- {
2052
- type: "search",
2053
- className: css2.input,
2054
- "aria-label": t("searchLabel"),
2055
- placeholder: t("searchPlaceholder"),
2056
- value: searchText,
2057
- onChange: (event) => {
2058
- setSearchText(event.target.value);
2059
- }
2060
- }
2061
- )
2062
- ] }),
2063
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.toolbarRow, children: [
2064
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: css2.toolbarLabel, children: t("categoryLabel") }),
2065
- MEMORY_CATEGORIES.map((category) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2066
- "button",
2067
- {
2068
- type: "button",
2069
- className: css2.chip,
2070
- "aria-pressed": state.categories.includes(category),
2071
- onClick: () => {
2072
- props.toggleCategory(category);
2073
- },
2074
- children: translateCategory(category, t)
2075
- },
2076
- category
2077
- ))
2078
- ] })
2079
- ] }),
2080
- state.error === null ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.error, role: "alert", children: state.error }),
2081
- state.actionError === null ? null : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.error, role: "alert", children: state.actionError }),
2082
- total === 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.empty, children: t(emptyKeyOf(state)) }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
2083
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: css2.list, children: state.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2084
- EntryRow,
2085
- {
2086
- entry,
2087
- expanded: expandedIds.has(entry.id),
2088
- staleLabel: t("staleMark"),
2089
- staleHint: t("staleHint"),
2090
- pinnedLabel: t("pinnedBadge"),
2091
- neverRecalledLabel: t("neverRecalled"),
2092
- scopeLabels,
2093
- translate: t,
2094
- onToggle: () => {
2095
- toggleExpanded(entry.id);
2096
- },
2097
- loadRaw: props.loadRawContent,
2098
- onSaveEdits: (edits) => {
2099
- void props.saveEntryEdits(entry.id, edits);
2100
- },
2101
- onDelete: () => {
2102
- void props.deleteEntry(entry.id);
2103
- },
2104
- onTogglePin: () => {
2105
- void props.togglePin(entry);
2106
- },
2107
- onToggleArchive: () => {
2108
- void props.toggleArchive(entry);
2109
- }
2110
- },
2111
- entry.id
2112
- )) }),
2113
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: css2.more, children: [
2114
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: css2.count, children: t("shownCount").replace("{shown}", String(shown)).replace("{total}", String(total)) }),
2115
- hasMore ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
2116
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: sentinelRef, className: css2.sentinel, "aria-hidden": "true" }),
2117
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2118
- "button",
2119
- {
2120
- type: "button",
2121
- className: css2.moreBtn,
2122
- disabled: state.loadingMore,
2123
- onClick: () => {
2124
- props.loadMore();
2125
- },
2126
- children: state.loadingMore ? t("loading") : t("loadMore")
2127
- }
2128
- )
2129
- ] }) : null
2130
- ] })
2131
- ] })
2132
- ] }) : null
2133
- ] });
2134
- }
2135
- function translateCategory(category, t) {
2136
- const key = CATEGORY_LABEL_KEYS[category];
2137
- return key === void 0 ? category : t(key);
2138
- }
2139
-
2140
- // src/client/IdentitySection.tsx
2141
- var import_react3 = require("react");
2142
- var import_jsx_runtime4 = require("react/jsx-runtime");
2143
- var KINDS = [
2144
- { kind: "soul", titleKey: "identitySoulTitle", emptyKey: "identitySoulEmpty", file: "SOUL.md" },
2145
- { kind: "user", titleKey: "identityUserTitle", emptyKey: "identityUserEmpty", file: "USER.md" }
2146
- ];
2147
- function formatTs2(ts) {
2148
- return new Date(ts).toLocaleString();
2149
- }
2150
- function sourceLabel(source, translate) {
2151
- if (source === "seed") return translate("identitySourceSeed");
2152
- if (source === "ui") return translate("identitySourceUi");
2153
- return translate("identitySourceTool");
2154
- }
2155
- function exportDocument(file, content) {
2156
- if (typeof Blob === "undefined" || typeof URL.createObjectURL !== "function") return;
2157
- const blob = new Blob([content], { type: "text/markdown" });
2158
- const url = URL.createObjectURL(blob);
2159
- const anchor = document.createElement("a");
2160
- anchor.href = url;
2161
- anchor.download = file;
2162
- anchor.click();
2163
- URL.revokeObjectURL(url);
2164
- }
2165
- function DocumentPanel(props) {
2166
- const { kind, file, title, emptyHint, record, history, translate, onRevert } = props;
2167
- const [confirmingVersion, setConfirmingVersion] = (0, import_react3.useState)(null);
2168
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.row, "data-testid": `identity-panel-${kind}`, children: [
2169
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.reviewHead, children: [
2170
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.title, children: title }),
2171
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.badges, children: record !== null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2172
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.badge, children: translate("identityCurrentVersion").replace("{version}", String(record.version)) }),
2173
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2174
- "button",
2175
- {
2176
- type: "button",
2177
- className: css2.moreBtn,
2178
- onClick: () => {
2179
- exportDocument(file, record.content);
2180
- },
2181
- children: translate("identityExport")
2240
+ id: "dsh-memory-max-search",
2241
+ label: t("maxSearchResults"),
2242
+ hint: t("maxSearchResultsHint"),
2243
+ overridden: isOverridden(snap, "maxSearchResults"),
2244
+ overriddenLabel: t("overridden"),
2245
+ resetLabel: t("reset"),
2246
+ invalidLabel: t("invalidNumber"),
2247
+ invalid: numericInvalid("maxSearchResults"),
2248
+ disabled,
2249
+ value: draft.maxSearchResults ?? "",
2250
+ onChange: (v) => edit("maxSearchResults", v === "" ? void 0 : Number(v)),
2251
+ onReset: () => {
2252
+ void props.form.unset("maxSearchResults");
2253
+ edit("maxSearchResults", void 0);
2182
2254
  }
2183
- )
2184
- ] }) : null })
2185
- ] }),
2186
- record === null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.empty, children: emptyHint }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2187
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { className: `${css2.content} ${css2.contentOpen}`, children: record.content }),
2188
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.list, children: [
2189
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: css2.meta, children: translate("identityHistoryTitle") }),
2190
- history.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.empty, children: translate("identityEmptyHistory") }) : history.map((snapshot) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.row, children: [
2191
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.content, children: `v${snapshot.version} \xB7 ${formatTs2(snapshot.ts)} \xB7 ${sourceLabel(snapshot.source, translate)}` }),
2192
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: css2.actions, children: confirmingVersion === snapshot.version ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2193
- "button",
2194
- {
2195
- type: "button",
2196
- className: css2.actionBtnDanger,
2197
- onClick: () => {
2198
- setConfirmingVersion(null);
2199
- void onRevert(kind, snapshot.version);
2200
- },
2201
- children: translate("identityRevertConfirm")
2202
- }
2203
- ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2204
- "button",
2205
- {
2206
- type: "button",
2207
- className: css2.actionBtn,
2208
- onClick: () => {
2209
- setConfirmingVersion(snapshot.version);
2210
- },
2211
- children: translate("identityRevertBtn")
2212
- }
2213
- ) })
2214
- ] }, `${kind}-${snapshot.version}`))
2255
+ }
2256
+ ),
2257
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2258
+ NumberField,
2259
+ {
2260
+ id: "dsh-memory-decay-days",
2261
+ label: t("decayDays"),
2262
+ hint: t("decayDaysHint"),
2263
+ overridden: isOverridden(snap, "decayDays"),
2264
+ overriddenLabel: t("overridden"),
2265
+ resetLabel: t("reset"),
2266
+ invalidLabel: t("invalidNumber"),
2267
+ invalid: numericInvalid("decayDays"),
2268
+ disabled,
2269
+ value: draft.decayDays ?? "",
2270
+ onChange: (v) => edit("decayDays", v === "" ? void 0 : Number(v)),
2271
+ onReset: () => {
2272
+ void props.form.unset("decayDays");
2273
+ edit("decayDays", void 0);
2274
+ }
2275
+ }
2276
+ ),
2277
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.footer, children: [
2278
+ failed ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.failed, role: "status", children: t("saveFailed") }) : null,
2279
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: css2.discard, disabled: !dirty || saving, onClick: discard, children: t("discard") }),
2280
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: css2.save, disabled: blocked, onClick: () => void save(), children: t(saving ? "saving" : "save") })
2215
2281
  ] })
2216
- ] })
2217
- ] });
2218
- }
2219
- function IdentitySection(props) {
2220
- const { useIdentitySection, t, load } = props;
2221
- const state = useIdentitySection((snapshot) => snapshot);
2222
- (0, import_react3.useEffect)(() => {
2223
- void load();
2224
- }, [load]);
2225
- if (state.status === "error") {
2226
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.section, children: [
2227
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: css2.title, children: t("identityNav") }),
2228
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.error, role: "alert", children: `${t("loadFailed")} ${state.error ?? ""}` }),
2229
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: css2.moreBtn, onClick: () => {
2230
- void load();
2231
- }, children: t("retry") })
2232
- ] });
2233
- }
2234
- if (state.status === "loading" || state.status === "idle") {
2235
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.section, children: [
2236
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: css2.title, children: t("identityNav") }),
2237
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.intro, children: t("loading") })
2238
- ] });
2239
- }
2240
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css2.section, children: [
2241
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { className: css2.title, children: t("identityNav") }),
2242
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.intro, children: t("identitySectionIntro") }),
2243
- state.actionError !== null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: css2.error, role: "alert", children: state.actionError }) : null,
2244
- KINDS.map(({ kind, titleKey, emptyKey, file }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2245
- DocumentPanel,
2246
- {
2247
- kind,
2248
- file,
2249
- title: t(titleKey),
2250
- emptyHint: t(emptyKey),
2251
- record: kind === "soul" ? state.soul : state.user,
2252
- history: state.history[kind],
2253
- translate: t,
2254
- onRevert: (revertKind, version) => props.revert(revertKind, version)
2255
- },
2256
- kind
2257
- ))
2282
+ ] }) : null
2258
2283
  ] });
2259
2284
  }
2260
2285
 
2261
2286
  // src/client/NamespaceCard.tsx
2262
- var import_react4 = require("react");
2287
+ var import_react5 = require("react");
2263
2288
  var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
2264
2289
  var import_jsx_runtime5 = require("react/jsx-runtime");
2265
- function namespaceCard(spec) {
2266
- return function SpecBoundNamespaceCard(props) {
2267
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(NamespaceCard, { ...props, spec });
2268
- };
2269
- }
2270
- function isOverridden2(snap, field) {
2271
- const user = snap.user;
2272
- if (user === void 0 || user === null || typeof user !== "object") return false;
2273
- return Object.prototype.hasOwnProperty.call(user, field);
2274
- }
2275
2290
  var MODEL_CATALOG_TIMEOUT_MS = 15e3;
2276
- function NamespaceCard(props) {
2277
- const snap = props.useNs((s) => s);
2291
+ function NamespaceSection(props) {
2292
+ const snap = useFormSnapshot(props.form);
2278
2293
  const t = props.t;
2279
2294
  const spec = props.spec;
2280
- const [open, setOpen] = (0, import_react4.useState)(false);
2295
+ const [open, setOpen] = (0, import_react5.useState)(false);
2281
2296
  const canLoadCatalog = typeof props.loadCatalog === "function";
2282
- const catalogStartedRef = (0, import_react4.useRef)(false);
2283
- const [catalog, setCatalog] = (0, import_react4.useState)(void 0);
2284
- const [catalogStatus, setCatalogStatus] = (0, import_react4.useState)("idle");
2285
- (0, import_react4.useEffect)(() => {
2297
+ const catalogStartedRef = (0, import_react5.useRef)(false);
2298
+ const [catalog, setCatalog] = (0, import_react5.useState)(void 0);
2299
+ const [catalogStatus, setCatalogStatus] = (0, import_react5.useState)("idle");
2300
+ (0, import_react5.useEffect)(() => {
2286
2301
  if (!open || !canLoadCatalog || catalogStartedRef.current) return;
2287
2302
  catalogStartedRef.current = true;
2288
2303
  setCatalogStatus("loading");
@@ -2303,10 +2318,10 @@ function NamespaceCard(props) {
2303
2318
  })();
2304
2319
  }, [open, canLoadCatalog]);
2305
2320
  const committed = snap.value ?? {};
2306
- const [draft, setDraft] = (0, import_react4.useState)({ ...committed });
2307
- const [saving, setSaving] = (0, import_react4.useState)(false);
2308
- const [failed, setFailed] = (0, import_react4.useState)(false);
2309
- (0, import_react4.useEffect)(() => {
2321
+ const [draft, setDraft] = (0, import_react5.useState)({ ...committed });
2322
+ const [saving, setSaving] = (0, import_react5.useState)(false);
2323
+ const [failed, setFailed] = (0, import_react5.useState)(false);
2324
+ (0, import_react5.useEffect)(() => {
2310
2325
  setDraft({ ...committed });
2311
2326
  setFailed(false);
2312
2327
  }, [committed]);
@@ -2330,13 +2345,8 @@ function NamespaceCard(props) {
2330
2345
  setSaving(true);
2331
2346
  setFailed(false);
2332
2347
  try {
2333
- const ops = [];
2334
- for (const field of spec.fields) {
2335
- if (draft[field.key] === committed[field.key]) continue;
2336
- const value = draft[field.key];
2337
- ops.push(value === void 0 ? props.unset(field.key) : props.set(field.key, value));
2338
- }
2339
- await Promise.all(ops);
2348
+ const accepted = await submitSection(props.form, draft, committed);
2349
+ if (!accepted) setFailed(true);
2340
2350
  } catch {
2341
2351
  setFailed(true);
2342
2352
  } finally {
@@ -2399,29 +2409,29 @@ function NamespaceCard(props) {
2399
2409
  }
2400
2410
  );
2401
2411
  };
2402
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { className: `${css.card}${open ? ` ${css.cardOpen}` : ""}`, children: [
2412
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { className: `${css2.card}${open ? ` ${css2.cardOpen}` : ""}`, children: [
2403
2413
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2404
2414
  "button",
2405
2415
  {
2406
2416
  type: "button",
2407
- className: css.header,
2417
+ className: css2.header,
2408
2418
  "aria-expanded": open,
2409
2419
  "aria-label": `${t(open ? "collapse" : "expand")}: ${t(spec.titleKey)}`,
2410
2420
  onClick: () => {
2411
2421
  setOpen(!open);
2412
2422
  },
2413
2423
  children: [
2414
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: css.headText, children: [
2415
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css.name, children: t(spec.titleKey) }),
2416
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css.description, children: t(spec.descriptionKey) })
2424
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: css2.headText, children: [
2425
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css2.name, children: t(spec.titleKey) }),
2426
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css2.description, children: t(spec.descriptionKey) })
2417
2427
  ] }),
2418
- dirty ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css.pending, children: t("unsaved") }) : null,
2419
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives2.IconChevronDownOutline14, { className: `${css.chevron}${open ? ` ${css.chevronOpen}` : ""}` })
2428
+ dirty ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css2.pending, children: t("unsaved") }) : null,
2429
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives2.IconChevronDownOutlineMedium, { className: `${css2.chevron}${open ? ` ${css2.chevronOpen}` : ""}` })
2420
2430
  ]
2421
2431
  }
2422
2432
  ),
2423
- open ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css.body, children: [
2424
- !snap.writable ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: css.readOnly, role: "status", children: t("readOnly") }) : null,
2433
+ open ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css2.body, children: [
2434
+ !snap.writable ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: css2.readOnly, role: "status", children: t("readOnly") }) : null,
2425
2435
  spec.fields.map((field) => {
2426
2436
  const label = t(field.labelKey ?? field.key);
2427
2437
  const hint = t(field.hintKey ?? `${field.key}Hint`);
@@ -2430,12 +2440,12 @@ function NamespaceCard(props) {
2430
2440
  id: `dsh-settings-${field.key}`,
2431
2441
  label,
2432
2442
  hint,
2433
- overridden: isOverridden2(snap, field.key),
2443
+ overridden: isOverridden(snap, field.key),
2434
2444
  overriddenLabel: t("overridden"),
2435
2445
  resetLabel: t("reset"),
2436
2446
  disabled,
2437
2447
  onReset: () => {
2438
- void props.unset(field.key);
2448
+ void props.form.unset(field.key);
2439
2449
  edit(field.key, void 0);
2440
2450
  }
2441
2451
  };
@@ -2474,15 +2484,133 @@ function NamespaceCard(props) {
2474
2484
  }
2475
2485
  );
2476
2486
  }),
2477
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css.footer, children: [
2478
- failed ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: css.failed, role: "status", children: t("saveFailed") }) : null,
2479
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: css.discard, disabled: !dirty || saving, onClick: discard, children: t("discard") }),
2480
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: css.save, disabled: blocked, onClick: () => void save(), children: t(saving ? "saving" : "save") })
2487
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css2.footer, children: [
2488
+ failed ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: css2.failed, role: "status", children: t("saveFailed") }) : null,
2489
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: css2.discard, disabled: !dirty || saving, onClick: discard, children: t("discard") }),
2490
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: css2.save, disabled: blocked, onClick: () => void save(), children: t(saving ? "saving" : "save") })
2481
2491
  ] })
2482
2492
  ] }) : null
2483
2493
  ] });
2484
2494
  }
2485
2495
 
2496
+ // src/client/model-catalog.ts
2497
+ var PROVIDER_FIELD = "extractionModelProvider";
2498
+ function catalogLabel(name, id) {
2499
+ return typeof name === "string" && name.length > 0 && name !== id ? `${name} (${id})` : id;
2500
+ }
2501
+ function providerOptions({ catalog }) {
2502
+ return (catalog?.groups ?? []).filter((g) => typeof g?.id === "string" && g.id.length > 0).map((g) => ({ value: g.id, label: catalogLabel(g.name, g.id) }));
2503
+ }
2504
+ function modelOptions({ catalog, draft }) {
2505
+ const groups = catalog?.groups ?? [];
2506
+ const providerId = draft[PROVIDER_FIELD];
2507
+ const hasProvider = typeof providerId === "string" && providerId.length > 0;
2508
+ const scoped = hasProvider ? groups.filter((g) => g.id === providerId) : groups;
2509
+ const seen = /* @__PURE__ */ new Set();
2510
+ const options = [];
2511
+ for (const g of scoped) {
2512
+ for (const m of g.models ?? []) {
2513
+ if (typeof m?.id !== "string" || m.id.length === 0 || seen.has(m.id)) continue;
2514
+ seen.add(m.id);
2515
+ const label = hasProvider ? catalogLabel(m.name, m.id) : `${g.id} \xB7 ${catalogLabel(m.name, m.id)}`;
2516
+ options.push({ value: m.id, label });
2517
+ }
2518
+ }
2519
+ return options;
2520
+ }
2521
+ function consolidationOptions() {
2522
+ return [
2523
+ { value: "two-tier", label: "two-tier" },
2524
+ { value: "legacy-judge", label: "legacy-judge" }
2525
+ ];
2526
+ }
2527
+
2528
+ // src/client/SettingsPage.tsx
2529
+ var import_jsx_runtime6 = require("react/jsx-runtime");
2530
+ var MEMORY_ENTRY_IDS = ["memory", "memory-review", "memory-identity", "memory-notes", "memory-autorecall"];
2531
+ var NOTES_SPEC = {
2532
+ titleKey: "notesCardTitle",
2533
+ descriptionKey: "notesCardDescription",
2534
+ fields: [
2535
+ { key: "notesEnabled", kind: "checkbox" },
2536
+ { key: "notesConventionsCharLimit", kind: "number", minValue: 0 },
2537
+ { key: "notesPitfallsCharLimit", kind: "number", minValue: 0 },
2538
+ { key: "notesMaxEntriesPerFile", kind: "number", minValue: 0 }
2539
+ ]
2540
+ };
2541
+ var AUTORECALL_SPEC = {
2542
+ titleKey: "autoRecallCardTitle",
2543
+ descriptionKey: "autoRecallCardDescription",
2544
+ fields: [
2545
+ { key: "autoRecallEnabled", kind: "checkbox" },
2546
+ { key: "autoRecallLimit", kind: "number", minValue: 1 },
2547
+ { key: "autoRecallMinChars", kind: "number", minValue: 1 },
2548
+ { key: "hitSignalEnabled", kind: "checkbox", labelKey: "hitSignalEnabled", hintKey: "hitSignalEnabledHint" },
2549
+ { key: "hitSignalThreshold", kind: "number", minValue: 0, labelKey: "hitSignalThreshold", hintKey: "hitSignalThresholdHint" }
2550
+ ]
2551
+ };
2552
+ var IDENTITY_SPEC = {
2553
+ titleKey: "identityCardTitle",
2554
+ descriptionKey: "identityCardDescription",
2555
+ fields: [
2556
+ { key: "identityEnabled", kind: "checkbox" },
2557
+ { key: "soulCharLimit", kind: "number", minValue: 0 },
2558
+ { key: "userCharLimit", kind: "number", minValue: 0 },
2559
+ { key: "identitySeedDir", kind: "text" }
2560
+ ]
2561
+ };
2562
+ var REVIEW_SPEC = {
2563
+ titleKey: "reviewCardTitle",
2564
+ descriptionKey: "reviewCardDescription",
2565
+ fields: [
2566
+ { key: "reviewEnabled", kind: "checkbox" },
2567
+ { key: "reviewCandidateThreshold", kind: "number", labelKey: "reviewThreshold", hintKey: "reviewThresholdHint", minValue: 1 },
2568
+ { key: "flushOnCompaction", kind: "checkbox" },
2569
+ { key: "flushOnDispose", kind: "checkbox" },
2570
+ {
2571
+ key: PROVIDER_FIELD,
2572
+ kind: "select",
2573
+ options: (input) => providerOptions(input),
2574
+ emptyOptionKey: "followSessionRoute"
2575
+ },
2576
+ {
2577
+ key: "extractionModelModel",
2578
+ kind: "select",
2579
+ options: (input) => modelOptions(input),
2580
+ emptyOptionKey: "followSessionRoute"
2581
+ },
2582
+ { key: "extractionBudget", kind: "number" },
2583
+ { key: "judgeEnabled", kind: "checkbox" },
2584
+ { key: "consolidation", kind: "select", options: () => consolidationOptions(), labelKey: "consolidation", hintKey: "consolidationHint" },
2585
+ { key: "pitfallStreakThreshold", kind: "number", minValue: 1 },
2586
+ {
2587
+ key: "confirmBeforeWrite",
2588
+ kind: "checkbox",
2589
+ labelKey: "confirmBeforeWrite",
2590
+ hintKey: "confirmBeforeWriteHint"
2591
+ },
2592
+ { key: "curatorEnabled", kind: "checkbox" },
2593
+ { key: "curatorEveryNSessions", kind: "number", minValue: 1 },
2594
+ { key: "curatorMaxEntries", kind: "number", minValue: 1 },
2595
+ { key: "curatorMinChars", kind: "number", minValue: 1 },
2596
+ { key: "sweepEnabled", kind: "checkbox", labelKey: "sweepEnabled", hintKey: "sweepEnabledHint" },
2597
+ { key: "sweepEveryNSessions", kind: "number", minValue: 1, labelKey: "sweepEveryNSessions", hintKey: "sweepEveryNSessionsHint" },
2598
+ { key: "sweepTopN", kind: "number", minValue: 2, labelKey: "sweepTopN", hintKey: "sweepTopNHint" }
2599
+ ]
2600
+ };
2601
+ function SettingsPage(props) {
2602
+ if (props.view !== "page") return null;
2603
+ const t = props.t;
2604
+ const { forms, loadCatalog } = props;
2605
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("ul", { className: css2.pageList, children: [
2606
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MemorySection2, { form: forms.memory, t }),
2607
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NamespaceSection, { spec: NOTES_SPEC, form: forms["memory-notes"], t }),
2608
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NamespaceSection, { spec: AUTORECALL_SPEC, form: forms["memory-autorecall"], t }),
2609
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NamespaceSection, { spec: IDENTITY_SPEC, form: forms["memory-identity"], t }),
2610
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NamespaceSection, { spec: REVIEW_SPEC, form: forms["memory-review"], t, ...loadCatalog === void 0 ? {} : { loadCatalog } })
2611
+ ] });
2612
+ }
2613
+
2486
2614
  // src/client/identity-section-store.ts
2487
2615
  var import_dsh_client_store2 = require("@deepseek-ai/dsh-client-store");
2488
2616
  var INITIAL2 = {
@@ -2581,38 +2709,6 @@ function messageOf2(error) {
2581
2709
  return error instanceof Error ? error.message : String(error);
2582
2710
  }
2583
2711
 
2584
- // src/client/model-catalog.ts
2585
- var PROVIDER_FIELD = "extractionModelProvider";
2586
- function catalogLabel(name, id) {
2587
- return typeof name === "string" && name.length > 0 && name !== id ? `${name} (${id})` : id;
2588
- }
2589
- function providerOptions({ catalog }) {
2590
- return (catalog?.groups ?? []).filter((g) => typeof g?.id === "string" && g.id.length > 0).map((g) => ({ value: g.id, label: catalogLabel(g.name, g.id) }));
2591
- }
2592
- function modelOptions({ catalog, draft }) {
2593
- const groups = catalog?.groups ?? [];
2594
- const providerId = draft[PROVIDER_FIELD];
2595
- const hasProvider = typeof providerId === "string" && providerId.length > 0;
2596
- const scoped = hasProvider ? groups.filter((g) => g.id === providerId) : groups;
2597
- const seen = /* @__PURE__ */ new Set();
2598
- const options = [];
2599
- for (const g of scoped) {
2600
- for (const m of g.models ?? []) {
2601
- if (typeof m?.id !== "string" || m.id.length === 0 || seen.has(m.id)) continue;
2602
- seen.add(m.id);
2603
- const label = hasProvider ? catalogLabel(m.name, m.id) : `${g.id} \xB7 ${catalogLabel(m.name, m.id)}`;
2604
- options.push({ value: m.id, label });
2605
- }
2606
- }
2607
- return options;
2608
- }
2609
- function consolidationOptions() {
2610
- return [
2611
- { value: "two-tier", label: "two-tier" },
2612
- { value: "legacy-judge", label: "legacy-judge" }
2613
- ];
2614
- }
2615
-
2616
2712
  // src/client/locales.ts
2617
2713
  var en = {
2618
2714
  // Card chrome (mirrors the PluginCard shell's keys).
@@ -3028,88 +3124,11 @@ var zh = {
3028
3124
  };
3029
3125
 
3030
3126
  // src/client/index.ts
3031
- var NOTES_SPEC = {
3032
- titleKey: "notesCardTitle",
3033
- descriptionKey: "notesCardDescription",
3034
- fields: [
3035
- { key: "notesEnabled", kind: "checkbox" },
3036
- { key: "notesConventionsCharLimit", kind: "number", minValue: 0 },
3037
- { key: "notesPitfallsCharLimit", kind: "number", minValue: 0 },
3038
- { key: "notesMaxEntriesPerFile", kind: "number", minValue: 0 }
3039
- ]
3040
- };
3041
- var AUTORECALL_SPEC = {
3042
- titleKey: "autoRecallCardTitle",
3043
- descriptionKey: "autoRecallCardDescription",
3044
- fields: [
3045
- { key: "autoRecallEnabled", kind: "checkbox" },
3046
- { key: "autoRecallLimit", kind: "number", minValue: 1 },
3047
- { key: "autoRecallMinChars", kind: "number", minValue: 1 },
3048
- { key: "hitSignalEnabled", kind: "checkbox", labelKey: "hitSignalEnabled", hintKey: "hitSignalEnabledHint" },
3049
- { key: "hitSignalThreshold", kind: "number", minValue: 0, labelKey: "hitSignalThreshold", hintKey: "hitSignalThresholdHint" }
3050
- ]
3051
- };
3052
- var IDENTITY_SPEC = {
3053
- titleKey: "identityCardTitle",
3054
- descriptionKey: "identityCardDescription",
3055
- fields: [
3056
- { key: "identityEnabled", kind: "checkbox" },
3057
- { key: "soulCharLimit", kind: "number", minValue: 0 },
3058
- { key: "userCharLimit", kind: "number", minValue: 0 },
3059
- { key: "identitySeedDir", kind: "text" }
3060
- ]
3061
- };
3062
- var PROVIDER_FIELD2 = "extractionModelProvider";
3063
- var REVIEW_SPEC = {
3064
- titleKey: "reviewCardTitle",
3065
- descriptionKey: "reviewCardDescription",
3066
- fields: [
3067
- { key: "reviewEnabled", kind: "checkbox" },
3068
- { key: "reviewCandidateThreshold", kind: "number", labelKey: "reviewThreshold", hintKey: "reviewThresholdHint", minValue: 1 },
3069
- { key: "flushOnCompaction", kind: "checkbox" },
3070
- { key: "flushOnDispose", kind: "checkbox" },
3071
- {
3072
- key: PROVIDER_FIELD2,
3073
- kind: "select",
3074
- options: providerOptions,
3075
- emptyOptionKey: "followSessionRoute"
3076
- },
3077
- {
3078
- key: "extractionModelModel",
3079
- kind: "select",
3080
- options: modelOptions,
3081
- emptyOptionKey: "followSessionRoute"
3082
- },
3083
- { key: "extractionBudget", kind: "number" },
3084
- { key: "judgeEnabled", kind: "checkbox" },
3085
- { key: "consolidation", kind: "select", options: consolidationOptions, labelKey: "consolidation", hintKey: "consolidationHint" },
3086
- { key: "pitfallStreakThreshold", kind: "number", minValue: 1 },
3087
- {
3088
- key: "confirmBeforeWrite",
3089
- kind: "checkbox",
3090
- labelKey: "confirmBeforeWrite",
3091
- hintKey: "confirmBeforeWriteHint"
3092
- },
3093
- { key: "curatorEnabled", kind: "checkbox" },
3094
- { key: "curatorEveryNSessions", kind: "number", minValue: 1 },
3095
- { key: "curatorMaxEntries", kind: "number", minValue: 1 },
3096
- { key: "curatorMinChars", kind: "number", minValue: 1 },
3097
- { key: "sweepEnabled", kind: "checkbox", labelKey: "sweepEnabled", hintKey: "sweepEnabledHint" },
3098
- { key: "sweepEveryNSessions", kind: "number", minValue: 1, labelKey: "sweepEveryNSessions", hintKey: "sweepEveryNSessionsHint" },
3099
- { key: "sweepTopN", kind: "number", minValue: 2, labelKey: "sweepTopN", hintKey: "sweepTopNHint" }
3100
- ]
3101
- };
3102
- var inject3 = ["slots", "locale", "connection", "settingsScope"];
3127
+ var inject3 = ["slots", "locale", "connection", "configForms"];
3103
3128
  var NS = "settings.memory";
3129
+ var BUNDLE_NAME = "@chenhw7/dsh-memory";
3104
3130
  var SECTION_ORDER = 25;
3105
3131
  var IDENTITY_SECTION_ORDER = 26;
3106
- var CARDS = [
3107
- { key: "memory" },
3108
- { key: "memory-notes", spec: NOTES_SPEC },
3109
- { key: "memory-autorecall", spec: AUTORECALL_SPEC },
3110
- { key: "memory-identity", spec: IDENTITY_SPEC },
3111
- { key: "memory-review", spec: REVIEW_SPEC }
3112
- ];
3113
3132
  function createMemoryRemoteApi(connection) {
3114
3133
  const call = connection?.rpc?.call;
3115
3134
  if (typeof call !== "function") return void 0;
@@ -3173,41 +3192,23 @@ function apply(ctx) {
3173
3192
  void identityController.load();
3174
3193
  });
3175
3194
  }, "dsh-memory: memory section reload on reconnect");
3176
- ctx.slots.inject("settings.plugin.item", function* () {
3177
- for (const card of CARDS) {
3178
- const scope = ctx.settingsScope.bind({ namespace: card.key });
3179
- if (card.spec === void 0) {
3180
- const typed = scope;
3181
- const injected3 = () => ({
3182
- hooks: { memory: typed },
3183
- set: (field, value) => typed.set(field, value),
3184
- unset: (field) => typed.unset(field)
3185
- });
3186
- yield ctx.slots.register({
3187
- name: "settings.plugin.item",
3188
- key: card.key,
3189
- locale: NS,
3190
- inject: injected3
3191
- }, MemoryPluginCard);
3192
- } else {
3193
- const spec = card.spec;
3194
- const typed = scope;
3195
- const withCatalog = loadCatalog !== void 0 && spec.fields.some((f) => f.kind === "select");
3196
- const injected3 = () => ({
3197
- hooks: { ns: typed },
3198
- set: (field, value) => typed.set(field, value),
3199
- unset: (field) => typed.unset(field),
3200
- ...withCatalog ? { loadCatalog } : {}
3201
- });
3202
- yield ctx.slots.register({
3203
- name: "settings.plugin.item",
3204
- key: card.key,
3205
- locale: NS,
3206
- inject: injected3
3207
- }, namespaceCard(spec));
3208
- }
3209
- }
3210
- });
3195
+ const formsFor = () => {
3196
+ const forms = {};
3197
+ for (const entryId of MEMORY_ENTRY_IDS) forms[entryId] = ctx.configForms.get(entryId);
3198
+ return forms;
3199
+ };
3200
+ ctx.effect(() => ctx.configForms.whileServed([...MEMORY_ENTRY_IDS], () => {
3201
+ const injected3 = () => ({
3202
+ forms: formsFor(),
3203
+ ...loadCatalog === void 0 ? {} : { loadCatalog }
3204
+ });
3205
+ return ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
3206
+ name: "plugins.bundle.config",
3207
+ key: BUNDLE_NAME,
3208
+ locale: NS,
3209
+ inject: injected3
3210
+ }, SettingsPage));
3211
+ }), "dsh-memory: settings page");
3211
3212
  const sectionInjected = () => ({
3212
3213
  hooks: { memorySection: controller.store },
3213
3214
  load: () => controller.load(),