@agimon-ai/po-git 0.0.0-alpha.19 → 0.0.0-alpha.191
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +149 -21
- package/README.md +18 -21
- package/dist/apiContracts.cjs +37 -4
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.mjs +37 -4
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/extensions/native.mjs +2147 -477
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +548 -274
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +547 -273
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +1573 -1309
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +5 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/po-runtime-identity.json +1 -0
- package/dist/{worktreeOperations-Dxs3txKL.cjs → worktreeOperations-BEk4VEj3.cjs} +298 -94
- package/dist/worktreeOperations-BEk4VEj3.cjs.map +1 -0
- package/dist/{worktreeOperations-Cd8Q12L4.mjs → worktreeOperations-hT6N8oSr.mjs} +268 -94
- package/dist/worktreeOperations-hT6N8oSr.mjs.map +1 -0
- package/llms.txt +1 -1
- package/package.json +95 -21
- package/src/prompts/{po-use-git → codemode-how-to-git}/SKILL.md +35 -32
- package/dist/worktreeOperations-Cd8Q12L4.mjs.map +0 -1
- package/dist/worktreeOperations-Dxs3txKL.cjs.map +0 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import os from "node:os";
|
|
1
|
+
import { C as READ_TIMEOUT_MS, E as runGit, S as NETWORK_TIMEOUT_MS, T as createWorktreeGit, a as GIT_WORKTREE_LIFECYCLE_EVENT, c as isWorktreeLifecycleEvent, d as registryFile, f as readJson, g as invalidRequest, h as PoGitExpectedError, i as GIT_SESSION_CHANGED_EVENT, l as credentialsFile, m as HubUnavailableError, n as createWorktreeRegistry, o as createWorktreeMessageInbox, p as writeJsonAtomic, r as validRefName, s as isSessionChangedEvent, t as createWorktreeOperations, u as poGitRoot, w as REBASE_TIMEOUT_MS } from "../worktreeOperations-hT6N8oSr.mjs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
import
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { composeServerProviderOverrides, defineServerPlugin, packageResourcePath, readPackageResource } from "@agimon-ai/po-core/serverPlugin";
|
|
6
6
|
import { composeRootHooks, composeRootInjects, defineChannel, defineHook, defineResource, defineRoot, defineRoute, defineServerTool } from "@agimon-ai/po-core/extensionFile";
|
|
7
|
+
import { PO_CODEMODE_SERVICE, readPoCodemode } from "@agimon-ai/po-core/codemode";
|
|
7
8
|
import { readPoSessionDelivery } from "@agimon-ai/po-session";
|
|
8
9
|
import { Type } from "typebox";
|
|
10
|
+
import { BACKGROUND_CONTEXT, PO_SHELL_SERVICE, requirePoShell, withAbortSignal } from "@agimon-ai/po-core/platform";
|
|
11
|
+
import { poApiCallerFrom } from "@agimon-ai/po-core/packageApi";
|
|
12
|
+
import { parseLaunchSelection } from "@agimon-ai/po-core/hubChannel";
|
|
9
13
|
//#region src/schemas/runWorktreeTool.ts
|
|
10
14
|
/**
|
|
11
15
|
* The tool's action vocabulary.
|
|
@@ -247,7 +251,8 @@ async function executeRunWorktreeTool(params, operations, context, options = {})
|
|
|
247
251
|
content: text(describe(record, context.sessionId), `Session: ${record.sessionId}`, dirtyFiles.length === 0 ? "Clean." : `${String(dirtyFiles.length)} uncommitted file(s): ${dirtyFiles.slice(0, 20).join(", ")}`),
|
|
248
252
|
details: {
|
|
249
253
|
action: params.action,
|
|
250
|
-
records: [record]
|
|
254
|
+
records: [record],
|
|
255
|
+
dirtyFiles
|
|
251
256
|
}
|
|
252
257
|
};
|
|
253
258
|
}
|
|
@@ -271,7 +276,10 @@ async function executeRunWorktreeTool(params, operations, context, options = {})
|
|
|
271
276
|
const waiting = await operations.messages(context, params.id);
|
|
272
277
|
return {
|
|
273
278
|
content: waiting.length === 0 ? text("No messages.") : text(`${String(waiting.length)} message(s):`, ...waiting.map((entry) => `[${entry.sentAt}] ${entry.from}: ${entry.text}`)),
|
|
274
|
-
details: {
|
|
279
|
+
details: {
|
|
280
|
+
action: params.action,
|
|
281
|
+
messages: waiting
|
|
282
|
+
}
|
|
275
283
|
};
|
|
276
284
|
}
|
|
277
285
|
case WORKTREE_ACTIONS.prune: {
|
|
@@ -286,12 +294,172 @@ async function executeRunWorktreeTool(params, operations, context, options = {})
|
|
|
286
294
|
`Untracked directories, left alone: ${plan.untracked.length === 0 ? "none" : plan.untracked.join(", ")}`,
|
|
287
295
|
...plan.keptBranches.length === 0 ? [] : [`Branches kept, they hold commits: ${plan.keptBranches.join(", ")}`]
|
|
288
296
|
]),
|
|
289
|
-
details: {
|
|
297
|
+
details: {
|
|
298
|
+
action: params.action,
|
|
299
|
+
plan
|
|
300
|
+
}
|
|
290
301
|
};
|
|
291
302
|
}
|
|
292
303
|
}
|
|
293
304
|
}
|
|
294
305
|
//#endregion
|
|
306
|
+
//#region src/services/worktreeNamespace/index.ts
|
|
307
|
+
const DECLARATIONS = `type WorktreeStatus = 'spawning' | 'running' | 'closing' | 'orphaned';
|
|
308
|
+
|
|
309
|
+
interface Worktree {
|
|
310
|
+
id: string;
|
|
311
|
+
branch: string;
|
|
312
|
+
baseRef: string;
|
|
313
|
+
/** Absolute path of the checkout, under ~/.po/git/worktrees. */
|
|
314
|
+
path: string;
|
|
315
|
+
repositoryRoot: string;
|
|
316
|
+
/** The session running inside the worktree. */
|
|
317
|
+
sessionId: string;
|
|
318
|
+
parentSessionId?: string;
|
|
319
|
+
status: WorktreeStatus;
|
|
320
|
+
createdAt: string;
|
|
321
|
+
/** How your session relates to it: 'parent' spawned it, 'child' runs inside it, 'other' is neither. */
|
|
322
|
+
relationship: 'parent' | 'child' | 'other';
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface WorktreeMessage {
|
|
326
|
+
worktreeId: string;
|
|
327
|
+
fromSessionId: string;
|
|
328
|
+
from: 'parent' | 'child';
|
|
329
|
+
text: string;
|
|
330
|
+
sentAt: string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
interface PrunePlan {
|
|
334
|
+
remove: Worktree[];
|
|
335
|
+
forget: Worktree[];
|
|
336
|
+
/** Kept because they hold uncommitted work. */
|
|
337
|
+
keptDirty: Worktree[];
|
|
338
|
+
untracked: string[];
|
|
339
|
+
/** Branches kept because they hold commits. */
|
|
340
|
+
keptBranches: string[];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
declare const worktrees: {
|
|
344
|
+
/** Every worktree for this repository. */
|
|
345
|
+
list(): Promise<Worktree[]>;
|
|
346
|
+
/** One worktree and its uncommitted files. */
|
|
347
|
+
status(id: string): Promise<{ worktree: Worktree; dirtyFiles: string[] }>;
|
|
348
|
+
/**
|
|
349
|
+
* Create a worktree on a new branch and start a Po session in it, nested under this one. baseRef defaults to
|
|
350
|
+
* the current branch's remote-tracking ref, then the remote default branch; name labels it in the rail; task is
|
|
351
|
+
* the new session's first message. Setup can be slow, so give exec a larger timeoutMs.
|
|
352
|
+
*/
|
|
353
|
+
spawn(request: { branch: string; baseRef?: string; name?: string; task?: string }): Promise<Worktree>;
|
|
354
|
+
/** Stop the worktree's session and delete its checkout. Refused on a dirty tree unless force is true. */
|
|
355
|
+
close(id: string, options?: { force?: boolean }): Promise<Worktree>;
|
|
356
|
+
/** Merge the worktree's branch into this checkout. Refused when this checkout is dirty. */
|
|
357
|
+
merge(id: string, options?: { message?: string }): Promise<Worktree>;
|
|
358
|
+
/** Remove orphaned worktrees. With dryRun, only return the plan. */
|
|
359
|
+
prune(options?: { dryRun?: boolean }): Promise<PrunePlan>;
|
|
360
|
+
/**
|
|
361
|
+
* Message the other side of a worktree. Use the record with relationship 'child' to report to your parent,
|
|
362
|
+
* and 'parent' to reach your own children. 'other' records are not communication edges.
|
|
363
|
+
*/
|
|
364
|
+
send(id: string, message: string): Promise<void>;
|
|
365
|
+
/** Messages waiting for you from a worktree. */
|
|
366
|
+
messages(id: string): Promise<WorktreeMessage[]>;
|
|
367
|
+
};`;
|
|
368
|
+
const json = (value) => JSON.parse(JSON.stringify(value));
|
|
369
|
+
/** Git worktrees for code mode: the actions of `run_worktree` as methods, returning records instead of text. */
|
|
370
|
+
function createWorktreeNamespace(options) {
|
|
371
|
+
return {
|
|
372
|
+
name: "worktrees",
|
|
373
|
+
summary: "Git worktrees, each with its own Po session nested under this one: worktrees.list, status, spawn, close, merge, prune, send and messages.",
|
|
374
|
+
declarations: DECLARATIONS,
|
|
375
|
+
bind(run) {
|
|
376
|
+
if (run.sessionId !== options.execution.sessionId) throw new Error("Worktrees namespace belongs to another session.");
|
|
377
|
+
let disposed = false;
|
|
378
|
+
run.onDispose(() => {
|
|
379
|
+
disposed = true;
|
|
380
|
+
});
|
|
381
|
+
const view = (record) => ({
|
|
382
|
+
...record,
|
|
383
|
+
relationship: record.parentSessionId === options.execution.sessionId ? "parent" : record.sessionId === options.execution.sessionId ? "child" : "other"
|
|
384
|
+
});
|
|
385
|
+
/** One `run_worktree` action through the tool's own code, so the tool and the namespace cannot drift. */
|
|
386
|
+
const act = async (name, action, input) => {
|
|
387
|
+
run.signal.throwIfAborted();
|
|
388
|
+
if (disposed) throw new Error("Worktrees namespace run is disposed.");
|
|
389
|
+
options.assertAvailable();
|
|
390
|
+
const params = validateParams({
|
|
391
|
+
action,
|
|
392
|
+
...typeof input === "object" && input !== null ? input : {}
|
|
393
|
+
});
|
|
394
|
+
const context = {
|
|
395
|
+
cwd: options.execution.cwd,
|
|
396
|
+
sessionId: options.execution.sessionId
|
|
397
|
+
};
|
|
398
|
+
const started = Date.now();
|
|
399
|
+
try {
|
|
400
|
+
const result = await executeRunWorktreeTool(params, options.operations, context, { signal: run.signal });
|
|
401
|
+
options.assertAvailable();
|
|
402
|
+
run.record?.({
|
|
403
|
+
name: `worktrees.${name}`,
|
|
404
|
+
tool: RUN_WORKTREE_TOOL_NAME,
|
|
405
|
+
args: params,
|
|
406
|
+
ok: true,
|
|
407
|
+
ms: Date.now() - started,
|
|
408
|
+
result
|
|
409
|
+
});
|
|
410
|
+
return result;
|
|
411
|
+
} catch (error) {
|
|
412
|
+
run.record?.({
|
|
413
|
+
name: `worktrees.${name}`,
|
|
414
|
+
tool: RUN_WORKTREE_TOOL_NAME,
|
|
415
|
+
args: params,
|
|
416
|
+
ok: false,
|
|
417
|
+
ms: Date.now() - started,
|
|
418
|
+
error: error instanceof Error ? error.message : String(error)
|
|
419
|
+
});
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
const record = (result) => view(result.details.records[0]);
|
|
424
|
+
const members = Object.create(null);
|
|
425
|
+
members.list = async () => json((await act("list", "list", {})).details.records.map(view));
|
|
426
|
+
members.status = async (id) => {
|
|
427
|
+
const { details } = await act("status", "status", { id });
|
|
428
|
+
return json({
|
|
429
|
+
worktree: view(details.records[0]),
|
|
430
|
+
dirtyFiles: details.dirtyFiles ?? []
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
members.spawn = async (request) => json(record(await act("spawn", "spawn_worktree", request)));
|
|
434
|
+
members.close = async (id, settings) => json(record(await act("close", "close_worktree", {
|
|
435
|
+
...settings,
|
|
436
|
+
id
|
|
437
|
+
})));
|
|
438
|
+
members.merge = async (id, settings) => json(record(await act("merge", "merge", {
|
|
439
|
+
...settings,
|
|
440
|
+
id
|
|
441
|
+
})));
|
|
442
|
+
members.prune = async (settings) => {
|
|
443
|
+
const { plan } = (await act("prune", "prune", settings)).details;
|
|
444
|
+
return json({
|
|
445
|
+
...plan,
|
|
446
|
+
remove: plan.remove.map(view),
|
|
447
|
+
forget: plan.forget.map(view),
|
|
448
|
+
keptDirty: plan.keptDirty.map(view)
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
members.send = async (id, message) => {
|
|
452
|
+
await act("send", "send", {
|
|
453
|
+
id,
|
|
454
|
+
message
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
members.messages = async (id) => json((await act("messages", "messages", { id })).details.messages);
|
|
458
|
+
return members;
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
295
463
|
//#region src/extensions/workspaces/sessions/(backend)/_lib/root.server.ts
|
|
296
464
|
function progressResult(action, label) {
|
|
297
465
|
return {
|
|
@@ -302,7 +470,16 @@ function progressResult(action, label) {
|
|
|
302
470
|
details: { action }
|
|
303
471
|
};
|
|
304
472
|
}
|
|
305
|
-
|
|
473
|
+
/** Tools that only read, so the checkout cannot have moved under them. */
|
|
474
|
+
const READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
|
|
475
|
+
"read",
|
|
476
|
+
"grep",
|
|
477
|
+
"find",
|
|
478
|
+
"ls",
|
|
479
|
+
"discover",
|
|
480
|
+
"load_skill"
|
|
481
|
+
]);
|
|
482
|
+
function createGitSession({ context, host: serverHost, agent, signal }) {
|
|
306
483
|
if (serverHost.context.directEvents === void 0) throw new Error("Git server plugin requires the session direct event bus.");
|
|
307
484
|
if (serverHost.context.sessionId === void 0) throw new Error("Git server plugin requires a session identity.");
|
|
308
485
|
const sessionId = serverHost.context.sessionId;
|
|
@@ -315,20 +492,12 @@ function createGitSession({ context, host: serverHost }) {
|
|
|
315
492
|
sessionDelivery: () => readPoSessionDelivery(context)
|
|
316
493
|
});
|
|
317
494
|
const resources = [{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
attribution: {
|
|
321
|
-
kind: "minor",
|
|
322
|
-
mode: "help"
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
name: "po-git",
|
|
326
|
-
kind: "context",
|
|
327
|
-
read: () => readPackageResource(import.meta.url, "llms.txt")
|
|
328
|
-
}, {
|
|
329
|
-
name: "po-use-git",
|
|
495
|
+
name: "codemode-how-to-git",
|
|
496
|
+
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.",
|
|
330
497
|
kind: "skill",
|
|
331
|
-
|
|
498
|
+
pinned: true,
|
|
499
|
+
path: packageResourcePath(import.meta.url, "src/prompts/codemode-how-to-git/SKILL.md"),
|
|
500
|
+
read: () => readPackageResource(import.meta.url, "src/prompts/codemode-how-to-git/SKILL.md")
|
|
332
501
|
}];
|
|
333
502
|
const tool = {
|
|
334
503
|
name: RUN_WORKTREE_TOOL_NAME,
|
|
@@ -348,17 +517,37 @@ function createGitSession({ context, host: serverHost }) {
|
|
|
348
517
|
const changed = (_event, execution) => {
|
|
349
518
|
directEvents.publish(GIT_SESSION_CHANGED_EVENT, execution.sessionId, { version: 1 });
|
|
350
519
|
};
|
|
520
|
+
const hooks = [{
|
|
521
|
+
event: "tool_execution_end",
|
|
522
|
+
handle: (event, execution) => READ_ONLY_TOOLS.has(event.toolName) ? void 0 : changed(event, execution)
|
|
523
|
+
}, {
|
|
524
|
+
event: "agent_settled",
|
|
525
|
+
handle: changed
|
|
526
|
+
}];
|
|
527
|
+
if (agent) {
|
|
528
|
+
const namespace = createWorktreeNamespace({
|
|
529
|
+
operations,
|
|
530
|
+
execution: agent.context,
|
|
531
|
+
assertAvailable: () => {
|
|
532
|
+
if (signal?.aborted) throw new Error("Git session is unavailable.");
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
context.inject([PO_CODEMODE_SERVICE], (scoped) => {
|
|
536
|
+
const codemode = readPoCodemode(scoped);
|
|
537
|
+
if (!codemode) return void 0;
|
|
538
|
+
const registration = codemode.register("@agimon-ai/po-git", namespace);
|
|
539
|
+
const restriction = agent.registerToolRestriction({ excludedTools: [RUN_WORKTREE_TOOL_NAME] });
|
|
540
|
+
return () => {
|
|
541
|
+
restriction.dispose();
|
|
542
|
+
registration.dispose();
|
|
543
|
+
};
|
|
544
|
+
});
|
|
545
|
+
}
|
|
351
546
|
return {
|
|
352
547
|
value: {
|
|
353
548
|
resources,
|
|
354
549
|
tool,
|
|
355
|
-
hooks
|
|
356
|
-
event: "tool_execution_end",
|
|
357
|
-
handle: changed
|
|
358
|
-
}, {
|
|
359
|
-
event: "agent_settled",
|
|
360
|
-
handle: changed
|
|
361
|
-
}]
|
|
550
|
+
hooks
|
|
362
551
|
},
|
|
363
552
|
onDispose: () => messageInbox.close()
|
|
364
553
|
};
|
|
@@ -469,11 +658,11 @@ const NAME_STATUS = {
|
|
|
469
658
|
T: "modified"
|
|
470
659
|
};
|
|
471
660
|
/** Line count of a small regular file, or undefined when it is binary, large, or not a regular file. */
|
|
472
|
-
function untrackedLines(root, relPath) {
|
|
661
|
+
async function untrackedLines(root, relPath) {
|
|
473
662
|
const absolute = path.join(root, relPath);
|
|
474
663
|
let stat;
|
|
475
664
|
try {
|
|
476
|
-
stat = fs.
|
|
665
|
+
stat = await fs.lstat(absolute);
|
|
477
666
|
} catch {
|
|
478
667
|
return;
|
|
479
668
|
}
|
|
@@ -482,7 +671,7 @@ function untrackedLines(root, relPath) {
|
|
|
482
671
|
binary: false
|
|
483
672
|
};
|
|
484
673
|
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) return void 0;
|
|
485
|
-
const content = fs.
|
|
674
|
+
const content = await fs.readFile(absolute);
|
|
486
675
|
if (content.subarray(0, BINARY_PROBE_BYTES).includes(0)) return {
|
|
487
676
|
lines: 0,
|
|
488
677
|
binary: true
|
|
@@ -605,8 +794,8 @@ function createBranchDiff() {
|
|
|
605
794
|
"--exclude-standard",
|
|
606
795
|
"-z"
|
|
607
796
|
]));
|
|
608
|
-
untracked.
|
|
609
|
-
const counted = index < MAX_UNTRACKED_COUNTED ? untrackedLines(root, relPath) : void 0;
|
|
797
|
+
for (const [index, relPath] of untracked.entries()) {
|
|
798
|
+
const counted = index < MAX_UNTRACKED_COUNTED ? await untrackedLines(root, relPath) : void 0;
|
|
610
799
|
entries.push({
|
|
611
800
|
path: relPath,
|
|
612
801
|
status: "untracked",
|
|
@@ -614,18 +803,20 @@ function createBranchDiff() {
|
|
|
614
803
|
removed: 0,
|
|
615
804
|
...counted?.binary ? { binary: true } : {}
|
|
616
805
|
});
|
|
617
|
-
}
|
|
806
|
+
}
|
|
618
807
|
entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
619
808
|
const conflicts = [...unmerged];
|
|
620
|
-
const
|
|
809
|
+
const rebaseMerge = await readLine$1(root, [
|
|
621
810
|
"rev-parse",
|
|
622
811
|
"--git-path",
|
|
623
812
|
"rebase-merge"
|
|
624
|
-
])
|
|
813
|
+
]);
|
|
814
|
+
const rebaseApply = await readLine$1(root, [
|
|
625
815
|
"rev-parse",
|
|
626
816
|
"--git-path",
|
|
627
817
|
"rebase-apply"
|
|
628
|
-
])
|
|
818
|
+
]);
|
|
819
|
+
const rebasing = (await Promise.all([rebaseMerge, rebaseApply].map(async (gitPath) => gitPath === void 0 ? false : fs.access(path.resolve(root, gitPath)).then(() => true, () => false)))).some(Boolean);
|
|
629
820
|
const upstreamRef = branch === void 0 ? void 0 : await upstreamOf(root, branch);
|
|
630
821
|
let upstream;
|
|
631
822
|
if (upstreamRef !== void 0) {
|
|
@@ -670,7 +861,7 @@ function createBranchDiff() {
|
|
|
670
861
|
if (entry === void 0) throw new Error("That path is not in this review.");
|
|
671
862
|
if (entry.status === "untracked") {
|
|
672
863
|
const absolute = path.join(review.root, entry.path);
|
|
673
|
-
const stat = fs.
|
|
864
|
+
const stat = await fs.lstat(absolute);
|
|
674
865
|
if (stat.isSymbolicLink()) return {
|
|
675
866
|
path: entry.path,
|
|
676
867
|
hunks: [{
|
|
@@ -678,7 +869,7 @@ function createBranchDiff() {
|
|
|
678
869
|
rows: [{
|
|
679
870
|
marker: "+",
|
|
680
871
|
line: 1,
|
|
681
|
-
content: fs.
|
|
872
|
+
content: await fs.readlink(absolute)
|
|
682
873
|
}]
|
|
683
874
|
}]
|
|
684
875
|
};
|
|
@@ -687,7 +878,7 @@ function createBranchDiff() {
|
|
|
687
878
|
hunks: [],
|
|
688
879
|
tooLarge: true
|
|
689
880
|
};
|
|
690
|
-
const content = fs.
|
|
881
|
+
const content = await fs.readFile(absolute);
|
|
691
882
|
if (content.subarray(0, BINARY_PROBE_BYTES).includes(0)) return {
|
|
692
883
|
path: entry.path,
|
|
693
884
|
hunks: [],
|
|
@@ -804,9 +995,9 @@ function isRecord(value) {
|
|
|
804
995
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
805
996
|
}
|
|
806
997
|
/** The workspace key: the canonical root, so a symlinked path and its target share one entry. */
|
|
807
|
-
function workspaceKey(workspaceRoot) {
|
|
998
|
+
async function workspaceKey(workspaceRoot) {
|
|
808
999
|
try {
|
|
809
|
-
return fs.
|
|
1000
|
+
return await fs.realpath(workspaceRoot);
|
|
810
1001
|
} catch {
|
|
811
1002
|
return path.resolve(workspaceRoot);
|
|
812
1003
|
}
|
|
@@ -855,7 +1046,7 @@ function publicView(config) {
|
|
|
855
1046
|
* the saved one, and only for the same host: a token never follows a host it
|
|
856
1047
|
* was not entered for.
|
|
857
1048
|
*/
|
|
858
|
-
function parseGitAuthSave(request, current, homeDir) {
|
|
1049
|
+
async function parseGitAuthSave(request, current, homeDir) {
|
|
859
1050
|
if (!isRecord(request)) throw invalidRequest("The git auth request is not an object.", "Send method none, ssh or https.");
|
|
860
1051
|
if (request.method === "none") return { method: "none" };
|
|
861
1052
|
if (request.method === "ssh") {
|
|
@@ -865,7 +1056,7 @@ function parseGitAuthSave(request, current, homeDir) {
|
|
|
865
1056
|
if (!keyPath.startsWith("/") && !keyPath.startsWith("~/")) throw invalidRequest("The key path is not absolute.", "Give the key as an absolute path or one under ~/.");
|
|
866
1057
|
let isFile = false;
|
|
867
1058
|
try {
|
|
868
|
-
isFile = fs.
|
|
1059
|
+
isFile = (await fs.stat(expandHome(keyPath, homeDir))).isFile();
|
|
869
1060
|
} catch {
|
|
870
1061
|
isFile = false;
|
|
871
1062
|
}
|
|
@@ -900,16 +1091,16 @@ function parseGitAuthSave(request, current, homeDir) {
|
|
|
900
1091
|
throw invalidRequest("The git auth method is unknown.", "Send method none, ssh or https.");
|
|
901
1092
|
}
|
|
902
1093
|
/** Tightens a file or folder something left readable by group or others. */
|
|
903
|
-
function tighten(target, mode) {
|
|
1094
|
+
async function tighten(target, mode) {
|
|
904
1095
|
try {
|
|
905
|
-
if ((fs.
|
|
1096
|
+
if (((await fs.stat(target)).mode & LOOSE_BITS) !== 0) await fs.chmod(target, mode);
|
|
906
1097
|
} catch {}
|
|
907
1098
|
}
|
|
908
|
-
function createGitAuthStore(homeDir = os.homedir()) {
|
|
909
|
-
const file = credentialsFile(homeDir);
|
|
910
|
-
const readFile = () => {
|
|
911
|
-
tighten(file, OWNER_ONLY_FILE);
|
|
912
|
-
const raw = readJson(file);
|
|
1099
|
+
function createGitAuthStore(homeDir = os.homedir(), environment = {}) {
|
|
1100
|
+
const file = credentialsFile(homeDir, environment);
|
|
1101
|
+
const readFile = async () => {
|
|
1102
|
+
await tighten(file, OWNER_ONLY_FILE);
|
|
1103
|
+
const raw = await readJson(file);
|
|
913
1104
|
const workspaces = {};
|
|
914
1105
|
if (isRecord(raw) && raw.version === 1 && isRecord(raw.workspaces)) for (const [key, value] of Object.entries(raw.workspaces)) {
|
|
915
1106
|
const config = parseConfig(value);
|
|
@@ -920,28 +1111,28 @@ function createGitAuthStore(homeDir = os.homedir()) {
|
|
|
920
1111
|
workspaces
|
|
921
1112
|
};
|
|
922
1113
|
};
|
|
923
|
-
const read = (workspaceRoot) => readFile().workspaces[workspaceKey(workspaceRoot)] ?? { method: "none" };
|
|
1114
|
+
const read = async (workspaceRoot) => (await readFile()).workspaces[await workspaceKey(workspaceRoot)] ?? { method: "none" };
|
|
924
1115
|
return {
|
|
925
1116
|
read,
|
|
926
|
-
view: (workspaceRoot) => publicView(read(workspaceRoot)),
|
|
927
|
-
save(workspaceRoot, request) {
|
|
928
|
-
const key = workspaceKey(workspaceRoot);
|
|
929
|
-
const current = readFile();
|
|
930
|
-
const next = parseGitAuthSave(request, current.workspaces[key] ?? { method: "none" }, homeDir);
|
|
931
|
-
const root = poGitRoot(homeDir);
|
|
932
|
-
fs.
|
|
1117
|
+
view: async (workspaceRoot) => publicView(await read(workspaceRoot)),
|
|
1118
|
+
async save(workspaceRoot, request) {
|
|
1119
|
+
const key = await workspaceKey(workspaceRoot);
|
|
1120
|
+
const current = await readFile();
|
|
1121
|
+
const next = await parseGitAuthSave(request, current.workspaces[key] ?? { method: "none" }, homeDir);
|
|
1122
|
+
const root = poGitRoot(homeDir, environment);
|
|
1123
|
+
await fs.mkdir(root, {
|
|
933
1124
|
recursive: true,
|
|
934
1125
|
mode: OWNER_ONLY_DIRECTORY
|
|
935
1126
|
});
|
|
936
|
-
fs.
|
|
1127
|
+
await fs.chmod(root, OWNER_ONLY_DIRECTORY);
|
|
937
1128
|
const workspaces = { ...current.workspaces };
|
|
938
1129
|
if (next.method === "none") delete workspaces[key];
|
|
939
1130
|
else workspaces[key] = next;
|
|
940
|
-
writeJsonAtomic(file, {
|
|
1131
|
+
await writeJsonAtomic(file, {
|
|
941
1132
|
version: 1,
|
|
942
1133
|
workspaces
|
|
943
1134
|
});
|
|
944
|
-
fs.
|
|
1135
|
+
await fs.chmod(file, OWNER_ONLY_FILE);
|
|
945
1136
|
return publicView(next);
|
|
946
1137
|
}
|
|
947
1138
|
};
|
|
@@ -1060,7 +1251,13 @@ function newSessionRequest(body) {
|
|
|
1060
1251
|
if (branch === void 0 || branch === false || !validRefName(branch)) return { error: "A valid branch name is required." };
|
|
1061
1252
|
const name = optionalText(record.name);
|
|
1062
1253
|
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.` };
|
|
1063
|
-
const
|
|
1254
|
+
const chosen = record.selection === void 0 ? {} : parseLaunchSelection(record.selection);
|
|
1255
|
+
if ("error" in chosen) return chosen;
|
|
1256
|
+
const profile = chosen.selection?.profile;
|
|
1257
|
+
const named = {
|
|
1258
|
+
...name === void 0 ? {} : { name },
|
|
1259
|
+
...profile === void 0 ? {} : { selection: { profile } }
|
|
1260
|
+
};
|
|
1064
1261
|
if (record.mode === "existing-branch") {
|
|
1065
1262
|
const remote = optionalText(record.remote);
|
|
1066
1263
|
if (remote === false || remote !== void 0 && !validRefName(remote)) return { error: "That remote name is not valid." };
|
|
@@ -1106,177 +1303,238 @@ function failed(error) {
|
|
|
1106
1303
|
}, { status: error.retryable ? 503 : 409 });
|
|
1107
1304
|
return Response.json({ error: "The worktree operation failed." }, { status: 500 });
|
|
1108
1305
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1306
|
+
function createGitApi(openDirectory) {
|
|
1307
|
+
return {
|
|
1308
|
+
basePath: "git",
|
|
1309
|
+
start(context) {
|
|
1310
|
+
if (context.directEvents === void 0) throw new Error("Git hub API requires the direct event bus.");
|
|
1311
|
+
const directEvents = context.directEvents;
|
|
1312
|
+
const publishLifecycle = (sessionId, repositoryRoot) => {
|
|
1313
|
+
directEvents.publish(GIT_WORKTREE_LIFECYCLE_EVENT, sessionId, {
|
|
1314
|
+
version: 1,
|
|
1315
|
+
repositoryRoot
|
|
1316
|
+
});
|
|
1317
|
+
};
|
|
1318
|
+
const git = createWorktreeGit();
|
|
1319
|
+
const operations = createWorktreeOperations({
|
|
1320
|
+
git,
|
|
1321
|
+
sessionService: context.sessionService,
|
|
1322
|
+
...context.homeDirectory === void 0 ? {} : { homeDir: context.homeDirectory },
|
|
1323
|
+
...context.environment === void 0 ? {} : { environment: context.environment }
|
|
1120
1324
|
});
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1325
|
+
/**
|
|
1326
|
+
* The new-session dialog's routes: the workspace's branches, and a top-level
|
|
1327
|
+
* worktree session on one. Workspace-mounted only, and always rooted at the
|
|
1328
|
+
* mount's own workspace, so a request can never name another directory.
|
|
1329
|
+
*/
|
|
1330
|
+
const newSession = async (request, url) => {
|
|
1331
|
+
const isBranches = request.method === "GET" && url.pathname === "/branches";
|
|
1332
|
+
const isCreate = request.method === "POST" && url.pathname === "/sessions";
|
|
1333
|
+
const isDelete = request.method === "DELETE" && url.pathname === "/branches";
|
|
1334
|
+
const isOpen = request.method === "POST" && url.pathname === `/branches/open`;
|
|
1335
|
+
if (!isBranches && !isCreate && !isDelete && !isOpen) return void 0;
|
|
1336
|
+
const workspaceRoot = context.scope === "workspace" ? context.workspaceRoot : void 0;
|
|
1337
|
+
if (workspaceRoot === void 0) return Response.json({ error: "This route belongs to a workspace." }, { status: 404 });
|
|
1338
|
+
if (isBranches) {
|
|
1339
|
+
const repositoryRoot = await git.repositoryRoot(workspaceRoot);
|
|
1340
|
+
const branches = repositoryRoot === void 0 ? {
|
|
1341
|
+
repository: false,
|
|
1342
|
+
local: [],
|
|
1343
|
+
remote: []
|
|
1344
|
+
} : {
|
|
1345
|
+
repository: true,
|
|
1346
|
+
...await git.listBranches(repositoryRoot)
|
|
1347
|
+
};
|
|
1348
|
+
return Response.json(branches);
|
|
1349
|
+
}
|
|
1350
|
+
if (isDelete || isOpen) {
|
|
1351
|
+
if (isOpen && poApiCallerFrom(request.headers)?.locality !== "local") return Response.json({ error: "Opening Finder is only available on the host." }, { status: 403 });
|
|
1352
|
+
const body = await request.json().catch(() => void 0);
|
|
1353
|
+
const branch = typeof body === "object" && body !== null ? body.branch : void 0;
|
|
1354
|
+
if (typeof branch !== "string" || !validRefName(branch)) return badRequest("A valid branch name is required.");
|
|
1355
|
+
const repositoryRoot = await git.repositoryRoot(workspaceRoot);
|
|
1356
|
+
if (repositoryRoot === void 0) return badRequest("This workspace is not a git checkout.");
|
|
1357
|
+
const branches = await git.listBranches(repositoryRoot);
|
|
1358
|
+
const local = branches.local.find((item) => item.name === branch);
|
|
1359
|
+
if (local === void 0) return Response.json({ error: "That local branch no longer exists." }, { status: 404 });
|
|
1360
|
+
if (isOpen) {
|
|
1361
|
+
if (local.checkedOutAt === void 0) return Response.json({ error: "This branch has no checked-out folder." }, { status: 409 });
|
|
1362
|
+
if (openDirectory === void 0) return Response.json({ error: "Finder is not available on this host." }, { status: 409 });
|
|
1363
|
+
try {
|
|
1364
|
+
await openDirectory(local.checkedOutAt);
|
|
1365
|
+
return Response.json({ opened: true });
|
|
1366
|
+
} catch {
|
|
1367
|
+
return Response.json({ error: "The branch folder could not be opened in Finder." }, { status: 409 });
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
if (local.checkedOutAt !== void 0 || branches.current === branch) return Response.json({ error: "Close this branch’s worktree before deleting it." }, { status: 409 });
|
|
1371
|
+
if (!await git.deleteBranch({
|
|
1372
|
+
repositoryRoot,
|
|
1373
|
+
branch
|
|
1374
|
+
})) return Response.json({ error: "Git refused to delete this branch. It may contain unmerged commits or be checked out." }, { status: 409 });
|
|
1375
|
+
return Response.json({ deleted: true });
|
|
1376
|
+
}
|
|
1377
|
+
const parsed = newSessionRequest(await request.json().catch(() => void 0));
|
|
1378
|
+
if ("error" in parsed) return badRequest(parsed.error);
|
|
1379
|
+
const record = await operations.spawn({ cwd: workspaceRoot }, {
|
|
1380
|
+
branch: parsed.branch,
|
|
1381
|
+
checkout: parsed.mode === "existing-branch" ? "existing" : "new",
|
|
1382
|
+
...parsed.mode === "existing-branch" && parsed.remote !== void 0 ? { remote: parsed.remote } : {},
|
|
1383
|
+
...parsed.mode === "new-branch" && parsed.baseRef !== void 0 ? { baseRef: parsed.baseRef } : {},
|
|
1384
|
+
...parsed.name === void 0 ? {} : { name: parsed.name },
|
|
1385
|
+
...parsed.selection === void 0 ? {} : { selection: parsed.selection }
|
|
1386
|
+
});
|
|
1387
|
+
publishLifecycle(record.sessionId, record.repositoryRoot);
|
|
1388
|
+
const created = {
|
|
1389
|
+
sessionId: record.sessionId,
|
|
1390
|
+
worktreeId: record.id
|
|
1148
1391
|
};
|
|
1149
|
-
return Response.json(
|
|
1150
|
-
}
|
|
1151
|
-
const parsed = newSessionRequest(await request.json().catch(() => void 0));
|
|
1152
|
-
if ("error" in parsed) return badRequest(parsed.error);
|
|
1153
|
-
const record = await operations.spawn({ cwd: workspaceRoot }, {
|
|
1154
|
-
branch: parsed.branch,
|
|
1155
|
-
checkout: parsed.mode === "existing-branch" ? "existing" : "new",
|
|
1156
|
-
...parsed.mode === "existing-branch" && parsed.remote !== void 0 ? { remote: parsed.remote } : {},
|
|
1157
|
-
...parsed.mode === "new-branch" && parsed.baseRef !== void 0 ? { baseRef: parsed.baseRef } : {},
|
|
1158
|
-
...parsed.name === void 0 ? {} : { name: parsed.name }
|
|
1159
|
-
});
|
|
1160
|
-
publishLifecycle(record.sessionId, record.repositoryRoot);
|
|
1161
|
-
const created = {
|
|
1162
|
-
sessionId: record.sessionId,
|
|
1163
|
-
worktreeId: record.id
|
|
1392
|
+
return Response.json(created, { status: 201 });
|
|
1164
1393
|
};
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
if (request.method === "GET") return Response.json(gitAuth.view(root));
|
|
1191
|
-
try {
|
|
1192
|
-
return Response.json(gitAuth.save(root, await request.json().catch(() => void 0)));
|
|
1193
|
-
} catch (error) {
|
|
1194
|
-
if (error instanceof PoGitExpectedError && error.code === "invalid_request") {
|
|
1195
|
-
const text = error.message.replace(/^\[[a-z_]+\] /u, "").replace("\nRecovery: ", " ");
|
|
1196
|
-
return Response.json({
|
|
1197
|
-
error: text,
|
|
1198
|
-
code: error.code
|
|
1199
|
-
}, { status: 400 });
|
|
1200
|
-
}
|
|
1201
|
-
throw error;
|
|
1202
|
-
}
|
|
1203
|
-
};
|
|
1204
|
-
/**
|
|
1205
|
-
* The session's change against its base. Session mounts only, rooted at the
|
|
1206
|
-
* session's own checkout; a file is served only when it is in the change set
|
|
1207
|
-
* computed for the request. Overlapping requests share an in-flight snapshot.
|
|
1208
|
-
*/
|
|
1209
|
-
const review = async (request, url) => {
|
|
1210
|
-
if (url.pathname !== "/review" && url.pathname !== "/review/file") return void 0;
|
|
1211
|
-
const cwd = context.scope === "session" ? context.cwd : void 0;
|
|
1212
|
-
if (cwd === void 0) return Response.json({ error: "This route belongs to a session." }, { status: 404 });
|
|
1213
|
-
if (request.method !== "GET") return Response.json({ error: "Use GET." }, { status: 405 });
|
|
1214
|
-
let recordedBaseRef;
|
|
1215
|
-
try {
|
|
1216
|
-
recordedBaseRef = createWorktreeRegistry(registryFile(cwd, homeDir)).list().find((record) => record.sessionId === context.sessionId)?.baseRef;
|
|
1217
|
-
} catch {
|
|
1218
|
-
recordedBaseRef = void 0;
|
|
1219
|
-
}
|
|
1220
|
-
const key = JSON.stringify([cwd, recordedBaseRef ?? null]);
|
|
1221
|
-
let pending = pendingReviews.get(key);
|
|
1222
|
-
if (pending === void 0) {
|
|
1223
|
-
pending = branchDiff.review(cwd, recordedBaseRef === void 0 ? {} : { recordedBaseRef }).finally(() => pendingReviews.delete(key));
|
|
1224
|
-
pendingReviews.set(key, pending);
|
|
1225
|
-
}
|
|
1226
|
-
const result = await pending;
|
|
1227
|
-
if (url.pathname === "/review") return Response.json(result?.summary ?? {
|
|
1228
|
-
repository: false,
|
|
1229
|
-
files: []
|
|
1230
|
-
});
|
|
1231
|
-
const filePath = url.searchParams.get("path") ?? "";
|
|
1232
|
-
if (result === void 0 || !result.summary.files.some((file) => file.path === filePath)) return Response.json({ error: "That file is not part of this review." }, { status: 404 });
|
|
1233
|
-
return Response.json(await branchDiff.fileDiff(result, filePath));
|
|
1234
|
-
};
|
|
1235
|
-
return {
|
|
1236
|
-
async fetch(request) {
|
|
1237
|
-
const url = new URL(request.url);
|
|
1394
|
+
/** The admitted root for a request, or a response explaining why not. */
|
|
1395
|
+
const rootOf = (url) => {
|
|
1396
|
+
const repositoryId = url.searchParams.get("repositoryId");
|
|
1397
|
+
if (repositoryId === null || repositoryId === "") return badRequest("A repositoryId is required.");
|
|
1398
|
+
const root = context.resolveRepository?.(repositoryId);
|
|
1399
|
+
if (root === void 0) return badRequest("That repository is not admitted to this cockpit.");
|
|
1400
|
+
return root;
|
|
1401
|
+
};
|
|
1402
|
+
const homeDir = context.homeDirectory ?? context.environment?.HOME;
|
|
1403
|
+
const gitAuth = homeDir === void 0 ? void 0 : createGitAuthStore(homeDir, context.environment);
|
|
1404
|
+
const branchDiff = createBranchDiff();
|
|
1405
|
+
const pendingReviews = /* @__PURE__ */ new Map();
|
|
1406
|
+
/**
|
|
1407
|
+
* A workspace's remote auth. Workspace mounts only, so the step-up gate on
|
|
1408
|
+
* `PUT /api/workspaces/<id>/plugins/git/auth` is the one way to write it.
|
|
1409
|
+
* The view never carries the token.
|
|
1410
|
+
*/
|
|
1411
|
+
const auth = async (request, url) => {
|
|
1412
|
+
if (url.pathname !== "/auth") return void 0;
|
|
1413
|
+
if (context.scope !== "workspace") return Response.json({ error: "This route belongs to a workspace." }, { status: 404 });
|
|
1414
|
+
if (request.method !== "GET" && request.method !== "PUT") return Response.json({ error: "Use GET or PUT." }, { status: 405 });
|
|
1415
|
+
if (gitAuth === void 0) throw new Error("Git auth requires the admitted host home directory.");
|
|
1416
|
+
const root = rootOf(url);
|
|
1417
|
+
if (root instanceof Response) return root;
|
|
1418
|
+
if (request.method === "GET") return Response.json(await gitAuth.view(root));
|
|
1238
1419
|
try {
|
|
1239
|
-
|
|
1240
|
-
if (answered !== void 0) return answered;
|
|
1420
|
+
return Response.json(await gitAuth.save(root, await request.json().catch(() => void 0)));
|
|
1241
1421
|
} catch (error) {
|
|
1242
|
-
|
|
1243
|
-
|
|
1422
|
+
if (error instanceof PoGitExpectedError && error.code === "invalid_request") {
|
|
1423
|
+
const text = error.message.replace(/^\[[a-z_]+\] /u, "").replace("\nRecovery: ", " ");
|
|
1424
|
+
return Response.json({
|
|
1425
|
+
error: text,
|
|
1426
|
+
code: error.code
|
|
1427
|
+
}, { status: 400 });
|
|
1428
|
+
}
|
|
1429
|
+
throw error;
|
|
1244
1430
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1431
|
+
};
|
|
1432
|
+
/**
|
|
1433
|
+
* The session's change against its base. Session mounts only, rooted at the
|
|
1434
|
+
* session's own checkout; a file is served only when it is in the change set
|
|
1435
|
+
* computed for the request. Overlapping requests share an in-flight snapshot.
|
|
1436
|
+
*/
|
|
1437
|
+
const review = async (request, url) => {
|
|
1438
|
+
if (url.pathname !== "/review" && url.pathname !== "/review/file") return void 0;
|
|
1439
|
+
const cwd = context.scope === "session" ? context.cwd : void 0;
|
|
1440
|
+
if (cwd === void 0) return Response.json({ error: "This route belongs to a session." }, { status: 404 });
|
|
1441
|
+
if (request.method !== "GET") return Response.json({ error: "Use GET." }, { status: 405 });
|
|
1442
|
+
if (homeDir === void 0) throw new Error("Git review requires the admitted host home directory.");
|
|
1443
|
+
let recordedBaseRef;
|
|
1252
1444
|
try {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1445
|
+
recordedBaseRef = (await createWorktreeRegistry(await registryFile(cwd, homeDir, context.environment)).list()).find((record) => record.sessionId === context.sessionId)?.baseRef;
|
|
1446
|
+
} catch {
|
|
1447
|
+
recordedBaseRef = void 0;
|
|
1448
|
+
}
|
|
1449
|
+
const key = JSON.stringify([cwd, recordedBaseRef ?? null]);
|
|
1450
|
+
let pending = pendingReviews.get(key);
|
|
1451
|
+
if (pending === void 0) {
|
|
1452
|
+
pending = branchDiff.review(cwd, recordedBaseRef === void 0 ? {} : { recordedBaseRef }).finally(() => pendingReviews.delete(key));
|
|
1453
|
+
pendingReviews.set(key, pending);
|
|
1454
|
+
}
|
|
1455
|
+
const result = await pending;
|
|
1456
|
+
if (url.pathname === "/review") return Response.json(result?.summary ?? {
|
|
1457
|
+
repository: false,
|
|
1458
|
+
files: []
|
|
1459
|
+
});
|
|
1460
|
+
const filePath = url.searchParams.get("path") ?? "";
|
|
1461
|
+
if (result === void 0 || !result.summary.files.some((file) => file.path === filePath)) return Response.json({ error: "That file is not part of this review." }, { status: 404 });
|
|
1462
|
+
return Response.json(await branchDiff.fileDiff(result, filePath));
|
|
1463
|
+
};
|
|
1464
|
+
return {
|
|
1465
|
+
async fetch(request) {
|
|
1466
|
+
const url = new URL(request.url);
|
|
1467
|
+
try {
|
|
1468
|
+
const answered = await newSession(request, url) ?? await auth(request, url) ?? await review(request, url);
|
|
1469
|
+
if (answered !== void 0) return answered;
|
|
1470
|
+
} catch (error) {
|
|
1471
|
+
context.onNotice(`git request failed: ${error.name}`);
|
|
1472
|
+
return failed(error);
|
|
1264
1473
|
}
|
|
1265
|
-
const
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1474
|
+
const root = rootOf(url);
|
|
1475
|
+
if (root instanceof Response) return root;
|
|
1476
|
+
const callerContext = {
|
|
1477
|
+
cwd: root,
|
|
1478
|
+
sessionId: url.searchParams.get("sessionId") ?? ""
|
|
1479
|
+
};
|
|
1480
|
+
if ((request.method === "POST" && url.pathname === "/worktrees" || request.method === "DELETE" && /^\/worktrees\/[^/]+$/u.test(url.pathname)) && callerContext.sessionId === "") return badRequest("A sessionId is required for worktree mutations.");
|
|
1481
|
+
try {
|
|
1482
|
+
if (request.method === "GET" && url.pathname === "/worktrees") return Response.json({ worktrees: await operations.list(callerContext) });
|
|
1483
|
+
if (request.method === "POST" && url.pathname === "/worktrees") {
|
|
1484
|
+
const body = await request.json();
|
|
1485
|
+
if (typeof body.branch !== "string" || body.branch.trim() === "") return badRequest("A branch is required.");
|
|
1486
|
+
const record = await operations.spawn(callerContext, {
|
|
1487
|
+
branch: body.branch,
|
|
1488
|
+
...body.baseRef === void 0 ? {} : { baseRef: body.baseRef },
|
|
1489
|
+
...body.name === void 0 ? {} : { name: body.name }
|
|
1490
|
+
});
|
|
1491
|
+
publishLifecycle(callerContext.sessionId, record.repositoryRoot);
|
|
1492
|
+
return Response.json({ worktree: record }, { status: 201 });
|
|
1493
|
+
}
|
|
1494
|
+
const closing = /^\/worktrees\/([^/]+)$/u.exec(url.pathname);
|
|
1495
|
+
if (request.method === "DELETE" && closing) {
|
|
1496
|
+
const record = await operations.close(callerContext, decodeURIComponent(String(closing[1])), url.searchParams.get("force") === "true");
|
|
1497
|
+
publishLifecycle(callerContext.sessionId, record.repositoryRoot);
|
|
1498
|
+
return Response.json({ worktree: record });
|
|
1499
|
+
}
|
|
1500
|
+
return Response.json({ error: "No such worktree route." }, { status: 404 });
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
context.onNotice(`worktree request failed: ${error.name}`);
|
|
1503
|
+
return failed(error);
|
|
1270
1504
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1505
|
+
},
|
|
1506
|
+
close() {}
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
//#endregion
|
|
1512
|
+
//#region src/extensions/(backend)/api/git/route.server.ts
|
|
1513
|
+
var route_server_default = defineRoute(({ context, host, signal }) => {
|
|
1514
|
+
let openDirectory;
|
|
1515
|
+
context.inject([PO_SHELL_SERVICE], (child) => {
|
|
1516
|
+
const shell = requirePoShell(child);
|
|
1517
|
+
const env = Object.fromEntries(Object.entries(host.context.environment ?? {}).filter((entry) => entry[1] !== void 0));
|
|
1518
|
+
openDirectory = async (path) => {
|
|
1519
|
+
const result = await shell.exec([
|
|
1520
|
+
"/usr/bin/open",
|
|
1521
|
+
"-a",
|
|
1522
|
+
"Finder",
|
|
1523
|
+
path
|
|
1524
|
+
], {
|
|
1525
|
+
env,
|
|
1526
|
+
inheritEnv: false
|
|
1527
|
+
}, withAbortSignal(AbortSignal.any([signal, AbortSignal.timeout(5e3)]), BACKGROUND_CONTEXT));
|
|
1528
|
+
if (!result.ok || result.value.exitCode !== 0) throw new Error("Finder could not be opened.");
|
|
1278
1529
|
};
|
|
1279
|
-
|
|
1530
|
+
return () => {
|
|
1531
|
+
openDirectory = void 0;
|
|
1532
|
+
};
|
|
1533
|
+
});
|
|
1534
|
+
return createGitApi(async (path) => {
|
|
1535
|
+
if (openDirectory === void 0) throw new Error("The host shell is unavailable.");
|
|
1536
|
+
await openDirectory(path);
|
|
1537
|
+
});
|
|
1280
1538
|
});
|
|
1281
1539
|
//#endregion
|
|
1282
1540
|
//#region src/services/gitFailure/index.ts
|
|
@@ -1413,7 +1671,7 @@ async function rebasing(root) {
|
|
|
1413
1671
|
"--git-path",
|
|
1414
1672
|
name
|
|
1415
1673
|
]);
|
|
1416
|
-
if (gitPath !== void 0 && fs.
|
|
1674
|
+
if (gitPath !== void 0 && await fs.access(path.resolve(root, gitPath)).then(() => true, () => false)) return true;
|
|
1417
1675
|
}
|
|
1418
1676
|
return false;
|
|
1419
1677
|
}
|
|
@@ -1584,8 +1842,9 @@ const GIT_CHANGES_TYPE = "git_changes";
|
|
|
1584
1842
|
* - Apart from the worktrees channel. Worktrees are repository management;
|
|
1585
1843
|
* this is the session's own code change.
|
|
1586
1844
|
* - Push, not poll. The session's server plugin publishes a "changed" event
|
|
1587
|
-
* after every tool call and settled turn;
|
|
1588
|
-
*
|
|
1845
|
+
* after every tool call that can write and every settled turn; a recount
|
|
1846
|
+
* waits for a quiet moment, so a burst of tool calls costs one, and runs one
|
|
1847
|
+
* in flight plus one rerun.
|
|
1589
1848
|
* - One sync command per session. A rebase and a push must never overlap.
|
|
1590
1849
|
* - Auth is read fresh for each command from the session's workspace, and goes
|
|
1591
1850
|
* only into that command's git child.
|
|
@@ -1594,6 +1853,8 @@ const GIT_CHANGES_TYPE = "git_changes";
|
|
|
1594
1853
|
* - Echoing git output. Failures go through classifyGitFailure, which matches
|
|
1595
1854
|
* stderr and drops it, because a remote URL in it can carry a token.
|
|
1596
1855
|
*/
|
|
1856
|
+
/** Each recount spawns several git processes and walks the worktree for untracked files. */
|
|
1857
|
+
const REFRESH_DELAY_MS = 1500;
|
|
1597
1858
|
function payloadOf$1(state) {
|
|
1598
1859
|
return {
|
|
1599
1860
|
...state.changes === void 0 ? {} : { changes: state.changes },
|
|
@@ -1638,17 +1899,19 @@ function createGitChangesChannel(options = {}) {
|
|
|
1638
1899
|
const homeDir = options.homeDir ?? os.homedir();
|
|
1639
1900
|
const diff = options.diff ?? createBranchDiff();
|
|
1640
1901
|
const sync = options.sync ?? createGitSync({ homeDir });
|
|
1641
|
-
const auth = options.auth ?? createGitAuthStore(homeDir);
|
|
1902
|
+
const auth = options.auth ?? createGitAuthStore(homeDir, options.environment);
|
|
1642
1903
|
const latest = /* @__PURE__ */ new Map();
|
|
1643
1904
|
const subscriptions = /* @__PURE__ */ new Map();
|
|
1644
1905
|
const scopes = /* @__PURE__ */ new Map();
|
|
1645
1906
|
const inFlight = /* @__PURE__ */ new Set();
|
|
1646
1907
|
const rerun = /* @__PURE__ */ new Set();
|
|
1647
1908
|
const busy = /* @__PURE__ */ new Set();
|
|
1909
|
+
const delayed = /* @__PURE__ */ new Map();
|
|
1910
|
+
const refreshDelayMs = options.refreshDelayMs ?? REFRESH_DELAY_MS;
|
|
1648
1911
|
/** The base the session's own worktree was created from, when it has one. */
|
|
1649
|
-
const recordedBaseRef = (scope) => {
|
|
1912
|
+
const recordedBaseRef = async (scope) => {
|
|
1650
1913
|
try {
|
|
1651
|
-
return createWorktreeRegistry(registryFile(scope.cwd, homeDir)).list().find((record) => record.sessionId === scope.sessionId)?.baseRef;
|
|
1914
|
+
return (await createWorktreeRegistry(await registryFile(scope.cwd, homeDir, options.environment)).list()).find((record) => record.sessionId === scope.sessionId)?.baseRef;
|
|
1652
1915
|
} catch {
|
|
1653
1916
|
return;
|
|
1654
1917
|
}
|
|
@@ -1681,8 +1944,7 @@ function createGitChangesChannel(options = {}) {
|
|
|
1681
1944
|
return;
|
|
1682
1945
|
}
|
|
1683
1946
|
inFlight.add(sessionId);
|
|
1684
|
-
|
|
1685
|
-
diff.review(scope.cwd, base === void 0 ? {} : { recordedBaseRef: base }).then((review) => {
|
|
1947
|
+
recordedBaseRef(scope).then((base) => diff.review(scope.cwd, base === void 0 ? {} : { recordedBaseRef: base })).then((review) => {
|
|
1686
1948
|
if (scopes.has(sessionId)) update(sessionId, { changes: review?.changes });
|
|
1687
1949
|
}).catch((error) => {
|
|
1688
1950
|
host.onNotice(`git diff refresh failed for ${sessionId} (${error instanceof Error ? error.name : "unknown"})`);
|
|
@@ -1691,12 +1953,22 @@ function createGitChangesChannel(options = {}) {
|
|
|
1691
1953
|
if (rerun.delete(sessionId)) refresh(sessionId);
|
|
1692
1954
|
});
|
|
1693
1955
|
};
|
|
1694
|
-
|
|
1956
|
+
/** Recounts once the session has been quiet for a moment. */
|
|
1957
|
+
const refreshSoon = (sessionId) => {
|
|
1958
|
+
clearTimeout(delayed.get(sessionId));
|
|
1959
|
+
const timer = setTimeout(() => {
|
|
1960
|
+
delayed.delete(sessionId);
|
|
1961
|
+
refresh(sessionId);
|
|
1962
|
+
}, refreshDelayMs);
|
|
1963
|
+
timer.unref?.();
|
|
1964
|
+
delayed.set(sessionId, timer);
|
|
1965
|
+
};
|
|
1966
|
+
const run = async (scope, command) => {
|
|
1695
1967
|
const workspaceRoot = scope.sessionContext?.workspaceRoot ?? scope.cwd;
|
|
1696
|
-
const base = recordedBaseRef(scope);
|
|
1968
|
+
const base = await recordedBaseRef(scope);
|
|
1697
1969
|
const context = {
|
|
1698
1970
|
cwd: scope.cwd,
|
|
1699
|
-
auth: auth.read(workspaceRoot),
|
|
1971
|
+
auth: await auth.read(workspaceRoot),
|
|
1700
1972
|
...base === void 0 ? {} : { recordedBaseRef: base }
|
|
1701
1973
|
};
|
|
1702
1974
|
if (command.action === "pull") return sync.pull(context);
|
|
@@ -1713,12 +1985,14 @@ function createGitChangesChannel(options = {}) {
|
|
|
1713
1985
|
scopes.set(scope.sessionId, scope);
|
|
1714
1986
|
refresh(scope.sessionId);
|
|
1715
1987
|
const unsubscribe = host.directEvents.subscribe(GIT_SESSION_CHANGED_EVENT, scope.sessionId, (payload) => {
|
|
1716
|
-
if (isSessionChangedEvent(payload))
|
|
1988
|
+
if (isSessionChangedEvent(payload)) refreshSoon(scope.sessionId);
|
|
1717
1989
|
});
|
|
1718
1990
|
subscriptions.set(scope.sessionId, unsubscribe);
|
|
1719
1991
|
},
|
|
1720
1992
|
sessionRemoved(sessionId) {
|
|
1721
1993
|
subscriptions.get(sessionId)?.();
|
|
1994
|
+
clearTimeout(delayed.get(sessionId));
|
|
1995
|
+
delayed.delete(sessionId);
|
|
1722
1996
|
subscriptions.delete(sessionId);
|
|
1723
1997
|
scopes.delete(sessionId);
|
|
1724
1998
|
latest.delete(sessionId);
|
|
@@ -1727,6 +2001,8 @@ function createGitChangesChannel(options = {}) {
|
|
|
1727
2001
|
},
|
|
1728
2002
|
close() {
|
|
1729
2003
|
for (const unsubscribe of subscriptions.values()) unsubscribe();
|
|
2004
|
+
for (const timer of delayed.values()) clearTimeout(timer);
|
|
2005
|
+
delayed.clear();
|
|
1730
2006
|
subscriptions.clear();
|
|
1731
2007
|
scopes.clear();
|
|
1732
2008
|
latest.clear();
|
|
@@ -1794,9 +2070,9 @@ function payloadOf(state) {
|
|
|
1794
2070
|
};
|
|
1795
2071
|
}
|
|
1796
2072
|
/** Worktrees visible to this session, using the hub's live session table for ownership. */
|
|
1797
|
-
function viewsFor(scope, deps) {
|
|
2073
|
+
async function viewsFor(scope, deps) {
|
|
1798
2074
|
try {
|
|
1799
|
-
return createWorktreeRegistry(registryFile(scope.cwd, deps.homeDir)).list().flatMap((record) => {
|
|
2075
|
+
return (await createWorktreeRegistry(await registryFile(scope.cwd, deps.homeDir, deps.environment)).list()).flatMap((record) => {
|
|
1800
2076
|
if (record.parentSessionId === void 0 && record.sessionId !== scope.sessionId) return [];
|
|
1801
2077
|
const owned = record.parentSessionId === void 0 || record.parentSessionId === scope.sessionId;
|
|
1802
2078
|
const unowned = !owned && !deps.sessionService.isLive(record.parentSessionId);
|
|
@@ -1821,11 +2097,15 @@ function sameList(left, right) {
|
|
|
1821
2097
|
return other !== void 0 && entry.id === other.id && entry.branch === other.branch && entry.sessionId === other.sessionId && entry.orphaned === other.orphaned && entry.unowned === other.unowned;
|
|
1822
2098
|
});
|
|
1823
2099
|
}
|
|
1824
|
-
function errorTargetFor(command) {
|
|
1825
|
-
|
|
2100
|
+
function errorTargetFor(command, error) {
|
|
2101
|
+
if (command.action === "close") return {
|
|
1826
2102
|
action: "close",
|
|
1827
2103
|
id: command.id
|
|
1828
2104
|
};
|
|
2105
|
+
return error instanceof PoGitExpectedError && error.code === "rift_missing" ? {
|
|
2106
|
+
action: "create",
|
|
2107
|
+
riftMissing: true
|
|
2108
|
+
} : { action: "create" };
|
|
1829
2109
|
}
|
|
1830
2110
|
/** A command the page sent, or undefined when the frame was not one. */
|
|
1831
2111
|
function parseCommand(payload) {
|
|
@@ -1853,11 +2133,15 @@ function parseCommand(payload) {
|
|
|
1853
2133
|
/**
|
|
1854
2134
|
* What the reader is told when a command fails.
|
|
1855
2135
|
*
|
|
1856
|
-
* An expected failure explains itself
|
|
1857
|
-
*
|
|
2136
|
+
* An expected failure explains itself, minus the `[code]` tag and recovery line
|
|
2137
|
+
* written for the agent's tool result. A dirty close is said in the person's
|
|
2138
|
+
* terms, because its message tells the agent to pass `force`. Anything else is
|
|
2139
|
+
* summarised, never echoed: a git error can carry a remote URL with a token in it.
|
|
1858
2140
|
*/
|
|
1859
2141
|
function failureText(error) {
|
|
1860
|
-
|
|
2142
|
+
if (!(error instanceof PoGitExpectedError)) return "The worktree operation failed.";
|
|
2143
|
+
if (error.code === "worktree_dirty") return "The worktree has uncommitted changes.";
|
|
2144
|
+
return error.message.replace(/^\[[a-z_]+\] /u, "").split("\nRecovery:")[0] ?? error.message;
|
|
1861
2145
|
}
|
|
1862
2146
|
/** Starts one direct-event subscription per managed session. */
|
|
1863
2147
|
function createWorktreesChannel(options = {}) {
|
|
@@ -1869,7 +2153,9 @@ function createWorktreesChannel(options = {}) {
|
|
|
1869
2153
|
if (sessionService === void 0) throw new HubUnavailableError("The cockpit session service is unavailable. Start the cockpit and try again.");
|
|
1870
2154
|
const worktrees = options.operations ?? createWorktreeOperations({
|
|
1871
2155
|
git: createWorktreeGit(),
|
|
1872
|
-
sessionService
|
|
2156
|
+
sessionService,
|
|
2157
|
+
...options.homeDir === void 0 ? {} : { homeDir: options.homeDir },
|
|
2158
|
+
...options.environment === void 0 ? {} : { environment: options.environment }
|
|
1873
2159
|
});
|
|
1874
2160
|
/** Announces a successful mutation to this session's lifecycle subscribers. */
|
|
1875
2161
|
const publishLifecycle = (scope, repositoryRoot) => {
|
|
@@ -1898,6 +2184,7 @@ function createWorktreesChannel(options = {}) {
|
|
|
1898
2184
|
});
|
|
1899
2185
|
const views = {
|
|
1900
2186
|
homeDir: options.homeDir,
|
|
2187
|
+
environment: options.environment,
|
|
1901
2188
|
sessionService
|
|
1902
2189
|
};
|
|
1903
2190
|
const latest = /* @__PURE__ */ new Map();
|
|
@@ -1910,10 +2197,13 @@ function createWorktreesChannel(options = {}) {
|
|
|
1910
2197
|
return generation;
|
|
1911
2198
|
};
|
|
1912
2199
|
/** Republishes a session, skipping a frame that would say nothing new. */
|
|
1913
|
-
const publish = (scope, force) => {
|
|
2200
|
+
const publish = async (scope, force) => {
|
|
2201
|
+
const generation = generations.get(scope.sessionId);
|
|
2202
|
+
const worktreeViews = await viewsFor(scope, views);
|
|
2203
|
+
if (generation === void 0 || generations.get(scope.sessionId) !== generation) return;
|
|
1914
2204
|
const previous = latest.get(scope.sessionId);
|
|
1915
2205
|
const next = {
|
|
1916
|
-
worktrees:
|
|
2206
|
+
worktrees: worktreeViews,
|
|
1917
2207
|
pending: previous?.pending,
|
|
1918
2208
|
error: previous?.error,
|
|
1919
2209
|
errorTarget: previous?.errorTarget
|
|
@@ -1925,7 +2215,7 @@ function createWorktreesChannel(options = {}) {
|
|
|
1925
2215
|
const mark = (scope, pending, error, errorTarget) => {
|
|
1926
2216
|
const previous = latest.get(scope.sessionId);
|
|
1927
2217
|
latest.set(scope.sessionId, {
|
|
1928
|
-
worktrees: previous?.worktrees ??
|
|
2218
|
+
worktrees: previous?.worktrees ?? [],
|
|
1929
2219
|
pending,
|
|
1930
2220
|
error,
|
|
1931
2221
|
errorTarget
|
|
@@ -1965,15 +2255,15 @@ function createWorktreesChannel(options = {}) {
|
|
|
1965
2255
|
sessionAdded(scope) {
|
|
1966
2256
|
newGeneration(scope.sessionId);
|
|
1967
2257
|
publish(scope, false);
|
|
1968
|
-
const unsubscribe = host.directEvents.subscribe(GIT_WORKTREE_LIFECYCLE_EVENT, scope.sessionId, (payload) => {
|
|
2258
|
+
const unsubscribe = host.directEvents.subscribe(GIT_WORKTREE_LIFECYCLE_EVENT, scope.sessionId, async (payload) => {
|
|
1969
2259
|
if (!isWorktreeLifecycleEvent(payload)) return;
|
|
1970
2260
|
let sameRepository = false;
|
|
1971
2261
|
try {
|
|
1972
|
-
sameRepository = registryFile(scope.cwd, options.homeDir) === registryFile(payload.repositoryRoot, options.homeDir);
|
|
2262
|
+
sameRepository = await registryFile(scope.cwd, options.homeDir, options.environment) === await registryFile(payload.repositoryRoot, options.homeDir, options.environment);
|
|
1973
2263
|
} catch {
|
|
1974
2264
|
sameRepository = false;
|
|
1975
2265
|
}
|
|
1976
|
-
if (sameRepository) publish(scope, false);
|
|
2266
|
+
if (sameRepository) await publish(scope, false);
|
|
1977
2267
|
});
|
|
1978
2268
|
subscriptions.set(scope.sessionId, unsubscribe);
|
|
1979
2269
|
},
|
|
@@ -2006,7 +2296,7 @@ function createWorktreesChannel(options = {}) {
|
|
|
2006
2296
|
}).catch((error) => {
|
|
2007
2297
|
if (generations.get(scope.sessionId) !== generation) return;
|
|
2008
2298
|
host.onNotice(`worktree command failed for ${scope.sessionId} (${failureText(error)})`);
|
|
2009
|
-
mark(scope, void 0, failureText(error), errorTargetFor(command));
|
|
2299
|
+
mark(scope, void 0, failureText(error), errorTargetFor(command, error));
|
|
2010
2300
|
}).finally(() => {
|
|
2011
2301
|
if (generations.get(scope.sessionId) === generation) busy.delete(scope.sessionId);
|
|
2012
2302
|
});
|
|
@@ -2028,20 +2318,8 @@ var agent_settled_server_default = defineHook((context) => context.root.hooks[1]
|
|
|
2028
2318
|
//#region src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server.ts
|
|
2029
2319
|
var tool_execution_end_server_default = defineHook((context) => context.root.hooks[0]);
|
|
2030
2320
|
//#endregion
|
|
2031
|
-
//#region src/extensions/workspaces/sessions/(backend)/resource/_lib/poGit.server.ts
|
|
2032
|
-
var poGit_server_default$1 = (context) => context.root.resources[0];
|
|
2033
|
-
//#endregion
|
|
2034
|
-
//#region src/extensions/workspaces/sessions/(backend)/resource/poGit.server.ts
|
|
2035
|
-
var poGit_server_default = defineResource(poGit_server_default$1);
|
|
2036
|
-
//#endregion
|
|
2037
|
-
//#region src/extensions/workspaces/sessions/(backend)/resource/_lib/poGitReadme.server.ts
|
|
2038
|
-
var poGitReadme_server_default$1 = (context) => context.root.resources[2];
|
|
2039
|
-
//#endregion
|
|
2040
|
-
//#region src/extensions/workspaces/sessions/(backend)/resource/poGitReadme.server.ts
|
|
2041
|
-
var poGitReadme_server_default = defineResource(poGitReadme_server_default$1);
|
|
2042
|
-
//#endregion
|
|
2043
2321
|
//#region src/extensions/workspaces/sessions/(backend)/resource/_lib/poUseGit.server.ts
|
|
2044
|
-
var poUseGit_server_default$1 = (context) => context.root.resources[
|
|
2322
|
+
var poUseGit_server_default$1 = (context) => context.root.resources[0];
|
|
2045
2323
|
//#endregion
|
|
2046
2324
|
//#region src/extensions/workspaces/sessions/(backend)/resource/poUseGit.server.ts
|
|
2047
2325
|
var poUseGit_server_default = defineResource(poUseGit_server_default$1);
|
|
@@ -2061,12 +2339,12 @@ const serverPlugin = defineServerPlugin({
|
|
|
2061
2339
|
name: "@agimon-ai/po-git",
|
|
2062
2340
|
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
2063
2341
|
injects: composeRootInjects({ session: [root_server_default] }),
|
|
2064
|
-
|
|
2342
|
+
host: (context) => ({
|
|
2065
2343
|
get api() {
|
|
2066
2344
|
return [at(route_server_default, context)];
|
|
2067
2345
|
},
|
|
2068
2346
|
get channels() {
|
|
2069
|
-
return [() => via({ frameType: "git_changes" }, git_changes_server_default
|
|
2347
|
+
return [() => via({ frameType: "git_changes" }, at(git_changes_server_default, context)), () => via({ frameType: "git_worktrees" }, at(git_worktrees_server_default, context))];
|
|
2070
2348
|
}
|
|
2071
2349
|
}),
|
|
2072
2350
|
workspace: (context) => ({
|
|
@@ -2074,7 +2352,7 @@ const serverPlugin = defineServerPlugin({
|
|
|
2074
2352
|
return [at(route_server_default, context)];
|
|
2075
2353
|
},
|
|
2076
2354
|
get channels() {
|
|
2077
|
-
return defined([context.hosted("
|
|
2355
|
+
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))]);
|
|
2078
2356
|
}
|
|
2079
2357
|
}),
|
|
2080
2358
|
session: async (context) => {
|
|
@@ -2089,17 +2367,13 @@ const serverPlugin = defineServerPlugin({
|
|
|
2089
2367
|
return [at(route_server_default, context)];
|
|
2090
2368
|
},
|
|
2091
2369
|
get channels() {
|
|
2092
|
-
return defined([context.hosted("
|
|
2370
|
+
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))]);
|
|
2093
2371
|
},
|
|
2094
2372
|
get hooks() {
|
|
2095
2373
|
return [via({ event: "agent_settled" }, at(agent_settled_server_default, contextSession)), via({ event: "tool_execution_end" }, at(tool_execution_end_server_default, contextSession))];
|
|
2096
2374
|
},
|
|
2097
2375
|
get resources() {
|
|
2098
|
-
return [
|
|
2099
|
-
at(poGit_server_default, contextSession),
|
|
2100
|
-
at(poGitReadme_server_default, contextSession),
|
|
2101
|
-
at(poUseGit_server_default, contextSession)
|
|
2102
|
-
];
|
|
2376
|
+
return [at(poUseGit_server_default, contextSession)];
|
|
2103
2377
|
},
|
|
2104
2378
|
get tools() {
|
|
2105
2379
|
return [via({ name: "run_worktree" }, at(runWorktree_server_default, contextSession))];
|