@aragon-agent/cli 0.6.52 → 0.6.54
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/CHANGELOG.md +38 -0
- package/README.md +4042 -3982
- package/dist/agent/controller.d.ts +26 -0
- package/dist/agent/controller.js +129 -1
- package/dist/agent/system-prompt.d.ts +14 -0
- package/dist/agent/system-prompt.js +3 -0
- package/dist/app/App.d.ts +7 -0
- package/dist/app/App.js +135 -6
- package/dist/cli.js +25 -1
- package/dist/commands/builtins.js +10 -0
- package/dist/commands/catalog.js +1 -0
- package/dist/commands/registry.d.ts +7 -0
- package/dist/compaction/compactor.d.ts +26 -0
- package/dist/compaction/compactor.js +81 -8
- package/dist/compaction/summarize-call.d.ts +22 -0
- package/dist/compaction/summarize-call.js +29 -0
- package/dist/compaction/wiring.js +22 -3
- package/dist/config/app-paths.d.ts +13 -0
- package/dist/config/app-paths.js +15 -0
- package/dist/config/cli-commands.d.ts +15 -0
- package/dist/config/cli-commands.js +32 -1
- package/dist/config/env.d.ts +1 -0
- package/dist/config/env.js +11 -0
- package/dist/config/load.d.ts +6 -0
- package/dist/config/load.js +10 -1
- package/dist/config/store.js +10 -1
- package/dist/exec/bridge/server.js +9 -2
- package/dist/exec/options.js +16 -2
- package/dist/governance/prompts/orchestrator-block.js +2 -2
- package/dist/host/controller-factory.d.ts +25 -0
- package/dist/host/controller-factory.js +7 -0
- package/dist/host/follow-up-seed.d.ts +109 -0
- package/dist/host/follow-up-seed.js +196 -0
- package/dist/host/follow-up.d.ts +73 -0
- package/dist/host/follow-up.js +123 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.js +3 -0
- package/dist/host/memory.d.ts +21 -0
- package/dist/host/memory.js +17 -0
- package/dist/host/sessions.d.ts +32 -2
- package/dist/host/sessions.js +40 -2
- package/dist/logging/install.d.ts +1 -0
- package/dist/logging/install.js +4 -0
- package/dist/logging/logger.d.ts +1 -1
- package/dist/memory/block.d.ts +24 -0
- package/dist/memory/block.js +54 -0
- package/dist/memory/command.d.ts +31 -0
- package/dist/memory/command.js +350 -0
- package/dist/memory/format.d.ts +51 -0
- package/dist/memory/format.js +308 -0
- package/dist/memory/paths.d.ts +68 -0
- package/dist/memory/paths.js +172 -0
- package/dist/memory/plan.d.ts +37 -0
- package/dist/memory/plan.js +184 -0
- package/dist/memory/resolve.d.ts +45 -0
- package/dist/memory/resolve.js +54 -0
- package/dist/memory/secrets.d.ts +30 -0
- package/dist/memory/secrets.js +73 -0
- package/dist/memory/service.d.ts +175 -0
- package/dist/memory/service.js +576 -0
- package/dist/memory/store.d.ts +133 -0
- package/dist/memory/store.js +694 -0
- package/dist/memory/tools.d.ts +36 -0
- package/dist/memory/tools.js +527 -0
- package/dist/memory/transfer.d.ts +53 -0
- package/dist/memory/transfer.js +93 -0
- package/dist/session/checkpoint.d.ts +18 -0
- package/dist/session/checkpoint.js +34 -0
- package/dist/session/limits.d.ts +16 -0
- package/dist/session/limits.js +16 -0
- package/dist/session/persist.d.ts +47 -0
- package/dist/session/persist.js +1 -0
- package/dist/session/startup-session.d.ts +6 -0
- package/dist/session/startup-session.js +3 -0
- package/dist/session/store.d.ts +14 -0
- package/dist/session/store.js +18 -0
- package/dist/session/validate-session.js +98 -0
- package/dist/tools/index.d.ts +21 -2
- package/dist/tools/index.js +33 -0
- package/package.json +3 -3
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/memory` and its subcommands (agent-memory spec 9.5).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/memory/**` is inside `glyphs.test.ts::inScope`. Outcome sentences come from
|
|
5
|
+
* `model/memory/copy.ts`; the usage text below is English, like every other command's help.
|
|
6
|
+
*
|
|
7
|
+
* THE COMMAND DOES NOT REACH THE UI THROUGH A CLOSURE. `registerBuiltinCommands(registry)`
|
|
8
|
+
* receives only the registry, so there is no context in which to build a port. The capability
|
|
9
|
+
* arrives on `CommandContext.memory`, an OPTIONAL field - `CommandContext` is constructed by
|
|
10
|
+
* literal in dozens of fixtures and a required field would break every one for a feature none of
|
|
11
|
+
* them is about. The port has two jobs: whether memory is on, and opening the manager on a page.
|
|
12
|
+
*
|
|
13
|
+
* EVERY MUTATION GOES THROUGH THE SERVICE (which goes through `store.ts`), because the store is
|
|
14
|
+
* the only write authority (I-12). A typed `/memory save` or `/memory rm` is the user's own
|
|
15
|
+
* action, which is why it is allowed to write at all (I-1): nothing here runs on its own.
|
|
16
|
+
*
|
|
17
|
+
* A REFERENCE IS RESOLVED, NEVER GUESSED. Two notes can share a title and two ids a prefix; an
|
|
18
|
+
* ambiguous reference prints up to five candidates and refuses, because the next word may be
|
|
19
|
+
* `rm`.
|
|
20
|
+
*
|
|
21
|
+
* THE COMMAND STAYS REGISTERED WHEN MEMORY IS OFF, and says so: the one surface that can explain
|
|
22
|
+
* a switch must not be removed by it.
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
25
|
+
import { join, resolve } from 'node:path';
|
|
26
|
+
import { MEMORY_DISABLED_COPY, MEMORY_MOUNT_REFUSED_COPY, MEMORY_UNAVAILABLE_COPY, memoryAgentWritesCopy, memoryAutoloadCopy, memoryDeletedCopy, memoryErrorCopy, memoryMountedCopy, memoryResetCopy, memoryRestoredCopy, memorySavedCopy, memoryUnmountedCopy, } from '@aragon-agent/tui/model/memory/copy';
|
|
27
|
+
import { clipCodePoints } from '@aragon-agent/tui/model/memory/validate';
|
|
28
|
+
import { getMemoryDir } from './paths.js';
|
|
29
|
+
import { resolveMemoryRef } from './resolve.js';
|
|
30
|
+
import { MAX_IMPORT_BYTES, buildExport, parseImport } from './transfer.js';
|
|
31
|
+
export const MEMORY_HELP = [
|
|
32
|
+
'/memory open the manager (Ctrl+M / Alt+M)',
|
|
33
|
+
'/memory list [words] numbered list; never prints a body',
|
|
34
|
+
'/memory show <ref> print one note into the transcript',
|
|
35
|
+
'/memory save [--global] <text> save a note now (project scope unless --global)',
|
|
36
|
+
'/memory add [text] open the editor, optionally prefilled',
|
|
37
|
+
'/memory rm <ref> move to the trash (30 days; /memory restore undoes it)',
|
|
38
|
+
'/memory restore [ref] list the trash, or bring one back',
|
|
39
|
+
'/memory mount|unmount|reset <ref> put a note in / out of this session',
|
|
40
|
+
'/memory auto on|off|reset auto-load for this session',
|
|
41
|
+
'/memory agent ask|auto|reset whether the agent must ask before it writes',
|
|
42
|
+
'/memory path where the notes live',
|
|
43
|
+
'/memory export <file> [--force] write every note to a JSON file (no ids, no history)',
|
|
44
|
+
'/memory import <file> add the notes in an export file (never overwrites)',
|
|
45
|
+
'<ref> is a number from `list`, an id, an exact title or a unique id prefix.',
|
|
46
|
+
].join('\n');
|
|
47
|
+
export function registerMemoryCommands(registry) {
|
|
48
|
+
registry.register({
|
|
49
|
+
name: 'memory',
|
|
50
|
+
aliases: ['mem'],
|
|
51
|
+
description: 'Memory manager: list, save, show, remove, mount, auto-load, agent writes',
|
|
52
|
+
run: (ctx) => runMemoryCommand(ctx),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** `1. mem_k3f9a2 [proj pin *] Prefer pnpm` - no body, ever. */
|
|
56
|
+
export function memoryListLine(row, at) {
|
|
57
|
+
const flags = [
|
|
58
|
+
row.scope === 'project' ? 'proj' : 'glob',
|
|
59
|
+
!row.enabled ? 'off' : row.load === 'pinned' ? 'pin' : row.load === 'manual' ? 'man' : 'auto',
|
|
60
|
+
row.rowState === 'body-mount' ? 'mounted' : row.rowState.startsWith('body-') ? 'loaded' : '',
|
|
61
|
+
row.rowState === 'unmounted' ? 'unmounted' : '',
|
|
62
|
+
].filter((part) => part.length > 0).join(' ');
|
|
63
|
+
return `${at + 1}. ${row.id} [${flags}] ${row.title}`;
|
|
64
|
+
}
|
|
65
|
+
function reportChange(ctx, result, row, kind) {
|
|
66
|
+
if (!result.ok) {
|
|
67
|
+
ctx.notify('warn', result.code === 'mount_refused' ? MEMORY_MOUNT_REFUSED_COPY : memoryErrorCopy(result.code));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const deferred = result.effect === 'deferred';
|
|
71
|
+
const text = kind === 'mount' ? memoryMountedCopy(row.title, deferred)
|
|
72
|
+
: kind === 'unmount' ? memoryUnmountedCopy(row.title, deferred)
|
|
73
|
+
: memoryResetCopy(row.title, deferred);
|
|
74
|
+
ctx.notify('info', text);
|
|
75
|
+
}
|
|
76
|
+
/** `<ref>` -> row, or `null` after saying why not. */
|
|
77
|
+
function resolveOrReport(ctx, service, ref) {
|
|
78
|
+
const rows = service.listRows();
|
|
79
|
+
const found = resolveMemoryRef(rows, ref);
|
|
80
|
+
if (found.ok)
|
|
81
|
+
return found.row;
|
|
82
|
+
if (found.code === 'ambiguous') {
|
|
83
|
+
const lines = found.candidates.map((row, at) => `${at + 1}) ${row.id} ${row.title}`);
|
|
84
|
+
ctx.notify('warn', `${memoryErrorCopy('ambiguous')}\n${lines.join('\n')}`);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
ctx.notify('warn', memoryErrorCopy('not_found'));
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function runList(ctx, service, query) {
|
|
91
|
+
const rows = service.listRows(query);
|
|
92
|
+
if (rows.length === 0) {
|
|
93
|
+
ctx.notify('info', query.length > 0 ? 'No memory matches.' : 'No memories yet. Try /memory add or Ctrl+M.');
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const lines = rows.map((row, at) => memoryListLine(row, at));
|
|
97
|
+
ctx.notify('info', `${lines.join('\n')}\n${rows.length} notes. /memory show <n> prints one.`);
|
|
98
|
+
}
|
|
99
|
+
function runShow(ctx, service, ref) {
|
|
100
|
+
const row = resolveOrReport(ctx, service, ref);
|
|
101
|
+
if (!row)
|
|
102
|
+
return;
|
|
103
|
+
const note = service.getNote(row.id);
|
|
104
|
+
if (!note.ok) {
|
|
105
|
+
ctx.notify('warn', memoryErrorCopy(note.code));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// THE ONLY PATH THAT PUTS A BODY INTO THE TRANSCRIPT, and it says so first: the transcript is
|
|
109
|
+
// saved with the session and is what a shared screenshot shows.
|
|
110
|
+
ctx.notify('info', 'The note text below goes into the conversation record.');
|
|
111
|
+
const tags = note.value.tags.map((tag) => `#${tag}`).join(' ');
|
|
112
|
+
ctx.notify('info', `${[note.value.title, tags].filter(Boolean).join(' ')}\n${note.value.body}`);
|
|
113
|
+
}
|
|
114
|
+
function runSave(ctx, service, rest) {
|
|
115
|
+
const global = /^--global(\s+|$)/.test(rest);
|
|
116
|
+
const text = rest.replace(/^--global(\s+|$)/, '').trim();
|
|
117
|
+
if (text.length === 0) {
|
|
118
|
+
ctx.notify('warn', 'Usage: /memory save [--global] <text>');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const firstLine = text.split('\n').find((line) => line.trim().length > 0) ?? text;
|
|
122
|
+
const title = clipCodePoints(firstLine.trim(), 60);
|
|
123
|
+
const saved = service.saveNote({
|
|
124
|
+
title,
|
|
125
|
+
summary: '',
|
|
126
|
+
body: text,
|
|
127
|
+
tags: [],
|
|
128
|
+
load: 'auto',
|
|
129
|
+
enabled: true,
|
|
130
|
+
scope: global ? 'global' : 'project',
|
|
131
|
+
});
|
|
132
|
+
if (saved.ok) {
|
|
133
|
+
ctx.notify('info', memorySavedCopy(saved.value.title));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// A typed command cannot show the "looks like a secret" confirmation, so it refuses and points
|
|
137
|
+
// at the editor, where the confirmation exists.
|
|
138
|
+
if (saved.code === 'secret_detected') {
|
|
139
|
+
ctx.notify('warn', `${memoryErrorCopy('secret_detected')} (${saved.kind ?? 'secret'}) Use Ctrl+M to confirm.`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
ctx.notify('warn', memoryErrorCopy(saved.code));
|
|
143
|
+
}
|
|
144
|
+
function runRemove(ctx, service, ref) {
|
|
145
|
+
const row = resolveOrReport(ctx, service, ref);
|
|
146
|
+
if (!row)
|
|
147
|
+
return;
|
|
148
|
+
const result = service.deleteNote(row.id, row.rev);
|
|
149
|
+
if (result.ok)
|
|
150
|
+
ctx.notify('info', memoryDeletedCopy(row.title, row.id));
|
|
151
|
+
else
|
|
152
|
+
ctx.notify('warn', memoryErrorCopy(result.code));
|
|
153
|
+
}
|
|
154
|
+
function runRestore(ctx, service, ref) {
|
|
155
|
+
const items = service.trash();
|
|
156
|
+
if (ref.length === 0) {
|
|
157
|
+
if (items.length === 0) {
|
|
158
|
+
ctx.notify('info', 'The trash is empty.');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const lines = items.map((item, at) => `${at + 1}. ${item.trashId} [${item.scope}] ${item.title}`);
|
|
162
|
+
ctx.notify('info', `${lines.join('\n')}\n/memory restore <n|id> brings one back.`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const byNumber = /^\d{1,4}$/.test(ref) ? items[Number.parseInt(ref, 10) - 1] : undefined;
|
|
166
|
+
const matches = byNumber
|
|
167
|
+
? [byNumber]
|
|
168
|
+
: items.filter((item) => item.trashId === ref || item.id === ref || item.trashId.startsWith(ref));
|
|
169
|
+
if (matches.length !== 1) {
|
|
170
|
+
ctx.notify('warn', matches.length === 0 ? memoryErrorCopy('not_found') : memoryErrorCopy('ambiguous'));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const item = matches[0];
|
|
174
|
+
const result = service.restoreTrashed(item.scope, item.trashId);
|
|
175
|
+
if (result.ok)
|
|
176
|
+
ctx.notify('info', memoryRestoredCopy(item.title));
|
|
177
|
+
else
|
|
178
|
+
ctx.notify('warn', memoryErrorCopy(result.code));
|
|
179
|
+
}
|
|
180
|
+
function runMount(ctx, service, verb, ref) {
|
|
181
|
+
const row = resolveOrReport(ctx, service, ref);
|
|
182
|
+
if (!row)
|
|
183
|
+
return;
|
|
184
|
+
reportChange(ctx, service.setOverride(row.id, verb), row, verb);
|
|
185
|
+
}
|
|
186
|
+
function runAuto(ctx, service, arg) {
|
|
187
|
+
const value = arg === 'on' ? true : arg === 'off' ? false : arg === 'reset' ? null : undefined;
|
|
188
|
+
if (value === undefined) {
|
|
189
|
+
ctx.notify('warn', 'Usage: /memory auto on|off|reset');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const result = service.setAutoload(value);
|
|
193
|
+
if (result.ok)
|
|
194
|
+
ctx.notify('info', memoryAutoloadCopy(value, result.effect === 'deferred'));
|
|
195
|
+
else
|
|
196
|
+
ctx.notify('warn', memoryErrorCopy(result.code));
|
|
197
|
+
}
|
|
198
|
+
function runAgent(ctx, service, arg) {
|
|
199
|
+
const value = arg === 'ask' ? 'ask' : arg === 'auto' ? 'auto' : arg === 'reset' ? null : undefined;
|
|
200
|
+
if (value === undefined) {
|
|
201
|
+
ctx.notify('warn', 'Usage: /memory agent ask|auto|reset (off can only be set in configuration)');
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (service.effectiveAgentWrites() === 'off' && value !== null) {
|
|
205
|
+
ctx.notify('warn', memoryAgentWritesCopy('off'));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const result = service.setAgentWrites(value);
|
|
209
|
+
if (result.ok)
|
|
210
|
+
ctx.notify('info', memoryAgentWritesCopy(value ?? 'reset'));
|
|
211
|
+
else
|
|
212
|
+
ctx.notify('warn', memoryErrorCopy(result.code));
|
|
213
|
+
}
|
|
214
|
+
function runPath(ctx, service) {
|
|
215
|
+
const root = getMemoryDir();
|
|
216
|
+
ctx.notify('info', `global: ${join(root, 'global')}\nproject: ${join(root, 'projects', service.getProject().key)} (${service.getProject().label})`);
|
|
217
|
+
}
|
|
218
|
+
function runExport(ctx, service, rest) {
|
|
219
|
+
const force = /(^|\s)--force\s*$/.test(rest);
|
|
220
|
+
const name = rest.replace(/(^|\s)--force\s*$/, '').trim();
|
|
221
|
+
if (name.length === 0) {
|
|
222
|
+
ctx.notify('warn', 'Usage: /memory export <file> [--force]');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const file = resolve(ctx.controller.getCwd(), name);
|
|
226
|
+
if (existsSync(file) && !force) {
|
|
227
|
+
ctx.notify('warn', `${file} already exists. Add --force to overwrite it.`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const notes = service.scanFresh();
|
|
231
|
+
try {
|
|
232
|
+
writeFileSync(file, buildExport(notes, Date.now()), { encoding: 'utf-8', mode: 0o600 });
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
ctx.notify('warn', memoryErrorCopy('write_failed'));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
ctx.notify('info', `Exported ${notes.length} notes to ${file}. The file is plain text.`);
|
|
239
|
+
}
|
|
240
|
+
function runImport(ctx, service, rest) {
|
|
241
|
+
if (rest.length === 0) {
|
|
242
|
+
ctx.notify('warn', 'Usage: /memory import <file>');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const file = resolve(ctx.controller.getCwd(), rest);
|
|
246
|
+
let text;
|
|
247
|
+
try {
|
|
248
|
+
if (statSync(file).size > MAX_IMPORT_BYTES) {
|
|
249
|
+
ctx.notify('warn', 'That file is larger than 2 MiB; refusing to import it.');
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
text = readFileSync(file, 'utf-8');
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
ctx.notify('warn', `Could not read ${file}.`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const parsed = parseImport(text);
|
|
259
|
+
if (parsed.failure !== undefined) {
|
|
260
|
+
ctx.notify('warn', parsed.failure === 'bad_schema'
|
|
261
|
+
? 'That is not a memory export file (wrong or missing schema).'
|
|
262
|
+
: parsed.failure === 'not_json' ? 'That file is not valid JSON.' : 'That file is too large.');
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const result = service.importNotes(parsed.drafts);
|
|
266
|
+
const skipped = result.skipped + parsed.skipped;
|
|
267
|
+
const ignored = parsed.ignored > 0 ? `, ${parsed.ignored} past the 400-note limit ignored` : '';
|
|
268
|
+
ctx.notify('info', `Imported ${result.added} notes; skipped ${skipped} (invalid, secret-like or over the per-scope limit)${ignored}.`);
|
|
269
|
+
}
|
|
270
|
+
/** Split `verb rest...`. */
|
|
271
|
+
function splitVerb(args) {
|
|
272
|
+
const trimmed = args.trim();
|
|
273
|
+
const space = trimmed.search(/\s/);
|
|
274
|
+
return {
|
|
275
|
+
verb: (space === -1 ? trimmed : trimmed.slice(0, space)).toLowerCase(),
|
|
276
|
+
rest: space === -1 ? '' : trimmed.slice(space + 1).trim(),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/** What `/memory add <text>` opens the editor with (a title taken from the first line). */
|
|
280
|
+
function seedOf(text) {
|
|
281
|
+
if (text.length === 0)
|
|
282
|
+
return {};
|
|
283
|
+
const first = text.split('\n').find((line) => line.trim().length > 0) ?? '';
|
|
284
|
+
return { title: clipCodePoints(first.trim(), 60), body: text };
|
|
285
|
+
}
|
|
286
|
+
/** The dispatcher. `enabled=false` is answered BEFORE any subcommand. */
|
|
287
|
+
export async function runMemoryCommand(ctx) {
|
|
288
|
+
// `=== false` first: a switched-off feature explains itself, even where there is no service.
|
|
289
|
+
if (ctx.controller.getConfig().memory?.enabled === false) {
|
|
290
|
+
ctx.notify('info', MEMORY_DISABLED_COPY);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const service = ctx.controller.getMemoryService();
|
|
294
|
+
const port = ctx.memory;
|
|
295
|
+
const { verb, rest } = splitVerb(ctx.args);
|
|
296
|
+
if (verb === 'help') {
|
|
297
|
+
ctx.notify('info', MEMORY_HELP);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!service || !port) {
|
|
301
|
+
ctx.notify('warn', MEMORY_UNAVAILABLE_COPY);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
switch (verb) {
|
|
305
|
+
case '':
|
|
306
|
+
port.openManager({ kind: 'list' });
|
|
307
|
+
return;
|
|
308
|
+
case 'list':
|
|
309
|
+
runList(ctx, service, rest);
|
|
310
|
+
return;
|
|
311
|
+
case 'show':
|
|
312
|
+
runShow(ctx, service, rest);
|
|
313
|
+
return;
|
|
314
|
+
case 'save':
|
|
315
|
+
runSave(ctx, service, rest);
|
|
316
|
+
return;
|
|
317
|
+
case 'add':
|
|
318
|
+
port.openManager({ kind: 'create', seed: seedOf(rest) });
|
|
319
|
+
return;
|
|
320
|
+
case 'rm':
|
|
321
|
+
case 'remove':
|
|
322
|
+
case 'delete':
|
|
323
|
+
runRemove(ctx, service, rest);
|
|
324
|
+
return;
|
|
325
|
+
case 'restore':
|
|
326
|
+
runRestore(ctx, service, rest);
|
|
327
|
+
return;
|
|
328
|
+
case 'mount':
|
|
329
|
+
case 'unmount':
|
|
330
|
+
case 'reset':
|
|
331
|
+
runMount(ctx, service, verb, rest);
|
|
332
|
+
return;
|
|
333
|
+
case 'auto':
|
|
334
|
+
runAuto(ctx, service, rest.toLowerCase());
|
|
335
|
+
return;
|
|
336
|
+
case 'agent':
|
|
337
|
+
runAgent(ctx, service, rest.toLowerCase());
|
|
338
|
+
return;
|
|
339
|
+
case 'path':
|
|
340
|
+
runPath(ctx, service);
|
|
341
|
+
return;
|
|
342
|
+
case 'export':
|
|
343
|
+
runExport(ctx, service, rest);
|
|
344
|
+
return;
|
|
345
|
+
case 'import':
|
|
346
|
+
runImport(ctx, service, rest);
|
|
347
|
+
return;
|
|
348
|
+
default: ctx.notify('warn', `Unknown subcommand "${verb}". /memory help lists them.`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One note file <-> a `MemoryNote` (agent-memory spec 5.2).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/memory/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* STRICT OUT, TOLERANT IN. A note is written in one fixed shape (field order, JSON-quoted
|
|
7
|
+
* strings, LF endings), but READ from whatever a person or a sync tool left behind: no
|
|
8
|
+
* frontmatter, unknown keys, a half-quoted title, CRLF, a BOM, a bad date. Every
|
|
9
|
+
* deviation degrades to a usable note flagged `repaired`; it never throws and it never
|
|
10
|
+
* discards the file (I-3). Reading never rewrites the file either (I-14): normalising is
|
|
11
|
+
* something a SAVE does, not something opening the manager does behind the user's back.
|
|
12
|
+
*
|
|
13
|
+
* The frontmatter is a deliberately tiny YAML subset (scalars, a flat list, quoted
|
|
14
|
+
* strings). `skills/manifest.ts` is a `.aragon-skill.json` reader, not a frontmatter
|
|
15
|
+
* parser, so there is nothing to reuse and no dependency worth adding for six keys.
|
|
16
|
+
*/
|
|
17
|
+
import { deriveMemorySummary } from '@aragon-agent/tui/model/memory/validate';
|
|
18
|
+
import type { MemoryNote, MemoryNoteLoad, MemoryNoteScope, MemoryNoteSource } from '@aragon-agent/tui/model/memory/types';
|
|
19
|
+
export { deriveMemorySummary };
|
|
20
|
+
/** The `schema:` value this build writes. A larger value found on disk is preserved. */
|
|
21
|
+
export declare const MEMORY_FILE_SCHEMA = 1;
|
|
22
|
+
/** First 10 hex chars of the sha1 of the file's bytes (D-16). */
|
|
23
|
+
export declare function computeRev(bytes: Uint8Array): string;
|
|
24
|
+
/** Decode strictly; `null` for bytes that are not valid UTF-8 (the file is skipped). */
|
|
25
|
+
export declare function decodeNoteBytes(bytes: Uint8Array): string | null;
|
|
26
|
+
interface ParseContext {
|
|
27
|
+
id: string;
|
|
28
|
+
scope: MemoryNoteScope;
|
|
29
|
+
mtimeMs: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse one file's bytes into a note. `null` ONLY when the bytes are not UTF-8 (the
|
|
33
|
+
* caller counts that as skipped); every other oddity becomes a repaired note.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseNoteBytes(bytes: Uint8Array, ctx: ParseContext): MemoryNote | null;
|
|
36
|
+
/** The fields a file carries (everything but the derived `rev` / `bytes` / counts). */
|
|
37
|
+
export interface SerializableNote {
|
|
38
|
+
title: string;
|
|
39
|
+
summary: string;
|
|
40
|
+
body: string;
|
|
41
|
+
tags: readonly string[];
|
|
42
|
+
load: MemoryNoteLoad;
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
updatedAt: number;
|
|
46
|
+
source: MemoryNoteSource;
|
|
47
|
+
schema: number;
|
|
48
|
+
extra?: Readonly<Record<string, string>>;
|
|
49
|
+
}
|
|
50
|
+
/** The exact bytes (as text) a note is stored as. Always LF; always ends in a newline. */
|
|
51
|
+
export declare function serializeNote(note: SerializableNote): string;
|