---
phase: 138-knowledge-compilation-contract
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - research/knowledge-hub/knowledge_hub/l2_compiler.py
  - research/knowledge-hub/knowledge_hub/cli_l2_compiler_handler.py
  - research/knowledge-hub/knowledge_hub/aitp_service.py
  - research/knowledge-hub/tests/test_l2_backend_contracts.py
  - research/knowledge-hub/tests/test_aitp_cli.py
  - research/knowledge-hub/tests/test_aitp_cli_e2e.py
autonomous: true
requirements:
  - REQ-KCOMP-01
  - REQ-KCOMP-02
must_haves:
  truths:
    - the compiled-knowledge surface must stay non-authoritative
    - provenance and authority level must be explicit in the contract
    - the new surface must extend the existing `l2_compiler` family rather than replacing it
---

<objective>
Lock one explicit compiled-knowledge contract that extends the current `L2`
compiler helpers with added/updated/provisional/contradiction semantics while
preserving the existing `L4` promotion boundary.
</objective>

<context>
@.planning/phases/138-knowledge-compilation-contract/138-CONTEXT.md
@.planning/REQUIREMENTS.md
@research/knowledge-hub/knowledge_hub/l2_compiler.py
@research/knowledge-hub/knowledge_hub/cli_l2_compiler_handler.py
@research/knowledge-hub/canonical/L2_COMPILER_PROTOCOL.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add failing contract tests for compiled knowledge</name>
  <files>research/knowledge-hub/tests/test_l2_backend_contracts.py, research/knowledge-hub/tests/test_aitp_cli.py</files>
  <read_first>research/knowledge-hub/tests/test_l2_backend_contracts.py, research/knowledge-hub/tests/test_aitp_cli.py, research/knowledge-hub/knowledge_hub/l2_compiler.py</read_first>
  <action>Add red tests that require one production compiler command and one contract vocabulary for compiled knowledge, including added/updated/provisional/contradiction summaries and explicit provenance authority levels.</action>
  <verify>python -m pytest research/knowledge-hub/tests/test_l2_backend_contracts.py -q</verify>
  <acceptance_criteria>
    - tests fail before implementation
    - failures prove the new compiled-knowledge contract does not yet exist
  </acceptance_criteria>
  <done>A red contract exists for the first `999.37` slice.</done>
</task>

<task type="auto">
  <name>Task 2: Implement the compiled-knowledge contract in the compiler family</name>
  <files>research/knowledge-hub/knowledge_hub/l2_compiler.py, research/knowledge-hub/knowledge_hub/cli_l2_compiler_handler.py, research/knowledge-hub/knowledge_hub/aitp_service.py</files>
  <read_first>research/knowledge-hub/knowledge_hub/l2_compiler.py, research/knowledge-hub/knowledge_hub/cli_l2_compiler_handler.py, research/knowledge-hub/knowledge_hub/aitp_service.py</read_first>
  <action>Add one new compiler/service/CLI surface for compiled knowledge that materializes a bounded non-authoritative workspace knowledge report with change/provisional/contradiction summaries.</action>
  <verify>python -m pytest research/knowledge-hub/tests/test_l2_backend_contracts.py -q</verify>
  <acceptance_criteria>
    - one production compiler command exists
    - the payload includes provenance/authority labels and change summaries
    - the surface stays explicitly non-canonical
  </acceptance_criteria>
  <done>The first compiled-knowledge contract exists in production.</done>
</task>

<task type="auto">
  <name>Task 3: Add one bounded CLI acceptance path</name>
  <files>research/knowledge-hub/tests/test_aitp_cli_e2e.py</files>
  <read_first>research/knowledge-hub/tests/test_aitp_cli_e2e.py, research/knowledge-hub/knowledge_hub/l2_compiler.py</read_first>
  <action>Add one bounded CLI acceptance path that seeds the relevant workspace state and proves the compiled-knowledge surface materializes real artifacts.</action>
  <verify>python -m pytest research/knowledge-hub/tests/test_aitp_cli_e2e.py -q -k \"compile_l2\"</verify>
  <acceptance_criteria>
    - the CLI path writes real JSON and markdown artifacts
    - the acceptance path proves the new surface is not just a mocked parser unit
  </acceptance_criteria>
  <done>The contract is proven through one bounded runtime path.</done>
</task>

</tasks>
