@paleo/worktree-env 0.3.0 → 0.4.1

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/dist/cli.d.ts CHANGED
@@ -2,11 +2,11 @@ export interface SetupArgs {
2
2
  help?: boolean;
3
3
  use?: string;
4
4
  create?: string;
5
- self?: boolean;
5
+ here?: boolean;
6
6
  owner?: string;
7
7
  "set-owner"?: string;
8
8
  remove?: string;
9
- "remove-self"?: boolean;
9
+ "remove-here"?: boolean;
10
10
  "no-remote-check"?: boolean;
11
11
  slot?: string;
12
12
  force?: boolean;
package/dist/cli.js CHANGED
@@ -12,7 +12,7 @@ const SETUP_OPTIONS = {
12
12
  arg: "branch",
13
13
  description: "Create a new branch + worktree, then set up the local environment. If the branch already exists, appends a numeric suffix (-2, -3, ...)",
14
14
  },
15
- self: {
15
+ here: {
16
16
  type: "boolean",
17
17
  description: "Set up the local environment in the current linked worktree",
18
18
  },
@@ -31,13 +31,13 @@ const SETUP_OPTIONS = {
31
31
  arg: "branch",
32
32
  description: "Remove a worktree by branch name (stop dev server, free slot, delete directory)",
33
33
  },
34
- "remove-self": {
34
+ "remove-here": {
35
35
  type: "boolean",
36
36
  description: "Remove the current linked worktree (same as --remove, but for the worktree you are in)",
37
37
  },
38
38
  "no-remote-check": {
39
39
  type: "boolean",
40
- description: "Skip remote branch verification when removing (use with --remove or --remove-self)",
40
+ description: "Skip remote branch verification when removing (use with --remove or --remove-here)",
41
41
  },
42
42
  slot: {
43
43
  type: "string",
@@ -87,10 +87,10 @@ export function printDevServerHelp() {
87
87
  console.log(formatHelp("dev-server [options]", "Start, stop, or list background dev-server processes.", DEV_SERVER_OPTIONS));
88
88
  }
89
89
  export function isSetupMode(args) {
90
- return args.use !== undefined || args.create !== undefined || Boolean(args.self);
90
+ return args.use !== undefined || args.create !== undefined || Boolean(args.here);
91
91
  }
92
92
  export function isRemoveMode(args) {
93
- return args.remove !== undefined || Boolean(args["remove-self"]);
93
+ return args.remove !== undefined || Boolean(args["remove-here"]);
94
94
  }
95
95
  export function isSetOwnerMode(args) {
96
96
  return args["set-owner"] !== undefined;
@@ -99,24 +99,24 @@ export function validateSetupFlags(args) {
99
99
  const modeFlags = [
100
100
  args.use,
101
101
  args.create,
102
- args.self,
102
+ args.here,
103
103
  isRemoveMode(args),
104
104
  isSetOwnerMode(args),
105
105
  ].filter(Boolean);
106
106
  if (modeFlags.length > 1) {
107
- throw new ConfigError("Error: --use, --create, --self, --remove, --remove-self, and --set-owner are mutually exclusive.");
107
+ throw new ConfigError("Error: --use, --create, --here, --remove, --remove-here, and --set-owner are mutually exclusive.");
108
108
  }
109
- if (args.remove !== undefined && args["remove-self"]) {
110
- throw new ConfigError("Error: --remove and --remove-self are mutually exclusive.");
109
+ if (args.remove !== undefined && args["remove-here"]) {
110
+ throw new ConfigError("Error: --remove and --remove-here are mutually exclusive.");
111
111
  }
112
112
  if ((args.slot !== undefined || args.force) && !isSetupMode(args)) {
113
- throw new ConfigError("Error: --slot and --force can only be used with --use, --create, or --self.");
113
+ throw new ConfigError("Error: --slot and --force can only be used with --use, --create, or --here.");
114
114
  }
115
115
  if (args.owner !== undefined && !isSetupMode(args)) {
116
- throw new ConfigError("Error: --owner is only valid with --use, --create, or --self.");
116
+ throw new ConfigError("Error: --owner is only valid with --use, --create, or --here.");
117
117
  }
118
118
  if (args["no-remote-check"] && !isRemoveMode(args)) {
119
- throw new ConfigError("Error: --no-remote-check is only valid with --remove or --remove-self.");
119
+ throw new ConfigError("Error: --no-remote-check is only valid with --remove or --remove-here.");
120
120
  }
121
121
  }
122
122
  export function validateDevServerFlags(args) {
@@ -8,7 +8,7 @@ import { defaultComputePorts, resolvePortScheme } from "./ports.js";
8
8
  import { handleSetOwner, readSlots, resolveAndRegisterSlot, validateSlotAvailability, writeSlots, } from "./slots.js";
9
9
  import { createBranch, detectWorktree, enforceWorktreeMode, getCurrentBranch, removeWorktree, useExistingBranch, verifyBranchAbsentFromRemote, } from "./worktree.js";
10
10
  import { cleanupPidFile, isProcessAlive, isProcessGroupAlive, killProcessGroup, readPid, } from "./process-control.js";
11
- function makeLog(verbose) {
11
+ function makeVerboseLog(verbose) {
12
12
  return (msg) => {
13
13
  if (verbose)
14
14
  console.log(msg);
@@ -64,7 +64,7 @@ export async function runSetupWorktree(config) {
64
64
  await runSetup(args, ctx, run, config);
65
65
  }
66
66
  async function runSetup(args, ctx, run, config) {
67
- const log = makeLog(run.verbose);
67
+ const verboseLog = makeVerboseLog(run.verbose);
68
68
  const scheme = resolvePortScheme(config);
69
69
  const portsFn = resolvePortsFn(config);
70
70
  validateSlotAvailability(args.slot, {
@@ -83,12 +83,13 @@ async function runSetup(args, ctx, run, config) {
83
83
  requestedOwner: args.owner,
84
84
  });
85
85
  const ports = portsFn(slot);
86
- log(`Using slot ${slot} (${Object.entries(ports)
86
+ verboseLog(`Using slot ${slot} (${Object.entries(ports)
87
87
  .map(([k, v]) => `${k}: ${v}`)
88
88
  .join(", ")})`);
89
+ console.log(`WORKTREE_CREATED path=${setupCtx.currentWorktree} branch=${branch} slot=${slot}`);
89
90
  const sharedDirs = config.sharedDirs ?? [".local", ".plans"];
90
- linkSharedDirectories(setupCtx, sharedDirs, log);
91
- generateConfigFiles(setupCtx, config.configFiles, slot, ports, args.force ?? false, log);
91
+ linkSharedDirectories(setupCtx, sharedDirs, verboseLog);
92
+ generateConfigFiles(setupCtx, config.configFiles, slot, ports, args.force ?? false, verboseLog);
92
93
  const force = args.force ?? false;
93
94
  const setupContext = {
94
95
  currentWorktree: setupCtx.currentWorktree,
@@ -147,8 +148,8 @@ function generateConfigFiles(ctx, entries, slot, ports, force, log) {
147
148
  }), entry.path, force, entry.required ?? false);
148
149
  }
149
150
  }
150
- function resolveRemoveTarget(args, ctx, registry, removeSelf) {
151
- if (removeSelf) {
151
+ function resolveRemoveTarget(args, ctx, registry, removeHere) {
152
+ if (removeHere) {
152
153
  if (ctx.isMainWorktree) {
153
154
  console.error("Error: Cannot remove the main worktree.");
154
155
  process.exit(1);
@@ -174,7 +175,7 @@ function resolveRemoveTarget(args, ctx, registry, removeSelf) {
174
175
  }
175
176
  const worktreePath = entry[1].worktree;
176
177
  if (resolve(ctx.currentWorktree) === resolve(worktreePath)) {
177
- console.error("Error: You are currently in this worktree. Use --remove-self instead.");
178
+ console.error("Error: You are currently in this worktree. Use --remove-here instead.");
178
179
  process.exit(1);
179
180
  }
180
181
  return { slotPort: entry[0], branch, worktreePath, owner: entry[1].owner };
@@ -207,10 +208,10 @@ async function stopDevServerByPidFiles(worktreePath, pidFiles, log) {
207
208
  }
208
209
  }
209
210
  async function handleRemove(args, ctx, run, config) {
210
- const log = makeLog(run.verbose);
211
- const removeSelf = Boolean(args["remove-self"]);
211
+ const verboseLog = makeVerboseLog(run.verbose);
212
+ const removeHere = Boolean(args["remove-here"]);
212
213
  const registry = readSlots(ctx.mainWorktree);
213
- const target = resolveRemoveTarget(args, ctx, registry, removeSelf);
214
+ const target = resolveRemoveTarget(args, ctx, registry, removeHere);
214
215
  if (!args["no-remote-check"]) {
215
216
  verifyBranchAbsentFromRemote(target.branch, run);
216
217
  }
@@ -222,7 +223,7 @@ async function handleRemove(args, ctx, run, config) {
222
223
  console.log(`Removed registry entry for branch "${target.branch}" (slot ${target.slotPort}${ownerSuffix}).`);
223
224
  return;
224
225
  }
225
- await stopDevServerByPidFiles(target.worktreePath, config.devServerPidFiles, log);
226
+ await stopDevServerByPidFiles(target.worktreePath, config.devServerPidFiles, verboseLog);
226
227
  if (config.teardownInfrastructure) {
227
228
  await config.teardownInfrastructure({
228
229
  worktree: target.worktreePath,
@@ -233,12 +234,12 @@ async function handleRemove(args, ctx, run, config) {
233
234
  delete registry.slots[target.slotPort];
234
235
  writeSlots(ctx.mainWorktree, registry);
235
236
  removeDevServerEntryByWorktree(ctx.mainWorktree, target.worktreePath);
236
- if (removeSelf) {
237
+ if (removeHere) {
237
238
  process.chdir(ctx.mainWorktree);
238
239
  }
239
240
  removeWorktree(target.worktreePath, run);
240
241
  console.log(`Removed worktree for branch "${target.branch}" (slot ${target.slotPort}${ownerSuffix}).`);
241
- if (removeSelf) {
242
+ if (removeHere) {
242
243
  console.log(`Now run: cd ${ctx.mainWorktree}`);
243
244
  }
244
245
  }
@@ -16,6 +16,6 @@ export declare function getCurrentBranch(worktreePath: string): string;
16
16
  export declare function enforceWorktreeMode(args: {
17
17
  use?: string;
18
18
  create?: string;
19
- self?: boolean;
19
+ here?: boolean;
20
20
  }, ctx: WorktreeContext): void;
21
21
  export declare function removeWorktree(worktreePath: string, run: RunCtx): void;
package/dist/worktree.js CHANGED
@@ -54,7 +54,6 @@ export function createBranch(requestedBranch, ctx, run) {
54
54
  execFileSync("git", ["worktree", "add", "-b", finalBranch, worktreePath], {
55
55
  stdio: stdioFor(run),
56
56
  });
57
- console.log(`Branch: ${finalBranch}`);
58
57
  return { ...ctx, currentWorktree: worktreePath, isMainWorktree: false };
59
58
  }
60
59
  export function verifyBranchAbsentFromRemote(branch, run) {
@@ -80,9 +79,9 @@ export function enforceWorktreeMode(args, ctx) {
80
79
  process.exit(1);
81
80
  }
82
81
  }
83
- else if (args.self) {
82
+ else if (args.here) {
84
83
  if (ctx.isMainWorktree) {
85
- console.error("Error: --self must be run from a linked worktree, not from the main worktree.");
84
+ console.error("Error: --here must be run from a linked worktree, not from the main worktree.");
86
85
  process.exit(1);
87
86
  }
88
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paleo/worktree-env",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Worktree-based concurrent local environment kernel.",
5
5
  "keywords": [
6
6
  "worktree",