@getengram/cli 0.1.1 → 0.2.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.
- package/dist/commands/log.d.ts +8 -0
- package/dist/commands/log.d.ts.map +1 -0
- package/dist/commands/log.js +55 -0
- package/dist/commands/log.js.map +1 -0
- package/dist/daemon/commands.d.ts +6 -0
- package/dist/daemon/commands.d.ts.map +1 -0
- package/dist/daemon/commands.js +265 -0
- package/dist/daemon/commands.js.map +1 -0
- package/dist/daemon/db.d.ts +30 -0
- package/dist/daemon/db.d.ts.map +1 -0
- package/dist/daemon/db.js +141 -0
- package/dist/daemon/db.js.map +1 -0
- package/dist/daemon/index.d.ts +2 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +2 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/daemon/parser.d.ts +25 -0
- package/dist/daemon/parser.d.ts.map +1 -0
- package/dist/daemon/parser.js +168 -0
- package/dist/daemon/parser.js.map +1 -0
- package/dist/daemon/status.d.ts +21 -0
- package/dist/daemon/status.d.ts.map +1 -0
- package/dist/daemon/status.js +107 -0
- package/dist/daemon/status.js.map +1 -0
- package/dist/daemon/syncer.d.ts +40 -0
- package/dist/daemon/syncer.d.ts.map +1 -0
- package/dist/daemon/syncer.js +220 -0
- package/dist/daemon/syncer.js.map +1 -0
- package/dist/daemon/types.d.ts +36 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/daemon/types.js +2 -0
- package/dist/daemon/types.js.map +1 -0
- package/dist/daemon/watcher.d.ts +18 -0
- package/dist/daemon/watcher.d.ts.map +1 -0
- package/dist/daemon/watcher.js +100 -0
- package/dist/daemon/watcher.js.map +1 -0
- package/dist/daemon/worker.d.ts +7 -0
- package/dist/daemon/worker.d.ts.map +1 -0
- package/dist/daemon/worker.js +83 -0
- package/dist/daemon/worker.js.map +1 -0
- package/dist/index.js +36 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Line types we skip entirely
|
|
2
|
+
const SKIP_TYPES = new Set([
|
|
3
|
+
"file-history-snapshot",
|
|
4
|
+
"progress",
|
|
5
|
+
"queue-operation",
|
|
6
|
+
"last-prompt",
|
|
7
|
+
]);
|
|
8
|
+
/**
|
|
9
|
+
* Parses Claude Code JSONL transcript lines into Engram messages.
|
|
10
|
+
*
|
|
11
|
+
* Claude Code writes one line per content block, so a single assistant
|
|
12
|
+
* response may span multiple lines sharing the same `message.id`. We
|
|
13
|
+
* accumulate blocks and flush when the message is complete (stop_reason
|
|
14
|
+
* is set) or a new message begins.
|
|
15
|
+
*/
|
|
16
|
+
export class Parser {
|
|
17
|
+
pending = null;
|
|
18
|
+
lastSessionId = null;
|
|
19
|
+
lastMeta = null;
|
|
20
|
+
onMessages;
|
|
21
|
+
constructor(onMessages) {
|
|
22
|
+
this.onMessages = onMessages;
|
|
23
|
+
}
|
|
24
|
+
processLine(line, filePath) {
|
|
25
|
+
let data;
|
|
26
|
+
try {
|
|
27
|
+
data = JSON.parse(line);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return; // malformed line, skip
|
|
31
|
+
}
|
|
32
|
+
// Skip noise
|
|
33
|
+
if (SKIP_TYPES.has(data.type))
|
|
34
|
+
return;
|
|
35
|
+
if (data.type === "system" && data.subtype)
|
|
36
|
+
return; // turn_duration etc.
|
|
37
|
+
// Extract session metadata
|
|
38
|
+
const sessionId = data.sessionId;
|
|
39
|
+
if (!sessionId)
|
|
40
|
+
return;
|
|
41
|
+
const projectDir = this.extractProjectDir(filePath);
|
|
42
|
+
const meta = {
|
|
43
|
+
sessionId,
|
|
44
|
+
cwd: data.cwd,
|
|
45
|
+
gitBranch: data.gitBranch,
|
|
46
|
+
projectDir,
|
|
47
|
+
version: data.version,
|
|
48
|
+
};
|
|
49
|
+
this.lastSessionId = sessionId;
|
|
50
|
+
this.lastMeta = meta;
|
|
51
|
+
if (!data.message)
|
|
52
|
+
return;
|
|
53
|
+
if (data.type === "user") {
|
|
54
|
+
// Flush any pending assistant message first
|
|
55
|
+
this.flushPending();
|
|
56
|
+
this.processUserLine(sessionId, meta, data);
|
|
57
|
+
}
|
|
58
|
+
else if (data.type === "assistant") {
|
|
59
|
+
this.processAssistantLine(sessionId, meta, data);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Flush any remaining accumulated assistant message. */
|
|
63
|
+
flush() {
|
|
64
|
+
this.flushPending();
|
|
65
|
+
}
|
|
66
|
+
processUserLine(sessionId, meta, data) {
|
|
67
|
+
const content = data.message.content;
|
|
68
|
+
if (typeof content === "string") {
|
|
69
|
+
// Plain user text
|
|
70
|
+
if (content.trim()) {
|
|
71
|
+
this.onMessages(sessionId, meta, [
|
|
72
|
+
{ role: "user", content },
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Array content — could contain tool_result blocks
|
|
78
|
+
if (!Array.isArray(content))
|
|
79
|
+
return;
|
|
80
|
+
const messages = [];
|
|
81
|
+
for (const block of content) {
|
|
82
|
+
if (block.type === "tool_result") {
|
|
83
|
+
const text = typeof block.content === "string"
|
|
84
|
+
? block.content
|
|
85
|
+
: JSON.stringify(block.content ?? "");
|
|
86
|
+
if (text.trim()) {
|
|
87
|
+
messages.push({
|
|
88
|
+
role: "tool",
|
|
89
|
+
content: text,
|
|
90
|
+
toolCallId: block.tool_use_id,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (messages.length > 0) {
|
|
96
|
+
this.onMessages(sessionId, meta, messages);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
processAssistantLine(sessionId, meta, data) {
|
|
100
|
+
const msg = data.message;
|
|
101
|
+
const messageId = msg.id ?? "";
|
|
102
|
+
const content = msg.content;
|
|
103
|
+
// If this is a new message ID, flush the previous one
|
|
104
|
+
if (this.pending && this.pending.messageId !== messageId) {
|
|
105
|
+
this.flushPending();
|
|
106
|
+
}
|
|
107
|
+
// Initialize accumulator if needed
|
|
108
|
+
if (!this.pending) {
|
|
109
|
+
this.pending = { messageId, textParts: [], toolUses: [] };
|
|
110
|
+
}
|
|
111
|
+
// Accumulate content blocks
|
|
112
|
+
if (typeof content === "string") {
|
|
113
|
+
if (content.trim()) {
|
|
114
|
+
this.pending.textParts.push(content);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (Array.isArray(content)) {
|
|
118
|
+
for (const block of content) {
|
|
119
|
+
if (block.type === "text" && block.text?.trim()) {
|
|
120
|
+
this.pending.textParts.push(block.text);
|
|
121
|
+
}
|
|
122
|
+
else if (block.type === "tool_use" && block.name) {
|
|
123
|
+
this.pending.toolUses.push({
|
|
124
|
+
name: block.name,
|
|
125
|
+
input: block.input,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Skip thinking blocks — internal reasoning, not conversation
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// If stop_reason is set, message is complete
|
|
132
|
+
if (msg.stop_reason) {
|
|
133
|
+
this.flushPending();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
flushPending() {
|
|
137
|
+
if (!this.pending || !this.lastSessionId || !this.lastMeta)
|
|
138
|
+
return;
|
|
139
|
+
const { textParts, toolUses } = this.pending;
|
|
140
|
+
const messages = [];
|
|
141
|
+
// Emit text content as assistant message
|
|
142
|
+
const text = textParts.join("\n\n").trim();
|
|
143
|
+
if (text) {
|
|
144
|
+
const metadata = toolUses.length > 0
|
|
145
|
+
? { tools_used: toolUses.map((t) => t.name) }
|
|
146
|
+
: undefined;
|
|
147
|
+
messages.push({ role: "assistant", content: text, metadata });
|
|
148
|
+
}
|
|
149
|
+
if (messages.length > 0) {
|
|
150
|
+
this.onMessages(this.lastSessionId, this.lastMeta, messages);
|
|
151
|
+
}
|
|
152
|
+
this.pending = null;
|
|
153
|
+
}
|
|
154
|
+
extractProjectDir(filePath) {
|
|
155
|
+
// ~/.claude/projects/-Users-op-code-engram/session.jsonl
|
|
156
|
+
// We want "engram" from the project dir name
|
|
157
|
+
const parts = filePath.split("/");
|
|
158
|
+
const projectsIdx = parts.indexOf("projects");
|
|
159
|
+
if (projectsIdx >= 0 && projectsIdx + 1 < parts.length) {
|
|
160
|
+
const dirName = parts[projectsIdx + 1];
|
|
161
|
+
// Take the last segment of the hyphenated path
|
|
162
|
+
const segments = dirName.split("-").filter(Boolean);
|
|
163
|
+
return segments[segments.length - 1] ?? dirName;
|
|
164
|
+
}
|
|
165
|
+
return "unknown";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/daemon/parser.ts"],"names":[],"mappings":"AAEA,8BAA8B;AAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,uBAAuB;IACvB,UAAU;IACV,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC;AAyCH;;;;;;;GAOG;AACH,MAAM,OAAO,MAAM;IACT,OAAO,GAA4B,IAAI,CAAC;IACxC,aAAa,GAAkB,IAAI,CAAC;IACpC,QAAQ,GAAuB,IAAI,CAAC;IACpC,UAAU,CAAa;IAE/B,YAAY,UAAsB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,QAAgB;QACxC,IAAI,IAAe,CAAC;QACpB,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,uBAAuB;QACjC,CAAC;QAED,aAAa;QACb,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,C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YACpD,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC;QAClD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type SyncHealth = "healthy" | "warning" | "error";
|
|
2
|
+
export interface SyncStatus {
|
|
3
|
+
health: SyncHealth;
|
|
4
|
+
last_sync_at: string | null;
|
|
5
|
+
last_error_at: string | null;
|
|
6
|
+
last_error: string | null;
|
|
7
|
+
error_type: "auth" | "billing" | "rate_limit" | "network" | "server" | null;
|
|
8
|
+
pending_messages: number;
|
|
9
|
+
consecutive_failures: number;
|
|
10
|
+
updated_at: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function readStatus(): SyncStatus;
|
|
13
|
+
/** Record a successful sync. */
|
|
14
|
+
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;
|
|
17
|
+
/** Update pending count without changing health. */
|
|
18
|
+
export declare function updatePending(count: number): void;
|
|
19
|
+
declare function classifyError(message: string): SyncStatus["error_type"];
|
|
20
|
+
export { classifyError };
|
|
21
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +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,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
const STATUS_FILE = join(homedir(), ".engram", "status.json");
|
|
5
|
+
const DEFAULT_STATUS = {
|
|
6
|
+
health: "healthy",
|
|
7
|
+
last_sync_at: null,
|
|
8
|
+
last_error_at: null,
|
|
9
|
+
last_error: null,
|
|
10
|
+
error_type: null,
|
|
11
|
+
pending_messages: 0,
|
|
12
|
+
consecutive_failures: 0,
|
|
13
|
+
updated_at: new Date().toISOString(),
|
|
14
|
+
};
|
|
15
|
+
let currentStatus = { ...DEFAULT_STATUS };
|
|
16
|
+
let lastNotifiedError = null;
|
|
17
|
+
export function readStatus() {
|
|
18
|
+
try {
|
|
19
|
+
if (existsSync(STATUS_FILE)) {
|
|
20
|
+
return JSON.parse(readFileSync(STATUS_FILE, "utf-8"));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// corrupt or missing
|
|
25
|
+
}
|
|
26
|
+
return { ...DEFAULT_STATUS };
|
|
27
|
+
}
|
|
28
|
+
function writeStatus() {
|
|
29
|
+
currentStatus.updated_at = new Date().toISOString();
|
|
30
|
+
try {
|
|
31
|
+
writeFileSync(STATUS_FILE, JSON.stringify(currentStatus, null, 2));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// best effort
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Record a successful sync. */
|
|
38
|
+
export function recordSuccess(pendingMessages) {
|
|
39
|
+
currentStatus.health = "healthy";
|
|
40
|
+
currentStatus.last_sync_at = new Date().toISOString();
|
|
41
|
+
currentStatus.last_error = null;
|
|
42
|
+
currentStatus.last_error_at = null;
|
|
43
|
+
currentStatus.error_type = null;
|
|
44
|
+
currentStatus.pending_messages = pendingMessages;
|
|
45
|
+
currentStatus.consecutive_failures = 0;
|
|
46
|
+
lastNotifiedError = null;
|
|
47
|
+
writeStatus();
|
|
48
|
+
}
|
|
49
|
+
/** Record a sync failure. Sends a desktop notification on first occurrence. */
|
|
50
|
+
export function recordFailure(error, errorType, pendingMessages) {
|
|
51
|
+
currentStatus.consecutive_failures++;
|
|
52
|
+
currentStatus.last_error = error;
|
|
53
|
+
currentStatus.last_error_at = new Date().toISOString();
|
|
54
|
+
currentStatus.error_type = errorType;
|
|
55
|
+
currentStatus.pending_messages = pendingMessages;
|
|
56
|
+
// Escalate health based on severity and consecutive failures
|
|
57
|
+
if (errorType === "auth" || errorType === "billing") {
|
|
58
|
+
currentStatus.health = "error";
|
|
59
|
+
}
|
|
60
|
+
else if (currentStatus.consecutive_failures >= 5) {
|
|
61
|
+
currentStatus.health = "error";
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
currentStatus.health = "warning";
|
|
65
|
+
}
|
|
66
|
+
writeStatus();
|
|
67
|
+
// Log once per error type (not per unique message) to avoid spam
|
|
68
|
+
if (errorType !== lastNotifiedError) {
|
|
69
|
+
lastNotifiedError = errorType;
|
|
70
|
+
logWarning(errorType);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Update pending count without changing health. */
|
|
74
|
+
export function updatePending(count) {
|
|
75
|
+
currentStatus.pending_messages = count;
|
|
76
|
+
writeStatus();
|
|
77
|
+
}
|
|
78
|
+
function classifyError(message) {
|
|
79
|
+
if (message.includes("401") || message.includes("403") || message.includes("Authentication")) {
|
|
80
|
+
return "auth";
|
|
81
|
+
}
|
|
82
|
+
if (message.includes("402") || message.includes("limit_exceeded") || message.includes("billing")) {
|
|
83
|
+
return "billing";
|
|
84
|
+
}
|
|
85
|
+
if (message.includes("429") || message.includes("rate")) {
|
|
86
|
+
return "rate_limit";
|
|
87
|
+
}
|
|
88
|
+
if (message.includes("5") && /\b5\d{2}\b/.test(message)) {
|
|
89
|
+
return "server";
|
|
90
|
+
}
|
|
91
|
+
return "network";
|
|
92
|
+
}
|
|
93
|
+
export { classifyError };
|
|
94
|
+
/** 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}`);
|
|
105
|
+
console.error(`[engram] Run 'engram status' for details.`);
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/daemon/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aA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,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Engram } from "@getengram/sdk";
|
|
2
|
+
import { DaemonDb } from "./db.js";
|
|
3
|
+
import type { ParsedMessage, SessionMeta } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Batches parsed messages and sends them to the Engram API.
|
|
6
|
+
* If offline, messages sit in the SQLite queue and are retried
|
|
7
|
+
* on the next flush cycle.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Syncer {
|
|
10
|
+
private db;
|
|
11
|
+
private client;
|
|
12
|
+
private timer;
|
|
13
|
+
private flushing;
|
|
14
|
+
private authFailed;
|
|
15
|
+
/** Billing backoff state */
|
|
16
|
+
private billingBackoffUntil;
|
|
17
|
+
private billingBackoffStep;
|
|
18
|
+
/** Sessions awaiting conversation creation (deferred from parse time). */
|
|
19
|
+
private pendingSessions;
|
|
20
|
+
constructor(db: DaemonDb, client: Engram);
|
|
21
|
+
/**
|
|
22
|
+
* Called by the parser when new messages are ready for a session.
|
|
23
|
+
* Queues messages locally; conversation creation is deferred to flush time
|
|
24
|
+
* to avoid blocking the parser on network calls.
|
|
25
|
+
*/
|
|
26
|
+
onMessages(sessionId: string, meta: SessionMeta, messages: ParsedMessage[]): Promise<void>;
|
|
27
|
+
startFlushLoop(): void;
|
|
28
|
+
stopFlushLoop(): void;
|
|
29
|
+
/** Flush all pending messages to the API. */
|
|
30
|
+
flush(): Promise<void>;
|
|
31
|
+
/** Create conversations for sessions that were deferred during parsing. */
|
|
32
|
+
private createPendingConversations;
|
|
33
|
+
private flushConversation;
|
|
34
|
+
/** Enter billing backoff — escalates each time: 5min → 15min → 1hr */
|
|
35
|
+
private enterBillingBackoff;
|
|
36
|
+
/** Reset billing backoff after a successful sync. */
|
|
37
|
+
private resetBillingBackoff;
|
|
38
|
+
private createConversation;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=syncer.d.ts.map
|
|
@@ -0,0 +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;AAazE;;;;GAIG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,EAAE,CAAW;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAA+C;IAC5D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAE3B,4BAA4B;IAC5B,OAAO,CAAC,mBAAmB,CAAa;IACxC,OAAO,CAAC,kBAAkB,CAAa;IAEvC,0EAA0E;IAC1E,OAAO,CAAC,eAAe,CAGnB;gBAEQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM;IAKxC;;;;OAIG;IACG,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,aAAa,EAAE,GACxB,OAAO,CAAC,IAAI,CAAC;IAchB,cAAc,IAAI,IAAI;IAItB,aAAa,IAAI,IAAI;IAOrB,6CAA6C;IACvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8C5B,2EAA2E;YAC7D,0BAA0B;YA8C1B,iBAAiB;IAoC/B,sEAAsE;IACtE,OAAO,CAAC,mBAAmB;IAc3B,qDAAqD;IACrD,OAAO,CAAC,mBAAmB;YAQb,kBAAkB;CA2BjC"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { recordSuccess, recordFailure, classifyError } from "./status.js";
|
|
2
|
+
const BATCH_SIZE = 200;
|
|
3
|
+
const FLUSH_INTERVAL_MS = 2_000;
|
|
4
|
+
const CONCURRENCY = 5;
|
|
5
|
+
/** Backoff schedule for billing/limit errors: 5min → 15min → 1hr → 1hr ... */
|
|
6
|
+
const BILLING_BACKOFF_MS = [
|
|
7
|
+
5 * 60_000, // 5 minutes
|
|
8
|
+
15 * 60_000, // 15 minutes
|
|
9
|
+
60 * 60_000, // 1 hour (cap)
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* Batches parsed messages and sends them to the Engram API.
|
|
13
|
+
* If offline, messages sit in the SQLite queue and are retried
|
|
14
|
+
* on the next flush cycle.
|
|
15
|
+
*/
|
|
16
|
+
export class Syncer {
|
|
17
|
+
db;
|
|
18
|
+
client;
|
|
19
|
+
timer = null;
|
|
20
|
+
flushing = false;
|
|
21
|
+
authFailed = false;
|
|
22
|
+
/** Billing backoff state */
|
|
23
|
+
billingBackoffUntil = 0;
|
|
24
|
+
billingBackoffStep = 0;
|
|
25
|
+
/** Sessions awaiting conversation creation (deferred from parse time). */
|
|
26
|
+
pendingSessions = new Map();
|
|
27
|
+
constructor(db, client) {
|
|
28
|
+
this.db = db;
|
|
29
|
+
this.client = client;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Called by the parser when new messages are ready for a session.
|
|
33
|
+
* Queues messages locally; conversation creation is deferred to flush time
|
|
34
|
+
* to avoid blocking the parser on network calls.
|
|
35
|
+
*/
|
|
36
|
+
async onMessages(sessionId, meta, messages) {
|
|
37
|
+
// Check if we already have a mapping
|
|
38
|
+
let conversationId = this.db.getConversationId(sessionId);
|
|
39
|
+
if (!conversationId) {
|
|
40
|
+
// Defer creation — store messages under the sessionId temporarily.
|
|
41
|
+
// The flush loop will create the conversation and re-map them.
|
|
42
|
+
this.pendingSessions.set(sessionId, meta);
|
|
43
|
+
conversationId = `pending:${sessionId}`;
|
|
44
|
+
}
|
|
45
|
+
this.db.enqueue(conversationId, messages);
|
|
46
|
+
}
|
|
47
|
+
startFlushLoop() {
|
|
48
|
+
this.timer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
|
|
49
|
+
}
|
|
50
|
+
stopFlushLoop() {
|
|
51
|
+
if (this.timer) {
|
|
52
|
+
clearInterval(this.timer);
|
|
53
|
+
this.timer = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Flush all pending messages to the API. */
|
|
57
|
+
async flush() {
|
|
58
|
+
if (this.flushing || this.authFailed)
|
|
59
|
+
return;
|
|
60
|
+
// Skip if in billing backoff window
|
|
61
|
+
if (Date.now() < this.billingBackoffUntil)
|
|
62
|
+
return;
|
|
63
|
+
this.flushing = true;
|
|
64
|
+
try {
|
|
65
|
+
// Step 1: Create any pending conversations
|
|
66
|
+
await this.createPendingConversations();
|
|
67
|
+
// Step 2: Flush messages for all conversations (with concurrency)
|
|
68
|
+
const convIds = this.db.getPendingConversationIds().filter((id) => !id.startsWith("pending:"));
|
|
69
|
+
// Process conversations in parallel, up to CONCURRENCY at a time
|
|
70
|
+
const chunks = [];
|
|
71
|
+
for (let i = 0; i < convIds.length; i += CONCURRENCY) {
|
|
72
|
+
chunks.push(convIds.slice(i, i + CONCURRENCY));
|
|
73
|
+
}
|
|
74
|
+
let hadError = false;
|
|
75
|
+
for (const chunk of chunks) {
|
|
76
|
+
const results = await Promise.allSettled(chunk.map((id) => this.flushConversation(id)));
|
|
77
|
+
if (results.some((r) => r.status === "rejected"))
|
|
78
|
+
hadError = true;
|
|
79
|
+
}
|
|
80
|
+
// Report sync health
|
|
81
|
+
const pending = this.db.getPendingCount();
|
|
82
|
+
if (!hadError && !this.authFailed) {
|
|
83
|
+
this.resetBillingBackoff();
|
|
84
|
+
recordSuccess(pending);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
89
|
+
console.error(`[engram] flush error: ${msg}`);
|
|
90
|
+
recordFailure(msg, classifyError(msg), this.db.getPendingCount());
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
this.flushing = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Create conversations for sessions that were deferred during parsing. */
|
|
97
|
+
async createPendingConversations() {
|
|
98
|
+
if (this.pendingSessions.size === 0)
|
|
99
|
+
return;
|
|
100
|
+
const entries = [...this.pendingSessions.entries()];
|
|
101
|
+
this.pendingSessions.clear();
|
|
102
|
+
// Create conversations in parallel batches
|
|
103
|
+
const batches = [];
|
|
104
|
+
for (let i = 0; i < entries.length; i += CONCURRENCY) {
|
|
105
|
+
batches.push(entries.slice(i, i + CONCURRENCY));
|
|
106
|
+
}
|
|
107
|
+
for (const batch of batches) {
|
|
108
|
+
const results = await Promise.allSettled(batch.map(async ([sessionId, meta]) => {
|
|
109
|
+
// Double-check (another flush may have created it)
|
|
110
|
+
if (this.db.getConversationId(sessionId))
|
|
111
|
+
return;
|
|
112
|
+
const conversationId = await this.createConversation(sessionId, meta);
|
|
113
|
+
// Migrate pending messages from pending:sessionId → real conversationId
|
|
114
|
+
this.db.remapPending(`pending:${sessionId}`, conversationId);
|
|
115
|
+
}));
|
|
116
|
+
for (const r of results) {
|
|
117
|
+
if (r.status === "rejected") {
|
|
118
|
+
const msg = r.reason instanceof Error ? r.reason.message : String(r.reason);
|
|
119
|
+
if (msg.includes("401") || msg.includes("403")) {
|
|
120
|
+
this.authFailed = true;
|
|
121
|
+
console.error(`[engram] auth error, stopping: ${msg}`);
|
|
122
|
+
recordFailure(msg, "auth", this.db.getPendingCount());
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const errType = classifyError(msg);
|
|
126
|
+
if (errType === "billing") {
|
|
127
|
+
this.enterBillingBackoff(msg);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
console.error(`[engram] create error (will retry): ${msg}`);
|
|
131
|
+
recordFailure(msg, errType, this.db.getPendingCount());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async flushConversation(conversationId) {
|
|
137
|
+
while (true) {
|
|
138
|
+
const rows = this.db.dequeue(conversationId, BATCH_SIZE);
|
|
139
|
+
if (rows.length === 0)
|
|
140
|
+
break;
|
|
141
|
+
const messages = rows.map(rowToMessage);
|
|
142
|
+
try {
|
|
143
|
+
await this.client.store({ conversationId, messages });
|
|
144
|
+
this.db.markSent(rows.map((r) => r.id));
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
148
|
+
if (msg.includes("401") || msg.includes("403") || msg.includes("Authentication")) {
|
|
149
|
+
this.authFailed = true;
|
|
150
|
+
console.error(`[engram] auth error, stopping flush: ${msg}`);
|
|
151
|
+
recordFailure(msg, "auth", this.db.getPendingCount());
|
|
152
|
+
this.stopFlushLoop();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Billing / limit errors — exponential backoff
|
|
156
|
+
const errType = classifyError(msg);
|
|
157
|
+
if (errType === "billing") {
|
|
158
|
+
this.enterBillingBackoff(msg);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// Rate limit or network — leave in queue for next cycle
|
|
162
|
+
console.error(`[engram] send failed (will retry): ${msg}`);
|
|
163
|
+
recordFailure(msg, errType, this.db.getPendingCount());
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Enter billing backoff — escalates each time: 5min → 15min → 1hr */
|
|
169
|
+
enterBillingBackoff(msg) {
|
|
170
|
+
const delay = BILLING_BACKOFF_MS[Math.min(this.billingBackoffStep, BILLING_BACKOFF_MS.length - 1)];
|
|
171
|
+
this.billingBackoffUntil = Date.now() + delay;
|
|
172
|
+
this.billingBackoffStep++;
|
|
173
|
+
const mins = Math.round(delay / 60_000);
|
|
174
|
+
console.error(`[engram] billing limit hit, backing off ${mins}m (attempt ${this.billingBackoffStep}): ${msg}`);
|
|
175
|
+
recordFailure(msg, "billing", this.db.getPendingCount());
|
|
176
|
+
}
|
|
177
|
+
/** Reset billing backoff after a successful sync. */
|
|
178
|
+
resetBillingBackoff() {
|
|
179
|
+
if (this.billingBackoffStep > 0) {
|
|
180
|
+
console.log("[engram] billing backoff cleared, resuming normal sync");
|
|
181
|
+
}
|
|
182
|
+
this.billingBackoffUntil = 0;
|
|
183
|
+
this.billingBackoffStep = 0;
|
|
184
|
+
}
|
|
185
|
+
async createConversation(sessionId, meta) {
|
|
186
|
+
const title = `${meta.projectDir} (${new Date().toISOString().slice(0, 16).replace("T", " ")})`;
|
|
187
|
+
const { conversationId } = await this.client.createConversation({
|
|
188
|
+
title,
|
|
189
|
+
agentId: "claude-code",
|
|
190
|
+
tags: ["claude-code", "auto-capture"],
|
|
191
|
+
metadata: {
|
|
192
|
+
sessionId,
|
|
193
|
+
projectDir: meta.projectDir,
|
|
194
|
+
cwd: meta.cwd,
|
|
195
|
+
gitBranch: meta.gitBranch,
|
|
196
|
+
capturedBy: "engram-daemon",
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
this.db.setSessionMap(sessionId, conversationId, {
|
|
200
|
+
projectDir: meta.projectDir,
|
|
201
|
+
cwd: meta.cwd,
|
|
202
|
+
gitBranch: meta.gitBranch,
|
|
203
|
+
});
|
|
204
|
+
return conversationId;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function rowToMessage(row) {
|
|
208
|
+
const msg = {
|
|
209
|
+
role: row.role,
|
|
210
|
+
content: row.content,
|
|
211
|
+
};
|
|
212
|
+
if (row.tool_call_id)
|
|
213
|
+
msg.toolCallId = row.tool_call_id;
|
|
214
|
+
if (row.tool_name)
|
|
215
|
+
msg.toolName = row.tool_name;
|
|
216
|
+
if (row.metadata)
|
|
217
|
+
msg.metadata = JSON.parse(row.metadata);
|
|
218
|
+
return msg;
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=syncer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncer.js","sourceRoot":"","sources":["../../src/daemon/syncer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa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rB,CAAC;IACF,IAAI,GAAG,CAAC,YAAY;QAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,YAAY,CAAC;IACxD,IAAI,GAAG,CAAC,SAAS;QAAE,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC;IAChD,IAAI,GAAG,CAAC,QAAQ;QAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1D,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Message parsed from a Claude Code JSONL transcript line. */
|
|
2
|
+
export interface ParsedMessage {
|
|
3
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
4
|
+
content: string;
|
|
5
|
+
toolCallId?: string;
|
|
6
|
+
toolName?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/** Metadata extracted from the first line of a Claude Code session. */
|
|
10
|
+
export interface SessionMeta {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
gitBranch?: string;
|
|
14
|
+
projectDir: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Row from the pending_messages table. */
|
|
18
|
+
export interface PendingRow {
|
|
19
|
+
id: number;
|
|
20
|
+
conversation_id: string;
|
|
21
|
+
role: string;
|
|
22
|
+
content: string;
|
|
23
|
+
tool_call_id: string | null;
|
|
24
|
+
tool_name: string | null;
|
|
25
|
+
metadata: string | null;
|
|
26
|
+
created_at: string;
|
|
27
|
+
}
|
|
28
|
+
/** Stats returned by `engram status`. */
|
|
29
|
+
export interface DaemonStats {
|
|
30
|
+
running: boolean;
|
|
31
|
+
pid: number | null;
|
|
32
|
+
trackedFiles: number;
|
|
33
|
+
pendingMessages: number;
|
|
34
|
+
sessionsMapped: number;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,2CAA2C;AAC3C,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":""}
|