@abraca/mcp 2.33.0 → 2.35.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.
@@ -1,418 +0,0 @@
1
- /**
2
- * Static catalog of Abracadabra page types and their metadata schemas.
3
- *
4
- * Kept in sync with `cou-sh/app/utils/docTypes.ts` and the plugin definitions
5
- * under `cou-sh/plugin-<name>/src/index.ts`. No UI dependencies — it
6
- * is a plain data description so agents (via MCP) and CLI tooling can discover
7
- * what fields apply to which renderer without having to read the dashboard
8
- * source code.
9
- *
10
- * Schema semantics (from page-type-guidelines.md):
11
- *
12
- * - `metaSchema` — fields that apply to DESCENDANTS (children, grandchildren,
13
- * and beyond) of a page of this type. E.g. the calendar's schema describes
14
- * what an *event* meta looks like, not the calendar itself.
15
- * - `defaultMetaFields` — fields inserted into the page doc's own metadata
16
- * when first rendered; these are view config knobs (e.g. `calendarView`).
17
- */
18
-
19
- export type MetaFieldType
20
- = | 'datetimerange'
21
- | 'daterange'
22
- | 'timerange'
23
- | 'datetime'
24
- | 'date'
25
- | 'time'
26
- | 'slider'
27
- | 'number'
28
- | 'toggle'
29
- | 'select'
30
- | 'multiselect'
31
- | 'colorPreset'
32
- | 'colorPicker'
33
- | 'location'
34
- | 'icon'
35
- | 'textarea'
36
- | 'url'
37
- | 'rating'
38
- | 'tags'
39
- | 'members'
40
-
41
- export interface PageTypeMetaField {
42
- type: MetaFieldType
43
- label?: string
44
- /** single-value fields */
45
- key?: string
46
- /** location */
47
- latKey?: string
48
- lngKey?: string
49
- /** ranges */
50
- startKey?: string
51
- endKey?: string
52
- allDayKey?: string
53
- /** color preset */
54
- presets?: string[]
55
- /** icon / select / tags */
56
- options?: string[]
57
- /** slider / number */
58
- min?: number
59
- max?: number
60
- step?: number
61
- unit?: string
62
- /** toggle default */
63
- default?: boolean
64
- }
65
-
66
- export interface PageTypeInfo {
67
- key: string
68
- label: string
69
- icon: string
70
- description?: string
71
- /** true = core type (always available); false = requires plugin */
72
- core: boolean
73
- plugin?: string
74
- supportsChildren: boolean
75
- childLabel?: string
76
- grandchildLabel?: string
77
- /** -1 = unlimited depth */
78
- defaultDepth?: number
79
- /** Fields that apply to this doc's descendants (children, grandchildren, ...) */
80
- metaSchema?: PageTypeMetaField[]
81
- /** Fields written to this doc's own meta on first render (renderer config) */
82
- defaultMetaFields?: PageTypeMetaField[]
83
- }
84
-
85
- const GEO_COLOR_PRESETS = ['#3b82f6', '#f97316', '#22c55e', '#ef4444', '#a855f7']
86
- const GEO_ICON_OPTIONS = [
87
- 'map-pin', 'star', 'flag', 'home', 'building-2', 'coffee', 'utensils',
88
- 'camera', 'heart', 'zap', 'triangle-alert', 'car', 'plane', 'anchor',
89
- 'tree-pine', 'mountain', 'waves', 'shield', 'crosshair', 'circle-dot',
90
- 'bookmark', 'gem', 'radio', 'compass',
91
- ]
92
-
93
- export const GEO_TYPE_META_SCHEMAS: Record<string, PageTypeMetaField[]> = {
94
- marker: [
95
- { type: 'location', latKey: 'geoLat', lngKey: 'geoLng', label: 'Location' },
96
- { type: 'icon', key: 'icon', options: GEO_ICON_OPTIONS, label: 'Icon' },
97
- { type: 'colorPreset', key: 'color', presets: GEO_COLOR_PRESETS, label: 'Color' },
98
- ],
99
- line: [
100
- { type: 'colorPreset', key: 'color', presets: GEO_COLOR_PRESETS, label: 'Color' },
101
- ],
102
- measure: [],
103
- }
104
-
105
- export const PAGE_TYPES: Record<string, PageTypeInfo> = {
106
- doc: {
107
- key: 'doc',
108
- label: 'Document',
109
- icon: 'file-text',
110
- description: 'Rich text document with real-time collaboration',
111
- core: true,
112
- supportsChildren: true,
113
- },
114
- prose: {
115
- key: 'prose',
116
- label: 'Prose',
117
- icon: 'pen-tool',
118
- description: 'Long-form prose with serif typography and a narrow readable measure',
119
- core: true,
120
- supportsChildren: true,
121
- childLabel: 'Item',
122
- defaultDepth: -1,
123
- },
124
- kanban: {
125
- key: 'kanban',
126
- label: 'Kanban',
127
- icon: 'kanban',
128
- description: 'Drag-and-drop task board with columns and cards',
129
- core: true,
130
- supportsChildren: true,
131
- childLabel: 'Column',
132
- grandchildLabel: 'Card',
133
- defaultMetaFields: [
134
- { type: 'select', key: 'kanbanColumnWidth', options: ['narrow', 'default', 'wide'], label: 'Column Width' },
135
- ],
136
- },
137
- gallery: {
138
- key: 'gallery',
139
- label: 'Gallery',
140
- icon: 'images',
141
- description: 'Visual grid of items with rich content',
142
- core: true,
143
- supportsChildren: true,
144
- childLabel: 'Item',
145
- metaSchema: [
146
- { type: 'location', latKey: 'geoLat', lngKey: 'geoLng', label: 'Location' },
147
- { type: 'datetime', key: 'datetimeStart', label: 'Date' },
148
- { type: 'tags', key: 'tags', label: 'Tags' },
149
- { type: 'rating', key: 'rating', max: 5, label: 'Rating' },
150
- { type: 'icon', key: 'icon', label: 'Icon' },
151
- { type: 'colorPreset', key: 'color', presets: ['#6366f1', '#ec4899', '#f97316', '#22c55e', '#3b82f6', '#a855f7'], label: 'Color' },
152
- ],
153
- defaultMetaFields: [
154
- { type: 'number', key: 'galleryColumns', min: 1, max: 6, step: 1, label: 'Columns' },
155
- { type: 'select', key: 'galleryAspect', options: ['square', '4:3', '3:2', '16:9', 'free'], label: 'Aspect Ratio' },
156
- { type: 'select', key: 'galleryCardStyle', options: ['default', 'compact', 'detailed'], label: 'Card Style' },
157
- { type: 'toggle', key: 'galleryShowLabels', label: 'Show Labels' },
158
- { type: 'select', key: 'gallerySortBy', options: ['manual', 'date', 'name', 'rating'], label: 'Sort' },
159
- ],
160
- },
161
- table: {
162
- key: 'table',
163
- label: 'Table',
164
- icon: 'table',
165
- description: 'Collaborative spreadsheet with custom fields',
166
- core: true,
167
- supportsChildren: true,
168
- childLabel: 'Column',
169
- grandchildLabel: 'Row',
170
- defaultMetaFields: [
171
- { type: 'select', key: 'tableMode', options: ['hierarchy', 'flat'], label: 'Mode' },
172
- { type: 'select', key: 'tableSortDir', options: ['asc', 'desc'], label: 'Sort Direction' },
173
- ],
174
- },
175
- outline: {
176
- key: 'outline',
177
- label: 'Outline',
178
- icon: 'list-tree',
179
- description: 'Hierarchical outline with keyboard navigation',
180
- core: true,
181
- supportsChildren: true,
182
- childLabel: 'Item',
183
- defaultDepth: -1,
184
- },
185
- checklist: {
186
- key: 'checklist',
187
- label: 'Checklist',
188
- icon: 'check-square',
189
- description: 'Collaborative checklist with sub-tasks, drag-and-drop, and due dates',
190
- core: true,
191
- supportsChildren: true,
192
- childLabel: 'Task',
193
- defaultDepth: -1,
194
- metaSchema: [
195
- { type: 'toggle', key: 'checked', label: 'Done' },
196
- { type: 'select', key: 'priority', options: ['none', 'low', 'medium', 'high'], label: 'Priority' },
197
- { type: 'date', key: 'dateEnd', label: 'Due date' },
198
- ],
199
- defaultMetaFields: [
200
- { type: 'select', key: 'checklistFilter', options: ['all', 'active', 'completed'], label: 'Filter' },
201
- { type: 'select', key: 'checklistSort', options: ['manual', 'priority', 'due'], label: 'Sort' },
202
- ],
203
- },
204
- graph: {
205
- key: 'graph',
206
- label: 'Graph',
207
- icon: 'git-fork',
208
- description: 'Force-directed knowledge graph — full document tree as nodes & edges',
209
- core: true,
210
- supportsChildren: true,
211
- childLabel: 'Node',
212
- defaultMetaFields: [
213
- { type: 'toggle', key: 'showRefEdges', label: 'Show Ref Edges', default: true },
214
- ],
215
- },
216
- timeline: {
217
- key: 'timeline',
218
- label: 'Timeline',
219
- icon: 'gantt-chart',
220
- description: 'Gantt-style project timeline with epics and tasks',
221
- core: true,
222
- supportsChildren: true,
223
- childLabel: 'Epic',
224
- grandchildLabel: 'Task',
225
- metaSchema: [
226
- { type: 'daterange', startKey: 'dateStart', endKey: 'dateEnd' },
227
- { type: 'slider', key: 'taskProgress', min: 0, max: 100, label: 'Progress' },
228
- { type: 'colorPreset', key: 'color', presets: ['#6366f1', '#818cf8', '#f97316', '#22c55e', '#3b82f6', '#a855f7'], label: 'Color' },
229
- ],
230
- },
231
- calendar: {
232
- key: 'calendar',
233
- label: 'Calendar',
234
- icon: 'calendar',
235
- description: 'Event calendar with month, week, and day views',
236
- core: true,
237
- supportsChildren: true,
238
- childLabel: 'Event',
239
- metaSchema: [
240
- { type: 'datetimerange', startKey: 'datetimeStart', endKey: 'datetimeEnd', allDayKey: 'allDay' },
241
- { type: 'colorPreset', key: 'color', presets: ['#6366f1', '#ec4899', '#f97316', '#22c55e', '#3b82f6', '#a855f7'], label: 'Color' },
242
- { type: 'icon', key: 'icon', label: 'Icon' },
243
- ],
244
- defaultMetaFields: [
245
- { type: 'select', key: 'calendarWeekStart', options: ['sun', 'mon'], label: 'Week Starts' },
246
- { type: 'select', key: 'calendarView', options: ['month', 'week', 'day'], label: 'Default View' },
247
- { type: 'toggle', key: 'calendarShowWeekNumbers', label: 'Show Week Numbers' },
248
- ],
249
- },
250
- map: {
251
- key: 'map',
252
- label: 'Map',
253
- icon: 'map',
254
- description: 'Collaborative world map with shared markers',
255
- core: true,
256
- supportsChildren: true,
257
- childLabel: 'Location',
258
- defaultMetaFields: [
259
- { type: 'toggle', key: 'mapShowLabels', label: 'Show Labels', default: true },
260
- ],
261
- },
262
- dashboard: {
263
- key: 'dashboard',
264
- label: 'Dashboard',
265
- icon: 'layout-dashboard',
266
- description: 'Arrange documents as draggable icons with optional widget views',
267
- core: true,
268
- supportsChildren: true,
269
- childLabel: 'Item',
270
- },
271
- call: {
272
- key: 'call',
273
- label: 'Call',
274
- icon: 'phone',
275
- description: 'Video call room with live audio and screen sharing',
276
- core: true,
277
- supportsChildren: false,
278
- },
279
- chart: {
280
- key: 'chart',
281
- label: 'Chart',
282
- icon: 'bar-chart-3',
283
- description: 'Charts — manual data points or aggregation over document trees',
284
- core: true,
285
- supportsChildren: true,
286
- childLabel: 'Data Point',
287
- grandchildLabel: 'Data Point',
288
- metaSchema: [
289
- { type: 'number', key: 'number', step: 0.01, label: 'Value' },
290
- { type: 'colorPreset', key: 'color', presets: ['#6366f1', '#ec4899', '#f97316', '#22c55e', '#3b82f6', '#a855f7', '#14b8a6', '#eab308'], label: 'Color' },
291
- { type: 'tags', key: 'tags', label: 'Tags' },
292
- ],
293
- defaultMetaFields: [
294
- { type: 'select', key: 'chartType', options: ['bar', 'stacked bar', 'line', 'donut', 'treemap'], label: 'Chart Type' },
295
- { type: 'select', key: 'chartMetric', options: ['value', 'type', 'tag', 'status', 'priority', 'activity', 'completion'], label: 'Metric' },
296
- { type: 'select', key: 'chartColorScheme', options: ['default', 'warm', 'cool', 'mono'], label: 'Colors' },
297
- { type: 'number', key: 'chartLimit', min: 3, max: 30, step: 1, label: 'Max Items' },
298
- { type: 'toggle', key: 'chartShowLegend', label: 'Show Legend', default: true },
299
- { type: 'toggle', key: 'chartShowValues', label: 'Show Values' },
300
- ],
301
- },
302
- sheets: {
303
- key: 'sheets',
304
- label: 'Sheets',
305
- icon: 'grid-3x3',
306
- description: 'Spreadsheet — cells, formulas, and formatting in a collaborative grid',
307
- core: true,
308
- supportsChildren: true,
309
- childLabel: 'Column',
310
- grandchildLabel: 'Cell',
311
- defaultMetaFields: [
312
- { type: 'number', key: 'sheetsDefaultColWidth', min: 40, max: 500, step: 10, label: 'Column Width' },
313
- { type: 'number', key: 'sheetsDefaultRowHeight', min: 20, max: 100, step: 2, label: 'Row Height' },
314
- { type: 'toggle', key: 'sheetsShowGridlines', label: 'Gridlines' },
315
- ],
316
- },
317
- slides: {
318
- key: 'slides',
319
- label: 'Slides',
320
- icon: 'presentation',
321
- description: 'Presentation slides with two-axis navigation',
322
- core: true,
323
- supportsChildren: true,
324
- childLabel: 'Slide',
325
- grandchildLabel: 'Sub-slide',
326
- metaSchema: [
327
- { type: 'select', key: 'slidesTransition', options: ['none', 'fade', 'slide'], label: 'Transition' },
328
- { type: 'colorPreset', key: 'color', presets: ['#6366f1', '#ec4899', '#f97316', '#22c55e', '#3b82f6', '#a855f7'], label: 'Accent' },
329
- ],
330
- defaultMetaFields: [
331
- { type: 'select', key: 'slidesTheme', options: ['dark', 'light'], label: 'Theme' },
332
- ],
333
- },
334
- overview: {
335
- key: 'overview',
336
- label: 'Overview',
337
- icon: 'radar',
338
- description: 'Space home — activity, people, stats, and health at a glance',
339
- core: true,
340
- supportsChildren: true,
341
- childLabel: 'Page',
342
- },
343
-
344
- // Plugin-contributed types — require the named plugin to be enabled server-side.
345
-
346
- spatial: {
347
- key: 'spatial',
348
- label: 'Spatial',
349
- icon: 'box',
350
- description: '3D scene with collaborative objects and real-time presence',
351
- core: false,
352
- plugin: 'spatial',
353
- supportsChildren: true,
354
- childLabel: 'Object',
355
- grandchildLabel: 'Part',
356
- defaultDepth: -1,
357
- metaSchema: [
358
- { type: 'select', key: 'spShape', options: ['box', 'sphere', 'cylinder', 'cone', 'plane', 'torus', 'glb'], label: 'Shape' },
359
- { type: 'colorPreset', key: 'color', presets: ['#6366f1', '#ef4444', '#22c55e', '#3b82f6', '#f97316', '#a855f7', '#ec4899', '#14b8a6'], label: 'Color' },
360
- { type: 'slider', key: 'spOpacity', min: 0, max: 100, label: 'Opacity' },
361
- { type: 'number', key: 'spX', step: 0.1, label: 'X' },
362
- { type: 'number', key: 'spY', step: 0.1, label: 'Y' },
363
- { type: 'number', key: 'spZ', step: 0.1, label: 'Z' },
364
- { type: 'number', key: 'spRX', min: -180, max: 180, step: 1, label: 'Rot X' },
365
- { type: 'number', key: 'spRY', min: -180, max: 180, step: 1, label: 'Rot Y' },
366
- { type: 'number', key: 'spRZ', min: -180, max: 180, step: 1, label: 'Rot Z' },
367
- { type: 'number', key: 'spSX', min: 0.01, max: 100, step: 0.1, label: 'Scale X' },
368
- { type: 'number', key: 'spSY', min: 0.01, max: 100, step: 0.1, label: 'Scale Y' },
369
- { type: 'number', key: 'spSZ', min: 0.01, max: 100, step: 0.1, label: 'Scale Z' },
370
- ],
371
- defaultMetaFields: [
372
- { type: 'toggle', key: 'spatialGridVisible', label: 'Show Grid', default: true },
373
- ],
374
- },
375
- media: {
376
- key: 'media',
377
- label: 'Media',
378
- icon: 'disc-3',
379
- description: 'Media player with synced listening and playlists',
380
- core: false,
381
- plugin: 'media',
382
- supportsChildren: true,
383
- childLabel: 'Track',
384
- defaultDepth: -1,
385
- metaSchema: [
386
- { type: 'tags', key: 'tags', label: 'Tags' },
387
- ],
388
- defaultMetaFields: [
389
- { type: 'select', key: 'mediaRepeat', options: ['off', 'all', 'one'], label: 'Repeat' },
390
- { type: 'toggle', key: 'mediaShuffle', label: 'Shuffle' },
391
- ],
392
- },
393
- coder: {
394
- key: 'coder',
395
- label: 'Coder',
396
- icon: 'code-2',
397
- description: 'Collaborative multi-file coding environment',
398
- core: false,
399
- plugin: 'coder',
400
- supportsChildren: true,
401
- childLabel: 'File',
402
- defaultDepth: -1,
403
- metaSchema: [
404
- { type: 'select', key: 'fileType', options: ['vue', 'ts', 'js', 'css', 'json', 'folder'], label: 'Type' },
405
- { type: 'toggle', key: 'entry', label: 'Entry Point' },
406
- ],
407
- },
408
- }
409
-
410
- export const TYPE_ALIASES: Record<string, string> = {
411
- desktop: 'dashboard',
412
- }
413
-
414
- export function resolvePageType(key: string | undefined): PageTypeInfo | undefined {
415
- if (!key) return undefined
416
- const resolved = TYPE_ALIASES[key] ?? key
417
- return PAGE_TYPES[resolved]
418
- }
@@ -1,183 +0,0 @@
1
- export interface UserMetaField {
2
- id: string
3
- type: string
4
- label?: string
5
- key?: string
6
- latKey?: string
7
- lngKey?: string
8
- startKey?: string
9
- endKey?: string
10
- allDayKey?: string
11
- presets?: string[]
12
- options?: string[]
13
- min?: number
14
- max?: number
15
- step?: number
16
- unit?: string
17
- default?: boolean
18
- }
19
-
20
- export interface PageMeta extends Record<string, unknown> {
21
- // Universal display
22
- color?: string
23
- icon?: string
24
- subtitle?: string
25
- note?: string
26
-
27
- // Datetime
28
- datetimeStart?: string
29
- datetimeEnd?: string
30
- allDay?: boolean
31
- dateStart?: string
32
- dateEnd?: string
33
- timeStart?: string
34
- timeEnd?: string
35
- dateTaken?: string
36
-
37
- // Task/status
38
- checked?: boolean
39
- priority?: number
40
- status?: string
41
- taskProgress?: number
42
- rating?: number
43
- tags?: string[]
44
- members?: { id: string; label: string }[]
45
-
46
- // Contact/value
47
- url?: string
48
- email?: string
49
- phone?: string
50
- number?: number
51
- unit?: string
52
-
53
- // Cover image
54
- coverUploadId?: string
55
- coverDocId?: string
56
- coverMimeType?: string
57
-
58
- // Geo/Map
59
- geoType?: 'marker' | 'line' | 'measure'
60
- geoLat?: number
61
- geoLng?: number
62
- geoDescription?: string
63
-
64
- // Dashboard
65
- deskX?: number
66
- deskY?: number
67
- deskZ?: number
68
- deskMode?: string
69
-
70
- // Mindmap
71
- mmX?: number
72
- mmY?: number
73
-
74
- // Graph
75
- graphX?: number
76
- graphY?: number
77
- graphPinned?: boolean
78
-
79
- // Spatial (3D) — spatial uses the universal `color` key (no spColor)
80
- spShape?: string
81
- spOpacity?: number
82
- spX?: number
83
- spY?: number
84
- spZ?: number
85
- spRX?: number
86
- spRY?: number
87
- spRZ?: number
88
- spSX?: number
89
- spSY?: number
90
- spSZ?: number
91
- spModelUploadId?: string
92
- spModelDocId?: string
93
-
94
- // Slides
95
- slidesTransition?: string
96
- slidesTheme?: string
97
-
98
- // Media metadata (extracted on import)
99
- mediaDuration?: number
100
- mediaWidth?: number
101
- mediaHeight?: number
102
- mediaCamera?: string
103
- mediaLens?: string
104
- mediaIso?: number
105
- mediaFocalLength?: number
106
- mediaAperture?: number
107
- mediaShutterSpeed?: string
108
- mediaArtist?: string
109
- mediaAlbum?: string
110
- mediaGenre?: string
111
- mediaYear?: number
112
-
113
- // Sheets cell formatting
114
- bold?: boolean
115
- italic?: boolean
116
- textColor?: string
117
- bgColor?: string
118
- align?: string
119
- formula?: string
120
-
121
- // Coder plugin (per-file)
122
- fileType?: string
123
- entry?: boolean
124
-
125
- // Renderer config (set on the page doc itself, not children)
126
- kanbanColumnWidth?: string
127
- galleryColumns?: number
128
- galleryAspect?: string
129
- galleryCardStyle?: string
130
- galleryShowLabels?: boolean
131
- gallerySortBy?: string
132
- calendarView?: string
133
- calendarWeekStart?: string
134
- calendarShowWeekNumbers?: boolean
135
- tableMode?: string
136
- tableSortKey?: string
137
- tableSortDir?: string
138
- tableColumns?: any[]
139
- tableColumnWidths?: Record<string, number>
140
- tableColumnOrder?: string[]
141
- timelineZoom?: string
142
- timelinePixelsPerDay?: number
143
- timelineCenterDate?: string
144
- checklistFilter?: string
145
- checklistSort?: string
146
- mapShowLabels?: boolean
147
- spatialGridVisible?: boolean
148
- graphSpacing?: string
149
- graphShowLabels?: boolean
150
- graphEdgeThickness?: string
151
- mmSpacing?: string
152
- showRefEdges?: boolean
153
- chartType?: string
154
- chartMetric?: string
155
- chartColorScheme?: string
156
- chartLimit?: number
157
- chartShowLegend?: boolean
158
- chartShowValues?: boolean
159
- mediaRepeat?: string
160
- mediaShuffle?: boolean
161
- sheetsDefaultColWidth?: number
162
- sheetsDefaultRowHeight?: number
163
- sheetsShowGridlines?: boolean
164
- sheetsColumnWidths?: Record<string, number>
165
- sheetsRowHeights?: Record<string, number>
166
- sheetsFreezeRows?: number
167
- sheetsFreezeCols?: number
168
-
169
- // Internal
170
- _metaFields?: UserMetaField[]
171
- _metaInitialized?: boolean
172
- }
173
-
174
- export interface TreeEntry {
175
- id: string
176
- label: string
177
- parentId: string | null
178
- order: number
179
- type?: string
180
- meta?: PageMeta
181
- createdAt?: number
182
- updatedAt?: number
183
- }
package/src/crypto.ts DELETED
@@ -1,69 +0,0 @@
1
- /**
2
- * Ed25519 key generation, persistence, and challenge signing for MCP agent auth.
3
- */
4
- import * as ed from '@noble/ed25519'
5
- import { sha512 } from '@noble/hashes/sha2.js'
6
- import { readFile, writeFile, mkdir } from 'node:fs/promises'
7
-
8
- // @noble/ed25519 v3 hash hook
9
- ed.hashes.sha512 = sha512
10
- ed.hashes.sha512Async = (m: Uint8Array) => Promise.resolve(sha512(m))
11
- import { existsSync } from 'node:fs'
12
- import { homedir } from 'node:os'
13
- import { join, dirname } from 'node:path'
14
-
15
- const DEFAULT_KEY_PATH = join(homedir(), '.abracadabra', 'agent.key')
16
-
17
- function toBase64url(bytes: Uint8Array): string {
18
- return Buffer.from(bytes).toString('base64url')
19
- }
20
-
21
- function fromBase64url(b64: string): Uint8Array {
22
- return new Uint8Array(Buffer.from(b64, 'base64url'))
23
- }
24
-
25
- export interface AgentKeypair {
26
- privateKey: Uint8Array
27
- publicKeyB64: string
28
- }
29
-
30
- /**
31
- * Load an existing Ed25519 keypair from disk, or generate and persist a new one.
32
- * The file stores the raw 32-byte private key seed.
33
- */
34
- export async function loadOrCreateKeypair(keyPath?: string): Promise<AgentKeypair> {
35
- const path = keyPath || DEFAULT_KEY_PATH
36
-
37
- if (existsSync(path)) {
38
- const seed = await readFile(path)
39
- if (seed.length !== 32) {
40
- throw new Error(`Invalid key file at ${path}: expected 32 bytes, got ${seed.length}`)
41
- }
42
- const privateKey = new Uint8Array(seed)
43
- const publicKey = ed.getPublicKey(privateKey)
44
- return { privateKey, publicKeyB64: toBase64url(publicKey) }
45
- }
46
-
47
- // Generate new keypair
48
- const privateKey = ed.utils.randomSecretKey()
49
- const publicKey = ed.getPublicKey(privateKey)
50
-
51
- // Ensure directory exists and write seed with restricted permissions
52
- const dir = dirname(path)
53
- if (!existsSync(dir)) {
54
- await mkdir(dir, { recursive: true, mode: 0o700 })
55
- }
56
- await writeFile(path, Buffer.from(privateKey), { mode: 0o600 })
57
-
58
- console.error(`[abracadabra-mcp] Generated new agent keypair at ${path}`)
59
- console.error(`[abracadabra-mcp] Public key: ${toBase64url(publicKey)}`)
60
-
61
- return { privateKey, publicKeyB64: toBase64url(publicKey) }
62
- }
63
-
64
- /** Sign a base64url challenge with the agent's private key; returns base64url signature. */
65
- export function signChallenge(challengeB64: string, privateKey: Uint8Array): string {
66
- const challenge = fromBase64url(challengeB64)
67
- const sig = ed.sign(challenge, privateKey)
68
- return toBase64url(sig)
69
- }