plateprocess.dev · PLATE release v0.12.0

Contemplation Engine V2 Contract Enumeration

Research: Contemplation Engine v2 Contract Enumeration + Gaps vs v1 + answer_signal Options + Phased Core Implementation Recommendations

Research Question

For Epic #257 (Contemplation Engine v2) and resolving Question #326: Enumerate the full contract from Design #143 (and docs/design/contemplation-engine-contract.md) versus the current v1 minimal implementation in src/plate_core/contemplation.py (and integration in mcp_server.py, curiosity_tools.py, agent_guidance.py, plate.agent.md). Resolve the open question in #326 on machine-readable answer_signal representation. Produce recommendations for the phased v2.1 scope (core engine + close + basic creation first, per interactive planning resolutions on #257). Identify gaps in transcript/provenance, signal eval, child creation, artifact mutation (PR-only), strict close (with citations + USAGE REPORT), revisions, blocking/resumption (#147/#148), tests, and encoding in guidance/catalog.

Sources

Primary sources reviewed for this research:

Findings

1. Design #143 Contract vs. v1 Implementation — Side-by-Side Mapping

The formal contract from Design #143 (docs/design/contemplation-engine-contract.md) specifies a 5-step sequence. Below is the mapping to current v1 code behavior:

Contract Step (Design #143) Required Behavior v1 Implementation Status (contemplation.py) Gap Analysis
1. Full transcript append (non-destructive) Post structured comment on Question with: original question verbatim, verbatim user answer, timestamp + session/provenance (agent login, MCP/CLI context, git commit), link to prior revision comment. Use provenance schema from Design #142. Partial. Lines 62-101: Creates PLATE-CONTEMPLATION block with timestamp, source, session, answered_by, answer excerpt (180 chars), actions list, close_signal_met flag. Does NOT capture: original question verbatim, full answer (only 180-char excerpt), revision_of links, git commit hash, Design #142 provenance schema fields (question_id, session_id UUID, author with @ prefix, revision_of databaseId). Missing: Full answer text (truncated at 180 chars), original question verbatim, revision_of linking, full Design #142 provenance JSON schema, git commit provenance.
2. Create forward-progress artifacts Parse answer against Question's documented answer_signal. If gaps/requirements identified: create appropriately labeled child issues (Feature/Research/Design/Question) with Closes or reference back. For process-impacting answers: directly prepare updates to AGENTS.md, .agentic/skills.yml, SPEC.md, CURRENT.md, wiki sources, docs/ via atomic PRs (never direct push). Update Epic #139 PLATE_SESSION_STATE. For research/design: commit to docs/research/ or docs/design/. Heuristic only. Lines 73-91: Simple keyword heuristics ("risk", "unknown", "create", "implement", "add" in answer text OR len > 80) create a generic [Feature]: Follow-up from answer to Question #N issue with 300-char excerpt. No signal parsing from Question body. No typed child creation (always Feature). No artifact mutations (AGENTS.md, fragments, SPEC, wiki, docs). No PLATE_SESSION_STATE updates. No research/design commit logic. Missing: answer_signal parsing from Question body. Deterministic child type selection (Feature/Research/Design/Question). Artifact mutation preparation (AGENTS.md, fragments, SPEC, wiki, docs) via PR creation. PLATE_SESSION_STATE updates. Research/design artifact commits. Evidence-based (not keyword-based) forward progress.
3. Revision/re-answer handling Always append (never mutate prior comments). Re-evaluate full history + new input; may close stale follow-on issues and/or spawn corrected ones. Preserve full chain for audit. Not implemented. No revision detection. No revision_of linking. No re-evaluation of prior answers. No stale issue closure. Missing: Entire revision/correction workflow. Detection of revised answers, revision_of links, history replay, stale issue management.
4. Closure decision Close Question if and only if answer_signal criteria verifiably met by accumulated transcript evidence (agent can cite specific answer excerpts; human confirmation for high-risk). On closure, include required === USAGE REPORT === block per AGENTS.md. Heuristic only. Lines 93-97: Simple keyword detection ("done", "complete", "resolved", "shipped"). Comment says "In real #149 this would fetch Question body and check against its answer_signal". No signal parsing. No citation of excerpts. No USAGE REPORT block emission. Missing: Real signal evaluation from Question body. Criteria verification with citations. USAGE REPORT block (required per AGENTS.md lines 141-149). Human confirmation path for high-risk. Evidence-based (not keyword-based) closure.
5. Persona and guidance updates Contract encoded in: AGENTS.md Question handling loop and babysit sections; plugin/agents/plate.agent.md; baseline agent catalog entries for Curiosity/Q&A; plate_plan_epic extensions for Q&A session state. Partial. QANDA_CURIOSITY_GUIDANCE in agent_guidance.py (lines 58-122) documents blocking pattern and resumption. plate.agent.md (lines 20-26) references MCP tools and native TUI preference. AGENTS.md (lines 91-99) has Question work loop stub. Baseline catalog not yet updated with Contemplation skills. plate_plan_epic (#257 note) defers to "host agent's chat or gh plate qanda". Missing: Explicit contract steps in AGENTS.md Question loop. Baseline catalog entries for run-qanda-session, contemplate-answer, create-blocking-question, resume-from-answered-question skills. Full contract encoding in plate_plan_epic integration.

Summary: v1 is a ~20% implementation of the Design #143 contract. Major gaps: signal parsing, artifact mutations, revision handling, strict evidence-based close with USAGE REPORT, contract encoding in guidance/catalog.

2. Full Inventory of `answer_signal` Options (Resolution of #326)

Question #326 asked: "What machine-readable answer_signal representation should Contemplation Engine v2 evaluate for strict closure?"

Prior answers on #326 (referenced in #257 Q&A Resolution + #326 body):

Current question.yml format (.github/ISSUE_TEMPLATE/question.yml lines 26-32):

- type: textarea
  id: answer_signal
  attributes:
    label: Answer signal
    description: How will we know this question is answered?
    placeholder: "A documented recommendation in docs/research/question-agent-packaging.md and follow-up implementation issue(s)."
  validations:
    required: true

This is free-text in the template, but the placeholder and prior usage suggest structured criteria.

Options evaluated:

Format Example Pros Cons Parseability Human Editability Agent Eval Complexity
Checklist (Markdown) - [ ] Recommendation cites X\n- [ ] Artifact committed to Y\n- [ ] Follow-up issues created Native GitHub rendering, familiar UX, explicit item-by-item tracking Requires Markdown parsing, checkbox state not machine-readable from issue body (need comment scan for checked state), ambiguous completion (partial checks?) Medium (regex for - [x] patterns) High (standard Markdown) Medium (pattern match + count checked vs total)
YAML block in issue body \``yaml\nanswer_signal:\n - condition: "artifact_committed"\n target: "docs/research/X.md"\n - condition: "follow_up_created"\n```` Structured, easy to parse, extensible Requires code block in issue body, less human-friendly for quick edits, not idiomatic GitHub High (YAML parser) Medium (code block editing) Low (direct field access)
JSON in hidden comment <!-- plate-answer-signal {"criteria": [...]} --> Machine-first, clean separation from human text Hidden from humans, poor discoverability/editability, violates "GitHub as UI" principle High (JSON parser) Low (hidden HTML comment) Low (direct field access)
Structured natural language with keywords "Answered when: (1) recommendation in docs/research/X.md AND (2) follow-up Feature created" Human-readable, no special syntax Requires NLP/LLM for parsing, ambiguous, brittle to phrasing changes, high token cost for eval Low (needs LLM) High (natural text) High (LLM-based inference per answer)
Checklist in question.yml + explicit eval contract Markdown checklist in answer_signal field + Design #143 contract defines eval: parse body for - [ ] items, contemplate checks each item against answer + created artifacts, close only when all checked or verifiable Balances GitHub-native UX + parseability; explicit contract for eval logic; extensible (can add typed criteria later) Still requires regex parsing + heuristic/LLM per item; partial ambiguity on what "verifiable" means per item Medium-High (regex + heuristic or light LLM per item) High (standard Markdown + familiar checkbox UX) Medium (structured parse + per-item verification; explicit contract reduces ambiguity)

Recommendation (resolves #326):

Use Markdown checklist in question.yml answer_signal field + explicit evaluation contract in Design #143 and Contemplation Engine.

Rationale:

Examples of well-formed answer_signal checklists:

## Answer signal

- [ ] Recommendation documented in `docs/research/contemplation-engine-v2-contract-enumeration.md` with side-by-side mapping and gap analysis.
- [ ] Machine-readable `answer_signal` format recommendation provided (resolves #326).
- [ ] Phased v2.1 scope recommendations with file-level handoff to Feature child.
- [ ] Test strategy outline included.
## Answer signal

- [ ] Analysis of stack options (TypeScript, Go, Python) committed to `docs/research/stack-selection.md`.
- [ ] Decision recorded with rationale and tradeoffs.
- [ ] Follow-up Feature issue created for migration (if stack changes).

Evaluation contract for Contemplation Engine v2:

On plate_record_answer + plate_contemplate (or trigger_contemplation):

  1. Fetch Question body via GitHub API.
  2. Extract answer_signal section (Markdown heading ## Answer signal or similar).
  3. Parse Markdown checklist items (regex: ^- \[ \] (.+)$ for unchecked, ^- \[x\] (.+)$ for checked).
  4. For each item, evaluate against:
    • Answer text (keyword/pattern match for explicit references).
    • Created artifacts (git tree lookup for file paths mentioned).
    • Created issues (contemplation log created_issues or GitHub search for linked issues).
    • Agent actions (contemplation log actions list).
  5. Strict close decision: Close Question if and only if:
    • All checklist items are verifiable as met (either explicitly checked in a revision comment or agent can cite evidence), OR
    • Human explicitly checks all items in a revision comment (append-only).
  6. On close: Emit === USAGE REPORT === block per AGENTS.md (lines 141-149).
  7. Citation requirement: Contemplation log or close comment must cite specific answer excerpts or artifact links proving each criterion met.

This resolves #326. The recommendation (checklist-style + #143 contract + guidance enforcement) matches the accepted answer in #326 and #257 planning.

3. Gap Analysis: v1 → v2 Contract

Detailed gaps identified from side-by-side mapping (§1) and contract requirements:

3.1 Full Non-Destructive Transcript + Provenance

Gap: v1 truncates answer at 180 chars (contemplation.py:70), omits original question verbatim, lacks revision_of links, missing git commit hash, doesn't follow Design #142 provenance JSON schema.

Required for v2:

Files to touch: contemplation.py (ContemplationEngine.contemplate method, lines 38-162), curiosity_tools.py (RecordAnswerTool, lines 174-232).

3.2 Typed Child Creation with Back-References

Gap: v1 always creates Feature issues (contemplation.py:76-91), no typed selection (Research/Design/Question), no back-references beyond title mention.

Required for v2:

Files to touch: contemplation.py (issue creation logic, lines 73-91).

3.3 PR-Based Mutations to Process Artifacts (AGENTS.md / fragments / SPEC / wiki / docs)

Gap: v1 has no artifact mutation logic (contemplation.py:118 comment: "Future: direct resource updates").

Required for v2:

Phased v2.1 scope (per #257 planning): Defer full mutation PR creation to v2.2+. In v2.1: log mutation intent (e.g., "Answer suggests updating AGENTS.md §Question loop; create follow-up Feature for process update"). Optionally: basic doc commits (research findings to docs/research/) as proof-of-concept.

Files to touch (v2.2+): contemplation.py (new mutation detection + PR creation via github_client), github_client.py (PR creation helpers).

3.4 Strict Evidence-Based Close Only on Verified Signal (Citations Required)

Gap: v1 uses keyword heuristics (contemplation.py:93-97), no signal parsing, no citations, no USAGE REPORT block.

Required for v2:

Files to touch: contemplation.py (signal parsing + eval logic, lines 93-101; close comment emission), curiosity_tools.py (RecordAnswerTool may trigger close via contemplation).

3.5 Append-Only Revisions (`revision_of`)

Gap: v1 has no revision handling.

Required for v2:

Files to touch: curiosity_tools.py (RecordAnswerTool: add revision_of param + field, lines 174-232), contemplation.py (history fetch + replay logic).

3.6 Full Blocking Paths + Unblock Reports + Merge Context

Gap: v1 has partial blocking support (contemplation.py:120-150), detects PLATE-BLOCKING-DUMP marker, posts unblock report, but no structured merge or child creation from blocking answer.

Required for v2 (harden #147/#148):

Files to touch: contemplation.py (blocking detection + merge logic, lines 120-150), curiosity_tools.py (CreateBlockingQuestionTool: ensure provenance compliance).

3.7 Tests

Gap: No dedicated contemplation tests. tests/test_curiosity_answers.py exists (imports Answer model from #150/#258) but doesn't cover contemplation contract.

Required for v2:

Files to touch: tests/test_contemplation.py (new), tests/test_curiosity_answers.py (integration tests), tests/ fixtures (mock Question bodies with answer_signal checklists).

3.8 Encoding in Guidance and Catalog

Gap: Partial (QANDA_CURIOSITY_GUIDANCE exists but lacks v2 contract details; baseline catalog not updated).

Required for v2:

Files to touch: agent_guidance.py, plugin/agents/plate.agent.md, src/plate_core/data/baseline_catalog.yml, AGENTS.md.

4. Recommendations for Phased v2.1 Scope (Core Engine + Close + Basic Creation First)

Per #257 planning resolutions, v2.1 should prioritize core reliability over full artifact mutations. Below is the recommended phased scope:

Phase v2.1 (this Feature #343): Core Engine + Strict Close + Basic Creation + Tests + Dogfood

In scope:

  1. Signal parsing and evaluation:

    • Parse answer_signal section from Question body (Markdown checklist).
    • Evaluate each criterion against answer text, created artifacts (git tree lookups), created issues (contemplation log + GitHub search), agent actions.
    • Strict close decision: close only if all criteria verifiable (with citations).
    • Emit USAGE REPORT block on close (per AGENTS.md).
  2. Improved transcript and provenance:

    • Full answer text (no truncation).
    • Original question text verbatim.
    • Design #142 provenance fields (question_id, session_id, author, source, revision_of).
    • Git commit hash if available.
  3. Basic typed child creation:

    • Heuristic or light LLM-based type selection (Feature/Research/Design/Question) from answer content.
    • Back-references in child issue body (Relates to #<Question> or Closes #<Question>).
    • Contemplation log records type + number.
  4. Revision handling (append-only):

    • RecordAnswerTool accepts revision_of param.
    • Contemplation fetches full history, re-evaluates.
    • Logs revision detection.
  5. Harden blocking/resumption (#147/#148):

    • Verify CreateBlockingQuestionTool follows Design #142 provenance.
    • On answer to blocking Q: structured merge into original issue body (append "Unblocked Info" section), post unblock report, create follow-on issues if warranted.
    • Full bidirectional traceability.
  6. Tests:

    • Unit tests: tests/test_contemplation.py (signal parse, eval, close, revision, blocking).
    • Integration tests: tests/test_curiosity_answers.py (RecordAnswer → contemplate → assert).
    • Dogfood: Answer 1+ real Question in this repo using v2 engine.
  7. Core guidance and catalog updates:

    • Update agent_guidance.py QANDA_CURIOSITY_GUIDANCE with v2 contract (signal eval, strict close, revision, blocking).
    • Update plugin/agents/plate.agent.md with v2 steps.
    • Update baseline_catalog.yml with contemplate-answer, create-blocking-question, resume-from-answered-question skills.
    • Light AGENTS.md §Question update (or reference to guidance).
  8. Fragment:

    • .agentic/releases/unreleased/contemplation-engine-v2-core.json describing implemented behavior, verification (tests + dogfood), references to #257/#342/#326/#143/#139, guidance updates.

Out of scope (defer to v2.2+ or separate Features):

Rationale for phasing:

Phase v2.2+ (future Features): Full Artifact Mutations + Advanced Capabilities

Out-of-scope for v2.1, recommend for v2.2+:

5. Test Strategy Outline

5.1 Unit Tests (`tests/test_contemplation.py`)

Coverage:

Mocking strategy:

5.2 Integration Tests (`tests/test_curiosity_answers.py` or new `tests/integration/test_qanda_flow.py`)

Coverage:

Integration with real GitHub API (optional, slow tests):

5.3 Dogfood Scenarios (Manual Verification + Automated Smoke Tests)

Scenario 1: Simple Question with checklist answer_signal

Scenario 2: Research Question with artifact criterion

Scenario 3: Blocking Question answered

Scenario 4: Revised answer

Automated smoke tests:

5.4 Test Maintenance and Coverage Goals

6. Risks, Dependencies, and Integration Notes

6.1 Risks

Risk Impact Mitigation
Over-mutation of files without human review High (accidental corruption of AGENTS.md, SPEC, workflows) Phase v2.1: log mutation intent only, defer PR creation to v2.2+. Always respect need:human-review for high-risk changes.
Token cost of full history replay on large Questions Medium (cost spike for Questions with 10+ answers) Cache parsed history per session; only re-parse on new answer. Future: local docs/curiosity/ index for fast lookup.
Ambiguous criterion interpretation Medium (false positives/negatives on close decisions) Use explicit heuristics + pattern matching in v2.1. Defer complex LLM-based interpretation to v2.2+. Always cite evidence; human can override.
Breaking existing v1 callers (RecordAnswerTool, plate_contemplate) Medium (regression in Q&A flows) Maintain backward compat: v1 behavior if no answer_signal in Question body. Add feature flag or version param if needed.
Incomplete Design #142 provenance in existing Questions Low (historical data may lack provenance) Accept graceful degradation: v2 adds full provenance to new answers; old answers parse best-effort. Migration/backfill is separate Feature.

6.2 Dependencies

Dependency Status Impact on v2.1
Answer Model (#142/#150/#258) Partial (Design #142 exists; Feature #150/#258 in progress per SPEC) Medium: v2.1 can proceed with GitHub comment parsing; committed index (docs/curiosity/answers-index.json) is optional enhancement. If #258 lands during v2.1 dev, integrate for fast lookups.
Q&A surfaces (#145/#154) Complete (RecordAnswerTool, ListQuestionsTool, plate_contemplate MCP exist per curiosity_tools.py) Low: v2.1 builds on existing tools. No blockers.
Epic #139 invariants Complete (defined in docs/research/curiosity-qanda-inventory.md) Low: v2.1 satisfies invariants (no info loss, findability, revisability, forward progress).
Design #143 contract Complete (docs/design/contemplation-engine-contract.md) None: v2.1 implements this contract.
Baseline catalog format Complete (baseline_catalog.yml exists, used by cli.py/mcp_server.py) None: v2.1 adds skills to existing catalog.

6.3 Integration Notes

Integration with #139 invariants:

Integration with #282 What Next?:

Integration with plate_plan_epic (#257 note):

Integration with existing guidance (agent_guidance.py, plate.agent.md):

Integration with baseline catalog (baseline_catalog.yml):

7. Explicit Handoff to Feature Child (#343)

This Research closes with committed artifact (docs/research/contemplation-engine-v2-contract-enumeration.md) and explicit handoff to Feature #343 for implementation.

Build instructions for Feature #343:

  1. Files to touch (primary implementation):

    • src/plate_core/contemplation.py (ContemplationEngine class, lines 32-162):
      • Update contemplate() method: parse answer_signal from Question body, evaluate criteria, emit full transcript + provenance, typed child creation, revision handling, strict close with citations + USAGE REPORT.
    • src/plate_core/mcp/curiosity_tools.py (RecordAnswerTool, lines 174-232):
      • Add revision_of parameter (optional int, default None).
      • Update PLATE-ANSWER block to include Design #142 provenance fields.
    • src/plate_core/agent_guidance.py (QANDA_CURIOSITY_GUIDANCE, lines 58-122):
      • Add v2 contract details (signal eval, strict close, revision, blocking).
    • plugin/agents/plate.agent.md (lines 20-26):
      • Update with v2 contract steps.
    • src/plate_core/data/baseline_catalog.yml:
      • Add contemplate-answer, create-blocking-question, resume-from-answered-question skills.
    • AGENTS.md (§Question, lines 91-99):
      • Add v2 contract summary or reference to agent_guidance.py.
  2. Files to touch (tests):

    • tests/test_contemplation.py (new file):
      • Unit tests per §5.1 (signal parse, eval, close, revision, blocking, USAGE REPORT).
    • tests/test_curiosity_answers.py (existing):
      • Add integration tests per §5.2 (RecordAnswer → contemplate → assert).
    • tests/fixtures/questions/ (new directory):
      • Add sample Question bodies (YAML or Markdown) for test data.
  3. Files to touch (fragment):

    • .agentic/releases/unreleased/contemplation-engine-v2-core.json (new):
      • Schema: {feature_id, title, summary, behavior_changes, verification_evidence, breaking_changes, migration_notes, related_issues, files_changed}.
      • Content: Describe v2 signal eval, strict close, revisions, blocking, tests, dogfood. References: #257, #342, #326, #143, #139.
  4. Implementation order (suggested):

    • Phase 1: Signal parsing (fetch Question body, extract answer_signal, parse Markdown checklist). Unit tests for parsing.
    • Phase 2: Criterion evaluation (keyword/pattern match, artifact lookup, issue lookup). Unit tests for eval.
    • Phase 3: Strict close decision (all criteria met → close; emit USAGE REPORT). Unit tests for close logic.
    • Phase 4: Improved transcript + provenance (full answer, original question, revision_of). Update RecordAnswerTool.
    • Phase 5: Typed child creation (heuristic type selection). Unit tests for child creation.
    • Phase 6: Revision handling (history fetch, re-eval). Unit tests for revision.
    • Phase 7: Harden blocking/resumption (structured merge, follow-on issues). Unit tests for blocking.
    • Phase 8: Integration tests (RecordAnswer → contemplate end-to-end).
    • Phase 9: Dogfood (answer real Question in this repo, verify correct behavior).
    • Phase 10: Guidance + catalog updates (agent_guidance.py, plate.agent.md, baseline_catalog.yml, AGENTS.md).
    • Phase 11: Fragment (.agentic/releases/unreleased/contemplation-engine-v2-core.json).
    • Phase 12: PR (Documentation or Feature label, clean title, Closes #257, Closes #326, Closes #342, Closes #343 in body).
  5. Baseline expectations:

    • All prior tests pass (no regressions).
    • New tests achieve ≥80% coverage for contemplation.py.
    • At least 1 real Question dogfooded end-to-end with v2 engine.
    • Fragment committed, guidance updated, PR passes CI.
  6. Out of scope for #343 (defer to follow-ups):

    • Full PR-based artifact mutations (log intent only in v2.1).
    • Advanced LLM-based criterion interpretation.
    • Migration/backfill of historical Questions.
    • Projects v2 field integration.

This completes the Research handoff. Feature #343 has explicit build instructions, file-level targets, phased scope, and test expectations.

Recommendation

This research successfully enumerates the full Contemplation Engine v2 contract from Design #143, maps it against current v1 implementation (with detailed gap analysis), resolves Question #326 on answer_signal representation (recommendation: Markdown checklist in question.yml + explicit eval contract in #143 + guidance enforcement), and provides phased v2.1 scope recommendations prioritizing core engine reliability (signal eval, strict close, basic creation, revisions, blocking, tests, dogfood) over full artifact mutations (deferred to v2.2+).

Next steps per PLATE:

  1. This Research closes with Documentation PR including Closes #342, Closes #326 in body (also updates #257 references as needed).
  2. Feature #343 proceeds with implementation per handoff instructions above.
  3. Dogfood v2 engine on at least 1 real Question in this repo.
  4. Post summary comment on Epic #257 after Feature #343 closes (per human checkpoints).
  5. Update PLATE_SESSION_STATE on #257 with child status (Research complete, Feature in progress).

Resolution of #326: Accepted recommendation is Markdown checklist in .github/ISSUE_TEMPLATE/question.yml answer_signal field, evaluated per Design #143 contract (parse checklist, verify each criterion against answer + artifacts + issues + actions, close only if all met with citations), enforced in agent_guidance.py QANDA_CURIOSITY_GUIDANCE, plugin/agents/plate.agent.md, and baseline catalog skills. This balances GitHub-native UX, parseability, human editability, and explicit eval contract. Examples and detailed evaluation procedure provided in §2.

All findings, gaps, recommendations, test strategy, risks, dependencies, and handoff are documented above per PLATE Research artifact format (docs/research/README.md). This research satisfies Epic #257 and Question #326 requirements.