Add system prompt options to extension commands

This commit is contained in:
Alexey Zaytsev
2026-06-01 15:40:48 -05:00
parent e56521e323
commit 8216cca5a7
6 changed files with 54 additions and 1 deletions

View File

@@ -2264,6 +2264,7 @@ export class AgentSession {
})();
},
getSystemPrompt: () => this.systemPrompt,
getSystemPromptOptions: () => this._baseSystemPromptOptions,
},
{
registerProvider: (name, config) => {

View File

@@ -240,6 +240,7 @@ export class ExtensionRunner {
private getContextUsageFn: () => ContextUsage | undefined = () => undefined;
private compactFn: (options?: CompactOptions) => void = () => {};
private getSystemPromptFn: () => string = () => "";
private getSystemPromptOptionsFn: () => BuildSystemPromptOptions = () => ({ cwd: this.cwd });
private newSessionHandler: NewSessionHandler = async () => ({ cancelled: false });
private forkHandler: ForkHandler = async () => ({ cancelled: false });
private navigateTreeHandler: NavigateTreeHandler = async () => ({ cancelled: false });
@@ -299,6 +300,7 @@ export class ExtensionRunner {
this.getContextUsageFn = contextActions.getContextUsage;
this.compactFn = contextActions.compact;
this.getSystemPromptFn = contextActions.getSystemPrompt;
this.getSystemPromptOptionsFn = contextActions.getSystemPromptOptions ?? (() => ({ cwd: this.cwd }));
// Flush provider registrations queued during extension loading
for (const { name, config, extensionPath } of this.runtime.pendingProviderRegistrations) {
@@ -648,6 +650,10 @@ export class ExtensionRunner {
{},
Object.getOwnPropertyDescriptors(this.createContext()),
) as ExtensionCommandContext;
context.getSystemPromptOptions = () => {
this.assertActive();
return this.getSystemPromptOptionsFn();
};
context.waitForIdle = () => {
this.assertActive();
return this.waitForIdleFn();

View File

@@ -335,6 +335,9 @@ export interface ExtensionContext {
* Includes session control methods only safe in user-initiated commands.
*/
export interface ExtensionCommandContext extends ExtensionContext {
/** Get the current base system-prompt construction options. */
getSystemPromptOptions(): BuildSystemPromptOptions;
/** Wait for the agent to finish streaming */
waitForIdle(): Promise<void>;
@@ -1506,6 +1509,7 @@ export interface ExtensionContextActions {
getContextUsage: () => ContextUsage | undefined;
compact: (options?: CompactOptions) => void;
getSystemPrompt: () => string;
getSystemPromptOptions?: () => BuildSystemPromptOptions;
}
/**