@agimon-ai/po-git 0.0.0-alpha.6 → 0.0.0-alpha.60

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/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_worktreeOperations = require("./worktreeOperations-DGUbUnYU.cjs");
2
+ const require_worktreeOperations = require("./worktreeOperations-C1ygq-Na.cjs");
3
3
  //#region src/services/extensionService/index.ts
4
4
  var DefaultGitExtensionService = class {
5
5
  async execute() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["_$___worktreeEvents0.WorktreeMessage"],"sources":["../src/services/worktreeEvents/index.ts","../src/types/worktreeRegistry.ts","../src/services/worktreeNaming/index.ts","../src/services/worktreeOperations/index.ts","../src/types/extension.ts","../src/services/extensionService/index.ts","../src/services/gitDependencies/index.ts"],"mappings":";;;cASa;KASD;UAEK;WACN,gBAAgB;WAChB;WACA;WACA,MAAM;WACN;WACA;;;;;;;;;;;KCRC;cAEC;UAEI;EACf,gBAAgB;;EAEhB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA;EACA,QAAQ;;EAER;;;;UC8De;;EAEf,QAAQ;;EAER,QAAQ;;EAER;;EAEA,WAAW;;;;;;;EAOX;;;;;;;;iBASc,UAAU;EACxB,kBAAkB;EAClB;EACA;EACA,aAAa;IACX;;;UCpHa;;EAEf;;;;;EAKA;;UAGe;EACf;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;UAGe;;EAEf,SAAS;;EAET,cAAc;;UAGC;EACf,MAAM,SAAS,iBAAiB,SAAS,sBAAsB,UAAU,eAAe,QAAQ;EAChG,MAAM,SAAS,iBAAiB,YAAY,iBAAiB,QAAQ;EACrE,KAAK,SAAS,kBAAkB,QAAQ;EACxC,OAAO,SAAS,iBAAiB,aAAa;IAAU,QAAQ;IAAgB;;EAChF,MAAM,SAAS,iBAAiB,YAAY,mBAAmB,QAAQ;EACvE,MAAM,SAAS,iBAAiB,kBAAkB,QAAQ,kBAAkB;EAC5E,KAAK,SAAS,iBAAiB,YAAY,kBAAkB;EAC7D,SAAS,SAAS,iBAAiB,aAAa,QAA9BA;;;;KCrDR;UAEK;EACf;EACA,OAAO;;UAGQ;EACf,WAAW,QAAQ;;UAGJ;EACf,SAAS;EACT,YAAY;;;;qBCbD,sCAAsC;EAC3C,WAAW,QAAQ;;;;wBCEX,sBAAsB,YAAW,QAAQ,4BAAiC"}
1
+ {"version":3,"file":"index.d.mts","names":["_$___worktreeEvents0.WorktreeMessage"],"sources":["../src/services/worktreeEvents/index.ts","../src/types/worktreeRegistry.ts","../src/services/worktreeNaming/index.ts","../src/services/worktreeOperations/index.ts","../src/types/extension.ts","../src/services/extensionService/index.ts","../src/services/gitDependencies/index.ts"],"mappings":";;;cASa;KASD;UAEK;WACN,gBAAgB;WAChB;WACA;WACA,MAAM;WACN;WACA;;;;;;;;;;;KCRC;cAEC;UAEI;EACf,gBAAgB;;EAEhB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA;EACA,QAAQ;;EAER;;;;UCgEe;;EAEf,QAAQ;;EAER,QAAQ;;EAER;;EAEA,WAAW;;;;;;;EAOX;;;;;;;;iBASc,UAAU;EACxB,kBAAkB;EAClB;EACA;EACA,aAAa;IACX;;;UCrFa;;EAEf;;;;;EAKA;;UAGe;EACf;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;UAGe;;EAEf,SAAS;;EAET,cAAc;;UAGC;EACf,MAAM,SAAS,iBAAiB,SAAS,sBAAsB,UAAU,eAAe,QAAQ;EAChG,MAAM,SAAS,iBAAiB,YAAY,iBAAiB,QAAQ;EACrE,KAAK,SAAS,kBAAkB,QAAQ;EACxC,OAAO,SAAS,iBAAiB,aAAa;IAAU,QAAQ;IAAgB;;EAChF,MAAM,SAAS,iBAAiB,YAAY,mBAAmB,QAAQ;EACvE,MAAM,SAAS,iBAAiB,kBAAkB,QAAQ,kBAAkB;EAC5E,KAAK,SAAS,iBAAiB,YAAY,kBAAkB;EAC7D,SAAS,SAAS,iBAAiB,aAAa,QAA9BA;;;;KCtFR;UAEK;EACf;EACA,OAAO;;UAGQ;EACf,WAAW,QAAQ;;UAGJ;EACf,SAAS;EACT,YAAY;;;;qBCbD,sCAAsC;EAC3C,WAAW,QAAQ;;;;wBCEX,sBAAsB,YAAW,QAAQ,4BAAiC"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { b as createWorktreeGit, t as createWorktreeOperations } from "./worktreeOperations-BSeyxUai.mjs";
1
+ import { T as createWorktreeGit, t as createWorktreeOperations } from "./worktreeOperations-CP2lYxrI.mjs";
2
2
  //#region src/services/extensionService/index.ts
3
3
  var DefaultGitExtensionService = class {
4
4
  async execute() {
@@ -21,13 +21,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
  //#endregion
23
23
  let node_child_process = require("node:child_process");
24
- let node_fs = require("node:fs");
25
- node_fs = __toESM(node_fs, 1);
24
+ let node_fs_promises = require("node:fs/promises");
25
+ node_fs_promises = __toESM(node_fs_promises, 1);
26
26
  let node_crypto = require("node:crypto");
27
- let node_os = require("node:os");
28
- node_os = __toESM(node_os, 1);
29
27
  let node_path = require("node:path");
30
28
  node_path = __toESM(node_path, 1);
29
+ let js_yaml = require("js-yaml");
30
+ let node_os = require("node:os");
31
+ node_os = __toESM(node_os, 1);
31
32
  let node_util = require("node:util");
32
33
  let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
33
34
  let node_timers_promises = require("node:timers/promises");
@@ -199,7 +200,7 @@ function createWorktreeGit() {
199
200
  path
200
201
  ], REMOVE_TIMEOUT_MS);
201
202
  if (result.code === 0) return;
202
- if (missingWorktree(result.stderr) && !node_fs.default.existsSync(path)) {
203
+ if (missingWorktree(result.stderr) && !await node_fs_promises.default.access(path).then(() => true, () => false)) {
203
204
  await prune(repositoryRoot);
204
205
  return;
205
206
  }
@@ -285,6 +286,23 @@ function createWorktreeGit() {
285
286
  };
286
287
  }
287
288
  //#endregion
289
+ //#region src/constants/git.ts
290
+ /** Workspace-mounted routes behind the new-session dialog. */
291
+ const GIT_BRANCHES_PATH = "/branches";
292
+ const GIT_SESSIONS_PATH = "/sessions";
293
+ /** Workspace-mounted: that workspace's remote auth for manual pull, push and rebase. */
294
+ const GIT_AUTH_PATH = "/auth";
295
+ /** Session-mounted: the session's change against its base, and one file's hunks. */
296
+ const GIT_REVIEW_PATH = "/review";
297
+ const GIT_REVIEW_FILE_PATH = "/review/file";
298
+ /** Repository file, relative to the checkout root, whose `setup` commands run in every new worktree. */
299
+ const WORKTREE_CONFIG_FILE = ".po/worktree.yaml";
300
+ /**
301
+ * po-runner's session command, so setup runs as a runner of the worktree session and its log
302
+ * shows in Runners. Mirrors po-runner's `runnerLaunchLine`; the command follows the separator.
303
+ */
304
+ const WORKTREE_SETUP_LAUNCH = "/runners start name=worktree-setup --";
305
+ //#endregion
288
306
  //#region src/services/errors/index.ts
289
307
  var PoGitExpectedError = class extends Error {
290
308
  code;
@@ -320,12 +338,12 @@ const OWNER_ONLY_FILE = 384;
320
338
  * record in it. Writing beside the target and renaming makes the swap atomic on
321
339
  * the same filesystem, so a reader sees either the old file or the new one.
322
340
  */
323
- function writeJsonAtomic(file, value) {
341
+ async function writeJsonAtomic(file, value) {
324
342
  const directory = node_path.default.dirname(file);
325
- node_fs.default.mkdirSync(directory, { recursive: true });
326
- const temporary = node_path.default.join(directory, `.${node_path.default.basename(file)}.${String(process.pid)}.tmp`);
327
- node_fs.default.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: OWNER_ONLY_FILE });
328
- node_fs.default.renameSync(temporary, file);
343
+ await node_fs_promises.default.mkdir(directory, { recursive: true });
344
+ const temporary = node_path.default.join(directory, `.${node_path.default.basename(file)}.${(0, node_crypto.randomUUID)()}.tmp`);
345
+ await node_fs_promises.default.writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: OWNER_ONLY_FILE });
346
+ await node_fs_promises.default.rename(temporary, file);
329
347
  }
330
348
  /**
331
349
  * Reads JSON, treating every failure as absent.
@@ -334,9 +352,9 @@ function writeJsonAtomic(file, value) {
334
352
  * here: there is nothing to act on. Distinguishing them would only offer a
335
353
  * choice no caller wants to make.
336
354
  */
337
- function readJson(file) {
355
+ async function readJson(file) {
338
356
  try {
339
- return JSON.parse(node_fs.default.readFileSync(file, "utf8"));
357
+ return JSON.parse(await node_fs_promises.default.readFile(file, "utf8"));
340
358
  } catch {
341
359
  return;
342
360
  }
@@ -355,12 +373,12 @@ const MAX_LABEL_LENGTH = 32;
355
373
  * the registry is per repository and must be found from inside a worktree too.
356
374
  * A session may run in a subdirectory, so the nearest enclosing checkout is used.
357
375
  */
358
- function gitCommonDirectory(directory) {
376
+ async function gitCommonDirectory(directory) {
359
377
  let root = node_path.default.resolve(directory);
360
378
  let marker = node_path.default.join(root, ".git");
361
379
  let stat;
362
380
  for (;;) try {
363
- stat = node_fs.default.statSync(marker);
381
+ stat = await node_fs_promises.default.stat(marker);
364
382
  break;
365
383
  } catch {
366
384
  const parent = node_path.default.dirname(root);
@@ -371,14 +389,14 @@ function gitCommonDirectory(directory) {
371
389
  if (stat.isDirectory()) return marker;
372
390
  let pointer;
373
391
  try {
374
- pointer = node_fs.default.readFileSync(marker, "utf8").trim();
392
+ pointer = (await node_fs_promises.default.readFile(marker, "utf8")).trim();
375
393
  } catch {
376
394
  return;
377
395
  }
378
396
  if (!pointer.startsWith("gitdir:")) return void 0;
379
397
  const gitDir = node_path.default.resolve(root, pointer.slice(7).trim());
380
398
  try {
381
- const common = node_fs.default.readFileSync(node_path.default.join(gitDir, "commondir"), "utf8").trim();
399
+ const common = (await node_fs_promises.default.readFile(node_path.default.join(gitDir, "commondir"), "utf8")).trim();
382
400
  return node_path.default.resolve(gitDir, common);
383
401
  } catch {
384
402
  return gitDir;
@@ -397,8 +415,8 @@ function repositoryLabel(root) {
397
415
  * registry. Falling back to the path keeps a non-repository directory usable
398
416
  * instead of failing, though nothing here should reach that case.
399
417
  */
400
- function repositoryId(root) {
401
- const common = gitCommonDirectory(root);
418
+ async function repositoryId(root) {
419
+ const common = await gitCommonDirectory(root);
402
420
  const token = common === void 0 ? `root:${node_path.default.resolve(root)}` : `git:${common}`;
403
421
  return (0, node_crypto.createHash)("sha256").update(token).digest("hex").slice(0, ID_LENGTH);
404
422
  }
@@ -434,22 +452,26 @@ function credentialsFile(homeDir = node_os.default.homedir()) {
434
452
  return node_path.default.join(poGitRoot(homeDir), "credentials.json");
435
453
  }
436
454
  /** One registry file per repository, keyed by the shared git directory. */
437
- function registryFile(repositoryRoot, homeDir = node_os.default.homedir()) {
438
- const id = repositoryId(repositoryRoot);
455
+ async function registryFile(repositoryRoot, homeDir = node_os.default.homedir()) {
456
+ const id = await repositoryId(repositoryRoot);
439
457
  const root = node_path.default.join(poGitRoot(homeDir), "registry");
440
458
  const canonical = node_path.default.join(root, id, "worktrees.json");
441
- if (node_fs.default.existsSync(canonical)) return canonical;
459
+ if (await node_fs_promises.default.access(canonical).then(() => true, () => false)) return canonical;
442
460
  let names;
443
461
  try {
444
- names = node_fs.default.readdirSync(root);
462
+ names = await node_fs_promises.default.readdir(root);
445
463
  } catch {
446
464
  return canonical;
447
465
  }
448
- const legacyFiles = names.filter((entry) => entry.endsWith(`--${id}`)).sort().map((entry) => node_path.default.join(root, entry, "worktrees.json")).filter((file) => node_fs.default.existsSync(file));
466
+ const legacyFiles = [];
467
+ for (const entry of names.filter((name) => name.endsWith(`--${id}`)).sort()) {
468
+ const file = node_path.default.join(root, entry, "worktrees.json");
469
+ if (await node_fs_promises.default.access(file).then(() => true, () => false)) legacyFiles.push(file);
470
+ }
449
471
  if (legacyFiles.length === 0) return canonical;
450
472
  const entries = /* @__PURE__ */ new Map();
451
473
  for (const file of legacyFiles) {
452
- const legacy = readJson(file);
474
+ const legacy = await readJson(file);
453
475
  if (legacy?.version !== 1 || !Array.isArray(legacy.entries)) continue;
454
476
  for (const value of legacy.entries) {
455
477
  if (typeof value !== "object" || value === null || !("id" in value) || typeof value.id !== "string" || value.id === "") continue;
@@ -460,16 +482,16 @@ function registryFile(repositoryRoot, homeDir = node_os.default.homedir()) {
460
482
  }
461
483
  }
462
484
  const temporary = `${canonical}.${(0, node_crypto.randomUUID)()}.migration`;
463
- writeJsonAtomic(temporary, {
485
+ await writeJsonAtomic(temporary, {
464
486
  version: 1,
465
487
  entries: [...entries.values()]
466
488
  });
467
489
  try {
468
- node_fs.default.linkSync(temporary, canonical);
490
+ await node_fs_promises.default.link(temporary, canonical);
469
491
  } catch (error) {
470
492
  if (error.code !== "EEXIST") throw error;
471
493
  } finally {
472
- node_fs.default.rmSync(temporary);
494
+ await node_fs_promises.default.rm(temporary);
473
495
  }
474
496
  return canonical;
475
497
  }
@@ -588,18 +610,22 @@ function refuseClose(input) {
588
610
  * uncommitted work, so losing the record would lose the only pointer to it.
589
611
  * Deletion is always a separate, named decision.
590
612
  */
591
- function reconcile(records, probe) {
613
+ async function reconcile(records, probe) {
592
614
  const changed = [];
615
+ const next = [];
616
+ for (const record of records) {
617
+ if (record.status === "orphaned" || await probe.exists(record.path) && probe.alive(record)) {
618
+ next.push(record);
619
+ continue;
620
+ }
621
+ changed.push(record.id);
622
+ next.push({
623
+ ...record,
624
+ status: "orphaned"
625
+ });
626
+ }
593
627
  return {
594
- records: records.map((record) => {
595
- if (record.status === "orphaned") return record;
596
- if (!(!probe.exists(record.path) || !probe.alive(record))) return record;
597
- changed.push(record.id);
598
- return {
599
- ...record,
600
- status: "orphaned"
601
- };
602
- }),
628
+ records: next,
603
629
  changed
604
630
  };
605
631
  }
@@ -659,25 +685,25 @@ function isRecord(value) {
659
685
  */
660
686
  function createWorktreeRegistry(file) {
661
687
  return {
662
- list() {
663
- const parsed = readJson(file);
688
+ async list() {
689
+ const parsed = await readJson(file);
664
690
  if (!parsed || parsed.version !== 1 || !Array.isArray(parsed.entries)) return [];
665
691
  return parsed.entries.filter(isRecord);
666
692
  },
667
- replace(entries) {
668
- writeJsonAtomic(file, {
693
+ async replace(entries) {
694
+ await writeJsonAtomic(file, {
669
695
  version: 1,
670
696
  entries
671
697
  });
672
698
  },
673
699
  async transaction(operation, signal) {
674
700
  const lock = `${file}.lock`;
675
- node_fs.default.mkdirSync(node_path.default.dirname(file), { recursive: true });
701
+ await node_fs_promises.default.mkdir(node_path.default.dirname(file), { recursive: true });
676
702
  const deadline = Date.now() + LOCK_WAIT_MS;
677
703
  for (;;) {
678
704
  signal?.throwIfAborted();
679
705
  try {
680
- node_fs.default.mkdirSync(lock, { mode: 448 });
706
+ await node_fs_promises.default.mkdir(lock, { mode: 448 });
681
707
  break;
682
708
  } catch (error) {
683
709
  if (error.code !== "EEXIST") throw error;
@@ -686,14 +712,14 @@ function createWorktreeRegistry(file) {
686
712
  }
687
713
  }
688
714
  try {
689
- node_fs.default.writeFileSync(node_path.default.join(lock, "owner.json"), JSON.stringify({
715
+ await node_fs_promises.default.writeFile(node_path.default.join(lock, "owner.json"), JSON.stringify({
690
716
  pid: process.pid,
691
717
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
692
718
  }), { mode: 384 });
693
719
  signal?.throwIfAborted();
694
720
  return await operation();
695
721
  } finally {
696
- node_fs.default.rmSync(lock, { recursive: true });
722
+ await node_fs_promises.default.rm(lock, { recursive: true });
697
723
  }
698
724
  }
699
725
  };
@@ -703,6 +729,23 @@ function createWorktreeRegistry(file) {
703
729
  const GIT_WORKTREE_DELEGATION_KIND = "git.worktree.delegation";
704
730
  const GIT_WORKTREE_MESSAGE_KIND = "git.worktree.message";
705
731
  const GIT_WORKTREE_REPORT_KIND = "git.worktree.report";
732
+ /**
733
+ * The repository's worktree setup as one shell command, or undefined when it asks for none.
734
+ * Read from the checkout the spawn starts in, so an uncommitted edit applies at once.
735
+ */
736
+ async function readWorktreeSetup(root) {
737
+ const file = node_path.default.join(root, WORKTREE_CONFIG_FILE);
738
+ let setup;
739
+ try {
740
+ setup = (0, js_yaml.load)(await node_fs_promises.default.readFile(file, "utf8"))?.setup;
741
+ } catch (error) {
742
+ if (error.code === "ENOENT") return void 0;
743
+ throw new PoGitExpectedError("invalid_request", `${WORKTREE_CONFIG_FILE} is not valid YAML (${error.message}).`, false, "Fix the file and try again.");
744
+ }
745
+ const commands = [setup ?? []].flat();
746
+ if (!commands.every((command) => typeof command === "string")) throw new PoGitExpectedError("invalid_request", `${WORKTREE_CONFIG_FILE} setup must be a command or a list of commands.`, false, "Fix the file and try again.");
747
+ return commands.filter((command) => command.trim() !== "").join(" && ") || void 0;
748
+ }
706
749
  function createWorktreeOperations(deps) {
707
750
  const { git } = deps;
708
751
  const sessionService = deps.sessionService;
@@ -723,7 +766,7 @@ function createWorktreeOperations(deps) {
723
766
  };
724
767
  const probe = {
725
768
  alive: (record) => requireSessionService().isLive(record.sessionId),
726
- exists: (path) => node_fs.default.existsSync(path)
769
+ exists: (path) => node_fs_promises.default.access(path).then(() => true, () => false)
727
770
  };
728
771
  /**
729
772
  * Everything an action needs about the repository it is acting on.
@@ -735,11 +778,11 @@ function createWorktreeOperations(deps) {
735
778
  const resolve = async (context) => {
736
779
  const root = await git.repositoryRoot(context.cwd);
737
780
  if (root === void 0) throw new PoGitExpectedError("not_a_repository", `${context.cwd} is not inside a git repository.`, false, "Run this from a repository checkout.");
738
- const store = createWorktreeRegistry(registryFile(root, deps.homeDir));
781
+ const store = createWorktreeRegistry(await registryFile(root, deps.homeDir));
739
782
  return {
740
783
  root,
741
784
  store,
742
- records: store.list()
785
+ records: await store.list()
743
786
  };
744
787
  };
745
788
  const require$1 = (records, id) => {
@@ -790,11 +833,11 @@ function createWorktreeOperations(deps) {
790
833
  const expectedPath = worktreeDirectory({
791
834
  worktreesRoot: worktreesRoot(deps.homeDir),
792
835
  repositoryLabel: repositoryLabel(root),
793
- repositoryId: repositoryId(root),
836
+ repositoryId: await repositoryId(root),
794
837
  branch: request.branch,
795
838
  shortId: shortId(reserved.sessionId)
796
839
  });
797
- if (existing.parentSessionId !== parentSessionId || existing.repositoryRoot !== root || existing.branch !== request.branch || existing.path !== expectedPath || existing.path !== reserved?.cwd || request.baseRef !== void 0 && existing.baseRef !== request.baseRef || !node_fs.default.existsSync(existing.path) || !(await git.listWorktreePaths(root)).includes(existing.path) || await git.repositoryRoot(existing.path) !== existing.path || await git.currentBranch(existing.path) !== request.branch) throw new PoGitExpectedError("invalid_request", "The reserved checkout no longer matches this setup.", false, "Inspect the existing branch and checkout; they will not be replaced.");
840
+ if (existing.parentSessionId !== parentSessionId || existing.repositoryRoot !== root || existing.branch !== request.branch || existing.path !== expectedPath || existing.path !== reserved?.cwd || request.baseRef !== void 0 && existing.baseRef !== request.baseRef || !await probe.exists(existing.path) || !(await git.listWorktreePaths(root)).includes(existing.path) || await git.repositoryRoot(existing.path) !== existing.path || await git.currentBranch(existing.path) !== request.branch) throw new PoGitExpectedError("invalid_request", "The reserved checkout no longer matches this setup.", false, "Inspect the existing branch and checkout; they will not be replaced.");
798
841
  if (!requireSessionService().isLive(existing.sessionId)) {
799
842
  if ((await requireSessionService().create({
800
843
  cwd: existing.path,
@@ -814,17 +857,18 @@ function createWorktreeOperations(deps) {
814
857
  });
815
858
  if (refusal !== void 0) throw new PoGitExpectedError("worktree_exists", refusal, false, "Pick another branch name, or close it.");
816
859
  const taskDelivery = request.task === void 0 ? void 0 : requireSessionDelivery();
860
+ const setup = await readWorktreeSetup(root);
817
861
  const existingBranch = request.checkout === "existing";
818
862
  const id = shortId(reserved?.sessionId ?? (0, node_crypto.randomUUID)());
819
863
  let path = worktreeDirectory({
820
864
  worktreesRoot: worktreesRoot(deps.homeDir),
821
865
  repositoryLabel: repositoryLabel(root),
822
- repositoryId: repositoryId(root),
866
+ repositoryId: await repositoryId(root),
823
867
  branch: request.branch,
824
868
  shortId: id
825
869
  });
826
870
  if (request.reservationId !== void 0) path = (await reservations.prepare(request.reservationId, parentSessionId, path)).cwd;
827
- const recovering = reserved?.cwd !== void 0 && node_fs.default.existsSync(path);
871
+ const recovering = reserved?.cwd !== void 0 && await probe.exists(path);
828
872
  if (recovering && (!(await git.listWorktreePaths(root)).includes(path) || await git.currentBranch(path) !== request.branch)) throw new PoGitExpectedError("invalid_request", "The reserved checkout no longer matches this setup.", false, "Inspect the existing directory; it will not be replaced.");
829
873
  if (!recovering) {
830
874
  if (existingBranch) {
@@ -896,17 +940,26 @@ function createWorktreeOperations(deps) {
896
940
  createdAt: now().toISOString()
897
941
  };
898
942
  try {
899
- store.replace([...records, record]);
943
+ await store.replace([...records, record]);
900
944
  } catch (error) {
901
945
  await requireSessionService().close(sessionId).catch(() => void 0);
902
946
  const kept = await rollback();
903
947
  throw new PoGitExpectedError("registry_write_failed", `The worktree was created but the registry could not be written (${error.message}).${kept}`, true, "Check the registry file for permissions or free space, then try again.");
904
948
  }
949
+ let setupStarted = false;
950
+ if (setup !== void 0) try {
951
+ const service = requireSessionService();
952
+ if (service.prompt === void 0) throw new Error("this host cannot run session commands");
953
+ await service.prompt(sessionId, `${WORKTREE_SETUP_LAUNCH} ${setup}`);
954
+ setupStarted = true;
955
+ } catch (error) {
956
+ options?.onProgress?.(`worktree setup did not start (${String(error)})`);
957
+ }
905
958
  if (request.task !== void 0 && taskDelivery !== void 0) try {
906
959
  const receipt = await taskDelivery.deliver({
907
960
  recipientKey: sessionId,
908
961
  kind: GIT_WORKTREE_DELEGATION_KIND,
909
- prompt: request.task,
962
+ prompt: setupStarted ? `${request.task}\n\nThe worktree setup (${setup}) is running as the runner "worktree-setup". Check it with po-runner before relying on installed dependencies or builds.` : request.task,
910
963
  metadata: {
911
964
  worktreeId: record.id,
912
965
  fromRole: "parent",
@@ -929,7 +982,7 @@ function createWorktreeOperations(deps) {
929
982
  requireOwner(context, record, "close");
930
983
  const refusal = refuseClose({
931
984
  record,
932
- dirtyFiles: node_fs.default.existsSync(record.path) ? await git.dirtyFiles(record.path) : [],
985
+ dirtyFiles: await probe.exists(record.path) ? await git.dirtyFiles(record.path) : [],
933
986
  force
934
987
  });
935
988
  if (refusal !== void 0) throw new PoGitExpectedError("worktree_dirty", refusal, false, "Commit the work, or pass force: true.");
@@ -939,13 +992,13 @@ function createWorktreeOperations(deps) {
939
992
  path: record.path,
940
993
  force
941
994
  });
942
- store.replace(records.filter((entry) => entry.id !== id));
995
+ await store.replace(records.filter((entry) => entry.id !== id));
943
996
  return record;
944
997
  },
945
998
  async list(context) {
946
999
  const { store, records } = await resolve(context);
947
- const outcome = reconcile(records, probe);
948
- if (outcome.changed.length > 0) store.replace(outcome.records);
1000
+ const outcome = await reconcile(records, probe);
1001
+ if (outcome.changed.length > 0) await store.replace(outcome.records);
949
1002
  return outcome.records;
950
1003
  },
951
1004
  async status(context, id) {
@@ -953,7 +1006,7 @@ function createWorktreeOperations(deps) {
953
1006
  const record = require$1(records, id);
954
1007
  return {
955
1008
  record,
956
- dirtyFiles: node_fs.default.existsSync(record.path) ? await git.dirtyFiles(record.path) : []
1009
+ dirtyFiles: await probe.exists(record.path) ? await git.dirtyFiles(record.path) : []
957
1010
  };
958
1011
  },
959
1012
  async merge(context, id, message) {
@@ -1026,10 +1079,10 @@ function createWorktreeOperations(deps) {
1026
1079
  },
1027
1080
  async prune(context, dryRun) {
1028
1081
  const { root, store, records } = await resolve(context);
1029
- const reconciled = reconcile(records, probe);
1082
+ const reconciled = await reconcile(records, probe);
1030
1083
  const gitPaths = await git.listWorktreePaths(root);
1031
1084
  const dirtyByPath = /* @__PURE__ */ new Map();
1032
- for (const record of reconciled.records) if (record.status === "orphaned" && node_fs.default.existsSync(record.path)) dirtyByPath.set(record.path, await git.dirtyFiles(record.path));
1085
+ for (const record of reconciled.records) if (record.status === "orphaned" && await probe.exists(record.path)) dirtyByPath.set(record.path, await git.dirtyFiles(record.path));
1033
1086
  const plan = planPrune({
1034
1087
  records: reconciled.records,
1035
1088
  gitPaths,
@@ -1037,7 +1090,7 @@ function createWorktreeOperations(deps) {
1037
1090
  dirtyByPath
1038
1091
  });
1039
1092
  if (dryRun) {
1040
- store.replace(reconciled.records);
1093
+ await store.replace(reconciled.records);
1041
1094
  return plan;
1042
1095
  }
1043
1096
  for (const record of plan.remove) await git.removeWorktree({
@@ -1050,7 +1103,7 @@ function createWorktreeOperations(deps) {
1050
1103
  branch: record.branch
1051
1104
  }).catch(() => false)) plan.keptBranches.push(record.branch);
1052
1105
  const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));
1053
- store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
1106
+ await store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
1054
1107
  return plan;
1055
1108
  }
1056
1109
  };
@@ -1072,7 +1125,7 @@ function createWorktreeOperations(deps) {
1072
1125
  return {
1073
1126
  ...operations,
1074
1127
  spawn: (context, request, options) => {
1075
- if (sessionService === void 0) return Promise.reject(new PoGitExpectedError("hub_unavailable", "The cockpit session service is unavailable.", true, "Use the cockpit worktree tool after its Git server facet is available."));
1128
+ if (sessionService === void 0) return Promise.reject(new PoGitExpectedError("hub_unavailable", "The cockpit session service is unavailable.", true, "Use the cockpit worktree tool after its Git server plugin is available."));
1076
1129
  if (!validRefName(request.branch) || request.baseRef !== void 0 && !validRefName(request.baseRef)) return Promise.reject(new PoGitExpectedError("invalid_request", "That is not a valid branch name.", false, "Pick another name."));
1077
1130
  if (request.reservationId !== void 0 && context.sessionId === void 0) return Promise.reject(new PoGitExpectedError("invalid_request", "A reserved worktree session requires its owning parent.", false, "Create the session from its pending setup card."));
1078
1131
  return locked(context, () => operations.spawn(context, request, options), options?.signal);
@@ -1084,6 +1137,36 @@ function createWorktreeOperations(deps) {
1084
1137
  };
1085
1138
  }
1086
1139
  //#endregion
1140
+ Object.defineProperty(exports, "GIT_AUTH_PATH", {
1141
+ enumerable: true,
1142
+ get: function() {
1143
+ return GIT_AUTH_PATH;
1144
+ }
1145
+ });
1146
+ Object.defineProperty(exports, "GIT_BRANCHES_PATH", {
1147
+ enumerable: true,
1148
+ get: function() {
1149
+ return GIT_BRANCHES_PATH;
1150
+ }
1151
+ });
1152
+ Object.defineProperty(exports, "GIT_REVIEW_FILE_PATH", {
1153
+ enumerable: true,
1154
+ get: function() {
1155
+ return GIT_REVIEW_FILE_PATH;
1156
+ }
1157
+ });
1158
+ Object.defineProperty(exports, "GIT_REVIEW_PATH", {
1159
+ enumerable: true,
1160
+ get: function() {
1161
+ return GIT_REVIEW_PATH;
1162
+ }
1163
+ });
1164
+ Object.defineProperty(exports, "GIT_SESSIONS_PATH", {
1165
+ enumerable: true,
1166
+ get: function() {
1167
+ return GIT_SESSIONS_PATH;
1168
+ }
1169
+ });
1087
1170
  Object.defineProperty(exports, "GIT_SESSION_CHANGED_EVENT", {
1088
1171
  enumerable: true,
1089
1172
  get: function() {
@@ -1217,4 +1300,4 @@ Object.defineProperty(exports, "writeJsonAtomic", {
1217
1300
  }
1218
1301
  });
1219
1302
 
1220
- //# sourceMappingURL=worktreeOperations-DGUbUnYU.cjs.map
1303
+ //# sourceMappingURL=worktreeOperations-C1ygq-Na.cjs.map