theorum 0.1.11 → 0.1.13

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.
Files changed (40) hide show
  1. package/README.md +25 -2
  2. package/docs/COMPACTION.md +227 -0
  3. package/docs/SECRETS.md +6 -1
  4. package/docs/STOP.md +85 -0
  5. package/esm/mod.d.ts +6 -2
  6. package/esm/mod.js +3 -1
  7. package/esm/src/cli/commands/bench.js +2 -4
  8. package/esm/src/cli/commands/fuzz-guardrails.js +195 -48
  9. package/esm/src/guardrails/injection.js +13 -8
  10. package/esm/src/guardrails/normalize.js +65 -38
  11. package/esm/src/guardrails/sensitive.js +1 -1
  12. package/esm/src/kernel/engine/compaction.d.ts +69 -0
  13. package/esm/src/kernel/engine/compaction.js +141 -0
  14. package/esm/src/kernel/engine/delta.js +30 -7
  15. package/esm/src/kernel/engine/history-tokens.d.ts +43 -0
  16. package/esm/src/kernel/engine/history-tokens.js +100 -0
  17. package/esm/src/kernel/engine/runner/mod.js +164 -62
  18. package/esm/src/kernel/engine/runner/state.d.ts +3 -1
  19. package/esm/src/kernel/engine/runner/steps.js +3 -0
  20. package/esm/src/kernel/mod.d.ts +4 -0
  21. package/esm/src/kernel/mod.js +2 -0
  22. package/esm/src/kernel/registry/profiles.js +37 -0
  23. package/esm/src/kernel/stop.d.ts +75 -0
  24. package/esm/src/kernel/stop.js +120 -0
  25. package/esm/src/kernel/types.d.ts +117 -1
  26. package/esm/src/providers/create-provider.d.ts +7 -0
  27. package/esm/src/providers/create-provider.js +24 -4
  28. package/esm/src/providers/expose-for-tests.js +5 -1
  29. package/esm/src/providers/local.d.ts +29 -0
  30. package/esm/src/providers/local.js +259 -0
  31. package/esm/src/providers/mod.d.ts +2 -0
  32. package/esm/src/providers/mod.js +1 -0
  33. package/esm/src/providers/openrouter.js +32 -13
  34. package/esm/src/providers/provider.js +1 -1
  35. package/esm/src/providers/speech.js +1 -1
  36. package/esm/src/streaming/mod.d.ts +3 -1
  37. package/esm/src/streaming/mod.js +2 -1
  38. package/package.json +6 -1
  39. package/docs/AGENT_PROFILE_CONTRACT.md +0 -189
  40. package/docs/CLI_SPEC.md +0 -183
package/docs/CLI_SPEC.md DELETED
@@ -1,183 +0,0 @@
1
- # Theorum CLI & Testing Architecture Specification
2
-
3
- ## 1. Overview & Goals
4
-
5
- The `theorum` CLI provides developer tooling, profile inspection, and stress-matrix synthesis for applications powered by Theorum.
6
-
7
- ### Core Objectives:
8
- 1. **Zero-Config Profile Stress Testing**: Automatically construct the most demanding valid payload (multimodal, deep reasoning, maximum tools) for any registered profile.
9
- 2. **Capability Matrix Permutations**: Systematically test or isolate specific capabilities (`--lite`, `--attachment`, `--voice`, `--map`, `--search`).
10
- 3. **Conflict Resolution**: Deterministically resolve provider conflicts (e.g. `search XOR maps`) and mutual exclusions without crashing.
11
- 4. **Host-Owned Execution**: The CLI never reads secrets or creates providers. Hosts supply providers when executing live tests programmatically.
12
- 5. **Interactive Turn REPL**: Execute ad-hoc runs only when the host has supplied a `ModelProvider`.
13
-
14
- ---
15
-
16
- ## 2. Command Surface & UX
17
-
18
- ```bash
19
- theorum <command> [subcommand] [flags]
20
- ```
21
-
22
- ### 2.1 `theorum test` (Profile Verification & Stress Runner)
23
-
24
- Builds validation turns against registered profiles. Live execution requires an explicit host-provided `ModelProvider`; Theorum does not read keys or create providers.
25
-
26
- ```bash
27
- # 1. Stress Combo (Default): Auto-constructs the toughest valid test for this host profile
28
- theorum test --profile your-profile
29
-
30
- # 2. Lite (Smoke ping): Minimal prompt, fast mode, tools disabled
31
- theorum test --profile your-profile --lite
32
-
33
- # 3. Explicit capability flags: Override/test specific modalities
34
- theorum test --profile your-profile --attachment ./reference.png --map --voice ./audio.wav
35
-
36
- # 4. Full matrix test: Runs every permutation of supported tools/inputs for a profile
37
- theorum test --profile your-profile --matrix
38
-
39
- # 5. Global suite: Test all registered profiles
40
- theorum test --all [--lite] [--concurrency 4]
41
- ```
42
-
43
- #### CLI Flag Matrix:
44
- | Flag | Type | Description |
45
- | :--- | :--- | :--- |
46
- | `--profile, -p` | `string` | Target profile ID registered by the host application |
47
- | `--all, -a` | `boolean` | Run test across all registered profiles |
48
- | `--lite` | `boolean` | Minimal single-turn connectivity ping (fast mode, tools off, text only) |
49
- | `--matrix` | `boolean` | Generate and execute all valid permutations for the profile |
50
- | `--attachment` | `string[]` | Path(s) to custom attachment files (PNG, PDF, CSV, etc.) |
51
- | `--voice` | `string` | Path to custom voice input audio (WAV, PCM) |
52
- | `--search` | `boolean` | Force Google Search tool on |
53
- | `--map` | `boolean` | Force Google Maps tool on |
54
- | `--mode` | `'fast' \| 'smart'` | Force reasoning / model speed tier |
55
- | `--timeout` | `number` | Timeout in seconds (default: 30) |
56
-
57
- ---
58
-
59
- ### 2.2 `theorum run` (Terminal REPL & Ad-hoc Execution)
60
-
61
- Interactive execution in the terminal with live streaming when called from a host that supplies a provider.
62
-
63
- ```bash
64
- # Interactive REPL
65
- theorum run --profile your-profile
66
-
67
- # One-shot CLI run
68
- theorum run --profile your-profile --prompt "Create a 3-tier architecture plan" --mode smart
69
- ```
70
-
71
- ---
72
-
73
- ### 2.3 `theorum profile` (Registry Inspection & Validation)
74
-
75
- ```bash
76
- # List all registered profiles and supported modalities
77
- theorum profile list
78
-
79
- # Show detailed profile definition (inputs, tools, schema, model config)
80
- theorum profile show your-profile
81
-
82
- # Validate structured output schemas
83
- theorum profile validate
84
- ```
85
-
86
- ---
87
-
88
- ## 3. Stress Matrix Synthesizer Logic
89
-
90
- When `theorum test --profile <id>` is invoked without explicit flags, the synthesizer inspects `Profile` metadata:
91
-
92
- ```ts
93
- interface SynthesizedTurn {
94
- profile: string;
95
- select?: 'fast' | 'smart';
96
- input: {
97
- text: string;
98
- voice?: AudioFixture;
99
- attachments?: AttachmentFixture[];
100
- };
101
- tools?: {
102
- googleSearch?: boolean;
103
- googleMaps?: boolean;
104
- codeExecution?: boolean;
105
- customTools?: string[];
106
- };
107
- }
108
- ```
109
-
110
- ### Auto-Synthesis Rules:
111
- 1. **Model & Thinking Selection**:
112
- - If profile supports `smart` mode $\to$ select `smart` (highest pinned thinking tokens).
113
- - Otherwise $\to$ use default profile model.
114
- 2. **Multimodal Fixtures**:
115
- - If `inputs.voice` is set $\to$ inject synthetic 16kHz PCM/WAV voice-input fixture.
116
- - If `inputs.attachments === true` $\to$ inject synthetic test document/image matching allowed MIME types within byte ceilings (`maxBytes`).
117
- 3. **Tool Resolution & Conflict Handling**:
118
- - Turn on all allowed tools in `profile.tools.allow`.
119
- - **Mutual Exclusion Rule**: If both `googleSearch` and `googleMaps` are allowed, default to testing `googleSearch`. When `--matrix` is passed, split into two separate test runs (`[search]` and `[maps]`).
120
- 4. **Structured Schema Validation**:
121
- - If `profile.outputs.structured` is defined, validate that the final LLM response strictly parses against the JSON schema.
122
-
123
- ---
124
-
125
- ## 4. Fixture Management (`src/cli/matrix/fixtures.ts`)
126
-
127
- Built-in zero-dependency synthetic fixtures:
128
- - **`TEST_PNG`**: 1x1 valid PNG image byte buffer (`image/png`).
129
- - **`TEST_PDF`**: Minimal valid PDF 1.4 document buffer (`application/pdf`).
130
- - **`TEST_WAV`**: 1-second 16kHz mono PCM/WAV audio tone (`audio/wav`).
131
- - **`TEST_CSV`**: Minimal CSV table data (`text/csv`).
132
-
133
- ---
134
-
135
- ## 5. File Structure in `theorum` Package
136
-
137
- ```
138
- theorum/
139
- ├── docs/
140
- │ ├── AGENT_PROFILE_CONTRACT.md
141
- │ └── CLI_SPEC.md <-- This specification
142
- ├── src/
143
- │ ├── cli/
144
- │ │ ├── index.ts # CLI Entry point & router
145
- │ │ ├── commands/
146
- │ │ │ ├── test.ts # 'theorum test' execution & reporting
147
- │ │ │ ├── run.ts # 'theorum run' REPL & SSE streaming
148
- │ │ │ └── profile.ts # 'theorum profile' inspector
149
- │ │ └── matrix/
150
- │ │ ├── fixtures.ts # Built-in synthetic media fixtures
151
- │ │ └── synthesizer.ts # Matrix & stress combo generator
152
- │ ├── guardrails/
153
- │ ├── kernel/
154
- │ └── observability/
155
- ├── deno.json # "tasks": { "theorum": "deno run -A src/cli/index.ts" }
156
- └── mod.ts
157
- ```
158
-
159
- ---
160
-
161
- ## 6. Output & Reporting Contract
162
-
163
- `theorum test` outputs concise terminal telemetry:
164
-
165
- ```
166
- [THEORUM TEST] Profile: your-profile (smart mode)
167
- ------------------------------------------------------------
168
- Inputs: [Text, Voice (1s WAV), Attachment (1 PNG)]
169
- Tools: [googleSearch, codeExecution]
170
- Provider: host-supplied ModelProvider
171
-
172
- ⚡ Streaming Turn Execution:
173
- ✓ Thinking tokens: 1,420 tokens (1.12s)
174
- ✓ Tool dispatched: codeExecution (0.34s)
175
- ✓ Schema output: 852 tokens (0.78s)
176
-
177
- Validation Checks:
178
- ✓ Security Canary: Intact & Redacted
179
- ✓ Schema Conformity: Valid (AST JSON)
180
- ✓ Latency: 2.24s total
181
-
182
- STATUS: PASSED ✓
183
- ```