cfd38d82fc
* refactor delegation system and add PR summary comments Delegation system: - replace mode-based delegation with select_mode → delegate two-step flow - orchestrator crafts self-contained subagent prompts (clean context — no system/repo/event instructions leak) - add role-based tool filtering via FastMCP authenticate hook (?role=subagent hides orchestrator-only tools) - add select_mode tool for orchestrator guidance per mode - add ask_question tool for lightweight research subagents - extract shared subagent lifecycle into subagent.ts (create, complete, stdout, instructions) - route set_output to per-subagent state when activeSubagentId is set - track per-subagent state (SubagentState Map) replacing boolean delegationActive flag - capture and aggregate AgentUsage across all agents (claude, codex, gemini, opencode) - write usage summary table to GitHub job summary - block built-in subagent spawning (Task for Claude, Task(*) for Cursor) - increase activity timeout from 60s to 300s (subagent thinking phases) - fix gh CLI misguidance in system prompt — explicitly forbid usage PR summary comments: - add prSummaryComment trigger (DB schema + migrations + Zod + UI toggle) - dispatch mini-effort summary job alongside PR review on pr.created - add update_pull_request_body MCP tool - add defaultEffort option to webhook dispatch Hardening: - rewrite delegate/selectMode tests with simulated state management - add toolFiltering.test.ts for role extraction, canAccess, set_output routing - remove non-null assertions for PULLFROG_TEMP_DIR (proper error throws) - use fetchWithRetry for direct tarball downloads - DRY fix for rate limit check in test runner Co-authored-by: Cursor <cursoragent@cursor.com> * fix: add type keyword to Effort import in handleWebhook.ts Co-authored-by: Cursor <cursoragent@cursor.com> * clean up delegation system, improve code quality across the codebase - simplify delegate tool to instructions + effort params with subagent lifecycle in subagent.ts - add select_mode and ask_question orchestrator-only tools with canAccess filtering - replace delegate.test.ts/selectMode.test.ts with toolFiltering.test.ts (live MCP integration) - add set_output routing for subagent context and AgentUsage tracking across all agents - add PR summary comment trigger (schema, UI, webhook dispatch with silent flag) - add update_pull_request_body MCP tool - fix changed-agents.sh to always include claude canary for non-agent action changes - fix cursor pagination bug in getSelectedInstallationReposPage - remove destructuring patterns, inline type definitions, and unsafe type casts - replace non-null assertions with explicit checks in install.ts - convert multi-param functions to single param objects (postCleanup, runActionLocal, etc.) - use isHttpError helper in API routes instead of catch-any patterns - add adhoc test fixtures for delegation scenarios (context isolation, error handling, synthesis, etc.) Co-authored-by: Cursor <cursoragent@cursor.com> * no subagent mutation, one mcp per subagent * address review feedback: parallel-safe usage tracking, subagent isolation, minor improvements * fix subagent state isolation: replace Object.freeze with shallow copy Object.freeze throws TypeErrors when subagent tools (checkout_pr, report_progress) write scalar properties to toolState. A shallow copy achieves the same isolation for scalar fields while allowing tools to work normally. Shared references (subagents Map, usageEntries array) remain shared for coordination. --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: pullfrog[bot] <226033991+pullfrog[bot]@users.noreply.github.com>
72 lines
3.0 KiB
TypeScript
72 lines
3.0 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import type { AgentResult, TestRunnerOptions, ValidationCheck } from "../utils.ts";
|
|
import { defineFixture, getAgentOutput, getStructuredOutput } from "../utils.ts";
|
|
|
|
/**
|
|
* delegate-context-isolation — verifies that the subagent's "clean room"
|
|
* actually works: the orchestrator receives a secret marker in its prompt but
|
|
* MUST NOT include it in the subagent's instructions.
|
|
*
|
|
* the subagent is told to report everything it knows about the task context.
|
|
* the validator checks that the secret marker does NOT appear in the subagent's
|
|
* reported context, proving it only sees what the orchestrator explicitly passes.
|
|
*
|
|
* this is a critical architectural property of the delegation system.
|
|
*/
|
|
|
|
const SECRET = randomUUID();
|
|
|
|
const fixture = defineFixture(
|
|
{
|
|
prompt: `You are an orchestrator. READ CAREFULLY.
|
|
|
|
Your SECRET value is: ${SECRET}
|
|
You MUST remember this secret and include it in your OWN final set_output call.
|
|
You MUST NOT include this secret in the subagent's instructions.
|
|
|
|
Your task:
|
|
1. Select Plan mode via select_mode.
|
|
2. Delegate to a subagent with mini effort. Your subagent instructions should be EXACTLY:
|
|
"You are a research subagent. Your only task is to report what you know. Call gh_pullfrog/set_output with a summary of: (a) the instructions you were given, (b) any context you have about the parent task. Start your output with CONTEXT_REPORT:"
|
|
DO NOT mention the secret value anywhere in the subagent instructions.
|
|
3. After delegation, call set_output with: "SECRET=${SECRET},SUBAGENT_SAID=<paste the subagent's output here>"
|
|
|
|
CRITICAL: Your final output MUST contain "SECRET=${SECRET}" exactly.`,
|
|
effort: "auto",
|
|
timeout: "8m",
|
|
},
|
|
{ localOnly: true }
|
|
);
|
|
|
|
function validator(result: AgentResult): ValidationCheck[] {
|
|
const output = getStructuredOutput(result);
|
|
const agentOutput = getAgentOutput(result);
|
|
|
|
const setOutputCalled = output !== null;
|
|
// orchestrator should include at least the first segment of the UUID (proving it read it).
|
|
// some agents paraphrase or truncate, so matching the first 8 hex chars is sufficient.
|
|
const secretPrefix = SECRET.slice(0, 8);
|
|
const secretInOutput = setOutputCalled && output !== null && output.includes(secretPrefix);
|
|
const delegationOccurred = /» delegating subagent=/i.test(agentOutput);
|
|
|
|
// the subagent's context report should NOT contain any part of the secret
|
|
const subagentMatch = output ? /SUBAGENT_SAID=([\s\S]*)/i.exec(output) : null;
|
|
const subagentOutput = subagentMatch ? subagentMatch[1] : "";
|
|
const secretLeaked = subagentOutput.includes(secretPrefix);
|
|
|
|
return [
|
|
{ name: "set_output", passed: setOutputCalled },
|
|
{ name: "secret_in_output", passed: secretInOutput },
|
|
{ name: "delegation_occurred", passed: delegationOccurred },
|
|
{ name: "no_secret_leak", passed: !secretLeaked },
|
|
];
|
|
}
|
|
|
|
export const test: TestRunnerOptions = {
|
|
name: "delegate-context-isolation",
|
|
fixture,
|
|
validator,
|
|
env: { GITHUB_REPOSITORY: "pullfrog/test-repo" },
|
|
tags: ["adhoc"],
|
|
};
|