@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.
Files changed (64) hide show
  1. package/dist/account/config.d.ts +4 -1
  2. package/dist/account/config.js +14 -1
  3. package/dist/account/device-client.d.ts +2 -0
  4. package/dist/account/device-client.js +11 -5
  5. package/dist/account/login-flow.d.ts +1 -0
  6. package/dist/account/login-flow.js +11 -5
  7. package/dist/account/store.d.ts +5 -0
  8. package/dist/account/store.js +38 -0
  9. package/dist/agent/controller.js +4 -1
  10. package/dist/app/App.d.ts +0 -6
  11. package/dist/app/App.js +21 -2
  12. package/dist/cli.js +6 -0
  13. package/dist/cloud-sync/coordinator.d.ts +64 -0
  14. package/dist/cloud-sync/coordinator.js +294 -0
  15. package/dist/cloud-sync/gene-adapter.d.ts +2 -0
  16. package/dist/cloud-sync/gene-adapter.js +234 -0
  17. package/dist/cloud-sync/identity.d.ts +19 -0
  18. package/dist/cloud-sync/identity.js +311 -0
  19. package/dist/cloud-sync/lease.d.ts +9 -0
  20. package/dist/cloud-sync/lease.js +173 -0
  21. package/dist/cloud-sync/memory-adapter.d.ts +4 -0
  22. package/dist/cloud-sync/memory-adapter.js +107 -0
  23. package/dist/cloud-sync/project-bindings.d.ts +7 -0
  24. package/dist/cloud-sync/project-bindings.js +68 -0
  25. package/dist/cloud-sync/protocol.d.ts +65 -0
  26. package/dist/cloud-sync/protocol.js +193 -0
  27. package/dist/cloud-sync/reconcile.d.ts +14 -0
  28. package/dist/cloud-sync/reconcile.js +539 -0
  29. package/dist/cloud-sync/state.d.ts +117 -0
  30. package/dist/cloud-sync/state.js +208 -0
  31. package/dist/cloud-sync/transport.d.ts +28 -0
  32. package/dist/cloud-sync/transport.js +134 -0
  33. package/dist/commands/account-command.d.ts +2 -1
  34. package/dist/commands/account-command.js +54 -7
  35. package/dist/config/app-paths.d.ts +2 -2
  36. package/dist/config/app-paths.js +4 -4
  37. package/dist/config/env.d.ts +2 -0
  38. package/dist/config/env.js +17 -0
  39. package/dist/gene/commit-exec.js +5 -1
  40. package/dist/gene/commit-prepare.js +3 -1
  41. package/dist/gene/commit-types.d.ts +2 -0
  42. package/dist/gene/manager-actions.js +29 -1
  43. package/dist/gene/manager-library.js +5 -4
  44. package/dist/gene/paths.d.ts +4 -3
  45. package/dist/gene/paths.js +9 -2
  46. package/dist/gene/store.d.ts +2 -0
  47. package/dist/gene/store.js +2 -1
  48. package/dist/gene/transfer.d.ts +2 -0
  49. package/dist/gene/transfer.js +2 -1
  50. package/dist/gene/version-service.d.ts +4 -0
  51. package/dist/gene/version-service.js +72 -8
  52. package/dist/gene/wiring.d.ts +9 -0
  53. package/dist/gene/wiring.js +1 -1
  54. package/dist/host/cloud-sync.d.ts +21 -0
  55. package/dist/host/cloud-sync.js +49 -0
  56. package/dist/memory/format.d.ts +2 -0
  57. package/dist/memory/format.js +11 -2
  58. package/dist/memory/paths.d.ts +5 -3
  59. package/dist/memory/paths.js +15 -6
  60. package/dist/memory/service.d.ts +2 -0
  61. package/dist/memory/service.js +43 -6
  62. package/dist/memory/store.d.ts +11 -1
  63. package/dist/memory/store.js +74 -9
  64. package/package.json +3 -3
@@ -0,0 +1,65 @@
1
+ export type LibraryKind = 'memory' | 'gene';
2
+ export type Content = Record<string, unknown>;
3
+ export interface LibraryKey {
4
+ kind: LibraryKind;
5
+ space: string;
6
+ itemId: string;
7
+ }
8
+ export interface LibraryItem extends LibraryKey {
9
+ rev: number;
10
+ seq: number;
11
+ updatedAt: number;
12
+ deleted: boolean;
13
+ content?: Content;
14
+ deleteReason?: string;
15
+ }
16
+ export interface Mutation extends LibraryKey {
17
+ schema: 1;
18
+ epoch: string;
19
+ opId: string;
20
+ baseRev: number;
21
+ op: 'create' | 'update' | 'delete';
22
+ content?: Content;
23
+ reason?: string;
24
+ }
25
+ export interface LocalEntry {
26
+ itemId: string;
27
+ content: Content;
28
+ blocked?: string;
29
+ localOnly?: boolean;
30
+ }
31
+ export interface AdapterScope {
32
+ space: string;
33
+ dataRoot: string;
34
+ projectKey?: string;
35
+ projectRoot?: string;
36
+ knownSecrets?: readonly string[];
37
+ }
38
+ export interface LibraryAdapter {
39
+ list?(scope: AdapterScope): Promise<string[]>;
40
+ read?(scope: AdapterScope, itemId: string): Promise<LocalEntry | null>;
41
+ scan(scope: AdapterScope): Promise<LocalEntry[]>;
42
+ apply(scope: AdapterScope, item: LibraryItem, expectedHash: string | null): Promise<void>;
43
+ copy(scope: AdapterScope, content: Content): Promise<string>;
44
+ }
45
+ export interface ChangePage {
46
+ schema: 1;
47
+ epoch: string;
48
+ fence: number;
49
+ nextAfter: number;
50
+ hasMore: boolean;
51
+ items: LibraryItem[];
52
+ }
53
+ export declare const UUID: RegExp;
54
+ export declare const isRecord: (v: unknown) => v is Content;
55
+ export declare const isSpace: (v: unknown) => v is string;
56
+ export declare const counter: (n: unknown) => n is number;
57
+ export declare const itemKey: (item: LibraryKey) => string;
58
+ export declare const conflictRef: (key: LibraryKey) => string;
59
+ export declare const contentHash: (content: Content) => string;
60
+ export declare const isKey: (v: Content) => boolean;
61
+ export declare function checkContent(key: LibraryKey, content: unknown, known?: readonly string[]): string | null;
62
+ export declare function parseItem(v: unknown): LibraryItem;
63
+ export declare function parsePage(v: unknown, after: number): ChangePage;
64
+ /** Revalidate queued operations before releasing a credential or uploading their content. */
65
+ export declare function validateMutation(input: unknown): input is Mutation;
@@ -0,0 +1,193 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { geneTypeOfId, isValidEvidenceRef, isValidGeneId } from '@aragon-agent/tui/model/gene/ids';
3
+ import { canonicalJson, validateGeneContent } from '@aragon-agent/tui/model/gene/validate';
4
+ import { getSecrets } from '@aragon-agent/tui/model/logging/secret-registry';
5
+ import { isValidNoteId } from '../memory/paths.js';
6
+ import { screenSecrets } from '../gene/secrets.js';
7
+ export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
8
+ export const isRecord = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
9
+ export const isSpace = (v) => typeof v === 'string' && (v === 'personal' || UUID.test(v));
10
+ export const counter = (n) => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0;
11
+ export const itemKey = (item) => [item.space, item.kind, item.itemId].join('/');
12
+ export const conflictRef = (key) => createHash('sha256').update(itemKey(key)).digest('hex').slice(0, 16);
13
+ export const contentHash = (content) => createHash('sha256').update(canonicalJson(content)).digest('hex');
14
+ export const isKey = (v) => isSpace(v.space) && (v.kind === 'memory' ? isValidNoteId(v.itemId) : v.kind === 'gene' && isValidGeneId(v.itemId));
15
+ function limited(s, min, max) {
16
+ return typeof s === 'string' && [...s].length <= max && (min === 0 || s.trim().length >= min);
17
+ }
18
+ function fields(v, names) {
19
+ return Object.keys(v).every(k => names.includes(k));
20
+ }
21
+ function checkMemory(c) {
22
+ return fields(c, ['title', 'summary', 'body', 'tags', 'load', 'enabled', 'source'])
23
+ && limited(c.title, 1, 80) && limited(c.summary, 0, 200) && limited(c.body, 1, 8000)
24
+ && Array.isArray(c.tags) && c.tags.length <= 6 && c.tags.every(t => limited(t, 1, 24))
25
+ && ['manual', 'auto', 'pinned'].includes(String(c.load)) && typeof c.enabled === 'boolean'
26
+ && ['user', 'hand', 'imported', 'agent'].includes(String(c.source));
27
+ }
28
+ function only(obj, allowed) {
29
+ return isRecord(obj) && fields(obj, allowed.split(' '));
30
+ }
31
+ function rows(value, allowed) {
32
+ return value === undefined || (Array.isArray(value) && value.every(entry => only(entry, allowed)));
33
+ }
34
+ function portableTool(p) {
35
+ if (!only(p, 'interfaceVersion implVersion exec inputSchema outputSchema requiredPermissions timeoutMs env examples envVarNames'))
36
+ return false;
37
+ if (!only(p.env, 'os commands nodeRange') || !isRecord(p.exec))
38
+ return false;
39
+ const exec = p.exec;
40
+ if (exec.kind === 'command' && !only(exec, 'kind argv'))
41
+ return false;
42
+ if (exec.kind === 'script' && !only(exec, 'kind interpreter evidence args'))
43
+ return false;
44
+ if (exec.kind === 'composite' && (!only(exec, 'kind steps') || !rows(exec.steps, 'tool args')))
45
+ return false;
46
+ if (!Array.isArray(p.examples))
47
+ return false;
48
+ return p.examples.every(e => only(e, 'name input expect fixtures') &&
49
+ only(e.expect, 'exitCode stdoutIncludes json') && rows(e.fixtures, 'path content'));
50
+ }
51
+ function portablePayload(type, value) {
52
+ if (!isRecord(value))
53
+ return false;
54
+ if (type === 'tool')
55
+ return portableTool(value);
56
+ if (type === 'skill')
57
+ return only(value, 'requires acceptance fallback') && rows(value.requires, 'id interface');
58
+ return only(value, 'kind claims resolves preference') && rows(value.claims, 'text evidence') &&
59
+ (value.preference === undefined || only(value.preference, 'horizon statedBy confirmed'));
60
+ }
61
+ function referenced(v) {
62
+ const refs = new Set(Array.isArray(v.evidence) ? v.evidence : []);
63
+ if (isRecord(v.payload)) {
64
+ if (Array.isArray(v.payload.claims))
65
+ for (const claim of v.payload.claims) {
66
+ if (isRecord(claim) && typeof claim.evidence === 'string' && claim.evidence)
67
+ refs.add(claim.evidence);
68
+ }
69
+ const exec = v.payload.exec;
70
+ if (isRecord(exec) && exec.kind === 'script' && typeof exec.evidence === 'string')
71
+ refs.add(exec.evidence);
72
+ }
73
+ return refs;
74
+ }
75
+ function checkGene(key, c) {
76
+ const type = geneTypeOfId(key.itemId);
77
+ if (!type || c.type !== type || !['standard', 'oversight'].includes(String(c.class)))
78
+ return false;
79
+ if (!fields(c, ['type', 'class', 'content', 'evidence', 'reason']) || !isRecord(c.content))
80
+ return false;
81
+ if (!Array.isArray(c.evidence) || !limited(c.reason, 0, 200))
82
+ return false;
83
+ const v = c.content;
84
+ if (!fields(v, [
85
+ 'name',
86
+ 'purpose',
87
+ 'trigger',
88
+ 'tags',
89
+ 'localeHints',
90
+ 'body',
91
+ 'applicability',
92
+ 'roles',
93
+ 'deps',
94
+ 'payload',
95
+ 'source',
96
+ 'evidence'
97
+ ]))
98
+ return false;
99
+ if (!isRecord(v.source) || !fields(v.source, ['origin', 'capturedAt']))
100
+ return false;
101
+ if (!only(v.applicability, 'os requiresTools fileGlobs projectKinds envStamp minWindowTokens') ||
102
+ !rows(v.deps, 'id interface kind') || !portablePayload(type, v.payload))
103
+ return false;
104
+ const refs = new Set();
105
+ for (const e of c.evidence) {
106
+ if (!isRecord(e) || !fields(e, ['ref', 'kind', 'text']) || !isValidEvidenceRef(e.ref) || refs.has(e.ref))
107
+ return false;
108
+ if (typeof e.text !== 'string' || !['user_statement', 'transcript', 'tool_output', 'file', 'symbol', 'url', 'case', 'impl'].includes(String(e.kind)))
109
+ return false;
110
+ if (e.kind === 'impl' ? Buffer.byteLength(e.text) > 16 * 1024 : [...e.text].length > 4000)
111
+ return false;
112
+ refs.add(e.ref);
113
+ }
114
+ const used = referenced(v);
115
+ if (!Array.isArray(v.evidence) || refs.size !== used.size || [...used].some(ref => !refs.has(ref)))
116
+ return false;
117
+ const scope = key.space === 'personal' ? { kind: 'user' } : { kind: 'project', key: 'project-12345678' };
118
+ // The domain recomputes the real risk alongside permission checks on import.
119
+ const projected = type === 'tool' && isRecord(v.payload)
120
+ ? { ...v, payload: { ...v.payload, risk: 'high' } } : v;
121
+ return validateGeneContent(type, projected, { scope, actor: 'user' }).ok;
122
+ }
123
+ function secretPath(v, path, known) {
124
+ if (typeof v === 'string')
125
+ return screenSecrets(v, known).hit ? path : null;
126
+ if (!v || typeof v !== 'object')
127
+ return null;
128
+ for (const [field, value] of Object.entries(v)) {
129
+ if (screenSecrets(field, known).hit)
130
+ return path;
131
+ const found = secretPath(value, path + '.' + field, known);
132
+ if (found)
133
+ return found;
134
+ }
135
+ return null;
136
+ }
137
+ export function checkContent(key, content, known = getSecrets()) {
138
+ if (screenSecrets(key.itemId, known).hit)
139
+ return 'itemId';
140
+ if (!isRecord(content) || Buffer.byteLength(JSON.stringify(content)) > 256 * 1024)
141
+ return 'content';
142
+ if (!(key.kind === 'memory' ? checkMemory(content) : checkGene(key, content)))
143
+ return 'content';
144
+ return secretPath(content, 'content', known);
145
+ }
146
+ export function parseItem(v) {
147
+ if (!isRecord(v) || !isKey(v) || !counter(v.rev) || !v.rev || !counter(v.seq) || !v.seq
148
+ || !counter(v.updatedAt) || typeof v.deleted !== 'boolean')
149
+ throw Error('Invalid library item');
150
+ const item = v;
151
+ if (item.deleted) {
152
+ const reasons = item.kind === 'memory' ? ['delete'] : ['delete', 'archive', 'revoke', 'forget'];
153
+ if (item.content !== undefined || !reasons.includes(String(item.deleteReason)))
154
+ throw Error('Invalid deletion');
155
+ }
156
+ else if (!isRecord(item.content))
157
+ throw Error('Missing library content');
158
+ return item;
159
+ }
160
+ export function parsePage(v, after) {
161
+ if (!isRecord(v) || v.schema !== 1 || typeof v.epoch !== 'string' || !UUID.test(v.epoch)
162
+ || !counter(v.fence) || !counter(v.nextAfter) || v.nextAfter > v.fence || after > v.nextAfter
163
+ || typeof v.hasMore !== 'boolean' || !Array.isArray(v.items) || v.items.length > 100)
164
+ throw Error('Invalid library page');
165
+ const items = v.items.map(parseItem);
166
+ let last = after;
167
+ for (const item of items) {
168
+ if (item.seq <= last || item.seq > v.nextAfter)
169
+ throw Error('Invalid library sequence');
170
+ last = item.seq;
171
+ }
172
+ if (v.hasMore ? !items.length || last !== v.nextAfter : v.nextAfter !== v.fence)
173
+ throw Error('Invalid library cursor');
174
+ return { schema: 1, epoch: v.epoch, fence: v.fence, nextAfter: v.nextAfter, hasMore: v.hasMore, items };
175
+ }
176
+ /** Revalidate queued operations before releasing a credential or uploading their content. */
177
+ export function validateMutation(input) {
178
+ if (!isRecord(input) || !isKey(input) || input.schema !== 1 || !counter(input.baseRev))
179
+ return false;
180
+ if (screenSecrets(String(input.itemId), getSecrets()).hit)
181
+ return false;
182
+ if (!UUID.test(String(input.epoch)) || !UUID.test(String(input.opId)))
183
+ return false;
184
+ const names = ['schema', 'epoch', 'opId', 'space', 'kind', 'itemId', 'baseRev', 'op'];
185
+ if (input.op === 'delete')
186
+ return input.baseRev > 0 && fields(input, [...names, 'reason'])
187
+ && (input.kind === 'gene' ? ['archive', 'forget', 'revoke', 'delete'] : ['delete']).includes(String(input.reason));
188
+ if (input.op !== 'create' && input.op !== 'update')
189
+ return false;
190
+ if ((input.op === 'create') !== (input.baseRev === 0) || !fields(input, [...names, 'content']))
191
+ return false;
192
+ return checkContent(input, input.content) === null;
193
+ }
@@ -0,0 +1,14 @@
1
+ import { type Content, type LibraryAdapter, type LibraryKind } from './protocol.js';
2
+ import { AccountState } from './state.js';
3
+ import { LibraryTransport } from './transport.js';
4
+ export interface SyncContext {
5
+ store: AccountState;
6
+ transport: LibraryTransport;
7
+ adapters: Record<LibraryKind, LibraryAdapter>;
8
+ }
9
+ export declare const digest: (content?: Content | null) => string | null;
10
+ export declare function reconcileLocals(ctx: SyncContext): Promise<void>;
11
+ export declare function receive(ctx: SyncContext): Promise<void>;
12
+ export declare function prepareDeletions(ctx: SyncContext): Promise<void>;
13
+ export declare function sendQueued(ctx: SyncContext): Promise<void>;
14
+ export declare function resolveConflict(ctx: SyncContext, key: string, choice: 'remote' | 'copy' | 'local'): Promise<void>;