@xevy/cli 0.1.29 → 0.1.30

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.
@@ -2,11 +2,13 @@
2
2
  * `xevy dev` — run the AI on this computer while its files and commands live
3
3
  * in a remote Dev Session.
4
4
  *
5
- * The CLI only resolves the local folder, starts or reuses one Dev Session,
6
- * waits for it, downloads the remote-tools extension and launches pi. The
7
- * extension (loaded with an explicit `-e`) owns heartbeats, the events stream
8
- * and edit uploads for as long as pi runs. Nothing but `<folder>/.xevy/*` is
9
- * ever written into the project folder.
5
+ * The CLI resolves the local folder, reconnects to the folder's Dev Session
6
+ * when one is still running, downloads the remote-tools extension and
7
+ * launches pi. Without a running session pi opens straight away: the AI
8
+ * starts or links one itself, using the project or task named on the command
9
+ * line as hints. The extension (loaded with an explicit `-e`) owns heartbeats,
10
+ * the events stream and edit uploads for as long as pi runs. Nothing but
11
+ * `<folder>/.xevy/*` is ever written into the project folder.
10
12
  */
11
13
  import { randomUUID } from "node:crypto";
12
14
  import fs from "node:fs";
@@ -17,8 +19,6 @@ import {
17
19
  DevSessionApiError,
18
20
  parseDevTarget,
19
21
  redactSensitive,
20
- selectDevSessionBranchTargets,
21
- selectOne,
22
22
  waitForReady,
23
23
  } from "./dev-session.mjs";
24
24
 
@@ -46,12 +46,12 @@ export class RemoteDevError extends Error {
46
46
  }
47
47
  }
48
48
 
49
- const DEV_USAGE_LINE = "Usage: xevy dev [<workspace>/<project>] [--dir <path>] [--new] [--new-conversation | --keep-conversation] [--base <url>] [-- <pi options>]";
49
+ const DEV_USAGE_LINE = "Usage: xevy dev [<workspace>/<project> | task/<task-id-or-code>] [--dir <path>] [--new] [--new-conversation | --keep-conversation] [--base <url>] [-- <pi options>]";
50
50
 
51
51
  /** Parses `xevy dev` arguments. Everything after `--` is passed to pi. */
52
52
  export function parseRemoteDevArgs(argv) {
53
53
  const args = [...argv];
54
- const result = { help: false, target: null, dir: null, newSession: false, newConversation: false, keepConversation: false, base: null, piArgs: [] };
54
+ const result = { help: false, target: null, task: null, dir: null, newSession: false, newConversation: false, keepConversation: false, base: null, piArgs: [] };
55
55
  const branchTargets = {};
56
56
  let targetReference = "";
57
57
  while (args.length > 0) {
@@ -81,7 +81,7 @@ export function parseRemoteDevArgs(argv) {
81
81
  continue;
82
82
  }
83
83
  if (argument.startsWith("-")) throw new RemoteDevError(`Unknown option for \`xevy dev\`: ${argument}. Put pi options after \`--\`.`);
84
- if (targetReference) throw new RemoteDevError("`xevy dev` accepts one project.");
84
+ if (targetReference) throw new RemoteDevError("`xevy dev` accepts one project or task.");
85
85
  targetReference = argument;
86
86
  }
87
87
  if (result.newConversation && result.keepConversation) throw new RemoteDevError("Use either --new-conversation or --keep-conversation, not both.");
@@ -95,10 +95,11 @@ export function parseRemoteDevArgs(argv) {
95
95
  } catch (error) {
96
96
  throw new RemoteDevError(error instanceof Error ? error.message : String(error));
97
97
  }
98
- if (target.kind !== "personal") {
99
- throw new RemoteDevError(`\`xevy dev\` works on a project: use \`xevy dev <workspace>/<project>\`. To open this Dev Session in your terminal instead, run \`xevy connect ${targetReference}\`.`);
98
+ if (target.kind === "session") {
99
+ throw new RemoteDevError(`\`xevy dev\` works on a project or task: use \`xevy dev <workspace>/<project>\` or \`xevy dev task/<task-id-or-code>\`. To open this Dev Session in your terminal instead, run \`xevy connect ${targetReference}\`.`);
100
100
  }
101
- result.target = target;
101
+ if (target.kind === "task") result.task = target.taskReference;
102
+ else result.target = target;
102
103
  }
103
104
  if (Object.keys(branchTargets).length) {
104
105
  if (!result.newSession) throw new RemoteDevError("--branch-target applies when starting a new Dev Session; add --new.");
@@ -171,6 +172,24 @@ export function resolveLocalFolder({ dir, cwd, homeDir, target, writeLine }) {
171
172
  return { folder, linked };
172
173
  }
173
174
 
175
+ /**
176
+ * The folder for a run without a project: `--dir`, else the current folder.
177
+ * A folder holding a local checkout linked to Xevy stays untouched; its
178
+ * project's folder is used instead and the project becomes the hint.
179
+ */
180
+ export function chooseFolder({ dir, cwd, homeDir, target, writeLine }) {
181
+ if (target) return { ...resolveLocalFolder({ dir, cwd, homeDir, target, writeLine }), project: target };
182
+ const folder = dir ? expandHome(dir, homeDir, cwd) : cwd;
183
+ const linked = readLinkedProject(folder);
184
+ if (linked?.mode === "remote") return { folder, linked, project: { kind: "personal", workspaceIdentifier: linked.workspaceIdentifier, projectIdentifier: linked.projectIdentifier } };
185
+ if (linked && dir) throw new RemoteDevError(`${folder} holds a local copy of a project linked to Xevy. Choose an empty folder for --dir.`);
186
+ if (linked) {
187
+ const project = { kind: "personal", workspaceIdentifier: linked.workspaceIdentifier, projectIdentifier: linked.projectIdentifier };
188
+ return { ...resolveLocalFolder({ dir: null, cwd, homeDir, target: project, writeLine }), project };
189
+ }
190
+ return { folder, linked: null, project: null };
191
+ }
192
+
174
193
  /** Creates the folder and its `.xevy/` tree with owner-only permissions. */
175
194
  export function prepareLocalFolder(folder) {
176
195
  fs.mkdirSync(folder, { recursive: true, mode: 0o700 });
@@ -197,8 +216,8 @@ export function writeProjectFile(folder, { linked, workspace, project, piSession
197
216
  const value = {
198
217
  workspaceIdentifier: workspace.identifier,
199
218
  projectIdentifier: project.identifier,
200
- workspaceId: workspace.id,
201
- projectId: project.id,
219
+ workspaceId: workspace.id ?? null,
220
+ projectId: project.id ?? null,
202
221
  mode: "remote",
203
222
  piSessionId,
204
223
  conversationSessionId,
@@ -225,7 +244,9 @@ export function chooseConversation({ linked, savedSessionId, sessionId, requeste
225
244
  if (newConversation) return { piSessionId: randomUUID(), reason: "asked" };
226
245
  if (keepConversation) return { piSessionId: saved, reason: "kept" };
227
246
  const owner = typeof linked.conversationSessionId === "string" && linked.conversationSessionId ? linked.conversationSessionId : savedSessionId;
228
- if (owner && (owner === sessionId || owner === requestedId)) return { piSessionId: saved, reason: "same" };
247
+ // A conversation that never had a Dev Session continues until it gets one.
248
+ if (!owner) return { piSessionId: saved, reason: "same" };
249
+ if (owner === sessionId || owner === requestedId) return { piSessionId: saved, reason: "same" };
229
250
  return { piSessionId: randomUUID(), reason: "changed" };
230
251
  }
231
252
 
@@ -455,89 +476,15 @@ async function readySession(api, session, { writeLine, sleep }) {
455
476
  }
456
477
 
457
478
  /**
458
- * Starts or reuses the one Dev Session this folder works with. The request key
459
- * is written to session.json before the start request, so a rerun after a
460
- * crash reuses it and the server returns the same session.
479
+ * Reconnects to the Dev Session this folder last worked with, following a
480
+ * move to another worker. Null when it has ended; the AI then starts a new one.
461
481
  */
462
- export async function resolveOrStartSession({ api, folder, state, project, options, interactive, ask, writeLine, sleep }) {
463
- let session = null;
464
- let sessionState = state;
465
- // The id the session was loaded by, before following a move to another worker.
466
- let requestedId = null;
467
-
468
- if (sessionState.sessionId && !options.newSession) {
469
- session = await loadSession(api, sessionState.sessionId);
470
- if (isReusable(session, project)) {
471
- requestedId = sessionState.sessionId;
472
- writeLine("Reusing your Dev Session…");
473
- } else session = null;
474
- }
475
-
476
- if (!session && sessionState.pendingRequestKey) {
477
- // A previous start may have reached Xevy before this computer saw the reply.
478
- const pending = await loadSession(api, sessionState.pendingRequestKey);
479
- if (isReusable(pending, project)) {
480
- session = pending;
481
- requestedId = sessionState.pendingRequestKey;
482
- writeLine("Reusing the Dev Session started on your last run…");
483
- }
484
- }
485
-
486
- let candidates = null;
487
- if (!session && !options.newSession) {
488
- candidates = await api.request(`/api/agent/dev-session-candidates?projectId=${encodeURIComponent(project.id)}`);
489
- const running = candidates?.personal?.existingSessions?.length ? candidates.personal.existingSessions
490
- : candidates?.personal?.existingSessionId ? [{ id: candidates.personal.existingSessionId, title: "Running Dev Session" }] : [];
491
- const choice = await selectOne({ items: running, label: "sessions", choose: "a session", describe: (item) => `${item.title} · ${item.id}`, interactive, ask, writeLine });
492
- if (choice) {
493
- const chosen = await loadSession(api, choice.id);
494
- if (isReusable(chosen, project)) {
495
- session = chosen;
496
- requestedId = choice.id;
497
- writeLine("Opening your running Dev Session…");
498
- }
499
- }
500
- }
501
-
502
- if (!session) {
503
- candidates ||= await api.request(`/api/agent/dev-session-candidates?projectId=${encodeURIComponent(project.id)}`);
504
- const repositories = candidates?.repositories || [];
505
- if (repositories.length === 0) {
506
- throw new RemoteDevError(candidates?.personal?.blocker || "No linked repository is configured for this project.");
507
- }
508
- const repository = await selectOne({
509
- items: repositories,
510
- label: "repositories",
511
- choose: "a repository",
512
- describe: (item) => `${item.displayName || item.role}${item.defaultBranch ? ` · ${item.defaultBranch}` : ""}`,
513
- interactive, ask, writeLine,
514
- });
515
- const branchTargets = await selectDevSessionBranchTargets({ repositories, interactive, ask, writeLine, branchTargets: options.branchTargets });
516
- const requestKey = options.requestKey || sessionState.pendingRequestKey || randomUUID();
517
- sessionState = writeSessionState(folder, { ...sessionState, sessionId: null, pendingRequestKey: requestKey });
518
- writeLine(`Starting a new Dev Session with ${repository.displayName || repository.role}…`);
519
- const started = await api.request("/api/agent/dev-sessions", {
520
- method: "POST",
521
- body: {
522
- target: {
523
- kind: "personal",
524
- requestKey,
525
- projectId: project.id,
526
- agentLocation: "local",
527
- runtimeRepositoryId: repository.id,
528
- ...(branchTargets ? { branchTargets } : {}),
529
- },
530
- },
531
- timeoutMs: 60_000,
532
- });
533
- session = started?.session;
534
- if (!session?.id) throw new RemoteDevError("Xevy accepted the request but returned no Dev Session. Run the command again to retry it safely.");
535
- sessionState = writeSessionState(folder, { ...sessionState, sessionId: session.id, pendingRequestKey: null });
536
- requestedId = session.id;
537
- }
538
-
539
- session = await readySession(api, session, { writeLine, sleep });
540
- sessionState = writeSessionState(folder, sessionStateFrom(sessionState, session));
482
+ export async function reconnectSession({ api, folder, state, project, writeLine, sleep }) {
483
+ const loaded = await loadSession(api, state.sessionId);
484
+ if (!isReusable(loaded, project)) return null;
485
+ writeLine("Reusing your Dev Session…");
486
+ const session = await readySession(api, loaded, { writeLine, sleep });
487
+ const nextState = writeSessionState(folder, sessionStateFrom(state, session));
541
488
 
542
489
  if (ACTIVE_AGENT_STATES.has(session.agentState)) {
543
490
  writeLine("⚠ Another Xevy agent is active in this Dev Session. File edits cannot overwrite each other, but commands from both agents run side by side.");
@@ -546,7 +493,7 @@ export async function resolveOrStartSession({ api, folder, state, project, optio
546
493
  if (!REQUIRED_WORKER_FEATURES.every((feature) => features.includes(feature))) {
547
494
  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}\`.`);
548
495
  }
549
- return { session, state: sessionState, requestedId };
496
+ return { session, state: nextState, requestedId: state.sessionId };
550
497
  }
551
498
 
552
499
  // ── Extension download ──────────────────────────────────────────────────────
@@ -594,11 +541,18 @@ export function buildRemotePiArgs({ extensionFiles, remoteExtension, folder, piS
594
541
  return args;
595
542
  }
596
543
 
597
- /** Environment for pi. `XEVY_REMOTE_DEV_SESSION` means "running on the worker" and is never passed. */
598
- export function buildRemotePiEnv({ env, folder, base, explicitBase }) {
599
- const next = { ...env, XEVY_REMOTE_PROJECT_DIR: path.resolve(folder) };
544
+ /**
545
+ * Environment for pi. `XEVY_REMOTE_DEV_SESSION` means "running on the worker"
546
+ * and is never passed. The hints tell the AI what was asked for; it decides
547
+ * whether and how to start a Dev Session.
548
+ */
549
+ export function buildRemotePiEnv({ env, folder, base, explicitBase, hints = null, piSessionId = null }) {
550
+ const next = { ...env, XEVY_REMOTE_PROJECT_DIR: path.resolve(folder), XEVY_REMOTE_BASE: base };
600
551
  delete next.XEVY_REMOTE_DEV_SESSION;
552
+ delete next.XEVY_REMOTE_DEV_HINTS;
601
553
  if (explicitBase) next.XEVY_BASE = base;
554
+ if (hints) next.XEVY_REMOTE_DEV_HINTS = JSON.stringify(hints);
555
+ if (piSessionId) next.XEVY_REMOTE_PI_SESSION_ID = piSessionId;
602
556
  return next;
603
557
  }
604
558
 
@@ -606,9 +560,14 @@ function shellQuote(value) {
606
560
  return /^[A-Za-z0-9_@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
607
561
  }
608
562
 
609
- /** The one line printed after pi exits. `session` is null when it ended, undefined when it could not be checked. */
610
- export function formatExitSummary({ target, session, pending, dirArgument }) {
611
- const resume = ["xevy", "dev", `${target.workspaceIdentifier}/${target.projectIdentifier}`, ...(dirArgument ? ["--dir", dirArgument] : [])].map(shellQuote).join(" ");
563
+ /**
564
+ * The one line printed after pi exits. `session` is null when it ended,
565
+ * undefined when it could not be checked; `started` is false when the AI never
566
+ * started or linked one.
567
+ */
568
+ export function formatExitSummary({ target, session, pending, dirArgument, started = true }) {
569
+ const resume = ["xevy", "dev", ...(target ? [`${target.workspaceIdentifier}/${target.projectIdentifier}`] : []), ...(dirArgument ? ["--dir", dirArgument] : [])].map(shellQuote).join(" ");
570
+ if (!started) return `No Dev Session was started · Run again: ${resume}`;
612
571
  const uploads = pending > 0 ? ` · ${pending} ${pending === 1 ? "edit" : "edits"} not uploaded yet (sent on your next run)` : "";
613
572
  if (session === null) return `The Dev Session has ended · Start a new one: ${resume}${uploads}`;
614
573
  const parts = [session === undefined ? "Could not check the Dev Session" : "Dev Session still running", `Resume: ${resume}`];
@@ -636,78 +595,111 @@ async function loadSummarySession(api, sessionId, log) {
636
595
  }
637
596
 
638
597
  /**
639
- * Runs `xevy dev` end to end and returns pi's exit code. All side effects are
640
- * injected so tests can drive it with a fake fetch and a fake pi.
598
+ * Runs `xevy dev` end to end and returns pi's exit code. A folder whose Dev
599
+ * Session is still running reconnects first; otherwise pi opens without any
600
+ * request to Xevy. All side effects are injected so tests can drive it with a
601
+ * fake fetch and a fake pi.
641
602
  */
642
603
  export async function runRemoteDev(options) {
643
- const { base, token, fetchImpl = globalThis.fetch, homeDir, cwd, writeLine, warn = writeLine, ask, interactive = false, extensionFiles, spawnPi, beforeLaunch = () => {}, sleep = defaultSleep, env = process.env, correlationId = randomUUID() } = options;
604
+ const { base, token, fetchImpl = globalThis.fetch, homeDir, cwd, writeLine, warn = writeLine, extensionFiles, spawnPi, beforeLaunch = () => {}, sleep = defaultSleep, env = process.env, correlationId = randomUUID() } = options;
644
605
  const secrets = [token];
645
606
  const say = (value = "") => writeLine(redactSensitive(value, secrets, null));
646
607
 
647
- let target = options.target;
648
- if (!target) {
649
- const linked = readLinkedProject(cwd);
650
- if (!linked) throw new RemoteDevError(`${DEV_USAGE_LINE}\nRun it with a project, or from a folder already set up by \`xevy dev\`.`);
651
- target = { kind: "personal", workspaceIdentifier: linked.workspaceIdentifier, projectIdentifier: linked.projectIdentifier };
652
- }
653
-
654
- const { folder, linked } = resolveLocalFolder({ dir: options.dir, cwd, homeDir, target, writeLine: say });
608
+ const { folder, linked, project: target } = chooseFolder({ dir: options.dir, cwd, homeDir, target: options.target || null, writeLine: say });
655
609
  const logged = createLoggedFetch(fetchImpl, correlationId);
656
610
  const baseApi = createApiClient({ base, token, fetchImpl: logged.fetch, registerController: () => () => {}, secrets });
657
611
  const api = withWorkerReconnect(baseApi, { writeLine: say, sleep });
658
612
 
659
- try {
660
- await api.request("/api/profile");
661
- } catch (error) {
662
- if (error instanceof DevSessionApiError && (error.status === 401 || error.status === 403)) {
663
- throw new RemoteDevError("Xevy did not accept your API key. Run `xevy setup --credentials` to store a new one.");
664
- }
665
- throw error;
666
- }
667
- const { workspace, project } = await resolveProject(api, target);
668
-
669
613
  prepareLocalFolder(folder);
670
614
  logged.attach(folder);
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 });
673
- const state = readSessionState(folder, base);
674
615
  say(`Working from ${folder}`);
616
+ const state = readSessionState(folder, base);
675
617
 
676
- const { session, requestedId } = await resolveOrStartSession({
677
- api, folder, state, project,
678
- options: { newSession: options.newSession, requestKey: options.requestKey, branchTargets: options.branchTargets },
679
- interactive, ask, writeLine: say, sleep,
618
+ // Reconnect only to this folder's own running session; anything else is the AI's choice.
619
+ let reconnected = null;
620
+ let workspace = linked ? { id: linked.workspaceId ?? null, identifier: linked.workspaceIdentifier } : null;
621
+ let project = linked ? { id: linked.projectId ?? null, identifier: linked.projectIdentifier } : null;
622
+ if (linked?.mode === "remote" && state.sessionId && !options.newSession && !options.task) {
623
+ try {
624
+ await api.request("/api/profile");
625
+ } catch (error) {
626
+ if (error instanceof DevSessionApiError && (error.status === 401 || error.status === 403)) {
627
+ throw new RemoteDevError("Xevy did not accept your API key. Run `xevy setup --credentials` to store a new one.");
628
+ }
629
+ throw error;
630
+ }
631
+ ({ workspace, project } = await resolveProject(api, target));
632
+ reconnected = await reconnectSession({ api, folder, state, project, writeLine: say, sleep });
633
+ if (!reconnected) {
634
+ writeSessionState(folder, { ...state, sessionId: null });
635
+ say("Your last Dev Session has ended. The AI starts a new one when it needs it.");
636
+ }
637
+ }
638
+
639
+ const conversation = chooseConversation({
640
+ linked,
641
+ savedSessionId: state.sessionId,
642
+ sessionId: reconnected?.session.id ?? null,
643
+ requestedId: reconnected?.requestedId ?? null,
644
+ newConversation: options.newConversation,
645
+ keepConversation: options.keepConversation,
680
646
  });
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.");
686
- if (session.hostname) say(`Preview: https://${session.hostname}`);
647
+ const piSessionId = conversation.piSessionId;
648
+ if (target) {
649
+ writeProjectFile(folder, {
650
+ linked,
651
+ workspace: workspace ?? { id: null, identifier: target.workspaceIdentifier },
652
+ project: project ?? { id: null, identifier: target.projectIdentifier },
653
+ piSessionId,
654
+ conversationSessionId: reconnected?.session.id ?? null,
655
+ });
656
+ }
657
+ logged.log({ op: "conversation", status: conversation.reason, sessionId: reconnected?.session.id ?? null });
658
+ if (conversation.reason === "asked" || (conversation.reason === "changed" && !reconnected)) say("Starting a new conversation.");
659
+ if (conversation.reason === "changed" && reconnected) say("Starting a new conversation for this Dev Session.");
660
+ if (reconnected?.session.hostname) say(`Preview: https://${reconnected.session.hostname}`);
687
661
 
688
662
  const remoteExtension = await ensureRemoteExtension({ base, fetchImpl, homeDir, writeLine: say, warn });
689
- const piArgs = buildRemotePiArgs({ extensionFiles, remoteExtension, folder, piSessionId: projectFile.piSessionId, piArgs: options.piArgs });
690
- logged.log({ op: "launch", sessionId: session.id });
663
+ const piArgs = buildRemotePiArgs({ extensionFiles, remoteExtension, folder, piSessionId, piArgs: options.piArgs });
664
+ const hints = {
665
+ project: target ? { workspaceIdentifier: target.workspaceIdentifier, projectIdentifier: target.projectIdentifier } : null,
666
+ task: options.task || null,
667
+ branchTargets: options.branchTargets || null,
668
+ requestKey: options.requestKey || null,
669
+ };
670
+ logged.log({ op: "launch", sessionId: reconnected?.session.id ?? null, linked: Boolean(reconnected) });
691
671
  beforeLaunch();
692
- const result = spawnPi(piArgs, { cwd: folder, env: buildRemotePiEnv({ env, folder, base, explicitBase: options.explicitBase }) });
672
+ const result = spawnPi(piArgs, { cwd: folder, env: buildRemotePiEnv({ env, folder, base, explicitBase: options.explicitBase, hints, piSessionId }) });
693
673
  if (result.error) throw new RemoteDevError(result.error.message);
694
674
  const exitCode = result.status ?? (result.signal ? 1 : 0);
695
675
  logged.log({ op: "exit", status: exitCode });
696
676
 
697
- // The extension may have moved the session while pi ran; the conversation moves with it.
677
+ // The AI may have started or linked a session, and the extension may have moved it; the conversation goes with it.
698
678
  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 });
679
+ const finalProject = readLinkedProject(folder);
680
+ const finalTarget = finalProject ? { workspaceIdentifier: finalProject.workspaceIdentifier, projectIdentifier: finalProject.projectIdentifier } : null;
681
+ if (!finalState.sessionId || !finalProject) {
682
+ say(formatExitSummary({ target: finalTarget, session: null, pending: countPendingUploads(folder), dirArgument: options.dir || null, started: false }));
683
+ return exitCode;
684
+ }
685
+ if (finalProject.conversationSessionId !== finalState.sessionId || finalProject.piSessionId !== piSessionId) {
686
+ writeProjectFile(folder, {
687
+ linked: finalProject,
688
+ workspace: { id: finalProject.workspaceId, identifier: finalProject.workspaceIdentifier },
689
+ project: { id: finalProject.projectId, identifier: finalProject.projectIdentifier },
690
+ piSessionId,
691
+ conversationSessionId: finalState.sessionId,
692
+ });
693
+ logged.log({ op: "conversation", status: reconnected && finalState.sessionId !== reconnected.session.id ? "moved" : "linked", sessionId: finalState.sessionId });
702
694
  }
703
695
  let finalSession;
704
696
  try {
705
- finalSession = finalState.sessionId ? await loadSummarySession(baseApi, finalState.sessionId, logged.log) : null;
706
- if (finalSession && !isReusable(finalSession, project)) finalSession = null;
697
+ finalSession = await loadSummarySession(baseApi, finalState.sessionId, logged.log);
698
+ if (finalSession && !isReusable(finalSession, { id: finalProject.projectId })) finalSession = null;
707
699
  } catch (error) {
708
700
  logged.log({ op: "summary", status: "error", error: error instanceof Error ? error.message : String(error) });
709
701
  finalSession = undefined;
710
702
  }
711
- say(formatExitSummary({ target, session: finalSession, pending: countPendingUploads(folder), dirArgument: options.dir || null }));
703
+ say(formatExitSummary({ target: finalTarget, session: finalSession, pending: countPendingUploads(folder), dirArgument: options.dir || null }));
712
704
  return exitCode;
713
705
  }
package/bin/xevy.mjs CHANGED
@@ -102,7 +102,7 @@ function usage() {
102
102
  xevy setup [options] Choose credentials, pi, skills, and MCP setup
103
103
  xevy update [--base u] Refresh the pi extensions + coding-agent skills/MCP
104
104
  xevy check [--base u] Report skill updates or missing coding-agent targets
105
- xevy dev [<ws>/<proj>] The AI runs on your computer and works on the Dev Session's files
105
+ xevy dev [<target>] Open the AI here; it starts or links a Dev Session and works on its files
106
106
  xevy connect <target> Attach your terminal to the AI running in the Dev Session
107
107
 
108
108
  Options:
@@ -125,6 +125,7 @@ Examples:
125
125
  npx @xevy/cli setup --credentials --mcp -a codex
126
126
  npx @xevy/cli setup --all -y
127
127
  npx @xevy/cli update
128
+ npx @xevy/cli dev
128
129
  npx @xevy/cli dev xevy/xevyai
129
130
  npx @xevy/cli connect task/VI22-07
130
131
  npx @xevy/cli connect xevy/xevyai
@@ -141,23 +142,27 @@ function remoteDevUsage() {
141
142
 
142
143
  ${devUsageLine().replace(/^Usage: /, "")}
143
144
 
144
- Starts your Dev Session for the project, or reuses the one already running,
145
- and opens the AI here. Every file it reads or edits and every command it runs
146
- stays in the Dev Session; this computer keeps the conversation and a short
147
- record of the AI's recent edits until they are saved.
148
-
149
- The AI works from ~/xevy/<project> (or the folder given with --dir). Only a
150
- .xevy folder is created there. Run the same command again to pick up where
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.
145
+ Opens the AI straight away. When your request needs code, the AI starts a Dev
146
+ Session or links one that is already running, picks the branch each
147
+ repository starts from, and tells you where its pull requests will go. A
148
+ project or task given here is a hint for the AI; nothing is asked before it
149
+ opens. Every file it reads or edits and every command it runs stays in the
150
+ Dev Session; this computer keeps the conversation and a short record of the
151
+ AI's recent edits until they are saved.
152
+
153
+ The AI works from the current folder, from ~/xevy/<project> when a project is
154
+ given, or from the folder given with --dir. Only a .xevy folder is created
155
+ there. Running \`xevy dev\` again in that folder reconnects to its Dev Session
156
+ while it runs. A different Dev Session (a --new start, or the saved one has
157
+ ended) starts a new conversation; a session that moved to another worker
158
+ keeps it.
154
159
 
155
160
  Options:
156
- --dir <path> Folder to work from instead of ~/xevy/<project>
157
- --new Start another Dev Session instead of reusing one
161
+ --dir <path> Folder to work from
162
+ --new Do not reconnect; let the AI start another Dev Session
158
163
  --request-key <uuid> Retry an interrupted start without creating a second session
159
164
  --branch-target <repositoryUUID>=<targetId>
160
- With --new: choose a configured branch target
165
+ With --new: the branch target the AI starts from
161
166
  --new-conversation Start a fresh conversation with the AI
162
167
  --keep-conversation Keep the saved conversation, even in another Dev Session
163
168
  --base <url> Xevy host
@@ -841,8 +846,6 @@ async function remoteDev(opts) {
841
846
  cwd: process.cwd(),
842
847
  writeLine: (line) => console.log(line),
843
848
  warn: (line) => console.warn(line),
844
- ask: promptLine,
845
- interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
846
849
  // pi needs the terminal to itself.
847
850
  beforeLaunch: closePrompts,
848
851
  spawnPi: (args, { cwd, env }) => spawnSync(PI_BIN, args, { stdio: "inherit", shell: isWindows, cwd, env }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xevy/cli",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "Xevy CLI \u2014 connect to remote Dev Sessions, configure credentials, pi, coding-agent skills, and MCP, and keep integrations current.",
5
5
  "type": "module",
6
6
  "keywords": [