Files
oh-my-pi/packages/coding-agent/src/modes/orchestrate.ts
T
Slava Zavadsky b6a3862ebc fix(coding-agent): gate prompt tool mentions on session tool availability
System and mode prompts referenced tools that may be absent from the
session catalog, forcing the model to satisfy requirements it cannot
execute (generalizes #8139's browser-verification mismatch):

- system-prompt.md: browser verification now keys on the actual UI
  surface and available tools (browser/computer/TUI/CLI), with an
  explicit behavioral/smoke-test fallback when no runtime tool exists;
  todo workflow guidance and the AST-section grep hint are gated on
  tool presence; the auto-QA report_issue block additionally requires
  the write tool.
- project-prompt.md: workspace-tree drill-in and additional-roots tool
  hints only name tools present in the session.
- plan-mode-active.md: ask-tool directives get a prose fallback and
  scout-via-task dispatch is gated on the task tool (render site now
  passes askAvailable/taskAvailable).
- orchestrate-notice.md: the tool budget, verify gates, todo tracking,
  and inline-edit guidance are gated on tool presence; the notice is
  skipped entirely when the task tool is inactive (render fn takes the
  active tool list).

Adds regression tests for each gate; changelog entry.
2026-08-10 20:24:34 -04:00

47 lines
2.0 KiB
TypeScript

import { prompt } from "@oh-my-pi/pi-utils";
import orchestrateNotice from "../prompts/system/orchestrate-notice.md" with { type: "text" };
import { createGradientHighlighter, type KeywordHighlighter } from "./gradient-highlight";
import { magicKeywordRegex } from "./magic-keyword-boundary";
import { keywordInProse } from "./markdown-prose";
/**
* "orchestrate" keyword support.
*
* Typing the standalone word in the input editor paints it with a cool
* teal→violet gradient ({@link highlightOrchestrate}); submitting a message that
* mentions it appends a hidden {@link renderOrchestrateNotice} notice that switches
* the model into multi-agent orchestration mode. Matching is prose-delimited and
* case-sensitive (lowercase only), so "orchestrated", "Orchestrate", or a path
* like "orchestrate.ts" never trigger either behavior. Replaces the former
* `/orchestrate` slash command.
*/
// Detection: lowercase keyword flanked by prose punctuation, whitespace, or a string edge.
const ORCHESTRATE_WORD = magicKeywordRegex("orchestrate");
/** Hidden system notice appended after a user message that mentions "orchestrate". */
export function renderOrchestrateNotice(options: { tools: readonly string[] }): string {
return prompt.render(orchestrateNotice, { tools: options.tools }).trim();
}
/**
* Whether `text` contains the standalone keyword "orchestrate" (lowercase,
* prose-delimited) in prose — never inside a code block, inline code span,
* or XML/HTML section.
*/
export function containsOrchestrate(text: string): boolean {
return keywordInProse(text, ORCHESTRATE_WORD);
}
/**
* Highlight every standalone "orchestrate" in `text` for editor display with a
* cool teal→violet gradient (hue 150..280), visually distinct from ultrathink's
* full-spectrum rainbow.
*/
export const highlightOrchestrate: KeywordHighlighter = createGradientHighlighter({
probe: /orchestrate/,
highlight: magicKeywordRegex("orchestrate", "g"),
stops: 14,
hue: t => 150 + t * 130,
});