@kenkaiiii/ggcoder 5.96.2 → 5.97.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/dist/app-sidecar/autopilot-runner.js +5 -3
- package/dist/app-sidecar/autopilot-runner.js.map +1 -1
- package/dist/app-sidecar/prompt-routes.js +4 -1
- package/dist/app-sidecar/prompt-routes.js.map +1 -1
- package/dist/app-sidecar.js +9 -4
- package/dist/app-sidecar.js.map +1 -1
- package/dist/core/agent-session.d.ts +5 -0
- package/dist/core/agent-session.js +104 -8
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/agents.d.ts +0 -10
- package/dist/core/agents.js +5 -1
- package/dist/core/agents.js.map +1 -1
- package/dist/core/ask-user.js +1 -1
- package/dist/core/ask-user.js.map +1 -1
- package/dist/core/claude-code/complete.d.ts +2 -0
- package/dist/core/claude-code/complete.js +3 -0
- package/dist/core/claude-code/complete.js.map +1 -1
- package/dist/core/claude-code/transcripts.d.ts +29 -0
- package/dist/core/claude-code/transcripts.js +117 -0
- package/dist/core/claude-code/transcripts.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +2 -0
- package/dist/core/compaction/compactor.js +7 -3
- package/dist/core/compaction/compactor.js.map +1 -1
- package/dist/core/compaction/tool-result-pruner.d.ts +12 -2
- package/dist/core/compaction/tool-result-pruner.js +14 -3
- package/dist/core/compaction/tool-result-pruner.js.map +1 -1
- package/dist/core/process-manager.d.ts +1 -1
- package/dist/core/process-manager.js +1 -1
- package/dist/core/session-manager.d.ts +5 -0
- package/dist/core/session-manager.js +12 -7
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/shell-path.d.ts +2 -0
- package/dist/core/shell-path.js +10 -1
- package/dist/core/shell-path.js.map +1 -1
- package/dist/modes/acp-mode.d.ts +1 -1
- package/dist/system-prompt.d.ts +5 -1
- package/dist/system-prompt.js +12 -5
- package/dist/system-prompt.js.map +1 -1
- package/dist/ui/components/Footer.js +2 -1
- package/dist/ui/components/Footer.js.map +1 -1
- package/package.json +4 -4
|
@@ -618,6 +618,7 @@ export declare class AgentSession {
|
|
|
618
618
|
private claudeCodeProcess;
|
|
619
619
|
/** Append a deferred built-in to the live tool list (append-only). */
|
|
620
620
|
private promoteDeferredBuiltin;
|
|
621
|
+
private reloadUsedTools;
|
|
621
622
|
private wrapToPromote;
|
|
622
623
|
/**
|
|
623
624
|
* Publish cached tool definitions into the deferred catalog so `tool_search`
|
|
@@ -811,6 +812,7 @@ export declare class AgentSession {
|
|
|
811
812
|
* compaction/plan-step-policy.ts says the shrink pays for itself.
|
|
812
813
|
*/
|
|
813
814
|
private maybeCompactPostTurn;
|
|
815
|
+
private withLiveAccessToken;
|
|
814
816
|
compact(existingCredentials?: {
|
|
815
817
|
accessToken: string;
|
|
816
818
|
accountId?: string;
|
|
@@ -1225,6 +1227,9 @@ export declare class AgentSession {
|
|
|
1225
1227
|
private prewarmController;
|
|
1226
1228
|
/** Claude Code session that has seen this history (Claude subscription route). */
|
|
1227
1229
|
private claudeCodeSession;
|
|
1230
|
+
private releaseClaudeCodeTranscript;
|
|
1231
|
+
/** Keep the retention pass off the transcript this chat would resume. */
|
|
1232
|
+
private holdClaudeCodeTranscript;
|
|
1228
1233
|
/** This chat's running Claude Code process, reused while `key` (its start settings) matches. */
|
|
1229
1234
|
private claudeCodeLive;
|
|
1230
1235
|
/**
|
|
@@ -13,9 +13,10 @@ import { loadWorkspaceCustomCommands } from "./custom-commands.js";
|
|
|
13
13
|
import { expandPromptCommand } from "./prompt-command-expansion.js";
|
|
14
14
|
import { SettingsManager } from "./settings-manager.js";
|
|
15
15
|
import { AuthStorage } from "./auth-storage.js";
|
|
16
|
-
import { dualAuthProvider } from "@kenkaiiii/gg-core";
|
|
16
|
+
import { claudeCodeConfigDir, dualAuthProvider } from "@kenkaiiii/gg-core";
|
|
17
|
+
import { claudeCodeTranscriptExists, holdClaudeCodeTranscript, pruneClaudeCodeTranscriptsOnce, } from "./claude-code/transcripts.js";
|
|
17
18
|
import { runSideWebSearch, runSideWebSearchViaClaudeCode, SIDE_SEARCH_MODEL, } from "../tools/side-web-search.js";
|
|
18
|
-
import { SessionManager, } from "./session-manager.js";
|
|
19
|
+
import { SessionManager, processIsAlive, } from "./session-manager.js";
|
|
19
20
|
import { ExtensionLoader } from "./extensions/loader.js";
|
|
20
21
|
import { shouldCompact, compact, } from "./compaction/compactor.js";
|
|
21
22
|
import { getHistoryMessageVisibility } from "./session-history.js";
|
|
@@ -747,6 +748,7 @@ export class AgentSession {
|
|
|
747
748
|
message: error instanceof Error ? error.message : String(error),
|
|
748
749
|
});
|
|
749
750
|
});
|
|
751
|
+
void pruneClaudeCodeTranscriptsOnce(claudeCodeConfigDir());
|
|
750
752
|
}
|
|
751
753
|
// GG Coder owns its command registry. Other agents start with an isolated
|
|
752
754
|
// empty registry and can register their own commands in their own file.
|
|
@@ -1059,7 +1061,14 @@ export class AgentSession {
|
|
|
1059
1061
|
/** One run on the Claude subscription route: Claude Code drives the loop with our prompt and tools. */
|
|
1060
1062
|
async runClaudeCodeLoop(process, options) {
|
|
1061
1063
|
let loopMessages = await this.prepareDynamicContext();
|
|
1062
|
-
|
|
1064
|
+
let resume = claudeCodeResumeId(this.claudeCodeSession, loopMessages);
|
|
1065
|
+
// Claude Code fails a resume whose transcript is gone (retention pass, or
|
|
1066
|
+
// removed by hand); our history can seed a fresh session instead.
|
|
1067
|
+
if (resume &&
|
|
1068
|
+
!(await claudeCodeTranscriptExists(process.env.CLAUDE_CONFIG_DIR ?? claudeCodeConfigDir(), resume))) {
|
|
1069
|
+
log("INFO", "claude-code", "Transcript missing; seeding a fresh session from history");
|
|
1070
|
+
resume = undefined;
|
|
1071
|
+
}
|
|
1063
1072
|
// A fresh Claude Code session gets our history as text; summarize it first
|
|
1064
1073
|
// when it would not fit.
|
|
1065
1074
|
if (!resume &&
|
|
@@ -1125,6 +1134,35 @@ export class AgentSession {
|
|
|
1125
1134
|
policy: CLAUDE_CODE_CACHE_TTL,
|
|
1126
1135
|
});
|
|
1127
1136
|
}
|
|
1137
|
+
// Same line names as the public-API route, which logs them from the agent loop.
|
|
1138
|
+
if (event.type === "turn_end") {
|
|
1139
|
+
const cacheRead = event.usage.cacheRead ?? 0;
|
|
1140
|
+
const cacheWrite = event.usage.cacheWrite ?? 0;
|
|
1141
|
+
const promptTokens = event.usage.inputTokens + cacheRead + cacheWrite;
|
|
1142
|
+
log("INFO", "stream", "cache_health", {
|
|
1143
|
+
promptTokens,
|
|
1144
|
+
cacheRead,
|
|
1145
|
+
cacheWrite,
|
|
1146
|
+
...(promptTokens > 0
|
|
1147
|
+
? { ratio: Math.round((cacheRead / promptTokens) * 100) / 100 }
|
|
1148
|
+
: {}),
|
|
1149
|
+
...(event.timing.ttftMs !== undefined ? { ttftMs: event.timing.ttftMs } : {}),
|
|
1150
|
+
providerDurationMs: event.timing.providerDurationMs,
|
|
1151
|
+
outputTokens: event.usage.outputTokens,
|
|
1152
|
+
provider: this.provider,
|
|
1153
|
+
model: this.model,
|
|
1154
|
+
transport: "claude_code",
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
else if (event.type === "retry") {
|
|
1158
|
+
log("INFO", "stream", "retry", {
|
|
1159
|
+
reason: event.reason,
|
|
1160
|
+
attempt: event.attempt,
|
|
1161
|
+
maxAttempts: event.maxAttempts,
|
|
1162
|
+
delayMs: event.delayMs,
|
|
1163
|
+
transport: "claude_code",
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1128
1166
|
this.eventBus.forwardAgentEvent(event);
|
|
1129
1167
|
}
|
|
1130
1168
|
}
|
|
@@ -1192,6 +1230,7 @@ export class AgentSession {
|
|
|
1192
1230
|
const history = this.messages.filter((m) => m.role !== "system");
|
|
1193
1231
|
const state = { sessionId, messageCount: history.length, anchor: history.at(-1) };
|
|
1194
1232
|
this.claudeCodeSession = state;
|
|
1233
|
+
this.holdClaudeCodeTranscript();
|
|
1195
1234
|
if (!this.sessionPath)
|
|
1196
1235
|
return;
|
|
1197
1236
|
await this.sessionManager.appendEntry(this.sessionPath, {
|
|
@@ -1219,6 +1258,26 @@ export class AgentSession {
|
|
|
1219
1258
|
this.tools.push(tool);
|
|
1220
1259
|
return tool;
|
|
1221
1260
|
}
|
|
1261
|
+
// A restored conversation still calls the on-demand tools it used; Claude
|
|
1262
|
+
// Code refuses any name missing from the list this process gives it.
|
|
1263
|
+
reloadUsedTools(messages) {
|
|
1264
|
+
if (this.deferredBuiltinToolNames.length === 0)
|
|
1265
|
+
return;
|
|
1266
|
+
for (const message of messages) {
|
|
1267
|
+
if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
1268
|
+
for (const part of message.content) {
|
|
1269
|
+
if (part.type === "tool_call")
|
|
1270
|
+
this.promoteDeferredBuiltin(part.name);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
else if (message.role === "tool") {
|
|
1274
|
+
for (const result of message.content) {
|
|
1275
|
+
for (const name of result.loadedTools ?? [])
|
|
1276
|
+
this.promoteDeferredBuiltin(name);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1222
1281
|
wrapToPromote(trigger, followUps, when = () => true) {
|
|
1223
1282
|
const index = this.tools.findIndex((t) => t.name === trigger);
|
|
1224
1283
|
const tool = index >= 0 ? this.tools[index] : undefined;
|
|
@@ -2315,7 +2374,7 @@ export class AgentSession {
|
|
|
2315
2374
|
if (shouldPruneToolResults(activeTokens, policy.targetTokens)) {
|
|
2316
2375
|
const cacheCold = this.getCacheExpiryStatus()?.expired ?? false;
|
|
2317
2376
|
const pruneResult = pruneStaleToolResults(messages, {
|
|
2318
|
-
minimumTokens: pruneMinimumTokens(activeTokens, cacheCold),
|
|
2377
|
+
minimumTokens: pruneMinimumTokens(activeTokens, cacheCold, policy.targetTokens),
|
|
2319
2378
|
});
|
|
2320
2379
|
if (pruneResult.pruned) {
|
|
2321
2380
|
this.cacheDiagnostics.noteEdit("tool_prune", pruneResult.freedTokens);
|
|
@@ -2931,6 +2990,18 @@ export class AgentSession {
|
|
|
2931
2990
|
}
|
|
2932
2991
|
})();
|
|
2933
2992
|
}
|
|
2993
|
+
// A caller's token was captured at run start; the loop may have rotated it since.
|
|
2994
|
+
async withLiveAccessToken(captured) {
|
|
2995
|
+
try {
|
|
2996
|
+
const live = await this.authStorage.resolveCredentials(this.provider, {
|
|
2997
|
+
storageKeys: this.currentAuthStorageKeys(),
|
|
2998
|
+
});
|
|
2999
|
+
return { ...captured, accessToken: live.accessToken };
|
|
3000
|
+
}
|
|
3001
|
+
catch {
|
|
3002
|
+
return captured;
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
2934
3005
|
async compact(existingCredentials, mode = "manual",
|
|
2935
3006
|
/** User-stated focus (`/compact <focus>`): what must survive verbatim. */
|
|
2936
3007
|
focus,
|
|
@@ -2941,12 +3012,13 @@ export class AgentSession {
|
|
|
2941
3012
|
? AbortSignal.any([this.opts.signal, abortSignal])
|
|
2942
3013
|
: (abortSignal ?? this.opts.signal);
|
|
2943
3014
|
const claudeCode = existingCredentials ? null : await this.claudeCodeProcess();
|
|
2944
|
-
const creds = existingCredentials
|
|
2945
|
-
(
|
|
3015
|
+
const creds = existingCredentials
|
|
3016
|
+
? await this.withLiveAccessToken(existingCredentials)
|
|
3017
|
+
: claudeCode
|
|
2946
3018
|
? { accessToken: "" }
|
|
2947
3019
|
: await this.authStorage.resolveCredentials(this.provider, {
|
|
2948
3020
|
storageKeys: this.currentAuthStorageKeys(),
|
|
2949
|
-
})
|
|
3021
|
+
});
|
|
2950
3022
|
const contextWindow = getContextWindow(this.model, {
|
|
2951
3023
|
provider: this.provider,
|
|
2952
3024
|
accountId: creds.accountId,
|
|
@@ -3788,6 +3860,8 @@ export class AgentSession {
|
|
|
3788
3860
|
}
|
|
3789
3861
|
const toolNames = this.tools.map((tool) => tool.name);
|
|
3790
3862
|
const deferredToolNames = this.deferredToolNamesForPrompt(toolNames);
|
|
3863
|
+
// A missing Claude Code binary fails the run itself with a clear message, not the prompt build.
|
|
3864
|
+
const deferredNeedSearch = deferredToolNames.length > 0 && (await this.claudeCodeProcess().then(Boolean, () => false));
|
|
3791
3865
|
// Whatever is rendered now is what the model has been told.
|
|
3792
3866
|
this.announcedLanguages = new Set(this.activeLanguages);
|
|
3793
3867
|
if (this.agentPrompt !== undefined) {
|
|
@@ -3795,6 +3869,7 @@ export class AgentSession {
|
|
|
3795
3869
|
cwd: this.cwd,
|
|
3796
3870
|
toolNames,
|
|
3797
3871
|
deferredToolNames,
|
|
3872
|
+
deferredNeedSearch,
|
|
3798
3873
|
context: this.opts.agentContext,
|
|
3799
3874
|
role: this.opts.agentRole,
|
|
3800
3875
|
environment: this.recordRenderedEnvironment(),
|
|
@@ -3802,7 +3877,7 @@ export class AgentSession {
|
|
|
3802
3877
|
...(this.languagesApply() ? { activeLanguages: this.activeLanguages } : {}),
|
|
3803
3878
|
});
|
|
3804
3879
|
}
|
|
3805
|
-
return buildSystemPrompt(this.cwd, this.skills, planMode, approvedPlanPath, toolNames, this.activeLanguages, this.provider, this.recordRenderedEnvironment(), deferredToolNames, this.contextLimits);
|
|
3880
|
+
return buildSystemPrompt(this.cwd, this.skills, planMode, approvedPlanPath, toolNames, this.activeLanguages, this.provider, this.recordRenderedEnvironment(), deferredToolNames, this.contextLimits, deferredNeedSearch);
|
|
3806
3881
|
}
|
|
3807
3882
|
/**
|
|
3808
3883
|
* Bring the system prompt to the exact state the next provider request will
|
|
@@ -4132,6 +4207,7 @@ export class AgentSession {
|
|
|
4132
4207
|
generation,
|
|
4133
4208
|
startedAt: new Date().toISOString(),
|
|
4134
4209
|
afterMessageCount: this.persistedTranscriptCount(),
|
|
4210
|
+
pid: process.pid,
|
|
4135
4211
|
});
|
|
4136
4212
|
}
|
|
4137
4213
|
/** Close the run journal. Its absence is what marks a run as crashed. */
|
|
@@ -4259,6 +4335,13 @@ export class AgentSession {
|
|
|
4259
4335
|
prewarmController = null;
|
|
4260
4336
|
/** Claude Code session that has seen this history (Claude subscription route). */
|
|
4261
4337
|
claudeCodeSession = null;
|
|
4338
|
+
releaseClaudeCodeTranscript;
|
|
4339
|
+
/** Keep the retention pass off the transcript this chat would resume. */
|
|
4340
|
+
holdClaudeCodeTranscript() {
|
|
4341
|
+
this.releaseClaudeCodeTranscript?.();
|
|
4342
|
+
const sessionId = this.claudeCodeSession?.sessionId;
|
|
4343
|
+
this.releaseClaudeCodeTranscript = sessionId ? holdClaudeCodeTranscript(sessionId) : undefined;
|
|
4344
|
+
}
|
|
4262
4345
|
/** This chat's running Claude Code process, reused while `key` (its start settings) matches. */
|
|
4263
4346
|
claudeCodeLive = null;
|
|
4264
4347
|
/**
|
|
@@ -4430,6 +4513,8 @@ export class AgentSession {
|
|
|
4430
4513
|
// step leaves background commands running after the app has quit.
|
|
4431
4514
|
this.stopBackgroundProcesses();
|
|
4432
4515
|
this.installedWatchStop?.();
|
|
4516
|
+
this.releaseClaudeCodeTranscript?.();
|
|
4517
|
+
this.releaseClaudeCodeTranscript = undefined;
|
|
4433
4518
|
// Quiesce any in-flight post-turn compaction BEFORE tearing down state:
|
|
4434
4519
|
// the background compact() snapshots and replaces `this.messages`, so
|
|
4435
4520
|
// letting it run past this point would checkpoint a near-empty history
|
|
@@ -4557,7 +4642,9 @@ export class AgentSession {
|
|
|
4557
4642
|
// not fail when Anthropic's stricter many-image limit activates later.
|
|
4558
4643
|
const systemMsg = this.messages[0]; // Already built
|
|
4559
4644
|
this.messages = [systemMsg, ...loadedMessages];
|
|
4645
|
+
this.reloadUsedTools(loadedMessages);
|
|
4560
4646
|
this.claudeCodeSession = parseClaudeCodeSessionState(savedClaudeCode?.type === "custom" ? savedClaudeCode.data : null, loadedMessages);
|
|
4647
|
+
this.holdClaudeCodeTranscript();
|
|
4561
4648
|
// Reads recorded for the previous conversation don't carry over.
|
|
4562
4649
|
this.clearReadTracker?.();
|
|
4563
4650
|
const normalizedImageCount = await normalizeMessageImages(this.messages);
|
|
@@ -4636,6 +4723,15 @@ export class AgentSession {
|
|
|
4636
4723
|
*/
|
|
4637
4724
|
async recordInterruptedRuns(runs) {
|
|
4638
4725
|
for (const run of runs) {
|
|
4726
|
+
// Another app has this chat open and is still running it: not a crash.
|
|
4727
|
+
if (run.pid !== undefined && run.pid !== process.pid && processIsAlive(run.pid)) {
|
|
4728
|
+
log("WARN", "session", "Unfinished run belongs to another live process; left open", {
|
|
4729
|
+
generation: String(run.generation),
|
|
4730
|
+
startedAt: run.startedAt,
|
|
4731
|
+
pid: String(run.pid),
|
|
4732
|
+
});
|
|
4733
|
+
continue;
|
|
4734
|
+
}
|
|
4639
4735
|
log("WARN", "session", "Restored a session with an unfinished run", {
|
|
4640
4736
|
generation: String(run.generation),
|
|
4641
4737
|
startedAt: run.startedAt,
|