@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/LICENSE +149 -21
- package/README.md +16 -4
- package/dist/extensions/native.mjs +2160 -534
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +286 -114
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +2 -2
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +283 -111
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +1412 -1291
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{worktreeOperations-DGUbUnYU.cjs → worktreeOperations-C1ygq-Na.cjs} +148 -65
- package/dist/worktreeOperations-C1ygq-Na.cjs.map +1 -0
- package/dist/{worktreeOperations-BSeyxUai.mjs → worktreeOperations-CP2lYxrI.mjs} +117 -64
- package/dist/worktreeOperations-CP2lYxrI.mjs.map +1 -0
- package/llms.txt +1 -1
- package/package.json +20 -18
- package/src/prompts/{po-use-git → codemode-how-to-git}/SKILL.md +35 -32
- package/dist/worktreeOperations-BSeyxUai.mjs.map +0 -1
- package/dist/worktreeOperations-DGUbUnYU.cjs.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import fs from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
-
import os from "node:os";
|
|
5
4
|
import path from "node:path";
|
|
5
|
+
import { load } from "js-yaml";
|
|
6
|
+
import os from "node:os";
|
|
6
7
|
import { isDeepStrictEqual } from "node:util";
|
|
7
8
|
import { poHomeDirectory } from "@agimon-ai/po-core/piSettings";
|
|
8
9
|
import { setTimeout } from "node:timers/promises";
|
|
@@ -174,7 +175,7 @@ function createWorktreeGit() {
|
|
|
174
175
|
path
|
|
175
176
|
], REMOVE_TIMEOUT_MS);
|
|
176
177
|
if (result.code === 0) return;
|
|
177
|
-
if (missingWorktree(result.stderr) && !fs.
|
|
178
|
+
if (missingWorktree(result.stderr) && !await fs.access(path).then(() => true, () => false)) {
|
|
178
179
|
await prune(repositoryRoot);
|
|
179
180
|
return;
|
|
180
181
|
}
|
|
@@ -260,6 +261,23 @@ function createWorktreeGit() {
|
|
|
260
261
|
};
|
|
261
262
|
}
|
|
262
263
|
//#endregion
|
|
264
|
+
//#region src/constants/git.ts
|
|
265
|
+
/** Workspace-mounted routes behind the new-session dialog. */
|
|
266
|
+
const GIT_BRANCHES_PATH = "/branches";
|
|
267
|
+
const GIT_SESSIONS_PATH = "/sessions";
|
|
268
|
+
/** Workspace-mounted: that workspace's remote auth for manual pull, push and rebase. */
|
|
269
|
+
const GIT_AUTH_PATH = "/auth";
|
|
270
|
+
/** Session-mounted: the session's change against its base, and one file's hunks. */
|
|
271
|
+
const GIT_REVIEW_PATH = "/review";
|
|
272
|
+
const GIT_REVIEW_FILE_PATH = "/review/file";
|
|
273
|
+
/** Repository file, relative to the checkout root, whose `setup` commands run in every new worktree. */
|
|
274
|
+
const WORKTREE_CONFIG_FILE = ".po/worktree.yaml";
|
|
275
|
+
/**
|
|
276
|
+
* po-runner's session command, so setup runs as a runner of the worktree session and its log
|
|
277
|
+
* shows in Runners. Mirrors po-runner's `runnerLaunchLine`; the command follows the separator.
|
|
278
|
+
*/
|
|
279
|
+
const WORKTREE_SETUP_LAUNCH = "/runners start name=worktree-setup --";
|
|
280
|
+
//#endregion
|
|
263
281
|
//#region src/services/errors/index.ts
|
|
264
282
|
var PoGitExpectedError = class extends Error {
|
|
265
283
|
code;
|
|
@@ -295,12 +313,12 @@ const OWNER_ONLY_FILE = 384;
|
|
|
295
313
|
* record in it. Writing beside the target and renaming makes the swap atomic on
|
|
296
314
|
* the same filesystem, so a reader sees either the old file or the new one.
|
|
297
315
|
*/
|
|
298
|
-
function writeJsonAtomic(file, value) {
|
|
316
|
+
async function writeJsonAtomic(file, value) {
|
|
299
317
|
const directory = path.dirname(file);
|
|
300
|
-
fs.
|
|
301
|
-
const temporary = path.join(directory, `.${path.basename(file)}.${
|
|
302
|
-
fs.
|
|
303
|
-
fs.
|
|
318
|
+
await fs.mkdir(directory, { recursive: true });
|
|
319
|
+
const temporary = path.join(directory, `.${path.basename(file)}.${randomUUID()}.tmp`);
|
|
320
|
+
await fs.writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: OWNER_ONLY_FILE });
|
|
321
|
+
await fs.rename(temporary, file);
|
|
304
322
|
}
|
|
305
323
|
/**
|
|
306
324
|
* Reads JSON, treating every failure as absent.
|
|
@@ -309,9 +327,9 @@ function writeJsonAtomic(file, value) {
|
|
|
309
327
|
* here: there is nothing to act on. Distinguishing them would only offer a
|
|
310
328
|
* choice no caller wants to make.
|
|
311
329
|
*/
|
|
312
|
-
function readJson(file) {
|
|
330
|
+
async function readJson(file) {
|
|
313
331
|
try {
|
|
314
|
-
return JSON.parse(fs.
|
|
332
|
+
return JSON.parse(await fs.readFile(file, "utf8"));
|
|
315
333
|
} catch {
|
|
316
334
|
return;
|
|
317
335
|
}
|
|
@@ -330,12 +348,12 @@ const MAX_LABEL_LENGTH = 32;
|
|
|
330
348
|
* the registry is per repository and must be found from inside a worktree too.
|
|
331
349
|
* A session may run in a subdirectory, so the nearest enclosing checkout is used.
|
|
332
350
|
*/
|
|
333
|
-
function gitCommonDirectory(directory) {
|
|
351
|
+
async function gitCommonDirectory(directory) {
|
|
334
352
|
let root = path.resolve(directory);
|
|
335
353
|
let marker = path.join(root, ".git");
|
|
336
354
|
let stat;
|
|
337
355
|
for (;;) try {
|
|
338
|
-
stat = fs.
|
|
356
|
+
stat = await fs.stat(marker);
|
|
339
357
|
break;
|
|
340
358
|
} catch {
|
|
341
359
|
const parent = path.dirname(root);
|
|
@@ -346,14 +364,14 @@ function gitCommonDirectory(directory) {
|
|
|
346
364
|
if (stat.isDirectory()) return marker;
|
|
347
365
|
let pointer;
|
|
348
366
|
try {
|
|
349
|
-
pointer = fs.
|
|
367
|
+
pointer = (await fs.readFile(marker, "utf8")).trim();
|
|
350
368
|
} catch {
|
|
351
369
|
return;
|
|
352
370
|
}
|
|
353
371
|
if (!pointer.startsWith("gitdir:")) return void 0;
|
|
354
372
|
const gitDir = path.resolve(root, pointer.slice(7).trim());
|
|
355
373
|
try {
|
|
356
|
-
const common = fs.
|
|
374
|
+
const common = (await fs.readFile(path.join(gitDir, "commondir"), "utf8")).trim();
|
|
357
375
|
return path.resolve(gitDir, common);
|
|
358
376
|
} catch {
|
|
359
377
|
return gitDir;
|
|
@@ -372,8 +390,8 @@ function repositoryLabel(root) {
|
|
|
372
390
|
* registry. Falling back to the path keeps a non-repository directory usable
|
|
373
391
|
* instead of failing, though nothing here should reach that case.
|
|
374
392
|
*/
|
|
375
|
-
function repositoryId(root) {
|
|
376
|
-
const common = gitCommonDirectory(root);
|
|
393
|
+
async function repositoryId(root) {
|
|
394
|
+
const common = await gitCommonDirectory(root);
|
|
377
395
|
const token = common === void 0 ? `root:${path.resolve(root)}` : `git:${common}`;
|
|
378
396
|
return createHash("sha256").update(token).digest("hex").slice(0, ID_LENGTH);
|
|
379
397
|
}
|
|
@@ -409,22 +427,26 @@ function credentialsFile(homeDir = os.homedir()) {
|
|
|
409
427
|
return path.join(poGitRoot(homeDir), "credentials.json");
|
|
410
428
|
}
|
|
411
429
|
/** One registry file per repository, keyed by the shared git directory. */
|
|
412
|
-
function registryFile(repositoryRoot, homeDir = os.homedir()) {
|
|
413
|
-
const id = repositoryId(repositoryRoot);
|
|
430
|
+
async function registryFile(repositoryRoot, homeDir = os.homedir()) {
|
|
431
|
+
const id = await repositoryId(repositoryRoot);
|
|
414
432
|
const root = path.join(poGitRoot(homeDir), "registry");
|
|
415
433
|
const canonical = path.join(root, id, "worktrees.json");
|
|
416
|
-
if (fs.
|
|
434
|
+
if (await fs.access(canonical).then(() => true, () => false)) return canonical;
|
|
417
435
|
let names;
|
|
418
436
|
try {
|
|
419
|
-
names = fs.
|
|
437
|
+
names = await fs.readdir(root);
|
|
420
438
|
} catch {
|
|
421
439
|
return canonical;
|
|
422
440
|
}
|
|
423
|
-
const legacyFiles =
|
|
441
|
+
const legacyFiles = [];
|
|
442
|
+
for (const entry of names.filter((name) => name.endsWith(`--${id}`)).sort()) {
|
|
443
|
+
const file = path.join(root, entry, "worktrees.json");
|
|
444
|
+
if (await fs.access(file).then(() => true, () => false)) legacyFiles.push(file);
|
|
445
|
+
}
|
|
424
446
|
if (legacyFiles.length === 0) return canonical;
|
|
425
447
|
const entries = /* @__PURE__ */ new Map();
|
|
426
448
|
for (const file of legacyFiles) {
|
|
427
|
-
const legacy = readJson(file);
|
|
449
|
+
const legacy = await readJson(file);
|
|
428
450
|
if (legacy?.version !== 1 || !Array.isArray(legacy.entries)) continue;
|
|
429
451
|
for (const value of legacy.entries) {
|
|
430
452
|
if (typeof value !== "object" || value === null || !("id" in value) || typeof value.id !== "string" || value.id === "") continue;
|
|
@@ -435,16 +457,16 @@ function registryFile(repositoryRoot, homeDir = os.homedir()) {
|
|
|
435
457
|
}
|
|
436
458
|
}
|
|
437
459
|
const temporary = `${canonical}.${randomUUID()}.migration`;
|
|
438
|
-
writeJsonAtomic(temporary, {
|
|
460
|
+
await writeJsonAtomic(temporary, {
|
|
439
461
|
version: 1,
|
|
440
462
|
entries: [...entries.values()]
|
|
441
463
|
});
|
|
442
464
|
try {
|
|
443
|
-
fs.
|
|
465
|
+
await fs.link(temporary, canonical);
|
|
444
466
|
} catch (error) {
|
|
445
467
|
if (error.code !== "EEXIST") throw error;
|
|
446
468
|
} finally {
|
|
447
|
-
fs.
|
|
469
|
+
await fs.rm(temporary);
|
|
448
470
|
}
|
|
449
471
|
return canonical;
|
|
450
472
|
}
|
|
@@ -563,18 +585,22 @@ function refuseClose(input) {
|
|
|
563
585
|
* uncommitted work, so losing the record would lose the only pointer to it.
|
|
564
586
|
* Deletion is always a separate, named decision.
|
|
565
587
|
*/
|
|
566
|
-
function reconcile(records, probe) {
|
|
588
|
+
async function reconcile(records, probe) {
|
|
567
589
|
const changed = [];
|
|
590
|
+
const next = [];
|
|
591
|
+
for (const record of records) {
|
|
592
|
+
if (record.status === "orphaned" || await probe.exists(record.path) && probe.alive(record)) {
|
|
593
|
+
next.push(record);
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
changed.push(record.id);
|
|
597
|
+
next.push({
|
|
598
|
+
...record,
|
|
599
|
+
status: "orphaned"
|
|
600
|
+
});
|
|
601
|
+
}
|
|
568
602
|
return {
|
|
569
|
-
records:
|
|
570
|
-
if (record.status === "orphaned") return record;
|
|
571
|
-
if (!(!probe.exists(record.path) || !probe.alive(record))) return record;
|
|
572
|
-
changed.push(record.id);
|
|
573
|
-
return {
|
|
574
|
-
...record,
|
|
575
|
-
status: "orphaned"
|
|
576
|
-
};
|
|
577
|
-
}),
|
|
603
|
+
records: next,
|
|
578
604
|
changed
|
|
579
605
|
};
|
|
580
606
|
}
|
|
@@ -634,25 +660,25 @@ function isRecord(value) {
|
|
|
634
660
|
*/
|
|
635
661
|
function createWorktreeRegistry(file) {
|
|
636
662
|
return {
|
|
637
|
-
list() {
|
|
638
|
-
const parsed = readJson(file);
|
|
663
|
+
async list() {
|
|
664
|
+
const parsed = await readJson(file);
|
|
639
665
|
if (!parsed || parsed.version !== 1 || !Array.isArray(parsed.entries)) return [];
|
|
640
666
|
return parsed.entries.filter(isRecord);
|
|
641
667
|
},
|
|
642
|
-
replace(entries) {
|
|
643
|
-
writeJsonAtomic(file, {
|
|
668
|
+
async replace(entries) {
|
|
669
|
+
await writeJsonAtomic(file, {
|
|
644
670
|
version: 1,
|
|
645
671
|
entries
|
|
646
672
|
});
|
|
647
673
|
},
|
|
648
674
|
async transaction(operation, signal) {
|
|
649
675
|
const lock = `${file}.lock`;
|
|
650
|
-
fs.
|
|
676
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
651
677
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
652
678
|
for (;;) {
|
|
653
679
|
signal?.throwIfAborted();
|
|
654
680
|
try {
|
|
655
|
-
fs.
|
|
681
|
+
await fs.mkdir(lock, { mode: 448 });
|
|
656
682
|
break;
|
|
657
683
|
} catch (error) {
|
|
658
684
|
if (error.code !== "EEXIST") throw error;
|
|
@@ -661,14 +687,14 @@ function createWorktreeRegistry(file) {
|
|
|
661
687
|
}
|
|
662
688
|
}
|
|
663
689
|
try {
|
|
664
|
-
fs.
|
|
690
|
+
await fs.writeFile(path.join(lock, "owner.json"), JSON.stringify({
|
|
665
691
|
pid: process.pid,
|
|
666
692
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
667
693
|
}), { mode: 384 });
|
|
668
694
|
signal?.throwIfAborted();
|
|
669
695
|
return await operation();
|
|
670
696
|
} finally {
|
|
671
|
-
fs.
|
|
697
|
+
await fs.rm(lock, { recursive: true });
|
|
672
698
|
}
|
|
673
699
|
}
|
|
674
700
|
};
|
|
@@ -678,6 +704,23 @@ function createWorktreeRegistry(file) {
|
|
|
678
704
|
const GIT_WORKTREE_DELEGATION_KIND = "git.worktree.delegation";
|
|
679
705
|
const GIT_WORKTREE_MESSAGE_KIND = "git.worktree.message";
|
|
680
706
|
const GIT_WORKTREE_REPORT_KIND = "git.worktree.report";
|
|
707
|
+
/**
|
|
708
|
+
* The repository's worktree setup as one shell command, or undefined when it asks for none.
|
|
709
|
+
* Read from the checkout the spawn starts in, so an uncommitted edit applies at once.
|
|
710
|
+
*/
|
|
711
|
+
async function readWorktreeSetup(root) {
|
|
712
|
+
const file = path.join(root, WORKTREE_CONFIG_FILE);
|
|
713
|
+
let setup;
|
|
714
|
+
try {
|
|
715
|
+
setup = load(await fs.readFile(file, "utf8"))?.setup;
|
|
716
|
+
} catch (error) {
|
|
717
|
+
if (error.code === "ENOENT") return void 0;
|
|
718
|
+
throw new PoGitExpectedError("invalid_request", `${WORKTREE_CONFIG_FILE} is not valid YAML (${error.message}).`, false, "Fix the file and try again.");
|
|
719
|
+
}
|
|
720
|
+
const commands = [setup ?? []].flat();
|
|
721
|
+
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.");
|
|
722
|
+
return commands.filter((command) => command.trim() !== "").join(" && ") || void 0;
|
|
723
|
+
}
|
|
681
724
|
function createWorktreeOperations(deps) {
|
|
682
725
|
const { git } = deps;
|
|
683
726
|
const sessionService = deps.sessionService;
|
|
@@ -698,7 +741,7 @@ function createWorktreeOperations(deps) {
|
|
|
698
741
|
};
|
|
699
742
|
const probe = {
|
|
700
743
|
alive: (record) => requireSessionService().isLive(record.sessionId),
|
|
701
|
-
exists: (path) => fs.
|
|
744
|
+
exists: (path) => fs.access(path).then(() => true, () => false)
|
|
702
745
|
};
|
|
703
746
|
/**
|
|
704
747
|
* Everything an action needs about the repository it is acting on.
|
|
@@ -710,11 +753,11 @@ function createWorktreeOperations(deps) {
|
|
|
710
753
|
const resolve = async (context) => {
|
|
711
754
|
const root = await git.repositoryRoot(context.cwd);
|
|
712
755
|
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.");
|
|
713
|
-
const store = createWorktreeRegistry(registryFile(root, deps.homeDir));
|
|
756
|
+
const store = createWorktreeRegistry(await registryFile(root, deps.homeDir));
|
|
714
757
|
return {
|
|
715
758
|
root,
|
|
716
759
|
store,
|
|
717
|
-
records: store.list()
|
|
760
|
+
records: await store.list()
|
|
718
761
|
};
|
|
719
762
|
};
|
|
720
763
|
const require = (records, id) => {
|
|
@@ -765,11 +808,11 @@ function createWorktreeOperations(deps) {
|
|
|
765
808
|
const expectedPath = worktreeDirectory({
|
|
766
809
|
worktreesRoot: worktreesRoot(deps.homeDir),
|
|
767
810
|
repositoryLabel: repositoryLabel(root),
|
|
768
|
-
repositoryId: repositoryId(root),
|
|
811
|
+
repositoryId: await repositoryId(root),
|
|
769
812
|
branch: request.branch,
|
|
770
813
|
shortId: shortId(reserved.sessionId)
|
|
771
814
|
});
|
|
772
|
-
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 || !
|
|
815
|
+
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.");
|
|
773
816
|
if (!requireSessionService().isLive(existing.sessionId)) {
|
|
774
817
|
if ((await requireSessionService().create({
|
|
775
818
|
cwd: existing.path,
|
|
@@ -789,17 +832,18 @@ function createWorktreeOperations(deps) {
|
|
|
789
832
|
});
|
|
790
833
|
if (refusal !== void 0) throw new PoGitExpectedError("worktree_exists", refusal, false, "Pick another branch name, or close it.");
|
|
791
834
|
const taskDelivery = request.task === void 0 ? void 0 : requireSessionDelivery();
|
|
835
|
+
const setup = await readWorktreeSetup(root);
|
|
792
836
|
const existingBranch = request.checkout === "existing";
|
|
793
837
|
const id = shortId(reserved?.sessionId ?? randomUUID());
|
|
794
838
|
let path = worktreeDirectory({
|
|
795
839
|
worktreesRoot: worktreesRoot(deps.homeDir),
|
|
796
840
|
repositoryLabel: repositoryLabel(root),
|
|
797
|
-
repositoryId: repositoryId(root),
|
|
841
|
+
repositoryId: await repositoryId(root),
|
|
798
842
|
branch: request.branch,
|
|
799
843
|
shortId: id
|
|
800
844
|
});
|
|
801
845
|
if (request.reservationId !== void 0) path = (await reservations.prepare(request.reservationId, parentSessionId, path)).cwd;
|
|
802
|
-
const recovering = reserved?.cwd !== void 0 &&
|
|
846
|
+
const recovering = reserved?.cwd !== void 0 && await probe.exists(path);
|
|
803
847
|
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.");
|
|
804
848
|
if (!recovering) {
|
|
805
849
|
if (existingBranch) {
|
|
@@ -871,17 +915,26 @@ function createWorktreeOperations(deps) {
|
|
|
871
915
|
createdAt: now().toISOString()
|
|
872
916
|
};
|
|
873
917
|
try {
|
|
874
|
-
store.replace([...records, record]);
|
|
918
|
+
await store.replace([...records, record]);
|
|
875
919
|
} catch (error) {
|
|
876
920
|
await requireSessionService().close(sessionId).catch(() => void 0);
|
|
877
921
|
const kept = await rollback();
|
|
878
922
|
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.");
|
|
879
923
|
}
|
|
924
|
+
let setupStarted = false;
|
|
925
|
+
if (setup !== void 0) try {
|
|
926
|
+
const service = requireSessionService();
|
|
927
|
+
if (service.prompt === void 0) throw new Error("this host cannot run session commands");
|
|
928
|
+
await service.prompt(sessionId, `${WORKTREE_SETUP_LAUNCH} ${setup}`);
|
|
929
|
+
setupStarted = true;
|
|
930
|
+
} catch (error) {
|
|
931
|
+
options?.onProgress?.(`worktree setup did not start (${String(error)})`);
|
|
932
|
+
}
|
|
880
933
|
if (request.task !== void 0 && taskDelivery !== void 0) try {
|
|
881
934
|
const receipt = await taskDelivery.deliver({
|
|
882
935
|
recipientKey: sessionId,
|
|
883
936
|
kind: GIT_WORKTREE_DELEGATION_KIND,
|
|
884
|
-
prompt: request.task,
|
|
937
|
+
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,
|
|
885
938
|
metadata: {
|
|
886
939
|
worktreeId: record.id,
|
|
887
940
|
fromRole: "parent",
|
|
@@ -904,7 +957,7 @@ function createWorktreeOperations(deps) {
|
|
|
904
957
|
requireOwner(context, record, "close");
|
|
905
958
|
const refusal = refuseClose({
|
|
906
959
|
record,
|
|
907
|
-
dirtyFiles:
|
|
960
|
+
dirtyFiles: await probe.exists(record.path) ? await git.dirtyFiles(record.path) : [],
|
|
908
961
|
force
|
|
909
962
|
});
|
|
910
963
|
if (refusal !== void 0) throw new PoGitExpectedError("worktree_dirty", refusal, false, "Commit the work, or pass force: true.");
|
|
@@ -914,13 +967,13 @@ function createWorktreeOperations(deps) {
|
|
|
914
967
|
path: record.path,
|
|
915
968
|
force
|
|
916
969
|
});
|
|
917
|
-
store.replace(records.filter((entry) => entry.id !== id));
|
|
970
|
+
await store.replace(records.filter((entry) => entry.id !== id));
|
|
918
971
|
return record;
|
|
919
972
|
},
|
|
920
973
|
async list(context) {
|
|
921
974
|
const { store, records } = await resolve(context);
|
|
922
|
-
const outcome = reconcile(records, probe);
|
|
923
|
-
if (outcome.changed.length > 0) store.replace(outcome.records);
|
|
975
|
+
const outcome = await reconcile(records, probe);
|
|
976
|
+
if (outcome.changed.length > 0) await store.replace(outcome.records);
|
|
924
977
|
return outcome.records;
|
|
925
978
|
},
|
|
926
979
|
async status(context, id) {
|
|
@@ -928,7 +981,7 @@ function createWorktreeOperations(deps) {
|
|
|
928
981
|
const record = require(records, id);
|
|
929
982
|
return {
|
|
930
983
|
record,
|
|
931
|
-
dirtyFiles:
|
|
984
|
+
dirtyFiles: await probe.exists(record.path) ? await git.dirtyFiles(record.path) : []
|
|
932
985
|
};
|
|
933
986
|
},
|
|
934
987
|
async merge(context, id, message) {
|
|
@@ -1001,10 +1054,10 @@ function createWorktreeOperations(deps) {
|
|
|
1001
1054
|
},
|
|
1002
1055
|
async prune(context, dryRun) {
|
|
1003
1056
|
const { root, store, records } = await resolve(context);
|
|
1004
|
-
const reconciled = reconcile(records, probe);
|
|
1057
|
+
const reconciled = await reconcile(records, probe);
|
|
1005
1058
|
const gitPaths = await git.listWorktreePaths(root);
|
|
1006
1059
|
const dirtyByPath = /* @__PURE__ */ new Map();
|
|
1007
|
-
for (const record of reconciled.records) if (record.status === "orphaned" &&
|
|
1060
|
+
for (const record of reconciled.records) if (record.status === "orphaned" && await probe.exists(record.path)) dirtyByPath.set(record.path, await git.dirtyFiles(record.path));
|
|
1008
1061
|
const plan = planPrune({
|
|
1009
1062
|
records: reconciled.records,
|
|
1010
1063
|
gitPaths,
|
|
@@ -1012,7 +1065,7 @@ function createWorktreeOperations(deps) {
|
|
|
1012
1065
|
dirtyByPath
|
|
1013
1066
|
});
|
|
1014
1067
|
if (dryRun) {
|
|
1015
|
-
store.replace(reconciled.records);
|
|
1068
|
+
await store.replace(reconciled.records);
|
|
1016
1069
|
return plan;
|
|
1017
1070
|
}
|
|
1018
1071
|
for (const record of plan.remove) await git.removeWorktree({
|
|
@@ -1025,7 +1078,7 @@ function createWorktreeOperations(deps) {
|
|
|
1025
1078
|
branch: record.branch
|
|
1026
1079
|
}).catch(() => false)) plan.keptBranches.push(record.branch);
|
|
1027
1080
|
const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));
|
|
1028
|
-
store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
|
|
1081
|
+
await store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
|
|
1029
1082
|
return plan;
|
|
1030
1083
|
}
|
|
1031
1084
|
};
|
|
@@ -1047,7 +1100,7 @@ function createWorktreeOperations(deps) {
|
|
|
1047
1100
|
return {
|
|
1048
1101
|
...operations,
|
|
1049
1102
|
spawn: (context, request, options) => {
|
|
1050
|
-
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
|
|
1103
|
+
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."));
|
|
1051
1104
|
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."));
|
|
1052
1105
|
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."));
|
|
1053
1106
|
return locked(context, () => operations.spawn(context, request, options), options?.signal);
|
|
@@ -1059,6 +1112,6 @@ function createWorktreeOperations(deps) {
|
|
|
1059
1112
|
};
|
|
1060
1113
|
}
|
|
1061
1114
|
//#endregion
|
|
1062
|
-
export { NETWORK_TIMEOUT_MS as _, GIT_WORKTREE_LIFECYCLE_EVENT as a,
|
|
1115
|
+
export { READ_TIMEOUT_MS as C, runGit as E, NETWORK_TIMEOUT_MS as S, createWorktreeGit as T, GIT_AUTH_PATH as _, GIT_WORKTREE_LIFECYCLE_EVENT as a, GIT_REVIEW_PATH as b, isWorktreeLifecycleEvent as c, registryFile as d, readJson as f, invalidRequest as g, PoGitExpectedError as h, GIT_SESSION_CHANGED_EVENT as i, credentialsFile as l, HubUnavailableError as m, createWorktreeRegistry as n, createWorktreeMessageInbox as o, writeJsonAtomic as p, validRefName as r, isSessionChangedEvent as s, createWorktreeOperations as t, poGitRoot as u, GIT_BRANCHES_PATH as v, REBASE_TIMEOUT_MS as w, GIT_SESSIONS_PATH as x, GIT_REVIEW_FILE_PATH as y };
|
|
1063
1116
|
|
|
1064
|
-
//# sourceMappingURL=worktreeOperations-
|
|
1117
|
+
//# sourceMappingURL=worktreeOperations-CP2lYxrI.mjs.map
|