@averyyy/pi-coding-agent 1.1.0-piclient.3 → 1.2.0-piclient.2
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 +64 -0
- package/dist/bundle/chunks/anthropic-messages-Y556A57W.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-ONC234KU.js +2 -0
- package/dist/bundle/chunks/{chunk-SJAIFNJC.js → chunk-27EJF7XV.js} +1 -1
- package/dist/bundle/chunks/chunk-32OQRHU5.js +7 -0
- package/dist/bundle/chunks/{chunk-L2QJRZTO.js → chunk-5UQLMALR.js} +1 -1
- package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
- package/dist/bundle/chunks/chunk-FMG3V7LC.js +2 -0
- package/dist/bundle/chunks/chunk-KHMP74W7.js +2 -0
- package/dist/bundle/chunks/{chunk-LQELYOUU.js → chunk-M6CJGLVS.js} +1 -1
- package/dist/bundle/chunks/{chunk-WMAKGH2U.js → chunk-MCRRDQUQ.js} +26 -92
- package/dist/bundle/chunks/chunk-OK5HMGJH.js +2 -0
- package/dist/bundle/chunks/{chunk-IHNTZDOC.js → chunk-PT5WCDHM.js} +1 -1
- package/dist/bundle/chunks/{chunk-JPAIS7JS.js → chunk-QNH5RXIC.js} +2 -2
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
- package/dist/bundle/chunks/{chunk-YESFPC53.js → chunk-RUVBX4HZ.js} +101 -90
- package/dist/bundle/chunks/{chunk-G7JAXKAE.js → chunk-SWXCGFWB.js} +1 -1
- package/dist/bundle/chunks/chunk-VBIW3SGN.js +6 -0
- package/dist/bundle/chunks/{chunk-M6HKFBHF.js → chunk-VOTHJ3C2.js} +1 -1
- package/dist/bundle/chunks/chunk-VZZDG22Y.js +9 -0
- package/dist/bundle/chunks/chunk-WALKIYXG.js +82 -0
- package/dist/bundle/chunks/chunk-XDNB4NV2.js +130 -0
- package/dist/bundle/chunks/{cli-G46DCMLG.js → cli-C7ZYV7NI.js} +3 -3
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-TXNQKF7U.js → cloudflare-workers-ai-system-one-46TPRDI6.js} +1 -1
- package/dist/bundle/chunks/codemode-worker.js +17 -9
- package/dist/bundle/chunks/easter-egg-3d-JPU5ICBY.js +2 -0
- package/dist/bundle/chunks/execute-G3X3GRKI.js +499 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/google-antigravity.js +75 -0
- package/dist/bundle/chunks/google-generative-ai-OPRBPNHR.js +2 -0
- package/dist/bundle/chunks/google-vertex-VC2DWOR5.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-JJ6S2EPK.js +5 -0
- package/dist/bundle/chunks/openai-codex-responses-NQKFQIGV.js +10 -0
- package/dist/bundle/chunks/{openai-completions-IIJZEEG4.js → openai-completions-NNHMY5BP.js} +1 -1
- package/dist/bundle/chunks/{openai-decisions-7HAB4DS5.js → openai-decisions-SA75ZFFT.js} +1 -1
- package/dist/bundle/chunks/openai-responses-XDTCR5JC.js +3 -0
- package/dist/bundle/chunks/{pi-messages-YHKPQIHC.js → pi-messages-EMTA6VNL.js} +1 -1
- package/dist/bundle/chunks/runtime-RTNZQVM5.js +2 -0
- package/dist/bundle/chunks/{typesafe-system-one-JIF5KZZR.js → typesafe-system-one-WHWA7H7I.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-PGCF2Z7J.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.d.ts +16 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +135 -87
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +20 -13
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bug-report.d.ts +9 -1
- package/dist/core/bug-report.d.ts.map +1 -1
- package/dist/core/compaction/utils.d.ts +6 -0
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +7 -8
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +4 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +2 -3
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +31 -7
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/key-id-schema.d.ts +6 -0
- package/dist/core/key-id-schema.d.ts.map +1 -0
- package/dist/core/key-id-schema.js +16 -0
- package/dist/core/key-id-schema.js.map +1 -0
- package/dist/core/keybindings-schema.d.ts +4 -0
- package/dist/core/keybindings-schema.d.ts.map +1 -0
- package/dist/core/keybindings-schema.js +16 -0
- package/dist/core/keybindings-schema.js.map +1 -0
- package/dist/core/keybindings.d.ts +198 -63
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +26 -23
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +695 -74
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +16 -166
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +11 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +3 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +2 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +12 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +82 -24
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +5 -1
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +65 -0
- package/dist/core/settings-defaults.d.ts.map +1 -0
- package/dist/core/settings-defaults.js +66 -0
- package/dist/core/settings-defaults.js.map +1 -0
- package/dist/core/settings-manager.d.ts +4 -147
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +48 -44
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +228 -0
- package/dist/core/settings-schema.d.ts.map +1 -0
- package/dist/core/settings-schema.js +287 -0
- package/dist/core/settings-schema.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +18 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +46 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +7 -40
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +64 -45
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/index.d.ts.map +1 -1
- package/dist/extensions/codemode/index.js +2 -1
- package/dist/extensions/codemode/index.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts +2 -2
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +9 -3
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +6 -12
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +44 -32
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/mcp/cli.js +5 -8
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +26 -23
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/resources.d.ts +0 -6
- package/dist/extensions/mcp/resources.d.ts.map +1 -1
- package/dist/extensions/mcp/resources.js +1 -1
- package/dist/extensions/mcp/resources.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +3 -6
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +4 -39
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts +2 -3
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +62 -6
- package/dist/extensions/mcp/tools.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +0 -2
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +2 -4
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +3 -2
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +2 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +11 -5
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.js +105 -0
- package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.js +94 -0
- package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +13 -16
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +21 -29
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +4 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +6 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/docs/cli-integration.md +1 -1
- package/docs/cli.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/compaction.md +2 -2
- package/docs/environment-variables.md +2 -1
- package/docs/extensions.md +7 -4
- package/docs/keybindings.md +1 -0
- package/docs/mcp.md +1 -1
- package/docs/models.md +1 -0
- package/docs/providers.md +30 -0
- package/docs/settings.md +3 -1
- package/docs/themes.md +4 -2
- package/docs/tui.md +1 -1
- package/examples/README.md +0 -3
- 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/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/overlay-test.ts +2 -2
- package/examples/extensions/plan-mode/index.ts +6 -2
- 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 +9 -20
- package/schemas/keybindings.schema.json +397 -0
- package/schemas/models.schema.json +1157 -0
- package/schemas/settings.schema.json +765 -0
- package/schemas/theme.schema.json +365 -0
- package/dist/bundle/chunks/anthropic-messages-VWV2LQLU.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-TJZBTKRM.js +0 -2
- package/dist/bundle/chunks/chunk-2DXGY63V.js +0 -15
- package/dist/bundle/chunks/chunk-4QEUO5LF.js +0 -20
- package/dist/bundle/chunks/chunk-JI2MPSJF.js +0 -2
- package/dist/bundle/chunks/chunk-MFRJR46A.js +0 -2
- package/dist/bundle/chunks/chunk-QEAD7ZDM.js +0 -82
- package/dist/bundle/chunks/chunk-XJNJKWWG.js +0 -138
- package/dist/bundle/chunks/easter-egg-3d-VPOZMPG6.js +0 -2
- package/dist/bundle/chunks/execute-W7LFAU5T.js +0 -490
- package/dist/bundle/chunks/google-generative-ai-MU3HY65Y.js +0 -2
- package/dist/bundle/chunks/google-vertex-4KLEFGPG.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-QSGGIXSP.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-XHPOB5DF.js +0 -10
- package/dist/bundle/chunks/openai-responses-27B2XLS7.js +0 -3
- package/dist/bundle/chunks/runtime-PVOHGROZ.js +0 -2
- package/dist/bundle/chunks/virtual-modules-LVJTWSUG.js +0 -2
- package/dist/modes/interactive/theme/theme-json.d.ts +0 -85
- package/dist/modes/interactive/theme/theme-json.d.ts.map +0 -1
- package/dist/modes/interactive/theme/theme-json.js +0 -132
- package/dist/modes/interactive/theme/theme-json.js.map +0 -1
- package/dist/modes/interactive/theme/theme-schema.json +0 -361
- package/examples/plugins/pi-example-plugin/README.md +0 -38
- package/examples/plugins/pi-example-plugin/package.json +0 -10
- package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
- package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
- package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
|
@@ -178,6 +178,8 @@ export class AgentSession {
|
|
|
178
178
|
_unsubscribeAgent;
|
|
179
179
|
_eventListeners = [];
|
|
180
180
|
_isAgentRunActive = false;
|
|
181
|
+
/** True while before_agent_start and pre-run compaction prepare a run that has sent no request yet. */
|
|
182
|
+
_isPreparingRun = false;
|
|
181
183
|
_agentRunAbortRequested = false;
|
|
182
184
|
_idleWaitPromise;
|
|
183
185
|
_resolveIdleWait;
|
|
@@ -844,6 +846,10 @@ export class AgentSession {
|
|
|
844
846
|
}
|
|
845
847
|
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
846
848
|
_handleAgentEvent = async (event, _signal) => {
|
|
849
|
+
// An abort requested while the run was starting, e.g. during before_agent_start, stops it
|
|
850
|
+
// here. agent_start is awaited before the first request.
|
|
851
|
+
if (event.type === "agent_start" && this._agentRunAbortRequested)
|
|
852
|
+
this.agent.abort();
|
|
847
853
|
// Record the calls a tool made through ctx.executeTool() and their usage on its result message.
|
|
848
854
|
if (this._nestedToolCalls) {
|
|
849
855
|
if (event.type === "message_start" && event.message.role === "toolResult") {
|
|
@@ -1312,6 +1318,7 @@ export class AgentSession {
|
|
|
1312
1318
|
exposure: this._getToolExposure(definition.name),
|
|
1313
1319
|
...(definition.namespace ? { namespace: definition.namespace } : {}),
|
|
1314
1320
|
...(definition.annotations ? { annotations: { ...definition.annotations } } : {}),
|
|
1321
|
+
...(definition.reachesTools ? { reachesTools: definition.reachesTools } : {}),
|
|
1315
1322
|
sourceInfo,
|
|
1316
1323
|
}));
|
|
1317
1324
|
}
|
|
@@ -1607,8 +1614,45 @@ export class AgentSession {
|
|
|
1607
1614
|
// =========================================================================
|
|
1608
1615
|
// Prompting
|
|
1609
1616
|
// =========================================================================
|
|
1610
|
-
|
|
1617
|
+
/**
|
|
1618
|
+
* Start a run from a user or custom message. The session counts as busy from here on, so
|
|
1619
|
+
* messages sent while before_agent_start handlers run are queued into this run instead of
|
|
1620
|
+
* starting another, and an abort requested meanwhile aborts the run as soon as it exists.
|
|
1621
|
+
* @param onStarted Called once the run's messages are prepared, before the first request.
|
|
1622
|
+
*/
|
|
1623
|
+
async _startRun(trigger, onStarted) {
|
|
1624
|
+
this._isAgentRunActive = true;
|
|
1611
1625
|
this._agentRunAbortRequested = false;
|
|
1626
|
+
let messages;
|
|
1627
|
+
this._isPreparingRun = true;
|
|
1628
|
+
try {
|
|
1629
|
+
messages = await this._prepareRun(trigger);
|
|
1630
|
+
}
|
|
1631
|
+
catch (error) {
|
|
1632
|
+
this._isAgentRunActive = false;
|
|
1633
|
+
this._flushPendingBashMessages();
|
|
1634
|
+
this._flushPendingCustomMessages();
|
|
1635
|
+
this._resolveIdleWaitIfIdle();
|
|
1636
|
+
throw error;
|
|
1637
|
+
}
|
|
1638
|
+
finally {
|
|
1639
|
+
this._isPreparingRun = false;
|
|
1640
|
+
}
|
|
1641
|
+
// Messages held while the run was starting go before its starting messages, as they would
|
|
1642
|
+
// have while idle. No run exists yet, so they cannot split a tool call from its result.
|
|
1643
|
+
this._flushPendingBashMessages();
|
|
1644
|
+
this._flushPendingCustomMessages();
|
|
1645
|
+
if (!messages) {
|
|
1646
|
+
// Aborted during pre-run compaction: no run was started.
|
|
1647
|
+
this._isAgentRunActive = false;
|
|
1648
|
+
this._resolveIdleWaitIfIdle();
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
onStarted?.();
|
|
1652
|
+
const startMessages = messages;
|
|
1653
|
+
await this._runAgentOperation(() => this.agent.prompt(startMessages));
|
|
1654
|
+
}
|
|
1655
|
+
async _runAgentOperation(start) {
|
|
1612
1656
|
// Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
|
|
1613
1657
|
this._failedResponse = undefined;
|
|
1614
1658
|
this._recordSelection();
|
|
@@ -1657,9 +1701,6 @@ export class AgentSession {
|
|
|
1657
1701
|
await this._emitAgentSettled();
|
|
1658
1702
|
}
|
|
1659
1703
|
}
|
|
1660
|
-
async _runAgentPrompt(messages) {
|
|
1661
|
-
await this._runAgentOperation(() => this.agent.prompt(messages));
|
|
1662
|
-
}
|
|
1663
1704
|
_sessionHasInfoEntry() {
|
|
1664
1705
|
return this.sessionManager.getEntries().some((entry) => entry.type === "session_info");
|
|
1665
1706
|
}
|
|
@@ -1731,6 +1772,90 @@ export class AgentSession {
|
|
|
1731
1772
|
this._sessionNameAbortController = undefined;
|
|
1732
1773
|
}
|
|
1733
1774
|
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Prepare a run and return its starting messages: compact first when needed, emit
|
|
1777
|
+
* before_agent_start, apply the run's prompt options and tool loadout, and build the starting
|
|
1778
|
+
* message followed by pending nextTurn messages (consumed here) and handler messages, with a
|
|
1779
|
+
* system patch first when the prompt changed.
|
|
1780
|
+
*/
|
|
1781
|
+
async _prepareRun(trigger) {
|
|
1782
|
+
// Check if we need to compact before sending (catches aborted responses).
|
|
1783
|
+
// The starting message is sent below, so do not call agent.continue() here.
|
|
1784
|
+
if (this._isAborting) {
|
|
1785
|
+
return undefined;
|
|
1786
|
+
}
|
|
1787
|
+
const lastAssistant = this._findLastAssistantMessage();
|
|
1788
|
+
if (lastAssistant) {
|
|
1789
|
+
const prePromptAbortController = new AbortController();
|
|
1790
|
+
let resolvePrePromptCompletion;
|
|
1791
|
+
const prePromptCompletion = new Promise((resolve) => {
|
|
1792
|
+
resolvePrePromptCompletion = resolve;
|
|
1793
|
+
});
|
|
1794
|
+
this._prePromptAbortController = prePromptAbortController;
|
|
1795
|
+
this._prePromptCompletionPromise = prePromptCompletion;
|
|
1796
|
+
try {
|
|
1797
|
+
await this._checkCompaction(lastAssistant, false, [], prePromptAbortController.signal);
|
|
1798
|
+
}
|
|
1799
|
+
finally {
|
|
1800
|
+
if (this._prePromptAbortController === prePromptAbortController) {
|
|
1801
|
+
this._prePromptAbortController = undefined;
|
|
1802
|
+
}
|
|
1803
|
+
if (this._prePromptCompletionPromise === prePromptCompletion) {
|
|
1804
|
+
this._prePromptCompletionPromise = undefined;
|
|
1805
|
+
}
|
|
1806
|
+
resolvePrePromptCompletion?.();
|
|
1807
|
+
}
|
|
1808
|
+
if (prePromptAbortController.signal.aborted || this._isAborting) {
|
|
1809
|
+
return undefined;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
if (isPiServerMode()) {
|
|
1813
|
+
this._detachPiServerTerminalAssistantFailure();
|
|
1814
|
+
}
|
|
1815
|
+
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1816
|
+
const result = await this._extensionRunner.emitBeforeAgentStart(trigger, this._baseSystemPromptOptions);
|
|
1817
|
+
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1818
|
+
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1819
|
+
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1820
|
+
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1821
|
+
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1822
|
+
if (!handlerEditedTools)
|
|
1823
|
+
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1824
|
+
const messages = [];
|
|
1825
|
+
if (trigger.messageType === "custom") {
|
|
1826
|
+
messages.push(trigger.message);
|
|
1827
|
+
}
|
|
1828
|
+
else {
|
|
1829
|
+
// Normalize images after before_agent_start so extension-driven model selection
|
|
1830
|
+
// determines the resize profile used for the request and history.
|
|
1831
|
+
const normalized = await this._normalizePromptImages(trigger.images);
|
|
1832
|
+
const text = normalized.hints.length > 0 ? `${trigger.prompt}\n\n${normalized.hints.join("\n")}` : trigger.prompt;
|
|
1833
|
+
messages.push({
|
|
1834
|
+
role: "user",
|
|
1835
|
+
content: [{ type: "text", text }, ...normalized.images],
|
|
1836
|
+
timestamp: Date.now(),
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
// Inject any pending "nextTurn" messages as context alongside the starting message
|
|
1840
|
+
messages.push(...this._pendingNextTurnMessages);
|
|
1841
|
+
this._pendingNextTurnMessages = [];
|
|
1842
|
+
for (const msg of result.messages) {
|
|
1843
|
+
messages.push({
|
|
1844
|
+
role: "custom",
|
|
1845
|
+
customType: msg.customType,
|
|
1846
|
+
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1847
|
+
content: msg.content ?? [],
|
|
1848
|
+
display: msg.display,
|
|
1849
|
+
details: msg.details,
|
|
1850
|
+
timestamp: Date.now(),
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
|
|
1854
|
+
this._runSystemPromptOptions = result.systemPromptOptions;
|
|
1855
|
+
if (updateMessage)
|
|
1856
|
+
messages.unshift(updateMessage);
|
|
1857
|
+
return messages;
|
|
1858
|
+
}
|
|
1734
1859
|
async _handlePostAgentRun() {
|
|
1735
1860
|
const message = this._lastAssistantMessage;
|
|
1736
1861
|
const toolResults = this._lastAssistantToolResults;
|
|
@@ -1892,9 +2017,6 @@ export class AgentSession {
|
|
|
1892
2017
|
preflightResult?.("queued");
|
|
1893
2018
|
return;
|
|
1894
2019
|
}
|
|
1895
|
-
// Flush any pending bash and custom messages before the new prompt
|
|
1896
|
-
this._flushPendingBashMessages();
|
|
1897
|
-
this._flushPendingCustomMessages();
|
|
1898
2020
|
// Validate model
|
|
1899
2021
|
if (!this.model) {
|
|
1900
2022
|
throw new Error(formatNoModelSelectedMessage());
|
|
@@ -1910,83 +2032,7 @@ export class AgentSession {
|
|
|
1910
2032
|
}
|
|
1911
2033
|
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
1912
2034
|
}
|
|
1913
|
-
|
|
1914
|
-
// The user's new prompt is sent below, so do not call agent.continue() here.
|
|
1915
|
-
if (this._isAborting) {
|
|
1916
|
-
return;
|
|
1917
|
-
}
|
|
1918
|
-
const lastAssistant = this._findLastAssistantMessage();
|
|
1919
|
-
if (lastAssistant) {
|
|
1920
|
-
const prePromptAbortController = new AbortController();
|
|
1921
|
-
let resolvePrePromptCompletion;
|
|
1922
|
-
const prePromptCompletion = new Promise((resolve) => {
|
|
1923
|
-
resolvePrePromptCompletion = resolve;
|
|
1924
|
-
});
|
|
1925
|
-
this._prePromptAbortController = prePromptAbortController;
|
|
1926
|
-
this._prePromptCompletionPromise = prePromptCompletion;
|
|
1927
|
-
try {
|
|
1928
|
-
await this._checkCompaction(lastAssistant, false, [], prePromptAbortController.signal);
|
|
1929
|
-
}
|
|
1930
|
-
finally {
|
|
1931
|
-
if (this._prePromptAbortController === prePromptAbortController) {
|
|
1932
|
-
this._prePromptAbortController = undefined;
|
|
1933
|
-
}
|
|
1934
|
-
if (this._prePromptCompletionPromise === prePromptCompletion) {
|
|
1935
|
-
this._prePromptCompletionPromise = undefined;
|
|
1936
|
-
}
|
|
1937
|
-
resolvePrePromptCompletion?.();
|
|
1938
|
-
}
|
|
1939
|
-
if (prePromptAbortController.signal.aborted || this._isAborting) {
|
|
1940
|
-
return;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
if (isPiServerMode()) {
|
|
1944
|
-
this._detachPiServerTerminalAssistantFailure();
|
|
1945
|
-
}
|
|
1946
|
-
// Emit before_agent_start before normalizing images so extension-driven model
|
|
1947
|
-
// selection determines the resize profile used for the request and history.
|
|
1948
|
-
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1949
|
-
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPromptOptions);
|
|
1950
|
-
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1951
|
-
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1952
|
-
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1953
|
-
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1954
|
-
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1955
|
-
if (!handlerEditedTools)
|
|
1956
|
-
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1957
|
-
const normalized = await this._normalizePromptImages(currentImages);
|
|
1958
|
-
const userText = normalized.hints.length > 0 ? `${expandedText}\n\n${normalized.hints.join("\n")}` : expandedText;
|
|
1959
|
-
// Build messages only after hooks and image normalization have completed.
|
|
1960
|
-
const messages = [];
|
|
1961
|
-
const userContent = [{ type: "text", text: userText }];
|
|
1962
|
-
userContent.push(...normalized.images);
|
|
1963
|
-
messages.push({
|
|
1964
|
-
role: "user",
|
|
1965
|
-
content: userContent,
|
|
1966
|
-
timestamp: Date.now(),
|
|
1967
|
-
});
|
|
1968
|
-
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
1969
|
-
for (const msg of this._pendingNextTurnMessages) {
|
|
1970
|
-
messages.push(msg);
|
|
1971
|
-
}
|
|
1972
|
-
this._pendingNextTurnMessages = [];
|
|
1973
|
-
for (const msg of result.messages) {
|
|
1974
|
-
messages.push({
|
|
1975
|
-
role: "custom",
|
|
1976
|
-
customType: msg.customType,
|
|
1977
|
-
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1978
|
-
content: msg.content ?? [],
|
|
1979
|
-
display: msg.display,
|
|
1980
|
-
details: msg.details,
|
|
1981
|
-
timestamp: Date.now(),
|
|
1982
|
-
});
|
|
1983
|
-
}
|
|
1984
|
-
const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
|
|
1985
|
-
this._runSystemPromptOptions = result.systemPromptOptions;
|
|
1986
|
-
if (updateMessage)
|
|
1987
|
-
messages.unshift(updateMessage);
|
|
1988
|
-
preflightResult?.("started");
|
|
1989
|
-
await this._runAgentPrompt(messages);
|
|
2035
|
+
await this._startRun({ messageType: "user", prompt: expandedText, images: currentImages }, () => preflightResult?.("started"));
|
|
1990
2036
|
}
|
|
1991
2037
|
/**
|
|
1992
2038
|
* Try to execute an extension command. Returns true if command was found and executed.
|
|
@@ -2176,10 +2222,10 @@ export class AgentSession {
|
|
|
2176
2222
|
}
|
|
2177
2223
|
else if (options?.triggerTurn) {
|
|
2178
2224
|
if (this._isEmittingAgentSettled) {
|
|
2179
|
-
this._deferredSettledActions.push(async () => await this.
|
|
2225
|
+
this._deferredSettledActions.push(async () => await this.sendCustomMessage(message, options));
|
|
2180
2226
|
return;
|
|
2181
2227
|
}
|
|
2182
|
-
await this.
|
|
2228
|
+
await this._startRun({ messageType: "custom", message: appMessage });
|
|
2183
2229
|
}
|
|
2184
2230
|
else if (this.isStreaming) {
|
|
2185
2231
|
// Appending now would put the message between an assistant tool call and its
|
|
@@ -2281,6 +2327,7 @@ export class AgentSession {
|
|
|
2281
2327
|
if (this._isAgentRunActive || this._isAborting || !this.agent.hasQueuedMessages()) {
|
|
2282
2328
|
return;
|
|
2283
2329
|
}
|
|
2330
|
+
this._agentRunAbortRequested = false;
|
|
2284
2331
|
void this._runAgentOperation(() => this.agent.continue()).catch((error) => {
|
|
2285
2332
|
this._extensionRunner.emitError({
|
|
2286
2333
|
extensionPath: "<runtime>",
|
|
@@ -2397,7 +2444,8 @@ export class AgentSession {
|
|
|
2397
2444
|
if (!hasAuth) {
|
|
2398
2445
|
throw new Error(`No API key for ${model.provider}/${model.id}`);
|
|
2399
2446
|
}
|
|
2400
|
-
|
|
2447
|
+
// A run being prepared has sent no request, so the new model applies to its first request.
|
|
2448
|
+
if (this.isStreaming && !this._isPreparingRun) {
|
|
2401
2449
|
await this.abort();
|
|
2402
2450
|
}
|
|
2403
2451
|
const previousModel = this.model;
|