zam-core 0.3.6 → 0.3.11
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/.agent/skills/zam/SKILL.md +177 -9
- package/.agents/skills/zam/SKILL.md +178 -9
- package/.claude/skills/zam/SKILL.md +177 -9
- package/README.de.md +3 -3
- package/README.md +3 -3
- package/dist/cli/index.js +3371 -1616
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +532 -146
- package/dist/index.js +2033 -898
- package/dist/index.js.map +1 -1
- package/package.json +21 -3
- package/templates/personal/README.md +31 -0
- package/templates/personal/beliefs/README.md +19 -0
- package/templates/personal/goals/README.md +19 -0
- package/templates/personal/package.json +9 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
type DatabaseValue = string | number | bigint | null | Uint8Array;
|
|
2
|
+
interface RunResult {
|
|
3
|
+
changes: number;
|
|
4
|
+
lastInsertRowid: number | bigint;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Asynchronous database contract used by the learning kernel.
|
|
8
|
+
*
|
|
9
|
+
* Every provider (local SQLite, optional libsql embedded replica, remote
|
|
10
|
+
* Turso over HTTP) implements this interface; no kernel or public API type
|
|
11
|
+
* depends on a concrete database package.
|
|
12
|
+
*/
|
|
13
|
+
interface Statement {
|
|
14
|
+
run(...params: unknown[]): Promise<RunResult>;
|
|
15
|
+
get(...params: unknown[]): Promise<unknown>;
|
|
16
|
+
all(...params: unknown[]): Promise<unknown[]>;
|
|
17
|
+
}
|
|
18
|
+
interface Database {
|
|
19
|
+
prepare(sql: string): Statement;
|
|
20
|
+
/** Execute one or more SQL statements without reading results. */
|
|
21
|
+
exec(sql: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Run a PRAGMA. Local providers support the full pragma surface; the
|
|
24
|
+
* remote provider only supports read pragmas that have a table-valued
|
|
25
|
+
* function equivalent (e.g. `table_info(...)`).
|
|
26
|
+
*/
|
|
27
|
+
pragma(source: string): Promise<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Run `fn` inside a BEGIN IMMEDIATE … COMMIT/ROLLBACK transaction.
|
|
30
|
+
* Transactions are serialized per connection; nested calls deadlock by
|
|
31
|
+
* design rather than silently interleaving writes.
|
|
32
|
+
*/
|
|
33
|
+
transaction<T>(fn: (db: Database) => Promise<T>): Promise<T>;
|
|
34
|
+
/** Pull changes from the cloud primary (embedded replicas only). */
|
|
35
|
+
sync?(): Promise<void>;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
}
|
|
2
38
|
|
|
3
39
|
/**
|
|
4
40
|
* Learning Analytics
|
|
@@ -29,12 +65,12 @@ interface DomainCompetence {
|
|
|
29
65
|
/**
|
|
30
66
|
* Get overall learning stats for a user (ported from PoC's `stats` command).
|
|
31
67
|
*/
|
|
32
|
-
declare function getUserStats(db: Database, userId: string): UserStats
|
|
68
|
+
declare function getUserStats(db: Database, userId: string): Promise<UserStats>;
|
|
33
69
|
/**
|
|
34
70
|
* Get competence per domain for a user.
|
|
35
71
|
* Used to suggest symbiosis mode transitions.
|
|
36
72
|
*/
|
|
37
|
-
declare function getDomainCompetence(db: Database, userId: string): DomainCompetence[]
|
|
73
|
+
declare function getDomainCompetence(db: Database, userId: string): Promise<DomainCompetence[]>;
|
|
38
74
|
|
|
39
75
|
/**
|
|
40
76
|
* Azure DevOps connector — fetches work items from ADO boards.
|
|
@@ -70,6 +106,11 @@ declare function fetchActiveWorkItems(config: ADOConfig): Promise<WorkItem[]>;
|
|
|
70
106
|
interface TursoCredentials {
|
|
71
107
|
url: string;
|
|
72
108
|
token: string;
|
|
109
|
+
/**
|
|
110
|
+
* Database access mode: "native" uses the legacy libsql driver, "remote"
|
|
111
|
+
* uses the HTTP provider (no native bindings; required on Windows ARM64).
|
|
112
|
+
*/
|
|
113
|
+
mode?: "native" | "remote";
|
|
73
114
|
}
|
|
74
115
|
interface ADOCredentials {
|
|
75
116
|
org_url: string;
|
|
@@ -87,7 +128,7 @@ declare function saveCredentials(creds: Credentials, path?: string): void;
|
|
|
87
128
|
/** Get complete Turso credentials, or null if incomplete. */
|
|
88
129
|
declare function getTursoCredentials(path?: string): TursoCredentials | null;
|
|
89
130
|
/** Set Turso credentials. */
|
|
90
|
-
declare function setTursoCredentials(url: string, token: string, path?: string): void;
|
|
131
|
+
declare function setTursoCredentials(url: string, token: string, path?: string, mode?: TursoCredentials["mode"]): void;
|
|
91
132
|
/** Clear Turso credentials. */
|
|
92
133
|
declare function clearTursoCredentials(path?: string): void;
|
|
93
134
|
/** Get complete ADO credentials, or null if incomplete. */
|
|
@@ -97,10 +138,16 @@ declare function setADOCredentials(orgUrl: string, project: string, pat: string,
|
|
|
97
138
|
/** Clear ADO credentials. */
|
|
98
139
|
declare function clearADOCredentials(path?: string): void;
|
|
99
140
|
|
|
141
|
+
/**
|
|
142
|
+
* - `local`: better-sqlite3 file database (default without cloud credentials)
|
|
143
|
+
* - `native`: legacy native libsql driver (remote URLs and embedded replicas)
|
|
144
|
+
* - `remote`: Turso over HTTP, no native bindings (works on Windows ARM64)
|
|
145
|
+
*/
|
|
146
|
+
type DatabaseProvider = "local" | "native" | "remote";
|
|
100
147
|
interface ConnectionOptions {
|
|
101
148
|
/** Path to the SQLite database file. Defaults to ~/.zam/zam.db */
|
|
102
149
|
dbPath?: string;
|
|
103
|
-
/** If true,
|
|
150
|
+
/** If true, run the schema even when the database already exists. */
|
|
104
151
|
initialize?: boolean;
|
|
105
152
|
/** Turso sync URL for embedded replica mode (e.g. libsql://db-name.turso.io) */
|
|
106
153
|
syncUrl?: string;
|
|
@@ -108,6 +155,8 @@ interface ConnectionOptions {
|
|
|
108
155
|
authToken?: string;
|
|
109
156
|
/** If false, ignore ~/.zam/credentials.json and force the local/default database. */
|
|
110
157
|
useConfiguredCloud?: boolean;
|
|
158
|
+
/** Explicit provider; overrides ZAM_DB_PROVIDER and the credentials mode. */
|
|
159
|
+
provider?: DatabaseProvider;
|
|
111
160
|
}
|
|
112
161
|
/**
|
|
113
162
|
* Open (or create) the ZAM database.
|
|
@@ -115,17 +164,110 @@ interface ConnectionOptions {
|
|
|
115
164
|
* Falls back to local SQLite and WAL mode when no cloud credentials exist.
|
|
116
165
|
* When syncUrl is provided explicitly, enables embedded replica sync with Turso.
|
|
117
166
|
*/
|
|
118
|
-
declare function openDatabase(options?: ConnectionOptions): Database
|
|
167
|
+
declare function openDatabase(options?: ConnectionOptions): Promise<Database>;
|
|
119
168
|
/**
|
|
120
169
|
* Open the database with Turso cloud credentials auto-detected.
|
|
121
170
|
* Credentials live in ~/.zam/credentials.json (NOT in the db), so a fresh
|
|
122
171
|
* machine only has to collect missing secrets instead of bootstrapping local
|
|
123
172
|
* state first.
|
|
124
173
|
*/
|
|
125
|
-
declare function openDatabaseWithSync(options?: Omit<ConnectionOptions, "syncUrl" | "authToken">): Database
|
|
174
|
+
declare function openDatabaseWithSync(options?: Omit<ConnectionOptions, "syncUrl" | "authToken">): Promise<Database>;
|
|
126
175
|
/** Get the default database path */
|
|
127
176
|
declare function getDefaultDbPath(): string;
|
|
128
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Minimal Hrana v3 over HTTP transport for Turso/libsql servers.
|
|
180
|
+
*
|
|
181
|
+
* Implements exactly the subset ZAM needs — execute, sequence, close, and
|
|
182
|
+
* baton-scoped streams for transactions — over plain `fetch`, so it runs on
|
|
183
|
+
* every architecture Node.js supports (including Windows ARM64, which has no
|
|
184
|
+
* native libsql binding).
|
|
185
|
+
*
|
|
186
|
+
* Protocol reference: https://github.com/tursodatabase/libsql/blob/main/docs/HRANA_3_SPEC.md
|
|
187
|
+
*/
|
|
188
|
+
interface HranaTransportOptions {
|
|
189
|
+
/** Database URL (libsql://, https:// or http://). */
|
|
190
|
+
url: string;
|
|
191
|
+
/** Turso auth token; omitted for unauthenticated local servers. */
|
|
192
|
+
authToken?: string;
|
|
193
|
+
/** Per-request timeout in milliseconds. */
|
|
194
|
+
timeoutMs?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Total attempts for requests that failed at the transport level before a
|
|
197
|
+
* response was received. Stateful stream requests (open batons) are never
|
|
198
|
+
* retried.
|
|
199
|
+
*/
|
|
200
|
+
maxAttempts?: number;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* RemoteTursoProvider — implements the async `Database` contract directly
|
|
205
|
+
* against a Turso/libsql server over HTTP (Hrana v3).
|
|
206
|
+
*
|
|
207
|
+
* No native bindings and no extra runtime dependencies, so this provider is
|
|
208
|
+
* the cloud path for architectures without a native libsql artifact (for
|
|
209
|
+
* example Windows ARM64). Under ZAM's online-first assumption it is suitable
|
|
210
|
+
* for interactive sessions: the per-review LLM call dominates latency.
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
type RemoteDatabaseOptions = HranaTransportOptions;
|
|
214
|
+
/** Open a remote Turso database over HTTP. */
|
|
215
|
+
declare function openRemoteDatabase(options: RemoteDatabaseOptions): Database;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Portable database snapshots — Increment 12, Phase 4.
|
|
219
|
+
*
|
|
220
|
+
* A snapshot is portable SQL text: a one-line JSON manifest comment followed by
|
|
221
|
+
* `INSERT` statements for every data row. It deliberately does NOT copy the
|
|
222
|
+
* live WAL database file, so a user can move their learning history between
|
|
223
|
+
* machines through a file-sync folder (Google Drive, OneDrive, iCloud, …)
|
|
224
|
+
* without risking the corruption that comes from syncing an open SQLite/WAL
|
|
225
|
+
* file directly.
|
|
226
|
+
*
|
|
227
|
+
* The schema is NOT embedded. Importing into a freshly initialized database —
|
|
228
|
+
* which always runs the current SCHEMA + migrations on open — keeps snapshots
|
|
229
|
+
* forward compatible across schema changes. Columns are written explicitly so a
|
|
230
|
+
* later-added column never breaks an older snapshot.
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
declare const SNAPSHOT_VERSION = 1;
|
|
234
|
+
interface SnapshotManifest {
|
|
235
|
+
format: string;
|
|
236
|
+
version: number;
|
|
237
|
+
createdAt: string;
|
|
238
|
+
/** Row count per table at export time. */
|
|
239
|
+
tables: Record<string, number>;
|
|
240
|
+
/** SHA-256 of the snapshot body (everything after the manifest line). */
|
|
241
|
+
checksum: string;
|
|
242
|
+
}
|
|
243
|
+
interface ImportResult {
|
|
244
|
+
/** Row count per table after the restore. */
|
|
245
|
+
tables: Record<string, number>;
|
|
246
|
+
total: number;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Serialize the active database to a portable SQL-text snapshot.
|
|
250
|
+
*/
|
|
251
|
+
declare function exportSnapshot(db: Database, options?: {
|
|
252
|
+
createdAt?: string;
|
|
253
|
+
}): Promise<string>;
|
|
254
|
+
/** Split a snapshot into its manifest and body; validates the header only. */
|
|
255
|
+
declare function parseSnapshot(snapshot: string): {
|
|
256
|
+
manifest: SnapshotManifest;
|
|
257
|
+
body: string;
|
|
258
|
+
};
|
|
259
|
+
/** Parse a snapshot and verify its body checksum. Returns the manifest. */
|
|
260
|
+
declare function verifySnapshot(snapshot: string): SnapshotManifest;
|
|
261
|
+
/**
|
|
262
|
+
* Restore a snapshot into `db`. The database must already carry the current
|
|
263
|
+
* schema (open it with `initialize: true`). Refuses to overwrite a non-empty
|
|
264
|
+
* database unless `force` is set, and verifies row counts inside the
|
|
265
|
+
* transaction so any mismatch rolls the whole restore back.
|
|
266
|
+
*/
|
|
267
|
+
declare function importSnapshot(db: Database, snapshot: string, options?: {
|
|
268
|
+
force?: boolean;
|
|
269
|
+
}): Promise<ImportResult>;
|
|
270
|
+
|
|
129
271
|
/**
|
|
130
272
|
* Goal file parser — reads markdown files with YAML-style frontmatter.
|
|
131
273
|
*
|
|
@@ -267,9 +409,9 @@ interface CreateAgentSkillInput {
|
|
|
267
409
|
token_slugs?: string[];
|
|
268
410
|
source?: SkillSource;
|
|
269
411
|
}
|
|
270
|
-
declare function createAgentSkill(db: Database, input: CreateAgentSkillInput): AgentSkill
|
|
271
|
-
declare function getAgentSkill(db: Database, slug: string): AgentSkill | undefined
|
|
272
|
-
declare function listAgentSkills(db: Database): AgentSkill[]
|
|
412
|
+
declare function createAgentSkill(db: Database, input: CreateAgentSkillInput): Promise<AgentSkill>;
|
|
413
|
+
declare function getAgentSkill(db: Database, slug: string): Promise<AgentSkill | undefined>;
|
|
414
|
+
declare function listAgentSkills(db: Database): Promise<AgentSkill[]>;
|
|
273
415
|
|
|
274
416
|
/**
|
|
275
417
|
* Card repository — typed wrappers around the cards table.
|
|
@@ -335,30 +477,30 @@ interface BlockedCard extends Card {
|
|
|
335
477
|
*
|
|
336
478
|
* Ported from the PoC's ensureCard helper.
|
|
337
479
|
*/
|
|
338
|
-
declare function ensureCard(db: Database, tokenId: string, userId: string): Card
|
|
480
|
+
declare function ensureCard(db: Database, tokenId: string, userId: string): Promise<Card>;
|
|
339
481
|
/**
|
|
340
482
|
* Get a card by token+user. Returns undefined if no card exists.
|
|
341
483
|
*/
|
|
342
|
-
declare function getCard(db: Database, tokenId: string, userId: string): Card | undefined
|
|
484
|
+
declare function getCard(db: Database, tokenId: string, userId: string): Promise<Card | undefined>;
|
|
343
485
|
/**
|
|
344
486
|
* Get a card by its ULID.
|
|
345
487
|
*/
|
|
346
|
-
declare function getCardById(db: Database, cardId: string): Card | undefined
|
|
488
|
+
declare function getCardById(db: Database, cardId: string): Promise<Card | undefined>;
|
|
347
489
|
/**
|
|
348
490
|
* Update a card's scheduling fields.
|
|
349
491
|
*
|
|
350
492
|
* Only the fields present in `updates` are changed. Throws if the card
|
|
351
493
|
* does not exist.
|
|
352
494
|
*/
|
|
353
|
-
declare function updateCard(db: Database, cardId: string, updates: UpdateCardInput): Card
|
|
495
|
+
declare function updateCard(db: Database, cardId: string, updates: UpdateCardInput): Promise<Card>;
|
|
354
496
|
/**
|
|
355
497
|
* Preview the review-log rows that will be removed when deleting a user's card.
|
|
356
498
|
*/
|
|
357
|
-
declare function getCardDeletionImpact(db: Database, tokenId: string, userId: string): CardDeletionImpact
|
|
499
|
+
declare function getCardDeletionImpact(db: Database, tokenId: string, userId: string): Promise<CardDeletionImpact>;
|
|
358
500
|
/**
|
|
359
501
|
* Delete one user's card for a token. Review logs cascade via FK.
|
|
360
502
|
*/
|
|
361
|
-
declare function deleteCardForUser(db: Database, tokenId: string, userId: string): DeleteCardResult
|
|
503
|
+
declare function deleteCardForUser(db: Database, tokenId: string, userId: string): Promise<DeleteCardResult>;
|
|
362
504
|
/**
|
|
363
505
|
* Get all cards that are due for review.
|
|
364
506
|
*
|
|
@@ -368,19 +510,20 @@ declare function deleteCardForUser(db: Database, tokenId: string, userId: string
|
|
|
368
510
|
*
|
|
369
511
|
* Ported from the PoC's due-tokens command.
|
|
370
512
|
*/
|
|
371
|
-
declare function getDueCards(db: Database, userId: string, now?: string): DueCard[]
|
|
513
|
+
declare function getDueCards(db: Database, userId: string, now?: string): Promise<DueCard[]>;
|
|
372
514
|
/**
|
|
373
515
|
* Get all blocked cards for a user.
|
|
374
516
|
*
|
|
375
517
|
* Returns cards joined with their token details so the caller can
|
|
376
518
|
* see what is waiting and why.
|
|
377
519
|
*/
|
|
378
|
-
declare function getBlockedCards(db: Database, userId: string): BlockedCard[]
|
|
520
|
+
declare function getBlockedCards(db: Database, userId: string): Promise<BlockedCard[]>;
|
|
379
521
|
|
|
380
522
|
/**
|
|
381
523
|
* Prerequisite repository — typed wrappers around the prerequisites table.
|
|
382
524
|
*
|
|
383
525
|
* Models the dependency graph: "to learn token A, first know token B."
|
|
526
|
+
* The graph must remain acyclic — cycles are rejected at insert time.
|
|
384
527
|
*/
|
|
385
528
|
|
|
386
529
|
interface Prerequisite {
|
|
@@ -394,26 +537,69 @@ interface PrerequisiteWithToken extends Prerequisite {
|
|
|
394
537
|
domain: string;
|
|
395
538
|
bloom_level: number;
|
|
396
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* Returns true if adding edge (tokenId → requiresId) would create a cycle.
|
|
542
|
+
* Uses BFS from requiresId: if tokenId is reachable, adding the edge closes
|
|
543
|
+
* a loop.
|
|
544
|
+
*/
|
|
545
|
+
declare function wouldCreateCycle(db: Database, tokenId: string, requiresId: string): Promise<boolean>;
|
|
397
546
|
/**
|
|
398
547
|
* Add a prerequisite edge: tokenId requires requiresId.
|
|
399
548
|
*
|
|
400
549
|
* Idempotent — silently ignores duplicate edges.
|
|
401
550
|
* Throws if either token ID does not exist (FK constraint).
|
|
402
551
|
* Throws if a token is declared as its own prerequisite.
|
|
552
|
+
* Throws if the edge would create a cycle in the prerequisite graph.
|
|
403
553
|
*/
|
|
404
|
-
declare function addPrerequisite(db: Database, tokenId: string, requiresId: string): void
|
|
554
|
+
declare function addPrerequisite(db: Database, tokenId: string, requiresId: string): Promise<void>;
|
|
405
555
|
/**
|
|
406
556
|
* Get the direct prerequisites of a token — "what does token X require?"
|
|
407
557
|
*
|
|
408
558
|
* Returns prerequisite rows joined with the required token's details.
|
|
409
559
|
*/
|
|
410
|
-
declare function getPrerequisites(db: Database, tokenId: string): PrerequisiteWithToken[]
|
|
560
|
+
declare function getPrerequisites(db: Database, tokenId: string): Promise<PrerequisiteWithToken[]>;
|
|
411
561
|
/**
|
|
412
562
|
* Get the direct dependents of a token — "what depends on token X?"
|
|
413
563
|
*
|
|
414
564
|
* Returns prerequisite rows joined with the dependent token's details.
|
|
415
565
|
*/
|
|
416
|
-
declare function getDependents(db: Database, tokenId: string): PrerequisiteWithToken[]
|
|
566
|
+
declare function getDependents(db: Database, tokenId: string): Promise<PrerequisiteWithToken[]>;
|
|
567
|
+
/** Token + optional per-user card snapshot, tailored for visual encoding (mastery, blocked state, bloom). */
|
|
568
|
+
interface NeighborhoodToken {
|
|
569
|
+
id: string;
|
|
570
|
+
slug: string;
|
|
571
|
+
concept: string;
|
|
572
|
+
domain: string;
|
|
573
|
+
bloom_level: number;
|
|
574
|
+
card: {
|
|
575
|
+
state: CardState$1;
|
|
576
|
+
reps: number;
|
|
577
|
+
stability: number;
|
|
578
|
+
difficulty: number;
|
|
579
|
+
blocked: boolean;
|
|
580
|
+
due_at: string;
|
|
581
|
+
last_review_at: string | null;
|
|
582
|
+
} | null;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* The direct neighborhood for a focus-centric 3D view:
|
|
586
|
+
* - center: the token in focus
|
|
587
|
+
* - prerequisites: direct "basis" tokens required by the center (foundations, placed "below")
|
|
588
|
+
* - dependents: direct tokens that require the center (higher-order abilities, placed "above")
|
|
589
|
+
*
|
|
590
|
+
* When userId is supplied, every node includes the user's Card state so the viz can
|
|
591
|
+
* encode personal mastery (e.g. color by stability/reps, highlight blocked or due).
|
|
592
|
+
*/
|
|
593
|
+
interface Neighborhood {
|
|
594
|
+
center: NeighborhoodToken;
|
|
595
|
+
prerequisites: NeighborhoodToken[];
|
|
596
|
+
dependents: NeighborhoodToken[];
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Fetch the direct (depth-1) prerequisite neighborhood around one token.
|
|
600
|
+
* This is the primary data source for the experimental 3D knowledge graph.
|
|
601
|
+
*/
|
|
602
|
+
declare function getTokenNeighborhood(db: Database, tokenId: string, userId?: string): Promise<Neighborhood>;
|
|
417
603
|
|
|
418
604
|
/**
|
|
419
605
|
* Review log repository — typed wrappers around the review_logs table.
|
|
@@ -457,17 +643,17 @@ interface ListReviewsOptions {
|
|
|
457
643
|
* Validates that the rating is between 1 and 4 (matching the schema CHECK).
|
|
458
644
|
* Returns the created review log entry.
|
|
459
645
|
*/
|
|
460
|
-
declare function logReview(db: Database, input: CreateReviewInput): ReviewLog
|
|
646
|
+
declare function logReview(db: Database, input: CreateReviewInput): Promise<ReviewLog>;
|
|
461
647
|
/**
|
|
462
648
|
* Get all reviews for a specific card, ordered by reviewed_at ascending.
|
|
463
649
|
*/
|
|
464
|
-
declare function getReviewsForCard(db: Database, cardId: string): ReviewLog[]
|
|
650
|
+
declare function getReviewsForCard(db: Database, cardId: string): Promise<ReviewLog[]>;
|
|
465
651
|
/**
|
|
466
652
|
* Get reviews for a user, with optional filtering.
|
|
467
653
|
*
|
|
468
654
|
* Results are ordered by reviewed_at descending (most recent first).
|
|
469
655
|
*/
|
|
470
|
-
declare function getReviewsForUser(db: Database, userId: string, options?: ListReviewsOptions): ReviewLog[]
|
|
656
|
+
declare function getReviewsForUser(db: Database, userId: string, options?: ListReviewsOptions): Promise<ReviewLog[]>;
|
|
471
657
|
|
|
472
658
|
/**
|
|
473
659
|
* Session repository — typed wrappers around sessions and session_steps.
|
|
@@ -522,7 +708,7 @@ interface SessionSummary {
|
|
|
522
708
|
*
|
|
523
709
|
* Ported from the PoC's start-session command.
|
|
524
710
|
*/
|
|
525
|
-
declare function startSession(db: Database, input: CreateSessionInput): Session
|
|
711
|
+
declare function startSession(db: Database, input: CreateSessionInput): Promise<Session>;
|
|
526
712
|
/**
|
|
527
713
|
* End a session by setting its completed_at timestamp.
|
|
528
714
|
*
|
|
@@ -530,7 +716,7 @@ declare function startSession(db: Database, input: CreateSessionInput): Session;
|
|
|
530
716
|
*
|
|
531
717
|
* Ported from the PoC's end-session command.
|
|
532
718
|
*/
|
|
533
|
-
declare function endSession(db: Database, sessionId: string): Session
|
|
719
|
+
declare function endSession(db: Database, sessionId: string): Promise<Session>;
|
|
534
720
|
/**
|
|
535
721
|
* Log a step within a session.
|
|
536
722
|
*
|
|
@@ -539,7 +725,7 @@ declare function endSession(db: Database, sessionId: string): Session;
|
|
|
539
725
|
*
|
|
540
726
|
* Ported from the PoC's log-step command.
|
|
541
727
|
*/
|
|
542
|
-
declare function logStep(db: Database, input: LogStepInput): SessionStep
|
|
728
|
+
declare function logStep(db: Database, input: LogStepInput): Promise<SessionStep>;
|
|
543
729
|
/**
|
|
544
730
|
* Get a full session summary: the session record plus all steps
|
|
545
731
|
* joined with their token details.
|
|
@@ -547,7 +733,7 @@ declare function logStep(db: Database, input: LogStepInput): SessionStep;
|
|
|
547
733
|
* Ported from the PoC's session-summary command.
|
|
548
734
|
* Throws if the session does not exist.
|
|
549
735
|
*/
|
|
550
|
-
declare function getSessionSummary(db: Database, sessionId: string): SessionSummary
|
|
736
|
+
declare function getSessionSummary(db: Database, sessionId: string): Promise<SessionSummary>;
|
|
551
737
|
|
|
552
738
|
/**
|
|
553
739
|
* User settings — key/value store backed by the user_config table.
|
|
@@ -559,15 +745,15 @@ interface UserSetting {
|
|
|
559
745
|
updated_at: string;
|
|
560
746
|
}
|
|
561
747
|
/** Get a single setting by key. Returns undefined if not set. */
|
|
562
|
-
declare function getSetting(db: Database, key: string): string | undefined
|
|
748
|
+
declare function getSetting(db: Database, key: string): Promise<string | undefined>;
|
|
563
749
|
/** Get all settings as a key-value map. */
|
|
564
|
-
declare function getAllSettings(db: Database): Record<string, string
|
|
750
|
+
declare function getAllSettings(db: Database): Promise<Record<string, string>>;
|
|
565
751
|
/** Get all settings with metadata. */
|
|
566
|
-
declare function getAllSettingsDetailed(db: Database): UserSetting[]
|
|
752
|
+
declare function getAllSettingsDetailed(db: Database): Promise<UserSetting[]>;
|
|
567
753
|
/** Set a setting (insert or update). */
|
|
568
|
-
declare function setSetting(db: Database, key: string, value: string): void
|
|
754
|
+
declare function setSetting(db: Database, key: string, value: string): Promise<void>;
|
|
569
755
|
/** Delete a setting. Returns true if it existed. */
|
|
570
|
-
declare function deleteSetting(db: Database, key: string): boolean
|
|
756
|
+
declare function deleteSetting(db: Database, key: string): Promise<boolean>;
|
|
571
757
|
|
|
572
758
|
/**
|
|
573
759
|
* Token repository — typed wrappers around the tokens table.
|
|
@@ -634,53 +820,57 @@ interface ScoredToken extends Token {
|
|
|
634
820
|
* Create a new knowledge token.
|
|
635
821
|
* Throws if a token with the same slug already exists.
|
|
636
822
|
*/
|
|
637
|
-
declare function createToken(db: Database, input: CreateTokenInput): Token
|
|
823
|
+
declare function createToken(db: Database, input: CreateTokenInput): Promise<Token>;
|
|
638
824
|
/**
|
|
639
825
|
* Look up a token by its unique slug.
|
|
640
826
|
* Returns undefined if not found.
|
|
641
827
|
*/
|
|
642
|
-
declare function getTokenBySlug(db: Database, slug: string): Token | undefined
|
|
828
|
+
declare function getTokenBySlug(db: Database, slug: string): Promise<Token | undefined>;
|
|
643
829
|
/**
|
|
644
830
|
* Look up a token by its ULID.
|
|
645
831
|
* Returns undefined if not found.
|
|
646
832
|
*/
|
|
647
|
-
declare function getTokenById(db: Database, id: string): Token | undefined
|
|
833
|
+
declare function getTokenById(db: Database, id: string): Promise<Token | undefined>;
|
|
648
834
|
/**
|
|
649
835
|
* Update mutable fields on a token.
|
|
650
836
|
*
|
|
651
837
|
* Slug is intentionally immutable in v1 because it is referenced by other
|
|
652
838
|
* parts of the system (for example agent skill metadata).
|
|
653
839
|
*/
|
|
654
|
-
declare function updateToken(db: Database, slug: string, updates: UpdateTokenInput): Token
|
|
840
|
+
declare function updateToken(db: Database, slug: string, updates: UpdateTokenInput): Promise<Token>;
|
|
655
841
|
/**
|
|
656
842
|
* Mark a token as deprecated. Deprecated tokens are excluded from review queues
|
|
657
843
|
* and search results but are not deleted — they can still be consulted.
|
|
658
844
|
*
|
|
659
845
|
* Throws if the token does not exist or is already deprecated.
|
|
660
846
|
*/
|
|
661
|
-
declare function deprecateToken(db: Database, slug: string): Token
|
|
847
|
+
declare function deprecateToken(db: Database, slug: string): Promise<Token>;
|
|
662
848
|
/**
|
|
663
849
|
* Preview the rows that will be removed or updated when deleting a token.
|
|
664
850
|
*/
|
|
665
|
-
declare function getTokenDeleteImpact(db: Database, slug: string): TokenDeleteImpact
|
|
851
|
+
declare function getTokenDeleteImpact(db: Database, slug: string): Promise<TokenDeleteImpact>;
|
|
666
852
|
/**
|
|
667
853
|
* Hard-delete a token and clean up non-FK references that point at its slug.
|
|
668
854
|
*/
|
|
669
|
-
declare function deleteToken(db: Database, slug: string): DeleteTokenResult
|
|
855
|
+
declare function deleteToken(db: Database, slug: string): Promise<DeleteTokenResult>;
|
|
670
856
|
/**
|
|
671
857
|
* Fuzzy search for tokens by keyword query.
|
|
672
858
|
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
859
|
+
* Uses SQLite LIKE queries on slug, concept, and domain to avoid loading
|
|
860
|
+
* every non-deprecated token into memory. Each search term runs its own
|
|
861
|
+
* LIKE query; results are aggregated in JS with a word-overlap score plus
|
|
862
|
+
* a substring bonus on the concept field. Results are returned sorted by
|
|
863
|
+
* relevance score descending.
|
|
864
|
+
*
|
|
865
|
+
* For very small search terms (< 3 chars) a light in-memory fallback is
|
|
866
|
+
* used to avoid matching every token.
|
|
677
867
|
*/
|
|
678
|
-
declare function findTokens(db: Database, query: string): ScoredToken[]
|
|
868
|
+
declare function findTokens(db: Database, query: string): Promise<ScoredToken[]>;
|
|
679
869
|
/**
|
|
680
870
|
* List all tokens, optionally filtered by domain.
|
|
681
871
|
* Results are ordered by bloom_level then slug.
|
|
682
872
|
*/
|
|
683
|
-
declare function listTokens(db: Database, options?: ListTokensOptions): Token[]
|
|
873
|
+
declare function listTokens(db: Database, options?: ListTokensOptions): Promise<Token[]>;
|
|
684
874
|
|
|
685
875
|
/**
|
|
686
876
|
* Monitor log analyzer — maps observed shell commands to token ratings.
|
|
@@ -777,93 +967,6 @@ declare function getMonitorLogStats(sessionId: string): {
|
|
|
777
967
|
lineCount: number;
|
|
778
968
|
};
|
|
779
969
|
|
|
780
|
-
/**
|
|
781
|
-
* Shell hook code generation for zsh, bash, and PowerShell.
|
|
782
|
-
*
|
|
783
|
-
* Pure functions that return shell code strings. The CLI command
|
|
784
|
-
* `zam monitor start/stop` calls these and prints to stdout.
|
|
785
|
-
*/
|
|
786
|
-
/**
|
|
787
|
-
* Generate zsh hooks that capture commands to a JSONL file.
|
|
788
|
-
* Uses $EPOCHREALTIME for sub-second timestamp precision.
|
|
789
|
-
*/
|
|
790
|
-
declare function generateZshHooks(monitorFile: string, sessionId: string): string;
|
|
791
|
-
/**
|
|
792
|
-
* Generate bash hooks that capture commands to a JSONL file.
|
|
793
|
-
* Uses DEBUG trap for preexec, PROMPT_COMMAND for precmd.
|
|
794
|
-
*/
|
|
795
|
-
declare function generateBashHooks(monitorFile: string, sessionId: string): string;
|
|
796
|
-
/**
|
|
797
|
-
* Generate PowerShell hooks that capture completed commands to a JSONL file.
|
|
798
|
-
* PowerShell has no zsh-style preexec hook, so this records the most recent
|
|
799
|
-
* history item from the prompt function after each command completes.
|
|
800
|
-
*/
|
|
801
|
-
declare function generatePowerShellHooks(monitorFile: string, sessionId: string): string;
|
|
802
|
-
/** Generate zsh code to remove monitor hooks. */
|
|
803
|
-
declare function generateZshUnhooks(): string;
|
|
804
|
-
/** Generate bash code to remove monitor hooks. */
|
|
805
|
-
declare function generateBashUnhooks(): string;
|
|
806
|
-
/** Generate PowerShell code to remove monitor hooks. */
|
|
807
|
-
declare function generatePowerShellUnhooks(): string;
|
|
808
|
-
|
|
809
|
-
/**
|
|
810
|
-
* Skill Discovery — identifies recurring non-standard command patterns
|
|
811
|
-
* across multiple sessions and proposes them as minimal reusable skills.
|
|
812
|
-
*
|
|
813
|
-
* The key insight from Increment 2: "The human's demonstrated competence
|
|
814
|
-
* is the gate for automation — not the other way around." A pattern must
|
|
815
|
-
* appear consistently across sessions before being proposed as a skill.
|
|
816
|
-
*
|
|
817
|
-
* Pure functions — no DB access. Callers provide command records and
|
|
818
|
-
* existing skills; this module returns proposed skills.
|
|
819
|
-
*/
|
|
820
|
-
|
|
821
|
-
interface CommandSequence {
|
|
822
|
-
/** The ordered command prefixes forming the pattern (e.g., ["git checkout", "npm install", "npm run build"]) */
|
|
823
|
-
steps: string[];
|
|
824
|
-
/** How many sessions contained this sequence */
|
|
825
|
-
sessionCount: number;
|
|
826
|
-
/** Total occurrences across all sessions */
|
|
827
|
-
totalOccurrences: number;
|
|
828
|
-
/** Example full commands from the most recent occurrence */
|
|
829
|
-
examples: string[];
|
|
830
|
-
}
|
|
831
|
-
interface SkillProposal {
|
|
832
|
-
/** Suggested slug for the skill */
|
|
833
|
-
slug: string;
|
|
834
|
-
/** Human-readable description of what the pattern does */
|
|
835
|
-
description: string;
|
|
836
|
-
/** The command steps forming the skill */
|
|
837
|
-
steps: string[];
|
|
838
|
-
/** How many sessions demonstrated this pattern */
|
|
839
|
-
sessionCount: number;
|
|
840
|
-
/** Confidence that this is a real, repeatable skill */
|
|
841
|
-
confidence: "high" | "medium" | "low";
|
|
842
|
-
/** Example commands from actual usage */
|
|
843
|
-
examples: string[];
|
|
844
|
-
}
|
|
845
|
-
interface DiscoveryOptions {
|
|
846
|
-
/** Minimum number of sessions a pattern must appear in (default: 2) */
|
|
847
|
-
minSessions?: number;
|
|
848
|
-
/** Minimum sequence length to consider (default: 2) */
|
|
849
|
-
minSequenceLength?: number;
|
|
850
|
-
/** Maximum sequence length to consider (default: 5) */
|
|
851
|
-
maxSequenceLength?: number;
|
|
852
|
-
/** Existing skill slugs to exclude from proposals */
|
|
853
|
-
existingSkillSlugs?: string[];
|
|
854
|
-
}
|
|
855
|
-
/**
|
|
856
|
-
* Discover recurring command patterns across multiple sessions.
|
|
857
|
-
*
|
|
858
|
-
* Takes a map of session ID → command records, finds command sequences
|
|
859
|
-
* that appear in multiple sessions, and proposes them as skills.
|
|
860
|
-
*
|
|
861
|
-
* @param sessionCommands - Map of session ID to that session's commands
|
|
862
|
-
* @param options - Discovery configuration
|
|
863
|
-
* @returns Array of skill proposals, sorted by confidence then session count
|
|
864
|
-
*/
|
|
865
|
-
declare function discoverSkills(sessionCommands: Map<string, CommandRecord[]>, options?: DiscoveryOptions): SkillProposal[];
|
|
866
|
-
|
|
867
970
|
/**
|
|
868
971
|
* Cascade Block & Unblock — prerequisite-aware blocking logic.
|
|
869
972
|
*
|
|
@@ -901,7 +1004,7 @@ interface UnblockResult {
|
|
|
901
1004
|
* @param tokenSlug - Slug of the token the user forgot
|
|
902
1005
|
* @returns Info about what was blocked and which prerequisites were surfaced
|
|
903
1006
|
*/
|
|
904
|
-
declare function cascadeBlock(db: Database, userId: string, tokenSlug: string): CascadeBlockResult
|
|
1007
|
+
declare function cascadeBlock(db: Database, userId: string, tokenSlug: string): Promise<CascadeBlockResult>;
|
|
905
1008
|
/**
|
|
906
1009
|
* Scan all blocked cards for a user and unblock any whose prerequisites are met.
|
|
907
1010
|
*
|
|
@@ -916,7 +1019,7 @@ declare function cascadeBlock(db: Database, userId: string, tokenSlug: string):
|
|
|
916
1019
|
* @param userId - The user whose blocked cards to check
|
|
917
1020
|
* @returns List of cards that were unblocked
|
|
918
1021
|
*/
|
|
919
|
-
declare function unblockReady(db: Database, userId: string): UnblockResult
|
|
1022
|
+
declare function unblockReady(db: Database, userId: string): Promise<UnblockResult>;
|
|
920
1023
|
|
|
921
1024
|
/**
|
|
922
1025
|
* FSRS-5 — Free Spaced Repetition Scheduler (v5)
|
|
@@ -970,6 +1073,168 @@ interface FSRS {
|
|
|
970
1073
|
*/
|
|
971
1074
|
declare function createFSRS(params?: Partial<FSRSParameters>): FSRS;
|
|
972
1075
|
|
|
1076
|
+
/**
|
|
1077
|
+
* Session synthesis connects shell observation to durable learning state.
|
|
1078
|
+
*
|
|
1079
|
+
* A preview analyzes monitor commands without mutating the database. Applying
|
|
1080
|
+
* one confirmed candidate updates the card, review log, session step, blocking
|
|
1081
|
+
* state, and synthesis audit record in a single transaction.
|
|
1082
|
+
*/
|
|
1083
|
+
|
|
1084
|
+
type SynthesisConfidence = "medium" | "high";
|
|
1085
|
+
interface SessionSynthesisCandidate {
|
|
1086
|
+
tokenId: string;
|
|
1087
|
+
tokenSlug: string;
|
|
1088
|
+
concept: string;
|
|
1089
|
+
domain: string;
|
|
1090
|
+
inferredRating: Rating;
|
|
1091
|
+
confidence: SynthesisConfidence;
|
|
1092
|
+
evidence: ObservationRating["evidence"];
|
|
1093
|
+
matchedCommandTexts: string[];
|
|
1094
|
+
}
|
|
1095
|
+
interface PrepareSessionSynthesisInput {
|
|
1096
|
+
sessionId: string;
|
|
1097
|
+
explicitPatterns?: TokenPattern[];
|
|
1098
|
+
minConfidence?: SynthesisConfidence;
|
|
1099
|
+
/** Test and integration hook; normal callers read the monitor log. */
|
|
1100
|
+
commands?: CommandRecord[];
|
|
1101
|
+
}
|
|
1102
|
+
interface SessionSynthesisPreview {
|
|
1103
|
+
sessionId: string;
|
|
1104
|
+
userId: string;
|
|
1105
|
+
patternCount: number;
|
|
1106
|
+
commandCount: number;
|
|
1107
|
+
alreadyApplied: number;
|
|
1108
|
+
skippedLowConfidence: number;
|
|
1109
|
+
candidates: SessionSynthesisCandidate[];
|
|
1110
|
+
unmatchedCommands: string[];
|
|
1111
|
+
timeSpan: {
|
|
1112
|
+
start: string;
|
|
1113
|
+
end: string;
|
|
1114
|
+
durationMs: number;
|
|
1115
|
+
} | null;
|
|
1116
|
+
}
|
|
1117
|
+
interface SessionSynthesisEvidence {
|
|
1118
|
+
signals: ObservationRating["evidence"];
|
|
1119
|
+
matchedCommandTexts: string[];
|
|
1120
|
+
}
|
|
1121
|
+
interface SessionSynthesisRecord {
|
|
1122
|
+
session_id: string;
|
|
1123
|
+
token_id: string;
|
|
1124
|
+
card_id: string;
|
|
1125
|
+
inferred_rating: Rating;
|
|
1126
|
+
confirmed_rating: Rating;
|
|
1127
|
+
confidence: SynthesisConfidence;
|
|
1128
|
+
evidence: SessionSynthesisEvidence;
|
|
1129
|
+
review_log_id: string;
|
|
1130
|
+
session_step_id: string;
|
|
1131
|
+
created_at: string;
|
|
1132
|
+
}
|
|
1133
|
+
interface ApplySessionSynthesisInput {
|
|
1134
|
+
sessionId: string;
|
|
1135
|
+
tokenSlug: string;
|
|
1136
|
+
inferredRating: Rating;
|
|
1137
|
+
confirmedRating: Rating;
|
|
1138
|
+
confidence: SynthesisConfidence;
|
|
1139
|
+
evidence: ObservationRating["evidence"];
|
|
1140
|
+
matchedCommandTexts: string[];
|
|
1141
|
+
}
|
|
1142
|
+
interface ApplySessionSynthesisResult {
|
|
1143
|
+
applied: boolean;
|
|
1144
|
+
record: SessionSynthesisRecord;
|
|
1145
|
+
blocked?: Awaited<ReturnType<typeof cascadeBlock>>;
|
|
1146
|
+
}
|
|
1147
|
+
declare function getSessionSynthesisRecords(db: Database, sessionId: string): Promise<SessionSynthesisRecord[]>;
|
|
1148
|
+
declare function prepareSessionSynthesis(db: Database, input: PrepareSessionSynthesisInput): Promise<SessionSynthesisPreview>;
|
|
1149
|
+
declare function applySessionSynthesis(db: Database, input: ApplySessionSynthesisInput): Promise<ApplySessionSynthesisResult>;
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Shell hook code generation for zsh, bash, and PowerShell.
|
|
1153
|
+
*
|
|
1154
|
+
* Pure functions that return shell code strings. The CLI command
|
|
1155
|
+
* `zam monitor start/stop` calls these and prints to stdout.
|
|
1156
|
+
*/
|
|
1157
|
+
/**
|
|
1158
|
+
* Generate zsh hooks that capture commands to a JSONL file.
|
|
1159
|
+
* Uses $EPOCHREALTIME for sub-second timestamp precision.
|
|
1160
|
+
*/
|
|
1161
|
+
declare function generateZshHooks(monitorFile: string, sessionId: string): string;
|
|
1162
|
+
/**
|
|
1163
|
+
* Generate bash hooks that capture commands to a JSONL file.
|
|
1164
|
+
* Uses DEBUG trap for preexec, PROMPT_COMMAND for precmd.
|
|
1165
|
+
*/
|
|
1166
|
+
declare function generateBashHooks(monitorFile: string, sessionId: string): string;
|
|
1167
|
+
/**
|
|
1168
|
+
* Generate PowerShell hooks that capture completed commands to a JSONL file.
|
|
1169
|
+
* PowerShell has no zsh-style preexec hook, so this records the most recent
|
|
1170
|
+
* history item from the prompt function after each command completes.
|
|
1171
|
+
*/
|
|
1172
|
+
declare function generatePowerShellHooks(monitorFile: string, sessionId: string): string;
|
|
1173
|
+
/** Generate zsh code to remove monitor hooks. */
|
|
1174
|
+
declare function generateZshUnhooks(): string;
|
|
1175
|
+
/** Generate bash code to remove monitor hooks. */
|
|
1176
|
+
declare function generateBashUnhooks(): string;
|
|
1177
|
+
/** Generate PowerShell code to remove monitor hooks. */
|
|
1178
|
+
declare function generatePowerShellUnhooks(): string;
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* Skill Discovery — identifies recurring non-standard command patterns
|
|
1182
|
+
* across multiple sessions and proposes them as minimal reusable skills.
|
|
1183
|
+
*
|
|
1184
|
+
* The key insight from Increment 2: "The human's demonstrated competence
|
|
1185
|
+
* is the gate for automation — not the other way around." A pattern must
|
|
1186
|
+
* appear consistently across sessions before being proposed as a skill.
|
|
1187
|
+
*
|
|
1188
|
+
* Pure functions — no DB access. Callers provide command records and
|
|
1189
|
+
* existing skills; this module returns proposed skills.
|
|
1190
|
+
*/
|
|
1191
|
+
|
|
1192
|
+
interface CommandSequence {
|
|
1193
|
+
/** The ordered command prefixes forming the pattern (e.g., ["git checkout", "npm install", "npm run build"]) */
|
|
1194
|
+
steps: string[];
|
|
1195
|
+
/** How many sessions contained this sequence */
|
|
1196
|
+
sessionCount: number;
|
|
1197
|
+
/** Total occurrences across all sessions */
|
|
1198
|
+
totalOccurrences: number;
|
|
1199
|
+
/** Example full commands from the most recent occurrence */
|
|
1200
|
+
examples: string[];
|
|
1201
|
+
}
|
|
1202
|
+
interface SkillProposal {
|
|
1203
|
+
/** Suggested slug for the skill */
|
|
1204
|
+
slug: string;
|
|
1205
|
+
/** Human-readable description of what the pattern does */
|
|
1206
|
+
description: string;
|
|
1207
|
+
/** The command steps forming the skill */
|
|
1208
|
+
steps: string[];
|
|
1209
|
+
/** How many sessions demonstrated this pattern */
|
|
1210
|
+
sessionCount: number;
|
|
1211
|
+
/** Confidence that this is a real, repeatable skill */
|
|
1212
|
+
confidence: "high" | "medium" | "low";
|
|
1213
|
+
/** Example commands from actual usage */
|
|
1214
|
+
examples: string[];
|
|
1215
|
+
}
|
|
1216
|
+
interface DiscoveryOptions {
|
|
1217
|
+
/** Minimum number of sessions a pattern must appear in (default: 2) */
|
|
1218
|
+
minSessions?: number;
|
|
1219
|
+
/** Minimum sequence length to consider (default: 2) */
|
|
1220
|
+
minSequenceLength?: number;
|
|
1221
|
+
/** Maximum sequence length to consider (default: 5) */
|
|
1222
|
+
maxSequenceLength?: number;
|
|
1223
|
+
/** Existing skill slugs to exclude from proposals */
|
|
1224
|
+
existingSkillSlugs?: string[];
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Discover recurring command patterns across multiple sessions.
|
|
1228
|
+
*
|
|
1229
|
+
* Takes a map of session ID → command records, finds command sequences
|
|
1230
|
+
* that appear in multiple sessions, and proposes them as skills.
|
|
1231
|
+
*
|
|
1232
|
+
* @param sessionCommands - Map of session ID to that session's commands
|
|
1233
|
+
* @param options - Discovery configuration
|
|
1234
|
+
* @returns Array of skill proposals, sorted by confidence then session count
|
|
1235
|
+
*/
|
|
1236
|
+
declare function discoverSkills(sessionCommands: Map<string, CommandRecord[]>, options?: DiscoveryOptions): SkillProposal[];
|
|
1237
|
+
|
|
973
1238
|
/**
|
|
974
1239
|
* Rating Evaluator
|
|
975
1240
|
*
|
|
@@ -984,6 +1249,7 @@ interface EvaluateInput {
|
|
|
984
1249
|
rating: Rating;
|
|
985
1250
|
sessionId?: string;
|
|
986
1251
|
responseTimeMs?: number;
|
|
1252
|
+
reviewLogId?: string;
|
|
987
1253
|
}
|
|
988
1254
|
interface EvaluateResult {
|
|
989
1255
|
nextDueAt: string;
|
|
@@ -1001,7 +1267,7 @@ interface EvaluateResult {
|
|
|
1001
1267
|
* Note: blocking logic (cascade-block) is handled separately by the caller
|
|
1002
1268
|
* when rating === 1 and the token has prerequisites.
|
|
1003
1269
|
*/
|
|
1004
|
-
declare function evaluateRating(db: Database, input: EvaluateInput): EvaluateResult
|
|
1270
|
+
declare function evaluateRating(db: Database, input: EvaluateInput): Promise<EvaluateResult>;
|
|
1005
1271
|
|
|
1006
1272
|
type ReviewActionType = "rate" | "skip" | "edit-token" | "deprecate-token" | "delete-token" | "delete-card" | "stop";
|
|
1007
1273
|
interface ExecuteReviewActionInput {
|
|
@@ -1022,7 +1288,7 @@ interface ReviewActionResult {
|
|
|
1022
1288
|
skipped?: boolean;
|
|
1023
1289
|
stopped?: boolean;
|
|
1024
1290
|
}
|
|
1025
|
-
declare function executeReviewAction(db: Database, input: ExecuteReviewActionInput): ReviewActionResult
|
|
1291
|
+
declare function executeReviewAction(db: Database, input: ExecuteReviewActionInput): Promise<ReviewActionResult>;
|
|
1026
1292
|
|
|
1027
1293
|
/**
|
|
1028
1294
|
* Active Recall Prompt Generation
|
|
@@ -1174,7 +1440,7 @@ interface ReviewQueue {
|
|
|
1174
1440
|
* @param options - Queue building options
|
|
1175
1441
|
* @returns The assembled review queue with metadata
|
|
1176
1442
|
*/
|
|
1177
|
-
declare function buildReviewQueue(db: Database, options: ReviewQueueOptions): ReviewQueue
|
|
1443
|
+
declare function buildReviewQueue(db: Database, options: ReviewQueueOptions): Promise<ReviewQueue>;
|
|
1178
1444
|
|
|
1179
1445
|
/**
|
|
1180
1446
|
* Get the path to ZAM's internal package SKILL.md.
|
|
@@ -1190,10 +1456,9 @@ declare function distributeGlobalSkills(home?: string): Array<{
|
|
|
1190
1456
|
success: boolean;
|
|
1191
1457
|
}>;
|
|
1192
1458
|
/**
|
|
1193
|
-
*
|
|
1194
|
-
* is automatically initialized on startup.
|
|
1459
|
+
* Add opt-in helpers for starting a monitored session to user shell profiles.
|
|
1195
1460
|
*/
|
|
1196
|
-
declare function injectShellHooks(): Array<{
|
|
1461
|
+
declare function injectShellHooks(home?: string): Array<{
|
|
1197
1462
|
shell: string;
|
|
1198
1463
|
file: string;
|
|
1199
1464
|
success: boolean;
|
|
@@ -1216,10 +1481,105 @@ type TranslationKey = "welcome" | "new_review_relearn" | "domains" | "instructio
|
|
|
1216
1481
|
*/
|
|
1217
1482
|
declare function t(locale: SupportedLocale, key: TranslationKey, params?: Record<string, string | number>): string;
|
|
1218
1483
|
|
|
1484
|
+
/**
|
|
1485
|
+
* Update-decision logic — Increment 12, Phase 5.
|
|
1486
|
+
*
|
|
1487
|
+
* The brain behind "the app noticed a newer version": given the current and
|
|
1488
|
+
* latest versions and how this copy was installed, decide what the UI should
|
|
1489
|
+
* do. Deliberately network-free and pure, so it is fully unit-tested; the
|
|
1490
|
+
* actual version fetch (e.g. GitHub releases) and the Tauri self-update live in
|
|
1491
|
+
* the CLI/desktop layers that call this.
|
|
1492
|
+
*/
|
|
1493
|
+
type InstallChannel = "developer" | "direct" | "winget" | "homebrew";
|
|
1494
|
+
/** Provisional package identifiers; finalized when channels ship (Phase 2). */
|
|
1495
|
+
declare const WINGET_PACKAGE_ID = "ZAM.ZAM";
|
|
1496
|
+
declare const HOMEBREW_CASK = "zam";
|
|
1497
|
+
type UpdateActionKind = "none" | "self-update" | "run-command" | "inform";
|
|
1498
|
+
interface UpdateDecision {
|
|
1499
|
+
updateAvailable: boolean;
|
|
1500
|
+
currentVersion: string;
|
|
1501
|
+
latestVersion: string;
|
|
1502
|
+
channel: InstallChannel;
|
|
1503
|
+
/** What the UI should do about the update. */
|
|
1504
|
+
action: UpdateActionKind;
|
|
1505
|
+
/** For "run-command"/"inform": the command to surface to the user. */
|
|
1506
|
+
command?: string;
|
|
1507
|
+
/** Locale-agnostic explanation; the UI provides its own localized copy. */
|
|
1508
|
+
reason: string;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Compare two semver-ish versions. Returns 1 if `a` is newer than `b`, -1 if
|
|
1512
|
+
* older, 0 if equal. A version with a prerelease tag (1.0.0-beta) sorts below
|
|
1513
|
+
* the same core release (1.0.0), per semver.
|
|
1514
|
+
*/
|
|
1515
|
+
declare function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
1516
|
+
/**
|
|
1517
|
+
* Decide what to do given current/latest versions and the install channel.
|
|
1518
|
+
* The mechanism follows how the copy was installed so we never self-replace a
|
|
1519
|
+
* package-managed install or a source checkout.
|
|
1520
|
+
*/
|
|
1521
|
+
declare function decideUpdate(input: {
|
|
1522
|
+
currentVersion: string;
|
|
1523
|
+
latestVersion: string;
|
|
1524
|
+
channel: InstallChannel;
|
|
1525
|
+
}): UpdateDecision;
|
|
1526
|
+
|
|
1527
|
+
/**
|
|
1528
|
+
* Per-machine install configuration — Increment 12, Phase 3.
|
|
1529
|
+
*
|
|
1530
|
+
* Records whether this machine runs ZAM in "developer" mode (source checkout,
|
|
1531
|
+
* git-backed workspace, manual `git`/`npm` updates) or "default" mode (an
|
|
1532
|
+
* installed application updated through a package manager or the in-app
|
|
1533
|
+
* updater). Stored in ~/.zam/config.json — a per-machine file, NOT the database
|
|
1534
|
+
* and NOT the personal folder, so the mode never travels through a shared Turso
|
|
1535
|
+
* database or a synced folder, where it would be wrong for the other machine.
|
|
1536
|
+
*
|
|
1537
|
+
* The personal-content folder itself is unchanged: it stays the existing
|
|
1538
|
+
* `personal.workspace_dir` setting, and can already point at any local or
|
|
1539
|
+
* file-synced directory (Drive, OneDrive, Dropbox, iCloud) — no GitHub required.
|
|
1540
|
+
*/
|
|
1541
|
+
|
|
1542
|
+
type InstallMode = "developer" | "default";
|
|
1543
|
+
interface InstallConfig {
|
|
1544
|
+
mode?: InstallMode;
|
|
1545
|
+
/** How this copy was installed; drives the self-update mechanism. */
|
|
1546
|
+
channel?: InstallChannel;
|
|
1547
|
+
}
|
|
1548
|
+
/** Load ~/.zam/config.json. Returns an empty config if missing or unreadable. */
|
|
1549
|
+
declare function loadInstallConfig(path?: string): InstallConfig;
|
|
1550
|
+
/** Persist the install config, preserving any unrelated keys already on disk. */
|
|
1551
|
+
declare function saveInstallConfig(config: InstallConfig, path?: string): void;
|
|
1552
|
+
/**
|
|
1553
|
+
* This machine's install mode. Defaults to "developer" — the only historical
|
|
1554
|
+
* mode — so existing source/CLI installs keep their behavior. A packaged
|
|
1555
|
+
* "default" install writes mode explicitly at install time.
|
|
1556
|
+
*/
|
|
1557
|
+
declare function getInstallMode(path?: string): InstallMode;
|
|
1558
|
+
declare function setInstallMode(mode: InstallMode, path?: string): void;
|
|
1559
|
+
/**
|
|
1560
|
+
* How this copy was installed, used to pick the self-update mechanism. Falls
|
|
1561
|
+
* back to "developer" for developer mode and "direct" for an installed app
|
|
1562
|
+
* whose channel was not recorded.
|
|
1563
|
+
*/
|
|
1564
|
+
declare function getInstallChannel(path?: string): InstallChannel;
|
|
1565
|
+
declare function setInstallChannel(channel: InstallChannel, path?: string): void;
|
|
1566
|
+
/**
|
|
1567
|
+
* Best-effort detection of the file-sync provider a folder lives in, from its
|
|
1568
|
+
* path. Used only for friendly messaging ("this folder syncs via OneDrive —
|
|
1569
|
+
* good for moving snapshots between machines"), never for behavior.
|
|
1570
|
+
*/
|
|
1571
|
+
declare function detectSyncProvider(dir: string): string | null;
|
|
1572
|
+
|
|
1219
1573
|
interface InstallResult {
|
|
1220
1574
|
success: boolean;
|
|
1221
1575
|
message: string;
|
|
1222
1576
|
}
|
|
1577
|
+
type LocalLLMRunner = "fastflowlm" | "ollama" | "generic";
|
|
1578
|
+
/** A resolved way to install a tool: a human label and the command to run. */
|
|
1579
|
+
interface InstallPlan {
|
|
1580
|
+
method: string;
|
|
1581
|
+
command: string;
|
|
1582
|
+
}
|
|
1223
1583
|
/**
|
|
1224
1584
|
* Check if a command is executable on the system.
|
|
1225
1585
|
*/
|
|
@@ -1232,6 +1592,32 @@ declare function installFastFlowLM(): InstallResult;
|
|
|
1232
1592
|
* Install Ollama via Homebrew on macOS.
|
|
1233
1593
|
*/
|
|
1234
1594
|
declare function installOllama(): InstallResult;
|
|
1595
|
+
/**
|
|
1596
|
+
* Prepare the recommended model after installing a local LLM runner.
|
|
1597
|
+
*/
|
|
1598
|
+
declare function prepareLocalModel(runner: LocalLLMRunner, model: string): InstallResult;
|
|
1599
|
+
/**
|
|
1600
|
+
* Pick how to install the opencode agent for the current machine.
|
|
1601
|
+
*
|
|
1602
|
+
* npm is preferred on every platform: ZAM already requires Node, and the
|
|
1603
|
+
* `opencode-ai` package pulls the correct native binary for Apple Silicon and
|
|
1604
|
+
* Windows on ARM — avoiding the bash-on-Windows and Homebrew-tap caveats.
|
|
1605
|
+
* Returns null when no automatic method is available (e.g. Windows without npm,
|
|
1606
|
+
* Scoop, or Chocolatey).
|
|
1607
|
+
*/
|
|
1608
|
+
declare function planOpenCodeInstall(env: {
|
|
1609
|
+
platform: NodeJS.Platform;
|
|
1610
|
+
hasNpm: boolean;
|
|
1611
|
+
hasBrew: boolean;
|
|
1612
|
+
hasScoop: boolean;
|
|
1613
|
+
hasChoco: boolean;
|
|
1614
|
+
}): InstallPlan | null;
|
|
1615
|
+
/**
|
|
1616
|
+
* Install the opencode agent (the default agent ZAM provisions). opencode reads
|
|
1617
|
+
* the AGENTS.md that `zam setup` writes, so it picks up the ZAM skill once both
|
|
1618
|
+
* are present.
|
|
1619
|
+
*/
|
|
1620
|
+
declare function installOpenCode(): InstallResult;
|
|
1235
1621
|
|
|
1236
1622
|
interface SystemProfile {
|
|
1237
1623
|
os: "windows" | "macos" | "linux" | "unknown";
|
|
@@ -1255,20 +1641,20 @@ interface RepoPaths {
|
|
|
1255
1641
|
* Resolve absolute paths for personal, team, and organization repositories.
|
|
1256
1642
|
* Personal falls back to personal.workspace_dir if repo.personal is not set.
|
|
1257
1643
|
*/
|
|
1258
|
-
declare function getRepoPaths(db: Database): RepoPaths
|
|
1644
|
+
declare function getRepoPaths(db: Database): Promise<RepoPaths>;
|
|
1259
1645
|
/**
|
|
1260
1646
|
* Resolve a specific repo's path, or null if not configured.
|
|
1261
1647
|
*/
|
|
1262
|
-
declare function resolveRepoPath(db: Database, type: "personal" | "team" | "org"): string | null
|
|
1648
|
+
declare function resolveRepoPath(db: Database, type: "personal" | "team" | "org"): Promise<string | null>;
|
|
1263
1649
|
/**
|
|
1264
1650
|
* Resolve paths to all existing "/beliefs" directories in the hierarchy,
|
|
1265
1651
|
* sorted from most specific (personal) to most general (org).
|
|
1266
1652
|
*/
|
|
1267
|
-
declare function resolveAllBeliefPaths(db: Database): string[]
|
|
1653
|
+
declare function resolveAllBeliefPaths(db: Database): Promise<string[]>;
|
|
1268
1654
|
/**
|
|
1269
1655
|
* Resolve paths to all existing "/goals" directories in the hierarchy,
|
|
1270
1656
|
* sorted from most specific (personal) to most general (org).
|
|
1271
1657
|
*/
|
|
1272
|
-
declare function resolveAllGoalPaths(db: Database): string[]
|
|
1658
|
+
declare function resolveAllGoalPaths(db: Database): Promise<string[]>;
|
|
1273
1659
|
|
|
1274
|
-
export { type ADOConfig, type ADOCredentials, type AgentSkill, type AnalysisResult, type BloomLevel$1 as BloomLevel, type Card, type CardDeletionImpact, type CardState$1 as CardState, type CascadeBlockResult, type CommandRecord, type CommandSequence, type CreateAgentSkillInput, type CreateGoalInput, type CreateReviewInput, type CreateSessionInput, type CreateTokenInput, type Credentials, DEFAULT_REVIEW_CONTEXT_MAX_CHARS, type DeleteCardResult, type DeleteTokenResult, type DiscoveryOptions, type DomainCompetence, type EvaluateInput, type EvaluateResult, type ExecuteReviewActionInput, type ExecutionContext, type FSRSParameters, type Goal, type GoalFrontmatter, type GoalStatus, type GoalSummary, type InstallResult, type LogStepInput, type MonitorEvent, type ObservationRating, type Prerequisite, type PrerequisiteWithToken, type PromptInput, type Rating, type RecallPrompt, type RepoPaths, type ResolvedReference, type ReviewActionResult, type ReviewActionType, type ReviewContext, type ReviewLog, type ReviewQueue, type ReviewQueueItem, type ReviewQueueOptions, type SchedulingCard, type Session, type SessionStep, type SessionSummary, type SkillProposal, type SkillSource, type SupportedLocale, type SymbiosisMode, type SystemProfile, type Token, type TokenDeleteImpact, type TokenPattern, type TranslationKey, type TursoCredentials, type UnblockResult, type UpdateCardInput, type UpdateTokenInput, type UserSetting, type UserStats, type WorkItem, addPrerequisite, analyzeObservation, buildReviewQueue, cascadeBlock, clearADOCredentials, clearTursoCredentials, createAgentSkill, createFSRS, createGoal, createToken, deleteCardForUser, deleteSetting, deleteToken, deprecateToken, detectSystemLocale, discoverSkills, distributeGlobalSkills, endSession, ensureCard, ensureMonitorDir, evaluateRating, executeReviewAction, extractTasks, extractTokenRefs, fetchActiveWorkItems, findTokens, generateBashHooks, generateBashUnhooks, generateConceptFreeCue, generatePowerShellHooks, generatePowerShellUnhooks, generatePrompt, generateZshHooks, generateZshUnhooks, getADOCredentials, getAgentSkill, getAllSettings, getAllSettingsDetailed, getBlockedCards, getCard, getCardById, getCardDeletionImpact, getDefaultDbPath, getDependents, getDomainCompetence, getDueCards, getGoal, getGoalTree, getMonitorDir, getMonitorLogStats, getMonitorPath, getPackageSkillPath, getPrerequisites, getRepoPaths, getReviewsForCard, getReviewsForUser, getSessionSummary, getSetting, getSystemProfile, getTokenById, getTokenBySlug, getTokenDeleteImpact, getTursoCredentials, getUserStats, hasCommand, injectShellHooks, installFastFlowLM, installOllama, interleave, listAgentSkills, listGoals, listTokens, loadADOConfig, loadCredentials, logReview, logStep, matchesFilePath, monitorLogExists, normalizeLocale, normalizePath, openDatabase, openDatabaseWithSync, pairCommands, parseGoalFile, parseMonitorLog, readMonitorLog, resolveAllBeliefPaths, resolveAllGoalPaths, resolveReference, resolveRepoPath, resolveReviewContext, saveCredentials, serializeGoal, setADOCredentials, setSetting, setTursoCredentials, startSession, t, unblockReady, updateCard, updateGoalStatus, updateToken, writeMonitorEvent };
|
|
1660
|
+
export { type ADOConfig, type ADOCredentials, type AgentSkill, type AnalysisResult, type ApplySessionSynthesisInput, type ApplySessionSynthesisResult, type BloomLevel$1 as BloomLevel, type Card, type CardDeletionImpact, type CardState$1 as CardState, type CascadeBlockResult, type CommandRecord, type CommandSequence, type ConnectionOptions, type CreateAgentSkillInput, type CreateGoalInput, type CreateReviewInput, type CreateSessionInput, type CreateTokenInput, type Credentials, DEFAULT_REVIEW_CONTEXT_MAX_CHARS, type Database, type DatabaseProvider, type DatabaseValue, type DeleteCardResult, type DeleteTokenResult, type DiscoveryOptions, type DomainCompetence, type EvaluateInput, type EvaluateResult, type ExecuteReviewActionInput, type ExecutionContext, type FSRSParameters, type Goal, type GoalFrontmatter, type GoalStatus, type GoalSummary, HOMEBREW_CASK, type ImportResult, type InstallChannel, type InstallConfig, type InstallMode, type InstallPlan, type InstallResult, type LocalLLMRunner, type LogStepInput, type MonitorEvent, type Neighborhood, type NeighborhoodToken, type ObservationRating, type PrepareSessionSynthesisInput, type Prerequisite, type PrerequisiteWithToken, type PromptInput, type Rating, type RecallPrompt, type RemoteDatabaseOptions, type RepoPaths, type ResolvedReference, type ReviewActionResult, type ReviewActionType, type ReviewContext, type ReviewLog, type ReviewQueue, type ReviewQueueItem, type ReviewQueueOptions, type RunResult, SNAPSHOT_VERSION, type SchedulingCard, type Session, type SessionStep, type SessionSummary, type SessionSynthesisCandidate, type SessionSynthesisEvidence, type SessionSynthesisPreview, type SessionSynthesisRecord, type SkillProposal, type SkillSource, type SnapshotManifest, type Statement, type SupportedLocale, type SymbiosisMode, type SynthesisConfidence, type SystemProfile, type Token, type TokenDeleteImpact, type TokenPattern, type TranslationKey, type TursoCredentials, type UnblockResult, type UpdateActionKind, type UpdateCardInput, type UpdateDecision, type UpdateTokenInput, type UserSetting, type UserStats, WINGET_PACKAGE_ID, type WorkItem, addPrerequisite, analyzeObservation, applySessionSynthesis, buildReviewQueue, cascadeBlock, clearADOCredentials, clearTursoCredentials, compareVersions, createAgentSkill, createFSRS, createGoal, createToken, decideUpdate, deleteCardForUser, deleteSetting, deleteToken, deprecateToken, detectSyncProvider, detectSystemLocale, discoverSkills, distributeGlobalSkills, endSession, ensureCard, ensureMonitorDir, evaluateRating, executeReviewAction, exportSnapshot, extractTasks, extractTokenRefs, fetchActiveWorkItems, findTokens, generateBashHooks, generateBashUnhooks, generateConceptFreeCue, generatePowerShellHooks, generatePowerShellUnhooks, generatePrompt, generateZshHooks, generateZshUnhooks, getADOCredentials, getAgentSkill, getAllSettings, getAllSettingsDetailed, getBlockedCards, getCard, getCardById, getCardDeletionImpact, getDefaultDbPath, getDependents, getDomainCompetence, getDueCards, getGoal, getGoalTree, getInstallChannel, getInstallMode, getMonitorDir, getMonitorLogStats, getMonitorPath, getPackageSkillPath, getPrerequisites, getRepoPaths, getReviewsForCard, getReviewsForUser, getSessionSummary, getSessionSynthesisRecords, getSetting, getSystemProfile, getTokenById, getTokenBySlug, getTokenDeleteImpact, getTokenNeighborhood, getTursoCredentials, getUserStats, hasCommand, importSnapshot, injectShellHooks, installFastFlowLM, installOllama, installOpenCode, interleave, listAgentSkills, listGoals, listTokens, loadADOConfig, loadCredentials, loadInstallConfig, logReview, logStep, matchesFilePath, monitorLogExists, normalizeLocale, normalizePath, openDatabase, openDatabaseWithSync, openRemoteDatabase, pairCommands, parseGoalFile, parseMonitorLog, parseSnapshot, planOpenCodeInstall, prepareLocalModel, prepareSessionSynthesis, readMonitorLog, resolveAllBeliefPaths, resolveAllGoalPaths, resolveReference, resolveRepoPath, resolveReviewContext, saveCredentials, saveInstallConfig, serializeGoal, setADOCredentials, setInstallChannel, setInstallMode, setSetting, setTursoCredentials, startSession, t, unblockReady, updateCard, updateGoalStatus, updateToken, verifySnapshot, wouldCreateCycle, writeMonitorEvent };
|