@kenkaiiii/ggcoder 6.1.0 → 6.2.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/assets/skills/gg-guide/SKILL.md +15 -14
- package/assets/skills/gg-guide/references/chat-motion-goals.md +43 -32
- package/assets/skills/gg-guide/references/checklist-and-safety.md +6 -5
- package/assets/skills/gg-guide/references/code-mode.md +21 -19
- package/assets/skills/gg-guide/references/getting-started.md +167 -71
- package/assets/skills/gg-guide/references/ken-and-autopilot.md +28 -24
- package/assets/skills/gg-guide/references/mcp-and-skills.md +23 -15
- package/assets/skills/gg-guide/references/models-and-sign-in.md +25 -26
- package/assets/skills/gg-guide/references/sessions-and-history.md +32 -18
- package/assets/skills/gg-guide/references/settings.md +85 -61
- package/assets/skills/gg-guide/references/troubleshooting-and-data.md +17 -3
- package/dist/app-sidecar/detached-sessions.d.ts +41 -0
- package/dist/app-sidecar/detached-sessions.js +72 -0
- package/dist/app-sidecar/detached-sessions.js.map +1 -0
- package/dist/app-sidecar/session-file-routes.d.ts +44 -0
- package/dist/app-sidecar/session-file-routes.js +175 -0
- package/dist/app-sidecar/session-file-routes.js.map +1 -0
- package/dist/app-sidecar/workspace-routes.d.ts +6 -0
- package/dist/app-sidecar/workspace-routes.js +35 -1
- package/dist/app-sidecar/workspace-routes.js.map +1 -1
- package/dist/app-sidecar.js +70 -31
- package/dist/app-sidecar.js.map +1 -1
- package/dist/core/agent-session.d.ts +6 -0
- package/dist/core/agent-session.js +19 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/claude-code/transcripts.d.ts +15 -5
- package/dist/core/claude-code/transcripts.js +90 -12
- package/dist/core/claude-code/transcripts.js.map +1 -1
- package/dist/core/project-discovery.js +17 -6
- package/dist/core/project-discovery.js.map +1 -1
- package/dist/core/subagent-manager.js +5 -2
- package/dist/core/subagent-manager.js.map +1 -1
- package/dist/core/subagent-store.d.ts +22 -0
- package/dist/core/subagent-store.js +106 -0
- package/dist/core/subagent-store.js.map +1 -1
- package/dist/core/tasks-store.d.ts +2 -0
- package/dist/core/tasks-store.js +6 -0
- package/dist/core/tasks-store.js.map +1 -1
- package/dist/goals-agent/goals-agent.d.ts +1 -8
- package/dist/goals-agent/goals-agent.js +1 -29
- package/dist/goals-agent/goals-agent.js.map +1 -1
- package/dist/modes/acp-mode.d.ts +3 -1
- package/dist/modes/acp-mode.js +84 -3
- package/dist/modes/acp-mode.js.map +1 -1
- package/package.json +4 -4
- package/dist/app-sidecar/poll.d.ts +0 -39
- package/dist/app-sidecar/poll.js +0 -184
- package/dist/app-sidecar/poll.js.map +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
import { SessionManager } from "../core/session-manager.js";
|
|
6
|
+
import { isSessionPath, isSessionTempPath, openSessionReadStream, plainSessionPath, sessionGroupPaths, } from "../core/session-storage.js";
|
|
7
|
+
import { readBody, json } from "./http.js";
|
|
8
|
+
/** The longest title a rename keeps, the same cap the session lists apply. */
|
|
9
|
+
export const SESSION_TITLE_MAX = 80;
|
|
10
|
+
async function realOrNull(p) {
|
|
11
|
+
try {
|
|
12
|
+
return await fs.realpath(p);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** The first line of a session file, when it is a session header. */
|
|
19
|
+
async function readIdentity(file) {
|
|
20
|
+
try {
|
|
21
|
+
const { stream, close } = await openSessionReadStream(file);
|
|
22
|
+
const rl = createInterface({ input: stream, crlfDelay: Infinity });
|
|
23
|
+
try {
|
|
24
|
+
for await (const line of rl) {
|
|
25
|
+
const head = JSON.parse(line);
|
|
26
|
+
if (head.type !== "session" || typeof head.id !== "string")
|
|
27
|
+
return null;
|
|
28
|
+
return { id: head.id, conversationId: head.conversationId ?? head.id };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
rl.close();
|
|
33
|
+
close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Unreadable or not JSON: not a session we can act on.
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A session file the app may change: inside `~/.gg` (after resolving links),
|
|
43
|
+
* named like a session, and starting with a session header. Anything else is
|
|
44
|
+
* refused, so a request can never reach another file.
|
|
45
|
+
*/
|
|
46
|
+
export async function checkedSessionFile(raw, agentDir) {
|
|
47
|
+
if (typeof raw !== "string" || !raw.trim())
|
|
48
|
+
return null;
|
|
49
|
+
const file = await realOrNull(path.resolve(raw));
|
|
50
|
+
const root = await realOrNull(agentDir);
|
|
51
|
+
if (!file || !root || !file.startsWith(root + path.sep))
|
|
52
|
+
return null;
|
|
53
|
+
if (!isSessionPath(file) || isSessionTempPath(file))
|
|
54
|
+
return null;
|
|
55
|
+
const identity = await readIdentity(file);
|
|
56
|
+
return identity ? { file, identity } : null;
|
|
57
|
+
}
|
|
58
|
+
const sameFile = (a, b) => path.resolve(plainSessionPath(a)) === path.resolve(plainSessionPath(b));
|
|
59
|
+
/** Every checkpoint of one conversation in its folder (compaction starts a new file). */
|
|
60
|
+
async function conversationFiles(file, conversationId) {
|
|
61
|
+
const dir = path.dirname(file);
|
|
62
|
+
const names = await fs.readdir(dir).catch(() => []);
|
|
63
|
+
const out = new Set();
|
|
64
|
+
for (const name of names) {
|
|
65
|
+
const full = path.join(dir, name);
|
|
66
|
+
if (!isSessionPath(full) || isSessionTempPath(full))
|
|
67
|
+
continue;
|
|
68
|
+
const identity = await readIdentity(full);
|
|
69
|
+
if (identity?.conversationId === conversationId)
|
|
70
|
+
out.add(plainSessionPath(full));
|
|
71
|
+
}
|
|
72
|
+
out.add(plainSessionPath(file));
|
|
73
|
+
return Array.from(out);
|
|
74
|
+
}
|
|
75
|
+
async function exists(p) {
|
|
76
|
+
return fs.lstat(p).then(() => true, () => false);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Move a conversation's files (every checkpoint, its archive and its saved
|
|
80
|
+
* images) into `~/.gg/trash/sessions/<when>-<id>/`, so a delete can be undone
|
|
81
|
+
* by moving them back. Returns the folder they went to.
|
|
82
|
+
*/
|
|
83
|
+
export async function trashConversation(file, identity, agentDir) {
|
|
84
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
85
|
+
const dest = path.join(agentDir, "trash", "sessions", `${stamp}-${identity.id.slice(0, 8)}`);
|
|
86
|
+
await fs.mkdir(dest, { recursive: true });
|
|
87
|
+
for (const plain of await conversationFiles(file, identity.conversationId)) {
|
|
88
|
+
const { plainPath, archivePath, assetsPath } = sessionGroupPaths(plain);
|
|
89
|
+
for (const src of [plainPath, archivePath, assetsPath]) {
|
|
90
|
+
if (await exists(src))
|
|
91
|
+
await fs.rename(src, path.join(dest, path.basename(src)));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return dest;
|
|
95
|
+
}
|
|
96
|
+
/** Collapse a typed title to one trimmed line within the cap; null when empty. */
|
|
97
|
+
export function cleanTitle(raw) {
|
|
98
|
+
if (typeof raw !== "string")
|
|
99
|
+
return null;
|
|
100
|
+
const title = Array.from(raw.replace(/\s+/g, " ").trim()).slice(0, SESSION_TITLE_MAX).join("");
|
|
101
|
+
return title || null;
|
|
102
|
+
}
|
|
103
|
+
export function labelEntry(title) {
|
|
104
|
+
return {
|
|
105
|
+
type: "label",
|
|
106
|
+
id: crypto.randomUUID(),
|
|
107
|
+
parentId: null,
|
|
108
|
+
timestamp: new Date().toISOString(),
|
|
109
|
+
label: title,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Daemon-level routes for a listed session's file, open or not:
|
|
114
|
+
* `POST /sessions/rename` {path, title} and `POST /sessions/trash` {path}.
|
|
115
|
+
* Trash refuses a conversation that is open in a window.
|
|
116
|
+
*/
|
|
117
|
+
export function handleSessionFileRoutes(req, res, url, method, ctx) {
|
|
118
|
+
if (method !== "POST" || (url !== "/sessions/rename" && url !== "/sessions/trash"))
|
|
119
|
+
return false;
|
|
120
|
+
void readBody(req, res).then(async (raw) => {
|
|
121
|
+
if (raw === null)
|
|
122
|
+
return;
|
|
123
|
+
let body;
|
|
124
|
+
try {
|
|
125
|
+
body = JSON.parse(raw);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
json(res, 400, { error: "invalid JSON body" });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const target = await checkedSessionFile(body.path, ctx.agentDir);
|
|
133
|
+
if (!target) {
|
|
134
|
+
json(res, 400, { error: "Not a session file GG Coder can change." });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Compared by real path, like the target, so a link in the way can't hide a match.
|
|
138
|
+
const live = await Promise.all(ctx.liveSessions().map(async (s) => ({
|
|
139
|
+
...s,
|
|
140
|
+
path: s.path ? ((await realOrNull(path.resolve(s.path))) ?? s.path) : undefined,
|
|
141
|
+
})));
|
|
142
|
+
if (url === "/sessions/rename") {
|
|
143
|
+
const title = cleanTitle(body.title);
|
|
144
|
+
if (!title) {
|
|
145
|
+
json(res, 400, { error: "A title is required." });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const open = live.find((s) => s.path && sameFile(s.path, target.file));
|
|
149
|
+
if (open)
|
|
150
|
+
await open.rename(title);
|
|
151
|
+
else
|
|
152
|
+
await new SessionManager(path.dirname(target.file)).appendEntry(target.file, labelEntry(title));
|
|
153
|
+
json(res, 200, { title });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
for (const s of live) {
|
|
157
|
+
if (!s.path)
|
|
158
|
+
continue;
|
|
159
|
+
const identity = await readIdentity(s.path);
|
|
160
|
+
if (sameFile(s.path, target.file) ||
|
|
161
|
+
identity?.conversationId === target.identity.conversationId) {
|
|
162
|
+
json(res, 409, { error: "This session is open in a window. Close it first." });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const trashedTo = await trashConversation(target.file, target.identity, ctx.agentDir);
|
|
167
|
+
json(res, 200, { trashedTo });
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
json(res, 500, { error: err instanceof Error ? err.message : String(err) });
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=session-file-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-file-routes.js","sourceRoot":"","sources":["../../src/app-sidecar/session-file-routes.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAmB,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAoBpC,KAAK,UAAU,UAAU,CAAC,CAAS;IACjC,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,qEAAqE;AACrE,KAAK,UAAU,YAAY,CAAC,IAAY;IACtC,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,qBAA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,CAAC,KAAK,CAAC,CAClB,CAAC;gBACJ,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC1B,OAAO;YACT,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;gBACrB,IAAI,CAAC,CAAC,CAAC,IAAI;oBAAE,SAAS;gBACtB,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC5C,IACE,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;oBAC7B,QAAQ,EAAE,cAAc,KAAK,MAAM,CAAC,QAAQ,CAAC,cAAc,EAC3D,CAAC;oBACD,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,mDAAmD,EAAE,CAAC,CAAC;oBAC/E,OAAO;gBACT,CAAC;YACH,CAAC;YACD,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;YACtF,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type http from "node:http";
|
|
2
2
|
import type { SessionRouteContext } from "./route-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* The OS temp folders, as written and as resolved (macOS's /var is /private/var).
|
|
5
|
+
* Benchmarks and scripts run sessions in fresh scratch dirs there; listed as
|
|
6
|
+
* projects, a removed one is replaced by its near-identical twin.
|
|
7
|
+
*/
|
|
8
|
+
export declare function tempRoots(): string[];
|
|
3
9
|
export declare function handleWorkspaceRoutes(ctx: SessionRouteContext, req: http.IncomingMessage, res: http.ServerResponse, url: string, method: string): boolean;
|
|
@@ -1,14 +1,36 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
1
3
|
import path from "node:path";
|
|
2
4
|
import { sessionToMarkdown, defaultExportFilename } from "../core/session-export.js";
|
|
3
5
|
import { discoverProjects } from "../core/project-discovery.js";
|
|
4
6
|
import { listWorktrees } from "./worktrees.js";
|
|
5
7
|
import { goalsRoot } from "../core/goals-store.js";
|
|
8
|
+
import { CHAT_FOLDER_NAME } from "../chat-agents/shared.js";
|
|
9
|
+
/** GG Motion's video workspace inside the projects root (gg-app's motion-workspace.ts). */
|
|
10
|
+
const MOTION_FOLDER_NAME = "GG Motion";
|
|
6
11
|
import { listSidecarSessions } from "../app-sidecar-sessions.js";
|
|
7
12
|
import { log } from "../core/logger.js";
|
|
8
13
|
import { readBody, json } from "./http.js";
|
|
9
14
|
import { parseToolDetail } from "./history.js";
|
|
10
15
|
import { searchProjectFiles } from "./file-search.js";
|
|
11
16
|
import { loadAppSettings, updateAppSettings } from "./app-settings.js";
|
|
17
|
+
/**
|
|
18
|
+
* The OS temp folders, as written and as resolved (macOS's /var is /private/var).
|
|
19
|
+
* Benchmarks and scripts run sessions in fresh scratch dirs there; listed as
|
|
20
|
+
* projects, a removed one is replaced by its near-identical twin.
|
|
21
|
+
*/
|
|
22
|
+
export function tempRoots() {
|
|
23
|
+
const roots = [os.tmpdir(), ...(process.platform === "win32" ? [] : ["/tmp"])];
|
|
24
|
+
const all = roots.flatMap((root) => {
|
|
25
|
+
try {
|
|
26
|
+
return [root, fs.realpathSync(root)];
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [root];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return [...new Set(all.map((root) => path.resolve(root)))];
|
|
33
|
+
}
|
|
12
34
|
export function handleWorkspaceRoutes(ctx, req, res, url, method) {
|
|
13
35
|
// "Add folder" / "Remove folder" in the More panel: another folder GG can
|
|
14
36
|
// work in, in Code and Chat windows. The model hears from the environment note.
|
|
@@ -95,7 +117,19 @@ export function handleWorkspaceRoutes(ctx, req, res, url, method) {
|
|
|
95
117
|
hiddenPaths: hiddenProjects,
|
|
96
118
|
// Goal workspaces have their own list; they are not coding projects.
|
|
97
119
|
// GG-made worktrees are listed under their project, not as projects.
|
|
98
|
-
|
|
120
|
+
// Chat's and Motion's folders have their own lists too, however
|
|
121
|
+
// they were found (a scan skips them by name; old sessions don't).
|
|
122
|
+
excludeRoots: [
|
|
123
|
+
goalsRoot(ctx.paths.agentDir),
|
|
124
|
+
path.join(ctx.paths.agentDir, "worktrees"),
|
|
125
|
+
...(projectsRoot
|
|
126
|
+
? [
|
|
127
|
+
path.join(projectsRoot, CHAT_FOLDER_NAME),
|
|
128
|
+
path.join(projectsRoot, MOTION_FOLDER_NAME),
|
|
129
|
+
]
|
|
130
|
+
: []),
|
|
131
|
+
...tempRoots(),
|
|
132
|
+
],
|
|
99
133
|
}))
|
|
100
134
|
.then((projects) => json(res, 200, { projects }))
|
|
101
135
|
.catch((err) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-routes.js","sourceRoot":"","sources":["../../src/app-sidecar/workspace-routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workspace-routes.js","sourceRoot":"","sources":["../../src/app-sidecar/workspace-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OA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AC,CAAC,CAAC;QACnE,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9B,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,QAAQ,GAAG,iBAAiB,CAChC;YACE,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrD,EACD,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EACzB,EAAE,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CACpD,CAAC;QACF,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QACvC,KAAK,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/app-sidecar.js
CHANGED
|
@@ -69,14 +69,15 @@ import { createAskUserTool } from "./tools/ask-user.js";
|
|
|
69
69
|
import { createUsageService } from "./app-sidecar/usage.js";
|
|
70
70
|
import { daemonReadBody, daemonJson, json } from "./app-sidecar/http.js";
|
|
71
71
|
import { runJsonModeIfRequested } from "./app-sidecar/json-mode.js";
|
|
72
|
+
import { createDetachedSessions } from "./app-sidecar/detached-sessions.js";
|
|
72
73
|
import { parseWorkspaceMode, } from "./app-sidecar/session-types.js";
|
|
73
74
|
import { ALL_PROVIDERS, loadProjectModelPrefs, loadKenModelPref, loadAutopilot, } from "./app-sidecar/app-settings.js";
|
|
74
75
|
import { KEN_ALLOWED_TOOLS } from "./app-sidecar/ken-context.js";
|
|
75
76
|
import { createProgressManager } from "./app-sidecar/progress-manager.js";
|
|
76
|
-
import { createPollClient } from "./app-sidecar/poll.js";
|
|
77
77
|
import { createTrophyManager } from "./app-sidecar/trophy-manager.js";
|
|
78
78
|
import { localTrophyDate } from "./core/trophies/engine.js";
|
|
79
79
|
import { handleSessionRoutes } from "./app-sidecar/session-routes.js";
|
|
80
|
+
import { handleSessionFileRoutes } from "./app-sidecar/session-file-routes.js";
|
|
80
81
|
import { handleGoalRoutes } from "./app-sidecar/goal-routes.js";
|
|
81
82
|
import { readGitState, resolveGitCwd } from "./app-sidecar/git-target.js";
|
|
82
83
|
import { goalPhase, goalsRoot, isGoalDir, isGoalStartMessage, startGoalOnAnswer, readGoal, } from "./core/goals-store.js";
|
|
@@ -105,6 +106,8 @@ import { keepAwake } from "./app-sidecar/keep-awake.js";
|
|
|
105
106
|
import { createAutopilotRunner } from "./app-sidecar/autopilot-runner.js";
|
|
106
107
|
/** Limit for re-reading git state in the background when git missed the usual 2 s. */
|
|
107
108
|
const SLOW_GIT_READ_TIMEOUT_MS = 15_000;
|
|
109
|
+
/** How often a detached session is checked for having gone idle. */
|
|
110
|
+
const DETACHED_SWEEP_MS = 1000;
|
|
108
111
|
async function main() {
|
|
109
112
|
// Hidden persistent-worker dispatch must win before strict JSON/server parsing.
|
|
110
113
|
if (process.argv.includes("--subagent-worker")) {
|
|
@@ -303,8 +306,6 @@ async function main() {
|
|
|
303
306
|
// XP/rank progress — loaded once per daemon; awards fan out to every window.
|
|
304
307
|
// Each frame is tagged `origin: true` only for the session that earned the
|
|
305
308
|
// XP, so that window alone plays sounds/chips while the rest just re-render.
|
|
306
|
-
// Home's weekly poll (daemon-level; one random voter id in ~/.gg/poll.json).
|
|
307
|
-
const poll = createPollClient({ agentDir: paths.agentDir });
|
|
308
309
|
const progress = await createProgressManager(paths.agentDir, (snapshot, originId) => {
|
|
309
310
|
for (const ctx of sessions.values())
|
|
310
311
|
ctx.broadcast("progress", { ...snapshot, origin: ctx.id === originId });
|
|
@@ -375,6 +376,30 @@ async function main() {
|
|
|
375
376
|
log("INFO", "app-sidecar", "session disposed", { id });
|
|
376
377
|
await ctx.dispose().catch(() => { });
|
|
377
378
|
};
|
|
379
|
+
// Sessions a window switched away from mid-run keep working (detached-sessions.ts).
|
|
380
|
+
const detached = createDetachedSessions({
|
|
381
|
+
get: (id) => {
|
|
382
|
+
const ctx = sessions.get(id);
|
|
383
|
+
return (ctx && {
|
|
384
|
+
...ctx,
|
|
385
|
+
sessionPath: () => ctx.session.getState().sessionPath,
|
|
386
|
+
title: () => ctx.session.getSessionPreview(),
|
|
387
|
+
});
|
|
388
|
+
},
|
|
389
|
+
close: (id) => {
|
|
390
|
+
void livePreview.onSessionClosed(id);
|
|
391
|
+
void closeSession(id);
|
|
392
|
+
},
|
|
393
|
+
announce: (list) => broadcastAll("background_sessions", { sessions: list }),
|
|
394
|
+
});
|
|
395
|
+
let detachedSweep;
|
|
396
|
+
const sweepDetached = () => {
|
|
397
|
+
detached.sweep();
|
|
398
|
+
if (detached.size === 0 && detachedSweep) {
|
|
399
|
+
clearInterval(detachedSweep);
|
|
400
|
+
detachedSweep = undefined;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
378
403
|
// Live preview: one per window, each with its own session in the window's project.
|
|
379
404
|
const livePreview = createLivePreviewManager({
|
|
380
405
|
assetsDir: findLivePreviewAssets(),
|
|
@@ -451,6 +476,18 @@ async function main() {
|
|
|
451
476
|
? body.cwd
|
|
452
477
|
: (process.env.GG_APP_CWD ?? process.cwd());
|
|
453
478
|
const sessionPath = typeof body.sessionPath === "string" && body.sessionPath ? body.sessionPath : undefined;
|
|
479
|
+
// Still working in the background since a window left it: take it back.
|
|
480
|
+
const liveId = sessionPath ? detached.reattach(sessionPath, mode, chatAgent) : null;
|
|
481
|
+
const live = liveId ? sessions.get(liveId) : undefined;
|
|
482
|
+
if (live) {
|
|
483
|
+
log("INFO", "app-sidecar", "detached session reattached", { id: live.id });
|
|
484
|
+
daemonJson(res, 200, {
|
|
485
|
+
sessionId: live.id,
|
|
486
|
+
sessionPath: live.session.getState().sessionPath ?? null,
|
|
487
|
+
cwd: live.cwd,
|
|
488
|
+
});
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
454
491
|
try {
|
|
455
492
|
// A resumed conversation comes back where its branch is checked out,
|
|
456
493
|
// even if the project's folder has moved to another branch since. It
|
|
@@ -496,15 +533,40 @@ async function main() {
|
|
|
496
533
|
});
|
|
497
534
|
return;
|
|
498
535
|
}
|
|
499
|
-
// Dispose a session: DELETE /session/:id.
|
|
536
|
+
// Dispose a session: DELETE /session/:id. `?detach=1` (a window switching
|
|
537
|
+
// to another session) keeps a working one running in the background.
|
|
500
538
|
if (method === "DELETE" && url.startsWith("/session/")) {
|
|
501
|
-
const
|
|
539
|
+
const [rawId, query = ""] = url.slice("/session/".length).split("?");
|
|
540
|
+
const id = decodeURIComponent(rawId ?? "");
|
|
541
|
+
if (new URLSearchParams(query).get("detach") === "1" && detached.detach(id)) {
|
|
542
|
+
log("INFO", "app-sidecar", "session detached while working", { id });
|
|
543
|
+
if (!detachedSweep) {
|
|
544
|
+
detachedSweep = setInterval(sweepDetached, DETACHED_SWEEP_MS);
|
|
545
|
+
detachedSweep.unref?.();
|
|
546
|
+
}
|
|
547
|
+
daemonJson(res, 200, { ok: true, detached: true });
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
502
550
|
// A closing window takes its live preview (and the preview's session) with it.
|
|
503
551
|
void livePreview.onSessionClosed(id);
|
|
504
552
|
void closeSession(id);
|
|
505
553
|
daemonJson(res, 200, { ok: true });
|
|
506
554
|
return;
|
|
507
555
|
}
|
|
556
|
+
// Sessions still working with no window (see `detached`).
|
|
557
|
+
if (method === "GET" && url === "/sessions/background") {
|
|
558
|
+
daemonJson(res, 200, { sessions: detached.list() });
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
// A listed session's file (rename, move to trash), open in a window or not.
|
|
562
|
+
if (handleSessionFileRoutes(req, res, url, method, {
|
|
563
|
+
agentDir: paths.agentDir,
|
|
564
|
+
liveSessions: () => Array.from(sessions.values(), (ctx) => ({
|
|
565
|
+
path: ctx.session.getState().sessionPath ?? undefined,
|
|
566
|
+
rename: (title) => ctx.session.renameSession(title),
|
|
567
|
+
})),
|
|
568
|
+
}))
|
|
569
|
+
return;
|
|
508
570
|
// Keep-awake is app-wide (one OS assertion for every window), so its
|
|
509
571
|
// setting lives at the daemon level and applies live to in-flight runs.
|
|
510
572
|
if (method === "GET" && url === "/keep-awake") {
|
|
@@ -550,32 +612,6 @@ async function main() {
|
|
|
550
612
|
daemonJson(res, 200, trophies.snapshot());
|
|
551
613
|
return;
|
|
552
614
|
}
|
|
553
|
-
// The weekly poll is app-wide, so no session header. Always 200 with the poll state; its
|
|
554
|
-
// `status` tells the app the poll server's answer (0 = unreachable).
|
|
555
|
-
if (method === "GET" && url === "/poll") {
|
|
556
|
-
void poll.current().then((state) => daemonJson(res, 200, state));
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
if (method === "POST" && url === "/poll/vote") {
|
|
560
|
-
void daemonReadBody(req, res).then(async (raw) => {
|
|
561
|
-
if (raw === null)
|
|
562
|
-
return;
|
|
563
|
-
let parsed;
|
|
564
|
-
try {
|
|
565
|
-
parsed = JSON.parse(raw || "{}");
|
|
566
|
-
}
|
|
567
|
-
catch {
|
|
568
|
-
daemonJson(res, 400, { error: "invalid JSON" });
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
if (typeof parsed.pollId !== "string" || typeof parsed.choice !== "number") {
|
|
572
|
-
daemonJson(res, 400, { error: "pollId and choice are required" });
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
daemonJson(res, 200, await poll.vote(parsed.pollId, parsed.choice));
|
|
576
|
-
});
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
615
|
// Subscription quota is account-wide, not project/session-specific. OAuth
|
|
580
616
|
// tokens stay in this daemon; only the active provider's normalized snapshot
|
|
581
617
|
// reaches the webview.
|
|
@@ -1278,6 +1314,9 @@ async function createSession(deps, opts) {
|
|
|
1278
1314
|
// Roots added with /add-dir — the header shows a badge when non-empty.
|
|
1279
1315
|
additionalRoots: session.getAdditionalRoots(),
|
|
1280
1316
|
worktreeOf,
|
|
1317
|
+
// A new session's file appears with its first message; the app's sidebar
|
|
1318
|
+
// matches its window to the listed session by it.
|
|
1319
|
+
sessionPath: session.getState().sessionPath,
|
|
1281
1320
|
};
|
|
1282
1321
|
}
|
|
1283
1322
|
// Startup resolves the model before discovery runs, so a saved local model
|