rex-worktrees 0.1.2 → 0.3.0
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 +31 -20
- package/dist/rex-worktrees +2 -2
- package/dist/rex-worktrees.js +1850 -518
- package/package.json +2 -1
package/dist/rex-worktrees.js
CHANGED
|
@@ -33453,6 +33453,8 @@ var withTime = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, label)
|
|
|
33453
33453
|
}), () => self, () => sync(() => {
|
|
33454
33454
|
console2.timeEnd(label);
|
|
33455
33455
|
}))));
|
|
33456
|
+
// src/git.ts
|
|
33457
|
+
import { resolve as resolvePath } from "path";
|
|
33456
33458
|
// src/contracts.ts
|
|
33457
33459
|
class AppError extends exports_Schema.TaggedError()("AppError", {
|
|
33458
33460
|
message: exports_Schema.String,
|
|
@@ -33476,9 +33478,19 @@ var ClientIdSchema = exports_Schema.String.pipe(exports_Schema.brand("ClientId")
|
|
|
33476
33478
|
var WindowIdSchema = exports_Schema.String.pipe(exports_Schema.brand("WindowId"));
|
|
33477
33479
|
var BlockIdSchema = exports_Schema.String.pipe(exports_Schema.brand("BlockId"));
|
|
33478
33480
|
var LayerIdSchema = exports_Schema.String.pipe(exports_Schema.brand("LayerId"));
|
|
33479
|
-
var
|
|
33481
|
+
var VcsSchema = exports_Schema.Literals(["git", "jj"]);
|
|
33482
|
+
var RepositoryFields = { path: exports_Schema.String, commonDir: exports_Schema.String, name: exports_Schema.String };
|
|
33483
|
+
var GitRepositorySchema = exports_Schema.Struct({ vcs: exports_Schema.Literal("git"), ...RepositoryFields });
|
|
33484
|
+
var JjRepositorySchema = exports_Schema.Struct({ vcs: exports_Schema.Literal("jj"), ...RepositoryFields });
|
|
33485
|
+
var RepositorySchema = exports_Schema.Union([GitRepositorySchema, JjRepositorySchema]);
|
|
33486
|
+
var JjWorkspaceNameSchema = exports_Schema.String.pipe(exports_Schema.brand("JjWorkspaceName"));
|
|
33487
|
+
var JjCommitIdSchema = exports_Schema.String.pipe(exports_Schema.brand("JjCommitId"));
|
|
33488
|
+
var JjChangeIdSchema = exports_Schema.String.pipe(exports_Schema.brand("JjChangeId"));
|
|
33489
|
+
var JjRevisionSchema = exports_Schema.Struct({ commitId: JjCommitIdSchema, changeId: JjChangeIdSchema, description: exports_Schema.String });
|
|
33490
|
+
var JjRevisionChoiceSchema = exports_Schema.Struct({ expression: exports_Schema.String, label: exports_Schema.String, revision: JjRevisionSchema });
|
|
33480
33491
|
var RepositoryHeadSchema = exports_Schema.Struct({ branch: exports_Schema.NullOr(exports_Schema.String), head: exports_Schema.String });
|
|
33481
|
-
var
|
|
33492
|
+
var GitWorktreeSchema = exports_Schema.Struct({
|
|
33493
|
+
vcs: exports_Schema.Literal("git"),
|
|
33482
33494
|
path: exports_Schema.String,
|
|
33483
33495
|
branch: exports_Schema.mutableKey(exports_Schema.NullOr(exports_Schema.String)),
|
|
33484
33496
|
head: exports_Schema.mutableKey(exports_Schema.String),
|
|
@@ -33486,7 +33498,17 @@ var WorktreeSchema = exports_Schema.Struct({
|
|
|
33486
33498
|
locked: exports_Schema.mutableKey(exports_Schema.Boolean),
|
|
33487
33499
|
prunable: exports_Schema.mutableKey(exports_Schema.Boolean)
|
|
33488
33500
|
});
|
|
33489
|
-
var
|
|
33501
|
+
var JjWorktreeSchema = exports_Schema.Struct({
|
|
33502
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33503
|
+
path: exports_Schema.NullOr(exports_Schema.String),
|
|
33504
|
+
name: JjWorkspaceNameSchema,
|
|
33505
|
+
head: JjCommitIdSchema,
|
|
33506
|
+
changeId: JjChangeIdSchema,
|
|
33507
|
+
present: exports_Schema.Boolean,
|
|
33508
|
+
colocated: exports_Schema.Boolean
|
|
33509
|
+
});
|
|
33510
|
+
var WorktreeSchema = exports_Schema.Union([GitWorktreeSchema, JjWorktreeSchema]);
|
|
33511
|
+
var WorktreePlanSchema = exports_Schema.Struct({ repository: GitRepositorySchema, path: exports_Schema.String, branch: exports_Schema.String, existing: exports_Schema.Boolean });
|
|
33490
33512
|
var CreateWorktreeOptionsSchema = exports_Schema.Struct({
|
|
33491
33513
|
startPoint: exports_Schema.optional(exports_Schema.String),
|
|
33492
33514
|
attachOnly: exports_Schema.optional(exports_Schema.Boolean),
|
|
@@ -33508,8 +33530,9 @@ var ResolvedConfigSchema = exports_Schema.Struct({
|
|
|
33508
33530
|
worktreeRoot: exports_Schema.UndefinedOr(exports_Schema.String),
|
|
33509
33531
|
projectRoots: exports_Schema.Array(exports_Schema.Struct({ path: exports_Schema.String, worktreeRoot: exports_Schema.String }))
|
|
33510
33532
|
});
|
|
33511
|
-
var InstallSchema = exports_Schema.Struct({ source: exports_Schema.String, home: exports_Schema.String, configPath: exports_Schema.String, lua: exports_Schema.String, rexBinDir: exports_Schema.String, managedBin: exports_Schema.optional(exports_Schema.String) });
|
|
33533
|
+
var InstallSchema = exports_Schema.Struct({ source: exports_Schema.String, home: exports_Schema.String, configPath: exports_Schema.String, lua: exports_Schema.String, rexBinDir: exports_Schema.String, managedBin: exports_Schema.optional(exports_Schema.String), pathEnv: exports_Schema.optional(exports_Schema.String), allowLinkedConfig: exports_Schema.optional(exports_Schema.Boolean) });
|
|
33512
33534
|
var AssociationSchema = exports_Schema.Struct({
|
|
33535
|
+
vcs: VcsSchema,
|
|
33513
33536
|
hostId: ServerHostIdSchema,
|
|
33514
33537
|
commonDir: exports_Schema.String,
|
|
33515
33538
|
path: exports_Schema.String,
|
|
@@ -33518,30 +33541,114 @@ var AssociationSchema = exports_Schema.Struct({
|
|
|
33518
33541
|
blockId: BlockIdSchema
|
|
33519
33542
|
});
|
|
33520
33543
|
var SessionTargetSchema = exports_Schema.Struct({ id: SessionIdSchema, label: exports_Schema.String });
|
|
33544
|
+
var SessionSelectionSchema = exports_Schema.Union([
|
|
33545
|
+
exports_Schema.Struct({ kind: exports_Schema.Literal("existing"), id: SessionIdSchema }),
|
|
33546
|
+
exports_Schema.Struct({
|
|
33547
|
+
kind: exports_Schema.Literal("new"),
|
|
33548
|
+
name: exports_Schema.String.pipe(exports_Schema.check(exports_Schema.isMaxLength(128), exports_Schema.isPattern(/^(?=.*\S)(?!.*[\p{ASCII}&&\p{Cc}]).*$/v)))
|
|
33549
|
+
})
|
|
33550
|
+
]);
|
|
33521
33551
|
var ClientTargetSchema = exports_Schema.Struct({ id: ClientIdSchema, label: exports_Schema.String });
|
|
33522
33552
|
var MachineSchema = exports_Schema.Struct({ key: exports_Schema.Union([exports_Schema.Literal("local"), RegisteredHostIdSchema]), label: exports_Schema.String, local: exports_Schema.Boolean, selector: exports_Schema.String });
|
|
33523
33553
|
var DestinationHostSchema = exports_Schema.Struct({ ...MachineSchema.fields, hostId: ServerHostIdSchema });
|
|
33524
|
-
var
|
|
33554
|
+
var GitCloneSourceSchema = exports_Schema.Struct({
|
|
33555
|
+
vcs: exports_Schema.Literal("git"),
|
|
33556
|
+
url: exports_Schema.String,
|
|
33557
|
+
sourceHostId: ServerHostIdSchema,
|
|
33558
|
+
branches: exports_Schema.Array(exports_Schema.String),
|
|
33559
|
+
branch: exports_Schema.optional(exports_Schema.String)
|
|
33560
|
+
});
|
|
33561
|
+
var JjCloneSourceSchema = exports_Schema.Struct({
|
|
33562
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33563
|
+
url: exports_Schema.String,
|
|
33564
|
+
sourceHostId: ServerHostIdSchema,
|
|
33565
|
+
revisions: exports_Schema.Array(JjRevisionChoiceSchema),
|
|
33566
|
+
revision: exports_Schema.optional(JjRevisionSchema)
|
|
33567
|
+
});
|
|
33568
|
+
var CloneSourceSchema = exports_Schema.Union([GitCloneSourceSchema, JjCloneSourceSchema]);
|
|
33569
|
+
var GitCloneInputSchema = exports_Schema.Struct({
|
|
33570
|
+
vcs: exports_Schema.Literal("git"),
|
|
33571
|
+
source: GitCloneSourceSchema,
|
|
33525
33572
|
repo: exports_Schema.String,
|
|
33526
|
-
|
|
33573
|
+
session: SessionSelectionSchema,
|
|
33574
|
+
clientId: exports_Schema.optional(ClientIdSchema),
|
|
33575
|
+
name: exports_Schema.String,
|
|
33576
|
+
branch: exports_Schema.String,
|
|
33577
|
+
branchMode: exports_Schema.Literals(["existing", "create"]),
|
|
33578
|
+
worktreeName: exports_Schema.optional(exports_Schema.String)
|
|
33579
|
+
});
|
|
33580
|
+
var JjCloneInputSchema = exports_Schema.Struct({
|
|
33581
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33582
|
+
source: JjCloneSourceSchema,
|
|
33583
|
+
repo: exports_Schema.String,
|
|
33584
|
+
session: SessionSelectionSchema,
|
|
33585
|
+
clientId: exports_Schema.optional(ClientIdSchema),
|
|
33527
33586
|
name: exports_Schema.String,
|
|
33528
|
-
branch: exports_Schema.optional(exports_Schema.String),
|
|
33529
33587
|
worktreeName: exports_Schema.optional(exports_Schema.String),
|
|
33530
|
-
|
|
33588
|
+
revision: exports_Schema.optional(exports_Schema.String)
|
|
33589
|
+
});
|
|
33590
|
+
var CloneInputSchema = exports_Schema.Union([GitCloneInputSchema, JjCloneInputSchema]);
|
|
33591
|
+
var ClonePlanFields = {
|
|
33592
|
+
hostId: ServerHostIdSchema,
|
|
33593
|
+
clientId: exports_Schema.optional(ClientIdSchema),
|
|
33594
|
+
repo: exports_Schema.String,
|
|
33595
|
+
existing: exports_Schema.Boolean,
|
|
33596
|
+
commonDir: exports_Schema.optional(exports_Schema.String),
|
|
33597
|
+
label: exports_Schema.String,
|
|
33598
|
+
detail: exports_Schema.optional(exports_Schema.String),
|
|
33599
|
+
warning: exports_Schema.optional(exports_Schema.String)
|
|
33600
|
+
};
|
|
33601
|
+
var GitClonePlanSchema = exports_Schema.Struct({
|
|
33602
|
+
...ClonePlanFields,
|
|
33603
|
+
vcs: exports_Schema.Literal("git"),
|
|
33604
|
+
input: GitCloneInputSchema,
|
|
33605
|
+
base: exports_Schema.optional(exports_Schema.String)
|
|
33606
|
+
});
|
|
33607
|
+
var JjClonePlanSchema = exports_Schema.Struct({
|
|
33608
|
+
...ClonePlanFields,
|
|
33609
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33610
|
+
input: JjCloneInputSchema,
|
|
33611
|
+
base: exports_Schema.optional(JjRevisionSchema)
|
|
33612
|
+
});
|
|
33613
|
+
var ClonePlanSchema = exports_Schema.Union([GitClonePlanSchema, JjClonePlanSchema]);
|
|
33614
|
+
var CloneLaunchResultSchema = exports_Schema.Struct({
|
|
33615
|
+
hostId: ServerHostIdSchema,
|
|
33616
|
+
sessionId: SessionIdSchema,
|
|
33617
|
+
windowId: WindowIdSchema,
|
|
33618
|
+
blockId: BlockIdSchema,
|
|
33619
|
+
repo: exports_Schema.String,
|
|
33620
|
+
pending: exports_Schema.Literal(true),
|
|
33621
|
+
warning: exports_Schema.optional(exports_Schema.String)
|
|
33622
|
+
});
|
|
33623
|
+
var CloneTaskRequestSchema = exports_Schema.Struct({ plan: ClonePlanSchema, sessionId: SessionIdSchema, rexBinDir: exports_Schema.optional(exports_Schema.String), rexLocalEndpoint: exports_Schema.optional(exports_Schema.String) });
|
|
33624
|
+
var LaunchInputFields = {
|
|
33625
|
+
repo: exports_Schema.String,
|
|
33626
|
+
session: SessionSelectionSchema,
|
|
33627
|
+
name: exports_Schema.String,
|
|
33531
33628
|
clientId: exports_Schema.optional(ClientIdSchema),
|
|
33532
33629
|
additional: exports_Schema.optional(exports_Schema.Boolean),
|
|
33533
33630
|
split: exports_Schema.optional(exports_Schema.Boolean)
|
|
33631
|
+
};
|
|
33632
|
+
var GitLaunchInputSchema = exports_Schema.Struct({
|
|
33633
|
+
...LaunchInputFields,
|
|
33634
|
+
vcs: exports_Schema.Literal("git"),
|
|
33635
|
+
branch: exports_Schema.optional(exports_Schema.String),
|
|
33636
|
+
worktreeName: exports_Schema.optional(exports_Schema.String),
|
|
33637
|
+
path: exports_Schema.optional(exports_Schema.String)
|
|
33534
33638
|
});
|
|
33535
|
-
var
|
|
33536
|
-
|
|
33639
|
+
var JjLaunchInputSchema = exports_Schema.Struct({
|
|
33640
|
+
...LaunchInputFields,
|
|
33641
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33642
|
+
path: exports_Schema.optional(exports_Schema.String),
|
|
33643
|
+
worktreeName: exports_Schema.optional(exports_Schema.String),
|
|
33644
|
+
revision: exports_Schema.optional(exports_Schema.String)
|
|
33645
|
+
});
|
|
33646
|
+
var LaunchInputSchema = exports_Schema.Union([GitLaunchInputSchema, JjLaunchInputSchema]);
|
|
33647
|
+
var LaunchPlanFields = {
|
|
33537
33648
|
hostId: ServerHostIdSchema,
|
|
33538
|
-
sessionId: SessionIdSchema,
|
|
33539
33649
|
clientId: exports_Schema.optional(ClientIdSchema),
|
|
33540
33650
|
path: exports_Schema.String,
|
|
33541
|
-
branch: exports_Schema.NullOr(exports_Schema.String),
|
|
33542
|
-
checkout: exports_Schema.Literals(["existing", "attach", "create"]),
|
|
33543
33651
|
worktreeRoot: exports_Schema.optional(exports_Schema.String),
|
|
33544
|
-
base: exports_Schema.optional(RepositoryHeadSchema),
|
|
33545
33652
|
action: exports_Schema.Literals(["focus", "new-tab", "split"]),
|
|
33546
33653
|
target: exports_Schema.optional(exports_Schema.Struct({ windowId: WindowIdSchema, blockId: BlockIdSchema, label: exports_Schema.String })),
|
|
33547
33654
|
nameRole: exports_Schema.Literals(["tab", "pane", "none"]),
|
|
@@ -33549,7 +33656,24 @@ var LaunchPlanSchema = exports_Schema.Struct({
|
|
|
33549
33656
|
label: exports_Schema.String,
|
|
33550
33657
|
detail: exports_Schema.optional(exports_Schema.String),
|
|
33551
33658
|
warning: exports_Schema.optional(exports_Schema.String)
|
|
33659
|
+
};
|
|
33660
|
+
var GitLaunchPlanSchema = exports_Schema.Struct({
|
|
33661
|
+
...LaunchPlanFields,
|
|
33662
|
+
vcs: exports_Schema.Literal("git"),
|
|
33663
|
+
input: GitLaunchInputSchema,
|
|
33664
|
+
branch: exports_Schema.NullOr(exports_Schema.String),
|
|
33665
|
+
checkout: exports_Schema.Literals(["existing", "attach", "create"]),
|
|
33666
|
+
base: exports_Schema.optional(RepositoryHeadSchema)
|
|
33552
33667
|
});
|
|
33668
|
+
var JjLaunchPlanSchema = exports_Schema.Struct({
|
|
33669
|
+
...LaunchPlanFields,
|
|
33670
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33671
|
+
input: JjLaunchInputSchema,
|
|
33672
|
+
checkout: exports_Schema.Literals(["existing", "create"]),
|
|
33673
|
+
workspaceName: JjWorkspaceNameSchema,
|
|
33674
|
+
base: exports_Schema.optional(JjRevisionSchema)
|
|
33675
|
+
});
|
|
33676
|
+
var LaunchPlanSchema = exports_Schema.Union([GitLaunchPlanSchema, JjLaunchPlanSchema]);
|
|
33553
33677
|
var LaunchResultSchema = exports_Schema.Struct({
|
|
33554
33678
|
hostId: ServerHostIdSchema,
|
|
33555
33679
|
sessionId: SessionIdSchema,
|
|
@@ -33560,7 +33684,7 @@ var LaunchResultSchema = exports_Schema.Struct({
|
|
|
33560
33684
|
action: exports_Schema.Literals(["focus", "new-tab", "split"]),
|
|
33561
33685
|
warning: exports_Schema.optional(exports_Schema.String)
|
|
33562
33686
|
});
|
|
33563
|
-
var
|
|
33687
|
+
var TaskRequestFields = {
|
|
33564
33688
|
repo: exports_Schema.String,
|
|
33565
33689
|
hostId: ServerHostIdSchema,
|
|
33566
33690
|
rexBinDir: exports_Schema.optional(exports_Schema.String),
|
|
@@ -33568,27 +33692,46 @@ var TaskRequestSchema = exports_Schema.Struct({
|
|
|
33568
33692
|
path: exports_Schema.String,
|
|
33569
33693
|
commonDir: exports_Schema.String,
|
|
33570
33694
|
sessionId: SessionIdSchema,
|
|
33695
|
+
worktreeRoot: exports_Schema.optional(exports_Schema.String)
|
|
33696
|
+
};
|
|
33697
|
+
var GitTaskRequestSchema = exports_Schema.Struct({
|
|
33698
|
+
...TaskRequestFields,
|
|
33699
|
+
vcs: exports_Schema.Literal("git"),
|
|
33571
33700
|
branch: exports_Schema.optional(exports_Schema.String),
|
|
33572
33701
|
worktreeName: exports_Schema.optional(exports_Schema.String),
|
|
33573
33702
|
base: exports_Schema.optional(exports_Schema.String),
|
|
33574
|
-
worktreeRoot: exports_Schema.optional(exports_Schema.String),
|
|
33575
33703
|
checkout: exports_Schema.optional(exports_Schema.Literals(["attach", "existing"]))
|
|
33576
33704
|
});
|
|
33577
|
-
var
|
|
33705
|
+
var JjTaskRequestSchema = exports_Schema.Struct({
|
|
33706
|
+
...TaskRequestFields,
|
|
33707
|
+
vcs: exports_Schema.Literal("jj"),
|
|
33708
|
+
checkout: exports_Schema.Literals(["existing", "create"]),
|
|
33709
|
+
workspaceName: JjWorkspaceNameSchema,
|
|
33710
|
+
base: exports_Schema.optional(JjRevisionSchema)
|
|
33711
|
+
});
|
|
33712
|
+
var TaskRequestSchema = exports_Schema.Union([GitTaskRequestSchema, JjTaskRequestSchema]);
|
|
33713
|
+
var RequestIdentitySchema = exports_Schema.Struct({ version: exports_Schema.Literal(4), hostId: ServerHostIdSchema });
|
|
33578
33714
|
var RequestSchema = exports_Schema.Union([
|
|
33579
33715
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("discover"), context: exports_Schema.optional(exports_Schema.String) }),
|
|
33716
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("clone-source"), repo: exports_Schema.String }),
|
|
33580
33717
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("project"), path: exports_Schema.String }),
|
|
33581
33718
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("worktrees"), repo: exports_Schema.String }),
|
|
33582
|
-
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("
|
|
33719
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("revision"), repo: exports_Schema.String, revision: exports_Schema.String }),
|
|
33583
33720
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("plan"), input: LaunchInputSchema }),
|
|
33721
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("clone-plan"), input: CloneInputSchema }),
|
|
33722
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("clone-launch"), input: CloneInputSchema, reviewed: ClonePlanSchema }),
|
|
33584
33723
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("launch"), input: LaunchInputSchema, reviewed: LaunchPlanSchema })
|
|
33585
33724
|
]);
|
|
33586
33725
|
var ResponseSchema = exports_Schema.Union([
|
|
33587
|
-
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("discover"), sessions: exports_Schema.Array(SessionTargetSchema), clients: exports_Schema.Array(ClientTargetSchema), projects: exports_Schema.Array(RepositorySchema), checkout: exports_Schema.optional(RepositorySchema) }),
|
|
33588
|
-
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("project"), project: RepositorySchema, checkout: RepositorySchema, worktrees: exports_Schema.Array(WorktreeSchema), branches: exports_Schema.Array(exports_Schema.String) }),
|
|
33589
|
-
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("
|
|
33590
|
-
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("
|
|
33726
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("discover"), sessions: exports_Schema.Array(SessionTargetSchema), clients: exports_Schema.Array(ClientTargetSchema), projects: exports_Schema.Array(RepositorySchema), roots: exports_Schema.optional(exports_Schema.Array(exports_Schema.String)), cloneRoot: exports_Schema.String, checkout: exports_Schema.optional(RepositorySchema) }),
|
|
33727
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("project"), project: RepositorySchema, checkout: RepositorySchema, worktrees: exports_Schema.Array(WorktreeSchema), branches: exports_Schema.Array(exports_Schema.String), revisions: exports_Schema.Array(JjRevisionChoiceSchema) }),
|
|
33728
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("project-missing"), path: exports_Schema.String }),
|
|
33729
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("clone-source"), source: CloneSourceSchema }),
|
|
33730
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("worktrees"), repository: RepositorySchema, worktrees: exports_Schema.Array(WorktreeSchema), branches: exports_Schema.Array(exports_Schema.String), revisions: exports_Schema.Array(JjRevisionChoiceSchema) }),
|
|
33731
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("revision"), revision: JjRevisionSchema }),
|
|
33591
33732
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("plan"), plan: LaunchPlanSchema }),
|
|
33733
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("clone-plan"), plan: ClonePlanSchema }),
|
|
33734
|
+
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("clone-launch"), result: CloneLaunchResultSchema }),
|
|
33592
33735
|
exports_Schema.Struct({ ...RequestIdentitySchema.fields, kind: exports_Schema.Literal("launch"), result: LaunchResultSchema })
|
|
33593
33736
|
]);
|
|
33594
33737
|
var RexWorktreesResponseSchema = exports_Schema.fromJsonString(exports_Schema.fromJsonString(ResponseSchema));
|
|
@@ -33597,25 +33740,33 @@ var PopupSizeSchema = exports_Schema.Struct({ columns: exports_Schema.Number, ro
|
|
|
33597
33740
|
var PopupBoundsSchema = exports_Schema.Tuple([exports_Schema.Number, exports_Schema.Number, exports_Schema.Number, exports_Schema.Number]);
|
|
33598
33741
|
var RexIdentitySchema = exports_Schema.Struct({ host_id: ServerHostIdSchema, endpoint: exports_Schema.String, principal: exports_Schema.Struct({ transport: exports_Schema.String }) });
|
|
33599
33742
|
var RexSessionsSchema = exports_Schema.Struct({ sessions: exports_Schema.Array(exports_Schema.Struct({ session_id: SessionIdSchema, label: exports_Schema.String })) });
|
|
33600
|
-
var
|
|
33601
|
-
|
|
33602
|
-
|
|
33603
|
-
|
|
33604
|
-
|
|
33605
|
-
|
|
33606
|
-
|
|
33607
|
-
|
|
33608
|
-
|
|
33609
|
-
|
|
33610
|
-
|
|
33611
|
-
|
|
33612
|
-
|
|
33613
|
-
layer_id: exports_Schema.NullOr(LayerIdSchema),
|
|
33614
|
-
kind: exports_Schema.String,
|
|
33615
|
-
bounds: exports_Schema.optional(exports_Schema.NullOr(PopupBoundsSchema)),
|
|
33616
|
-
blocks: exports_Schema.Array(exports_Schema.Struct({ block_id: BlockIdSchema, owner: exports_Schema.optional(exports_Schema.NullOr(ClientIdSchema)) }))
|
|
33743
|
+
var RexSessionCreatedSchema = exports_Schema.Struct({ session_id: SessionIdSchema });
|
|
33744
|
+
var RexClientsSchema = exports_Schema.Struct({
|
|
33745
|
+
clients: exports_Schema.Array(exports_Schema.Struct({
|
|
33746
|
+
client_id: ClientIdSchema,
|
|
33747
|
+
info: exports_Schema.optional(exports_Schema.Struct({ kind: exports_Schema.String, label: exports_Schema.optional(exports_Schema.String) })),
|
|
33748
|
+
connection_state: exports_Schema.optional(exports_Schema.String)
|
|
33749
|
+
}))
|
|
33750
|
+
});
|
|
33751
|
+
var RexWindowsSchema = exports_Schema.Struct({
|
|
33752
|
+
windows: exports_Schema.Array(exports_Schema.Struct({
|
|
33753
|
+
window_id: WindowIdSchema,
|
|
33754
|
+
label: exports_Schema.String,
|
|
33755
|
+
layers: exports_Schema.Array(exports_Schema.Struct({ blocks: exports_Schema.optional(exports_Schema.Array(exports_Schema.Struct({ block_id: BlockIdSchema, host_id: ServerHostIdSchema }))) }))
|
|
33617
33756
|
}))
|
|
33618
|
-
})
|
|
33757
|
+
});
|
|
33758
|
+
var RexViewSchema = exports_Schema.Struct({
|
|
33759
|
+
active_window_id: exports_Schema.NullOr(WindowIdSchema),
|
|
33760
|
+
windows: exports_Schema.Array(exports_Schema.Struct({
|
|
33761
|
+
window_id: WindowIdSchema,
|
|
33762
|
+
layers: exports_Schema.Array(exports_Schema.Struct({
|
|
33763
|
+
layer_id: exports_Schema.NullOr(LayerIdSchema),
|
|
33764
|
+
kind: exports_Schema.String,
|
|
33765
|
+
bounds: exports_Schema.optional(exports_Schema.NullOr(PopupBoundsSchema)),
|
|
33766
|
+
blocks: exports_Schema.Array(exports_Schema.Struct({ block_id: BlockIdSchema, owner: exports_Schema.optional(exports_Schema.NullOr(ClientIdSchema)) }))
|
|
33767
|
+
}))
|
|
33768
|
+
}))
|
|
33769
|
+
});
|
|
33619
33770
|
var RexResizedSchema = exports_Schema.Struct({ revision: exports_Schema.Number });
|
|
33620
33771
|
var RexTerminalSizeSchema = exports_Schema.Struct({ ...PopupSizeSchema.fields, owner: exports_Schema.NullOr(ClientIdSchema) });
|
|
33621
33772
|
var RexCreatedSchema = exports_Schema.Struct({ window_id: exports_Schema.optional(WindowIdSchema), block_ids: exports_Schema.Array(BlockIdSchema) });
|
|
@@ -33633,19 +33784,21 @@ var RexActionsSchema = exports_Schema.Struct({ actions: exports_Schema.Array(exp
|
|
|
33633
33784
|
var RexHelperArgsSchema = exports_Schema.Struct({ properties: exports_Schema.Struct({ request: exports_Schema.Struct({ type: exports_Schema.Literal("string") }) }) });
|
|
33634
33785
|
var RexConfigCheckSchema = exports_Schema.Struct({ path: exports_Schema.String, exists: exports_Schema.Boolean, diagnostics: exports_Schema.Array(exports_Schema.Unknown) });
|
|
33635
33786
|
var CliBooleanFlagSchema = exports_Schema.Literals(["--additional", "--split", "--no-context", "--managed-popup"]);
|
|
33636
|
-
var CliStringFlagSchema = exports_Schema.Literals(["--bin", "--host", "--repo", "--session", "--name", "--branch", "--worktree", "--worktree-name", "--client", "--context", "--origin-session", "--origin-block", "--origin-client"]);
|
|
33787
|
+
var CliStringFlagSchema = exports_Schema.Literals(["--bin", "--config", "--host", "--repo", "--session", "--name", "--branch", "--revision", "--worktree", "--worktree-name", "--client", "--context", "--origin-session", "--origin-block", "--origin-client"]);
|
|
33637
33788
|
var CliFlagsSchema = exports_Schema.Struct({
|
|
33638
33789
|
"--additional": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
|
|
33639
33790
|
"--split": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
|
|
33640
33791
|
"--no-context": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
|
|
33641
33792
|
"--managed-popup": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.Boolean)),
|
|
33642
33793
|
"--bin": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33794
|
+
"--config": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33643
33795
|
"--host": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33644
33796
|
"--repo": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33645
33797
|
"--session": exports_Schema.mutableKey(exports_Schema.optional(SessionIdSchema)),
|
|
33646
33798
|
"--name": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33647
33799
|
"--branch": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33648
33800
|
"--worktree": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33801
|
+
"--revision": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33649
33802
|
"--worktree-name": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
33650
33803
|
"--client": exports_Schema.mutableKey(exports_Schema.optional(ClientIdSchema)),
|
|
33651
33804
|
"--context": exports_Schema.mutableKey(exports_Schema.optional(exports_Schema.String)),
|
|
@@ -33671,9 +33824,55 @@ var run4 = exports_Effect.fnUntraced(function* (program, args2, cwd, env) {
|
|
|
33671
33824
|
}));
|
|
33672
33825
|
});
|
|
33673
33826
|
|
|
33674
|
-
// src/
|
|
33827
|
+
// src/checkout.ts
|
|
33675
33828
|
var fail16 = (message) => exports_Effect.fail(new AppError({ message }));
|
|
33676
33829
|
var missing2 = (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound";
|
|
33830
|
+
var planCheckoutPath = exports_Effect.fnUntraced(function* (primaryPath, metadataDirectories, checkoutPaths, name, worktreeRoot) {
|
|
33831
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
33832
|
+
const path = yield* exports_Path.Path;
|
|
33833
|
+
if (worktreeRoot !== undefined && !path.isAbsolute(worktreeRoot))
|
|
33834
|
+
return yield* fail16("Worktree root must be absolute");
|
|
33835
|
+
const base = worktreeRoot === undefined ? `${primaryPath}.worktrees` : path.resolve(worktreeRoot);
|
|
33836
|
+
const destination = path.resolve(base, name);
|
|
33837
|
+
if (destination === base || !destination.startsWith(`${base}${path.sep}`))
|
|
33838
|
+
return yield* fail16("Worktree name escapes worktree directory");
|
|
33839
|
+
const inside = (parent, child) => child === parent || child.startsWith(`${parent}${path.sep}`);
|
|
33840
|
+
for (const checkout of checkoutPaths) {
|
|
33841
|
+
if (inside(checkout, base) || inside(checkout, destination))
|
|
33842
|
+
return yield* fail16(`Worktree root is inside checkout: ${checkout}`);
|
|
33843
|
+
}
|
|
33844
|
+
for (const metadata of metadataDirectories) {
|
|
33845
|
+
if (inside(metadata, base) || inside(metadata, destination))
|
|
33846
|
+
return yield* fail16(`Worktree root is inside metadata directory: ${metadata}`);
|
|
33847
|
+
}
|
|
33848
|
+
const forbidden2 = worktreeRoot === undefined ? [] : yield* exports_Effect.forEach([...checkoutPaths, ...metadataDirectories], (directory) => exports_Effect.catchIf(fs.stat(directory), missing2, () => exports_Effect.succeed(undefined)));
|
|
33849
|
+
if (forbidden2.some((entry) => entry && exports_Option.isNone(entry.ino)))
|
|
33850
|
+
return yield* fail16("Cannot verify worktree root filesystem identity");
|
|
33851
|
+
for (let part = path.parse(destination).root;; ) {
|
|
33852
|
+
const info2 = yield* exports_Effect.catchIf(fs.lstat(part), missing2, () => exports_Effect.succeed(undefined));
|
|
33853
|
+
if (info2?.type === "SymbolicLink")
|
|
33854
|
+
return yield* fail16(`Symlinked worktree path: ${part}`);
|
|
33855
|
+
if (worktreeRoot !== undefined && info2?.type === "Directory" && exports_Option.isNone(info2.ino))
|
|
33856
|
+
return yield* fail16("Cannot verify worktree root filesystem identity");
|
|
33857
|
+
const inode = info2 && exports_Option.getOrUndefined(info2.ino);
|
|
33858
|
+
if (inode !== undefined && forbidden2.some((entry) => entry !== undefined && info2 !== undefined && entry.dev === info2.dev && exports_Option.getOrUndefined(entry.ino) === inode)) {
|
|
33859
|
+
return yield* fail16(`Worktree root aliases a checkout or metadata directory: ${part}`);
|
|
33860
|
+
}
|
|
33861
|
+
if (part === destination) {
|
|
33862
|
+
if (info2)
|
|
33863
|
+
return yield* fail16(`Worktree path already exists: ${part}`);
|
|
33864
|
+
break;
|
|
33865
|
+
}
|
|
33866
|
+
if (info2 && info2.type !== "Directory")
|
|
33867
|
+
return yield* fail16(`Not a directory: ${part}`);
|
|
33868
|
+
part = path.join(part, path.relative(part, destination).split(path.sep)[0]);
|
|
33869
|
+
}
|
|
33870
|
+
return destination;
|
|
33871
|
+
});
|
|
33872
|
+
|
|
33873
|
+
// src/git.ts
|
|
33874
|
+
var fail17 = (message) => exports_Effect.fail(new AppError({ message }));
|
|
33875
|
+
var missing3 = (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound";
|
|
33677
33876
|
var notRepository = (error2) => exports_Schema.is(CommandError)(error2) && error2.program === "git" && error2.args.includes("rev-parse") && (error2.stderr.startsWith("fatal: not a git repository") || error2.stderr.startsWith("fatal: this operation must be run in a work tree"));
|
|
33678
33877
|
var git = (cwd, ...args2) => {
|
|
33679
33878
|
const env = {};
|
|
@@ -33684,6 +33883,95 @@ var git = (cwd, ...args2) => {
|
|
|
33684
33883
|
env.LC_ALL = "C";
|
|
33685
33884
|
return run4("git", ["-C", cwd, ...args2], undefined, env);
|
|
33686
33885
|
};
|
|
33886
|
+
var gitContext = exports_Effect.fnUntraced(function* (directory) {
|
|
33887
|
+
return yield* git(directory, "rev-parse", "--absolute-git-dir").pipe(exports_Effect.map((output) => output.trim()), exports_Effect.catchIf(notRepository, () => exports_Effect.succeed(undefined)));
|
|
33888
|
+
});
|
|
33889
|
+
var safeOrigin = (raw, sameHost, base) => {
|
|
33890
|
+
if (!raw || raw.startsWith("-") || /[\p{ASCII}&&\p{Cc}]/v.test(raw) || /^[a-z][a-z0-9+.-]*::/i.test(raw))
|
|
33891
|
+
throw new Error("Unsafe origin URL");
|
|
33892
|
+
if (raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || raw.startsWith("file://")) {
|
|
33893
|
+
if (!sameHost)
|
|
33894
|
+
throw new Error("Local source origins require the same Rex host");
|
|
33895
|
+
if (raw.startsWith("file://")) {
|
|
33896
|
+
const url = new URL(raw);
|
|
33897
|
+
if (url.host || url.search || url.hash || !url.pathname.startsWith("/"))
|
|
33898
|
+
throw new Error("Unsafe origin URL");
|
|
33899
|
+
const decoded = decodeURIComponent(url.pathname);
|
|
33900
|
+
if (/[\p{ASCII}&&\p{Cc}]/v.test(decoded))
|
|
33901
|
+
throw new Error("Unsafe origin URL");
|
|
33902
|
+
return decoded;
|
|
33903
|
+
}
|
|
33904
|
+
if (!base && !raw.startsWith("/"))
|
|
33905
|
+
throw new Error("Unsafe origin URL");
|
|
33906
|
+
return raw.startsWith("/") ? raw : resolvePath(base, raw);
|
|
33907
|
+
}
|
|
33908
|
+
if (/\s/.test(raw))
|
|
33909
|
+
throw new Error("Unsafe origin URL");
|
|
33910
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)) {
|
|
33911
|
+
const url = new URL(raw);
|
|
33912
|
+
if (!["https:", "ssh:", "git:"].includes(url.protocol) || !url.hostname || !url.pathname || url.search || url.hash || (url.protocol === "ssh:" ? !!url.password || !!url.username && !/^[a-zA-Z0-9_][a-zA-Z0-9_.-]*$/.test(url.username) : !!url.username || !!url.password))
|
|
33913
|
+
throw new Error("Unsafe origin URL");
|
|
33914
|
+
return raw;
|
|
33915
|
+
}
|
|
33916
|
+
if (/^(?:[a-zA-Z0-9_][a-zA-Z0-9_.-]*@)?[\w.-]+:[a-zA-Z0-9_./~+%-][a-zA-Z0-9_./~+%:-]*$/.test(raw))
|
|
33917
|
+
return raw;
|
|
33918
|
+
throw new Error("Unsafe origin URL");
|
|
33919
|
+
};
|
|
33920
|
+
var origin = exports_Effect.fnUntraced(function* (repoPath, sameHost) {
|
|
33921
|
+
const raw = yield* git(repoPath, "config", "--get", "remote.origin.url").pipe(exports_Effect.catch(() => fail17("Repository has no usable origin URL")));
|
|
33922
|
+
return yield* exports_Effect.try({
|
|
33923
|
+
try: () => safeOrigin(raw.replace(/\n$/, ""), sameHost, repoPath),
|
|
33924
|
+
catch: () => new AppError({ message: "Repository origin URL is unsafe or local to another Rex host" })
|
|
33925
|
+
});
|
|
33926
|
+
});
|
|
33927
|
+
var cloneSource = exports_Effect.fnUntraced(function* (repoPath, sourceHostId) {
|
|
33928
|
+
const repo = yield* repository(repoPath);
|
|
33929
|
+
const url = yield* origin(repo.path, true);
|
|
33930
|
+
const refs = yield* git(repo.path, "for-each-ref", "--format=%(refname)", "refs/heads", "refs/remotes/origin");
|
|
33931
|
+
const branches = [...new Set(refs.split(`
|
|
33932
|
+
`).flatMap((ref) => ref.startsWith("refs/heads/") ? [ref.slice("refs/heads/".length)] : ref.startsWith("refs/remotes/origin/") && ref !== "refs/remotes/origin/HEAD" ? [ref.slice("refs/remotes/origin/".length)] : []))];
|
|
33933
|
+
const remoteHead = yield* git(repo.path, "symbolic-ref", "--quiet", "refs/remotes/origin/HEAD").pipe(exports_Effect.catch(() => exports_Effect.succeed("")));
|
|
33934
|
+
const current = yield* git(repo.path, "branch", "--show-current");
|
|
33935
|
+
const branch = remoteHead.trim().replace(/^refs\/remotes\/origin\//, "") || current.trim() || undefined;
|
|
33936
|
+
const source = { vcs: "git", url, sourceHostId, branches, ...branch ? { branch } : {} };
|
|
33937
|
+
return source;
|
|
33938
|
+
});
|
|
33939
|
+
var remoteBranches = exports_Effect.fnUntraced(function* (repoPath) {
|
|
33940
|
+
const refs = yield* git(repoPath, "for-each-ref", "--format=%(refname)", "refs/remotes/origin");
|
|
33941
|
+
return refs.split(`
|
|
33942
|
+
`).filter((ref) => ref.startsWith("refs/remotes/origin/") && ref !== "refs/remotes/origin/HEAD").map((ref) => ref.slice("refs/remotes/origin/".length));
|
|
33943
|
+
});
|
|
33944
|
+
var remoteBranchHead = exports_Effect.fnUntraced(function* (repoPath, branch) {
|
|
33945
|
+
return (yield* git(repoPath, "rev-parse", "--verify", `refs/remotes/origin/${branch}^{commit}`)).trim();
|
|
33946
|
+
});
|
|
33947
|
+
var originDefaultHead = exports_Effect.fnUntraced(function* (repoPath) {
|
|
33948
|
+
const ref = yield* git(repoPath, "symbolic-ref", "--quiet", "refs/remotes/origin/HEAD").pipe(exports_Effect.catch(() => fail17("Cannot determine the existing repository's cached origin default branch")));
|
|
33949
|
+
return (yield* git(repoPath, "rev-parse", "--verify", `${ref.trim()}^{commit}`)).trim();
|
|
33950
|
+
});
|
|
33951
|
+
var cloneRepository = exports_Effect.fnUntraced(function* (url, destination) {
|
|
33952
|
+
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
33953
|
+
const env = {};
|
|
33954
|
+
for (const [key5, value3] of Object.entries(process.env))
|
|
33955
|
+
if (!key5.startsWith("GIT_") && value3 !== undefined)
|
|
33956
|
+
env[key5] = value3;
|
|
33957
|
+
env.GIT_TERMINAL_PROMPT = "1";
|
|
33958
|
+
const child = yield* spawner.spawn(exports_ChildProcess.make("git", ["clone", "--origin", "origin", "--", url, destination], {
|
|
33959
|
+
env,
|
|
33960
|
+
stdin: "inherit",
|
|
33961
|
+
stdout: "inherit",
|
|
33962
|
+
stderr: "inherit"
|
|
33963
|
+
}));
|
|
33964
|
+
const code = yield* child.exitCode;
|
|
33965
|
+
if (code !== 0)
|
|
33966
|
+
return yield* fail17(`Git clone failed (exit ${code}); destination retained at ${destination}`);
|
|
33967
|
+
}, exports_Effect.scoped);
|
|
33968
|
+
var validCloneBranch = exports_Effect.fnUntraced(function* (branch, worktreeName) {
|
|
33969
|
+
if (!branch || branch.startsWith("-") || branch.split("/").some((part) => !part || part === "." || part === "..") || /[\p{ASCII}&&\p{Cc}]/v.test(branch))
|
|
33970
|
+
return yield* fail17("Invalid clone branch");
|
|
33971
|
+
yield* run4("git", ["check-ref-format", "--branch", branch]).pipe(exports_Effect.catch(() => fail17("Invalid clone branch")));
|
|
33972
|
+
if (worktreeName !== undefined && (!worktreeName.trim() || worktreeName.startsWith("-") || worktreeName.split(/[\\/]/).some((part) => !part || part === "." || part === "..") || /[\p{ASCII}&&\p{Cc}]/v.test(worktreeName)))
|
|
33973
|
+
return yield* fail17("Invalid worktree name");
|
|
33974
|
+
});
|
|
33687
33975
|
var listWorktrees = exports_Effect.fnUntraced(function* (repoPath) {
|
|
33688
33976
|
const output = yield* git(repoPath, "worktree", "list", "--porcelain", "-z");
|
|
33689
33977
|
const records = [];
|
|
@@ -33694,7 +33982,7 @@ var listWorktrees = exports_Effect.fnUntraced(function* (repoPath) {
|
|
|
33694
33982
|
records.push(record2);
|
|
33695
33983
|
record2 = undefined;
|
|
33696
33984
|
} else if (line.startsWith("worktree ")) {
|
|
33697
|
-
record2 = { path: line.slice(9), branch: null, head: "", bare: false, locked: false, prunable: false };
|
|
33985
|
+
record2 = { vcs: "git", path: line.slice(9), branch: null, head: "", bare: false, locked: false, prunable: false };
|
|
33698
33986
|
} else if (record2) {
|
|
33699
33987
|
if (line.startsWith("HEAD "))
|
|
33700
33988
|
record2.head = line.slice(5);
|
|
@@ -33709,7 +33997,7 @@ var listWorktrees = exports_Effect.fnUntraced(function* (repoPath) {
|
|
|
33709
33997
|
}
|
|
33710
33998
|
}
|
|
33711
33999
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
33712
|
-
return yield* exports_Effect.forEach(records, (record3) => exports_Effect.catchIf(fs.realPath(record3.path).pipe(exports_Effect.map((real) => ({ ...record3, path: real }))), (error2) =>
|
|
34000
|
+
return yield* exports_Effect.forEach(records, (record3) => exports_Effect.catchIf(fs.realPath(record3.path).pipe(exports_Effect.map((real) => ({ ...record3, path: real }))), (error2) => missing3(error2), () => exports_Effect.succeed(record3)));
|
|
33713
34001
|
});
|
|
33714
34002
|
var repository = exports_Effect.fnUntraced(function* (input) {
|
|
33715
34003
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
@@ -33717,7 +34005,7 @@ var repository = exports_Effect.fnUntraced(function* (input) {
|
|
|
33717
34005
|
const canonical = yield* fs.realPath(input);
|
|
33718
34006
|
const top = (yield* git(canonical, "rev-parse", "--show-toplevel")).replace(/\n$/, "");
|
|
33719
34007
|
const common = (yield* git(canonical, "rev-parse", "--path-format=absolute", "--git-common-dir")).replace(/\n$/, "");
|
|
33720
|
-
return { path: yield* fs.realPath(top), commonDir: yield* fs.realPath(path.resolve(canonical, common)), name: path.basename(top) };
|
|
34008
|
+
return { vcs: "git", path: yield* fs.realPath(top), commonDir: yield* fs.realPath(path.resolve(canonical, common)), name: path.basename(top) };
|
|
33721
34009
|
});
|
|
33722
34010
|
var project = exports_Effect.fnUntraced(function* (input) {
|
|
33723
34011
|
const checkout = yield* repository(input);
|
|
@@ -33727,43 +34015,9 @@ var project = exports_Effect.fnUntraced(function* (input) {
|
|
|
33727
34015
|
return checkout;
|
|
33728
34016
|
if (primary.path === checkout.path)
|
|
33729
34017
|
return checkout;
|
|
33730
|
-
const main = primary.bare ? undefined : yield* exports_Effect.catchIf(exports_Effect.catchIf(repository(primary.path), (error2) =>
|
|
34018
|
+
const main = primary.bare ? undefined : yield* exports_Effect.catchIf(exports_Effect.catchIf(repository(primary.path), (error2) => missing3(error2), () => exports_Effect.succeed(undefined)), (error2) => notRepository(error2), () => exports_Effect.succeed(undefined));
|
|
33731
34019
|
return main?.commonDir === checkout.commonDir ? main : { ...checkout, name: path.basename(primary.path) };
|
|
33732
34020
|
});
|
|
33733
|
-
var discoverProjects = exports_Effect.fnUntraced(function* (roots, explicitProjects, contextPath) {
|
|
33734
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
33735
|
-
const path = yield* exports_Path.Path;
|
|
33736
|
-
const candidates = [...contextPath ? [contextPath] : [], ...explicitProjects];
|
|
33737
|
-
for (const root of roots) {
|
|
33738
|
-
if (!(yield* fs.exists(root)))
|
|
33739
|
-
continue;
|
|
33740
|
-
candidates.push(root);
|
|
33741
|
-
for (const name of yield* fs.readDirectory(root)) {
|
|
33742
|
-
const first = path.join(root, name);
|
|
33743
|
-
if (!(yield* fs.exists(first)))
|
|
33744
|
-
continue;
|
|
33745
|
-
const info2 = yield* fs.stat(first);
|
|
33746
|
-
if (info2.type !== "Directory")
|
|
33747
|
-
continue;
|
|
33748
|
-
candidates.push(first);
|
|
33749
|
-
for (const child of yield* fs.readDirectory(first)) {
|
|
33750
|
-
const second = path.join(first, child);
|
|
33751
|
-
if ((yield* fs.exists(second)) && (yield* fs.stat(second)).type === "Directory")
|
|
33752
|
-
candidates.push(second);
|
|
33753
|
-
}
|
|
33754
|
-
}
|
|
33755
|
-
}
|
|
33756
|
-
const found = [];
|
|
33757
|
-
const seen = new Set;
|
|
33758
|
-
for (const candidate of candidates) {
|
|
33759
|
-
const repo = yield* exports_Effect.catchIf(exports_Effect.catchIf(project(candidate), (error2) => missing2(error2), () => exports_Effect.succeed(undefined)), (error2) => notRepository(error2), () => exports_Effect.succeed(undefined));
|
|
33760
|
-
if (repo && !seen.has(repo.commonDir)) {
|
|
33761
|
-
seen.add(repo.commonDir);
|
|
33762
|
-
found.push(repo);
|
|
33763
|
-
}
|
|
33764
|
-
}
|
|
33765
|
-
return found;
|
|
33766
|
-
});
|
|
33767
34021
|
var listBranches = exports_Effect.fnUntraced(function* (repoPath) {
|
|
33768
34022
|
const refs = yield* git(repoPath, "for-each-ref", "--format=%(refname)%00", "refs/heads");
|
|
33769
34023
|
return refs.split(`\x00
|
|
@@ -33778,80 +34032,44 @@ var planWorktree = exports_Effect.fnUntraced(function* (repoPath, branch, worktr
|
|
|
33778
34032
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
33779
34033
|
const path = yield* exports_Path.Path;
|
|
33780
34034
|
if (!branch || branch.startsWith("-") || branch.includes("\x00") || branch.split("/").some((part) => part === "." || part === ".." || part === "")) {
|
|
33781
|
-
return yield*
|
|
34035
|
+
return yield* fail17(`Invalid branch name: ${JSON.stringify(branch)}`);
|
|
33782
34036
|
}
|
|
33783
34037
|
yield* git(repoPath, "check-ref-format", "--branch", branch);
|
|
33784
34038
|
if (worktreeName !== undefined && (!worktreeName.trim() || path.isAbsolute(worktreeName) || /[\p{ASCII}&&\p{Cc}]/v.test(worktreeName) || worktreeName.split(/[\\/]/).some((part) => !part || part === "." || part === ".."))) {
|
|
33785
|
-
return yield*
|
|
34039
|
+
return yield* fail17(`Invalid worktree name: ${JSON.stringify(worktreeName)}`);
|
|
33786
34040
|
}
|
|
33787
34041
|
const repo = yield* repository(repoPath);
|
|
33788
34042
|
const worktrees = yield* listWorktrees(repo.path);
|
|
33789
34043
|
const checked = worktrees.find((worktree) => worktree.branch === branch);
|
|
33790
34044
|
if (checked) {
|
|
33791
|
-
const gitFile = yield* exports_Effect.catchIf(fs.stat(path.join(checked.path, ".git")), (error2) =>
|
|
34045
|
+
const gitFile = yield* exports_Effect.catchIf(fs.stat(path.join(checked.path, ".git")), (error2) => missing3(error2), () => exports_Effect.succeed(undefined));
|
|
33792
34046
|
if (checked.prunable || !gitFile) {
|
|
33793
|
-
return yield*
|
|
34047
|
+
return yield* fail17(`Branch ${branch} is assigned to an unavailable checkout: ${checked.path}`);
|
|
33794
34048
|
}
|
|
33795
34049
|
return { repository: repo, path: checked.path, branch, existing: true };
|
|
33796
34050
|
}
|
|
33797
34051
|
const main = worktrees.find((worktree) => !worktree.bare);
|
|
33798
34052
|
if (!main)
|
|
33799
|
-
return yield*
|
|
33800
|
-
|
|
33801
|
-
return yield* fail16("Worktree root must be absolute");
|
|
33802
|
-
const base = worktreeRoot === undefined ? `${main.path}.worktrees` : path.resolve(worktreeRoot);
|
|
33803
|
-
const destination = path.resolve(base, worktreeName ?? branch);
|
|
33804
|
-
if (destination === base || !destination.startsWith(`${base}${path.sep}`))
|
|
33805
|
-
return yield* fail16("Worktree name escapes worktree directory");
|
|
33806
|
-
const inside = (parent, child) => child === parent || child.startsWith(`${parent}${path.sep}`);
|
|
33807
|
-
for (const checkout of worktrees) {
|
|
33808
|
-
if (inside(checkout.path, base) || inside(checkout.path, destination)) {
|
|
33809
|
-
return yield* fail16(`Worktree root is inside checkout: ${checkout.path}`);
|
|
33810
|
-
}
|
|
33811
|
-
}
|
|
33812
|
-
if (inside(repo.commonDir, base) || inside(repo.commonDir, destination))
|
|
33813
|
-
return yield* fail16(`Worktree root is inside Git directory: ${repo.commonDir}`);
|
|
33814
|
-
const forbidden2 = worktreeRoot === undefined ? [] : yield* exports_Effect.forEach([...worktrees.map((checkout) => checkout.path), repo.commonDir], (directory) => exports_Effect.catchIf(fs.stat(directory), (error2) => missing2(error2), () => exports_Effect.succeed(undefined)));
|
|
33815
|
-
if (forbidden2.some((entry) => entry && exports_Option.isNone(entry.ino))) {
|
|
33816
|
-
return yield* fail16("Cannot verify worktree root filesystem identity");
|
|
33817
|
-
}
|
|
33818
|
-
for (let part = path.parse(destination).root;; ) {
|
|
33819
|
-
const info2 = yield* exports_Effect.catchIf(fs.lstat(part), (error2) => missing2(error2), () => exports_Effect.succeed(undefined));
|
|
33820
|
-
if (info2?.type === "SymbolicLink")
|
|
33821
|
-
return yield* fail16(`Symlinked worktree path: ${part}`);
|
|
33822
|
-
if (worktreeRoot !== undefined && info2?.type === "Directory" && exports_Option.isNone(info2.ino)) {
|
|
33823
|
-
return yield* fail16("Cannot verify worktree root filesystem identity");
|
|
33824
|
-
}
|
|
33825
|
-
const inode = info2 && exports_Option.getOrUndefined(info2.ino);
|
|
33826
|
-
if (inode !== undefined && forbidden2.some((entry) => entry !== undefined && info2 !== undefined && entry.dev === info2.dev && exports_Option.getOrUndefined(entry.ino) === inode))
|
|
33827
|
-
return yield* fail16(`Worktree root aliases a checkout or Git directory: ${part}`);
|
|
33828
|
-
if (part === destination) {
|
|
33829
|
-
if (info2)
|
|
33830
|
-
return yield* fail16(`Worktree path already exists: ${part}`);
|
|
33831
|
-
break;
|
|
33832
|
-
}
|
|
33833
|
-
if (info2 && info2.type !== "Directory")
|
|
33834
|
-
return yield* fail16(`Not a directory: ${part}`);
|
|
33835
|
-
part = path.join(part, path.relative(part, destination).split(path.sep)[0]);
|
|
33836
|
-
}
|
|
34053
|
+
return yield* fail17("No main checkout exists");
|
|
34054
|
+
const destination = yield* planCheckoutPath(main.path, [repo.commonDir], worktrees.map((worktree) => worktree.path), worktreeName ?? branch, worktreeRoot);
|
|
33837
34055
|
return { repository: repo, path: destination, branch, existing: false };
|
|
33838
34056
|
});
|
|
33839
34057
|
var createWorktree = exports_Effect.fnUntraced(function* (repoPath, branch, options = {}) {
|
|
33840
34058
|
const { startPoint: pinned, attachOnly, worktreeRoot, worktreeName } = options;
|
|
33841
34059
|
if (pinned !== undefined && !/^[0-9a-f]{40,64}$/.test(pinned))
|
|
33842
|
-
return yield*
|
|
34060
|
+
return yield* fail17("Invalid pinned base commit");
|
|
33843
34061
|
if (pinned !== undefined && (yield* listBranches(repoPath)).includes(branch))
|
|
33844
|
-
return yield*
|
|
34062
|
+
return yield* fail17(`Branch ${branch} appeared after review; inspect before retrying`);
|
|
33845
34063
|
if (attachOnly && !(yield* listBranches(repoPath)).includes(branch))
|
|
33846
|
-
return yield*
|
|
34064
|
+
return yield* fail17(`Branch ${branch} disappeared after review; inspect before retrying`);
|
|
33847
34065
|
const plan = yield* planWorktree(repoPath, branch, worktreeRoot, worktreeName);
|
|
33848
34066
|
if (plan.existing) {
|
|
33849
34067
|
if (pinned !== undefined || attachOnly)
|
|
33850
|
-
return yield*
|
|
34068
|
+
return yield* fail17(`Branch ${branch} changed checkout after review; inspect before retrying`);
|
|
33851
34069
|
const worktrees = yield* listWorktrees(plan.repository.path);
|
|
33852
34070
|
const existing = worktrees.find((worktree) => worktree.path === plan.path);
|
|
33853
34071
|
if (!existing)
|
|
33854
|
-
return yield*
|
|
34072
|
+
return yield* fail17(`Worktree ${plan.path} disappeared after review; inspect before retrying`);
|
|
33855
34073
|
return existing;
|
|
33856
34074
|
}
|
|
33857
34075
|
const branches = yield* listBranches(plan.repository.path);
|
|
@@ -33859,27 +34077,379 @@ var createWorktree = exports_Effect.fnUntraced(function* (repoPath, branch, opti
|
|
|
33859
34077
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
33860
34078
|
const path = yield* exports_Path.Path;
|
|
33861
34079
|
if (pinned !== undefined && branchExists)
|
|
33862
|
-
return yield*
|
|
34080
|
+
return yield* fail17(`Branch ${branch} appeared after review; inspect before retrying`);
|
|
33863
34081
|
if (attachOnly && !branchExists)
|
|
33864
|
-
return yield*
|
|
34082
|
+
return yield* fail17(`Branch ${branch} disappeared after review; inspect before retrying`);
|
|
33865
34083
|
const current = yield* planWorktree(repoPath, branch, worktreeRoot, worktreeName);
|
|
33866
34084
|
if (current.existing) {
|
|
33867
34085
|
if (pinned !== undefined || attachOnly)
|
|
33868
|
-
return yield*
|
|
34086
|
+
return yield* fail17(`Branch ${branch} changed checkout after review; inspect before retrying`);
|
|
33869
34087
|
const existing = (yield* listWorktrees(plan.repository.path)).find((worktree) => worktree.path === current.path);
|
|
33870
34088
|
if (!existing)
|
|
33871
|
-
return yield*
|
|
34089
|
+
return yield* fail17(`Worktree ${current.path} disappeared after review; inspect before retrying`);
|
|
33872
34090
|
return existing;
|
|
33873
34091
|
}
|
|
33874
34092
|
yield* fs.makeDirectory(path.dirname(current.path), { recursive: true });
|
|
33875
34093
|
if ((yield* fs.realPath(path.dirname(current.path))) !== path.dirname(current.path)) {
|
|
33876
|
-
return yield*
|
|
34094
|
+
return yield* fail17(`Symlinked worktree parent: ${path.dirname(current.path)}`);
|
|
34095
|
+
}
|
|
34096
|
+
yield* git(plan.repository.path, "worktree", "add", ...pinned !== undefined || !branchExists && !attachOnly ? ["-b", branch] : [], "--", current.path, ...pinned !== undefined ? [pinned] : branchExists || attachOnly ? [branch] : []);
|
|
34097
|
+
const created = (yield* listWorktrees(plan.repository.path)).find((worktree) => worktree.path === current.path);
|
|
34098
|
+
if (!created)
|
|
34099
|
+
return yield* fail17(`Git did not list created worktree ${current.path}`);
|
|
34100
|
+
return created;
|
|
34101
|
+
});
|
|
34102
|
+
|
|
34103
|
+
// src/jj.ts
|
|
34104
|
+
var fail18 = (message) => exports_Effect.fail(new AppError({ message }));
|
|
34105
|
+
var missing4 = (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound";
|
|
34106
|
+
var isolatedEnv = () => {
|
|
34107
|
+
const env = {};
|
|
34108
|
+
for (const [key5, value3] of Object.entries(process.env))
|
|
34109
|
+
if (!key5.startsWith("GIT_") && value3 !== undefined)
|
|
34110
|
+
env[key5] = value3;
|
|
34111
|
+
env.LC_ALL = "C";
|
|
34112
|
+
return env;
|
|
34113
|
+
};
|
|
34114
|
+
var jj = (repo, ...args2) => run4("jj", ["-R", repo, "--no-pager", "--color=never", ...args2], undefined, isolatedEnv());
|
|
34115
|
+
var inventory = (repo, ...args2) => jj(repo, "--ignore-working-copy", "--at-op=@", ...args2);
|
|
34116
|
+
var version = exports_Effect.fnUntraced(function* () {
|
|
34117
|
+
for (const [program, minimum] of [["jj", [0, 46]], ["git", [2, 42]]]) {
|
|
34118
|
+
const output = yield* run4(program, ["--version"], undefined, isolatedEnv()).pipe(exports_Effect.catchIf((error2) => missing4(error2), () => fail18(`${program} executable not found on this Rex host; install ${program} >= ${minimum.join(".")} and ensure it is on the popup/task PATH`)));
|
|
34119
|
+
const match9 = /\b(\d+)\.(\d+)(?:\.\d+)?\b/.exec(output);
|
|
34120
|
+
if (!match9 || Number(match9[1]) < minimum[0] || Number(match9[1]) === minimum[0] && Number(match9[2]) < minimum[1]) {
|
|
34121
|
+
return yield* fail18(`Requires ${program} >= ${minimum.join(".")}`);
|
|
34122
|
+
}
|
|
34123
|
+
}
|
|
34124
|
+
});
|
|
34125
|
+
var workspaceTemplate = 'json({"name" => name, "path" => root, "commitId" => self.target().commit_id(), "changeId" => self.target().change_id()}) ++ "\\n"';
|
|
34126
|
+
var revisionTemplate = 'json({"commitId" => commit_id, "changeId" => change_id, "description" => description, "conflict" => self.conflict()}) ++ "\\n"';
|
|
34127
|
+
var workspaceRow = exports_Schema.Struct({ name: JjWorkspaceNameSchema, path: exports_Schema.NullOr(exports_Schema.String), commitId: JjCommitIdSchema, changeId: JjChangeIdSchema });
|
|
34128
|
+
var revisionRow = exports_Schema.Struct({ commitId: JjCommitIdSchema, changeId: JjChangeIdSchema, description: exports_Schema.String, conflict: exports_Schema.Boolean });
|
|
34129
|
+
var bookmarkRow = exports_Schema.Struct({ name: exports_Schema.String, remote: exports_Schema.NullOr(exports_Schema.String), present: exports_Schema.Boolean, conflict: exports_Schema.Boolean, target: exports_Schema.String });
|
|
34130
|
+
var bookmarkTemplate = 'json({"name" => name, "remote" => remote, "present" => present, "conflict" => conflict, "target" => try(self.normal_target().commit_id(), "")}) ++ "\\n"';
|
|
34131
|
+
var rows = (schema, raw) => exports_Effect.forEach(raw.split(`
|
|
34132
|
+
`).filter(Boolean), (line) => exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(schema))(line));
|
|
34133
|
+
var validName = exports_Effect.fnUntraced(function* (value3) {
|
|
34134
|
+
if (!value3.trim() || value3 !== value3.trim() || value3.startsWith("-") || /[\\/\p{Cc}]/u.test(value3) || value3 === "." || value3 === "..")
|
|
34135
|
+
return yield* fail18("Invalid JJ workspace name");
|
|
34136
|
+
return yield* exports_Schema.decodeUnknownEffect(JjWorkspaceNameSchema)(value3);
|
|
34137
|
+
});
|
|
34138
|
+
var validPin = exports_Effect.fnUntraced(function* (id2) {
|
|
34139
|
+
if (!/^[0-9a-f]{40,64}$/.test(id2))
|
|
34140
|
+
return yield* fail18("Invalid full JJ base commit ID");
|
|
34141
|
+
return yield* exports_Schema.decodeUnknownEffect(JjCommitIdSchema)(id2);
|
|
34142
|
+
});
|
|
34143
|
+
var marker = exports_Effect.fnUntraced(function* (input) {
|
|
34144
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34145
|
+
const path = yield* exports_Path.Path;
|
|
34146
|
+
let directory = yield* fs.realPath(input);
|
|
34147
|
+
const info2 = yield* fs.stat(directory);
|
|
34148
|
+
if (info2.type !== "Directory")
|
|
34149
|
+
directory = path.dirname(directory);
|
|
34150
|
+
for (;; ) {
|
|
34151
|
+
const dot = path.join(directory, ".jj");
|
|
34152
|
+
const exists2 = yield* fs.stat(dot).pipe(exports_Effect.catchIf(missing4, () => exports_Effect.succeed(undefined)));
|
|
34153
|
+
if (exists2) {
|
|
34154
|
+
if (exists2.type !== "Directory")
|
|
34155
|
+
return yield* fail18("Invalid JJ workspace metadata");
|
|
34156
|
+
return { directory, dot };
|
|
34157
|
+
}
|
|
34158
|
+
const parent = path.dirname(directory);
|
|
34159
|
+
if (parent === directory)
|
|
34160
|
+
return yield* fail18("Not a JJ repository");
|
|
34161
|
+
directory = parent;
|
|
34162
|
+
}
|
|
34163
|
+
});
|
|
34164
|
+
var metadata = exports_Effect.fnUntraced(function* (dot) {
|
|
34165
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34166
|
+
const path = yield* exports_Path.Path;
|
|
34167
|
+
const pointer = path.join(dot, "repo");
|
|
34168
|
+
const entry = yield* fs.stat(pointer).pipe(exports_Effect.catchIf(missing4, () => fail18("JJ workspace has no repository metadata")));
|
|
34169
|
+
if (entry.type === "Directory")
|
|
34170
|
+
return yield* fs.realPath(pointer);
|
|
34171
|
+
if (entry.type !== "File")
|
|
34172
|
+
return yield* fail18("Invalid JJ repository pointer");
|
|
34173
|
+
const text = (yield* fs.readFileString(pointer)).trim();
|
|
34174
|
+
if (!text || text.includes("\x00"))
|
|
34175
|
+
return yield* fail18("Invalid JJ repository pointer");
|
|
34176
|
+
const target = yield* fs.realPath(path.resolve(dot, text));
|
|
34177
|
+
if ((yield* fs.stat(target)).type !== "Directory")
|
|
34178
|
+
return yield* fail18("Invalid JJ repository pointer");
|
|
34179
|
+
return target;
|
|
34180
|
+
});
|
|
34181
|
+
var repository2 = exports_Effect.fnUntraced(function* (input) {
|
|
34182
|
+
yield* version();
|
|
34183
|
+
const path = yield* exports_Path.Path;
|
|
34184
|
+
const { directory, dot } = yield* marker(input);
|
|
34185
|
+
return { vcs: "jj", path: directory, commonDir: yield* metadata(dot), name: path.basename(directory) };
|
|
34186
|
+
});
|
|
34187
|
+
var listWorkspaces = exports_Effect.fnUntraced(function* (repo) {
|
|
34188
|
+
const current = yield* repository2(repo);
|
|
34189
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34190
|
+
const path = yield* exports_Path.Path;
|
|
34191
|
+
const parsed = yield* rows(workspaceRow, yield* inventory(current.path, "workspace", "list", "-T", workspaceTemplate));
|
|
34192
|
+
return yield* exports_Effect.forEach(parsed, (item) => exports_Effect.gen(function* () {
|
|
34193
|
+
if (!item.path)
|
|
34194
|
+
return { vcs: "jj", path: null, name: item.name, head: item.commitId, changeId: item.changeId, present: false, colocated: false };
|
|
34195
|
+
const location = path.resolve(item.path);
|
|
34196
|
+
const real = yield* fs.realPath(location).pipe(exports_Effect.catchIf(missing4, () => exports_Effect.succeed(undefined)));
|
|
34197
|
+
let present = false;
|
|
34198
|
+
if (real) {
|
|
34199
|
+
const dot = yield* fs.stat(path.join(real, ".jj")).pipe(exports_Effect.catchIf(missing4, () => exports_Effect.succeed(undefined)));
|
|
34200
|
+
if (dot?.type === "Directory") {
|
|
34201
|
+
const linked = yield* metadata(path.join(real, ".jj"));
|
|
34202
|
+
present = linked === current.commonDir;
|
|
34203
|
+
}
|
|
34204
|
+
}
|
|
34205
|
+
const colocated = present && !!(yield* fs.stat(path.join(real, ".git")).pipe(exports_Effect.catchIf(missing4, () => exports_Effect.succeed(undefined))));
|
|
34206
|
+
return { vcs: "jj", path: real ?? location, name: item.name, head: item.commitId, changeId: item.changeId, present, colocated };
|
|
34207
|
+
}));
|
|
34208
|
+
});
|
|
34209
|
+
var project2 = exports_Effect.fnUntraced(function* (input) {
|
|
34210
|
+
const current = yield* repository2(input);
|
|
34211
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34212
|
+
const path = yield* exports_Path.Path;
|
|
34213
|
+
const primaryPath = path.dirname(path.dirname(current.commonDir));
|
|
34214
|
+
const primary = (yield* listWorkspaces(current.path)).find((item) => item.path === primaryPath);
|
|
34215
|
+
if (!primary?.present)
|
|
34216
|
+
return current;
|
|
34217
|
+
return { ...current, path: yield* fs.realPath(primaryPath), name: path.basename(primaryPath) };
|
|
34218
|
+
});
|
|
34219
|
+
var resolveRevision = exports_Effect.fnUntraced(function* (repo, expression) {
|
|
34220
|
+
if (!expression.trim() || expression.startsWith("-") || /[\p{Cc}]/u.test(expression))
|
|
34221
|
+
return yield* fail18("Invalid JJ base revision");
|
|
34222
|
+
const current = yield* repository2(repo);
|
|
34223
|
+
const revset = /^[0-9a-f]{40,64}$/.test(expression) ? `commit_id("${expression}")` : expression;
|
|
34224
|
+
const parsed = yield* rows(revisionRow, yield* inventory(current.path, "log", "-r", revset, "--no-graph", "--limit", "2", "-T", revisionTemplate));
|
|
34225
|
+
if (parsed.length !== 1 || parsed[0].conflict)
|
|
34226
|
+
return yield* fail18("JJ base must resolve to one non-conflicted revision");
|
|
34227
|
+
const { commitId, changeId, description } = parsed[0];
|
|
34228
|
+
return { commitId, changeId, description };
|
|
34229
|
+
});
|
|
34230
|
+
var listRevisions = exports_Effect.fnUntraced(function* (repo) {
|
|
34231
|
+
const current = yield* repository2(repo);
|
|
34232
|
+
const bookmarks = (yield* rows(bookmarkRow, yield* inventory(current.path, "bookmark", "list", "-T", bookmarkTemplate))).filter((item) => item.present && !item.conflict && /^[0-9a-f]{40,64}$/.test(item.target));
|
|
34233
|
+
const choices = [];
|
|
34234
|
+
const mainline = yield* inventory(current.path, "log", "-r", "trunk()", "--no-graph", "--limit", "2", "-T", revisionTemplate).pipe(exports_Effect.catchIf((error2) => exports_Schema.is(CommandError)(error2) && error2.program === "jj" && /^Error: (?:Failed to (?:parse|resolve) revset|Invalid revset|Revision |Revset |Cannot resolve |No such revision)/i.test(error2.stderr), () => exports_Effect.succeed("")));
|
|
34235
|
+
const mainlineRows = yield* rows(revisionRow, mainline);
|
|
34236
|
+
if (mainlineRows.length === 1 && !mainlineRows[0].conflict && !/^0+$/.test(mainlineRows[0].commitId)) {
|
|
34237
|
+
const item = mainlineRows[0];
|
|
34238
|
+
choices.push({
|
|
34239
|
+
expression: "trunk()",
|
|
34240
|
+
label: `Mainline \xB7 ${item.description.trim() || item.changeId.slice(0, 12)} \xB7 ${item.commitId.slice(0, 12)}`,
|
|
34241
|
+
revision: { commitId: item.commitId, changeId: item.changeId, description: item.description }
|
|
34242
|
+
});
|
|
34243
|
+
}
|
|
34244
|
+
const candidates = ["@-", "bookmarks()", "remote_bookmarks()"];
|
|
34245
|
+
for (const expression of candidates) {
|
|
34246
|
+
const raw = yield* inventory(current.path, "log", "-r", expression, "--no-graph", "--limit", "40", "-T", revisionTemplate);
|
|
34247
|
+
for (const item of yield* rows(revisionRow, raw)) {
|
|
34248
|
+
if (item.conflict || choices.some((choice) => choice.revision.commitId === item.commitId))
|
|
34249
|
+
continue;
|
|
34250
|
+
const revision = { commitId: item.commitId, changeId: item.changeId, description: item.description };
|
|
34251
|
+
const ref = bookmarks.find((bookmark) => bookmark.target === item.commitId && (expression === "remote_bookmarks()" ? bookmark.remote !== null : bookmark.remote === null));
|
|
34252
|
+
const label = expression === "@-" ? "Parent" : ref ? `${ref.name}${ref.remote ? `@${ref.remote}` : ""}` : expression === "bookmarks()" ? "Bookmark" : "Remote bookmark";
|
|
34253
|
+
choices.push({ expression: item.commitId, label: `${label} \xB7 ${item.description.trim() || item.changeId.slice(0, 12)} \xB7 ${item.commitId.slice(0, 12)}`, revision });
|
|
34254
|
+
}
|
|
34255
|
+
}
|
|
34256
|
+
return choices;
|
|
34257
|
+
});
|
|
34258
|
+
var gitRoot = exports_Effect.fnUntraced(function* (repo) {
|
|
34259
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34260
|
+
const raw = (yield* inventory(repo, "git", "root")).trim();
|
|
34261
|
+
if (!raw)
|
|
34262
|
+
return yield* fail18("JJ backing Git directory is unavailable");
|
|
34263
|
+
return yield* fs.realPath(raw);
|
|
34264
|
+
});
|
|
34265
|
+
var cloneSource2 = exports_Effect.fnUntraced(function* (repo, sourceHostId) {
|
|
34266
|
+
const current = yield* repository2(repo);
|
|
34267
|
+
const raw = yield* run4("git", ["--git-dir", yield* gitRoot(current.path), "config", "--get", "remote.origin.url"], undefined, isolatedEnv()).pipe(exports_Effect.catch(() => fail18("JJ repository has no usable origin URL")));
|
|
34268
|
+
const url = yield* exports_Effect.try({ try: () => safeOrigin(raw.replace(/\n$/, ""), true, current.path), catch: () => new AppError({ message: "JJ origin URL is unsafe or local to another Rex host" }) });
|
|
34269
|
+
const revisions = yield* listRevisions(current.path);
|
|
34270
|
+
const remote = (yield* rows(bookmarkRow, yield* inventory(current.path, "bookmark", "list", "-T", bookmarkTemplate))).filter((item) => item.present && !item.conflict && item.remote === "origin");
|
|
34271
|
+
const revision = remote.length === 1 ? revisions.find((choice) => choice.revision.commitId === remote[0].target)?.revision : undefined;
|
|
34272
|
+
return { vcs: "jj", url, sourceHostId, revisions, ...revision ? { revision } : {} };
|
|
34273
|
+
});
|
|
34274
|
+
var planWorkspace = exports_Effect.fnUntraced(function* (repo, name, revision, worktreeRoot) {
|
|
34275
|
+
const workspaceName = yield* validName(name);
|
|
34276
|
+
const source = yield* repository2(repo);
|
|
34277
|
+
const primary = yield* project2(source.path);
|
|
34278
|
+
const workspaces = yield* listWorkspaces(source.path);
|
|
34279
|
+
if (workspaces.some((item) => item.name === workspaceName))
|
|
34280
|
+
return yield* fail18(`JJ workspace ${name} already registered; inspect it before retrying`);
|
|
34281
|
+
const base = yield* resolveRevision(source.path, revision);
|
|
34282
|
+
const gitDirectory = yield* gitRoot(primary.path);
|
|
34283
|
+
const path = yield* planCheckoutPath(primary.path, [primary.commonDir, gitDirectory], workspaces.flatMap((item) => item.path === null ? [] : [item.path]), name, worktreeRoot);
|
|
34284
|
+
return { repository: source, path, workspaceName, base };
|
|
34285
|
+
});
|
|
34286
|
+
var createWorkspace = exports_Effect.fnUntraced(function* (repo, name, base, worktreeRoot) {
|
|
34287
|
+
const pin = yield* validPin(base.commitId);
|
|
34288
|
+
const planned = yield* planWorkspace(repo, name, pin, worktreeRoot);
|
|
34289
|
+
if (planned.base.changeId !== base.changeId || planned.base.commitId !== pin)
|
|
34290
|
+
return yield* fail18("JJ base changed since review; inspect before retrying");
|
|
34291
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34292
|
+
const path = yield* exports_Path.Path;
|
|
34293
|
+
yield* fs.makeDirectory(path.dirname(planned.path), { recursive: true });
|
|
34294
|
+
if ((yield* fs.realPath(path.dirname(planned.path))) !== path.dirname(planned.path))
|
|
34295
|
+
return yield* fail18("Symlinked JJ workspace parent");
|
|
34296
|
+
yield* jj(planned.repository.path, "workspace", "add", "--name", name, "-r", `commit_id("${pin}")`, planned.path);
|
|
34297
|
+
const created = (yield* listWorkspaces(planned.repository.path)).find((item) => item.name === name && item.path === planned.path);
|
|
34298
|
+
if (!created?.present)
|
|
34299
|
+
return yield* fail18(`JJ did not list created workspace at ${planned.path}; inspect before retrying`);
|
|
34300
|
+
return created;
|
|
34301
|
+
});
|
|
34302
|
+
var newChange = exports_Effect.fnUntraced(function* (repo, base) {
|
|
34303
|
+
const pin = yield* validPin(base.commitId);
|
|
34304
|
+
const current = yield* repository2(repo);
|
|
34305
|
+
const resolved = yield* resolveRevision(current.path, pin);
|
|
34306
|
+
if (resolved.changeId !== base.changeId)
|
|
34307
|
+
return yield* fail18("Selected JJ base is unavailable in destination clone; clone retained");
|
|
34308
|
+
const before = (yield* listWorkspaces(current.path)).find((item) => item.path === current.path);
|
|
34309
|
+
if (!before?.present)
|
|
34310
|
+
return yield* fail18("Cloned JJ default workspace is unavailable");
|
|
34311
|
+
yield* jj(current.path, "new", "-r", `commit_id("${pin}")`);
|
|
34312
|
+
const after = (yield* listWorkspaces(current.path)).find((item) => item.name === before.name);
|
|
34313
|
+
if (!after?.present)
|
|
34314
|
+
return yield* fail18("JJ did not list cloned default workspace after new change");
|
|
34315
|
+
return after;
|
|
34316
|
+
});
|
|
34317
|
+
var cloneRepository2 = exports_Effect.fnUntraced(function* (url, destination) {
|
|
34318
|
+
yield* version();
|
|
34319
|
+
const safe = yield* exports_Effect.try({ try: () => safeOrigin(url, true), catch: () => new AppError({ message: "Unsafe JJ clone URL" }) });
|
|
34320
|
+
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
34321
|
+
const child = yield* spawner.spawn(exports_ChildProcess.make("jj", ["git", "clone", safe, destination], {
|
|
34322
|
+
env: isolatedEnv(),
|
|
34323
|
+
stdin: "inherit",
|
|
34324
|
+
stdout: "inherit",
|
|
34325
|
+
stderr: "inherit"
|
|
34326
|
+
})).pipe(exports_Effect.mapError(() => new AppError({ message: "Unable to launch JJ clone; destination may need inspection" })));
|
|
34327
|
+
const code = yield* child.exitCode;
|
|
34328
|
+
if (code !== 0)
|
|
34329
|
+
return yield* fail18(`JJ clone failed (exit ${code}); destination retained at ${destination}`);
|
|
34330
|
+
}, exports_Effect.scoped);
|
|
34331
|
+
|
|
34332
|
+
// src/repositories.ts
|
|
34333
|
+
var missing5 = (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound";
|
|
34334
|
+
var backend = exports_Effect.fnUntraced(function* (input) {
|
|
34335
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34336
|
+
const path = yield* exports_Path.Path;
|
|
34337
|
+
const canonical = yield* fs.realPath(input);
|
|
34338
|
+
let current = (yield* fs.stat(canonical)).type === "Directory" ? canonical : path.dirname(canonical);
|
|
34339
|
+
for (;; ) {
|
|
34340
|
+
if (yield* fs.lstat(path.join(current, ".jj")).pipe(exports_Effect.map(() => true), exports_Effect.catchIf(missing5, () => exports_Effect.succeed(false))))
|
|
34341
|
+
return "jj";
|
|
34342
|
+
if (yield* fs.lstat(path.join(current, ".git")).pipe(exports_Effect.map(() => true), exports_Effect.catchIf(missing5, () => exports_Effect.succeed(false))))
|
|
34343
|
+
return "git";
|
|
34344
|
+
const parent = path.dirname(current);
|
|
34345
|
+
if (parent === current)
|
|
34346
|
+
return "git";
|
|
34347
|
+
current = parent;
|
|
34348
|
+
}
|
|
34349
|
+
});
|
|
34350
|
+
var repository3 = exports_Effect.fnUntraced(function* (input) {
|
|
34351
|
+
return (yield* backend(input)) === "jj" ? yield* repository2(input) : yield* repository(input);
|
|
34352
|
+
});
|
|
34353
|
+
var project3 = exports_Effect.fnUntraced(function* (input) {
|
|
34354
|
+
return (yield* backend(input)) === "jj" ? yield* project2(input) : yield* project(input);
|
|
34355
|
+
});
|
|
34356
|
+
var discoverProjects = exports_Effect.fnUntraced(function* (roots, explicitProjects, contextPath) {
|
|
34357
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34358
|
+
const path = yield* exports_Path.Path;
|
|
34359
|
+
const candidates = [...contextPath ? [contextPath] : [], ...explicitProjects];
|
|
34360
|
+
for (const root of roots) {
|
|
34361
|
+
if (!(yield* fs.exists(root)))
|
|
34362
|
+
continue;
|
|
34363
|
+
candidates.push(root);
|
|
34364
|
+
for (const name of yield* fs.readDirectory(root)) {
|
|
34365
|
+
const first = path.join(root, name);
|
|
34366
|
+
if (!(yield* fs.exists(first)))
|
|
34367
|
+
continue;
|
|
34368
|
+
const info2 = yield* fs.stat(first);
|
|
34369
|
+
if (info2.type !== "Directory")
|
|
34370
|
+
continue;
|
|
34371
|
+
candidates.push(first);
|
|
34372
|
+
for (const child of yield* fs.readDirectory(first)) {
|
|
34373
|
+
const second = path.join(first, child);
|
|
34374
|
+
if ((yield* fs.exists(second)) && (yield* fs.stat(second)).type === "Directory")
|
|
34375
|
+
candidates.push(second);
|
|
34376
|
+
}
|
|
34377
|
+
}
|
|
34378
|
+
}
|
|
34379
|
+
const found = [];
|
|
34380
|
+
const seen = new Set;
|
|
34381
|
+
for (const candidate of candidates) {
|
|
34382
|
+
const repo = yield* exports_Effect.catchIf(exports_Effect.catchIf(project3(candidate), (error2) => missing5(error2), () => exports_Effect.succeed(undefined)), (error2) => notRepository(error2), () => exports_Effect.succeed(undefined));
|
|
34383
|
+
if (repo && !seen.has(`${repo.vcs}\x00${repo.commonDir}`)) {
|
|
34384
|
+
seen.add(`${repo.vcs}\x00${repo.commonDir}`);
|
|
34385
|
+
found.push(repo);
|
|
34386
|
+
}
|
|
34387
|
+
}
|
|
34388
|
+
return found;
|
|
34389
|
+
});
|
|
34390
|
+
|
|
34391
|
+
// src/state.ts
|
|
34392
|
+
import { randomUUID } from "crypto";
|
|
34393
|
+
import { homedir } from "os";
|
|
34394
|
+
var cloneRootFile = exports_Effect.fnUntraced(function* (stateRoot) {
|
|
34395
|
+
const path = yield* exports_Path.Path;
|
|
34396
|
+
const root = stateRoot ?? (process.env.XDG_STATE_HOME || path.join(homedir(), ".local", "state"));
|
|
34397
|
+
if (!path.isAbsolute(root))
|
|
34398
|
+
return yield* new AppError({ message: "State home must be absolute" });
|
|
34399
|
+
return path.join(root, "rex-worktrees", "clone-root.json");
|
|
34400
|
+
});
|
|
34401
|
+
var CloneRootSchema = exports_Schema.Struct({ cloneRoot: exports_Schema.String });
|
|
34402
|
+
var rememberedCloneRoot = exports_Effect.fnUntraced(function* (stateRoot) {
|
|
34403
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34404
|
+
const path = yield* exports_Path.Path;
|
|
34405
|
+
const filename = yield* cloneRootFile(stateRoot);
|
|
34406
|
+
const raw = yield* fs.readFileString(filename).pipe(exports_Effect.catchIf((error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound", () => exports_Effect.succeed(undefined)));
|
|
34407
|
+
if (raw === undefined)
|
|
34408
|
+
return;
|
|
34409
|
+
const record2 = yield* exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(CloneRootSchema))(raw).pipe(exports_Effect.catch(() => exports_Effect.succeed(undefined)));
|
|
34410
|
+
return record2 && path.isAbsolute(record2.cloneRoot) && path.resolve(record2.cloneRoot) === record2.cloneRoot ? record2.cloneRoot : undefined;
|
|
34411
|
+
});
|
|
34412
|
+
var rememberCloneRoot = exports_Effect.fnUntraced(function* (parent, stateRoot) {
|
|
34413
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34414
|
+
const path = yield* exports_Path.Path;
|
|
34415
|
+
if (!path.isAbsolute(parent) || path.resolve(parent) !== parent)
|
|
34416
|
+
return yield* new AppError({ message: "Clone parent must be normalized and absolute" });
|
|
34417
|
+
const filename = yield* cloneRootFile(stateRoot);
|
|
34418
|
+
yield* fs.makeDirectory(path.dirname(filename), { recursive: true, mode: 448 });
|
|
34419
|
+
const temporary = `${filename}.${randomUUID()}.tmp`;
|
|
34420
|
+
yield* fs.writeFileString(temporary, JSON.stringify({ cloneRoot: parent }), { flag: "wx", mode: 384 });
|
|
34421
|
+
yield* fs.rename(temporary, filename).pipe(exports_Effect.ensuring(fs.remove(temporary, { force: true }).pipe(exports_Effect.ignore)));
|
|
34422
|
+
});
|
|
34423
|
+
var saveAssociation = exports_Effect.fnUntraced(function* (association) {
|
|
34424
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34425
|
+
const path = yield* exports_Path.Path;
|
|
34426
|
+
const root = process.env.XDG_STATE_HOME || path.join(homedir(), ".local", "state");
|
|
34427
|
+
const directory = path.join(root, "rex-worktrees", "associations");
|
|
34428
|
+
yield* fs.makeDirectory(directory, { recursive: true, mode: 448 });
|
|
34429
|
+
const id2 = randomUUID();
|
|
34430
|
+
const temporary = path.join(directory, `${id2}.tmp`);
|
|
34431
|
+
const destination = path.join(directory, `${id2}.json`);
|
|
34432
|
+
yield* fs.writeFileString(temporary, JSON.stringify(association), { flag: "wx", mode: 384 });
|
|
34433
|
+
yield* fs.rename(temporary, destination).pipe(exports_Effect.ensuring(fs.remove(temporary, { force: true }).pipe(exports_Effect.ignore)));
|
|
34434
|
+
});
|
|
34435
|
+
var associations = exports_Effect.gen(function* () {
|
|
34436
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
34437
|
+
const path = yield* exports_Path.Path;
|
|
34438
|
+
const directory = path.join(process.env.XDG_STATE_HOME || path.join(homedir(), ".local", "state"), "rex-worktrees", "associations");
|
|
34439
|
+
const result4 = [];
|
|
34440
|
+
if (!(yield* fs.exists(directory)))
|
|
34441
|
+
return result4;
|
|
34442
|
+
for (const name of yield* fs.readDirectory(directory)) {
|
|
34443
|
+
if (!name.endsWith(".json"))
|
|
34444
|
+
continue;
|
|
34445
|
+
const raw = yield* exports_Effect.catchIf(fs.readFileString(path.join(directory, name)), (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound", () => exports_Effect.succeed(undefined));
|
|
34446
|
+
if (raw === undefined)
|
|
34447
|
+
continue;
|
|
34448
|
+
const record2 = yield* exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(AssociationSchema))(raw).pipe(exports_Effect.catch(() => exports_Effect.succeed(undefined)));
|
|
34449
|
+
if (record2)
|
|
34450
|
+
result4.push(record2);
|
|
33877
34451
|
}
|
|
33878
|
-
|
|
33879
|
-
const created = (yield* listWorktrees(plan.repository.path)).find((worktree) => worktree.path === current.path);
|
|
33880
|
-
if (!created)
|
|
33881
|
-
return yield* fail16(`Git did not list created worktree ${current.path}`);
|
|
33882
|
-
return created;
|
|
34452
|
+
return result4;
|
|
33883
34453
|
});
|
|
33884
34454
|
|
|
33885
34455
|
// src/config.ts
|
|
@@ -33907,12 +34477,27 @@ var loadConfig = exports_Effect.gen(function* () {
|
|
|
33907
34477
|
};
|
|
33908
34478
|
return config;
|
|
33909
34479
|
});
|
|
34480
|
+
var resolveCloneRoot = exports_Effect.fnUntraced(function* (roots, projects, stateRoot) {
|
|
34481
|
+
const path = yield* exports_Path.Path;
|
|
34482
|
+
if (roots[0])
|
|
34483
|
+
return roots[0];
|
|
34484
|
+
const remembered = yield* rememberedCloneRoot(stateRoot);
|
|
34485
|
+
if (remembered)
|
|
34486
|
+
return remembered;
|
|
34487
|
+
const parents = new Set(projects.map((project4) => path.dirname(project4.path)));
|
|
34488
|
+
if (parents.size === 1)
|
|
34489
|
+
return [...parents][0];
|
|
34490
|
+
const home = process.env.HOME;
|
|
34491
|
+
if (!home || !path.isAbsolute(home))
|
|
34492
|
+
return yield* new AppError({ message: "Target HOME must be an absolute directory" });
|
|
34493
|
+
return home;
|
|
34494
|
+
});
|
|
33910
34495
|
var resolveWorktreeRoot = exports_Effect.fnUntraced(function* (repoPath) {
|
|
33911
34496
|
const config = yield* loadConfig;
|
|
33912
|
-
const target = yield*
|
|
34497
|
+
const target = yield* project3(repoPath);
|
|
33913
34498
|
for (const entry of config.projectRoots) {
|
|
33914
|
-
const candidate = yield* exports_Effect.catchIf(exports_Effect.catchIf(
|
|
33915
|
-
if (candidate?.commonDir === target.commonDir)
|
|
34499
|
+
const candidate = yield* exports_Effect.catchIf(exports_Effect.catchIf(repository3(entry.path), (error2) => missing3(error2), () => exports_Effect.succeed(undefined)), (error2) => notRepository(error2), () => exports_Effect.succeed(undefined));
|
|
34500
|
+
if (candidate?.vcs === target.vcs && candidate.commonDir === target.commonDir)
|
|
33916
34501
|
return entry.worktreeRoot;
|
|
33917
34502
|
}
|
|
33918
34503
|
const path = yield* exports_Path.Path;
|
|
@@ -33923,6 +34508,8 @@ var resolveWorktreeRoot = exports_Effect.fnUntraced(function* (repoPath) {
|
|
|
33923
34508
|
import { hostname } from "os";
|
|
33924
34509
|
var localName = hostname().toLowerCase().replace(/\.$/, "").replace(/\.local$/, "");
|
|
33925
34510
|
var localDirectoryUri = (raw) => {
|
|
34511
|
+
if (raw.startsWith("/"))
|
|
34512
|
+
return raw.includes("\x00") ? undefined : raw;
|
|
33926
34513
|
try {
|
|
33927
34514
|
const url = new URL(raw);
|
|
33928
34515
|
const authority = url.hostname.toLowerCase().replace(/\.$/, "").replace(/\.local$/, "");
|
|
@@ -33993,6 +34580,10 @@ var listSessions = exports_Effect.gen(function* () {
|
|
|
33993
34580
|
const result4 = yield* parse3(RexSessionsSchema, yield* rex(["ls", "--json"]));
|
|
33994
34581
|
return result4.sessions.map((session) => ({ id: session.session_id, label: session.label }));
|
|
33995
34582
|
});
|
|
34583
|
+
var createSession = exports_Effect.fnUntraced(function* (name) {
|
|
34584
|
+
const result4 = yield* parse3(RexSessionCreatedSchema, yield* rex(["api", "call", "session.create", JSON.stringify({ label: name })]));
|
|
34585
|
+
return result4.session_id;
|
|
34586
|
+
});
|
|
33996
34587
|
var listClients = exports_Effect.gen(function* () {
|
|
33997
34588
|
const result4 = yield* parse3(RexClientsSchema, yield* rex(["client", "ls", "--json"]));
|
|
33998
34589
|
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 }));
|
|
@@ -34008,9 +34599,11 @@ var originDirectory = exports_Effect.fnUntraced(function* (sessionId, blockId) {
|
|
|
34008
34599
|
return;
|
|
34009
34600
|
const raw = yield* rex(["block", "call", "-s", sessionId, "-b", blockId, "pwd"]);
|
|
34010
34601
|
const result4 = yield* parse3(RexDirectorySchema, raw);
|
|
34011
|
-
if (
|
|
34012
|
-
return;
|
|
34013
|
-
|
|
34602
|
+
if (result4.pwd)
|
|
34603
|
+
return localDirectoryUri(result4.pwd);
|
|
34604
|
+
const processInfo = yield* parse3(RexProcessSchema, yield* rex(["block", "call", "-s", sessionId, "-b", blockId, "process"]));
|
|
34605
|
+
const cwd = processInfo.foreground?.cwd;
|
|
34606
|
+
return cwd?.startsWith("/") && !cwd.includes("\x00") ? cwd : undefined;
|
|
34014
34607
|
});
|
|
34015
34608
|
var fitPopupBounds = (bounds, preferred, observed) => {
|
|
34016
34609
|
if (![...bounds, preferred.columns, preferred.rows, observed.columns, observed.rows].every(Number.isFinite) || bounds[2] <= 0 || bounds[3] <= 0 || observed.columns <= 0 || observed.rows <= 0 || preferred.columns <= 0 || preferred.rows <= 0)
|
|
@@ -34093,8 +34686,9 @@ var makePopupSizer = exports_Effect.gen(function* () {
|
|
|
34093
34686
|
}))));
|
|
34094
34687
|
return resize;
|
|
34095
34688
|
});
|
|
34689
|
+
var commandWithPath = (command) => process.env.PATH ? ["/usr/bin/env", `PATH=${process.env.PATH}`, ...command] : command;
|
|
34096
34690
|
var createTab = exports_Effect.fnUntraced(function* (sessionId, name, cwd, command) {
|
|
34097
|
-
const result4 = yield* parse3(RexCreatedSchema, yield* rex(["window", "new", "-s", sessionId, name, "-c", cwd, "--shell=none", "--keep-open", "--json", "--", ...command]));
|
|
34691
|
+
const result4 = yield* parse3(RexCreatedSchema, yield* rex(["window", "new", "-s", sessionId, name, "-c", cwd, "--shell=none", "--keep-open", "--json", "--", ...commandWithPath(command)]));
|
|
34098
34692
|
const blockId = result4.block_ids[0];
|
|
34099
34693
|
if (!blockId)
|
|
34100
34694
|
return yield* exports_Effect.fail(new AppError({ message: "Rex created a tab without a terminal block" }));
|
|
@@ -34103,7 +34697,7 @@ var createTab = exports_Effect.fnUntraced(function* (sessionId, name, cwd, comma
|
|
|
34103
34697
|
return { windowId: result4.window_id, blockId };
|
|
34104
34698
|
});
|
|
34105
34699
|
var createSplit = exports_Effect.fnUntraced(function* (sessionId, windowId, blockId, name, cwd, command) {
|
|
34106
|
-
const result4 = yield* parse3(RexCreatedSchema, yield* rex(["split", "-s", sessionId, "-b", blockId, "--split=right", "--label", name, "-c", cwd, "--shell=none", "--keep-open", "--json", "--", ...command]));
|
|
34700
|
+
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)]));
|
|
34107
34701
|
const created = result4.block_ids.find((id2) => id2 !== blockId);
|
|
34108
34702
|
if (!created)
|
|
34109
34703
|
return yield* exports_Effect.fail(new AppError({ message: "Rex created a split without a new terminal block" }));
|
|
@@ -34126,29 +34720,29 @@ var focus = exports_Effect.fnUntraced(function* (sessionId, windowId, clientId,
|
|
|
34126
34720
|
}
|
|
34127
34721
|
return warnings.length ? warnings.join("; ") : undefined;
|
|
34128
34722
|
});
|
|
34129
|
-
var openPopup = exports_Effect.fnUntraced(function* (command, sessionId,
|
|
34723
|
+
var openPopup = exports_Effect.fnUntraced(function* (command, sessionId, origin2 = {}) {
|
|
34130
34724
|
const path = yield* exports_Path.Path;
|
|
34131
34725
|
const endpoint = (yield* localIdentity).endpoint;
|
|
34132
34726
|
const program = yield* binary(path);
|
|
34133
34727
|
const localRex = (args3) => run4(program, ["-S", endpoint, "--autostart=false", ...args3], undefined, nativeEnv());
|
|
34134
34728
|
const view = yield* parse3(RexViewSchema, yield* localRex(["api", "call", "-s", sessionId, "session.view", JSON.stringify({ session_id: sessionId })]));
|
|
34135
|
-
const source =
|
|
34136
|
-
if (
|
|
34729
|
+
const source = origin2.blockId ? view.windows.find((window) => window.layers.some((layer12) => layer12.blocks.some((block) => block.block_id === origin2.blockId))) : undefined;
|
|
34730
|
+
if (origin2.blockId && !source)
|
|
34137
34731
|
return yield* exports_Effect.fail(new AppError({ message: "Source pane is no longer in the selected Rex session" }));
|
|
34138
34732
|
const windowId = source?.window_id ?? view.active_window_id;
|
|
34139
34733
|
if (!windowId || !view.windows.some((window) => window.window_id === windowId)) {
|
|
34140
34734
|
return yield* exports_Effect.fail(new AppError({ message: "No active Rex window for the popup" }));
|
|
34141
34735
|
}
|
|
34142
|
-
const sourceOwner = source?.layers.flatMap((layer12) => layer12.blocks).find((block) => block.block_id ===
|
|
34736
|
+
const sourceOwner = source?.layers.flatMap((layer12) => layer12.blocks).find((block) => block.block_id === origin2.blockId)?.owner;
|
|
34143
34737
|
const clients = (yield* parse3(RexClientsSchema, yield* localRex(["client", "ls", "--json"]))).clients.filter((client) => client.info?.kind === "app" && client.connection_state === "connected");
|
|
34144
|
-
const clientId = [sourceOwner,
|
|
34738
|
+
const clientId = [sourceOwner, origin2.clientId].find((id2) => id2 && clients.some((client) => client.client_id === id2));
|
|
34145
34739
|
const popupCommand = clientId ? [...command, "--managed-popup", "--origin-client", clientId] : [...command, "--managed-popup"];
|
|
34146
34740
|
const width2 = 0.68, height = 0.35;
|
|
34147
34741
|
const args2 = {
|
|
34148
34742
|
session_id: sessionId,
|
|
34149
34743
|
window_id: windowId,
|
|
34150
34744
|
bounds: [(1 - width2) / 2, (1 - height) / 2, width2, height],
|
|
34151
|
-
layout: { block: { flavor: "com.superlogical.terminal.shell", options: { command: popupCommand, shell: "none", cwd: process.cwd(), exit: { on_completion: true } } } },
|
|
34745
|
+
layout: { block: { flavor: "com.superlogical.terminal.shell", options: { command: commandWithPath(popupCommand), shell: "none", cwd: process.cwd(), exit: { on_completion: true } } } },
|
|
34152
34746
|
focus: true
|
|
34153
34747
|
};
|
|
34154
34748
|
const created = yield* parse3(RexLayerSchema, yield* localRex(["api", "call", "-s", sessionId, "session.new_layer", JSON.stringify(args2)]));
|
|
@@ -34173,43 +34767,11 @@ var closeManagedPopup = exports_Effect.gen(function* () {
|
|
|
34173
34767
|
yield* localRex(["block", "close", "-s", sessionId, blockId]);
|
|
34174
34768
|
});
|
|
34175
34769
|
|
|
34176
|
-
// src/state.ts
|
|
34177
|
-
import { randomUUID } from "crypto";
|
|
34178
|
-
import { homedir } from "os";
|
|
34179
|
-
var saveAssociation = exports_Effect.fnUntraced(function* (association) {
|
|
34180
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
34181
|
-
const path = yield* exports_Path.Path;
|
|
34182
|
-
const root = process.env.XDG_STATE_HOME || path.join(homedir(), ".local", "state");
|
|
34183
|
-
const directory = path.join(root, "rex-worktrees", "associations");
|
|
34184
|
-
yield* fs.makeDirectory(directory, { recursive: true, mode: 448 });
|
|
34185
|
-
const id2 = randomUUID();
|
|
34186
|
-
const temporary = path.join(directory, `${id2}.tmp`);
|
|
34187
|
-
const destination = path.join(directory, `${id2}.json`);
|
|
34188
|
-
yield* fs.writeFileString(temporary, JSON.stringify(association), { flag: "wx", mode: 384 });
|
|
34189
|
-
yield* fs.rename(temporary, destination).pipe(exports_Effect.ensuring(fs.remove(temporary, { force: true }).pipe(exports_Effect.ignore)));
|
|
34190
|
-
});
|
|
34191
|
-
var associations = exports_Effect.gen(function* () {
|
|
34192
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
34193
|
-
const path = yield* exports_Path.Path;
|
|
34194
|
-
const directory = path.join(process.env.XDG_STATE_HOME || path.join(homedir(), ".local", "state"), "rex-worktrees", "associations");
|
|
34195
|
-
const result4 = [];
|
|
34196
|
-
if (!(yield* fs.exists(directory)))
|
|
34197
|
-
return result4;
|
|
34198
|
-
for (const name of yield* fs.readDirectory(directory)) {
|
|
34199
|
-
if (!name.endsWith(".json"))
|
|
34200
|
-
continue;
|
|
34201
|
-
const raw = yield* exports_Effect.catchIf(fs.readFileString(path.join(directory, name)), (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound", () => exports_Effect.succeed(undefined));
|
|
34202
|
-
if (raw === undefined)
|
|
34203
|
-
continue;
|
|
34204
|
-
const record2 = yield* exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(AssociationSchema))(raw).pipe(exports_Effect.catch(() => exports_Effect.succeed(undefined)));
|
|
34205
|
-
if (record2)
|
|
34206
|
-
result4.push(record2);
|
|
34207
|
-
}
|
|
34208
|
-
return result4;
|
|
34209
|
-
});
|
|
34210
|
-
|
|
34211
34770
|
// src/worktrees.ts
|
|
34212
|
-
|
|
34771
|
+
import { constants as constants2 } from "fs";
|
|
34772
|
+
import { access as access3 } from "fs/promises";
|
|
34773
|
+
var fail19 = (message) => exports_Effect.fail(new AppError({ message }));
|
|
34774
|
+
var sameSession = (a, b) => a.kind === b.kind && (a.kind === "existing" && b.kind === "existing" ? a.id === b.id : a.kind === "new" && b.kind === "new" && a.name === b.name);
|
|
34213
34775
|
var canonical = exports_Effect.fnUntraced(function* (path) {
|
|
34214
34776
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
34215
34777
|
return yield* fs.realPath(path);
|
|
@@ -34241,56 +34803,87 @@ var liveBlock = exports_Effect.fnUntraced(function* (sessionId, windowId, blockI
|
|
|
34241
34803
|
const pathname = localDirectoryUri(reported.pwd);
|
|
34242
34804
|
if (!pathname)
|
|
34243
34805
|
return false;
|
|
34244
|
-
const cwd = yield* exports_Effect.catchIf(canonical(pathname), (error2) =>
|
|
34806
|
+
const cwd = yield* exports_Effect.catchIf(canonical(pathname), (error2) => missing3(error2), () => exports_Effect.succeed(""));
|
|
34245
34807
|
return cwd === path ? window.label : false;
|
|
34246
34808
|
});
|
|
34247
34809
|
var planLaunch = exports_Effect.fnUntraced(function* (input, expectedHostId) {
|
|
34248
34810
|
const host = yield* localHost;
|
|
34249
34811
|
if (expectedHostId && host.id !== expectedHostId)
|
|
34250
|
-
return yield*
|
|
34251
|
-
|
|
34252
|
-
|
|
34812
|
+
return yield* fail19(`Wrong Rex host: expected ${expectedHostId}, got ${host.id}`);
|
|
34813
|
+
yield* exports_Schema.decodeUnknownEffect(SessionSelectionSchema)(input.session);
|
|
34814
|
+
if (input.session.kind === "existing") {
|
|
34815
|
+
const sessionId = input.session.id;
|
|
34816
|
+
if (!(yield* listSessions).some((item) => item.id === sessionId))
|
|
34817
|
+
return yield* fail19(`Rex session ${sessionId} does not exist locally`);
|
|
34818
|
+
}
|
|
34253
34819
|
const clients = yield* listClients;
|
|
34254
34820
|
if (input.clientId && !clients.some((item) => item.id === input.clientId))
|
|
34255
|
-
return yield*
|
|
34821
|
+
return yield* fail19(`Rex app client ${input.clientId} is not connected locally`);
|
|
34256
34822
|
const clientId = input.clientId ?? (clients.length === 1 ? clients[0]?.id : undefined);
|
|
34257
|
-
|
|
34258
|
-
|
|
34259
|
-
|
|
34260
|
-
return yield* fail17("Worktree name only applies to a branch checkout");
|
|
34261
|
-
const repo = yield* repository(input.repo);
|
|
34262
|
-
const worktreeRoot = input.branch ? yield* resolveWorktreeRoot(repo.path) : undefined;
|
|
34823
|
+
const repo = yield* repository3(input.repo);
|
|
34824
|
+
if (repo.vcs !== input.vcs)
|
|
34825
|
+
return yield* fail19("Repository backend changed since selection");
|
|
34263
34826
|
let path;
|
|
34264
|
-
let branch;
|
|
34265
34827
|
let checkout;
|
|
34828
|
+
let branch = null;
|
|
34829
|
+
let workspaceName;
|
|
34266
34830
|
let base;
|
|
34267
|
-
|
|
34268
|
-
|
|
34269
|
-
|
|
34270
|
-
|
|
34271
|
-
|
|
34272
|
-
|
|
34273
|
-
|
|
34831
|
+
let gitBase;
|
|
34832
|
+
let worktreeRoot;
|
|
34833
|
+
let detail;
|
|
34834
|
+
if (input.vcs === "git") {
|
|
34835
|
+
if (!!input.branch === !!input.path)
|
|
34836
|
+
return yield* fail19("Select exactly one branch or existing worktree path");
|
|
34837
|
+
if (input.path && input.worktreeName !== undefined)
|
|
34838
|
+
return yield* fail19("Worktree name only applies to a branch checkout");
|
|
34839
|
+
worktreeRoot = input.branch ? yield* resolveWorktreeRoot(repo.path) : undefined;
|
|
34840
|
+
if (input.branch) {
|
|
34841
|
+
const destination = yield* planWorktree(repo.path, input.branch, worktreeRoot, input.worktreeName);
|
|
34842
|
+
path = destination.path;
|
|
34843
|
+
branch = input.branch;
|
|
34844
|
+
checkout = destination.existing ? "existing" : (yield* listBranches(repo.path)).includes(branch) ? "attach" : "create";
|
|
34845
|
+
if (checkout === "create")
|
|
34846
|
+
gitBase = yield* repositoryHead(repo.path);
|
|
34847
|
+
} else {
|
|
34848
|
+
if (!input.path)
|
|
34849
|
+
return yield* fail19("Select an existing worktree path");
|
|
34850
|
+
path = yield* canonical(input.path);
|
|
34851
|
+
const tree = (yield* listWorktrees(repo.path)).find((entry) => entry.path === path);
|
|
34852
|
+
if (!tree)
|
|
34853
|
+
return yield* fail19(`${path} is not a Git worktree of ${repo.path}`);
|
|
34854
|
+
branch = tree.branch;
|
|
34855
|
+
checkout = "existing";
|
|
34856
|
+
}
|
|
34857
|
+
detail = checkout === "existing" && !!input.branch ? `Branch ${branch} is already checked out; opening its existing worktree.` : checkout === "attach" ? `Branch ${branch} already exists; attaching a checkout, not creating the branch.` : undefined;
|
|
34274
34858
|
} else {
|
|
34275
|
-
if (!input.path)
|
|
34276
|
-
return yield*
|
|
34277
|
-
|
|
34278
|
-
|
|
34279
|
-
|
|
34280
|
-
|
|
34281
|
-
|
|
34282
|
-
|
|
34859
|
+
if (!!input.path === !!input.worktreeName || input.path && input.revision || !input.path && !input.revision)
|
|
34860
|
+
return yield* fail19("Select an existing workspace path or a new workspace name and base revision");
|
|
34861
|
+
if (input.path) {
|
|
34862
|
+
path = yield* canonical(input.path);
|
|
34863
|
+
const tree = (yield* listWorkspaces(repo.path)).find((entry) => entry.path === path && entry.present);
|
|
34864
|
+
if (!tree)
|
|
34865
|
+
return yield* fail19(`${path} is not an available JJ workspace of ${repo.path}`);
|
|
34866
|
+
workspaceName = tree.name;
|
|
34867
|
+
checkout = "existing";
|
|
34868
|
+
} else {
|
|
34869
|
+
worktreeRoot = yield* resolveWorktreeRoot(repo.path);
|
|
34870
|
+
const planned = yield* planWorkspace(repo.path, input.worktreeName, input.revision, worktreeRoot);
|
|
34871
|
+
path = planned.path;
|
|
34872
|
+
workspaceName = planned.workspaceName;
|
|
34873
|
+
base = planned.base;
|
|
34874
|
+
checkout = "create";
|
|
34875
|
+
}
|
|
34283
34876
|
}
|
|
34284
34877
|
let warning;
|
|
34285
34878
|
const records = yield* associations.pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
|
|
34286
|
-
warning = exports_Cause.pretty(exports_Cause.fail(error2));
|
|
34879
|
+
warning = [warning, exports_Cause.pretty(exports_Cause.fail(error2))].filter(Boolean).join("; ");
|
|
34287
34880
|
return [];
|
|
34288
34881
|
})));
|
|
34289
34882
|
if (!clientId && clients.length > 1)
|
|
34290
34883
|
warning = [warning, "Multiple Rex apps are connected; select the session in the intended app"].filter(Boolean).join("; ");
|
|
34291
34884
|
let target;
|
|
34292
34885
|
for (const entry of records) {
|
|
34293
|
-
if (entry.hostId !== host.id || entry.commonDir !== repo.commonDir || entry.path !== path || entry.sessionId !== input.
|
|
34886
|
+
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)
|
|
34294
34887
|
continue;
|
|
34295
34888
|
const label = yield* liveBlock(entry.sessionId, entry.windowId, entry.blockId, host.id, path);
|
|
34296
34889
|
if (label !== false) {
|
|
@@ -34300,46 +34893,61 @@ var planLaunch = exports_Effect.fnUntraced(function* (input, expectedHostId) {
|
|
|
34300
34893
|
}
|
|
34301
34894
|
const action = input.split && target ? "split" : target && !input.additional && !input.split ? "focus" : "new-tab";
|
|
34302
34895
|
const nameRole = action === "focus" ? "none" : action === "split" ? "pane" : "tab";
|
|
34303
|
-
if (nameRole !== "none" && (!input.name.trim() || input.name.startsWith("-") || /[\p{ASCII}&&\p{Cc}]/v.test(input.name)))
|
|
34304
|
-
return yield*
|
|
34305
|
-
|
|
34306
|
-
|
|
34307
|
-
|
|
34308
|
-
|
|
34896
|
+
if (nameRole !== "none" && (!input.name.trim() || input.name.startsWith("-") || /[\p{ASCII}&&\p{Cc}]/v.test(input.name)))
|
|
34897
|
+
return yield* fail19(`Invalid Rex ${nameRole} name`);
|
|
34898
|
+
if (input.split && !target)
|
|
34899
|
+
detail = "No live tab for this checkout; opening a new tab instead.";
|
|
34900
|
+
if (input.vcs === "jj" && checkout === "create")
|
|
34901
|
+
detail = [detail, `Creating a JJ workspace snapshots ${repo.path}; its working-copy commit and colocated Git index intent-to-add entries may change.`].filter(Boolean).join(" ");
|
|
34902
|
+
const common = {
|
|
34309
34903
|
hostId: host.id,
|
|
34310
|
-
sessionId: input.sessionId,
|
|
34311
34904
|
...clientId ? { clientId } : {},
|
|
34312
34905
|
path,
|
|
34313
|
-
branch,
|
|
34314
|
-
checkout,
|
|
34315
34906
|
...worktreeRoot ? { worktreeRoot } : {},
|
|
34316
|
-
...base ? { base } : {},
|
|
34317
34907
|
action,
|
|
34318
34908
|
...target ? { target } : {},
|
|
34319
34909
|
nameRole,
|
|
34320
34910
|
...nameRole !== "none" ? { name: input.name } : {},
|
|
34321
|
-
label: action === "focus" ? "Focus existing tab" : checkout === "create" ? "Create worktree & open" : checkout === "attach" ? "Attach branch & open" : action === "split" ? "Open pane" : "Open tab",
|
|
34322
34911
|
...detail ? { detail } : {},
|
|
34323
34912
|
...warning ? { warning } : {}
|
|
34324
34913
|
};
|
|
34325
|
-
|
|
34914
|
+
if (input.vcs === "git")
|
|
34915
|
+
return {
|
|
34916
|
+
...common,
|
|
34917
|
+
vcs: "git",
|
|
34918
|
+
input: { ...input, repo: repo.path, ...input.path ? { path } : {} },
|
|
34919
|
+
branch,
|
|
34920
|
+
checkout,
|
|
34921
|
+
...gitBase ? { base: gitBase } : {},
|
|
34922
|
+
label: action === "focus" ? "Focus existing tab" : checkout === "create" ? "Create worktree & open" : checkout === "attach" ? "Attach branch & open" : action === "split" ? "Open pane" : "Open tab"
|
|
34923
|
+
};
|
|
34924
|
+
return {
|
|
34925
|
+
...common,
|
|
34926
|
+
vcs: "jj",
|
|
34927
|
+
checkout: checkout === "create" ? "create" : "existing",
|
|
34928
|
+
input: { ...input, repo: repo.path, ...input.path ? { path } : {} },
|
|
34929
|
+
workspaceName,
|
|
34930
|
+
...base ? { base } : {},
|
|
34931
|
+
label: action === "focus" ? "Focus existing tab" : checkout === "create" ? "Create workspace & open" : action === "split" ? "Open pane" : "Open tab"
|
|
34932
|
+
};
|
|
34326
34933
|
});
|
|
34327
|
-
var sameLaunchPlan = (a, b) => a.
|
|
34934
|
+
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.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);
|
|
34328
34935
|
var launch = exports_Effect.fnUntraced(function* (input, command, reviewed, expectedHostId) {
|
|
34329
34936
|
const pathService = yield* exports_Path.Path;
|
|
34330
34937
|
if (!command[0] || !pathService.isAbsolute(command[0]))
|
|
34331
|
-
return yield*
|
|
34938
|
+
return yield* fail19("The task executable must be an absolute path");
|
|
34332
34939
|
const plan = yield* planLaunch(input, expectedHostId);
|
|
34333
34940
|
if (reviewed && !sameLaunchPlan(reviewed, plan))
|
|
34334
|
-
return yield*
|
|
34941
|
+
return yield* fail19("Launch plan changed since review; inspect the destination before submitting again");
|
|
34335
34942
|
if (plan.action === "focus") {
|
|
34336
34943
|
const target2 = plan.target;
|
|
34337
|
-
if (!target2)
|
|
34338
|
-
return yield*
|
|
34339
|
-
const
|
|
34944
|
+
if (!target2 || plan.input.session.kind !== "existing")
|
|
34945
|
+
return yield* fail19("The reviewed focus target is no longer available");
|
|
34946
|
+
const sessionId2 = plan.input.session.id;
|
|
34947
|
+
const warning2 = [plan.warning, yield* focus(sessionId2, target2.windowId, plan.clientId, target2.blockId)].filter(Boolean).join("; ") || undefined;
|
|
34340
34948
|
const result5 = {
|
|
34341
34949
|
hostId: plan.hostId,
|
|
34342
|
-
sessionId:
|
|
34950
|
+
sessionId: sessionId2,
|
|
34343
34951
|
windowId: target2.windowId,
|
|
34344
34952
|
blockId: target2.blockId,
|
|
34345
34953
|
path: plan.path,
|
|
@@ -34349,31 +34957,44 @@ var launch = exports_Effect.fnUntraced(function* (input, command, reviewed, expe
|
|
|
34349
34957
|
};
|
|
34350
34958
|
return result5;
|
|
34351
34959
|
}
|
|
34352
|
-
const repo = yield*
|
|
34353
|
-
|
|
34960
|
+
const repo = yield* repository3(plan.input.repo);
|
|
34961
|
+
if (repo.vcs !== plan.vcs)
|
|
34962
|
+
return yield* fail19("Repository backend changed since review");
|
|
34963
|
+
const sessionId = plan.input.session.kind === "existing" ? plan.input.session.id : yield* createSession(plan.input.session.name);
|
|
34964
|
+
const common = {
|
|
34354
34965
|
repo: repo.path,
|
|
34355
34966
|
path: plan.path,
|
|
34356
34967
|
commonDir: repo.commonDir,
|
|
34357
|
-
sessionId
|
|
34968
|
+
sessionId,
|
|
34358
34969
|
hostId: plan.hostId,
|
|
34359
34970
|
...process.env.REX_BIN_DIR ? { rexBinDir: process.env.REX_BIN_DIR } : {},
|
|
34360
34971
|
...process.env.REX_WORKTREES_LOCAL_ENDPOINT ? { rexLocalEndpoint: process.env.REX_WORKTREES_LOCAL_ENDPOINT } : {},
|
|
34972
|
+
...plan.worktreeRoot ? { worktreeRoot: plan.worktreeRoot } : {}
|
|
34973
|
+
};
|
|
34974
|
+
const request3 = plan.vcs === "git" ? {
|
|
34975
|
+
...common,
|
|
34976
|
+
vcs: "git",
|
|
34361
34977
|
...plan.input.branch ? { branch: plan.input.branch } : {},
|
|
34362
34978
|
...plan.input.worktreeName !== undefined ? { worktreeName: plan.input.worktreeName } : {},
|
|
34363
34979
|
...plan.base ? { base: plan.base.head } : {},
|
|
34364
|
-
...plan.worktreeRoot ? { worktreeRoot: plan.worktreeRoot } : {},
|
|
34365
34980
|
...plan.checkout !== "create" ? { checkout: plan.checkout } : {}
|
|
34981
|
+
} : {
|
|
34982
|
+
...common,
|
|
34983
|
+
vcs: "jj",
|
|
34984
|
+
checkout: plan.checkout,
|
|
34985
|
+
workspaceName: plan.workspaceName,
|
|
34986
|
+
...plan.base ? { base: plan.base } : {}
|
|
34366
34987
|
};
|
|
34367
34988
|
const argv = [...command, "task", JSON.stringify(request3)];
|
|
34368
34989
|
const target = plan.target;
|
|
34369
34990
|
const name = plan.name;
|
|
34370
34991
|
if (!name)
|
|
34371
|
-
return yield*
|
|
34372
|
-
const created = plan.action === "split" ? target ? yield* createSplit(
|
|
34373
|
-
const warning = [plan.warning, yield* focus(
|
|
34992
|
+
return yield* fail19("The reviewed Rex tab name is no longer available");
|
|
34993
|
+
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);
|
|
34994
|
+
const warning = [plan.warning, yield* focus(sessionId, created.windowId, plan.clientId, created.blockId)].filter(Boolean).join("; ") || undefined;
|
|
34374
34995
|
const result4 = {
|
|
34375
34996
|
hostId: plan.hostId,
|
|
34376
|
-
sessionId
|
|
34997
|
+
sessionId,
|
|
34377
34998
|
windowId: created.windowId,
|
|
34378
34999
|
blockId: created.blockId,
|
|
34379
35000
|
path: plan.path,
|
|
@@ -34387,7 +35008,7 @@ var shell = exports_Effect.fnUntraced(function* (cwd) {
|
|
|
34387
35008
|
const path = yield* exports_Path.Path;
|
|
34388
35009
|
const program = process.env.SHELL || "/bin/sh";
|
|
34389
35010
|
if (!path.isAbsolute(program))
|
|
34390
|
-
return yield*
|
|
35011
|
+
return yield* fail19("SHELL must be an absolute executable path");
|
|
34391
35012
|
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
34392
35013
|
const child = yield* spawner.spawn(exports_ChildProcess.make(program, path.basename(program) === "sh" ? ["-i"] : ["-l", "-i"], {
|
|
34393
35014
|
cwd,
|
|
@@ -34397,35 +35018,54 @@ var shell = exports_Effect.fnUntraced(function* (cwd) {
|
|
|
34397
35018
|
}));
|
|
34398
35019
|
const code = yield* child.exitCode;
|
|
34399
35020
|
if (code !== 0)
|
|
34400
|
-
return yield*
|
|
35021
|
+
return yield* fail19(`Shell exited with status ${code}`);
|
|
34401
35022
|
}, exports_Effect.scoped);
|
|
34402
35023
|
var task = exports_Effect.fnUntraced(function* (request3) {
|
|
34403
35024
|
if (request3.rexBinDir) {
|
|
34404
35025
|
const path2 = yield* exports_Path.Path;
|
|
34405
35026
|
if (!path2.isAbsolute(request3.rexBinDir))
|
|
34406
|
-
return yield*
|
|
35027
|
+
return yield* fail19("REX_BIN_DIR must be an absolute directory");
|
|
34407
35028
|
process.env.REX_BIN_DIR = request3.rexBinDir;
|
|
34408
35029
|
}
|
|
34409
35030
|
if (request3.rexLocalEndpoint)
|
|
34410
35031
|
process.env.REX_WORKTREES_LOCAL_ENDPOINT = request3.rexLocalEndpoint;
|
|
34411
35032
|
const host = yield* localHost;
|
|
34412
35033
|
if (host.id !== request3.hostId)
|
|
34413
|
-
return yield*
|
|
34414
|
-
if (!request3.branch && request3.worktreeName !== undefined)
|
|
34415
|
-
return yield*
|
|
35034
|
+
return yield* fail19(`Wrong Rex task host: expected ${request3.hostId}, got ${host.id}`);
|
|
35035
|
+
if (request3.vcs === "git" && !request3.branch && request3.worktreeName !== undefined)
|
|
35036
|
+
return yield* fail19("Worktree name only applies to a branch checkout");
|
|
34416
35037
|
if (process.env.REX_SESSION !== request3.sessionId || !process.env.REX_BLOCK)
|
|
34417
|
-
return yield*
|
|
35038
|
+
return yield* fail19("Task must run in its requested Rex session and terminal");
|
|
34418
35039
|
const blockId = yield* exports_Schema.decodeUnknownEffect(BlockIdSchema)(process.env.REX_BLOCK);
|
|
34419
35040
|
if (!(yield* listSessions).some((item) => item.id === request3.sessionId))
|
|
34420
|
-
return yield*
|
|
34421
|
-
const current = yield*
|
|
34422
|
-
if (current.commonDir !== request3.commonDir || current.path !== request3.repo)
|
|
34423
|
-
return yield*
|
|
35041
|
+
return yield* fail19("Requested Rex session no longer exists");
|
|
35042
|
+
const current = yield* repository3(request3.repo);
|
|
35043
|
+
if (current.vcs !== request3.vcs || current.commonDir !== request3.commonDir || current.path !== request3.repo)
|
|
35044
|
+
return yield* fail19("Repository identity changed since launch");
|
|
34424
35045
|
let path;
|
|
34425
|
-
if (request3.
|
|
35046
|
+
if (request3.vcs === "jj") {
|
|
35047
|
+
if (request3.checkout === "create") {
|
|
35048
|
+
if (!request3.base)
|
|
35049
|
+
return yield* fail19("New JJ workspace requires a pinned base revision");
|
|
35050
|
+
const planned = yield* planWorkspace(request3.repo, request3.workspaceName, request3.base.commitId, request3.worktreeRoot);
|
|
35051
|
+
if (planned.path !== request3.path || planned.workspaceName !== request3.workspaceName || planned.base.commitId !== request3.base.commitId || planned.base.changeId !== request3.base.changeId)
|
|
35052
|
+
return yield* fail19("JJ workspace destination or pinned base changed since launch");
|
|
35053
|
+
const created = yield* createWorkspace(request3.repo, request3.workspaceName, request3.base, request3.worktreeRoot);
|
|
35054
|
+
if (!created.path || !created.present)
|
|
35055
|
+
return yield* fail19(`JJ workspace registration has no available checkout; inspect ${request3.path}`);
|
|
35056
|
+
path = yield* canonical(created.path);
|
|
35057
|
+
} else {
|
|
35058
|
+
if (request3.base)
|
|
35059
|
+
return yield* fail19("Existing JJ workspace cannot change its base revision");
|
|
35060
|
+
path = yield* canonical(request3.path);
|
|
35061
|
+
const tree = (yield* listWorkspaces(request3.repo)).find((entry2) => entry2.path === path && entry2.name === request3.workspaceName && entry2.present);
|
|
35062
|
+
if (!tree)
|
|
35063
|
+
return yield* fail19("Selected JJ workspace no longer belongs to repository");
|
|
35064
|
+
}
|
|
35065
|
+
} else if (request3.branch) {
|
|
34426
35066
|
const plan = yield* planWorktree(request3.repo, request3.branch, request3.worktreeRoot, request3.worktreeName);
|
|
34427
35067
|
if (plan.path !== request3.path || request3.checkout === "existing" && !plan.existing)
|
|
34428
|
-
return yield*
|
|
35068
|
+
return yield* fail19("Worktree destination changed since launch");
|
|
34429
35069
|
if (request3.checkout === "existing") {
|
|
34430
35070
|
path = yield* canonical(request3.path);
|
|
34431
35071
|
} else {
|
|
@@ -34441,23 +35081,277 @@ var task = exports_Effect.fnUntraced(function* (request3) {
|
|
|
34441
35081
|
path = yield* canonical(request3.path);
|
|
34442
35082
|
const trees = yield* listWorktrees(request3.repo);
|
|
34443
35083
|
if (!trees.some((tree) => tree.path === path))
|
|
34444
|
-
return yield*
|
|
35084
|
+
return yield* fail19("Selected worktree no longer belongs to repository");
|
|
34445
35085
|
}
|
|
34446
35086
|
if (path !== request3.path)
|
|
34447
|
-
return yield*
|
|
35087
|
+
return yield* fail19(`Worktree path changed; checkout remains at ${path}`);
|
|
34448
35088
|
const windows = yield* windowList(request3.sessionId).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
|
|
34449
35089
|
console.error(`Worktree ${path} is available; cannot inspect Rex terminal for association: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
|
|
34450
35090
|
return [];
|
|
34451
35091
|
})));
|
|
34452
35092
|
const entry = windows.find((window) => window.layers.some((layer12) => layer12.blocks?.some((block) => block.block_id === blockId && block.host_id === host.id)));
|
|
34453
35093
|
if (entry) {
|
|
34454
|
-
yield* saveAssociation({ hostId: host.id, commonDir: current.commonDir, path, sessionId: request3.sessionId, windowId: entry.window_id, blockId }).pipe(exports_Effect.catch((error2) => exports_Effect.sync(() => {
|
|
35094
|
+
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(() => {
|
|
34455
35095
|
console.error(`Worktree ${path} is available; association not saved: ${exports_Cause.pretty(exports_Cause.fail(error2))}`);
|
|
34456
35096
|
})));
|
|
34457
35097
|
} else
|
|
34458
35098
|
console.error(`Worktree ${path} is available; Rex block could not be associated, select this worktree by path next time.`);
|
|
34459
35099
|
yield* shell(path);
|
|
34460
35100
|
});
|
|
35101
|
+
var cloneDestination = exports_Effect.fnUntraced(function* (destination, url, vcs = "git", sourceHostId) {
|
|
35102
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
35103
|
+
const path = yield* exports_Path.Path;
|
|
35104
|
+
if (!path.isAbsolute(destination) || path.resolve(destination) !== destination || destination === path.parse(destination).root)
|
|
35105
|
+
return yield* fail19("Clone destination must be a normalized absolute directory");
|
|
35106
|
+
const parts2 = destination.slice(path.parse(destination).root.length).split(path.sep);
|
|
35107
|
+
let current = path.parse(destination).root;
|
|
35108
|
+
for (let index2 = 0;index2 < parts2.length; index2++) {
|
|
35109
|
+
const parent = current;
|
|
35110
|
+
current = path.join(current, parts2[index2]);
|
|
35111
|
+
const info2 = yield* exports_Effect.catchIf(fs.lstat(current), missing3, () => exports_Effect.succeed(undefined));
|
|
35112
|
+
if (info2?.type === "SymbolicLink")
|
|
35113
|
+
return yield* fail19(`Symlinked clone destination: ${current}`);
|
|
35114
|
+
if (index2 < parts2.length - 1 && info2 && info2.type !== "Directory")
|
|
35115
|
+
return yield* fail19(`Not a directory: ${current}`);
|
|
35116
|
+
if (index2 < parts2.length - 1 && info2 && ((yield* gitContext(current)) || (yield* fs.exists(path.join(current, ".jj")))))
|
|
35117
|
+
return yield* fail19(vcs === "git" ? `Clone destination is inside a checkout or Git metadata: ${current}` : `Clone destination is inside a checkout or VCS metadata: ${current}`);
|
|
35118
|
+
if (index2 === parts2.length - 1 && info2) {
|
|
35119
|
+
if (info2.type !== "Directory")
|
|
35120
|
+
return yield* fail19(`Clone destination already exists: ${current}`);
|
|
35121
|
+
const repo = yield* repository3(current).pipe(exports_Effect.catchIf((error2) => missing3(error2) || exports_Schema.is(CommandError)(error2) && error2.args.includes("rev-parse"), () => fail19(`Clone destination already exists and is not a repository: ${current}`)));
|
|
35122
|
+
if (repo.path !== current || repo.vcs !== vcs)
|
|
35123
|
+
return yield* fail19(`Clone destination is not the requested ${vcs} repository: ${current}`);
|
|
35124
|
+
const actual = repo.vcs === "git" ? yield* origin(current, true) : (yield* cloneSource2(current, sourceHostId ?? (yield* localHost).id)).url;
|
|
35125
|
+
if (actual !== url)
|
|
35126
|
+
return yield* fail19(`Clone destination belongs to a different origin: ${current}`);
|
|
35127
|
+
return repo.commonDir;
|
|
35128
|
+
}
|
|
35129
|
+
if (parent === current)
|
|
35130
|
+
return yield* fail19("Invalid clone destination");
|
|
35131
|
+
}
|
|
35132
|
+
return;
|
|
35133
|
+
});
|
|
35134
|
+
var checkCloneParent = exports_Effect.fnUntraced(function* (destination) {
|
|
35135
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
35136
|
+
const path = yield* exports_Path.Path;
|
|
35137
|
+
let ancestor = path.dirname(destination);
|
|
35138
|
+
while (!(yield* fs.lstat(ancestor).pipe(exports_Effect.map(() => true), exports_Effect.catchIf(missing3, () => exports_Effect.succeed(false)))))
|
|
35139
|
+
ancestor = path.dirname(ancestor);
|
|
35140
|
+
yield* exports_Effect.tryPromise({
|
|
35141
|
+
try: () => access3(ancestor, constants2.W_OK | constants2.X_OK),
|
|
35142
|
+
catch: (cause) => new AppError({ message: `Cannot create clone destination ${destination}: ${ancestor} is not writable; choose another destination or fix its permissions`, cause })
|
|
35143
|
+
});
|
|
35144
|
+
});
|
|
35145
|
+
var planClone = exports_Effect.fnUntraced(function* (input, expectedHostId) {
|
|
35146
|
+
const host = yield* localHost;
|
|
35147
|
+
if (expectedHostId && host.id !== expectedHostId)
|
|
35148
|
+
return yield* fail19("Wrong Rex clone host");
|
|
35149
|
+
if (input.vcs !== input.source.vcs)
|
|
35150
|
+
return yield* fail19("Clone source backend does not match request");
|
|
35151
|
+
yield* exports_Schema.decodeUnknownEffect(SessionSelectionSchema)(input.session);
|
|
35152
|
+
if (input.session.kind === "existing") {
|
|
35153
|
+
const sessionId = input.session.id;
|
|
35154
|
+
if (!(yield* listSessions).some((item) => item.id === sessionId))
|
|
35155
|
+
return yield* fail19("Requested Rex session does not exist");
|
|
35156
|
+
}
|
|
35157
|
+
const clients = yield* listClients;
|
|
35158
|
+
if (input.clientId && !clients.some((item) => item.id === input.clientId))
|
|
35159
|
+
return yield* fail19("Requested Rex app client is not connected");
|
|
35160
|
+
if (!input.name.trim() || input.name.startsWith("-") || /[\p{ASCII}&&\p{Cc}]/v.test(input.name))
|
|
35161
|
+
return yield* fail19("Invalid Rex tab name");
|
|
35162
|
+
if (input.vcs === "git")
|
|
35163
|
+
yield* validCloneBranch(input.branch, input.worktreeName);
|
|
35164
|
+
else if (input.worktreeName !== undefined && !input.worktreeName.trim())
|
|
35165
|
+
return yield* fail19("JJ workspace name cannot be blank");
|
|
35166
|
+
const url = yield* exports_Effect.try({
|
|
35167
|
+
try: () => safeOrigin(input.source.url, input.source.sourceHostId === host.id),
|
|
35168
|
+
catch: () => new AppError({ message: "Clone source URL is unsafe or local to another Rex host" })
|
|
35169
|
+
});
|
|
35170
|
+
const commonDir = yield* cloneDestination(input.repo, url, input.vcs, host.id);
|
|
35171
|
+
if (commonDir === undefined)
|
|
35172
|
+
yield* checkCloneParent(input.repo);
|
|
35173
|
+
const existing = commonDir !== undefined;
|
|
35174
|
+
let gitBase;
|
|
35175
|
+
let base;
|
|
35176
|
+
if (input.vcs === "git") {
|
|
35177
|
+
gitBase = existing && input.branchMode === "create" ? yield* originDefaultHead(input.repo) : undefined;
|
|
35178
|
+
} else if (input.revision !== undefined) {
|
|
35179
|
+
if (!/^[0-9a-f]{40,64}$/.test(input.revision))
|
|
35180
|
+
return yield* fail19("Clone base must be a full source-resolved commit ID");
|
|
35181
|
+
base = [input.source.revision, ...input.source.revisions.map((choice) => choice.revision)].find((candidate) => candidate?.commitId === input.revision);
|
|
35182
|
+
if (!base)
|
|
35183
|
+
return yield* fail19("Clone base must be resolved on the source host before transfer");
|
|
35184
|
+
if (existing) {
|
|
35185
|
+
const reached = yield* resolveRevision(input.repo, base.commitId);
|
|
35186
|
+
if (reached.commitId !== base.commitId || reached.changeId !== base.changeId)
|
|
35187
|
+
return yield* fail19("Selected source revision is not available at the destination");
|
|
35188
|
+
}
|
|
35189
|
+
}
|
|
35190
|
+
if (input.vcs === "jj" && existing && !base)
|
|
35191
|
+
base = yield* resolveRevision(input.repo, "@-");
|
|
35192
|
+
const clientId = input.clientId ?? (clients.length === 1 ? clients[0]?.id : undefined);
|
|
35193
|
+
const warning = !clientId && clients.length > 1 ? "Multiple Rex apps are connected; select the intended app" : undefined;
|
|
35194
|
+
const snapshotDetail = input.vcs === "jj" && (input.worktreeName || existing) ? `JJ ${input.worktreeName ? "workspace creation" : "new change"} snapshots the destination workspace at ${input.repo}; its working-copy commit and colocated Git index intent-to-add entries may change.` : undefined;
|
|
35195
|
+
const common = {
|
|
35196
|
+
hostId: host.id,
|
|
35197
|
+
...clientId ? { clientId } : {},
|
|
35198
|
+
repo: input.repo,
|
|
35199
|
+
existing,
|
|
35200
|
+
...commonDir ? { commonDir } : {},
|
|
35201
|
+
label: existing ? "Open existing repository" : "Clone & Open",
|
|
35202
|
+
detail: [`Source ${url} \u2192 ${input.repo}. Only pushed history transfers; credentials stay on this machine.`, snapshotDetail].filter(Boolean).join(" "),
|
|
35203
|
+
...warning ? { warning } : {}
|
|
35204
|
+
};
|
|
35205
|
+
if (input.vcs === "git")
|
|
35206
|
+
return {
|
|
35207
|
+
...common,
|
|
35208
|
+
vcs: "git",
|
|
35209
|
+
input: { ...input, source: { ...input.source, url } },
|
|
35210
|
+
...gitBase ? { base: gitBase } : {}
|
|
35211
|
+
};
|
|
35212
|
+
return {
|
|
35213
|
+
...common,
|
|
35214
|
+
vcs: "jj",
|
|
35215
|
+
input: { ...input, source: { ...input.source, url } },
|
|
35216
|
+
...base ? { base } : {}
|
|
35217
|
+
};
|
|
35218
|
+
});
|
|
35219
|
+
var sameClonePlan = (a, b) => a.vcs === b.vcs && a.input.vcs === b.input.vcs && a.hostId === b.hostId && a.clientId === b.clientId && a.repo === b.repo && a.existing === b.existing && a.commonDir === b.commonDir && a.input.repo === b.input.repo && sameSession(a.input.session, b.input.session) && a.input.clientId === b.input.clientId && a.input.name === b.input.name && a.input.worktreeName === b.input.worktreeName && a.input.source.url === b.input.source.url && a.input.source.sourceHostId === b.input.source.sourceHostId && (a.vcs === "git" && b.vcs === "git" && a.input.vcs === "git" && b.input.vcs === "git" ? a.base === b.base && a.input.branch === b.input.branch && a.input.branchMode === b.input.branchMode && a.input.source.branch === b.input.source.branch && a.input.source.branches.length === b.input.source.branches.length && a.input.source.branches.every((branch, index2) => branch === b.input.source.branches[index2]) : a.vcs === "jj" && b.vcs === "jj" && a.input.vcs === "jj" && b.input.vcs === "jj" && a.base?.commitId === b.base?.commitId && a.base?.changeId === b.base?.changeId && a.input.revision === b.input.revision && a.input.source.revision?.commitId === b.input.source.revision?.commitId && a.input.source.revision?.changeId === b.input.source.revision?.changeId && a.input.source.revisions.length === b.input.source.revisions.length && a.input.source.revisions.every((choice, index2) => choice.expression === b.input.source.revisions[index2]?.expression && choice.revision.commitId === b.input.source.revisions[index2]?.revision.commitId && choice.revision.changeId === b.input.source.revisions[index2]?.revision.changeId));
|
|
35220
|
+
var launchClone = exports_Effect.fnUntraced(function* (input, command, reviewed, expectedHostId) {
|
|
35221
|
+
const path = yield* exports_Path.Path;
|
|
35222
|
+
if (!command[0] || !path.isAbsolute(command[0]))
|
|
35223
|
+
return yield* fail19("The task executable must be an absolute path");
|
|
35224
|
+
const plan = yield* planClone(input, expectedHostId);
|
|
35225
|
+
if (reviewed && !sameClonePlan(reviewed, plan))
|
|
35226
|
+
return yield* fail19("Clone plan changed since review; inspect before submitting again");
|
|
35227
|
+
const home = process.env.HOME;
|
|
35228
|
+
if (!home || !path.isAbsolute(home))
|
|
35229
|
+
return yield* fail19("Target HOME must be an absolute directory");
|
|
35230
|
+
const request3 = {
|
|
35231
|
+
plan,
|
|
35232
|
+
sessionId: plan.input.session.kind === "existing" ? plan.input.session.id : yield* createSession(plan.input.session.name),
|
|
35233
|
+
...process.env.REX_BIN_DIR ? { rexBinDir: process.env.REX_BIN_DIR } : {},
|
|
35234
|
+
...process.env.REX_WORKTREES_LOCAL_ENDPOINT ? { rexLocalEndpoint: process.env.REX_WORKTREES_LOCAL_ENDPOINT } : {}
|
|
35235
|
+
};
|
|
35236
|
+
const created = yield* createTab(request3.sessionId, input.name, home, [...command, "clone-task", JSON.stringify(request3)]);
|
|
35237
|
+
const warning = [plan.warning, yield* focus(request3.sessionId, created.windowId, plan.clientId, created.blockId)].filter(Boolean).join("; ") || undefined;
|
|
35238
|
+
const result4 = { hostId: plan.hostId, sessionId: request3.sessionId, windowId: created.windowId, blockId: created.blockId, repo: plan.repo, pending: true, ...warning ? { warning } : {} };
|
|
35239
|
+
return result4;
|
|
35240
|
+
});
|
|
35241
|
+
var prepareCloneCheckout = exports_Effect.fnUntraced(function* (plan) {
|
|
35242
|
+
if (plan.vcs === "git")
|
|
35243
|
+
yield* validCloneBranch(plan.input.branch, plan.input.worktreeName);
|
|
35244
|
+
const url = yield* exports_Effect.try({
|
|
35245
|
+
try: () => safeOrigin(plan.input.source.url, plan.input.source.sourceHostId === plan.hostId),
|
|
35246
|
+
catch: () => new AppError({ message: "Clone source URL is unsafe or local to another Rex host" })
|
|
35247
|
+
});
|
|
35248
|
+
if (url !== plan.input.source.url || plan.input.vcs !== plan.vcs)
|
|
35249
|
+
return yield* fail19("Clone source changed since review");
|
|
35250
|
+
const observed = yield* cloneDestination(plan.repo, url, plan.vcs, plan.hostId);
|
|
35251
|
+
if (observed !== plan.commonDir || observed !== undefined !== plan.existing)
|
|
35252
|
+
return yield* fail19("Clone destination identity changed since review");
|
|
35253
|
+
if (plan.vcs === "git" && plan.existing && plan.input.branchMode === "create" && (!plan.base || plan.base !== (yield* originDefaultHead(plan.repo))))
|
|
35254
|
+
return yield* fail19("Origin default branch changed since review");
|
|
35255
|
+
if (plan.vcs === "jj" && plan.existing && plan.base) {
|
|
35256
|
+
const reached = yield* resolveRevision(plan.repo, plan.base.commitId);
|
|
35257
|
+
if (reached.commitId !== plan.base.commitId || reached.changeId !== plan.base.changeId)
|
|
35258
|
+
return yield* fail19("JJ clone base changed since review");
|
|
35259
|
+
}
|
|
35260
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
35261
|
+
const pathService = yield* exports_Path.Path;
|
|
35262
|
+
if (!plan.existing) {
|
|
35263
|
+
const parent = pathService.dirname(plan.repo);
|
|
35264
|
+
yield* fs.makeDirectory(parent, { recursive: true });
|
|
35265
|
+
if ((yield* cloneDestination(plan.repo, url, plan.vcs, plan.hostId)) !== undefined)
|
|
35266
|
+
return yield* fail19("Clone target appeared since launch; destination left untouched");
|
|
35267
|
+
if ((yield* fs.realPath(parent)) !== parent)
|
|
35268
|
+
return yield* fail19("Clone parent changed to a symlink");
|
|
35269
|
+
yield* fs.makeDirectory(plan.repo);
|
|
35270
|
+
if ((yield* fs.realPath(parent)) !== parent || (yield* fs.realPath(plan.repo)) !== plan.repo)
|
|
35271
|
+
return yield* fail19(`Clone path changed; reserved destination retained at ${plan.repo}`);
|
|
35272
|
+
if (plan.vcs === "git")
|
|
35273
|
+
yield* cloneRepository(url, plan.repo);
|
|
35274
|
+
else
|
|
35275
|
+
yield* cloneRepository2(url, plan.repo);
|
|
35276
|
+
}
|
|
35277
|
+
const repo = yield* repository3(plan.repo);
|
|
35278
|
+
if (repo.path !== plan.repo || repo.vcs !== plan.vcs || plan.existing && repo.commonDir !== plan.commonDir)
|
|
35279
|
+
return yield* fail19(`Clone repository changed; retained at ${plan.repo}`);
|
|
35280
|
+
const actual = repo.vcs === "git" ? yield* origin(repo.path, true) : (yield* cloneSource2(repo.path, plan.hostId)).url;
|
|
35281
|
+
if (actual !== url)
|
|
35282
|
+
return yield* fail19(`Clone origin changed; retained at ${plan.repo}`);
|
|
35283
|
+
if (plan.vcs === "jj") {
|
|
35284
|
+
const base = plan.base ?? (yield* resolveRevision(repo.path, "@-"));
|
|
35285
|
+
let cwd2;
|
|
35286
|
+
if (plan.input.worktreeName) {
|
|
35287
|
+
const planned = yield* planWorkspace(repo.path, plan.input.worktreeName, base.commitId, yield* resolveWorktreeRoot(repo.path));
|
|
35288
|
+
if (planned.base.commitId !== base.commitId || planned.base.changeId !== base.changeId)
|
|
35289
|
+
return yield* fail19(`JJ clone base is unavailable; clone retained at ${plan.repo}`);
|
|
35290
|
+
const created = yield* createWorkspace(repo.path, planned.workspaceName, base, yield* resolveWorktreeRoot(repo.path));
|
|
35291
|
+
if (!created.path || !created.present || created.path !== planned.path)
|
|
35292
|
+
return yield* fail19(`JJ workspace registration changed; clone retained at ${plan.repo}`);
|
|
35293
|
+
cwd2 = created.path;
|
|
35294
|
+
} else if (plan.existing || plan.input.revision) {
|
|
35295
|
+
const created = yield* newChange(repo.path, base);
|
|
35296
|
+
if (!created.path || !created.present || created.path !== repo.path)
|
|
35297
|
+
return yield* fail19(`JJ default workspace changed; clone retained at ${plan.repo}`);
|
|
35298
|
+
cwd2 = created.path;
|
|
35299
|
+
} else {
|
|
35300
|
+
cwd2 = repo.path;
|
|
35301
|
+
}
|
|
35302
|
+
return { repo, cwd: yield* fs.realPath(cwd2) };
|
|
35303
|
+
}
|
|
35304
|
+
const local = yield* listBranches(repo.path);
|
|
35305
|
+
const remote = yield* remoteBranches(repo.path);
|
|
35306
|
+
const { branch, branchMode } = plan.input;
|
|
35307
|
+
let cwd;
|
|
35308
|
+
if (branchMode === "existing") {
|
|
35309
|
+
if (!local.includes(branch) && !remote.includes(branch))
|
|
35310
|
+
return yield* fail19(`Branch ${branch} was not pushed to origin; clone retained at ${plan.repo}`);
|
|
35311
|
+
const worktreeRoot = yield* resolveWorktreeRoot(repo.path);
|
|
35312
|
+
if (local.includes(branch)) {
|
|
35313
|
+
const planned = yield* planWorktree(repo.path, branch, worktreeRoot, plan.input.worktreeName);
|
|
35314
|
+
cwd = planned.existing ? planned.path : (yield* createWorktree(repo.path, branch, { attachOnly: true, worktreeRoot, worktreeName: plan.input.worktreeName })).path;
|
|
35315
|
+
} else {
|
|
35316
|
+
cwd = (yield* createWorktree(repo.path, branch, { startPoint: yield* remoteBranchHead(repo.path, branch), worktreeRoot, worktreeName: plan.input.worktreeName })).path;
|
|
35317
|
+
}
|
|
35318
|
+
} else {
|
|
35319
|
+
if (local.includes(branch) || remote.includes(branch))
|
|
35320
|
+
return yield* fail19(`Branch ${branch} already exists; clone retained at ${plan.repo}`);
|
|
35321
|
+
const base = plan.existing ? plan.base : (yield* repositoryHead(repo.path)).head;
|
|
35322
|
+
if (!base)
|
|
35323
|
+
return yield* fail19("Origin default branch changed since review");
|
|
35324
|
+
cwd = (yield* createWorktree(repo.path, branch, { startPoint: base, worktreeRoot: yield* resolveWorktreeRoot(repo.path), worktreeName: plan.input.worktreeName })).path;
|
|
35325
|
+
}
|
|
35326
|
+
return { repo, cwd: yield* fs.realPath(cwd) };
|
|
35327
|
+
});
|
|
35328
|
+
var cloneTask = exports_Effect.fnUntraced(function* (request3) {
|
|
35329
|
+
if (request3.rexBinDir) {
|
|
35330
|
+
const path = yield* exports_Path.Path;
|
|
35331
|
+
if (!path.isAbsolute(request3.rexBinDir))
|
|
35332
|
+
return yield* fail19("REX_BIN_DIR must be absolute");
|
|
35333
|
+
process.env.REX_BIN_DIR = request3.rexBinDir;
|
|
35334
|
+
}
|
|
35335
|
+
if (request3.rexLocalEndpoint)
|
|
35336
|
+
process.env.REX_WORKTREES_LOCAL_ENDPOINT = request3.rexLocalEndpoint;
|
|
35337
|
+
const { plan } = request3;
|
|
35338
|
+
if (process.env.REX_SESSION !== request3.sessionId || !process.env.REX_BLOCK)
|
|
35339
|
+
return yield* fail19("Clone task must run in its requested Rex terminal");
|
|
35340
|
+
const blockId = yield* exports_Schema.decodeUnknownEffect(BlockIdSchema)(process.env.REX_BLOCK);
|
|
35341
|
+
if (!(yield* listSessions).some((item) => item.id === request3.sessionId))
|
|
35342
|
+
return yield* fail19("Requested Rex session no longer exists");
|
|
35343
|
+
if (!sameClonePlan(plan, yield* planClone(plan.input, plan.hostId)))
|
|
35344
|
+
return yield* fail19("Clone target changed since launch; destination left untouched");
|
|
35345
|
+
const { repo, cwd } = yield* prepareCloneCheckout(plan);
|
|
35346
|
+
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))}`))));
|
|
35347
|
+
const windows = yield* windowList(request3.sessionId).pipe(exports_Effect.catch(() => exports_Effect.succeed([])));
|
|
35348
|
+
const window = windows.find((entry) => entry.layers.some((layer12) => layer12.blocks?.some((block) => block.block_id === blockId && block.host_id === plan.hostId)));
|
|
35349
|
+
if (window)
|
|
35350
|
+
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))}`))));
|
|
35351
|
+
else
|
|
35352
|
+
console.error(`Checkout ${cwd} is available; Rex block could not be associated`);
|
|
35353
|
+
yield* shell(cwd);
|
|
35354
|
+
});
|
|
34461
35355
|
|
|
34462
35356
|
// src/host.ts
|
|
34463
35357
|
var dispatchHost = exports_Effect.fnUntraced(function* (request3, command) {
|
|
@@ -34465,41 +35359,90 @@ var dispatchHost = exports_Effect.fnUntraced(function* (request3, command) {
|
|
|
34465
35359
|
if (host.id !== request3.hostId)
|
|
34466
35360
|
return yield* exports_Effect.fail(new AppError({ message: `Wrong Rex host: expected ${request3.hostId}, got ${host.id}` }));
|
|
34467
35361
|
const path = yield* exports_Path.Path;
|
|
34468
|
-
const paths = request3.kind === "discover" ? request3.context ? [request3.context] : [] : request3.kind === "project" ? [request3.path] : request3.kind === "plan" || request3.kind === "launch" ? [request3.input.repo, ...request3.input.path ? [request3.input.path] : []] : [request3.repo];
|
|
35362
|
+
const paths = 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];
|
|
34469
35363
|
if (paths.some((value3) => !path.isAbsolute(value3)))
|
|
34470
35364
|
return yield* exports_Effect.fail(new AppError({ message: "Destination repository and worktree paths must be absolute" }));
|
|
34471
|
-
const identity3 = { version:
|
|
35365
|
+
const identity3 = { version: 4, hostId: host.id };
|
|
34472
35366
|
let result4;
|
|
34473
35367
|
switch (request3.kind) {
|
|
34474
35368
|
case "discover": {
|
|
34475
35369
|
const config = yield* loadConfig;
|
|
34476
|
-
const checkoutEffect = request3.context ? exports_Effect.catchIf(exports_Effect.catchIf(
|
|
35370
|
+
const checkoutEffect = request3.context ? exports_Effect.catchIf(exports_Effect.catchIf(repository3(request3.context), (error2) => missing3(error2), () => exports_Effect.succeed(undefined)), (error2) => notRepository(error2), () => exports_Effect.succeed(undefined)) : exports_Effect.succeed(undefined);
|
|
34477
35371
|
const { checkout, sessions, clients, projects } = yield* exports_Effect.all({
|
|
34478
35372
|
checkout: checkoutEffect,
|
|
34479
35373
|
sessions: listSessions,
|
|
34480
35374
|
clients: listClients,
|
|
34481
35375
|
projects: discoverProjects(config.roots, config.projects, request3.context)
|
|
34482
35376
|
}, { concurrency: 4 });
|
|
34483
|
-
result4 = {
|
|
35377
|
+
result4 = {
|
|
35378
|
+
...identity3,
|
|
35379
|
+
kind: "discover",
|
|
35380
|
+
sessions,
|
|
35381
|
+
clients,
|
|
35382
|
+
projects,
|
|
35383
|
+
roots: config.roots,
|
|
35384
|
+
cloneRoot: yield* resolveCloneRoot(config.roots, projects),
|
|
35385
|
+
...checkout ? { checkout } : {}
|
|
35386
|
+
};
|
|
34484
35387
|
break;
|
|
34485
35388
|
}
|
|
34486
35389
|
case "project": {
|
|
34487
|
-
const
|
|
34488
|
-
const
|
|
34489
|
-
|
|
35390
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
35391
|
+
const info2 = yield* fs.stat(request3.path).pipe(exports_Effect.catchIf(missing3, () => exports_Effect.succeed(undefined)));
|
|
35392
|
+
if (!info2) {
|
|
35393
|
+
result4 = { ...identity3, kind: "project-missing", path: request3.path };
|
|
35394
|
+
break;
|
|
35395
|
+
}
|
|
35396
|
+
const checkout = yield* repository3(request3.path);
|
|
35397
|
+
const canonical2 = yield* project3(request3.path);
|
|
35398
|
+
result4 = {
|
|
35399
|
+
...identity3,
|
|
35400
|
+
kind: "project",
|
|
35401
|
+
project: canonical2,
|
|
35402
|
+
checkout,
|
|
35403
|
+
worktrees: canonical2.vcs === "git" ? yield* listWorktrees(canonical2.path) : yield* listWorkspaces(canonical2.path),
|
|
35404
|
+
branches: canonical2.vcs === "git" ? yield* listBranches(canonical2.path) : [],
|
|
35405
|
+
revisions: canonical2.vcs === "jj" ? yield* listRevisions(canonical2.path) : []
|
|
35406
|
+
};
|
|
34490
35407
|
break;
|
|
34491
35408
|
}
|
|
34492
|
-
case "
|
|
34493
|
-
|
|
35409
|
+
case "clone-source": {
|
|
35410
|
+
const repo = yield* repository3(request3.repo);
|
|
35411
|
+
result4 = {
|
|
35412
|
+
...identity3,
|
|
35413
|
+
kind: "clone-source",
|
|
35414
|
+
source: repo.vcs === "git" ? yield* cloneSource(repo.path, host.id) : yield* cloneSource2(repo.path, host.id)
|
|
35415
|
+
};
|
|
35416
|
+
break;
|
|
35417
|
+
}
|
|
35418
|
+
case "worktrees": {
|
|
35419
|
+
const repo = yield* repository3(request3.repo);
|
|
35420
|
+
result4 = {
|
|
35421
|
+
...identity3,
|
|
35422
|
+
kind: "worktrees",
|
|
35423
|
+
repository: repo,
|
|
35424
|
+
worktrees: repo.vcs === "git" ? yield* listWorktrees(repo.path) : yield* listWorkspaces(repo.path),
|
|
35425
|
+
branches: repo.vcs === "git" ? yield* listBranches(repo.path) : [],
|
|
35426
|
+
revisions: repo.vcs === "jj" ? yield* listRevisions(repo.path) : []
|
|
35427
|
+
};
|
|
34494
35428
|
break;
|
|
34495
|
-
|
|
34496
|
-
|
|
34497
|
-
|
|
35429
|
+
}
|
|
35430
|
+
case "revision": {
|
|
35431
|
+
const repo = yield* repository3(request3.repo);
|
|
35432
|
+
if (repo.vcs !== "jj")
|
|
35433
|
+
return yield* exports_Effect.fail(new AppError({ message: "Base revision requires a JJ repository" }));
|
|
35434
|
+
result4 = { ...identity3, kind: "revision", revision: yield* resolveRevision(repo.path, request3.revision) };
|
|
34498
35435
|
break;
|
|
34499
35436
|
}
|
|
34500
35437
|
case "plan":
|
|
34501
35438
|
result4 = { ...identity3, kind: "plan", plan: yield* planLaunch(request3.input, host.id) };
|
|
34502
35439
|
break;
|
|
35440
|
+
case "clone-plan":
|
|
35441
|
+
result4 = { ...identity3, kind: "clone-plan", plan: yield* planClone(request3.input, host.id) };
|
|
35442
|
+
break;
|
|
35443
|
+
case "clone-launch":
|
|
35444
|
+
result4 = { ...identity3, kind: "clone-launch", result: yield* launchClone(request3.input, command, request3.reviewed, host.id) };
|
|
35445
|
+
break;
|
|
34503
35446
|
case "launch":
|
|
34504
35447
|
result4 = { ...identity3, kind: "launch", result: yield* launch(request3.input, command, request3.reviewed, host.id) };
|
|
34505
35448
|
break;
|
|
@@ -34512,7 +35455,7 @@ var hostRequest = exports_Effect.fnUntraced(function* (raw, command) {
|
|
|
34512
35455
|
});
|
|
34513
35456
|
|
|
34514
35457
|
// src/client.ts
|
|
34515
|
-
var
|
|
35458
|
+
var fail20 = (message) => exports_Effect.fail(new AppError({ message }));
|
|
34516
35459
|
var listMachines = exports_Effect.gen(function* () {
|
|
34517
35460
|
const registry = yield* machinesRegistry;
|
|
34518
35461
|
const machines = [
|
|
@@ -34525,75 +35468,97 @@ var connectMachine = exports_Effect.fnUntraced(function* (machine) {
|
|
|
34525
35468
|
const choices = yield* listMachines;
|
|
34526
35469
|
const current = choices.find((choice) => choice.key === machine.key && choice.local === machine.local);
|
|
34527
35470
|
if (!current)
|
|
34528
|
-
return yield*
|
|
35471
|
+
return yield* fail20(`Rex machine ${machine.label} is no longer registered; choose another machine`);
|
|
34529
35472
|
if (current.local)
|
|
34530
35473
|
return { ...current, hostId: (yield* localHost).id };
|
|
34531
35474
|
const identity3 = yield* remoteIdentity(current.selector);
|
|
34532
35475
|
const registered = (yield* machinesRegistry).hosts.find((entry) => entry.host.id === current.key);
|
|
34533
35476
|
if (!registered?.host.endpoints.includes(identity3.endpoint)) {
|
|
34534
|
-
return yield*
|
|
35477
|
+
return yield* fail20(`Rex machine ${current.label} resolved to an unexpected server; refusing to route remotely`);
|
|
34535
35478
|
}
|
|
34536
35479
|
const raw = yield* remoteRex(current.selector, ["actions", "--json"]);
|
|
34537
35480
|
const actions = yield* exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(RexActionsSchema))(raw);
|
|
34538
35481
|
const helper = actions.actions.find((action) => action.name === "worktrees_request");
|
|
34539
35482
|
if (!helper) {
|
|
34540
|
-
return yield*
|
|
35483
|
+
return yield* fail20(`rex-worktrees is not installed on ${current.label}. Build and run rex-worktrees setup on that machine, then reload its Rex config.`);
|
|
34541
35484
|
}
|
|
34542
35485
|
yield* exports_Schema.decodeUnknownEffect(RexHelperArgsSchema)(helper.args);
|
|
34543
35486
|
return { ...current, hostId: identity3.host_id };
|
|
34544
35487
|
});
|
|
34545
35488
|
var request3 = exports_Effect.fnUntraced(function* (host, command, body) {
|
|
34546
|
-
const encoded = { version:
|
|
35489
|
+
const encoded = { version: 4, hostId: host.hostId, ...body };
|
|
34547
35490
|
let response;
|
|
34548
35491
|
if (host.local) {
|
|
34549
35492
|
response = yield* dispatchHost(encoded, command);
|
|
34550
35493
|
} else {
|
|
34551
35494
|
const current = yield* connectMachine(host);
|
|
34552
35495
|
if (current.hostId !== host.hostId)
|
|
34553
|
-
return yield*
|
|
35496
|
+
return yield* fail20(`Rex host identity changed for ${host.label}; reconnect before continuing`);
|
|
34554
35497
|
const raw = yield* remoteRex(current.selector, ["do", "worktrees_request", "--args", JSON.stringify({ request: JSON.stringify(encoded) }), "--json"]);
|
|
34555
35498
|
response = yield* exports_Schema.decodeUnknownEffect(RexWorktreesResponseSchema)(raw);
|
|
34556
35499
|
}
|
|
34557
|
-
if (response.hostId !== host.hostId || response.version !==
|
|
34558
|
-
return yield*
|
|
35500
|
+
if (response.hostId !== host.hostId || response.version !== 4 || response.kind !== body.kind && !(body.kind === "project" && response.kind === "project-missing" && response.path === body.path))
|
|
35501
|
+
return yield* fail20(`Unexpected Rex host/protocol response from ${host.label}; update rex-worktrees on that machine, run setup, and reload its Rex config`);
|
|
34559
35502
|
return response;
|
|
34560
35503
|
});
|
|
34561
35504
|
var discover = exports_Effect.fnUntraced(function* (host, command, context3) {
|
|
34562
35505
|
const result4 = yield* request3(host, command, { kind: "discover", ...host.local && context3 ? { context: context3 } : {} });
|
|
34563
35506
|
if (result4.kind !== "discover")
|
|
34564
|
-
return yield*
|
|
34565
|
-
return { sessions: result4.sessions, clients: result4.clients, projects: result4.projects, ...result4.checkout ? { checkout: result4.checkout } : {} };
|
|
35507
|
+
return yield* fail20("Unexpected discovery response");
|
|
35508
|
+
return { sessions: result4.sessions, clients: result4.clients, projects: result4.projects, roots: result4.roots ?? [], cloneRoot: result4.cloneRoot, ...result4.checkout ? { checkout: result4.checkout } : {} };
|
|
34566
35509
|
});
|
|
34567
35510
|
var inspectProject = exports_Effect.fnUntraced(function* (host, command, path) {
|
|
34568
35511
|
const result4 = yield* request3(host, command, { kind: "project", path });
|
|
35512
|
+
if (result4.kind === "project-missing")
|
|
35513
|
+
return yield* fail20(`Project directory does not exist: ${result4.path}`);
|
|
34569
35514
|
if (result4.kind !== "project")
|
|
34570
|
-
return yield*
|
|
34571
|
-
return { project: result4.project, checkout: result4.checkout, worktrees: result4.worktrees, branches: result4.branches };
|
|
35515
|
+
return yield* fail20("Unexpected project response");
|
|
35516
|
+
return { project: result4.project, checkout: result4.checkout, worktrees: result4.worktrees, branches: result4.branches, revisions: result4.revisions };
|
|
34572
35517
|
});
|
|
34573
35518
|
var inspectWorktrees = exports_Effect.fnUntraced(function* (host, command, repo) {
|
|
34574
35519
|
const result4 = yield* request3(host, command, { kind: "worktrees", repo });
|
|
34575
35520
|
if (result4.kind !== "worktrees")
|
|
34576
|
-
return yield*
|
|
34577
|
-
return { worktrees: result4.worktrees, branches: result4.branches };
|
|
35521
|
+
return yield* fail20("Unexpected worktree response");
|
|
35522
|
+
return { repository: result4.repository, worktrees: result4.worktrees, branches: result4.branches, revisions: result4.revisions };
|
|
34578
35523
|
});
|
|
34579
|
-
var
|
|
34580
|
-
const result4 = yield* request3(host, command, { kind: "
|
|
34581
|
-
if (result4.kind !== "
|
|
34582
|
-
return yield*
|
|
34583
|
-
return
|
|
35524
|
+
var inspectRevision = exports_Effect.fnUntraced(function* (host, command, repo, revision) {
|
|
35525
|
+
const result4 = yield* request3(host, command, { kind: "revision", repo, revision });
|
|
35526
|
+
if (result4.kind !== "revision")
|
|
35527
|
+
return yield* fail20("Unexpected revision response");
|
|
35528
|
+
return result4.revision;
|
|
34584
35529
|
});
|
|
34585
35530
|
var review = exports_Effect.fnUntraced(function* (host, command, input) {
|
|
34586
35531
|
const result4 = yield* request3(host, command, { kind: "plan", input });
|
|
34587
35532
|
if (result4.kind !== "plan")
|
|
34588
|
-
return yield*
|
|
35533
|
+
return yield* fail20("Unexpected review response");
|
|
34589
35534
|
return result4.plan;
|
|
34590
35535
|
});
|
|
34591
35536
|
var submit = exports_Effect.fnUntraced(function* (host, command, input, reviewed) {
|
|
34592
35537
|
if (reviewed.hostId !== host.hostId)
|
|
34593
|
-
return yield*
|
|
35538
|
+
return yield* fail20("Reviewed destination belongs to another host");
|
|
34594
35539
|
const result4 = yield* request3(host, command, { kind: "launch", input, reviewed });
|
|
34595
35540
|
if (result4.kind !== "launch")
|
|
34596
|
-
return yield*
|
|
35541
|
+
return yield* fail20("Unexpected launch response");
|
|
35542
|
+
return result4.result;
|
|
35543
|
+
});
|
|
35544
|
+
var sourceForClone = exports_Effect.fnUntraced(function* (host, command, repo) {
|
|
35545
|
+
const result4 = yield* request3(host, command, { kind: "clone-source", repo });
|
|
35546
|
+
if (result4.kind !== "clone-source")
|
|
35547
|
+
return yield* fail20("Unexpected clone source response");
|
|
35548
|
+
return result4.source;
|
|
35549
|
+
});
|
|
35550
|
+
var reviewClone = exports_Effect.fnUntraced(function* (host, command, input) {
|
|
35551
|
+
const result4 = yield* request3(host, command, { kind: "clone-plan", input });
|
|
35552
|
+
if (result4.kind !== "clone-plan")
|
|
35553
|
+
return yield* fail20("Unexpected clone review response");
|
|
35554
|
+
return result4.plan;
|
|
35555
|
+
});
|
|
35556
|
+
var submitClone = exports_Effect.fnUntraced(function* (host, command, input, reviewed) {
|
|
35557
|
+
if (reviewed.hostId !== host.hostId)
|
|
35558
|
+
return yield* fail20("Reviewed clone destination belongs to another host");
|
|
35559
|
+
const result4 = yield* request3(host, command, { kind: "clone-launch", input, reviewed });
|
|
35560
|
+
if (result4.kind !== "clone-launch")
|
|
35561
|
+
return yield* fail20("Unexpected clone launch response");
|
|
34597
35562
|
return result4.result;
|
|
34598
35563
|
});
|
|
34599
35564
|
|
|
@@ -34603,7 +35568,8 @@ import { randomUUID as randomUUID2 } from "crypto";
|
|
|
34603
35568
|
// lua/rex-worktrees.lua
|
|
34604
35569
|
var rex_worktrees_default = `-- rex-worktrees: managed module
|
|
34605
35570
|
local installed_rex_bin_dir = false
|
|
34606
|
-
|
|
35571
|
+
local installed_path_env = false
|
|
35572
|
+
-- Opening is opt-in via opts.key.
|
|
34607
35573
|
local M = {}
|
|
34608
35574
|
|
|
34609
35575
|
function M.setup(opts)
|
|
@@ -34621,6 +35587,7 @@ function M.setup(opts)
|
|
|
34621
35587
|
local function worktrees_request(request)
|
|
34622
35588
|
local exec_opts = { stdin = request, timeout = 20, env = {} }
|
|
34623
35589
|
if rex_bin_dir then exec_opts.env.REX_BIN_DIR = rex_bin_dir end
|
|
35590
|
+
if installed_path_env ~= false then exec_opts.env.PATH = installed_path_env end
|
|
34624
35591
|
if os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") then exec_opts.env.REX_WORKTREES_LOCAL_ENDPOINT = os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") end
|
|
34625
35592
|
local result, run_err = rex.exec({ bin, "host-request" }, exec_opts)
|
|
34626
35593
|
if not result then error(run_err, 0) end
|
|
@@ -34646,7 +35613,7 @@ function M.setup(opts)
|
|
|
34646
35613
|
rex.action{
|
|
34647
35614
|
name = "worktrees_open",
|
|
34648
35615
|
title = "Open Worktree\u2026",
|
|
34649
|
-
description = "Choose
|
|
35616
|
+
description = "Choose a project, Rex machine, checkout, and exact session",
|
|
34650
35617
|
run = function(ctx)
|
|
34651
35618
|
local session_id = ctx.session_id or rex.session_id
|
|
34652
35619
|
if type(session_id) ~= "string" then error("Select a Rex session first", 0) end
|
|
@@ -34664,6 +35631,7 @@ function M.setup(opts)
|
|
|
34664
35631
|
end
|
|
34665
35632
|
local exec_opts = { timeout = 20, env = {} }
|
|
34666
35633
|
if rex_bin_dir then exec_opts.env.REX_BIN_DIR = rex_bin_dir end
|
|
35634
|
+
if installed_path_env ~= false then exec_opts.env.PATH = installed_path_env end
|
|
34667
35635
|
if os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") then exec_opts.env.REX_WORKTREES_LOCAL_ENDPOINT = os.getenv("REX_WORKTREES_LOCAL_ENDPOINT") end
|
|
34668
35636
|
local result, run_err = rex.exec(command, exec_opts)
|
|
34669
35637
|
if not result then error(run_err, 0) end
|
|
@@ -34680,6 +35648,7 @@ function M.setup(opts)
|
|
|
34680
35648
|
end,
|
|
34681
35649
|
}
|
|
34682
35650
|
|
|
35651
|
+
|
|
34683
35652
|
if opts.key then rex.bind(opts.key, "worktrees_open") end
|
|
34684
35653
|
end
|
|
34685
35654
|
|
|
@@ -34697,21 +35666,27 @@ require("rex-worktrees").setup()
|
|
|
34697
35666
|
-- END rex-worktrees
|
|
34698
35667
|
`;
|
|
34699
35668
|
var managedRegistration = /^-- BEGIN rex-worktrees\nrequire\("rex-worktrees"\)\.setup\(\{ bin = "(?:\\.|[^"\\])*" \}\)\n-- END rex-worktrees\n$/;
|
|
34700
|
-
var
|
|
35669
|
+
var marker2 = `-- rex-worktrees: managed module
|
|
34701
35670
|
`;
|
|
34702
35671
|
var rexBinPlaceholder = "local installed_rex_bin_dir = false";
|
|
34703
|
-
var
|
|
34704
|
-
var
|
|
35672
|
+
var pathEnvPlaceholder = "local installed_path_env = false";
|
|
35673
|
+
var luaLiteral = (value3) => JSON.stringify(value3).replace(/\\u00([0-1][0-9a-f])/gi, (_, hex) => `\\${parseInt(hex, 16).toString().padStart(3, "0")}`);
|
|
35674
|
+
var fail21 = (message) => exports_Effect.fail(new AppError({ message }));
|
|
35675
|
+
var installSetup = exports_Effect.fnUntraced(function* ({ source, home, configPath, lua: module, rexBinDir, managedBin, pathEnv, allowLinkedConfig = true }) {
|
|
34705
35676
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
34706
35677
|
const path = yield* exports_Path.Path;
|
|
34707
35678
|
if (!path.isAbsolute(configPath) || !path.isAbsolute(home) || !path.isAbsolute(source) || !path.isAbsolute(rexBinDir) || managedBin !== undefined && !path.isAbsolute(managedBin))
|
|
34708
35679
|
return yield* new AppError({ message: "Setup requires absolute paths" });
|
|
34709
|
-
if (!module.startsWith(
|
|
35680
|
+
if (!module.startsWith(marker2))
|
|
34710
35681
|
return yield* new AppError({ message: "Embedded Lua module is missing its install marker" });
|
|
34711
|
-
if (!module.startsWith(`${
|
|
35682
|
+
if (!module.startsWith(`${marker2}${rexBinPlaceholder}
|
|
34712
35683
|
`) || module.split(rexBinPlaceholder).length !== 2)
|
|
34713
35684
|
return yield* new AppError({ message: "Embedded Lua module must contain exactly one Rex CLI directory placeholder after its marker" });
|
|
34714
|
-
|
|
35685
|
+
if (!module.startsWith(`${marker2}${rexBinPlaceholder}
|
|
35686
|
+
${pathEnvPlaceholder}
|
|
35687
|
+
`) || module.split(pathEnvPlaceholder).length !== 2)
|
|
35688
|
+
return yield* new AppError({ message: "Embedded Lua module must contain exactly one host PATH placeholder after its Rex CLI directory placeholder" });
|
|
35689
|
+
const installedLua = module.replace(rexBinPlaceholder, `local installed_rex_bin_dir = ${luaLiteral(rexBinDir)}`).replace(pathEnvPlaceholder, `local installed_path_env = ${pathEnv === undefined ? "false" : luaLiteral(pathEnv)}`);
|
|
34715
35690
|
const bin = managedBin ?? path.join(home, ".local", "bin", "rex-worktrees");
|
|
34716
35691
|
const registration = managedBin === undefined ? manualRegistration : `-- BEGIN rex-worktrees
|
|
34717
35692
|
require("rex-worktrees").setup({ bin = ${JSON.stringify(managedBin)} })
|
|
@@ -34722,35 +35697,37 @@ require("rex-worktrees").setup({ bin = ${JSON.stringify(managedBin)} })
|
|
|
34722
35697
|
const binaryInfo = managedBin === undefined ? yield* info2(bin) : undefined;
|
|
34723
35698
|
const luaInfo = yield* info2(luaPath);
|
|
34724
35699
|
if (binaryInfo && binaryInfo.type !== "File")
|
|
34725
|
-
return yield*
|
|
35700
|
+
return yield* fail21(`Refusing to replace non-file binary: ${bin}`);
|
|
34726
35701
|
if (luaInfo && luaInfo.type !== "File")
|
|
34727
|
-
return yield*
|
|
34728
|
-
if (luaInfo && !(yield* fs.readFileString(luaPath)).startsWith(
|
|
34729
|
-
return yield*
|
|
35702
|
+
return yield* fail21(`Refusing to replace non-file Lua module: ${luaPath}`);
|
|
35703
|
+
if (luaInfo && !(yield* fs.readFileString(luaPath)).startsWith(marker2))
|
|
35704
|
+
return yield* fail21(`Refusing to replace unrelated Lua module: ${luaPath}`);
|
|
34730
35705
|
const initInfo = yield* info2(configPath);
|
|
34731
35706
|
if (initInfo && initInfo.type !== "File" && initInfo.type !== "SymbolicLink")
|
|
34732
|
-
return yield*
|
|
35707
|
+
return yield* fail21(`Rex init is not a file: ${configPath}`);
|
|
35708
|
+
if (initInfo?.type === "SymbolicLink" && !allowLinkedConfig)
|
|
35709
|
+
return yield* fail21(`Refusing linked Rex init: ${configPath}`);
|
|
34733
35710
|
const current = initInfo ? yield* fs.readFileString(configPath) : "";
|
|
34734
35711
|
const begin = "-- BEGIN rex-worktrees";
|
|
34735
35712
|
const end3 = "-- END rex-worktrees";
|
|
34736
35713
|
const start = current.indexOf(begin);
|
|
34737
35714
|
const finish = current.indexOf(end3);
|
|
34738
35715
|
if (start < 0 !== finish < 0 || start >= 0 && (current.indexOf(begin, start + begin.length) !== -1 || current.indexOf(end3, finish + end3.length) !== -1 || current.slice(start, finish + end3.length + 1) !== manualRegistration && !managedRegistration.test(current.slice(start, finish + end3.length + 1))))
|
|
34739
|
-
return yield*
|
|
35716
|
+
return yield* fail21(`Malformed rex-worktrees registration in ${configPath}`);
|
|
34740
35717
|
if (start < 0 && /require\s*\(?\s*["']rex-worktrees["']/.test(current))
|
|
34741
|
-
return yield*
|
|
35718
|
+
return yield* fail21(`Existing rex-worktrees registration in ${configPath}; remove it before setup`);
|
|
34742
35719
|
const sourceInfo = yield* fs.stat(source);
|
|
34743
35720
|
if (sourceInfo.type !== "File")
|
|
34744
|
-
return yield*
|
|
35721
|
+
return yield* fail21(`Installer source is not a file: ${source}`);
|
|
34745
35722
|
if (managedBin !== undefined) {
|
|
34746
35723
|
const target = yield* info2(managedBin);
|
|
34747
35724
|
if (!target)
|
|
34748
|
-
return yield*
|
|
35725
|
+
return yield* fail21(`Managed binary does not exist: ${managedBin}`);
|
|
34749
35726
|
const managedInfo = yield* fs.stat(managedBin);
|
|
34750
35727
|
if (managedInfo.type !== "File" || (managedInfo.mode & 73) === 0)
|
|
34751
|
-
return yield*
|
|
35728
|
+
return yield* fail21(`Managed binary must be an executable file: ${managedBin}`);
|
|
34752
35729
|
if ((yield* fs.realPath(managedBin)) !== (yield* fs.realPath(source)))
|
|
34753
|
-
return yield*
|
|
35730
|
+
return yield* fail21(`Managed binary must resolve to the running executable: ${managedBin}`);
|
|
34754
35731
|
} else
|
|
34755
35732
|
yield* fs.makeDirectory(path.dirname(bin), { recursive: true });
|
|
34756
35733
|
yield* fs.makeDirectory(path.dirname(luaPath), { recursive: true });
|
|
@@ -34773,18 +35750,20 @@ require("rex-worktrees").setup({ bin = ${JSON.stringify(managedBin)} })
|
|
|
34773
35750
|
yield* fs.writeFileString(configPath, `${current.slice(0, start)}${registration}${current.slice(finish + end3.length + 1)}`);
|
|
34774
35751
|
return { bin, luaPath, configPath };
|
|
34775
35752
|
});
|
|
34776
|
-
var setup = exports_Effect.fnUntraced(function* (managedBin) {
|
|
35753
|
+
var setup = exports_Effect.fnUntraced(function* (managedBin, configPath) {
|
|
34777
35754
|
const home = process.env.HOME;
|
|
34778
35755
|
if (!home)
|
|
34779
|
-
return yield*
|
|
35756
|
+
return yield* fail21("HOME is required");
|
|
34780
35757
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
34781
35758
|
const path = yield* exports_Path.Path;
|
|
35759
|
+
if (configPath !== undefined && !path.isAbsolute(configPath))
|
|
35760
|
+
return yield* fail21(`--config must be an absolute path: ${configPath}`);
|
|
34782
35761
|
const executable = (dir2) => exports_Effect.catchIf(fs.stat(path.join(dir2, "rex")).pipe(exports_Effect.map((info2) => info2.type === "File" && (info2.mode & 73) !== 0)), (error2) => exports_PlatformError.isPlatformError(error2) && error2.reason._tag === "NotFound", () => exports_Effect.succeed(false));
|
|
34783
35762
|
const configured = process.env.REX_BIN_DIR;
|
|
34784
35763
|
let rexBinDir;
|
|
34785
35764
|
if (configured) {
|
|
34786
35765
|
if (!path.isAbsolute(configured) || !(yield* executable(configured)))
|
|
34787
|
-
return yield*
|
|
35766
|
+
return yield* fail21(`REX_BIN_DIR must be an absolute directory containing an executable rex: ${configured}`);
|
|
34788
35767
|
rexBinDir = configured;
|
|
34789
35768
|
} else {
|
|
34790
35769
|
for (const entry of (process.env.PATH ?? "").split(":")) {
|
|
@@ -34795,12 +35774,16 @@ var setup = exports_Effect.fnUntraced(function* (managedBin) {
|
|
|
34795
35774
|
}
|
|
34796
35775
|
}
|
|
34797
35776
|
if (!rexBinDir)
|
|
34798
|
-
return yield*
|
|
34799
|
-
|
|
34800
|
-
|
|
34801
|
-
|
|
34802
|
-
|
|
34803
|
-
|
|
35777
|
+
return yield* fail21("Rex CLI not found: set REX_BIN_DIR or add an executable rex to PATH");
|
|
35778
|
+
let target = configPath;
|
|
35779
|
+
if (target === undefined) {
|
|
35780
|
+
const response = yield* rex(["config", "check", "--json"]);
|
|
35781
|
+
const checked = yield* exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(RexConfigCheckSchema))(response);
|
|
35782
|
+
if (checked.diagnostics.length)
|
|
35783
|
+
return yield* fail21("Rex config has diagnostics; fix it before setup");
|
|
35784
|
+
target = checked.path;
|
|
35785
|
+
}
|
|
35786
|
+
return yield* installSetup({ source: process.execPath, home, configPath: target, lua: rex_worktrees_default, rexBinDir, managedBin, allowLinkedConfig: configPath === undefined, ...process.env.PATH !== undefined ? { pathEnv: process.env.PATH } : {} });
|
|
34804
35787
|
});
|
|
34805
35788
|
// node_modules/effect/dist/cli/Prompt.js
|
|
34806
35789
|
var exports_Prompt = {};
|
|
@@ -34886,12 +35869,12 @@ var cursorMove = (column, row = 0) => {
|
|
|
34886
35869
|
}
|
|
34887
35870
|
return command;
|
|
34888
35871
|
};
|
|
34889
|
-
var eraseLines = (
|
|
35872
|
+
var eraseLines = (rows2) => {
|
|
34890
35873
|
let command = "";
|
|
34891
|
-
for (let i = 0;i <
|
|
34892
|
-
command += `${ESC}2K` + (i <
|
|
35874
|
+
for (let i = 0;i < rows2; i++) {
|
|
35875
|
+
command += `${ESC}2K` + (i < rows2 - 1 ? `${ESC}1A` : "");
|
|
34893
35876
|
}
|
|
34894
|
-
if (
|
|
35877
|
+
if (rows2 > 0) {
|
|
34895
35878
|
command += `${ESC}G`;
|
|
34896
35879
|
}
|
|
34897
35880
|
return command;
|
|
@@ -35341,12 +36324,12 @@ var eraseText = (text, columns) => {
|
|
|
35341
36324
|
if (columns === 0) {
|
|
35342
36325
|
return eraseLine + cursorTo(0);
|
|
35343
36326
|
}
|
|
35344
|
-
let
|
|
36327
|
+
let rows2 = 0;
|
|
35345
36328
|
const lines = text.split(NEWLINE_REGEXP);
|
|
35346
36329
|
for (const line of lines) {
|
|
35347
|
-
|
|
36330
|
+
rows2 += 1 + Math.floor(Math.max(line.length - 1, 0) / columns);
|
|
35348
36331
|
}
|
|
35349
|
-
return eraseLines(
|
|
36332
|
+
return eraseLines(rows2);
|
|
35350
36333
|
};
|
|
35351
36334
|
var lines = (prompt, columns) => {
|
|
35352
36335
|
const lines2 = prompt.split(NEWLINE_REGEXP);
|
|
@@ -37469,7 +38452,7 @@ var safeDisplayText = (text, preserveWhitespace = false) => {
|
|
|
37469
38452
|
};
|
|
37470
38453
|
var fit = (text, width2) => Bun.stringWidth(text) > width2 ? Bun.sliceAnsi(text, 0, Math.max(0, width2), { ellipsis: "\u2026" }) : text;
|
|
37471
38454
|
var pad = (text, width2) => text + " ".repeat(Math.max(0, width2 - Bun.stringWidth(text)));
|
|
37472
|
-
var renderFormFrame = (view, focused, editing, columns,
|
|
38455
|
+
var renderFormFrame = (view, focused, editing, columns, rows2, colors2 = !process.env.NO_COLOR, fill = true) => {
|
|
37473
38456
|
const width2 = Math.max(20, columns);
|
|
37474
38457
|
const inside = width2 - 4;
|
|
37475
38458
|
const screen = [];
|
|
@@ -37477,10 +38460,10 @@ var renderFormFrame = (view, focused, editing, columns, rows, colors2 = !process
|
|
|
37477
38460
|
const line = (left, right) => color(`${left}${"\u2500".repeat(width2 - 2)}${right}`, "muted", colors2);
|
|
37478
38461
|
const add4 = (text) => screen.push(border(fit(text, inside)));
|
|
37479
38462
|
screen.push(line("\u250C", "\u2510"));
|
|
37480
|
-
const heading = `${color("REX", "cyan", colors2)}
|
|
37481
|
-
add4(
|
|
38463
|
+
const heading = `${color("REX", "cyan", colors2)} ${color("/ WORKTREES", "bold", colors2)}`;
|
|
38464
|
+
add4(heading);
|
|
37482
38465
|
screen.push(line("\u251C", "\u2524"));
|
|
37483
|
-
const budget = Math.max(0,
|
|
38466
|
+
const budget = Math.max(0, rows2 - (editing ? rows2 >= 20 ? 10 : 8 : 7));
|
|
37484
38467
|
const body = [];
|
|
37485
38468
|
const addBody = (text) => body.push(border(fit(text, inside)));
|
|
37486
38469
|
const addWrapped = (text, tone, limit = budget) => {
|
|
@@ -37493,12 +38476,12 @@ var renderFormFrame = (view, focused, editing, columns, rows, colors2 = !process
|
|
|
37493
38476
|
};
|
|
37494
38477
|
for (const row of view.rows) {
|
|
37495
38478
|
const active = focused === row.id;
|
|
37496
|
-
const label = pad(fit(safeDisplayText(row.label).toUpperCase(),
|
|
38479
|
+
const label = pad(fit(safeDisplayText(row.label).toUpperCase(), 13), 13);
|
|
37497
38480
|
const value3 = safeDisplayText(row.value) || "\u2014";
|
|
37498
|
-
const room = Math.max(1, inside -
|
|
38481
|
+
const room = Math.max(1, inside - 19);
|
|
37499
38482
|
const indicator = active ? color("\u203A", "cyan", colors2) : " ";
|
|
37500
38483
|
addBody(`${indicator} ${color(label, row.disabled ? "muted" : active ? "cyan" : "bold", colors2)} ${color(fit(value3, room), row.disabled ? "muted" : active ? "bold" : "muted", colors2)}`);
|
|
37501
|
-
if (!editing &&
|
|
38484
|
+
if (!editing && row.detail && (row.id === "destination" && row.detail.startsWith("/") || !view.error && active) && body.length < budget - 3)
|
|
37502
38485
|
addWrapped(row.detail, "muted", budget - 3);
|
|
37503
38486
|
}
|
|
37504
38487
|
if (view.error) {
|
|
@@ -37514,13 +38497,13 @@ var renderFormFrame = (view, focused, editing, columns, rows, colors2 = !process
|
|
|
37514
38497
|
while (body.length < budget)
|
|
37515
38498
|
addBody("");
|
|
37516
38499
|
screen.push(...body.slice(0, budget));
|
|
37517
|
-
if (!editing)
|
|
38500
|
+
if (!editing) {
|
|
37518
38501
|
screen.push(line("\u251C", "\u2524"));
|
|
37519
|
-
|
|
37520
|
-
|
|
37521
|
-
|
|
37522
|
-
|
|
37523
|
-
|
|
38502
|
+
const submit2 = focused === "submit" ? color("\u203A", "cyan", colors2) : " ";
|
|
38503
|
+
const cancel = focused === "cancel" ? color("\u203A", "cyan", colors2) : " ";
|
|
38504
|
+
add4(`${submit2} ${color(fit(safeDisplayText(view.submitLabel), Math.max(1, inside - 19)), view.submitDisabled ? "muted" : "cyan", colors2)} ${cancel} ${color("Cancel", focused === "cancel" ? "cyan" : "muted", colors2)}`);
|
|
38505
|
+
add4(color(" \u2191\u2193 / jk move \xB7 Tab next \xB7 Enter select \xB7 Ctrl+S submit \xB7 Esc close", "muted", colors2));
|
|
38506
|
+
}
|
|
37524
38507
|
screen.push(line("\u2514", "\u2518"));
|
|
37525
38508
|
return screen.join(`\r
|
|
37526
38509
|
`) + (editing ? `\r
|
|
@@ -37557,7 +38540,7 @@ var advanceInputChoice = (state, event, choices, selectionOnly = false) => {
|
|
|
37557
38540
|
const next = matches[(current + (key5.name === "up" ? -1 : 1) + matches.length) % matches.length];
|
|
37558
38541
|
return next === undefined ? { _tag: "Beep" } : { _tag: "NextFrame", state: { ...state, selected: next } };
|
|
37559
38542
|
}
|
|
37560
|
-
if (key5.name === "enter" || key5.name === "return") {
|
|
38543
|
+
if (key5.name === "enter" || key5.name === "return" || key5.ctrl && key5.name === "s") {
|
|
37561
38544
|
const picked = state.selected === null ? undefined : choices[state.selected];
|
|
37562
38545
|
if (picked && state.selected !== null && matches.includes(state.selected))
|
|
37563
38546
|
return { _tag: "Submit", value: { kind: "selected", value: picked.value } };
|
|
@@ -37572,10 +38555,10 @@ var advanceInputChoice = (state, event, choices, selectionOnly = false) => {
|
|
|
37572
38555
|
return { _tag: "Beep" };
|
|
37573
38556
|
return { _tag: "NextFrame", state: { text: state.text + text, selected: selectionOnly ? state.selected : null } };
|
|
37574
38557
|
};
|
|
37575
|
-
var renderInputChoice = (message, state, choices, columns,
|
|
38558
|
+
var renderInputChoice = (message, state, choices, columns, rows2, colors2 = !process.env.NO_COLOR, selectionOnly = false) => {
|
|
37576
38559
|
const width2 = Math.max(20, columns) - 2;
|
|
37577
38560
|
const matches = matchingChoices(choices, state.text);
|
|
37578
|
-
const count2 =
|
|
38561
|
+
const count2 = rows2 >= 20 ? 3 : 1;
|
|
37579
38562
|
const selected = matches.indexOf(state.selected ?? -1);
|
|
37580
38563
|
const start = selected < 0 ? 0 : Math.max(0, Math.min(selected, matches.length - count2));
|
|
37581
38564
|
const lines2 = [
|
|
@@ -37618,45 +38601,108 @@ var acknowledge = (title, lines2, tone) => exports_Prompt.run(exports_Prompt.Cus
|
|
|
37618
38601
|
clear: () => exports_Effect.succeed(""),
|
|
37619
38602
|
process: (input) => exports_Effect.succeed(input.key.name === "enter" || input.key.name === "return" || input.key.name === "space" || input.key.name === "escape" || input.key.ctrl && input.key.name === "c" ? { _tag: "Submit", value: undefined } : { _tag: "Beep" })
|
|
37620
38603
|
})).pipe(exports_Effect.catch(() => exports_Effect.void));
|
|
37621
|
-
var problem = (error2) => exports_Cause.pretty(exports_Cause.fail(error2));
|
|
38604
|
+
var problem = (error2) => error2 instanceof AppError ? error2.message : exports_Cause.pretty(exports_Cause.fail(error2));
|
|
37622
38605
|
var selected = (value3, current, title, description) => ({ value: value3, selected: current, title, description });
|
|
37623
|
-
var generatedName = (draft) => draft.worktreeName ?? draft.destination?.label ?? draft.projectChoice?.name ?? "Worktree";
|
|
37624
|
-
var inputFor = (draft) =>
|
|
37625
|
-
|
|
37626
|
-
|
|
37627
|
-
|
|
37628
|
-
|
|
37629
|
-
|
|
37630
|
-
|
|
37631
|
-
|
|
37632
|
-
|
|
38606
|
+
var generatedName = (draft) => draft.worktreeName ?? (draft.clone?.vcs === "jj" ? draft.projectChoice?.name : draft.destination?.label) ?? draft.projectChoice?.name ?? "Worktree";
|
|
38607
|
+
var inputFor = (draft) => {
|
|
38608
|
+
if (!draft.host || !draft.project || !draft.projectChoice || !draft.destination || !draft.session)
|
|
38609
|
+
return;
|
|
38610
|
+
const common = {
|
|
38611
|
+
repo: draft.project.vcs === "jj" ? draft.sourcePath ?? draft.project.path : draft.project.path,
|
|
38612
|
+
session: draft.session,
|
|
38613
|
+
name: generatedName(draft),
|
|
38614
|
+
clientId: draft.clientId,
|
|
38615
|
+
additional: draft.mode === "new-tab",
|
|
38616
|
+
split: draft.mode === "split"
|
|
38617
|
+
};
|
|
38618
|
+
if (draft.project.vcs === "jj")
|
|
38619
|
+
return draft.destination.path ? { ...common, vcs: "jj", path: draft.destination.path } : draft.worktreeName && draft.destination.revision ? { ...common, vcs: "jj", worktreeName: draft.worktreeName, revision: draft.destination.revision } : undefined;
|
|
38620
|
+
return draft.destination.branch ? { ...common, vcs: "git", branch: draft.destination.branch, ...draft.worktreeName ? { worktreeName: draft.worktreeName } : {} } : { ...common, vcs: "git", path: draft.destination.path };
|
|
38621
|
+
};
|
|
37633
38622
|
var changeMachine = (draft, machine) => draft.machine?.key === machine.key ? { ...draft, machine } : { machine, projectChoice: draft.projectChoice, mode: draft.mode };
|
|
37634
38623
|
var changeProjectChoice = (draft, projectChoice) => ({
|
|
37635
38624
|
...draft,
|
|
37636
38625
|
projectChoice,
|
|
37637
38626
|
project: undefined,
|
|
38627
|
+
clone: undefined,
|
|
37638
38628
|
destination: undefined,
|
|
37639
|
-
worktreeName: undefined
|
|
38629
|
+
worktreeName: undefined,
|
|
38630
|
+
sourcePath: undefined
|
|
37640
38631
|
});
|
|
37641
38632
|
var changeProject = (draft, candidate) => ({
|
|
37642
38633
|
...draft,
|
|
37643
38634
|
project: candidate,
|
|
37644
|
-
|
|
37645
|
-
|
|
38635
|
+
clone: undefined,
|
|
38636
|
+
destination: draft.project?.vcs === candidate.vcs && draft.project.commonDir === candidate.commonDir ? draft.destination : undefined,
|
|
38637
|
+
worktreeName: draft.project?.vcs === candidate.vcs && draft.project.commonDir === candidate.commonDir ? draft.worktreeName : undefined,
|
|
38638
|
+
sourcePath: candidate.vcs === "jj" && draft.project?.vcs === "jj" && draft.project.commonDir === candidate.commonDir ? draft.sourcePath : undefined
|
|
37646
38639
|
});
|
|
37647
38640
|
var changeDestination = (draft, candidate, worktreeName) => ({
|
|
37648
38641
|
...draft,
|
|
37649
38642
|
destination: candidate,
|
|
37650
38643
|
worktreeName: candidate.path ? undefined : worktreeName
|
|
37651
38644
|
});
|
|
37652
|
-
var selectWorktree = (draft, tree) =>
|
|
37653
|
-
|
|
38645
|
+
var selectWorktree = (draft, tree) => {
|
|
38646
|
+
if (!tree.path || tree.vcs === "jj" && !tree.present)
|
|
38647
|
+
throw new AppError({ message: `Workspace ${tree.vcs === "jj" ? tree.name : tree.path} is unavailable; inspect its registered location before opening` });
|
|
38648
|
+
return {
|
|
38649
|
+
...changeDestination(draft, {
|
|
38650
|
+
path: tree.path,
|
|
38651
|
+
label: tree.vcs === "jj" ? tree.name : tree.path.split("/").filter(Boolean).at(-1) ?? tree.path
|
|
38652
|
+
}),
|
|
38653
|
+
...tree.vcs === "jj" ? {
|
|
38654
|
+
sourcePath: tree.path,
|
|
38655
|
+
projectChoice: draft.projectChoice?.source && draft.projectChoice.source.hostId === draft.host?.hostId ? { ...draft.projectChoice, source: { ...draft.projectChoice.source, checkoutPath: tree.path } } : draft.projectChoice
|
|
38656
|
+
} : {}
|
|
38657
|
+
};
|
|
38658
|
+
};
|
|
38659
|
+
var typeWorktreeName = (draft, name, mainline) => ({
|
|
37654
38660
|
...draft,
|
|
37655
38661
|
worktreeName: name,
|
|
37656
|
-
destination: draft.destination
|
|
38662
|
+
destination: draft.destination && !draft.destination.path ? draft.destination : draft.project?.vcs === "jj" && !draft.clone && mainline ? { revision: mainline.revision.commitId, label: mainline.label } : undefined
|
|
37657
38663
|
});
|
|
37658
|
-
var
|
|
37659
|
-
var
|
|
38664
|
+
var selectRevision = (draft, choice) => changeDestination(draft, { revision: choice.revision.commitId, label: choice.label }, draft.worktreeName);
|
|
38665
|
+
var cloneInputFor = (draft) => {
|
|
38666
|
+
if (!draft.host || !draft.clone || !draft.session || !draft.clone.repo.startsWith("/"))
|
|
38667
|
+
return;
|
|
38668
|
+
if (draft.clone.vcs === "jj")
|
|
38669
|
+
return {
|
|
38670
|
+
vcs: "jj",
|
|
38671
|
+
source: {
|
|
38672
|
+
vcs: "jj",
|
|
38673
|
+
url: draft.clone.url,
|
|
38674
|
+
sourceHostId: draft.clone.sourceHostId,
|
|
38675
|
+
revisions: draft.clone.revisions,
|
|
38676
|
+
...draft.clone.revision ? { revision: draft.clone.revision } : {}
|
|
38677
|
+
},
|
|
38678
|
+
repo: draft.clone.repo,
|
|
38679
|
+
session: draft.session,
|
|
38680
|
+
clientId: draft.clientId,
|
|
38681
|
+
name: generatedName(draft),
|
|
38682
|
+
...draft.worktreeName ? { worktreeName: draft.worktreeName } : {},
|
|
38683
|
+
...draft.destination?.revision ? { revision: draft.destination.revision } : {}
|
|
38684
|
+
};
|
|
38685
|
+
if (!draft.destination?.branch)
|
|
38686
|
+
return;
|
|
38687
|
+
return {
|
|
38688
|
+
vcs: "git",
|
|
38689
|
+
source: {
|
|
38690
|
+
vcs: "git",
|
|
38691
|
+
url: draft.clone.url,
|
|
38692
|
+
sourceHostId: draft.clone.sourceHostId,
|
|
38693
|
+
branches: draft.clone.branches,
|
|
38694
|
+
branch: draft.clone.branch
|
|
38695
|
+
},
|
|
38696
|
+
repo: draft.clone.repo,
|
|
38697
|
+
session: draft.session,
|
|
38698
|
+
clientId: draft.clientId,
|
|
38699
|
+
name: generatedName(draft),
|
|
38700
|
+
branch: draft.destination.branch,
|
|
38701
|
+
branchMode: draft.clone.branches.includes(draft.destination.branch) ? "existing" : "create",
|
|
38702
|
+
...draft.worktreeName ? { worktreeName: draft.worktreeName } : {}
|
|
38703
|
+
};
|
|
38704
|
+
};
|
|
38705
|
+
var popup = (command, context3, origin2 = {}, preferredMachine) => exports_Effect.scoped(exports_Effect.suspend(() => {
|
|
37660
38706
|
let launchAcknowledged = false;
|
|
37661
38707
|
return exports_Effect.gen(function* () {
|
|
37662
38708
|
const terminal = yield* exports_Terminal.Terminal;
|
|
@@ -37667,20 +38713,23 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37667
38713
|
let focused = "project";
|
|
37668
38714
|
let error2;
|
|
37669
38715
|
let plan;
|
|
38716
|
+
let clonePlan;
|
|
38717
|
+
let cloneRoot = "";
|
|
38718
|
+
let cloneRoots = [];
|
|
37670
38719
|
let contextPath;
|
|
37671
38720
|
const resizePopup = yield* makePopupSizer;
|
|
37672
38721
|
let activeView;
|
|
37673
38722
|
let repaint;
|
|
37674
38723
|
const fitRequests = yield* exports_Queue.sliding(1);
|
|
37675
38724
|
yield* exports_Effect.forever(exports_Effect.gen(function* () {
|
|
37676
|
-
const { view, columns, rows, editing } = yield* exports_Queue.take(fitRequests);
|
|
37677
|
-
const warning = yield* resizePopup({ columns: 96, rows: popupTargetRows(view, columns, editing) }, { columns, rows });
|
|
38725
|
+
const { view, columns, rows: rows2, editing } = yield* exports_Queue.take(fitRequests);
|
|
38726
|
+
const warning = yield* resizePopup({ columns: 96, rows: popupTargetRows(view, columns, editing) }, { columns, rows: rows2 });
|
|
37678
38727
|
if (activeView !== view)
|
|
37679
38728
|
return;
|
|
37680
38729
|
const changed = view.fitWarning !== warning;
|
|
37681
38730
|
view.fitWarning = warning;
|
|
37682
38731
|
if (changed && repaint)
|
|
37683
|
-
yield* exports_Queue.offer(repaint, { columns, rows });
|
|
38732
|
+
yield* exports_Queue.offer(repaint, { columns, rows: rows2 });
|
|
37684
38733
|
})).pipe(exports_Effect.forkScoped);
|
|
37685
38734
|
const chooseField = exports_Effect.fnUntraced(function* (view, initialFocus) {
|
|
37686
38735
|
const terminal2 = yield* exports_Terminal.Terminal;
|
|
@@ -37697,9 +38746,9 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37697
38746
|
const prompt = exports_Prompt.Custom(initial, resized, {
|
|
37698
38747
|
render: (index2, action) => action._tag === "Submit" ? exports_Effect.succeed("") : exports_Effect.gen(function* () {
|
|
37699
38748
|
const columns = yield* terminal2.columns;
|
|
37700
|
-
const
|
|
37701
|
-
yield* exports_Queue.offer(fitRequests, { view, columns, rows, editing: false });
|
|
37702
|
-
return `\x1B[H\x1B[2J${renderFormFrame(view, fields[index2], false, columns,
|
|
38749
|
+
const rows2 = yield* terminal2.rows;
|
|
38750
|
+
yield* exports_Queue.offer(fitRequests, { view, columns, rows: rows2, editing: false });
|
|
38751
|
+
return `\x1B[H\x1B[2J${renderFormFrame(view, fields[index2], false, columns, rows2)}`;
|
|
37703
38752
|
}),
|
|
37704
38753
|
clear: () => exports_Effect.succeed(""),
|
|
37705
38754
|
process: (event, index2) => {
|
|
@@ -37708,6 +38757,8 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37708
38757
|
const { key: key5 } = event.input;
|
|
37709
38758
|
if (key5.name === "escape" || key5.ctrl && key5.name === "c")
|
|
37710
38759
|
return exports_Effect.succeed({ _tag: "Submit", value: "cancel" });
|
|
38760
|
+
if (key5.ctrl && key5.name === "s")
|
|
38761
|
+
return exports_Effect.succeed(view.submitDisabled ? { _tag: "Beep" } : { _tag: "Submit", value: "submit" });
|
|
37711
38762
|
if (key5.name === "enter" || key5.name === "return") {
|
|
37712
38763
|
const selected2 = fields[index2];
|
|
37713
38764
|
return exports_Effect.succeed(selected2 === "submit" && view.submitDisabled || view.rows.some((row) => row.id === selected2 && row.disabled) ? { _tag: "Beep" } : { _tag: "Submit", value: selected2 });
|
|
@@ -37732,14 +38783,14 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37732
38783
|
const result4 = yield* exports_Prompt.run(exports_Prompt.Custom({ text: "", selected: options.selected === undefined || options.selected < 0 ? null : options.selected }, resized, {
|
|
37733
38784
|
render: (state, action) => action._tag === "Submit" ? exports_Effect.succeed("") : exports_Effect.gen(function* () {
|
|
37734
38785
|
const columns = yield* terminal2.columns;
|
|
37735
|
-
const
|
|
38786
|
+
const rows2 = yield* terminal2.rows;
|
|
37736
38787
|
const view = activeView;
|
|
37737
38788
|
if (view)
|
|
37738
|
-
yield* exports_Queue.offer(fitRequests, { view, columns, rows, editing: true });
|
|
37739
|
-
const editor = renderInputChoice(options.message, state, options.choices, columns,
|
|
38789
|
+
yield* exports_Queue.offer(fitRequests, { view, columns, rows: rows2, editing: true });
|
|
38790
|
+
const editor = renderInputChoice(options.message, state, options.choices, columns, rows2, !process.env.NO_COLOR, options.selectionOnly);
|
|
37740
38791
|
if (!view)
|
|
37741
38792
|
return "";
|
|
37742
|
-
return `\x1B[H\x1B[2J${renderFormFrame(view, focused, true, columns,
|
|
38793
|
+
return `\x1B[H\x1B[2J${renderFormFrame(view, focused, true, columns, rows2)}${editor}`;
|
|
37743
38794
|
}),
|
|
37744
38795
|
clear: () => exports_Effect.succeed(""),
|
|
37745
38796
|
process: (event, state) => exports_Effect.succeed(event._tag === "Event" ? { _tag: "NextFrame", state } : advanceInputChoice(state, event.input, options.choices, options.selectionOnly))
|
|
@@ -37758,7 +38809,7 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37758
38809
|
return picked.value;
|
|
37759
38810
|
});
|
|
37760
38811
|
let projects = [];
|
|
37761
|
-
const focusClient = (clients) => clients.some((item) => item.id === draft.clientId) ? draft.clientId : draft.host?.local && clients.some((item) => item.id ===
|
|
38812
|
+
const focusClient = (clients) => clients.some((item) => item.id === draft.clientId) ? draft.clientId : draft.host?.local && clients.some((item) => item.id === origin2.clientId) ? origin2.clientId : clients.length === 1 ? clients[0]?.id : undefined;
|
|
37762
38813
|
const loadMachines = exports_Effect.gen(function* () {
|
|
37763
38814
|
const found = yield* exports_Effect.result(listMachines);
|
|
37764
38815
|
if (exports_Result.isFailure(found))
|
|
@@ -37768,40 +38819,82 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37768
38819
|
error2 = undefined;
|
|
37769
38820
|
}
|
|
37770
38821
|
});
|
|
37771
|
-
const
|
|
37772
|
-
|
|
37773
|
-
|
|
37774
|
-
|
|
37775
|
-
|
|
37776
|
-
|
|
37777
|
-
|
|
37778
|
-
|
|
37779
|
-
|
|
37780
|
-
|
|
37781
|
-
|
|
38822
|
+
const clonePath = (choice) => choice.name && choice.name !== "." && choice.name !== ".." && !/[/\\\p{Cc}\u202a-\u202e\u2066-\u2069]/u.test(choice.name) ? `${cloneRoot.replace(/\/$/, "")}/${choice.name}` : undefined;
|
|
38823
|
+
const known = (host, repository4, checkout) => ({
|
|
38824
|
+
name: repository4.name,
|
|
38825
|
+
source: {
|
|
38826
|
+
machineKey: host.key,
|
|
38827
|
+
hostId: host.hostId,
|
|
38828
|
+
repository: repository4,
|
|
38829
|
+
...repository4.vcs === "jj" && checkout?.vcs === "jj" && checkout.commonDir === repository4.commonDir ? { checkoutPath: checkout.path } : {}
|
|
38830
|
+
}
|
|
38831
|
+
});
|
|
38832
|
+
const proposeClone = exports_Effect.fnUntraced(function* (choice, host, repo) {
|
|
38833
|
+
const reference = choice.source;
|
|
38834
|
+
if (!reference)
|
|
38835
|
+
return yield* exports_Effect.fail(new AppError({ message: "Choose a known source project before cloning" }));
|
|
38836
|
+
const sourceMachine = machines.find((item) => item.key === reference.machineKey);
|
|
38837
|
+
if (!sourceMachine)
|
|
38838
|
+
return yield* exports_Effect.fail(new AppError({ message: "Source Rex machine is no longer registered" }));
|
|
38839
|
+
const sourceHost = yield* connectMachine(sourceMachine);
|
|
38840
|
+
if (sourceHost.hostId !== reference.hostId)
|
|
38841
|
+
return yield* exports_Effect.fail(new AppError({ message: "Source Rex host identity changed; select the project again" }));
|
|
38842
|
+
const source = yield* sourceForClone(sourceHost, command, reference.checkoutPath ?? reference.repository.path);
|
|
38843
|
+
draft = {
|
|
38844
|
+
...draft,
|
|
38845
|
+
projectChoice: choice,
|
|
38846
|
+
host,
|
|
38847
|
+
project: undefined,
|
|
38848
|
+
clone: { ...source, repo },
|
|
38849
|
+
destination: source.vcs === "git" && source.branch ? { branch: source.branch, label: source.branch } : undefined,
|
|
38850
|
+
worktreeName: undefined
|
|
38851
|
+
};
|
|
37782
38852
|
});
|
|
37783
|
-
const
|
|
37784
|
-
|
|
37785
|
-
|
|
38853
|
+
const cloneDestination2 = exports_Effect.fnUntraced(function* (choice, host) {
|
|
38854
|
+
let repo = clonePath(choice);
|
|
38855
|
+
if (!repo) {
|
|
38856
|
+
const picked = yield* inputChoice({
|
|
38857
|
+
message: "Project name is not a safe clone directory; type an absolute clone destination",
|
|
38858
|
+
choices: []
|
|
38859
|
+
});
|
|
38860
|
+
repo = picked.kind === "selected" ? picked.value : picked.text.trim();
|
|
38861
|
+
}
|
|
38862
|
+
if (!repo.startsWith("/"))
|
|
38863
|
+
return yield* exports_Effect.fail(new AppError({ message: "Clone destination must be an absolute path on this machine" }));
|
|
38864
|
+
yield* proposeClone(choice, host, repo);
|
|
37786
38865
|
});
|
|
37787
38866
|
const bindProject = exports_Effect.fnUntraced(function* (choice, host, available) {
|
|
37788
38867
|
const source = choice.source;
|
|
37789
|
-
let path = source?.machineKey === host.key && source.hostId === host.hostId ? source.repository.path : undefined;
|
|
38868
|
+
let path = source?.machineKey === host.key && source.hostId === host.hostId ? source.checkoutPath ?? source.repository.path : undefined;
|
|
37790
38869
|
if (!path && choice.path?.startsWith("/"))
|
|
37791
38870
|
path = choice.path;
|
|
38871
|
+
if (source && (source.machineKey !== host.key || source.hostId !== host.hostId)) {
|
|
38872
|
+
if (path)
|
|
38873
|
+
yield* proposeClone(choice, host, path);
|
|
38874
|
+
else
|
|
38875
|
+
yield* cloneDestination2(choice, host);
|
|
38876
|
+
return;
|
|
38877
|
+
}
|
|
37792
38878
|
if (!path) {
|
|
37793
38879
|
const directory = yield* inputChoice({
|
|
37794
|
-
message: `Project directory on ${host.label} (
|
|
38880
|
+
message: `Project directory on ${host.label} (existing checkout; absolute path)`,
|
|
37795
38881
|
choices: available.map((repo) => ({ value: repo.path, title: repo.name, description: repo.path }))
|
|
37796
38882
|
});
|
|
37797
38883
|
path = directory.kind === "selected" ? directory.value : directory.text.trim();
|
|
37798
38884
|
}
|
|
37799
38885
|
if (!path.startsWith("/"))
|
|
37800
38886
|
return yield* exports_Effect.fail(new AppError({ message: "Project directory must be an absolute path on this machine" }));
|
|
37801
|
-
const inspected = yield* inspectProject(host, command, path);
|
|
37802
|
-
if (
|
|
38887
|
+
const inspected = yield* exports_Effect.result(inspectProject(host, command, path));
|
|
38888
|
+
if (exports_Result.isFailure(inspected)) {
|
|
38889
|
+
if (choice.source && inspected.failure instanceof AppError && inspected.failure.message.startsWith("Project directory does not exist:")) {
|
|
38890
|
+
yield* proposeClone(choice, host, path);
|
|
38891
|
+
return;
|
|
38892
|
+
}
|
|
38893
|
+
return yield* exports_Effect.fail(inspected.failure);
|
|
38894
|
+
}
|
|
38895
|
+
if (source?.machineKey === host.key && source.hostId === host.hostId && (inspected.success.project.vcs !== source.repository.vcs || inspected.success.project.commonDir !== source.repository.commonDir))
|
|
37803
38896
|
return yield* exports_Effect.fail(new AppError({ message: "Project directory changed; select the exact project directory again" }));
|
|
37804
|
-
return inspected;
|
|
38897
|
+
return inspected.success;
|
|
37805
38898
|
});
|
|
37806
38899
|
const activate2 = exports_Effect.fnUntraced(function* (machine) {
|
|
37807
38900
|
const previousHostId = draft.host?.hostId;
|
|
@@ -37813,6 +38906,9 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37813
38906
|
draft = { machine, projectChoice: draft.projectChoice, mode: draft.mode };
|
|
37814
38907
|
sessions = [];
|
|
37815
38908
|
plan = undefined;
|
|
38909
|
+
clonePlan = undefined;
|
|
38910
|
+
cloneRoot = "";
|
|
38911
|
+
cloneRoots = [];
|
|
37816
38912
|
error2 = problem(connected.failure);
|
|
37817
38913
|
return;
|
|
37818
38914
|
}
|
|
@@ -37820,6 +38916,7 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37820
38916
|
draft = { machine, projectChoice: draft.projectChoice, mode: draft.mode };
|
|
37821
38917
|
sessions = [];
|
|
37822
38918
|
plan = undefined;
|
|
38919
|
+
clonePlan = undefined;
|
|
37823
38920
|
}
|
|
37824
38921
|
draft = { ...draft, host: connected.success };
|
|
37825
38922
|
const discovered = yield* exports_Effect.result(discover(connected.success, command, discoveredContext));
|
|
@@ -37827,26 +38924,37 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37827
38924
|
draft = { machine, projectChoice: draft.projectChoice, mode: draft.mode };
|
|
37828
38925
|
sessions = [];
|
|
37829
38926
|
plan = undefined;
|
|
38927
|
+
clonePlan = undefined;
|
|
38928
|
+
cloneRoot = "";
|
|
38929
|
+
cloneRoots = [];
|
|
37830
38930
|
error2 = problem(discovered.failure);
|
|
37831
38931
|
return;
|
|
37832
38932
|
}
|
|
37833
38933
|
const found = discovered.success;
|
|
38934
|
+
cloneRoot = found.cloneRoot;
|
|
38935
|
+
cloneRoots = found.roots;
|
|
37834
38936
|
projects = [
|
|
37835
38937
|
...projects.filter((item) => item.source?.machineKey !== machine.key || item.source.hostId !== connected.success.hostId),
|
|
37836
|
-
...found.projects.map((repo) => known(connected.success, repo))
|
|
38938
|
+
...found.projects.map((repo) => known(connected.success, repo, found.checkout))
|
|
37837
38939
|
];
|
|
37838
38940
|
sessions = found.sessions;
|
|
37839
38941
|
draft = {
|
|
37840
38942
|
...draft,
|
|
37841
|
-
|
|
38943
|
+
session: draft.session?.kind === "new" ? draft.session : sessions.some((item) => item.id === (draft.session?.kind === "existing" ? draft.session.id : undefined)) ? draft.session : connected.success.local && origin2.sessionId && sessions.some((item) => item.id === origin2.sessionId) ? { kind: "existing", id: origin2.sessionId } : sessions.length === 1 ? { kind: "existing", id: sessions[0].id } : undefined,
|
|
37842
38944
|
clientId: focusClient(found.clients)
|
|
37843
38945
|
};
|
|
37844
38946
|
if (!draft.projectChoice && found.checkout && discoveredContext) {
|
|
37845
38947
|
const inspected = yield* exports_Effect.result(inspectProject(connected.success, command, found.checkout.path));
|
|
38948
|
+
if (exports_Result.isFailure(inspected)) {
|
|
38949
|
+
error2 = problem(inspected.failure);
|
|
38950
|
+
return;
|
|
38951
|
+
}
|
|
37846
38952
|
if (exports_Result.isSuccess(inspected)) {
|
|
37847
|
-
draft = changeProjectChoice(draft, known(connected.success, inspected.success.project));
|
|
38953
|
+
draft = changeProjectChoice(draft, known(connected.success, inspected.success.project, inspected.success.checkout));
|
|
37848
38954
|
draft = changeProject(draft, inspected.success.project);
|
|
37849
|
-
|
|
38955
|
+
if (inspected.success.checkout.vcs === "jj")
|
|
38956
|
+
draft = { ...draft, sourcePath: inspected.success.checkout.path };
|
|
38957
|
+
const tree = inspected.success.worktrees.find((item) => item.path === found.checkout?.path && (item.vcs === "jj" ? item.present : !item.bare && !item.prunable));
|
|
37850
38958
|
if (tree)
|
|
37851
38959
|
draft = selectWorktree(draft, tree);
|
|
37852
38960
|
}
|
|
@@ -37857,19 +38965,23 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37857
38965
|
error2 = problem(inspected.failure);
|
|
37858
38966
|
return;
|
|
37859
38967
|
}
|
|
37860
|
-
|
|
38968
|
+
if (inspected.success) {
|
|
38969
|
+
draft = changeProject(draft, inspected.success.project);
|
|
38970
|
+
if (inspected.success.checkout.vcs === "jj" && !draft.sourcePath)
|
|
38971
|
+
draft = { ...draft, sourcePath: inspected.success.checkout.path };
|
|
38972
|
+
if (!draft.destination) {
|
|
38973
|
+
const checkoutPath = inspected.success.checkout.path;
|
|
38974
|
+
const tree = inspected.success.worktrees.find((item) => item.path === checkoutPath && (item.vcs === "jj" ? item.present : !item.bare && !item.prunable));
|
|
38975
|
+
if (tree)
|
|
38976
|
+
draft = selectWorktree(draft, tree);
|
|
38977
|
+
}
|
|
38978
|
+
}
|
|
37861
38979
|
}
|
|
37862
38980
|
error2 = undefined;
|
|
37863
|
-
yield* refresh;
|
|
37864
38981
|
});
|
|
37865
38982
|
const formView = (initializing = false) => {
|
|
37866
|
-
const
|
|
37867
|
-
{
|
|
37868
|
-
id: "project",
|
|
37869
|
-
label: "Project",
|
|
37870
|
-
value: draft.projectChoice?.name ?? "Choose a project",
|
|
37871
|
-
detail: draft.project?.path ?? (draft.projectChoice ? "Choose its directory on this machine" : undefined)
|
|
37872
|
-
},
|
|
38983
|
+
const rows2 = [
|
|
38984
|
+
{ id: "project", label: "Project", value: draft.projectChoice?.name ?? "Choose a project" },
|
|
37873
38985
|
{
|
|
37874
38986
|
id: "machine",
|
|
37875
38987
|
label: "Machine",
|
|
@@ -37878,32 +38990,57 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37878
38990
|
},
|
|
37879
38991
|
{
|
|
37880
38992
|
id: "destination",
|
|
37881
|
-
label: "
|
|
37882
|
-
value: draft.worktreeName ?? draft.destination?.label ?? "Choose
|
|
37883
|
-
detail:
|
|
37884
|
-
disabled: !draft.host || !draft.project
|
|
37885
|
-
},
|
|
37886
|
-
{
|
|
37887
|
-
id: "branch",
|
|
37888
|
-
label: "Branch",
|
|
37889
|
-
value: draft.destination?.branch ?? (draft.destination?.path ? plan?.branch ?? "Existing checkout" : "Select or type branch"),
|
|
37890
|
-
disabled: !draft.host || !draft.project || !(draft.worktreeName || draft.destination?.path)
|
|
38993
|
+
label: draft.clone ? "Clone to" : draft.project?.vcs === "jj" ? "Workspace" : "Checkout",
|
|
38994
|
+
value: draft.clone?.repo ?? (draft.project?.vcs === "jj" && !draft.destination?.path ? draft.worktreeName : undefined) ?? draft.destination?.label ?? (draft.project?.vcs === "jj" ? "Choose workspace or type new name" : "Choose checkout or type branch"),
|
|
38995
|
+
detail: draft.clone?.repo ?? draft.destination?.path,
|
|
38996
|
+
disabled: !draft.host || !(draft.project || draft.clone)
|
|
37891
38997
|
},
|
|
37892
38998
|
{
|
|
37893
38999
|
id: "session",
|
|
37894
39000
|
label: "Session",
|
|
37895
|
-
value: sessions.find((s) => s.id === draft.
|
|
37896
|
-
detail: draft.
|
|
39001
|
+
value: draft.session?.kind === "new" ? `New: ${draft.session.name}` : sessions.find((s) => s.id === (draft.session?.kind === "existing" ? draft.session.id : undefined))?.label ?? (draft.session?.kind === "existing" ? draft.session.id : "Choose or type new session"),
|
|
39002
|
+
detail: draft.session?.kind === "existing" ? draft.session.id : draft.session?.kind === "new" ? "Create on confirmation" : undefined,
|
|
37897
39003
|
disabled: !draft.host
|
|
37898
|
-
}
|
|
37899
|
-
{ id: "mode", label: "Mode", value: draft.mode === "auto" ? "Reuse matching tab, otherwise new tab" : draft.mode === "new-tab" ? "Always new tab" : "Split matching tab, otherwise new tab", disabled: !draft.host }
|
|
39004
|
+
}
|
|
37900
39005
|
];
|
|
39006
|
+
if (draft.project?.vcs === "jj" && !draft.destination?.path || draft.clone?.vcs === "jj")
|
|
39007
|
+
rows2.push({
|
|
39008
|
+
id: "branch",
|
|
39009
|
+
label: "Start from",
|
|
39010
|
+
value: draft.destination?.revision ? draft.destination.label : draft.clone ? "Cloned default" : "Select or type revision",
|
|
39011
|
+
disabled: !draft.host || !!draft.project && !draft.worktreeName
|
|
39012
|
+
});
|
|
39013
|
+
if (draft.clone?.vcs === "git")
|
|
39014
|
+
rows2.push({ id: "branch", label: "Branch", value: draft.destination?.branch ?? "Select or type branch", disabled: !draft.host });
|
|
39015
|
+
if (draft.clone || draft.project?.vcs === "git" && draft.destination?.branch && !draft.destination.path)
|
|
39016
|
+
rows2.push({
|
|
39017
|
+
id: "checkoutName",
|
|
39018
|
+
label: draft.clone?.vcs === "jj" ? "Workspace" : "Directory",
|
|
39019
|
+
value: draft.worktreeName ?? (draft.clone?.vcs === "jj" ? "Use cloned default workspace" : "Default (derived from branch)"),
|
|
39020
|
+
disabled: !draft.host
|
|
39021
|
+
});
|
|
39022
|
+
if (!draft.clone)
|
|
39023
|
+
rows2.push({
|
|
39024
|
+
id: "mode",
|
|
39025
|
+
label: "Mode",
|
|
39026
|
+
value: draft.mode === "auto" ? "Reuse matching tab, otherwise new tab" : draft.mode === "new-tab" ? "Always new tab" : "Split matching tab, otherwise new tab",
|
|
39027
|
+
disabled: !draft.host
|
|
39028
|
+
});
|
|
39029
|
+
const safeOpen = !draft.clone && !!draft.destination?.path && draft.session?.kind === "existing";
|
|
37901
39030
|
return {
|
|
37902
|
-
rows:
|
|
37903
|
-
submitLabel: plan?.label ?? "Open
|
|
37904
|
-
submitDisabled: initializing || !draft.host || !
|
|
37905
|
-
notice: [
|
|
37906
|
-
|
|
39031
|
+
rows: rows2.map((row) => ({ ...row, disabled: initializing || row.disabled })),
|
|
39032
|
+
submitLabel: clonePlan?.label ?? plan?.label ?? (draft.clone ? "Review clone" : safeOpen ? "Open checkout" : "Review & open"),
|
|
39033
|
+
submitDisabled: initializing || !draft.host || !(cloneInputFor(draft) || inputFor(draft)),
|
|
39034
|
+
notice: [
|
|
39035
|
+
clonePlan || plan ? "Review this action; submit again to launch" : draft.clone ? "Only pushed history transfers" : undefined,
|
|
39036
|
+
plan ? `Destination: ${plan.path}` : undefined,
|
|
39037
|
+
clonePlan?.detail,
|
|
39038
|
+
clonePlan?.vcs === "jj" ? `Start from: ${draft.destination?.revision ? `${draft.destination.label} (${draft.destination.revision})` : "cloned default"}` : undefined,
|
|
39039
|
+
clonePlan?.warning,
|
|
39040
|
+
plan?.detail,
|
|
39041
|
+
plan?.warning
|
|
39042
|
+
].filter(Boolean).join(" \xB7 ") || undefined,
|
|
39043
|
+
error: initializing ? undefined : error2 ?? (!draft.projectChoice ? "Select a project" : !draft.machine ? "Select a Rex machine" : !draft.host ? "Connect to the selected machine and install its worktrees helper if missing" : !(draft.project || draft.clone) ? "Select the exact project directory on this machine" : !draft.destination && draft.project?.vcs !== "jj" && draft.clone?.vcs !== "jj" ? "Select a branch" : draft.project?.vcs === "jj" && (!draft.worktreeName && !draft.destination?.path || !!draft.worktreeName && !draft.destination?.revision) ? "Choose an existing workspace or a new workspace name and starting revision" : !draft.session ? "Choose an existing Rex session or type a new name" : undefined),
|
|
37907
39044
|
fitWarning: activeView?.fitWarning
|
|
37908
39045
|
};
|
|
37909
39046
|
};
|
|
@@ -37930,8 +39067,42 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37930
39067
|
if (action === "cancel")
|
|
37931
39068
|
return;
|
|
37932
39069
|
if (action === "submit") {
|
|
39070
|
+
const cloneInput = cloneInputFor(draft);
|
|
39071
|
+
if (!draft.host || !(cloneInput || inputFor(draft)))
|
|
39072
|
+
continue;
|
|
39073
|
+
if (cloneInput) {
|
|
39074
|
+
const current2 = yield* exports_Effect.result(reviewClone(draft.host, command, cloneInput));
|
|
39075
|
+
if (exports_Result.isFailure(current2)) {
|
|
39076
|
+
error2 = problem(current2.failure);
|
|
39077
|
+
clonePlan = undefined;
|
|
39078
|
+
continue;
|
|
39079
|
+
}
|
|
39080
|
+
if (!clonePlan || !sameClonePlan(current2.success, clonePlan)) {
|
|
39081
|
+
error2 = clonePlan ? "Clone destination or Rex target changed; review the updated URL and destination before submitting again" : undefined;
|
|
39082
|
+
clonePlan = current2.success;
|
|
39083
|
+
continue;
|
|
39084
|
+
}
|
|
39085
|
+
const launched2 = yield* exports_Effect.result(submitClone(draft.host, command, cloneInput, clonePlan));
|
|
39086
|
+
if (exports_Result.isFailure(launched2)) {
|
|
39087
|
+
launchAcknowledged = true;
|
|
39088
|
+
yield* acknowledge("Clone needs inspection", [
|
|
39089
|
+
problem(launched2.failure),
|
|
39090
|
+
`Destination: ${clonePlan.repo}`,
|
|
39091
|
+
"A clone or Rex tab may already exist. Inspect the destination and session before opening again."
|
|
39092
|
+
], "error");
|
|
39093
|
+
return yield* exports_Effect.fail(launched2.failure);
|
|
39094
|
+
}
|
|
39095
|
+
if (launched2.success.warning)
|
|
39096
|
+
yield* acknowledge("Clone task submitted with warning", [
|
|
39097
|
+
`Session: ${launched2.success.sessionId}`,
|
|
39098
|
+
`Destination: ${launched2.success.repo}`,
|
|
39099
|
+
"The clone task was created; Rex may not have focused its tab. Inspect the session before opening again.",
|
|
39100
|
+
launched2.success.warning
|
|
39101
|
+
], "warning");
|
|
39102
|
+
return;
|
|
39103
|
+
}
|
|
37933
39104
|
const input = inputFor(draft);
|
|
37934
|
-
if (!
|
|
39105
|
+
if (!input)
|
|
37935
39106
|
continue;
|
|
37936
39107
|
const current = yield* exports_Effect.result(review(draft.host, command, input));
|
|
37937
39108
|
if (exports_Result.isFailure(current)) {
|
|
@@ -37939,11 +39110,19 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37939
39110
|
plan = undefined;
|
|
37940
39111
|
continue;
|
|
37941
39112
|
}
|
|
37942
|
-
if (!sameLaunchPlan(current.success, plan)) {
|
|
37943
|
-
plan = current.success;
|
|
39113
|
+
if (plan && !sameLaunchPlan(current.success, plan)) {
|
|
37944
39114
|
error2 = "Destination or Rex target changed; review the updated action before submitting again";
|
|
39115
|
+
plan = current.success;
|
|
37945
39116
|
continue;
|
|
37946
39117
|
}
|
|
39118
|
+
if (!plan) {
|
|
39119
|
+
const safeOpen = !!draft.destination?.path && draft.session?.kind === "existing" && current.success.checkout === "existing" && current.success.path === draft.destination.path && safeDisplayText(draft.destination.path) === draft.destination.path && !current.success.detail && !current.success.warning && !view.fitWarning && naturalFormRows(view, yield* terminal.columns) + 1 <= (yield* terminal.rows);
|
|
39120
|
+
plan = current.success;
|
|
39121
|
+
if (!safeOpen) {
|
|
39122
|
+
error2 = undefined;
|
|
39123
|
+
continue;
|
|
39124
|
+
}
|
|
39125
|
+
}
|
|
37947
39126
|
const launched = yield* exports_Effect.result(submit(draft.host, command, input, plan));
|
|
37948
39127
|
if (exports_Result.isFailure(launched)) {
|
|
37949
39128
|
launchAcknowledged = true;
|
|
@@ -37959,13 +39138,14 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37959
39138
|
`Session: ${launched.success.sessionId}`,
|
|
37960
39139
|
`Destination: ${launched.success.path}`,
|
|
37961
39140
|
`Action: ${launched.success.action}`,
|
|
37962
|
-
launched.success.pending ?
|
|
37963
|
-
...[plan.warning, launched.success.warning].filter((line) => !!line)
|
|
39141
|
+
launched.success.pending ? `Task submitted; ${plan.vcs === "jj" ? "JJ" : "Git"} setup may still be running.` : "Existing task focused.",
|
|
39142
|
+
...new Set([plan.warning, launched.success.warning].filter((line) => !!line))
|
|
37964
39143
|
], "warning");
|
|
37965
39144
|
return;
|
|
37966
39145
|
}
|
|
37967
39146
|
if (view.rows.find((row) => row.id === action)?.disabled)
|
|
37968
39147
|
continue;
|
|
39148
|
+
error2 = undefined;
|
|
37969
39149
|
const editing = yield* exports_Effect.result(exports_Effect.gen(function* () {
|
|
37970
39150
|
if (action === "machine") {
|
|
37971
39151
|
yield* loadMachines;
|
|
@@ -37992,84 +39172,201 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
37992
39172
|
const host = draft.host;
|
|
37993
39173
|
if (host) {
|
|
37994
39174
|
const found = yield* discover(host, command);
|
|
39175
|
+
cloneRoots = found.roots;
|
|
37995
39176
|
const inspected = yield* bindProject(choice, host, found.projects);
|
|
37996
|
-
|
|
37997
|
-
|
|
37998
|
-
|
|
39177
|
+
if (inspected) {
|
|
39178
|
+
draft = changeProjectChoice(draft, choice);
|
|
39179
|
+
draft = changeProject(draft, inspected.project);
|
|
39180
|
+
if (inspected.checkout.vcs === "jj")
|
|
39181
|
+
draft = { ...draft, sourcePath: inspected.checkout.path };
|
|
39182
|
+
const tree = inspected.worktrees.find((item) => item.path === inspected.checkout.path && (item.vcs === "jj" ? item.present : !item.bare && !item.prunable));
|
|
39183
|
+
if (tree)
|
|
39184
|
+
draft = selectWorktree(draft, tree);
|
|
39185
|
+
}
|
|
39186
|
+
projects = [
|
|
39187
|
+
...projects.filter((item) => item.source?.machineKey !== host.key || item.source.hostId !== host.hostId),
|
|
39188
|
+
...found.projects.map((repo) => known(host, repo, found.checkout))
|
|
39189
|
+
];
|
|
37999
39190
|
sessions = found.sessions;
|
|
38000
|
-
if (!sessions.some((item) => item.id === draft.
|
|
38001
|
-
draft = { ...draft,
|
|
39191
|
+
if (draft.session?.kind === "existing" && !sessions.some((item) => item.id === (draft.session?.kind === "existing" ? draft.session.id : undefined)))
|
|
39192
|
+
draft = { ...draft, session: sessions.length === 1 ? { kind: "existing", id: sessions[0].id } : undefined };
|
|
38002
39193
|
draft = { ...draft, clientId: focusClient(found.clients) };
|
|
38003
39194
|
} else
|
|
38004
39195
|
draft = changeProjectChoice(draft, choice);
|
|
38005
39196
|
} else if (action === "destination") {
|
|
38006
|
-
if (!draft.host || !draft.project)
|
|
39197
|
+
if (!draft.host || !(draft.project || draft.clone))
|
|
38007
39198
|
return yield* exports_Effect.fail(new AppError({ message: "Select a project and machine before choosing a worktree" }));
|
|
38008
|
-
|
|
38009
|
-
|
|
38010
|
-
|
|
38011
|
-
|
|
38012
|
-
|
|
38013
|
-
|
|
38014
|
-
|
|
38015
|
-
|
|
38016
|
-
|
|
38017
|
-
|
|
38018
|
-
|
|
38019
|
-
|
|
39199
|
+
if (draft.clone) {
|
|
39200
|
+
const clone = draft.clone;
|
|
39201
|
+
const picked = yield* inputChoice({
|
|
39202
|
+
message: "Clone to (absolute destination path on selected machine)",
|
|
39203
|
+
choices: [
|
|
39204
|
+
{ value: clone.repo, title: "Current clone destination", description: clone.repo },
|
|
39205
|
+
...cloneRoots.map((root) => ({
|
|
39206
|
+
value: `${root.replace(/\/$/, "")}/${draft.projectChoice?.name ?? "project"}`,
|
|
39207
|
+
title: "Configured root suggestion",
|
|
39208
|
+
description: `${root.replace(/\/$/, "")}/${draft.projectChoice?.name ?? "project"}`
|
|
39209
|
+
}))
|
|
39210
|
+
]
|
|
39211
|
+
});
|
|
39212
|
+
const repo = (picked.kind === "selected" ? picked.value : picked.text).trim();
|
|
39213
|
+
if (!repo.startsWith("/"))
|
|
39214
|
+
return yield* exports_Effect.fail(new AppError({ message: "Clone destination must be an absolute path on this machine" }));
|
|
39215
|
+
draft = { ...draft, clone: { ...clone, repo } };
|
|
38020
39216
|
} else {
|
|
38021
|
-
const
|
|
38022
|
-
|
|
38023
|
-
|
|
38024
|
-
const
|
|
38025
|
-
|
|
38026
|
-
|
|
38027
|
-
|
|
38028
|
-
|
|
38029
|
-
|
|
39217
|
+
const found = yield* inspectWorktrees(draft.host, command, draft.project.vcs === "jj" ? draft.sourcePath ?? draft.project.path : draft.project.path);
|
|
39218
|
+
const trees = found.worktrees.filter((tree) => tree.vcs === "jj" || !tree.bare && !tree.prunable);
|
|
39219
|
+
const git2 = draft.project.vcs === "git";
|
|
39220
|
+
const picked = yield* inputChoice({
|
|
39221
|
+
message: git2 ? "Checkout (select exact worktree or branch, or type new branch)" : "Workspace (select existing, Clone this project, or type new workspace name)",
|
|
39222
|
+
choices: [
|
|
39223
|
+
...trees.map((tree) => ({
|
|
39224
|
+
value: tree,
|
|
39225
|
+
title: tree.vcs === "jj" ? tree.name : tree.path.split("/").filter(Boolean).at(-1) ?? tree.path,
|
|
39226
|
+
description: tree.vcs === "jj" ? tree.present && tree.path ? `${tree.changeId.slice(0, 12)} \xB7 ${tree.path}` : `Unavailable \xB7 ${tree.path ?? "location unknown"}` : `${tree.branch ?? "Detached HEAD"} \xB7 ${tree.path}`
|
|
39227
|
+
})),
|
|
39228
|
+
...git2 ? found.branches.map((branch) => ({
|
|
39229
|
+
value: { kind: "branch", value: branch },
|
|
39230
|
+
title: `Branch: ${branch}`,
|
|
39231
|
+
description: trees.find((tree) => tree.vcs === "git" && tree.branch === branch)?.path ?? "Free branch \u2014 attach new checkout"
|
|
39232
|
+
})) : [],
|
|
39233
|
+
...draft.projectChoice?.source ? [{
|
|
39234
|
+
value: "clone",
|
|
39235
|
+
title: "Clone this project\u2026",
|
|
39236
|
+
description: clonePath(draft.projectChoice) ? `Propose ${clonePath(draft.projectChoice)} \xB7 only pushed history transfers` : "Choose an absolute clone destination \xB7 only pushed history transfers"
|
|
39237
|
+
}] : []
|
|
39238
|
+
]
|
|
39239
|
+
});
|
|
39240
|
+
if (picked.kind === "selected") {
|
|
39241
|
+
if (picked.value === "clone")
|
|
39242
|
+
yield* cloneDestination2(draft.projectChoice, draft.host);
|
|
39243
|
+
else if ("kind" in picked.value) {
|
|
39244
|
+
const branch = picked.value.value;
|
|
39245
|
+
const existing = trees.find((tree) => tree.vcs === "git" && tree.branch === branch);
|
|
39246
|
+
draft = existing ? selectWorktree(draft, existing) : changeDestination(draft, { branch, label: branch }, draft.worktreeName);
|
|
39247
|
+
} else {
|
|
39248
|
+
if (picked.value.vcs === "jj" && (!picked.value.present || !picked.value.path))
|
|
39249
|
+
return yield* exports_Effect.fail(new AppError({ message: `Workspace ${picked.value.name} is unavailable; inspect its registered location before opening` }));
|
|
39250
|
+
draft = selectWorktree(draft, picked.value);
|
|
39251
|
+
}
|
|
39252
|
+
} else {
|
|
39253
|
+
const name = picked.text.trim();
|
|
39254
|
+
if (!name || name.startsWith("-") && git2 || /[\p{ASCII}&&\p{Cc}]/v.test(name) || !git2 && (name.startsWith("/") || name.split(/[\\/]/).some((part) => !part || part === "." || part === "..")))
|
|
39255
|
+
return yield* exports_Effect.fail(new AppError({ message: git2 ? "Branch name must be a valid Git branch" : "Invalid workspace name" }));
|
|
39256
|
+
if (git2) {
|
|
39257
|
+
const existing = trees.find((tree) => tree.vcs === "git" && tree.branch === name);
|
|
39258
|
+
draft = existing ? selectWorktree(draft, existing) : changeDestination(draft, { branch: name, label: name }, draft.worktreeName);
|
|
39259
|
+
} else
|
|
39260
|
+
draft = typeWorktreeName(draft, name, found.revisions.find((choice) => choice.expression === "trunk()"));
|
|
39261
|
+
}
|
|
38030
39262
|
}
|
|
38031
|
-
} else if (action === "
|
|
38032
|
-
if (!draft.host || !draft.project)
|
|
38033
|
-
return yield* exports_Effect.fail(new AppError({ message: "Select a project and machine before choosing a branch" }));
|
|
38034
|
-
const found = yield* inspectWorktrees(draft.host, command, draft.project.path);
|
|
39263
|
+
} else if (action === "checkoutName") {
|
|
38035
39264
|
const picked = yield* inputChoice({
|
|
38036
|
-
message: "
|
|
38037
|
-
choices:
|
|
38038
|
-
value:
|
|
38039
|
-
title:
|
|
38040
|
-
|
|
38041
|
-
}))
|
|
39265
|
+
message: draft.clone?.vcs === "jj" ? "Optional separate workspace name" : "Optional custom checkout directory name",
|
|
39266
|
+
choices: [
|
|
39267
|
+
{ value: null, title: "Use default", description: "No separate custom name" },
|
|
39268
|
+
...draft.worktreeName ? [{ value: draft.worktreeName, title: "Current custom name" }] : []
|
|
39269
|
+
]
|
|
38042
39270
|
});
|
|
38043
|
-
|
|
38044
|
-
|
|
38045
|
-
|
|
38046
|
-
|
|
38047
|
-
|
|
39271
|
+
if (picked.kind === "selected" && picked.value === null)
|
|
39272
|
+
draft = { ...draft, worktreeName: undefined };
|
|
39273
|
+
else {
|
|
39274
|
+
const name = (picked.kind === "selected" ? picked.value : picked.text).trim();
|
|
39275
|
+
if (!name || /[\p{ASCII}&&\p{Cc}]/v.test(name) || name.split(/[\\/]/).some((part) => !part || part === "." || part === ".."))
|
|
39276
|
+
return yield* exports_Effect.fail(new AppError({ message: "Invalid custom checkout name" }));
|
|
39277
|
+
draft = { ...draft, worktreeName: name };
|
|
39278
|
+
}
|
|
39279
|
+
} else if (action === "branch") {
|
|
39280
|
+
if (!draft.host || !(draft.project || draft.clone))
|
|
39281
|
+
return yield* exports_Effect.fail(new AppError({ message: "Select a project and machine before choosing a base or branch" }));
|
|
39282
|
+
const jjClone = draft.clone?.vcs === "jj" ? draft.clone : undefined;
|
|
39283
|
+
if (draft.project?.vcs === "jj" || jjClone) {
|
|
39284
|
+
if (draft.destination?.path)
|
|
39285
|
+
return yield* exports_Effect.fail(new AppError({ message: "Opening an existing workspace does not change its revision" }));
|
|
39286
|
+
const found = jjClone ? undefined : yield* inspectWorktrees(draft.host, command, draft.sourcePath ?? draft.project.path);
|
|
39287
|
+
const revisions = jjClone ? jjClone.revisions : found.revisions;
|
|
39288
|
+
const picked = yield* inputChoice({
|
|
39289
|
+
message: jjClone ? "Start from source revision (or cloned default)" : "Start from revision for new workspace",
|
|
39290
|
+
choices: [
|
|
39291
|
+
...jjClone ? [{ value: null, title: "Cloned default", description: "Use the clone's native default" }] : [],
|
|
39292
|
+
...revisions.map((choice) => ({
|
|
39293
|
+
value: choice,
|
|
39294
|
+
title: choice.label,
|
|
39295
|
+
description: `${choice.expression} \xB7 ${choice.revision.commitId.slice(0, 12)}`
|
|
39296
|
+
}))
|
|
39297
|
+
]
|
|
39298
|
+
});
|
|
39299
|
+
if (picked.kind === "selected" && picked.value === null)
|
|
39300
|
+
draft = { ...draft, destination: undefined };
|
|
39301
|
+
else {
|
|
39302
|
+
let choice;
|
|
39303
|
+
if (picked.kind === "selected")
|
|
39304
|
+
choice = picked.value;
|
|
39305
|
+
else {
|
|
39306
|
+
const expression = picked.text.trim();
|
|
39307
|
+
if (!expression)
|
|
39308
|
+
return yield* exports_Effect.fail(new AppError({ message: "A singular starting revision is required" }));
|
|
39309
|
+
let sourceHost = draft.host;
|
|
39310
|
+
let repo = draft.sourcePath ?? draft.project?.path;
|
|
39311
|
+
if (jjClone) {
|
|
39312
|
+
const reference = draft.projectChoice?.source;
|
|
39313
|
+
const machine = machines.find((item) => item.key === reference?.machineKey);
|
|
39314
|
+
if (!reference || !machine)
|
|
39315
|
+
return yield* exports_Effect.fail(new AppError({ message: "Clone source machine is no longer registered" }));
|
|
39316
|
+
sourceHost = yield* connectMachine(machine);
|
|
39317
|
+
if (sourceHost.hostId !== reference.hostId || sourceHost.hostId !== jjClone.sourceHostId)
|
|
39318
|
+
return yield* exports_Effect.fail(new AppError({ message: "Clone source host identity changed; reselect the project" }));
|
|
39319
|
+
repo = reference.checkoutPath ?? reference.repository.path;
|
|
39320
|
+
}
|
|
39321
|
+
const revision = yield* inspectRevision(sourceHost, command, repo, expression);
|
|
39322
|
+
choice = { expression, label: expression, revision };
|
|
39323
|
+
}
|
|
39324
|
+
draft = selectRevision(draft, choice);
|
|
39325
|
+
if (jjClone)
|
|
39326
|
+
draft = { ...draft, clone: { ...jjClone, revision: choice.revision } };
|
|
39327
|
+
}
|
|
39328
|
+
} else if (draft.clone?.vcs === "git") {
|
|
39329
|
+
const picked = yield* inputChoice({
|
|
39330
|
+
message: "Branch (select source branch or type new branch; only pushed history transfers)",
|
|
39331
|
+
choices: draft.clone.branches.map((branch2) => ({
|
|
39332
|
+
value: branch2,
|
|
39333
|
+
title: branch2,
|
|
39334
|
+
description: "Use this branch from the cloned origin"
|
|
39335
|
+
}))
|
|
39336
|
+
});
|
|
39337
|
+
const branch = picked.kind === "selected" ? picked.value : picked.text.trim();
|
|
39338
|
+
if (!branch || branch.startsWith("-") || /[\p{ASCII}&&\p{Cc}]/v.test(branch))
|
|
39339
|
+
return yield* exports_Effect.fail(new AppError({ message: "Branch name must be a valid Git branch" }));
|
|
39340
|
+
draft = { ...draft, destination: { branch, label: branch } };
|
|
39341
|
+
}
|
|
38048
39342
|
} else if (action === "session") {
|
|
38049
39343
|
if (!draft.host)
|
|
38050
39344
|
return yield* exports_Effect.fail(new AppError({ message: "Select a machine before choosing a session" }));
|
|
38051
39345
|
const found = yield* discover(draft.host, command);
|
|
38052
39346
|
sessions = found.sessions;
|
|
38053
|
-
if (!sessions.length)
|
|
38054
|
-
return yield* exports_Effect.fail(new AppError({ message: "No Rex sessions available on selected machine" }));
|
|
38055
39347
|
draft = { ...draft, clientId: focusClient(found.clients) };
|
|
38056
|
-
|
|
39348
|
+
const picked = yield* inputChoice({
|
|
39349
|
+
message: "Session (select existing or type new name)",
|
|
39350
|
+
choices: sessions.map((item) => ({ value: item.id, title: item.label, description: item.id }))
|
|
39351
|
+
});
|
|
39352
|
+
draft = { ...draft, session: picked.kind === "selected" ? { kind: "existing", id: picked.value } : { kind: "new", name: picked.text } };
|
|
38057
39353
|
} else if (action === "mode") {
|
|
38058
|
-
draft = {
|
|
38059
|
-
|
|
38060
|
-
|
|
38061
|
-
|
|
38062
|
-
|
|
39354
|
+
draft = {
|
|
39355
|
+
...draft,
|
|
39356
|
+
mode: yield* choose("Open mode", [
|
|
39357
|
+
selected("auto", draft.mode === "auto", "Reuse matching tab", "Focus existing task, otherwise open new tab"),
|
|
39358
|
+
selected("new-tab", draft.mode === "new-tab", "Always new tab"),
|
|
39359
|
+
selected("split", draft.mode === "split", "Split matching task", "Opens new tab when no live target exists")
|
|
39360
|
+
])
|
|
39361
|
+
};
|
|
38063
39362
|
}
|
|
38064
39363
|
}));
|
|
38065
39364
|
if (exports_Result.isFailure(editing)) {
|
|
38066
39365
|
if (!exports_Terminal.isQuitError(editing.failure))
|
|
38067
39366
|
error2 = problem(editing.failure);
|
|
38068
39367
|
} else {
|
|
38069
|
-
|
|
38070
|
-
|
|
38071
|
-
yield* refresh;
|
|
38072
|
-
}
|
|
39368
|
+
plan = undefined;
|
|
39369
|
+
clonePlan = undefined;
|
|
38073
39370
|
}
|
|
38074
39371
|
}
|
|
38075
39372
|
}).pipe(exports_Effect.catchCause((cause) => exports_Cause.hasInterrupts(cause) || launchAcknowledged ? exports_Effect.failCause(cause) : acknowledge("Could not open worktrees", [exports_Cause.pretty(cause)], "error").pipe(exports_Effect.andThen(exports_Effect.failCause(cause)))));
|
|
@@ -38077,14 +39374,18 @@ var popup = (command, context3, origin = {}, preferredMachine) => exports_Effect
|
|
|
38077
39374
|
|
|
38078
39375
|
// src/main.ts
|
|
38079
39376
|
var compiled = true;
|
|
38080
|
-
var help = `rex-worktrees \u2014 Git worktrees on existing Rex machines
|
|
38081
|
-
setup [--bin /absolute/path/rex-worktrees]
|
|
39377
|
+
var help = `rex-worktrees \u2014 Git worktrees and JJ workspaces on existing Rex machines
|
|
39378
|
+
setup [--bin /absolute/path/rex-worktrees] [--config /absolute/path/init.lua]
|
|
39379
|
+
install Lua module; copy binary to ~/.local/bin unless --bin is set
|
|
38082
39380
|
popup [--host HOST] [--context PATH | --no-context] [--origin-session ID [--origin-block ID]] [--origin-client ID]
|
|
38083
39381
|
interactive terminal chooser
|
|
38084
39382
|
launch-popup [--session ID] [--origin-block ID | --no-context] [--origin-client ID] [--host HOST]
|
|
38085
39383
|
open a floating chooser in the source window
|
|
38086
|
-
open --repo PATH --session ID --name NAME (--branch NAME | --worktree PATH)
|
|
38087
|
-
|
|
39384
|
+
open --repo PATH --session ID --name NAME (--branch NAME | --worktree PATH) [--worktree-name NAME]
|
|
39385
|
+
Git: branch checkout or existing worktree
|
|
39386
|
+
open --repo PATH --session ID --name NAME (--worktree PATH | --worktree-name NAME --revision EXPR)
|
|
39387
|
+
JJ: existing workspace or new workspace at base revision
|
|
39388
|
+
[--host HOST] [--client ID] [--additional | --split]
|
|
38088
39389
|
host-request read a JSON request on stdin, write a JSON response
|
|
38089
39390
|
help
|
|
38090
39391
|
|
|
@@ -38126,15 +39427,16 @@ var main = exports_Effect.gen(function* () {
|
|
|
38126
39427
|
}
|
|
38127
39428
|
if (verb === "setup") {
|
|
38128
39429
|
const flags = yield* parseFlags(args2);
|
|
38129
|
-
if (Object.keys(flags).some((key5) => key5 !== "--bin"))
|
|
38130
|
-
return yield* exports_Effect.fail(new AppError({ message: "Invalid setup flags" }));
|
|
39430
|
+
if (Object.keys(flags).some((key5) => key5 !== "--bin" && key5 !== "--config") || flags["--config"] && !flags["--bin"])
|
|
39431
|
+
return yield* exports_Effect.fail(new AppError({ message: "Invalid setup flags: --config requires --bin" }));
|
|
38131
39432
|
if (!compiled)
|
|
38132
39433
|
return yield* exports_Effect.fail(new AppError({ message: "Build first with bun run build, then run ./dist/rex-worktrees setup" }));
|
|
38133
|
-
const installed = yield* setup(flags["--bin"]);
|
|
39434
|
+
const installed = yield* setup(flags["--bin"], flags["--config"]);
|
|
38134
39435
|
yield* exports_Console.log(`${flags["--bin"] ? "Registered binary" : "Installed binary"}: ${installed.bin}
|
|
38135
39436
|
Installed Lua module: ${installed.luaPath}
|
|
38136
|
-
Updated Rex config: ${installed.configPath}
|
|
38137
|
-
|
|
39437
|
+
Updated Rex config: ${installed.configPath}${flags["--config"] ? `
|
|
39438
|
+
Rex will load the registration when it next starts.` : `
|
|
39439
|
+
Run rex config reload to activate.`}`);
|
|
38138
39440
|
return;
|
|
38139
39441
|
}
|
|
38140
39442
|
if (verb === "popup") {
|
|
@@ -38149,13 +39451,13 @@ Run rex config reload to activate.`);
|
|
|
38149
39451
|
const envSession = process.env.REX_SESSION === undefined ? undefined : yield* exports_Schema.decodeUnknownEffect(SessionIdSchema)(process.env.REX_SESSION);
|
|
38150
39452
|
const sessionId = flags["--origin-session"] ?? envSession;
|
|
38151
39453
|
const blockId = flags["--origin-block"] ?? (!flags["--no-context"] && sessionId === envSession && process.env.REX_BLOCK !== undefined ? yield* exports_Schema.decodeUnknownEffect(BlockIdSchema)(process.env.REX_BLOCK) : undefined);
|
|
38152
|
-
const
|
|
39454
|
+
const origin2 = {
|
|
38153
39455
|
sessionId,
|
|
38154
39456
|
blockId,
|
|
38155
39457
|
clientId: flags["--origin-client"] ?? (process.env.REX_CLIENT === undefined ? undefined : yield* exports_Schema.decodeUnknownEffect(ClientIdSchema)(process.env.REX_CLIENT))
|
|
38156
39458
|
};
|
|
38157
39459
|
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());
|
|
38158
|
-
yield* popup(executable, context3,
|
|
39460
|
+
yield* popup(executable, context3, origin2, flags["--host"]);
|
|
38159
39461
|
if (flags["--managed-popup"])
|
|
38160
39462
|
yield* closeManagedPopup;
|
|
38161
39463
|
return;
|
|
@@ -38178,9 +39480,14 @@ Run rex config reload to activate.`);
|
|
|
38178
39480
|
return yield* exports_Effect.fail(new AppError({ message: `Rex host ${selected2} is not registered` }));
|
|
38179
39481
|
const palette = typeof flags["--origin-block"] === "string";
|
|
38180
39482
|
const command = [...executable, "popup", "--origin-session", sessionId];
|
|
38181
|
-
if (palette && blockId)
|
|
39483
|
+
if (palette && blockId) {
|
|
39484
|
+
const context3 = yield* originDirectory(sessionId, blockId);
|
|
38182
39485
|
command.push("--origin-block", blockId);
|
|
38183
|
-
|
|
39486
|
+
if (context3)
|
|
39487
|
+
command.push("--context", context3);
|
|
39488
|
+
else
|
|
39489
|
+
command.push("--no-context");
|
|
39490
|
+
} else if (flags["--no-context"])
|
|
38184
39491
|
command.push("--no-context");
|
|
38185
39492
|
else
|
|
38186
39493
|
command.push("--context", process.cwd());
|
|
@@ -38198,35 +39505,53 @@ Run rex config reload to activate.`);
|
|
|
38198
39505
|
return yield* exports_Effect.fail(new AppError({ message: "--bin is only supported by setup" }));
|
|
38199
39506
|
if (!flags["--repo"] || !flags["--session"] || !flags["--name"])
|
|
38200
39507
|
return yield* exports_Effect.fail(new AppError({ message: "open requires --repo PATH --session ID --name NAME" }));
|
|
38201
|
-
if (Boolean(flags["--branch"]) === Boolean(flags["--worktree"]))
|
|
38202
|
-
return yield* exports_Effect.fail(new AppError({ message: "Choose exactly one of --branch NAME or --worktree PATH" }));
|
|
38203
|
-
if (flags["--worktree-name"] !== undefined && flags["--worktree"] !== undefined)
|
|
38204
|
-
return yield* exports_Effect.fail(new AppError({ message: "--worktree-name requires --branch, not --worktree" }));
|
|
38205
39508
|
if (flags["--additional"] && flags["--split"])
|
|
38206
39509
|
return yield* exports_Effect.fail(new AppError({ message: "--additional and --split are mutually exclusive" }));
|
|
38207
|
-
const input = {
|
|
38208
|
-
repo: flags["--repo"],
|
|
38209
|
-
sessionId: flags["--session"],
|
|
38210
|
-
name: flags["--name"],
|
|
38211
|
-
branch: flags["--branch"],
|
|
38212
|
-
worktreeName: flags["--worktree-name"],
|
|
38213
|
-
path: flags["--worktree"],
|
|
38214
|
-
clientId: flags["--client"],
|
|
38215
|
-
additional: flags["--additional"],
|
|
38216
|
-
split: flags["--split"]
|
|
38217
|
-
};
|
|
38218
|
-
if (!input.repo.trim() || !input.name.trim() || !input.sessionId.trim())
|
|
38219
|
-
return yield* exports_Effect.fail(new AppError({ message: "Required values cannot be blank" }));
|
|
38220
39510
|
const selected2 = flags["--host"];
|
|
38221
39511
|
const machine = (yield* listMachines).find((machine2) => !selected2 ? machine2.local : machine2.key === selected2 || machine2.label === selected2 || machine2.selector === selected2);
|
|
38222
39512
|
if (!machine)
|
|
38223
39513
|
return yield* exports_Effect.fail(new AppError({ message: `Rex host ${selected2} is not registered` }));
|
|
38224
39514
|
const host = yield* connectMachine(machine);
|
|
38225
|
-
if (!host.local && (!isAbsolute2(
|
|
39515
|
+
if (!host.local && (!isAbsolute2(flags["--repo"]) || flags["--worktree"] && !isAbsolute2(flags["--worktree"])))
|
|
38226
39516
|
return yield* exports_Effect.fail(new AppError({ message: "Remote repository and worktree paths must be absolute on the destination machine" }));
|
|
38227
|
-
const
|
|
38228
|
-
const
|
|
38229
|
-
|
|
39517
|
+
const repoPath = host.local ? resolve6(flags["--repo"]) : flags["--repo"];
|
|
39518
|
+
const vcs = host.local ? (yield* repository3(repoPath)).vcs : (yield* inspectProject(host, executable, repoPath)).checkout.vcs;
|
|
39519
|
+
let input;
|
|
39520
|
+
if (vcs === "git") {
|
|
39521
|
+
if (flags["--revision"] || Boolean(flags["--branch"]) === Boolean(flags["--worktree"]))
|
|
39522
|
+
return yield* exports_Effect.fail(new AppError({ message: "Git requires exactly one of --branch NAME or --worktree PATH; --revision is JJ-only" }));
|
|
39523
|
+
if (flags["--worktree-name"] !== undefined && flags["--worktree"] !== undefined)
|
|
39524
|
+
return yield* exports_Effect.fail(new AppError({ message: "--worktree-name requires --branch, not --worktree" }));
|
|
39525
|
+
input = {
|
|
39526
|
+
vcs,
|
|
39527
|
+
repo: repoPath,
|
|
39528
|
+
session: { kind: "existing", id: flags["--session"] },
|
|
39529
|
+
name: flags["--name"],
|
|
39530
|
+
branch: flags["--branch"],
|
|
39531
|
+
worktreeName: flags["--worktree-name"],
|
|
39532
|
+
path: flags["--worktree"] && (host.local ? resolve6(flags["--worktree"]) : flags["--worktree"]),
|
|
39533
|
+
clientId: flags["--client"],
|
|
39534
|
+
additional: flags["--additional"],
|
|
39535
|
+
split: flags["--split"]
|
|
39536
|
+
};
|
|
39537
|
+
} else {
|
|
39538
|
+
if (flags["--branch"] || Boolean(flags["--worktree"]) === Boolean(flags["--worktree-name"]) || flags["--worktree"] && flags["--revision"] || flags["--worktree-name"] && !flags["--revision"])
|
|
39539
|
+
return yield* exports_Effect.fail(new AppError({ message: "JJ requires --worktree PATH or --worktree-name NAME with --revision EXPR; --branch is Git-only" }));
|
|
39540
|
+
input = {
|
|
39541
|
+
vcs,
|
|
39542
|
+
repo: repoPath,
|
|
39543
|
+
session: { kind: "existing", id: flags["--session"] },
|
|
39544
|
+
name: flags["--name"],
|
|
39545
|
+
worktreeName: flags["--worktree-name"],
|
|
39546
|
+
revision: flags["--revision"],
|
|
39547
|
+
path: flags["--worktree"] && (host.local ? resolve6(flags["--worktree"]) : flags["--worktree"]),
|
|
39548
|
+
clientId: flags["--client"],
|
|
39549
|
+
additional: flags["--additional"],
|
|
39550
|
+
split: flags["--split"]
|
|
39551
|
+
};
|
|
39552
|
+
}
|
|
39553
|
+
const reviewed = yield* review(host, executable, input);
|
|
39554
|
+
yield* exports_Console.log(JSON.stringify(yield* submit(host, executable, input, reviewed), null, 2));
|
|
38230
39555
|
return;
|
|
38231
39556
|
}
|
|
38232
39557
|
if (verb === "task") {
|
|
@@ -38236,6 +39561,13 @@ Run rex config reload to activate.`);
|
|
|
38236
39561
|
yield* task(request4);
|
|
38237
39562
|
return;
|
|
38238
39563
|
}
|
|
39564
|
+
if (verb === "clone-task") {
|
|
39565
|
+
if (args2.length !== 1)
|
|
39566
|
+
return yield* exports_Effect.fail(new AppError({ message: "clone-task requires one JSON argument" }));
|
|
39567
|
+
const request4 = yield* exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(CloneTaskRequestSchema))(args2[0]);
|
|
39568
|
+
yield* cloneTask(request4);
|
|
39569
|
+
return;
|
|
39570
|
+
}
|
|
38239
39571
|
if (verb === "host-request") {
|
|
38240
39572
|
if (args2.length)
|
|
38241
39573
|
return yield* exports_Effect.fail(new AppError({ message: "host-request reads JSON from stdin" }));
|