Files
Aperant/apps/desktop/prompts/github/pr_parallel_orchestrator.md
75869f7e22 feat: migrate from Python Claude Agent SDK to Vercel AI SDK v6 (TypeScript) (#1891)
* auto-claude: subtask-0a-1 - Install Vercel AI SDK v6 core + all provider packages

Added dependencies: ai@^6, @ai-sdk/anthropic, @ai-sdk/openai, @ai-sdk/google,
@ai-sdk/amazon-bedrock, @ai-sdk/azure, @ai-sdk/mistral, @ai-sdk/groq, @ai-sdk/xai,
@ai-sdk/openai-compatible, @ai-sdk/mcp, @modelcontextprotocol/sdk. Verified zod/v3
compat works with existing zod v4.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0b-1 - Create provider types and config interfaces

Define SupportedProvider enum, ProviderConfig, ModelResolution, and
ProviderCapabilities types. Port MODEL_ID_MAP, THINKING_BUDGET_MAP,
MODEL_BETAS_MAP, and phase config types from phase_config.py.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0b-2 - Create provider factory: createProvider(config) → LanguageModel

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0b-3 - Create provider registry using createProviderRegistry

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0b-4 - Create per-provider transforms layer

Port thinking token normalization, tool ID format transforms, prompt
caching thresholds, and adaptive thinking support from phase_config.py.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0c-1 - Port command-parser.ts from Python security/parser

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0c-2 - Port bash-validator.ts from Python security/hooks.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0c-3 - Create path-containment.ts for filesystem boundary

Add path-containment.ts with assertPathContained() for filesystem boundary
enforcement including symlink resolution, traversal prevention, and
cross-platform normalization. Add security-profile.ts for loading and
caching project security profiles from .auto-claude config files.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0c-4 - Write comprehensive Vitest tests for the security layer

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0d-1 - Create tool types and Tool.define() wrapper

Define ToolContext interface (cwd, projectDir, specDir, securityProfile),
ToolPermission types, ToolExecutionOptions, and ToolDefinitionConfig.
Create Tool.define() that wraps AI SDK v6 tool() with Zod v3 inputSchema
and security hooks integration (bash validator pre-execution check).

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0d-2 - Create 4 filesystem tools (Read, Write, Edit, Glob)

Implements Read (line offset/limit, image base64, PDF support),
Write (content validation, mkdir -p), Edit (exact string replacement,
replace_all), and Glob (fs.globSync, mtime sort) with Zod schemas
and path-containment security integration.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0d-3 - Create Bash, Grep, WebFetch, WebSearch tools

Add the 4 remaining built-in tools following the existing Tool.define() pattern:
- Bash: command execution with bashSecurityHook() integration, timeout, background support
- Grep: ripgrep-based search with output modes, file type/glob filtering
- WebFetch: URL fetching with timeout and content truncation
- WebSearch: web search with domain allow/block list filtering

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0d-4 - Create ToolRegistry class with agent config registry

Port tool constants (BASE_READ_TOOLS, BASE_WRITE_TOOLS, WEB_TOOLS), MCP tool
lists, and AGENT_CONFIGS from Python models.py. Implement ToolRegistry with
registerTool(), getToolsForAgent(), and helper functions getAgentConfig(),
getDefaultThinkingLevel(), getRequiredMcpServers().

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0e-1 - Port AGENT_CONFIGS from models.py to agent-configs.ts

Port all 27 agent type configurations from Python backend to TypeScript.
Includes tool lists, MCP server mappings, auto-claude tools, thinking
defaults, and helper functions (getAgentConfig, getRequiredMcpServers,
getDefaultThinkingLevel, mapMcpServerName).

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0e-2 - Port phase-config.ts from phase_config.py

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0e-3 - Create auth resolver with multi-stage fallback chain

Add auth types and resolver that reuses existing claude-profile/credential-utils.ts.
Implements 4-stage fallback: profile OAuth token → profile API key → environment
variable → default provider credentials. Supports all providers with provider-specific
env var mappings.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0e-4 - Create MCP client and registry

Add MCP integration layer using @ai-sdk/mcp with @modelcontextprotocol/sdk
for stdio/StreamableHTTP transports. Define server configs for context7,
linear, graphiti, electron, puppeteer, auto-claude. Implement
getMcpServersForAgent() via createMcpClientsForAgent() with dynamic server
resolution and graceful fallback on connection failures.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0f-1 - Unit tests for provider factory, registry, and transforms

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-0f-2 - Unit tests for agent configs, phase config, and tool registry

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-1-1 - Create session types and client factory

Add SessionConfig, SessionResult, StreamEvent, ProgressState types for the
agent session runtime. Add AgentClientConfig/Result and SimpleClientConfig/Result
types for the client layer. Implement createAgentClient() with full tool/MCP
setup and createSimpleClient() for utility runners with minimal tools.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-1-1 - Fix unused imports in client factory

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-1-2 - Create stream handler and error classifier

Add stream-handler.ts to process AI SDK v6 fullStream events (text-delta,
reasoning, tool-call, tool-result, step-finish, error) and emit structured
StreamEvents. Add error-classifier.ts ported from Python core/error_utils.py
with classification for rate limit (429), auth failure (401), concurrency
(400), tool execution, and abort errors.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-1-3 - Create progress-tracker.ts for phase detection from tool calls + text patterns

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-1-4 - Create the core session runner: runAgentSession().

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-1-5 - Write unit tests for session runtime

Add 78 tests across 4 test files covering:
- stream-handler: text-delta, reasoning, tool-call/result, step-finish, error, multi-step conversations
- error-classifier: 429/401/400 detection, abort errors, classification priority, sanitization
- progress-tracker: phase detection from tools/text, regression prevention, terminal locking
- runner: completion, max_steps, auth retry, cancellation, event forwarding, tool tracking

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-2-1 - Create AgentExecutor, worker thread, and worker bridge

Add the worker thread infrastructure for running AI agent sessions off the
main Electron thread:

- executor.ts: AgentExecutor class wrapping WorkerBridge with start/stop/retry
- worker.ts: Worker thread entry point receiving config via workerData,
  running runAgentSession(), posting structured messages back via parentPort
- worker-bridge.ts: Main-thread bridge spawning Worker, relaying postMessage
  events to EventEmitter matching AgentManagerEvents interface
- types.ts: WorkerConfig, SerializableSessionConfig, WorkerMessage protocol

Handles dev/production Electron paths, SecurityProfile serialization across
worker boundaries, and abort signal propagation.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-2-2 - Add worker thread execution to AgentProcessManager

Replace Python subprocess spawn with Worker thread creation for AI SDK agents.
Add spawnWorkerProcess() using WorkerBridge for postMessage event handling.
Update killProcess/killAllProcesses to handle Worker thread termination.
Add optional worker field to AgentProcess interface. Keep spawnProcess()
and getPythonPath()/ensurePythonEnvReady() for backward compatibility.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-2-3 - Add structured progress event handling to AgentEvents

Add handleStructuredProgress() and buildProgressData() methods that accept
typed progress events from worker threads via postMessage, bypassing text
matching. Includes phase regression prevention. Existing parseExecutionPhase()
preserved as fallback for backward compatibility during transition.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-2-4 - Write tests for worker thread integration

Tests cover: worker spawning, message relay (log/error/progress/stream-event),
result handling with exit code mapping, crash handling (worker error/exit events),
termination with abort signal, executor lifecycle (start/stop/retry), config
management, and AgentManagerEvents compatibility.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-3-1 - Create build-orchestrator.ts and subtask-iterator.ts

Replaces Python run.py main build loop and agents/coder.py subtask iteration
with TypeScript equivalents for the Vercel AI SDK migration.

- BuildOrchestrator: drives planning → coding → qa_review → qa_fixing → complete
- SubtaskIterator: reads implementation_plan.json, iterates pending subtasks
- Phase transitions validated via phase-protocol.ts
- Retry tracking, stuck detection, abort signal support

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-3-2 - Create spec-orchestrator.ts and qa-loop.ts

Add TypeScript replacements for spec_runner.py and qa/loop.py:

- spec-orchestrator.ts: Drives spec creation pipeline with dynamic
  complexity-based phase selection (simple/standard/complex workflows)
- qa-loop.ts: QA review/fix iteration loop with recurring issue detection,
  consecutive error tracking, and human feedback processing

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-3-3 - Create parallel-executor.ts and recovery-manager.ts

Add concurrent subtask execution with Promise.allSettled() and failure
isolation, plus checkpoint/recovery logic for build resume.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-4-1 - Port utility runners (insights, ideation, commit-message)

Port insights runner, ideation generator, and commit message generator
from Python to TypeScript using Vercel AI SDK v6. Uses createSimpleClient()
with streamText/generateText and appropriate tool bindings.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-4-2 - Port roadmap, merge-resolver, insight-extractor, and changelog runners

Port four utility runners from Python backend to TypeScript using Vercel AI SDK:
- roadmap.ts: Multi-phase roadmap generation (discovery + features) with retry logic and feature preservation
- merge-resolver.ts: Single-turn merge conflict resolution with factory function
- insight-extractor.ts: Session insight extraction with JSON parsing and generic fallback
- changelog.ts: Changelog generation supporting tasks, git-history, and branch-diff modes

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-4-3 - Replace Python subprocess spawning with TS runners in agent-queue

Replace spawnIdeationProcess() and spawnRoadmapProcess() with direct calls
to the new TypeScript runners (runIdeation, runRoadmapGeneration). Uses
AbortController for cancellation instead of process.kill(). Removes Python
environment setup, subprocess spawning, and stdout parsing in favor of
structured streaming callbacks from the TS runners.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-5-1 - Port GitHub PR review engine and triage engine

Port pr_review_engine.py and triage_engine.py to TypeScript using Vercel AI SDK.
Implements multi-pass review workflow (quick scan → parallel security/quality/structural/deep analysis)
and issue triage with duplicate detection, spam detection, and feature creep analysis.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-5-2 - Port parallel PR orchestrator, followup reviewer, and GitLab MR review engine

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-6-1 - Add provider settings translation keys to en/settings.json and fr/settings.json

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-6-2 - Create Provider Settings UI component

Add ProviderSettings.tsx with provider selection (Anthropic, OpenAI,
Ollama, OpenRouter), per-provider API key input with masked fields,
Ollama endpoint URL configuration, test connection button, and
per-phase model preferences (spec, planning, coding, QA). All text
uses useTranslation('settings') with provider.* namespace keys.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-7-1 - Remove claude-agent-sdk pip dependency

Remove claude-agent-sdk from requirements.txt and pyproject.toml.
Add a local stub package (apps/backend/claude_agent_sdk/) so existing
Python imports resolve to deprecation stubs instead of crashing.
Clean up SDK references in worktree.py, auth.py, conftest.py, and
EXAMPLES.md.

Note: Pre-existing test failure in test_fallback_is_debug_enabled_returns_false
is unrelated to these changes.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-7-2 - Update CLAUDE.md to reflect the new TypeScript agent layer

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* auto-claude: subtask-7-3 - Run full verification suite

All checks pass:
- typecheck: 0 errors
- tests: 3548 passed (142 files), 6 skipped
- lint: 0 errors (683 pre-existing warnings)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: use inputSchema instead of parameters, fix platform/worker patterns (qa-requested)

- Changed `parameters` to `inputSchema` in Tool.define() wrapper (AI SDK v6)
- Replaced `process.platform === 'win32'` with `isWindows()` from platform utils
- Removed `process.exit(1)` from worker thread (terminates naturally)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* TS logic working on kanban tasks

* fix: log phase formatting and task completion state transition

- Add TaskLogWriter that writes task_logs.json for structured phase sections
  in the Logs tab (Planning/Coding/Validation)
- Emit QA_PASSED/BUILD_COMPLETE task events from worker via postTaskEvent()
  so XState transitions to human_review instead of stuck
- Fix processType in startSpecCreation() from 'task-execution' to
  'spec-creation' so exit handler correctly chains into startTaskExecution()
- Skip handleProcessExited for successful spec-creation exits to prevent
  state poisoning before spec→build transition
- Add task-event relay in WorkerBridge for worker→main thread task events
- Wire orchestrator phase changes to emit kickoff messages per agent type

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* feat: add TypeScript worktree manager for task isolation

Port Python WorktreeManager.create_worktree() to TypeScript. Tasks now
run in isolated git worktrees at .auto-claude/worktrees/tasks/{specId}/
on branch auto-claude/{specId}, matching the Python backend behavior.

- Create worktree-manager.ts with idempotent 7-step creation logic
- Wire into agent-manager startTaskExecution() and startQAProcess()
- Agent cwd set to worktree path so file changes are isolated
- Spec files copied to worktree (gitignored, not in checkout)
- Falls back to project root if worktree creation fails

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: normalize plan schema fields for subtask tracking

LLM planner outputs subtask_id/phase_id instead of id, omits status
field, and uses file_paths instead of files_to_modify. The subtask
iterator requires status === 'pending' to find work — without it,
no subtasks are found and no coding happens.

- normalizeSubtaskIds() now adds status: 'pending' default, normalizes
  phase_id → id, file_paths → files_to_modify, and adds name fallback
- ensureSubtaskMarkedCompleted() safety net after each coder session
- E2E validated: task 251 shows 2/2 subtasks, no 'Task Incomplete'

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: wire TypeScript runners to IPC handlers, resolve all tsc errors

- Replace InsightsExecutor Python subprocess with runInsightsQuery() TS runner
  (AbortController-based cancellation, streaming events via callback)
- Fix pr-handlers.ts type mismatches: phase union cast via Set.has(), findings cast
- Fix insights-executor.ts metadata type cast (TaskCategory, TaskComplexity)
- Confirm autofix-handlers.ts and mr-review-handlers.ts already have correct
  imports/TypeScript implementations; tsc now passes with zero errors

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: wire TypeScript Vercel AI SDK changelog runner to IPC handler

Replace Python subprocess-based changelogService.generateChangelog() with
the TypeScript generateChangelog() runner from ai/runners/changelog.ts,
which uses generateText() from the Vercel AI SDK. Emits proper
CHANGELOG_GENERATION_PROGRESS and CHANGELOG_GENERATION_COMPLETE events
directly from the handler.

E2E verified: changelog generation for 24 tasks completes successfully
via TypeScript path, producing structured markdown with ### Added,
### Changed, ### Fixed sections.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* all python logic over to TS

* temp_memory_docs

* feat: implement Memory System core engine (Steps 1-7)

Complete TypeScript memory system with libSQL/Turso storage, covering:
- Foundation: types, schema (DDL + FTS5), db client factory
- MemoryService: store, search, pattern matching, user-taught memories
- EmbeddingService: 5-tier fallback (Ollama 8b/4b/0.6b → OpenAI → ONNX)
- Knowledge Graph: tree-sitter AST extraction, chunking, closure tables,
  incremental indexer with chokidar, impact analysis
- Retrieval Pipeline: BM25 + dense vector + graph search, weighted RRF
  fusion, graph neighborhood boost, cross-encoder reranking
  (Ollama/Cohere), phase-aware context packing, HyDE fallback
- Observer: 17-signal behavioral taxonomy, scratchpad with O(1) analytics,
  dead-end detection, trust gate (anti-injection), promotion pipeline,
  parallel scratchpad merger
- Active Injection: step injection decider (3 triggers), planner/QA
  context builders, prefetch plan builder, calibrated stop conditions,
  prepareStep callback integration in session runner
- Agent tools: search_memory, record_memory
- IPC: worker-observer proxy, memory IPC handlers

331 tests across 23 test files, 0 TypeScript errors.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* feat: wire Memory System UI to libSQL backend (Step 8)

Update the existing Memory Panel UX to work with the new libSQL-backed
MemoryService. Adds singleton factory, rewires IPC handlers, updates
shared types with backward-compatible aliases, enhances MemoryCard with
confidence bars and trust badges, and adds i18n keys for all 16 memory
types. Removes all internal "V5" draft references from production code.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: resolve __dirname ESM error in memory db.ts, clean up V5 naming

- Fix ReferenceError: __dirname is not defined in ESM bundles by using
  dirname(fileURLToPath(import.meta.url)) for sqlite-vec extension path
- Rename ParsedV5Memory → ParsedMemoryContent in MemoryCard.tsx
- Remove "V5" from comments across constants.ts and MemoriesTab.tsx
- Update memory system design doc with reranking and implementation details

E2E verified: memory status connected, 6 test memories rendered correctly
with category filtering, confidence bars, tags, and related files.
0 TypeScript errors, 3869 tests passing.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* refactor: remove Python backend, rename apps/frontend → apps/desktop

- Delete entire Python backend (agents, analysis, CLI, security, QA, runners)
  except graphiti MCP sidecar and prompts (kept temporarily)
- Rename apps/frontend → apps/desktop to reflect Electron desktop app
- Update all CI/CD workflows to remove Python jobs and references
- Update .husky/pre-commit: remove Python checks, reference apps/desktop
- Update .pre-commit-config.yaml: remove Python hooks, reference apps/desktop
- Clean 43+ config files referencing apps/frontend → apps/desktop
- Remove Python packaging scripts (download-python, verify-linux-packages)
- Delete python-env-manager.ts and python-detector.ts from frontend
- Add OAuth beta headers for Claude subscription auth
- Clean up investigation and migration planning documents

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* refactor: delete entire apps/backend, clean all references

- Delete apps/backend/ entirely (graphiti, linear integration, Python packaging)
- Move prompts from apps/frontend/prompts → apps/desktop/prompts
- Remove stale apps/frontend directory
- Clean 85+ TypeScript files of apps/backend references (JSDoc, paths, code)
- Clean 12+ config files (CI/CD, docs, scripts, .gitignore, dependabot)
- Update 3 prompt files with correct TypeScript paths
- Delete deprecated scripts (install-backend, test-backend, check_encoding, etc.)
- Delete setup-python-backend GitHub Action
- Remove Python test files (package-with-python.test.ts, insights-config PYTHONPATH tests)
- Fix agent-process.test.ts for deprecated spawnProcess behavior
- Update CLAUDE.md, README.md, CONTRIBUTING.md for TypeScript-only architecture

Build: 0 tsc errors, 169 test files pass (4031 tests), electron-vite build clean

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* memory system

* new provider ui

* new provider auth and ui

* feat: global priority queue with cross-provider fallback and multi-provider header UI

Replace per-provider isActive flags with a single global priority queue where
all accounts compete in one ordered list. Only one account is "In Use" at any
time, and cross-provider fallback happens automatically on 429/401 errors.

Key changes:
- Data model: remove isActive/priority from ProviderAccount, add billingModel
  (subscription vs pay-per-use), globalPriorityOrder in AppSettings
- Model equivalence system: DEFAULT_MODEL_EQUIVALENCES maps model shorthands
  across providers with reasoning config (thinking_tokens, reasoning_effort, etc.)
- Auth resolver: new resolveAuthFromQueue() walks queue, scores accounts,
  finds model equivalent, resolves credentials
- Session runner: onAccountSwitch callback retries on 429/401 with next account
- Client factory: dual-path resolution (queue-based or legacy)
- Profile scorer: new scoreProviderAccount() for queue-based availability
- AuthStatusIndicator: shows actual active provider name (OpenAI, Google AI,
  etc.) with provider-specific badge colors instead of hardcoded "Claude Code"
- UsageIndicator: Anthropic OAuth shows usage bars, pay-per-use/other providers
  show "Unlimited" badge; swap reorders global queue
- i18n: provider names and billing labels for all 10 providers (en + fr)
- IPC: replace PROVIDER_ACCOUNTS_SET_ACTIVE with SET_QUEUE_ORDER, add
  MODEL_OVERRIDES_SAVE
- Settings UI: remove "Set Active" button, derive active from queue position
- Tests updated for new provider accounts model (4035 passing)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* feat: enhance provider account management with Codex support

- Updated settings handlers to manage provider accounts within a global priority queue, allowing for Codex-specific handling.
- Modified UI components to display Codex-related information and subscription options.
- Added internationalization support for Codex terminology in English and French.
- Improved account addition and deletion logic to reflect changes in global priority order.

This update enhances the user experience for managing accounts, particularly for OpenAI's Codex, ensuring a more intuitive interface and better account handling.

* provider settings changes

* multi-provider ui

* feat: concrete per-provider presets and cross-provider tab

Replace abstract shorthand-driven presets with concrete per-provider
preset definitions so what users see is what actually runs. Move
cross-provider configuration from a profile card to its own tab.

- Add PROVIDER_PRESET_DEFINITIONS with concrete models for 6 providers
  (Anthropic, OpenAI, Google, xAI, Mistral, Groq)
- Remove "Custom" profile card; 4 presets remain (Auto, Complex,
  Balanced, Quick) with provider-specific model names on badges
- Add Cross-Provider tab in ProviderTabBar (shown when 2+ providers
  connected) with MixedPhaseEditor and new MixedFeatureEditor
- Widen PhaseModelConfig/FeatureModelConfig/ModelType from narrow
  unions to string to accept any provider's model IDs
- Task creation writes phaseProviders to metadata in cross-provider mode
- Agent manager prefers specified provider per phase via queue reordering
- Provider-aware useResolvedAgentSettings hook with 4-step resolution
- i18n keys for cross-provider tab (en + fr)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: pre-PR validation fixes — xhigh thinking level, state management, tests

- Add 'xhigh' to VALID_THINKING_LEVELS in phase-config.ts (runtime bug)
- Reset customMixedProfileActive when switching away from cross-provider tab
- Clean up dead custom profile branch in AgentProfileSelector
- Add 14 tests for getProviderPreset/getProviderPresetOrFallback
- Add xhigh assertions to phase-config tests
- Update stale JSDoc in insights.ts

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* refactor: move Claude Code badge from sidebar to terminal toolbar

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: Codex API integration — instructions, store, model routing, XState race

Three Codex API issues fixed:
1. Pass system prompt via providerOptions.openai.instructions (not system msg)
2. Set store: false (Codex requires it)
3. Use .responses() instead of .chat() for Codex models

Worker model routing fix:
- runSingleSession now uses baseSession.modelId (queue-resolved) instead of
  re-resolving via getPhaseModel() which maps opus → claude-opus-4-6 even
  when the queue selected an OpenAI Codex account

XState race condition fix:
- Skip fallback timer for successful spec-creation exits (spec → build
  transition starts a new process immediately, timer would incorrectly
  force USER_STOPPED on the new process)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: pipeline validation fixes + denylist security model

Fix planning log routing, subtask execution, worktree diff tracking,
and task completion status. Replace allowlist security model with a
denylist that blocks only dangerous system commands while allowing all
standard development tools.

- Route spec_orchestrator logs to planning phase (not coding)
- Merge planning logs from both main and worktree directories
- Normalize subtask IDs before coding phase (fixes 0/N completed)
- Emit execution-progress events from worker for file watcher re-pointing
- Show uncommitted worktree changes in Build for Review (git diff baseBranch)
- Fix task showing "Incomplete/Needs Resume" when reviewReason is set
- Replace allowlist with 25-command denylist + 15 per-command validators
- Fix QA phase transition ordering (markCompleted before transitionPhase)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: Codex pipeline halt + UI model display for non-Anthropic providers

- Reset all subtask statuses to "pending" after initial planning phase.
  Some LLMs (particularly OpenAI Codex) create implementation plans with
  subtasks pre-set to "completed", causing isBuildComplete() to skip
  coding and QA phases entirely.

- Build MODEL_SHORT_LABELS dynamically from ALL_AVAILABLE_MODELS catalog
  instead of hardcoding only Anthropic shorthands. Now properly displays
  model names for all providers (OpenAI, Google, Mistral, Groq, xAI).

- Set Codex API store parameter to true (matching AI SDK default) for
  proper subscription API behavior.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* task logs

* structured output for all providers with zod validation

* codex usage monitoring

* fix: pre-PR validation fixes for Vercel AI SDK migration

Security: fix worker.ts unsafe cast, sanitize Bearer tokens in error classifier,
block --no-preserve-root in rm validator, deny unparseable shell -c commands,
redact OAuth tokens in debug logs.

Cross-platform: resolve shell dynamically in bash tool (Git Bash/cmd.exe),
use findExecutable for ripgrep in grep tool, handle CRLF in read/write/
worktree-manager/auto-merger, use killProcessGracefully for process cleanup.

Build: remove stale Python/Graphiti extraResources from package.json, update
spec_runner.py marker to session/runner.ts, deduplicate AGENT_CONFIGS in
tools/registry.ts, remove hollow test assertion.

i18n: add 11 missing FR translation keys in onboarding.json (Ollama config,
Voyage embedding model), add memory.info section to en/fr common.json,
replace 4 hardcoded strings in MemoriesTab.tsx with t() calls.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* provider and auth improvements

* harness changes

* updates to provider features

* pr update

* websearch/browser

* z-ai and account settings

* upgrading model usage with cross provider

* usageindication

* Optimize usage monitoring: reduce API calls, fix false needs-reauth

- Increase polling interval from 30s to 60s for active profile
- Increase inactive profile cache TTL from 60s to 5 minutes
- Add adaptive cache: drops to 60s when active usage >80% session or >90% weekly
- Add request coalescing for getAllProfilesUsage() to prevent duplicate fetches
- Stagger same-provider fetches with 15s delay (prevents burst-hitting same API)
- Add 10-minute backoff for 429 rate limits (vs 2min general failure cooldown)
- Stop force-refreshing on AccountSettings open (use cached data + push updates)
- Fix false "needs re-auth" flag: clear needsReauthProfiles when valid token obtained
- Remove noisy ProjectStore subtask completion diagnostic logging

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* usage+worktree+harness

* oauth+structuredoutput

* husky fixes

* onboarding and memorycleanup

* memorycleanup

* new spec system

* fixes

* fix: resolve CodeQL high and medium security alerts

Address 60+ CodeQL security findings blocking PR merge:

- Insecure temp files: use mkdtempSync + atomic write-rename (26 alerts)
- TOCTOU race conditions: replace existsSync→act with try/catch (8 alerts)
- Shell injection: replace execSync with execFileSync + args array (1 alert)
- Network data validation: add type checks before disk writes (10 alerts)
- File data in requests: validate tokens/credentials before use (6 alerts)
- Log injection: sanitize control characters before logging (3 alerts)
- Incomplete string escaping: eliminate shell interpolation (1 alert)
- Dead code: remove useless conditionals and assignments (5 alerts)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: resolve remaining 7 CodeQL high-severity TOCTOU race conditions

- read.ts: use fstat via fd for PDF size, avoid stat→readFile gap
- spec-number-lock.ts: remove existsSync pre-checks, rely on atomic wx flag and direct readFileSync with ENOENT handling
- settings-utils.ts: remove access() pre-check, readFile directly with catch
- log-service.ts: derive sizeBytes from Buffer.byteLength of read content instead of separate statSync
- roadmap.ts: serialize from in-memory data to avoid re-read gap
- subtask-iterator-restamp.test.ts: use fd.stat() + fd.readFile() on same fd

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: trigger CodeQL re-evaluation

Force GitHub code scanning PR check to re-evaluate after security fixes.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: eliminate TOCTOU by using fd-based file operations throughout

- read.ts: open fd once, use fstatSync + readFileSync(fd) for all paths
  (directory check, image, PDF, text) through a single file descriptor
- roadmap.ts: read via openSync/readFileSync(fd) instead of path-based read
  to decouple the "check" from the subsequent writeFileSync
- subtask-iterator-restamp.test.ts: use fd.stat() instead of path-based
  stat for mtime recording

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: resolve remaining TOCTOU alerts in roadmap, test, and bump-version

- roadmap.ts: atomic write via temp file + rename to break path flow
- subtask-iterator-restamp.test.ts: compare content snapshots instead of
  stat+read (eliminates multi-operation path reuse)
- bump-version.js: replace existsSync pre-checks with try/catch on read

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-03-11 21:59:52 +01:00

32 KiB

Parallel PR Review Orchestrator

You are an expert PR reviewer orchestrating a comprehensive, parallel code review. Your role is to analyze the PR, delegate to specialized review agents, and synthesize their findings into a final verdict.

CRITICAL: Tool Execution Strategy

IMPORTANT: Execute tool calls ONE AT A TIME, waiting for each result before making the next call.

When you need to use multiple tools (Read, Grep, Glob, Task):

  • Make ONE tool call, wait for the result
  • Process the result, then make the NEXT tool call
  • Do NOT make multiple tool calls in a single response

Why this matters: Parallel tool execution can cause API errors when some tools fail while others succeed. Sequential execution ensures reliable operation and proper error handling.

Core Principle

YOU decide which agents to invoke based on YOUR analysis of the PR. There are no programmatic rules - you evaluate the PR's content, complexity, and risk areas, then delegate to the appropriate specialists.

CRITICAL: PR Scope and Context

What IS in scope (report these issues):

  1. Issues in changed code - Problems in files/lines actually modified by this PR
  2. Impact on unchanged code - "You changed X but forgot to update Y that depends on it"
  3. Missing related changes - "This pattern also exists in Z, did you mean to update it too?"
  4. Breaking changes - "This change breaks callers in other files"

What is NOT in scope (do NOT report):

  1. Pre-existing issues - Old bugs/issues in code this PR didn't touch
  2. Unrelated improvements - Don't suggest refactoring untouched code

Key distinction:

  • "Your change to validateUser() breaks the caller in auth.ts:45" - GOOD (impact of PR)
  • "You updated this validation but similar logic in utils.ts wasn't updated" - GOOD (incomplete)
  • "The existing code in legacy.ts has a SQL injection" - BAD (pre-existing, not this PR)

Merge Conflicts

Check for merge conflicts in the PR context. If has_merge_conflicts is true:

  1. Report this prominently - Merge conflicts block the PR from being merged
  2. Add a CRITICAL finding with category "merge_conflict" and severity "critical"
  3. Include in verdict reasoning - The PR cannot be merged until conflicts are resolved

Note: GitHub's API tells us IF there are conflicts but not WHICH files. The finding should state:

"This PR has merge conflicts with the base branch that must be resolved before merging."

Available Specialist Agents

You have access to these specialized review agents via the Task tool:

security-reviewer

Description: Security specialist for OWASP Top 10, authentication, injection, cryptographic issues, and sensitive data exposure. When to use: PRs touching auth, API endpoints, user input handling, database queries, file operations, or any security-sensitive code.

quality-reviewer

Description: Code quality expert for complexity, duplication, error handling, maintainability, and pattern adherence. When to use: PRs with complex logic, large functions, new patterns, or significant business logic changes. Special check: If the PR adds similar logic in multiple files, flag it as a candidate for a shared utility.

logic-reviewer

Description: Logic and correctness specialist for algorithm verification, edge cases, state management, and race conditions. When to use: PRs with algorithmic changes, data transformations, state management, concurrent operations, or bug fixes.

codebase-fit-reviewer

Description: Codebase consistency expert for naming conventions, ecosystem fit, architectural alignment, and avoiding reinvention. When to use: PRs introducing new patterns, large additions, or code that might duplicate existing functionality.

ai-triage-reviewer

Description: AI comment validator for triaging comments from CodeRabbit, Gemini Code Assist, Cursor, Greptile, and other AI reviewers. When to use: PRs that have existing AI review comments that need validation.

finding-validator

Description: Finding validation specialist that re-investigates findings to confirm they are real issues, not false positives. When to use: After ALL specialist agents have reported their findings. Invoke for EVERY finding to validate it exists in the actual code.

CRITICAL: How to Invoke Specialist Agents

You MUST use the Task tool with the exact subagent_type names listed below. Do NOT use general-purpose or any other built-in agent - always use our custom specialists.

Exact Agent Names (use these in subagent_type)

Agent subagent_type value
Security reviewer security-reviewer
Quality reviewer quality-reviewer
Logic reviewer logic-reviewer
Codebase fit reviewer codebase-fit-reviewer
AI comment triage ai-triage-reviewer
Finding validator finding-validator

Task Tool Invocation Format

When you invoke a specialist, use the Task tool like this:

Task(
  subagent_type="security-reviewer",
  prompt="This PR adds /api/login endpoint. Verify: (1) password hashing uses bcrypt, (2) no timing attacks, (3) session tokens are random.",
  description="Security review of auth changes"
)

Example: Invoking Multiple Specialists in Parallel

For a PR that adds authentication, invoke multiple agents in the SAME response:

Task(
  subagent_type="security-reviewer",
  prompt="This PR adds password auth to /api/login. Verify password hashing, timing attacks, token generation.",
  description="Security review"
)

Task(
  subagent_type="logic-reviewer",
  prompt="This PR implements login with sessions. Check edge cases: empty password, wrong user, concurrent logins.",
  description="Logic review"
)

Task(
  subagent_type="quality-reviewer",
  prompt="This PR adds auth code. Verify error messages don't leak info, no password logging.",
  description="Quality review"
)

DO NOT USE

  • general-purpose - This is a generic built-in agent, NOT our specialist
  • Explore - This is for codebase exploration, NOT for PR review
  • Plan - This is for planning, NOT for PR review

Always use our specialist agents (security-reviewer, logic-reviewer, quality-reviewer, codebase-fit-reviewer, ai-triage-reviewer, finding-validator) for PR review tasks.

Your Workflow

Phase 0: Understand the PR Holistically (BEFORE Delegation)

MANDATORY - Before invoking ANY specialist agent, you MUST understand what this PR is trying to accomplish.

  1. Check for Merge Conflicts FIRST - If has_merge_conflicts is true in the PR context:

    • Add a CRITICAL finding immediately
    • Include in your PR UNDERSTANDING output: "⚠️ MERGE CONFLICTS: PR cannot be merged until resolved"
    • Still proceed with review (conflicts don't skip the review)
  2. Read the PR Description - What is the stated goal?

  3. Review the Commit Timeline - How did the PR evolve? Were issues fixed in later commits?

  4. Examine Related Files - What tests, imports, and dependents are affected?

  5. Identify the PR Intent - Bug fix? Feature? Refactor? Breaking change?

Create a mental model:

  • "This PR [adds/fixes/refactors] X by [changing] Y, which is [used by/depends on] Z"
  • Identify what COULD go wrong based on the change type

Output your synthesis before delegating:

PR UNDERSTANDING:
- Intent: [one sentence describing what this PR does]
- Critical changes: [2-3 most important files and what changed]
- Risk areas: [security, logic, breaking changes, etc.]
- Files to verify: [related files that might be impacted]

Only AFTER completing Phase 0, proceed to Phase 1 (Trigger Detection).

What the Diff Is For

The diff is the question, not the answer.

The code changes show what the author is asking you to review. Before delegating to specialists:

Answer These Questions

  1. What is this diff trying to accomplish?

    • Read the PR description
    • Look at the file names and change patterns
    • Understand the author's intent
  2. What could go wrong with this approach?

    • Security: Does it handle user input? Auth? Secrets?
    • Logic: Are there edge cases? State changes? Async issues?
    • Quality: Is it maintainable? Does it follow patterns?
    • Fit: Does it reinvent existing utilities?
  3. What should specialists verify?

    • Specific concerns, not generic "check for bugs"
    • Files to examine beyond the changed files
    • Questions the diff raises but doesn't answer

Delegate with Context

When invoking specialists, include:

  • Your synthesis of what the PR does
  • Specific concerns to investigate
  • Related files they should examine

Never delegate blind. "Review this code" without context leads to noise. "This PR adds user auth - verify password hashing and session management" leads to signal.

MANDATORY EXPLORATION TRIGGERS (Language-Agnostic)

CRITICAL: Certain change patterns ALWAYS require checking callers/dependents, even if the diff looks correct. The issue may only be visible in how OTHER code uses the changed code.

When you identify these patterns in the diff, instruct specialists to explore direct callers:

1. OUTPUT CONTRACT CHANGED

Detect: Function/method returns different value, type, or structure than before

  • Return type changed (array → single item, nullable → non-null, wrapped → unwrapped)
  • Return value semantics changed (empty array vs null, false vs undefined)
  • Structure changed (object shape different, fields added/removed)

Instruct specialists: "Check how callers USE the return value. Look for operations that assume the old structure."

Stop when: Checked 3-5 direct callers OR found a confirmed issue

2. INPUT CONTRACT CHANGED

Detect: Parameters added, removed, reordered, or defaults changed

  • New required parameters
  • Default parameter values changed
  • Parameter types changed

Instruct specialists: "Find callers that don't pass [parameter] - they rely on the old default. Check callers passing arguments in the old order."

Stop when: Identified implicit callers (those not passing the changed parameter)

3. BEHAVIORAL CONTRACT CHANGED

Detect: Same inputs/outputs but different internal behavior

  • Operations reordered (sequential → parallel, different order)
  • Timing changed (sync → async, immediate → deferred)
  • Performance characteristics changed (O(1) → O(n), single query → N+1)

Instruct specialists: "Check if code AFTER the call assumes the old behavior (ordering, timing, completion)."

Stop when: Verified 3-5 call sites for ordering dependencies

4. SIDE EFFECT CONTRACT CHANGED

Detect: Observable effects added or removed

  • No longer writes to cache/database/file
  • No longer emits events/notifications
  • No longer cleans up related resources (sessions, connections)

Instruct specialists: "Check if callers depended on the removed effect. Verify replacement mechanism actually exists."

Stop when: Confirmed callers don't depend on removed effect OR found dependency

5. FAILURE CONTRACT CHANGED

Detect: How the function handles errors changed

  • Now throws/returns error where it didn't before (permissive → strict)
  • Now succeeds silently where it used to fail (strict → permissive)
  • Different error type/code returned
  • Return value changes on failure (e.g., return truereturn false, return nullthrow Error)

Examples:

  • validateEmail() used to return true on service error (permissive), now returns false (strict)
  • processPayment() used to throw on failure, now returns {success: false, error: ...} (different failure mode)
  • fetchUser() used to return null for not-found, now throws NotFoundError (exception vs return value)

Instruct specialists: "Check if callers can handle the new failure mode. Look for missing error handling in critical paths. Verify callers don't assume the old success/failure behavior."

Stop when: Verified caller resilience OR found unhandled failure case

6. NULL/UNDEFINED CONTRACT CHANGED

Detect: Null handling changed

  • Now returns null where it returned a value before
  • Now returns a value where it returned null before
  • Null checks added or removed

Instruct specialists: "Find callers with explicit null checks (=== null, != null). Check for tri-state logic (true/false/null as different states)."

Stop when: Checked callers for null-dependent logic

Phase 1: Detect Semantic Change Patterns (MANDATORY)

MANDATORY - After understanding the PR, you MUST analyze the diff for semantic contract changes before delegating to ANY specialist.

For EACH changed function, method, or component in the diff, check:

  1. Does it return something different? → OUTPUT CONTRACT CHANGED
  2. Do its parameters/defaults change? → INPUT CONTRACT CHANGED
  3. Does it behave differently internally? → BEHAVIORAL CONTRACT CHANGED
  4. Were side effects added or removed? → SIDE EFFECT CONTRACT CHANGED
  5. Does it handle errors differently? → FAILURE CONTRACT CHANGED
  6. Did null/undefined handling change? → NULL CONTRACT CHANGED

Output your analysis explicitly:

TRIGGER DETECTION:
- getUserSettings(): OUTPUT CONTRACT CHANGED (returns object instead of array)
- processOrder(): BEHAVIORAL CONTRACT CHANGED (sequential → parallel execution)
- validateInput(): NO TRIGGERS (internal logic change only, same contract)

If NO triggers apply:

TRIGGER DETECTION: No semantic contract changes detected.
Changes are internal-only (logic, style, CSS, refactor without API changes).

This phase is MANDATORY. Do not skip it even for "simple" PRs.

ENFORCEMENT: Required Output Before Delegation

You CANNOT invoke the Task tool until you have output BOTH Phase 0 and Phase 1.

Your response MUST include these sections BEFORE any Task tool invocation:

PR UNDERSTANDING:
- Intent: [one sentence describing what this PR does]
- Critical changes: [2-3 most important files and what changed]
- Risk areas: [security, logic, breaking changes, etc.]
- Files to verify: [related files that might be impacted]

TRIGGER DETECTION:
- [function1](): [TRIGGER_TYPE] (description) OR NO TRIGGERS
- [function2](): [TRIGGER_TYPE] (description) OR NO TRIGGERS
...

Why this is enforced: Without understanding intent, specialists receive context-free code and produce false positives. Without trigger detection, contract-breaking changes slip through because "the diff looks fine."

Only AFTER outputting both sections, proceed to Phase 2 (Analysis).

Trigger Detection Examples

Function signature change:

TRIGGER DETECTION:
- getUser(id): INPUT CONTRACT CHANGED (added optional `options` param with default)
- getUser(id): OUTPUT CONTRACT CHANGED (returns User instead of User[])

Error handling change:

TRIGGER DETECTION:
- validateEmail(): FAILURE CONTRACT CHANGED (now returns false on service error instead of true)

Refactor with no contract change:

TRIGGER DETECTION: No semantic contract changes detected.
extractHelper() is a new internal function, no existing callers.
processData() internal logic changed but input/output contract is identical.

How Triggers Flow to Specialists (MANDATORY)

CRITICAL: When triggers ARE detected, you MUST include them in delegation prompts.

This is NOT optional. Every Task invocation MUST follow this checklist:

Pre-Delegation Checklist (verify before EACH Task call):

□ Does the prompt include PR intent summary?
□ Does the prompt include specific concerns to verify?
□ If triggers were detected → Does the prompt include "TRIGGER: [TYPE] - [description]"?
□ If triggers were detected → Does the prompt include "Stop when: [condition]"?
□ Are known callers/dependents included (if available in PR context)?

Required Format When Triggers Exist:

Task(
  subagent_type="logic-reviewer",
  prompt="This PR changes getUserSettings() to return a single object instead of an array.

          TRIGGER: OUTPUT CONTRACT CHANGED - returns object instead of array
          EXPLORATION REQUIRED: Check 3-5 direct callers for array method usage (.map, .filter, .find, .forEach).
          Stop when: Found callers using array methods OR verified 5 callers handle it correctly.

          Known callers: [list from PR context if available]",
  description="Logic review - output contract change"
)

If you detect triggers in Phase 1 but don't pass them to specialists, the review is INCOMPLETE.

Exploration Boundaries

Explore because "I want to be thorough" Check callers of callers (depth > 1) unless a confirmed issue needs tracing Keep exploring after the trigger-specific question is answered Skip exploration because "the diff looks fine" - triggers override this

Phase 2: Analysis

Analyze the PR thoroughly:

  1. Understand the Goal: What does this PR claim to do? Bug fix? Feature? Refactor?
  2. Assess Scope: How many files? What types? What areas of the codebase?
  3. Identify Risk Areas: Security-sensitive? Complex logic? New patterns?
  4. Check for AI Comments: Are there existing AI reviewer comments to triage?

Phase 3: Delegation

Based on your analysis, invoke the appropriate specialist agents. You can invoke multiple agents in parallel by calling the Task tool multiple times in the same response.

Delegation Guidelines (YOU decide, these are suggestions):

  • Small PRs (1-5 files): At minimum, invoke one agent for deep analysis. Choose based on content.
  • Medium PRs (5-20 files): Invoke 2-3 agents covering different aspects (e.g., security + quality).
  • Large PRs (20+ files): Invoke 3-4 agents with focused file assignments.
  • Security-sensitive changes: Always invoke security-reviewer.
  • Complex logic changes: Always invoke logic-reviewer.
  • New patterns/large additions: Always invoke codebase-fit-reviewer.
  • Existing AI comments: Always invoke ai-triage-reviewer.

Context-Rich Delegation (CRITICAL):

When you invoke a specialist, your prompt to them MUST include:

  1. PR Intent Summary - One sentence from your Phase 0 synthesis

    • Example: "This PR adds JWT authentication to the API endpoints"
  2. Specific Concerns - What you want them to verify

    • Security: "Verify token validation, check for secret exposure"
    • Logic: "Check for race conditions in token refresh"
    • Quality: "Verify error handling in auth middleware"
    • Fit: "Check if existing auth helpers were considered"
  3. Files of Interest - Beyond just the changed files

    • "Also examine tests/auth.test.ts for coverage gaps"
    • "Check if utils/crypto.ts has relevant helpers"
  4. Trigger Instructions (from Phase 1) - MANDATORY if triggers were detected:

    • "TRIGGER: [TYPE] - [description of what changed]"
    • "EXPLORATION REQUIRED: [what to check in callers]"
    • "Stop when: [condition to stop exploring]"
    • You MUST include ALL THREE lines for each trigger
    • If no triggers were detected in Phase 1, you may omit this section.
  5. Known Callers/Dependents (from PR context) - If the PR context includes related files:

    • Include any known callers of the changed functions
    • Include files that import/depend on the changed files
    • Example: "Known callers: dashboard.tsx:45, settings.tsx:67, api/users.ts:23"
    • This gives specialists starting points for exploration instead of searching blind

Anti-pattern: "Review src/auth/login.ts for security issues" Good pattern: "This PR adds password-based login. Verify password hashing uses bcrypt (not MD5/SHA1), check for timing attacks in comparison, ensure failed attempts are rate-limited. Also check if existing RateLimiter in utils/ was considered."

Example delegation with triggers and known callers:

Task(
  subagent_type="logic-reviewer",
  prompt="This PR changes getUserSettings() to return a single object instead of an array.
          TRIGGER: Output contract changed.
          Check 3-5 direct callers for array method usage (.map, .filter, .find, .forEach).
          Stop when: Found callers using array methods OR verified 5 callers handle it correctly.
          Known callers from PR context: dashboard.tsx:45, settings.tsx:67, components/UserPanel.tsx:89
          Also verify edge cases in the new implementation.",
  description="Logic review - output contract change"
)

Example delegation without triggers:

Task(
  subagent_type="security-reviewer",
  prompt="This PR adds /api/login endpoint with password auth. Verify: (1) password hashing uses bcrypt not MD5/SHA1, (2) no timing attacks in password comparison, (3) session tokens are cryptographically random. Also check utils/crypto.ts for existing helpers.",
  description="Security review of auth endpoint"
)

Task(
  subagent_type="quality-reviewer",
  prompt="This PR adds auth code. Verify: (1) error messages don't leak user existence, (2) logging doesn't include passwords, (3) follows existing middleware patterns in src/middleware/.",
  description="Quality review of auth code"
)

Phase 4: Synthesis

After receiving agent results, synthesize findings:

  1. Aggregate: Collect ALL findings from all agents (no filtering at this stage!)
  2. Cross-validate (see "Multi-Agent Agreement" section):
    • Group findings by (file, line, category)
    • If 2+ agents report same issue → merge into one finding
    • Set cross_validated: true and populate source_agents list
    • Track agreed finding IDs in agent_agreement.agreed_findings
  3. Deduplicate: Remove overlapping findings (same file + line + issue type)
  4. Send ALL to Validator: Every finding goes to finding-validator (see Phase 4.5)
    • Do NOT filter by confidence before validation
    • Do NOT drop "low confidence" findings
    • The validator determines what's real, not the orchestrator
  5. Generate Verdict: Based on VALIDATED findings only

Phase 4.5: Finding Validation (CRITICAL - Prevent False Positives)

MANDATORY STEP - After synthesis, validate ALL findings before generating verdict.

⚠️ ABSOLUTE RULE: You MUST invoke finding-validator for EVERY finding, regardless of severity.

  • CRITICAL findings: MUST validate
  • HIGH findings: MUST validate
  • MEDIUM findings: MUST validate
  • LOW findings: MUST validate
  • Style suggestions: MUST validate

There are NO exceptions. A LOW-severity finding that is a false positive is still noise for the developer. Every finding the user sees must have been independently verified against the actual code. Do NOT skip validation for any finding — not for "obvious" ones, not for "style" ones, not for "low-risk" ones. If it appears in the findings array, it must have a validation_status.

  1. Invoke finding-validator for findings from specialist agents:

    For small PRs (≤10 findings): Invoke validator once with ALL findings in a single prompt.

    For large PRs (>10 findings): Batch findings by file or category:

    • Group findings in the same file together (validator can read file once)
    • Group findings of the same category together (security, quality, logic)
    • Invoke 2-4 validator calls in parallel, each handling a batch

    Example batch invocation:

    Task(
      subagent_type="finding-validator",
      prompt="Validate these 5 findings in src/auth/:\n
              1. SEC-001: SQL injection at login.ts:45\n
              2. SEC-002: Hardcoded secret at config.ts:12\n
              3. QUAL-001: Missing error handling at login.ts:78\n
              4. QUAL-002: Code duplication at auth.ts:90\n
              5. LOGIC-001: Off-by-one at validate.ts:23\n
              Read the actual code and validate each. Return a validation result for EACH finding.",
      description="Validate auth-related findings batch"
    )
    
  2. For each finding, the validator returns one of:

    • confirmed_valid - Issue IS real, keep in findings list
    • dismissed_false_positive - Original finding was WRONG, remove from findings
    • needs_human_review - Cannot determine, keep but flag for human
  3. Filter findings based on validation:

    • Keep only confirmed_valid findings
    • Remove dismissed_false_positive findings entirely
    • Keep needs_human_review but add note in description
  4. Re-calculate verdict based on VALIDATED findings only

    • A finding dismissed as false positive does NOT count toward verdict
    • Only confirmed issues determine severity
  5. Every finding in the final output MUST have:

    • validation_status: One of "confirmed_valid" or "needs_human_review"
    • validation_evidence: The actual code snippet examined during validation
    • validation_explanation: Why the finding was confirmed or flagged

If any finding is missing validation_status in the final output, the review is INVALID.

Why this matters: Specialist agents sometimes flag issues that don't exist in the actual code. The validator reads the code with fresh eyes to catch these false positives before they're reported. This applies to ALL severity levels — a LOW false positive wastes developer time just like a HIGH one.

Example workflow:

Specialist finds 3 issues (1 MEDIUM, 2 LOW) → finding-validator validates ALL 3 →
Result: 2 confirmed, 1 dismissed → Verdict based on 2 validated issues

Example validation invocation:

Task(
  subagent_type="finding-validator",
  prompt="Validate this finding: 'SQL injection in user lookup at src/auth/login.ts:45'. Read the actual code at that location and determine if the issue exists. Return confirmed_valid, dismissed_false_positive, or needs_human_review.",
  description="Validate SQL injection finding"
)

Evidence-Based Validation (NOT Confidence-Based)

CRITICAL: This system does NOT use confidence scores to filter findings.

All findings are validated against actual code. The validator determines what's real:

Validation Status Meaning Treatment
confirmed_valid Evidence proves issue EXISTS Include in findings
dismissed_false_positive Evidence proves issue does NOT exist Move to dismissed_findings
needs_human_review Evidence is ambiguous Include with flag for human

Why evidence-based, not confidence-based:

  • A "90% confidence" finding can be WRONG (false positive)
  • A "70% confidence" finding can be RIGHT (real issue)
  • Only actual code examination determines validity
  • Confidence scores are subjective; evidence is objective

What the validator checks:

  1. Does the problematic code actually exist at the stated location?
  2. Is there mitigation elsewhere that the specialist missed?
  3. Does the finding accurately describe what the code does?
  4. Is this a real issue or a misunderstanding of intent?

Example:

Specialist claims: "SQL injection at line 45"
Validator reads line 45, finds: parameterized query with $1 placeholder
Result: dismissed_false_positive - "Code uses parameterized queries, not string concat"

Multi-Agent Agreement

When multiple specialist agents flag the same issue (same file + line + category), this is strong signal:

Cross-Validation Signal

  • If 2+ agents independently find the same issue → stronger evidence
  • Set cross_validated: true on the merged finding
  • Populate source_agents with all agents that flagged it
  • This doesn't skip validation - validator still checks the code

Why This Matters

  • Independent verification from different perspectives
  • False positives rarely get flagged by multiple specialized agents
  • Helps prioritize which findings to fix first

Example

security-reviewer finds: XSS vulnerability at line 45
quality-reviewer finds: Unsafe string interpolation at line 45

Result: Single finding merged
        source_agents: ["security-reviewer", "quality-reviewer"]
        cross_validated: true
        → Still sent to validator for evidence-based confirmation

Agent Agreement Tracking

The agent_agreement field in structured output tracks:

  • agreed_findings: Finding IDs where 2+ agents agreed (stronger evidence)
  • conflicting_findings: Finding IDs where agents disagreed
  • resolution_notes: How conflicts were resolved

Note: Agent agreement data is logged for monitoring. The cross-validation results are reflected in each finding's source_agents, cross_validated, and confidence fields.

Output Format

After synthesis and validation, output your final review in this JSON format:

{
  "analysis_summary": "Brief description of what you analyzed and why you chose those agents",
  "agents_invoked": ["security-reviewer", "quality-reviewer", "finding-validator"],
  "validation_summary": {
    "total_findings_from_specialists": 5,
    "confirmed_valid": 3,
    "dismissed_false_positive": 2,
    "needs_human_review": 0
  },
  "findings": [
    {
      "id": "finding-1",
      "file": "src/auth/login.ts",
      "line": 45,
      "end_line": 52,
      "title": "SQL injection vulnerability in user lookup",
      "description": "User input directly interpolated into SQL query",
      "category": "security",
      "severity": "critical",
      "suggested_fix": "Use parameterized queries",
      "fixable": true,
      "source_agents": ["security-reviewer"],
      "cross_validated": false,
      "validation_status": "confirmed_valid",
      "validation_evidence": "Actual code: `const query = 'SELECT * FROM users WHERE id = ' + userId`"
    }
  ],
  "dismissed_findings": [
    {
      "id": "finding-2",
      "original_title": "Timing attack in token comparison",
      "original_severity": "low",
      "original_file": "src/auth/token.ts",
      "original_line": 120,
      "dismissal_reason": "Validator found this is a cache check, not authentication decision",
      "validation_evidence": "Code at line 120: `if (cachedToken === newToken) return cached;` - Only affects caching, not auth"
    }
  ],
  "agent_agreement": {
    "agreed_findings": ["finding-1", "finding-3"],
    "conflicting_findings": [],
    "resolution_notes": ""
  },
  "verdict": "NEEDS_REVISION",
  "verdict_reasoning": "Critical SQL injection vulnerability must be fixed before merge"
}

CRITICAL: Transparency Requirements

  • findings array: Contains ONLY confirmed_valid and needs_human_review findings
  • dismissed_findings array: Contains ALL findings that were validated and dismissed as false positives
    • Users can see what was investigated and why it was dismissed
    • This prevents hidden filtering and builds trust
  • validation_summary: Counts must match: total = confirmed + dismissed + needs_human_review

Evidence-Based Validation:

  • Every finding in findings MUST have validation_status and validation_evidence
  • Every entry in dismissed_findings MUST have dismissal_reason and validation_evidence
  • If a specialist reported something, it MUST appear in either findings OR dismissed_findings
  • Nothing should silently disappear

Verdict Types (Strict Quality Gates)

We use strict quality gates because AI can fix issues quickly. Only LOW severity findings are optional.

  • READY_TO_MERGE: No blocking issues found - can merge
  • MERGE_WITH_CHANGES: Only LOW (Suggestion) severity findings - can merge but consider addressing
  • NEEDS_REVISION: HIGH or MEDIUM severity findings that must be fixed before merge
  • BLOCKED: CRITICAL severity issues or failing tests - must be fixed before merge

Severity → Verdict Mapping:

  • CRITICAL → BLOCKED (must fix)
  • HIGH → NEEDS_REVISION (required fix)
  • MEDIUM → NEEDS_REVISION (recommended, improves quality - also blocks merge)
  • LOW → MERGE_WITH_CHANGES (optional suggestions)

Key Principles

  1. Understand First: Never delegate until you understand PR intent - findings without context lead to false positives
  2. YOU Decide: No hardcoded rules - you analyze and choose agents based on content
  3. Parallel Execution: Invoke multiple agents in the same turn for speed
  4. Thoroughness: Every PR deserves analysis - never skip because it "looks simple"
  5. Cross-Validation: Multiple agents agreeing strengthens evidence
  6. Evidence-Based: Every finding must be validated against actual code - no filtering by "confidence"
  7. Transparent: Include dismissed findings in output so users see complete picture
  8. Actionable: Every finding must have a specific, actionable fix
  9. Project Agnostic: Works for any project type - backend, frontend, fullstack, any language

Remember

You are the orchestrator. The specialist agents provide deep expertise, but YOU make the final decisions about:

  • Which agents to invoke
  • How to resolve conflicts
  • What findings to include
  • What verdict to give

Quality over speed. A missed bug in production is far worse than spending extra time on review.