@xevy/cli 0.1.28 → 0.1.29
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/README.md +8 -2
- package/bin/dev-session.mjs +20 -5
- package/bin/remote-dev.mjs +99 -21
- package/bin/xevy.mjs +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -159,7 +159,8 @@ xevy dev xevy/xevyai # start or reuse your Dev Session and op
|
|
|
159
159
|
xevy dev # same, from a folder already set up by xevy dev
|
|
160
160
|
xevy dev xevy/xevyai --new-conversation # keep the Dev Session, start a fresh conversation
|
|
161
161
|
xevy dev xevy/xevyai --dir ~/work/shop # work from another folder
|
|
162
|
-
xevy dev xevy/xevyai --new # start another Dev Session
|
|
162
|
+
xevy dev xevy/xevyai --new # start another Dev Session, with a new conversation
|
|
163
|
+
xevy dev xevy/xevyai --new --keep-conversation # start another Dev Session, keep the conversation
|
|
163
164
|
xevy dev xevy/xevyai -- --verbose # pass options to pi after --
|
|
164
165
|
```
|
|
165
166
|
|
|
@@ -172,7 +173,12 @@ cleared once they are saved in the Dev Session.
|
|
|
172
173
|
The AI works from `~/xevy/<project>`, or the folder given with `--dir`. Only a
|
|
173
174
|
`.xevy` folder is created there, readable by you alone. It holds the link to the
|
|
174
175
|
project and your conversation, so running the same command again picks up the
|
|
175
|
-
same Dev Session and the same conversation.
|
|
176
|
+
same Dev Session and the same conversation. A conversation belongs to one Dev
|
|
177
|
+
Session: when the AI opens a different one (a `--new` start, another running
|
|
178
|
+
session picked, or the saved one has ended), the CLI starts a new conversation
|
|
179
|
+
and says so. A Dev Session that moved to another worker keeps its conversation.
|
|
180
|
+
Add `--keep-conversation` to carry the saved conversation into another Dev
|
|
181
|
+
Session. If a start is interrupted, the next
|
|
176
182
|
run finishes it without creating a second Dev Session. A folder that already
|
|
177
183
|
holds a local copy of the project is left untouched.
|
|
178
184
|
|
package/bin/dev-session.mjs
CHANGED
|
@@ -223,11 +223,23 @@ function extractApiError(payload, fallback) {
|
|
|
223
223
|
return fallback;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/** Milliseconds from a Retry-After header (seconds or an HTTP date), or null. */
|
|
227
|
+
function parseRetryAfterMs(header) {
|
|
228
|
+
if (!header) return null;
|
|
229
|
+
const seconds = Number(header);
|
|
230
|
+
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1000;
|
|
231
|
+
const date = Date.parse(header);
|
|
232
|
+
return Number.isFinite(date) ? Math.max(0, date - Date.now()) : null;
|
|
233
|
+
}
|
|
234
|
+
|
|
226
235
|
export class DevSessionApiError extends Error {
|
|
227
|
-
constructor(status, message, payload) {
|
|
236
|
+
constructor(status, message, payload, retryAfterMs = null) {
|
|
228
237
|
super(message);
|
|
229
238
|
this.name = "DevSessionApiError";
|
|
230
239
|
this.status = status;
|
|
240
|
+
const hint = payload && typeof payload === "object" ? Number(payload.error?.retryAfterMs ?? payload.details?.retryAfterMs) : NaN;
|
|
241
|
+
// Retry-After header first, else the body's retryAfterMs; null when the server gave no hint.
|
|
242
|
+
this.retryAfterMs = retryAfterMs ?? (Number.isFinite(hint) && hint >= 0 ? hint : null);
|
|
231
243
|
this.code = payload && typeof payload === "object"
|
|
232
244
|
? payload.code || payload.error?.code || null
|
|
233
245
|
: null;
|
|
@@ -282,7 +294,7 @@ export function createApiClient({ base, token, fetchImpl, registerController, se
|
|
|
282
294
|
}
|
|
283
295
|
const fallback = `Xevy request failed (HTTP ${response.status}).`;
|
|
284
296
|
const message = redactSensitive(extractApiError(payload, fallback), secrets);
|
|
285
|
-
throw new DevSessionApiError(response.status, message, payload);
|
|
297
|
+
throw new DevSessionApiError(response.status, message, payload, parseRetryAfterMs(response.headers?.get?.("retry-after")));
|
|
286
298
|
} catch (error) {
|
|
287
299
|
if (error instanceof DevSessionApiError) throw error;
|
|
288
300
|
if (controller.signal.aborted) {
|
|
@@ -313,7 +325,7 @@ function formatTask(task) {
|
|
|
313
325
|
return `${code}${task.title} (${task.workspaceIdentifier}/${task.projectIdentifier})`;
|
|
314
326
|
}
|
|
315
327
|
|
|
316
|
-
export async function selectOne({ items, label, describe, interactive, ask, writeLine }) {
|
|
328
|
+
export async function selectOne({ items, label, choose, describe, interactive, ask, writeLine }) {
|
|
317
329
|
if (items.length === 0) return null;
|
|
318
330
|
if (items.length === 1) return items[0];
|
|
319
331
|
writeLine(`Multiple ${label} match:`);
|
|
@@ -322,7 +334,7 @@ export async function selectOne({ items, label, describe, interactive, ask, writ
|
|
|
322
334
|
throw new Error(`Multiple ${label} match; rerun interactively and choose one.`);
|
|
323
335
|
}
|
|
324
336
|
while (true) {
|
|
325
|
-
const answer = await ask(`Choose ${label
|
|
337
|
+
const answer = await ask(`Choose ${choose ?? label} [1-${items.length}]: `);
|
|
326
338
|
const index = Number.parseInt(answer, 10) - 1;
|
|
327
339
|
if (Number.isInteger(index) && index >= 0 && index < items.length) return items[index];
|
|
328
340
|
writeLine(`Enter a number from 1 to ${items.length}.`);
|
|
@@ -341,6 +353,7 @@ export async function selectDevSessionBranchTargets({ repositories, interactive,
|
|
|
341
353
|
const selected = await selectOne({
|
|
342
354
|
items: [...ordered, { id: "", label: "Repository default", branch: repository.defaultBranch || "remote default" }],
|
|
343
355
|
label: `branch targets for ${repository.displayName || repository.role || repository.id}`,
|
|
356
|
+
choose: `a branch target for ${repository.displayName || repository.role || repository.id}`,
|
|
344
357
|
describe: target => `${target.label} · ${target.branch}`,
|
|
345
358
|
interactive, ask, writeLine,
|
|
346
359
|
});
|
|
@@ -1104,6 +1117,7 @@ export async function runDevSession(options) {
|
|
|
1104
1117
|
const repository = await selectOne({
|
|
1105
1118
|
items: repositories,
|
|
1106
1119
|
label: "repositories",
|
|
1120
|
+
choose: "a repository",
|
|
1107
1121
|
describe: (item) => `${item.displayName || item.role}${item.defaultBranch ? ` · ${item.defaultBranch}` : ""}`,
|
|
1108
1122
|
interactive,
|
|
1109
1123
|
ask,
|
|
@@ -1144,7 +1158,7 @@ export async function runDevSession(options) {
|
|
|
1144
1158
|
);
|
|
1145
1159
|
const running = candidates?.personal?.existingSessions?.length ? candidates.personal.existingSessions
|
|
1146
1160
|
: candidates?.personal?.existingSessionId ? [{ id: candidates.personal.existingSessionId, title: "Running workspace" }] : [];
|
|
1147
|
-
const choice = options.newSession ? null : await selectOne({ items: running, label: "sessions", describe: (item) => `${item.title} · ${item.id}`, interactive, ask, writeLine });
|
|
1161
|
+
const choice = options.newSession ? null : await selectOne({ items: running, label: "sessions", choose: "a session", describe: (item) => `${item.title} · ${item.id}`, interactive, ask, writeLine });
|
|
1148
1162
|
const existingSessionId = choice?.id || null;
|
|
1149
1163
|
if (existingSessionId) {
|
|
1150
1164
|
sessionPath = `/api/agent/dev-sessions/${encodeURIComponent(existingSessionId)}`;
|
|
@@ -1160,6 +1174,7 @@ export async function runDevSession(options) {
|
|
|
1160
1174
|
const repository = await selectOne({
|
|
1161
1175
|
items: repositories,
|
|
1162
1176
|
label: "repositories",
|
|
1177
|
+
choose: "a repository",
|
|
1163
1178
|
describe: (item) => `${item.displayName || item.role}${item.defaultBranch ? ` · ${item.defaultBranch}` : ""}`,
|
|
1164
1179
|
interactive,
|
|
1165
1180
|
ask,
|
package/bin/remote-dev.mjs
CHANGED
|
@@ -32,8 +32,10 @@ const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{
|
|
|
32
32
|
const MAX_SESSION_MOVES = 5;
|
|
33
33
|
const RECONNECT_POLL_MS = 3_000;
|
|
34
34
|
const RECONNECT_MAX_WAIT_MS = 10 * 60_000;
|
|
35
|
+
const RECONNECT_MAX_BACKOFF_MS = 15_000;
|
|
35
36
|
const EXTENSION_DOWNLOAD_TIMEOUT_MS = 10_000;
|
|
36
37
|
const SUMMARY_TIMEOUT_MS = 5_000;
|
|
38
|
+
const SUMMARY_ATTEMPTS = 4;
|
|
37
39
|
const ACTIVE_AGENT_STATES = new Set(["working", "waiting"]);
|
|
38
40
|
|
|
39
41
|
export class RemoteDevError extends Error {
|
|
@@ -44,12 +46,12 @@ export class RemoteDevError extends Error {
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
const DEV_USAGE_LINE = "Usage: xevy dev [<workspace>/<project>] [--dir <path>] [--new] [--new-conversation] [--base <url>] [-- <pi options>]";
|
|
49
|
+
const DEV_USAGE_LINE = "Usage: xevy dev [<workspace>/<project>] [--dir <path>] [--new] [--new-conversation | --keep-conversation] [--base <url>] [-- <pi options>]";
|
|
48
50
|
|
|
49
51
|
/** Parses `xevy dev` arguments. Everything after `--` is passed to pi. */
|
|
50
52
|
export function parseRemoteDevArgs(argv) {
|
|
51
53
|
const args = [...argv];
|
|
52
|
-
const result = { help: false, target: null, dir: null, newSession: false, newConversation: false, base: null, piArgs: [] };
|
|
54
|
+
const result = { help: false, target: null, dir: null, newSession: false, newConversation: false, keepConversation: false, base: null, piArgs: [] };
|
|
53
55
|
const branchTargets = {};
|
|
54
56
|
let targetReference = "";
|
|
55
57
|
while (args.length > 0) {
|
|
@@ -58,6 +60,7 @@ export function parseRemoteDevArgs(argv) {
|
|
|
58
60
|
if (argument === "-h" || argument === "--help") return { ...result, help: true };
|
|
59
61
|
if (argument === "--new") { result.newSession = true; continue; }
|
|
60
62
|
if (argument === "--new-conversation") { result.newConversation = true; continue; }
|
|
63
|
+
if (argument === "--keep-conversation") { result.keepConversation = true; continue; }
|
|
61
64
|
if (argument === "--dir" || argument === "--base" || argument === "--request-key") {
|
|
62
65
|
const value = args.shift();
|
|
63
66
|
if (!value) throw new RemoteDevError(`Missing value for ${argument}`);
|
|
@@ -81,6 +84,7 @@ export function parseRemoteDevArgs(argv) {
|
|
|
81
84
|
if (targetReference) throw new RemoteDevError("`xevy dev` accepts one project.");
|
|
82
85
|
targetReference = argument;
|
|
83
86
|
}
|
|
87
|
+
if (result.newConversation && result.keepConversation) throw new RemoteDevError("Use either --new-conversation or --keep-conversation, not both.");
|
|
84
88
|
if (result.piArgs.some((arg) => /^(?:--model|--provider|--thinking|-m)(?:=|$)/.test(arg))) {
|
|
85
89
|
throw new RemoteDevError("Xevy selects models and reasoning automatically. Remove model/provider/thinking options and try again.");
|
|
86
90
|
}
|
|
@@ -188,22 +192,43 @@ function writeJson(file, value) {
|
|
|
188
192
|
writeFileAtomic(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
/** Writes project.json,
|
|
192
|
-
export function writeProjectFile(folder, { linked, workspace, project,
|
|
193
|
-
const keepConversation = !newConversation && typeof linked?.piSessionId === "string" && UUID_PATTERN.test(linked.piSessionId);
|
|
195
|
+
/** Writes project.json: the project link, the conversation id and the Dev Session that conversation belongs to. */
|
|
196
|
+
export function writeProjectFile(folder, { linked, workspace, project, piSessionId, conversationSessionId = null, now = new Date() }) {
|
|
194
197
|
const value = {
|
|
195
198
|
workspaceIdentifier: workspace.identifier,
|
|
196
199
|
projectIdentifier: project.identifier,
|
|
197
200
|
workspaceId: workspace.id,
|
|
198
201
|
projectId: project.id,
|
|
199
202
|
mode: "remote",
|
|
200
|
-
piSessionId
|
|
203
|
+
piSessionId,
|
|
204
|
+
conversationSessionId,
|
|
201
205
|
createdAt: typeof linked?.createdAt === "string" ? linked.createdAt : now.toISOString(),
|
|
202
206
|
};
|
|
203
207
|
writeJson(path.join(xevyDir(folder), "project.json"), value);
|
|
204
208
|
return value;
|
|
205
209
|
}
|
|
206
210
|
|
|
211
|
+
function savedConversationId(linked) {
|
|
212
|
+
return typeof linked?.piSessionId === "string" && UUID_PATTERN.test(linked.piSessionId) ? linked.piSessionId : null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Keeps the saved conversation only for the Dev Session it belongs to. A moved
|
|
217
|
+
* session is the same work: `requestedId` is the id the session was loaded by,
|
|
218
|
+
* before following any move. Folders set up before the owner was recorded
|
|
219
|
+
* treat the session saved in session.json as the owner.
|
|
220
|
+
* Returns the conversation id and why: first, asked, kept, same or changed.
|
|
221
|
+
*/
|
|
222
|
+
export function chooseConversation({ linked, savedSessionId, sessionId, requestedId, newConversation, keepConversation }) {
|
|
223
|
+
const saved = savedConversationId(linked);
|
|
224
|
+
if (!saved) return { piSessionId: randomUUID(), reason: "first" };
|
|
225
|
+
if (newConversation) return { piSessionId: randomUUID(), reason: "asked" };
|
|
226
|
+
if (keepConversation) return { piSessionId: saved, reason: "kept" };
|
|
227
|
+
const owner = typeof linked.conversationSessionId === "string" && linked.conversationSessionId ? linked.conversationSessionId : savedSessionId;
|
|
228
|
+
if (owner && (owner === sessionId || owner === requestedId)) return { piSessionId: saved, reason: "same" };
|
|
229
|
+
return { piSessionId: randomUUID(), reason: "changed" };
|
|
230
|
+
}
|
|
231
|
+
|
|
207
232
|
function emptySessionState(baseUrl) {
|
|
208
233
|
return { version: 1, baseUrl, sessionId: null, pendingRequestKey: null, repositories: [], hostname: null, branch: null, updatedAt: null };
|
|
209
234
|
}
|
|
@@ -325,20 +350,38 @@ function movedTargetOf(session) {
|
|
|
325
350
|
return next && next !== session.id ? next : null;
|
|
326
351
|
}
|
|
327
352
|
|
|
328
|
-
/**
|
|
353
|
+
/** A worker reconnecting, the session server restarting, or a gateway answering in its place. 4xx is never retried. */
|
|
354
|
+
function retryKind(error) {
|
|
355
|
+
if (!(error instanceof DevSessionApiError)) return null;
|
|
356
|
+
if (isApiError(error, 503, "LIVE_WORKER_RECONNECTING")) return "worker";
|
|
357
|
+
if (isApiError(error, 503, "LIVE_SERVER_RESTARTING")) return "server";
|
|
358
|
+
if ([502, 503, 504].includes(error.status) && !error.code) return "server";
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Retries calls while the worker reconnects or the server restarts instead of failing the run. */
|
|
329
363
|
export function withWorkerReconnect(api, { writeLine, sleep, maxWaitMs = RECONNECT_MAX_WAIT_MS }) {
|
|
364
|
+
// The restart line is said once per run; the worker line once per waiting call, as before.
|
|
365
|
+
let serverAnnounced = false;
|
|
330
366
|
return {
|
|
331
367
|
async request(requestPath, options) {
|
|
332
368
|
const deadline = Date.now() + maxWaitMs;
|
|
333
|
-
let
|
|
369
|
+
let workerAnnounced = false;
|
|
370
|
+
let backoffMs = RECONNECT_POLL_MS;
|
|
334
371
|
while (true) {
|
|
335
372
|
try {
|
|
336
373
|
return await api.request(requestPath, options);
|
|
337
374
|
} catch (error) {
|
|
338
|
-
|
|
339
|
-
if (!
|
|
340
|
-
|
|
341
|
-
|
|
375
|
+
const kind = retryKind(error);
|
|
376
|
+
if (!kind || Date.now() >= deadline) throw error;
|
|
377
|
+
if (kind === "worker" && !workerAnnounced) writeLine("Reconnecting to the Dev Session…");
|
|
378
|
+
if (kind === "server" && !serverAnnounced) writeLine("The Dev Session server is restarting. Waiting…");
|
|
379
|
+
if (kind === "worker") workerAnnounced = true;
|
|
380
|
+
else serverAnnounced = true;
|
|
381
|
+
const hinted = Number.isFinite(error.retryAfterMs) ? error.retryAfterMs : null;
|
|
382
|
+
const waitMs = Math.min(hinted ?? backoffMs, Math.max(0, deadline - Date.now()));
|
|
383
|
+
if (hinted === null) backoffMs = Math.min(backoffMs * 2, RECONNECT_MAX_BACKOFF_MS);
|
|
384
|
+
await sleep(waitMs);
|
|
342
385
|
}
|
|
343
386
|
}
|
|
344
387
|
},
|
|
@@ -419,11 +462,15 @@ async function readySession(api, session, { writeLine, sleep }) {
|
|
|
419
462
|
export async function resolveOrStartSession({ api, folder, state, project, options, interactive, ask, writeLine, sleep }) {
|
|
420
463
|
let session = null;
|
|
421
464
|
let sessionState = state;
|
|
465
|
+
// The id the session was loaded by, before following a move to another worker.
|
|
466
|
+
let requestedId = null;
|
|
422
467
|
|
|
423
468
|
if (sessionState.sessionId && !options.newSession) {
|
|
424
469
|
session = await loadSession(api, sessionState.sessionId);
|
|
425
|
-
if (isReusable(session, project))
|
|
426
|
-
|
|
470
|
+
if (isReusable(session, project)) {
|
|
471
|
+
requestedId = sessionState.sessionId;
|
|
472
|
+
writeLine("Reusing your Dev Session…");
|
|
473
|
+
} else session = null;
|
|
427
474
|
}
|
|
428
475
|
|
|
429
476
|
if (!session && sessionState.pendingRequestKey) {
|
|
@@ -431,6 +478,7 @@ export async function resolveOrStartSession({ api, folder, state, project, optio
|
|
|
431
478
|
const pending = await loadSession(api, sessionState.pendingRequestKey);
|
|
432
479
|
if (isReusable(pending, project)) {
|
|
433
480
|
session = pending;
|
|
481
|
+
requestedId = sessionState.pendingRequestKey;
|
|
434
482
|
writeLine("Reusing the Dev Session started on your last run…");
|
|
435
483
|
}
|
|
436
484
|
}
|
|
@@ -440,11 +488,12 @@ export async function resolveOrStartSession({ api, folder, state, project, optio
|
|
|
440
488
|
candidates = await api.request(`/api/agent/dev-session-candidates?projectId=${encodeURIComponent(project.id)}`);
|
|
441
489
|
const running = candidates?.personal?.existingSessions?.length ? candidates.personal.existingSessions
|
|
442
490
|
: candidates?.personal?.existingSessionId ? [{ id: candidates.personal.existingSessionId, title: "Running Dev Session" }] : [];
|
|
443
|
-
const choice = await selectOne({ items: running, label: "sessions", describe: (item) => `${item.title} · ${item.id}`, interactive, ask, writeLine });
|
|
491
|
+
const choice = await selectOne({ items: running, label: "sessions", choose: "a session", describe: (item) => `${item.title} · ${item.id}`, interactive, ask, writeLine });
|
|
444
492
|
if (choice) {
|
|
445
493
|
const chosen = await loadSession(api, choice.id);
|
|
446
494
|
if (isReusable(chosen, project)) {
|
|
447
495
|
session = chosen;
|
|
496
|
+
requestedId = choice.id;
|
|
448
497
|
writeLine("Opening your running Dev Session…");
|
|
449
498
|
}
|
|
450
499
|
}
|
|
@@ -459,6 +508,7 @@ export async function resolveOrStartSession({ api, folder, state, project, optio
|
|
|
459
508
|
const repository = await selectOne({
|
|
460
509
|
items: repositories,
|
|
461
510
|
label: "repositories",
|
|
511
|
+
choose: "a repository",
|
|
462
512
|
describe: (item) => `${item.displayName || item.role}${item.defaultBranch ? ` · ${item.defaultBranch}` : ""}`,
|
|
463
513
|
interactive, ask, writeLine,
|
|
464
514
|
});
|
|
@@ -483,6 +533,7 @@ export async function resolveOrStartSession({ api, folder, state, project, optio
|
|
|
483
533
|
session = started?.session;
|
|
484
534
|
if (!session?.id) throw new RemoteDevError("Xevy accepted the request but returned no Dev Session. Run the command again to retry it safely.");
|
|
485
535
|
sessionState = writeSessionState(folder, { ...sessionState, sessionId: session.id, pendingRequestKey: null });
|
|
536
|
+
requestedId = session.id;
|
|
486
537
|
}
|
|
487
538
|
|
|
488
539
|
session = await readySession(api, session, { writeLine, sleep });
|
|
@@ -495,7 +546,7 @@ export async function resolveOrStartSession({ api, folder, state, project, optio
|
|
|
495
546
|
if (!REQUIRED_WORKER_FEATURES.every((feature) => features.includes(feature))) {
|
|
496
547
|
throw new RemoteDevError(`This Dev Session's worker needs an update before it can run commands for a local AI. Try again later, or work in the Dev Session's terminal with \`xevy connect session/${session.id}\`.`);
|
|
497
548
|
}
|
|
498
|
-
return { session, state: sessionState };
|
|
549
|
+
return { session, state: sessionState, requestedId };
|
|
499
550
|
}
|
|
500
551
|
|
|
501
552
|
// ── Extension download ──────────────────────────────────────────────────────
|
|
@@ -566,6 +617,24 @@ export function formatExitSummary({ target, session, pending, dirArgument }) {
|
|
|
566
617
|
return `${parts.join(" · ")}${uploads}`;
|
|
567
618
|
}
|
|
568
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Reads the session for the exit summary. pi ran under spawnSync, so the event
|
|
622
|
+
* loop never saw the server close the keep-alive connections opened before
|
|
623
|
+
* launch; the first request can land on one and fail with "other side closed".
|
|
624
|
+
* A few more attempts reach a fresh connection. API errors are answers, not retried.
|
|
625
|
+
*/
|
|
626
|
+
async function loadSummarySession(api, sessionId, log) {
|
|
627
|
+
// Each failed attempt discards one dead pooled connection; the pool can hold several.
|
|
628
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
629
|
+
try {
|
|
630
|
+
return await loadSession(api, sessionId, { timeoutMs: SUMMARY_TIMEOUT_MS });
|
|
631
|
+
} catch (error) {
|
|
632
|
+
if (error instanceof DevSessionApiError || attempt >= SUMMARY_ATTEMPTS) throw error;
|
|
633
|
+
log({ op: "summary", status: "retry", attempt, error: error instanceof Error ? error.message : String(error) });
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
569
638
|
/**
|
|
570
639
|
* Runs `xevy dev` end to end and returns pi's exit code. All side effects are
|
|
571
640
|
* injected so tests can drive it with a fake fetch and a fake pi.
|
|
@@ -599,16 +668,21 @@ export async function runRemoteDev(options) {
|
|
|
599
668
|
|
|
600
669
|
prepareLocalFolder(folder);
|
|
601
670
|
logged.attach(folder);
|
|
602
|
-
|
|
603
|
-
|
|
671
|
+
// Link the folder first, so a run interrupted while the session starts can be resumed without naming the project.
|
|
672
|
+
writeProjectFile(folder, { linked, workspace, project, piSessionId: savedConversationId(linked) ?? randomUUID(), conversationSessionId: linked?.conversationSessionId ?? null });
|
|
604
673
|
const state = readSessionState(folder, base);
|
|
605
674
|
say(`Working from ${folder}`);
|
|
606
675
|
|
|
607
|
-
const { session } = await resolveOrStartSession({
|
|
676
|
+
const { session, requestedId } = await resolveOrStartSession({
|
|
608
677
|
api, folder, state, project,
|
|
609
678
|
options: { newSession: options.newSession, requestKey: options.requestKey, branchTargets: options.branchTargets },
|
|
610
679
|
interactive, ask, writeLine: say, sleep,
|
|
611
680
|
});
|
|
681
|
+
const conversation = chooseConversation({ linked, savedSessionId: state.sessionId, sessionId: session.id, requestedId, newConversation: options.newConversation, keepConversation: options.keepConversation });
|
|
682
|
+
const projectFile = writeProjectFile(folder, { linked, workspace, project, piSessionId: conversation.piSessionId, conversationSessionId: session.id });
|
|
683
|
+
logged.log({ op: "conversation", status: conversation.reason, sessionId: session.id });
|
|
684
|
+
if (conversation.reason === "asked") say("Starting a new conversation.");
|
|
685
|
+
if (conversation.reason === "changed") say("Starting a new conversation for this Dev Session.");
|
|
612
686
|
if (session.hostname) say(`Preview: https://${session.hostname}`);
|
|
613
687
|
|
|
614
688
|
const remoteExtension = await ensureRemoteExtension({ base, fetchImpl, homeDir, writeLine: say, warn });
|
|
@@ -620,11 +694,15 @@ export async function runRemoteDev(options) {
|
|
|
620
694
|
const exitCode = result.status ?? (result.signal ? 1 : 0);
|
|
621
695
|
logged.log({ op: "exit", status: exitCode });
|
|
622
696
|
|
|
623
|
-
// The extension may have moved the session while pi ran.
|
|
697
|
+
// The extension may have moved the session while pi ran; the conversation moves with it.
|
|
624
698
|
const finalState = readSessionState(folder, base);
|
|
699
|
+
if (finalState.sessionId && finalState.sessionId !== session.id) {
|
|
700
|
+
writeProjectFile(folder, { linked: projectFile, workspace, project, piSessionId: projectFile.piSessionId, conversationSessionId: finalState.sessionId });
|
|
701
|
+
logged.log({ op: "conversation", status: "moved", sessionId: finalState.sessionId });
|
|
702
|
+
}
|
|
625
703
|
let finalSession;
|
|
626
704
|
try {
|
|
627
|
-
finalSession = finalState.sessionId ? await
|
|
705
|
+
finalSession = finalState.sessionId ? await loadSummarySession(baseApi, finalState.sessionId, logged.log) : null;
|
|
628
706
|
if (finalSession && !isReusable(finalSession, project)) finalSession = null;
|
|
629
707
|
} catch (error) {
|
|
630
708
|
logged.log({ op: "summary", status: "error", error: error instanceof Error ? error.message : String(error) });
|
package/bin/xevy.mjs
CHANGED
|
@@ -148,7 +148,9 @@ record of the AI's recent edits until they are saved.
|
|
|
148
148
|
|
|
149
149
|
The AI works from ~/xevy/<project> (or the folder given with --dir). Only a
|
|
150
150
|
.xevy folder is created there. Run the same command again to pick up where
|
|
151
|
-
you left off.
|
|
151
|
+
you left off. A different Dev Session (a --new start, another session picked,
|
|
152
|
+
or the saved one has ended) starts a new conversation; a session that moved to
|
|
153
|
+
another worker keeps it.
|
|
152
154
|
|
|
153
155
|
Options:
|
|
154
156
|
--dir <path> Folder to work from instead of ~/xevy/<project>
|
|
@@ -157,6 +159,7 @@ Options:
|
|
|
157
159
|
--branch-target <repositoryUUID>=<targetId>
|
|
158
160
|
With --new: choose a configured branch target
|
|
159
161
|
--new-conversation Start a fresh conversation with the AI
|
|
162
|
+
--keep-conversation Keep the saved conversation, even in another Dev Session
|
|
160
163
|
--base <url> Xevy host
|
|
161
164
|
-- <pi options> Pass the remaining options to pi
|
|
162
165
|
|
package/package.json
CHANGED