@skillre/dsh-plugin-sticky-wall 0.7.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +34 -11
- package/README.md +35 -14
- package/UNINSTALL.md +22 -7
- package/compatibility.json +78 -1
- package/lib/client.js +1062 -337
- package/lib/config.d.ts +18 -0
- package/lib/config.js +27 -0
- package/lib/frontmatter.d.ts +81 -0
- package/lib/frontmatter.js +440 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +236 -36
- package/lib/migrate.d.ts +62 -0
- package/lib/migrate.js +314 -0
- package/lib/store.d.ts +130 -68
- package/lib/store.js +314 -97
- package/lib/transport.d.ts +7 -4
- package/lib/transport.js +14 -3
- package/lib/types.d.ts +87 -6
- package/lib/types.js +38 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -3
- package/docs/PREVIEW.md +0 -39
package/lib/index.js
CHANGED
|
@@ -7,23 +7,137 @@
|
|
|
7
7
|
* route, and the optional agent tool — belongs to this plugin's Fiber, so
|
|
8
8
|
* stopping or updating the row releases all three with no residue.
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { Config, resolveConfig, resolveNotesDir } from './config.js';
|
|
11
14
|
import { StickyWallStore } from './store.js';
|
|
12
15
|
import { createExecuteRoute } from './transport.js';
|
|
13
|
-
import { LIMITS } from './types.js';
|
|
16
|
+
import { COLORS, LEGACY_DOMAIN_NAME, LEGACY_DOMAIN_VERSION, LIMITS, WIDTHS } from './types.js';
|
|
14
17
|
export { Config, StickyWallStore };
|
|
15
18
|
export const name = 'skillre-sticky-wall';
|
|
16
19
|
/**
|
|
17
|
-
* Required services.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* Required services.
|
|
21
|
+
*
|
|
22
|
+
* `connection` provides the authenticated Client route and is a hard dependency:
|
|
23
|
+
* without it the wall could never be reached, so mounting should fail loudly.
|
|
24
|
+
*
|
|
25
|
+
* `storageDomain` is deliberately NOT listed. Notes live on disk now, and the
|
|
26
|
+
* domain is consulted only when a 0.7.x install still needs migrating, so it is
|
|
27
|
+
* read through `ctx.get()` and its absence is a normal, supported state (a fresh
|
|
28
|
+
* install has nothing to migrate).
|
|
21
29
|
*/
|
|
22
|
-
export const inject = ['
|
|
30
|
+
export const inject = ['connection'];
|
|
23
31
|
/** Read an optional Cordis service without declaring it required. */
|
|
24
32
|
function service(ctx, key) {
|
|
25
33
|
return ctx.get(key);
|
|
26
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The record schema the legacy domain validates every stored note against.
|
|
37
|
+
*
|
|
38
|
+
* This MUST be a real schema. `storageDomain` runs
|
|
39
|
+
* `tableSpec.valueSchema.parse(raw)` on every record while opening the domain,
|
|
40
|
+
* so declaring the table as a bare `{}` makes `valueSchema` undefined, throws on
|
|
41
|
+
* the first record, and — because the spec asks for `invalidRecords:
|
|
42
|
+
* 'backup-and-skip'` — makes the backend move EVERY note aside as
|
|
43
|
+
* `<id>.json.bak.<stamp>` and treat it as absent. That is exactly what shipped
|
|
44
|
+
* in 0.8.0: the migration reported zero notes, seeded a welcome note, and the
|
|
45
|
+
* user's wall appeared empty while the data sat renamed on disk.
|
|
46
|
+
*
|
|
47
|
+
* It is deliberately permissive (`passthrough`, every field optional) because
|
|
48
|
+
* its job is to LOAD a retired format, not to police it: a record missing a
|
|
49
|
+
* field must still migrate with a sane default rather than be quarantined.
|
|
50
|
+
*/
|
|
51
|
+
const LegacyNoteSchema = z
|
|
52
|
+
.object({
|
|
53
|
+
id: z.string().min(1),
|
|
54
|
+
title: z.string().optional(),
|
|
55
|
+
body: z.string().optional(),
|
|
56
|
+
tags: z.array(z.string()).optional(),
|
|
57
|
+
color: z.string().optional(),
|
|
58
|
+
pinned: z.boolean().optional(),
|
|
59
|
+
archived: z.boolean().optional(),
|
|
60
|
+
createdAt: z.string().optional(),
|
|
61
|
+
updatedAt: z.string().optional(),
|
|
62
|
+
layout: z
|
|
63
|
+
.object({
|
|
64
|
+
x: z.number(),
|
|
65
|
+
y: z.number(),
|
|
66
|
+
rotate: z.number(),
|
|
67
|
+
width: z.string(),
|
|
68
|
+
})
|
|
69
|
+
.nullable()
|
|
70
|
+
.optional(),
|
|
71
|
+
})
|
|
72
|
+
.passthrough();
|
|
73
|
+
/**
|
|
74
|
+
* Drain a 0.7.x install's storage-domain notes so they can be migrated.
|
|
75
|
+
*
|
|
76
|
+
* The domain's `notes` table is the ONLY thing read here: the migration writes
|
|
77
|
+
* `.md` files and never writes back, so a failed migration leaves the legacy
|
|
78
|
+
* records untouched and the next start retries. The handle is always closed,
|
|
79
|
+
* even when reading throws, because an open domain reserves its name for the
|
|
80
|
+
* whole process.
|
|
81
|
+
*/
|
|
82
|
+
async function readLegacyNotes(facility) {
|
|
83
|
+
const domain = await facility.open({
|
|
84
|
+
name: LEGACY_DOMAIN_NAME,
|
|
85
|
+
version: LEGACY_DOMAIN_VERSION,
|
|
86
|
+
layout: 'per-record',
|
|
87
|
+
// `backup-and-skip` is kept: it is the only accepted value, and with a real
|
|
88
|
+
// schema it now means what it was meant to mean — one genuinely corrupt
|
|
89
|
+
// record is set aside instead of sinking the whole migration.
|
|
90
|
+
invalidRecords: 'backup-and-skip',
|
|
91
|
+
tables: { notes: { valueSchema: LegacyNoteSchema } },
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
const notes = [];
|
|
95
|
+
for (const [key, value] of domain.table('notes').entries()) {
|
|
96
|
+
const record = value;
|
|
97
|
+
if (record === null || typeof record !== 'object')
|
|
98
|
+
continue;
|
|
99
|
+
const stamp = new Date().toISOString();
|
|
100
|
+
notes.push({
|
|
101
|
+
// The storage key IS the note id; trust it over a disagreeing field so a
|
|
102
|
+
// half-written record still migrates under the identity the wall stored.
|
|
103
|
+
id: typeof record.id === 'string' && record.id !== '' ? record.id : key,
|
|
104
|
+
title: typeof record.title === 'string' ? record.title : '',
|
|
105
|
+
body: typeof record.body === 'string' ? record.body : '',
|
|
106
|
+
tags: Array.isArray(record.tags) ? record.tags.map(String) : [],
|
|
107
|
+
color: COLORS.includes(String(record.color)) ? record.color : 'yellow',
|
|
108
|
+
pinned: record.pinned === true,
|
|
109
|
+
archived: record.archived === true,
|
|
110
|
+
createdAt: typeof record.createdAt === 'string' ? record.createdAt : stamp,
|
|
111
|
+
updatedAt: typeof record.updatedAt === 'string' ? record.updatedAt : stamp,
|
|
112
|
+
layout: record.layout === null || record.layout === undefined
|
|
113
|
+
? null
|
|
114
|
+
: {
|
|
115
|
+
x: Number(record.layout.x) || 0,
|
|
116
|
+
y: Number(record.layout.y) || 0,
|
|
117
|
+
rotate: Number(record.layout.rotate) || 0,
|
|
118
|
+
width: WIDTHS.includes(String(record.layout.width))
|
|
119
|
+
? record.layout.width
|
|
120
|
+
: 'md',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return notes;
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
await domain.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The directory a 0.7.x install's storage domain wrote its records into.
|
|
132
|
+
*
|
|
133
|
+
* It sits beside the notes directory, under the same DSH home, so it is derived
|
|
134
|
+
* rather than configured: `storages/<domain name>/notes`. The recovery path uses
|
|
135
|
+
* it to find the `<id>.json.bak.<stamp>` files a broken 0.8.0 run left behind.
|
|
136
|
+
*/
|
|
137
|
+
function legacyNotesDirOf(notesDir) {
|
|
138
|
+
const home = dirname(dirname(notesDir));
|
|
139
|
+
return join(home, 'storages', LEGACY_DOMAIN_NAME, 'notes');
|
|
140
|
+
}
|
|
27
141
|
/** Model-facing text for one tool result; short, deterministic and readable. */
|
|
28
142
|
function renderWall(value) {
|
|
29
143
|
const data = (value ?? {});
|
|
@@ -41,6 +155,22 @@ function renderWall(value) {
|
|
|
41
155
|
});
|
|
42
156
|
return [`${String(data.total ?? notes.length)} notes (${String(data.archived ?? 0)} archived):`, ...lines].join('\n');
|
|
43
157
|
}
|
|
158
|
+
if (action === 'read') {
|
|
159
|
+
// The whole point of this action: the model gets the note's FULL text, not a
|
|
160
|
+
// 140-character head. Without it an agent asked to expand a note had to ask
|
|
161
|
+
// the user to paste it back, which is exactly the friction this removes.
|
|
162
|
+
const note = data.note;
|
|
163
|
+
if (note === undefined)
|
|
164
|
+
return 'No such note.';
|
|
165
|
+
const meta = [
|
|
166
|
+
`id: ${note.id}`,
|
|
167
|
+
note.title !== '' ? `title: ${note.title}` : '',
|
|
168
|
+
`color: ${note.color}${note.pinned ? ' · pinned' : ''}${note.archived ? ' · archived' : ''}`,
|
|
169
|
+
note.tags.length > 0 ? `tags: ${note.tags.join(', ')}` : '',
|
|
170
|
+
typeof data.path === 'string' ? `file: ${data.path}` : '',
|
|
171
|
+
].filter((line) => line !== '');
|
|
172
|
+
return [...meta, '', note.body].join('\n');
|
|
173
|
+
}
|
|
44
174
|
if (action === 'arrange') {
|
|
45
175
|
const notes = Array.isArray(data.changed) ? data.changed : [];
|
|
46
176
|
return notes.length === 0 ? 'The wall was already tidy.' : `Tidied ${notes.length} note${notes.length === 1 ? '' : 's'} into the shelf arrangement.`;
|
|
@@ -54,8 +184,10 @@ function renderWall(value) {
|
|
|
54
184
|
return notes.length === 0 ? 'No note changed.' : notes.map((note) => `${note.id} ${note.archived ? 'archived' : 'restored'}`).join('\n');
|
|
55
185
|
}
|
|
56
186
|
const note = data.note;
|
|
57
|
-
if (note)
|
|
58
|
-
|
|
187
|
+
if (note) {
|
|
188
|
+
const where = note.layout === null ? '' : ` at (${String(note.layout.x)}, ${String(note.layout.y)})`;
|
|
189
|
+
return `${action === 'create' ? 'Created' : 'Updated'} note ${note.id}${note.title ? ` (${note.title})` : ''}${where}: ${note.body.replace(/\s+/g, ' ').slice(0, 140)}`;
|
|
190
|
+
}
|
|
59
191
|
return 'Done.';
|
|
60
192
|
}
|
|
61
193
|
/** Register the model-facing capture tool when the registry is present. */
|
|
@@ -66,30 +198,48 @@ function registerAgentTool(ctx, ready) {
|
|
|
66
198
|
ctx.effect(() => {
|
|
67
199
|
const disposer = tools.register({
|
|
68
200
|
name: 'sticky_wall',
|
|
69
|
-
description: "Capture and manage sticky notes on the user's DSH note wall (便签墙): quick inspiration, temporary tasks and short reminders.
|
|
201
|
+
description: "Capture and manage sticky notes on the user's DSH note wall (便签墙): quick inspiration, temporary tasks and short reminders. " +
|
|
202
|
+
'Each note is a real Markdown file under the notes directory: its attributes (title, colour, tags, pin, size, canvas position) live in the YAML frontmatter block at the top, and everything after that block is the note body. ' +
|
|
203
|
+
"Use `read` to get a note's full text, `list` to scan titles, `create`/`update` to write attributes or text, and `move` to place a card on the canvas. " +
|
|
204
|
+
"To revise a note's PROSE you may edit the backing file directly with the file tools — but never modify the frontmatter between the `---` lines; change attributes with this tool's `update` action instead.",
|
|
70
205
|
parameters: {
|
|
71
206
|
type: 'object',
|
|
72
207
|
additionalProperties: false,
|
|
73
208
|
required: ['action'],
|
|
74
209
|
properties: {
|
|
75
|
-
action: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
210
|
+
action: {
|
|
211
|
+
type: 'string',
|
|
212
|
+
enum: ['list', 'read', 'create', 'update', 'move', 'archive', 'delete', 'clear-archived', 'arrange'],
|
|
213
|
+
description: 'list: scan notes. read: one note in full. create/update: write attributes or text. move: place one card on the canvas. archive/delete: batch state changes. clear-archived: permanent sweep. arrange: tidy the whole wall.',
|
|
214
|
+
},
|
|
215
|
+
id: { type: 'string', description: 'Exact note id; required by read, update and move.' },
|
|
216
|
+
ids: { type: 'array', items: { type: 'string' }, description: `Note ids; required by archive and delete (1–${LIMITS.bulk} entries).` },
|
|
217
|
+
body: { type: 'string', description: `The note text. Required by create; optional patch field for update. Max ${LIMITS.body} characters.` },
|
|
218
|
+
title: { type: 'string', description: `Short heading (max ${LIMITS.title} characters); '' clears it.` },
|
|
219
|
+
tags: { type: 'array', items: { type: 'string' }, description: `Lowercase tags (max ${LIMITS.tags}, each max ${LIMITS.tag} characters); [] clears them.` },
|
|
220
|
+
color: { type: 'string', enum: ['yellow', 'pink', 'green', 'blue', 'purple', 'orange'], description: 'Pastel note colour.' },
|
|
82
221
|
pinned: { type: 'boolean', description: 'Pin the note to the top of the wall.' },
|
|
83
|
-
archived: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
222
|
+
archived: {
|
|
223
|
+
type: 'boolean',
|
|
224
|
+
// Required rather than defaulted: a model asked to RESTORE a note that
|
|
225
|
+
// merely omits this field used to re-archive it, silently doing the
|
|
226
|
+
// opposite of the request. A destructive flag must never default.
|
|
227
|
+
description: 'Required by archive: true archives, false restores. Never omitted.',
|
|
228
|
+
},
|
|
229
|
+
includeArchived: { type: 'boolean', description: 'list only: include archived notes (default false).' },
|
|
230
|
+
x: { type: 'number', description: 'Canvas horizontal position of the card, in canvas pixels. Used by create and move.' },
|
|
231
|
+
y: { type: 'number', description: 'Canvas vertical position of the card, in canvas pixels. Used by create and move.' },
|
|
232
|
+
width: { type: 'string', enum: ['sm', 'md', 'lg'], description: 'Card width preset. Used by create and move.' },
|
|
233
|
+
rotate: { type: 'number', description: 'Card tilt in degrees, clamped to ±12. Used by create and move.' },
|
|
234
|
+
limit: { type: 'integer', description: `list only: how many notes to return (1–${LIMITS.listLimit}, default 20).` },
|
|
88
235
|
},
|
|
89
236
|
},
|
|
90
237
|
timeoutMs: 20_000,
|
|
91
238
|
isConcurrencySafe(args) {
|
|
92
|
-
|
|
239
|
+
if (typeof args !== 'object' || args === null)
|
|
240
|
+
return false;
|
|
241
|
+
const action = args.action;
|
|
242
|
+
return action === 'list' || action === 'read';
|
|
93
243
|
},
|
|
94
244
|
output: {
|
|
95
245
|
schema: { type: 'object', additionalProperties: true },
|
|
@@ -101,10 +251,31 @@ function registerAgentTool(ctx, ready) {
|
|
|
101
251
|
execution.signal.throwIfAborted();
|
|
102
252
|
const store = await ready;
|
|
103
253
|
const args = (raw ?? {});
|
|
254
|
+
/** A complete placement from the flat coordinates, when all of them exist. */
|
|
255
|
+
const layoutFrom = () => {
|
|
256
|
+
if (typeof args.x !== 'number' || typeof args.y !== 'number')
|
|
257
|
+
return undefined;
|
|
258
|
+
const width = args.width === 'sm' || args.width === 'md' || args.width === 'lg' ? args.width : 'md';
|
|
259
|
+
return { x: args.x, y: args.y, rotate: typeof args.rotate === 'number' ? args.rotate : 0, width };
|
|
260
|
+
};
|
|
104
261
|
switch (args.action) {
|
|
105
|
-
case 'list':
|
|
106
|
-
|
|
107
|
-
|
|
262
|
+
case 'list': {
|
|
263
|
+
// `includeArchived` was declared but ignored: `summary()` always read
|
|
264
|
+
// every note, so the tool's own description was false. Filter here so
|
|
265
|
+
// the flag means what it says.
|
|
266
|
+
const summary = store.summary(typeof args.limit === 'number' ? args.limit : 20);
|
|
267
|
+
const notes = args.includeArchived === true ? summary.notes : summary.notes.filter((note) => !note.archived);
|
|
268
|
+
return { action: 'list', ...summary, notes, archived: summary.archived, total: summary.total };
|
|
269
|
+
}
|
|
270
|
+
case 'read': {
|
|
271
|
+
const id = String(args.id ?? '');
|
|
272
|
+
const note = store.read(id);
|
|
273
|
+
if (note === null)
|
|
274
|
+
throw new Error(`No note with id ${JSON.stringify(id)}.`);
|
|
275
|
+
return { action: 'read', note, path: store.pathOf(id) };
|
|
276
|
+
}
|
|
277
|
+
case 'create': {
|
|
278
|
+
const placement = layoutFrom();
|
|
108
279
|
return {
|
|
109
280
|
action: 'create',
|
|
110
281
|
note: await store.create({
|
|
@@ -113,11 +284,10 @@ function registerAgentTool(ctx, ready) {
|
|
|
113
284
|
...(Array.isArray(args.tags) ? { tags: args.tags.map(String) } : {}),
|
|
114
285
|
...(typeof args.color === 'string' ? { color: args.color } : {}),
|
|
115
286
|
...(typeof args.pinned === 'boolean' ? { pinned: args.pinned } : {}),
|
|
116
|
-
...(
|
|
117
|
-
? { layout: { x: args.x, y: args.y, rotate: 0, width: 'md' } }
|
|
118
|
-
: {}),
|
|
287
|
+
...(placement === undefined ? {} : { layout: placement }),
|
|
119
288
|
}),
|
|
120
289
|
};
|
|
290
|
+
}
|
|
121
291
|
case 'update':
|
|
122
292
|
return {
|
|
123
293
|
action: 'update',
|
|
@@ -130,8 +300,27 @@ function registerAgentTool(ctx, ready) {
|
|
|
130
300
|
...(typeof args.archived === 'boolean' ? { archived: args.archived } : {}),
|
|
131
301
|
}),
|
|
132
302
|
};
|
|
303
|
+
case 'move': {
|
|
304
|
+
const id = String(args.id ?? '');
|
|
305
|
+
const current = store.read(id);
|
|
306
|
+
if (current === null)
|
|
307
|
+
throw new Error(`No note with id ${JSON.stringify(id)}.`);
|
|
308
|
+
// A move keeps whatever the caller did not restate, so positioning a
|
|
309
|
+
// card does not silently change its size or straighten its tilt.
|
|
310
|
+
const base = current.layout;
|
|
311
|
+
const layout = {
|
|
312
|
+
x: typeof args.x === 'number' ? args.x : base?.x ?? 0,
|
|
313
|
+
y: typeof args.y === 'number' ? args.y : base?.y ?? 0,
|
|
314
|
+
rotate: typeof args.rotate === 'number' ? args.rotate : base?.rotate ?? 0,
|
|
315
|
+
width: args.width === 'sm' || args.width === 'md' || args.width === 'lg' ? args.width : base?.width ?? 'md',
|
|
316
|
+
};
|
|
317
|
+
return { action: 'move', note: await store.move(id, layout) };
|
|
318
|
+
}
|
|
133
319
|
case 'archive':
|
|
134
|
-
|
|
320
|
+
// A destructive flag must be stated, never inferred.
|
|
321
|
+
if (typeof args.archived !== 'boolean')
|
|
322
|
+
throw new Error('archive requires `archived: true` to archive or `archived: false` to restore.');
|
|
323
|
+
return { action: 'archive', notes: await store.setArchived(args.ids ?? [], args.archived) };
|
|
135
324
|
case 'delete':
|
|
136
325
|
return { action: 'delete', removed: await store.remove(args.ids ?? []) };
|
|
137
326
|
case 'clear-archived':
|
|
@@ -151,17 +340,26 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
151
340
|
const connection = service(ctx, 'connection');
|
|
152
341
|
if (!connection?.fetch?.register)
|
|
153
342
|
throw new Error('Sticky wall requires the current DSH Connection exact Fetch-route registry.');
|
|
343
|
+
const notesDir = resolveNotesDir(config.notesDir, process.env, homedir());
|
|
344
|
+
// The legacy storage domain is now OPTIONAL: notes live on disk, and the
|
|
345
|
+
// domain is only opened once, to drain a 0.7.x install's records into `.md`
|
|
346
|
+
// files. A profile that never had the domain simply has nothing to migrate.
|
|
154
347
|
const facility = service(ctx, 'storageDomain');
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const ready = StickyWallStore.open((spec) => facility.open(spec), {
|
|
348
|
+
const ready = StickyWallStore.open({
|
|
349
|
+
notesDir,
|
|
158
350
|
maxNotes: config.maxNotes,
|
|
159
351
|
seedWelcomeNote: config.seedWelcomeNote,
|
|
352
|
+
readLegacy: facility?.open === undefined ? undefined : () => readLegacyNotes(facility),
|
|
353
|
+
// Where a broken 0.8.0 run quarantined the legacy records, so the corrected
|
|
354
|
+
// migration can recover them from `.bak` files instead of reporting an
|
|
355
|
+
// already-migrated wall and leaving the user's notes stranded.
|
|
356
|
+
legacyNotesDir: facility?.open === undefined ? undefined : legacyNotesDirOf(notesDir),
|
|
357
|
+
log: (message) => ctx.logger?.warn?.(`sticky-wall: ${message}`),
|
|
160
358
|
});
|
|
161
359
|
ready.catch((error) => {
|
|
162
360
|
// The route and the tool both await `ready`, so the failure also reaches the
|
|
163
361
|
// first caller; log it once so it is never silent in the Host log.
|
|
164
|
-
ctx.logger?.error?.(`sticky-wall:
|
|
362
|
+
ctx.logger?.error?.(`sticky-wall: notes directory failed to open: ${error instanceof Error ? error.message : String(error)}`);
|
|
165
363
|
});
|
|
166
364
|
ctx.effect(() => () => {
|
|
167
365
|
void ready.then((store) => store.close()).catch(() => { });
|
|
@@ -170,13 +368,15 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
170
368
|
const store = await ready;
|
|
171
369
|
return {
|
|
172
370
|
list: (includeArchived, sort) => store.list(includeArchived, sort),
|
|
173
|
-
|
|
371
|
+
revisionOf: () => store.revision,
|
|
372
|
+
notesDir: store.notesDir,
|
|
373
|
+
create: (input, id, options) => store.create(input, id, options),
|
|
174
374
|
update: (id, patch) => store.update(id, patch),
|
|
175
375
|
setArchived: (ids, archived) => store.setArchived(ids, archived),
|
|
176
376
|
remove: (ids) => store.remove(ids),
|
|
177
377
|
clearArchived: () => store.clearArchived(),
|
|
178
378
|
move: (id, layout) => store.move(id, layout),
|
|
179
|
-
arrange: () => store.arrange(),
|
|
379
|
+
arrange: (options) => store.arrange(options),
|
|
180
380
|
};
|
|
181
381
|
})), 'skillre-sticky-wall client route');
|
|
182
382
|
if (config.enableAgentTool)
|
package/lib/migrate.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time migration from the 0.7.x storage domain to real `.md` files.
|
|
3
|
+
*
|
|
4
|
+
* The old build kept a wall in a JSON storage domain. 0.8.0 stores one file per
|
|
5
|
+
* note instead, so an existing user's wall has to be carried across exactly once,
|
|
6
|
+
* without losing a note and without ever leaving a half-migrated directory that
|
|
7
|
+
* the next start would mistake for a finished one.
|
|
8
|
+
*
|
|
9
|
+
* The whole design follows from one requirement: **the notes directory must
|
|
10
|
+
* never be observable in a partial state.** So the notes are written into a
|
|
11
|
+
* sibling staging directory and published with a single `rename`, which is
|
|
12
|
+
* atomic within one parent directory. A crash before the rename leaves the legacy
|
|
13
|
+
* wall untouched and the staging directory removable; a crash after it leaves a
|
|
14
|
+
* complete wall that the marker then declares migrated.
|
|
15
|
+
*
|
|
16
|
+
* Nothing here is on the hot path, and nothing here runs when the directory
|
|
17
|
+
* already holds notes: a user who has been on 0.8.0 for months must not have a
|
|
18
|
+
* stale legacy domain re-imported over edits they have made since.
|
|
19
|
+
*/
|
|
20
|
+
import { type Note } from './types.js';
|
|
21
|
+
/** What one migration attempt did, and why it did nothing when it did nothing. */
|
|
22
|
+
export interface MigrateResult {
|
|
23
|
+
/** True only when this call published the notes directory. */
|
|
24
|
+
migrated: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Stable outcome: `migrated`, `already-present`, `no-legacy`, or `failed`.
|
|
27
|
+
*
|
|
28
|
+
* `already-present` is the normal steady state, not an error — it is what a
|
|
29
|
+
* second start reports after a successful migration.
|
|
30
|
+
*/
|
|
31
|
+
reason: string;
|
|
32
|
+
/** Notes carried across, set only when `migrated` is true. */
|
|
33
|
+
count?: number;
|
|
34
|
+
/** Human-readable cause, set only when `reason` is `failed`. */
|
|
35
|
+
error?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Everything the migration needs; `now` is injectable for a deterministic marker. */
|
|
38
|
+
export interface MigrateOptions {
|
|
39
|
+
/** Destination directory, `<DSH_HOME>/sticky-notes`. */
|
|
40
|
+
notesDir: string;
|
|
41
|
+
/** Drains the legacy storage domain; resolves to every note it held. */
|
|
42
|
+
readLegacy: () => Promise<Note[]>;
|
|
43
|
+
/** Clock for the marker's `at` field. */
|
|
44
|
+
now?: (() => Date) | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Where the legacy records live on disk, when the caller knows.
|
|
47
|
+
*
|
|
48
|
+
* Only used to recover a wall that 0.8.0 left looking empty: that build
|
|
49
|
+
* quarantined every record as `<id>.json.bak.<stamp>` in this directory, so
|
|
50
|
+
* the files are the only remaining copy. Omit it and that recovery cannot run
|
|
51
|
+
* — which is correct for a caller that has no legacy medium at all.
|
|
52
|
+
*/
|
|
53
|
+
legacyNotesDir?: string | undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Move the legacy notes into `notesDir`, or explain why there was nothing to do.
|
|
57
|
+
*
|
|
58
|
+
* Never throws for an expected outcome: a failed migration is reported as
|
|
59
|
+
* `{ migrated: false, reason: 'failed' }` with the notes directory left absent,
|
|
60
|
+
* so the next start retries with the legacy wall still intact.
|
|
61
|
+
*/
|
|
62
|
+
export declare function migrateNotes(options: MigrateOptions): Promise<MigrateResult>;
|