@kenkaiiii/ggcoder 5.109.0 → 6.0.1
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 +1 -1
- package/assets/skills/gg-guide/references/code-mode.md +3 -0
- package/dist/app-sidecar/branch-routes.d.ts +42 -0
- package/dist/app-sidecar/branch-routes.js +189 -0
- package/dist/app-sidecar/branch-routes.js.map +1 -0
- package/dist/app-sidecar/git-branches.d.ts +81 -0
- package/dist/app-sidecar/git-branches.js +270 -0
- package/dist/app-sidecar/git-branches.js.map +1 -0
- package/dist/app-sidecar/history-routes.js +3 -0
- package/dist/app-sidecar/history-routes.js.map +1 -1
- package/dist/app-sidecar/history.d.ts +2 -0
- package/dist/app-sidecar/history.js.map +1 -1
- package/dist/app-sidecar/repo-polls.d.ts +3 -1
- package/dist/app-sidecar/repo-polls.js +9 -1
- package/dist/app-sidecar/repo-polls.js.map +1 -1
- package/dist/app-sidecar/route-context.d.ts +1 -0
- package/dist/app-sidecar/session-types.d.ts +5 -0
- package/dist/app-sidecar/workspace-routes.js +12 -2
- package/dist/app-sidecar/workspace-routes.js.map +1 -1
- package/dist/app-sidecar/worktrees.d.ts +100 -0
- package/dist/app-sidecar/worktrees.js +260 -0
- package/dist/app-sidecar/worktrees.js.map +1 -0
- package/dist/app-sidecar-sessions.d.ts +3 -1
- package/dist/app-sidecar-sessions.js +6 -4
- package/dist/app-sidecar-sessions.js.map +1 -1
- package/dist/app-sidecar.js +159 -7
- package/dist/app-sidecar.js.map +1 -1
- package/dist/core/agent-session.d.ts +79 -0
- package/dist/core/agent-session.js +206 -46
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/checkout-record.d.ts +22 -0
- package/dist/core/checkout-record.js +68 -0
- package/dist/core/checkout-record.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +2 -0
- package/dist/core/claude-code/events.js +27 -2
- package/dist/core/claude-code/events.js.map +1 -1
- package/dist/core/claude-code/live-session.d.ts +2 -0
- package/dist/core/claude-code/live-session.js +7 -1
- package/dist/core/claude-code/live-session.js.map +1 -1
- package/dist/core/compaction/tool-result-pruner.d.ts +11 -0
- package/dist/core/compaction/tool-result-pruner.js +26 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -1
- package/dist/core/destructive-git-guard.d.ts +23 -0
- package/dist/core/destructive-git-guard.js +11 -8
- package/dist/core/destructive-git-guard.js.map +1 -1
- package/dist/core/event-bus.d.ts +11 -0
- package/dist/core/event-bus.js +10 -0
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/lsp/servers.js +1 -1
- package/dist/core/project-discovery.d.ts +3 -1
- package/dist/core/project-discovery.js +5 -3
- package/dist/core/project-discovery.js.map +1 -1
- package/dist/core/regrounding.d.ts +9 -1
- package/dist/core/regrounding.js +46 -6
- package/dist/core/regrounding.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/shared-checkout-guard.d.ts +78 -0
- package/dist/core/shared-checkout-guard.js +219 -0
- package/dist/core/shared-checkout-guard.js.map +1 -0
- package/dist/modes/subagent-worker-mode.js +4 -0
- package/dist/modes/subagent-worker-mode.js.map +1 -1
- package/dist/system-prompt.js +3 -1
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/ask-user.js +2 -1
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/bash.d.ts +3 -1
- package/dist/tools/bash.js +19 -7
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/enter-plan.js +2 -1
- package/dist/tools/enter-plan.js.map +1 -1
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/prompt-hints.js +1 -1
- package/dist/tools/prompt-hints.js.map +1 -1
- package/dist/ui/App.js +2 -2
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/hooks/useAgentLoop.d.ts +1 -1
- package/dist/ui/hooks/useAgentLoop.js +10 -1
- package/dist/ui/hooks/useAgentLoop.js.map +1 -1
- package/dist/utils/git.d.ts +7 -0
- package/dist/utils/git.js +12 -1
- package/dist/utils/git.js.map +1 -1
- package/package.json +12 -12
|
@@ -22,7 +22,9 @@ async function listChatSessions(cwd, sessionsDir) {
|
|
|
22
22
|
* `homeDir` only exists so tests can point the Claude Code / Codex lookup at a
|
|
23
23
|
* fixture home; production always uses the real one.
|
|
24
24
|
*/
|
|
25
|
-
export async function listSidecarSessions(cwd, requestedAgent, coderSessionsDir, homeDir
|
|
25
|
+
export async function listSidecarSessions(cwd, requestedAgent, coderSessionsDir, homeDir,
|
|
26
|
+
/** The project's GG-made worktrees: their conversations are listed with it. */
|
|
27
|
+
worktreeCwds = []) {
|
|
26
28
|
if (requestedAgent === MOTION_SESSIONS_QUERY) {
|
|
27
29
|
return listRecentSessions(cwd, MOTION_SESSION_LIMIT, motionSessionsDir(coderSessionsDir));
|
|
28
30
|
}
|
|
@@ -33,7 +35,7 @@ export async function listSidecarSessions(cwd, requestedAgent, coderSessionsDir,
|
|
|
33
35
|
const sessions = await listChatSessions(cwd, sessionsDirForChatAgent(coderSessionsDir, requestedAgent));
|
|
34
36
|
return sessions.slice(0, CHAT_SESSION_LIMIT);
|
|
35
37
|
}
|
|
36
|
-
return listCodingSessions(cwd, coderSessionsDir, homeDir);
|
|
38
|
+
return listCodingSessions(cwd, coderSessionsDir, homeDir, worktreeCwds);
|
|
37
39
|
}
|
|
38
40
|
const groups = await Promise.all(CHAT_AGENT_IDS.map(async (agentId) => {
|
|
39
41
|
const sessions = await listChatSessions(cwd, chatAgentSessionsDir(coderSessionsDir, agentId));
|
|
@@ -62,9 +64,9 @@ export async function listSidecarSessions(cwd, requestedAgent, coderSessionsDir,
|
|
|
62
64
|
* A foreign store being slow or unreadable must never empty the native list,
|
|
63
65
|
* so its failure degrades to "no foreign rows".
|
|
64
66
|
*/
|
|
65
|
-
async function listCodingSessions(cwd, coderSessionsDir, homeDir) {
|
|
67
|
+
async function listCodingSessions(cwd, coderSessionsDir, homeDir, worktreeCwds = []) {
|
|
66
68
|
const [native, foreign] = await Promise.all([
|
|
67
|
-
listRecentSessions(cwd, CODING_SESSION_LIMIT, coderSessionsDir),
|
|
69
|
+
listRecentSessions(cwd, CODING_SESSION_LIMIT, coderSessionsDir, worktreeCwds),
|
|
68
70
|
listForeignSessions(cwd, FOREIGN_SESSION_LIMIT, homeDir).catch(() => []),
|
|
69
71
|
]);
|
|
70
72
|
// Native first: a session already resumable here beats one that needs an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-sidecar-sessions.js","sourceRoot":"","sources":["../src/app-sidecar-sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,GAExB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GAEnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAE1F,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,kFAAkF;AAClF,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAIhC,wFAAwF;AACxF,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACpF,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,GAAW,EAAE,WAAmB;IAC9D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B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
|
|
49
49
|
import { SettingsManager } from "./core/settings-manager.js";
|
|
50
50
|
import { getModel, withoutPaidTier, getDefaultThinkingLevel, getContextWindow, clearRuntimeModels, registerRuntimeModels, } from "./core/model-registry.js";
|
|
51
51
|
import { resolveStartOrFallback } from "./core/resolve-start.js";
|
|
52
|
-
import { getGitBranch, getGitDirtyFileCount, isGitRepo } from "./utils/git.js";
|
|
52
|
+
import { getGitBranch, getGitDirtyFileCount, isGitRepo, realpathNative } from "./utils/git.js";
|
|
53
|
+
import { anyOtherWindowBusyOnCheckout, branchChangeNote, countOtherWindowsOnCheckout, checkoutRoot, describeOtherWindows, } from "./core/shared-checkout-guard.js";
|
|
53
54
|
import { scoreProjectHealth } from "./core/project-health-score.js";
|
|
54
55
|
import { createRepoPolls } from "./app-sidecar/repo-polls.js";
|
|
55
56
|
import { extractPlanSteps, stepsDoneThrough } from "./utils/plan-steps.js";
|
|
@@ -84,6 +85,10 @@ import { handleWorkspaceRoutes } from "./app-sidecar/workspace-routes.js";
|
|
|
84
85
|
import { handleHistoryRoutes } from "./app-sidecar/history-routes.js";
|
|
85
86
|
import { handlePromptRoutes } from "./app-sidecar/prompt-routes.js";
|
|
86
87
|
import { handleTaskRoutes } from "./app-sidecar/task-routes.js";
|
|
88
|
+
import { handleBranchRoutes } from "./app-sidecar/branch-routes.js";
|
|
89
|
+
import { resolveResumeCheckout } from "./app-sidecar/git-branches.js";
|
|
90
|
+
import { WorktreeSetups, mainCheckoutOf, resolveSetupCommand, setupNote, } from "./app-sidecar/worktrees.js";
|
|
91
|
+
import { readCheckoutRecord } from "./core/checkout-record.js";
|
|
87
92
|
import { handleRunControlRoutes } from "./app-sidecar/run-control-routes.js";
|
|
88
93
|
import { handleAuthRoutes } from "./app-sidecar/auth-routes.js";
|
|
89
94
|
import { handleIntegrationRoutes } from "./app-sidecar/integration-routes.js";
|
|
@@ -220,6 +225,15 @@ async function main() {
|
|
|
220
225
|
// request to its window's session via the `x-gg-session` header (and the
|
|
221
226
|
// `?session=` query for the SSE /events stream).
|
|
222
227
|
const sessions = new Map();
|
|
228
|
+
// A window that moved into a worktree resumes its conversation in a new
|
|
229
|
+
// session there; this note (keyed by that conversation file) tells its agent.
|
|
230
|
+
const pendingMoveNotes = new Map();
|
|
231
|
+
// New worktrees (real paths) whose setup runs once a window opens in them.
|
|
232
|
+
const pendingSetups = new Set();
|
|
233
|
+
// Setups running (or still stopping) in new worktrees; removal waits on them.
|
|
234
|
+
const worktreeSetups = new WorktreeSetups();
|
|
235
|
+
// Chat rows for conversations that reopened somewhere new for their branch.
|
|
236
|
+
const pendingCheckoutNotices = new Map();
|
|
223
237
|
/**
|
|
224
238
|
* Fan one frame out to every window.
|
|
225
239
|
*
|
|
@@ -256,6 +270,14 @@ async function main() {
|
|
|
256
270
|
};
|
|
257
271
|
/** Apply a saved MCP server change to every open window, no restart needed. */
|
|
258
272
|
const syncMcpServer = (name) => syncMcpServerAcross(sessions.values(), name, paths.settingsFile);
|
|
273
|
+
/** How many live windows other than `selfId` use the git checkout rooted at `root`. */
|
|
274
|
+
const otherWindowsOnCheckout = (root, selfId) => countOtherWindowsOnCheckout([...sessions.values()].map((ctx) => ({ id: ctx.id, gitDir: ctx.gitDir?.() ?? null })), selfId, root);
|
|
275
|
+
/** Whether a live window other than `selfId` on the checkout rooted at `root` is working. */
|
|
276
|
+
const otherWindowBusyOnCheckout = (root, selfId) => anyOtherWindowBusyOnCheckout([...sessions.values()].map((ctx) => ({
|
|
277
|
+
id: ctx.id,
|
|
278
|
+
gitDir: ctx.gitDir?.() ?? null,
|
|
279
|
+
isBusy: ctx.isBusy,
|
|
280
|
+
})), selfId, root);
|
|
259
281
|
/** Whether any live window session in `cwd` is working right now. */
|
|
260
282
|
const busyAt = (cwd) => {
|
|
261
283
|
const target = path.resolve(cwd);
|
|
@@ -317,6 +339,12 @@ async function main() {
|
|
|
317
339
|
repoPolls,
|
|
318
340
|
sessionIdsAt,
|
|
319
341
|
busyAt,
|
|
342
|
+
otherWindowsOnCheckout,
|
|
343
|
+
otherWindowBusyOnCheckout,
|
|
344
|
+
pendingMoveNotes,
|
|
345
|
+
pendingSetups,
|
|
346
|
+
worktreeSetups,
|
|
347
|
+
pendingCheckoutNotices,
|
|
320
348
|
syncMcpServer,
|
|
321
349
|
// The preview's own session has no window to preview from.
|
|
322
350
|
...(preview
|
|
@@ -419,11 +447,37 @@ async function main() {
|
|
|
419
447
|
}
|
|
420
448
|
const mode = parseWorkspaceMode(body.mode);
|
|
421
449
|
const chatAgent = parseChatAgentId(body.chatAgent);
|
|
422
|
-
const
|
|
450
|
+
const requestedCwd = typeof body.cwd === "string" && body.cwd
|
|
423
451
|
? body.cwd
|
|
424
452
|
: (process.env.GG_APP_CWD ?? process.cwd());
|
|
425
453
|
const sessionPath = typeof body.sessionPath === "string" && body.sessionPath ? body.sessionPath : undefined;
|
|
426
454
|
try {
|
|
455
|
+
// A resumed conversation comes back where its branch is checked out,
|
|
456
|
+
// even if the project's folder has moved to another branch since. It
|
|
457
|
+
// never creates a worktree (hooks, setup) on its own; see resolveResumeCheckout.
|
|
458
|
+
let sessionCwd = requestedCwd;
|
|
459
|
+
if (mode === "code" &&
|
|
460
|
+
sessionPath &&
|
|
461
|
+
!isGoalDir(goalsRoot(paths.agentDir), requestedCwd)) {
|
|
462
|
+
const record = await readCheckoutRecord(sessionPath);
|
|
463
|
+
if (record) {
|
|
464
|
+
const resumed = await resolveResumeCheckout(requestedCwd, record).catch((error) => {
|
|
465
|
+
log("WARN", "app-sidecar", "resume checkout failed", { error: String(error) });
|
|
466
|
+
return { cwd: requestedCwd, note: null, notice: null };
|
|
467
|
+
});
|
|
468
|
+
sessionCwd = resumed.cwd;
|
|
469
|
+
if (resumed.note)
|
|
470
|
+
pendingMoveNotes.set(sessionPath, resumed.note);
|
|
471
|
+
if (resumed.notice)
|
|
472
|
+
pendingCheckoutNotices.set(sessionPath, resumed.notice);
|
|
473
|
+
if (sessionCwd !== requestedCwd) {
|
|
474
|
+
log("INFO", "app-sidecar", "resuming on its recorded branch", {
|
|
475
|
+
branch: record.branch,
|
|
476
|
+
cwd: sessionCwd,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
427
481
|
const ctx = await openSession({ mode, chatAgent, cwd: sessionCwd, sessionPath });
|
|
428
482
|
// The conversation file too, so the app can reopen this exact
|
|
429
483
|
// session if the daemon restarts (a new session has no path yet
|
|
@@ -431,6 +485,7 @@ async function main() {
|
|
|
431
485
|
daemonJson(res, 200, {
|
|
432
486
|
sessionId: ctx.id,
|
|
433
487
|
sessionPath: ctx.session.getState().sessionPath ?? null,
|
|
488
|
+
cwd: sessionCwd,
|
|
434
489
|
});
|
|
435
490
|
}
|
|
436
491
|
catch (err) {
|
|
@@ -625,7 +680,7 @@ let lastLocalScanSummary;
|
|
|
625
680
|
* logger, PATH, shared auth file, and radio live at the daemon level.
|
|
626
681
|
*/
|
|
627
682
|
async function createSession(deps, opts) {
|
|
628
|
-
const { auth, progress, trophies, memoryStore, jiwaStore, broadcastAll, oauthInFlightProviders, repoPolls, sessionIdsAt, busyAt, syncMcpServer, } = deps;
|
|
683
|
+
const { auth, progress, trophies, memoryStore, jiwaStore, broadcastAll, oauthInFlightProviders, repoPolls, sessionIdsAt, busyAt, syncMcpServer, otherWindowsOnCheckout, otherWindowBusyOnCheckout, pendingMoveNotes, pendingSetups, worktreeSetups, pendingCheckoutNotices, } = deps;
|
|
629
684
|
const paths = deps.paths;
|
|
630
685
|
const mode = opts.mode;
|
|
631
686
|
let chatAgent = opts.chatAgent;
|
|
@@ -867,6 +922,8 @@ async function createSession(deps, opts) {
|
|
|
867
922
|
// window (project picker, session list) — whenever a resumed session was
|
|
868
923
|
// over the context threshold. First prompt compacts instead, with UI events.
|
|
869
924
|
deferLoadCompaction: true,
|
|
925
|
+
// Refuse a branch switch in a checkout another window also uses.
|
|
926
|
+
getCheckoutSharers: async (root) => describeOtherWindows(await otherWindowsOnCheckout(root, opts.id)),
|
|
870
927
|
};
|
|
871
928
|
let session;
|
|
872
929
|
if (mode === "chat") {
|
|
@@ -964,6 +1021,21 @@ async function createSession(deps, opts) {
|
|
|
964
1021
|
});
|
|
965
1022
|
}
|
|
966
1023
|
await session.initialize();
|
|
1024
|
+
// This window just moved into a worktree (Git panel branch picker): tell the
|
|
1025
|
+
// agent where it now works before its next turn.
|
|
1026
|
+
const moveNote = resumeSessionPath ? pendingMoveNotes.get(resumeSessionPath) : undefined;
|
|
1027
|
+
if (resumeSessionPath && moveNote) {
|
|
1028
|
+
pendingMoveNotes.delete(resumeSessionPath);
|
|
1029
|
+
session.notify("worktree-move", moveNote);
|
|
1030
|
+
}
|
|
1031
|
+
// Reopened somewhere new for its branch: the user sees why, in the chat.
|
|
1032
|
+
const checkoutNotice = resumeSessionPath
|
|
1033
|
+
? pendingCheckoutNotices.get(resumeSessionPath)
|
|
1034
|
+
: undefined;
|
|
1035
|
+
if (resumeSessionPath && checkoutNotice) {
|
|
1036
|
+
pendingCheckoutNotices.delete(resumeSessionPath);
|
|
1037
|
+
session.noteCheckout(checkoutNotice);
|
|
1038
|
+
}
|
|
967
1039
|
// A goal's attached folders join its workspace so the coordinator can read
|
|
968
1040
|
// them. A resumed session may already carry them; `addDirectory` skips those.
|
|
969
1041
|
if (goal) {
|
|
@@ -1153,7 +1225,13 @@ async function createSession(deps, opts) {
|
|
|
1153
1225
|
const initialTarget = await resolveGitCwd(cwd, goal?.record ?? null);
|
|
1154
1226
|
let gitCwd = initialTarget.dir;
|
|
1155
1227
|
const initialGit = await readGitState(gitCwd);
|
|
1228
|
+
// Which repository this checkout belongs to when it is a linked worktree,
|
|
1229
|
+
// so Home opens on the project rather than the worktree folder.
|
|
1230
|
+
const worktreeOf = initialGit.isRepo
|
|
1231
|
+
? await Promise.all([mainCheckoutOf(gitCwd), checkoutRoot(gitCwd)]).then(([main, own]) => main && own && main !== own ? main : null)
|
|
1232
|
+
: null;
|
|
1156
1233
|
let gitBranch = initialGit.branch;
|
|
1234
|
+
/** The repository's main folder when this window works in a linked worktree. */
|
|
1157
1235
|
let gitIsRepo = initialGit.isRepo;
|
|
1158
1236
|
let gitDirtyFileCount = initialGit.dirtyFileCount;
|
|
1159
1237
|
// Open issue/PR counts for the origin repo's GitHub slug, via the `gh` CLI's
|
|
@@ -1199,6 +1277,7 @@ async function createSession(deps, opts) {
|
|
|
1199
1277
|
tasks: session.listBackgroundProcesses(),
|
|
1200
1278
|
// Roots added with /add-dir — the header shows a badge when non-empty.
|
|
1201
1279
|
additionalRoots: session.getAdditionalRoots(),
|
|
1280
|
+
worktreeOf,
|
|
1202
1281
|
};
|
|
1203
1282
|
}
|
|
1204
1283
|
// Startup resolves the model before discovery runs, so a saved local model
|
|
@@ -1405,6 +1484,7 @@ async function createSession(deps, opts) {
|
|
|
1405
1484
|
session.eventBus.on("diagnostics", (d) => broadcast("diagnostics", d));
|
|
1406
1485
|
session.eventBus.on("security_notice", (d) => broadcast("security_notice", d));
|
|
1407
1486
|
session.eventBus.on("security_block", (d) => broadcast("security_block", d));
|
|
1487
|
+
session.eventBus.on("checkout_notice", (d) => broadcast("checkout_notice", d));
|
|
1408
1488
|
// Fires BEFORE the candidate final answer streams. The webview holds assistant
|
|
1409
1489
|
// text back while armed, so an injected follow-up supersedes a draft that was never
|
|
1410
1490
|
// painted instead of deleting one the user already started reading.
|
|
@@ -2246,6 +2326,22 @@ async function createSession(deps, opts) {
|
|
|
2246
2326
|
// every other window on the same repo; each window broadcasts only changes.
|
|
2247
2327
|
function watchRepo(dir) {
|
|
2248
2328
|
const repoKey = path.resolve(dir);
|
|
2329
|
+
// Every window on a shared checkout follows its branch live, and its agent
|
|
2330
|
+
// is told: it would otherwise keep editing and committing on a branch
|
|
2331
|
+
// another window (or the user) switched to underneath it.
|
|
2332
|
+
const branch = repoPolls.branch.subscribe(repoKey, (next) => {
|
|
2333
|
+
if (next === null || next === gitBranch)
|
|
2334
|
+
return;
|
|
2335
|
+
const previous = gitBranch;
|
|
2336
|
+
gitBranch = next;
|
|
2337
|
+
broadcast("extras", footerExtras());
|
|
2338
|
+
if (previous)
|
|
2339
|
+
session.notify("git-branch", branchChangeNote(previous, next));
|
|
2340
|
+
// The conversation is on this branch now; resuming it should come back here.
|
|
2341
|
+
void checkoutRoot(gitCwd)
|
|
2342
|
+
.then((root) => (root ? session.recordCheckout({ branch: next, cwd: root }) : undefined))
|
|
2343
|
+
.catch(() => { });
|
|
2344
|
+
});
|
|
2249
2345
|
const dirtyFiles = repoPolls.dirtyFiles.subscribe(repoKey, (next) => {
|
|
2250
2346
|
if (next === gitDirtyFileCount)
|
|
2251
2347
|
return;
|
|
@@ -2283,6 +2379,7 @@ async function createSession(deps, opts) {
|
|
|
2283
2379
|
ci,
|
|
2284
2380
|
health,
|
|
2285
2381
|
unsubscribe() {
|
|
2382
|
+
branch.unsubscribe();
|
|
2286
2383
|
dirtyFiles.unsubscribe();
|
|
2287
2384
|
gitHubCounts?.unsubscribe();
|
|
2288
2385
|
ci.unsubscribe();
|
|
@@ -2571,6 +2668,61 @@ async function createSession(deps, opts) {
|
|
|
2571
2668
|
serveController = v;
|
|
2572
2669
|
},
|
|
2573
2670
|
};
|
|
2671
|
+
const isBusy = () => running ||
|
|
2672
|
+
runClaim.active ||
|
|
2673
|
+
autopilotActive ||
|
|
2674
|
+
session.listSubAgents().some((w) => w.state === "running" || w.state === "starting");
|
|
2675
|
+
const branchCtx = {
|
|
2676
|
+
gitDir: () => gitCwd,
|
|
2677
|
+
isBusy,
|
|
2678
|
+
canMove: () => mode === "code" && goal === null,
|
|
2679
|
+
sessionPath: () => session.getState().sessionPath ?? null,
|
|
2680
|
+
sharedWith: async (root) => describeOtherWindows(await otherWindowsOnCheckout(root, opts.id)),
|
|
2681
|
+
worktreesRoot: path.join(paths.agentDir, "worktrees"),
|
|
2682
|
+
onSwitched: (branch, previous) => {
|
|
2683
|
+
gitBranch = branch;
|
|
2684
|
+
broadcast("extras", footerExtras());
|
|
2685
|
+
session.notify("git-branch", previous
|
|
2686
|
+
? `${branchChangeNote(previous, branch)} The user switched it from the Git panel.`
|
|
2687
|
+
: `The user switched this checkout to branch \`${branch}\` from the Git panel.`);
|
|
2688
|
+
},
|
|
2689
|
+
queueMoveNote: (sessionPath, note) => pendingMoveNotes.set(sessionPath, note),
|
|
2690
|
+
recordCheckout: (record) => session.recordCheckout(record),
|
|
2691
|
+
queueSetup: async (worktreePath) => {
|
|
2692
|
+
pendingSetups.add(await realpathNative(worktreePath).catch(() => worktreePath));
|
|
2693
|
+
},
|
|
2694
|
+
windowsIn: (root) => otherWindowsOnCheckout(root, ""),
|
|
2695
|
+
othersBusyIn: (root) => otherWindowBusyOnCheckout(root, opts.id),
|
|
2696
|
+
setupRunningIn: (worktreePath) => worktreeSetups.stillRunning(worktreePath),
|
|
2697
|
+
};
|
|
2698
|
+
// A brand-new worktree runs its setup (install) once, as a background task
|
|
2699
|
+
// the user and the agent can both see, the first time a window opens in it.
|
|
2700
|
+
async function startPendingWorktreeSetup() {
|
|
2701
|
+
const real = await realpathNative(gitCwd).catch(() => gitCwd);
|
|
2702
|
+
if (!pendingSetups.delete(real))
|
|
2703
|
+
return;
|
|
2704
|
+
const setup = await resolveSetupCommand(real).catch(() => null);
|
|
2705
|
+
const started = setup
|
|
2706
|
+
? await session.startBackgroundProcess(setup.command, real).catch((error) => {
|
|
2707
|
+
log("WARN", "app-sidecar", "worktree setup failed to start", { error: String(error) });
|
|
2708
|
+
return null;
|
|
2709
|
+
})
|
|
2710
|
+
: null;
|
|
2711
|
+
if (started) {
|
|
2712
|
+
await worktreeSetups.started(real, started.pid);
|
|
2713
|
+
log("INFO", "app-sidecar", "worktree setup started", { command: setup?.command ?? "" });
|
|
2714
|
+
}
|
|
2715
|
+
session.notify("worktree-setup", setupNote(setup, started?.id ?? null));
|
|
2716
|
+
broadcast("extras", footerExtras());
|
|
2717
|
+
}
|
|
2718
|
+
void startPendingWorktreeSetup();
|
|
2719
|
+
// Remember the branch this conversation starts on, so reopening it later
|
|
2720
|
+
// (from Home, or after a restart) comes back to it.
|
|
2721
|
+
if (mode === "code" && goal === null) {
|
|
2722
|
+
void checkoutRoot(gitCwd)
|
|
2723
|
+
.then((root) => root && gitBranch ? session.recordCheckout({ branch: gitBranch, cwd: root }) : undefined)
|
|
2724
|
+
.catch(() => { });
|
|
2725
|
+
}
|
|
2574
2726
|
// OPTIONS/CORS preflight is handled at the daemon level before delegation.
|
|
2575
2727
|
function handle(req, res, url, method) {
|
|
2576
2728
|
if (handleSessionRoutes(routeCtx, req, res, url, method))
|
|
@@ -2585,6 +2737,8 @@ async function createSession(deps, opts) {
|
|
|
2585
2737
|
return;
|
|
2586
2738
|
if (handleTaskRoutes(routeCtx, req, res, url, method))
|
|
2587
2739
|
return;
|
|
2740
|
+
if (handleBranchRoutes(branchCtx, req, res, url, method))
|
|
2741
|
+
return;
|
|
2588
2742
|
if (handleRunControlRoutes(routeCtx, req, res, url, method))
|
|
2589
2743
|
return;
|
|
2590
2744
|
if (handleAuthRoutes(routeCtx, req, res, url, method))
|
|
@@ -2648,10 +2802,8 @@ async function createSession(deps, opts) {
|
|
|
2648
2802
|
handle,
|
|
2649
2803
|
dispose,
|
|
2650
2804
|
stopBackgroundProcesses,
|
|
2651
|
-
isBusy
|
|
2652
|
-
|
|
2653
|
-
autopilotActive ||
|
|
2654
|
-
session.listSubAgents().some((w) => w.state === "running" || w.state === "starting"),
|
|
2805
|
+
isBusy,
|
|
2806
|
+
gitDir: () => gitCwd,
|
|
2655
2807
|
};
|
|
2656
2808
|
}
|
|
2657
2809
|
main().catch(async (err) => {
|