@aragon-agent/cli 0.6.70 → 0.6.72
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 +20 -0
- package/README.md +33 -14
- package/dist/account/config.d.ts +61 -0
- package/dist/account/config.js +83 -0
- package/dist/account/device-client.d.ts +113 -0
- package/dist/account/device-client.js +425 -0
- package/dist/account/format.d.ts +51 -0
- package/dist/account/format.js +102 -0
- package/dist/account/login-flow.d.ts +68 -0
- package/dist/account/login-flow.js +305 -0
- package/dist/account/session.d.ts +62 -0
- package/dist/account/session.js +63 -0
- package/dist/account/store.d.ts +86 -0
- package/dist/account/store.js +231 -0
- package/dist/agent/controller.d.ts +25 -1
- package/dist/agent/controller.js +78 -3
- package/dist/agent/project-guidance-prompt.js +97 -97
- package/dist/app/App.d.ts +12 -3
- package/dist/app/App.js +216 -3
- package/dist/cli.js +2 -2
- package/dist/commands/account-command.d.ts +86 -0
- package/dist/commands/account-command.js +165 -0
- package/dist/commands/builtins.js +15 -0
- package/dist/commands/catalog.js +17 -1
- package/dist/config/app-paths.d.ts +15 -0
- package/dist/config/app-paths.js +17 -0
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +4 -0
- package/dist/config/env.js +6 -0
- package/dist/config/load.js +36 -1
- package/dist/governance/engine/lifecycle.js +1 -1
- package/dist/governance/prompts/orchestrator-block.js +3 -3
- package/dist/host/controller-factory.d.ts +15 -0
- package/dist/host/controller-factory.js +10 -2
- package/dist/host/memory.d.ts +5 -1
- package/dist/host/memory.js +13 -0
- package/dist/memory/block.d.ts +38 -4
- package/dist/memory/block.js +52 -5
- package/dist/memory/command.js +56 -2
- package/dist/memory/journal.d.ts +58 -0
- package/dist/memory/journal.js +202 -0
- package/dist/memory/ledger.d.ts +54 -0
- package/dist/memory/ledger.js +105 -0
- package/dist/memory/paths.d.ts +10 -0
- package/dist/memory/paths.js +31 -0
- package/dist/memory/service.d.ts +54 -1
- package/dist/memory/service.js +156 -1
- package/dist/memory/store.d.ts +21 -3
- package/dist/memory/store.js +66 -6
- package/dist/memory/tools-batch.d.ts +27 -0
- package/dist/memory/tools-batch.js +462 -0
- package/dist/memory/tools-shared.d.ts +176 -0
- package/dist/memory/tools-shared.js +305 -0
- package/dist/memory/tools.d.ts +19 -28
- package/dist/memory/tools.js +148 -228
- package/dist/memory/undo.d.ts +53 -0
- package/dist/memory/undo.js +173 -0
- package/dist/redteam/prompt-template.js +16 -16
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +16 -1
- package/package.json +3 -3
- package/runtime/insecure-tls-warning.cjs +62 -62
- package/runtime/insecure-tls-warning.d.cts +5 -5
- package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -14
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The memory journal: an append-only record of every applied change
|
|
3
|
+
* (memory-agent-autonomy spec 5.2 / 8.1).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - `src/memory/**` is inside `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* WHY IT EXISTS. Approval used to be per write, so the transcript was the record. Autonomy has no
|
|
8
|
+
* per-write moment, so the record has to be made somewhere else: one line per applied op, no note
|
|
9
|
+
* text, kept for three months. It is the only cross-process truth about what changed - which is
|
|
10
|
+
* what `/memory undo`, the activity page and the 24h budget all read (D-5 / D-8).
|
|
11
|
+
*
|
|
12
|
+
* APPEND, NEVER REWRITE. `appendFileSync` gives append semantics through `O_APPEND`; there is no
|
|
13
|
+
* temp file and no rename, unlike notes. The price is real and it is documented rather than
|
|
14
|
+
* hidden: two processes appending at the same moment can interleave one line into another, so the
|
|
15
|
+
* READER treats a broken line as normal (skipped and counted, never thrown).
|
|
16
|
+
*
|
|
17
|
+
* NEVER THROWS (I-3). A failed append returns `'failed'` and the caller carries on: the note write
|
|
18
|
+
* already happened, and reporting it as failed because the bookkeeping line did not land would be a
|
|
19
|
+
* lie with worse consequences than a missing history row.
|
|
20
|
+
*
|
|
21
|
+
* READ-ONLY ON THE READ PATH (I-14's spirit): `readJournal` and `listJournalFiles` create nothing
|
|
22
|
+
* and touch no mtime - a start-up that only reads must not look like a write to a snapshot test.
|
|
23
|
+
*/
|
|
24
|
+
import { appendFileSync, existsSync, readFileSync, readdirSync, statSync, unlinkSync, } from 'node:fs';
|
|
25
|
+
import { join } from 'node:path';
|
|
26
|
+
import { MEMORY_LIMITS } from '@aragon-agent/tui/model/memory/limits';
|
|
27
|
+
import { journalMonthKey, parseJournalLine, serializeJournalLine, utf8Bytes, } from '@aragon-agent/tui/model/memory/activity';
|
|
28
|
+
import { getLogger } from '../logging/logger.js';
|
|
29
|
+
import { journalDir, journalFile } from './paths.js';
|
|
30
|
+
import { mkdirPrivate } from './store.js';
|
|
31
|
+
const MONTH_FILE = /^\d{4}-\d{2}\.jsonl$/;
|
|
32
|
+
function warn(event, fields) {
|
|
33
|
+
try {
|
|
34
|
+
getLogger().warn('memory', event, fields);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Logging must never be the thing that breaks a write.
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Append one row to the current month's file for `target`.
|
|
42
|
+
*
|
|
43
|
+
* The directory is created here (mode 0700) and nowhere else: a process that never writes a note
|
|
44
|
+
* never creates `.journal/`, which is what keeps a read-only session invisible to a directory
|
|
45
|
+
* snapshot.
|
|
46
|
+
*/
|
|
47
|
+
export function appendJournalEntry(target, entry) {
|
|
48
|
+
const line = serializeJournalLine(entry);
|
|
49
|
+
if (line === null) {
|
|
50
|
+
warn('journal_line_rejected', { op: entry.op, id: entry.id });
|
|
51
|
+
return 'failed';
|
|
52
|
+
}
|
|
53
|
+
const file = journalFile(target, journalMonthKey(entry.at));
|
|
54
|
+
if (file === null) {
|
|
55
|
+
warn('journal_path_rejected', { scope: target.scope });
|
|
56
|
+
return 'failed';
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
// THE LINE HAS TO FIT, NOT JUST THE FILE (spec 5.2: the month file stays at or below
|
|
60
|
+
// `journalFileMaxBytes`). Testing the file alone let the last admitted line push it past the
|
|
61
|
+
// ceiling by up to one `journalLineMax`.
|
|
62
|
+
if (!fitsInFile(file, line)) {
|
|
63
|
+
warn('journal_file_full', { scope: target.scope, month: journalMonthKey(entry.at) });
|
|
64
|
+
return 'failed';
|
|
65
|
+
}
|
|
66
|
+
const dir = journalDir(target);
|
|
67
|
+
// THE SAME DIRECTORY DISCIPLINE AS THE NOTES (spec 8.1 asks for `mkdirPrivate`'s semantics; a
|
|
68
|
+
// second copy of it would have to be kept in step by hand).
|
|
69
|
+
if (dir !== null)
|
|
70
|
+
mkdirPrivate(dir);
|
|
71
|
+
appendFileSync(file, `${line}\n`, { encoding: 'utf-8', mode: 0o600 });
|
|
72
|
+
return 'ok';
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
warn('journal_append_failed', { scope: target.scope, reason: String(error) });
|
|
76
|
+
return 'failed';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Would appending `line` keep this month file within its byte ceiling? */
|
|
80
|
+
function fitsInFile(file, line) {
|
|
81
|
+
const addition = Buffer.byteLength(line, 'utf-8') + 1;
|
|
82
|
+
try {
|
|
83
|
+
if (!existsSync(file))
|
|
84
|
+
return addition <= MEMORY_LIMITS.journalFileMaxBytes;
|
|
85
|
+
return statSync(file).size + addition <= MEMORY_LIMITS.journalFileMaxBytes;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// An unreadable size is not a reason to refuse: a missing ceiling is better than a journal that
|
|
89
|
+
// stops recording because one stat failed.
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* This scope's month files, newest first.
|
|
95
|
+
*
|
|
96
|
+
* Names sort chronologically (`YYYY-MM`), so the order needs no `mtime` and survives a copy that
|
|
97
|
+
* rewrites timestamps. Missing directories read as an empty list.
|
|
98
|
+
*/
|
|
99
|
+
export function listJournalFiles(target) {
|
|
100
|
+
const dir = journalDir(target);
|
|
101
|
+
if (dir === null)
|
|
102
|
+
return [];
|
|
103
|
+
let names;
|
|
104
|
+
try {
|
|
105
|
+
names = readdirSync(dir)
|
|
106
|
+
.filter((name) => MONTH_FILE.test(name))
|
|
107
|
+
.sort((a, b) => b.localeCompare(a));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
return names.map((name) => join(dir, name));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The newest `limit` rows, newest first, plus how many lines had to be skipped.
|
|
116
|
+
*
|
|
117
|
+
* `limit` defaults to the activity page's bound; the 24h budget calls this with
|
|
118
|
+
* `journalSeedScanMax` instead, because counting to 50 and then treating a restart as "0 writes"
|
|
119
|
+
* is exactly the bypass D-8 exists to close.
|
|
120
|
+
*/
|
|
121
|
+
export function readJournal(target, limit = MEMORY_LIMITS.activityRowsMax) {
|
|
122
|
+
const cap = Math.max(1, Math.min(limit, MEMORY_LIMITS.journalSeedScanMax));
|
|
123
|
+
const entries = [];
|
|
124
|
+
let skipped = 0;
|
|
125
|
+
let scanned = 0;
|
|
126
|
+
for (const file of listJournalFiles(target)) {
|
|
127
|
+
let text;
|
|
128
|
+
try {
|
|
129
|
+
text = readFileSync(file, 'utf-8');
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
skipped += 1;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const lines = text.split('\n');
|
|
136
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
137
|
+
if (scanned >= MEMORY_LIMITS.journalSeedScanMax) {
|
|
138
|
+
return { entries, skipped };
|
|
139
|
+
}
|
|
140
|
+
const raw = lines[index] ?? '';
|
|
141
|
+
if (raw.trim().length === 0)
|
|
142
|
+
continue;
|
|
143
|
+
scanned += 1;
|
|
144
|
+
// A LINE OVER THE CEILING IS NOT A LINE THIS FORMAT CAN PRODUCE (spec 5.2). Parsing it anyway
|
|
145
|
+
// meant one hand-edited 512 KiB row would be `JSON.parse`d whole on every start-up; the writer
|
|
146
|
+
// never emits one, so the reader treats it the way it treats every other impossible row.
|
|
147
|
+
if (utf8Bytes(raw) > MEMORY_LIMITS.journalLineMax) {
|
|
148
|
+
skipped += 1;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const entry = parseJournalLine(raw);
|
|
152
|
+
if (entry === null) {
|
|
153
|
+
skipped += 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
entries.push(entry);
|
|
157
|
+
if (entries.length >= cap)
|
|
158
|
+
return { entries, skipped };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { entries, skipped };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Keep the newest `journalMonthsKept` month files in this scope, delete the rest.
|
|
165
|
+
*
|
|
166
|
+
* Called once per process from the first user turn (spec 8.1's named call site), never from a
|
|
167
|
+
* read path. A file that cannot be deleted is skipped: housekeeping must not fail a turn.
|
|
168
|
+
*/
|
|
169
|
+
export function pruneJournal(target, now) {
|
|
170
|
+
const keep = MEMORY_LIMITS.journalMonthsKept;
|
|
171
|
+
const files = listJournalFiles(target);
|
|
172
|
+
const currentMonth = journalMonthKey(now);
|
|
173
|
+
let removed = 0;
|
|
174
|
+
for (const file of files) {
|
|
175
|
+
const month = file.slice(file.length - 'YYYY-MM.jsonl'.length, -'.jsonl'.length);
|
|
176
|
+
if (month >= currentMonth)
|
|
177
|
+
continue;
|
|
178
|
+
const age = monthsBetween(month, currentMonth);
|
|
179
|
+
if (age < keep)
|
|
180
|
+
continue;
|
|
181
|
+
try {
|
|
182
|
+
unlinkSync(file);
|
|
183
|
+
removed += 1;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// A locked file is harmless; the next launch tries again.
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (removed > 0)
|
|
190
|
+
warn('journal_pruned', { scope: target.scope, files: removed });
|
|
191
|
+
return removed;
|
|
192
|
+
}
|
|
193
|
+
/** Whole months from `from` to `to`; negative when `from` is the later one. */
|
|
194
|
+
function monthsBetween(from, to) {
|
|
195
|
+
const fromYear = Number.parseInt(from.slice(0, 4), 10);
|
|
196
|
+
const fromMonth = Number.parseInt(from.slice(5, 7), 10);
|
|
197
|
+
const toYear = Number.parseInt(to.slice(0, 4), 10);
|
|
198
|
+
const toMonth = Number.parseInt(to.slice(5, 7), 10);
|
|
199
|
+
if (!Number.isFinite(fromYear) || !Number.isFinite(toYear))
|
|
200
|
+
return 0;
|
|
201
|
+
return (toYear - fromYear) * 12 + (toMonth - fromMonth);
|
|
202
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The write ledger, without a session (memory-agent-autonomy spec 8.1 / 8.2 / 11.1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/memory/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS FILE EXISTS. `/memory undo` and the activity page run inside a session, where a
|
|
7
|
+
* `MemoryService` is already there to answer `targets()` and to publish the change. A GUI host has
|
|
8
|
+
* neither: it may import the engine only through `host/**` (layering L7), it never constructs a
|
|
9
|
+
* service (that scans the notes and rebuilds a prompt block nobody will read), and yet it owns the
|
|
10
|
+
* two channels a person uses to see and to take back what the agent did.
|
|
11
|
+
*
|
|
12
|
+
* So: the same journal, the same inverse operations, the same `undoBatch`, driven by a host object
|
|
13
|
+
* that knows the scopes and nothing else. `noteChanged()` is a no-op here on purpose - there is no
|
|
14
|
+
* prompt to rebuild - and `journalAppend` is real, because an undo that is not written down is
|
|
15
|
+
* exactly the silent rewrite the ledger exists to prevent (T12).
|
|
16
|
+
*/
|
|
17
|
+
import { type MemoryTarget } from './store.js';
|
|
18
|
+
import type { MemoryJournalEntry, UndoOutcome } from '@aragon-agent/tui/model/memory/types';
|
|
19
|
+
/** The two read/write pairs a GUI host needs, and nothing else. */
|
|
20
|
+
export interface MemoryLedger {
|
|
21
|
+
/** Journal rows across every scope, newest first. Never creates the ledger directory. */
|
|
22
|
+
activity(limit?: number): MemoryJournalEntry[];
|
|
23
|
+
/** The newest batch the agent applied, or `null` when there is nothing to undo. */
|
|
24
|
+
latestBatch(): string | null;
|
|
25
|
+
/** Every still-applied row of one batch, oldest first. */
|
|
26
|
+
batchRows(batch: string): MemoryJournalEntry[];
|
|
27
|
+
/** Undo one batch across every scope. An absent id means the newest agent batch. */
|
|
28
|
+
undo(batchId?: string): UndoOutcome;
|
|
29
|
+
/** Drop month files beyond `journalMonthsKept`. Returns how many went. */
|
|
30
|
+
prune(now?: number): number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Back the host object with the scopes a host can actually see.
|
|
34
|
+
*
|
|
35
|
+
* `targets` is a GETTER, not a captured list: a project created while the window is open must be
|
|
36
|
+
* visible to the next undo, and its journal would otherwise be unreachable for the rest of the
|
|
37
|
+
* process's life.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createMemoryLedger(targets: () => readonly MemoryTarget[], now?: () => number): MemoryLedger;
|
|
40
|
+
/**
|
|
41
|
+
* Every scope on this machine: `global` plus each project that has a directory.
|
|
42
|
+
*
|
|
43
|
+
* THE ONLY WAY A HOST-LEVEL UNDO CAN BE COMPLETE: the newest agent batch may well belong to a
|
|
44
|
+
* project the window is not showing, and an undo that silently skipped it would report "1 of 1"
|
|
45
|
+
* while leaving the other note changed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function allMemoryTargets(): MemoryTarget[];
|
|
48
|
+
/**
|
|
49
|
+
* Undo one batch with no session in hand (the facade `host/memory.ts` exports).
|
|
50
|
+
*
|
|
51
|
+
* EXACTLY the session's semantics: `undoBatch` is shared, so the inverse operations, the skip
|
|
52
|
+
* reasons and the `actor: 'user'` rows cannot differ between `/memory undo` and a window's button.
|
|
53
|
+
*/
|
|
54
|
+
export declare function undoBatchForTargets(batchId?: string, now?: () => number): UndoOutcome;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The write ledger, without a session (memory-agent-autonomy spec 8.1 / 8.2 / 11.1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/memory/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS FILE EXISTS. `/memory undo` and the activity page run inside a session, where a
|
|
7
|
+
* `MemoryService` is already there to answer `targets()` and to publish the change. A GUI host has
|
|
8
|
+
* neither: it may import the engine only through `host/**` (layering L7), it never constructs a
|
|
9
|
+
* service (that scans the notes and rebuilds a prompt block nobody will read), and yet it owns the
|
|
10
|
+
* two channels a person uses to see and to take back what the agent did.
|
|
11
|
+
*
|
|
12
|
+
* So: the same journal, the same inverse operations, the same `undoBatch`, driven by a host object
|
|
13
|
+
* that knows the scopes and nothing else. `noteChanged()` is a no-op here on purpose - there is no
|
|
14
|
+
* prompt to rebuild - and `journalAppend` is real, because an undo that is not written down is
|
|
15
|
+
* exactly the silent rewrite the ledger exists to prevent (T12).
|
|
16
|
+
*/
|
|
17
|
+
import { listProjectScopes } from './store.js';
|
|
18
|
+
import { appendJournalEntry, pruneJournal, readJournal } from './journal.js';
|
|
19
|
+
import { undoBatch, latestBatch, batchRows } from './undo.js';
|
|
20
|
+
import { MEMORY_LIMITS } from '@aragon-agent/tui/model/memory/limits';
|
|
21
|
+
/**
|
|
22
|
+
* Back the host object with the scopes a host can actually see.
|
|
23
|
+
*
|
|
24
|
+
* `targets` is a GETTER, not a captured list: a project created while the window is open must be
|
|
25
|
+
* visible to the next undo, and its journal would otherwise be unreachable for the rest of the
|
|
26
|
+
* process's life.
|
|
27
|
+
*/
|
|
28
|
+
export function createMemoryLedger(targets, now = Date.now) {
|
|
29
|
+
const host = {
|
|
30
|
+
targets: () => [...targets()],
|
|
31
|
+
targetOf: (scope) => hostTargetOf(targets(), scope),
|
|
32
|
+
writeOptions: (source) => ({
|
|
33
|
+
source,
|
|
34
|
+
knownSecrets: [],
|
|
35
|
+
now: now(),
|
|
36
|
+
}),
|
|
37
|
+
journalAppend: (entry) => {
|
|
38
|
+
try {
|
|
39
|
+
appendJournalEntry(hostTargetOf(targets(), entry.scope), { v: 1, at: now(), ...entry });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// A host with no such project can still have changed nothing there; the ledger row is the
|
|
43
|
+
// only thing lost, and `appendJournalEntry` already never throws on its own account.
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
noteChanged: () => {
|
|
47
|
+
// A host has no prompt to rebuild; the window re-reads through `memory:activity`.
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
activity: (limit = MEMORY_LIMITS.activityRowsMax) => rowsOf(targets(), limit),
|
|
52
|
+
latestBatch: () => latestBatch(host),
|
|
53
|
+
batchRows: (batch) => batchRows(host, batch),
|
|
54
|
+
undo: (batchId) => undoBatch(host, batchId === undefined ? { reason: 'user' } : { batchId, reason: 'user' }),
|
|
55
|
+
prune: (at = now()) => {
|
|
56
|
+
let removed = 0;
|
|
57
|
+
for (const target of targets())
|
|
58
|
+
removed += pruneJournal(target, at);
|
|
59
|
+
return removed;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The scope a host may act on.
|
|
65
|
+
*
|
|
66
|
+
* A `project` scope it cannot name is a CONTRADICTION, and an undo must never guess one: the
|
|
67
|
+
* inverse of a row in an unknown project would look the note up in the wrong directory and report
|
|
68
|
+
* `not_found`, which reads to the user as "it is already gone". Returning `global` there would be
|
|
69
|
+
* worse - it would search the wrong tree and could act on a note that merely shares an id.
|
|
70
|
+
*/
|
|
71
|
+
function hostTargetOf(targets, scope) {
|
|
72
|
+
const found = targets.find((target) => target.scope === scope);
|
|
73
|
+
if (found !== undefined)
|
|
74
|
+
return found;
|
|
75
|
+
if (scope === 'global')
|
|
76
|
+
return { scope: 'global' };
|
|
77
|
+
throw new Error('memory ledger: no project target for a project-scoped row');
|
|
78
|
+
}
|
|
79
|
+
function rowsOf(targets, limit) {
|
|
80
|
+
const rows = [];
|
|
81
|
+
for (const target of targets) {
|
|
82
|
+
rows.push(...readJournal(target, MEMORY_LIMITS.journalSeedScanMax).entries);
|
|
83
|
+
}
|
|
84
|
+
return rows.sort((a, b) => b.at - a.at).slice(0, Math.max(1, limit));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Every scope on this machine: `global` plus each project that has a directory.
|
|
88
|
+
*
|
|
89
|
+
* THE ONLY WAY A HOST-LEVEL UNDO CAN BE COMPLETE: the newest agent batch may well belong to a
|
|
90
|
+
* project the window is not showing, and an undo that silently skipped it would report "1 of 1"
|
|
91
|
+
* while leaving the other note changed.
|
|
92
|
+
*/
|
|
93
|
+
export function allMemoryTargets() {
|
|
94
|
+
const projects = listProjectScopes().map((entry) => ({ scope: 'project', projectKey: entry.key }));
|
|
95
|
+
return [{ scope: 'global' }, ...projects];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Undo one batch with no session in hand (the facade `host/memory.ts` exports).
|
|
99
|
+
*
|
|
100
|
+
* EXACTLY the session's semantics: `undoBatch` is shared, so the inverse operations, the skip
|
|
101
|
+
* reasons and the `actor: 'user'` rows cannot differ between `/memory undo` and a window's button.
|
|
102
|
+
*/
|
|
103
|
+
export function undoBatchForTargets(batchId, now = Date.now) {
|
|
104
|
+
return createMemoryLedger(allMemoryTargets, now).undo(batchId);
|
|
105
|
+
}
|
package/dist/memory/paths.d.ts
CHANGED
|
@@ -53,6 +53,16 @@ export declare function scopeDir(target: MemoryTarget): string | null;
|
|
|
53
53
|
export declare function trashDir(target: MemoryTarget): string | null;
|
|
54
54
|
/** `.trash/versions/<scope segment>/<id>` for overwritten versions. */
|
|
55
55
|
export declare function versionsDir(target: MemoryTarget, id: string): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* `.journal/<scope segment>`: the append-only write ledger (memory-agent-autonomy spec 5.1).
|
|
58
|
+
*
|
|
59
|
+
* Under `memory/` but OUTSIDE the scope directories, which is what keeps it invisible to
|
|
60
|
+
* `scanScope`: `store.ts::isIgnoredName` skips entries that start with `.`, so a JSONL ledger is
|
|
61
|
+
* never mistaken for a note and never parsed as Markdown.
|
|
62
|
+
*/
|
|
63
|
+
export declare function journalDir(target: MemoryTarget): string | null;
|
|
64
|
+
/** One month of one scope's ledger. `month` must be `YYYY-MM`; anything else gets `null`. */
|
|
65
|
+
export declare function journalFile(target: MemoryTarget, month: string): string | null;
|
|
56
66
|
/**
|
|
57
67
|
* The file for one note, or `null` when the id is not acceptable.
|
|
58
68
|
*
|
package/dist/memory/paths.js
CHANGED
|
@@ -137,6 +137,37 @@ export function versionsDir(target, id) {
|
|
|
137
137
|
const dir = join(root, scopeSegment(target), id);
|
|
138
138
|
return isInside(root, dir) ? dir : null;
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* `.journal/<scope segment>`: the append-only write ledger (memory-agent-autonomy spec 5.1).
|
|
142
|
+
*
|
|
143
|
+
* Under `memory/` but OUTSIDE the scope directories, which is what keeps it invisible to
|
|
144
|
+
* `scanScope`: `store.ts::isIgnoredName` skips entries that start with `.`, so a JSONL ledger is
|
|
145
|
+
* never mistaken for a note and never parsed as Markdown.
|
|
146
|
+
*/
|
|
147
|
+
export function journalDir(target) {
|
|
148
|
+
if (target.scope === 'project' && !isValidProjectKey(target.projectKey))
|
|
149
|
+
return null;
|
|
150
|
+
const root = join(getMemoryDir(), '.journal');
|
|
151
|
+
const dir = join(root, scopeSegment(target));
|
|
152
|
+
return isInside(root, dir) ? dir : null;
|
|
153
|
+
}
|
|
154
|
+
/** One month of one scope's ledger. `month` must be `YYYY-MM`; anything else gets `null`. */
|
|
155
|
+
export function journalFile(target, month) {
|
|
156
|
+
// THE SHAPE IS NOT ENOUGH: 2026-99 and 2026-00 match the pattern and name a file nothing reads.
|
|
157
|
+
// Every sibling here validates its input semantically (isValidNoteId, isValidProjectKey), and this
|
|
158
|
+
// helper is reachable from a GUI host, so a month is checked as a month.
|
|
159
|
+
const matched = /^(\d{4})-(\d{2})$/.exec(month);
|
|
160
|
+
if (matched === null)
|
|
161
|
+
return null;
|
|
162
|
+
const monthNumber = Number.parseInt(matched[2] ?? '', 10);
|
|
163
|
+
if (monthNumber < 1 || monthNumber > 12)
|
|
164
|
+
return null;
|
|
165
|
+
const dir = journalDir(target);
|
|
166
|
+
if (dir === null)
|
|
167
|
+
return null;
|
|
168
|
+
const file = join(dir, `${month}.jsonl`);
|
|
169
|
+
return isInside(dir, file) && dirname(file) === dir ? file : null;
|
|
170
|
+
}
|
|
140
171
|
/**
|
|
141
172
|
* The file for one note, or `null` when the id is not acceptable.
|
|
142
173
|
*
|
package/dist/memory/service.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* picked up - there is no watcher to rely on.
|
|
23
23
|
*/
|
|
24
24
|
import type { CliConfig, MemoryConfig } from '@aragon-agent/tui/model/config/schema';
|
|
25
|
-
import type { MemoryChange, MemoryDraftInput, MemoryMountOverride, MemoryNote, MemoryNoteScope, MemoryResult, MemoryRowView, MemorySessionState, MemorySessionView, MemoryTrashItem } from '@aragon-agent/tui/model/memory/types';
|
|
25
|
+
import type { MemoryAutonomyPolicy, MemoryAutonomyState, MemoryChange, MemoryDraftInput, MemoryJournalEntry, MemoryMountOverride, MemoryNote, MemoryNoteScope, MemoryResult, MemoryRowView, MemorySessionState, MemorySessionView, MemoryTrashItem, MemoryWriteDecision, MemoryWriteIntent, UndoOutcome } from '@aragon-agent/tui/model/memory/types';
|
|
26
26
|
import { type MemoryTarget, type ProjectIdentity } from './paths.js';
|
|
27
27
|
import { type MemoryWriteOptions } from './store.js';
|
|
28
28
|
export type { MemoryChange };
|
|
@@ -55,6 +55,12 @@ export declare class MemoryService {
|
|
|
55
55
|
private block;
|
|
56
56
|
private lastEmitted;
|
|
57
57
|
private readonly listeners;
|
|
58
|
+
/** Write counters for THIS process. Never persisted: an approval does not survive a restart. */
|
|
59
|
+
private autonomy;
|
|
60
|
+
/** `pruneJournal` runs once per process, on the first real user turn. */
|
|
61
|
+
private prunedThisProcess;
|
|
62
|
+
/** The one-shot "memory is now self-managed" line has been handed to a surface. */
|
|
63
|
+
private autonomyNoticeTaken;
|
|
58
64
|
constructor(deps: MemoryServiceDeps);
|
|
59
65
|
getProject(): ProjectIdentity;
|
|
60
66
|
/** Both scopes the current workspace can see, project first. */
|
|
@@ -71,6 +77,44 @@ export declare class MemoryService {
|
|
|
71
77
|
private effectiveAutoload;
|
|
72
78
|
/** What `agentWrites` is right now. `off` can only come from configuration. */
|
|
73
79
|
effectiveAgentWrites(): 'ask' | 'auto' | 'off';
|
|
80
|
+
/**
|
|
81
|
+
* The policy right now: the configured numbers, plus this session's `agentWrites` override.
|
|
82
|
+
*
|
|
83
|
+
* Read live on every call - a session can switch `ask` <-> `auto` between two tool calls, and a
|
|
84
|
+
* cached policy would keep deciding with the mode the user just left.
|
|
85
|
+
*/
|
|
86
|
+
autonomyPolicy(): MemoryAutonomyPolicy;
|
|
87
|
+
/** The counters, read-only. The state object never leaves this class (RV-P2-1). */
|
|
88
|
+
autonomyState(): Readonly<MemoryAutonomyState>;
|
|
89
|
+
/** Decide one write. Pure: the policy and the counters go in, the verdict comes out (spec 6.2). */
|
|
90
|
+
decide(intent: MemoryWriteIntent): MemoryWriteDecision;
|
|
91
|
+
/** Record an applied write (allow, or an approved confirm): both budgets advance. */
|
|
92
|
+
noteApplied(decision: MemoryWriteDecision, intent: MemoryWriteIntent, applied: number): void;
|
|
93
|
+
/** Record a decline. Two of them in one turn stop every further write (D-4). */
|
|
94
|
+
noteDeclined(decision: MemoryWriteDecision): void;
|
|
95
|
+
/**
|
|
96
|
+
* Start of a real user turn: clear the per-turn counters and, once per process, prune the journal.
|
|
97
|
+
*
|
|
98
|
+
* CALLED FROM `prepareUserTurn`'s non-steering branch ONLY (spec 5.3 / RV-P2-6): a steering turn
|
|
99
|
+
* is the same turn with one more sentence in it, and treating it as new would hand the model a
|
|
100
|
+
* fresh batch of three automatic writes for saying "also, check the tests".
|
|
101
|
+
*/
|
|
102
|
+
beginTurn(): void;
|
|
103
|
+
/** A fresh batch id (`mbt_` + 8 hex) for one tool call. */
|
|
104
|
+
newBatchId(): string;
|
|
105
|
+
/** Append one row to the write ledger. Failures are logged there, never raised here. */
|
|
106
|
+
journalAppend(entry: Omit<MemoryJournalEntry, 'v' | 'at'>): void;
|
|
107
|
+
/** Recent ledger rows for both scopes, newest first (the activity page and `/memory activity`). */
|
|
108
|
+
activity(limit?: number): MemoryJournalEntry[];
|
|
109
|
+
/** Undo one agent batch: the user's recovery lever (D-6). `reason: 'user'` marks the ledger row. */
|
|
110
|
+
undoLast(batchId?: string): UndoOutcome;
|
|
111
|
+
/**
|
|
112
|
+
* `true` exactly once per process: the first automatic write is announced, the second is not.
|
|
113
|
+
* The controller owns the sentence; this only owns "has it been said".
|
|
114
|
+
*/
|
|
115
|
+
takeAutonomyNotice(): boolean;
|
|
116
|
+
/** The 24h write count as the journal remembers it, or 0 when it cannot be read. */
|
|
117
|
+
private seedUsedDay;
|
|
74
118
|
/** Apply a change to session state, deferring the prompt rewrite when a turn is running. */
|
|
75
119
|
private afterChange;
|
|
76
120
|
setOverride(id: string, state: MemoryMountOverride | 'reset'): MemoryChange;
|
|
@@ -92,6 +136,15 @@ export declare class MemoryService {
|
|
|
92
136
|
private planWith;
|
|
93
137
|
/** Plan + key for `config`, memoised on the key. */
|
|
94
138
|
private compute;
|
|
139
|
+
/**
|
|
140
|
+
* The hash of everything the `<memory>` block depends on, and nothing else (I-4).
|
|
141
|
+
*
|
|
142
|
+
* THE POLICY IS PART OF IT, ALL THREE PARTS (RV-P1-4). The two policy sentences in the block are
|
|
143
|
+
* only appended under `auto`, so `auto -> ask` changes the bytes; without the mode in this key
|
|
144
|
+
* `renderBlock` short-circuits on the old key and the model keeps being told it needs no
|
|
145
|
+
* approval after the user switched back to asking. The threshold and the protection switch are in
|
|
146
|
+
* the sentences themselves, so they are in the key too.
|
|
147
|
+
*/
|
|
95
148
|
private keyOf;
|
|
96
149
|
/**
|
|
97
150
|
* Re-read the directory (cached by mtime + size), drop overrides for notes that vanished,
|