Draft candidate Context Compiler directives from natural-language input.
Project description
Context Compiler Directive Drafter
Turn natural-language requests into candidate Context Compiler directives.
context-compiler-directive-drafter helps hosts translate user requests like:
Please use Docker for container examples.
into candidate directives, such as:
use docker
This package drafts suggestions for the Context Compiler. Only context-compiler applies directives and updates state.
The drafter suggests candidate directives. context-compiler decides what to do with them.
When To Use It
Use this package when you want to:
- Translate user requests into safe, canonical directives.
- Avoid accidental or unsafe state changes from ambiguous input.
- Add a conservative natural-language-to-directive step before applying changes.
Installation
Install in your host environment:
pip install "context-compiler-directive-drafter"
For local development:
uv sync --group dev
Basic Usage
Draft and validate a candidate directive:
from context_compiler_directive_drafter import preprocess_heuristic, parse_preprocessor_output
user_message = "Please use Docker for container examples."
result = preprocess_heuristic(user_message)
candidate = parse_preprocessor_output(
result["directive"],
source_input=user_message,
)
if candidate is not None:
print("Candidate directive:", candidate)
else:
print("No canonical directive found.")
The host validates drafted output before passing it to engine.step(...).
For small runnable examples, see examples/basic_usage.py and examples/prompt_rendering.py.
Public API
Public interface:
preprocess_heuristic(message): Heuristically draft a candidate directive.parse_preprocessor_output(raw_output, *, source_input=None): Validate and parse drafting output.validate_preprocessor_output(raw_output, *, source_input=None): Classify raw output as directive, no_directive, or unknown.render_prompt(path, state): Load and fill prompt templates.- Constants and sentinels exported from the package.
Recommended Host Flow
- Run
preprocess_heuristic(message). - If a candidate exists, validate it with
parse_preprocessor_output(...). - If not valid, consider fallback drafting (e.g., LLM prompt).
- Always validate fallback output with
parse_preprocessor_output(..., source_input=message). - If validation yields a directive, pass it to
context-compiler. - Otherwise, pass the original user input unchanged.
Safety Guidance:
- Always validate drafting output before compiler handoff.
- Never pass raw model output directly to the compiler.
- Bypass drafting when clarification is pending.
- Do not edit
engine.statedirectly. - Prefer abstaining over unsafe rewrites.
Do not pass raw model output to the compiler.
Prompt Resources
The package includes prompt templates for integrations that use model-based drafting when heuristic drafting does not produce a result.
- prompts/default.txt: recommended default prompt
- prompts/llama.txt: stricter prompt for Llama-family models
Use render_prompt(path, state) to load a template and fill it with the current compiler state.
The rendered prompt can be sent to an LLM to attempt directive drafting when heuristic drafting does not produce a result.
Any model output should still be validated with parse_preprocessor_output(...) or validate_preprocessor_output(...) before it is used.
Current Limits
This package is intentionally conservative. It abstains when input is:
- Ambiguous, mixed-intent, or quoted.
- Embedded in prose, markdown, or code.
- Not matching a canonical directive form.
Boundary rules:
- Process the full message, not fragments.
- Emit at most one canonical directive.
- Do not mine surrounding prose for commands.
- Do not split multi-instruction input.
- Avoid broad semantic rewrites.
- Prefer false negatives over false positives.
Hosts that want broader proposal behavior should implement it explicitly.
CLI
The CLI command is directive-drafter. The CLI currently supports a limited set of behaviors:
uv run directive-drafter "please make replies concise"
It returns a non-zero exit status and explains that a broader natural-language drafting workflow is not yet exposed as a user-facing CLI command.
Development
Run local checks:
uv run pre-commit run --all-files
uv run pytest
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file context_compiler_directive_drafter-0.1.1.tar.gz.
File metadata
- Download URL: context_compiler_directive_drafter-0.1.1.tar.gz
- Upload date:
- Size: 77.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96fc74056a4b78e4127edff36e5364573820b236228a23df87e4613d94c760cb
|
|
| MD5 |
ea7e7f9fbeae620430bfe860687d8430
|
|
| BLAKE2b-256 |
f6b266d644e7f6a7e3dedb584ffed1fd242c2134b8b9b2d76c57a7b44553601c
|
Provenance
The following attestation bundles were made for context_compiler_directive_drafter-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on rlippmann/context-compiler-directive-drafter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
context_compiler_directive_drafter-0.1.1.tar.gz -
Subject digest:
96fc74056a4b78e4127edff36e5364573820b236228a23df87e4613d94c760cb - Sigstore transparency entry: 1923084041
- Sigstore integration time:
-
Permalink:
rlippmann/context-compiler-directive-drafter@7d5936b37962226ec1854f83caf2c907706863b4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/rlippmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7d5936b37962226ec1854f83caf2c907706863b4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file context_compiler_directive_drafter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: context_compiler_directive_drafter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96f2e26cbb54e7778e33d26dcf05689ed428d3a00079078f6212b8c75ac39ebe
|
|
| MD5 |
238b4337a294fd66707579bf26ffccbd
|
|
| BLAKE2b-256 |
643b3a40cdde1cd68afcd8301e37c7e9960b4fb43c31a97746298f80f4af2c30
|
Provenance
The following attestation bundles were made for context_compiler_directive_drafter-0.1.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on rlippmann/context-compiler-directive-drafter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
context_compiler_directive_drafter-0.1.1-py3-none-any.whl -
Subject digest:
96f2e26cbb54e7778e33d26dcf05689ed428d3a00079078f6212b8c75ac39ebe - Sigstore transparency entry: 1923084181
- Sigstore integration time:
-
Permalink:
rlippmann/context-compiler-directive-drafter@7d5936b37962226ec1854f83caf2c907706863b4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/rlippmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7d5936b37962226ec1854f83caf2c907706863b4 -
Trigger Event:
release
-
Statement type: