11# Context Compiler Directive Drafter
22
3- Draft candidate Context Compiler directives from natural-language input.
3+ Directive Drafter turns user input into non-authoritative candidate directives
4+ for host review. It combines deterministic heuristic drafting with an optional
5+ fallback acquisition step for input the heuristic path cannot interpret
6+ confidently.
47
5- For example, the drafter can turn:
6-
7- > Please use Docker for container examples.
8-
9- into the candidate directive:
10-
11- > use docker
12-
13- Drafts are non-authoritative. ` context-compiler ` remains responsible for
14- grammar validity, policy decisions, application, and authoritative state.
8+ The Drafter proposes. Context Compiler remains authoritative for grammar,
9+ policy decisions, application, and state.
1510
1611## Installation
1712
@@ -27,103 +22,73 @@ uv sync --group dev
2722
2823## Basic usage
2924
25+ This Python example uses the deterministic heuristic path:
26+
3027``` python
28+ from context_compiler import Engine
29+ from context_compiler.grammar import CanonicalDirective
30+
3131from context_compiler_directive_drafter import (
3232 DirectiveDrafter,
3333 RejectedDirective,
3434 UnknownDirective,
3535)
3636
37- result = DirectiveDrafter().draft_directive(
38- " Please use Docker for container examples. "
39- )
37+ drafter = DirectiveDrafter()
38+ engine = Engine()
39+ result = drafter.draft_directive( " I prefer concise replies " )
4040
41- if hasattr (result.result, " text" ):
42- print (" Candidate directive:" , result.result.text)
41+ if isinstance (result.result, CanonicalDirective):
42+ print (" Candidate directive:" , result.result.text) # use concise replies
43+ if input (" Confirm and apply this directive? [y/N] " ).lower() == " y" :
44+ decision = engine.apply_directive(result.result)
45+ print (" Compiler decision:" , decision)
4346elif isinstance (result.result, RejectedDirective):
4447 print (" Directive acquisition rejected:" , result.result.reason)
4548elif isinstance (result.result, UnknownDirective):
46- print (" Need clarification:" , result.result.reason)
47- ```
48-
49- ` DraftResult.result ` is one of three high-level outcomes:
50-
51- - ` CanonicalDirective ` : a proposed directive for host review;
52- - ` RejectedDirective ` : terminal acquisition rejection that is not sent to fallback;
53- - ` UnknownDirective ` : semantic uncertainty eligible for optional fallback acquisition.
54-
55- The ` source ` field identifies the final producer, such as ` heuristic ` or a
56- configured fallback source. It does not represent compiler approval or applied
57- state. For a runnable example, see [ examples/basic_usage.py] ( examples/basic_usage.py ) .
58-
59- ## Fallback integrations
60-
61- The drafter always tries heuristic drafting first. Configure a fallback when
62- the host wants provider-backed interpretation of ` UnknownDirective ` results.
63- Fallback callbacks receive the original input and return candidate directive
64- text or ` None ` .
65-
66- ### OpenAI-compatible providers
67-
68- ``` bash
69- pip install " context-compiler-directive-drafter[openai]"
49+ print (" Need clarification or optional fallback:" , result.result.reason)
7050```
7151
72- ``` python
73- import os
52+ ` DraftResult.result ` has one of three high-level forms:
7453
75- from context_compiler_directive_drafter import DirectiveDrafter
76- from context_compiler_directive_drafter.fallbacks.openai import create_openai_fallback
54+ - ` CanonicalDirective ` : a candidate directive for host review;
55+ - ` RejectedDirective ` : a terminal acquisition rejection;
56+ - ` UnknownDirective ` : semantic uncertainty that may be sent to an optional
57+ fallback.
7758
78- fallback = create_openai_fallback(
79- model = " gpt-4o-mini" ,
80- api_key = os.environ[" OPENAI_API_KEY" ],
81- )
82- drafter = DirectiveDrafter(fallback = fallback, fallback_source = " openai" )
83- ```
59+ The ` source ` field identifies the producer of the final drafting result. It does
60+ not represent compiler approval, applied state, or authoritative state.
8461
85- Use ` create_async_openai_fallback(...) ` with
86- ` DirectiveDrafter(async_fallback=...) ` and ` async_draft_directive(...) ` for an
87- asynchronous host path. OpenAI-compatible endpoints can provide a custom
88- ` base_url ` .
62+ ## Optional fallbacks
8963
90- ### LiteLLM
64+ Fallbacks are optional acquisition integrations for ` UnknownDirective ` results.
65+ They receive the original input and may propose candidate directive text for
66+ the host to review. For example, a fallback may interpret:
9167
92- ``` bash
93- pip install " context-compiler-directive-drafter[litellm]"
94- ```
95-
96- ``` python
97- from context_compiler_directive_drafter.fallbacks.litellm import create_litellm_fallback
68+ > The intended audience is senior management
9869
99- fallback = create_litellm_fallback(model = " anthropic/claude-sonnet-4-5" )
100- ```
70+ as:
10171
102- Pass LiteLLM's provider/model identifier unchanged. For native integrations,
103- the [ ` fallbacks ` namespace] ( src/context_compiler_directive_drafter/fallbacks/__init__.py )
104- provides provider-neutral callback types, fallback profiles, structured-response
105- parsing, and invalid-response errors.
72+ > ` set premise intended audience is senior management `
10673
107- Provider adapters handle provider response formats. The Drafter uses Core
108- grammar parsing and validation for returned candidate text and constructs the
109- non-authoritative result.
74+ The premise interpretation depends on optional fallback acquisition; it is not
75+ claimed as deterministic heuristic behavior. Available fallback integrations
76+ depend on the implementation. See the [ Python fallback integrations] ( docs/PythonFallbacks.md )
77+ document for provider-specific setup.
11078
11179## Authority boundary
11280
113- The Drafter proposes; the Context Compiler decides and applies. Hosts should
114- review or confirm a ` CanonicalDirective ` before handing it to Core. Never pass
115- raw provider output directly to the compiler, and do not use the Drafter to
116- read or mutate authoritative compiler state.
117-
118- The drafter's acquisition rules, including rejection, uncertainty, bounded
119- rewrites, and other input-boundary behavior, are specified in
120- [ DrafterAcquisitionSpec.md] ( docs/DrafterAcquisitionSpec.md ) .
81+ Hosts decide whether to confirm a proposed ` CanonicalDirective ` . Only after
82+ confirmation should a host hand it to Context Compiler through
83+ ` engine.apply_directive(...) ` . Do not pass raw fallback output directly to the
84+ compiler, and do not use the Drafter to read or mutate authoritative compiler
85+ state.
12186
12287## Further documentation
12388
12489- [ Acquisition specification] ( docs/DrafterAcquisitionSpec.md )
90+ - [ Python fallback integrations] ( docs/PythonFallbacks.md )
12591- [ Contributor guidance] ( CONTRIBUTING.md )
126- - [ English evaluation data and review workflow] ( docs/EnglishEvaluationCorpus.md )
12792
12893## Development
12994
@@ -132,10 +97,6 @@ uv run pre-commit run --all-files
13297uv run pytest
13398```
13499
135- The shared compatibility fixtures under ` tests/fixtures/ ` are the executable
136- authority for portable behavior; detailed fixture and evaluation material is
137- kept out of this entry-point document.
138-
139100## License
140101
141102Apache-2.0
0 commit comments