@phren/cli 0.3.67 → 0.3.69
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/bridge/agent-hook-callback.js +11 -2
- package/dist/bridge/agent-hooks.d.ts +11 -1
- package/dist/bridge/agent-hooks.js +259 -40
- package/dist/bridge/changes.d.ts +2 -2
- package/dist/bridge/changes.js +11 -9
- package/dist/bridge/checkpoints.d.ts +24 -0
- package/dist/bridge/checkpoints.js +423 -0
- package/dist/bridge/claude-input-state.d.ts +14 -0
- package/dist/bridge/claude-input-state.js +58 -0
- package/dist/bridge/claude-queue.js +5 -2
- package/dist/bridge/claude-suggestion.d.ts +3 -0
- package/dist/bridge/claude-suggestion.js +10 -0
- package/dist/bridge/codex-threads.d.ts +7 -1
- package/dist/bridge/codex-threads.js +185 -56
- package/dist/bridge/conversation-search.d.ts +20 -0
- package/dist/bridge/conversation-search.js +928 -0
- package/dist/bridge/git-watch.d.ts +46 -0
- package/dist/bridge/git-watch.js +351 -0
- package/dist/bridge/git-worktree-remove.d.ts +44 -0
- package/dist/bridge/git-worktree-remove.js +140 -0
- package/dist/bridge/git-worktrees.d.ts +14 -0
- package/dist/bridge/git-worktrees.js +7 -3
- package/dist/bridge/git-write-policy.js +1 -1
- package/dist/bridge/gitboy-webhooks.d.ts +3 -1
- package/dist/bridge/gitboy-webhooks.js +26 -2
- package/dist/bridge/herdr.d.ts +6 -1
- package/dist/bridge/herdr.js +56 -10
- package/dist/bridge/hook-fast.js +13 -1
- package/dist/bridge/input-classification.d.ts +33 -0
- package/dist/bridge/input-classification.js +84 -0
- package/dist/bridge/pane-status.d.ts +3 -3
- package/dist/bridge/pane-status.js +16 -8
- package/dist/bridge/prompt-deliveries.d.ts +30 -4
- package/dist/bridge/prompt-deliveries.js +365 -13
- package/dist/bridge/prompt-identity.d.ts +8 -0
- package/dist/bridge/prompt-identity.js +15 -0
- package/dist/bridge/request-origin.js +2 -1
- package/dist/bridge/schedule-events.d.ts +17 -0
- package/dist/bridge/schedule-events.js +53 -0
- package/dist/bridge/schedule-format.d.ts +22 -2
- package/dist/bridge/schedule-format.js +40 -5
- package/dist/bridge/schedule-update.js +2 -1
- package/dist/bridge/schedule-watch.js +15 -5
- package/dist/bridge/schedules.d.ts +9 -0
- package/dist/bridge/schedules.js +120 -7
- package/dist/bridge/server-pane-routes.d.ts +7 -8
- package/dist/bridge/server-pane-routes.js +186 -82
- package/dist/bridge/server-routes.d.ts +26 -2
- package/dist/bridge/server-routes.js +180 -56
- package/dist/bridge/server-stream.js +66 -15
- package/dist/bridge/server.js +25 -7
- package/dist/bridge/session-activity.d.ts +49 -4
- package/dist/bridge/session-activity.js +47 -0
- package/dist/bridge/session-evidence.d.ts +18 -0
- package/dist/bridge/session-evidence.js +72 -0
- package/dist/bridge/session-seen.d.ts +23 -0
- package/dist/bridge/session-seen.js +69 -0
- package/dist/bridge/tab-activity.d.ts +26 -1
- package/dist/bridge/tab-activity.js +64 -9
- package/dist/bridge/terminal-resolve.d.ts +20 -0
- package/dist/bridge/terminal-resolve.js +145 -0
- package/dist/bridge/terminal-tmux.d.ts +8 -3
- package/dist/bridge/terminal-tmux.js +59 -7
- package/dist/bridge/transcript-claude.d.ts +12 -2
- package/dist/bridge/transcript-claude.js +91 -13
- package/dist/bridge/transcript-index.d.ts +4 -2
- package/dist/bridge/transcript-index.js +6 -5
- package/dist/bridge/transcript-preview.d.ts +16 -1
- package/dist/bridge/transcript-preview.js +171 -27
- package/dist/bridge/transcripts.d.ts +41 -1
- package/dist/bridge/transcripts.js +181 -23
- package/dist/bridge/turn-queue-pane.d.ts +6 -0
- package/dist/bridge/turn-queue-pane.js +30 -0
- package/dist/bridge/turn-queue.d.ts +86 -0
- package/dist/bridge/turn-queue.js +280 -0
- package/dist/bridge/turn-records.d.ts +18 -0
- package/dist/bridge/turn-records.js +77 -5
- package/dist/bridge-hook.mjs +7074 -3173
- package/dist/cli/config-shared.js +2 -1
- package/dist/cli/schedules.js +6 -1
- package/dist/content/secrets.js +1 -1
- package/dist/modules/registry.js +12 -11
- package/package.json +1 -1
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export declare function materializedRoot(): string;
|
|
2
2
|
export declare function materializedPath(session: string): string;
|
|
3
|
+
/** Codex 0.155 threads the SQLite store knows, by stable thread identity. Search
|
|
4
|
+
* uses this to discover threads that have no rollout file to glob. */
|
|
5
|
+
export declare function codexThreadSessions(limit?: number, after?: string): Promise<string[]>;
|
|
6
|
+
/** The materialized row retains its original turn, independently of whichever
|
|
7
|
+
* turn happens to be active when search catches up. */
|
|
8
|
+
export declare function codexTurnSettled(session: string, turn: string | null): Promise<boolean | undefined>;
|
|
3
9
|
/** A working pane whose projection cursor stopped at an unfinished turn can
|
|
4
10
|
* keep accepting input even though none of it will be readable again. */
|
|
5
11
|
export declare function threadHealth(session: string, agentStatus: unknown): Promise<{
|
|
@@ -13,7 +19,7 @@ export declare function codexThreadPreview(session: string): Promise<{
|
|
|
13
19
|
/** Bring the materialized file up to date with the store. Returns the file
|
|
14
20
|
* when the thread exists there, undefined otherwise. Safe to call often:
|
|
15
21
|
* an unchanged thread costs one aggregate query. */
|
|
16
|
-
export declare function materializeCodexThread(session: string): Promise<string | undefined>;
|
|
22
|
+
export declare function materializeCodexThread(session: string, deadline?: number, maxItems?: number): Promise<string | undefined>;
|
|
17
23
|
/** The pending queued question as the pane's choice shape: the asking
|
|
18
24
|
* sentence and one numbered option per choice (Codex answers with number
|
|
19
25
|
* keys once alt+up has opened the queue). Undefined when nothing answerable
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { mkdir, open, readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
|
|
3
3
|
import { codexHome } from "../home-paths.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { atomic, bridgeRoot, object, objects, sessionId } from "./protocol.js";
|
|
@@ -7,10 +7,47 @@ import { atomic, bridgeRoot, object, objects, sessionId } from "./protocol.js";
|
|
|
7
7
|
* longer writes the rollout file its `state_5.sqlite` still names. The Hook
|
|
8
8
|
* materializes such a thread into a rollout-shaped JSONL of its own, append
|
|
9
9
|
* only, so every reader of Codex transcripts keeps working unchanged. */
|
|
10
|
-
const
|
|
10
|
+
const OUTPUT_TAIL = 4_000;
|
|
11
11
|
const STALLED_AFTER_MS = 10 * 60 * 1_000;
|
|
12
12
|
export function materializedRoot() { return path.join(bridgeRoot(), "codex-threads"); }
|
|
13
13
|
export function materializedPath(session) { return path.join(materializedRoot(), `${session}.jsonl`); }
|
|
14
|
+
/** Codex 0.155 threads the SQLite store knows, by stable thread identity. Search
|
|
15
|
+
* uses this to discover threads that have no rollout file to glob. */
|
|
16
|
+
export async function codexThreadSessions(limit = 5_000, after = "") {
|
|
17
|
+
const history = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
|
|
18
|
+
if (!history)
|
|
19
|
+
return [];
|
|
20
|
+
try {
|
|
21
|
+
return objects(history.prepare(`select distinct thread_id from thread_items
|
|
22
|
+
where thread_id > ? order by thread_id limit ?`).all(after, limit))
|
|
23
|
+
.map(row => String(row.thread_id));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
history.close();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The materialized row retains its original turn, independently of whichever
|
|
33
|
+
* turn happens to be active when search catches up. */
|
|
34
|
+
export async function codexTurnSettled(session, turn) {
|
|
35
|
+
const history = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
|
|
36
|
+
if (!history || !turn) {
|
|
37
|
+
history?.close();
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const row = object(history.prepare("select status from thread_turns where thread_id = ? and turn_id = ?").get(session, turn));
|
|
42
|
+
return typeof row.status === "string" ? row.status !== "inProgress" : undefined;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
history.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
14
51
|
async function openReadOnly(file) {
|
|
15
52
|
try {
|
|
16
53
|
await stat(file);
|
|
@@ -105,14 +142,14 @@ export async function codexThreadPreview(session) {
|
|
|
105
142
|
/** Bring the materialized file up to date with the store. Returns the file
|
|
106
143
|
* when the thread exists there, undefined otherwise. Safe to call often:
|
|
107
144
|
* an unchanged thread costs one aggregate query. */
|
|
108
|
-
export async function materializeCodexThread(session) {
|
|
145
|
+
export async function materializeCodexThread(session, deadline = Infinity, maxItems = Infinity) {
|
|
109
146
|
if (!sessionId.safeParse(session).success)
|
|
110
147
|
return undefined;
|
|
111
148
|
const key = materializedPath(session);
|
|
112
149
|
const pending = materializations.get(key);
|
|
113
150
|
if (pending)
|
|
114
151
|
return pending;
|
|
115
|
-
const work = materializeThread(session);
|
|
152
|
+
const work = materializeThread(session, deadline, maxItems);
|
|
116
153
|
materializations.set(key, work);
|
|
117
154
|
try {
|
|
118
155
|
return await work;
|
|
@@ -121,7 +158,7 @@ export async function materializeCodexThread(session) {
|
|
|
121
158
|
materializations.delete(key);
|
|
122
159
|
}
|
|
123
160
|
}
|
|
124
|
-
async function materializeThread(session) {
|
|
161
|
+
async function materializeThread(session, deadline, maxItems) {
|
|
125
162
|
if (!sessionId.safeParse(session).success)
|
|
126
163
|
return undefined;
|
|
127
164
|
const history = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
|
|
@@ -138,44 +175,84 @@ async function materializeThread(session) {
|
|
|
138
175
|
state = { ...state, ...object(JSON.parse(await readFile(stateFile, "utf8"))) };
|
|
139
176
|
}
|
|
140
177
|
catch { /* first time */ }
|
|
141
|
-
|
|
142
|
-
|
|
178
|
+
// Older projections lack complete turn identities or update cursors. Rebuild the cache
|
|
179
|
+
// beside the live file, then replace it atomically; the transcript reader
|
|
180
|
+
// observes the new inode and resets its revision and row numbers together.
|
|
181
|
+
const upgrading = state.version !== 2 && (state.count > 0 || state.scanOrdinal !== undefined);
|
|
182
|
+
const outputFile = upgrading ? file + ".building" : file;
|
|
183
|
+
const progressFile = upgrading ? outputFile + ".state.json" : stateFile;
|
|
184
|
+
if (upgrading) {
|
|
185
|
+
if (!state.upgrading)
|
|
186
|
+
await atomic(stateFile, JSON.stringify({ ...state, upgrading: true }));
|
|
187
|
+
state = { lastOrdinal: -1, maxUpdated: -1, count: 0, done: {} };
|
|
188
|
+
try {
|
|
189
|
+
state = { ...state, ...object(JSON.parse(await readFile(progressFile, "utf8"))) };
|
|
190
|
+
}
|
|
191
|
+
catch { /* first upgrade batch */ }
|
|
192
|
+
if (state.version !== 2) {
|
|
193
|
+
state = { lastOrdinal: -1, maxUpdated: -1, count: 0, done: {} };
|
|
194
|
+
await rm(outputFile, { force: true });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
state.version = 2;
|
|
198
|
+
const fresh = state.count === 0 && state.scanOrdinal === undefined;
|
|
199
|
+
let turn = {};
|
|
200
|
+
try {
|
|
201
|
+
turn = object(history.prepare("select turn_id, status from thread_turns where thread_id = ? order by rollout_ordinal desc limit 1").get(session));
|
|
202
|
+
}
|
|
203
|
+
catch { /* legacy store without turn metadata */ }
|
|
143
204
|
const turnSignature = JSON.stringify(turn);
|
|
144
|
-
if (
|
|
145
|
-
|
|
205
|
+
if (Number(summary.last) > (state.scanOrdinal ?? -1))
|
|
206
|
+
state.forwardDone = false;
|
|
207
|
+
if (!upgrading && !Object.keys(state.deferred ?? {}).length && state.forwardDone && state.updateTarget === undefined && !fresh && state.count === Number(summary.n)
|
|
208
|
+
&& state.lastOrdinal === Number(summary.last) && state.maxUpdated === Number(summary.updated) && state.turnSignature === turnSignature)
|
|
146
209
|
return file;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
210
|
+
let pending;
|
|
211
|
+
try {
|
|
212
|
+
pending = pendingMessage(history, session);
|
|
213
|
+
}
|
|
214
|
+
catch { /* legacy store without item turn identities */ }
|
|
215
|
+
state.deferred ??= {};
|
|
216
|
+
const columns = new Set(objects(history.prepare("PRAGMA table_info(thread_items)").all()).map(row => String(row.name)));
|
|
217
|
+
const stamps = new Map();
|
|
150
218
|
const lines = [];
|
|
151
219
|
if (fresh) {
|
|
152
220
|
const meta = await threadMeta(session);
|
|
153
|
-
// A child thread's row names its parent inside `source`; the child
|
|
154
|
-
// agent tree verifies that link from the first line, so it rides along.
|
|
155
221
|
lines.push(JSON.stringify({ type: "session_meta", payload: { id: session, ...(meta.cwd ? { cwd: meta.cwd } : {}),
|
|
156
222
|
source: meta.spawn ? { subagent: { thread_spawn: meta.spawn } } : "codex-thread-store" } }));
|
|
157
223
|
if (meta.model)
|
|
158
224
|
lines.push(JSON.stringify({ type: "turn_context", payload: { model: meta.model } }));
|
|
159
225
|
}
|
|
160
|
-
|
|
226
|
+
const emit = (row) => {
|
|
227
|
+
if (typeof row.turn_id === "string" && !stamps.has(String(row.turn_id))) {
|
|
228
|
+
let turn = {};
|
|
229
|
+
try {
|
|
230
|
+
turn = object(history.prepare("select started_at from thread_turns where thread_id = ? and turn_id = ?").get(session, row.turn_id));
|
|
231
|
+
}
|
|
232
|
+
catch { /* unavailable in legacy stores */ }
|
|
233
|
+
stamps.set(String(row.turn_id), epochMs(turn.started_at) ?? 0);
|
|
234
|
+
}
|
|
161
235
|
let item;
|
|
162
236
|
try {
|
|
163
237
|
item = object(JSON.parse(String(row.item_json)));
|
|
164
238
|
}
|
|
165
239
|
catch {
|
|
166
|
-
|
|
240
|
+
return;
|
|
167
241
|
}
|
|
168
242
|
const id = String(item.id ?? `ordinal-${row.rollout_ordinal}`), emitted = state.done[id];
|
|
169
|
-
if (item.type === "agentMessage" && id === pending?.id)
|
|
170
|
-
|
|
243
|
+
if (item.type === "agentMessage" && id === pending?.id) {
|
|
244
|
+
state.deferred[id] = String(row.item_id);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
delete state.deferred[id];
|
|
171
248
|
const calls = callRows(item), output = outputRow(item);
|
|
172
249
|
// Preserve only queue state actually recorded by the harness. The
|
|
173
250
|
// append-only transcript pairs the queued user row with a content-free
|
|
174
251
|
// consumption marker when that same item leaves the queue.
|
|
175
252
|
if (emitted === "queued" && item.type === "userMessage" && item.status !== "queued") {
|
|
176
|
-
lines.push(JSON.stringify({ type: "phren_queue_consumed", key: queueKey(session, id) }));
|
|
253
|
+
lines.push(JSON.stringify({ type: "phren_queue_consumed", key: queueKey(session, id), phrenTurnId: row.turn_id }));
|
|
177
254
|
state.done[id] = "done";
|
|
178
|
-
|
|
255
|
+
return;
|
|
179
256
|
}
|
|
180
257
|
if (!emitted) {
|
|
181
258
|
if (calls) {
|
|
@@ -189,11 +266,11 @@ async function materializeThread(session) {
|
|
|
189
266
|
// agent tree keeps finding native subagents.
|
|
190
267
|
lines.push(JSON.stringify(subAgentRow(item)));
|
|
191
268
|
state.done[id] = "done";
|
|
192
|
-
|
|
269
|
+
return;
|
|
193
270
|
}
|
|
194
271
|
else if (messageRow(item)) {
|
|
195
272
|
const at = rowTime(row, item, stamps);
|
|
196
|
-
const message = { ...messageRow(item), ...(at ? { timestamp: at } : {}) };
|
|
273
|
+
const message = { ...messageRow(item), phrenTurnId: row.turn_id, ...(at ? { timestamp: at } : {}) };
|
|
197
274
|
const queued = item.type === "userMessage" && item.status === "queued";
|
|
198
275
|
lines.push(JSON.stringify(queued ? { ...message, phrenQueued: true, phrenQueueKey: queueKey(session, id) } : message));
|
|
199
276
|
// A question the agent asked (delivered async) rides along as the
|
|
@@ -202,7 +279,7 @@ async function materializeThread(session) {
|
|
|
202
279
|
if (asked)
|
|
203
280
|
lines.push(JSON.stringify(asked));
|
|
204
281
|
state.done[id] = queued ? "queued" : "done";
|
|
205
|
-
|
|
282
|
+
return;
|
|
206
283
|
}
|
|
207
284
|
else if (isQueuedQuestionItem(item)) {
|
|
208
285
|
// The queued follow-up question reads in the transcript as the
|
|
@@ -210,20 +287,77 @@ async function materializeThread(session) {
|
|
|
210
287
|
// quoting a reply, so no async event rides along here.
|
|
211
288
|
const title = questionTitle(objects(item.questions));
|
|
212
289
|
if (title)
|
|
213
|
-
lines.push(JSON.stringify({ type: "response_item", payload: { type: "message", role: "assistant", content: [{ type: "output_text", text: title }] } }));
|
|
290
|
+
lines.push(JSON.stringify({ type: "response_item", phrenTurnId: row.turn_id, timestamp: rowTime(row, item, stamps), payload: { type: "message", role: "assistant", content: [{ type: "output_text", text: title }] } }));
|
|
214
291
|
state.done[id] = "done";
|
|
215
|
-
|
|
292
|
+
return;
|
|
216
293
|
}
|
|
217
294
|
else
|
|
218
|
-
|
|
295
|
+
return;
|
|
219
296
|
}
|
|
220
297
|
if (state.done[id] === "call" && output) {
|
|
221
298
|
lines.push(JSON.stringify(output));
|
|
222
299
|
state.done[id] = "done";
|
|
223
300
|
}
|
|
301
|
+
};
|
|
302
|
+
let processed = 0;
|
|
303
|
+
// Skipped streaming replies are retried independently of forward progress,
|
|
304
|
+
// including completion signalled only in thread_turns (no item update).
|
|
305
|
+
for (const [id, item] of Object.entries(state.deferred)) {
|
|
306
|
+
if (processed >= Math.min(16, maxItems) || Date.now() >= deadline)
|
|
307
|
+
break;
|
|
308
|
+
processed++;
|
|
309
|
+
const row = itemById(history, session, columns, item);
|
|
310
|
+
if (row)
|
|
311
|
+
emit(row);
|
|
312
|
+
else
|
|
313
|
+
delete state.deferred[id];
|
|
314
|
+
}
|
|
315
|
+
// Freeze each update pass at its own high watermark. Ongoing writes start
|
|
316
|
+
// another pass afterward; they never rewind the historical forward cursor.
|
|
317
|
+
if (state.updateTarget === undefined && Number(summary.updated) > state.maxUpdated)
|
|
318
|
+
state.updateTarget = Number(summary.updated);
|
|
319
|
+
const updateLimit = maxItems === Infinity ? Infinity : Math.min(maxItems, processed + 32);
|
|
320
|
+
while (state.updateTarget !== undefined && processed < updateLimit && Date.now() < deadline) {
|
|
321
|
+
const rows = itemRows(history, session, columns, state, true);
|
|
322
|
+
if (!rows.length) {
|
|
323
|
+
state.maxUpdated = state.updateTarget;
|
|
324
|
+
delete state.updateTarget;
|
|
325
|
+
delete state.updateAt;
|
|
326
|
+
delete state.updateOrdinal;
|
|
327
|
+
delete state.updateItem;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
for (const row of rows) {
|
|
331
|
+
if (processed >= updateLimit || Date.now() >= deadline)
|
|
332
|
+
break;
|
|
333
|
+
processed++;
|
|
334
|
+
emit(row);
|
|
335
|
+
state.updateAt = Number(row.updated_at_ordinal);
|
|
336
|
+
state.updateOrdinal = Number(row.rollout_ordinal);
|
|
337
|
+
state.updateItem = String(row.item_id);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
while (processed < maxItems && Date.now() < deadline) {
|
|
341
|
+
const rows = itemRows(history, session, columns, state, false);
|
|
342
|
+
if (!rows.length) {
|
|
343
|
+
state.forwardDone = true;
|
|
344
|
+
state.count = Number(summary.n);
|
|
345
|
+
state.lastOrdinal = Number(summary.last);
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
state.forwardDone = false;
|
|
349
|
+
for (const row of rows) {
|
|
350
|
+
if (processed >= maxItems || Date.now() >= deadline)
|
|
351
|
+
break;
|
|
352
|
+
processed++;
|
|
353
|
+
emit(row);
|
|
354
|
+
state.scanOrdinal = Number(row.rollout_ordinal);
|
|
355
|
+
state.scanItem = String(row.item_id);
|
|
356
|
+
}
|
|
224
357
|
}
|
|
358
|
+
state.turnSignature = turnSignature;
|
|
225
359
|
if (lines.length) {
|
|
226
|
-
const handle = await open(
|
|
360
|
+
const handle = await open(outputFile, "a", 0o600);
|
|
227
361
|
try {
|
|
228
362
|
await handle.appendFile(lines.join("\n") + "\n");
|
|
229
363
|
}
|
|
@@ -231,11 +365,12 @@ async function materializeThread(session) {
|
|
|
231
365
|
await handle.close();
|
|
232
366
|
}
|
|
233
367
|
}
|
|
234
|
-
|
|
235
|
-
state.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
368
|
+
await atomic(progressFile, JSON.stringify(state));
|
|
369
|
+
if (upgrading && state.forwardDone && state.updateTarget === undefined) {
|
|
370
|
+
await rename(outputFile, file);
|
|
371
|
+
await atomic(stateFile, JSON.stringify(state));
|
|
372
|
+
await rm(progressFile, { force: true });
|
|
373
|
+
}
|
|
239
374
|
return file;
|
|
240
375
|
}
|
|
241
376
|
catch {
|
|
@@ -247,31 +382,25 @@ async function materializeThread(session) {
|
|
|
247
382
|
}
|
|
248
383
|
/** The thread's items in order, with when each was created where the store records it (`created_at_ms`, absent
|
|
249
384
|
* from some stores) and its turn. */
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
catch {
|
|
255
|
-
try {
|
|
256
|
-
return objects(history.prepare("select rollout_ordinal, item_type, item_json, updated_at_ordinal, turn_id from thread_items where thread_id = ? order by rollout_ordinal limit ?").all(session, MAX_ITEMS));
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
return objects(history.prepare("select rollout_ordinal, item_type, item_json, updated_at_ordinal from thread_items where thread_id = ? order by rollout_ordinal limit ?").all(session, MAX_ITEMS));
|
|
260
|
-
}
|
|
261
|
-
}
|
|
385
|
+
function itemProjection(columns) {
|
|
386
|
+
const key = columns.has("item_id") ? "item_id" : "CAST(rollout_ordinal AS TEXT)";
|
|
387
|
+
return { key, fields: `rollout_ordinal, ${key} AS item_id, item_type, item_json, updated_at_ordinal,
|
|
388
|
+
${columns.has("turn_id") ? "turn_id" : "NULL AS turn_id"}, ${columns.has("created_at_ms") ? "created_at_ms" : "NULL AS created_at_ms"}` };
|
|
262
389
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
390
|
+
function itemRows(history, session, columns, state, updates) {
|
|
391
|
+
const { key, fields } = itemProjection(columns);
|
|
392
|
+
return objects(updates
|
|
393
|
+
? history.prepare(`SELECT ${fields} FROM thread_items WHERE thread_id = ? AND updated_at_ordinal > ? AND updated_at_ordinal <= ?
|
|
394
|
+
AND (updated_at_ordinal, rollout_ordinal, ${key}) > (?, ?, ?)
|
|
395
|
+
ORDER BY updated_at_ordinal, rollout_ordinal, ${key} LIMIT 128`)
|
|
396
|
+
.all(session, state.maxUpdated, state.updateTarget, state.updateAt ?? -1, state.updateOrdinal ?? -1, state.updateItem ?? "")
|
|
397
|
+
: history.prepare(`SELECT ${fields} FROM thread_items WHERE thread_id = ? AND (rollout_ordinal, ${key}) > (?, ?)
|
|
398
|
+
ORDER BY rollout_ordinal, ${key} LIMIT 128`).all(session, state.scanOrdinal ?? -1, state.scanItem ?? ""));
|
|
399
|
+
}
|
|
400
|
+
function itemById(history, session, columns, item) {
|
|
401
|
+
const { key, fields } = itemProjection(columns);
|
|
402
|
+
const row = history.prepare(`SELECT ${fields} FROM thread_items WHERE thread_id = ? AND ${key} = ? LIMIT 1`).get(session, item);
|
|
403
|
+
return row ? object(row) : undefined;
|
|
275
404
|
}
|
|
276
405
|
/** Seconds or milliseconds since the epoch, as milliseconds; undefined for anything else. */
|
|
277
406
|
function epochMs(value) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ConversationSource = "claude" | "codex" | "copilot" | "opencode";
|
|
2
|
+
export interface ConversationSearchHit {
|
|
3
|
+
conversation: string;
|
|
4
|
+
source: ConversationSource;
|
|
5
|
+
title: string;
|
|
6
|
+
cwd: string | null;
|
|
7
|
+
pane: string | null;
|
|
8
|
+
entry: string;
|
|
9
|
+
at: string;
|
|
10
|
+
role: "user" | "assistant";
|
|
11
|
+
snippet: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ConversationSearchPage {
|
|
14
|
+
results: ConversationSearchHit[];
|
|
15
|
+
cursor: string | null;
|
|
16
|
+
partial?: true;
|
|
17
|
+
}
|
|
18
|
+
/** Serialize index updates in this Hook process; reads stay consistent with the
|
|
19
|
+
* last write and two searches cannot rebuild the same file twice at once. */
|
|
20
|
+
export declare function conversationSearch(q: string | null | undefined, limit?: string | null, cursor?: string | null): Promise<ConversationSearchPage>;
|