@averyyy/pi-coding-agent 1.3.0-piclient.4 → 1.4.0-piclient.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/CHANGELOG.md +59 -0
- package/dist/bundle/chunks/anthropic-messages-3TZAX2CL.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-5OV6AS44.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +8 -8
- package/dist/bundle/chunks/{chunk-27EJF7XV.js → chunk-3EGEEHMN.js} +1 -1
- package/dist/bundle/chunks/{chunk-VBIW3SGN.js → chunk-3LTMO2WY.js} +1 -1
- package/dist/bundle/chunks/{chunk-PYGXRV27.js → chunk-3V45WARH.js} +1 -1
- package/dist/bundle/chunks/{chunk-S3GGRYIO.js → chunk-5AGIVGSV.js} +1 -1
- package/dist/bundle/chunks/{chunk-MSGIVOTQ.js → chunk-6QSWJM5G.js} +1 -1
- package/dist/bundle/chunks/{chunk-F5ZABL6Z.js → chunk-7CBJINYJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-DRQDKNXA.js → chunk-7DDKXS2Q.js} +1 -1
- package/dist/bundle/chunks/{chunk-JBOKZR45.js → chunk-BRYV63PL.js} +2 -2
- package/dist/bundle/chunks/{chunk-H3QXYIF7.js → chunk-CF5GWZHW.js} +1 -1
- package/dist/bundle/chunks/chunk-D3OXAPLU.js +11 -0
- package/dist/bundle/chunks/{chunk-WALKIYXG.js → chunk-GA3MDGH3.js} +1 -1
- package/dist/bundle/chunks/chunk-H2AI7MFJ.js +9 -0
- package/dist/bundle/chunks/{chunk-XDNB4NV2.js → chunk-H2UJDH5M.js} +10 -9
- package/dist/bundle/chunks/chunk-H76KZMOI.js +2 -0
- package/dist/bundle/chunks/chunk-HZG4C6GI.js +2 -0
- package/dist/bundle/chunks/{chunk-4L3WN2XY.js → chunk-JXWJOIH4.js} +1 -1
- package/dist/bundle/chunks/{chunk-6CYCI3EJ.js → chunk-LVVZS2NO.js} +1 -1
- package/dist/bundle/chunks/{chunk-A5PVA2BG.js → chunk-OSZFX42P.js} +3 -3
- package/dist/bundle/chunks/{chunk-PT5WCDHM.js → chunk-PG7P2LUM.js} +2 -2
- package/dist/bundle/chunks/{chunk-DYPQLT4D.js → chunk-RU2UAASR.js} +47 -41
- package/dist/bundle/chunks/chunk-TLSZ4DWU.js +16 -0
- package/dist/bundle/chunks/{chunk-ZBURYEWF.js → chunk-TMTOQ7H7.js} +1 -1
- package/dist/bundle/chunks/{chunk-22CYIUS4.js → chunk-UKVNB6C4.js} +1 -1
- package/dist/bundle/chunks/chunk-VHUVVKJM.js +2 -0
- package/dist/bundle/chunks/{chunk-32OQRHU5.js → chunk-VYYRESZJ.js} +1 -1
- package/dist/bundle/chunks/chunk-WVXVPMMO.js +2 -0
- package/dist/bundle/chunks/{cli-C7ZYV7NI.js → cli-QUNA6INU.js} +1 -1
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-QIIM6OB4.js +2 -0
- package/dist/bundle/chunks/{easter-egg-3d-JPU5ICBY.js → easter-egg-3d-4L2AVJKX.js} +1 -1
- package/dist/bundle/chunks/{execute-ZWI524ZI.js → execute-UNST3ORJ.js} +9 -3
- package/dist/bundle/chunks/google-antigravity-runtime.js +7 -7
- package/dist/bundle/chunks/google-generative-ai-MSA77EGV.js +2 -0
- package/dist/bundle/chunks/google-vertex-MQ5IHJDO.js +2 -0
- package/dist/bundle/chunks/{https-proxy-agent-UDEHOBGS.js → https-proxy-agent-LVOO5TPL.js} +1 -1
- package/dist/bundle/chunks/{jiti-loader-C3NU2SDH.js → jiti-loader-GL4HJFAD.js} +1 -1
- package/dist/bundle/chunks/{jiti-static-loader-E6ANQD5T.js → jiti-static-loader-2RCDI6B4.js} +1 -1
- package/dist/bundle/chunks/{lib-TEDK3E5I.js → lib-4AVRLBHM.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-FYN623RH.js → llama-cpp-classify-U4EH6TAM.js} +2 -2
- package/dist/bundle/chunks/{mistral-conversations-IDNVOMLP.js → mistral-conversations-OJFHLO4F.js} +1 -1
- package/dist/bundle/chunks/{multipart-parser-SQ6GDJL7.js → multipart-parser-FMGQ7342.js} +1 -1
- package/dist/bundle/chunks/{node-TWVVAGPO.js → node-AUOGOBCN.js} +1 -1
- package/dist/bundle/chunks/{node-N5BSDOA5.js → node-KCMANYC2.js} +1 -1
- package/dist/bundle/chunks/openai-codex-responses-UIB63WGM.js +10 -0
- package/dist/bundle/chunks/openai-completions-T5JB7LUM.js +7 -0
- package/dist/bundle/chunks/{openai-decisions-CWANEVXX.js → openai-decisions-Q46R33J3.js} +1 -1
- package/dist/bundle/chunks/openai-responses-FGTD6NDJ.js +4 -0
- package/dist/bundle/chunks/openrouter-images-WBAVKHHY.js +2 -0
- package/dist/bundle/chunks/pi-messages-S7RKCD5K.js +8 -0
- package/dist/bundle/chunks/{runtime-RTNZQVM5.js → runtime-SITSZTHV.js} +1 -1
- package/dist/bundle/chunks/{src-UK77SYZE.js → src-QKGKDFSU.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-DFEHTLK5.js +2 -0
- package/dist/bundle/chunks/virtual-modules-RXJOVL6L.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +16 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +88 -29
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/client-identity.d.ts +8 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +15 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +3 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +35 -30
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +2 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +3 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/model-config.d.ts +915 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +48 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.js +2 -2
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +6 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.js +2 -2
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-server-client.d.ts.map +1 -1
- package/dist/core/pi-server-client.js +4 -1
- package/dist/core/pi-server-client.js.map +1 -1
- package/dist/core/pi-server-observer.d.ts +93 -0
- package/dist/core/pi-server-observer.d.ts.map +1 -0
- package/dist/core/pi-server-observer.js +452 -0
- package/dist/core/pi-server-observer.js.map +1 -0
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +18 -10
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +99 -24
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +11 -15
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +73 -115
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +1 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +3 -2
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +45 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/codemode.md +2 -2
- package/docs/compaction.md +3 -3
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +1 -0
- package/docs/extensions.md +133 -10
- package/docs/models-configuration.md +196 -0
- package/docs/models.md +21 -5
- package/docs/settings.md +1 -1
- package/docs/tui.md +70 -0
- package/docs/windows.md +16 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +7 -6
- package/schemas/models.schema.json +83 -29
- package/dist/bundle/chunks/anthropic-messages-JKZEYO3X.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-CALHHRO4.js +0 -2
- package/dist/bundle/chunks/chunk-2TBKESBE.js +0 -2
- package/dist/bundle/chunks/chunk-3IAHLZM6.js +0 -2
- package/dist/bundle/chunks/chunk-KO7M2ZFM.js +0 -11
- package/dist/bundle/chunks/chunk-NAPMJL5U.js +0 -11
- package/dist/bundle/chunks/chunk-VZZDG22Y.js +0 -9
- package/dist/bundle/chunks/chunk-XIQJS2WK.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-W3JVUOXV.js +0 -2
- package/dist/bundle/chunks/google-generative-ai-4YEPBKDH.js +0 -2
- package/dist/bundle/chunks/google-vertex-5HD3H47T.js +0 -2
- package/dist/bundle/chunks/openai-codex-responses-TWAB375R.js +0 -10
- package/dist/bundle/chunks/openai-completions-3LCSEI2J.js +0 -7
- package/dist/bundle/chunks/openai-responses-JEQACBMR.js +0 -3
- package/dist/bundle/chunks/openrouter-images-DUPG5DZO.js +0 -2
- package/dist/bundle/chunks/pi-messages-V27DSLVC.js +0 -8
- package/dist/bundle/chunks/typesafe-system-one-JJVDHYHL.js +0 -2
- package/dist/bundle/chunks/virtual-modules-4VB3FSWN.js +0 -2
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -72
- package/dist/core/provider-attribution.js.map +0 -1
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
16
|
import { basename, dirname } from "node:path";
|
|
17
17
|
import { runToolCall, } from "@earendil-works/pi-agent-core";
|
|
18
|
-
import { contentText, getCurrentSystemMessage, normalizeContext, retryDelayMs } from "@earendil-works/pi-ai";
|
|
18
|
+
import { contentText, getCurrentSystemMessage, getCurrentTools, normalizeContext, retryDelayMs, } from "@earendil-works/pi-ai";
|
|
19
19
|
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@earendil-works/pi-ai/compat";
|
|
20
20
|
import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
|
|
21
21
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
@@ -228,7 +228,6 @@ export class AgentSession {
|
|
|
228
228
|
_entryIdsByMessage = new WeakMap();
|
|
229
229
|
_boundaryDispatchedMessages = new WeakSet();
|
|
230
230
|
_lastAssistantMessage;
|
|
231
|
-
_lastAssistantToolResults = [];
|
|
232
231
|
_lastActivityOutcome = "completed";
|
|
233
232
|
_isBeforeSettle = false;
|
|
234
233
|
_abortDuringBeforeSettle = false;
|
|
@@ -820,9 +819,15 @@ export class AgentSession {
|
|
|
820
819
|
this._resolveIdleWait = undefined;
|
|
821
820
|
resolve();
|
|
822
821
|
}
|
|
822
|
+
_setAgentRunActive(running) {
|
|
823
|
+
if (this._isAgentRunActive === running)
|
|
824
|
+
return;
|
|
825
|
+
this._isAgentRunActive = running;
|
|
826
|
+
this._emit({ type: "run_state_changed", running });
|
|
827
|
+
}
|
|
823
828
|
async _emitAgentSettled() {
|
|
824
829
|
this._cacheWarmer?.onAgentSettled();
|
|
825
|
-
this.
|
|
830
|
+
this._setAgentRunActive(false);
|
|
826
831
|
this._isEmittingAgentSettled = true;
|
|
827
832
|
try {
|
|
828
833
|
const aborted = this._agentRunAbortRequested;
|
|
@@ -906,8 +911,12 @@ export class AgentSession {
|
|
|
906
911
|
// Regular LLM message - persist as SessionMessageEntry
|
|
907
912
|
entryId = this.sessionManager.appendMessage(event.message);
|
|
908
913
|
}
|
|
909
|
-
if (entryId)
|
|
914
|
+
if (entryId) {
|
|
910
915
|
this._entryIdsByMessage.set(event.message, entryId);
|
|
916
|
+
const entry = this.sessionManager.getEntry(entryId);
|
|
917
|
+
if (entry)
|
|
918
|
+
this._emit({ type: "message_committed", entry });
|
|
919
|
+
}
|
|
911
920
|
// Other message types (bashExecution, compactionSummary, branchSummary) are persisted elsewhere
|
|
912
921
|
if (event.message.role === "assistant") {
|
|
913
922
|
const assistantMsg = event.message;
|
|
@@ -933,7 +942,6 @@ export class AgentSession {
|
|
|
933
942
|
// extension and listener dispatch above also picks up messages that turn_end
|
|
934
943
|
// handlers queued.
|
|
935
944
|
if (event.type === "turn_end") {
|
|
936
|
-
this._lastAssistantToolResults = event.toolResults;
|
|
937
945
|
this._flushPendingCustomMessages();
|
|
938
946
|
}
|
|
939
947
|
};
|
|
@@ -976,7 +984,24 @@ export class AgentSession {
|
|
|
976
984
|
}
|
|
977
985
|
return undefined;
|
|
978
986
|
}
|
|
979
|
-
|
|
987
|
+
/**
|
|
988
|
+
* Persistently omit a failed attempt and its tool results from model context. Results are
|
|
989
|
+
* found in the projected context, so the pair stays together whether the attempt comes from
|
|
990
|
+
* the current run or a resumed session. An unpaired result fails the next request (#11227).
|
|
991
|
+
*/
|
|
992
|
+
_omitRecoveryAttempt(message) {
|
|
993
|
+
const toolCallIds = new Set(message.content.flatMap((block) => (block.type === "toolCall" ? [block.id] : [])));
|
|
994
|
+
// A context edit replaces the projected copy, so match it by source entry as well.
|
|
995
|
+
const entryId = this._findPersistedMessageEntryId(message);
|
|
996
|
+
const messages = this.agent.state.messages;
|
|
997
|
+
const index = messages.findIndex((m) => m === message || (entryId !== undefined && this._entryIdsByMessage.get(m) === entryId));
|
|
998
|
+
const toolResults = [];
|
|
999
|
+
for (const m of index < 0 ? [] : messages.slice(index + 1)) {
|
|
1000
|
+
if (m.role === "assistant")
|
|
1001
|
+
break;
|
|
1002
|
+
if (m.role === "toolResult" && toolCallIds.has(m.toolCallId))
|
|
1003
|
+
toolResults.push(m);
|
|
1004
|
+
}
|
|
980
1005
|
const targets = [message, ...toolResults];
|
|
981
1006
|
const targetIds = targets.map((target) => this._findPersistedMessageEntryId(target));
|
|
982
1007
|
const unresolvedProjectedTarget = targets.some((target, index) => targetIds[index] === undefined && this.agent.state.messages.includes(target));
|
|
@@ -1051,6 +1076,7 @@ export class AgentSession {
|
|
|
1051
1076
|
this.sessionManager.resetLeaf();
|
|
1052
1077
|
}
|
|
1053
1078
|
this._refreshFinalizedContext();
|
|
1079
|
+
this._emit({ type: "session_tree_changed" });
|
|
1054
1080
|
return;
|
|
1055
1081
|
}
|
|
1056
1082
|
// Preserve metadata after the failed attempt. The canonical projection can
|
|
@@ -1087,6 +1113,7 @@ export class AgentSession {
|
|
|
1087
1113
|
}
|
|
1088
1114
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1089
1115
|
this.agent.state.messages = sessionContext.messages;
|
|
1116
|
+
this._emit({ type: "session_tree_changed" });
|
|
1090
1117
|
}
|
|
1091
1118
|
_replaceMessageInPlace(target, replacement) {
|
|
1092
1119
|
// Agent-core stores the finalized message object in its state before emitting message_end.
|
|
@@ -1217,6 +1244,7 @@ export class AgentSession {
|
|
|
1217
1244
|
* Call this when completely done with the session.
|
|
1218
1245
|
*/
|
|
1219
1246
|
dispose() {
|
|
1247
|
+
this._emit({ type: "session_disposed" });
|
|
1220
1248
|
try {
|
|
1221
1249
|
this.abortRetry();
|
|
1222
1250
|
this.abortCompaction();
|
|
@@ -1242,6 +1270,7 @@ export class AgentSession {
|
|
|
1242
1270
|
/** Refresh the public finalized transcript from the canonical session projection. */
|
|
1243
1271
|
refreshContext() {
|
|
1244
1272
|
this._refreshFinalizedContext();
|
|
1273
|
+
this._emit({ type: "session_tree_changed" });
|
|
1245
1274
|
}
|
|
1246
1275
|
/** Full agent state */
|
|
1247
1276
|
get state() {
|
|
@@ -1606,11 +1635,27 @@ export class AgentSession {
|
|
|
1606
1635
|
*/
|
|
1607
1636
|
_restoreToolsFromTranscript(modifiers = []) {
|
|
1608
1637
|
this._pendingToolNames.clear();
|
|
1609
|
-
|
|
1610
|
-
|
|
1638
|
+
// All system messages on the branch, including those before a compaction. Compaction snapshots
|
|
1639
|
+
// are derived from these, so replaying them gives the current loadout.
|
|
1640
|
+
const systemMessages = this.sessionManager
|
|
1641
|
+
.getBranch()
|
|
1642
|
+
.flatMap((entry) => (entry.type === "message" && entry.message.role === "system" ? [entry.message] : []));
|
|
1643
|
+
// No recorded loadout: keep the current tools.
|
|
1644
|
+
if (systemMessages.length === 0)
|
|
1611
1645
|
return;
|
|
1612
|
-
|
|
1646
|
+
// Tools the branch ever added or removed. Removed tools stay inactive.
|
|
1647
|
+
const mentioned = new Set(systemMessages
|
|
1648
|
+
.flatMap((message) => [...(message.toolsAdded ?? []), ...(message.toolsRemoved ?? [])])
|
|
1649
|
+
.map((tool) => tool.name));
|
|
1650
|
+
// Extension tools the branch never mentioned were registered after it recorded its loadout, so
|
|
1651
|
+
// they are activated like newly registered tools. Built-in tools follow `defaultTools` instead.
|
|
1652
|
+
const newTools = [...this._toolRegistry.keys()].filter((name) => !mentioned.has(name) && !this._baseToolDefinitions.has(name) && this._isActivatedOnRegistration(name));
|
|
1653
|
+
// The recorded loadout plus the new tools, with `--tools +name`/`-name` applied.
|
|
1654
|
+
const names = applyToolModifiers([...getCurrentTools(systemMessages).map((tool) => tool.name), ...newTools], modifiers);
|
|
1655
|
+
// Recorded tools that are not registered yet, such as MCP tools of servers still connecting, are
|
|
1656
|
+
// activated when they register. Excluded tools never register, so they are not kept pending.
|
|
1613
1657
|
this._pendingToolNames = new Set(names.filter((name) => this._isAllowedTool(name)));
|
|
1658
|
+
// Ignores names that are not registered.
|
|
1614
1659
|
this._setActiveTools(names);
|
|
1615
1660
|
}
|
|
1616
1661
|
// =========================================================================
|
|
@@ -1623,7 +1668,7 @@ export class AgentSession {
|
|
|
1623
1668
|
* @param onStarted Called once the run's messages are prepared, before the first request.
|
|
1624
1669
|
*/
|
|
1625
1670
|
async _startRun(trigger, onStarted) {
|
|
1626
|
-
this.
|
|
1671
|
+
this._setAgentRunActive(true);
|
|
1627
1672
|
this._agentRunAbortRequested = false;
|
|
1628
1673
|
let messages;
|
|
1629
1674
|
this._isPreparingRun = true;
|
|
@@ -1631,7 +1676,7 @@ export class AgentSession {
|
|
|
1631
1676
|
messages = await this._prepareRun(trigger);
|
|
1632
1677
|
}
|
|
1633
1678
|
catch (error) {
|
|
1634
|
-
this.
|
|
1679
|
+
this._setAgentRunActive(false);
|
|
1635
1680
|
this._flushPendingBashMessages();
|
|
1636
1681
|
this._flushPendingCustomMessages();
|
|
1637
1682
|
this._resolveIdleWaitIfIdle();
|
|
@@ -1646,23 +1691,29 @@ export class AgentSession {
|
|
|
1646
1691
|
this._flushPendingCustomMessages();
|
|
1647
1692
|
if (!messages) {
|
|
1648
1693
|
// Aborted during pre-run compaction: no run was started.
|
|
1649
|
-
this.
|
|
1694
|
+
this._setAgentRunActive(false);
|
|
1650
1695
|
this._resolveIdleWaitIfIdle();
|
|
1651
1696
|
return;
|
|
1652
1697
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1698
|
+
try {
|
|
1699
|
+
onStarted?.();
|
|
1700
|
+
const startMessages = messages;
|
|
1701
|
+
await this._runAgentOperation(() => this.agent.prompt(startMessages));
|
|
1702
|
+
}
|
|
1703
|
+
catch (error) {
|
|
1704
|
+
this._setAgentRunActive(false);
|
|
1705
|
+
throw error;
|
|
1706
|
+
}
|
|
1656
1707
|
}
|
|
1657
1708
|
async _runAgentOperation(start) {
|
|
1658
1709
|
// Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
|
|
1659
1710
|
this._failedResponse = undefined;
|
|
1660
|
-
this.
|
|
1661
|
-
// The run records the loadout in the transcript; restored tools that did not register by now
|
|
1662
|
-
// are dropped, so a tool that never registers does not stay pending.
|
|
1663
|
-
this._pendingToolNames.clear();
|
|
1664
|
-
this._isAgentRunActive = true;
|
|
1711
|
+
this._setAgentRunActive(true);
|
|
1665
1712
|
try {
|
|
1713
|
+
this._recordSelection();
|
|
1714
|
+
// The run records the loadout in the transcript; restored tools that did not register by now
|
|
1715
|
+
// are dropped, so a tool that never registers does not stay pending.
|
|
1716
|
+
this._pendingToolNames.clear();
|
|
1666
1717
|
await start();
|
|
1667
1718
|
while (!this._agentRunAbortRequested) {
|
|
1668
1719
|
const shouldContinue = await this._handlePostAgentRun();
|
|
@@ -1796,7 +1847,7 @@ export class AgentSession {
|
|
|
1796
1847
|
this._prePromptAbortController = prePromptAbortController;
|
|
1797
1848
|
this._prePromptCompletionPromise = prePromptCompletion;
|
|
1798
1849
|
try {
|
|
1799
|
-
await this._checkCompaction(lastAssistant, false,
|
|
1850
|
+
await this._checkCompaction(lastAssistant, false, prePromptAbortController.signal);
|
|
1800
1851
|
}
|
|
1801
1852
|
finally {
|
|
1802
1853
|
if (this._prePromptAbortController === prePromptAbortController) {
|
|
@@ -1860,9 +1911,7 @@ export class AgentSession {
|
|
|
1860
1911
|
}
|
|
1861
1912
|
async _handlePostAgentRun() {
|
|
1862
1913
|
const message = this._lastAssistantMessage;
|
|
1863
|
-
const toolResults = this._lastAssistantToolResults;
|
|
1864
1914
|
this._lastAssistantMessage = undefined;
|
|
1865
|
-
this._lastAssistantToolResults = [];
|
|
1866
1915
|
if (this._agentRunAbortRequested) {
|
|
1867
1916
|
this._finishCancelledRetry();
|
|
1868
1917
|
return false;
|
|
@@ -1897,7 +1946,7 @@ export class AgentSession {
|
|
|
1897
1946
|
});
|
|
1898
1947
|
this._retryAttempt = 0;
|
|
1899
1948
|
}
|
|
1900
|
-
if (await this._checkCompaction(message
|
|
1949
|
+
if (await this._checkCompaction(message)) {
|
|
1901
1950
|
return !this._agentRunAbortRequested;
|
|
1902
1951
|
}
|
|
1903
1952
|
if (isPiServerMode() && this._isTerminalAssistantFailure(message)) {
|
|
@@ -2241,10 +2290,13 @@ export class AgentSession {
|
|
|
2241
2290
|
}
|
|
2242
2291
|
}
|
|
2243
2292
|
_appendCustomMessage(appMessage) {
|
|
2244
|
-
this.sessionManager.appendCustomMessageEntry(appMessage.customType, appMessage.content, appMessage.display, appMessage.details);
|
|
2293
|
+
const entryId = this.sessionManager.appendCustomMessageEntry(appMessage.customType, appMessage.content, appMessage.display, appMessage.details);
|
|
2245
2294
|
this._refreshFinalizedContext();
|
|
2246
2295
|
this._emit({ type: "message_start", message: appMessage });
|
|
2247
2296
|
this._emit({ type: "message_end", message: appMessage });
|
|
2297
|
+
const entry = this.sessionManager.getEntry(entryId);
|
|
2298
|
+
if (entry)
|
|
2299
|
+
this._emit({ type: "message_committed", entry });
|
|
2248
2300
|
}
|
|
2249
2301
|
/**
|
|
2250
2302
|
* Append custom messages queued while the agent was running.
|
|
@@ -2932,7 +2984,7 @@ export class AgentSession {
|
|
|
2932
2984
|
* @param assistantMessage The assistant message to check
|
|
2933
2985
|
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
2934
2986
|
*/
|
|
2935
|
-
async _checkCompaction(assistantMessage, skipAbortedCheck = true,
|
|
2987
|
+
async _checkCompaction(assistantMessage, skipAbortedCheck = true, externalSignal) {
|
|
2936
2988
|
if (externalSignal?.aborted)
|
|
2937
2989
|
return false;
|
|
2938
2990
|
const settings = this.settingsManager.getCompactionSettings(this.model);
|
|
@@ -3004,7 +3056,7 @@ export class AgentSession {
|
|
|
3004
3056
|
}
|
|
3005
3057
|
// Persistently omit the selected final attempt before post-run recovery compaction.
|
|
3006
3058
|
this._overflowRecoveryAttempted = true;
|
|
3007
|
-
this._omitRecoveryAttempt(assistantMessage
|
|
3059
|
+
this._omitRecoveryAttempt(assistantMessage);
|
|
3008
3060
|
if (isPiServerMode())
|
|
3009
3061
|
this._detachPiServerTerminalAssistantFailure();
|
|
3010
3062
|
const retry = await this._runAutoCompaction("overflow", willRetry, undefined, undefined, externalSignal);
|
|
@@ -3926,8 +3978,11 @@ export class AgentSession {
|
|
|
3926
3978
|
this._pendingBashMessages.push(bashMessage);
|
|
3927
3979
|
}
|
|
3928
3980
|
else {
|
|
3929
|
-
this.sessionManager.appendMessage(bashMessage);
|
|
3981
|
+
const entryId = this.sessionManager.appendMessage(bashMessage);
|
|
3930
3982
|
this._refreshFinalizedContext();
|
|
3983
|
+
const entry = this.sessionManager.getEntry(entryId);
|
|
3984
|
+
if (entry)
|
|
3985
|
+
this._emit({ type: "message_committed", entry });
|
|
3931
3986
|
}
|
|
3932
3987
|
}
|
|
3933
3988
|
/**
|
|
@@ -3954,7 +4009,10 @@ export class AgentSession {
|
|
|
3954
4009
|
if (this._pendingBashMessages.length === 0)
|
|
3955
4010
|
return;
|
|
3956
4011
|
for (const bashMessage of this._pendingBashMessages) {
|
|
3957
|
-
this.sessionManager.appendMessage(bashMessage);
|
|
4012
|
+
const entryId = this.sessionManager.appendMessage(bashMessage);
|
|
4013
|
+
const entry = this.sessionManager.getEntry(entryId);
|
|
4014
|
+
if (entry)
|
|
4015
|
+
this._emit({ type: "message_committed", entry });
|
|
3958
4016
|
}
|
|
3959
4017
|
this._pendingBashMessages = [];
|
|
3960
4018
|
this._refreshFinalizedContext();
|
|
@@ -4135,6 +4193,7 @@ export class AgentSession {
|
|
|
4135
4193
|
// Update finalized context from the canonical session projection.
|
|
4136
4194
|
this._refreshFinalizedContext();
|
|
4137
4195
|
this._restoreToolsFromTranscript();
|
|
4196
|
+
this._emit({ type: "session_tree_changed" });
|
|
4138
4197
|
// Emit session_tree event
|
|
4139
4198
|
await this._extensionRunner.emit({
|
|
4140
4199
|
type: "session_tree",
|