Created
September 29, 2025 07:39
-
-
Save CharlieGreenman/224d3c200c8f37e1739d06277b8bd77b to your computer and use it in GitHub Desktop.
CoF - Use Chain of Frames using text only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const PARALLEL_FRAMES_PROMPTS = { | |
| INTAKE: `**Role:** Gateway. **Goal:** Normalize the incoming coding problem for downstream workers. | |
| **Do not** solve the problem. Output only the block below. | |
| [INTAKE] | |
| Restatement: <one-paragraph restatement> | |
| I/O-Contracts: <input types, output type, constraints> | |
| EdgeCases: <bullet list> | |
| Tests (min 5): <table or list of input→expected> | |
| PerfTarget: <big-O target & memory> | |
| Determinism: <true/false & source of nondeterminism> | |
| k (Parallelism): <integer> | |
| PartitionKey: <how to split input> | |
| MergeRule: <deterministic merge description> | |
| Safety: <timeouts, max mem, forbidden ops> | |
| [/INTAKE]`, | |
| PLANNING: `**Role:** Planner. **Goal:** Plan a Parallel Chain-of-Frames (pCoF) solution. **No code.** | |
| [PLAN] | |
| Problem: <1–2 sentences> | |
| Algorithm: <high level approach> | |
| Parallelization: <map/reduce | D&C | task parallelism> | |
| Frames F1..Fk: <what each frame does> | |
| Invariants: <must hold after each frame> | |
| Barriers: <B1, B2… and what they check> | |
| Merge: <rule & complexity> | |
| Correctness: <key argument> | |
| Complexity: <work & span> | |
| [/PLAN]`, | |
| PARTITIONING: `**Role:** Partitioner. **Goal:** Emit exact slices for k workers. **No solving.** | |
| [PARTITION] | |
| k: <int> | |
| Policy: <block/range/hash/task> | |
| Slices: | |
| * F1.InputSlice: <concrete slice> | |
| * F2.InputSlice: <…> | |
| … | |
| * Fk.InputSlice: <…> | |
| StableOrdering: <how to order slices> | |
| [/PARTITION]`, | |
| WORKER: `**Role:** Worker Fi. **Goal:** Process your assigned InputSlice. **Frames only. No extra text. No code.** | |
| [PARALLEL FRAME Fi] | |
| InputSlice: <verbatim from partition> | |
| LocalState: <vars/indices before> | |
| Op: <pure operation you will apply> | |
| Output: <local result; exact schema agreed> | |
| [/PARALLEL FRAME Fi]`, | |
| BARRIER: `**Role:** Barrier B1. **Goal:** Validate completeness and invariants. **No rewriting.** | |
| [BARRIER B1] | |
| ExpectedFrames: <F1..Fk> | |
| ReceivedFrames: <list> | |
| Missing: <list or empty> | |
| InvariantChecks: <pass/fail with notes> | |
| Proceed: <yes/no> | |
| [/BARRIER B1]`, | |
| MERGER: `**Role:** Aggregator. **Goal:** Merge \`[PARALLEL FRAME Fi]\` blocks deterministically. **No extra prose.** | |
| [MERGE M1] | |
| Rule: <deterministic rule; e.g., k-way merge / sum / concat in StableOrdering> | |
| Inputs: <F1.Output, F2.Output, …, Fk.Output> | |
| Result: <merged result> | |
| [/MERGE M1] | |
| [FINAL FRAME] | |
| Answer: <one line final answer> | |
| Reason: <one sentence referencing Merge rule & frames> | |
| [/FINAL FRAME]`, | |
| VALIDATOR: `**Role:** Validator. **Goal:** Validate \`[FINAL FRAME]\` using provided tests & constraints. | |
| [VALIDATION] | |
| TestSet: <rerun canonical tests> | |
| PassCount: <x/y> | |
| Failures: <list input→expected vs actual> | |
| EdgeCaseProbe: <any additional probes> | |
| ComplexityCheck: <meets target? notes> | |
| Verdict: <accept/reject with reason> | |
| [/VALIDATION]`, | |
| CODE_SYNTHESIS: `**Role:** Synthesizer. **Goal:** Emit production-grade code that implements the validated algorithm & merge rule. No exploratory commentary. | |
| [CODE] | |
| Language: <e.g., Python 3.11> | |
| Constraints: <time/mem, no globals, pure functions where possible> | |
| Structure: <functions/classes; entrypoint signature> | |
| Implementation: | |
| \`\`\`<language> | |
| # final solution | |
| … | |
| \`\`\` | |
| [/CODE] | |
| [EXPLAINSHORT] | |
| WhyWorks: <3–5 bullet points> | |
| Complexity: <time, space> | |
| [/EXPLAINSHORT]`, | |
| RECOVERY: `**Role:** Recovery. **Goal:** Diagnose and fix failures without changing global contract. | |
| [RECOVERY] | |
| Issue: <missing frames | invariant fail | merge conflict> | |
| RootCause: <analysis> | |
| Action: <repartition | reissue frames Fi..Fj | adjust merge rule (if allowed)> | |
| PatchedPlan: <delta from [PLAN]> | |
| [/RECOVERY]`, | |
| ORCHESTRATOR: `**Role:** Orchestrator. **Goal:** Execute the pipeline: INTAKE → PLAN → PARTITION → WORKERS(F1..Fk) → BARRIER → MERGE → VALIDATE → CODE (if accepted). Enforce schemas and halt on failure. | |
| [ORCH] | |
| Problem: <raw prompt> | |
| k: <int or 'auto'> | |
| StrictSchemas: <true> | |
| HaltOn: <missing frame | invariant fail | validation fail> | |
| Artifacts: <collect all blocks in order> | |
| [/ORCH]` | |
| } as const; | |
| export const PARALLEL_FRAMES_PHASES = [ | |
| 'INTAKE', | |
| 'PLANNING', | |
| 'PARTITIONING', | |
| 'WORKER', | |
| 'BARRIER', | |
| 'MERGER', | |
| 'VALIDATOR', | |
| 'CODE_SYNTHESIS', | |
| 'RECOVERY', | |
| 'ORCHESTRATOR' | |
| ] as const; | |
| export type ParallelFramesPhase = typeof PARALLEL_FRAMES_PHASES[number]; | |
| export interface IntakeResult { | |
| restatement: string; | |
| ioContracts: string; | |
| edgeCases: string[]; | |
| tests: Array<{input: any; expected: any}>; | |
| perfTarget: string; | |
| determinism: boolean; | |
| k: number; | |
| partitionKey: string; | |
| mergeRule: string; | |
| safety: string; | |
| } | |
| export interface PlanResult { | |
| problem: string; | |
| algorithm: string; | |
| parallelization: 'map/reduce' | 'D&C' | 'task parallelism'; | |
| frames: string[]; | |
| invariants: string[]; | |
| barriers: string[]; | |
| merge: string; | |
| correctness: string; | |
| complexity: string; | |
| } | |
| export interface PartitionResult { | |
| k: number; | |
| policy: 'block' | 'range' | 'hash' | 'task'; | |
| slices: Array<{frameId: string; inputSlice: any}>; | |
| stableOrdering: string; | |
| } | |
| export interface WorkerFrame { | |
| frameId: string; | |
| inputSlice: any; | |
| localState: any; | |
| operation: string; | |
| output: any; | |
| } | |
| export interface BarrierResult { | |
| expectedFrames: string[]; | |
| receivedFrames: string[]; | |
| missing: string[]; | |
| invariantChecks: string; | |
| proceed: boolean; | |
| } | |
| export interface MergeResult { | |
| rule: string; | |
| inputs: any; | |
| result: any; | |
| finalAnswer: string; | |
| reason: string; | |
| } | |
| export interface ValidationResult { | |
| testSet: Array<{input: any; expected: any; actual: any}>; | |
| passCount: number; | |
| totalCount: number; | |
| failures: Array<{input: any; expected: any; actual: any}>; | |
| edgeCaseProbe: string; | |
| complexityCheck: string; | |
| verdict: 'accept' | 'reject'; | |
| reason?: string; | |
| } | |
| export interface CodeSynthesisResult { | |
| language: string; | |
| constraints: string; | |
| structure: string; | |
| implementation: string; | |
| whyWorks: string[]; | |
| complexity: string; | |
| } | |
| export interface RecoveryResult { | |
| issue: string; | |
| rootCause: string; | |
| action: string; | |
| patchedPlan: string; | |
| } | |
| export interface OrchestratorConfig { | |
| problem: string; | |
| k: number | 'auto'; | |
| strictSchemas: boolean; | |
| haltOn: string[]; | |
| artifacts: any[]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment