@agimon-ai/doompi-git 0.0.1-alpha.16 → 0.0.1-alpha.18
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/{src/schemas/apiContracts.cjs → apiContracts.cjs} +9 -7
- package/dist/apiContracts.cjs.map +1 -0
- package/dist/{src/schemas/apiContracts.d.mts.map → apiContracts.d.mts.map} +1 -1
- package/dist/{src/schemas/apiContracts.mjs → apiContracts.mjs} +2 -2
- package/dist/apiContracts.mjs.map +1 -0
- package/dist/extensions/pi.cjs +82 -12
- package/dist/extensions/pi.cjs.map +1 -1
- package/dist/extensions/pi.d.mts +2 -3
- package/dist/extensions/pi.d.mts.map +1 -1
- package/dist/extensions/pi.mjs +76 -6
- package/dist/extensions/pi.mjs.map +1 -1
- package/dist/extensions/server.cjs +442 -22
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +429 -9
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/gitDependencies-C4rNqWB3.mjs +22 -0
- package/dist/gitDependencies-C4rNqWB3.mjs.map +1 -0
- package/dist/gitDependencies-aS4JV4T6.cjs +33 -0
- package/dist/gitDependencies-aS4JV4T6.cjs.map +1 -0
- package/dist/index-BQq2vblZ.d.mts +143 -0
- package/dist/index-BQq2vblZ.d.mts.map +1 -0
- package/dist/index.cjs +3 -4
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +1 -2
- package/dist/runWorktree-4Y-9N-xc.cjs +318 -0
- package/dist/runWorktree-4Y-9N-xc.cjs.map +1 -0
- package/dist/{src/services/runWorktree/index.mjs → runWorktree-DYMe2tpB.mjs} +150 -4
- package/dist/runWorktree-DYMe2tpB.mjs.map +1 -0
- package/dist/worktreeOperations-48AZFket.mjs +981 -0
- package/dist/worktreeOperations-48AZFket.mjs.map +1 -0
- package/dist/worktreeOperations-B870r6so.cjs +1065 -0
- package/dist/worktreeOperations-B870r6so.cjs.map +1 -0
- package/package.json +16 -16
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/api-contracts.cjs +0 -7
- package/dist/api-contracts.d.cts +0 -2
- package/dist/api-contracts.d.mts +0 -2
- package/dist/api-contracts.mjs +0 -2
- package/dist/extensions/pi.d.cts +0 -7
- package/dist/extensions/pi.d.cts.map +0 -1
- package/dist/extensions/server.d.cts +0 -5
- package/dist/extensions/server.d.cts.map +0 -1
- package/dist/index.d.cts +0 -4
- package/dist/src/constants/git.cjs +0 -8
- package/dist/src/constants/git.cjs.map +0 -1
- package/dist/src/constants/git.mjs +0 -7
- package/dist/src/constants/git.mjs.map +0 -1
- package/dist/src/extensions/(backend)/api/_lib/route.server.cjs +0 -93
- package/dist/src/extensions/(backend)/api/_lib/route.server.cjs.map +0 -1
- package/dist/src/extensions/(backend)/api/_lib/route.server.mjs +0 -92
- package/dist/src/extensions/(backend)/api/_lib/route.server.mjs.map +0 -1
- package/dist/src/extensions/(backend)/api/route.server.cjs +0 -7
- package/dist/src/extensions/(backend)/api/route.server.cjs.map +0 -1
- package/dist/src/extensions/(backend)/api/route.server.mjs +0 -8
- package/dist/src/extensions/(backend)/api/route.server.mjs.map +0 -1
- package/dist/src/extensions/(backend)/channel/_lib/git-worktrees.server.cjs +0 -226
- package/dist/src/extensions/(backend)/channel/_lib/git-worktrees.server.cjs.map +0 -1
- package/dist/src/extensions/(backend)/channel/_lib/git-worktrees.server.mjs +0 -225
- package/dist/src/extensions/(backend)/channel/_lib/git-worktrees.server.mjs.map +0 -1
- package/dist/src/extensions/(backend)/channel/git-worktrees.server.cjs +0 -7
- package/dist/src/extensions/(backend)/channel/git-worktrees.server.cjs.map +0 -1
- package/dist/src/extensions/(backend)/channel/git-worktrees.server.mjs +0 -8
- package/dist/src/extensions/(backend)/channel/git-worktrees.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.cli.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.cli.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.server.cjs +0 -73
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.server.mjs +0 -72
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/root.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/_lib/git.cli.cjs +0 -17
- package/dist/src/extensions/workspaces/sessions/(backend)/command/_lib/git.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/_lib/git.cli.mjs +0 -16
- package/dist/src/extensions/workspaces/sessions/(backend)/command/_lib/git.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/git.cli.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/command/git.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/git.cli.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/command/git.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompi-use-git.cli.cjs +0 -15
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompi-use-git.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompi-use-git.cli.mjs +0 -15
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompi-use-git.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGit.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGit.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGit.server.mjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGit.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGitReadme.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGitReadme.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGitReadme.server.mjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiGitReadme.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiUseGit.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiUseGit.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiUseGit.server.mjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/_lib/doompiUseGit.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-git.cli.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-git.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-git.cli.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-git.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGit.server.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGit.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGit.server.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGit.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGitReadme.server.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGitReadme.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGitReadme.server.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiGitReadme.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiUseGit.server.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiUseGit.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiUseGit.server.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompiUseGit.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/_lib/runWorktree.cli.cjs +0 -38
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/_lib/runWorktree.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/_lib/runWorktree.cli.mjs +0 -36
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/_lib/runWorktree.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.cli.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.cli.mjs +0 -8
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/tool/runWorktree.server.mjs.map +0 -1
- package/dist/src/schemas/apiContracts.cjs.map +0 -1
- package/dist/src/schemas/apiContracts.d.cts +0 -53
- package/dist/src/schemas/apiContracts.d.cts.map +0 -1
- package/dist/src/schemas/apiContracts.mjs.map +0 -1
- package/dist/src/schemas/runWorktreeTool.cjs +0 -152
- package/dist/src/schemas/runWorktreeTool.cjs.map +0 -1
- package/dist/src/schemas/runWorktreeTool.mjs +0 -150
- package/dist/src/schemas/runWorktreeTool.mjs.map +0 -1
- package/dist/src/services/atomicJson/index.cjs +0 -42
- package/dist/src/services/atomicJson/index.cjs.map +0 -1
- package/dist/src/services/atomicJson/index.mjs +0 -38
- package/dist/src/services/atomicJson/index.mjs.map +0 -1
- package/dist/src/services/compositionMirror/index.cjs +0 -119
- package/dist/src/services/compositionMirror/index.cjs.map +0 -1
- package/dist/src/services/compositionMirror/index.mjs +0 -116
- package/dist/src/services/compositionMirror/index.mjs.map +0 -1
- package/dist/src/services/errors/index.cjs +0 -29
- package/dist/src/services/errors/index.cjs.map +0 -1
- package/dist/src/services/errors/index.mjs +0 -27
- package/dist/src/services/errors/index.mjs.map +0 -1
- package/dist/src/services/extensionService/index.cjs +0 -13
- package/dist/src/services/extensionService/index.cjs.map +0 -1
- package/dist/src/services/extensionService/index.d.cts +0 -7
- package/dist/src/services/extensionService/index.d.cts.map +0 -1
- package/dist/src/services/extensionService/index.d.mts +0 -7
- package/dist/src/services/extensionService/index.d.mts.map +0 -1
- package/dist/src/services/extensionService/index.mjs +0 -13
- package/dist/src/services/extensionService/index.mjs.map +0 -1
- package/dist/src/services/gitCli/index.cjs +0 -144
- package/dist/src/services/gitCli/index.cjs.map +0 -1
- package/dist/src/services/gitCli/index.mjs +0 -142
- package/dist/src/services/gitCli/index.mjs.map +0 -1
- package/dist/src/services/gitDependencies/index.cjs +0 -14
- package/dist/src/services/gitDependencies/index.cjs.map +0 -1
- package/dist/src/services/gitDependencies/index.d.cts +0 -5
- package/dist/src/services/gitDependencies/index.d.cts.map +0 -1
- package/dist/src/services/gitDependencies/index.d.mts +0 -5
- package/dist/src/services/gitDependencies/index.d.mts.map +0 -1
- package/dist/src/services/gitDependencies/index.mjs +0 -14
- package/dist/src/services/gitDependencies/index.mjs.map +0 -1
- package/dist/src/services/paths/index.cjs +0 -75
- package/dist/src/services/paths/index.cjs.map +0 -1
- package/dist/src/services/paths/index.mjs +0 -69
- package/dist/src/services/paths/index.mjs.map +0 -1
- package/dist/src/services/repositoryIdentity/index.cjs +0 -71
- package/dist/src/services/repositoryIdentity/index.cjs.map +0 -1
- package/dist/src/services/repositoryIdentity/index.mjs +0 -65
- package/dist/src/services/repositoryIdentity/index.mjs.map +0 -1
- package/dist/src/services/runWorktree/index.cjs +0 -146
- package/dist/src/services/runWorktree/index.cjs.map +0 -1
- package/dist/src/services/runWorktree/index.mjs.map +0 -1
- package/dist/src/services/worktreeEvents/index.cjs +0 -64
- package/dist/src/services/worktreeEvents/index.cjs.map +0 -1
- package/dist/src/services/worktreeEvents/index.d.cts +0 -14
- package/dist/src/services/worktreeEvents/index.d.cts.map +0 -1
- package/dist/src/services/worktreeEvents/index.d.mts +0 -14
- package/dist/src/services/worktreeEvents/index.d.mts.map +0 -1
- package/dist/src/services/worktreeEvents/index.mjs +0 -60
- package/dist/src/services/worktreeEvents/index.mjs.map +0 -1
- package/dist/src/services/worktreeNaming/index.cjs +0 -99
- package/dist/src/services/worktreeNaming/index.cjs.map +0 -1
- package/dist/src/services/worktreeNaming/index.d.cts +0 -33
- package/dist/src/services/worktreeNaming/index.d.cts.map +0 -1
- package/dist/src/services/worktreeNaming/index.d.mts +0 -33
- package/dist/src/services/worktreeNaming/index.d.mts.map +0 -1
- package/dist/src/services/worktreeNaming/index.mjs +0 -94
- package/dist/src/services/worktreeNaming/index.mjs.map +0 -1
- package/dist/src/services/worktreeOperations/index.cjs +0 -363
- package/dist/src/services/worktreeOperations/index.cjs.map +0 -1
- package/dist/src/services/worktreeOperations/index.d.cts +0 -41
- package/dist/src/services/worktreeOperations/index.d.cts.map +0 -1
- package/dist/src/services/worktreeOperations/index.d.mts +0 -41
- package/dist/src/services/worktreeOperations/index.d.mts.map +0 -1
- package/dist/src/services/worktreeOperations/index.mjs +0 -361
- package/dist/src/services/worktreeOperations/index.mjs.map +0 -1
- package/dist/src/services/worktreeRegistry/index.cjs +0 -66
- package/dist/src/services/worktreeRegistry/index.cjs.map +0 -1
- package/dist/src/services/worktreeRegistry/index.mjs +0 -63
- package/dist/src/services/worktreeRegistry/index.mjs.map +0 -1
- package/dist/src/types/extension.d.cts +0 -16
- package/dist/src/types/extension.d.cts.map +0 -1
- package/dist/src/types/extension.d.mts +0 -16
- package/dist/src/types/extension.d.mts.map +0 -1
- package/dist/src/types/webWorktrees.cjs +0 -20
- package/dist/src/types/webWorktrees.cjs.map +0 -1
- package/dist/src/types/webWorktrees.mjs +0 -20
- package/dist/src/types/webWorktrees.mjs.map +0 -1
- package/dist/src/types/worktreeRegistry.d.cts +0 -40
- package/dist/src/types/worktreeRegistry.d.cts.map +0 -1
- package/dist/src/types/worktreeRegistry.d.mts +0 -40
- package/dist/src/types/worktreeRegistry.d.mts.map +0 -1
- /package/dist/{src/schemas/apiContracts.d.mts → apiContracts.d.mts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../src/services/worktreeOperations/index.ts"],"mappings":";;;;;;iBAmBiB;;EAEf;;EAEA;;iBAGe;EACf;EACA;EACA;EACA;;EAEA;;iBAGe;;EAEf,SAAS;;EAET,cAAc;;iBAGC;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,QAA9B"}
|
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { mirrorComposition } from "../compositionMirror/index.mjs";
|
|
2
|
-
import { DoomGitExpectedError, HubUnavailableError } from "../errors/index.mjs";
|
|
3
|
-
import { repositoryId, repositoryLabel, shortId } from "../repositoryIdentity/index.mjs";
|
|
4
|
-
import { registryFile, worktreesRoot } from "../paths/index.mjs";
|
|
5
|
-
import { MAX_WORKTREE_MESSAGE_BYTES } from "../worktreeEvents/index.mjs";
|
|
6
|
-
import { planPrune, reconcile, refuseClose, refuseSpawn, worktreeDirectory } from "../worktreeNaming/index.mjs";
|
|
7
|
-
import { createWorktreeRegistry } from "../worktreeRegistry/index.mjs";
|
|
8
|
-
import fs from "node:fs";
|
|
9
|
-
import { randomUUID } from "node:crypto";
|
|
10
|
-
//#region src/services/worktreeOperations/index.ts
|
|
11
|
-
const GIT_WORKTREE_DELEGATION_KIND = "git.worktree.delegation";
|
|
12
|
-
const GIT_WORKTREE_MESSAGE_KIND = "git.worktree.message";
|
|
13
|
-
const GIT_WORKTREE_REPORT_KIND = "git.worktree.report";
|
|
14
|
-
function createWorktreeOperations(deps) {
|
|
15
|
-
const { git } = deps;
|
|
16
|
-
const sessionService = deps.sessionService;
|
|
17
|
-
const mirror = deps.mirror ?? mirrorComposition;
|
|
18
|
-
const now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
19
|
-
const requireSessionService = () => {
|
|
20
|
-
if (sessionService === void 0) throw new HubUnavailableError("The cockpit session service is unavailable. Start the cockpit and try again.");
|
|
21
|
-
return sessionService;
|
|
22
|
-
};
|
|
23
|
-
const requireMessageInbox = () => {
|
|
24
|
-
if (deps.messageInbox === void 0) throw new HubUnavailableError("The Git message service is unavailable. Start the cockpit and try again.");
|
|
25
|
-
return deps.messageInbox;
|
|
26
|
-
};
|
|
27
|
-
const readSessionDelivery = () => deps.sessionDelivery?.();
|
|
28
|
-
const requireSessionDelivery = () => {
|
|
29
|
-
const delivery = readSessionDelivery();
|
|
30
|
-
if (delivery === void 0) throw new HubUnavailableError("The Session delivery service is unavailable. Start the cockpit and try again.");
|
|
31
|
-
return delivery;
|
|
32
|
-
};
|
|
33
|
-
const probe = {
|
|
34
|
-
alive: (record) => requireSessionService().isLive(record.sessionId),
|
|
35
|
-
exists: (path) => fs.existsSync(path)
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Everything an action needs about the repository it is acting on.
|
|
39
|
-
*
|
|
40
|
-
* Resolved per call rather than cached: a session's cwd is stable, but the
|
|
41
|
-
* worktree registry is shared and another process may have written it since
|
|
42
|
-
* the last call.
|
|
43
|
-
*/
|
|
44
|
-
const resolve = async (context) => {
|
|
45
|
-
const root = await git.repositoryRoot(context.cwd);
|
|
46
|
-
if (root === void 0) throw new DoomGitExpectedError("not_a_repository", `${context.cwd} is not inside a git repository.`, false, "Run this from a repository checkout.");
|
|
47
|
-
const store = createWorktreeRegistry(registryFile(root, deps.homeDir));
|
|
48
|
-
return {
|
|
49
|
-
root,
|
|
50
|
-
store,
|
|
51
|
-
records: store.list()
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const require = (records, id) => {
|
|
55
|
-
const record = records.find((entry) => entry.id === id);
|
|
56
|
-
if (record === void 0) throw new DoomGitExpectedError("worktree_not_found", `No worktree with id ${id}.`, false, "Call list to see the current ids.");
|
|
57
|
-
return record;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Refuses to destroy or merge a worktree another live session is using.
|
|
61
|
-
*
|
|
62
|
-
* `parentSessionId` records who asked for the worktree. Two sessions in one
|
|
63
|
-
* checkout share this registry, so without the check either could close the
|
|
64
|
-
* other's work in progress by id.
|
|
65
|
-
*
|
|
66
|
-
* Once that session is gone there is no owner left to protect, and refusing
|
|
67
|
-
* would strand the worktree: nothing else could ever close it.
|
|
68
|
-
*/
|
|
69
|
-
const requireOwner = (context, record, action) => {
|
|
70
|
-
if (record.parentSessionId === context.sessionId) return;
|
|
71
|
-
if (!requireSessionService().isLive(record.parentSessionId)) return;
|
|
72
|
-
throw new DoomGitExpectedError("worktree_not_owned", `Worktree ${record.id} belongs to another session.`, false, `Ask the session that created it to ${action} it, or close that session first.`);
|
|
73
|
-
};
|
|
74
|
-
const peerFor = (context, record) => {
|
|
75
|
-
if (context.sessionId === record.parentSessionId) return {
|
|
76
|
-
sessionId: record.sessionId,
|
|
77
|
-
party: "parent"
|
|
78
|
-
};
|
|
79
|
-
if (context.sessionId === record.sessionId) return {
|
|
80
|
-
sessionId: record.parentSessionId,
|
|
81
|
-
party: "child"
|
|
82
|
-
};
|
|
83
|
-
throw new DoomGitExpectedError("worktree_not_owned", `Worktree ${record.id} belongs to another session.`, false, "Use a worktree owned by this session.");
|
|
84
|
-
};
|
|
85
|
-
const requirePeerLive = (peerSessionId) => {
|
|
86
|
-
if (!requireSessionService().isLive(peerSessionId)) throw new DoomGitExpectedError("worktree_peer_unavailable", "The other worktree session is no longer live.", false, "Start a new worktree session before sending a message.");
|
|
87
|
-
};
|
|
88
|
-
const operations = {
|
|
89
|
-
async spawn(context, request, options) {
|
|
90
|
-
const { root, store, records } = await resolve(context);
|
|
91
|
-
const reservations = request.reservationId === void 0 ? void 0 : requireSessionService().reservations;
|
|
92
|
-
if (request.reservationId !== void 0 && (!reservations || request.task !== void 0)) throw new DoomGitExpectedError("invalid_request", "Reserved worktree sessions require host setup and cannot start a task.", false, "Create the session from its pending setup card.");
|
|
93
|
-
const reserved = request.reservationId === void 0 ? void 0 : reservations.read(request.reservationId, context.sessionId);
|
|
94
|
-
const existing = reserved === void 0 ? void 0 : records.find((record) => record.sessionId === reserved.sessionId);
|
|
95
|
-
if (existing) {
|
|
96
|
-
if (existing.parentSessionId !== context.sessionId || existing.branch !== request.branch || existing.path !== reserved?.cwd || request.baseRef !== void 0 && existing.baseRef !== request.baseRef) throw new DoomGitExpectedError("invalid_request", "This setup already owns a different worktree.", false, "Recover its existing branch and checkout.");
|
|
97
|
-
await reservations.complete(request.reservationId, context.sessionId);
|
|
98
|
-
return existing;
|
|
99
|
-
}
|
|
100
|
-
const refusal = refuseSpawn({
|
|
101
|
-
branch: request.branch,
|
|
102
|
-
existing: records
|
|
103
|
-
});
|
|
104
|
-
if (refusal !== void 0) throw new DoomGitExpectedError("worktree_exists", refusal, false, "Pick another branch name, or close it.");
|
|
105
|
-
const taskDelivery = request.task === void 0 ? void 0 : requireSessionDelivery();
|
|
106
|
-
const baseRef = request.baseRef ?? await git.currentBranch(root) ?? "HEAD";
|
|
107
|
-
const id = shortId(reserved?.sessionId ?? randomUUID());
|
|
108
|
-
let path = worktreeDirectory({
|
|
109
|
-
worktreesRoot: worktreesRoot(deps.homeDir),
|
|
110
|
-
repositoryLabel: repositoryLabel(root),
|
|
111
|
-
repositoryId: repositoryId(root),
|
|
112
|
-
branch: request.branch,
|
|
113
|
-
shortId: id
|
|
114
|
-
});
|
|
115
|
-
if (request.reservationId !== void 0) path = (await reservations.prepare(request.reservationId, context.sessionId, path)).cwd;
|
|
116
|
-
const recovering = reserved?.cwd !== void 0 && fs.existsSync(path);
|
|
117
|
-
if (recovering && (!(await git.listWorktreePaths(root)).includes(path) || await git.currentBranch(path) !== request.branch)) throw new DoomGitExpectedError("invalid_request", "The reserved checkout no longer matches this setup.", false, "Inspect the existing directory; it will not be replaced.");
|
|
118
|
-
const cancelled = () => options?.signal?.aborted === true;
|
|
119
|
-
const rollback = async () => {
|
|
120
|
-
if (reserved) return ` The reserved checkout at ${path} was retained for recovery.`;
|
|
121
|
-
await git.removeWorktree({
|
|
122
|
-
repositoryRoot: root,
|
|
123
|
-
path,
|
|
124
|
-
force: true
|
|
125
|
-
}).catch(() => void 0);
|
|
126
|
-
return await git.deleteBranch({
|
|
127
|
-
repositoryRoot: root,
|
|
128
|
-
branch: request.branch
|
|
129
|
-
}).catch(() => false) ? "" : ` The branch ${request.branch} has work on it and was kept.`;
|
|
130
|
-
};
|
|
131
|
-
options?.onProgress?.(`creating branch ${request.branch}\u2026`);
|
|
132
|
-
if (!recovering) await git.addWorktree({
|
|
133
|
-
repositoryRoot: root,
|
|
134
|
-
path,
|
|
135
|
-
branch: request.branch,
|
|
136
|
-
baseRef
|
|
137
|
-
});
|
|
138
|
-
if (cancelled()) {
|
|
139
|
-
const kept = await rollback();
|
|
140
|
-
throw new DoomGitExpectedError("spawn_cancelled", `Cancelled before the session started.${kept}`, false, reserved ? "Retry setup with the same branch to recover the reserved checkout." : "The worktree was removed; run it again when you are ready.");
|
|
141
|
-
}
|
|
142
|
-
options?.onProgress?.("mirroring build output…");
|
|
143
|
-
if (!recovering) mirror(root, path);
|
|
144
|
-
options?.onProgress?.("starting session…");
|
|
145
|
-
let sessionId;
|
|
146
|
-
try {
|
|
147
|
-
sessionId = (await requireSessionService().create({
|
|
148
|
-
cwd: path,
|
|
149
|
-
name: request.name ?? request.branch,
|
|
150
|
-
parentSessionId: context.sessionId,
|
|
151
|
-
sessionProvenance: "worktree",
|
|
152
|
-
...options?.signal === void 0 ? {} : { signal: options.signal },
|
|
153
|
-
...request.reservationId === void 0 ? {} : { reservationId: request.reservationId }
|
|
154
|
-
})).sessionId;
|
|
155
|
-
if (reserved && sessionId !== reserved.sessionId) throw new Error("The host did not use the reserved session identity.");
|
|
156
|
-
} catch (error) {
|
|
157
|
-
const kept = await rollback();
|
|
158
|
-
if (cancelled()) throw new DoomGitExpectedError("spawn_cancelled", `Cancelled while the session was starting.${kept}`, false, reserved ? "Retry setup with the same branch to recover the reserved checkout." : "The worktree was removed; run it again when you are ready.");
|
|
159
|
-
if (error instanceof HubUnavailableError) throw new DoomGitExpectedError("hub_unavailable", `${error.message}${kept}`, true, "Start the cockpit and try again.");
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
const record = {
|
|
163
|
-
version: 1,
|
|
164
|
-
id,
|
|
165
|
-
branch: request.branch,
|
|
166
|
-
baseRef,
|
|
167
|
-
path,
|
|
168
|
-
repositoryRoot: root,
|
|
169
|
-
sessionId,
|
|
170
|
-
parentSessionId: context.sessionId,
|
|
171
|
-
status: "running",
|
|
172
|
-
createdAt: now().toISOString()
|
|
173
|
-
};
|
|
174
|
-
try {
|
|
175
|
-
store.replace([...records, record]);
|
|
176
|
-
} catch (error) {
|
|
177
|
-
await requireSessionService().close(sessionId).catch(() => void 0);
|
|
178
|
-
const kept = await rollback();
|
|
179
|
-
throw new DoomGitExpectedError("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.");
|
|
180
|
-
}
|
|
181
|
-
if (request.task !== void 0 && taskDelivery !== void 0) try {
|
|
182
|
-
const receipt = await taskDelivery.deliver({
|
|
183
|
-
recipientKey: sessionId,
|
|
184
|
-
kind: GIT_WORKTREE_DELEGATION_KIND,
|
|
185
|
-
prompt: request.task,
|
|
186
|
-
metadata: {
|
|
187
|
-
worktreeId: record.id,
|
|
188
|
-
fromRole: "parent",
|
|
189
|
-
text: request.task,
|
|
190
|
-
sentAt: record.createdAt
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
const admission = await taskDelivery.waitForAdmission(receipt.deliveryId);
|
|
194
|
-
if (admission !== "admitted") throw new Error(admission === "recovery_required" ? "The recipient could not admit the task." : "The recipient did not confirm task admission before the timeout.");
|
|
195
|
-
} catch (error) {
|
|
196
|
-
throw new DoomGitExpectedError("task_delivery_failed", `Worktree ${record.id} was created, but its task admission was not confirmed (${error.message}).`, true, `Use send with worktree ${record.id} to deliver the task without recreating the worktree.`);
|
|
197
|
-
}
|
|
198
|
-
if (request.reservationId !== void 0) await reservations.complete(request.reservationId, context.sessionId);
|
|
199
|
-
return record;
|
|
200
|
-
},
|
|
201
|
-
async close(context, id, force) {
|
|
202
|
-
const { root, store, records } = await resolve(context);
|
|
203
|
-
const record = require(records, id);
|
|
204
|
-
requireOwner(context, record, "close");
|
|
205
|
-
const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];
|
|
206
|
-
const refusal = refuseClose({
|
|
207
|
-
record,
|
|
208
|
-
dirtyFiles,
|
|
209
|
-
force
|
|
210
|
-
});
|
|
211
|
-
if (refusal !== void 0) throw new DoomGitExpectedError("worktree_dirty", refusal, false, "Commit the work, or pass force: true.");
|
|
212
|
-
await requireSessionService().close(record.sessionId);
|
|
213
|
-
await git.removeWorktree({
|
|
214
|
-
repositoryRoot: root,
|
|
215
|
-
path: record.path,
|
|
216
|
-
force
|
|
217
|
-
});
|
|
218
|
-
store.replace(records.filter((entry) => entry.id !== id));
|
|
219
|
-
return record;
|
|
220
|
-
},
|
|
221
|
-
async list(context) {
|
|
222
|
-
const { store, records } = await resolve(context);
|
|
223
|
-
const outcome = reconcile(records, probe);
|
|
224
|
-
if (outcome.changed.length > 0) store.replace(outcome.records);
|
|
225
|
-
return outcome.records;
|
|
226
|
-
},
|
|
227
|
-
async status(context, id) {
|
|
228
|
-
const { records } = await resolve(context);
|
|
229
|
-
const record = require(records, id);
|
|
230
|
-
return {
|
|
231
|
-
record,
|
|
232
|
-
dirtyFiles: fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : []
|
|
233
|
-
};
|
|
234
|
-
},
|
|
235
|
-
async merge(context, id, message) {
|
|
236
|
-
const { root, records } = await resolve(context);
|
|
237
|
-
const record = require(records, id);
|
|
238
|
-
requireOwner(context, record, "merge");
|
|
239
|
-
const parentDirty = await git.dirtyFiles(root);
|
|
240
|
-
if (parentDirty.length > 0) throw new DoomGitExpectedError("worktree_dirty", `The parent checkout has ${String(parentDirty.length)} uncommitted file(s): ${parentDirty.slice(0, 10).join(", ")}.`, false, "Commit or stash the parent checkout first.");
|
|
241
|
-
await git.mergeBranch({
|
|
242
|
-
repositoryRoot: root,
|
|
243
|
-
branch: record.branch,
|
|
244
|
-
...message === void 0 ? {} : { message }
|
|
245
|
-
});
|
|
246
|
-
return record;
|
|
247
|
-
},
|
|
248
|
-
/** Sends only between the parent session and its own worktree session. */
|
|
249
|
-
async send(context, id, message) {
|
|
250
|
-
if (Buffer.byteLength(message, "utf8") > 65536) throw new DoomGitExpectedError("message_too_large", `A message may not exceed ${String(MAX_WORKTREE_MESSAGE_BYTES)} bytes.`, false, "Send a shorter message.");
|
|
251
|
-
const { records } = await resolve(context);
|
|
252
|
-
const record = require(records, id);
|
|
253
|
-
const peer = peerFor(context, record);
|
|
254
|
-
requirePeerLive(peer.sessionId);
|
|
255
|
-
const sentAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
256
|
-
const delivery = readSessionDelivery();
|
|
257
|
-
if (delivery !== void 0) {
|
|
258
|
-
const kind = peer.party === "parent" ? GIT_WORKTREE_MESSAGE_KIND : GIT_WORKTREE_REPORT_KIND;
|
|
259
|
-
const receipt = await delivery.deliver({
|
|
260
|
-
recipientKey: peer.sessionId,
|
|
261
|
-
kind,
|
|
262
|
-
prompt: peer.party === "parent" ? `Parent message for worktree ${record.id}:\n\n${message}` : `Report from worktree ${record.id}:\n\n${message}`,
|
|
263
|
-
metadata: {
|
|
264
|
-
worktreeId: record.id,
|
|
265
|
-
fromRole: peer.party,
|
|
266
|
-
text: message,
|
|
267
|
-
sentAt
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
const admission = await delivery.waitForAdmission(receipt.deliveryId);
|
|
271
|
-
if (admission !== "admitted") throw new DoomGitExpectedError("message_delivery_failed", `Worktree ${record.id} persisted the message, but its session did not confirm admission.`, true, admission === "recovery_required" ? "Call messages from the recipient session to recover the persisted text." : "The message remains durable; retry after the recipient is ready.");
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
requireMessageInbox().send(peer.sessionId, {
|
|
275
|
-
version: 1,
|
|
276
|
-
worktreeId: record.id,
|
|
277
|
-
fromSessionId: context.sessionId,
|
|
278
|
-
from: peer.party,
|
|
279
|
-
text: message,
|
|
280
|
-
sentAt
|
|
281
|
-
});
|
|
282
|
-
},
|
|
283
|
-
async messages(context, id) {
|
|
284
|
-
const { records } = await resolve(context);
|
|
285
|
-
const record = require(records, id);
|
|
286
|
-
const peer = peerFor(context, record);
|
|
287
|
-
const delivery = readSessionDelivery();
|
|
288
|
-
if (delivery === void 0) return requireMessageInbox().receive(record.id);
|
|
289
|
-
return delivery.inbox({
|
|
290
|
-
consumed: false,
|
|
291
|
-
metadata: { worktreeId: record.id }
|
|
292
|
-
}).filter((entry) => entry.senderKey === peer.sessionId && (entry.state === "admitted" || entry.state === "recovery_required") && (peer.party === "parent" ? entry.kind === GIT_WORKTREE_REPORT_KIND : entry.kind === GIT_WORKTREE_MESSAGE_KIND || entry.kind === GIT_WORKTREE_DELEGATION_KIND)).map((entry) => {
|
|
293
|
-
delivery.consume(entry.deliveryId);
|
|
294
|
-
return {
|
|
295
|
-
version: 1,
|
|
296
|
-
worktreeId: record.id,
|
|
297
|
-
fromSessionId: entry.senderKey,
|
|
298
|
-
from: peer.party === "parent" ? "child" : "parent",
|
|
299
|
-
text: entry.state === "recovery_required" ? `[Recovery required: prompt admission was not confirmed] ${entry.metadata.text ?? entry.prompt}` : entry.metadata.text ?? entry.prompt,
|
|
300
|
-
sentAt: entry.metadata.sentAt ?? ""
|
|
301
|
-
};
|
|
302
|
-
});
|
|
303
|
-
},
|
|
304
|
-
async prune(context, dryRun) {
|
|
305
|
-
const { root, store, records } = await resolve(context);
|
|
306
|
-
const reconciled = reconcile(records, probe);
|
|
307
|
-
const gitPaths = await git.listWorktreePaths(root);
|
|
308
|
-
const dirtyByPath = /* @__PURE__ */ new Map();
|
|
309
|
-
for (const record of reconciled.records) if (record.status === "orphaned" && fs.existsSync(record.path)) dirtyByPath.set(record.path, await git.dirtyFiles(record.path));
|
|
310
|
-
const plan = planPrune({
|
|
311
|
-
records: reconciled.records,
|
|
312
|
-
gitPaths,
|
|
313
|
-
worktreesRoot: worktreesRoot(deps.homeDir),
|
|
314
|
-
dirtyByPath
|
|
315
|
-
});
|
|
316
|
-
if (dryRun) {
|
|
317
|
-
store.replace(reconciled.records);
|
|
318
|
-
return plan;
|
|
319
|
-
}
|
|
320
|
-
for (const record of plan.remove) await git.removeWorktree({
|
|
321
|
-
repositoryRoot: root,
|
|
322
|
-
path: record.path,
|
|
323
|
-
force: false
|
|
324
|
-
});
|
|
325
|
-
for (const record of [...plan.remove, ...plan.forget]) if (!await git.deleteBranch({
|
|
326
|
-
repositoryRoot: root,
|
|
327
|
-
branch: record.branch
|
|
328
|
-
}).catch(() => false)) plan.keptBranches.push(record.branch);
|
|
329
|
-
const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));
|
|
330
|
-
store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));
|
|
331
|
-
return plan;
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
const locked = async (context, operation, signal) => {
|
|
335
|
-
try {
|
|
336
|
-
const { store } = await resolve(context);
|
|
337
|
-
return await store.transaction(operation, signal);
|
|
338
|
-
} catch (error) {
|
|
339
|
-
if (signal?.aborted && !(error instanceof DoomGitExpectedError)) throw new DoomGitExpectedError("spawn_cancelled", "The worktree operation was cancelled.", false, "Inspect its recorded state before retrying.");
|
|
340
|
-
if ([
|
|
341
|
-
"ENOTDIR",
|
|
342
|
-
"EACCES",
|
|
343
|
-
"EROFS",
|
|
344
|
-
"ENOSPC"
|
|
345
|
-
].includes(String(error.code))) throw new DoomGitExpectedError("registry_write_failed", "The worktree registry is not writable.", true, "Check permissions and free space before retrying.");
|
|
346
|
-
throw error;
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
return {
|
|
350
|
-
...operations,
|
|
351
|
-
spawn: (context, request, options) => locked(context, () => operations.spawn(context, request, options), options?.signal),
|
|
352
|
-
close: (context, id, force) => locked(context, () => operations.close(context, id, force)),
|
|
353
|
-
list: (context) => locked(context, () => operations.list(context)),
|
|
354
|
-
merge: (context, id, message) => locked(context, () => operations.merge(context, id, message)),
|
|
355
|
-
prune: (context, dryRun) => locked(context, () => operations.prune(context, dryRun))
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
//#endregion
|
|
359
|
-
export { createWorktreeOperations };
|
|
360
|
-
|
|
361
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/services/worktreeOperations/index.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport fs from 'node:fs';\n\nimport type { DoomHubSessionService } from '@agimon-ai/doompi-core/hub-channel';\nimport type { DoomSessionDeliveryService } from '@agimon-ai/doompi-session';\n\nimport { WORKTREE_RECORD_VERSION } from '../../types/worktreeRegistry';\nimport type { WorktreeGit, WorktreeRecord } from '../../types/worktreeRegistry';\nimport { mirrorComposition } from '../compositionMirror';\nimport { DoomGitExpectedError, HubUnavailableError } from '../errors';\nimport { registryFile, worktreesRoot } from '../paths';\nimport { repositoryId, repositoryLabel, shortId } from '../repositoryIdentity';\nimport { MAX_WORKTREE_MESSAGE_BYTES, type WorktreeMessageInbox, type WorktreeMessageParty } from '../worktreeEvents';\nimport { planPrune, reconcile, refuseClose, refuseSpawn, worktreeDirectory } from '../worktreeNaming';\nimport { createWorktreeRegistry } from '../worktreeRegistry';\n\nconst GIT_WORKTREE_DELEGATION_KIND = 'git.worktree.delegation';\nconst GIT_WORKTREE_MESSAGE_KIND = 'git.worktree.message';\nconst GIT_WORKTREE_REPORT_KIND = 'git.worktree.report';\nexport interface WorktreeContext {\n /** Where the calling session is working, used to find the repository. */\n cwd: string;\n /** The calling session, recorded as the new session's parent. */\n sessionId: string;\n}\n\nexport interface SpawnWorktreeRequest {\n branch: string;\n baseRef?: string;\n name?: string;\n task?: string;\n /** Host-owned execution setup, exposed by the UI rather than the agent tool. */\n reservationId?: string;\n}\n\nexport interface SpawnOptions {\n /** Aborted when the caller gives up, so a spawn nobody is waiting for stops. */\n signal?: AbortSignal;\n /** Phase labels, for a caller that can show them while the work runs. */\n onProgress?: (label: string) => void;\n}\n\nexport interface WorktreeOperations {\n spawn(context: WorktreeContext, request: SpawnWorktreeRequest, options?: SpawnOptions): Promise<WorktreeRecord>;\n close(context: WorktreeContext, id: string, force: boolean): Promise<WorktreeRecord>;\n list(context: WorktreeContext): Promise<WorktreeRecord[]>;\n status(context: WorktreeContext, id: string): Promise<{ record: WorktreeRecord; dirtyFiles: string[] }>;\n merge(context: WorktreeContext, id: string, message?: string): Promise<WorktreeRecord>;\n prune(context: WorktreeContext, dryRun: boolean): Promise<ReturnType<typeof planPrune>>;\n send(context: WorktreeContext, id: string, message: string): Promise<void>;\n messages(context: WorktreeContext, id: string): Promise<import('../worktreeEvents').WorktreeMessage[]>;\n}\n\nexport interface WorktreeOperationsDeps {\n git: WorktreeGit;\n /** The canonical hub-owned session lifecycle. */\n sessionService?: DoomHubSessionService;\n /** Legacy in-memory fallback used outside the fixed Session composition. */\n messageInbox?: WorktreeMessageInbox;\n /** Reads the active Session provider when an operation executes. */\n sessionDelivery?: () => DoomSessionDeliveryService | undefined;\n /** Injected so a test never copies a real dependency tree. */\n mirror?: typeof mirrorComposition;\n homeDir?: string;\n /** Injected so a record's createdAt is reproducible in a test. */\n now?: () => Date;\n}\n\nexport function createWorktreeOperations(deps: WorktreeOperationsDeps): WorktreeOperations {\n const { git } = deps;\n const sessionService = deps.sessionService;\n const mirror = deps.mirror ?? mirrorComposition;\n const now = deps.now ?? (() => new Date());\n const requireSessionService = (): DoomHubSessionService => {\n if (sessionService === undefined)\n throw new HubUnavailableError('The cockpit session service is unavailable. Start the cockpit and try again.');\n return sessionService;\n };\n const requireMessageInbox = (): WorktreeMessageInbox => {\n if (deps.messageInbox === undefined)\n throw new HubUnavailableError('The Git message service is unavailable. Start the cockpit and try again.');\n return deps.messageInbox;\n };\n const readSessionDelivery = (): DoomSessionDeliveryService | undefined => deps.sessionDelivery?.();\n const requireSessionDelivery = (): DoomSessionDeliveryService => {\n const delivery = readSessionDelivery();\n if (delivery === undefined)\n throw new HubUnavailableError('The Session delivery service is unavailable. Start the cockpit and try again.');\n return delivery;\n };\n const probe = {\n alive: (record: WorktreeRecord) => requireSessionService().isLive(record.sessionId),\n exists: (path: string) => fs.existsSync(path),\n };\n\n /**\n * Everything an action needs about the repository it is acting on.\n *\n * Resolved per call rather than cached: a session's cwd is stable, but the\n * worktree registry is shared and another process may have written it since\n * the last call.\n */\n const resolve = async (context: WorktreeContext) => {\n const root = await git.repositoryRoot(context.cwd);\n if (root === undefined) {\n throw new DoomGitExpectedError(\n 'not_a_repository',\n `${context.cwd} is not inside a git repository.`,\n false,\n 'Run this from a repository checkout.',\n );\n }\n const store = createWorktreeRegistry(registryFile(root, deps.homeDir));\n return { root, store, records: store.list() };\n };\n\n const require = (records: readonly WorktreeRecord[], id: string): WorktreeRecord => {\n const record = records.find((entry) => entry.id === id);\n if (record === undefined) {\n throw new DoomGitExpectedError(\n 'worktree_not_found',\n `No worktree with id ${id}.`,\n false,\n 'Call list to see the current ids.',\n );\n }\n return record;\n };\n\n /**\n * Refuses to destroy or merge a worktree another live session is using.\n *\n * `parentSessionId` records who asked for the worktree. Two sessions in one\n * checkout share this registry, so without the check either could close the\n * other's work in progress by id.\n *\n * Once that session is gone there is no owner left to protect, and refusing\n * would strand the worktree: nothing else could ever close it.\n */\n const requireOwner = (context: WorktreeContext, record: WorktreeRecord, action: string): void => {\n if (record.parentSessionId === context.sessionId) return;\n if (!requireSessionService().isLive(record.parentSessionId)) return;\n throw new DoomGitExpectedError(\n 'worktree_not_owned',\n `Worktree ${record.id} belongs to another session.`,\n false,\n `Ask the session that created it to ${action} it, or close that session first.`,\n );\n };\n\n const peerFor = (\n context: WorktreeContext,\n record: WorktreeRecord,\n ): { sessionId: string; party: WorktreeMessageParty } => {\n if (context.sessionId === record.parentSessionId) return { sessionId: record.sessionId, party: 'parent' };\n if (context.sessionId === record.sessionId) return { sessionId: record.parentSessionId, party: 'child' };\n throw new DoomGitExpectedError(\n 'worktree_not_owned',\n `Worktree ${record.id} belongs to another session.`,\n false,\n 'Use a worktree owned by this session.',\n );\n };\n\n const requirePeerLive = (peerSessionId: string): void => {\n if (!requireSessionService().isLive(peerSessionId)) {\n throw new DoomGitExpectedError(\n 'worktree_peer_unavailable',\n 'The other worktree session is no longer live.',\n false,\n 'Start a new worktree session before sending a message.',\n );\n }\n };\n\n const operations: WorktreeOperations = {\n async spawn(context, request, options) {\n const { root, store, records } = await resolve(context);\n const reservations = request.reservationId === undefined ? undefined : requireSessionService().reservations;\n if (request.reservationId !== undefined && (!reservations || request.task !== undefined))\n throw new DoomGitExpectedError(\n 'invalid_request',\n 'Reserved worktree sessions require host setup and cannot start a task.',\n false,\n 'Create the session from its pending setup card.',\n );\n const reserved =\n request.reservationId === undefined ? undefined : reservations!.read(request.reservationId, context.sessionId);\n const existing =\n reserved === undefined ? undefined : records.find((record) => record.sessionId === reserved.sessionId);\n if (existing) {\n if (\n existing.parentSessionId !== context.sessionId ||\n existing.branch !== request.branch ||\n existing.path !== reserved?.cwd ||\n (request.baseRef !== undefined && existing.baseRef !== request.baseRef)\n )\n throw new DoomGitExpectedError(\n 'invalid_request',\n 'This setup already owns a different worktree.',\n false,\n 'Recover its existing branch and checkout.',\n );\n await reservations!.complete(request.reservationId!, context.sessionId);\n return existing;\n }\n const refusal = refuseSpawn({ branch: request.branch, existing: records });\n if (refusal !== undefined) {\n throw new DoomGitExpectedError('worktree_exists', refusal, false, 'Pick another branch name, or close it.');\n }\n const taskDelivery = request.task === undefined ? undefined : requireSessionDelivery();\n const baseRef = request.baseRef ?? (await git.currentBranch(root)) ?? 'HEAD';\n const id = shortId(reserved?.sessionId ?? randomUUID());\n let path = worktreeDirectory({\n worktreesRoot: worktreesRoot(deps.homeDir),\n repositoryLabel: repositoryLabel(root),\n repositoryId: repositoryId(root),\n branch: request.branch,\n shortId: id,\n });\n if (request.reservationId !== undefined) {\n path = (await reservations!.prepare(request.reservationId, context.sessionId, path)).cwd;\n }\n const recovering = reserved?.cwd !== undefined && fs.existsSync(path);\n if (\n recovering &&\n (!(await git.listWorktreePaths(root)).includes(path) || (await git.currentBranch(path)) !== request.branch)\n )\n throw new DoomGitExpectedError(\n 'invalid_request',\n 'The reserved checkout no longer matches this setup.',\n false,\n 'Inspect the existing directory; it will not be replaced.',\n );\n // The worktree and the branch are made by one command, so they are undone\n // by one too. `worktree remove` leaves the branch behind, and a branch\n // nobody asked for is what a failed spawn used to leave on the floor.\n const cancelled = (): boolean => options?.signal?.aborted === true;\n const rollback = async (): Promise<string> => {\n if (reserved) return ` The reserved checkout at ${path} was retained for recovery.`;\n await git.removeWorktree({ repositoryRoot: root, path, force: true }).catch(() => undefined);\n const deleted = await git.deleteBranch({ repositoryRoot: root, branch: request.branch }).catch(() => false);\n return deleted ? '' : ` The branch ${request.branch} has work on it and was kept.`;\n };\n\n options?.onProgress?.(`creating branch ${request.branch}\\u2026`);\n if (!recovering) await git.addWorktree({ repositoryRoot: root, path, branch: request.branch, baseRef });\n\n // Checked here rather than only inside the session call: this is the\n // point where a checkout exists that nothing has recorded yet, which is\n // exactly the state an interrupted spawn used to leave behind.\n if (cancelled()) {\n const kept = await rollback();\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n `Cancelled before the session started.${kept}`,\n false,\n reserved\n ? 'Retry setup with the same branch to recover the reserved checkout.'\n : 'The worktree was removed; run it again when you are ready.',\n );\n }\n\n // Before the session, because the session composes the extensions this\n // repository's config names and those live in build output git does not\n // track. A worktree without it starts and dies on the first package it\n // cannot resolve. Nothing here can fail the spawn: a repository with no\n // build output to mirror simply has none.\n options?.onProgress?.('mirroring build output\\u2026');\n if (!recovering) mirror(root, path);\n\n // The worktree exists from here on, so every later failure has to leave\n // it removed or recorded. An unrecorded directory on disk is the one\n // outcome with no way back: nothing would ever list it again.\n options?.onProgress?.('starting session\\u2026');\n let sessionId: string;\n try {\n const session = await requireSessionService().create({\n cwd: path,\n name: request.name ?? request.branch,\n parentSessionId: context.sessionId,\n sessionProvenance: 'worktree',\n ...(options?.signal === undefined ? {} : { signal: options.signal }),\n ...(request.reservationId === undefined ? {} : { reservationId: request.reservationId }),\n });\n sessionId = session.sessionId;\n if (reserved && sessionId !== reserved.sessionId)\n throw new Error('The host did not use the reserved session identity.');\n } catch (error) {\n const kept = await rollback();\n if (cancelled()) {\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n `Cancelled while the session was starting.${kept}`,\n false,\n reserved\n ? 'Retry setup with the same branch to recover the reserved checkout.'\n : 'The worktree was removed; run it again when you are ready.',\n );\n }\n if (error instanceof HubUnavailableError) {\n throw new DoomGitExpectedError(\n 'hub_unavailable',\n `${error.message}${kept}`,\n true,\n 'Start the cockpit and try again.',\n );\n }\n throw error;\n }\n\n const record: WorktreeRecord = {\n version: WORKTREE_RECORD_VERSION,\n id,\n branch: request.branch,\n baseRef,\n path,\n repositoryRoot: root,\n sessionId,\n parentSessionId: context.sessionId,\n status: 'running',\n createdAt: now().toISOString(),\n };\n try {\n store.replace([...records, record]);\n } catch (error) {\n // A live session with no record is the worst outcome available here:\n // it runs, and no id anything can name points at it. The session goes\n // back too, rather than being left for someone to find by hand.\n await requireSessionService()\n .close(sessionId)\n .catch(() => undefined);\n const kept = await rollback();\n throw new DoomGitExpectedError(\n 'registry_write_failed',\n `The worktree was created but the registry could not be written (${(error as Error).message}).${kept}`,\n true,\n 'Check the registry file for permissions or free space, then try again.',\n );\n }\n if (request.task !== undefined && taskDelivery !== undefined) {\n try {\n const receipt = await taskDelivery.deliver({\n recipientKey: sessionId,\n kind: GIT_WORKTREE_DELEGATION_KIND,\n prompt: request.task,\n metadata: {\n worktreeId: record.id,\n fromRole: 'parent',\n text: request.task,\n sentAt: record.createdAt,\n },\n });\n const admission = await taskDelivery.waitForAdmission(receipt.deliveryId);\n if (admission !== 'admitted') {\n throw new Error(\n admission === 'recovery_required'\n ? 'The recipient could not admit the task.'\n : 'The recipient did not confirm task admission before the timeout.',\n );\n }\n } catch (error) {\n throw new DoomGitExpectedError(\n 'task_delivery_failed',\n `Worktree ${record.id} was created, but its task admission was not confirmed (${(error as Error).message}).`,\n true,\n `Use send with worktree ${record.id} to deliver the task without recreating the worktree.`,\n );\n }\n }\n if (request.reservationId !== undefined) await reservations!.complete(request.reservationId, context.sessionId);\n return record;\n },\n\n async close(context, id, force) {\n const { root, store, records } = await resolve(context);\n const record = require(records, id);\n requireOwner(context, record, 'close');\n const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];\n const refusal = refuseClose({ record, dirtyFiles, force });\n if (refusal !== undefined) {\n throw new DoomGitExpectedError('worktree_dirty', refusal, false, 'Commit the work, or pass force: true.');\n }\n // The session is stopped before the directory goes. Removing a checkout\n // while a process still holds files open in it is how a half-removed\n // worktree and a stale git administrative entry are made.\n await requireSessionService().close(record.sessionId);\n await git.removeWorktree({ repositoryRoot: root, path: record.path, force });\n store.replace(records.filter((entry) => entry.id !== id));\n return record;\n },\n\n async list(context) {\n const { store, records } = await resolve(context);\n const outcome = reconcile(records, probe);\n if (outcome.changed.length > 0) store.replace(outcome.records);\n return outcome.records;\n },\n\n async status(context, id) {\n const { records } = await resolve(context);\n const record = require(records, id);\n const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];\n return { record, dirtyFiles };\n },\n\n async merge(context, id, message) {\n const { root, records } = await resolve(context);\n const record = require(records, id);\n requireOwner(context, record, 'merge');\n // The merge lands in the parent, so the parent is what must be clean. A\n // dirty parent would mix the person's in-flight edits into a merge commit\n // they did not intend to make.\n const parentDirty = await git.dirtyFiles(root);\n if (parentDirty.length > 0) {\n throw new DoomGitExpectedError(\n 'worktree_dirty',\n `The parent checkout has ${String(parentDirty.length)} uncommitted file(s): ${parentDirty.slice(0, 10).join(', ')}.`,\n false,\n 'Commit or stash the parent checkout first.',\n );\n }\n await git.mergeBranch({\n repositoryRoot: root,\n branch: record.branch,\n ...(message === undefined ? {} : { message }),\n });\n return record;\n },\n\n /** Sends only between the parent session and its own worktree session. */\n async send(context, id, message) {\n if (Buffer.byteLength(message, 'utf8') > MAX_WORKTREE_MESSAGE_BYTES) {\n throw new DoomGitExpectedError(\n 'message_too_large',\n `A message may not exceed ${String(MAX_WORKTREE_MESSAGE_BYTES)} bytes.`,\n false,\n 'Send a shorter message.',\n );\n }\n const { records } = await resolve(context);\n const record = require(records, id);\n const peer = peerFor(context, record);\n requirePeerLive(peer.sessionId);\n const sentAt = new Date().toISOString();\n const delivery = readSessionDelivery();\n if (delivery !== undefined) {\n const kind = peer.party === 'parent' ? GIT_WORKTREE_MESSAGE_KIND : GIT_WORKTREE_REPORT_KIND;\n const receipt = await delivery.deliver({\n recipientKey: peer.sessionId,\n kind,\n prompt:\n peer.party === 'parent'\n ? `Parent message for worktree ${record.id}:\\n\\n${message}`\n : `Report from worktree ${record.id}:\\n\\n${message}`,\n metadata: { worktreeId: record.id, fromRole: peer.party, text: message, sentAt },\n });\n const admission = await delivery.waitForAdmission(receipt.deliveryId);\n if (admission !== 'admitted') {\n throw new DoomGitExpectedError(\n 'message_delivery_failed',\n `Worktree ${record.id} persisted the message, but its session did not confirm admission.`,\n true,\n admission === 'recovery_required'\n ? 'Call messages from the recipient session to recover the persisted text.'\n : 'The message remains durable; retry after the recipient is ready.',\n );\n }\n return;\n }\n requireMessageInbox().send(peer.sessionId, {\n version: 1,\n worktreeId: record.id,\n fromSessionId: context.sessionId,\n from: peer.party,\n text: message,\n sentAt,\n });\n },\n\n async messages(context, id) {\n const { records } = await resolve(context);\n const record = require(records, id);\n const peer = peerFor(context, record);\n const delivery = readSessionDelivery();\n if (delivery === undefined) return requireMessageInbox().receive(record.id);\n const entries = delivery\n .inbox({ consumed: false, metadata: { worktreeId: record.id } })\n .filter(\n (entry) =>\n entry.senderKey === peer.sessionId &&\n (entry.state === 'admitted' || entry.state === 'recovery_required') &&\n (peer.party === 'parent'\n ? entry.kind === GIT_WORKTREE_REPORT_KIND\n : entry.kind === GIT_WORKTREE_MESSAGE_KIND || entry.kind === GIT_WORKTREE_DELEGATION_KIND),\n );\n return entries.map((entry) => {\n delivery.consume(entry.deliveryId);\n return {\n version: 1,\n worktreeId: record.id,\n fromSessionId: entry.senderKey,\n from: peer.party === 'parent' ? ('child' as const) : ('parent' as const),\n text:\n entry.state === 'recovery_required'\n ? `[Recovery required: prompt admission was not confirmed] ${entry.metadata.text ?? entry.prompt}`\n : (entry.metadata.text ?? entry.prompt),\n sentAt: entry.metadata.sentAt ?? '',\n };\n });\n },\n\n async prune(context, dryRun) {\n const { root, store, records } = await resolve(context);\n const reconciled = reconcile(records, probe);\n const gitPaths = await git.listWorktreePaths(root);\n const dirtyByPath = new Map<string, readonly string[]>();\n for (const record of reconciled.records) {\n if (record.status === 'orphaned' && fs.existsSync(record.path)) {\n dirtyByPath.set(record.path, await git.dirtyFiles(record.path));\n }\n }\n const plan = planPrune({\n records: reconciled.records,\n gitPaths,\n worktreesRoot: worktreesRoot(deps.homeDir),\n dirtyByPath,\n });\n if (dryRun) {\n store.replace(reconciled.records);\n return plan;\n }\n for (const record of plan.remove) {\n await git.removeWorktree({ repositoryRoot: root, path: record.path, force: false });\n }\n // The checkout goes, so the branch it was made for goes with it. Safe\n // delete only: git keeps anything holding commits, and the plan says\n // which ones it kept rather than leaving the reader to notice later.\n for (const record of [...plan.remove, ...plan.forget]) {\n const deleted = await git.deleteBranch({ repositoryRoot: root, branch: record.branch }).catch(() => false);\n if (!deleted) plan.keptBranches.push(record.branch);\n }\n const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));\n store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));\n return plan;\n },\n };\n const locked = async <T>(context: WorktreeContext, operation: () => Promise<T>, signal?: AbortSignal): Promise<T> => {\n try {\n const { store } = await resolve(context);\n return await store.transaction(operation, signal);\n } catch (error) {\n if (signal?.aborted && !(error instanceof DoomGitExpectedError))\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n 'The worktree operation was cancelled.',\n false,\n 'Inspect its recorded state before retrying.',\n );\n if (['ENOTDIR', 'EACCES', 'EROFS', 'ENOSPC'].includes(String((error as NodeJS.ErrnoException).code)))\n throw new DoomGitExpectedError(\n 'registry_write_failed',\n 'The worktree registry is not writable.',\n true,\n 'Check permissions and free space before retrying.',\n );\n throw error;\n }\n };\n // ponytail: serialize Git lifecycle mutations, not session execution. Keeping\n // the lock across startup avoids a second lease system for partially created trees.\n return {\n ...operations,\n spawn: (context, request, options) =>\n locked(context, () => operations.spawn(context, request, options), options?.signal),\n close: (context, id, force) => locked(context, () => operations.close(context, id, force)),\n list: (context) => locked(context, () => operations.list(context)),\n merge: (context, id, message) => locked(context, () => operations.merge(context, id, message)),\n prune: (context, dryRun) => locked(context, () => operations.prune(context, dryRun)),\n };\n}\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,+BAA+B;AACrC,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;AAkDjC,SAAgB,yBAAyB,MAAkD;CACzF,MAAM,EAAE,QAAQ;CAChB,MAAM,iBAAiB,KAAK;CAC5B,MAAM,SAAS,KAAK,UAAU;CAC9B,MAAM,MAAM,KAAK,8BAAc,IAAI,KAAK;CACxC,MAAM,8BAAqD;EACzD,IAAI,mBAAmB,KAAA,GACrB,MAAM,IAAI,oBAAoB,8EAA8E;EAC9G,OAAO;CACT;CACA,MAAM,4BAAkD;EACtD,IAAI,KAAK,iBAAiB,KAAA,GACxB,MAAM,IAAI,oBAAoB,0EAA0E;EAC1G,OAAO,KAAK;CACd;CACA,MAAM,4BAAoE,KAAK,kBAAkB;CACjG,MAAM,+BAA2D;EAC/D,MAAM,WAAW,oBAAoB;EACrC,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,oBAAoB,+EAA+E;EAC/G,OAAO;CACT;CACA,MAAM,QAAQ;EACZ,QAAQ,WAA2B,sBAAsB,CAAC,CAAC,OAAO,OAAO,SAAS;EAClF,SAAS,SAAiB,GAAG,W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R;CACF;CAGA,OAAO;EACL,GAAG;EACH,QAAQ,SAAS,SAAS,YACxB,OAAO,eAAe,WAAW,MAAM,SAAS,SAAS,OAAO,GAAG,SAAS,MAAM;EACpF,QAAQ,SAAS,IAAI,UAAU,OAAO,eAAe,WAAW,MAAM,SAAS,IAAI,KAAK,CAAC;EACzF,OAAO,YAAY,OAAO,eAAe,WAAW,KAAK,OAAO,CAAC;EACjE,QAAQ,SAAS,IAAI,YAAY,OAAO,eAAe,WAAW,MAAM,SAAS,IAAI,OAAO,CAAC;EAC7F,QAAQ,SAAS,WAAW,OAAO,eAAe,WAAW,MAAM,SAAS,MAAM,CAAC;CACrF;AACF"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_index = require("../errors/index.cjs");
|
|
3
|
-
const require_index$1 = require("../atomicJson/index.cjs");
|
|
4
|
-
let node_fs = require("node:fs");
|
|
5
|
-
node_fs = require_runtime.__toESM(node_fs, 1);
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_runtime.__toESM(node_path, 1);
|
|
8
|
-
let node_timers_promises = require("node:timers/promises");
|
|
9
|
-
//#region src/services/worktreeRegistry/index.ts
|
|
10
|
-
const LOCK_WAIT_MS = 5e3;
|
|
11
|
-
const LOCK_RETRY_MS = 25;
|
|
12
|
-
function isRecord(value) {
|
|
13
|
-
if (typeof value !== "object" || value === null) return false;
|
|
14
|
-
const record = value;
|
|
15
|
-
return record.version === 1 && typeof record.id === "string" && record.id !== "" && typeof record.path === "string" && typeof record.branch === "string" && typeof record.sessionId === "string";
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Repository mutations hold an exclusive directory lock from the read through
|
|
19
|
-
* the final commit. This works across independently loaded packages and hosts.
|
|
20
|
-
* A crashed owner leaves a visible lock, never a lease another writer may steal.
|
|
21
|
-
*/
|
|
22
|
-
function createWorktreeRegistry(file) {
|
|
23
|
-
return {
|
|
24
|
-
list() {
|
|
25
|
-
const parsed = require_index$1.readJson(file);
|
|
26
|
-
if (!parsed || parsed.version !== 1 || !Array.isArray(parsed.entries)) return [];
|
|
27
|
-
return parsed.entries.filter(isRecord);
|
|
28
|
-
},
|
|
29
|
-
replace(entries) {
|
|
30
|
-
require_index$1.writeJsonAtomic(file, {
|
|
31
|
-
version: 1,
|
|
32
|
-
entries
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
async transaction(operation, signal) {
|
|
36
|
-
const lock = `${file}.lock`;
|
|
37
|
-
node_fs.default.mkdirSync(node_path.default.dirname(file), { recursive: true });
|
|
38
|
-
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
39
|
-
for (;;) {
|
|
40
|
-
signal?.throwIfAborted();
|
|
41
|
-
try {
|
|
42
|
-
node_fs.default.mkdirSync(lock, { mode: 448 });
|
|
43
|
-
break;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (error.code !== "EEXIST") throw error;
|
|
46
|
-
if (Date.now() >= deadline) throw new require_index.DoomGitExpectedError("registry_busy", "Another worktree operation holds the repository registry.", true, "Retry after it finishes. After a host crash, inspect and remove the abandoned worktrees.json.lock directory.");
|
|
47
|
-
await (0, node_timers_promises.setTimeout)(LOCK_RETRY_MS, void 0, { signal });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
node_fs.default.writeFileSync(node_path.default.join(lock, "owner.json"), JSON.stringify({
|
|
52
|
-
pid: process.pid,
|
|
53
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
54
|
-
}), { mode: 384 });
|
|
55
|
-
signal?.throwIfAborted();
|
|
56
|
-
return await operation();
|
|
57
|
-
} finally {
|
|
58
|
-
node_fs.default.rmSync(lock, { recursive: true });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
exports.createWorktreeRegistry = createWorktreeRegistry;
|
|
65
|
-
|
|
66
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["readJson","path","DoomGitExpectedError","setTimeout"],"sources":["../../../../src/services/worktreeRegistry/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { setTimeout } from 'node:timers/promises';\n\nimport {\n WORKTREE_RECORD_VERSION,\n type WorktreeRecord,\n type WorktreeRegistryFile,\n type WorktreeRegistryStore,\n} from '../../types/worktreeRegistry';\nimport { readJson, writeJsonAtomic } from '../atomicJson';\nimport { DoomGitExpectedError } from '../errors';\n\nconst LOCK_WAIT_MS = 5000;\nconst LOCK_RETRY_MS = 25;\n\nfunction isRecord(value: unknown): value is WorktreeRecord {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Partial<WorktreeRecord>;\n return (\n record.version === WORKTREE_RECORD_VERSION &&\n typeof record.id === 'string' &&\n record.id !== '' &&\n typeof record.path === 'string' &&\n typeof record.branch === 'string' &&\n typeof record.sessionId === 'string'\n );\n}\n\n/**\n * Repository mutations hold an exclusive directory lock from the read through\n * the final commit. This works across independently loaded packages and hosts.\n * A crashed owner leaves a visible lock, never a lease another writer may steal.\n */\nexport function createWorktreeRegistry(file: string): WorktreeRegistryStore {\n return {\n list() {\n const parsed = readJson<WorktreeRegistryFile>(file);\n if (!parsed || parsed.version !== WORKTREE_RECORD_VERSION || !Array.isArray(parsed.entries)) return [];\n return parsed.entries.filter(isRecord);\n },\n replace(entries) {\n writeJsonAtomic(file, { version: WORKTREE_RECORD_VERSION, entries } satisfies WorktreeRegistryFile);\n },\n async transaction(operation, signal) {\n const lock = `${file}.lock`;\n fs.mkdirSync(path.dirname(file), { recursive: true });\n const deadline = Date.now() + LOCK_WAIT_MS;\n for (;;) {\n signal?.throwIfAborted();\n try {\n fs.mkdirSync(lock, { mode: 0o700 });\n break;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n if (Date.now() >= deadline)\n throw new DoomGitExpectedError(\n 'registry_busy',\n 'Another worktree operation holds the repository registry.',\n true,\n 'Retry after it finishes. After a host crash, inspect and remove the abandoned worktrees.json.lock directory.',\n );\n await setTimeout(LOCK_RETRY_MS, undefined, { signal });\n }\n }\n try {\n fs.writeFileSync(\n path.join(lock, 'owner.json'),\n JSON.stringify({ pid: process.pid, createdAt: new Date().toISOString() }),\n { mode: 0o600 },\n );\n signal?.throwIfAborted();\n return await operation();\n } finally {\n fs.rmSync(lock, { recursive: true });\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAEtB,SAAS,SAAS,OAAyC;CACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,SAAS;CACf,OACE,OAAO,YAAA,KACP,OAAO,OAAO,OAAO,YACrB,OAAO,OAAO,MACd,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,WAAW,YACzB,OAAO,OAAO,cAAc;AAEhC;;;;;;AAOA,SAAgB,uBAAuB,MAAqC;CAC1E,OAAO;EACL,OAAO;GACL,MAAM,SAASA,gBAAAA,SAA+B,IAAI;GAClD,IAAI,CAAC,UAAU,OAAO,YAAA,KAAuC,CAAC,MAAM,QAAQ,OAAO,OAAO,GAAG,OAAO,CAAC;GACrG,OAAO,OAAO,QAAQ,OAAO,QAAQ;EACvC;EACA,QAAQ,SAAS;GACf,gBAAA,gBAAgB,MAAM;IAAE,SAAA;IAAkC;GAAQ,CAAgC;EACpG;EACA,MAAM,YAAY,WAAW,QAAQ;GACnC,MAAM,OAAO,GAAG,KAAK;GACrB,QAAA,QAAG,UAAUC,UAAAA,QAAK,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;GACpD,MAAM,WAAW,KAAK,IAAI,IAAI;GAC9B,SAAS;IACP,QAAQ,eAAe;IACvB,IAAI;KACF,QAAA,QAAG,UAAU,MAAM,EAAE,MAAM,IAAM,CAAC;KAClC;IACF,SAAS,OAAO;KACd,IAAK,MAAgC,SAAS,UAAU,MAAM;KAC9D,IAAI,KAAK,IAAI,KAAK,UAChB,MAAM,IAAIC,cAAAA,qBACR,iBACA,6DACA,MACA,8GACF;KACF,OAAA,GAAMC,qBAAAA,WAAAA,CAAW,eAAe,KAAA,GAAW,EAAE,OAAO,CAAC;IACvD;GACF;GACA,IAAI;IACF,QAAA,QAAG,cACDF,UAAAA,QAAK,KAAK,MAAM,YAAY,GAC5B,KAAK,UAAU;KAAE,KAAK,QAAQ;KAAK,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;IAAE,CAAC,GACxE,EAAE,MAAM,IAAM,CAChB;IACA,QAAQ,eAAe;IACvB,OAAO,MAAM,UAAU;GACzB,UAAU;IACR,QAAA,QAAG,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;GACrC;EACF;CACF;AACF"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { DoomGitExpectedError } from "../errors/index.mjs";
|
|
2
|
-
import { readJson, writeJsonAtomic } from "../atomicJson/index.mjs";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { setTimeout } from "node:timers/promises";
|
|
6
|
-
//#region src/services/worktreeRegistry/index.ts
|
|
7
|
-
const LOCK_WAIT_MS = 5e3;
|
|
8
|
-
const LOCK_RETRY_MS = 25;
|
|
9
|
-
function isRecord(value) {
|
|
10
|
-
if (typeof value !== "object" || value === null) return false;
|
|
11
|
-
const record = value;
|
|
12
|
-
return record.version === 1 && typeof record.id === "string" && record.id !== "" && typeof record.path === "string" && typeof record.branch === "string" && typeof record.sessionId === "string";
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Repository mutations hold an exclusive directory lock from the read through
|
|
16
|
-
* the final commit. This works across independently loaded packages and hosts.
|
|
17
|
-
* A crashed owner leaves a visible lock, never a lease another writer may steal.
|
|
18
|
-
*/
|
|
19
|
-
function createWorktreeRegistry(file) {
|
|
20
|
-
return {
|
|
21
|
-
list() {
|
|
22
|
-
const parsed = readJson(file);
|
|
23
|
-
if (!parsed || parsed.version !== 1 || !Array.isArray(parsed.entries)) return [];
|
|
24
|
-
return parsed.entries.filter(isRecord);
|
|
25
|
-
},
|
|
26
|
-
replace(entries) {
|
|
27
|
-
writeJsonAtomic(file, {
|
|
28
|
-
version: 1,
|
|
29
|
-
entries
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
async transaction(operation, signal) {
|
|
33
|
-
const lock = `${file}.lock`;
|
|
34
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
35
|
-
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
36
|
-
for (;;) {
|
|
37
|
-
signal?.throwIfAborted();
|
|
38
|
-
try {
|
|
39
|
-
fs.mkdirSync(lock, { mode: 448 });
|
|
40
|
-
break;
|
|
41
|
-
} catch (error) {
|
|
42
|
-
if (error.code !== "EEXIST") throw error;
|
|
43
|
-
if (Date.now() >= deadline) throw new DoomGitExpectedError("registry_busy", "Another worktree operation holds the repository registry.", true, "Retry after it finishes. After a host crash, inspect and remove the abandoned worktrees.json.lock directory.");
|
|
44
|
-
await setTimeout(LOCK_RETRY_MS, void 0, { signal });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
fs.writeFileSync(path.join(lock, "owner.json"), JSON.stringify({
|
|
49
|
-
pid: process.pid,
|
|
50
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
51
|
-
}), { mode: 384 });
|
|
52
|
-
signal?.throwIfAborted();
|
|
53
|
-
return await operation();
|
|
54
|
-
} finally {
|
|
55
|
-
fs.rmSync(lock, { recursive: true });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
export { createWorktreeRegistry };
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/services/worktreeRegistry/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { setTimeout } from 'node:timers/promises';\n\nimport {\n WORKTREE_RECORD_VERSION,\n type WorktreeRecord,\n type WorktreeRegistryFile,\n type WorktreeRegistryStore,\n} from '../../types/worktreeRegistry';\nimport { readJson, writeJsonAtomic } from '../atomicJson';\nimport { DoomGitExpectedError } from '../errors';\n\nconst LOCK_WAIT_MS = 5000;\nconst LOCK_RETRY_MS = 25;\n\nfunction isRecord(value: unknown): value is WorktreeRecord {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Partial<WorktreeRecord>;\n return (\n record.version === WORKTREE_RECORD_VERSION &&\n typeof record.id === 'string' &&\n record.id !== '' &&\n typeof record.path === 'string' &&\n typeof record.branch === 'string' &&\n typeof record.sessionId === 'string'\n );\n}\n\n/**\n * Repository mutations hold an exclusive directory lock from the read through\n * the final commit. This works across independently loaded packages and hosts.\n * A crashed owner leaves a visible lock, never a lease another writer may steal.\n */\nexport function createWorktreeRegistry(file: string): WorktreeRegistryStore {\n return {\n list() {\n const parsed = readJson<WorktreeRegistryFile>(file);\n if (!parsed || parsed.version !== WORKTREE_RECORD_VERSION || !Array.isArray(parsed.entries)) return [];\n return parsed.entries.filter(isRecord);\n },\n replace(entries) {\n writeJsonAtomic(file, { version: WORKTREE_RECORD_VERSION, entries } satisfies WorktreeRegistryFile);\n },\n async transaction(operation, signal) {\n const lock = `${file}.lock`;\n fs.mkdirSync(path.dirname(file), { recursive: true });\n const deadline = Date.now() + LOCK_WAIT_MS;\n for (;;) {\n signal?.throwIfAborted();\n try {\n fs.mkdirSync(lock, { mode: 0o700 });\n break;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n if (Date.now() >= deadline)\n throw new DoomGitExpectedError(\n 'registry_busy',\n 'Another worktree operation holds the repository registry.',\n true,\n 'Retry after it finishes. After a host crash, inspect and remove the abandoned worktrees.json.lock directory.',\n );\n await setTimeout(LOCK_RETRY_MS, undefined, { signal });\n }\n }\n try {\n fs.writeFileSync(\n path.join(lock, 'owner.json'),\n JSON.stringify({ pid: process.pid, createdAt: new Date().toISOString() }),\n { mode: 0o600 },\n );\n signal?.throwIfAborted();\n return await operation();\n } finally {\n fs.rmSync(lock, { recursive: true });\n }\n },\n };\n}\n"],"mappings":";;;;;;AAaA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAEtB,SAAS,SAAS,OAAyC;CACzD,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,SAAS;CACf,OACE,OAAO,YAAA,KACP,OAAO,OAAO,OAAO,YACrB,OAAO,OAAO,MACd,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,WAAW,YACzB,OAAO,OAAO,cAAc;AAEhC;;;;;;AAOA,SAAgB,uBAAuB,MAAqC;CAC1E,OAAO;EACL,OAAO;GACL,MAAM,SAAS,SAA+B,IAAI;GAClD,IAAI,CAAC,UAAU,OAAO,YAAA,KAAuC,CAAC,MAAM,QAAQ,OAAO,OAAO,GAAG,OAAO,CAAC;GACrG,OAAO,OAAO,QAAQ,OAAO,QAAQ;EACvC;EACA,QAAQ,SAAS;GACf,gBAAgB,MAAM;IAAE,SAAA;IAAkC;GAAQ,CAAgC;EACpG;EACA,MAAM,YAAY,WAAW,QAAQ;GACnC,MAAM,OAAO,GAAG,KAAK;GACrB,GAAG,UAAU,KAAK,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;GACpD,MAAM,WAAW,KAAK,IAAI,IAAI;GAC9B,SAAS;IACP,QAAQ,eAAe;IACvB,IAAI;KACF,GAAG,UAAU,MAAM,EAAE,MAAM,IAAM,CAAC;KAClC;IACF,SAAS,OAAO;KACd,IAAK,MAAgC,SAAS,UAAU,MAAM;KAC9D,IAAI,KAAK,IAAI,KAAK,UAChB,MAAM,IAAI,qBACR,iBACA,6DACA,MACA,8GACF;KACF,MAAM,WAAW,eAAe,KAAA,GAAW,EAAE,OAAO,CAAC;IACvD;GACF;GACA,IAAI;IACF,GAAG,cACD,KAAK,KAAK,MAAM,YAAY,GAC5B,KAAK,UAAU;KAAE,KAAK,QAAQ;KAAK,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;IAAE,CAAC,GACxE,EAAE,MAAM,IAAM,CAChB;IACA,QAAQ,eAAe;IACvB,OAAO,MAAM,UAAU;GACzB,UAAU;IACR,GAAG,OAAO,MAAM,EAAE,WAAW,KAAK,CAAC;GACrC;EACF;CACF;AACF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { WorktreeOperations } from "../services/worktreeOperations/index.cjs";
|
|
2
|
-
//#region src/types/extension.d.ts
|
|
3
|
-
export type GitNotificationLevel = 'info';
|
|
4
|
-
export interface GitExtensionResult {
|
|
5
|
-
message: string;
|
|
6
|
-
level: GitNotificationLevel;
|
|
7
|
-
}
|
|
8
|
-
export interface GitExtensionService {
|
|
9
|
-
execute(): Promise<GitExtensionResult>;
|
|
10
|
-
}
|
|
11
|
-
export interface GitExtensionDependencies {
|
|
12
|
-
service: GitExtensionService;
|
|
13
|
-
operations: WorktreeOperations;
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//# sourceMappingURL=extension.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.cts","names":[],"sources":["../../../src/types/extension.ts"],"mappings":";;YAGY;iBAEK;EACf;EACA,OAAO;;iBAGQ;EACf,WAAW,QAAQ;;iBAGJ;EACf,SAAS;EACT,YAAY"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { WorktreeOperations } from "../services/worktreeOperations/index.mjs";
|
|
2
|
-
//#region src/types/extension.d.ts
|
|
3
|
-
export type GitNotificationLevel = 'info';
|
|
4
|
-
export interface GitExtensionResult {
|
|
5
|
-
message: string;
|
|
6
|
-
level: GitNotificationLevel;
|
|
7
|
-
}
|
|
8
|
-
export interface GitExtensionService {
|
|
9
|
-
execute(): Promise<GitExtensionResult>;
|
|
10
|
-
}
|
|
11
|
-
export interface GitExtensionDependencies {
|
|
12
|
-
service: GitExtensionService;
|
|
13
|
-
operations: WorktreeOperations;
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//# sourceMappingURL=extension.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.mts","names":[],"sources":["../../../src/types/extension.ts"],"mappings":";;YAGY;iBAEK;EACf;EACA,OAAO;;iBAGQ;EACf,WAAW,QAAQ;;iBAGJ;EACf,SAAS;EACT,YAAY"}
|