Skip to main content

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"],
)

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): Validate and parse drafting output.
  • validate_preprocessor_output(raw_output): 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

  1. Run preprocess_heuristic(message).
  2. If a candidate exists, validate it with parse_preprocessor_output(...).
  3. If not valid, consider fallback drafting (e.g., LLM prompt).
  4. Always validate fallback output with parse_preprocessor_output(...).
  5. If validation yields a directive, pass it to context-compiler.
  6. 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.state directly.
  • Prefer abstaining over unsafe rewrites.
  • Output validation checks structure and canonical grammar only.
  • A structurally valid drafted directive may still be the wrong interpretation of the user's meaning.
  • Reviewed semantic drafting belongs in a separate higher-level workflow.

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 snapshot.

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 shown or 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.
  • Abstain when one message contains multiple directive-shaped instructions.
  • Do not mine surrounding prose for commands.
  • Do not split one message into multiple drafted directives.
  • Avoid broad semantic rewrites.
  • Prefer false negatives over false positives.

context-compiler-directive-drafter only proposes at most one candidate directive. context-compiler remains responsible for independently enforcing the single-directive invariant before any authoritative application.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

context_compiler_directive_drafter-0.1.2.tar.gz (77.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file context_compiler_directive_drafter-0.1.2.tar.gz.

File metadata

File hashes

Hashes for context_compiler_directive_drafter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 612b295e827f9019e1dab9ca16979bbaf948d6d7b52e11d4cb723ffe8a3675bb
MD5 35c6013fec899eba9d398c745eb2c319
BLAKE2b-256 8437da53095be377487fb24dae5d5bcefee3f3cb56e193f7e51f62c3f4ccd187

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_compiler_directive_drafter-0.1.2.tar.gz:

Publisher: publish-pypi.yml on rlippmann/context-compiler-directive-drafter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file context_compiler_directive_drafter-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for context_compiler_directive_drafter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 56ed34c01544e69ab660b0e9cfb5032800c1ccb9afea2ecc0d827476af9be7d4
MD5 d7e0b8691d0fdb6df32bdbbf099756e8
BLAKE2b-256 4aa15523810cbc5649bf047b27809186a9f89d9d74de7d1d5979410b57fce609

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_compiler_directive_drafter-0.1.2-py3-none-any.whl:

Publisher: publish-pypi.yml on rlippmann/context-compiler-directive-drafter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page