@tinchu0/knitt 0.1.0-beta.1 → 0.1.0-beta.2

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.
@@ -1,10 +1,17 @@
1
+ import { recordCaptureStatus, readCaptureStatuses, pendingForSession, } from "./status.js";
2
+ import { execFileSync } from "node:child_process";
1
3
  import { mkdirSync } from "node:fs";
2
4
  import { dirname, resolve } from "node:path";
3
- import { capture, flush, recallInstruction, selectionInstruction } from "./hooks.js";
5
+ import { capture, flush, recallInstruction, selectionInstruction, } from "./hooks.js";
4
6
  import { resolveScope, resolveConnection } from "./scope.js";
5
7
  import { captureTranscript } from "./transcript.js";
6
8
  import { MemoryStore } from "../../memory/src/store.js";
7
9
  const [action, client] = process.argv.slice(2);
10
+ let captureSession;
11
+ let capturedAt = null;
12
+ let captureState = "unobserved";
13
+ let selectedSessionToken;
14
+ const statusDirectory = process.env.MEMORY_QUEUE ?? resolve(".memory/queue");
8
15
  try {
9
16
  if (!["claude", "codex", "antigravity"].includes(client ?? ""))
10
17
  throw new Error("Choose claude, codex or antigravity");
@@ -28,7 +35,69 @@ try {
28
35
  }
29
36
  let scope;
30
37
  let selectedSessionId;
31
- if (process.env.MEMORY_SESSION_SELECTION === "1" && action !== "flush") {
38
+ const conversationMode = process.env.MEMORY_CONVERSATION_MODE === "1";
39
+ if (conversationMode && action !== "flush") {
40
+ const { repoId, workspace } = resolveConnection(payload);
41
+ const nativeSessionId = payload.session_id ?? payload.conversationId;
42
+ if (typeof nativeSessionId !== "string" || !nativeSessionId)
43
+ throw new Error("A native session ID is required");
44
+ selectedSessionId = nativeSessionId;
45
+ captureSession = { repoId, client, nativeSessionId };
46
+ const path = process.env.MEMORY_DB ?? resolve(".memory/events.sqlite");
47
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
48
+ const store = new MemoryStore(path, { conversationMode: true });
49
+ try {
50
+ if (process.env.MEMORY_CAPTURE_NEW_SESSIONS !== "1" &&
51
+ !store.sessionSelection(repoId, nativeSessionId)) {
52
+ console.log(action === "recall"
53
+ ? JSON.stringify(selectionInstruction(client, repoId, nativeSessionId, workspace))
54
+ : "{}");
55
+ process.exit(0);
56
+ }
57
+ const git = (args) => {
58
+ try {
59
+ return (execFileSync("git", args, {
60
+ cwd: workspace,
61
+ encoding: "utf8",
62
+ stdio: ["ignore", "pipe", "ignore"],
63
+ }).trim() || undefined);
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ };
69
+ const branch = git(["symbolic-ref", "--short", "HEAD"]), commit = git(["rev-parse", "HEAD"]);
70
+ const conversation = store.ensureSession({ repoId, client, nativeSessionId }, { workspace, branch, commit });
71
+ if (action === "recall" &&
72
+ process.env.MEMORY_LAUNCH_FEATURE?.startsWith("conversation:"))
73
+ store.linkSource({ repoId, client, nativeSessionId }, process.env.MEMORY_LAUNCH_FEATURE);
74
+ if (action === "recall") {
75
+ selectedSessionToken = store.issueSessionToken(captureSession);
76
+ if (!readCaptureStatuses(statusDirectory).some((s) => s.session.repoId === repoId &&
77
+ s.session.client === client &&
78
+ s.session.nativeSessionId === nativeSessionId))
79
+ recordCaptureStatus(statusDirectory, {
80
+ session: captureSession,
81
+ lastCaptureAt: null,
82
+ lastDeliveryAt: null,
83
+ pending: pendingForSession(statusDirectory, captureSession),
84
+ lastErrorCode: null,
85
+ captureState: "unobserved",
86
+ });
87
+ }
88
+ scope = {
89
+ repoId,
90
+ featureId: conversation.conversationId,
91
+ branch,
92
+ commit,
93
+ };
94
+ }
95
+ finally {
96
+ store.close();
97
+ }
98
+ }
99
+ else if (process.env.MEMORY_SESSION_SELECTION === "1" &&
100
+ action !== "flush") {
32
101
  const { repoId, workspace } = resolveConnection(payload);
33
102
  const sessionId = payload.session_id ?? payload.conversationId;
34
103
  if (typeof sessionId !== "string" || !sessionId)
@@ -62,34 +131,90 @@ try {
62
131
  else
63
132
  scope = resolveScope(payload);
64
133
  if (action === "recall") {
65
- console.log(JSON.stringify(recallInstruction(client, scope, process.env.MEMORY_WORKSPACE, selectedSessionId)));
134
+ console.log(JSON.stringify(recallInstruction(client, scope, process.env.MEMORY_WORKSPACE, selectedSessionId, selectedSessionToken)));
66
135
  }
67
136
  else if (action === "capture" || action === "flush") {
68
- const directory = process.env.MEMORY_QUEUE ?? resolve(".memory/queue");
137
+ const directory = statusDirectory;
69
138
  if (action === "capture") {
70
139
  const transcriptPath = payload.transcript_path ?? payload.transcriptPath;
71
140
  if (typeof transcriptPath === "string" && transcriptPath) {
72
- console.error(JSON.stringify(captureTranscript({
73
- directory, client: client, scope,
141
+ const report = captureTranscript({
142
+ directory,
143
+ client: client,
144
+ scope,
74
145
  sessionId: String(payload.session_id ?? payload.conversationId ?? ""),
75
146
  path: transcriptPath,
76
- })));
147
+ ...(conversationMode ? { session: captureSession } : {}),
148
+ });
149
+ console.error(JSON.stringify(report));
150
+ if (report.events > 0)
151
+ capturedAt = new Date().toISOString();
152
+ captureState =
153
+ report.remainingBytes > 0
154
+ ? "partial"
155
+ : report.events > 0
156
+ ? "captured"
157
+ : report.records > 0
158
+ ? "no_supported_text"
159
+ : "no_new_text";
77
160
  }
78
161
  else {
79
- capture(directory, client, scope, payload);
162
+ capture(directory, client, scope, payload, conversationMode ? captureSession : undefined);
163
+ capturedAt = new Date().toISOString();
164
+ captureState = "captured";
80
165
  }
81
166
  }
82
- const report = flush(directory, event => {
167
+ const touched = new Map();
168
+ if (captureSession)
169
+ touched.set(JSON.stringify(captureSession), {
170
+ session: captureSession,
171
+ delivered: false,
172
+ });
173
+ const report = flush(directory, (event, queuedSession) => {
174
+ if (queuedSession) {
175
+ if (event.repoId !== queuedSession.repoId ||
176
+ event.sessionId !== queuedSession.nativeSessionId ||
177
+ !event.source?.startsWith(queuedSession.client + ":"))
178
+ throw new Error("Queued evidence identity mismatch");
179
+ const id = JSON.stringify(queuedSession);
180
+ if (!touched.has(id))
181
+ touched.set(id, { session: queuedSession, delivered: false });
182
+ }
83
183
  const path = process.env.MEMORY_DB ?? resolve(".memory/events.sqlite");
84
184
  mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
85
- const store = new MemoryStore(path);
185
+ const store = new MemoryStore(path, {
186
+ conversationMode: !!queuedSession,
187
+ });
86
188
  try {
87
- store.save(event);
189
+ if (queuedSession)
190
+ store.appendEvidence(queuedSession, event);
191
+ else
192
+ store.save(event);
88
193
  }
89
194
  finally {
90
195
  store.close();
91
196
  }
197
+ if (queuedSession)
198
+ touched.get(JSON.stringify(queuedSession)).delivered = true;
92
199
  });
200
+ for (const { session, delivered } of touched.values()) {
201
+ const ownCapture = action === "capture" &&
202
+ captureSession &&
203
+ JSON.stringify(session) === JSON.stringify(captureSession);
204
+ const previous = readCaptureStatuses(directory).find((s) => JSON.stringify(s.session) === JSON.stringify(session));
205
+ const pending = pendingForSession(directory, session);
206
+ recordCaptureStatus(directory, {
207
+ session,
208
+ lastCaptureAt: ownCapture ? capturedAt : null,
209
+ lastDeliveryAt: delivered ? new Date().toISOString() : null,
210
+ pending,
211
+ lastErrorCode: pending ? "DELIVERY_PENDING" : null,
212
+ lastAttemptAt: ownCapture ? new Date().toISOString() : null,
213
+ captureState: ownCapture
214
+ ? captureState
215
+ : (previous?.captureState ?? "unobserved"),
216
+ });
217
+ }
93
218
  console.error(JSON.stringify(report));
94
219
  console.log("{}");
95
220
  }
@@ -97,13 +222,36 @@ try {
97
222
  throw new Error("Choose capture, recall or flush");
98
223
  }
99
224
  catch (error) {
225
+ if (action === "capture" && captureSession) {
226
+ try {
227
+ recordCaptureStatus(statusDirectory, {
228
+ session: captureSession,
229
+ lastCaptureAt: capturedAt,
230
+ lastDeliveryAt: null,
231
+ pending: pendingForSession(statusDirectory, captureSession),
232
+ lastErrorCode: "CAPTURE_FAILED",
233
+ lastAttemptAt: new Date().toISOString(),
234
+ captureState: "error",
235
+ });
236
+ }
237
+ catch {
238
+ /* The data path itself may be unavailable; stderr still reports failure. */
239
+ }
240
+ }
100
241
  // Hook failure must not prevent the user's coding turn.
101
- console.error("Shared memory: " + (error instanceof Error ? error.message : String(error)));
242
+ console.error("Shared memory: " +
243
+ (error instanceof Error ? error.message : String(error)));
102
244
  if (action === "recall" && process.env.MEMORY_WORKSPACE) {
103
- const message = "Memory handoff blocked. " + (error instanceof Error ? error.message : String(error));
245
+ const message = "Memory handoff blocked. " +
246
+ (error instanceof Error ? error.message : String(error));
104
247
  console.log(JSON.stringify({
105
- continue: false, systemMessage: message,
106
- hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: message + " Do not continue imported work or edit another project from this chat." },
248
+ continue: false,
249
+ systemMessage: message,
250
+ hookSpecificOutput: {
251
+ hookEventName: "SessionStart",
252
+ additionalContext: message +
253
+ " Do not continue imported work or edit another project from this chat.",
254
+ },
107
255
  }));
108
256
  }
109
257
  else
@@ -1,3 +1,7 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { existsSync } from "node:fs";
3
+ import { schemaVersion } from "../../memory/src/migrations.js";
4
+ import { discoverConversations, importDiscovered } from "./discovery.js";
1
5
  import { createInterface } from "node:readline/promises";
2
6
  import { pickConversation } from "./picker.js";
3
7
  import { parseArgs } from "node:util";
@@ -7,29 +11,114 @@ import { fileURLToPath } from "node:url";
7
11
  import { mkdirSync } from "node:fs";
8
12
  import { execFileSync } from "node:child_process";
9
13
  import { createHash } from "node:crypto";
10
- import { findConversations, selectConversation, importConversation } from "./handoff.js";
14
+ import { findConversations, selectConversation, importConversation, } from "./handoff.js";
11
15
  import { MemoryStore } from "../../memory/src/store.js";
12
16
  import { resolveRepository } from "./repository.js";
13
- import { planConnection, applyConnectionPlan } from "../../installer/src/connections.js";
17
+ import { planConnection, applyConnectionPlan, } from "../../installer/src/connections.js";
14
18
  import { codexLaunch, displayCommand } from "./launch.js";
15
19
  async function main() {
16
20
  const { values, positionals } = parseArgs({
17
21
  allowPositionals: true,
18
22
  options: {
19
- conversation: { type: "string" }, workspace: { type: "string" },
20
- from: { type: "string", default: "antigravity" }, to: { type: "string", default: "codex" },
21
- "data-root": { type: "string", multiple: true }, preview: { type: "boolean", default: false },
23
+ home: { type: "string" },
24
+ session: { type: "string" },
25
+ client: { type: "string" },
26
+ conversation: { type: "string" },
27
+ workspace: { type: "string" },
28
+ from: { type: "string", default: "antigravity" },
29
+ to: { type: "string", default: "codex" },
30
+ "data-root": { type: "string", multiple: true },
31
+ preview: { type: "boolean", default: false },
22
32
  launch: { type: "boolean", default: false },
23
33
  },
24
34
  });
25
35
  const action = positionals[0];
26
- if (!["list", "handoff"].includes(action) || values.from !== "antigravity" || values.to !== "codex") {
36
+ if (action === "continue") {
37
+ if (!values.workspace ||
38
+ !values.session ||
39
+ !values.client ||
40
+ !["codex", "claude", "antigravity"].includes(values.client))
41
+ throw new Error("Pass --workspace, --session and --client codex|claude|antigravity");
42
+ const resolved = resolveRepository(resolve(values.workspace));
43
+ const workspace = resolved.workspace, repoId = process.env.MEMORY_REPO ?? resolved.repoId;
44
+ const database = process.env.MEMORY_DB;
45
+ if (!database)
46
+ throw new Error("Set MEMORY_DB to the connected installation database");
47
+ if (process.env.MEMORY_CONVERSATION_MODE !== "1")
48
+ throw new Error("Use an opted-in project connection");
49
+ if (!process.stdin.isTTY)
50
+ throw new Error("Run the continuation picker interactively");
51
+ if (!existsSync(database))
52
+ throw new Error("No local conversation database; start the connected agent first");
53
+ const probe = new DatabaseSync(database, { readOnly: true });
54
+ try {
55
+ if (Number(probe.prepare("PRAGMA user_version").get().user_version) !==
56
+ schemaVersion)
57
+ throw new Error("Start the opted-in agent to prepare a compatible schema first");
58
+ if (!probe
59
+ .prepare("SELECT 1 FROM native_sessions WHERE repo=? AND client=? AND native_id=?")
60
+ .get(repoId, values.client, values.session))
61
+ throw new Error("Unknown native session; start the connected agent first");
62
+ }
63
+ finally {
64
+ probe.close();
65
+ }
66
+ const store = new MemoryStore(database, { conversationMode: true });
67
+ try {
68
+ const key = {
69
+ repoId,
70
+ client: values.client,
71
+ nativeSessionId: values.session,
72
+ };
73
+ store.sessionConversation(key);
74
+ const choices = discoverConversations(store, repoId, workspace).conversations.filter((c) => c.storedId !== store.sessionConversation(key).conversationId &&
75
+ !(c.client === key.client && c.sourceId === key.nativeSessionId));
76
+ if (!process.stdin.isTTY)
77
+ throw new Error("Run the continuation picker interactively");
78
+ const reader = createInterface({
79
+ input: process.stdin,
80
+ output: process.stdout,
81
+ });
82
+ let chosen;
83
+ try {
84
+ chosen = await pickConversation(choices, {
85
+ ask: (p) => reader.question(p),
86
+ write: (t) => {
87
+ process.stdout.write(t);
88
+ },
89
+ });
90
+ }
91
+ finally {
92
+ reader.close();
93
+ }
94
+ if (!chosen) {
95
+ console.log("Cancelled. Previous selection retained.");
96
+ return;
97
+ }
98
+ const source = choices.find((c) => c.id === chosen.id);
99
+ const id = importDiscovered(store, repoId, source, join(dirname(database), "history-import"));
100
+ console.log(JSON.stringify(store.linkSource(key, id)));
101
+ return;
102
+ }
103
+ finally {
104
+ store.close();
105
+ }
106
+ }
107
+ if (!["list", "handoff"].includes(action) ||
108
+ values.from !== "antigravity" ||
109
+ values.to !== "codex") {
27
110
  throw new Error("Usage: npm run memory -- list [--workspace PATH] | handoff --conversation TITLE_OR_ID [--workspace PATH] [--preview]. Supported handoff: Antigravity to Codex.");
28
111
  }
29
- const roots = values["data-root"] ?? ["antigravity", "antigravity-cli", "antigravity-ide"].map(name => join(homedir(), ".gemini", name));
112
+ const roots = values["data-root"] ??
113
+ ["antigravity", "antigravity-cli", "antigravity-ide"].map((name) => join(homedir(), ".gemini", name));
30
114
  const conversations = findConversations(roots, values.workspace);
31
115
  if (action === "list") {
32
- console.log(JSON.stringify(conversations.map(({ id, title, workspace, modified }) => ({ id, title, workspace, modified })), null, 2));
116
+ console.log(JSON.stringify(conversations.map(({ id, title, workspace, modified }) => ({
117
+ id,
118
+ title,
119
+ workspace,
120
+ modified,
121
+ })), null, 2));
33
122
  return;
34
123
  }
35
124
  let conversation;
@@ -38,9 +127,17 @@ async function main() {
38
127
  else {
39
128
  if (!process.stdin.isTTY)
40
129
  throw new Error("User selection required. Run handoff interactively to open the chat picker, or pass an explicit --conversation.");
41
- const reader = createInterface({ input: process.stdin, output: process.stdout });
130
+ const reader = createInterface({
131
+ input: process.stdin,
132
+ output: process.stdout,
133
+ });
42
134
  try {
43
- conversation = await pickConversation(conversations, { ask: prompt => reader.question(prompt), write: text => { process.stdout.write(text); } });
135
+ conversation = await pickConversation(conversations, {
136
+ ask: (prompt) => reader.question(prompt),
137
+ write: (text) => {
138
+ process.stdout.write(text);
139
+ },
140
+ });
44
141
  }
45
142
  finally {
46
143
  reader.close();
@@ -54,13 +151,26 @@ async function main() {
54
151
  const app = resolve(fileURLToPath(new URL("../../../", import.meta.url)));
55
152
  const database = process.env.MEMORY_DB ?? join(app, ".memory/events.sqlite");
56
153
  const featureId = "antigravity:" + conversation.id;
57
- const launch = codexLaunch(workspace, { featureId, title: conversation.title });
154
+ const launch = codexLaunch(workspace, {
155
+ featureId,
156
+ title: conversation.title,
157
+ });
58
158
  const destinationCommand = displayCommand("env", [
59
159
  ...Object.entries(launch.env).map(([name, value]) => name + "=" + value),
60
- launch.command, ...launch.args,
160
+ launch.command,
161
+ ...launch.args,
61
162
  ]);
62
163
  if (values.preview) {
63
- console.log(JSON.stringify({ action, title: conversation.title, workspace, repoId, featureId, destination: "codex", database, changesApplied: false }, null, 2));
164
+ console.log(JSON.stringify({
165
+ action,
166
+ title: conversation.title,
167
+ workspace,
168
+ repoId,
169
+ featureId,
170
+ destination: "codex",
171
+ database,
172
+ changesApplied: false,
173
+ }, null, 2));
64
174
  return;
65
175
  }
66
176
  mkdirSync(dirname(database), { recursive: true, mode: 0o700 });
@@ -68,18 +178,39 @@ async function main() {
68
178
  let report;
69
179
  try {
70
180
  report = importConversation({
71
- conversation, repoId, store,
72
- directory: join(app, ".memory/handoffs", createHash("sha256").update(repoId + featureId).digest("hex")),
181
+ conversation,
182
+ repoId,
183
+ store,
184
+ directory: join(app, ".memory/handoffs", createHash("sha256")
185
+ .update(repoId + featureId)
186
+ .digest("hex")),
73
187
  });
74
188
  }
75
189
  finally {
76
190
  store.close();
77
191
  }
78
192
  // The destination feature binding is installed only after the history has been saved.
79
- applyConnectionPlan(planConnection({ workspace, appRoot: app, database, repoId, clients: ["codex"] }));
80
- console.log(JSON.stringify({ title: conversation.title, workspace, repoId, ...report, ready: true, destinationCommand }, null, 2));
193
+ applyConnectionPlan(planConnection({
194
+ workspace,
195
+ appRoot: app,
196
+ database,
197
+ repoId,
198
+ clients: ["codex"],
199
+ }));
200
+ console.log(JSON.stringify({
201
+ title: conversation.title,
202
+ workspace,
203
+ repoId,
204
+ ...report,
205
+ ready: true,
206
+ destinationCommand,
207
+ }, null, 2));
81
208
  if (values.launch) {
82
- execFileSync(launch.command, launch.args, { cwd: workspace, stdio: "inherit", env: { ...process.env, ...launch.env } });
209
+ execFileSync(launch.command, launch.args, {
210
+ cwd: workspace,
211
+ stdio: "inherit",
212
+ env: { ...process.env, ...launch.env },
213
+ });
83
214
  }
84
215
  else {
85
216
  console.log("Continue in the destination workspace with this command, or rerun handoff with --launch:");
@@ -0,0 +1,128 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+ import { createHash } from "node:crypto";
4
+ import { findConversations, importConversation } from "./handoff.js";
5
+ import { captureTranscript } from "./transcript.js";
6
+ import { flush } from "./hooks.js";
7
+ import { discoverJsonl } from "./providers/jsonl.js";
8
+ export function discoverConversations(store, repoId, workspace, roots = {
9
+ codex: join(homedir(), ".codex/sessions"),
10
+ claude: join(homedir(), ".claude/projects"),
11
+ antigravity: ["antigravity", "antigravity-cli", "antigravity-ide"].map((n) => join(homedir(), ".gemini", n)),
12
+ }) {
13
+ const conversations = store
14
+ .listConversations(repoId)
15
+ .map((c) => ({
16
+ id: c.conversationId,
17
+ title: c.title,
18
+ workspace,
19
+ root: "",
20
+ modified: "",
21
+ client: c.client,
22
+ sourceId: c.conversationId,
23
+ storedId: c.conversationId,
24
+ }));
25
+ const diagnostics = [];
26
+ for (const [client, root] of [
27
+ ["codex", roots.codex],
28
+ ["claude", roots.claude],
29
+ ]) {
30
+ const result = discoverJsonl(client, root, workspace);
31
+ conversations.push(...result.conversations);
32
+ diagnostics.push(...result.diagnostics);
33
+ }
34
+ try {
35
+ conversations.push(...findConversations(roots.antigravity, workspace).map((c) => ({
36
+ ...c,
37
+ id: "antigravity:" + c.id,
38
+ sourceId: c.id,
39
+ client: "antigravity",
40
+ })));
41
+ }
42
+ catch {
43
+ diagnostics.push("Antigravity history unavailable or unsupported");
44
+ }
45
+ const seen = new Set();
46
+ const unique = conversations.filter((c) => {
47
+ if (!c.storedId) {
48
+ try {
49
+ store.sessionConversation({
50
+ repoId,
51
+ client: c.client,
52
+ nativeSessionId: c.sourceId,
53
+ });
54
+ return false;
55
+ }
56
+ catch {
57
+ /* external conversation not captured yet */
58
+ }
59
+ }
60
+ const identity = c.storedId ?? c.client + ":" + c.sourceId;
61
+ if (seen.has(identity))
62
+ return false;
63
+ seen.add(identity);
64
+ return true;
65
+ });
66
+ return { conversations: unique, diagnostics };
67
+ }
68
+ export function importDiscovered(store, repoId, source, directory) {
69
+ if (source.storedId) {
70
+ if (!store
71
+ .listConversations(repoId)
72
+ .some((c) => c.conversationId === source.storedId))
73
+ throw new Error("Unknown stored conversation");
74
+ return source.storedId;
75
+ }
76
+ const key = {
77
+ repoId,
78
+ client: source.client,
79
+ nativeSessionId: source.sourceId,
80
+ };
81
+ try {
82
+ return store.sessionConversation(key).conversationId;
83
+ }
84
+ catch {
85
+ /* Import only previously uncaptured sources. */
86
+ }
87
+ const conversation = store.ensureSession(key, {
88
+ workspace: source.workspace,
89
+ });
90
+ const queue = join(directory, createHash("sha256").update(source.id).digest("hex"));
91
+ if (source.client === "antigravity") {
92
+ const report = importConversation({
93
+ conversation: { ...source, id: source.sourceId },
94
+ repoId,
95
+ directory: queue,
96
+ store,
97
+ });
98
+ store.importLegacyEvidence(key, report.featureId);
99
+ }
100
+ else {
101
+ if (!source.transcript || !["codex", "claude"].includes(source.client))
102
+ throw new Error("Unsupported history provider");
103
+ let previous = -1;
104
+ for (;;) {
105
+ const report = captureTranscript({
106
+ directory: queue,
107
+ client: source.client,
108
+ scope: { repoId, featureId: conversation.conversationId },
109
+ sessionId: source.sourceId,
110
+ path: source.transcript,
111
+ session: key,
112
+ });
113
+ if (report.remainingBytes === 0 || report.offset === previous)
114
+ break;
115
+ previous = report.offset;
116
+ }
117
+ for (;;) {
118
+ const report = flush(queue, (event) => {
119
+ store.appendEvidence(key, event);
120
+ });
121
+ if (!report.pending)
122
+ break;
123
+ if (!report.delivered)
124
+ throw new Error("History remains queued; delivery failed");
125
+ }
126
+ }
127
+ return conversation.conversationId;
128
+ }