@aragon-agent/cli 0.6.76 → 0.6.78
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/dist/account/config.d.ts +4 -1
- package/dist/account/config.js +14 -1
- package/dist/account/device-client.d.ts +2 -0
- package/dist/account/device-client.js +11 -5
- package/dist/account/login-flow.d.ts +1 -0
- package/dist/account/login-flow.js +11 -5
- package/dist/account/store.d.ts +5 -0
- package/dist/account/store.js +38 -0
- package/dist/agent/controller.js +4 -1
- package/dist/app/App.d.ts +0 -6
- package/dist/app/App.js +21 -2
- package/dist/cli.js +6 -0
- package/dist/cloud-sync/coordinator.d.ts +64 -0
- package/dist/cloud-sync/coordinator.js +294 -0
- package/dist/cloud-sync/gene-adapter.d.ts +2 -0
- package/dist/cloud-sync/gene-adapter.js +234 -0
- package/dist/cloud-sync/identity.d.ts +19 -0
- package/dist/cloud-sync/identity.js +311 -0
- package/dist/cloud-sync/lease.d.ts +9 -0
- package/dist/cloud-sync/lease.js +173 -0
- package/dist/cloud-sync/memory-adapter.d.ts +4 -0
- package/dist/cloud-sync/memory-adapter.js +107 -0
- package/dist/cloud-sync/project-bindings.d.ts +7 -0
- package/dist/cloud-sync/project-bindings.js +68 -0
- package/dist/cloud-sync/protocol.d.ts +65 -0
- package/dist/cloud-sync/protocol.js +193 -0
- package/dist/cloud-sync/reconcile.d.ts +14 -0
- package/dist/cloud-sync/reconcile.js +539 -0
- package/dist/cloud-sync/state.d.ts +117 -0
- package/dist/cloud-sync/state.js +208 -0
- package/dist/cloud-sync/transport.d.ts +28 -0
- package/dist/cloud-sync/transport.js +134 -0
- package/dist/commands/account-command.d.ts +2 -1
- package/dist/commands/account-command.js +54 -7
- package/dist/config/app-paths.d.ts +2 -2
- package/dist/config/app-paths.js +4 -4
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +17 -0
- package/dist/gene/commit-exec.js +5 -1
- package/dist/gene/commit-prepare.js +3 -1
- package/dist/gene/commit-types.d.ts +2 -0
- package/dist/gene/manager-actions.js +29 -1
- package/dist/gene/manager-library.js +5 -4
- package/dist/gene/paths.d.ts +4 -3
- package/dist/gene/paths.js +9 -2
- package/dist/gene/store.d.ts +2 -0
- package/dist/gene/store.js +2 -1
- package/dist/gene/transfer.d.ts +2 -0
- package/dist/gene/transfer.js +2 -1
- package/dist/gene/version-service.d.ts +4 -0
- package/dist/gene/version-service.js +72 -8
- package/dist/gene/wiring.d.ts +9 -0
- package/dist/gene/wiring.js +1 -1
- package/dist/host/cloud-sync.d.ts +21 -0
- package/dist/host/cloud-sync.js +49 -0
- package/dist/memory/format.d.ts +2 -0
- package/dist/memory/format.js +11 -2
- package/dist/memory/paths.d.ts +5 -3
- package/dist/memory/paths.js +15 -6
- package/dist/memory/service.d.ts +2 -0
- package/dist/memory/service.js +43 -6
- package/dist/memory/store.d.ts +11 -1
- package/dist/memory/store.js +74 -9
- package/package.json +3 -3
package/dist/memory/service.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* (`prepareUserTurn`), which is also where edits made by another process or by hand are
|
|
22
22
|
* picked up - there is no watcher to rely on.
|
|
23
23
|
*/
|
|
24
|
+
import { captureLibraryIdentity, assertLibraryIdentity, withLibraryWriteSync } from '../cloud-sync/identity.js';
|
|
24
25
|
import { createHash } from 'node:crypto';
|
|
25
26
|
import { CHARS_PER_TOKEN } from '@aragon-agent/core';
|
|
26
27
|
import { DEFAULT_MEMORY_CONFIG } from '@aragon-agent/tui/model/config/schema';
|
|
@@ -39,6 +40,7 @@ import { createNote, listTrash, moveNote, purgeExpiredTrash, readNote, restoreNo
|
|
|
39
40
|
const MAX_RESTORED_OVERRIDES = 400;
|
|
40
41
|
export class MemoryService {
|
|
41
42
|
deps;
|
|
43
|
+
libraryIdentity = captureLibraryIdentity();
|
|
42
44
|
session = { autoload: null, overrides: {}, agentWrites: null };
|
|
43
45
|
notes = [];
|
|
44
46
|
project;
|
|
@@ -69,7 +71,7 @@ export class MemoryService {
|
|
|
69
71
|
if (deps.purgeTrashOnStart !== false) {
|
|
70
72
|
const timer = setTimeout(() => {
|
|
71
73
|
try {
|
|
72
|
-
purgeExpiredTrash(this.now());
|
|
74
|
+
withLibraryWriteSync(this.libraryIdentity, () => purgeExpiredTrash(this.now()));
|
|
73
75
|
}
|
|
74
76
|
catch {
|
|
75
77
|
// Best effort; the sweep is housekeeping only.
|
|
@@ -84,24 +86,32 @@ export class MemoryService {
|
|
|
84
86
|
}
|
|
85
87
|
/** Both scopes the current workspace can see, project first. */
|
|
86
88
|
targets() {
|
|
87
|
-
|
|
89
|
+
if (!this.isCurrentLibrary())
|
|
90
|
+
return [];
|
|
91
|
+
return [this.targetOf('project'), this.targetOf('global')];
|
|
88
92
|
}
|
|
89
93
|
targetOf(scope) {
|
|
90
94
|
return scope === 'global'
|
|
91
|
-
? { scope: 'global' }
|
|
92
|
-
: { scope: 'project', projectKey: this.project.key };
|
|
95
|
+
? { scope: 'global', libraryIdentity: this.libraryIdentity }
|
|
96
|
+
: { scope: 'project', projectKey: this.project.key, libraryIdentity: this.libraryIdentity };
|
|
93
97
|
}
|
|
94
98
|
// ---- reading -----------------------------------------------------------
|
|
95
99
|
/** The notes as of the last sync (full text). */
|
|
96
100
|
getNotes() {
|
|
101
|
+
if (!this.isCurrentLibrary())
|
|
102
|
+
return [];
|
|
97
103
|
return this.notes;
|
|
98
104
|
}
|
|
99
105
|
/** `true` if any note exists at all, enabled or not. */
|
|
100
106
|
hasNotes() {
|
|
107
|
+
if (!this.isCurrentLibrary())
|
|
108
|
+
return false;
|
|
101
109
|
return this.notes.length > 0;
|
|
102
110
|
}
|
|
103
111
|
/** Fresh read of one note by id (CAS source), resolving which scope owns it. */
|
|
104
112
|
getNote(id) {
|
|
113
|
+
if (!this.isCurrentLibrary())
|
|
114
|
+
return { ok: false, code: 'disabled' };
|
|
105
115
|
if (!isValidNoteId(id))
|
|
106
116
|
return { ok: false, code: 'invalid_id' };
|
|
107
117
|
const known = this.notes.find((note) => note.id === id);
|
|
@@ -115,6 +125,8 @@ export class MemoryService {
|
|
|
115
125
|
}
|
|
116
126
|
/** Rows for a list: catalog fields plus where each stands in the context. */
|
|
117
127
|
listRows(query) {
|
|
128
|
+
if (!this.isCurrentLibrary())
|
|
129
|
+
return [];
|
|
118
130
|
const computed = this.compute(this.deps.getConfig());
|
|
119
131
|
const plan = computed.plan;
|
|
120
132
|
const inCatalog = new Set(plan.catalog.map((row) => row.id));
|
|
@@ -206,6 +218,7 @@ export class MemoryService {
|
|
|
206
218
|
}
|
|
207
219
|
/** Append one row to the write ledger. Failures are logged there, never raised here. */
|
|
208
220
|
journalAppend(entry) {
|
|
221
|
+
assertLibraryIdentity(this.libraryIdentity);
|
|
209
222
|
appendJournalEntry(this.targetOf(entry.scope), { v: 1, at: this.now(), ...entry });
|
|
210
223
|
}
|
|
211
224
|
/** Recent ledger rows for both scopes, newest first (the activity page and `/memory activity`). */
|
|
@@ -320,6 +333,8 @@ export class MemoryService {
|
|
|
320
333
|
// ---- prompt integration ------------------------------------------------
|
|
321
334
|
/** Hash of everything the block depends on, and nothing else (I-4). */
|
|
322
335
|
promptKey(config) {
|
|
336
|
+
if (!this.isCurrentLibrary())
|
|
337
|
+
return 'unavailable';
|
|
323
338
|
return this.compute(config).key;
|
|
324
339
|
}
|
|
325
340
|
/**
|
|
@@ -330,6 +345,8 @@ export class MemoryService {
|
|
|
330
345
|
* smaller one.
|
|
331
346
|
*/
|
|
332
347
|
renderBlock(config) {
|
|
348
|
+
if (!this.isCurrentLibrary())
|
|
349
|
+
return '';
|
|
333
350
|
const cfg = config.memory ?? this.memoryConfig;
|
|
334
351
|
if (!cfg.enabled)
|
|
335
352
|
return '';
|
|
@@ -455,8 +472,10 @@ export class MemoryService {
|
|
|
455
472
|
* a read must not touch session state - so this returns the list and changes nothing.
|
|
456
473
|
*/
|
|
457
474
|
scanFresh() {
|
|
458
|
-
|
|
459
|
-
|
|
475
|
+
if (!this.isCurrentLibrary())
|
|
476
|
+
return [];
|
|
477
|
+
const project = scanScope(this.targetOf('project')).notes;
|
|
478
|
+
const global = scanScope(this.targetOf('global')).notes;
|
|
460
479
|
const taken = new Set(project.map((note) => note.id));
|
|
461
480
|
// An id lives in ONE scope: overrides are keyed by id alone, so a global note that
|
|
462
481
|
// shares an id with a project note (possible only for hand-placed files) is ignored.
|
|
@@ -523,6 +542,8 @@ export class MemoryService {
|
|
|
523
542
|
* UI-side write path (I-1): there is no autosave and no draft on disk.
|
|
524
543
|
*/
|
|
525
544
|
saveNote(draft, options = {}) {
|
|
545
|
+
if (!this.isCurrentLibrary())
|
|
546
|
+
return { ok: false, code: 'disabled' };
|
|
526
547
|
const opts = this.writeOptions('user', options.confirmSecret);
|
|
527
548
|
let result;
|
|
528
549
|
if (options.id === undefined) {
|
|
@@ -636,6 +657,8 @@ export class MemoryService {
|
|
|
636
657
|
// ---- view --------------------------------------------------------------
|
|
637
658
|
/** The whole session view. Always delivered whole: a missed update heals on the next. */
|
|
638
659
|
getView() {
|
|
660
|
+
if (!this.isCurrentLibrary())
|
|
661
|
+
return UNAVAILABLE_VIEW;
|
|
639
662
|
const config = this.deps.getConfig();
|
|
640
663
|
const cfg = config.memory ?? this.memoryConfig;
|
|
641
664
|
if (!cfg.enabled)
|
|
@@ -701,6 +724,20 @@ export class MemoryService {
|
|
|
701
724
|
}
|
|
702
725
|
}
|
|
703
726
|
}
|
|
727
|
+
isCurrentLibrary() {
|
|
728
|
+
try {
|
|
729
|
+
assertLibraryIdentity(this.libraryIdentity);
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
// A previous session may finish rendering while its account is being switched.
|
|
734
|
+
this.notes = [];
|
|
735
|
+
this.computed = null;
|
|
736
|
+
this.block = '';
|
|
737
|
+
this.blockKey = null;
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
704
741
|
now() {
|
|
705
742
|
return this.deps.now?.() ?? Date.now();
|
|
706
743
|
}
|
package/dist/memory/store.d.ts
CHANGED
|
@@ -91,6 +91,12 @@ export interface MemoryWriteOptions {
|
|
|
91
91
|
export declare function mkdirPrivate(dir: string): void;
|
|
92
92
|
/** Create a note. Mints the id; never overwrites an existing file. */
|
|
93
93
|
export declare function createNote(target: MemoryTarget, input: MemoryDraftInput, opts: MemoryWriteOptions): MemoryResult<MemoryNote>;
|
|
94
|
+
/** Import a validated protocol ID without granting the author local write authority. */
|
|
95
|
+
export declare function importNote(target: MemoryTarget, input: MemoryDraftInput, record: {
|
|
96
|
+
id: string;
|
|
97
|
+
creator: MemoryNoteSource;
|
|
98
|
+
knownSecrets?: readonly string[];
|
|
99
|
+
}): MemoryResult<MemoryNote>;
|
|
94
100
|
/**
|
|
95
101
|
* Replace a note's content, but only if it is still the version the caller saw (I-11).
|
|
96
102
|
*
|
|
@@ -111,7 +117,11 @@ export declare function updateNote(target: MemoryTarget, id: string, input: Memo
|
|
|
111
117
|
*/
|
|
112
118
|
export declare function restoreVersion(target: MemoryTarget, id: string, backupFile: string, expectedRev: string, opts: MemoryWriteOptions): MemoryResult<MemoryNote>;
|
|
113
119
|
/** Move a note to the trash (30 days), if it is still the version the caller saw. */
|
|
114
|
-
export declare function trashNote(target: MemoryTarget, id: string, expectedRev: string, now?: number
|
|
120
|
+
export declare function trashNote(target: MemoryTarget, id: string, expectedRev: string, now?: number, movedTo?: {
|
|
121
|
+
itemId: string;
|
|
122
|
+
projectKey?: string;
|
|
123
|
+
contentHash: string;
|
|
124
|
+
}): MemoryResult<{
|
|
115
125
|
trashId: string;
|
|
116
126
|
}>;
|
|
117
127
|
/**
|
package/dist/memory/store.js
CHANGED
|
@@ -27,14 +27,17 @@
|
|
|
27
27
|
* had written - exactly once, silently, with no test to notice.
|
|
28
28
|
*/
|
|
29
29
|
import { chmodSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
30
|
+
import { createHash } from 'node:crypto';
|
|
30
31
|
import { join } from 'node:path';
|
|
31
32
|
import process from 'node:process';
|
|
32
33
|
import { MEMORY_LIMITS } from '@aragon-agent/tui/model/memory/limits';
|
|
33
34
|
import { deriveMemorySummary, validateMemoryDraft, } from '@aragon-agent/tui/model/memory/validate';
|
|
35
|
+
import { contentHash } from '../cloud-sync/protocol.js';
|
|
36
|
+
import { captureLibraryIdentity, withLibraryWriteSync } from '../cloud-sync/identity.js';
|
|
37
|
+
import { beginLibraryDeletion, isCloudDeleted, wakeLibrarySync } from '../cloud-sync/state.js';
|
|
34
38
|
import { getLogger } from '../logging/logger.js';
|
|
35
|
-
import { getMemoryDir } from '../config/app-paths.js';
|
|
36
39
|
import { computeRev, parseNoteBytes, serializeNote, MEMORY_FILE_SCHEMA, } from './format.js';
|
|
37
|
-
import { isInside, isValidNoteId, isValidProjectKey, mintNoteId, noteFile, projectMetaFile, scopeDir, stemOfNoteFile, trashDir, versionsDir, } from './paths.js';
|
|
40
|
+
import { getMemoryDir, isInside, isValidNoteId, isValidProjectKey, mintNoteId, noteFile, projectMetaFile, scopeDir, stemOfNoteFile, trashDir, versionsDir, } from './paths.js';
|
|
38
41
|
import { looksLikeSecret } from './secrets.js';
|
|
39
42
|
function realSleep(ms) {
|
|
40
43
|
try {
|
|
@@ -222,6 +225,16 @@ export function readNote(target, id) {
|
|
|
222
225
|
function fail(code, extra) {
|
|
223
226
|
return { ok: false, code, ...extra };
|
|
224
227
|
}
|
|
228
|
+
/** Keep the store's value-based failure contract when another writer or account owns the home. */
|
|
229
|
+
function withNoteWrite(target, write) {
|
|
230
|
+
try {
|
|
231
|
+
return withLibraryWriteSync(target.libraryIdentity ?? captureLibraryIdentity(), write);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
log('write_refused', { scope: target.scope, code: 'write_failed' });
|
|
235
|
+
return fail('write_failed');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
225
238
|
function normaliseTitle(title) {
|
|
226
239
|
return title.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
227
240
|
}
|
|
@@ -368,7 +381,7 @@ function touchProjectMeta(target, info, now) {
|
|
|
368
381
|
function buildNoteBytes(input, base) {
|
|
369
382
|
return serializeNote({
|
|
370
383
|
title: input.title,
|
|
371
|
-
summary: input.summary
|
|
384
|
+
summary: input.summary,
|
|
372
385
|
body: input.body,
|
|
373
386
|
tags: input.tags,
|
|
374
387
|
load: input.load,
|
|
@@ -389,6 +402,18 @@ function reparse(file, id, scope, text, mtimeMs) {
|
|
|
389
402
|
}
|
|
390
403
|
/** Create a note. Mints the id; never overwrites an existing file. */
|
|
391
404
|
export function createNote(target, input, opts) {
|
|
405
|
+
return createWithIdentity(target, input, opts);
|
|
406
|
+
}
|
|
407
|
+
/** Import a validated protocol ID without granting the author local write authority. */
|
|
408
|
+
export function importNote(target, input, record) {
|
|
409
|
+
if (!isValidNoteId(record.id))
|
|
410
|
+
return fail('invalid_id');
|
|
411
|
+
return createWithIdentity(target, input, { source: 'imported', knownSecrets: record.knownSecrets ?? [] }, record);
|
|
412
|
+
}
|
|
413
|
+
function createWithIdentity(target, input, opts, record) {
|
|
414
|
+
return withNoteWrite(target, () => createWithIdentityLocked(target, input, opts, record));
|
|
415
|
+
}
|
|
416
|
+
function createWithIdentityLocked(target, input, opts, record) {
|
|
392
417
|
const dir = scopeDir(target);
|
|
393
418
|
if (dir === null)
|
|
394
419
|
return fail('invalid_id');
|
|
@@ -409,15 +434,17 @@ export function createNote(target, input, opts) {
|
|
|
409
434
|
}
|
|
410
435
|
const now = opts.now ?? Date.now();
|
|
411
436
|
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
412
|
-
const id = mintNoteId();
|
|
437
|
+
const id = record?.id ?? mintNoteId();
|
|
413
438
|
const file = noteFile(target, id);
|
|
439
|
+
if (record && file && existsSync(file))
|
|
440
|
+
return fail('conflict');
|
|
414
441
|
if (file === null || existsSync(file))
|
|
415
442
|
continue;
|
|
416
443
|
const text = buildNoteBytes(input, {
|
|
417
444
|
createdAt: now,
|
|
418
445
|
updatedAt: now,
|
|
419
446
|
schema: MEMORY_FILE_SCHEMA,
|
|
420
|
-
source: opts.source,
|
|
447
|
+
source: record?.creator ?? opts.source,
|
|
421
448
|
});
|
|
422
449
|
const outcome = writeFileAtomic(file, text, true);
|
|
423
450
|
if (outcome === 'exists')
|
|
@@ -427,6 +454,7 @@ export function createNote(target, input, opts) {
|
|
|
427
454
|
return fail('write_failed');
|
|
428
455
|
}
|
|
429
456
|
revision += 1;
|
|
457
|
+
wakeLibrarySync();
|
|
430
458
|
touchProjectMeta(target, opts.projectInfo, now);
|
|
431
459
|
const note = reparse(file, id, target.scope, text, now);
|
|
432
460
|
log('note_created', { id, scope: target.scope, op: 'create', rev: note.rev, chars: note.bodyChars });
|
|
@@ -438,6 +466,7 @@ function sameContent(note, input) {
|
|
|
438
466
|
const summary = input.summary.length > 0 ? input.summary : deriveMemorySummary(input.body);
|
|
439
467
|
return (note.title === input.title &&
|
|
440
468
|
note.summary === summary &&
|
|
469
|
+
note.summaryDerived === (input.summary.length === 0) &&
|
|
441
470
|
note.body.replace(/\s+$/, '') === input.body.replace(/\s+$/, '') &&
|
|
442
471
|
note.load === input.load &&
|
|
443
472
|
note.enabled === input.enabled &&
|
|
@@ -453,6 +482,9 @@ function sameContent(note, input) {
|
|
|
453
482
|
* nothing.
|
|
454
483
|
*/
|
|
455
484
|
export function updateNote(target, id, input, expectedRev, opts) {
|
|
485
|
+
return withNoteWrite(target, () => updateNoteLocked(target, id, input, expectedRev, opts));
|
|
486
|
+
}
|
|
487
|
+
function updateNoteLocked(target, id, input, expectedRev, opts) {
|
|
456
488
|
const file = noteFile(target, id);
|
|
457
489
|
if (file === null)
|
|
458
490
|
return fail('invalid_id');
|
|
@@ -492,6 +524,7 @@ export function updateNote(target, id, input, expectedRev, opts) {
|
|
|
492
524
|
return fail('write_failed');
|
|
493
525
|
}
|
|
494
526
|
revision += 1;
|
|
527
|
+
wakeLibrarySync();
|
|
495
528
|
touchProjectMeta(target, opts.projectInfo, now);
|
|
496
529
|
const note = reparse(file, id, target.scope, text, now);
|
|
497
530
|
log('note_updated', { id, scope: target.scope, op: 'update', rev: note.rev, chars: note.bodyChars });
|
|
@@ -538,7 +571,7 @@ export function restoreVersion(target, id, backupFile, expectedRev, opts) {
|
|
|
538
571
|
return fail('not_found');
|
|
539
572
|
const draft = {
|
|
540
573
|
title: note.title,
|
|
541
|
-
summary: note.summary,
|
|
574
|
+
summary: note.summaryDerived ? '' : note.summary,
|
|
542
575
|
body: note.body,
|
|
543
576
|
tags: note.tags,
|
|
544
577
|
load: note.load,
|
|
@@ -548,7 +581,10 @@ export function restoreVersion(target, id, backupFile, expectedRev, opts) {
|
|
|
548
581
|
return updateNote(target, id, draft, expectedRev, opts);
|
|
549
582
|
}
|
|
550
583
|
/** Move a note to the trash (30 days), if it is still the version the caller saw. */
|
|
551
|
-
export function trashNote(target, id, expectedRev, now = Date.now()) {
|
|
584
|
+
export function trashNote(target, id, expectedRev, now = Date.now(), movedTo) {
|
|
585
|
+
return withNoteWrite(target, () => trashNoteLocked(target, id, expectedRev, now, movedTo));
|
|
586
|
+
}
|
|
587
|
+
function trashNoteLocked(target, id, expectedRev, now = Date.now(), movedTo) {
|
|
552
588
|
const file = noteFile(target, id);
|
|
553
589
|
const dir = trashDir(target);
|
|
554
590
|
if (file === null || dir === null)
|
|
@@ -558,6 +594,13 @@ export function trashNote(target, id, expectedRev, now = Date.now()) {
|
|
|
558
594
|
return fail(current.code);
|
|
559
595
|
if (current.value.rev !== expectedRev)
|
|
560
596
|
return fail('conflict', { current: current.value });
|
|
597
|
+
const confirm = beginLibraryDeletion({
|
|
598
|
+
kind: 'memory', itemId: id, reason: 'delete', sourcePath: file,
|
|
599
|
+
verify: { path: join(dir, id + '.' + now + '.md'),
|
|
600
|
+
sha256: createHash('sha256').update(readFileSync(file)).digest('hex') },
|
|
601
|
+
...(target.scope === 'project' ? { projectKey: target.projectKey } : {}),
|
|
602
|
+
...(movedTo ? { target: movedTo } : {}),
|
|
603
|
+
});
|
|
561
604
|
try {
|
|
562
605
|
mkdirPrivate(dir);
|
|
563
606
|
renameWithRetry(file, join(dir, `${id}.${now}.md`));
|
|
@@ -566,8 +609,10 @@ export function trashNote(target, id, expectedRev, now = Date.now()) {
|
|
|
566
609
|
log('write_refused', { op: 'delete', id, scope: target.scope, code: 'write_failed' });
|
|
567
610
|
return fail('write_failed');
|
|
568
611
|
}
|
|
612
|
+
confirm();
|
|
569
613
|
cache.delete(file);
|
|
570
614
|
revision += 1;
|
|
615
|
+
wakeLibrarySync();
|
|
571
616
|
log('note_trashed', { id, scope: target.scope, op: 'delete', rev: current.value.rev });
|
|
572
617
|
return { ok: true, value: { trashId: `${id}.${now}` } };
|
|
573
618
|
}
|
|
@@ -583,6 +628,9 @@ function parseTrashId(trashId) {
|
|
|
583
628
|
* (never over the live note) and the caller is told which.
|
|
584
629
|
*/
|
|
585
630
|
export function restoreNote(target, trashId) {
|
|
631
|
+
return withNoteWrite(target, () => restoreNoteLocked(target, trashId));
|
|
632
|
+
}
|
|
633
|
+
function restoreNoteLocked(target, trashId) {
|
|
586
634
|
const parsed = parseTrashId(trashId);
|
|
587
635
|
const dir = trashDir(target);
|
|
588
636
|
const live = scopeDir(target);
|
|
@@ -594,7 +642,9 @@ export function restoreNote(target, trashId) {
|
|
|
594
642
|
if (scanScope(target).notes.length >= MEMORY_LIMITS.maxNotesPerScope)
|
|
595
643
|
return fail('limit_reached');
|
|
596
644
|
let id = parsed.id;
|
|
597
|
-
|
|
645
|
+
const cloudDeleted = isCloudDeleted({ kind: 'memory', itemId: id,
|
|
646
|
+
...(target.scope === 'project' ? { projectKey: target.projectKey } : {}) });
|
|
647
|
+
if (cloudDeleted || existsSync(join(live, `${id}.md`))) {
|
|
598
648
|
id = mintNoteId();
|
|
599
649
|
for (let attempt = 0; attempt < 5 && existsSync(join(live, `${id}.md`)); attempt += 1)
|
|
600
650
|
id = mintNoteId();
|
|
@@ -611,6 +661,7 @@ export function restoreNote(target, trashId) {
|
|
|
611
661
|
}
|
|
612
662
|
cache.delete(to);
|
|
613
663
|
revision += 1;
|
|
664
|
+
wakeLibrarySync();
|
|
614
665
|
log('note_restored', { id, scope: target.scope, op: 'restore' });
|
|
615
666
|
return { ok: true, value: { id } };
|
|
616
667
|
}
|
|
@@ -643,6 +694,9 @@ export function listTrash(target) {
|
|
|
643
694
|
}
|
|
644
695
|
/** Delete one trashed note for good. */
|
|
645
696
|
export function purgeTrash(target, trashId) {
|
|
697
|
+
return withNoteWrite(target, () => purgeTrashLocked(target, trashId));
|
|
698
|
+
}
|
|
699
|
+
function purgeTrashLocked(target, trashId) {
|
|
646
700
|
const parsed = parseTrashId(trashId);
|
|
647
701
|
const dir = trashDir(target);
|
|
648
702
|
if (parsed === null || dir === null)
|
|
@@ -698,6 +752,9 @@ export function purgeExpiredTrash(now = Date.now()) {
|
|
|
698
752
|
* second step fails both exist (and the caller is told) - duplicate, never lost.
|
|
699
753
|
*/
|
|
700
754
|
export function moveNote(from, id, to, expectedRev, opts) {
|
|
755
|
+
return withNoteWrite(from, () => moveNoteLocked(from, id, to, expectedRev, opts));
|
|
756
|
+
}
|
|
757
|
+
function moveNoteLocked(from, id, to, expectedRev, opts) {
|
|
701
758
|
const current = readNote(from, id);
|
|
702
759
|
if (!current.ok)
|
|
703
760
|
return fail(current.code);
|
|
@@ -715,7 +772,15 @@ export function moveNote(from, id, to, expectedRev, opts) {
|
|
|
715
772
|
}, { ...opts, confirmSecret: true });
|
|
716
773
|
if (!created.ok)
|
|
717
774
|
return created;
|
|
718
|
-
const trashed = trashNote(from, id, expectedRev, opts.now
|
|
775
|
+
const trashed = trashNote(from, id, expectedRev, opts.now, {
|
|
776
|
+
itemId: created.value.id,
|
|
777
|
+
contentHash: contentHash({
|
|
778
|
+
title: created.value.title, summary: created.value.summaryDerived ? '' : created.value.summary,
|
|
779
|
+
body: created.value.body, tags: created.value.tags, load: created.value.load,
|
|
780
|
+
enabled: created.value.enabled, source: created.value.source,
|
|
781
|
+
}),
|
|
782
|
+
...(to.scope === 'project' ? { projectKey: to.projectKey } : {}),
|
|
783
|
+
});
|
|
719
784
|
if (!trashed.ok)
|
|
720
785
|
return fail('write_failed', { current: created.value });
|
|
721
786
|
return created;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aragon-agent/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.78",
|
|
4
4
|
"description": "AragonAgent CLI — a Claude-Code / Codex-style interactive terminal UI (TUI) on top of the @aragon-agent/core engine. Installable and runnable via npm / npx.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "AragonAgent contributors",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"prepublishOnly": "npm run build"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@aragon-agent/core": "^0.2.
|
|
62
|
-
"@aragon-agent/tui": "0.0.
|
|
61
|
+
"@aragon-agent/core": "^0.2.90",
|
|
62
|
+
"@aragon-agent/tui": "0.0.31",
|
|
63
63
|
"commander": "^12.1.0",
|
|
64
64
|
"dotenv": "^16.6.1",
|
|
65
65
|
"env-paths": "^3.0.0",
|