Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Context Compiler helps applications keep explicit user instructions separate fro

The model writes responses. The compiler stores premise and policy rules.

This package is the TypeScript implementation of the Context Compiler engine, aligned with Python 0.7 API behavior.
This package is the TypeScript implementation of the Context Compiler engine, aligned with Python 0.7 behavior.

## What it does

Expand Down Expand Up @@ -45,12 +45,12 @@ Directive examples:
- checkpoint restore
- experimental preprocessor behavior
- public API behavior
- Core public API for engine usage and transcript compilation.
- Core public API for engine usage and transcript replay.
- Checkpoint APIs for saving and restoring rules plus pending clarification state.
- Controller APIs for step envelopes, preview/dry-run, and structural state diffs.
- Decision constants exported for host-side checks.
- Decision constants for host-side checks.
- Experimental preprocessor module exposed through a package subpath import.
- Fixture parity aligned to the Python 0.7.3 fixture snapshot.
- Fixture parity aligned with the Python 0.7.3 fixture snapshot.

## Not Included Yet

Expand All @@ -73,7 +73,7 @@ npm install @rlippmann/context-compiler
## Quick Start

```ts
import { createEngine, get_clarify_prompt, is_clarify, is_update } from '@rlippmann/context-compiler';
import { createEngine, get_clarify_prompt, is_clarify, is_passthrough, is_update } from '@rlippmann/context-compiler';

const engine = createEngine();
const decision = engine.step('set premise concise replies');
Expand All @@ -83,7 +83,7 @@ if (is_update(decision)) {
console.log(engine.state);
} else if (is_clarify(decision)) {
console.log(get_clarify_prompt(decision));
} else {
} else if (is_passthrough(decision)) {
// passthrough
}
```
Expand All @@ -95,7 +95,7 @@ if (is_update(decision)) {
- `engine.state` -> current stored premise/policy rules snapshot.
- `engine.has_pending_clarification()` -> check whether confirmation-only input is currently required.
- `engine.exportJson()` / `engine.importJson(payload)` -> state serialization utilities.
- `engine.exportCheckpoint()` / `engine.importCheckpoint(payload)` -> checkpoint persistence (`authoritative_state` + pending confirmation state) for safe resume.
- `engine.exportCheckpoint()` / `engine.importCheckpoint(payload)` -> checkpoint persistence (`authoritative_state` + pending confirmation state) that safely resumes pending confirmations.
- `engine.exportCheckpointJson()` / `engine.importCheckpointJson(payload)` -> JSON checkpoint wrapper persistence helpers.
- `compile_transcript(messages)` -> replay user messages and return `state` or `confirm`.
- `engine.apply_transcript(messages)` -> replay user messages onto an existing engine instance.
Expand Down
8 changes: 4 additions & 4 deletions demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

These scripts show side-by-side LLM outcomes with and without stored compiler rules, aligned with the [Python reference demos](https://github.com/rlippmann/context-compiler/blob/main/demos/README.md).

Scored demos compare three host flows:
Scored demos compare three host-side flows:
- baseline
- compiler path (full transcript + injected stored rules/state)
- compiler+compact (compacted transcript + injected stored rules/state)
- compiler path (full transcript + injected stored rules and state)
- compiler+compact (compacted transcript + injected stored rules and state)

Demo 06 is informational (context/prompt compaction metrics), not scored.

## Result variability note

LLM demo outcomes can vary across environments. In practice, PASS/FAIL patterns may differ based on:
LLM demo outcomes can vary across environments. PASS/FAIL patterns may differ based on:
- provider
- client layer
- model serving path
Expand Down
9 changes: 6 additions & 3 deletions examples/08_controller_preview_diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import {
DECISION_CLARIFY,
DECISION_PASSTHROUGH,
DECISION_UPDATE,
POLICY_PROHIBIT,
POLICY_USE,
createEngine,
getPolicyItems,
get_clarify_prompt,
getPremiseValue,
get_decision_state,
is_clarify,
Expand All @@ -24,8 +27,8 @@ function summarizeState(state: EngineState): {
} {
return {
premise: getPremiseValue(state),
usePolicies: getPolicyItems(state, 'use'),
prohibitPolicies: getPolicyItems(state, 'prohibit')
usePolicies: getPolicyItems(state, POLICY_USE),
prohibitPolicies: getPolicyItems(state, POLICY_PROHIBIT)
};
}

Expand All @@ -46,7 +49,7 @@ function summarizeDecision(decision: Decision): {
if (is_clarify(decision)) {
return {
kind: DECISION_CLARIFY,
promptToUser: decision.prompt_to_user,
promptToUser: get_clarify_prompt(decision),
decisionState: null
};
}
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
TypeScript examples showing how host applications keep rules and corrections consistent across turns.

These examples follow the Python 0.7 behavior baseline and use only core APIs.
Request-scoped integrations can persist compiler state with checkpoint APIs so rules and corrections stay consistent across turns.
Request-based integrations can persist compiler state with checkpoint APIs so rules and corrections stay consistent across turns.

## 01_persistent_guardrails.ts

Expand All @@ -30,7 +30,7 @@ Includes single-item correction with `remove policy <item>`.

## 06_transcript_replay.ts

Demonstrates transcript replay behavior with `compile_transcript(messages)` and replay onto current engine state via `engine.apply_transcript(...)`.
Shows transcript replay with `compile_transcript(messages)` and replay onto current engine state with `engine.apply_transcript(...)`.

## 07_single_policy_correction.ts

Expand All @@ -39,5 +39,5 @@ Demonstrates explicit single-policy correction without `reset policies`:

## 08_controller_preview_diff.ts

Demonstrates controller-layer auditability with `preview(engine, input)` and `state_diff(before, after)`.
Shows controller-layer auditability with `preview(engine, input)` and `state_diff(before, after)`.
Shows that preview does not mutate live engine state, then applies the same input with `step(engine, input)`.
57 changes: 9 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rlippmann/context-compiler",
"version": "0.6.1",
"version": "0.7.0",
"description": "Store AI rules and corrections separately from chat history so they stay consistent across turns.",
"keywords": [
"llm",
Expand Down
Loading