fix(coding-agent): fixed crashes when system prompts were provided as strings

- Normalized agent `setSystemPrompt` to wrap string inputs into one-item arrays.
- Updated session creation to accept string `systemPrompt` values and normalize callback or direct results to string arrays.
- Adjusted extension result handling and test fixtures to accept string `systemPrompt` and missing `assistant_message` fields without crashing.
This commit is contained in:
can1357
2026-06-14 21:53:24 +02:00
parent 572b06f406
commit 77ea88e436
5 changed files with 12 additions and 8 deletions
+2 -2
View File
@@ -657,8 +657,8 @@ export class Agent {
}
// State mutators
setSystemPrompt(v: string[]) {
this.#state.systemPrompt = v;
setSystemPrompt(v: string[] | string) {
this.#state.systemPrompt = typeof v === "string" ? [v] : v;
}
setModel(m: Model) {
+1
View File
@@ -15,6 +15,7 @@
- Fixed `omp dry-balance --bench` to recover from 401 token failures by re-minting the failing OAuth credential in place before switching accounts
- Fixed selector-style UI components to honor `tui.select.up` and `tui.select.down` keybindings instead of hard-coding raw Up/Down arrow bytes ([#1535](https://github.com/can1357/oh-my-pi/issues/1535)).
- Fixed a collapsed, still-streaming tool preview (an `eval`/`bash`/`ssh` box with output streaming in) reading as "weirdly truncated" — top border and head rows missing — once its box outgrew the viewport, snapping back to whole only while expanded with `ctrl+o` and breaking again when collapsed. A streaming preview was classified commit-unstable whenever collapsed, so the transcript offered none of its rows to native scrollback; once the box outgrew the window its head fell into the gap between the commit boundary and the window top, committed nowhere and repainted nowhere. The `provisionalPendingPreview` flag now applies only to the pending call preview (before any result) — once a streaming result exists the result renderer is the live, top-anchored shape and the block is commit-stable in both collapsed and expanded states, so its durable head always reaches scrollback.
- Fixed a crash in subagent task execution and extensions when a string (instead of a string array) was returned or set for the system prompt. Gracefully wrap string values in arrays.
## [15.13.0] - 2026-06-14
@@ -907,7 +907,8 @@ export class ExtensionRunner {
messages.push(result.message);
}
if (result.systemPrompt !== undefined) {
currentSystemPrompt = result.systemPrompt;
currentSystemPrompt =
typeof result.systemPrompt === "string" ? [result.systemPrompt] : result.systemPrompt;
systemPromptModified = true;
}
}
+6 -5
View File
@@ -404,7 +404,7 @@ export interface CreateAgentSessionOptions {
scopedModels?: Array<{ model: Model; thinkingLevel?: ThinkingLevel }>;
/** System prompt blocks. Array replaces default, function receives default blocks and returns final blocks. */
systemPrompt?: string[] | ((defaultPrompt: string[]) => string[]);
systemPrompt?: string | string[] | ((defaultPrompt: string[]) => string | string[]);
/** Optional provider-facing session identifier for prompt caches and sticky auth selection.
* Keeps persisted session files isolated while reusing provider-side caches. */
providerSessionId?: string;
@@ -2176,11 +2176,12 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
if (options.systemPrompt === undefined) {
return defaultPrompt;
}
if (Array.isArray(options.systemPrompt)) {
return { systemPrompt: options.systemPrompt };
}
const customPrompt =
typeof options.systemPrompt === "function"
? options.systemPrompt(defaultPrompt.systemPrompt)
: options.systemPrompt;
return {
systemPrompt: options.systemPrompt(defaultPrompt.systemPrompt),
systemPrompt: typeof customPrompt === "string" ? [customPrompt] : customPrompt,
};
};
+1
View File
@@ -70,6 +70,7 @@ class _FakeRpcClient:
messages: list = []
events: list = []
assistant_text: str = "ok"
assistant_message: dict | None = None
return _Turn()