feat(coding-agent): add ctx.getSystemPrompt() to extension context
Adds a method to access the effective system prompt (after any per-turn extension modifications) from the extension context. Implementation: - Add systemPrompt getter to AgentSession reading from agent.state.systemPrompt - Wire getSystemPrompt through ExtensionContextActions to ExtensionRunner - Add getSystemPrompt to interactive-mode's shortcut context - Update docs with ctx.getSystemPrompt() section - Add system-prompt-header.ts example - Add example to docs reference table Closes #1098
This commit is contained in:
@@ -514,6 +514,11 @@ export class AgentSession {
|
||||
return this.agent.state.isStreaming;
|
||||
}
|
||||
|
||||
/** Current effective system prompt (includes any per-turn extension modifications) */
|
||||
get systemPrompt(): string {
|
||||
return this.agent.state.systemPrompt;
|
||||
}
|
||||
|
||||
/** Current retry attempt (0 if not retrying) */
|
||||
get retryAttempt(): number {
|
||||
return this._retryAttempt;
|
||||
@@ -1756,6 +1761,7 @@ export class AgentSession {
|
||||
}
|
||||
})();
|
||||
},
|
||||
getSystemPrompt: () => this.systemPrompt,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,6 +159,7 @@ export class ExtensionRunner {
|
||||
private hasPendingMessagesFn: () => boolean = () => false;
|
||||
private getContextUsageFn: () => ContextUsage | undefined = () => undefined;
|
||||
private compactFn: (options?: CompactOptions) => void = () => {};
|
||||
private getSystemPromptFn: () => string = () => "";
|
||||
private newSessionHandler: NewSessionHandler = async () => ({ cancelled: false });
|
||||
private forkHandler: ForkHandler = async () => ({ cancelled: false });
|
||||
private navigateTreeHandler: NavigateTreeHandler = async () => ({ cancelled: false });
|
||||
@@ -203,6 +204,7 @@ export class ExtensionRunner {
|
||||
this.shutdownHandler = contextActions.shutdown;
|
||||
this.getContextUsageFn = contextActions.getContextUsage;
|
||||
this.compactFn = contextActions.compact;
|
||||
this.getSystemPromptFn = contextActions.getSystemPrompt;
|
||||
|
||||
// Process provider registrations queued during extension loading
|
||||
for (const { name, config } of this.runtime.pendingProviderRegistrations) {
|
||||
@@ -421,6 +423,7 @@ export class ExtensionRunner {
|
||||
shutdown: () => this.shutdownHandler(),
|
||||
getContextUsage: () => this.getContextUsageFn(),
|
||||
compact: (options) => this.compactFn(options),
|
||||
getSystemPrompt: () => this.getSystemPromptFn(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -260,6 +260,8 @@ export interface ExtensionContext {
|
||||
getContextUsage(): ContextUsage | undefined;
|
||||
/** Trigger compaction without awaiting completion. */
|
||||
compact(options?: CompactOptions): void;
|
||||
/** Get the current effective system prompt. */
|
||||
getSystemPrompt(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1084,6 +1086,7 @@ export interface ExtensionContextActions {
|
||||
shutdown: () => void;
|
||||
getContextUsage: () => ContextUsage | undefined;
|
||||
compact: (options?: CompactOptions) => void;
|
||||
getSystemPrompt: () => string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1120,6 +1120,7 @@ export class InteractiveMode {
|
||||
}
|
||||
})();
|
||||
},
|
||||
getSystemPrompt: () => this.session.systemPrompt,
|
||||
});
|
||||
|
||||
// Set up the extension shortcut handler on the default editor
|
||||
|
||||
Reference in New Issue
Block a user