@agimon-ai/po-git 0.0.0-alpha.196 → 0.0.0-alpha.198
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -4
- package/dist/apiContracts.cjs +41 -8
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +41 -8
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/extensions/native.mjs +33 -3
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +1224 -453
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +1171 -400
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +30 -2
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/{worktreeOperations-BEk4VEj3.cjs → gitDependencies-D8bKxZSc.cjs} +1436 -170
- package/dist/gitDependencies-D8bKxZSc.cjs.map +1 -0
- package/dist/gitDependencies-Delu4xip.mjs +2432 -0
- package/dist/gitDependencies-Delu4xip.mjs.map +1 -0
- package/dist/index.cjs +13 -22
- package/dist/index.d.mts +261 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -22
- package/dist/po-runtime-identity.json +1 -1
- package/llms.txt +3 -3
- package/package.json +12 -8
- package/src/prompts/codemode-how-to-git/SKILL.md +55 -10
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/worktreeOperations-BEk4VEj3.cjs.map +0 -1
- package/dist/worktreeOperations-hT6N8oSr.mjs +0 -1238
- package/dist/worktreeOperations-hT6N8oSr.mjs.map +0 -1
|
@@ -2,21 +2,93 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const
|
|
5
|
+
const require_gitDependencies = require("../gitDependencies-D8bKxZSc.cjs");
|
|
6
|
+
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
7
|
+
let _agimon_ai_po_sparo = require("@agimon-ai/po-sparo");
|
|
8
|
+
let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin");
|
|
6
9
|
let node_fs_promises = require("node:fs/promises");
|
|
7
|
-
node_fs_promises =
|
|
10
|
+
node_fs_promises = require_gitDependencies.__toESM(node_fs_promises, 1);
|
|
11
|
+
let node_crypto = require("node:crypto");
|
|
8
12
|
let node_path = require("node:path");
|
|
9
|
-
node_path =
|
|
13
|
+
node_path = require_gitDependencies.__toESM(node_path, 1);
|
|
10
14
|
let node_os = require("node:os");
|
|
11
|
-
node_os =
|
|
12
|
-
let
|
|
15
|
+
node_os = require_gitDependencies.__toESM(node_os, 1);
|
|
16
|
+
let typebox_value = require("typebox/value");
|
|
17
|
+
let typebox = require("typebox");
|
|
18
|
+
let _agimon_ai_po_core_workflow = require("@agimon-ai/po-core/workflow");
|
|
13
19
|
let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
|
|
14
20
|
let _agimon_ai_po_core_codemode = require("@agimon-ai/po-core/codemode");
|
|
15
21
|
let _agimon_ai_po_session = require("@agimon-ai/po-session");
|
|
16
|
-
let
|
|
17
|
-
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
22
|
+
let _agimon_ai_po_core_locale = require("@agimon-ai/po-core/locale");
|
|
18
23
|
let _agimon_ai_po_core_packageApi = require("@agimon-ai/po-core/packageApi");
|
|
19
24
|
let _agimon_ai_po_core_hubChannel = require("@agimon-ai/po-core/hubChannel");
|
|
25
|
+
//#region src/extensions/workspaces/(backend)/root.server.ts
|
|
26
|
+
var root_server_default$1 = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ context, signal }) => {
|
|
27
|
+
context.inject([_agimon_ai_po_core_serverPlugin.PO_SERVER_SCOPE_SERVICE, _agimon_ai_po_core_platform.PO_FS_SERVICE], (scoped) => {
|
|
28
|
+
let shell;
|
|
29
|
+
let shellSignal = AbortSignal.abort(/* @__PURE__ */ new Error("Git engine requires the host shell (po/shell)."));
|
|
30
|
+
scoped.inject([_agimon_ai_po_core_platform.PO_SHELL_SERVICE], (child) => {
|
|
31
|
+
const lifetime = new AbortController();
|
|
32
|
+
shell = (0, _agimon_ai_po_core_platform.requirePoShell)(child);
|
|
33
|
+
shellSignal = lifetime.signal;
|
|
34
|
+
return () => {
|
|
35
|
+
shell = void 0;
|
|
36
|
+
lifetime.abort(/* @__PURE__ */ new Error("Git engine host shell was disposed."));
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
const engine = (0, _agimon_ai_po_sparo.createGitEngineService)({
|
|
40
|
+
fs: (0, _agimon_ai_po_sparo.createPoFsAdapter)((0, _agimon_ai_po_core_platform.requirePoFs)(scoped), (operationSignal) => (0, _agimon_ai_po_core_platform.withAbortSignal)(AbortSignal.any([signal, operationSignal]), _agimon_ai_po_core_platform.BACKGROUND_CONTEXT)),
|
|
41
|
+
exec: ({ environment }) => {
|
|
42
|
+
const env = Object.fromEntries(Object.entries(environment).filter((entry) => entry[1] !== void 0));
|
|
43
|
+
return { async run(command, args, options) {
|
|
44
|
+
if (shell === void 0) throw new Error("Git engine requires the host shell (po/shell).");
|
|
45
|
+
const operationSignal = AbortSignal.any([
|
|
46
|
+
signal,
|
|
47
|
+
shellSignal,
|
|
48
|
+
options.signal ?? signal,
|
|
49
|
+
AbortSignal.timeout(12e4)
|
|
50
|
+
]);
|
|
51
|
+
operationSignal.throwIfAborted();
|
|
52
|
+
let stdout = "";
|
|
53
|
+
let stderr = "";
|
|
54
|
+
let bytes = 0;
|
|
55
|
+
const outputLimit = new AbortController();
|
|
56
|
+
const result = await shell.exec([command, ...args], {
|
|
57
|
+
cwd: options.cwd,
|
|
58
|
+
env,
|
|
59
|
+
inheritEnv: false,
|
|
60
|
+
timeout: 12e4,
|
|
61
|
+
onOutput(text, _context, info) {
|
|
62
|
+
bytes += new TextEncoder().encode(text).byteLength;
|
|
63
|
+
if (bytes > 4194304) {
|
|
64
|
+
outputLimit.abort(/* @__PURE__ */ new Error("Git engine command output exceeded 4 MiB."));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (info.stream === "stdout") stdout += text;
|
|
68
|
+
else stderr += text;
|
|
69
|
+
}
|
|
70
|
+
}, (0, _agimon_ai_po_core_platform.withAbortSignal)(AbortSignal.any([operationSignal, outputLimit.signal]), _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
71
|
+
outputLimit.signal.throwIfAborted();
|
|
72
|
+
operationSignal.throwIfAborted();
|
|
73
|
+
if (!result.ok) throw result.error;
|
|
74
|
+
return {
|
|
75
|
+
exitCode: result.value.exitCode,
|
|
76
|
+
stdout,
|
|
77
|
+
stderr
|
|
78
|
+
};
|
|
79
|
+
} };
|
|
80
|
+
},
|
|
81
|
+
logger: {
|
|
82
|
+
info: (message) => console.info(message),
|
|
83
|
+
warn: (message) => console.warn(message),
|
|
84
|
+
error: (message) => console.error(message)
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return (0, _agimon_ai_po_core_serverPlugin.requirePoServerScope)(scoped).provide(require_gitDependencies.GIT_ENGINE_CONTRACT, engine);
|
|
88
|
+
});
|
|
89
|
+
return { value: void 0 };
|
|
90
|
+
});
|
|
91
|
+
//#endregion
|
|
20
92
|
//#region src/schemas/runWorktreeTool.ts
|
|
21
93
|
/**
|
|
22
94
|
* The tool's action vocabulary.
|
|
@@ -33,7 +105,10 @@ const WORKTREE_ACTIONS = {
|
|
|
33
105
|
merge: "merge",
|
|
34
106
|
prune: "prune",
|
|
35
107
|
send: "send",
|
|
36
|
-
messages: "messages"
|
|
108
|
+
messages: "messages",
|
|
109
|
+
profiles: "profiles",
|
|
110
|
+
expand: "expand",
|
|
111
|
+
reapply: "reapply"
|
|
37
112
|
};
|
|
38
113
|
/**
|
|
39
114
|
* Which fields each action accepts.
|
|
@@ -48,7 +123,8 @@ const WORKTREE_ACTION_FIELDS = {
|
|
|
48
123
|
"branch",
|
|
49
124
|
"baseRef",
|
|
50
125
|
"task",
|
|
51
|
-
"name"
|
|
126
|
+
"name",
|
|
127
|
+
"sparseProfile"
|
|
52
128
|
],
|
|
53
129
|
close_worktree: [
|
|
54
130
|
"action",
|
|
@@ -68,12 +144,20 @@ const WORKTREE_ACTION_FIELDS = {
|
|
|
68
144
|
"id",
|
|
69
145
|
"message"
|
|
70
146
|
],
|
|
71
|
-
messages: ["action", "id"]
|
|
147
|
+
messages: ["action", "id"],
|
|
148
|
+
profiles: ["action", "baseRef"],
|
|
149
|
+
expand: [
|
|
150
|
+
"action",
|
|
151
|
+
"id",
|
|
152
|
+
"folders"
|
|
153
|
+
],
|
|
154
|
+
reapply: ["action", "id"]
|
|
72
155
|
};
|
|
73
156
|
const SpawnParams = typebox.Type.Object({
|
|
74
157
|
action: typebox.Type.Literal(WORKTREE_ACTIONS.spawn_worktree),
|
|
75
158
|
branch: typebox.Type.String({ minLength: 1 }),
|
|
76
159
|
baseRef: typebox.Type.Optional(typebox.Type.String({ minLength: 1 })),
|
|
160
|
+
sparseProfile: typebox.Type.Optional(typebox.Type.String({ minLength: 1 })),
|
|
77
161
|
task: typebox.Type.Optional(typebox.Type.String({ minLength: 1 })),
|
|
78
162
|
name: typebox.Type.Optional(typebox.Type.String({ minLength: 1 }))
|
|
79
163
|
}, { additionalProperties: false });
|
|
@@ -113,7 +197,20 @@ typebox.Type.Union([
|
|
|
113
197
|
MergeParams,
|
|
114
198
|
PruneParams,
|
|
115
199
|
SendParams,
|
|
116
|
-
MessagesParams
|
|
200
|
+
MessagesParams,
|
|
201
|
+
typebox.Type.Object({
|
|
202
|
+
action: typebox.Type.Literal("profiles"),
|
|
203
|
+
baseRef: typebox.Type.Optional(typebox.Type.String({ minLength: 1 }))
|
|
204
|
+
}, { additionalProperties: false }),
|
|
205
|
+
typebox.Type.Object({
|
|
206
|
+
action: typebox.Type.Literal("expand"),
|
|
207
|
+
id: typebox.Type.String({ minLength: 1 }),
|
|
208
|
+
folders: typebox.Type.Array(typebox.Type.String({ minLength: 1 }), { minItems: 1 })
|
|
209
|
+
}, { additionalProperties: false }),
|
|
210
|
+
typebox.Type.Object({
|
|
211
|
+
action: typebox.Type.Literal("reapply"),
|
|
212
|
+
id: typebox.Type.String({ minLength: 1 })
|
|
213
|
+
}, { additionalProperties: false })
|
|
117
214
|
]);
|
|
118
215
|
/** The actions that accept `field`, so the declared docs cannot drift from the validator. */
|
|
119
216
|
function acceptingActions(field) {
|
|
@@ -143,6 +240,14 @@ const RunWorktreeToolSchema = typebox.Type.Object({
|
|
|
143
240
|
minLength: 1,
|
|
144
241
|
description: `Base ref, defaulting to the current branch. Actions: ${acceptingActions("baseRef")}.`
|
|
145
242
|
})),
|
|
243
|
+
sparseProfile: typebox.Type.Optional(typebox.Type.String({
|
|
244
|
+
minLength: 1,
|
|
245
|
+
description: "Sparse checkout profile, independent of the launch profile."
|
|
246
|
+
})),
|
|
247
|
+
folders: typebox.Type.Optional(typebox.Type.Array(typebox.Type.String({ minLength: 1 }), {
|
|
248
|
+
minItems: 1,
|
|
249
|
+
description: "Relative cone folders for expand."
|
|
250
|
+
})),
|
|
146
251
|
task: typebox.Type.Optional(typebox.Type.String({
|
|
147
252
|
minLength: 1,
|
|
148
253
|
description: `First message for the new session. Actions: ${acceptingActions("task")}.`
|
|
@@ -170,6 +275,9 @@ const RUN_WORKTREE_DESCRIPTION = `Create and manage git worktrees, each with its
|
|
|
170
275
|
|
|
171
276
|
Actions:
|
|
172
277
|
- spawn_worktree: create a worktree on a new branch and start a session in it. Requires 'branch'. Optional 'baseRef' (defaults to the current branch's remote-tracking ref, then the remote default branch), 'name' for the rail, 'task' as the first message.
|
|
278
|
+
- profiles: list sparse checkout profiles at baseRef.
|
|
279
|
+
- expand: add folders to a sparse worktree. Requires 'id' and 'folders'.
|
|
280
|
+
- reapply: refresh a sparse worktree from HEAD. Requires 'id'.
|
|
173
281
|
- close_worktree: stop a worktree's session and delete its checkout. Requires 'id'. Refuses a dirty tree unless 'force' is true.
|
|
174
282
|
- list: every worktree for this repository, with status and relationship to the calling session.
|
|
175
283
|
- status: one worktree, its relationship to the calling session, and its uncommitted files. Requires 'id'.
|
|
@@ -182,27 +290,29 @@ For a nested worktree session, use the record labelled 'child' in list to report
|
|
|
182
290
|
Worktrees live outside the repository, under ~/.po/git/worktrees.`;
|
|
183
291
|
/** Rejects calls that do not match one documented action shape. */
|
|
184
292
|
function validateParams(input) {
|
|
185
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) throw
|
|
293
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) throw require_gitDependencies.invalidRequest("run_worktree parameters must be an object.", "Call it with one documented action shape.");
|
|
186
294
|
const record = input;
|
|
187
295
|
const action = record.action;
|
|
188
|
-
if (typeof action !== "string" || !IMPLEMENTED_ACTIONS.has(action)) throw
|
|
296
|
+
if (typeof action !== "string" || !IMPLEMENTED_ACTIONS.has(action)) throw require_gitDependencies.invalidRequest(`Unknown action ${typeof action === "string" ? `'${action}'` : "value"}.`, `Use one of: ${[...IMPLEMENTED_ACTIONS].join(", ")}.`);
|
|
189
297
|
const allowed = WORKTREE_ACTION_FIELDS[action];
|
|
190
298
|
const unexpected = Object.keys(record).filter((key) => !allowed.includes(key));
|
|
191
|
-
if (unexpected.length > 0) throw
|
|
299
|
+
if (unexpected.length > 0) throw require_gitDependencies.invalidRequest(`action='${action}' does not accept: ${unexpected.join(", ")}.`, `Fields for '${action}': ${allowed.join(", ")}.`);
|
|
192
300
|
for (const field of ["branch", "id"]) if (allowed.includes(field) && field in record) {
|
|
193
301
|
const value = record[field];
|
|
194
|
-
if (typeof value !== "string" || value.trim() === "") throw
|
|
302
|
+
if (typeof value !== "string" || value.trim() === "") throw require_gitDependencies.invalidRequest(`action='${action}' requires a nonblank '${field}'.`, `Pass a ${field}.`);
|
|
195
303
|
}
|
|
196
304
|
for (const field of [
|
|
197
305
|
"baseRef",
|
|
198
306
|
"name",
|
|
199
307
|
"task",
|
|
200
|
-
"message"
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (action ===
|
|
204
|
-
if (
|
|
205
|
-
if (
|
|
308
|
+
"message",
|
|
309
|
+
"sparseProfile"
|
|
310
|
+
]) if (field in record && (typeof record[field] !== "string" || record[field].trim() === "")) throw require_gitDependencies.invalidRequest(`action='${action}' requires a nonblank '${field}'.`, `Pass a ${field}.`);
|
|
311
|
+
if (action === "expand" && (!Array.isArray(record.folders) || record.folders.length === 0 || !record.folders.every((folder) => typeof folder === "string" && folder.trim() !== ""))) throw require_gitDependencies.invalidRequest("expand requires nonempty folders.", "Pass relative cone folders.");
|
|
312
|
+
for (const field of ["force", "dryRun"]) if (field in record && typeof record[field] !== "boolean") throw require_gitDependencies.invalidRequest(`action='${action}' requires boolean '${field}'.`, `Pass true or false for ${field}.`);
|
|
313
|
+
if (action === WORKTREE_ACTIONS.send && typeof record.message !== "string") throw require_gitDependencies.invalidRequest("action='send' requires 'message'.", "Pass the message to send.");
|
|
314
|
+
if (action === WORKTREE_ACTIONS.spawn_worktree && typeof record.branch !== "string") throw require_gitDependencies.invalidRequest("action='spawn_worktree' requires 'branch'.", "Name the branch to create.");
|
|
315
|
+
if ((action === WORKTREE_ACTIONS.expand || action === WORKTREE_ACTIONS.reapply || action === WORKTREE_ACTIONS.close_worktree || action === WORKTREE_ACTIONS.status || action === WORKTREE_ACTIONS.merge || action === WORKTREE_ACTIONS.send || action === WORKTREE_ACTIONS.messages) && typeof record.id !== "string") throw require_gitDependencies.invalidRequest(`action='${action}' requires 'id'.`, "Call list to see the current ids.");
|
|
206
316
|
return record;
|
|
207
317
|
}
|
|
208
318
|
function describe(record, sessionId) {
|
|
@@ -217,9 +327,31 @@ function text(...lines) {
|
|
|
217
327
|
}
|
|
218
328
|
async function executeRunWorktreeTool(params, operations, context, options = {}) {
|
|
219
329
|
switch (params.action) {
|
|
330
|
+
case WORKTREE_ACTIONS.profiles: {
|
|
331
|
+
const profiles = await operations.profiles(context, params.baseRef, options);
|
|
332
|
+
return {
|
|
333
|
+
content: text(profiles.sparseProfiles?.join(", ") ?? "Sparse checkout is not configured."),
|
|
334
|
+
details: {
|
|
335
|
+
action: params.action,
|
|
336
|
+
...profiles
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
case WORKTREE_ACTIONS.expand:
|
|
341
|
+
case WORKTREE_ACTIONS.reapply: {
|
|
342
|
+
const record = params.action === "expand" ? await operations.expand(context, params.id, params.folders, options) : await operations.reapply(context, params.id, options);
|
|
343
|
+
return {
|
|
344
|
+
content: text(`Worktree ${record.id} sparse checkout updated.`),
|
|
345
|
+
details: {
|
|
346
|
+
action: params.action,
|
|
347
|
+
records: [record]
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
220
351
|
case WORKTREE_ACTIONS.spawn_worktree: {
|
|
221
352
|
const record = await operations.spawn(context, {
|
|
222
353
|
branch: params.branch,
|
|
354
|
+
...params.sparseProfile === void 0 ? {} : { sparseProfile: params.sparseProfile },
|
|
223
355
|
...params.baseRef === void 0 ? {} : { baseRef: params.baseRef },
|
|
224
356
|
...params.name === void 0 ? {} : { name: params.name },
|
|
225
357
|
...params.task === void 0 ? {} : { task: params.task }
|
|
@@ -317,14 +449,19 @@ interface Worktree {
|
|
|
317
449
|
id: string;
|
|
318
450
|
branch: string;
|
|
319
451
|
baseRef: string;
|
|
320
|
-
/** Absolute path of the checkout
|
|
452
|
+
/** Absolute path of the checkout. Imported worktrees stay at their original path. */
|
|
321
453
|
path: string;
|
|
322
454
|
repositoryRoot: string;
|
|
323
455
|
/** The session running inside the worktree. */
|
|
324
456
|
sessionId: string;
|
|
325
457
|
parentSessionId?: string;
|
|
326
458
|
status: WorktreeStatus;
|
|
459
|
+
/** started confirms runner launch only; unconfirmed handoffs must not be blindly retried. */
|
|
460
|
+
setupStage?: 'none' | 'started' | 'failed' | 'unconfirmed';
|
|
327
461
|
createdAt: string;
|
|
462
|
+
sparseProfile?: string;
|
|
463
|
+
extraFolders?: string[];
|
|
464
|
+
sparseFingerprint?: string;
|
|
328
465
|
/** How your session relates to it: 'parent' spawned it, 'child' runs inside it, 'other' is neither. */
|
|
329
466
|
relationship: 'parent' | 'child' | 'other';
|
|
330
467
|
}
|
|
@@ -357,7 +494,12 @@ declare const worktrees: {
|
|
|
357
494
|
* the current branch's remote-tracking ref, then the remote default branch; name labels it in the rail; task is
|
|
358
495
|
* the new session's first message. Setup can be slow, so give exec a larger timeoutMs.
|
|
359
496
|
*/
|
|
360
|
-
spawn(request: { branch: string; baseRef?: string; name?: string; task?: string }): Promise<Worktree>;
|
|
497
|
+
spawn(request: { branch: string; baseRef?: string; name?: string; task?: string; sparseProfile?: string }): Promise<Worktree>;
|
|
498
|
+
/** Run a repository workflow in its own checkout. Retrying the same attemptId never recreates uncertain work. */
|
|
499
|
+
startWorkflow(request: { key: string; attemptId?: string; branch?: string; sparseProfile?: string; inputs?: Record<string, string> }): Promise<{ attemptId: string; worktreeId: string; sessionId: string; branch: string; runId?: string; admission: 'pending' | 'registered' }>;
|
|
500
|
+
profiles(options?: { baseRef?: string }): Promise<{ sparseProfiles?: string[]; defaultSparseProfile?: string }>;
|
|
501
|
+
expand(id: string, folders: string[]): Promise<Worktree>;
|
|
502
|
+
reapply(id: string): Promise<Worktree>;
|
|
361
503
|
/** Stop the worktree's session and delete its checkout. Refused on a dirty tree unless force is true. */
|
|
362
504
|
close(id: string, options?: { force?: boolean }): Promise<Worktree>;
|
|
363
505
|
/** Merge the worktree's branch into this checkout. Refused when this checkout is dirty. */
|
|
@@ -377,7 +519,7 @@ const json = (value) => JSON.parse(JSON.stringify(value));
|
|
|
377
519
|
function createWorktreeNamespace(options) {
|
|
378
520
|
return {
|
|
379
521
|
name: "worktrees",
|
|
380
|
-
summary: "
|
|
522
|
+
summary: "Create and manage Git worktree sessions, select or expand a sparse checkout, and start isolated repository workflows.",
|
|
381
523
|
declarations: DECLARATIONS,
|
|
382
524
|
bind(run) {
|
|
383
525
|
if (run.sessionId !== options.execution.sessionId) throw new Error("Worktrees namespace belongs to another session.");
|
|
@@ -390,13 +532,15 @@ function createWorktreeNamespace(options) {
|
|
|
390
532
|
relationship: record.parentSessionId === options.execution.sessionId ? "parent" : record.sessionId === options.execution.sessionId ? "child" : "other"
|
|
391
533
|
});
|
|
392
534
|
/** One `run_worktree` action through the tool's own code, so the tool and the namespace cannot drift. */
|
|
393
|
-
const act = async (name, action, input) => {
|
|
535
|
+
const act = async (name, action, input = {}, target) => {
|
|
394
536
|
run.signal.throwIfAborted();
|
|
395
537
|
if (disposed) throw new Error("Worktrees namespace run is disposed.");
|
|
396
538
|
options.assertAvailable();
|
|
539
|
+
if (typeof input !== "object" || input === null || Array.isArray(input) || "action" in input) throw require_gitDependencies.invalidRequest(`Invalid options for worktrees.${name}.`, "Pass the documented fields without an action.");
|
|
397
540
|
const params = validateParams({
|
|
398
|
-
|
|
399
|
-
...
|
|
541
|
+
...input,
|
|
542
|
+
...target,
|
|
543
|
+
action
|
|
400
544
|
});
|
|
401
545
|
const context = {
|
|
402
546
|
cwd: options.execution.cwd,
|
|
@@ -429,6 +573,15 @@ function createWorktreeNamespace(options) {
|
|
|
429
573
|
};
|
|
430
574
|
const record = (result) => view(result.details.records[0]);
|
|
431
575
|
const members = Object.create(null);
|
|
576
|
+
members.profiles = async (settings) => {
|
|
577
|
+
const { action: _action, ...profiles } = (await act("profiles", "profiles", settings)).details;
|
|
578
|
+
return json(profiles);
|
|
579
|
+
};
|
|
580
|
+
members.expand = async (id, folders) => json(record(await act("expand", "expand", {
|
|
581
|
+
id,
|
|
582
|
+
folders
|
|
583
|
+
})));
|
|
584
|
+
members.reapply = async (id) => json(record(await act("reapply", "reapply", { id })));
|
|
432
585
|
members.list = async () => json((await act("list", "list", {})).details.records.map(view));
|
|
433
586
|
members.status = async (id) => {
|
|
434
587
|
const { details } = await act("status", "status", { id });
|
|
@@ -438,14 +591,36 @@ function createWorktreeNamespace(options) {
|
|
|
438
591
|
});
|
|
439
592
|
};
|
|
440
593
|
members.spawn = async (request) => json(record(await act("spawn", "spawn_worktree", request)));
|
|
441
|
-
members.
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
594
|
+
members.startWorkflow = async (request) => {
|
|
595
|
+
run.signal.throwIfAborted();
|
|
596
|
+
if (disposed) throw new Error("Worktrees namespace run is disposed.");
|
|
597
|
+
options.assertAvailable();
|
|
598
|
+
if (!(0, typebox_value.Check)(require_gitDependencies.StartWorktreeWorkflowSchema, request)) throw new Error("A repository workflow key and valid launch fields are required.");
|
|
599
|
+
const workflows = options.workflows?.();
|
|
600
|
+
if (!workflows) throw new Error("Isolated workflow admissions are unavailable in this session.");
|
|
601
|
+
const attemptId = request.attemptId ?? `git-${(0, node_crypto.randomUUID)()}`;
|
|
602
|
+
const started = await workflows.start({
|
|
603
|
+
attemptId,
|
|
604
|
+
definition: {
|
|
605
|
+
source: "repo",
|
|
606
|
+
key: request.key
|
|
607
|
+
},
|
|
608
|
+
...request.branch === void 0 ? {} : { branch: request.branch },
|
|
609
|
+
...request.sparseProfile === void 0 ? {} : { sparseProfile: request.sparseProfile },
|
|
610
|
+
...request.inputs === void 0 ? {} : { overrides: { inputs: request.inputs } }
|
|
611
|
+
}, run.signal);
|
|
612
|
+
options.assertAvailable();
|
|
613
|
+
return json({
|
|
614
|
+
attemptId,
|
|
615
|
+
worktreeId: started.worktreeId,
|
|
616
|
+
sessionId: started.sessionId,
|
|
617
|
+
branch: started.branch,
|
|
618
|
+
admission: started.admission.state,
|
|
619
|
+
...started.admission.state === "registered" ? { runId: started.admission.run.runId } : {}
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
members.close = async (id, settings) => json(record(await act("close", "close_worktree", settings, { id })));
|
|
623
|
+
members.merge = async (id, settings) => json(record(await act("merge", "merge", settings, { id })));
|
|
449
624
|
members.prune = async (settings) => {
|
|
450
625
|
const { plan } = (await act("prune", "prune", settings)).details;
|
|
451
626
|
return json({
|
|
@@ -467,6 +642,370 @@ function createWorktreeNamespace(options) {
|
|
|
467
642
|
};
|
|
468
643
|
}
|
|
469
644
|
//#endregion
|
|
645
|
+
//#region src/services/worktreeWorkflows/index.ts
|
|
646
|
+
var WorktreeWorkflowError = class extends Error {
|
|
647
|
+
code;
|
|
648
|
+
constructor(code, message, options) {
|
|
649
|
+
super(message, options);
|
|
650
|
+
this.code = code;
|
|
651
|
+
this.name = "WorktreeWorkflowError";
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
function canonical(value) {
|
|
655
|
+
if (Array.isArray(value)) return value.map(canonical);
|
|
656
|
+
if (value === null || typeof value !== "object") return value;
|
|
657
|
+
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical(value[key])]));
|
|
658
|
+
}
|
|
659
|
+
function defaultBranch(input) {
|
|
660
|
+
const safe = (value) => value.replace(/[^A-Za-z0-9._-]+/gu, "-").replace(/^[.-]+|[.-]+$/gu, "") || "run";
|
|
661
|
+
return `wf/${safe(node_path.default.basename(input.definition.key, node_path.default.extname(input.definition.key)))}/${safe(input.attemptId)}`;
|
|
662
|
+
}
|
|
663
|
+
function remoteBase(record) {
|
|
664
|
+
const ref = record.baseRef.replace(/^refs\/remotes\//u, "");
|
|
665
|
+
const slash = ref.indexOf("/");
|
|
666
|
+
if (slash < 1 || !record.baseCommit) return void 0;
|
|
667
|
+
const remote = ref.slice(0, slash);
|
|
668
|
+
const branch = ref.slice(slash + 1);
|
|
669
|
+
return require_gitDependencies.validRefName(remote) && require_gitDependencies.validRefName(branch) ? {
|
|
670
|
+
remote,
|
|
671
|
+
branch,
|
|
672
|
+
sha: record.baseCommit
|
|
673
|
+
} : void 0;
|
|
674
|
+
}
|
|
675
|
+
/** One coordinator over the existing admissions/runs services, never a second workflow engine. */
|
|
676
|
+
function createWorktreeWorkflows(options) {
|
|
677
|
+
if (!options.sessionId.trim()) throw new Error("A workflow launcher session is required.");
|
|
678
|
+
const context = {
|
|
679
|
+
cwd: options.cwd,
|
|
680
|
+
sessionId: options.sessionId
|
|
681
|
+
};
|
|
682
|
+
const watching = /* @__PURE__ */ new Map();
|
|
683
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
684
|
+
options.signal.addEventListener("abort", () => {
|
|
685
|
+
for (const stop of watching.values()) stop();
|
|
686
|
+
watching.clear();
|
|
687
|
+
}, { once: true });
|
|
688
|
+
const operation = (signal) => ({
|
|
689
|
+
env: options.environment,
|
|
690
|
+
signal: AbortSignal.any([options.signal, ...signal ? [signal] : []])
|
|
691
|
+
});
|
|
692
|
+
const store = async () => {
|
|
693
|
+
const root = await options.git.repositoryRoot(options.cwd);
|
|
694
|
+
if (!root) throw new WorktreeWorkflowError("not_started", "A repository checkout is required.");
|
|
695
|
+
return options.registry ? options.registry(root) : require_gitDependencies.createWorktreeRegistry(await require_gitDependencies.registryFile(root, options.homeDirectory, options.environment));
|
|
696
|
+
};
|
|
697
|
+
const mutate = async (fn, signal) => {
|
|
698
|
+
const registry = await store();
|
|
699
|
+
return registry.transaction(async () => {
|
|
700
|
+
const attempts = await registry.workflowAttempts();
|
|
701
|
+
const result = await fn(attempts);
|
|
702
|
+
await registry.replaceWorkflowAttempts(attempts);
|
|
703
|
+
return result;
|
|
704
|
+
}, operation(signal).signal);
|
|
705
|
+
};
|
|
706
|
+
const update = (attempt, signal) => mutate((attempts) => {
|
|
707
|
+
const index = attempts.findIndex((entry) => entry.launcherSessionId === options.sessionId && entry.attemptId === attempt.attemptId);
|
|
708
|
+
if (index < 0 || attempts[index].fingerprint !== attempt.fingerprint) throw new WorktreeWorkflowError("unknown", "The durable workflow intent changed.");
|
|
709
|
+
attempts[index] = structuredClone(attempt);
|
|
710
|
+
}, signal);
|
|
711
|
+
const ownRecords = async () => (await options.operations.list(context)).filter((record) => record.parentSessionId === options.sessionId && record.workflow);
|
|
712
|
+
const retain = async (record, reason) => {
|
|
713
|
+
await options.operations.linkWorkflow(context, record.id, {
|
|
714
|
+
...record.workflow,
|
|
715
|
+
state: "retained",
|
|
716
|
+
reason
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
const settle = async (record, attempt, state) => {
|
|
720
|
+
try {
|
|
721
|
+
const admission = attempt.admission;
|
|
722
|
+
if (admission?.state !== "registered" || JSON.stringify(canonical(state.run)) !== JSON.stringify(canonical(admission.run)) || state.run.ownerSessionId !== record.sessionId) return;
|
|
723
|
+
const current = (await ownRecords()).find((entry) => entry.id === record.id);
|
|
724
|
+
if (!current || current.sessionId !== record.sessionId || current.path !== record.path || current.status !== "running" || current.workflow?.state !== "admitted" || current.workflow?.runId !== state.run.runId || current.workflow.admissionId !== admission.admissionId || current.workflow.attemptId !== attempt.attemptId || current.workflow.fingerprint !== attempt.fingerprint) return;
|
|
725
|
+
let reason;
|
|
726
|
+
let verifiedHead;
|
|
727
|
+
if (state.stage !== "completed" || state.outcome !== "success") reason = `The run ended ${state.outcome ?? state.stage}.`;
|
|
728
|
+
else if (await options.git.repositoryRoot(current.path) !== current.path || await options.git.currentBranch(current.path) !== current.branch || !(await options.git.listWorktreePaths(current.repositoryRoot)).includes(current.path)) reason = "The exact linked checkout could not be verified.";
|
|
729
|
+
else if ((await options.git.dirtyFiles(current.path)).length > 0) reason = "Uncommitted files remain.";
|
|
730
|
+
else {
|
|
731
|
+
const head = await options.git.revision(current.path, "HEAD", operation());
|
|
732
|
+
verifiedHead = head;
|
|
733
|
+
if (!current.baseCommit) reason = "The original commit is unknown.";
|
|
734
|
+
else if (head !== current.baseCommit) {
|
|
735
|
+
const base = remoteBase(current);
|
|
736
|
+
if (!base || await options.git.remoteBranchHead(current.path, base.remote, current.branch, operation()) !== head) reason = "Delivery of this exact branch HEAD could not be verified.";
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (reason) {
|
|
740
|
+
await retain(current, reason);
|
|
741
|
+
await update({
|
|
742
|
+
...attempt,
|
|
743
|
+
state: "retained"
|
|
744
|
+
});
|
|
745
|
+
} else {
|
|
746
|
+
await options.operations.close(context, current.id, false, {
|
|
747
|
+
...current.workflow,
|
|
748
|
+
sessionId: current.sessionId,
|
|
749
|
+
path: current.path,
|
|
750
|
+
head: verifiedHead
|
|
751
|
+
});
|
|
752
|
+
await update({
|
|
753
|
+
...attempt,
|
|
754
|
+
state: "closed"
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
} catch (error) {
|
|
758
|
+
options.onError(error);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
const watch = (record, attempt) => {
|
|
762
|
+
const admission = attempt.admission;
|
|
763
|
+
if (admission?.state !== "registered" || watching.has(record.id) || options.signal.aborted) return;
|
|
764
|
+
const runs = options.runs();
|
|
765
|
+
if (!runs) return;
|
|
766
|
+
let stopped = false;
|
|
767
|
+
let unsubscribe;
|
|
768
|
+
const stop = () => {
|
|
769
|
+
stopped = true;
|
|
770
|
+
unsubscribe?.();
|
|
771
|
+
watching.delete(record.id);
|
|
772
|
+
};
|
|
773
|
+
watching.set(record.id, stop);
|
|
774
|
+
unsubscribe = runs.subscribe(admission.run.runId, (state) => {
|
|
775
|
+
if (stopped || state.stage === "running") return;
|
|
776
|
+
if (JSON.stringify(canonical(state.run)) !== JSON.stringify(canonical(admission.run))) return;
|
|
777
|
+
stop();
|
|
778
|
+
settle(record, attempt, state);
|
|
779
|
+
});
|
|
780
|
+
if (stopped) unsubscribe();
|
|
781
|
+
};
|
|
782
|
+
const link = async (record, attempt, admission) => {
|
|
783
|
+
if (admission.attemptId !== attempt.attemptId || admission.state === "registered" && admission.run.ownerSessionId !== record.sessionId) throw new WorktreeWorkflowError("unknown", "The admission does not belong to this checkout session.");
|
|
784
|
+
if (record.workflow?.admissionId && record.workflow.admissionId !== admission.admissionId || record.workflow?.runId && (admission.state !== "registered" || record.workflow.runId !== admission.run.runId) || attempt.admission && attempt.admission.admissionId !== admission.admissionId) throw new WorktreeWorkflowError("unknown", "The recorded workflow admission identity changed. The checkout was kept.");
|
|
785
|
+
if (record.workflow?.state === "retained" || [
|
|
786
|
+
"retained",
|
|
787
|
+
"closed",
|
|
788
|
+
"rejected"
|
|
789
|
+
].includes(attempt.state)) {
|
|
790
|
+
if (admission.state === "rejected") throw new WorktreeWorkflowError("not_started", "This rejected attempt remains retained.");
|
|
791
|
+
return {
|
|
792
|
+
worktreeId: record.id,
|
|
793
|
+
sessionId: record.sessionId,
|
|
794
|
+
branch: record.branch,
|
|
795
|
+
admission
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
const linked = {
|
|
799
|
+
attemptId: attempt.attemptId,
|
|
800
|
+
fingerprint: attempt.fingerprint,
|
|
801
|
+
state: admission.state === "rejected" ? "retained" : "admitted",
|
|
802
|
+
admissionId: admission.admissionId,
|
|
803
|
+
...admission.state === "registered" ? { runId: admission.run.runId } : {},
|
|
804
|
+
...admission.state === "rejected" ? { reason: `Admission rejected: ${admission.errors.join("; ")}` } : {}
|
|
805
|
+
};
|
|
806
|
+
await options.operations.linkWorkflow(context, record.id, linked);
|
|
807
|
+
const updated = {
|
|
808
|
+
...attempt,
|
|
809
|
+
admission,
|
|
810
|
+
state: admission.state === "rejected" ? "rejected" : "admitted",
|
|
811
|
+
worktreeId: record.id,
|
|
812
|
+
sessionId: record.sessionId
|
|
813
|
+
};
|
|
814
|
+
await update(updated);
|
|
815
|
+
if (admission.state === "rejected") throw new WorktreeWorkflowError("not_started", "The workflow admission was rejected. The checkout was kept.");
|
|
816
|
+
watch({
|
|
817
|
+
...record,
|
|
818
|
+
workflow: linked
|
|
819
|
+
}, updated);
|
|
820
|
+
return {
|
|
821
|
+
worktreeId: record.id,
|
|
822
|
+
sessionId: record.sessionId,
|
|
823
|
+
branch: record.branch,
|
|
824
|
+
admission
|
|
825
|
+
};
|
|
826
|
+
};
|
|
827
|
+
const start = async (input, branch, fingerprint, signal) => {
|
|
828
|
+
const admissions = options.admissions();
|
|
829
|
+
if (!admissions) throw new WorktreeWorkflowError("not_started", "Workflow admissions are unavailable.");
|
|
830
|
+
const records = await ownRecords();
|
|
831
|
+
const legacy = records.find((record) => record.workflow.attemptId === input.attemptId);
|
|
832
|
+
const { attempt, created } = await mutate((attempts) => {
|
|
833
|
+
let attempt = attempts.find((entry) => entry.launcherSessionId === options.sessionId && entry.attemptId === input.attemptId);
|
|
834
|
+
if (!attempt && legacy) {
|
|
835
|
+
attempt = {
|
|
836
|
+
attemptId: input.attemptId,
|
|
837
|
+
fingerprint: legacy.workflow.fingerprint,
|
|
838
|
+
launcherSessionId: options.sessionId,
|
|
839
|
+
branch: legacy.branch,
|
|
840
|
+
definition: input.definition,
|
|
841
|
+
createdAt: legacy.createdAt,
|
|
842
|
+
state: "spawned",
|
|
843
|
+
worktreeId: legacy.id,
|
|
844
|
+
sessionId: legacy.sessionId
|
|
845
|
+
};
|
|
846
|
+
attempts.push(attempt);
|
|
847
|
+
}
|
|
848
|
+
if (attempt) {
|
|
849
|
+
if (attempt.fingerprint !== fingerprint) throw new WorktreeWorkflowError("attempt_conflict", "This workflow attempt was started with different arguments.");
|
|
850
|
+
return {
|
|
851
|
+
attempt: structuredClone(attempt),
|
|
852
|
+
created: false
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
attempt = {
|
|
856
|
+
attemptId: input.attemptId,
|
|
857
|
+
fingerprint,
|
|
858
|
+
launcherSessionId: options.sessionId,
|
|
859
|
+
branch,
|
|
860
|
+
definition: input.definition,
|
|
861
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
862
|
+
state: "reserved"
|
|
863
|
+
};
|
|
864
|
+
attempts.push(attempt);
|
|
865
|
+
return {
|
|
866
|
+
attempt: structuredClone(attempt),
|
|
867
|
+
created: true
|
|
868
|
+
};
|
|
869
|
+
}, signal);
|
|
870
|
+
let record = records.find((entry) => entry.id === attempt.worktreeId) ?? legacy;
|
|
871
|
+
if (!created) {
|
|
872
|
+
if (!record || record.status === "orphaned") {
|
|
873
|
+
if (attempt.state === "rejected" && !record) throw new WorktreeWorkflowError("not_started", "This attempt was rejected before checkout creation. Use a new attempt identity after fixing it.");
|
|
874
|
+
if (attempt.state === "closed" && attempt.admission && attempt.worktreeId && attempt.sessionId) return {
|
|
875
|
+
worktreeId: attempt.worktreeId,
|
|
876
|
+
sessionId: attempt.sessionId,
|
|
877
|
+
branch: attempt.branch,
|
|
878
|
+
admission: attempt.admission
|
|
879
|
+
};
|
|
880
|
+
throw new WorktreeWorkflowError("unknown", "This attempt may have created work. Its checkout is absent or orphaned and will not be recreated.");
|
|
881
|
+
}
|
|
882
|
+
const admission = await admissions.read(input.attemptId);
|
|
883
|
+
if (!admission) throw new WorktreeWorkflowError("unknown", "This attempt has no authoritative admission outcome. Its checkout was kept.");
|
|
884
|
+
return link(record, attempt, admission);
|
|
885
|
+
}
|
|
886
|
+
let report;
|
|
887
|
+
try {
|
|
888
|
+
report = await admissions.validate({
|
|
889
|
+
kind: "launch",
|
|
890
|
+
definition: input.definition,
|
|
891
|
+
...input.overrides ? { overrides: input.overrides } : {}
|
|
892
|
+
});
|
|
893
|
+
} catch (error) {
|
|
894
|
+
await update({
|
|
895
|
+
...attempt,
|
|
896
|
+
state: "rejected"
|
|
897
|
+
}, signal);
|
|
898
|
+
throw new WorktreeWorkflowError("not_started", "Workflow validation failed before checkout creation.", { cause: error });
|
|
899
|
+
}
|
|
900
|
+
const frozen = input.overrides?.allocation;
|
|
901
|
+
const refusal = report.errors.length ? `The workflow is not valid: ${report.errors.map((issue) => issue.message).join("; ")}` : report.allocation === void 0 ? void 0 : frozen === void 0 ? "This role-bound workflow needs an allocation prepared before the checkout, and none was supplied." : JSON.stringify(canonical(report.allocation)) !== JSON.stringify(canonical(frozen)) ? "The workflow allocation changed since it was prepared." : void 0;
|
|
902
|
+
if (refusal) {
|
|
903
|
+
await update({
|
|
904
|
+
...attempt,
|
|
905
|
+
state: "rejected"
|
|
906
|
+
}, signal);
|
|
907
|
+
throw new WorktreeWorkflowError("not_started", refusal);
|
|
908
|
+
}
|
|
909
|
+
operation(signal).signal.throwIfAborted();
|
|
910
|
+
try {
|
|
911
|
+
record = await options.operations.spawn(context, {
|
|
912
|
+
branch,
|
|
913
|
+
...input.sparseProfile ? { sparseProfile: input.sparseProfile } : {}
|
|
914
|
+
}, {
|
|
915
|
+
workflow: {
|
|
916
|
+
attemptId: input.attemptId,
|
|
917
|
+
fingerprint
|
|
918
|
+
},
|
|
919
|
+
...input.preset ? { preset: input.preset } : {},
|
|
920
|
+
signal: operation(signal).signal
|
|
921
|
+
});
|
|
922
|
+
await update({
|
|
923
|
+
...attempt,
|
|
924
|
+
worktreeId: record.id,
|
|
925
|
+
sessionId: record.sessionId,
|
|
926
|
+
state: "spawned"
|
|
927
|
+
});
|
|
928
|
+
const base = remoteBase(record);
|
|
929
|
+
if (!base) throw new WorktreeWorkflowError("not_started", "The workflow base is not a verifiable remote branch. The checkout was kept.");
|
|
930
|
+
const pending = {
|
|
931
|
+
...attempt,
|
|
932
|
+
worktreeId: record.id,
|
|
933
|
+
sessionId: record.sessionId,
|
|
934
|
+
state: "admitting"
|
|
935
|
+
};
|
|
936
|
+
await update(pending);
|
|
937
|
+
const admission = await admissions.launch(input.attemptId, input.definition, {
|
|
938
|
+
...input.overrides,
|
|
939
|
+
env: {
|
|
940
|
+
...input.overrides?.env,
|
|
941
|
+
SPARO_BASE_REMOTE: base.remote,
|
|
942
|
+
SPARO_BASE_BRANCH: base.branch,
|
|
943
|
+
SPARO_BASE_SHA: base.sha,
|
|
944
|
+
SPARO_BRANCH: record.branch,
|
|
945
|
+
PO_GIT_BASE_REMOTE: base.remote,
|
|
946
|
+
PO_GIT_BASE_BRANCH: base.branch,
|
|
947
|
+
PO_GIT_BASE_SHA: base.sha,
|
|
948
|
+
PO_GIT_BRANCH: record.branch
|
|
949
|
+
},
|
|
950
|
+
targetSessionId: record.sessionId
|
|
951
|
+
});
|
|
952
|
+
return await link(record, pending, admission);
|
|
953
|
+
} catch (error) {
|
|
954
|
+
if (error instanceof WorktreeWorkflowError) throw error;
|
|
955
|
+
throw new WorktreeWorkflowError("unknown", "The workflow launch outcome is uncertain. Inspect the saved attempt before retrying.", { cause: error });
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
return {
|
|
959
|
+
start(input, signal) {
|
|
960
|
+
options.signal.throwIfAborted();
|
|
961
|
+
signal?.throwIfAborted();
|
|
962
|
+
if (!input || typeof input.attemptId !== "string" || !input.attemptId.trim() || !(0, typebox_value.Check)(_agimon_ai_po_core_workflow.PoWorkflowDefinitionRefSchema, input.definition) || input.definition.source !== "repo" || input.sparseProfile !== void 0 && !require_gitDependencies.validSparseProfile(input.sparseProfile)) return Promise.reject(new WorktreeWorkflowError("not_started", "A valid repository workflow and attempt identity are required."));
|
|
963
|
+
const snapshot = structuredClone(input);
|
|
964
|
+
const branch = snapshot.branch ?? defaultBranch(snapshot);
|
|
965
|
+
if (!require_gitDependencies.validRefName(branch)) return Promise.reject(new WorktreeWorkflowError("not_started", "The workflow branch is invalid."));
|
|
966
|
+
const fingerprint = (0, node_crypto.createHash)("sha256").update(JSON.stringify(canonical({
|
|
967
|
+
definition: snapshot.definition,
|
|
968
|
+
branch,
|
|
969
|
+
profile: snapshot.sparseProfile,
|
|
970
|
+
preset: snapshot.preset,
|
|
971
|
+
overrides: snapshot.overrides
|
|
972
|
+
}))).digest("hex");
|
|
973
|
+
const existing = inFlight.get(snapshot.attemptId);
|
|
974
|
+
if (existing) return existing.fingerprint === fingerprint ? existing.promise : Promise.reject(new WorktreeWorkflowError("attempt_conflict", "This workflow attempt is already starting with different arguments."));
|
|
975
|
+
const promise = start(snapshot, branch, fingerprint, signal).finally(() => {
|
|
976
|
+
inFlight.delete(snapshot.attemptId);
|
|
977
|
+
});
|
|
978
|
+
inFlight.set(snapshot.attemptId, {
|
|
979
|
+
fingerprint,
|
|
980
|
+
promise
|
|
981
|
+
});
|
|
982
|
+
return promise;
|
|
983
|
+
},
|
|
984
|
+
async reconcile(signal) {
|
|
985
|
+
operation(signal).signal.throwIfAborted();
|
|
986
|
+
const admissions = options.admissions();
|
|
987
|
+
if (!admissions) return;
|
|
988
|
+
const records = await ownRecords();
|
|
989
|
+
const registry = await store();
|
|
990
|
+
const attempts = await registry.transaction(() => registry.workflowAttempts(), operation(signal).signal);
|
|
991
|
+
for (const attempt of attempts.filter((entry) => entry.launcherSessionId === options.sessionId && ![
|
|
992
|
+
"closed",
|
|
993
|
+
"rejected",
|
|
994
|
+
"retained"
|
|
995
|
+
].includes(entry.state))) {
|
|
996
|
+
const record = records.find((entry) => entry.id === attempt.worktreeId || entry.workflow.attemptId === attempt.attemptId);
|
|
997
|
+
if (!record || record.status === "orphaned") continue;
|
|
998
|
+
try {
|
|
999
|
+
const admission = await admissions.read(attempt.attemptId);
|
|
1000
|
+
if (admission) await link(record, attempt, admission);
|
|
1001
|
+
} catch (error) {
|
|
1002
|
+
options.onError(error);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
//#endregion
|
|
470
1009
|
//#region src/extensions/workspaces/sessions/(backend)/_lib/root.server.ts
|
|
471
1010
|
function progressResult(action, label) {
|
|
472
1011
|
return {
|
|
@@ -486,18 +1025,66 @@ const READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
|
|
|
486
1025
|
"discover",
|
|
487
1026
|
"load_skill"
|
|
488
1027
|
]);
|
|
489
|
-
function createGitSession({ context, host: serverHost, agent, signal }) {
|
|
1028
|
+
async function createGitSession({ context, host: serverHost, agent, signal }) {
|
|
490
1029
|
if (serverHost.context.directEvents === void 0) throw new Error("Git server plugin requires the session direct event bus.");
|
|
491
1030
|
if (serverHost.context.sessionId === void 0) throw new Error("Git server plugin requires a session identity.");
|
|
492
1031
|
const sessionId = serverHost.context.sessionId;
|
|
493
1032
|
const directEvents = serverHost.context.directEvents;
|
|
494
|
-
const messageInbox =
|
|
495
|
-
const
|
|
496
|
-
|
|
1033
|
+
const messageInbox = require_gitDependencies.createWorktreeMessageInbox(directEvents, sessionId);
|
|
1034
|
+
const setupReceiver = context.inject(["po/runner-launch"], (child) => {
|
|
1035
|
+
const runner = child.get("po/runner-launch");
|
|
1036
|
+
const cwd = serverHost.context.cwd;
|
|
1037
|
+
if (!runner || !cwd) return void 0;
|
|
1038
|
+
return require_gitDependencies.receiveWorktreeSetup(directEvents, sessionId, cwd, runner, signal);
|
|
1039
|
+
});
|
|
1040
|
+
const operations = require_gitDependencies.createWorktreeOperations({
|
|
1041
|
+
git: require_gitDependencies.createWorktreeGit(),
|
|
1042
|
+
...require_gitDependencies.createGitOperationDependencies({
|
|
1043
|
+
context,
|
|
1044
|
+
host: serverHost,
|
|
1045
|
+
signal
|
|
1046
|
+
}),
|
|
497
1047
|
sessionService: serverHost.context.sessionService,
|
|
498
1048
|
messageInbox,
|
|
499
1049
|
sessionDelivery: () => (0, _agimon_ai_po_session.readPoSessionDelivery)(context)
|
|
500
1050
|
});
|
|
1051
|
+
const homeDirectory = serverHost.context.homeDirectory ?? serverHost.context.environment?.HOME;
|
|
1052
|
+
let workflows;
|
|
1053
|
+
const workflowProvider = context.inject([_agimon_ai_po_core_serverPlugin.PO_SERVER_SCOPE_SERVICE], async (scoped) => {
|
|
1054
|
+
if (!homeDirectory || !serverHost.context.cwd) return void 0;
|
|
1055
|
+
const lifetime = new AbortController();
|
|
1056
|
+
const service = createWorktreeWorkflows({
|
|
1057
|
+
sessionId,
|
|
1058
|
+
cwd: serverHost.context.cwd,
|
|
1059
|
+
homeDirectory,
|
|
1060
|
+
environment: serverHost.context.environment ?? {},
|
|
1061
|
+
signal: AbortSignal.any([signal, lifetime.signal]),
|
|
1062
|
+
operations,
|
|
1063
|
+
git: {
|
|
1064
|
+
...require_gitDependencies.createWorktreeGit(),
|
|
1065
|
+
revision: require_gitDependencies.revision,
|
|
1066
|
+
remoteBranchHead: require_gitDependencies.remoteBranchHead
|
|
1067
|
+
},
|
|
1068
|
+
admissions: () => (0, _agimon_ai_po_core_workflow.readPoWorkflowAdmissionsService)(scoped),
|
|
1069
|
+
runs: () => (0, _agimon_ai_po_core_workflow.readPoWorkflowRunsService)(scoped),
|
|
1070
|
+
onError: (error) => serverHost.context.onNotice(`Workflow checkout retained (${error instanceof Error ? error.name : "unknown error"}).`)
|
|
1071
|
+
});
|
|
1072
|
+
const release = await (0, _agimon_ai_po_core_serverPlugin.requirePoServerScope)(scoped).provide(require_gitDependencies.GIT_WORKFLOWS_CONTRACT, service);
|
|
1073
|
+
workflows = service;
|
|
1074
|
+
return async () => {
|
|
1075
|
+
if (workflows === service) workflows = void 0;
|
|
1076
|
+
lifetime.abort();
|
|
1077
|
+
await release();
|
|
1078
|
+
};
|
|
1079
|
+
});
|
|
1080
|
+
if (context.get(_agimon_ai_po_core_serverPlugin.PO_SERVER_SCOPE_SERVICE) !== void 0) await workflowProvider.await();
|
|
1081
|
+
const workflowServices = context.inject([_agimon_ai_po_core_workflow.PO_WORKFLOW_ADMISSIONS_SERVICE, _agimon_ai_po_core_workflow.PO_WORKFLOW_RUNS_SERVICE], async () => {
|
|
1082
|
+
try {
|
|
1083
|
+
await workflows?.reconcile();
|
|
1084
|
+
} catch (error) {
|
|
1085
|
+
serverHost.context.onNotice(`Workflow reconciliation deferred (${error instanceof Error ? error.name : "unknown error"}).`);
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
501
1088
|
const resources = [{
|
|
502
1089
|
name: "codemode-how-to-git",
|
|
503
1090
|
description: "Hand a branch of work to a separate session in its own checkout, keeping the current checkout untouched. Use for a long refactor, a risky migration, or parallel features that touch the same files; not for parallel work on one branch.",
|
|
@@ -522,7 +1109,7 @@ function createGitSession({ context, host: serverHost, agent, signal }) {
|
|
|
522
1109
|
}
|
|
523
1110
|
};
|
|
524
1111
|
const changed = (_event, execution) => {
|
|
525
|
-
directEvents.publish(
|
|
1112
|
+
directEvents.publish(require_gitDependencies.GIT_SESSION_CHANGED_EVENT, execution.sessionId, { version: 1 });
|
|
526
1113
|
};
|
|
527
1114
|
const hooks = [{
|
|
528
1115
|
event: "tool_execution_end",
|
|
@@ -534,6 +1121,7 @@ function createGitSession({ context, host: serverHost, agent, signal }) {
|
|
|
534
1121
|
if (agent) {
|
|
535
1122
|
const namespace = createWorktreeNamespace({
|
|
536
1123
|
operations,
|
|
1124
|
+
workflows: () => workflows,
|
|
537
1125
|
execution: agent.context,
|
|
538
1126
|
assertAvailable: () => {
|
|
539
1127
|
if (signal?.aborted) throw new Error("Git session is unavailable.");
|
|
@@ -556,7 +1144,12 @@ function createGitSession({ context, host: serverHost, agent, signal }) {
|
|
|
556
1144
|
tool,
|
|
557
1145
|
hooks
|
|
558
1146
|
},
|
|
559
|
-
onDispose: () =>
|
|
1147
|
+
onDispose: async () => {
|
|
1148
|
+
await workflowServices.dispose();
|
|
1149
|
+
await workflowProvider.dispose();
|
|
1150
|
+
await setupReceiver.dispose();
|
|
1151
|
+
messageInbox.close();
|
|
1152
|
+
}
|
|
560
1153
|
};
|
|
561
1154
|
}
|
|
562
1155
|
const root = (0, _agimon_ai_po_core_extensionFile.defineRoot)(createGitSession);
|
|
@@ -592,15 +1185,15 @@ const BINARY_PROBE_BYTES = 8192;
|
|
|
592
1185
|
const SHORT_SHA = 7;
|
|
593
1186
|
const DEFAULT_BRANCHES = ["main", "master"];
|
|
594
1187
|
async function read(cwd, args) {
|
|
595
|
-
const result = await
|
|
1188
|
+
const result = await require_gitDependencies.runGit(cwd, args, { timeout: require_gitDependencies.READ_TIMEOUT_MS });
|
|
596
1189
|
return result.code === 0 ? result.stdout : void 0;
|
|
597
1190
|
}
|
|
598
|
-
async function readLine
|
|
1191
|
+
async function readLine(cwd, args) {
|
|
599
1192
|
const out = (await read(cwd, args))?.trim();
|
|
600
1193
|
return out === void 0 || out === "" ? void 0 : out;
|
|
601
1194
|
}
|
|
602
1195
|
async function commitExists(cwd, ref) {
|
|
603
|
-
return await readLine
|
|
1196
|
+
return await readLine(cwd, [
|
|
604
1197
|
"rev-parse",
|
|
605
1198
|
"--verify",
|
|
606
1199
|
"--quiet",
|
|
@@ -609,7 +1202,7 @@ async function commitExists(cwd, ref) {
|
|
|
609
1202
|
}
|
|
610
1203
|
/** A local branch's upstream, so the review measures against what fetch keeps current. */
|
|
611
1204
|
async function upstreamOf(cwd, ref) {
|
|
612
|
-
return readLine
|
|
1205
|
+
return readLine(cwd, [
|
|
613
1206
|
"rev-parse",
|
|
614
1207
|
"--abbrev-ref",
|
|
615
1208
|
"--symbolic-full-name",
|
|
@@ -618,13 +1211,13 @@ async function upstreamOf(cwd, ref) {
|
|
|
618
1211
|
}
|
|
619
1212
|
/** The ref the review is measured against. Exported for sync, whose rebase uses the same base. */
|
|
620
1213
|
async function resolveBaseRef(cwd, branch, recordedBaseRef) {
|
|
621
|
-
if (!(recordedBaseRef === void 0 || branch !== void 0 && (recordedBaseRef === branch || recordedBaseRef.endsWith(`/${branch}`))) && recordedBaseRef !== void 0 && await commitExists(cwd, recordedBaseRef)) return (await readLine
|
|
1214
|
+
if (!(recordedBaseRef === void 0 || branch !== void 0 && (recordedBaseRef === branch || recordedBaseRef.endsWith(`/${branch}`))) && recordedBaseRef !== void 0 && await commitExists(cwd, recordedBaseRef)) return (await readLine(cwd, [
|
|
622
1215
|
"rev-parse",
|
|
623
1216
|
"--verify",
|
|
624
1217
|
"--quiet",
|
|
625
1218
|
`refs/heads/${recordedBaseRef}`
|
|
626
1219
|
]) !== void 0 ? await upstreamOf(cwd, recordedBaseRef) : void 0) ?? recordedBaseRef;
|
|
627
|
-
const originHead = await readLine
|
|
1220
|
+
const originHead = await readLine(cwd, [
|
|
628
1221
|
"symbolic-ref",
|
|
629
1222
|
"--quiet",
|
|
630
1223
|
"--short",
|
|
@@ -638,7 +1231,7 @@ async function resolveBase(cwd, branch, recordedBaseRef) {
|
|
|
638
1231
|
const ref = await resolveBaseRef(cwd, branch, recordedBaseRef);
|
|
639
1232
|
const head = await commitExists(cwd, "HEAD");
|
|
640
1233
|
if (ref !== void 0 && head) {
|
|
641
|
-
const mergeBase = await readLine
|
|
1234
|
+
const mergeBase = await readLine(cwd, [
|
|
642
1235
|
"merge-base",
|
|
643
1236
|
ref,
|
|
644
1237
|
"HEAD"
|
|
@@ -750,9 +1343,9 @@ function parseUnifiedDiff(diff) {
|
|
|
750
1343
|
function createBranchDiff() {
|
|
751
1344
|
return {
|
|
752
1345
|
async review(cwd, options = {}) {
|
|
753
|
-
const root = await readLine
|
|
1346
|
+
const root = await readLine(cwd, ["rev-parse", "--show-toplevel"]);
|
|
754
1347
|
if (root === void 0) return void 0;
|
|
755
|
-
const branch = await readLine
|
|
1348
|
+
const branch = await readLine(root, [
|
|
756
1349
|
"symbolic-ref",
|
|
757
1350
|
"--quiet",
|
|
758
1351
|
"--short",
|
|
@@ -813,12 +1406,12 @@ function createBranchDiff() {
|
|
|
813
1406
|
}
|
|
814
1407
|
entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
815
1408
|
const conflicts = [...unmerged];
|
|
816
|
-
const rebaseMerge = await readLine
|
|
1409
|
+
const rebaseMerge = await readLine(root, [
|
|
817
1410
|
"rev-parse",
|
|
818
1411
|
"--git-path",
|
|
819
1412
|
"rebase-merge"
|
|
820
1413
|
]);
|
|
821
|
-
const rebaseApply = await readLine
|
|
1414
|
+
const rebaseApply = await readLine(root, [
|
|
822
1415
|
"rev-parse",
|
|
823
1416
|
"--git-path",
|
|
824
1417
|
"rebase-apply"
|
|
@@ -827,7 +1420,7 @@ function createBranchDiff() {
|
|
|
827
1420
|
const upstreamRef = branch === void 0 ? void 0 : await upstreamOf(root, branch);
|
|
828
1421
|
let upstream;
|
|
829
1422
|
if (upstreamRef !== void 0) {
|
|
830
|
-
const [behind, ahead] = (await readLine
|
|
1423
|
+
const [behind, ahead] = (await readLine(root, [
|
|
831
1424
|
"rev-list",
|
|
832
1425
|
"--left-right",
|
|
833
1426
|
"--count",
|
|
@@ -910,7 +1503,7 @@ function createBranchDiff() {
|
|
|
910
1503
|
}]
|
|
911
1504
|
};
|
|
912
1505
|
}
|
|
913
|
-
const result = await
|
|
1506
|
+
const result = await require_gitDependencies.runGit(review.root, [
|
|
914
1507
|
"diff",
|
|
915
1508
|
"-U3",
|
|
916
1509
|
"--no-color",
|
|
@@ -921,7 +1514,7 @@ function createBranchDiff() {
|
|
|
921
1514
|
"--",
|
|
922
1515
|
`:(top,literal)${entry.path}`
|
|
923
1516
|
], {
|
|
924
|
-
timeout:
|
|
1517
|
+
timeout: require_gitDependencies.READ_TIMEOUT_MS,
|
|
925
1518
|
maxBuffer: MAX_FILE_BYTES
|
|
926
1519
|
});
|
|
927
1520
|
if (result.overflow) return {
|
|
@@ -974,7 +1567,6 @@ const LOOSE_BITS = 63;
|
|
|
974
1567
|
const HOST_PATTERN = /^[a-z0-9.-]{1,253}(:\d{1,5})?$/u;
|
|
975
1568
|
const MAX_USERNAME = 256;
|
|
976
1569
|
const MAX_TOKEN = 4096;
|
|
977
|
-
const SETTINGS_HINT = "Open settings, then repository, then git remote.";
|
|
978
1570
|
/** Environment that would make git log or skip what this module relies on. */
|
|
979
1571
|
const STRIPPED_ALWAYS = ["GIT_CURL_VERBOSE", "GIT_TRACE_REDACT"];
|
|
980
1572
|
const STRIPPED_PREFIXES = ["GIT_TRACE"];
|
|
@@ -1054,20 +1646,20 @@ function publicView(config) {
|
|
|
1054
1646
|
* was not entered for.
|
|
1055
1647
|
*/
|
|
1056
1648
|
async function parseGitAuthSave(request, current, homeDir) {
|
|
1057
|
-
if (!isRecord(request)) throw
|
|
1649
|
+
if (!isRecord(request)) throw require_gitDependencies.invalidRequest("The git auth request is not an object.", "Send method none, ssh or https.");
|
|
1058
1650
|
if (request.method === "none") return { method: "none" };
|
|
1059
1651
|
if (request.method === "ssh") {
|
|
1060
1652
|
if (request.keyPath === void 0 || request.keyPath === "") return { method: "ssh" };
|
|
1061
|
-
if (typeof request.keyPath !== "string" || hasControl(request.keyPath)) throw
|
|
1653
|
+
if (typeof request.keyPath !== "string" || hasControl(request.keyPath)) throw require_gitDependencies.invalidRequest("The key path is not a plain path.", "Give the key as an absolute path or one under ~/.");
|
|
1062
1654
|
const keyPath = request.keyPath.trim();
|
|
1063
|
-
if (!keyPath.startsWith("/") && !keyPath.startsWith("~/")) throw
|
|
1655
|
+
if (!keyPath.startsWith("/") && !keyPath.startsWith("~/")) throw require_gitDependencies.invalidRequest("The key path is not absolute.", "Give the key as an absolute path or one under ~/.");
|
|
1064
1656
|
let isFile = false;
|
|
1065
1657
|
try {
|
|
1066
1658
|
isFile = (await node_fs_promises.default.stat(expandHome(keyPath, homeDir))).isFile();
|
|
1067
1659
|
} catch {
|
|
1068
1660
|
isFile = false;
|
|
1069
1661
|
}
|
|
1070
|
-
if (!isFile) throw
|
|
1662
|
+
if (!isFile) throw require_gitDependencies.invalidRequest(`No key file at ${keyPath}.`, "Check the path, or leave it blank to use ssh-agent.");
|
|
1071
1663
|
return {
|
|
1072
1664
|
method: "ssh",
|
|
1073
1665
|
keyPath
|
|
@@ -1075,11 +1667,11 @@ async function parseGitAuthSave(request, current, homeDir) {
|
|
|
1075
1667
|
}
|
|
1076
1668
|
if (request.method === "https") {
|
|
1077
1669
|
const host = typeof request.host === "string" ? request.host.trim().toLowerCase() : "";
|
|
1078
|
-
if (!HOST_PATTERN.test(host)) throw
|
|
1670
|
+
if (!HOST_PATTERN.test(host)) throw require_gitDependencies.invalidRequest("The host is not a host name.", "Use a host like github.com, with an optional :port.");
|
|
1079
1671
|
const username = typeof request.username === "string" ? request.username.trim() : "";
|
|
1080
|
-
if (username === "" || username.length > MAX_USERNAME || hasControl(username)) throw
|
|
1672
|
+
if (username === "" || username.length > MAX_USERNAME || hasControl(username)) throw require_gitDependencies.invalidRequest("The username is empty or not plain text.", "Enter the username the host knows you by.");
|
|
1081
1673
|
if (request.token !== void 0 && request.token !== "") {
|
|
1082
|
-
if (typeof request.token !== "string" || request.token.length > MAX_TOKEN || hasControl(request.token)) throw
|
|
1674
|
+
if (typeof request.token !== "string" || request.token.length > MAX_TOKEN || hasControl(request.token)) throw require_gitDependencies.invalidRequest("The token is not plain text.", "Paste the token again without line breaks.");
|
|
1083
1675
|
return {
|
|
1084
1676
|
method: "https",
|
|
1085
1677
|
host,
|
|
@@ -1093,9 +1685,9 @@ async function parseGitAuthSave(request, current, homeDir) {
|
|
|
1093
1685
|
username,
|
|
1094
1686
|
token: current.token
|
|
1095
1687
|
};
|
|
1096
|
-
throw
|
|
1688
|
+
throw require_gitDependencies.invalidRequest(current.method === "https" ? "The host changed, so the saved token cannot follow it." : "A token is required.", "Enter the personal access token for this host.");
|
|
1097
1689
|
}
|
|
1098
|
-
throw
|
|
1690
|
+
throw require_gitDependencies.invalidRequest("The git auth method is unknown.", "Send method none, ssh or https.");
|
|
1099
1691
|
}
|
|
1100
1692
|
/** Tightens a file or folder something left readable by group or others. */
|
|
1101
1693
|
async function tighten(target, mode) {
|
|
@@ -1104,10 +1696,10 @@ async function tighten(target, mode) {
|
|
|
1104
1696
|
} catch {}
|
|
1105
1697
|
}
|
|
1106
1698
|
function createGitAuthStore(homeDir = node_os.default.homedir(), environment = {}) {
|
|
1107
|
-
const file =
|
|
1699
|
+
const file = require_gitDependencies.credentialsFile(homeDir, environment);
|
|
1108
1700
|
const readFile = async () => {
|
|
1109
1701
|
await tighten(file, OWNER_ONLY_FILE);
|
|
1110
|
-
const raw = await
|
|
1702
|
+
const raw = await require_gitDependencies.readJson(file);
|
|
1111
1703
|
const workspaces = {};
|
|
1112
1704
|
if (isRecord(raw) && raw.version === 1 && isRecord(raw.workspaces)) for (const [key, value] of Object.entries(raw.workspaces)) {
|
|
1113
1705
|
const config = parseConfig(value);
|
|
@@ -1126,7 +1718,7 @@ function createGitAuthStore(homeDir = node_os.default.homedir(), environment = {
|
|
|
1126
1718
|
const key = await workspaceKey(workspaceRoot);
|
|
1127
1719
|
const current = await readFile();
|
|
1128
1720
|
const next = await parseGitAuthSave(request, current.workspaces[key] ?? { method: "none" }, homeDir);
|
|
1129
|
-
const root =
|
|
1721
|
+
const root = require_gitDependencies.poGitRoot(homeDir, environment);
|
|
1130
1722
|
await node_fs_promises.default.mkdir(root, {
|
|
1131
1723
|
recursive: true,
|
|
1132
1724
|
mode: OWNER_ONLY_DIRECTORY
|
|
@@ -1135,7 +1727,7 @@ function createGitAuthStore(homeDir = node_os.default.homedir(), environment = {
|
|
|
1135
1727
|
const workspaces = { ...current.workspaces };
|
|
1136
1728
|
if (next.method === "none") delete workspaces[key];
|
|
1137
1729
|
else workspaces[key] = next;
|
|
1138
|
-
await
|
|
1730
|
+
await require_gitDependencies.writeJsonAtomic(file, {
|
|
1139
1731
|
version: 1,
|
|
1140
1732
|
workspaces
|
|
1141
1733
|
});
|
|
@@ -1238,97 +1830,481 @@ function remoteEnv(config, remoteUrl, baseEnv, homeDir) {
|
|
|
1238
1830
|
};
|
|
1239
1831
|
}
|
|
1240
1832
|
//#endregion
|
|
1241
|
-
//#region src/services/
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1833
|
+
//#region src/services/gitFailure/index.ts
|
|
1834
|
+
const english = (_key, fallback, vars) => (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars);
|
|
1835
|
+
const RULES = [
|
|
1836
|
+
{
|
|
1837
|
+
code: "host_key_changed",
|
|
1838
|
+
phrases: ["remote host identification has changed"],
|
|
1839
|
+
message: (t) => t("git.failure.host_key_changed.message", "The remote's SSH host key changed since this machine last saw it."),
|
|
1840
|
+
recovery: (t) => t("git.failure.host_key_changed.recovery", "Check with the host that the change is expected, then update ~/.ssh/known_hosts from a terminal."),
|
|
1841
|
+
retryable: false
|
|
1842
|
+
},
|
|
1843
|
+
{
|
|
1844
|
+
code: "host_key_unknown",
|
|
1845
|
+
phrases: [
|
|
1846
|
+
"host key verification failed",
|
|
1847
|
+
"no ed25519 host key is known",
|
|
1848
|
+
"no rsa host key is known"
|
|
1849
|
+
],
|
|
1850
|
+
message: (t) => t("git.failure.host_key_unknown.message", "This machine does not trust the remote's SSH host key yet."),
|
|
1851
|
+
recovery: (t) => t("git.failure.host_key_unknown.recovery", "Run `ssh -T git@<host>` once in a terminal and accept the key, then try again."),
|
|
1852
|
+
retryable: false
|
|
1853
|
+
},
|
|
1854
|
+
{
|
|
1855
|
+
code: "auth_failed",
|
|
1856
|
+
phrases: [
|
|
1857
|
+
"authentication failed",
|
|
1858
|
+
"could not read username",
|
|
1859
|
+
"could not read password",
|
|
1860
|
+
"permission denied (publickey",
|
|
1861
|
+
"returned error: 401",
|
|
1862
|
+
"returned error: 403",
|
|
1863
|
+
"terminal prompts disabled",
|
|
1864
|
+
"load key",
|
|
1865
|
+
"unprotected private key",
|
|
1866
|
+
"invalid format"
|
|
1867
|
+
],
|
|
1868
|
+
message: (t) => t("git.failure.auth_failed.message", "The remote refused the credentials."),
|
|
1869
|
+
recovery: (t) => t("git.failure.auth_failed.recovery", "Check this workspace's git remote auth. Open settings, then repository, then git remote."),
|
|
1870
|
+
retryable: false
|
|
1871
|
+
},
|
|
1872
|
+
{
|
|
1873
|
+
code: "repository_not_found",
|
|
1874
|
+
phrases: ["repository not found", "does not appear to be a git repository"],
|
|
1875
|
+
message: (t) => t("git.failure.repository_not_found.message", "The remote repository was not found, or these credentials cannot see it."),
|
|
1876
|
+
recovery: (t) => t("git.failure.repository_not_found.recovery", "Check the remote URL and that the credentials have access. Open settings, then repository, then git remote."),
|
|
1877
|
+
retryable: false
|
|
1878
|
+
},
|
|
1879
|
+
{
|
|
1880
|
+
code: "remote_unreachable",
|
|
1881
|
+
phrases: [
|
|
1882
|
+
"could not resolve host",
|
|
1883
|
+
"connection refused",
|
|
1884
|
+
"connection timed out",
|
|
1885
|
+
"operation timed out",
|
|
1886
|
+
"unable to access",
|
|
1887
|
+
"network is unreachable"
|
|
1888
|
+
],
|
|
1889
|
+
message: (t) => t("git.failure.remote_unreachable.message", "The remote could not be reached."),
|
|
1890
|
+
recovery: (t) => t("git.failure.remote_unreachable.recovery", "Check the network and the remote URL, then try again."),
|
|
1891
|
+
retryable: true
|
|
1892
|
+
},
|
|
1893
|
+
{
|
|
1894
|
+
code: "push_lease_rejected",
|
|
1895
|
+
phrases: ["(stale info)"],
|
|
1896
|
+
message: (t) => t("git.failure.push_lease_rejected.message", "The remote branch moved since your last fetch, so the force push was refused."),
|
|
1897
|
+
recovery: (t) => t("git.failure.push_lease_rejected.recovery", "Pull to see the new commits, then decide whether to push again."),
|
|
1898
|
+
retryable: false
|
|
1899
|
+
},
|
|
1900
|
+
{
|
|
1901
|
+
code: "push_needs_force",
|
|
1902
|
+
phrases: ["(non-fast-forward)", "(fetch first)"],
|
|
1903
|
+
message: (t) => t("git.failure.push_needs_force.message", "The remote branch has commits yours replaced, usually after a rebase."),
|
|
1904
|
+
recovery: (t) => t("git.failure.push_needs_force.recovery", "Confirm a force push with lease, or pull first to keep the remote commits."),
|
|
1905
|
+
retryable: false
|
|
1906
|
+
},
|
|
1907
|
+
{
|
|
1908
|
+
code: "worktree_dirty",
|
|
1909
|
+
phrases: [
|
|
1910
|
+
"unstaged changes",
|
|
1911
|
+
"uncommitted changes",
|
|
1912
|
+
"would be overwritten",
|
|
1913
|
+
"your index contains uncommitted changes"
|
|
1914
|
+
],
|
|
1915
|
+
message: (t) => t("git.failure.worktree_dirty.message", "There are uncommitted changes in the way."),
|
|
1916
|
+
recovery: (t) => t("git.failure.worktree_dirty.recovery", "Commit or stash your changes first."),
|
|
1917
|
+
retryable: false
|
|
1287
1918
|
}
|
|
1288
|
-
|
|
1919
|
+
];
|
|
1920
|
+
function classifyGitFailure(operation, result, mismatch, t = english) {
|
|
1921
|
+
if (result.timedOut) return new require_gitDependencies.PoGitExpectedError("git_timeout", t("git.failure.timeout", "git {operation} took too long and was stopped.", { operation }), true, t("git.failure.timeoutRecovery", "Check the network, then try again."));
|
|
1922
|
+
const text = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
1923
|
+
const rule = RULES.find((candidate) => candidate.phrases.some((phrase) => text.includes(phrase)));
|
|
1924
|
+
if (rule === void 0) return new require_gitDependencies.PoGitExpectedError("git_failed", t("git.failure.failed", "git {operation} failed (exit {code}).", {
|
|
1925
|
+
operation,
|
|
1926
|
+
code: String(result.code)
|
|
1927
|
+
}), false, t("git.failure.failedRecovery", "Run the same command in a terminal in this checkout to see what git says."));
|
|
1928
|
+
const recovery = rule.code === "auth_failed" && mismatch !== void 0 ? `${mismatch} ${rule.recovery(t)}` : rule.recovery(t);
|
|
1929
|
+
return new require_gitDependencies.PoGitExpectedError(rule.code, rule.message(t), rule.retryable, recovery);
|
|
1289
1930
|
}
|
|
1290
1931
|
//#endregion
|
|
1291
|
-
//#region src/
|
|
1932
|
+
//#region src/services/gitSync/index.ts
|
|
1292
1933
|
/**
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1295
|
-
* Hub-scoped because worktrees are a property of a repository, not of one
|
|
1296
|
-
* session: the panel lists and creates them whether or not the session that
|
|
1297
|
-
* made them is focused, and a session-scoped API would disappear with it.
|
|
1934
|
+
* Manual pull, push and rebase for a session's checkout.
|
|
1298
1935
|
*
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1301
|
-
*
|
|
1302
|
-
|
|
1303
|
-
|
|
1936
|
+
* DESIGN PATTERNS:
|
|
1937
|
+
* - The workspace's auth goes into the environment of the one fetch or push
|
|
1938
|
+
* that needs it, built fresh per call. Rebase itself runs locally and never
|
|
1939
|
+
* sees a credential.
|
|
1940
|
+
* - Fetch and rebase are separate commands, so a hung network can never leave a
|
|
1941
|
+
* rebase half applied.
|
|
1942
|
+
* - A conflicted rebase is not an error. It is left paused for the reader to
|
|
1943
|
+
* hand to the agent or abort, and git's own state reports it from then on.
|
|
1944
|
+
* - Pull and rebase refuse uncommitted tracked changes rather than stash them.
|
|
1945
|
+
* Untracked files only block when git says they would be overwritten.
|
|
1946
|
+
* - Push never forces on its own. A rejection comes back as `push_needs_force`,
|
|
1947
|
+
* and only a confirmed retry sends `--force-with-lease --force-if-includes`,
|
|
1948
|
+
* which git refuses if the remote holds commits this branch never integrated.
|
|
1949
|
+
*/
|
|
1950
|
+
const DONE = { outcome: "done" };
|
|
1951
|
+
function expected(code, message, recovery) {
|
|
1952
|
+
return new require_gitDependencies.PoGitExpectedError(code, message, false, recovery);
|
|
1953
|
+
}
|
|
1954
|
+
function createGitSync(options) {
|
|
1955
|
+
const baseEnv = options.baseEnv ?? {};
|
|
1956
|
+
async function readLine(cwd, args) {
|
|
1957
|
+
const result = await require_gitDependencies.runGit(cwd, args, {
|
|
1958
|
+
timeout: require_gitDependencies.READ_TIMEOUT_MS,
|
|
1959
|
+
env: baseEnv
|
|
1960
|
+
});
|
|
1961
|
+
const out = result.stdout.trim();
|
|
1962
|
+
return result.code === 0 && out !== "" ? out : void 0;
|
|
1963
|
+
}
|
|
1964
|
+
async function toplevel(cwd) {
|
|
1965
|
+
const root = await readLine(cwd, ["rev-parse", "--show-toplevel"]);
|
|
1966
|
+
if (root === void 0) throw expected("not_a_repository", "This session is not in a git checkout.", "Open the session in a git repository.");
|
|
1967
|
+
return root;
|
|
1968
|
+
}
|
|
1969
|
+
async function rebasing(root) {
|
|
1970
|
+
for (const name of ["rebase-merge", "rebase-apply"]) {
|
|
1971
|
+
const gitPath = await readLine(root, [
|
|
1972
|
+
"rev-parse",
|
|
1973
|
+
"--git-path",
|
|
1974
|
+
name
|
|
1975
|
+
]);
|
|
1976
|
+
if (gitPath !== void 0 && await node_fs_promises.default.access(node_path.default.resolve(root, gitPath)).then(() => true, () => false)) return true;
|
|
1977
|
+
}
|
|
1978
|
+
return false;
|
|
1979
|
+
}
|
|
1980
|
+
async function conflicts(root) {
|
|
1981
|
+
return (await require_gitDependencies.runGit(root, [
|
|
1982
|
+
"diff",
|
|
1983
|
+
"--name-only",
|
|
1984
|
+
"--diff-filter=U",
|
|
1985
|
+
"-z"
|
|
1986
|
+
], {
|
|
1987
|
+
timeout: require_gitDependencies.READ_TIMEOUT_MS,
|
|
1988
|
+
env: baseEnv
|
|
1989
|
+
})).stdout.split("\0").filter((file) => file !== "");
|
|
1990
|
+
}
|
|
1991
|
+
async function currentBranch(root) {
|
|
1992
|
+
const branch = await readLine(root, [
|
|
1993
|
+
"symbolic-ref",
|
|
1994
|
+
"--quiet",
|
|
1995
|
+
"--short",
|
|
1996
|
+
"HEAD"
|
|
1997
|
+
]);
|
|
1998
|
+
if (branch === void 0) throw expected("detached_head", "HEAD is detached, so there is no branch to sync.", "Check out a branch first.");
|
|
1999
|
+
return branch;
|
|
2000
|
+
}
|
|
2001
|
+
async function guard(root, needsCleanTree) {
|
|
2002
|
+
if (await rebasing(root)) throw expected("rebase_in_progress", "A rebase is paused in this checkout.", "Ask the agent to resolve it, or abort the rebase.");
|
|
2003
|
+
const branch = await currentBranch(root);
|
|
2004
|
+
if (needsCleanTree) {
|
|
2005
|
+
if (await readLine(root, [
|
|
2006
|
+
"status",
|
|
2007
|
+
"--porcelain",
|
|
2008
|
+
"--untracked-files=no"
|
|
2009
|
+
]) !== void 0) throw expected("worktree_dirty", "There are uncommitted changes.", "Commit or stash your changes first.");
|
|
2010
|
+
}
|
|
2011
|
+
return branch;
|
|
2012
|
+
}
|
|
2013
|
+
const baselines = /* @__PURE__ */ new Map();
|
|
2014
|
+
/** One credentialed network command against `remote`, classified on failure. */
|
|
2015
|
+
const network = async (root, context, remote, operation, args, urlArgs = []) => {
|
|
2016
|
+
const url = await readLine(root, [
|
|
2017
|
+
"remote",
|
|
2018
|
+
"get-url",
|
|
2019
|
+
...urlArgs,
|
|
2020
|
+
remote
|
|
2021
|
+
]);
|
|
2022
|
+
if (url === void 0) throw expected("no_remote", `There is no remote named ${remote}.`, "Add the remote in a terminal first.");
|
|
2023
|
+
const prepared = remoteEnv(context.auth, url, baseEnv, options.homeDir);
|
|
2024
|
+
const result = await require_gitDependencies.runGit(root, args, {
|
|
2025
|
+
timeout: require_gitDependencies.NETWORK_TIMEOUT_MS,
|
|
2026
|
+
env: prepared.env,
|
|
2027
|
+
...context.signal ? { signal: context.signal } : {}
|
|
2028
|
+
});
|
|
2029
|
+
if (result.code !== 0) throw classifyGitFailure(operation, result, prepared.mismatch, context.t);
|
|
2030
|
+
};
|
|
2031
|
+
/** Rebases onto `onto`; a stop on conflicts leaves the rebase paused and says so. */
|
|
2032
|
+
const rebaseOnto = async (root, onto, context) => {
|
|
2033
|
+
context.signal?.throwIfAborted();
|
|
2034
|
+
const before = baselines.get(root) ?? await require_gitDependencies.revision(root, "HEAD", {
|
|
2035
|
+
env: baseEnv,
|
|
2036
|
+
...context.signal ? { signal: context.signal } : {}
|
|
2037
|
+
});
|
|
2038
|
+
baselines.set(root, before);
|
|
2039
|
+
const result = await require_gitDependencies.runGit(root, ["rebase", onto], {
|
|
2040
|
+
timeout: require_gitDependencies.REBASE_TIMEOUT_MS,
|
|
2041
|
+
...context.signal ? { signal: context.signal } : {},
|
|
2042
|
+
env: {
|
|
2043
|
+
...baseEnv,
|
|
2044
|
+
GIT_EDITOR: "true",
|
|
2045
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
if (result.code === 0) {
|
|
2049
|
+
if (before !== await require_gitDependencies.revision(root, "HEAD", {
|
|
2050
|
+
env: baseEnv,
|
|
2051
|
+
...context.signal ? { signal: context.signal } : {}
|
|
2052
|
+
})) await options.reapplySparse?.(root, context.signal);
|
|
2053
|
+
baselines.delete(root);
|
|
2054
|
+
return DONE;
|
|
2055
|
+
}
|
|
2056
|
+
if (await rebasing(root)) return {
|
|
2057
|
+
outcome: "paused",
|
|
2058
|
+
conflicts: await conflicts(root)
|
|
2059
|
+
};
|
|
2060
|
+
baselines.delete(root);
|
|
2061
|
+
throw classifyGitFailure("rebase", result, void 0, context.t);
|
|
2062
|
+
};
|
|
2063
|
+
/** The remote a ref like `origin/main` or `refs/remotes/origin/main` belongs to. */
|
|
2064
|
+
const remoteOfRef = async (root, ref) => {
|
|
2065
|
+
const full = await readLine(root, [
|
|
2066
|
+
"rev-parse",
|
|
2067
|
+
"--symbolic-full-name",
|
|
2068
|
+
ref
|
|
2069
|
+
]);
|
|
2070
|
+
if (full === void 0 || !full.startsWith("refs/remotes/")) return void 0;
|
|
2071
|
+
const rest = full.slice(13);
|
|
2072
|
+
const cut = rest.indexOf("/");
|
|
2073
|
+
return cut > 0 ? rest.slice(0, cut) : void 0;
|
|
2074
|
+
};
|
|
2075
|
+
return {
|
|
2076
|
+
async pull(context) {
|
|
2077
|
+
const root = await toplevel(context.cwd);
|
|
2078
|
+
const branch = await guard(root, true);
|
|
2079
|
+
const remote = await readLine(root, ["config", `branch.${branch}.remote`]);
|
|
2080
|
+
const upstream = await readLine(root, [
|
|
2081
|
+
"rev-parse",
|
|
2082
|
+
"--abbrev-ref",
|
|
2083
|
+
"--symbolic-full-name",
|
|
2084
|
+
`${branch}@{upstream}`
|
|
2085
|
+
]);
|
|
2086
|
+
if (remote === void 0 || upstream === void 0) throw expected("no_upstream", `${branch} has no upstream to pull from.`, "Push once to set an upstream.");
|
|
2087
|
+
if (remote !== ".") await network(root, context, remote, "fetch", [
|
|
2088
|
+
"fetch",
|
|
2089
|
+
"--prune",
|
|
2090
|
+
remote
|
|
2091
|
+
]);
|
|
2092
|
+
return rebaseOnto(root, upstream, context);
|
|
2093
|
+
},
|
|
2094
|
+
async push(context, force) {
|
|
2095
|
+
const root = await toplevel(context.cwd);
|
|
2096
|
+
const branch = await guard(root, false);
|
|
2097
|
+
const configuredRemote = await readLine(root, ["config", `branch.${branch}.remote`]);
|
|
2098
|
+
const merge = await readLine(root, ["config", `branch.${branch}.merge`]);
|
|
2099
|
+
let remote = configuredRemote;
|
|
2100
|
+
let target = merge;
|
|
2101
|
+
const args = ["push", "--porcelain"];
|
|
2102
|
+
if (remote === void 0 || target === void 0 || remote === ".") {
|
|
2103
|
+
const remotes = (await readLine(root, ["remote"]) ?? "").split("\n").filter((name) => name !== "");
|
|
2104
|
+
remote = remotes.includes("origin") ? "origin" : remotes.length === 1 ? remotes[0] : void 0;
|
|
2105
|
+
if (remote === void 0) throw expected("no_remote", "There is no remote to push to.", remotes.length === 0 ? "Add a remote in a terminal first." : "Push once from a terminal to choose the remote.");
|
|
2106
|
+
target = `refs/heads/${branch}`;
|
|
2107
|
+
args.push("--set-upstream");
|
|
2108
|
+
}
|
|
2109
|
+
if (force) args.push(`--force-with-lease=${target}`, "--force-if-includes");
|
|
2110
|
+
args.push(remote, `HEAD:${target}`);
|
|
2111
|
+
await network(root, context, remote, "push", args, ["--push"]);
|
|
2112
|
+
return DONE;
|
|
2113
|
+
},
|
|
2114
|
+
async rebase(context) {
|
|
2115
|
+
const root = await toplevel(context.cwd);
|
|
2116
|
+
const base = await resolveBaseRef(root, await guard(root, true), context.recordedBaseRef);
|
|
2117
|
+
if (base === void 0) throw expected("no_base", "No base branch to rebase onto.", "Fetch the remote, or create the worktree from a base.");
|
|
2118
|
+
const remote = await remoteOfRef(root, base);
|
|
2119
|
+
if (remote !== void 0) await network(root, context, remote, "fetch", [
|
|
2120
|
+
"fetch",
|
|
2121
|
+
"--prune",
|
|
2122
|
+
remote
|
|
2123
|
+
]);
|
|
2124
|
+
return rebaseOnto(root, base, context);
|
|
2125
|
+
},
|
|
2126
|
+
async abortRebase(context) {
|
|
2127
|
+
const root = await toplevel(context.cwd);
|
|
2128
|
+
if (!await rebasing(root)) {
|
|
2129
|
+
baselines.delete(root);
|
|
2130
|
+
return DONE;
|
|
2131
|
+
}
|
|
2132
|
+
const result = await require_gitDependencies.runGit(root, ["rebase", "--abort"], {
|
|
2133
|
+
timeout: require_gitDependencies.REBASE_TIMEOUT_MS,
|
|
2134
|
+
env: baseEnv,
|
|
2135
|
+
...context.signal ? { signal: context.signal } : {}
|
|
2136
|
+
});
|
|
2137
|
+
if (result.code !== 0) throw classifyGitFailure("rebase --abort", result, void 0, context.t);
|
|
2138
|
+
baselines.delete(root);
|
|
2139
|
+
return DONE;
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
//#endregion
|
|
2144
|
+
//#region src/services/newSessionRequest/index.ts
|
|
2145
|
+
const MAX_NAME_LENGTH = 120;
|
|
2146
|
+
/** Trimmed text, undefined when absent or blank, false when not text at all. */
|
|
2147
|
+
function optionalText(value) {
|
|
2148
|
+
if (value === void 0) return void 0;
|
|
2149
|
+
if (typeof value !== "string") return false;
|
|
2150
|
+
const trimmed = value.trim();
|
|
2151
|
+
return trimmed === "" ? void 0 : trimmed;
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
* Validates a new-session dialog request for a worktree session. Every ref is
|
|
2155
|
+
* checked here, before it can reach git as a positional argument.
|
|
2156
|
+
*/
|
|
2157
|
+
function newSessionRequest(body) {
|
|
2158
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return { error: "A request body is required." };
|
|
2159
|
+
const record = body;
|
|
2160
|
+
if (Object.hasOwn(record, "profile")) return { error: "Use sparseProfile for a sparse checkout, or selection.profile for a launch profile." };
|
|
2161
|
+
const branch = optionalText(record.branch);
|
|
2162
|
+
if (branch === void 0 || branch === false || !require_gitDependencies.validRefName(branch)) return { error: "A valid branch name is required." };
|
|
2163
|
+
const name = optionalText(record.name);
|
|
2164
|
+
if (name === false || name !== void 0 && name.length > MAX_NAME_LENGTH) return { error: `The session name must be text of up to ${String(MAX_NAME_LENGTH)} characters.` };
|
|
2165
|
+
if (Object.hasOwn(record, "sparseProfile") && !require_gitDependencies.validSparseProfile(record.sparseProfile)) return { error: "A valid sparse profile name is required." };
|
|
2166
|
+
const chosen = record.selection === void 0 ? {} : (0, _agimon_ai_po_core_hubChannel.parseLaunchSelection)(record.selection);
|
|
2167
|
+
if ("error" in chosen) return chosen;
|
|
2168
|
+
const profile = chosen.selection?.profile;
|
|
2169
|
+
const named = {
|
|
2170
|
+
...record.sparseProfile === void 0 ? {} : { sparseProfile: record.sparseProfile },
|
|
2171
|
+
...name === void 0 ? {} : { name },
|
|
2172
|
+
...profile === void 0 ? {} : { selection: { profile } }
|
|
2173
|
+
};
|
|
2174
|
+
if (record.mode === "existing-branch") {
|
|
2175
|
+
const remote = optionalText(record.remote);
|
|
2176
|
+
if (remote === false || remote !== void 0 && !require_gitDependencies.validRefName(remote)) return { error: "That remote name is not valid." };
|
|
2177
|
+
return {
|
|
2178
|
+
mode: "existing-branch",
|
|
2179
|
+
branch,
|
|
2180
|
+
...remote === void 0 ? {} : { remote },
|
|
2181
|
+
...named
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
if (record.mode === "new-branch") {
|
|
2185
|
+
const baseRef = optionalText(record.baseRef);
|
|
2186
|
+
if (baseRef === false || baseRef !== void 0 && !require_gitDependencies.validRefName(baseRef)) return { error: "That base branch is not valid." };
|
|
2187
|
+
return {
|
|
2188
|
+
mode: "new-branch",
|
|
2189
|
+
branch,
|
|
2190
|
+
...baseRef === void 0 ? {} : { baseRef },
|
|
2191
|
+
...named
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
return { error: "The mode must be existing-branch or new-branch." };
|
|
2195
|
+
}
|
|
2196
|
+
//#endregion
|
|
2197
|
+
//#region src/extensions/(backend)/api/git/_lib/route.server.ts
|
|
2198
|
+
/**
|
|
2199
|
+
* The worktree surface the cockpit panel calls.
|
|
2200
|
+
*
|
|
2201
|
+
* Hub-scoped because worktrees are a property of a repository, not of one
|
|
2202
|
+
* session: the panel lists and creates them whether or not the session that
|
|
2203
|
+
* made them is focused, and a session-scoped API would disappear with it.
|
|
2204
|
+
*
|
|
2205
|
+
* The panel names a repository by the hub's opaque id and never by path.
|
|
2206
|
+
* `resolveRepository` turns that into an admitted root, so a browser cannot
|
|
2207
|
+
* point this at a directory the cockpit was never given.
|
|
2208
|
+
*/
|
|
2209
|
+
function badRequest(message) {
|
|
1304
2210
|
return Response.json({ error: message }, { status: 400 });
|
|
1305
2211
|
}
|
|
1306
2212
|
function failed(error) {
|
|
1307
|
-
if (error instanceof
|
|
2213
|
+
if (error instanceof require_gitDependencies.PoGitExpectedError) return Response.json({
|
|
1308
2214
|
error: error.message,
|
|
1309
2215
|
code: error.code
|
|
1310
2216
|
}, { status: error.retryable ? 503 : 409 });
|
|
1311
2217
|
return Response.json({ error: "The worktree operation failed." }, { status: 500 });
|
|
1312
2218
|
}
|
|
1313
|
-
function createGitApi(openDirectory) {
|
|
2219
|
+
function createGitApi(openDirectory, dependencies = {}, translate) {
|
|
1314
2220
|
return {
|
|
1315
2221
|
basePath: "git",
|
|
1316
2222
|
start(context) {
|
|
1317
2223
|
if (context.directEvents === void 0) throw new Error("Git hub API requires the direct event bus.");
|
|
1318
2224
|
const directEvents = context.directEvents;
|
|
1319
2225
|
const publishLifecycle = (sessionId, repositoryRoot) => {
|
|
1320
|
-
directEvents.publish(
|
|
2226
|
+
directEvents.publish(require_gitDependencies.GIT_WORKTREE_LIFECYCLE_EVENT, sessionId, {
|
|
1321
2227
|
version: 1,
|
|
1322
2228
|
repositoryRoot
|
|
1323
2229
|
});
|
|
1324
2230
|
};
|
|
1325
|
-
const git =
|
|
1326
|
-
const operations =
|
|
2231
|
+
const git = require_gitDependencies.createWorktreeGit();
|
|
2232
|
+
const operations = require_gitDependencies.createWorktreeOperations({
|
|
2233
|
+
...dependencies,
|
|
1327
2234
|
git,
|
|
1328
2235
|
sessionService: context.sessionService,
|
|
1329
2236
|
...context.homeDirectory === void 0 ? {} : { homeDir: context.homeDirectory },
|
|
1330
2237
|
...context.environment === void 0 ? {} : { environment: context.environment }
|
|
1331
2238
|
});
|
|
2239
|
+
const sync = createGitSync({
|
|
2240
|
+
homeDir: context.homeDirectory ?? context.environment?.HOME ?? "",
|
|
2241
|
+
baseEnv: context.environment ?? {},
|
|
2242
|
+
async reapplySparse(cwd, signal) {
|
|
2243
|
+
const record = (await require_gitDependencies.createWorktreeRegistry(await require_gitDependencies.registryFile(cwd, context.homeDirectory, context.environment)).list()).find((entry) => entry.path === cwd && entry.sessionId === context.sessionId);
|
|
2244
|
+
if (record?.sparseProfile) await operations.reapply({
|
|
2245
|
+
cwd,
|
|
2246
|
+
sessionId: context.sessionId
|
|
2247
|
+
}, record.id, { signal });
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
const sessionCommand = async (request, url) => {
|
|
2251
|
+
if (!["/session-worktrees", "/sync"].includes(url.pathname)) return void 0;
|
|
2252
|
+
if (context.scope !== "session" || !context.cwd || !context.sessionId) return Response.json({ error: "This route belongs to a session." }, { status: 404 });
|
|
2253
|
+
if (request.method !== "POST") return Response.json({ error: "Use POST." }, { status: 405 });
|
|
2254
|
+
const caller = {
|
|
2255
|
+
cwd: context.cwd,
|
|
2256
|
+
sessionId: context.sessionId
|
|
2257
|
+
};
|
|
2258
|
+
const body = await request.json().catch(() => void 0);
|
|
2259
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return badRequest("A command is required.");
|
|
2260
|
+
const command = body;
|
|
2261
|
+
if (url.pathname === "/sync") {
|
|
2262
|
+
if (Object.keys(command).some((key) => !["action", "force"].includes(key)) || command.force !== void 0 && typeof command.force !== "boolean") return badRequest("Unknown sync command field.");
|
|
2263
|
+
const recordedBaseRef = (await require_gitDependencies.createWorktreeRegistry(await require_gitDependencies.registryFile(caller.cwd, context.homeDirectory, context.environment)).list()).find((entry) => entry.sessionId === caller.sessionId)?.baseRef;
|
|
2264
|
+
const auth = await createGitAuthStore(context.homeDirectory ?? context.environment?.HOME ?? "", context.environment).read(context.sessionContext?.workspaceRoot ?? caller.cwd);
|
|
2265
|
+
const syncContext = {
|
|
2266
|
+
...caller,
|
|
2267
|
+
auth,
|
|
2268
|
+
recordedBaseRef,
|
|
2269
|
+
signal: request.signal,
|
|
2270
|
+
...translate ? { t: translate } : {}
|
|
2271
|
+
};
|
|
2272
|
+
if (command.action === "pull") return Response.json(await sync.pull(syncContext));
|
|
2273
|
+
if (command.action === "push") return Response.json(await sync.push(syncContext, command.force === true));
|
|
2274
|
+
if (command.action === "rebase") return Response.json(await sync.rebase(syncContext));
|
|
2275
|
+
if (command.action === "abort-rebase") return Response.json(await sync.abortRebase(syncContext));
|
|
2276
|
+
return badRequest("Unknown sync command.");
|
|
2277
|
+
}
|
|
2278
|
+
if (Object.keys(command).some((key) => ![
|
|
2279
|
+
"action",
|
|
2280
|
+
"branch",
|
|
2281
|
+
"baseRef",
|
|
2282
|
+
"sparseProfile",
|
|
2283
|
+
"reservationId",
|
|
2284
|
+
"id",
|
|
2285
|
+
"force",
|
|
2286
|
+
"folders"
|
|
2287
|
+
].includes(key))) return badRequest("Unknown command field.");
|
|
2288
|
+
if (command.reservationId !== void 0 && (typeof command.reservationId !== "string" || !/^[A-Za-z0-9_-]+$/u.test(command.reservationId))) return badRequest("Invalid reservation.");
|
|
2289
|
+
if (command.action === "create") {
|
|
2290
|
+
if (typeof command.branch !== "string") return badRequest("A branch is required.");
|
|
2291
|
+
const result = await operations.spawn(caller, {
|
|
2292
|
+
branch: command.branch,
|
|
2293
|
+
...command.baseRef === void 0 ? {} : { baseRef: command.baseRef },
|
|
2294
|
+
...command.sparseProfile === void 0 ? {} : { sparseProfile: command.sparseProfile },
|
|
2295
|
+
...command.reservationId === void 0 ? {} : { reservationId: command.reservationId }
|
|
2296
|
+
}, { signal: request.signal });
|
|
2297
|
+
return Response.json({ worktree: result });
|
|
2298
|
+
}
|
|
2299
|
+
if (command.action === "close" && typeof command.id === "string") return Response.json({ worktree: await operations.close(caller, command.id, command.force === true) });
|
|
2300
|
+
if (![
|
|
2301
|
+
"profiles",
|
|
2302
|
+
"expand",
|
|
2303
|
+
"reapply"
|
|
2304
|
+
].includes(String(command.action))) return badRequest("Unknown worktree command.");
|
|
2305
|
+
const result = await executeRunWorktreeTool(validateParams(body), operations, caller, { signal: request.signal });
|
|
2306
|
+
return Response.json(result.details);
|
|
2307
|
+
};
|
|
1332
2308
|
/**
|
|
1333
2309
|
* The new-session dialog's routes: the workspace's branches, and a top-level
|
|
1334
2310
|
* worktree session on one. Workspace-mounted only, and always rooted at the
|
|
@@ -1350,7 +2326,8 @@ function createGitApi(openDirectory) {
|
|
|
1350
2326
|
remote: []
|
|
1351
2327
|
} : {
|
|
1352
2328
|
repository: true,
|
|
1353
|
-
...await git.listBranches(repositoryRoot)
|
|
2329
|
+
...await git.listBranches(repositoryRoot),
|
|
2330
|
+
...await operations.profiles({ cwd: repositoryRoot }, url.searchParams.get("baseRef") ?? void 0, { signal: request.signal })
|
|
1354
2331
|
};
|
|
1355
2332
|
return Response.json(branches);
|
|
1356
2333
|
}
|
|
@@ -1358,7 +2335,7 @@ function createGitApi(openDirectory) {
|
|
|
1358
2335
|
if (isOpen && (0, _agimon_ai_po_core_packageApi.poApiCallerFrom)(request.headers)?.locality !== "local") return Response.json({ error: "Opening Finder is only available on the host." }, { status: 403 });
|
|
1359
2336
|
const body = await request.json().catch(() => void 0);
|
|
1360
2337
|
const branch = typeof body === "object" && body !== null ? body.branch : void 0;
|
|
1361
|
-
if (typeof branch !== "string" || !
|
|
2338
|
+
if (typeof branch !== "string" || !require_gitDependencies.validRefName(branch)) return badRequest("A valid branch name is required.");
|
|
1362
2339
|
const repositoryRoot = await git.repositoryRoot(workspaceRoot);
|
|
1363
2340
|
if (repositoryRoot === void 0) return badRequest("This workspace is not a git checkout.");
|
|
1364
2341
|
const branches = await git.listBranches(repositoryRoot);
|
|
@@ -1385,12 +2362,13 @@ function createGitApi(openDirectory) {
|
|
|
1385
2362
|
if ("error" in parsed) return badRequest(parsed.error);
|
|
1386
2363
|
const record = await operations.spawn({ cwd: workspaceRoot }, {
|
|
1387
2364
|
branch: parsed.branch,
|
|
2365
|
+
...parsed.sparseProfile === void 0 ? {} : { sparseProfile: parsed.sparseProfile },
|
|
1388
2366
|
checkout: parsed.mode === "existing-branch" ? "existing" : "new",
|
|
1389
2367
|
...parsed.mode === "existing-branch" && parsed.remote !== void 0 ? { remote: parsed.remote } : {},
|
|
1390
2368
|
...parsed.mode === "new-branch" && parsed.baseRef !== void 0 ? { baseRef: parsed.baseRef } : {},
|
|
1391
2369
|
...parsed.name === void 0 ? {} : { name: parsed.name },
|
|
1392
2370
|
...parsed.selection === void 0 ? {} : { selection: parsed.selection }
|
|
1393
|
-
});
|
|
2371
|
+
}, { signal: request.signal });
|
|
1394
2372
|
publishLifecycle(record.sessionId, record.repositoryRoot);
|
|
1395
2373
|
const created = {
|
|
1396
2374
|
sessionId: record.sessionId,
|
|
@@ -1426,7 +2404,7 @@ function createGitApi(openDirectory) {
|
|
|
1426
2404
|
try {
|
|
1427
2405
|
return Response.json(await gitAuth.save(root, await request.json().catch(() => void 0)));
|
|
1428
2406
|
} catch (error) {
|
|
1429
|
-
if (error instanceof
|
|
2407
|
+
if (error instanceof require_gitDependencies.PoGitExpectedError && error.code === "invalid_request") {
|
|
1430
2408
|
const text = error.message.replace(/^\[[a-z_]+\] /u, "").replace("\nRecovery: ", " ");
|
|
1431
2409
|
return Response.json({
|
|
1432
2410
|
error: text,
|
|
@@ -1449,7 +2427,7 @@ function createGitApi(openDirectory) {
|
|
|
1449
2427
|
if (homeDir === void 0) throw new Error("Git review requires the admitted host home directory.");
|
|
1450
2428
|
let recordedBaseRef;
|
|
1451
2429
|
try {
|
|
1452
|
-
recordedBaseRef = (await
|
|
2430
|
+
recordedBaseRef = (await require_gitDependencies.createWorktreeRegistry(await require_gitDependencies.registryFile(cwd, homeDir, context.environment)).list()).find((record) => record.sessionId === context.sessionId)?.baseRef;
|
|
1453
2431
|
} catch {
|
|
1454
2432
|
recordedBaseRef = void 0;
|
|
1455
2433
|
}
|
|
@@ -1472,7 +2450,7 @@ function createGitApi(openDirectory) {
|
|
|
1472
2450
|
async fetch(request) {
|
|
1473
2451
|
const url = new URL(request.url);
|
|
1474
2452
|
try {
|
|
1475
|
-
const answered = await newSession(request, url) ?? await auth(request, url) ?? await review(request, url);
|
|
2453
|
+
const answered = await sessionCommand(request, url) ?? await newSession(request, url) ?? await auth(request, url) ?? await review(request, url);
|
|
1476
2454
|
if (answered !== void 0) return answered;
|
|
1477
2455
|
} catch (error) {
|
|
1478
2456
|
context.onNotice(`git request failed: ${error.name}`);
|
|
@@ -1492,6 +2470,7 @@ function createGitApi(openDirectory) {
|
|
|
1492
2470
|
if (typeof body.branch !== "string" || body.branch.trim() === "") return badRequest("A branch is required.");
|
|
1493
2471
|
const record = await operations.spawn(callerContext, {
|
|
1494
2472
|
branch: body.branch,
|
|
2473
|
+
...body.sparseProfile === void 0 ? {} : { sparseProfile: body.sparseProfile },
|
|
1495
2474
|
...body.baseRef === void 0 ? {} : { baseRef: body.baseRef },
|
|
1496
2475
|
...body.name === void 0 ? {} : { name: body.name }
|
|
1497
2476
|
});
|
|
@@ -1517,7 +2496,8 @@ function createGitApi(openDirectory) {
|
|
|
1517
2496
|
}
|
|
1518
2497
|
//#endregion
|
|
1519
2498
|
//#region src/extensions/(backend)/api/git/route.server.ts
|
|
1520
|
-
var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)((
|
|
2499
|
+
var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)((plugin) => {
|
|
2500
|
+
const { context, host, signal } = plugin;
|
|
1521
2501
|
let openDirectory;
|
|
1522
2502
|
context.inject([_agimon_ai_po_core_platform.PO_SHELL_SERVICE], (child) => {
|
|
1523
2503
|
const shell = (0, _agimon_ai_po_core_platform.requirePoShell)(child);
|
|
@@ -1541,285 +2521,9 @@ var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)(({
|
|
|
1541
2521
|
return createGitApi(async (path) => {
|
|
1542
2522
|
if (openDirectory === void 0) throw new Error("The host shell is unavailable.");
|
|
1543
2523
|
await openDirectory(path);
|
|
1544
|
-
});
|
|
2524
|
+
}, require_gitDependencies.createGitOperationDependencies(plugin), (key, fallback, vars) => (0, _agimon_ai_po_core_locale.readPoLang)(context)?.t((0, _agimon_ai_po_core_locale.readPoPersonLocale)(context)?.read() ?? (0, _agimon_ai_po_core_locale.canonicalLocale)(host.context.environment?.PO_LANG), key, fallback, vars) ?? (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars));
|
|
1545
2525
|
});
|
|
1546
2526
|
//#endregion
|
|
1547
|
-
//#region src/services/gitFailure/index.ts
|
|
1548
|
-
const RULES = [
|
|
1549
|
-
{
|
|
1550
|
-
code: "host_key_changed",
|
|
1551
|
-
phrases: ["remote host identification has changed"],
|
|
1552
|
-
message: "The remote's SSH host key changed since this machine last saw it.",
|
|
1553
|
-
recovery: "Check with the host that the change is expected, then update ~/.ssh/known_hosts from a terminal.",
|
|
1554
|
-
retryable: false
|
|
1555
|
-
},
|
|
1556
|
-
{
|
|
1557
|
-
code: "host_key_unknown",
|
|
1558
|
-
phrases: [
|
|
1559
|
-
"host key verification failed",
|
|
1560
|
-
"no ed25519 host key is known",
|
|
1561
|
-
"no rsa host key is known"
|
|
1562
|
-
],
|
|
1563
|
-
message: "This machine does not trust the remote's SSH host key yet.",
|
|
1564
|
-
recovery: "Run `ssh -T git@<host>` once in a terminal and accept the key, then try again.",
|
|
1565
|
-
retryable: false
|
|
1566
|
-
},
|
|
1567
|
-
{
|
|
1568
|
-
code: "auth_failed",
|
|
1569
|
-
phrases: [
|
|
1570
|
-
"authentication failed",
|
|
1571
|
-
"could not read username",
|
|
1572
|
-
"could not read password",
|
|
1573
|
-
"permission denied (publickey",
|
|
1574
|
-
"returned error: 401",
|
|
1575
|
-
"returned error: 403",
|
|
1576
|
-
"terminal prompts disabled",
|
|
1577
|
-
"load key",
|
|
1578
|
-
"unprotected private key",
|
|
1579
|
-
"invalid format"
|
|
1580
|
-
],
|
|
1581
|
-
message: "The remote refused the credentials.",
|
|
1582
|
-
recovery: `Check this workspace's git remote auth. ${SETTINGS_HINT}`,
|
|
1583
|
-
retryable: false
|
|
1584
|
-
},
|
|
1585
|
-
{
|
|
1586
|
-
code: "repository_not_found",
|
|
1587
|
-
phrases: ["repository not found", "does not appear to be a git repository"],
|
|
1588
|
-
message: "The remote repository was not found, or these credentials cannot see it.",
|
|
1589
|
-
recovery: `Check the remote URL and that the credentials have access. ${SETTINGS_HINT}`,
|
|
1590
|
-
retryable: false
|
|
1591
|
-
},
|
|
1592
|
-
{
|
|
1593
|
-
code: "remote_unreachable",
|
|
1594
|
-
phrases: [
|
|
1595
|
-
"could not resolve host",
|
|
1596
|
-
"connection refused",
|
|
1597
|
-
"connection timed out",
|
|
1598
|
-
"operation timed out",
|
|
1599
|
-
"unable to access",
|
|
1600
|
-
"network is unreachable"
|
|
1601
|
-
],
|
|
1602
|
-
message: "The remote could not be reached.",
|
|
1603
|
-
recovery: "Check the network and the remote URL, then try again.",
|
|
1604
|
-
retryable: true
|
|
1605
|
-
},
|
|
1606
|
-
{
|
|
1607
|
-
code: "push_lease_rejected",
|
|
1608
|
-
phrases: ["(stale info)"],
|
|
1609
|
-
message: "The remote branch moved since your last fetch, so the force push was refused.",
|
|
1610
|
-
recovery: "Pull to see the new commits, then decide whether to push again.",
|
|
1611
|
-
retryable: false
|
|
1612
|
-
},
|
|
1613
|
-
{
|
|
1614
|
-
code: "push_needs_force",
|
|
1615
|
-
phrases: ["(non-fast-forward)", "(fetch first)"],
|
|
1616
|
-
message: "The remote branch has commits yours replaced, usually after a rebase.",
|
|
1617
|
-
recovery: "Confirm a force push with lease, or pull first to keep the remote commits.",
|
|
1618
|
-
retryable: false
|
|
1619
|
-
},
|
|
1620
|
-
{
|
|
1621
|
-
code: "worktree_dirty",
|
|
1622
|
-
phrases: [
|
|
1623
|
-
"unstaged changes",
|
|
1624
|
-
"uncommitted changes",
|
|
1625
|
-
"would be overwritten",
|
|
1626
|
-
"your index contains uncommitted changes"
|
|
1627
|
-
],
|
|
1628
|
-
message: "There are uncommitted changes in the way.",
|
|
1629
|
-
recovery: "Commit or stash your changes first.",
|
|
1630
|
-
retryable: false
|
|
1631
|
-
}
|
|
1632
|
-
];
|
|
1633
|
-
function classifyGitFailure(operation, result, mismatch) {
|
|
1634
|
-
if (result.timedOut) return new require_worktreeOperations.PoGitExpectedError("git_timeout", `git ${operation} took too long and was stopped.`, true, "Check the network, then try again.");
|
|
1635
|
-
const text = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
1636
|
-
const rule = RULES.find((candidate) => candidate.phrases.some((phrase) => text.includes(phrase)));
|
|
1637
|
-
if (rule === void 0) return new require_worktreeOperations.PoGitExpectedError("git_failed", `git ${operation} failed (exit ${String(result.code)}).`, false, "Run the same command in a terminal in this checkout to see what git says.");
|
|
1638
|
-
const recovery = rule.code === "auth_failed" && mismatch !== void 0 ? `${mismatch} ${rule.recovery}` : rule.recovery;
|
|
1639
|
-
return new require_worktreeOperations.PoGitExpectedError(rule.code, rule.message, rule.retryable, recovery);
|
|
1640
|
-
}
|
|
1641
|
-
//#endregion
|
|
1642
|
-
//#region src/services/gitSync/index.ts
|
|
1643
|
-
/**
|
|
1644
|
-
* Manual pull, push and rebase for a session's checkout.
|
|
1645
|
-
*
|
|
1646
|
-
* DESIGN PATTERNS:
|
|
1647
|
-
* - The workspace's auth goes into the environment of the one fetch or push
|
|
1648
|
-
* that needs it, built fresh per call. Rebase itself runs locally and never
|
|
1649
|
-
* sees a credential.
|
|
1650
|
-
* - Fetch and rebase are separate commands, so a hung network can never leave a
|
|
1651
|
-
* rebase half applied.
|
|
1652
|
-
* - A conflicted rebase is not an error. It is left paused for the reader to
|
|
1653
|
-
* hand to the agent or abort, and git's own state reports it from then on.
|
|
1654
|
-
* - Pull and rebase refuse uncommitted tracked changes rather than stash them.
|
|
1655
|
-
* Untracked files only block when git says they would be overwritten.
|
|
1656
|
-
* - Push never forces on its own. A rejection comes back as `push_needs_force`,
|
|
1657
|
-
* and only a confirmed retry sends `--force-with-lease --force-if-includes`,
|
|
1658
|
-
* which git refuses if the remote holds commits this branch never integrated.
|
|
1659
|
-
*/
|
|
1660
|
-
const DONE = { outcome: "done" };
|
|
1661
|
-
function expected(code, message, recovery) {
|
|
1662
|
-
return new require_worktreeOperations.PoGitExpectedError(code, message, false, recovery);
|
|
1663
|
-
}
|
|
1664
|
-
async function readLine(cwd, args) {
|
|
1665
|
-
const result = await require_worktreeOperations.runGit(cwd, args, { timeout: require_worktreeOperations.READ_TIMEOUT_MS });
|
|
1666
|
-
const out = result.stdout.trim();
|
|
1667
|
-
return result.code === 0 && out !== "" ? out : void 0;
|
|
1668
|
-
}
|
|
1669
|
-
async function toplevel(cwd) {
|
|
1670
|
-
const root = await readLine(cwd, ["rev-parse", "--show-toplevel"]);
|
|
1671
|
-
if (root === void 0) throw expected("not_a_repository", "This session is not in a git checkout.", "Open the session in a git repository.");
|
|
1672
|
-
return root;
|
|
1673
|
-
}
|
|
1674
|
-
async function rebasing(root) {
|
|
1675
|
-
for (const name of ["rebase-merge", "rebase-apply"]) {
|
|
1676
|
-
const gitPath = await readLine(root, [
|
|
1677
|
-
"rev-parse",
|
|
1678
|
-
"--git-path",
|
|
1679
|
-
name
|
|
1680
|
-
]);
|
|
1681
|
-
if (gitPath !== void 0 && await node_fs_promises.default.access(node_path.default.resolve(root, gitPath)).then(() => true, () => false)) return true;
|
|
1682
|
-
}
|
|
1683
|
-
return false;
|
|
1684
|
-
}
|
|
1685
|
-
async function conflicts(root) {
|
|
1686
|
-
return (await require_worktreeOperations.runGit(root, [
|
|
1687
|
-
"diff",
|
|
1688
|
-
"--name-only",
|
|
1689
|
-
"--diff-filter=U",
|
|
1690
|
-
"-z"
|
|
1691
|
-
], { timeout: require_worktreeOperations.READ_TIMEOUT_MS })).stdout.split("\0").filter((file) => file !== "");
|
|
1692
|
-
}
|
|
1693
|
-
async function currentBranch(root) {
|
|
1694
|
-
const branch = await readLine(root, [
|
|
1695
|
-
"symbolic-ref",
|
|
1696
|
-
"--quiet",
|
|
1697
|
-
"--short",
|
|
1698
|
-
"HEAD"
|
|
1699
|
-
]);
|
|
1700
|
-
if (branch === void 0) throw expected("detached_head", "HEAD is detached, so there is no branch to sync.", "Check out a branch first.");
|
|
1701
|
-
return branch;
|
|
1702
|
-
}
|
|
1703
|
-
async function guard(root, needsCleanTree) {
|
|
1704
|
-
if (await rebasing(root)) throw expected("rebase_in_progress", "A rebase is paused in this checkout.", "Ask the agent to resolve it, or abort the rebase.");
|
|
1705
|
-
const branch = await currentBranch(root);
|
|
1706
|
-
if (needsCleanTree) {
|
|
1707
|
-
if (await readLine(root, [
|
|
1708
|
-
"status",
|
|
1709
|
-
"--porcelain",
|
|
1710
|
-
"--untracked-files=no"
|
|
1711
|
-
]) !== void 0) throw expected("worktree_dirty", "There are uncommitted changes.", "Commit or stash your changes first.");
|
|
1712
|
-
}
|
|
1713
|
-
return branch;
|
|
1714
|
-
}
|
|
1715
|
-
function createGitSync(options) {
|
|
1716
|
-
const baseEnv = options.baseEnv ?? process.env;
|
|
1717
|
-
/** One credentialed network command against `remote`, classified on failure. */
|
|
1718
|
-
const network = async (root, context, remote, operation, args, urlArgs = []) => {
|
|
1719
|
-
const url = await readLine(root, [
|
|
1720
|
-
"remote",
|
|
1721
|
-
"get-url",
|
|
1722
|
-
...urlArgs,
|
|
1723
|
-
remote
|
|
1724
|
-
]);
|
|
1725
|
-
if (url === void 0) throw expected("no_remote", `There is no remote named ${remote}.`, "Add the remote in a terminal first.");
|
|
1726
|
-
const prepared = remoteEnv(context.auth, url, baseEnv, options.homeDir);
|
|
1727
|
-
const result = await require_worktreeOperations.runGit(root, args, {
|
|
1728
|
-
timeout: require_worktreeOperations.NETWORK_TIMEOUT_MS,
|
|
1729
|
-
env: prepared.env
|
|
1730
|
-
});
|
|
1731
|
-
if (result.code !== 0) throw classifyGitFailure(operation, result, prepared.mismatch);
|
|
1732
|
-
};
|
|
1733
|
-
/** Rebases onto `onto`; a stop on conflicts leaves the rebase paused and says so. */
|
|
1734
|
-
const rebaseOnto = async (root, onto) => {
|
|
1735
|
-
const result = await require_worktreeOperations.runGit(root, ["rebase", onto], {
|
|
1736
|
-
timeout: require_worktreeOperations.REBASE_TIMEOUT_MS,
|
|
1737
|
-
env: {
|
|
1738
|
-
...baseEnv,
|
|
1739
|
-
GIT_EDITOR: "true",
|
|
1740
|
-
GIT_TERMINAL_PROMPT: "0"
|
|
1741
|
-
}
|
|
1742
|
-
});
|
|
1743
|
-
if (result.code === 0) return DONE;
|
|
1744
|
-
if (await rebasing(root)) return {
|
|
1745
|
-
outcome: "paused",
|
|
1746
|
-
conflicts: await conflicts(root)
|
|
1747
|
-
};
|
|
1748
|
-
throw classifyGitFailure("rebase", result);
|
|
1749
|
-
};
|
|
1750
|
-
/** The remote a ref like `origin/main` or `refs/remotes/origin/main` belongs to. */
|
|
1751
|
-
const remoteOfRef = async (root, ref) => {
|
|
1752
|
-
const full = await readLine(root, [
|
|
1753
|
-
"rev-parse",
|
|
1754
|
-
"--symbolic-full-name",
|
|
1755
|
-
ref
|
|
1756
|
-
]);
|
|
1757
|
-
if (full === void 0 || !full.startsWith("refs/remotes/")) return void 0;
|
|
1758
|
-
const rest = full.slice(13);
|
|
1759
|
-
const cut = rest.indexOf("/");
|
|
1760
|
-
return cut > 0 ? rest.slice(0, cut) : void 0;
|
|
1761
|
-
};
|
|
1762
|
-
return {
|
|
1763
|
-
async pull(context) {
|
|
1764
|
-
const root = await toplevel(context.cwd);
|
|
1765
|
-
const branch = await guard(root, true);
|
|
1766
|
-
const remote = await readLine(root, ["config", `branch.${branch}.remote`]);
|
|
1767
|
-
const upstream = await readLine(root, [
|
|
1768
|
-
"rev-parse",
|
|
1769
|
-
"--abbrev-ref",
|
|
1770
|
-
"--symbolic-full-name",
|
|
1771
|
-
`${branch}@{upstream}`
|
|
1772
|
-
]);
|
|
1773
|
-
if (remote === void 0 || upstream === void 0) throw expected("no_upstream", `${branch} has no upstream to pull from.`, "Push once to set an upstream.");
|
|
1774
|
-
if (remote !== ".") await network(root, context, remote, "fetch", [
|
|
1775
|
-
"fetch",
|
|
1776
|
-
"--prune",
|
|
1777
|
-
remote
|
|
1778
|
-
]);
|
|
1779
|
-
return rebaseOnto(root, upstream);
|
|
1780
|
-
},
|
|
1781
|
-
async push(context, force) {
|
|
1782
|
-
const root = await toplevel(context.cwd);
|
|
1783
|
-
const branch = await guard(root, false);
|
|
1784
|
-
const configuredRemote = await readLine(root, ["config", `branch.${branch}.remote`]);
|
|
1785
|
-
const merge = await readLine(root, ["config", `branch.${branch}.merge`]);
|
|
1786
|
-
let remote = configuredRemote;
|
|
1787
|
-
let target = merge;
|
|
1788
|
-
const args = ["push", "--porcelain"];
|
|
1789
|
-
if (remote === void 0 || target === void 0 || remote === ".") {
|
|
1790
|
-
const remotes = (await readLine(root, ["remote"]) ?? "").split("\n").filter((name) => name !== "");
|
|
1791
|
-
remote = remotes.includes("origin") ? "origin" : remotes.length === 1 ? remotes[0] : void 0;
|
|
1792
|
-
if (remote === void 0) throw expected("no_remote", "There is no remote to push to.", remotes.length === 0 ? "Add a remote in a terminal first." : "Push once from a terminal to choose the remote.");
|
|
1793
|
-
target = `refs/heads/${branch}`;
|
|
1794
|
-
args.push("--set-upstream");
|
|
1795
|
-
}
|
|
1796
|
-
if (force) args.push(`--force-with-lease=${target}`, "--force-if-includes");
|
|
1797
|
-
args.push(remote, `HEAD:${target}`);
|
|
1798
|
-
await network(root, context, remote, "push", args, ["--push"]);
|
|
1799
|
-
return DONE;
|
|
1800
|
-
},
|
|
1801
|
-
async rebase(context) {
|
|
1802
|
-
const root = await toplevel(context.cwd);
|
|
1803
|
-
const base = await resolveBaseRef(root, await guard(root, true), context.recordedBaseRef);
|
|
1804
|
-
if (base === void 0) throw expected("no_base", "No base branch to rebase onto.", "Fetch the remote, or create the worktree from a base.");
|
|
1805
|
-
const remote = await remoteOfRef(root, base);
|
|
1806
|
-
if (remote !== void 0) await network(root, context, remote, "fetch", [
|
|
1807
|
-
"fetch",
|
|
1808
|
-
"--prune",
|
|
1809
|
-
remote
|
|
1810
|
-
]);
|
|
1811
|
-
return rebaseOnto(root, base);
|
|
1812
|
-
},
|
|
1813
|
-
async abortRebase(context) {
|
|
1814
|
-
const root = await toplevel(context.cwd);
|
|
1815
|
-
if (!await rebasing(root)) return DONE;
|
|
1816
|
-
const result = await require_worktreeOperations.runGit(root, ["rebase", "--abort"], { timeout: require_worktreeOperations.REBASE_TIMEOUT_MS });
|
|
1817
|
-
if (result.code !== 0) throw classifyGitFailure("rebase --abort", result);
|
|
1818
|
-
return DONE;
|
|
1819
|
-
}
|
|
1820
|
-
};
|
|
1821
|
-
}
|
|
1822
|
-
//#endregion
|
|
1823
2527
|
//#region src/types/gitReview.ts
|
|
1824
2528
|
/**
|
|
1825
2529
|
* The cockpit's view of what this session changed against its base: the counts
|
|
@@ -1889,13 +2593,13 @@ const PENDING = {
|
|
|
1889
2593
|
/** The error target a failure maps to: a rejected plain push asks for a confirmed lease force. */
|
|
1890
2594
|
function errorTargetFor$1(command, error) {
|
|
1891
2595
|
if (command.action !== "push") return { action: command.action };
|
|
1892
|
-
return error instanceof
|
|
2596
|
+
return error instanceof require_gitDependencies.PoGitExpectedError && error.code === "push_needs_force" && command.force !== true ? {
|
|
1893
2597
|
action: "push",
|
|
1894
2598
|
forceRequired: true
|
|
1895
2599
|
} : { action: "push" };
|
|
1896
2600
|
}
|
|
1897
2601
|
function failureText$1(error) {
|
|
1898
|
-
if (error instanceof
|
|
2602
|
+
if (error instanceof require_gitDependencies.PoGitExpectedError) return error.message.replace(/^\[[a-z_]+\] /u, "").replace("\nRecovery: ", " ");
|
|
1899
2603
|
return "The git command failed.";
|
|
1900
2604
|
}
|
|
1901
2605
|
function createGitChangesChannel(options = {}) {
|
|
@@ -1918,7 +2622,7 @@ function createGitChangesChannel(options = {}) {
|
|
|
1918
2622
|
/** The base the session's own worktree was created from, when it has one. */
|
|
1919
2623
|
const recordedBaseRef = async (scope) => {
|
|
1920
2624
|
try {
|
|
1921
|
-
return (await
|
|
2625
|
+
return (await require_gitDependencies.createWorktreeRegistry(await require_gitDependencies.registryFile(scope.cwd, homeDir, options.environment)).list()).find((record) => record.sessionId === scope.sessionId)?.baseRef;
|
|
1922
2626
|
} catch {
|
|
1923
2627
|
return;
|
|
1924
2628
|
}
|
|
@@ -1971,17 +2675,30 @@ function createGitChangesChannel(options = {}) {
|
|
|
1971
2675
|
delayed.set(sessionId, timer);
|
|
1972
2676
|
};
|
|
1973
2677
|
const run = async (scope, command) => {
|
|
2678
|
+
if (options.scopedCommands) {
|
|
2679
|
+
const response = await host.requestSessionApi(scope, {
|
|
2680
|
+
basePath: "git",
|
|
2681
|
+
path: "/sync",
|
|
2682
|
+
method: "POST",
|
|
2683
|
+
body: JSON.stringify(command)
|
|
2684
|
+
});
|
|
2685
|
+
const result = await response.json();
|
|
2686
|
+
if (!response.ok) throw new require_gitDependencies.PoGitExpectedError(result.code ?? "git_failed", result.error ?? "The git command failed.", false, "Inspect the checkout before retrying.");
|
|
2687
|
+
return result;
|
|
2688
|
+
}
|
|
1974
2689
|
const workspaceRoot = scope.sessionContext?.workspaceRoot ?? scope.cwd;
|
|
1975
2690
|
const base = await recordedBaseRef(scope);
|
|
1976
2691
|
const context = {
|
|
1977
2692
|
cwd: scope.cwd,
|
|
2693
|
+
...options.t ? { t: (key, fallback, vars) => options.t(scope, key, fallback, vars) } : {},
|
|
1978
2694
|
auth: await auth.read(workspaceRoot),
|
|
1979
2695
|
...base === void 0 ? {} : { recordedBaseRef: base }
|
|
1980
2696
|
};
|
|
1981
|
-
|
|
1982
|
-
if (command.action === "
|
|
1983
|
-
if (command.action === "
|
|
1984
|
-
return
|
|
2697
|
+
const sessionSync = sync;
|
|
2698
|
+
if (command.action === "pull") return sessionSync.pull(context);
|
|
2699
|
+
if (command.action === "push") return sessionSync.push(context, command.force === true);
|
|
2700
|
+
if (command.action === "rebase") return sessionSync.rebase(context);
|
|
2701
|
+
return sessionSync.abortRebase(context);
|
|
1985
2702
|
};
|
|
1986
2703
|
const source = {
|
|
1987
2704
|
payloadFor(scope) {
|
|
@@ -1991,8 +2708,8 @@ function createGitChangesChannel(options = {}) {
|
|
|
1991
2708
|
sessionAdded(scope) {
|
|
1992
2709
|
scopes.set(scope.sessionId, scope);
|
|
1993
2710
|
refresh(scope.sessionId);
|
|
1994
|
-
const unsubscribe = host.directEvents.subscribe(
|
|
1995
|
-
if (
|
|
2711
|
+
const unsubscribe = host.directEvents.subscribe(require_gitDependencies.GIT_SESSION_CHANGED_EVENT, scope.sessionId, (payload) => {
|
|
2712
|
+
if (require_gitDependencies.isSessionChangedEvent(payload)) refreshSoon(scope.sessionId);
|
|
1996
2713
|
});
|
|
1997
2714
|
subscriptions.set(scope.sessionId, unsubscribe);
|
|
1998
2715
|
},
|
|
@@ -2028,7 +2745,7 @@ function createGitChangesChannel(options = {}) {
|
|
|
2028
2745
|
errorTarget: void 0
|
|
2029
2746
|
});
|
|
2030
2747
|
run(scope, command).then(() => update(scope.sessionId, { pending: void 0 })).catch((error) => {
|
|
2031
|
-
host.onNotice(`git ${command.action} failed for ${scope.sessionId} (${error instanceof
|
|
2748
|
+
host.onNotice(`git ${command.action} failed for ${scope.sessionId} (${error instanceof require_gitDependencies.PoGitExpectedError ? error.code : "unexpected"})`);
|
|
2032
2749
|
update(scope.sessionId, {
|
|
2033
2750
|
pending: void 0,
|
|
2034
2751
|
error: failureText$1(error),
|
|
@@ -2048,7 +2765,12 @@ function createGitChangesChannel(options = {}) {
|
|
|
2048
2765
|
}
|
|
2049
2766
|
//#endregion
|
|
2050
2767
|
//#region src/extensions/(backend)/channel/git-changes.server.ts
|
|
2051
|
-
var git_changes_server_default = (0, _agimon_ai_po_core_extensionFile.defineChannel)(createGitChangesChannel
|
|
2768
|
+
var git_changes_server_default = (0, _agimon_ai_po_core_extensionFile.defineChannel)(({ context, host }) => createGitChangesChannel({
|
|
2769
|
+
homeDir: host.context.homeDirectory,
|
|
2770
|
+
environment: host.context.environment,
|
|
2771
|
+
scopedCommands: true,
|
|
2772
|
+
t: (scope, key, fallback, vars) => (0, _agimon_ai_po_core_locale.readPoLang)(context)?.t((0, _agimon_ai_po_core_locale.readPoPersonLocale)(context)?.read() ?? (0, _agimon_ai_po_core_locale.canonicalLocale)(scope.environment?.PO_LANG), key, fallback, vars) ?? (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars)
|
|
2773
|
+
}), { context: true });
|
|
2052
2774
|
//#endregion
|
|
2053
2775
|
//#region src/types/webWorktrees.ts
|
|
2054
2776
|
/**
|
|
@@ -2079,7 +2801,7 @@ function payloadOf(state) {
|
|
|
2079
2801
|
/** Worktrees visible to this session, using the hub's live session table for ownership. */
|
|
2080
2802
|
async function viewsFor(scope, deps) {
|
|
2081
2803
|
try {
|
|
2082
|
-
return (await
|
|
2804
|
+
return (await require_gitDependencies.createWorktreeRegistry(await require_gitDependencies.registryFile(scope.cwd, deps.homeDir, deps.environment)).list()).flatMap((record) => {
|
|
2083
2805
|
if (record.parentSessionId === void 0 && record.sessionId !== scope.sessionId) return [];
|
|
2084
2806
|
const owned = record.parentSessionId === void 0 || record.parentSessionId === scope.sessionId;
|
|
2085
2807
|
const unowned = !owned && !deps.sessionService.isLive(record.parentSessionId);
|
|
@@ -2109,7 +2831,7 @@ function errorTargetFor(command, error) {
|
|
|
2109
2831
|
action: "close",
|
|
2110
2832
|
id: command.id
|
|
2111
2833
|
};
|
|
2112
|
-
return error instanceof
|
|
2834
|
+
return error instanceof require_gitDependencies.PoGitExpectedError && error.code === "rift_missing" ? {
|
|
2113
2835
|
action: "create",
|
|
2114
2836
|
riftMissing: true
|
|
2115
2837
|
} : { action: "create" };
|
|
@@ -2121,7 +2843,9 @@ function parseCommand(payload) {
|
|
|
2121
2843
|
if (value.action === "create") {
|
|
2122
2844
|
if (typeof value.branch !== "string" || value.branch.trim() === "") return void 0;
|
|
2123
2845
|
if (value.reservationId !== void 0 && (typeof value.reservationId !== "string" || !/^[A-Za-z0-9_-]+$/u.test(value.reservationId))) return void 0;
|
|
2846
|
+
if (value.sparseProfile !== void 0 && (typeof value.sparseProfile !== "string" || value.sparseProfile.trim() === "")) return void 0;
|
|
2124
2847
|
return {
|
|
2848
|
+
...typeof value.sparseProfile === "string" ? { sparseProfile: value.sparseProfile } : {},
|
|
2125
2849
|
action: "create",
|
|
2126
2850
|
branch: value.branch.trim(),
|
|
2127
2851
|
...typeof value.baseRef === "string" && value.baseRef.trim() !== "" ? { baseRef: value.baseRef.trim() } : {},
|
|
@@ -2146,7 +2870,7 @@ function parseCommand(payload) {
|
|
|
2146
2870
|
* summarised, never echoed: a git error can carry a remote URL with a token in it.
|
|
2147
2871
|
*/
|
|
2148
2872
|
function failureText(error) {
|
|
2149
|
-
if (!(error instanceof
|
|
2873
|
+
if (!(error instanceof require_gitDependencies.PoGitExpectedError)) return "The worktree operation failed.";
|
|
2150
2874
|
if (error.code === "worktree_dirty") return "The worktree has uncommitted changes.";
|
|
2151
2875
|
return error.message.replace(/^\[[a-z_]+\] /u, "").split("\nRecovery:")[0] ?? error.message;
|
|
2152
2876
|
}
|
|
@@ -2157,16 +2881,16 @@ function createWorktreesChannel(options = {}) {
|
|
|
2157
2881
|
frameType: GIT_WORKTREES_TYPE,
|
|
2158
2882
|
start(host) {
|
|
2159
2883
|
const sessionService = host.sessionService;
|
|
2160
|
-
if (sessionService === void 0) throw new
|
|
2161
|
-
const worktrees = options.operations ??
|
|
2162
|
-
git:
|
|
2884
|
+
if (sessionService === void 0) throw new require_gitDependencies.HubUnavailableError("The cockpit session service is unavailable. Start the cockpit and try again.");
|
|
2885
|
+
const worktrees = options.operations ?? require_gitDependencies.createWorktreeOperations({
|
|
2886
|
+
git: require_gitDependencies.createWorktreeGit(),
|
|
2163
2887
|
sessionService,
|
|
2164
2888
|
...options.homeDir === void 0 ? {} : { homeDir: options.homeDir },
|
|
2165
2889
|
...options.environment === void 0 ? {} : { environment: options.environment }
|
|
2166
2890
|
});
|
|
2167
2891
|
/** Announces a successful mutation to this session's lifecycle subscribers. */
|
|
2168
2892
|
const publishLifecycle = (scope, repositoryRoot) => {
|
|
2169
|
-
host.directEvents.publish(
|
|
2893
|
+
host.directEvents.publish(require_gitDependencies.GIT_WORKTREE_LIFECYCLE_EVENT, scope.sessionId, {
|
|
2170
2894
|
version: 1,
|
|
2171
2895
|
repositoryRoot
|
|
2172
2896
|
});
|
|
@@ -2175,6 +2899,22 @@ function createWorktreesChannel(options = {}) {
|
|
|
2175
2899
|
const parent = host.sessions().find((scope) => scope.sessionId === parentSessionId);
|
|
2176
2900
|
if (parent === void 0) throw new Error("The conversation parent session is unavailable.");
|
|
2177
2901
|
const branch = `po/conversation-${reservationId.slice(0, 12)}`;
|
|
2902
|
+
if (options.scopedCommands) {
|
|
2903
|
+
if (!(await host.requestSessionApi(parent, {
|
|
2904
|
+
basePath: "git",
|
|
2905
|
+
path: "/session-worktrees",
|
|
2906
|
+
method: "POST",
|
|
2907
|
+
body: JSON.stringify({
|
|
2908
|
+
action: "create",
|
|
2909
|
+
branch,
|
|
2910
|
+
reservationId
|
|
2911
|
+
}),
|
|
2912
|
+
...signal ? { signal } : {}
|
|
2913
|
+
})).ok) throw new Error("The conversation worktree could not be created.");
|
|
2914
|
+
const reservations = sessionService.reservations;
|
|
2915
|
+
if (!reservations) throw new Error("Conversation reservations are unavailable.");
|
|
2916
|
+
return reservations.complete(reservationId, parentSessionId);
|
|
2917
|
+
}
|
|
2178
2918
|
const record = await worktrees.spawn({
|
|
2179
2919
|
cwd: parent.cwd,
|
|
2180
2920
|
sessionId: parent.sessionId
|
|
@@ -2238,10 +2978,24 @@ function createWorktreesChannel(options = {}) {
|
|
|
2238
2978
|
if (generations.get(scope.sessionId) !== generation) return;
|
|
2239
2979
|
mark(scope, pending, error, errorTarget);
|
|
2240
2980
|
};
|
|
2981
|
+
if (options.scopedCommands) {
|
|
2982
|
+
markCurrent(command.action === "create" ? `creating ${command.branch}…` : `closing ${command.id}…`, void 0, void 0);
|
|
2983
|
+
const response = await host.requestSessionApi(scope, {
|
|
2984
|
+
basePath: "git",
|
|
2985
|
+
path: "/session-worktrees",
|
|
2986
|
+
method: "POST",
|
|
2987
|
+
body: JSON.stringify(command)
|
|
2988
|
+
});
|
|
2989
|
+
const result = await response.json();
|
|
2990
|
+
if (!response.ok) throw new require_gitDependencies.PoGitExpectedError(result.code ?? "git_failed", result.error ?? "The worktree operation failed.", false, "Inspect the worktree before retrying.");
|
|
2991
|
+
if (result.worktree) publishLifecycle(scope, result.worktree.repositoryRoot);
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2241
2994
|
if (command.action === "create") {
|
|
2242
2995
|
markCurrent(`creating ${command.branch}…`, void 0, void 0);
|
|
2243
2996
|
const record = await worktrees.spawn(context, {
|
|
2244
2997
|
branch: command.branch,
|
|
2998
|
+
...command.sparseProfile === void 0 ? {} : { sparseProfile: command.sparseProfile },
|
|
2245
2999
|
...command.baseRef === void 0 ? {} : { baseRef: command.baseRef },
|
|
2246
3000
|
...command.reservationId === void 0 ? {} : { reservationId: command.reservationId }
|
|
2247
3001
|
}, { onProgress: (label) => markCurrent(label, void 0, void 0) });
|
|
@@ -2262,11 +3016,11 @@ function createWorktreesChannel(options = {}) {
|
|
|
2262
3016
|
sessionAdded(scope) {
|
|
2263
3017
|
newGeneration(scope.sessionId);
|
|
2264
3018
|
publish(scope, false);
|
|
2265
|
-
const unsubscribe = host.directEvents.subscribe(
|
|
2266
|
-
if (!
|
|
3019
|
+
const unsubscribe = host.directEvents.subscribe(require_gitDependencies.GIT_WORKTREE_LIFECYCLE_EVENT, scope.sessionId, async (payload) => {
|
|
3020
|
+
if (!require_gitDependencies.isWorktreeLifecycleEvent(payload)) return;
|
|
2267
3021
|
let sameRepository = false;
|
|
2268
3022
|
try {
|
|
2269
|
-
sameRepository = await
|
|
3023
|
+
sameRepository = await require_gitDependencies.registryFile(scope.cwd, options.homeDir, options.environment) === await require_gitDependencies.registryFile(payload.repositoryRoot, options.homeDir, options.environment);
|
|
2270
3024
|
} catch {
|
|
2271
3025
|
sameRepository = false;
|
|
2272
3026
|
}
|
|
@@ -2317,7 +3071,11 @@ function createWorktreesChannel(options = {}) {
|
|
|
2317
3071
|
}
|
|
2318
3072
|
//#endregion
|
|
2319
3073
|
//#region src/extensions/(backend)/channel/git-worktrees.server.ts
|
|
2320
|
-
var git_worktrees_server_default = (0, _agimon_ai_po_core_extensionFile.defineChannel)(createWorktreesChannel
|
|
3074
|
+
var git_worktrees_server_default = (0, _agimon_ai_po_core_extensionFile.defineChannel)((plugin) => createWorktreesChannel({
|
|
3075
|
+
homeDir: plugin.host.context.homeDirectory,
|
|
3076
|
+
environment: plugin.host.context.environment,
|
|
3077
|
+
scopedCommands: true
|
|
3078
|
+
}), { context: true });
|
|
2321
3079
|
//#endregion
|
|
2322
3080
|
//#region src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server.ts
|
|
2323
3081
|
var agent_settled_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)((context) => context.root.hooks[1]);
|
|
@@ -2344,8 +3102,11 @@ const via = (identity, value) => value === void 0 ? void 0 : {
|
|
|
2344
3102
|
};
|
|
2345
3103
|
const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
|
|
2346
3104
|
name: "@agimon-ai/po-git",
|
|
2347
|
-
providerOverrides: (0, _agimon_ai_po_core_serverPlugin.composeServerProviderOverrides)(root_server_default),
|
|
2348
|
-
injects: (0, _agimon_ai_po_core_extensionFile.composeRootInjects)({
|
|
3105
|
+
providerOverrides: (0, _agimon_ai_po_core_serverPlugin.composeServerProviderOverrides)(root_server_default$1, root_server_default),
|
|
3106
|
+
injects: (0, _agimon_ai_po_core_extensionFile.composeRootInjects)({
|
|
3107
|
+
workspace: [root_server_default$1],
|
|
3108
|
+
session: [root_server_default$1, root_server_default]
|
|
3109
|
+
}),
|
|
2349
3110
|
host: (context) => ({
|
|
2350
3111
|
get api() {
|
|
2351
3112
|
return [at(route_server_default, context)];
|
|
@@ -2354,22 +3115,32 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
|
|
|
2354
3115
|
return [() => via({ frameType: "git_changes" }, at(git_changes_server_default, context)), () => via({ frameType: "git_worktrees" }, at(git_worktrees_server_default, context))];
|
|
2355
3116
|
}
|
|
2356
3117
|
}),
|
|
2357
|
-
workspace: (context) =>
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
3118
|
+
workspace: async (context) => {
|
|
3119
|
+
const scopeWorkspace = await context.scopeRoot("workspace", root_server_default$1, context);
|
|
3120
|
+
return {
|
|
3121
|
+
...(0, _agimon_ai_po_core_extensionFile.composeRootHooks)(scopeWorkspace),
|
|
3122
|
+
get api() {
|
|
3123
|
+
return [at(route_server_default, context)];
|
|
3124
|
+
},
|
|
3125
|
+
get channels() {
|
|
3126
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "git_changes" }, at(git_changes_server_default, context)), context.hosted("host") ? void 0 : () => via({ frameType: "git_worktrees" }, at(git_worktrees_server_default, context))]);
|
|
3127
|
+
},
|
|
3128
|
+
services: [...scopeWorkspace.services ?? []]
|
|
3129
|
+
};
|
|
3130
|
+
},
|
|
2365
3131
|
session: async (context) => {
|
|
2366
|
-
const
|
|
2367
|
-
const
|
|
3132
|
+
const scopeWorkspace = await context.scopeRoot("workspace", root_server_default$1, context);
|
|
3133
|
+
const contextWorkspace = {
|
|
2368
3134
|
...context,
|
|
3135
|
+
root: scopeWorkspace.value
|
|
3136
|
+
};
|
|
3137
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, contextWorkspace);
|
|
3138
|
+
const contextSession = {
|
|
3139
|
+
...contextWorkspace,
|
|
2369
3140
|
root: scopeSession.value
|
|
2370
3141
|
};
|
|
2371
3142
|
return {
|
|
2372
|
-
...(0, _agimon_ai_po_core_extensionFile.composeRootHooks)(scopeSession),
|
|
3143
|
+
...(0, _agimon_ai_po_core_extensionFile.composeRootHooks)(scopeWorkspace, scopeSession),
|
|
2373
3144
|
get api() {
|
|
2374
3145
|
return [at(route_server_default, context)];
|
|
2375
3146
|
},
|
|
@@ -2385,9 +3156,9 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
|
|
|
2385
3156
|
get tools() {
|
|
2386
3157
|
return [via({ name: "run_worktree" }, at(runWorktree_server_default, contextSession))];
|
|
2387
3158
|
},
|
|
2388
|
-
services: [...scopeSession.services ?? []],
|
|
3159
|
+
services: [...scopeWorkspace.services ?? [], ...scopeSession.services ?? []],
|
|
2389
3160
|
get activities() {
|
|
2390
|
-
return [...scopeSession.activities ?? []];
|
|
3161
|
+
return [...scopeWorkspace.activities ?? [], ...scopeSession.activities ?? []];
|
|
2391
3162
|
}
|
|
2392
3163
|
};
|
|
2393
3164
|
}
|