@tinchu0/knitt 0.1.0-beta.5 → 0.1.0-beta.6

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 (42) hide show
  1. package/README.md +25 -27
  2. package/dist/apps/server/src/cloud-picker.js +245 -0
  3. package/dist/apps/server/src/onboarding.js +266 -0
  4. package/dist/apps/server/src/plugin-bootstrap.js +82 -0
  5. package/dist/apps/server/src/plugin-hook.js +51 -0
  6. package/dist/apps/server/src/plugin-main.js +10 -0
  7. package/dist/apps/server/src/server.js +126 -258
  8. package/dist/packages/adapters/src/cli.js +59 -190
  9. package/dist/packages/adapters/src/command.js +18 -149
  10. package/dist/packages/adapters/src/handoff.js +2 -3
  11. package/dist/packages/adapters/src/histories.js +2 -3
  12. package/dist/packages/adapters/src/hooks.js +43 -122
  13. package/dist/packages/adapters/src/launch.js +3 -10
  14. package/dist/packages/adapters/src/question-ui.js +4 -4
  15. package/dist/packages/adapters/src/repository.js +5 -32
  16. package/dist/packages/adapters/src/scope.js +1 -1
  17. package/dist/packages/adapters/src/server-name.js +1 -2
  18. package/dist/packages/adapters/src/transcript.js +15 -70
  19. package/dist/packages/cloud/src/client.js +40 -0
  20. package/dist/packages/cloud/src/local-sync.js +300 -0
  21. package/dist/packages/installer/src/antigravity.js +3 -3
  22. package/dist/packages/installer/src/cli.js +79 -194
  23. package/dist/packages/installer/src/cloud-cli.js +199 -0
  24. package/dist/packages/installer/src/connections.js +43 -170
  25. package/dist/packages/installer/src/runtime.js +10 -72
  26. package/dist/packages/memory/src/store.js +58 -200
  27. package/dist/skills/knit/SKILL.md +20 -4
  28. package/docs/clients/npm-installation.md +17 -13
  29. package/docs/usage.md +19 -10
  30. package/package.json +9 -7
  31. package/dist/apps/server/src/conversation-server.js +0 -203
  32. package/dist/memory-schema.json +0 -1
  33. package/dist/packages/adapters/src/discovery.js +0 -128
  34. package/dist/packages/adapters/src/providers/jsonl.js +0 -105
  35. package/dist/packages/adapters/src/status.js +0 -81
  36. package/dist/packages/contracts/src/conversations.js +0 -30
  37. package/dist/packages/memory/src/checkpoints.js +0 -68
  38. package/dist/packages/memory/src/context.js +0 -91
  39. package/dist/packages/memory/src/conversations.js +0 -148
  40. package/dist/packages/memory/src/migrations.js +0 -55
  41. package/dist/skills/continue-chat/SKILL.md +0 -15
  42. package/docs/clients/local-agent-memory.md +0 -50
@@ -1,116 +1,58 @@
1
- import { recordCaptureStatus, readCaptureStatuses, pendingForSession, } from './status.js';
2
- import { execFileSync } from 'node:child_process';
3
- import { mkdirSync } from 'node:fs';
4
- import { dirname, resolve } from 'node:path';
5
- import { capture, flush, recallInstruction, selectionInstruction, } from './hooks.js';
6
- import { resolveScope, resolveConnection } from './scope.js';
7
- import { captureTranscript } from './transcript.js';
8
- import { MemoryStore } from '../../memory/src/store.js';
1
+ import { syncWorkspace } from '../../cloud/src/local-sync.js';
2
+ import { defaultHome } from '../../installer/src/runtime.js';
3
+ import { mkdirSync } from "node:fs";
4
+ import { dirname, resolve } from "node:path";
5
+ import { capture, flush, recallInstruction, selectionInstruction } from "./hooks.js";
6
+ import { resolveScope, resolveConnection } from "./scope.js";
7
+ import { captureTranscript } from "./transcript.js";
8
+ import { MemoryStore } from "../../memory/src/store.js";
9
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');
15
10
  try {
16
- if (!['claude', 'codex', 'antigravity'].includes(client ?? ''))
17
- throw new Error('Choose claude, codex or antigravity');
11
+ if (!["claude", "codex", "antigravity"].includes(client ?? ""))
12
+ throw new Error("Choose claude, codex or antigravity");
18
13
  let payload = {};
19
- if (action === 'capture' || action === 'recall') {
14
+ if (action === "capture" || action === "recall") {
20
15
  const chunks = [];
21
16
  let bytes = 0;
22
17
  for await (const chunk of process.stdin) {
23
18
  bytes += chunk.length;
24
19
  if (bytes > 1024 * 1024)
25
- throw new Error('Hook input exceeds 1 MiB');
20
+ throw new Error("Hook input exceeds 1 MiB");
26
21
  chunks.push(chunk);
27
22
  }
28
- const text = Buffer.concat(chunks).toString('utf8').trim();
23
+ const text = Buffer.concat(chunks).toString("utf8").trim();
29
24
  if (text) {
30
25
  const parsed = JSON.parse(text);
31
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
32
- throw new Error('Hook input must be an object');
26
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
27
+ throw new Error("Hook input must be an object");
33
28
  payload = parsed;
34
29
  }
35
30
  }
36
- let scope;
37
- let selectedSessionId;
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 });
31
+ // Private capture is independent of continuation selection, including new sessions.
32
+ if (action === 'capture') {
49
33
  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
- };
34
+ await syncWorkspace(process.env.KNITT_HOME ?? process.env.SHARED_MEMORY_HOME ?? defaultHome(), process.env, String(payload.cwd ?? process.env.MEMORY_WORKSPACE ?? process.cwd()));
94
35
  }
95
- finally {
96
- store.close();
36
+ catch (error) {
37
+ console.error('Knitt private sync queued: ' + String(error));
97
38
  }
98
39
  }
99
- else if (process.env.MEMORY_SESSION_SELECTION === '1' &&
100
- action !== 'flush') {
40
+ let scope;
41
+ let selectedSessionId;
42
+ if (process.env.MEMORY_SESSION_SELECTION === "1" && action !== "flush") {
101
43
  const { repoId, workspace } = resolveConnection(payload);
102
44
  const sessionId = payload.session_id ?? payload.conversationId;
103
- if (typeof sessionId !== 'string' || !sessionId)
104
- throw new Error('A native session ID is required for chat selection');
45
+ if (typeof sessionId !== "string" || !sessionId)
46
+ throw new Error("A native session ID is required for chat selection");
105
47
  selectedSessionId = sessionId;
106
- const path = process.env.MEMORY_DB ?? resolve('.memory/events.sqlite');
48
+ const path = process.env.MEMORY_DB ?? resolve(".memory/events.sqlite");
107
49
  mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
108
50
  const store = new MemoryStore(path);
109
51
  let selection;
110
52
  try {
111
53
  selection = store.sessionSelection(repoId, sessionId);
112
54
  if (!selection && process.env.MEMORY_LAUNCH_FEATURE) {
113
- store.selectSession(repoId, sessionId, process.env.MEMORY_LAUNCH_FEATURE, process.env.MEMORY_LAUNCH_TITLE ?? 'Selected chat');
55
+ store.selectSession(repoId, sessionId, process.env.MEMORY_LAUNCH_FEATURE, process.env.MEMORY_LAUNCH_TITLE ?? "Selected chat");
114
56
  selection = store.sessionSelection(repoId, sessionId);
115
57
  }
116
58
  }
@@ -118,142 +60,69 @@ try {
118
60
  store.close();
119
61
  }
120
62
  if (!selection) {
121
- if (action === 'recall')
63
+ if (action === "recall")
122
64
  console.log(JSON.stringify(selectionInstruction(client, repoId, sessionId, workspace, process.env.MEMORY_MCP_SERVER)));
123
65
  else {
124
- console.error('Shared memory: no chat selected for this session; capture skipped');
125
- console.log('{}');
66
+ console.error("Shared memory: no chat selected for this session; capture skipped");
67
+ console.log("{}");
126
68
  }
127
69
  process.exit(0);
128
70
  }
71
+ // Shared source text can occur anywhere in the host transcript. Agents save
72
+ // recipient-authored progress explicitly into the continuation instead.
73
+ if (action === "capture" && selection.featureId.startsWith("cloud-work:")) {
74
+ console.log("{}");
75
+ process.exit(0);
76
+ }
129
77
  scope = { repoId, featureId: selection.featureId };
130
78
  }
131
79
  else
132
80
  scope = resolveScope(payload);
133
- if (action === 'recall') {
134
- console.log(JSON.stringify(recallInstruction(client, scope, process.env.MEMORY_WORKSPACE, selectedSessionId, selectedSessionToken, process.env.MEMORY_MCP_SERVER)));
81
+ if (action === "recall") {
82
+ console.log(JSON.stringify(recallInstruction(client, scope, process.env.MEMORY_WORKSPACE, selectedSessionId, process.env.MEMORY_MCP_SERVER)));
135
83
  }
136
- else if (action === 'capture' || action === 'flush') {
137
- const directory = statusDirectory;
138
- if (action === 'capture') {
84
+ else if (action === "capture" || action === "flush") {
85
+ const directory = process.env.MEMORY_QUEUE ?? resolve(".memory/queue");
86
+ if (action === "capture") {
139
87
  const transcriptPath = payload.transcript_path ?? payload.transcriptPath;
140
- if (typeof transcriptPath === 'string' && transcriptPath) {
141
- const report = captureTranscript({
142
- directory,
143
- client: client,
144
- scope,
145
- sessionId: String(payload.session_id ?? payload.conversationId ?? ''),
88
+ if (typeof transcriptPath === "string" && transcriptPath) {
89
+ console.error(JSON.stringify(captureTranscript({
90
+ directory, client: client, scope,
91
+ sessionId: String(payload.session_id ?? payload.conversationId ?? ""),
146
92
  path: transcriptPath,
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';
93
+ })));
160
94
  }
161
95
  else {
162
- capture(directory, client, scope, payload, conversationMode ? captureSession : undefined);
163
- capturedAt = new Date().toISOString();
164
- captureState = 'captured';
96
+ capture(directory, client, scope, payload);
165
97
  }
166
98
  }
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
- }
183
- const path = process.env.MEMORY_DB ?? resolve('.memory/events.sqlite');
99
+ const report = flush(directory, event => {
100
+ const path = process.env.MEMORY_DB ?? resolve(".memory/events.sqlite");
184
101
  mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
185
- const store = new MemoryStore(path, {
186
- conversationMode: !!queuedSession,
187
- });
102
+ const store = new MemoryStore(path);
188
103
  try {
189
- if (queuedSession)
190
- store.appendEvidence(queuedSession, event);
191
- else
192
- store.save(event);
104
+ store.save(event);
193
105
  }
194
106
  finally {
195
107
  store.close();
196
108
  }
197
- if (queuedSession)
198
- touched.get(JSON.stringify(queuedSession)).delivered = true;
199
109
  });
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
- }
218
110
  console.error(JSON.stringify(report));
219
- console.log('{}');
111
+ console.log("{}");
220
112
  }
221
113
  else
222
- throw new Error('Choose capture, recall or flush');
114
+ throw new Error("Choose capture, recall or flush");
223
115
  }
224
116
  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
- }
241
117
  // Hook failure must not prevent the user's coding turn.
242
- console.error('Shared memory: ' +
243
- (error instanceof Error ? error.message : String(error)));
244
- if (action === 'recall' && process.env.MEMORY_WORKSPACE) {
245
- const message = 'Memory handoff blocked. ' +
246
- (error instanceof Error ? error.message : String(error));
118
+ console.error("Shared memory: " + (error instanceof Error ? error.message : String(error)));
119
+ if (action === "recall" && process.env.MEMORY_WORKSPACE) {
120
+ const message = "Memory handoff blocked. " + (error instanceof Error ? error.message : String(error));
247
121
  console.log(JSON.stringify({
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
- },
122
+ continue: false, systemMessage: message,
123
+ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: message + " Do not continue imported work or edit another project from this chat." },
255
124
  }));
256
125
  }
257
126
  else
258
- console.log('{}');
127
+ console.log("{}");
259
128
  }
@@ -1,7 +1,3 @@
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";
5
1
  import { createInterface } from "node:readline/promises";
6
2
  import { pickConversation } from "./picker.js";
7
3
  import { parseArgs } from "node:util";
@@ -11,114 +7,29 @@ import { fileURLToPath } from "node:url";
11
7
  import { mkdirSync } from "node:fs";
12
8
  import { execFileSync } from "node:child_process";
13
9
  import { createHash } from "node:crypto";
14
- import { findConversations, selectConversation, importConversation, } from "./handoff.js";
10
+ import { findConversations, selectConversation, importConversation } from "./handoff.js";
15
11
  import { MemoryStore } from "../../memory/src/store.js";
16
12
  import { resolveRepository } from "./repository.js";
17
- import { planConnection, applyConnectionPlan, } from "../../installer/src/connections.js";
13
+ import { planConnection, applyConnectionPlan } from "../../installer/src/connections.js";
18
14
  import { codexLaunch, displayCommand } from "./launch.js";
19
15
  async function main() {
20
16
  const { values, positionals } = parseArgs({
21
17
  allowPositionals: true,
22
18
  options: {
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 },
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 },
32
22
  launch: { type: "boolean", default: false },
33
23
  },
34
24
  });
35
25
  const action = positionals[0];
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") {
26
+ if (!["list", "handoff"].includes(action) || values.from !== "antigravity" || values.to !== "codex") {
110
27
  throw new Error("Usage: npm run memory -- list [--workspace PATH] | handoff --conversation TITLE_OR_ID [--workspace PATH] [--preview]. Supported handoff: Antigravity to Codex.");
111
28
  }
112
- const roots = values["data-root"] ??
113
- ["antigravity", "antigravity-cli", "antigravity-ide"].map((name) => join(homedir(), ".gemini", name));
29
+ const roots = values["data-root"] ?? ["antigravity", "antigravity-cli", "antigravity-ide"].map(name => join(homedir(), ".gemini", name));
114
30
  const conversations = findConversations(roots, values.workspace);
115
31
  if (action === "list") {
116
- console.log(JSON.stringify(conversations.map(({ id, title, workspace, modified }) => ({
117
- id,
118
- title,
119
- workspace,
120
- modified,
121
- })), null, 2));
32
+ console.log(JSON.stringify(conversations.map(({ id, title, workspace, modified }) => ({ id, title, workspace, modified })), null, 2));
122
33
  return;
123
34
  }
124
35
  let conversation;
@@ -127,17 +38,9 @@ async function main() {
127
38
  else {
128
39
  if (!process.stdin.isTTY)
129
40
  throw new Error("User selection required. Run handoff interactively to open the chat picker, or pass an explicit --conversation.");
130
- const reader = createInterface({
131
- input: process.stdin,
132
- output: process.stdout,
133
- });
41
+ const reader = createInterface({ input: process.stdin, output: process.stdout });
134
42
  try {
135
- conversation = await pickConversation(conversations, {
136
- ask: (prompt) => reader.question(prompt),
137
- write: (text) => {
138
- process.stdout.write(text);
139
- },
140
- });
43
+ conversation = await pickConversation(conversations, { ask: prompt => reader.question(prompt), write: text => { process.stdout.write(text); } });
141
44
  }
142
45
  finally {
143
46
  reader.close();
@@ -151,26 +54,13 @@ async function main() {
151
54
  const app = resolve(fileURLToPath(new URL("../../../", import.meta.url)));
152
55
  const database = process.env.MEMORY_DB ?? join(app, ".memory/events.sqlite");
153
56
  const featureId = "antigravity:" + conversation.id;
154
- const launch = codexLaunch(workspace, {
155
- featureId,
156
- title: conversation.title,
157
- });
57
+ const launch = codexLaunch(workspace, { featureId, title: conversation.title });
158
58
  const destinationCommand = displayCommand("env", [
159
59
  ...Object.entries(launch.env).map(([name, value]) => name + "=" + value),
160
- launch.command,
161
- ...launch.args,
60
+ launch.command, ...launch.args,
162
61
  ]);
163
62
  if (values.preview) {
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));
63
+ console.log(JSON.stringify({ action, title: conversation.title, workspace, repoId, featureId, destination: "codex", database, changesApplied: false }, null, 2));
174
64
  return;
175
65
  }
176
66
  mkdirSync(dirname(database), { recursive: true, mode: 0o700 });
@@ -178,39 +68,18 @@ async function main() {
178
68
  let report;
179
69
  try {
180
70
  report = importConversation({
181
- conversation,
182
- repoId,
183
- store,
184
- directory: join(app, ".memory/handoffs", createHash("sha256")
185
- .update(repoId + featureId)
186
- .digest("hex")),
71
+ conversation, repoId, store,
72
+ directory: join(app, ".memory/handoffs", createHash("sha256").update(repoId + featureId).digest("hex")),
187
73
  });
188
74
  }
189
75
  finally {
190
76
  store.close();
191
77
  }
192
78
  // The destination feature binding is installed only after the history has been saved.
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));
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));
208
81
  if (values.launch) {
209
- execFileSync(launch.command, launch.args, {
210
- cwd: workspace,
211
- stdio: "inherit",
212
- env: { ...process.env, ...launch.env },
213
- });
82
+ execFileSync(launch.command, launch.args, { cwd: workspace, stdio: "inherit", env: { ...process.env, ...launch.env } });
214
83
  }
215
84
  else {
216
85
  console.log("Continue in the destination workspace with this command, or rerun handoff with --launch:");
@@ -1,4 +1,3 @@
1
- import { canonicalWorkspace } from "./repository.js";
2
1
  import { historyTimestamp } from "./history-time.js";
3
2
  import { execFileSync } from "node:child_process";
4
3
  import { existsSync, realpathSync } from "node:fs";
@@ -50,7 +49,7 @@ export function findConversations(roots, workspace) {
50
49
  if (!/^[A-Za-z0-9_-]{1,128}$/.test(id))
51
50
  continue;
52
51
  for (const directory of workspaces(String(row.workspace_uris))) {
53
- if (workspace && canonicalWorkspace(directory) !== canonicalWorkspace(workspace) && (!expectedRepository || commonDirectory(directory) !== expectedRepository))
52
+ if (workspace && resolve(directory) !== resolve(workspace) && (!expectedRepository || commonDirectory(directory) !== expectedRepository))
54
53
  continue;
55
54
  const conversation = { id, title: String(row.title), workspace: directory, root, modified: String(row.last_modified_time) };
56
55
  const key = id + ":" + directory;
@@ -83,7 +82,7 @@ export function importConversation(options) {
83
82
  let source = "transcript";
84
83
  let captured = 0;
85
84
  if (existsSync(transcript)) {
86
- if (relative(realpathSync.native(conversation.root), realpathSync.native(transcript)).startsWith(".."))
85
+ if (relative(realpathSync(conversation.root), realpathSync(transcript)).startsWith(".."))
87
86
  throw new Error("Transcript escapes the source data directory");
88
87
  let previousOffset = -1;
89
88
  for (;;) {
@@ -1,4 +1,3 @@
1
- import { canonicalWorkspace } from './repository.js';
2
1
  import { historyTimestamp as timestamp } from './history-time.js';
3
2
  import { closeSync, existsSync, openSync, readSync, readdirSync, realpathSync, statSync } from 'node:fs';
4
3
  import { isAbsolute, join, relative, resolve } from 'node:path';
@@ -35,7 +34,7 @@ const object = (value) => !!value && typeof value === 'object' && !Array.isArray
35
34
  function inside(root, path) {
36
35
  if (!existsSync(path))
37
36
  return false;
38
- const delta = relative(realpathSync.native(root), realpathSync.native(path));
37
+ const delta = relative(realpathSync(root), realpathSync(path));
39
38
  return delta !== '..' && !delta.startsWith('..' + (process.platform === 'win32' ? '\\' : '/')) && !isAbsolute(delta);
40
39
  }
41
40
  function files(directory, recursive = false) {
@@ -198,7 +197,7 @@ export function discoverHistories(options) {
198
197
  return repositories.get(directory);
199
198
  };
200
199
  const expected = options.workspace ? common(options.workspace) : null;
201
- const matches = (directory) => !options.workspace || canonicalWorkspace(directory) === canonicalWorkspace(options.workspace) || (!!expected && common(directory) === expected);
200
+ const matches = (directory) => !options.workspace || resolve(directory) === resolve(options.workspace) || (!!expected && common(directory) === expected);
202
201
  const found = new Map();
203
202
  const add = (conversations) => {
204
203
  for (const conversation of conversations) {