Files
oh-my-pi/packages/coding-agent/src/task/template.ts
T
can1357 8f1da70d79 feat(coding-agent): enabled simple-mode routing in task tool execution
- Added task.simple to settings and schema with default, schema-free, and independent modes.
- Added mode-aware task schema and validation to enforce context/schema rules per simple mode.
- Updated prompts and template rendering to tailor headers and guidance for each simple mode.
- Added simple-mode capabilities and updated TaskTool execution for mode-aware context behavior.
- Added tests for independent rendering and mode-specific rejection of invalid context or schema inputs.
2026-04-15 18:13:47 +02:00

48 lines
1.4 KiB
TypeScript

import { prompt } from "@oh-my-pi/pi-utils";
import subagentUserPromptTemplate from "../prompts/system/subagent-user-prompt.md" with { type: "text" };
import { getTaskSimpleModeCapabilities, type TaskSimpleMode } from "./simple-mode";
import type { TaskItem } from "./types";
interface RenderResult {
/** Full task text sent to the subagent */
task: string;
/** Raw per-task assignment text, without prompt template boilerplate */
assignment: string;
id: string;
description: string;
}
/**
* Build the full task text from shared context and per-task assignment.
*
* If context is provided, it is prepended with a separator.
*/
export function renderTemplate(
context: string | undefined,
task: TaskItem,
simpleMode: TaskSimpleMode = "default",
): RenderResult {
let { id, description, assignment } = task;
assignment = assignment.trim();
const { contextEnabled } = getTaskSimpleModeCapabilities(simpleMode);
context = contextEnabled ? context?.trim() : undefined;
if (!context || !assignment) {
if (simpleMode === "independent" && assignment) {
return {
task: prompt.render(subagentUserPromptTemplate, { assignment, independentMode: true }),
assignment,
id,
description,
};
}
return { task: assignment || context!, assignment: assignment || context!, id, description };
}
return {
task: prompt.render(subagentUserPromptTemplate, { context, assignment, independentMode: false }),
assignment,
id,
description,
};
}