rex-worktrees 0.4.6 → 0.4.7

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 CHANGED
@@ -52,6 +52,9 @@ The underlined `REX / WORKTREES` header, fields, and footer keep fixed positions
52
52
 
53
53
  Shells and interactive Git/JJ clones stay attached to the destination terminal. The shell comes from `$SHELL`, falling back to `/bin/sh`.
54
54
 
55
+ Rex owns terminal placement, focus, and popup cleanup. New sessions and their first terminal are created together; checkout/clone work then runs in that terminal independently of the chooser.
56
+ Connection and review snapshots are operation-local: new sessions and forced new tabs skip reuse scans, and submission still checks fresh host and checkout state.
57
+
55
58
  | Key | Action |
56
59
  | --- | --- |
57
60
  | Tab / Shift+Tab | Move between fields and buttons |
@@ -82,7 +85,7 @@ Both settings are optional. `projects` lists repositories explicitly; `roots` di
82
85
 
83
86
  ### Other machines
84
87
 
85
- Install and run setup on each execution machine, with matching plugin versions and local Git/JJ tools. Connect the host through Rex first. Paths and configuration belong to the selected machine.
88
+ Install and run setup on each execution machine, with matching plugin versions and local Git/JJ tools. Connect the host through Rex first. Paths and configuration belong to the selected machine. This native-integration update uses helper protocol v5; update all execution machines together.
86
89
 
87
90
  If the selected machine lacks the project, the form proposes cloning it and shows the repository destination explicitly. **Directory** edits that path, and submission becomes **Clone & open**. Changing a field never starts a clone. The Worktree picker can also create a separate worktree after cloning; Directory then controls that worktree's path. Cloning opens a new tab. Only pushed history transfers—not uncommitted work, unpublished changes, or credentials. Cross-host execution and cloning are experimental; live remote Linux destinations have not been verified.
88
91
 
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/rex-worktrees
3
- size: 64508304 bytes
4
- sha256: c869f674c2632f77c9316460b8dd1ea66b585d5cafc407046d5851cd90cb8bd4
3
+ size: 64491792 bytes
4
+ sha256: c6bff9f6e9f3ba2fb81f60d456750c962d35023c9d7257d491e8f351c2546b08
@@ -33679,7 +33679,9 @@ var CloneLaunchResultSchema = exports_Schema.Struct({
33679
33679
  pending: exports_Schema.Literal(true),
33680
33680
  warning: exports_Schema.optional(exports_Schema.String)
33681
33681
  });
33682
- var CloneTaskRequestSchema = exports_Schema.Struct({ plan: ClonePlanSchema, sessionId: SessionIdSchema, rexBinDir: exports_Schema.optional(exports_Schema.String), rexLocalEndpoint: exports_Schema.optional(exports_Schema.String) });
33682
+ var RexTaskSettingsSchema = exports_Schema.Struct({ rexBinDir: exports_Schema.optional(exports_Schema.String), rexLocalEndpoint: exports_Schema.optional(exports_Schema.String) });
33683
+ var RexTaskIdentitySchema = exports_Schema.Struct({ REX_SESSION: SessionIdSchema, REX_BLOCK: BlockIdSchema });
33684
+ var CloneTaskRequestSchema = exports_Schema.Struct({ plan: ClonePlanSchema, ...RexTaskSettingsSchema.fields });
33683
33685
  var LaunchInputFields = {
33684
33686
  repo: exports_Schema.String,
33685
33687
  session: SessionSelectionSchema,
@@ -33710,7 +33712,7 @@ var LaunchPlanFields = {
33710
33712
  path: exports_Schema.String,
33711
33713
  worktreeRoot: exports_Schema.optional(exports_Schema.String),
33712
33714
  action: exports_Schema.Literals(["focus", "new-tab", "split"]),
33713
- target: exports_Schema.optional(exports_Schema.Struct({ windowId: WindowIdSchema, blockId: BlockIdSchema, label: exports_Schema.String })),
33715
+ target: exports_Schema.optional(exports_Schema.Struct({ windowId: WindowIdSchema, blockId: BlockIdSchema })),
33714
33716
  nameRole: exports_Schema.Literals(["tab", "pane", "none"]),
33715
33717
  name: exports_Schema.optional(exports_Schema.String),
33716
33718
  label: exports_Schema.String,
@@ -33747,11 +33749,10 @@ var LaunchResultSchema = exports_Schema.Struct({
33747
33749
  var TaskRequestFields = {
33748
33750
  repo: exports_Schema.String,
33749
33751
  hostId: ServerHostIdSchema,
33750
- rexBinDir: exports_Schema.optional(exports_Schema.String),
33751
- rexLocalEndpoint: exports_Schema.optional(exports_Schema.String),
33752
+ ...RexTaskSettingsSchema.fields,
33752
33753
  path: exports_Schema.String,
33753
33754
  commonDir: exports_Schema.String,
33754
- sessionId: SessionIdSchema,
33755
+ session: SessionSelectionSchema,
33755
33756
  worktreeRoot: exports_Schema.optional(exports_Schema.String)
33756
33757
  };
33757
33758
  var GitTaskRequestSchema = exports_Schema.Struct({
@@ -33770,7 +33771,7 @@ var JjTaskRequestSchema = exports_Schema.Struct({
33770
33771
  base: exports_Schema.optional(JjRevisionSchema)
33771
33772
  });
33772
33773
  var TaskRequestSchema = exports_Schema.Union([GitTaskRequestSchema, JjTaskRequestSchema]);
33773
- var RequestIdentitySchema = exports_Schema.Struct({ version: exports_Schema.Literal(4), hostId: ServerHostIdSchema });
33774
+ var RequestIdentitySchema = exports_Schema.Struct({ version: exports_Schema.Literal(5), hostId: ServerHostIdSchema });
33774
33775
  var RequestSchema = exports_Schema.Union([
33775
33776
  exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("discover"), context: exports_Schema.optional(exports_Schema.String) }),
33776
33777
  exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("sessions") }),
@@ -33801,7 +33802,9 @@ var RexNativeConfigResponseSchema = exports_Schema.fromJsonString(exports_Schema
33801
33802
  var PopupOriginSchema = exports_Schema.Struct({ sessionId: exports_Schema.optional(SessionIdSchema), blockId: exports_Schema.optional(BlockIdSchema), clientId: exports_Schema.optional(ClientIdSchema) });
33802
33803
  var RexIdentitySchema = exports_Schema.Struct({ host_id: ServerHostIdSchema, endpoint: exports_Schema.String, principal: exports_Schema.Struct({ transport: exports_Schema.String }) });
33803
33804
  var RexSessionsSchema = exports_Schema.Struct({ sessions: exports_Schema.Array(exports_Schema.Struct({ session_id: SessionIdSchema, label: exports_Schema.String })) });
33804
- var RexSessionCreatedSchema = exports_Schema.Struct({ session_id: SessionIdSchema });
33805
+ var RexCreatedSchema = exports_Schema.Struct({ window_id: WindowIdSchema, block_ids: exports_Schema.Array(BlockIdSchema) });
33806
+ var RexSplitCreatedSchema = exports_Schema.Struct({ block_ids: exports_Schema.Array(BlockIdSchema) });
33807
+ var RexSessionCreatedSchema = exports_Schema.Struct({ session_id: SessionIdSchema, initial_windows: exports_Schema.Array(RexCreatedSchema) });
33805
33808
  var RexClientsSchema = exports_Schema.Struct({
33806
33809
  clients: exports_Schema.Array(exports_Schema.Struct({
33807
33810
  client_id: ClientIdSchema,
@@ -33809,11 +33812,12 @@ var RexClientsSchema = exports_Schema.Struct({
33809
33812
  connection_state: exports_Schema.optional(exports_Schema.String)
33810
33813
  }))
33811
33814
  });
33812
- var RexWindowsSchema = exports_Schema.Struct({
33813
- windows: exports_Schema.Array(exports_Schema.Struct({
33814
- window_id: WindowIdSchema,
33815
- label: exports_Schema.String,
33816
- layers: exports_Schema.Array(exports_Schema.Struct({ blocks: exports_Schema.optional(exports_Schema.Array(exports_Schema.Struct({ block_id: BlockIdSchema, host_id: ServerHostIdSchema }))) }))
33815
+ var RexBlocksSchema = exports_Schema.Struct({
33816
+ blocks: exports_Schema.Array(exports_Schema.Struct({
33817
+ block_id: BlockIdSchema,
33818
+ host_id: exports_Schema.optional(ServerHostIdSchema),
33819
+ placement: exports_Schema.String,
33820
+ window_id: exports_Schema.optional(exports_Schema.NullOr(WindowIdSchema))
33817
33821
  }))
33818
33822
  });
33819
33823
  var popupSize = { columns: 80, rows: 16 };
@@ -33847,7 +33851,6 @@ var RexViewSchema = exports_Schema.Struct({
33847
33851
  }))
33848
33852
  }))
33849
33853
  });
33850
- var RexCreatedSchema = exports_Schema.Struct({ window_id: exports_Schema.optional(WindowIdSchema), block_ids: exports_Schema.Array(BlockIdSchema) });
33851
33854
  var RexLayerSchema = exports_Schema.Struct({ layer_id: exports_Schema.NullOr(LayerIdSchema), block_ids: exports_Schema.NullOr(exports_Schema.Array(exports_Schema.NullOr(BlockIdSchema))), revision: exports_Schema.Number });
33852
33855
  var RexDirectorySchema = exports_Schema.Struct({ pwd: exports_Schema.optional(exports_Schema.String) });
33853
33856
  var RexRegistrySchema = exports_Schema.Struct({
@@ -33861,13 +33864,12 @@ var RexProcessSchema = exports_Schema.Struct({
33861
33864
  var RexActionsSchema = exports_Schema.Struct({ actions: exports_Schema.Array(exports_Schema.Struct({ name: exports_Schema.String, args: exports_Schema.optional(exports_Schema.Unknown) })) });
33862
33865
  var RexHelperArgsSchema = exports_Schema.Struct({ properties: exports_Schema.Struct({ request: exports_Schema.Struct({ type: exports_Schema.Literal("string") }) }) });
33863
33866
  var RexConfigCheckSchema = exports_Schema.Struct({ path: exports_Schema.String, exists: exports_Schema.Boolean, diagnostics: exports_Schema.Array(exports_Schema.Unknown) });
33864
- var CliBooleanFlagSchema = exports_Schema.Literals(["--additional", "--split", "--no-context", "--managed-popup"]);
33867
+ var CliBooleanFlagSchema = exports_Schema.Literals(["--additional", "--split", "--no-context"]);
33865
33868
  var CliStringFlagSchema = exports_Schema.Literals(["--bin", "--config", "--host", "--repo", "--session", "--name", "--branch", "--revision", "--worktree", "--worktree-name", "--client", "--context", "--origin-session", "--origin-block", "--origin-client"]);
33866
33869
  var CliFlagsSchema = exports_Schema.Struct({
33867
33870
  "--additional": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
33868
33871
  "--split": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
33869
33872
  "--no-context": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
33870
- "--managed-popup": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
33871
33873
  "--bin": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
33872
33874
  "--config": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
33873
33875
  "--host": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
@@ -34608,22 +34610,20 @@ var listSessions = exports_Effect.gen(function* () {
34608
34610
  const result4 = yield* parse3(RexSessionsSchema, yield* rex(["ls", "--json"]));
34609
34611
  return result4.sessions.map((session) => ({ id: session.session_id, label: session.label }));
34610
34612
  });
34611
- var createSession = exports_Effect.fnUntraced(function* (name) {
34612
- const result4 = yield* parse3(RexSessionCreatedSchema, yield* rex(["api", "call", "session.create", JSON.stringify({ label: name })]));
34613
- return result4.session_id;
34614
- });
34615
34613
  var listClients = exports_Effect.gen(function* () {
34616
- const result4 = yield* parse3(RexClientsSchema, yield* rex(["client", "ls", "--json"]));
34614
+ const result4 = yield* parse3(RexClientsSchema, yield* rex(["api", "call", "client.list", JSON.stringify({ kinds: ["app"] })]));
34617
34615
  return result4.clients.filter((client) => client.info?.kind === "app" && client.connection_state === "connected").map((client) => ({ id: client.client_id, label: client.info?.label ?? client.client_id }));
34618
34616
  });
34619
- var windowList = exports_Effect.fnUntraced(function* (sessionId) {
34620
- const result4 = yield* parse3(RexWindowsSchema, yield* rex(["window", "ls", "-s", sessionId, "--json"]));
34621
- return result4.windows;
34617
+ var localBlocks = exports_Effect.fnUntraced(function* (sessionId) {
34618
+ const host = yield* localHost;
34619
+ const result4 = yield* parse3(RexBlocksSchema, yield* rex(["api", "call", "-s", sessionId, "session.list_blocks", JSON.stringify({ session_id: sessionId })]));
34620
+ return result4.blocks.filter((item) => item.host_id === host.id && item.placement === "placed");
34621
+ });
34622
+ var localBlockWindow = exports_Effect.fnUntraced(function* (sessionId, blockId) {
34623
+ return (yield* localBlocks(sessionId)).find((item) => item.block_id === blockId)?.window_id ?? undefined;
34622
34624
  });
34623
34625
  var originDirectory = exports_Effect.fnUntraced(function* (sessionId, blockId) {
34624
- const host = yield* localHost;
34625
- const windows = yield* windowList(sessionId);
34626
- if (!windows.some((window) => window.layers.some((layer12) => layer12.blocks?.some((block) => block.block_id === blockId && block.host_id === host.id))))
34626
+ if (!(yield* localBlockWindow(sessionId, blockId)))
34627
34627
  return;
34628
34628
  const raw = yield* rex(["block", "call", "-s", sessionId, "-b", blockId, "pwd"]);
34629
34629
  const result4 = yield* parse3(RexDirectorySchema, raw);
@@ -34641,46 +34641,85 @@ var commandWithPath = (command) => {
34641
34641
  ];
34642
34642
  return env.length ? ["/usr/bin/env", ...env, ...command] : command;
34643
34643
  };
34644
- var createTab = exports_Effect.fnUntraced(function* (sessionId, name, cwd, command) {
34645
- const result4 = yield* parse3(RexCreatedSchema, yield* rex(["window", "new", "-s", sessionId, name, "-c", cwd, "--shell=none", "--keep-open", "--json", "--", ...commandWithPath(command)]));
34646
- const blockId = result4.block_ids[0];
34647
- if (!blockId)
34648
- return yield* exports_Effect.fail(new AppError({ message: "Rex created a tab without a terminal block" }));
34649
- if (!result4.window_id)
34650
- return yield* exports_Effect.fail(new AppError({ message: "Rex did not return a window ID" }));
34651
- return { windowId: result4.window_id, blockId };
34652
- });
34653
- var createSplit = exports_Effect.fnUntraced(function* (sessionId, windowId, blockId, name, cwd, command) {
34654
- const result4 = yield* parse3(RexCreatedSchema, yield* rex(["split", "-s", sessionId, "-b", blockId, "--split=right", "--label", name, "-c", cwd, "--shell=none", "--keep-open", "--json", "--", ...commandWithPath(command)]));
34655
- const created = result4.block_ids.find((id2) => id2 !== blockId);
34656
- if (!created)
34657
- return yield* exports_Effect.fail(new AppError({ message: "Rex created a split without a new terminal block" }));
34658
- return { windowId: result4.window_id ?? windowId, blockId: created };
34659
- });
34660
- var focus = exports_Effect.fnUntraced(function* (sessionId, windowId, clientId, blockId) {
34644
+ var terminalLayout = (command, cwd, label, onCompletion = false, size8) => ({
34645
+ block: { flavor: "com.superlogical.terminal.shell", label, options: {
34646
+ command: commandWithPath(command),
34647
+ shell: "none",
34648
+ cwd,
34649
+ exit: { on_completion: onCompletion },
34650
+ ...size8 ? { size: size8 } : {}
34651
+ } }
34652
+ });
34653
+ var openTerminal = exports_Effect.fnUntraced(function* (session, name, cwd, command, target) {
34654
+ const layout = terminalLayout(command, cwd, name);
34655
+ let sessionId;
34656
+ let created;
34657
+ if (session.kind === "new") {
34658
+ const result4 = yield* parse3(RexSessionCreatedSchema, yield* rex(["api", "call", "session.create", JSON.stringify({
34659
+ label: session.name,
34660
+ initial_windows: [{ window_label: name, layout }]
34661
+ })]));
34662
+ sessionId = result4.session_id;
34663
+ created = result4.initial_windows[0];
34664
+ } else if (target) {
34665
+ sessionId = session.id;
34666
+ const result4 = yield* parse3(RexSplitCreatedSchema, yield* rex(["api", "call", "-s", sessionId, "session.new_split", JSON.stringify({
34667
+ session_id: sessionId,
34668
+ anchor_id: target.blockId,
34669
+ direction: "horizontal",
34670
+ side: "after",
34671
+ layout,
34672
+ focus: true
34673
+ })]));
34674
+ created = { window_id: target.windowId, block_ids: result4.block_ids };
34675
+ } else {
34676
+ sessionId = session.id;
34677
+ created = yield* parse3(RexCreatedSchema, yield* rex(["api", "call", "-s", sessionId, "session.new_window", JSON.stringify({
34678
+ session_id: sessionId,
34679
+ window_label: name,
34680
+ layout,
34681
+ focus: true
34682
+ })]));
34683
+ }
34684
+ const blockId = created?.block_ids[0];
34685
+ if (!created || !blockId)
34686
+ return yield* exports_Effect.fail(new AppError({ message: "Rex did not return the created window and terminal" }));
34687
+ return { sessionId, windowId: created.window_id, blockId };
34688
+ });
34689
+ var taskContext = exports_Effect.fnUntraced(function* (session, settings, expectedHostId) {
34690
+ const path = yield* exports_Path.Path;
34691
+ if (settings.rexBinDir) {
34692
+ if (!path.isAbsolute(settings.rexBinDir))
34693
+ return yield* exports_Effect.fail(new AppError({ message: "REX_BIN_DIR must be absolute" }));
34694
+ process.env.REX_BIN_DIR = settings.rexBinDir;
34695
+ }
34696
+ if (settings.rexLocalEndpoint)
34697
+ process.env.REX_WORKTREES_LOCAL_ENDPOINT = settings.rexLocalEndpoint;
34698
+ const { REX_SESSION: sessionId, REX_BLOCK: blockId } = yield* exports_Schema.decodeUnknownEffect(RexTaskIdentitySchema)(process.env);
34699
+ if (session.kind === "existing" && session.id !== sessionId)
34700
+ return yield* exports_Effect.fail(new AppError({ message: "Task must run in its requested Rex session and terminal" }));
34701
+ if ((yield* localHost).id !== expectedHostId || !(yield* localBlockWindow(sessionId, blockId)))
34702
+ return yield* exports_Effect.fail(new AppError({ message: "Task must run in a placed terminal on its requested Rex host" }));
34703
+ return { sessionId, blockId };
34704
+ });
34705
+ var focus = exports_Effect.fnUntraced(function* (sessionId, windowId, blockId, clientId) {
34661
34706
  const warnings = [];
34662
- yield* rex(["focus", "-s", sessionId, windowId]).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34663
- warnings.push(exports_Cause.pretty(exports_Cause.fail(error2)));
34707
+ yield* rex(["api", "call", "-s", sessionId, "session.focus_block", JSON.stringify({ session_id: sessionId, block_id: blockId })]).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34708
+ warnings.push(`Could not focus Rex pane: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
34664
34709
  })));
34665
- if (clientId) {
34666
- yield* rex(["-C", clientId, "do", "session.select", `session_id=${sessionId}`, `window_id=${windowId}`]).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34710
+ if (clientId)
34711
+ yield* rex(["api", "call", "client.perform", JSON.stringify({
34712
+ client_id: clientId,
34713
+ action: "session.select",
34714
+ args: { session_id: sessionId, window_id: windowId }
34715
+ })]).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34667
34716
  warnings.push(`Could not focus Rex app: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
34668
34717
  })));
34669
- }
34670
- if (blockId) {
34671
- yield* rex(["focus", "-s", sessionId, "-w", windowId, blockId]).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34672
- warnings.push(`Could not focus Rex pane: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
34673
- })));
34674
- }
34675
34718
  return warnings.length ? warnings.join("; ") : undefined;
34676
34719
  });
34677
34720
  var findPane = (node, blockId) => !node ? undefined : node.block_id === blockId ? node : node.split ? findPane(node.split.before, blockId) ?? findPane(node.split.after, blockId) : undefined;
34678
34721
  var openPopup = exports_Effect.fnUntraced(function* (command, sessionId, origin2 = {}) {
34679
- const path = yield* exports_Path.Path;
34680
- const endpoint = (yield* localIdentity).endpoint;
34681
- const program = yield* binary(path);
34682
- const localRex = (args3) => run4(program, ["-S", endpoint, "--autostart=false", ...args3], undefined, nativeEnv());
34683
- const view = yield* parse3(RexViewSchema, yield* localRex(["api", "call", "-s", sessionId, "session.view", JSON.stringify({ session_id: sessionId })]));
34722
+ const view = yield* parse3(RexViewSchema, yield* rex(["api", "call", "-s", sessionId, "session.view", JSON.stringify({ session_id: sessionId })]));
34684
34723
  const source = origin2.blockId ? view.windows.find((window2) => window2.layers.some((layer12) => layer12.blocks.some((block) => block.block_id === origin2.blockId))) : undefined;
34685
34724
  if (origin2.blockId && !source)
34686
34725
  return yield* exports_Effect.fail(new AppError({ message: "Source pane is no longer in the selected Rex session" }));
@@ -34690,9 +34729,9 @@ var openPopup = exports_Effect.fnUntraced(function* (command, sessionId, origin2
34690
34729
  return yield* exports_Effect.fail(new AppError({ message: "No active Rex window for the popup" }));
34691
34730
  }
34692
34731
  const sourceOwner = source?.layers.flatMap((layer12) => layer12.blocks).find((block) => block.block_id === origin2.blockId)?.owner;
34693
- const clients = (yield* parse3(RexClientsSchema, yield* localRex(["client", "ls", "--json"]))).clients.filter((client) => client.info?.kind === "app" && client.connection_state === "connected");
34694
- const clientId = [sourceOwner, origin2.clientId].find((id2) => id2 && clients.some((client) => client.client_id === id2));
34695
- const popupCommand = clientId ? [...command, "--managed-popup", "--origin-client", clientId] : [...command, "--managed-popup"];
34732
+ const clients = yield* listClients;
34733
+ const clientId = [sourceOwner, origin2.clientId].find((id2) => id2 && clients.some((client) => client.id === id2));
34734
+ const popupCommand = clientId ? [...command, "--origin-client", clientId] : command;
34696
34735
  const blocks = window.layers.flatMap((layer12) => layer12.blocks);
34697
34736
  const terminals = blocks.filter((block) => block.flavor === "com.superlogical.terminal.shell");
34698
34737
  const terminal = terminals.find((block) => block.block_id === origin2.blockId) ?? terminals.find((block) => block.block_id === window.focused_block_id) ?? terminals[0];
@@ -34701,7 +34740,7 @@ var openPopup = exports_Effect.fnUntraced(function* (command, sessionId, origin2
34701
34740
  const pane = window.layers.map((layer12) => findPane(layer12.layout, terminal.block_id)).find((node) => node !== undefined);
34702
34741
  if (!pane)
34703
34742
  return yield* exports_Effect.fail(new AppError({ message: "Rex terminal geometry changed before opening the popup" }));
34704
- const size8 = yield* parse3(RexTerminalSizeSchema, yield* localRex(["block", "call", "-s", sessionId, "-b", terminal.block_id, "size"]));
34743
+ const size8 = yield* parse3(RexTerminalSizeSchema, yield* rex(["block", "call", "-s", sessionId, "-b", terminal.block_id, "size"]));
34705
34744
  const zoomed = window.zoomed_block_id === terminal.block_id;
34706
34745
  width2 = Math.min(1, (popupSize.columns + 2) * (zoomed ? 1 : pane.rect[2]) / size8.columns);
34707
34746
  height = Math.min(1, (popupSize.rows + 3) * (zoomed ? 1 : pane.rect[3]) / size8.rows);
@@ -34710,30 +34749,14 @@ var openPopup = exports_Effect.fnUntraced(function* (command, sessionId, origin2
34710
34749
  session_id: sessionId,
34711
34750
  window_id: windowId,
34712
34751
  bounds: [(1 - width2) / 2, (1 - height) / 2, width2, height],
34713
- layout: { block: { flavor: "com.superlogical.terminal.shell", options: { command: commandWithPath(popupCommand), shell: "none", cwd: process.cwd(), size: popupSize, exit: { on_completion: true } } } },
34752
+ layout: terminalLayout(popupCommand, process.cwd(), "Worktrees", true, popupSize),
34714
34753
  focus: true
34715
34754
  };
34716
- const created = yield* parse3(RexLayerSchema, yield* localRex(["api", "call", "-s", sessionId, "session.new_layer", JSON.stringify(args2)]));
34755
+ const created = yield* parse3(RexLayerSchema, yield* rex(["api", "call", "-s", sessionId, "session.new_layer", JSON.stringify(args2)]));
34717
34756
  if (!created.layer_id || !created.block_ids?.some(Boolean))
34718
34757
  return yield* exports_Effect.fail(new AppError({ message: "Rex did not return a floating terminal layer" }));
34719
34758
  return created;
34720
- });
34721
- var closeManagedPopup = exports_Effect.gen(function* () {
34722
- const sessionId = process.env.REX_SESSION === undefined ? undefined : yield* exports_Schema.decodeUnknownEffect(SessionIdSchema)(process.env.REX_SESSION);
34723
- const blockId = process.env.REX_BLOCK === undefined ? undefined : yield* exports_Schema.decodeUnknownEffect(BlockIdSchema)(process.env.REX_BLOCK);
34724
- if (!sessionId || !blockId) {
34725
- return yield* exports_Effect.fail(new AppError({ message: "Cannot close managed Rex popup without its own session and block" }));
34726
- }
34727
- const path = yield* exports_Path.Path;
34728
- const endpoint = (yield* localIdentity).endpoint;
34729
- const program = yield* binary(path);
34730
- const localRex = (args2) => run4(program, ["-S", endpoint, "--autostart=false", ...args2], undefined, nativeEnv());
34731
- const view = yield* parse3(RexViewSchema, yield* localRex(["api", "call", "-s", sessionId, "session.view", JSON.stringify({ session_id: sessionId })]));
34732
- if (!view.windows.some((window) => window.layers.some((layer12) => layer12.blocks.some((block) => block.block_id === blockId)))) {
34733
- return yield* exports_Effect.fail(new AppError({ message: "Managed Rex popup block is no longer in its own session" }));
34734
- }
34735
- yield* localRex(["block", "close", "-s", sessionId, blockId]);
34736
- });
34759
+ }, withLocalIdentity);
34737
34760
 
34738
34761
  // src/config.ts
34739
34762
  var loadConfig = exports_Effect.gen(function* () {
@@ -34801,14 +34824,7 @@ var staleBlock = (error2, sessionId, blockId) => {
34801
34824
  const diagnostic = (error2.stderr.trim() || error2.stdout.trim()).trim();
34802
34825
  return diagnostic === `Error: block target "${blockId}" not found` || diagnostic === `Error: block target "${blockId}" not found: session scope: session "${sessionId}" not found`;
34803
34826
  };
34804
- var liveBlock = exports_Effect.fnUntraced(function* (sessionId, windowId, blockId, hostId, path) {
34805
- const windows = yield* windowList(sessionId);
34806
- const window = windows.find((entry) => entry.window_id === windowId);
34807
- if (!window)
34808
- return false;
34809
- const block = window.layers.flatMap((layer12) => layer12.blocks ?? []).find((entry) => entry.block_id === blockId);
34810
- if (!block || block.host_id !== hostId)
34811
- return false;
34827
+ var liveBlock = exports_Effect.fnUntraced(function* (sessionId, blockId, path) {
34812
34828
  const raw = yield* exports_Effect.catchIf(rex(["block", "call", "-s", sessionId, "-b", blockId, "process"]), (error2) => staleBlock(error2, sessionId, blockId), () => exports_Effect.succeed(""));
34813
34829
  if (!raw)
34814
34830
  return false;
@@ -34822,7 +34838,7 @@ var liveBlock = exports_Effect.fnUntraced(function* (sessionId, windowId, blockI
34822
34838
  if (!pathname)
34823
34839
  return false;
34824
34840
  const cwd = yield* exports_Effect.catchIf(canonical(pathname), (error2) => missing3(error2), () => exports_Effect.succeed(""));
34825
- return cwd === path ? window.label : false;
34841
+ return cwd === path;
34826
34842
  });
34827
34843
  var planLaunch = exports_Effect.fnUntraced(function* (input, expectedHostId) {
34828
34844
  const host = yield* localHost;
@@ -34902,20 +34918,24 @@ var planLaunch = exports_Effect.fnUntraced(function* (input, expectedHostId) {
34902
34918
  }
34903
34919
  }
34904
34920
  let warning;
34905
- const records = yield* associations.pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34906
- warning = [warning, exports_Cause.pretty(exports_Cause.fail(error2))].filter(Boolean).join("; ");
34907
- return [];
34908
- })));
34909
34921
  if (!clientId && clients.length > 1)
34910
- warning = [warning, "Multiple Rex apps are connected; select the session in the intended app"].filter(Boolean).join("; ");
34922
+ warning = "Multiple Rex apps are connected; select the session in the intended app";
34911
34923
  let target;
34912
- for (const entry of records) {
34913
- if (entry.vcs !== repo.vcs || entry.hostId !== host.id || entry.commonDir !== repo.commonDir || entry.path !== path || input.session.kind !== "existing" || entry.sessionId !== input.session.id)
34914
- continue;
34915
- const label = yield* liveBlock(entry.sessionId, entry.windowId, entry.blockId, host.id, path);
34916
- if (label !== false) {
34917
- target = { windowId: entry.windowId, blockId: entry.blockId, label };
34918
- break;
34924
+ if (input.session.kind === "existing" && (!input.additional || input.split)) {
34925
+ const sessionId = input.session.id;
34926
+ const records = yield* associations.pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
34927
+ warning = [warning, exports_Cause.pretty(exports_Cause.fail(error2))].filter(Boolean).join("; ");
34928
+ return [];
34929
+ })));
34930
+ const candidates = records.filter((entry) => entry.vcs === repo.vcs && entry.hostId === host.id && entry.commonDir === repo.commonDir && entry.path === path && entry.sessionId === sessionId);
34931
+ const blocks = candidates.length ? yield* localBlocks(sessionId) : [];
34932
+ for (const entry of candidates) {
34933
+ if (blocks.find((block) => block.block_id === entry.blockId)?.window_id !== entry.windowId)
34934
+ continue;
34935
+ if (yield* liveBlock(sessionId, entry.blockId, path)) {
34936
+ target = { windowId: entry.windowId, blockId: entry.blockId };
34937
+ break;
34938
+ }
34919
34939
  }
34920
34940
  }
34921
34941
  const action = input.split && target ? "split" : target && !input.additional && !input.split ? "focus" : "new-tab";
@@ -34958,7 +34978,7 @@ var planLaunch = exports_Effect.fnUntraced(function* (input, expectedHostId) {
34958
34978
  label: action === "focus" ? "Focus existing tab" : checkout === "create" ? "Create workspace & open" : action === "split" ? "Open pane" : "Open tab"
34959
34979
  };
34960
34980
  });
34961
- var sameLaunchPlan = (a, b) => a.vcs === b.vcs && a.input.vcs === b.input.vcs && a.hostId === b.hostId && a.worktreeRoot === b.worktreeRoot && a.clientId === b.clientId && a.input.repo === b.input.repo && sameSession(a.input.session, b.input.session) && a.input.path === b.input.path && a.input.directory === b.input.directory && a.input.worktreeName === b.input.worktreeName && a.input.name === b.input.name && a.input.clientId === b.input.clientId && a.input.additional === b.input.additional && a.input.split === b.input.split && a.path === b.path && a.checkout === b.checkout && a.action === b.action && a.nameRole === b.nameRole && a.name === b.name && a.target?.windowId === b.target?.windowId && a.target?.blockId === b.target?.blockId && a.target?.label === b.target?.label && (a.vcs === "git" && b.vcs === "git" && a.input.vcs === "git" && b.input.vcs === "git" ? a.input.branch === b.input.branch && a.branch === b.branch && a.base?.head === b.base?.head && a.base?.branch === b.base?.branch : a.vcs === "jj" && b.vcs === "jj" && a.input.vcs === "jj" && b.input.vcs === "jj" && a.input.revision === b.input.revision && a.workspaceName === b.workspaceName && a.base?.commitId === b.base?.commitId && a.base?.changeId === b.base?.changeId);
34981
+ var sameLaunchPlan = (a, b) => a.vcs === b.vcs && a.input.vcs === b.input.vcs && a.hostId === b.hostId && a.worktreeRoot === b.worktreeRoot && a.clientId === b.clientId && a.input.repo === b.input.repo && sameSession(a.input.session, b.input.session) && a.input.path === b.input.path && a.input.directory === b.input.directory && a.input.worktreeName === b.input.worktreeName && a.input.name === b.input.name && a.input.clientId === b.input.clientId && a.input.additional === b.input.additional && a.input.split === b.input.split && a.path === b.path && a.checkout === b.checkout && a.action === b.action && a.nameRole === b.nameRole && a.name === b.name && a.target?.windowId === b.target?.windowId && a.target?.blockId === b.target?.blockId && (a.vcs === "git" && b.vcs === "git" && a.input.vcs === "git" && b.input.vcs === "git" ? a.input.branch === b.input.branch && a.branch === b.branch && a.base?.head === b.base?.head && a.base?.branch === b.base?.branch : a.vcs === "jj" && b.vcs === "jj" && a.input.vcs === "jj" && b.input.vcs === "jj" && a.input.revision === b.input.revision && a.workspaceName === b.workspaceName && a.base?.commitId === b.base?.commitId && a.base?.changeId === b.base?.changeId);
34962
34982
  var launch = exports_Effect.fnUntraced(function* (input, command, reviewed, expectedHostId) {
34963
34983
  const pathService = yield* exports_Path.Path;
34964
34984
  if (!command[0] || !pathService.isAbsolute(command[0]))
@@ -34970,11 +34990,11 @@ var launch = exports_Effect.fnUntraced(function* (input, command, reviewed, expe
34970
34990
  const target2 = plan.target;
34971
34991
  if (!target2 || plan.input.session.kind !== "existing")
34972
34992
  return yield* fail19("The reviewed focus target is no longer available");
34973
- const sessionId2 = plan.input.session.id;
34974
- const warning2 = [plan.warning, yield* focus(sessionId2, target2.windowId, plan.clientId, target2.blockId)].filter(Boolean).join("; ") || undefined;
34993
+ const sessionId = plan.input.session.id;
34994
+ const warning2 = [plan.warning, yield* focus(sessionId, target2.windowId, target2.blockId, plan.clientId)].filter(Boolean).join("; ") || undefined;
34975
34995
  const result5 = {
34976
34996
  hostId: plan.hostId,
34977
- sessionId: sessionId2,
34997
+ sessionId,
34978
34998
  windowId: target2.windowId,
34979
34999
  blockId: target2.blockId,
34980
35000
  path: plan.path,
@@ -34987,15 +35007,13 @@ var launch = exports_Effect.fnUntraced(function* (input, command, reviewed, expe
34987
35007
  const repo = yield* repository3(plan.input.repo);
34988
35008
  if (repo.vcs !== plan.vcs)
34989
35009
  return yield* fail19("Repository backend changed since review");
34990
- const sessionId = plan.input.session.kind === "existing" ? plan.input.session.id : yield* createSession(plan.input.session.name);
34991
35010
  const common = {
34992
35011
  repo: repo.path,
34993
35012
  path: plan.path,
34994
35013
  commonDir: repo.commonDir,
34995
- sessionId,
35014
+ session: plan.input.session,
34996
35015
  hostId: plan.hostId,
34997
- ...process.env.REX_BIN_DIR ? { rexBinDir: process.env.REX_BIN_DIR } : {},
34998
- ...process.env.REX_WORKTREES_LOCAL_ENDPOINT ? { rexLocalEndpoint: process.env.REX_WORKTREES_LOCAL_ENDPOINT } : {},
35016
+ ...taskSettings(),
34999
35017
  ...plan.worktreeRoot ? { worktreeRoot: plan.worktreeRoot } : {}
35000
35018
  };
35001
35019
  const request3 = plan.vcs === "git" ? {
@@ -35017,13 +35035,13 @@ var launch = exports_Effect.fnUntraced(function* (input, command, reviewed, expe
35017
35035
  const name = plan.name;
35018
35036
  if (!name)
35019
35037
  return yield* fail19("The reviewed Rex tab name is no longer available");
35020
- const created = plan.action === "split" ? target ? yield* createSplit(sessionId, target.windowId, target.blockId, name, plan.path, argv) : yield* fail19("The reviewed split target is no longer available") : yield* createTab(sessionId, name, plan.checkout === "existing" ? plan.path : repo.path, argv);
35021
- const warning = [plan.warning, yield* focus(sessionId, created.windowId, plan.clientId, created.blockId)].filter(Boolean).join("; ") || undefined;
35038
+ if (plan.action === "split" && !target)
35039
+ return yield* fail19("The reviewed split target is no longer available");
35040
+ const created = yield* openTerminal(plan.input.session, name, plan.checkout === "existing" ? plan.path : repo.path, argv, plan.action === "split" ? target : undefined);
35041
+ const warning = [plan.warning, yield* focus(created.sessionId, created.windowId, created.blockId, plan.clientId)].filter(Boolean).join("; ") || undefined;
35022
35042
  const result4 = {
35023
35043
  hostId: plan.hostId,
35024
- sessionId,
35025
- windowId: created.windowId,
35026
- blockId: created.blockId,
35044
+ ...created,
35027
35045
  path: plan.path,
35028
35046
  pending: true,
35029
35047
  action: plan.action,
@@ -35048,25 +35066,20 @@ var shell = exports_Effect.fnUntraced(function* (cwd) {
35048
35066
  if (code !== 0)
35049
35067
  return yield* fail19(`Shell exited with status ${code}`);
35050
35068
  }, exports_Effect.scoped);
35069
+ var taskSettings = () => ({
35070
+ ...process.env.REX_BIN_DIR ? { rexBinDir: process.env.REX_BIN_DIR } : {},
35071
+ ...process.env.REX_WORKTREES_LOCAL_ENDPOINT ? { rexLocalEndpoint: process.env.REX_WORKTREES_LOCAL_ENDPOINT } : {}
35072
+ });
35073
+ var associateTask = exports_Effect.fnUntraced(function* (association) {
35074
+ const windowId = yield* localBlockWindow(association.sessionId, association.blockId);
35075
+ if (!windowId)
35076
+ return yield* fail19("Rex task terminal is no longer placed on its requested host");
35077
+ yield* saveAssociation({ ...association, windowId });
35078
+ }, (effect2) => effect2.pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => console.error(`Checkout is available; association not saved: ${exports_Cause.pretty(exports_Cause.fail(error2))}`)))));
35051
35079
  var task = exports_Effect.fnUntraced(function* (request3) {
35052
- if (request3.rexBinDir) {
35053
- const path2 = yield* exports_Path.Path;
35054
- if (!path2.isAbsolute(request3.rexBinDir))
35055
- return yield* fail19("REX_BIN_DIR must be an absolute directory");
35056
- process.env.REX_BIN_DIR = request3.rexBinDir;
35057
- }
35058
- if (request3.rexLocalEndpoint)
35059
- process.env.REX_WORKTREES_LOCAL_ENDPOINT = request3.rexLocalEndpoint;
35060
- const host = yield* localHost;
35061
- if (host.id !== request3.hostId)
35062
- return yield* fail19(`Wrong Rex task host: expected ${request3.hostId}, got ${host.id}`);
35080
+ const { sessionId, blockId } = yield* taskContext(request3.session, request3, request3.hostId);
35063
35081
  if (request3.vcs === "git" && !request3.branch && request3.worktreeName !== undefined)
35064
35082
  return yield* fail19("Worktree name only applies to a branch checkout");
35065
- if (process.env.REX_SESSION !== request3.sessionId || !process.env.REX_BLOCK)
35066
- return yield* fail19("Task must run in its requested Rex session and terminal");
35067
- const blockId = yield* exports_Schema.decodeUnknownEffect(BlockIdSchema)(process.env.REX_BLOCK);
35068
- if (!(yield* listSessions).some((item) => item.id === request3.sessionId))
35069
- return yield* fail19("Requested Rex session no longer exists");
35070
35083
  const current = yield* repository3(request3.repo);
35071
35084
  if (current.vcs !== request3.vcs || current.commonDir !== request3.commonDir || current.path !== request3.repo)
35072
35085
  return yield* fail19("Repository identity changed since launch");
@@ -35086,7 +35099,7 @@ var task = exports_Effect.fnUntraced(function* (request3) {
35086
35099
  if (request3.base)
35087
35100
  return yield* fail19("Existing JJ workspace cannot change its base revision");
35088
35101
  path = yield* canonical(request3.path);
35089
- const tree = (yield* listWorkspaces(request3.repo)).find((entry2) => entry2.path === path && entry2.name === request3.workspaceName && entry2.present);
35102
+ const tree = (yield* listWorkspaces(request3.repo)).find((entry) => entry.path === path && entry.name === request3.workspaceName && entry.present);
35090
35103
  if (!tree)
35091
35104
  return yield* fail19("Selected JJ workspace no longer belongs to repository");
35092
35105
  }
@@ -35113,17 +35126,7 @@ var task = exports_Effect.fnUntraced(function* (request3) {
35113
35126
  }
35114
35127
  if (path !== request3.path)
35115
35128
  return yield* fail19(`Worktree path changed; checkout remains at ${path}`);
35116
- const windows = yield* windowList(request3.sessionId).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
35117
- console.error(`Worktree ${path} is available; cannot inspect Rex terminal for association: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
35118
- return [];
35119
- })));
35120
- const entry = windows.find((window) => window.layers.some((layer12) => layer12.blocks?.some((block) => block.block_id === blockId && block.host_id === host.id)));
35121
- if (entry) {
35122
- yield* saveAssociation({ vcs: request3.vcs, hostId: host.id, commonDir: current.commonDir, path, sessionId: request3.sessionId, windowId: entry.window_id, blockId }).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
35123
- console.error(`Worktree ${path} is available; association not saved: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
35124
- })));
35125
- } else
35126
- console.error(`Worktree ${path} is available; Rex block could not be associated, select this worktree by path next time.`);
35129
+ yield* associateTask({ vcs: request3.vcs, hostId: request3.hostId, commonDir: current.commonDir, path, sessionId, blockId });
35127
35130
  yield* shell(path);
35128
35131
  });
35129
35132
  var cloneDestination = exports_Effect.fnUntraced(function* (destination, url, vcs = "git", sourceHostId) {
@@ -35276,15 +35279,10 @@ var launchClone = exports_Effect.fnUntraced(function* (input, command, reviewed,
35276
35279
  const home = process.env.HOME;
35277
35280
  if (!home || !path.isAbsolute(home))
35278
35281
  return yield* fail19("Target HOME must be an absolute directory");
35279
- const request3 = {
35280
- plan,
35281
- sessionId: plan.input.session.kind === "existing" ? plan.input.session.id : yield* createSession(plan.input.session.name),
35282
- ...process.env.REX_BIN_DIR ? { rexBinDir: process.env.REX_BIN_DIR } : {},
35283
- ...process.env.REX_WORKTREES_LOCAL_ENDPOINT ? { rexLocalEndpoint: process.env.REX_WORKTREES_LOCAL_ENDPOINT } : {}
35284
- };
35285
- const created = yield* createTab(request3.sessionId, input.name, home, [...command, "clone-task", JSON.stringify(request3)]);
35286
- const warning = [plan.warning, yield* focus(request3.sessionId, created.windowId, plan.clientId, created.blockId)].filter(Boolean).join("; ") || undefined;
35287
- const result4 = { hostId: plan.hostId, sessionId: request3.sessionId, windowId: created.windowId, blockId: created.blockId, repo: plan.repo, pending: true, ...warning ? { warning } : {} };
35282
+ const request3 = { plan, ...taskSettings() };
35283
+ const created = yield* openTerminal(plan.input.session, input.name, home, [...command, "clone-task", JSON.stringify(request3)]);
35284
+ const warning = [plan.warning, yield* focus(created.sessionId, created.windowId, created.blockId, plan.clientId)].filter(Boolean).join("; ") || undefined;
35285
+ const result4 = { hostId: plan.hostId, ...created, repo: plan.repo, pending: true, ...warning ? { warning } : {} };
35288
35286
  return result4;
35289
35287
  });
35290
35288
  var prepareCloneCheckout = exports_Effect.fnUntraced(function* (plan) {
@@ -35401,34 +35399,23 @@ var prepareCloneCheckout = exports_Effect.fnUntraced(function* (plan) {
35401
35399
  return { repo, cwd: yield* fs.realPath(cwd) };
35402
35400
  });
35403
35401
  var cloneTask = exports_Effect.fnUntraced(function* (request3) {
35404
- if (request3.rexBinDir) {
35405
- const path = yield* exports_Path.Path;
35406
- if (!path.isAbsolute(request3.rexBinDir))
35407
- return yield* fail19("REX_BIN_DIR must be absolute");
35408
- process.env.REX_BIN_DIR = request3.rexBinDir;
35409
- }
35410
- if (request3.rexLocalEndpoint)
35411
- process.env.REX_WORKTREES_LOCAL_ENDPOINT = request3.rexLocalEndpoint;
35412
35402
  const { plan } = request3;
35413
- if (process.env.REX_SESSION !== request3.sessionId || !process.env.REX_BLOCK)
35414
- return yield* fail19("Clone task must run in its requested Rex terminal");
35415
- const blockId = yield* exports_Schema.decodeUnknownEffect(BlockIdSchema)(process.env.REX_BLOCK);
35416
- if (!(yield* listSessions).some((item) => item.id === request3.sessionId))
35417
- return yield* fail19("Requested Rex session no longer exists");
35403
+ const { sessionId, blockId } = yield* taskContext(plan.input.session, request3, plan.hostId);
35418
35404
  if (!sameClonePlan(plan, yield* planClone(plan.input, plan.hostId)))
35419
35405
  return yield* fail19("Clone target changed since launch; destination left untouched");
35420
35406
  const { repo, cwd } = yield* prepareCloneCheckout(plan);
35421
35407
  yield* rememberCloneRoot((yield* exports_Path.Path).dirname(repo.path)).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => console.error(`Checkout ${cwd} is available; clone parent not remembered: ${exports_Cause.pretty(exports_Cause.fail(error2))}`))));
35422
- const windows = yield* windowList(request3.sessionId).pipe(exports_Effect.catch(() => exports_Effect.succeed([])));
35423
- const window = windows.find((entry) => entry.layers.some((layer12) => layer12.blocks?.some((block) => block.block_id === blockId && block.host_id === plan.hostId)));
35424
- if (window)
35425
- yield* saveAssociation({ vcs: repo.vcs, hostId: plan.hostId, commonDir: repo.commonDir, path: cwd, sessionId: request3.sessionId, windowId: window.window_id, blockId }).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => console.error(`Checkout ${cwd} is available; association not saved: ${exports_Cause.pretty(exports_Cause.fail(error2))}`))));
35426
- else
35427
- console.error(`Checkout ${cwd} is available; Rex block could not be associated`);
35408
+ yield* associateTask({ vcs: repo.vcs, hostId: plan.hostId, commonDir: repo.commonDir, path: cwd, sessionId, blockId });
35428
35409
  yield* shell(cwd);
35429
35410
  });
35430
35411
 
35431
35412
  // src/host.ts
35413
+ var checkoutInventory = (repo) => exports_Effect.all({
35414
+ worktrees: repo.vcs === "git" ? listWorktrees(repo.path) : listWorkspaces(repo.path),
35415
+ branches: repo.vcs === "git" ? listBranches(repo.path) : exports_Effect.succeed([]),
35416
+ revisions: repo.vcs === "jj" ? listRevisions(repo.path) : exports_Effect.succeed([]),
35417
+ worktreeRoot: resolveWorktreeRoot(repo.path)
35418
+ }, { concurrency: 4 });
35432
35419
  var dispatchHost = exports_Effect.fnUntraced(function* (request3, command) {
35433
35420
  const host = yield* localHost;
35434
35421
  if (host.id !== request3.hostId)
@@ -35437,7 +35424,7 @@ var dispatchHost = exports_Effect.fnUntraced(function* (request3, command) {
35437
35424
  const paths = request3.kind === "sessions" ? [] : request3.kind === "discover" ? request3.context ? [request3.context] : [] : request3.kind === "project" ? [request3.path] : request3.kind === "clone-plan" || request3.kind === "clone-launch" ? [request3.input.repo] : request3.kind === "plan" || request3.kind === "launch" ? [request3.input.repo, ...request3.input.path ? [request3.input.path] : []] : [request3.repo];
35438
35425
  if (paths.some((value3) => !path.isAbsolute(value3)))
35439
35426
  return yield* exports_Effect.fail(new AppError({ message: "Destination repository and worktree paths must be absolute" }));
35440
- const identity3 = { version: 4, hostId: host.id };
35427
+ const identity3 = { version: 5, hostId: host.id };
35441
35428
  let result4;
35442
35429
  switch (request3.kind) {
35443
35430
  case "sessions": {
@@ -35475,12 +35462,7 @@ var dispatchHost = exports_Effect.fnUntraced(function* (request3, command) {
35475
35462
  }
35476
35463
  const checkout = yield* repository3(request3.path);
35477
35464
  const canonical2 = yield* project3(request3.path);
35478
- const inventory2 = yield* exports_Effect.all({
35479
- worktrees: canonical2.vcs === "git" ? listWorktrees(canonical2.path) : listWorkspaces(canonical2.path),
35480
- branches: canonical2.vcs === "git" ? listBranches(canonical2.path) : exports_Effect.succeed([]),
35481
- revisions: canonical2.vcs === "jj" ? listRevisions(canonical2.path) : exports_Effect.succeed([]),
35482
- worktreeRoot: resolveWorktreeRoot(canonical2.path)
35483
- }, { concurrency: 4 });
35465
+ const inventory2 = yield* checkoutInventory(canonical2);
35484
35466
  result4 = {
35485
35467
  ...identity3,
35486
35468
  kind: "project",
@@ -35501,12 +35483,7 @@ var dispatchHost = exports_Effect.fnUntraced(function* (request3, command) {
35501
35483
  }
35502
35484
  case "worktrees": {
35503
35485
  const repo = yield* repository3(request3.repo);
35504
- const inventory2 = yield* exports_Effect.all({
35505
- worktrees: repo.vcs === "git" ? listWorktrees(repo.path) : listWorkspaces(repo.path),
35506
- branches: repo.vcs === "git" ? listBranches(repo.path) : exports_Effect.succeed([]),
35507
- revisions: repo.vcs === "jj" ? listRevisions(repo.path) : exports_Effect.succeed([]),
35508
- worktreeRoot: resolveWorktreeRoot(repo.path)
35509
- }, { concurrency: 4 });
35486
+ const inventory2 = yield* checkoutInventory(repo);
35510
35487
  result4 = {
35511
35488
  ...identity3,
35512
35489
  kind: "worktrees",
@@ -35544,23 +35521,20 @@ var hostRequest = exports_Effect.fnUntraced(function* (raw, command) {
35544
35521
 
35545
35522
  // src/client.ts
35546
35523
  var fail20 = (message) => exports_Effect.fail(new AppError({ message }));
35547
- var listMachines = exports_Effect.gen(function* () {
35548
- const registry = yield* machinesRegistry;
35549
- const machines = [
35550
- { key: "local", label: registry.home.this_machine && registry.home.label || "This machine", local: true, selector: process.env.REX_WORKTREES_LOCAL_ENDPOINT ?? "local" },
35551
- ...registry.hosts.map(({ host }) => ({ key: host.id, label: host.label, local: false, selector: host.label }))
35552
- ];
35553
- return machines;
35554
- });
35524
+ var machinesIn = (registry) => [
35525
+ { key: "local", label: registry.home.this_machine && registry.home.label || "This machine", local: true, selector: process.env.REX_WORKTREES_LOCAL_ENDPOINT ?? "local" },
35526
+ ...registry.hosts.map(({ host }) => ({ key: host.id, label: host.label, local: false, selector: host.label }))
35527
+ ];
35528
+ var listMachines = exports_Effect.map(machinesRegistry, machinesIn);
35555
35529
  var connectMachine = exports_Effect.fnUntraced(function* (machine) {
35556
- const choices = yield* listMachines;
35557
- const current = choices.find((choice) => choice.key === machine.key && choice.local === machine.local);
35530
+ const registry = yield* machinesRegistry;
35531
+ const current = machinesIn(registry).find((choice) => choice.key === machine.key && choice.local === machine.local);
35558
35532
  if (!current)
35559
35533
  return yield* fail20(`Rex machine ${machine.label} is no longer registered; choose another machine`);
35560
35534
  if (current.local)
35561
35535
  return { ...current, hostId: (yield* localHost).id };
35562
35536
  const identity3 = yield* remoteIdentity(current.selector);
35563
- const registered = (yield* machinesRegistry).hosts.find((entry) => entry.host.id === current.key);
35537
+ const registered = registry.hosts.find((entry) => entry.host.id === current.key);
35564
35538
  if (!registered?.host.endpoints.includes(identity3.endpoint)) {
35565
35539
  return yield* fail20(`Rex machine ${current.label} resolved to an unexpected server; refusing to route remotely`);
35566
35540
  }
@@ -35574,9 +35548,9 @@ var connectMachine = exports_Effect.fnUntraced(function* (machine) {
35574
35548
  return { ...current, hostId: identity3.host_id };
35575
35549
  });
35576
35550
  var connectedRequest = exports_Effect.fnUntraced(function* (host, command, body) {
35577
- const encoded = { version: 4, hostId: host.hostId, ...body };
35551
+ const encoded = { version: 5, hostId: host.hostId, ...body };
35578
35552
  const response = host.local ? yield* dispatchHost(encoded, command) : yield* exports_Schema.decodeUnknownEffect(RexWorktreesResponseSchema)(yield* remoteRex(host.selector, ["do", "worktrees_request", "--args", JSON.stringify({ request: JSON.stringify(encoded) }), "--json"]));
35579
- if (response.hostId !== host.hostId || response.version !== 4 || response.kind !== body.kind && !(body.kind === "project" && response.kind === "project-missing" && response.path === body.path))
35553
+ if (response.hostId !== host.hostId || response.version !== 5 || response.kind !== body.kind && !(body.kind === "project" && response.kind === "project-missing" && response.path === body.path))
35580
35554
  return yield* fail20(`Unexpected Rex host/protocol response from ${host.label}; update rex-worktrees on that machine, run setup, and reload its Rex config`);
35581
35555
  return response;
35582
35556
  });
@@ -35701,13 +35675,16 @@ function M.setup(opts)
35701
35675
  if type(config.projects) == "table" and next(config.projects) == nil then config.projects = nil end
35702
35676
  local settings = rex.json.encode({ config = config, directory = config_dir })
35703
35677
 
35678
+ local function exec_options(stdin)
35679
+ local options = { stdin = stdin, timeout = 20, env = { REX_WORKTREES_CONFIG = settings } }
35680
+ if rex_bin_dir then options.env.REX_BIN_DIR = rex_bin_dir end
35681
+ if installed_path_env ~= false then options.env.PATH = installed_path_env end
35682
+ options.env.REX_WORKTREES_LOCAL_ENDPOINT = os.getenv("REX_WORKTREES_LOCAL_ENDPOINT")
35683
+ return options
35684
+ end
35685
+
35704
35686
  local function worktrees_request(request)
35705
- local exec_opts = { stdin = request, timeout = 20, env = {} }
35706
- exec_opts.env.REX_WORKTREES_CONFIG = settings
35707
- if rex_bin_dir then exec_opts.env.REX_BIN_DIR = rex_bin_dir end
35708
- if installed_path_env ~= false then exec_opts.env.PATH = installed_path_env end
35709
- if os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") then exec_opts.env.REX_WORKTREES_LOCAL_ENDPOINT = os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") end
35710
- local result, run_err = rex.exec({ bin, "host-request" }, exec_opts)
35687
+ local result, run_err = rex.exec({ bin, "host-request" }, exec_options(request))
35711
35688
  if not result then error(run_err, 0) end
35712
35689
  if not result.ok then
35713
35690
  error("rex-worktrees host-request failed (exit " .. tostring(result.code)
@@ -35761,12 +35738,7 @@ function M.setup(opts)
35761
35738
  table.insert(command, "--origin-client")
35762
35739
  table.insert(command, ctx.client_id)
35763
35740
  end
35764
- local exec_opts = { timeout = 20, env = {} }
35765
- exec_opts.env.REX_WORKTREES_CONFIG = settings
35766
- if rex_bin_dir then exec_opts.env.REX_BIN_DIR = rex_bin_dir end
35767
- if installed_path_env ~= false then exec_opts.env.PATH = installed_path_env end
35768
- if os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") then exec_opts.env.REX_WORKTREES_LOCAL_ENDPOINT = os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") end
35769
- local result, run_err = rex.exec(command, exec_opts)
35741
+ local result, run_err = rex.exec(command, exec_options())
35770
35742
  if not result then error(run_err, 0) end
35771
35743
  if not result.ok then
35772
35744
  error("rex-worktrees launch-popup failed: " ..
@@ -39557,7 +39529,7 @@ Run rex config reload to activate.`}`);
39557
39529
  }
39558
39530
  if (verb === "popup") {
39559
39531
  const flags = yield* parseFlags(args2);
39560
- if (Object.keys(flags).some((key5) => !["--host", "--context", "--origin-session", "--origin-block", "--origin-client", "--no-context", "--managed-popup"].includes(key5))) {
39532
+ if (Object.keys(flags).some((key5) => !["--host", "--context", "--origin-session", "--origin-block", "--origin-client", "--no-context"].includes(key5))) {
39561
39533
  return yield* exports_Effect.fail(new AppError({ message: "Invalid popup flags" }));
39562
39534
  }
39563
39535
  if (flags["--context"] && flags["--no-context"])
@@ -39574,8 +39546,6 @@ Run rex config reload to activate.`}`);
39574
39546
  };
39575
39547
  const context3 = typeof flags["--context"] === "string" ? exports_Effect.succeed(resolve6(flags["--context"])) : flags["--no-context"] ? exports_Effect.succeed(undefined) : args2.length && sessionId && blockId ? originDirectory(sessionId, blockId) : exports_Effect.succeed(process.cwd());
39576
39548
  yield* popup(executable, context3, origin2, flags["--host"]);
39577
- if (flags["--managed-popup"])
39578
- yield* closeManagedPopup;
39579
39549
  return;
39580
39550
  }
39581
39551
  if (verb === "launch-popup") {
@@ -39613,7 +39583,7 @@ Run rex config reload to activate.`}`);
39613
39583
  return;
39614
39584
  }
39615
39585
  if (verb === "open") {
39616
- if (args2.some((arg) => ["--context", "--origin-session", "--origin-block", "--origin-client", "--no-context", "--managed-popup"].includes(arg))) {
39586
+ if (args2.some((arg) => ["--context", "--origin-session", "--origin-block", "--origin-client", "--no-context"].includes(arg))) {
39617
39587
  return yield* exports_Effect.fail(new AppError({ message: "Context flags are only supported by popup" }));
39618
39588
  }
39619
39589
  const flags = yield* parseFlags(args2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rex-worktrees",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Git worktrees and Jujutsu workspaces for Rex",
5
5
  "license": "MIT",
6
6
  "author": "Samuel Ho",