Buckets:
| #!/usr/bin/env python3 | |
| """Build phase/role prompts from harness artifacts. | |
| The prompt builder turns the harness philosophy into concrete instructions: | |
| fixed role isolation, project-specific emphasis, and explicit boundaries. | |
| It intentionally reads only the compact handoff artifacts, not the full chat. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| from console_io import configure_utf8_output | |
| configure_utf8_output() | |
| PROJECT_GUIDANCE = { | |
| "web-app": { | |
| "developer": [ | |
| "Preserve responsive UI behavior and API contracts.", | |
| "Add loading, error, and empty states when the touched surface needs them.", | |
| "Keep frontend and backend data shapes explicit.", | |
| ], | |
| "code-qa": [ | |
| "Run unit/API tests where available.", | |
| "Check API shape drift, auth/CORS assumptions, and data validation.", | |
| "Record lint/static-check evidence.", | |
| ], | |
| "func-qa": [ | |
| "Use Browser/GPT-5.5 visual checks for desktop and mobile widths.", | |
| "Verify user-visible workflows, not just API responses.", | |
| "Capture screenshot observations when UI is involved.", | |
| ], | |
| "user-acceptance": [ | |
| "Use Browser as a real user: click from the entry point through each core flow.", | |
| "Cover desktop and mobile viewport where relevant.", | |
| "Record screenshots, expected result, observed result, and pass/fail.", | |
| ], | |
| }, | |
| "cli-tool": { | |
| "developer": [ | |
| "Keep stdout/stderr behavior deterministic.", | |
| "Define exit-code behavior for success and failure paths.", | |
| "Add tests for argument, empty-input, and output-format boundaries.", | |
| ], | |
| "code-qa": [ | |
| "Run the actual CLI/library tests, not only file-presence checks.", | |
| "Check cross-platform path, newline, encoding, and shell quoting assumptions.", | |
| "Record lint/static-review evidence.", | |
| ], | |
| "func-qa": [ | |
| "Run representative CLI commands and compare exact stdout/stderr.", | |
| "Verify no-argument and invalid-input behavior when in scope.", | |
| "Record command, exit code, and observed output.", | |
| ], | |
| "user-acceptance": [ | |
| "Act like a terminal user, not a tester reading code.", | |
| "Run representative commands and record command, exit code, stdout, and stderr.", | |
| "Compare observed output with the promised user-facing behavior.", | |
| ], | |
| }, | |
| "quant-trading": { | |
| "developer": [ | |
| "Protect capital and risk limits before adding strategy complexity.", | |
| "Avoid look-ahead bias and hidden future-data leakage.", | |
| "Keep exchange/network side effects behind explicit adapters or mocks.", | |
| ], | |
| "code-qa": [ | |
| "Check risk controls, position sizing, and failure modes.", | |
| "Verify backtest assumptions and reproducibility.", | |
| "Record test evidence for extreme-market and disconnected-data cases.", | |
| ], | |
| "func-qa": [ | |
| "Validate strategy behavior against acceptance scenarios, not profit claims.", | |
| "Check drawdown, stop-loss, and reconnect paths when in scope.", | |
| "Never imply live trading safety without explicit credentials and user confirmation.", | |
| ], | |
| "user-acceptance": [ | |
| "Use simulated/backtest scenarios only unless the user explicitly confirms live trading.", | |
| "Record scenario, risk limit, position changes, drawdown, and observed behavior.", | |
| "Do not describe simulated acceptance as live-trading safety.", | |
| ], | |
| }, | |
| "data-pipeline": { | |
| "developer": [ | |
| "Make schema assumptions explicit.", | |
| "Handle empty input, malformed rows, and retry/idempotency boundaries.", | |
| "Keep transformations testable with small fixtures.", | |
| ], | |
| "code-qa": [ | |
| "Run fixture-based tests and schema checks.", | |
| "Check idempotency, null handling, and partial-failure behavior.", | |
| "Record data-quality evidence.", | |
| ], | |
| "func-qa": [ | |
| "Verify input-to-output examples against acceptance criteria.", | |
| "Check logs/errors are actionable for failed rows or stages.", | |
| ], | |
| "user-acceptance": [ | |
| "Run representative sample input through the pipeline.", | |
| "Record sample input, output, schema/row checks, and user-visible errors.", | |
| ], | |
| }, | |
| "mobile-app": { | |
| "developer": [ | |
| "Prioritize small-screen ergonomics and permission states.", | |
| "Keep offline/error states explicit when touched.", | |
| ], | |
| "code-qa": [ | |
| "Check state management, permission handling, and platform assumptions.", | |
| "Record test/lint evidence.", | |
| ], | |
| "func-qa": [ | |
| "Use Browser/device-sized visual checks when the app is web-rendered.", | |
| "Verify touch-sized controls and narrow viewport layout.", | |
| ], | |
| "user-acceptance": [ | |
| "Act like a mobile user: tap through core flows.", | |
| "Record viewport/device size, screenshot, expected result, and observed result.", | |
| ], | |
| }, | |
| "video-production": { | |
| "storyboard-planner": [ | |
| "Turn the spec into scenes with timing, visual intent, and transition notes.", | |
| "Keep narration, scene purpose, and frame requirements aligned.", | |
| ], | |
| "creative-director": [ | |
| "Review continuity, pacing, color, and text-visual fit.", | |
| "Reject generic decorative visuals that do not carry the script.", | |
| ], | |
| "visual-qa": [ | |
| "Verify storyboard/design artifacts and rendered frames/screenshots.", | |
| "Check subtitle sync, format, and visual continuity when available.", | |
| ], | |
| "user-acceptance": [ | |
| "Watch rendered frames or storyboard sequence as an audience member.", | |
| "Record scene/frame evidence, subtitle/transition observations, and pass/fail.", | |
| ], | |
| }, | |
| "design-document": { | |
| "creative-director": [ | |
| "Protect brand/object specificity and visual hierarchy.", | |
| "Reject vague style words unless tied to visible criteria.", | |
| ], | |
| "visual-qa": [ | |
| "Check exported artifacts for layout, format, text fit, and consistency.", | |
| ], | |
| "user-acceptance": [ | |
| "Open exported design artifacts as the final recipient.", | |
| "Record layout, format, readability, and visual identity observations.", | |
| ], | |
| }, | |
| "default": { | |
| "developer": [ | |
| "Implement only the current manifest task and its tests.", | |
| "Keep changes scoped to the listed files.", | |
| ], | |
| "code-qa": [ | |
| "Run available tests and record execution evidence.", | |
| "Check maintainability and obvious safety issues.", | |
| ], | |
| "func-qa": [ | |
| "Verify acceptance criteria through user-observable behavior.", | |
| "Record pass/fail evidence.", | |
| ], | |
| "user-acceptance": [ | |
| "Run the primary user scenario from entry to result.", | |
| "Record expected result, observed result, and pass/fail.", | |
| ], | |
| }, | |
| } | |
| ROLE_CONTRACTS = { | |
| "developer": { | |
| "knows": "Only the current task slice and acceptance criteria.", | |
| "does_not_know": "Later code-qa, func-qa, audit, or remediation flow.", | |
| "output": "Code files, test files, and a brief file list.", | |
| "rules": [ | |
| "Do not reopen product discussion or change requirements during implementation.", | |
| "If requirements, red lines, or acceptance boundaries are unclear, stop and report a Module 1 blocker.", | |
| "Write or update tests before implementation when practical.", | |
| "Do not edit files outside the task file_scope unless impossible.", | |
| "Do not perform QA/audit work for later roles.", | |
| ], | |
| }, | |
| "code-qa": { | |
| "knows": "The implementation exists and must be technically verified.", | |
| "does_not_know": "func-qa details or remediation flow.", | |
| "output": "code-qa-report.md with test and lint/static-review evidence.", | |
| "rules": [ | |
| "Do not redefine requirements; verify against the locked spec and manifest.", | |
| "If the implementation exposes a missing boundary, report it as a Module 1 blocker.", | |
| "Run actual tests or explain why a command is unavailable.", | |
| "Check code health, security basics, and maintainability.", | |
| "Do not perform business/browser acceptance for func-qa.", | |
| ], | |
| }, | |
| "func-qa": { | |
| "knows": "code-qa passed and behavior must be verified.", | |
| "does_not_know": "Developer implementation details or remediation flow.", | |
| "output": "func-qa-report.md with user-observable pass/fail evidence.", | |
| "rules": [ | |
| "Do not invent new user requirements; verify the locked acceptance criteria.", | |
| "If behavior cannot be judged from the spec, report a Module 1 blocker.", | |
| "Verify acceptance criteria through behavior, CLI commands, API calls, or Browser checks.", | |
| "Use Browser and GPT-5.5/Codex vision for UI work.", | |
| "Record exact commands, screenshots, or observations as applicable.", | |
| ], | |
| }, | |
| "storyboard-planner": { | |
| "knows": "Creative spec and current storyboard task.", | |
| "does_not_know": "Later creative review or visual QA decisions.", | |
| "output": "storyboard/design planning artifact.", | |
| "rules": ["Keep scenes concrete, timed, and verifiable."], | |
| }, | |
| "creative-director": { | |
| "knows": "Creative artifacts need review.", | |
| "does_not_know": "Later visual QA details.", | |
| "output": "creative-review.md.", | |
| "rules": ["Review creative coherence and reject vague visual claims."], | |
| }, | |
| "visual-qa": { | |
| "knows": "Visual artifacts must be verified.", | |
| "does_not_know": "Earlier creative process details.", | |
| "output": "visual-qa-report.md.", | |
| "rules": ["Verify actual rendered/exported artifacts when available."], | |
| }, | |
| "user-acceptance": { | |
| "knows": "The implementation and QA reports exist; final user-side behavior must be checked.", | |
| "does_not_know": "Internal implementation rationale or unresolved product debate.", | |
| "output": "user-acceptance-report.md with scenario-by-scenario user evidence.", | |
| "rules": [ | |
| "Act like the target user entering through the real product surface.", | |
| "Verify promised workflows one by one with observed evidence.", | |
| "Do not inspect code as the primary evidence for this role.", | |
| "If the user path cannot be exercised, report the missing runnable surface as a blocker.", | |
| ], | |
| }, | |
| } | |
| def load_json(path: Path) -> dict: | |
| if not path.is_file(): | |
| return {} | |
| return json.loads(path.read_text(encoding="utf-8-sig")) | |
| def first_present(data: dict, names: list[str], default=None): | |
| for name in names: | |
| if name in data: | |
| return data[name] | |
| return default | |
| def normalize_task(task: dict) -> dict: | |
| return { | |
| "id": first_present(task, ["id"], ""), | |
| "description": first_present(task, ["description", "描述"], ""), | |
| "acceptance_ids": first_present(task, ["acceptance_ids", "验收标准ID"], []), | |
| "file_scope": first_present(task, ["file_scope", "文件范围"], []), | |
| "task_type": first_present(task, ["task_type", "任务类型"], ""), | |
| } | |
| def select_task(manifest: dict, task_id: str | None) -> dict: | |
| tasks = manifest.get("tasks", []) | |
| if not tasks: | |
| return {} | |
| if task_id: | |
| for task in tasks: | |
| if str(task.get("id")) == task_id: | |
| return task | |
| return tasks[0] | |
| def as_lines(values) -> list[str]: | |
| if not values: | |
| return [] | |
| if isinstance(values, list): | |
| return [str(v) for v in values] | |
| return [str(values)] | |
| def build_prompt(task_dir: Path, role: str, task_id: str | None) -> str: | |
| profile = load_json(task_dir / "project-profile.json") | |
| manifest = load_json(task_dir / "execution-manifest.json") | |
| task = normalize_task(select_task(manifest, task_id)) | |
| project_type = profile.get("project_type", "default") | |
| complexity = profile.get("complexity", manifest.get("risk_level", "L2")) | |
| gates = profile.get("gates", []) | |
| tools = profile.get("tools", []) | |
| acceptance = manifest.get("acceptance_criteria", profile.get("acceptance_criteria", [])) | |
| contract = ROLE_CONTRACTS.get(role, ROLE_CONTRACTS["developer"]) | |
| guidance = PROJECT_GUIDANCE.get(project_type, PROJECT_GUIDANCE["default"]) | |
| focus = guidance.get(role, guidance.get("developer", PROJECT_GUIDANCE["default"]["developer"])) | |
| lines = [ | |
| f"# Harness Agent Prompt: {role}", | |
| "", | |
| "## Identity", | |
| f"You are the `{role}` role inside Module 2 of Codex Harness.", | |
| "You must obey the harness state machine and current task boundary.", | |
| "", | |
| "## Project Profile", | |
| f"- project_type: {project_type}", | |
| f"- complexity: {complexity}", | |
| f"- gates: {', '.join(gates) if gates else '(none listed)'}", | |
| "", | |
| "## Role Isolation", | |
| f"- You know: {contract['knows']}", | |
| f"- You do not know: {contract['does_not_know']}", | |
| "", | |
| "## Current Task Slice", | |
| f"- task_id: {task.get('id') or '(not specified)'}", | |
| f"- task_type: {task.get('task_type') or '(not specified)'}", | |
| f"- description: {task.get('description') or '(not specified)'}", | |
| f"- acceptance_ids: {', '.join(as_lines(task.get('acceptance_ids'))) or '(not specified)'}", | |
| f"- file_scope: {', '.join(as_lines(task.get('file_scope'))) or '(not specified)'}", | |
| "", | |
| "## Project-Specific Focus", | |
| ] | |
| lines.extend(f"- {item}" for item in focus) | |
| lines.extend([ | |
| "", | |
| "## Acceptance Criteria", | |
| ]) | |
| for item in acceptance: | |
| if isinstance(item, dict): | |
| aid = item.get("id", "") | |
| summary = first_present(item, ["summary", "摘要"], "") | |
| method = first_present(item, ["method", "判定方式"], "") | |
| lines.append(f"- {aid}: {summary} ({method})") | |
| else: | |
| lines.append(f"- {item}") | |
| lines.extend([ | |
| "", | |
| "## Available Tools From Profile", | |
| ]) | |
| if tools: | |
| for tool in tools: | |
| lines.append(f"- {json.dumps(tool, ensure_ascii=False)}") | |
| else: | |
| lines.append("- No project-specific tools listed.") | |
| lines.extend([ | |
| "", | |
| "## Hard Rules", | |
| ]) | |
| lines.extend(f"- {rule}" for rule in contract["rules"]) | |
| lines.extend([ | |
| "- Module 1 decides requirements, red lines, and boundaries; Module 2 executes.", | |
| "- Do not hold a new debate or broaden product scope inside Module 2.", | |
| "- Do not skip or mark gates as passed yourself.", | |
| "- Do not broaden scope beyond the manifest unless the current task is impossible.", | |
| "- If blocked, report the blocker and the smallest artifact needed to unblock.", | |
| "- Keep the final handoff compact enough for the coordinator to record in the context ledger.", | |
| "- After this role finishes, its context will be closed or discarded; put durable facts in the required artifact.", | |
| "", | |
| "## Required Output", | |
| contract["output"], | |
| ]) | |
| return "\n".join(lines) + "\n" | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description="Build a Codex Harness role prompt") | |
| parser.add_argument("--task-dir", required=True) | |
| parser.add_argument("--role", required=True) | |
| parser.add_argument("--task-id") | |
| args = parser.parse_args() | |
| task_dir = Path(args.task_dir).resolve() | |
| if not task_dir.is_dir(): | |
| print(f"FAIL: task directory does not exist: {task_dir}", file=sys.stderr) | |
| return 1 | |
| print(build_prompt(task_dir, args.role, args.task_id), end="") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |
Xet Storage Details
- Size:
- 16.3 kB
- Xet hash:
- 967c20548c19192baecd06ef61c2d2cd491126cd34a2169c107a99af6638d6e9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.