feat: Expose BuildSystemPromptOptions on before-agent-start event. (#3473)
Resolves: #3463
This commit is contained in:
@@ -76,7 +76,7 @@ import { CURRENT_SESSION_VERSION, getLatestCompactionEntry, type SessionHeader }
|
||||
import type { SettingsManager } from "./settings-manager.js";
|
||||
import type { SlashCommandInfo } from "./slash-commands.js";
|
||||
import { createSyntheticSourceInfo, type SourceInfo } from "./source-info.js";
|
||||
import { buildSystemPrompt } from "./system-prompt.js";
|
||||
import { type BuildSystemPromptOptions, buildSystemPrompt } from "./system-prompt.js";
|
||||
import { type BashOperations, createLocalBashOperations } from "./tools/bash.js";
|
||||
import { createAllToolDefinitions } from "./tools/index.js";
|
||||
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
||||
@@ -300,6 +300,7 @@ export class AgentSession {
|
||||
|
||||
// Base system prompt (without extension appends) - used to apply fresh appends each turn
|
||||
private _baseSystemPrompt = "";
|
||||
private _baseSystemPromptOptions: BuildSystemPromptOptions = {};
|
||||
|
||||
constructor(config: AgentSessionConfig) {
|
||||
this.agent = config.agent;
|
||||
@@ -906,7 +907,7 @@ export class AgentSession {
|
||||
const loadedSkills = this._resourceLoader.getSkills().skills;
|
||||
const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
|
||||
|
||||
return buildSystemPrompt({
|
||||
this._baseSystemPromptOptions = {
|
||||
cwd: this._cwd,
|
||||
skills: loadedSkills,
|
||||
contextFiles: loadedContextFiles,
|
||||
@@ -915,7 +916,8 @@ export class AgentSession {
|
||||
selectedTools: validToolNames,
|
||||
toolSnippets,
|
||||
promptGuidelines,
|
||||
});
|
||||
};
|
||||
return buildSystemPrompt(this._baseSystemPromptOptions);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
@@ -1048,6 +1050,7 @@ export class AgentSession {
|
||||
expandedText,
|
||||
currentImages,
|
||||
this._baseSystemPrompt,
|
||||
this._baseSystemPromptOptions,
|
||||
);
|
||||
// Add all custom messages from extensions
|
||||
if (result?.messages) {
|
||||
|
||||
@@ -36,6 +36,7 @@ export type {
|
||||
BeforeAgentStartEventResult,
|
||||
BeforeProviderRequestEvent,
|
||||
BeforeProviderRequestEventResult,
|
||||
BuildSystemPromptOptions,
|
||||
// Context
|
||||
CompactOptions,
|
||||
// Events - Agent
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { ResourceDiagnostic } from "../diagnostics.js";
|
||||
import type { KeybindingsConfig } from "../keybindings.js";
|
||||
import type { ModelRegistry } from "../model-registry.js";
|
||||
import type { SessionManager } from "../session-manager.js";
|
||||
import type { BuildSystemPromptOptions } from "../system-prompt.js";
|
||||
import type {
|
||||
BeforeAgentStartEvent,
|
||||
BeforeAgentStartEventResult,
|
||||
@@ -789,6 +790,7 @@ export class ExtensionRunner {
|
||||
prompt: string,
|
||||
images: ImageContent[] | undefined,
|
||||
systemPrompt: string,
|
||||
systemPromptOptions: BuildSystemPromptOptions,
|
||||
): Promise<BeforeAgentStartCombinedResult | undefined> {
|
||||
const ctx = this.createContext();
|
||||
const messages: NonNullable<BeforeAgentStartEventResult["message"]>[] = [];
|
||||
@@ -806,6 +808,7 @@ export class ExtensionRunner {
|
||||
prompt,
|
||||
images,
|
||||
systemPrompt: currentSystemPrompt,
|
||||
systemPromptOptions,
|
||||
};
|
||||
const handlerResult = await handler(event, ctx);
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ import type {
|
||||
} from "../session-manager.js";
|
||||
import type { SlashCommandInfo } from "../slash-commands.js";
|
||||
import type { SourceInfo } from "../source-info.js";
|
||||
import type { BuildSystemPromptOptions } from "../system-prompt.js";
|
||||
import type { BashOperations } from "../tools/bash.js";
|
||||
import type { EditToolDetails } from "../tools/edit.js";
|
||||
import type {
|
||||
@@ -75,6 +76,7 @@ import type {
|
||||
} from "../tools/index.js";
|
||||
|
||||
export type { ExecOptions, ExecResult } from "../exec.js";
|
||||
export type { BuildSystemPromptOptions } from "../system-prompt.js";
|
||||
export type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode };
|
||||
export type { AppKeybinding, KeybindingsManager } from "../keybindings.js";
|
||||
|
||||
@@ -582,9 +584,14 @@ export interface AfterProviderResponseEvent {
|
||||
/** Fired after user submits prompt but before agent loop. */
|
||||
export interface BeforeAgentStartEvent {
|
||||
type: "before_agent_start";
|
||||
/** The raw user prompt text (after expansion). */
|
||||
prompt: string;
|
||||
/** Images attached to the user prompt, if any. */
|
||||
images?: ImageContent[];
|
||||
/** The fully assembled system prompt string. */
|
||||
systemPrompt: string;
|
||||
/** Structured options used to build the system prompt. Extensions can inspect this to understand what Pi loaded without re-discovering resources. */
|
||||
systemPromptOptions: BuildSystemPromptOptions;
|
||||
}
|
||||
|
||||
/** Fired when an agent loop starts */
|
||||
|
||||
@@ -35,6 +35,8 @@ export {
|
||||
type AgentToolResult,
|
||||
type AgentToolUpdateCallback,
|
||||
type BeforeAgentStartEvent,
|
||||
type BeforeAgentStartEventResult,
|
||||
type BuildSystemPromptOptions,
|
||||
type ContextEvent,
|
||||
defineTool,
|
||||
discoverAndLoadExtensions,
|
||||
|
||||
Reference in New Issue
Block a user