context-compiler 0.9.0.dev13__py3-none-any.whl → 0.9.0.dev15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -316,7 +316,10 @@ def _match_directive_token(
316
316
  token_index += 1
317
317
  continue
318
318
 
319
- if text[index].casefold() != token_char:
319
+ character = text[index]
320
+ if "A" <= character <= "Z":
321
+ character = chr(ord(character) + (ord("a") - ord("A")))
322
+ if character != token_char:
320
323
  return None
321
324
  index += 1
322
325
  token_index += 1
@@ -349,6 +352,18 @@ def _contains_multiple_canonical_directives(text: str) -> bool:
349
352
  return False
350
353
 
351
354
 
355
+ def _contains_multiple_premise_directives(text: str) -> bool:
356
+ """Report premise compounds without inspecting opaque premise payload text."""
357
+ first_start = _match_canonical_directive_start(text, 0)
358
+ if first_start is None:
359
+ return False
360
+
361
+ for index, character in enumerate(text[first_start:], start=first_start):
362
+ if character == "\n" and _match_canonical_directive_start(text, index + 1) is not None:
363
+ return True
364
+ return False
365
+
366
+
352
367
  def _starts_with_directive_family(text: str) -> bool:
353
368
  for token, require_space_or_end in _DIRECTIVE_FAMILY_STARTS:
354
369
  if (
@@ -457,7 +472,12 @@ def _validate_operand_constraints(kind: DirectiveKind, operands: Mapping[str, st
457
472
 
458
473
  def _validate_rendered_canonical_shape(kind: DirectiveKind, operands: Mapping[str, str]) -> None:
459
474
  rendered = _serialize_canonical_directive(kind, MappingProxyType(dict(operands)))
460
- if _contains_multiple_canonical_directives(rendered):
475
+ contains_compound = (
476
+ _contains_multiple_premise_directives(rendered)
477
+ if kind in {DirectiveKind.SET_PREMISE, DirectiveKind.CHANGE_PREMISE}
478
+ else _contains_multiple_canonical_directives(rendered)
479
+ )
480
+ if contains_compound:
461
481
  raise ValueError(f"Operands do not produce a canonical {kind.value} directive.")
462
482
 
463
483
 
@@ -476,7 +496,15 @@ def decompose_directive(text: str) -> CanonicalDirective | InvalidDirectiveSynta
476
496
  return None
477
497
  if not _starts_with_directive_family(trimmed_text):
478
498
  return None
479
- if _contains_multiple_canonical_directives(trimmed_text):
499
+ premise_directive = _match_directive_token(
500
+ trimmed_text, 0, _SET_PREMISE_START, require_space_or_end=True
501
+ ) or _match_directive_token(trimmed_text, 0, _CHANGE_PREMISE_START, require_space_or_end=True)
502
+ contains_compound = (
503
+ _contains_multiple_premise_directives(trimmed_text)
504
+ if premise_directive is not None
505
+ else _contains_multiple_canonical_directives(trimmed_text)
506
+ )
507
+ if contains_compound:
480
508
  return _invalid_directive_syntax(DirectiveSyntaxFailure.COMPOUND_DIRECTIVE)
481
509
 
482
510
  normalized = _normalized_for_matching(trimmed_text)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: context-compiler
3
- Version: 0.9.0.dev13
3
+ Version: 0.9.0.dev15
4
4
  Summary: Deterministic conversational state engine for LLM applications.
5
5
  Project-URL: Homepage, https://github.com/rlippmann/context-compiler
6
6
  Project-URL: Repository, https://github.com/rlippmann/context-compiler
@@ -25,6 +25,7 @@ Description-Content-Type: text/markdown
25
25
  [![PyPI version](https://img.shields.io/pypi/v/context-compiler)](https://pypi.org/project/context-compiler/)
26
26
  [![Python versions](https://img.shields.io/pypi/pyversions/context-compiler)](https://pypi.org/project/context-compiler/)
27
27
  [![License](https://img.shields.io/pypi/l/context-compiler)](https://pypi.org/project/context-compiler/)
28
+ [![codecov](https://codecov.io/gh/rlippmann/context-compiler/branch/main/graph/badge.svg)](https://codecov.io/gh/rlippmann/context-compiler)
28
29
 
29
30
  Context Compiler is a deterministic conversational state authority for LLM applications.
30
31
  It handles canonical directive execution, semantic validation, terminal error
@@ -95,7 +96,7 @@ set premise concise replies
95
96
  - Base model: silently accepts / rewrites
96
97
  - Context Compiler: applies a repeatable state update
97
98
 
98
- ### Single-directive grammar
99
+ ### Compound directive rejection
99
100
 
100
101
  ```text
101
102
  use docker and prohibit peanuts
@@ -113,7 +114,7 @@ use podman instead of docker
113
114
 
114
115
  - Without explicit state transition rules: behavior depends on host/model handling
115
116
  - Context Compiler: applies the deterministic resulting transition when
116
- `docker` is absent and `use podman` is otherwise valid; other semantic
117
+ `docker` is present and `use podman` is otherwise valid; other semantic
117
118
  conflicts may still error
118
119
 
119
120
  ### Lifecycle enforcement
@@ -272,6 +273,10 @@ uv sync --dev
272
273
  uv run pytest
273
274
  ```
274
275
 
276
+ CI enforces 100% coverage for the core `src/context_compiler` package. The
277
+ coverage badge represents that authoritative core-package target, not the
278
+ entire repository.
279
+
275
280
  ## Decision API
276
281
 
277
282
  Each user message produces one immutable `Decision` variant. Use concrete
@@ -480,7 +485,8 @@ User: reset policies
480
485
  User: clear state
481
486
  ```
482
487
 
483
- Grammar invariant: one input may contain at most one canonical directive.
488
+ Grammar invariant: a single input never applies more than one canonical
489
+ directive.
484
490
  Directive-shaped invalid input is outside the canonical language, and
485
491
  `error` is reserved for canonical directives that later fail semantic
486
492
  evaluation against authoritative state.
@@ -504,18 +510,25 @@ clear state
504
510
 
505
511
  Invalid:
506
512
  use docker and prohibit peanuts
507
- set premise vegetarian and use docker
508
513
  clear state then set premise new project
514
+
515
+ Premise payload (opaque):
516
+ set premise vegetarian and use docker
509
517
  ```
510
518
 
519
+ Policy compounds such as `use docker and prohibit peanuts` remain invalid;
520
+ premise `VALUE` is opaque and may contain directive-like words.
521
+
511
522
  Quote behavior follows the current grammar literally:
512
523
 
513
524
  ```text
514
- Passthrough:
525
+ Passthrough (`no_directive`):
515
526
  "use docker and prohibit peanuts"
516
527
 
517
- Invalid:
528
+ Invalid directive:
518
529
  use "docker and prohibit peanuts"
530
+
531
+ Canonical directive (`set premise`):
519
532
  set premise "use docker and prohibit peanuts"
520
533
  ```
521
534
 
@@ -2,11 +2,11 @@ context_compiler/__init__.py,sha256=v-MGOUi1gAoWDqB3N5b3dOqVQ-AQ8-a6R6N03ISWvO4,
2
2
  context_compiler/const.py,sha256=WeEGDXY8lepFghH9wko0hH51oxoZQBfDnFxSyeIaaWI,465
3
3
  context_compiler/decision.py,sha256=_z1ilbU0BrMofSpzEd0dn0ODiNhceCo-NRnsgjxURKE,3911
4
4
  context_compiler/engine.py,sha256=MjClRgsDcd34H7cgb3wGcYauZ1uKqOh-BsUXSZT-vmY,13465
5
- context_compiler/grammar.py,sha256=J1N8jy72rOJ79zYuhRUHvZFwcmPyoGY4RnfT0KvlwqQ,24490
5
+ context_compiler/grammar.py,sha256=R8GyZ_ExsUHI2WFFa6rgtsdjs4gbCs0cuEMMVC1Ba7I,25663
6
6
  context_compiler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  context_compiler/repl.py,sha256=blIrLafAJG_5yFxN62Nb34JGvB1F-c-BlOUq_8AjUE8,16006
8
- context_compiler-0.9.0.dev13.dist-info/METADATA,sha256=Og5fzi8wEPRXLGkimsieZ0oZXHjzd0sqxDjLcpJvqZQ,20141
9
- context_compiler-0.9.0.dev13.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
10
- context_compiler-0.9.0.dev13.dist-info/entry_points.txt,sha256=xnk4WE9zaC2NAMIF59WD3Y_45E8aA9KH-pZ4lqSzH-U,64
11
- context_compiler-0.9.0.dev13.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- context_compiler-0.9.0.dev13.dist-info/RECORD,,
8
+ context_compiler-0.9.0.dev15.dist-info/METADATA,sha256=mEOCZNOzuog6g6Dc54AcaZeXnlwlsLsIYclNp0QxhCE,20697
9
+ context_compiler-0.9.0.dev15.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
10
+ context_compiler-0.9.0.dev15.dist-info/entry_points.txt,sha256=xnk4WE9zaC2NAMIF59WD3Y_45E8aA9KH-pZ4lqSzH-U,64
11
+ context_compiler-0.9.0.dev15.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ context_compiler-0.9.0.dev15.dist-info/RECORD,,