@getengram/cli 0.5.1 → 0.6.1

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 (58) hide show
  1. package/dist/commands/exclude.d.ts +4 -0
  2. package/dist/commands/exclude.d.ts.map +1 -0
  3. package/dist/commands/exclude.js +53 -0
  4. package/dist/commands/exclude.js.map +1 -0
  5. package/dist/commands/import.d.ts +1 -12
  6. package/dist/commands/import.d.ts.map +1 -1
  7. package/dist/commands/import.js +4 -21
  8. package/dist/commands/import.js.map +1 -1
  9. package/dist/commands/usage.d.ts.map +1 -1
  10. package/dist/commands/usage.js +13 -2
  11. package/dist/commands/usage.js.map +1 -1
  12. package/dist/commands/vault.d.ts.map +1 -1
  13. package/dist/commands/vault.js +41 -3
  14. package/dist/commands/vault.js.map +1 -1
  15. package/dist/config.d.ts +4 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js.map +1 -1
  18. package/dist/daemon/commands.d.ts +9 -0
  19. package/dist/daemon/commands.d.ts.map +1 -1
  20. package/dist/daemon/commands.js +92 -2
  21. package/dist/daemon/commands.js.map +1 -1
  22. package/dist/daemon/db.d.ts +12 -0
  23. package/dist/daemon/db.d.ts.map +1 -1
  24. package/dist/daemon/db.js +44 -0
  25. package/dist/daemon/db.js.map +1 -1
  26. package/dist/daemon/exclusions.d.ts +14 -0
  27. package/dist/daemon/exclusions.d.ts.map +1 -0
  28. package/dist/daemon/exclusions.js +119 -0
  29. package/dist/daemon/exclusions.js.map +1 -0
  30. package/dist/daemon/parser.d.ts +7 -0
  31. package/dist/daemon/parser.d.ts.map +1 -1
  32. package/dist/daemon/parser.js +82 -5
  33. package/dist/daemon/parser.js.map +1 -1
  34. package/dist/daemon/preflight.d.ts +0 -17
  35. package/dist/daemon/preflight.d.ts.map +1 -1
  36. package/dist/daemon/preflight.js +27 -5
  37. package/dist/daemon/preflight.js.map +1 -1
  38. package/dist/daemon/scrubber.d.ts +74 -0
  39. package/dist/daemon/scrubber.d.ts.map +1 -0
  40. package/dist/daemon/scrubber.js +131 -0
  41. package/dist/daemon/scrubber.js.map +1 -0
  42. package/dist/daemon/status.d.ts +30 -3
  43. package/dist/daemon/status.d.ts.map +1 -1
  44. package/dist/daemon/status.js +92 -15
  45. package/dist/daemon/status.js.map +1 -1
  46. package/dist/daemon/syncer.d.ts +24 -2
  47. package/dist/daemon/syncer.d.ts.map +1 -1
  48. package/dist/daemon/syncer.js +116 -4
  49. package/dist/daemon/syncer.js.map +1 -1
  50. package/dist/daemon/worker-main.js +26 -2
  51. package/dist/daemon/worker-main.js.map +1 -1
  52. package/dist/index.js +74 -3
  53. package/dist/index.js.map +1 -1
  54. package/dist/storage-error.d.ts +23 -0
  55. package/dist/storage-error.d.ts.map +1 -0
  56. package/dist/storage-error.js +32 -0
  57. package/dist/storage-error.js.map +1 -0
  58. package/package.json +2 -2
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Value-exact secret scrubbing for captured transcripts.
3
+ *
4
+ * The problem this solves is structural, not a missing regex. Pattern-based
5
+ * redaction (services/conversation.ts → redact()) catches credentials that
6
+ * have a shape — sk_live_…, postgres://…, PEM blocks. It cannot catch the
7
+ * secrets people actually keep in a vault: a password, a passphrase, a PIN,
8
+ * a licence key, a recovery phrase. Measured on the shipped redactor, 12 of
9
+ * 17 realistic vault contents passed through verbatim. A four-digit PIN is
10
+ * indistinguishable from any other number; no pattern can fix that without
11
+ * destroying the memory it is meant to protect.
12
+ *
13
+ * Zero-knowledge makes it worse for the server specifically: it holds no
14
+ * plaintext vault values, so it can never build an exact denylist. Only the
15
+ * client can — the vault key lives here, and `engram vault get` decrypts on
16
+ * this machine every day. So this is where the exact match belongs.
17
+ *
18
+ * What it does: holds the plaintext of every named vault secret (and the
19
+ * vault key itself) in memory, and replaces exact occurrences in outgoing
20
+ * message content with `[VAULT:name]` before anything is queued. That is the
21
+ * same token form the SDK's resolveSecrets understands, so a recalled memory
22
+ * still reads coherently and can still be resolved by a client with the key.
23
+ *
24
+ * What it never does: write a value to disk, include one in a log line, or
25
+ * send one anywhere. Values are refreshed from the vault on an interval and
26
+ * dropped on stop. The daemon already runs as the user who owns the 0600
27
+ * key file and already holds the API key; this adds no new trust boundary,
28
+ * only closes a leak inside the existing one.
29
+ */
30
+ export interface VaultLike {
31
+ list(): Promise<Array<{
32
+ name: string;
33
+ }>>;
34
+ get(name: string): Promise<string | null>;
35
+ }
36
+ export interface ScrubResult {
37
+ text: string;
38
+ /** Number of replacements made. Names only — never the values. */
39
+ replaced: Array<{
40
+ name: string;
41
+ count: number;
42
+ }>;
43
+ }
44
+ /** Values shorter than this are not scrubbed: too likely to be coincidence. */
45
+ export declare const MIN_SCRUB_LENGTH = 4;
46
+ export declare class SecretScrubber {
47
+ private readonly vault;
48
+ private readonly vaultKey;
49
+ private readonly log;
50
+ /** name → plaintext. The only place plaintext lives, and only in memory. */
51
+ private values;
52
+ private timer;
53
+ constructor(vault: VaultLike | null, vaultKey: string | undefined, log?: (msg: string) => void);
54
+ /** True when there is anything to scrub against. */
55
+ get active(): boolean;
56
+ /** Names currently loaded. Safe to log. */
57
+ get names(): string[];
58
+ /**
59
+ * Load every secret's plaintext. Failures are non-fatal: the previous set
60
+ * stays in force, so a transient network error can never turn scrubbing
61
+ * off silently in the middle of a session.
62
+ */
63
+ refresh(): Promise<void>;
64
+ /** Refresh now and on an interval. */
65
+ start(intervalMs?: number): void;
66
+ stop(): void;
67
+ /**
68
+ * Replace every exact occurrence of a known secret with its token.
69
+ * Longest values first, so a secret that contains another secret is
70
+ * replaced whole rather than leaving a readable fragment behind.
71
+ */
72
+ scrub(text: string): ScrubResult;
73
+ }
74
+ //# sourceMappingURL=scrubber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrubber.d.ts","sourceRoot":"","sources":["../../src/daemon/scrubber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACzC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAED,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,qBAAa,cAAc;IAMvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAPtB,4EAA4E;IAC5E,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,KAAK,CAA+B;gBAGzB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,GAAG,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAe;IAGxD,oDAAoD;IACpD,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,2CAA2C;IAC3C,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC9B,sCAAsC;IACtC,KAAK,CAAC,UAAU,SAAc,GAAG,IAAI;IAMrC,IAAI,IAAI,IAAI;IAOZ;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;CAqBjC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Value-exact secret scrubbing for captured transcripts.
3
+ *
4
+ * The problem this solves is structural, not a missing regex. Pattern-based
5
+ * redaction (services/conversation.ts → redact()) catches credentials that
6
+ * have a shape — sk_live_…, postgres://…, PEM blocks. It cannot catch the
7
+ * secrets people actually keep in a vault: a password, a passphrase, a PIN,
8
+ * a licence key, a recovery phrase. Measured on the shipped redactor, 12 of
9
+ * 17 realistic vault contents passed through verbatim. A four-digit PIN is
10
+ * indistinguishable from any other number; no pattern can fix that without
11
+ * destroying the memory it is meant to protect.
12
+ *
13
+ * Zero-knowledge makes it worse for the server specifically: it holds no
14
+ * plaintext vault values, so it can never build an exact denylist. Only the
15
+ * client can — the vault key lives here, and `engram vault get` decrypts on
16
+ * this machine every day. So this is where the exact match belongs.
17
+ *
18
+ * What it does: holds the plaintext of every named vault secret (and the
19
+ * vault key itself) in memory, and replaces exact occurrences in outgoing
20
+ * message content with `[VAULT:name]` before anything is queued. That is the
21
+ * same token form the SDK's resolveSecrets understands, so a recalled memory
22
+ * still reads coherently and can still be resolved by a client with the key.
23
+ *
24
+ * What it never does: write a value to disk, include one in a log line, or
25
+ * send one anywhere. Values are refreshed from the vault on an interval and
26
+ * dropped on stop. The daemon already runs as the user who owns the 0600
27
+ * key file and already holds the API key; this adds no new trust boundary,
28
+ * only closes a leak inside the existing one.
29
+ */
30
+ /** Values shorter than this are not scrubbed: too likely to be coincidence. */
31
+ export const MIN_SCRUB_LENGTH = 4;
32
+ export class SecretScrubber {
33
+ vault;
34
+ vaultKey;
35
+ log;
36
+ /** name → plaintext. The only place plaintext lives, and only in memory. */
37
+ values = new Map();
38
+ timer = null;
39
+ constructor(vault, vaultKey, log = () => { }) {
40
+ this.vault = vault;
41
+ this.vaultKey = vaultKey;
42
+ this.log = log;
43
+ }
44
+ /** True when there is anything to scrub against. */
45
+ get active() {
46
+ return this.values.size > 0;
47
+ }
48
+ /** Names currently loaded. Safe to log. */
49
+ get names() {
50
+ return [...this.values.keys()];
51
+ }
52
+ /**
53
+ * Load every secret's plaintext. Failures are non-fatal: the previous set
54
+ * stays in force, so a transient network error can never turn scrubbing
55
+ * off silently in the middle of a session.
56
+ */
57
+ async refresh() {
58
+ const next = new Map();
59
+ // The key itself is the most damaging thing to leak, and `engram vault
60
+ // keygen` without --save prints it to the terminal.
61
+ if (this.vaultKey && this.vaultKey.length >= MIN_SCRUB_LENGTH) {
62
+ next.set("vault-key", this.vaultKey);
63
+ }
64
+ if (this.vault) {
65
+ try {
66
+ const entries = await this.vault.list();
67
+ for (const { name } of entries) {
68
+ try {
69
+ const value = await this.vault.get(name);
70
+ if (value && value.length >= MIN_SCRUB_LENGTH)
71
+ next.set(name, value);
72
+ }
73
+ catch {
74
+ // One unreadable secret must not block the rest.
75
+ }
76
+ }
77
+ }
78
+ catch (err) {
79
+ const msg = err instanceof Error ? err.message : String(err);
80
+ this.log(`vault scrubber: refresh failed, keeping previous set (${msg})`);
81
+ if (this.values.size > 0)
82
+ return;
83
+ }
84
+ }
85
+ const before = this.values.size;
86
+ this.values = next;
87
+ if (next.size !== before) {
88
+ this.log(`vault scrubber: protecting ${next.size} secret(s)`);
89
+ }
90
+ }
91
+ /** Refresh now and on an interval. */
92
+ start(intervalMs = 10 * 60_000) {
93
+ void this.refresh();
94
+ this.timer = setInterval(() => void this.refresh(), intervalMs);
95
+ this.timer.unref?.();
96
+ }
97
+ stop() {
98
+ if (this.timer)
99
+ clearInterval(this.timer);
100
+ this.timer = null;
101
+ // Drop plaintext the moment it is no longer needed.
102
+ this.values.clear();
103
+ }
104
+ /**
105
+ * Replace every exact occurrence of a known secret with its token.
106
+ * Longest values first, so a secret that contains another secret is
107
+ * replaced whole rather than leaving a readable fragment behind.
108
+ */
109
+ scrub(text) {
110
+ if (!text || this.values.size === 0)
111
+ return { text, replaced: [] };
112
+ const ordered = [...this.values.entries()].sort((a, b) => b[1].length - a[1].length);
113
+ let out = text;
114
+ const replaced = [];
115
+ for (const [name, value] of ordered) {
116
+ let count = 0;
117
+ let idx = out.indexOf(value);
118
+ if (idx === -1)
119
+ continue;
120
+ const token = `[VAULT:${name}]`;
121
+ while (idx !== -1) {
122
+ out = out.slice(0, idx) + token + out.slice(idx + value.length);
123
+ count++;
124
+ idx = out.indexOf(value, idx + token.length);
125
+ }
126
+ replaced.push({ name, count });
127
+ }
128
+ return { text: out, replaced };
129
+ }
130
+ }
131
+ //# sourceMappingURL=scrubber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrubber.js","sourceRoot":"","sources":["../../src/daemon/scrubber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAaH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,OAAO,cAAc;IAMN;IACA;IACA;IAPnB,4EAA4E;IACpE,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnC,KAAK,GAA0B,IAAI,CAAC;IAE5C,YACmB,KAAuB,EACvB,QAA4B,EAC5B,MAA6B,GAAG,EAAE,GAAE,CAAC;QAFrC,UAAK,GAAL,KAAK,CAAkB;QACvB,aAAQ,GAAR,QAAQ,CAAoB;QAC5B,QAAG,GAAH,GAAG,CAAkC;IACrD,CAAC;IAEJ,oDAAoD;IACpD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,2CAA2C;IAC3C,IAAI,KAAK;QACP,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;QAEvC,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,gBAAgB,EAAE,CAAC;YAC9D,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,CAAC;gBACH,MAAM,O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AAG,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YAC/C,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF"}
@@ -1,21 +1,48 @@
1
1
  export type SyncHealth = "healthy" | "warning" | "error";
2
+ export type SyncErrorType = "auth"
3
+ /** Lifetime memory is full. Distinct from `billing`: retrying will never
4
+ * succeed on its own — it needs an upgrade or deleted conversations. */
5
+ | "storage_full" | "billing" | "rate_limit" | "network" | "server";
2
6
  export interface SyncStatus {
3
7
  health: SyncHealth;
4
8
  last_sync_at: string | null;
5
9
  last_error_at: string | null;
6
10
  last_error: string | null;
7
- error_type: "auth" | "billing" | "rate_limit" | "network" | "server" | null;
11
+ error_type: SyncErrorType | null;
8
12
  pending_messages: number;
9
13
  consecutive_failures: number;
14
+ /** Populated on a storage_full error so the numbers can be shown without
15
+ * a network round trip (the CLI may be offline when it surfaces them). */
16
+ storage: {
17
+ used: number;
18
+ limit: number;
19
+ } | null;
10
20
  updated_at: string;
11
21
  }
12
22
  export declare function readStatus(): SyncStatus;
13
23
  /** Record a successful sync. */
14
24
  export declare function recordSuccess(pendingMessages: number): void;
15
- /** Record a sync failure. Sends a desktop notification on first occurrence. */
16
- export declare function recordFailure(error: string, errorType: SyncStatus["error_type"], pendingMessages: number): void;
25
+ /**
26
+ * Record a sync failure. Logs once per error type and, for the two states
27
+ * the user must act on (auth, storage_full), raises a desktop notification
28
+ * on first occurrence — the daemon is headless, so a line in daemon.log is
29
+ * not "telling" anyone.
30
+ */
31
+ export declare function recordFailure(error: string, errorType: SyncStatus["error_type"], pendingMessages: number, storage?: {
32
+ used?: number;
33
+ limit?: number;
34
+ } | null): void;
17
35
  /** Update pending count without changing health. */
18
36
  export declare function updatePending(count: number): void;
19
37
  declare function classifyError(message: string): SyncStatus["error_type"];
20
38
  export { classifyError };
39
+ /**
40
+ * One-line summary of a sync error, in the second person. Shared by the
41
+ * daemon log, the desktop notification, and the banner the CLI prints on
42
+ * the next interactive command.
43
+ */
44
+ export declare function syncErrorSummary(errorType: SyncStatus["error_type"], storage?: {
45
+ used: number;
46
+ limit: number;
47
+ } | null): string;
21
48
  //# sourceMappingURL=status.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/daemon/status.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAEzD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC;IAC5E,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB;AAgBD,wBAAgB,UAAU,IAAI,UAAU,CASvC;AAWD,gCAAgC;AAChC,wBAAgB,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAU3D;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,UAAU,CAAC,YAAY,CAAC,EACnC,eAAe,EAAE,MAAM,GACtB,IAAI,CAuBN;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGjD;AAED,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC,CAchE;AAED,OA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U,CAAC,YAAY,CAAC,CAoBhE;AAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAIzB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,UAAU,CAAC,YAAY,CAAC,EACnC,OAAO,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAC/C,MAAM,CAsBR"}
@@ -10,6 +10,7 @@ const DEFAULT_STATUS = {
10
10
  error_type: null,
11
11
  pending_messages: 0,
12
12
  consecutive_failures: 0,
13
+ storage: null,
13
14
  updated_at: new Date().toISOString(),
14
15
  };
15
16
  let currentStatus = { ...DEFAULT_STATUS };
@@ -17,7 +18,13 @@ let lastNotifiedError = null;
17
18
  export function readStatus() {
18
19
  try {
19
20
  if (existsSync(STATUS_FILE)) {
20
- return JSON.parse(readFileSync(STATUS_FILE, "utf-8"));
21
+ // Merged over the defaults: a status.json written by an older CLI
22
+ // predates newer fields, and callers should get null rather than
23
+ // undefined for them.
24
+ return {
25
+ ...DEFAULT_STATUS,
26
+ ...JSON.parse(readFileSync(STATUS_FILE, "utf-8")),
27
+ };
21
28
  }
22
29
  }
23
30
  catch {
@@ -43,18 +50,29 @@ export function recordSuccess(pendingMessages) {
43
50
  currentStatus.error_type = null;
44
51
  currentStatus.pending_messages = pendingMessages;
45
52
  currentStatus.consecutive_failures = 0;
53
+ currentStatus.storage = null;
46
54
  lastNotifiedError = null;
47
55
  writeStatus();
48
56
  }
49
- /** Record a sync failure. Sends a desktop notification on first occurrence. */
50
- export function recordFailure(error, errorType, pendingMessages) {
57
+ /**
58
+ * Record a sync failure. Logs once per error type and, for the two states
59
+ * the user must act on (auth, storage_full), raises a desktop notification
60
+ * on first occurrence — the daemon is headless, so a line in daemon.log is
61
+ * not "telling" anyone.
62
+ */
63
+ export function recordFailure(error, errorType, pendingMessages, storage) {
51
64
  currentStatus.consecutive_failures++;
52
65
  currentStatus.last_error = error;
53
66
  currentStatus.last_error_at = new Date().toISOString();
54
67
  currentStatus.error_type = errorType;
55
68
  currentStatus.pending_messages = pendingMessages;
69
+ if (errorType === "storage_full" &&
70
+ typeof storage?.used === "number" &&
71
+ typeof storage?.limit === "number") {
72
+ currentStatus.storage = { used: storage.used, limit: storage.limit };
73
+ }
56
74
  // Escalate health based on severity and consecutive failures
57
- if (errorType === "auth" || errorType === "billing") {
75
+ if (errorType === "auth" || errorType === "billing" || errorType === "storage_full") {
58
76
  currentStatus.health = "error";
59
77
  }
60
78
  else if (currentStatus.consecutive_failures >= 5) {
@@ -67,7 +85,10 @@ export function recordFailure(error, errorType, pendingMessages) {
67
85
  // Log once per error type (not per unique message) to avoid spam
68
86
  if (errorType !== lastNotifiedError) {
69
87
  lastNotifiedError = errorType;
70
- logWarning(errorType);
88
+ logWarning(errorType, currentStatus.storage);
89
+ if (errorType === "auth" || errorType === "storage_full") {
90
+ notifyDesktop(errorType, currentStatus.storage);
91
+ }
71
92
  }
72
93
  }
73
94
  /** Update pending count without changing health. */
@@ -79,6 +100,12 @@ function classifyError(message) {
79
100
  if (message.includes("401") || message.includes("403") || message.includes("Authentication")) {
80
101
  return "auth";
81
102
  }
103
+ // Must precede the generic billing check: a storage_full body also carries
104
+ // a 402, but it is a different situation — backing off and retrying can
105
+ // never clear it, so it gets its own state and its own copy.
106
+ if (message.includes("storage_full")) {
107
+ return "storage_full";
108
+ }
82
109
  if (message.includes("402") || message.includes("limit_exceeded") || message.includes("billing")) {
83
110
  return "billing";
84
111
  }
@@ -91,17 +118,67 @@ function classifyError(message) {
91
118
  return "network";
92
119
  }
93
120
  export { classifyError };
121
+ const n = (x) => x.toLocaleString("en-US");
122
+ /**
123
+ * One-line summary of a sync error, in the second person. Shared by the
124
+ * daemon log, the desktop notification, and the banner the CLI prints on
125
+ * the next interactive command.
126
+ */
127
+ export function syncErrorSummary(errorType, storage) {
128
+ switch (errorType) {
129
+ case "auth":
130
+ return "Authentication failed — run 'engram auth login'.";
131
+ case "storage_full": {
132
+ const size = storage ? `${n(storage.used)}/${n(storage.limit)} messages` : "its limit";
133
+ return (`Engram's memory is full (${size}). Everything already saved is safe and ` +
134
+ `searchable — but new captures are queued locally and will NOT be saved ` +
135
+ `until you free space. Upgrade ($9/mo for 1,000,000 messages) or delete ` +
136
+ `old conversations: https://getengram.app/pricing`);
137
+ }
138
+ case "billing":
139
+ return "Plan limit reached — upgrade at https://getengram.app/pricing. Messages are queued locally and will retry with backoff.";
140
+ case "rate_limit":
141
+ return "Rate limited — messages queued, will retry.";
142
+ case "server":
143
+ return "Server error — messages queued, will retry.";
144
+ default:
145
+ return "Can't reach servers — messages queued locally.";
146
+ }
147
+ }
94
148
  /** Log a warning to stderr (goes to daemon.log). One line per error type. */
95
- function logWarning(errorType) {
96
- const warnings = {
97
- auth: "Authentication failed — run 'engram auth login'",
98
- billing: "Plan limit reached — upgrade at https://getengram.app/pricing. Messages are queued locally and will retry with backoff.",
99
- rate_limit: "Rate limited — messages queued, will retry",
100
- network: "Can't reach servers — messages queued locally",
101
- server: "Server error — messages queued, will retry",
102
- };
103
- const msg = warnings[errorType ?? "network"] ?? "Unknown sync error";
104
- console.error(`[engram] WARNING: ${msg}`);
149
+ function logWarning(errorType, storage) {
150
+ console.error(`[engram] WARNING: ${syncErrorSummary(errorType, storage)}`);
105
151
  console.error(`[engram] Run 'engram status' for details.`);
106
152
  }
153
+ /**
154
+ * Best-effort desktop notification. The daemon runs headless under launchd,
155
+ * so stderr goes to daemon.log where nobody reads it — for states that need
156
+ * a human decision, this is the only channel that actually reaches them.
157
+ *
158
+ * Deliberately fire-and-forget and fully swallowed: notification tooling is
159
+ * absent on plenty of systems (headless Linux, minimal containers) and a
160
+ * failure to notify must never disturb syncing.
161
+ */
162
+ function notifyDesktop(errorType, storage) {
163
+ const title = errorType === "storage_full" ? "Engram memory is full" : "Engram needs attention";
164
+ const body = errorType === "storage_full" && storage
165
+ ? `${n(storage.used)}/${n(storage.limit)} messages used. New captures are paused.`
166
+ : syncErrorSummary(errorType, storage).slice(0, 180);
167
+ try {
168
+ // Lazy require: keeps the module import-light for the daemon bootstrap,
169
+ // which deliberately avoids pulling in anything heavy at startup.
170
+ const { execFile } = require("node:child_process");
171
+ const done = () => { };
172
+ if (process.platform === "darwin") {
173
+ const esc = (s) => s.replace(/["\\]/g, "\\$&");
174
+ execFile("osascript", ["-e", `display notification "${esc(body)}" with title "${esc(title)}"`], done);
175
+ }
176
+ else if (process.platform === "linux") {
177
+ execFile("notify-send", [title, body], done);
178
+ }
179
+ }
180
+ catch {
181
+ // no notification tooling — the log line and the CLI banner still stand
182
+ }
183
+ }
107
184
  //# sourceMappingURL=status.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/daemon/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AAe9D,MAAM,cAAc,GAAe;IACjC,MAAM,EAAE,SAAS;IACjB,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,gBAAgB,EAAE,CAAC;IACnB,oBAAoB,EAAE,CAAC;IACvB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;CACrC,CAAC;AAEF,IAAI,aAAa,GAAe,EAAE,GAAG,cAAc,EAAE,CAAC;AACtD,IAAI,iBAAiB,GAAkB,IAAI,CAAC;AAE5C,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC;QACH,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,Y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oBAAoB,CAAwC,CAAC;QAC1F,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QACtB,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAClC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACvD,QAAQ,CACN,WAAW,EACX,CAAC,IAAI,EAAE,yBAAyB,GAAG,CAAC,IAAI,CAAC,iBAAiB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EACxE,IAAI,CACL,CAAC;QACJ,CAAC;aAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACxC,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;AACH,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { Engram } from "@getengram/sdk";
2
2
  import { DaemonDb } from "./db.js";
3
+ import type { SecretScrubber } from "./scrubber.js";
3
4
  import type { ParsedMessage, SessionMeta } from "./types.js";
4
5
  /**
5
6
  * Batches parsed messages and sends them to the Engram API.
@@ -7,6 +8,7 @@ import type { ParsedMessage, SessionMeta } from "./types.js";
7
8
  * on the next flush cycle.
8
9
  */
9
10
  export declare class Syncer {
11
+ private readonly scrubber;
10
12
  private db;
11
13
  private client;
12
14
  private timer;
@@ -17,13 +19,24 @@ export declare class Syncer {
17
19
  private billingBackoffStep;
18
20
  /** Sessions awaiting conversation creation (deferred from parse time). */
19
21
  private pendingSessions;
20
- constructor(db: DaemonDb, client: Engram);
22
+ constructor(db: DaemonDb, client: Engram, scrubber?: SecretScrubber | null);
21
23
  /**
22
24
  * Called by the parser when new messages are ready for a session.
23
25
  * Queues messages locally; conversation creation is deferred to flush time
24
26
  * to avoid blocking the parser on network calls.
25
27
  */
26
28
  onMessages(sessionId: string, meta: SessionMeta, messages: ParsedMessage[]): Promise<void>;
29
+ /**
30
+ * The user said not to save this session. Semantics are "this session was
31
+ * never captured": stop future capture, wipe the local queue, and delete
32
+ * whatever already reached the server. The remote delete is persisted in
33
+ * excluded_sessions.delete_pending and retried from the flush loop until
34
+ * it succeeds — offline opt-out must still stick.
35
+ */
36
+ private excludeSession;
37
+ /** Delete server-side conversations for opted-out sessions; keeps
38
+ * delete_pending until the server confirms. */
39
+ private retryRemoteDeletes;
27
40
  startFlushLoop(): void;
28
41
  stopFlushLoop(): void;
29
42
  /** Flush all pending messages to the API. */
@@ -35,7 +48,16 @@ export declare class Syncer {
35
48
  * to the full batch on the next success). */
36
49
  private batchOverride;
37
50
  private flushConversation;
38
- /** Enter billing backoff — escalates each time: 5min → 15min → 1hr */
51
+ /**
52
+ * Enter billing backoff — escalates each time: 5min → 15min → 1hr.
53
+ *
54
+ * A full memory is separated out here. It arrives as a 402 like any other
55
+ * billing error, but retrying can never clear it on its own: it needs an
56
+ * upgrade or deleted conversations. It gets its own status state (so the
57
+ * CLI can say "memory is full" rather than "plan limit reached") and its
58
+ * used/limit numbers are carried through, so the banner can name them
59
+ * even when the machine is offline.
60
+ */
39
61
  private enterBillingBackoff;
40
62
  /** Reset billing backoff after a successful sync. */
41
63
  private resetBillingBackoff;
@@ -1 +1 @@
1
- {"version":3,"file":"syncer.d.ts","sourceRoot":"","sources":["../../src/daemon/syncer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAc,MAAM,YAAY,CAAC;AAqBzE;;;;GAIG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,EAAE,CAAW;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAA+C;I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