# Codex Gap Checklist

This document tracks the auditable capability gaps between the current `never2average-clone` agents/TUI and the behavior expected from a stronger OpenCode/Codex-style runtime for our usecases.

## Gap Estimate

- Versus OpenCode on our usecases: `5-10%`
- Versus Codex overall on our usecases: `16-22%`

These numbers are not product-market statements. They are an engineering estimate of workflow/runtime maturity on:
- long-horizon analyst runs
- subagent delegation quality
- tool routing discipline
- fullscreen TUI interaction quality
- skill/runtime integration depth

## Audit Scope

Reviewed code paths:
- [src/analysts.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analysts.ts)
- [src/analyst-skills.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-skills.ts)
- [src/agent.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/agent.ts)
- [src/openfinances-go.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/openfinances-go.ts)
- [src/tools/sub-agent.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/tools/sub-agent.ts)
- [src/tools/index.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/tools/index.ts)
- [src/cli.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/cli.ts)
- [src/fullscreen-ui.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/fullscreen-ui.ts)
- [src/commands.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/commands.ts)

Reference baseline:
- OpenAI Codex core prompt spec: https://github.com/openai/codex/blob/main/codex-rs/core/prompt_with_apply_patch_instructions.md
- OpenAI Codex TUI chat widget: https://github.com/openai/codex/blob/main/codex-rs/tui/src/chatwidget.rs

## Checklist

### A1. Analyst runtime policies are still mostly prompt-only
- Severity: `P1`
- Status: `done`
- Evidence:
  - [src/analysts.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analysts.ts:23)
  - [src/tools/index.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/tools/index.ts:58)
  - [src/analyst-policy.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-policy.ts)
  - [src/agent.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/agent.ts)
- Problem:
  - `value_creation` and `pricing_research` differ mainly by loaded skill text.
  - They still share one general runtime/tool bundle.
- Acceptance criteria:
  - [x] Each analyst has an explicit runtime policy layer beyond prompt text.
  - [x] Tool availability, fallback order, and output contract can differ by analyst without branching only inside prose.
  - [x] Evals prove the two analysts route differently on materially different tasks.

### A2. Subagents do not inherit enough structured parent state
- Severity: `P1`
- Status: `done`
- Evidence:
  - [src/tools/sub-agent.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/tools/sub-agent.ts:15)
  - [src/cli.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/cli.ts:201)
  - [src/analyst-policy.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-policy.ts)
- Problem:
  - Child runs start with empty `messages` and `plan`.
  - The child only receives a freeform `message`, so artifact/dataset/plan continuity depends on the parent restating it manually.
- Acceptance criteria:
  - [x] `sub_agent` passes structured parent context: analyst, active artifact, bound dataset, current plan, and task label.
  - [x] Child runs can inherit or reference relevant transcript slices without copying the full thread blindly.
  - [x] Delegation logs show what context was forwarded.

### A3. Analyst workflow compliance is only enforced in external evals
- Severity: `P1`
- Status: `done`
- Evidence:
  - [src/analysts.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analysts.ts:23)
  - [src/analyst-skills.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-skills.ts:127)
  - [src/agent.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/agent.ts:198)
  - [src/analyst-policy.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-policy.ts)
- Problem:
  - Live parity scripts check stage/header discipline.
  - Normal interactive runs do not.
- Acceptance criteria:
  - [x] Normal agent runs can validate required response sections for decision-grade tasks.
  - [x] Missing required sections can trigger one corrective retry before finalizing.
  - [x] The user can see when a response was repaired for structure.

### A4. OpenCode Go tool recovery still aborts too early under repeated ambiguity
- Severity: `P2`
- Status: `done`
- Evidence:
  - [src/openfinances-go.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/openfinances-go.ts:388)
- Problem:
  - Recoverable tool-error batches used to abort too quickly and without enough diagnostic shape.
- Acceptance criteria:
  - [x] Recovery path distinguishes transient tool noise from true schema misuse.
  - [x] The run can survive more than one repair cycle when progress is still being made.
  - [x] Abort messages include the failing tools and last recovery hints.

### A5. Slash command nesting is hardcoded, not command-tree driven
- Severity: `P2`
- Status: `done`
- Evidence:
  - [src/commands.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/commands.ts:57)
  - [src/commands.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/commands.ts:1077)
  - [src/cli.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/cli.ts:89)
- Problem:
  - Nested slash branches were maintained in a separate suggestion list.
  - The completer path had bespoke branching.
- Acceptance criteria:
  - [x] Slash navigation is derived from a single command tree.
  - [x] Adding a nested command does not require updating multiple hardcoded structures.
  - [x] The fullscreen overlay and any completer logic consume the same command graph.

### A6. Fullscreen transcript is line-oriented rather than cell-oriented
- Severity: `P2`
- Status: `done`
- Evidence:
  - [src/fullscreen-ui.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/fullscreen-ui.ts:70)
  - [src/fullscreen-ui.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/fullscreen-ui.ts:272)
  - [src/fullscreen-ui.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/fullscreen-ui.ts:355)
- Problem:
  - Transcript rendering is flattened text plus a live assistant string.
  - Codex uses committed history cells plus an in-flight active cell.
- Acceptance criteria:
  - [x] Transcript entries become structured cells with stable identity.
  - [x] In-flight tool/activity state can update in place without rewriting the whole viewport.
  - [x] Overlay/transcript views can share the same active live tail.

### A7. Skill integration is loaded from files but not executed as structured stages
- Severity: `P3`
- Status: `done`
- Evidence:
  - [src/analyst-skills.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-skills.ts:42)
  - [src/analyst-skills.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/analyst-skills.ts:127)
  - [src/agent.ts](/Users/priyeshsrivastava/financial-analyst-tui/src/agent.ts)
  - [scripts/live-usecase-parity.ts](/Users/priyeshsrivastava/financial-analyst-tui/scripts/live-usecase-parity.ts)
- Problem:
  - `SKILL.md` is the workflow source of truth.
  - But runtime behavior still treats the body as unstructured prompt text.
- Acceptance criteria:
  - [x] At least the core stage headings of a skill are parsed into a structured runtime representation.
  - [x] The runtime can track whether expected skill stages were visited.
  - [x] Eval reports can attribute failures to a missing skill stage instead of only missing output text.

## Implementation Order

Recommended order:

1. Keep expanding long-horizon eval coverage rather than adding new prompt-only policy text

## Interpretation

### What is already good enough
- Skill files are real and loaded at runtime.
- The live parity harness is materially stronger than before.
- Tool schemas are far more uniform than they were in earlier versions.
- The fullscreen TUI is functional and audit-friendly enough for current operator work.

### What is still fundamentally behind Codex
- Delegation depth and continuity
- Runtime-native workflow enforcement
- Interactive transcript/state architecture
- Long-horizon recovery under tool ambiguity

### What this batch closed
- `A2` is now effectively closed:
  - subagents inherit structured parent context,
  - recent transcript slices,
  - copied plan state,
  - and delegation logs now show forwarded context.
- `A1` is now closed:
  - analyst-specific runtime policies shape tool ordering,
  - tool availability,
  - and response-contract enforcement.
- `A3` is now closed:
  - normal runs can repair one structurally incomplete answer automatically,
  - and the fullscreen transcript shows that a structural repair occurred.
- `A5` is now closed:
  - nested slash navigation is generated from command metadata,
  - and the completer/overlay both consume the same command tree.
- `A6` is now closed:
  - transcript cells have stable identity,
  - in-flight tool and assistant activity update in place,
  - and the active assistant tail now lives inside the transcript model rather than in a side buffer.
- `A4` is now closed:
  - recoverable loops distinguish schema misuse from transient execution failures,
  - stricter failures stop sooner,
  - and transient failures get a longer leash with clearer abort diagnostics.
- `A7` is now closed:
  - skill files are parsed into structured stages,
  - normal runs emit visited/missing stage summaries,
  - fullscreen transcript shows the stage summary,
  - and the live parity harness fails on missing expected stages rather than only missing headers.

### What matters most for your usecases
For pricing/value-creation work, the biggest practical gap is not markdown skills or slash UX. It is this:
- can the agent stay on the right artifact/dataset/workflow path over a long turn,
- while delegating bounded work correctly,
- and return a decision-grade answer without drifting into generic tool use.

That is why the remaining work is mostly:
- broader long-horizon eval depth,
- more adversarial partial-context scenarios,
- and continued runtime discipline under ambiguity rather than another skills-format rewrite.
