@kenkaiiii/ggcoder 5.74.3 → 5.75.0
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/bulletproof/SKILL.md +1 -1
- package/assets/skills/clarify/SKILL.md +1 -1
- package/assets/skills/code-review/SKILL.md +1 -1
- package/assets/skills/compliance-guard/SKILL.md +1 -1
- package/assets/skills/durable/SKILL.md +1 -1
- package/assets/skills/evidence-led-ui/SKILL.md +1 -1
- package/assets/skills/lean/SKILL.md +1 -1
- package/assets/skills/refactoring/SKILL.md +1 -1
- package/assets/skills/root-cause/SKILL.md +1 -1
- package/assets/skills/shared-language/SKILL.md +1 -1
- package/assets/skills/tdd/SKILL.md +1 -1
- package/dist/app-sidecar/app-settings.d.ts +65 -0
- package/dist/app-sidecar/app-settings.js +147 -0
- package/dist/app-sidecar/app-settings.js.map +1 -0
- package/dist/app-sidecar/attachments.d.ts +11 -0
- package/dist/app-sidecar/attachments.js +47 -0
- package/dist/app-sidecar/attachments.js.map +1 -0
- package/dist/app-sidecar/auth-routes.d.ts +3 -0
- package/dist/app-sidecar/auth-routes.js +290 -0
- package/dist/app-sidecar/auth-routes.js.map +1 -0
- package/dist/app-sidecar/autopilot-runner.d.ts +61 -0
- package/dist/app-sidecar/autopilot-runner.js +367 -0
- package/dist/app-sidecar/autopilot-runner.js.map +1 -0
- package/dist/app-sidecar/file-search.d.ts +15 -0
- package/dist/app-sidecar/file-search.js +103 -0
- package/dist/app-sidecar/file-search.js.map +1 -0
- package/dist/app-sidecar/hf-pull-manager.d.ts +20 -0
- package/dist/app-sidecar/hf-pull-manager.js +224 -0
- package/dist/app-sidecar/hf-pull-manager.js.map +1 -0
- package/dist/app-sidecar/history-routes.d.ts +3 -0
- package/dist/app-sidecar/history-routes.js +375 -0
- package/dist/app-sidecar/history-routes.js.map +1 -0
- package/dist/app-sidecar/history.d.ts +67 -0
- package/dist/app-sidecar/history.js +23 -0
- package/dist/app-sidecar/history.js.map +1 -0
- package/dist/app-sidecar/http.d.ts +5 -0
- package/dist/app-sidecar/http.js +27 -0
- package/dist/app-sidecar/http.js.map +1 -0
- package/dist/app-sidecar/integration-routes.d.ts +3 -0
- package/dist/app-sidecar/integration-routes.js +286 -0
- package/dist/app-sidecar/integration-routes.js.map +1 -0
- package/dist/app-sidecar/json-mode.d.ts +10 -0
- package/dist/app-sidecar/json-mode.js +73 -0
- package/dist/app-sidecar/json-mode.js.map +1 -0
- package/dist/app-sidecar/keep-awake.d.ts +4 -0
- package/dist/app-sidecar/keep-awake.js +5 -0
- package/dist/app-sidecar/keep-awake.js.map +1 -0
- package/dist/app-sidecar/ken-context.d.ts +20 -0
- package/dist/app-sidecar/ken-context.js +55 -0
- package/dist/app-sidecar/ken-context.js.map +1 -0
- package/dist/app-sidecar/mcp-routes.d.ts +3 -0
- package/dist/app-sidecar/mcp-routes.js +185 -0
- package/dist/app-sidecar/mcp-routes.js.map +1 -0
- package/dist/app-sidecar/mcp-rows.d.ts +31 -0
- package/dist/app-sidecar/mcp-rows.js +77 -0
- package/dist/app-sidecar/mcp-rows.js.map +1 -0
- package/dist/app-sidecar/progress-manager.d.ts +10 -0
- package/dist/app-sidecar/progress-manager.js +116 -0
- package/dist/app-sidecar/progress-manager.js.map +1 -0
- package/dist/app-sidecar/prompt-routes.d.ts +3 -0
- package/dist/app-sidecar/prompt-routes.js +354 -0
- package/dist/app-sidecar/prompt-routes.js.map +1 -0
- package/dist/app-sidecar/route-context.d.ts +145 -0
- package/dist/app-sidecar/route-context.js +2 -0
- package/dist/app-sidecar/route-context.js.map +1 -0
- package/dist/app-sidecar/run-control-routes.d.ts +3 -0
- package/dist/app-sidecar/run-control-routes.js +430 -0
- package/dist/app-sidecar/run-control-routes.js.map +1 -0
- package/dist/app-sidecar/session-routes.d.ts +3 -0
- package/dist/app-sidecar/session-routes.js +115 -0
- package/dist/app-sidecar/session-routes.js.map +1 -0
- package/dist/app-sidecar/session-types.d.ts +39 -0
- package/dist/app-sidecar/session-types.js +5 -0
- package/dist/app-sidecar/session-types.js.map +1 -0
- package/dist/app-sidecar/task-routes.d.ts +3 -0
- package/dist/app-sidecar/task-routes.js +149 -0
- package/dist/app-sidecar/task-routes.js.map +1 -0
- package/dist/app-sidecar/usage.d.ts +19 -0
- package/dist/app-sidecar/usage.js +153 -0
- package/dist/app-sidecar/usage.js.map +1 -0
- package/dist/app-sidecar/workspace-routes.d.ts +3 -0
- package/dist/app-sidecar/workspace-routes.js +244 -0
- package/dist/app-sidecar/workspace-routes.js.map +1 -0
- package/dist/app-sidecar.js +440 -3720
- package/dist/app-sidecar.js.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/core/acceptance-checks.js +3 -9
- package/dist/core/acceptance-checks.js.map +1 -1
- package/dist/core/agent-session/helpers.d.ts +26 -0
- package/dist/core/agent-session/helpers.js +47 -0
- package/dist/core/agent-session/helpers.js.map +1 -0
- package/dist/core/agent-session/mcp-tools.d.ts +68 -0
- package/dist/core/agent-session/mcp-tools.js +195 -0
- package/dist/core/agent-session/mcp-tools.js.map +1 -0
- package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
- package/dist/core/agent-session/run-loop-monitor.js +164 -0
- package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
- package/dist/core/agent-session/transcript-markers.d.ts +57 -0
- package/dist/core/agent-session/transcript-markers.js +166 -0
- package/dist/core/agent-session/transcript-markers.js.map +1 -0
- package/dist/core/agent-session/verification-tracker.d.ts +46 -0
- package/dist/core/agent-session/verification-tracker.js +246 -0
- package/dist/core/agent-session/verification-tracker.js.map +1 -0
- package/dist/core/agent-session.d.ts +21 -87
- package/dist/core/agent-session.js +141 -712
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-providers.js +3 -3
- package/dist/core/auth-providers.js.map +1 -1
- package/dist/core/bundled-agents.js +6 -6
- package/dist/core/bundled-agents.js.map +1 -1
- package/dist/core/checklist-git.d.ts +19 -0
- package/dist/core/checklist-git.js +54 -0
- package/dist/core/checklist-git.js.map +1 -0
- package/dist/core/checklist-items.d.ts +10 -1
- package/dist/core/checklist-items.js +22 -0
- package/dist/core/checklist-items.js.map +1 -1
- package/dist/core/checklist-prompt.d.ts +5 -1
- package/dist/core/checklist-prompt.js +16 -5
- package/dist/core/checklist-prompt.js.map +1 -1
- package/dist/core/checklist-snapshot.d.ts +5 -1
- package/dist/core/checklist-snapshot.js +19 -2
- package/dist/core/checklist-snapshot.js.map +1 -1
- package/dist/core/context-limits.js +1 -1
- package/dist/core/context-limits.js.map +1 -1
- package/dist/core/skills.js +6 -9
- package/dist/core/skills.js.map +1 -1
- package/dist/core/style-packs/index.js +2 -11
- package/dist/core/style-packs/index.js.map +1 -1
- package/dist/core/style-packs/packs.d.ts +3 -12
- package/dist/core/style-packs/packs.js +132 -173
- package/dist/core/style-packs/packs.js.map +1 -1
- package/dist/system-prompt.js +55 -78
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/ask-user.js +13 -74
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/bash.js +13 -78
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/checklist.d.ts +2 -10
- package/dist/tools/checklist.js +7 -39
- package/dist/tools/checklist.js.map +1 -1
- package/dist/tools/code-nav.js +7 -29
- package/dist/tools/code-nav.js.map +1 -1
- package/dist/tools/edit.d.ts +3 -9
- package/dist/tools/edit.js +66 -65
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/enter-plan.js +2 -7
- package/dist/tools/enter-plan.js.map +1 -1
- package/dist/tools/exit-plan.js +2 -3
- package/dist/tools/exit-plan.js.map +1 -1
- package/dist/tools/find.js +3 -4
- package/dist/tools/find.js.map +1 -1
- package/dist/tools/grep.js +6 -18
- package/dist/tools/grep.js.map +1 -1
- package/dist/tools/ls.js +3 -3
- package/dist/tools/ls.js.map +1 -1
- package/dist/tools/prompt-hints.js +34 -47
- package/dist/tools/prompt-hints.js.map +1 -1
- package/dist/tools/read.js +8 -20
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/search-code.js +4 -12
- package/dist/tools/search-code.js.map +1 -1
- package/dist/tools/skill.js +13 -7
- package/dist/tools/skill.js.map +1 -1
- package/dist/tools/subagent-control.js +7 -22
- package/dist/tools/subagent-control.js.map +1 -1
- package/dist/tools/subagent.js +4 -7
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/task-output.js +4 -15
- package/dist/tools/task-output.js.map +1 -1
- package/dist/tools/task-send.js +5 -17
- package/dist/tools/task-send.js.map +1 -1
- package/dist/tools/task-stop.js +2 -2
- package/dist/tools/task-stop.js.map +1 -1
- package/dist/tools/tool-search.js +2 -7
- package/dist/tools/tool-search.js.map +1 -1
- package/dist/tools/tool-tiers.d.ts +17 -4
- package/dist/tools/tool-tiers.js +38 -15
- package/dist/tools/tool-tiers.js.map +1 -1
- package/dist/tools/web-fetch.js +7 -33
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/write.js +3 -4
- package/dist/tools/write.js.map +1 -1
- package/dist/ui/components/Footer.js +1 -2
- package/dist/ui/components/Footer.js.map +1 -1
- package/package.json +7 -4
- package/dist/core/api-benchmark.d.ts +0 -63
- package/dist/core/api-benchmark.js +0 -381
- package/dist/core/api-benchmark.js.map +0 -1
- package/dist/core/bash-spawn-benchmark.d.ts +0 -1
- package/dist/core/bash-spawn-benchmark.js +0 -139
- package/dist/core/bash-spawn-benchmark.js.map +0 -1
- package/dist/core/cache-warm-benchmark.d.ts +0 -21
- package/dist/core/cache-warm-benchmark.js +0 -170
- package/dist/core/cache-warm-benchmark.js.map +0 -1
- package/dist/core/fast-apply-benchmark.d.ts +0 -25
- package/dist/core/fast-apply-benchmark.js +0 -284
- package/dist/core/fast-apply-benchmark.js.map +0 -1
- package/dist/core/hashline-edit-benchmark.d.ts +0 -88
- package/dist/core/hashline-edit-benchmark.js +0 -518
- package/dist/core/hashline-edit-benchmark.js.map +0 -1
- package/dist/core/semantic-search-benchmark.d.ts +0 -36
- package/dist/core/semantic-search-benchmark.js +0 -211
- package/dist/core/semantic-search-benchmark.js.map +0 -1
- package/dist/core/speed-benchmark.d.ts +0 -132
- package/dist/core/speed-benchmark.js +0 -410
- package/dist/core/speed-benchmark.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { AppErrorPayload } from "../app-error.js";
|
|
2
|
+
import type { ToolDetail } from "../core/session-export.js";
|
|
3
|
+
export interface HistoryEntryForWire {
|
|
4
|
+
role: "user" | "assistant";
|
|
5
|
+
text: string;
|
|
6
|
+
images?: string[];
|
|
7
|
+
hook?: "ideal" | "loop_break" | "regrounding" | null;
|
|
8
|
+
command?: boolean;
|
|
9
|
+
compacted?: boolean;
|
|
10
|
+
/** Persisted counts for a compacted row's "N → M messages" summary. */
|
|
11
|
+
compactionCounts?: {
|
|
12
|
+
originalCount: number;
|
|
13
|
+
newCount: number;
|
|
14
|
+
};
|
|
15
|
+
/** True when this entry is a Ken Kai (mentor) turn: a `user` row is the `@Ken`
|
|
16
|
+
* question, an `assistant` row is Ken's reply. The webview renders these in
|
|
17
|
+
* Ken's color (user bubble tinted; assistant as a Ken bubble). */
|
|
18
|
+
ken?: boolean;
|
|
19
|
+
/** Present when this entry is a persisted autopilot verdict marker (an
|
|
20
|
+
* `assistant` row with empty `text`). The webview renders it exactly like
|
|
21
|
+
* the live `autopilot` item — never the raw verdict keyword the model
|
|
22
|
+
* actually replied with (e.g. `ALL_CLEAR`). */
|
|
23
|
+
autopilot?: {
|
|
24
|
+
phase: "prompted" | "done" | "human" | "capped" | "plan_approved";
|
|
25
|
+
reason?: string;
|
|
26
|
+
body?: string;
|
|
27
|
+
/** Stable seed derived from persisted marker data for deterministic all-clear copy. */
|
|
28
|
+
copySeed?: string;
|
|
29
|
+
};
|
|
30
|
+
/** True when this user prompt came from a Ken "Send to GG Coder" button —
|
|
31
|
+
* the webview renders the shimmering label instead of the prompt body. */
|
|
32
|
+
kenSent?: boolean;
|
|
33
|
+
/** Enhancer highlight segments for this user prompt (unedited enhanced sends). */
|
|
34
|
+
enhancements?: unknown[];
|
|
35
|
+
/** Plan-mode entry banner (ASCII logo + reason), persisted at plan_enter. */
|
|
36
|
+
plan?: {
|
|
37
|
+
reason: string;
|
|
38
|
+
};
|
|
39
|
+
/** Task header row (task title), persisted at task_start. */
|
|
40
|
+
task?: {
|
|
41
|
+
title: string;
|
|
42
|
+
};
|
|
43
|
+
/** Error row (headline/message/guidance), persisted by broadcastError.
|
|
44
|
+
* `scope` selects the live prefix (ken_error → "Ken: ", autopilot_error →
|
|
45
|
+
* "Autopilot: "). */
|
|
46
|
+
error?: AppErrorPayload;
|
|
47
|
+
/** Webview-copy info row marker (e.g. the video-capability warning). */
|
|
48
|
+
infoKind?: "video_warning";
|
|
49
|
+
toolImages?: Array<{
|
|
50
|
+
src: string;
|
|
51
|
+
path?: string;
|
|
52
|
+
}>;
|
|
53
|
+
subagentGroup?: Array<{
|
|
54
|
+
agentName?: string;
|
|
55
|
+
status: "done" | "error";
|
|
56
|
+
toolUseCount: number;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Detect whether a restored user message is actually an injected self-correction
|
|
61
|
+
* hook prompt, by its distinctive opening phrase. Returns the hook kind so the
|
|
62
|
+
* webview can render the short notice line instead of the full prompt body.
|
|
63
|
+
*/
|
|
64
|
+
/** `?tools=` on /export. Anything unrecognised (including absent) falls back to
|
|
65
|
+
* the human-facing `summary` default rather than dumping every payload. */
|
|
66
|
+
export declare function parseToolDetail(value: string | null): ToolDetail;
|
|
67
|
+
export declare function detectHookKind(text: string): "ideal" | "loop_break" | "regrounding" | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ── Chat attachments (images / videos / files dropped into the input) ──────
|
|
2
|
+
// The webview sends base64 payloads; we persist each under .gg/uploads/ so the
|
|
3
|
+
/**
|
|
4
|
+
* Detect whether a restored user message is actually an injected self-correction
|
|
5
|
+
* hook prompt, by its distinctive opening phrase. Returns the hook kind so the
|
|
6
|
+
* webview can render the short notice line instead of the full prompt body.
|
|
7
|
+
*/
|
|
8
|
+
/** `?tools=` on /export. Anything unrecognised (including absent) falls back to
|
|
9
|
+
* the human-facing `summary` default rather than dumping every payload. */
|
|
10
|
+
export function parseToolDetail(value) {
|
|
11
|
+
return value === "none" || value === "full" ? value : "summary";
|
|
12
|
+
}
|
|
13
|
+
export function detectHookKind(text) {
|
|
14
|
+
const t = text.trimStart();
|
|
15
|
+
if (t.startsWith("Ideal? Review the actual work"))
|
|
16
|
+
return "ideal";
|
|
17
|
+
if (t.startsWith("Stuck? You've repeated essentially"))
|
|
18
|
+
return "loop_break";
|
|
19
|
+
if (t.startsWith("Re-ground. The conversation was just compacted"))
|
|
20
|
+
return "regrounding";
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/app-sidecar/history.ts"],"names":[],"mappings":"AAmDA,8EAA8E;AAC9E,+EAA+E;AAE/E;;;;GAIG;AACH;4EAC4E;AAC5E,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAC3B,IAAI,CAAC,CAAC,UAAU,CAAC,+BAA+B,CAAC;QAAE,OAAO,OAAO,CAAC;IAClE,IAAI,CAAC,CAAC,UAAU,CAAC,oCAAoC,CAAC;QAAE,OAAO,YAAY,CAAC;IAC5E,IAAI,CAAC,CAAC,UAAU,CAAC,gDAAgD,CAAC;QAAE,OAAO,aAAa,CAAC;IACzF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type http from "node:http";
|
|
2
|
+
export declare function daemonReadBody(req: http.IncomingMessage, res: http.ServerResponse): Promise<string | null>;
|
|
3
|
+
export declare function daemonJson(res: http.ServerResponse, status: number, body: unknown): void;
|
|
4
|
+
export declare function readBody(req: http.IncomingMessage, res: http.ServerResponse): Promise<string | null>;
|
|
5
|
+
export declare function json(res: http.ServerResponse, status: number, body: unknown): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readCappedBody } from "../utils/http-body.js";
|
|
2
|
+
import { environmentSecrets, redactValue } from "@kenkaiiii/gg-ai";
|
|
3
|
+
// ── Daemon-level HTTP helpers (shared by the session-management routes) ─────
|
|
4
|
+
// The per-session route table has its own local copies; these serve the
|
|
5
|
+
// daemon's own POST /session / DELETE /session routes.
|
|
6
|
+
export function daemonReadBody(req, res) {
|
|
7
|
+
return readCappedBody(req, res);
|
|
8
|
+
}
|
|
9
|
+
export function daemonJson(res, status, body) {
|
|
10
|
+
// No CORS headers: only the Rust proxy (no Origin) should call this daemon.
|
|
11
|
+
// Granting origins would let any web page read responses from loopback.
|
|
12
|
+
res.writeHead(status, {
|
|
13
|
+
"content-type": "application/json",
|
|
14
|
+
});
|
|
15
|
+
res.end(JSON.stringify(body));
|
|
16
|
+
}
|
|
17
|
+
export function readBody(req, res) {
|
|
18
|
+
return readCappedBody(req, res);
|
|
19
|
+
}
|
|
20
|
+
export function json(res, status, body) {
|
|
21
|
+
const payload = JSON.stringify(redactValue(body, { secrets: environmentSecrets(process.env) }));
|
|
22
|
+
res.writeHead(status, {
|
|
23
|
+
"content-type": "application/json",
|
|
24
|
+
});
|
|
25
|
+
res.end(payload);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/app-sidecar/http.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEnE,+EAA+E;AAC/E,wEAAwE;AACxE,uDAAuD;AACvD,MAAM,UAAU,cAAc,CAC5B,GAAyB,EACzB,GAAwB;IAExB,OAAO,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAwB,EAAE,MAAc,EAAE,IAAa;IAChF,4EAA4E;IAC5E,wEAAwE;IACxE,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;QACpB,cAAc,EAAE,kBAAkB;KACnC,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,QAAQ,CACtB,GAAyB,EACzB,GAAwB;IAExB,OAAO,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAwB,EAAE,MAAc,EAAE,IAAa;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAChG,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;QACpB,cAAc,EAAE,kBAAkB;KACnC,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { isValidHfRepoId } from "../hf-pull.js";
|
|
2
|
+
import { parseLocalModelId } from "@kenkaiiii/gg-core";
|
|
3
|
+
import { LocalEndpointError, addCustomEndpoint, removeCustomEndpoint, } from "../core/local-endpoint-store.js";
|
|
4
|
+
import { clearRuntimeModels } from "../core/model-registry.js";
|
|
5
|
+
import { log } from "../core/logger.js";
|
|
6
|
+
import { startServeMode } from "../modes/serve-mode.js";
|
|
7
|
+
import { installSteroids, probeSteroids } from "../core/steroids.js";
|
|
8
|
+
import { loadTelegramConfig, saveTelegramConfig, verifyBotToken } from "../core/telegram-config.js";
|
|
9
|
+
import { readBody, json } from "./http.js";
|
|
10
|
+
export function handleIntegrationRoutes(ctx, req, res, url, method) {
|
|
11
|
+
// ── Telegram config (mirrors `ggcoder telegram`) ─────────
|
|
12
|
+
// ── Local models ──────────────────────────────────────
|
|
13
|
+
// GET returns the last scan (cheap, no probing) so opening the modal is
|
|
14
|
+
// instant; POST /local/scan is the explicit refresh.
|
|
15
|
+
if (method === "GET" && url === "/local") {
|
|
16
|
+
json(res, 200, ctx.localStatePayload());
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (method === "POST" && url === "/local/scan") {
|
|
20
|
+
void ctx
|
|
21
|
+
.scanLocalModels(true)
|
|
22
|
+
.then(() => {
|
|
23
|
+
ctx.broadcast("models_change", { local: ctx.localStatePayload() });
|
|
24
|
+
json(res, 200, ctx.localStatePayload());
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
ctx.broadcastError("error", "local model scan failed", err);
|
|
28
|
+
json(res, 500, { error: "Local model scan failed — see the sidecar log." });
|
|
29
|
+
});
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (method === "POST" && url === "/local/endpoints") {
|
|
33
|
+
void readBody(req, res).then(async (raw) => {
|
|
34
|
+
if (raw === null)
|
|
35
|
+
return;
|
|
36
|
+
let body;
|
|
37
|
+
try {
|
|
38
|
+
body = JSON.parse(raw);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
json(res, 400, { error: "invalid JSON body" });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const endpoint = await addCustomEndpoint({
|
|
46
|
+
baseUrl: body.baseUrl ?? "",
|
|
47
|
+
...(body.label ? { label: body.label } : {}),
|
|
48
|
+
...(body.apiKey ? { apiKey: body.apiKey } : {}),
|
|
49
|
+
});
|
|
50
|
+
await ctx.scanLocalModels(true);
|
|
51
|
+
ctx.broadcast("models_change", { local: ctx.localStatePayload() });
|
|
52
|
+
json(res, 200, {
|
|
53
|
+
endpoint: { id: endpoint.id, label: endpoint.label },
|
|
54
|
+
...ctx.localStatePayload(),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
// Validation errors are the user's typo, not a system fault — 400 with
|
|
59
|
+
// the exact reason, and nothing in the transcript.
|
|
60
|
+
if (err instanceof LocalEndpointError) {
|
|
61
|
+
json(res, 400, { error: err.message });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
ctx.broadcastError("error", "add local endpoint failed", err);
|
|
65
|
+
json(res, 500, { error: "Could not save the endpoint — see the sidecar log." });
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (method === "DELETE" && url.startsWith("/local/endpoints/")) {
|
|
71
|
+
const id = decodeURIComponent(url.slice("/local/endpoints/".length));
|
|
72
|
+
void (async () => {
|
|
73
|
+
try {
|
|
74
|
+
await removeCustomEndpoint(id);
|
|
75
|
+
clearRuntimeModels((m) => m.provider === "local" && parseLocalModelId(m.id)?.endpointId === id);
|
|
76
|
+
await ctx.scanLocalModels(true);
|
|
77
|
+
ctx.broadcast("models_change", { local: ctx.localStatePayload() });
|
|
78
|
+
json(res, 200, ctx.localStatePayload());
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err instanceof LocalEndpointError) {
|
|
82
|
+
json(res, 400, { error: err.message });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
ctx.broadcastError("error", "remove local endpoint failed", err);
|
|
86
|
+
json(res, 500, { error: "Could not remove the endpoint — see the sidecar log." });
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
// ── Hugging Face search & pull (the "Add from Hugging Face" modal) ──
|
|
92
|
+
if (method === "GET" && url === "/hf/pull") {
|
|
93
|
+
json(res, 200, ctx.hfPull ? { active: ctx.hfPullPayload(ctx.hfPull) } : { active: null });
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (method === "POST" && url === "/hf/search") {
|
|
97
|
+
void readBody(req, res).then(async (raw) => {
|
|
98
|
+
if (raw === null)
|
|
99
|
+
return;
|
|
100
|
+
let body;
|
|
101
|
+
try {
|
|
102
|
+
body = JSON.parse(raw);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
json(res, 400, { error: "invalid JSON body" });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// Strip control characters and cap length — this goes into a URL query.
|
|
109
|
+
const query = String(body.query ?? "")
|
|
110
|
+
// eslint-disable-next-line no-control-regex -- stripping control characters is the point
|
|
111
|
+
.replace(/[\u0000-\u001f]/g, "")
|
|
112
|
+
.trim()
|
|
113
|
+
.slice(0, 100);
|
|
114
|
+
if (!query) {
|
|
115
|
+
json(res, 400, { error: "Type something to search for." });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
json(res, 200, { models: await ctx.hfSearch(query) });
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
ctx.broadcastError("error", "hugging face search failed", err);
|
|
123
|
+
json(res, 502, {
|
|
124
|
+
error: `Hugging Face search failed — ${err instanceof Error ? err.message : "network error"}.`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
if (method === "POST" && url === "/hf/pull") {
|
|
131
|
+
void readBody(req, res).then(async (raw) => {
|
|
132
|
+
if (raw === null)
|
|
133
|
+
return;
|
|
134
|
+
let body;
|
|
135
|
+
try {
|
|
136
|
+
body = JSON.parse(raw);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
json(res, 400, { error: "invalid JSON body" });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const repo = String(body.repo ?? "").trim();
|
|
143
|
+
if (!isValidHfRepoId(repo)) {
|
|
144
|
+
json(res, 400, { error: 'Expected a Hugging Face repo like "org/model".' });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
json(res, 200, await ctx.startHfPull(repo));
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
const status = err instanceof Error && "status" in err && typeof err.status === "number"
|
|
152
|
+
? err.status
|
|
153
|
+
: 502;
|
|
154
|
+
if (status >= 500)
|
|
155
|
+
ctx.broadcastError("error", "hugging face pull failed", err);
|
|
156
|
+
json(res, status, { error: err instanceof Error ? err.message : "Pull failed." });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
if (method === "POST" && url === "/hf/pull/cancel") {
|
|
162
|
+
json(res, 200, { ok: ctx.cancelHfPull() });
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (method === "GET" && url === "/telegram") {
|
|
166
|
+
void loadTelegramConfig().then((cfg) => {
|
|
167
|
+
if (!cfg) {
|
|
168
|
+
json(res, 200, { configured: false });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// Never return the raw token to the webview — a short masked preview is
|
|
172
|
+
// enough to show "already set".
|
|
173
|
+
const t = cfg.botToken;
|
|
174
|
+
const tokenPreview = t.length > 14 ? `${t.slice(0, 10)}\u2026${t.slice(-4)}` : "set";
|
|
175
|
+
json(res, 200, { configured: true, userId: cfg.userId, tokenPreview });
|
|
176
|
+
});
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
if (method === "POST" && url === "/telegram") {
|
|
180
|
+
void readBody(req, res).then(async (raw) => {
|
|
181
|
+
if (raw === null)
|
|
182
|
+
return;
|
|
183
|
+
let botTokenInput;
|
|
184
|
+
let userIdInput;
|
|
185
|
+
try {
|
|
186
|
+
const body = JSON.parse(raw);
|
|
187
|
+
botTokenInput = (body.botToken ?? "").trim();
|
|
188
|
+
userIdInput = String(body.userId ?? "").trim();
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
json(res, 400, { error: "invalid JSON body" });
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
// Keep the existing token when the field is left blank (the webview shows
|
|
195
|
+
// a masked preview, not the real token).
|
|
196
|
+
const existing = await loadTelegramConfig();
|
|
197
|
+
const botToken = botTokenInput || existing?.botToken || "";
|
|
198
|
+
if (!botToken) {
|
|
199
|
+
json(res, 400, { error: "Bot token is required." });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const userId = userIdInput ? parseInt(userIdInput, 10) : existing?.userId;
|
|
203
|
+
if (!userId || Number.isNaN(userId)) {
|
|
204
|
+
json(res, 400, { error: "A numeric Telegram user ID is required." });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const verified = await verifyBotToken(botToken);
|
|
208
|
+
if (!verified.ok) {
|
|
209
|
+
json(res, 400, { error: "Invalid bot token — Telegram rejected it." });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
await saveTelegramConfig({ botToken, userId });
|
|
213
|
+
json(res, 200, { ok: true, userId, username: verified.username ?? null });
|
|
214
|
+
});
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
// ── Serve lifecycle (mirrors `ggcoder serve`) ───────────
|
|
218
|
+
if (method === "GET" && url === "/serve") {
|
|
219
|
+
void loadTelegramConfig().then((cfg) => json(res, 200, { running: ctx.serveController !== null, configured: cfg !== null }));
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
if (method === "POST" && url === "/serve/start") {
|
|
223
|
+
void (async () => {
|
|
224
|
+
if (ctx.serveController) {
|
|
225
|
+
json(res, 200, { running: true });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const cfg = await loadTelegramConfig();
|
|
229
|
+
if (!cfg) {
|
|
230
|
+
json(res, 400, { error: "Telegram isn't set up yet. Open Serve settings first." });
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const st = ctx.session.getState();
|
|
234
|
+
try {
|
|
235
|
+
ctx.serveController = await startServeMode({
|
|
236
|
+
provider: st.provider,
|
|
237
|
+
model: st.model,
|
|
238
|
+
cwd: ctx.cwd,
|
|
239
|
+
version: "app",
|
|
240
|
+
thinkingLevel: ctx.session.getThinkingLevel() ?? undefined,
|
|
241
|
+
telegram: { botToken: cfg.botToken, userId: cfg.userId },
|
|
242
|
+
embedded: true,
|
|
243
|
+
});
|
|
244
|
+
ctx.broadcast("serve_change", { running: true });
|
|
245
|
+
log("INFO", "app-sidecar", "serve started", { userId: cfg.userId });
|
|
246
|
+
json(res, 200, { running: true });
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
ctx.serveController = null;
|
|
250
|
+
json(res, 400, { error: err instanceof Error ? err.message : String(err) });
|
|
251
|
+
}
|
|
252
|
+
})();
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
if (method === "POST" && url === "/serve/stop") {
|
|
256
|
+
void (async () => {
|
|
257
|
+
if (ctx.serveController) {
|
|
258
|
+
await ctx.serveController.stop().catch(() => { });
|
|
259
|
+
ctx.serveController = null;
|
|
260
|
+
ctx.broadcast("serve_change", { running: false });
|
|
261
|
+
log("INFO", "app-sidecar", "serve stopped");
|
|
262
|
+
}
|
|
263
|
+
json(res, 200, { running: false });
|
|
264
|
+
})();
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
// ── Agent Steroids (local code corpus) ───────────────────────────────
|
|
268
|
+
if (method === "GET" && url === "/steroids") {
|
|
269
|
+
void probeSteroids().then((status) => json(res, 200, status));
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
if (method === "POST" && url === "/steroids/install") {
|
|
273
|
+
void installSteroids()
|
|
274
|
+
.then((status) => {
|
|
275
|
+
ctx.broadcast("steroids_change", status);
|
|
276
|
+
log("INFO", "app-sidecar", "steroids installed", { version: status.version });
|
|
277
|
+
json(res, 200, status);
|
|
278
|
+
})
|
|
279
|
+
.catch((err) => {
|
|
280
|
+
json(res, 400, { error: err instanceof Error ? err.message : String(err) });
|
|
281
|
+
});
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=integration-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration-routes.js","sourceRoot":"","sources":["../../src/app-sidecar/integration-routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,UAAU,uBAAuB,CACrC,GAAwB,EACxB,GAAyB,EACzB,GAAwB,EACxB,GAAW,EACX,MAAc;IAEd,4DAA4D;IAC5D,yDAAyD;IACzD,wEAAwE;IACxE,qDAAqD;IACrD,IAAI,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC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AI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACtB,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,CAAC,CAAC;QACL,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-agents spawn the ggcoder CLI in JSON mode to run a delegated task. In the
|
|
3
|
+
* packaged desktop app the only runnable entry is THIS bundle (there's no
|
|
4
|
+
* sibling `cli.js`), so the subagent tool ends up spawning the sidecar itself.
|
|
5
|
+
* Without this guard that would boot a second HTTP server, emit no NDJSON, and
|
|
6
|
+
* hang until the 10-minute hard timeout. So when invoked with `--json`, behave
|
|
7
|
+
* exactly like `ggcoder --json …`: stream the sub-agent run as NDJSON and exit,
|
|
8
|
+
* never starting the HTTP/SSE server. Mirrors the `values.json` branch in cli.ts.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runJsonModeIfRequested(): Promise<boolean>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { runJsonMode } from "../modes/json-mode.js";
|
|
3
|
+
import { parseThinkingLevel } from "../cli/thinking-arg.js";
|
|
4
|
+
/**
|
|
5
|
+
* Sub-agents spawn the ggcoder CLI in JSON mode to run a delegated task. In the
|
|
6
|
+
* packaged desktop app the only runnable entry is THIS bundle (there's no
|
|
7
|
+
* sibling `cli.js`), so the subagent tool ends up spawning the sidecar itself.
|
|
8
|
+
* Without this guard that would boot a second HTTP server, emit no NDJSON, and
|
|
9
|
+
* hang until the 10-minute hard timeout. So when invoked with `--json`, behave
|
|
10
|
+
* exactly like `ggcoder --json …`: stream the sub-agent run as NDJSON and exit,
|
|
11
|
+
* never starting the HTTP/SSE server. Mirrors the `values.json` branch in cli.ts.
|
|
12
|
+
*/
|
|
13
|
+
export async function runJsonModeIfRequested() {
|
|
14
|
+
if (!process.argv.includes("--json"))
|
|
15
|
+
return false;
|
|
16
|
+
const { values, positionals } = parseArgs({
|
|
17
|
+
args: process.argv.slice(2),
|
|
18
|
+
options: {
|
|
19
|
+
json: { type: "boolean" },
|
|
20
|
+
provider: { type: "string" },
|
|
21
|
+
model: { type: "string" },
|
|
22
|
+
"max-turns": { type: "string" },
|
|
23
|
+
"system-prompt": { type: "string" },
|
|
24
|
+
"agent-prompt": { type: "string" },
|
|
25
|
+
"agent-context": { type: "string" },
|
|
26
|
+
tools: { type: "string" },
|
|
27
|
+
"mcp-servers": { type: "string" },
|
|
28
|
+
"prompt-cache-key": { type: "string" },
|
|
29
|
+
thinking: { type: "string" },
|
|
30
|
+
},
|
|
31
|
+
allowPositionals: true,
|
|
32
|
+
strict: true,
|
|
33
|
+
});
|
|
34
|
+
const maxTurnsRaw = values["max-turns"];
|
|
35
|
+
// Optional tool allow-list forwarded by the subagent spawner from an agent
|
|
36
|
+
// definition's `tools:` frontmatter. Mirrors the identical parsing in
|
|
37
|
+
// cli.ts's `values.json` branch — keep both in sync (see subagent.ts).
|
|
38
|
+
const parsedTools = values.tools
|
|
39
|
+
? values.tools
|
|
40
|
+
.split(",")
|
|
41
|
+
.map((t) => t.trim())
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
: [];
|
|
44
|
+
const allowedTools = parsedTools.length > 0 ? parsedTools : undefined;
|
|
45
|
+
// MCP servers the agent definition asked for. Without forwarding these, an
|
|
46
|
+
// allow-listed child connects no MCP at all and loses live code search.
|
|
47
|
+
const parsedMcpServers = values["mcp-servers"]
|
|
48
|
+
? values["mcp-servers"]
|
|
49
|
+
.split(",")
|
|
50
|
+
.map((s) => s.trim())
|
|
51
|
+
.filter(Boolean)
|
|
52
|
+
: [];
|
|
53
|
+
const allowedMcpServers = parsedMcpServers.length > 0 ? parsedMcpServers : undefined;
|
|
54
|
+
await runJsonMode({
|
|
55
|
+
message: positionals[0] ?? "",
|
|
56
|
+
provider: (values.provider ?? "anthropic"),
|
|
57
|
+
model: values.model ?? "claude-opus-5-5",
|
|
58
|
+
cwd: process.cwd(),
|
|
59
|
+
systemPrompt: values["system-prompt"],
|
|
60
|
+
agentPrompt: values["agent-prompt"],
|
|
61
|
+
agentContext: values["agent-context"] === "none" ? "none" : undefined,
|
|
62
|
+
maxTurns: maxTurnsRaw ? parseInt(maxTurnsRaw, 10) : undefined,
|
|
63
|
+
allowedTools,
|
|
64
|
+
allowedMcpServers,
|
|
65
|
+
promptCacheKey: values["prompt-cache-key"],
|
|
66
|
+
thinkingLevel: parseThinkingLevel(values.thinking),
|
|
67
|
+
}).catch(async (err) => {
|
|
68
|
+
process.stderr.write((err instanceof Error ? err.message : String(err)) + "\n");
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=json-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-mode.js","sourceRoot":"","sources":["../../src/app-sidecar/json-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;QACxC,IAAI,EAAE,OAAO,CAAC,IAA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AAC;IAClB,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { KeepAwake } from "../core/keep-awake.js";
|
|
2
|
+
/** App-wide idle-sleep guard: every window's runs share one OS assertion. The
|
|
3
|
+
* `keepAwake` setting is applied at daemon start and live via /keep-awake. */
|
|
4
|
+
export const keepAwake = new KeepAwake();
|
|
5
|
+
//# sourceMappingURL=keep-awake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keep-awake.js","sourceRoot":"","sources":["../../src/app-sidecar/keep-awake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;+EAC+E;AAC/E,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentSession } from "../core/agent-session.js";
|
|
2
|
+
import type { WorkflowCommandSpec } from "../core/autopilot-gate.js";
|
|
3
|
+
/** Ken's read-only tool allow-list. Excludes every mutating tool (write/edit/
|
|
4
|
+
* bash/tasks/subagent/generate_image/enter_plan/exit_plan/task_*) so the mentor
|
|
5
|
+
* agent can research + see, but never change the repo. */
|
|
6
|
+
export declare const KEN_ALLOWED_TOOLS: string[];
|
|
7
|
+
/** Extract the plain text of the most recent assistant message (Ken's reply).
|
|
8
|
+
* Strips tool-call / image blocks, returning just the prose Ken streamed. */
|
|
9
|
+
export declare function lastAssistantText(messages: ReturnType<AgentSession["getMessages"]>): string;
|
|
10
|
+
/**
|
|
11
|
+
* Assemble Ken's context digest for one `@Ken` question: git/env + the build
|
|
12
|
+
* session's compaction summary + recent activity. Prepended to the user's
|
|
13
|
+
* question as Ken's prompt body each turn. Project docs (CLAUDE.md/AGENTS.md)
|
|
14
|
+
* are NOT here — they're folded into Ken's cached system prompt once per
|
|
15
|
+
* session instead (see ken-prompt.ts), so they hit the provider prompt cache
|
|
16
|
+
* instead of being re-sent uncached on every question. Workflow commands +
|
|
17
|
+
* autopilot-injected prompts are passed through so the digest labels them as
|
|
18
|
+
* what they are instead of user-authored asks.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildKenContext(buildSession: AgentSession, cwd: string, gitBranch: string | null, question: string, workflowCommands: readonly WorkflowCommandSpec[], injectedPrompts: readonly string[]): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { buildKenDigest } from "../core/ken-context.js";
|
|
2
|
+
/** Ken's read-only tool allow-list. Excludes every mutating tool (write/edit/
|
|
3
|
+
* bash/tasks/subagent/generate_image/enter_plan/exit_plan/task_*) so the mentor
|
|
4
|
+
* agent can research + see, but never change the repo. */
|
|
5
|
+
export const KEN_ALLOWED_TOOLS = [
|
|
6
|
+
"read",
|
|
7
|
+
"grep",
|
|
8
|
+
"find",
|
|
9
|
+
"ls",
|
|
10
|
+
"source_path",
|
|
11
|
+
"web_fetch",
|
|
12
|
+
"web_search",
|
|
13
|
+
"screenshot",
|
|
14
|
+
// Local corpus of real repos: lets Ken verify against code that ships
|
|
15
|
+
// instead of assuming — core to how he's meant to work. Read-only.
|
|
16
|
+
"steroids",
|
|
17
|
+
];
|
|
18
|
+
/** Extract the plain text of the most recent assistant message (Ken's reply).
|
|
19
|
+
* Strips tool-call / image blocks, returning just the prose Ken streamed. */
|
|
20
|
+
export function lastAssistantText(messages) {
|
|
21
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
22
|
+
const m = messages[i];
|
|
23
|
+
if (m.role !== "assistant")
|
|
24
|
+
continue;
|
|
25
|
+
if (typeof m.content === "string")
|
|
26
|
+
return m.content;
|
|
27
|
+
return m.content
|
|
28
|
+
.map((c) => (c.type === "text" && "text" in c && typeof c.text === "string" ? c.text : ""))
|
|
29
|
+
.join("");
|
|
30
|
+
}
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Assemble Ken's context digest for one `@Ken` question: git/env + the build
|
|
35
|
+
* session's compaction summary + recent activity. Prepended to the user's
|
|
36
|
+
* question as Ken's prompt body each turn. Project docs (CLAUDE.md/AGENTS.md)
|
|
37
|
+
* are NOT here — they're folded into Ken's cached system prompt once per
|
|
38
|
+
* session instead (see ken-prompt.ts), so they hit the provider prompt cache
|
|
39
|
+
* instead of being re-sent uncached on every question. Workflow commands +
|
|
40
|
+
* autopilot-injected prompts are passed through so the digest labels them as
|
|
41
|
+
* what they are instead of user-authored asks.
|
|
42
|
+
*/
|
|
43
|
+
export function buildKenContext(buildSession, cwd, gitBranch, question, workflowCommands, injectedPrompts) {
|
|
44
|
+
return buildKenDigest({
|
|
45
|
+
question,
|
|
46
|
+
cwd,
|
|
47
|
+
gitBranch,
|
|
48
|
+
messages: buildSession.getMessages(),
|
|
49
|
+
verificationEvidence: buildSession.getVerificationEvidence(),
|
|
50
|
+
verificationProblem: buildSession.getVerificationProblem(),
|
|
51
|
+
workflowCommands,
|
|
52
|
+
injectedPrompts,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=ken-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ken-context.js","sourceRoot":"","sources":["../../src/app-sidecar/ken-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD;;2DAE2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM;IACN,MAAM;IACN,MAAM;IACN,IAAI;IACJ,aAAa;IACb,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,sEAAsE;IACtE,mEAAmE;IACnE,UAAU;CACX,CAAC;AAEF;8EAC8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,QAAiD;IACjF,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,CAAC,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