theorum 0.1.3 → 0.1.4

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 (187) hide show
  1. package/README.md +30 -9
  2. package/deno.json +57 -0
  3. package/deno.lock +469 -0
  4. package/{esm/mod.d.ts → mod.ts} +57 -15
  5. package/package.json +35 -44
  6. package/src/cli/commands/profile.ts +57 -0
  7. package/src/cli/commands/run.ts +66 -0
  8. package/src/cli/commands/test.ts +195 -0
  9. package/src/cli/index.ts +161 -0
  10. package/src/cli/matrix/fixtures.ts +96 -0
  11. package/src/cli/matrix/synthesizer.ts +240 -0
  12. package/src/guardrails/error.ts +142 -0
  13. package/src/guardrails/injection.ts +254 -0
  14. package/src/guardrails/mod.ts +40 -0
  15. package/src/guardrails/quota.ts +87 -0
  16. package/src/guardrails/sanitize.ts +165 -0
  17. package/src/guardrails/sensitive.ts +96 -0
  18. package/src/host/mint-trace.ts +54 -0
  19. package/{esm/src/host/mod.js → src/host/mod.ts} +11 -3
  20. package/src/host/reply.ts +32 -0
  21. package/src/kernel/engine/assert.ts +29 -0
  22. package/src/kernel/engine/boundary.ts +75 -0
  23. package/src/kernel/engine/delta.ts +440 -0
  24. package/src/kernel/engine/hash.ts +11 -0
  25. package/src/kernel/engine/record.ts +8 -0
  26. package/src/kernel/engine/repair.ts +56 -0
  27. package/src/kernel/engine/runner/gates.ts +338 -0
  28. package/src/kernel/engine/runner/mod.ts +135 -0
  29. package/src/kernel/engine/runner/state.ts +31 -0
  30. package/src/kernel/engine/runner/steps.ts +183 -0
  31. package/src/kernel/engine/runner/stream.ts +83 -0
  32. package/src/kernel/engine/runner/tokens.ts +47 -0
  33. package/src/kernel/engine/runner/tools.ts +266 -0
  34. package/{esm/src/kernel/engine/runner.d.ts → src/kernel/engine/runner.ts} +2 -1
  35. package/src/kernel/engine/tree.ts +18 -0
  36. package/src/kernel/mod.ts +39 -0
  37. package/src/kernel/registry/attachments.ts +195 -0
  38. package/src/kernel/registry/catalog.ts +181 -0
  39. package/src/kernel/registry/ingress.ts +223 -0
  40. package/src/kernel/registry/profiles.ts +165 -0
  41. package/src/kernel/registry/provider-request.ts +31 -0
  42. package/src/kernel/registry/resolve.ts +290 -0
  43. package/src/kernel/registry/schemas.ts +29 -0
  44. package/src/kernel/registry/tools.ts +45 -0
  45. package/{esm/src/kernel/registry/vault.d.ts → src/kernel/registry/vault.ts} +17 -2
  46. package/src/kernel/types.ts +576 -0
  47. package/{esm/src/observability/mod.js → src/observability/mod.ts} +11 -2
  48. package/src/observability/spans.ts +70 -0
  49. package/src/observability/trace-attach.ts +96 -0
  50. package/src/observability/trace-record.ts +254 -0
  51. package/src/observability/trace-usage.ts +36 -0
  52. package/src/observability/trace.ts +143 -0
  53. package/src/presets/google.ts +147 -0
  54. package/src/presets/mod.ts +24 -0
  55. package/src/providers/create-provider.ts +64 -0
  56. package/src/providers/gemini-tape.ts +59 -0
  57. package/src/providers/google-tap.ts +57 -0
  58. package/src/providers/interactions.ts +182 -0
  59. package/src/providers/keys.ts +182 -0
  60. package/{esm/src/providers/mod.js → src/providers/mod.ts} +4 -2
  61. package/{esm/src/providers/openrouter-mod.js → src/providers/openrouter-mod.ts} +7 -3
  62. package/src/providers/openrouter-payload.ts +232 -0
  63. package/src/providers/openrouter.ts +758 -0
  64. package/src/providers/pcm.ts +37 -0
  65. package/src/providers/provider.ts +206 -0
  66. package/src/providers/speech.ts +180 -0
  67. package/src/providers/sse.ts +59 -0
  68. package/esm/_dnt.polyfills.d.ts +0 -110
  69. package/esm/_dnt.polyfills.js +0 -144
  70. package/esm/_dnt.shims.d.ts +0 -5
  71. package/esm/_dnt.shims.js +0 -61
  72. package/esm/mod.js +0 -49
  73. package/esm/package.json +0 -3
  74. package/esm/src/cli/commands/profile.d.ts +0 -2
  75. package/esm/src/cli/commands/profile.js +0 -53
  76. package/esm/src/cli/commands/run.d.ts +0 -10
  77. package/esm/src/cli/commands/run.js +0 -55
  78. package/esm/src/cli/commands/test.d.ts +0 -15
  79. package/esm/src/cli/commands/test.js +0 -140
  80. package/esm/src/cli/index.d.ts +0 -4
  81. package/esm/src/cli/index.js +0 -148
  82. package/esm/src/cli/matrix/fixtures.d.ts +0 -13
  83. package/esm/src/cli/matrix/fixtures.js +0 -77
  84. package/esm/src/cli/matrix/synthesizer.d.ts +0 -29
  85. package/esm/src/cli/matrix/synthesizer.js +0 -187
  86. package/esm/src/guardrails/error.d.ts +0 -33
  87. package/esm/src/guardrails/error.js +0 -114
  88. package/esm/src/guardrails/injection.d.ts +0 -12
  89. package/esm/src/guardrails/injection.js +0 -220
  90. package/esm/src/guardrails/mod.d.ts +0 -14
  91. package/esm/src/guardrails/mod.js +0 -14
  92. package/esm/src/guardrails/sanitize.d.ts +0 -22
  93. package/esm/src/guardrails/sanitize.js +0 -133
  94. package/esm/src/guardrails/sensitive.d.ts +0 -12
  95. package/esm/src/guardrails/sensitive.js +0 -88
  96. package/esm/src/host/mint-trace.d.ts +0 -27
  97. package/esm/src/host/mint-trace.js +0 -33
  98. package/esm/src/host/mod.d.ts +0 -13
  99. package/esm/src/host/reply.d.ts +0 -14
  100. package/esm/src/host/reply.js +0 -27
  101. package/esm/src/kernel/engine/boundary.d.ts +0 -10
  102. package/esm/src/kernel/engine/boundary.js +0 -55
  103. package/esm/src/kernel/engine/delta.d.ts +0 -8
  104. package/esm/src/kernel/engine/delta.js +0 -389
  105. package/esm/src/kernel/engine/hash.d.ts +0 -1
  106. package/esm/src/kernel/engine/hash.js +0 -9
  107. package/esm/src/kernel/engine/record.d.ts +0 -2
  108. package/esm/src/kernel/engine/record.js +0 -7
  109. package/esm/src/kernel/engine/repair.d.ts +0 -7
  110. package/esm/src/kernel/engine/repair.js +0 -38
  111. package/esm/src/kernel/engine/runner/gates.d.ts +0 -4
  112. package/esm/src/kernel/engine/runner/gates.js +0 -206
  113. package/esm/src/kernel/engine/runner/mod.d.ts +0 -14
  114. package/esm/src/kernel/engine/runner/mod.js +0 -103
  115. package/esm/src/kernel/engine/runner/state.d.ts +0 -16
  116. package/esm/src/kernel/engine/runner/state.js +0 -8
  117. package/esm/src/kernel/engine/runner/steps.d.ts +0 -15
  118. package/esm/src/kernel/engine/runner/steps.js +0 -119
  119. package/esm/src/kernel/engine/runner/stream.d.ts +0 -11
  120. package/esm/src/kernel/engine/runner/stream.js +0 -65
  121. package/esm/src/kernel/engine/runner/tokens.d.ts +0 -3
  122. package/esm/src/kernel/engine/runner/tokens.js +0 -38
  123. package/esm/src/kernel/engine/runner/tools.d.ts +0 -13
  124. package/esm/src/kernel/engine/runner/tools.js +0 -197
  125. package/esm/src/kernel/engine/runner.js +0 -6
  126. package/esm/src/kernel/engine/tree.d.ts +0 -2
  127. package/esm/src/kernel/engine/tree.js +0 -17
  128. package/esm/src/kernel/mod.d.ts +0 -18
  129. package/esm/src/kernel/mod.js +0 -16
  130. package/esm/src/kernel/registry/attachments.d.ts +0 -16
  131. package/esm/src/kernel/registry/attachments.js +0 -156
  132. package/esm/src/kernel/registry/catalog.d.ts +0 -31
  133. package/esm/src/kernel/registry/catalog.js +0 -135
  134. package/esm/src/kernel/registry/ingress.d.ts +0 -13
  135. package/esm/src/kernel/registry/ingress.js +0 -163
  136. package/esm/src/kernel/registry/profiles.d.ts +0 -34
  137. package/esm/src/kernel/registry/profiles.js +0 -120
  138. package/esm/src/kernel/registry/provider-request.d.ts +0 -4
  139. package/esm/src/kernel/registry/provider-request.js +0 -25
  140. package/esm/src/kernel/registry/resolve.d.ts +0 -19
  141. package/esm/src/kernel/registry/resolve.js +0 -217
  142. package/esm/src/kernel/registry/schemas.d.ts +0 -14
  143. package/esm/src/kernel/registry/schemas.js +0 -23
  144. package/esm/src/kernel/registry/tools.d.ts +0 -12
  145. package/esm/src/kernel/registry/tools.js +0 -36
  146. package/esm/src/kernel/registry/vault.js +0 -18
  147. package/esm/src/kernel/types.d.ts +0 -521
  148. package/esm/src/kernel/types.js +0 -10
  149. package/esm/src/observability/mod.d.ts +0 -12
  150. package/esm/src/observability/spans.d.ts +0 -16
  151. package/esm/src/observability/spans.js +0 -56
  152. package/esm/src/observability/trace-attach.d.ts +0 -16
  153. package/esm/src/observability/trace-attach.js +0 -67
  154. package/esm/src/observability/trace-record.d.ts +0 -112
  155. package/esm/src/observability/trace-record.js +0 -140
  156. package/esm/src/observability/trace-usage.d.ts +0 -3
  157. package/esm/src/observability/trace-usage.js +0 -32
  158. package/esm/src/observability/trace.d.ts +0 -23
  159. package/esm/src/observability/trace.js +0 -121
  160. package/esm/src/presets/google.d.ts +0 -50
  161. package/esm/src/presets/google.js +0 -96
  162. package/esm/src/presets/mod.d.ts +0 -11
  163. package/esm/src/presets/mod.js +0 -10
  164. package/esm/src/providers/create-provider.d.ts +0 -29
  165. package/esm/src/providers/create-provider.js +0 -38
  166. package/esm/src/providers/gemini-tape.d.ts +0 -2
  167. package/esm/src/providers/gemini-tape.js +0 -46
  168. package/esm/src/providers/google-tap.d.ts +0 -3
  169. package/esm/src/providers/google-tap.js +0 -48
  170. package/esm/src/providers/interactions.d.ts +0 -5
  171. package/esm/src/providers/interactions.js +0 -152
  172. package/esm/src/providers/keys.d.ts +0 -19
  173. package/esm/src/providers/keys.js +0 -129
  174. package/esm/src/providers/mod.d.ts +0 -12
  175. package/esm/src/providers/openrouter-mod.d.ts +0 -13
  176. package/esm/src/providers/openrouter-payload.d.ts +0 -32
  177. package/esm/src/providers/openrouter-payload.js +0 -179
  178. package/esm/src/providers/openrouter.d.ts +0 -15
  179. package/esm/src/providers/openrouter.js +0 -589
  180. package/esm/src/providers/pcm.d.ts +0 -7
  181. package/esm/src/providers/pcm.js +0 -35
  182. package/esm/src/providers/provider.d.ts +0 -15
  183. package/esm/src/providers/provider.js +0 -166
  184. package/esm/src/providers/speech.d.ts +0 -23
  185. package/esm/src/providers/speech.js +0 -125
  186. package/esm/src/providers/sse.d.ts +0 -7
  187. package/esm/src/providers/sse.js +0 -53
@@ -36,18 +36,60 @@
36
36
  *
37
37
  * @module
38
38
  */
39
- import "./_dnt.polyfills.js";
40
- export { publicError, TheorumError } from './src/guardrails/error.js';
41
- export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, } from './src/guardrails/sanitize.js';
42
- export { runTurn } from './src/kernel/engine/runner.js';
43
- export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './src/kernel/registry/catalog.js';
44
- export type { ProfileDefinition } from './src/kernel/registry/profiles.js';
45
- export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './src/kernel/registry/profiles.js';
46
- export { projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
47
- export { getStructured, registerStructured } from './src/kernel/registry/schemas.js';
48
- export { executeTool } from './src/kernel/registry/tools.js';
49
- export type * from './src/kernel/types.js';
50
- export { jsonlSink, memorySink, noopSink, resolveTraceDir, sinkFromDir, writeTrace, } from './src/observability/trace.js';
51
- export type { TraceRecord } from './src/observability/trace-record.js';
52
- export type { CreateProviderOptions, GeminiTransport, GeminiVault } from './src/providers/mod.js';
53
- export { createProvider } from './src/providers/mod.js';
39
+
40
+ export { publicError, TheorumError } from './src/guardrails/error.ts';
41
+ export type { QuotaSlotStatus } from './src/guardrails/quota.ts';
42
+ export {
43
+ clientIp,
44
+ quotaMessage,
45
+ releaseSlot,
46
+ resetSlots,
47
+ skipQuota,
48
+ takeSlot,
49
+ } from './src/guardrails/quota.ts';
50
+ export {
51
+ PROJECT_ID_MAX,
52
+ sanitizeProjectId,
53
+ sanitizeText,
54
+ sanitizeTurnRequest,
55
+ } from './src/guardrails/sanitize.ts';
56
+ export { runTurn } from './src/kernel/engine/runner.ts';
57
+ export {
58
+ CATALOG,
59
+ clampThinkingLevel,
60
+ clampThinkingLevelForApiId,
61
+ geminiKindForMime,
62
+ getTool,
63
+ listBuiltinIds,
64
+ mimeAllowed,
65
+ mimeEssence,
66
+ modelEntryByApiId,
67
+ registerTools,
68
+ requireModelSpec,
69
+ resetTools,
70
+ } from './src/kernel/registry/catalog.ts';
71
+ export type { ProfileDefinition } from './src/kernel/registry/profiles.ts';
72
+ export {
73
+ clearProfiles,
74
+ defineProfile,
75
+ getProfile,
76
+ hasProfile,
77
+ listProfiles,
78
+ registerProfile,
79
+ registerProfiles,
80
+ } from './src/kernel/registry/profiles.ts';
81
+ export { projectProfile, resolveTurn } from './src/kernel/registry/resolve.ts';
82
+ export { getStructured, registerStructured } from './src/kernel/registry/schemas.ts';
83
+ export { executeTool } from './src/kernel/registry/tools.ts';
84
+ export type * from './src/kernel/types.ts';
85
+ export {
86
+ jsonlSink,
87
+ memorySink,
88
+ noopSink,
89
+ resolveTraceDir,
90
+ sinkFromDir,
91
+ writeTrace,
92
+ } from './src/observability/trace.ts';
93
+ export type { TraceRecord } from './src/observability/trace-record.ts';
94
+ export type { CreateProviderOptions, GeminiTransport, GeminiVault } from './src/providers/mod.ts';
95
+ export { createProvider } from './src/providers/mod.ts';
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "theorum",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, dynamic tools, provider adapters, guardrails, and host-injected traces.",
5
+ "license": "MIT",
6
+ "type": "module",
5
7
  "keywords": [
6
8
  "agent",
7
9
  "ai",
@@ -13,53 +15,42 @@
13
15
  "openrouter",
14
16
  "gemini"
15
17
  ],
16
- "license": "MIT",
17
- "module": "./esm/mod.js",
18
18
  "exports": {
19
- ".": {
20
- "import": "./esm/mod.js"
21
- },
22
- "./kernel": {
23
- "import": "./esm/src/kernel/mod.js"
24
- },
25
- "./providers": {
26
- "import": "./esm/src/providers/mod.js"
27
- },
28
- "./openrouter": {
29
- "import": "./esm/src/providers/openrouter-mod.js"
30
- },
31
- "./guardrails": {
32
- "import": "./esm/src/guardrails/mod.js"
33
- },
34
- "./observability": {
35
- "import": "./esm/src/observability/mod.js"
36
- },
37
- "./host": {
38
- "import": "./esm/src/host/mod.js"
39
- },
40
- "./cli": {
41
- "import": "./esm/src/cli/index.js"
42
- },
43
- "./presets": {
44
- "import": "./esm/src/presets/mod.js"
45
- },
46
- "./presets/google": {
47
- "import": "./esm/src/presets/google.js"
48
- }
49
- },
50
- "scripts": {},
51
- "bin": {
52
- "theorum": "esm/src/cli/index.js"
19
+ ".": "./mod.ts",
20
+ "./kernel": "./src/kernel/mod.ts",
21
+ "./providers": "./src/providers/mod.ts",
22
+ "./openrouter": "./src/providers/openrouter-mod.ts",
23
+ "./guardrails": "./src/guardrails/mod.ts",
24
+ "./observability": "./src/observability/mod.ts",
25
+ "./host": "./src/host/mod.ts",
26
+ "./cli": "./src/cli/index.ts",
27
+ "./presets": "./src/presets/mod.ts",
28
+ "./presets/google": "./src/presets/google.ts"
53
29
  },
54
- "type": "module",
55
- "sideEffects": false,
30
+ "files": [
31
+ "README.md",
32
+ "deno.json",
33
+ "deno.lock",
34
+ "docs/",
35
+ "mod.ts",
36
+ "src/"
37
+ ],
56
38
  "dependencies": {
57
39
  "@openrouter/ai-sdk-provider": "1.5.4",
58
- "ai": "5.0.244",
59
- "@deno/shim-deno": "~0.18.0"
40
+ "ai": "5.0.244"
60
41
  },
61
- "devDependencies": {
62
- "@types/node": "^20.9.0"
42
+ "scripts": {
43
+ "build:npm": "deno run --allow-read --allow-write --allow-env --allow-net --allow-run=npm scripts/build-npm.ts",
44
+ "test": "deno test --allow-read --allow-write --allow-net",
45
+ "coverage": "rm -rf coverage && deno test --allow-read --allow-write --allow-net --coverage=coverage tests/ && deno coverage coverage --lcov --output=coverage/lcov.info && node scripts/lcov-to-istanbul.mjs",
46
+ "lint:biome": "biome check .",
47
+ "lint:ast-grep": "ast-grep scan",
48
+ "lint:fallow": "npm run coverage && fallow audit && fallow health && fallow dupes && fallow dead-code",
49
+ "lint": "npm run lint:biome && npm run lint:ast-grep && npm run lint:fallow"
63
50
  },
64
- "_generatedBy": "dnt@0.43.2"
51
+ "devDependencies": {
52
+ "@biomejs/biome": "^2.5.8",
53
+ "@ast-grep/cli": "^0.41.0",
54
+ "fallow": "3.17.0"
55
+ }
65
56
  }
@@ -0,0 +1,57 @@
1
+ import { getProfile, listProfiles } from '../../kernel/registry/profiles.ts';
2
+ import type { Profile } from '../../kernel/types.ts';
3
+
4
+ function formatProfileInputs(p: Profile): string {
5
+ const inputs: string[] = [];
6
+ if (p.inputs.text !== false) inputs.push('text');
7
+ if (p.inputs.voice) inputs.push('voice');
8
+ if (p.inputs.attachments) inputs.push(`attachments [${p.inputs.attachments.accept?.join(', ')}]`);
9
+ return inputs.join(' | ');
10
+ }
11
+
12
+ function printProfileCard(p: Profile): void {
13
+ const tools = p.tools.allow?.length ? p.tools.allow.join(', ') : 'none';
14
+ const models = p.model.allow?.join(', ') || 'default';
15
+ const structured =
16
+ typeof p.outputs.structured === 'string'
17
+ ? p.outputs.structured
18
+ : p.outputs.structured
19
+ ? 'custom'
20
+ : 'none';
21
+
22
+ console.log(` • Profile: ${p.id.padEnd(16)} (handle: ${p.identity.handle})`);
23
+ console.log(` - Models: ${models}`);
24
+ console.log(` - Inputs: ${formatProfileInputs(p)}`);
25
+ console.log(` - Tools: ${tools}`);
26
+ console.log(` - Structured: ${structured}`);
27
+ console.log(` - Key Bucket: ${p.model.key ?? 'freeA'}`);
28
+ console.log('-'.repeat(70));
29
+ }
30
+
31
+ export function listProfilesCommand(): void {
32
+ const profiles = listProfiles();
33
+ console.log('\n Registered Theorum Profiles:');
34
+ console.log('='.repeat(70));
35
+ if (profiles.length === 0) {
36
+ console.log(' (No profiles registered in runtime)');
37
+ console.log(`${'='.repeat(70)}\n`);
38
+ return;
39
+ }
40
+
41
+ for (const p of profiles) {
42
+ printProfileCard(p);
43
+ }
44
+ console.log(`Total: ${profiles.length} profiles registered.\n`);
45
+ }
46
+
47
+ export function showProfileCommand(profileId: string): void {
48
+ try {
49
+ const profile = getProfile(profileId);
50
+ console.log(`\n Profile Details: ${profileId}`);
51
+ console.log('='.repeat(70));
52
+ console.log(JSON.stringify(profile, null, 2));
53
+ console.log(`${'='.repeat(70)}\n`);
54
+ } catch (err) {
55
+ console.error(`\n Error: ${err instanceof Error ? err.message : String(err)}\n`);
56
+ }
57
+ }
@@ -0,0 +1,66 @@
1
+ import { runTurn } from '../../kernel/engine/runner.ts';
2
+ import { getProfile } from '../../kernel/registry/profiles.ts';
3
+ import type { ModelProvider, TurnEvent, TurnRequest } from '../../kernel/types.ts';
4
+
5
+ export interface RunOptions {
6
+ profile: string;
7
+ prompt?: string;
8
+ mode?: string;
9
+ search?: boolean;
10
+ map?: boolean;
11
+ provider?: ModelProvider;
12
+ }
13
+
14
+ function handleRunEvent(event: TurnEvent): void {
15
+ if (event.type === 'thought' && event.text) {
16
+ Deno.stdout.write(new TextEncoder().encode(`\x1b[2m${event.text}\x1b[0m`));
17
+ } else if (event.type === 'text' && event.text) {
18
+ Deno.stdout.write(new TextEncoder().encode(event.text));
19
+ } else if (event.type === 'tool' && event.tool) {
20
+ console.log(`\n\x1b[33m⚡ [Tool Call] ${event.tool.name}\x1b[0m:`, event.tool.arguments);
21
+ } else if (event.type === 'structured' && event.structured) {
22
+ console.log('\n\x1b[32m✓ [Structured Output]\x1b[0m:');
23
+ console.log(JSON.stringify(event.structured, null, 2));
24
+ } else if (event.type === 'media' && event.media) {
25
+ console.log(`\n\x1b[34m🖼 [Media Output]\x1b[0m (${event.media.mimeType})`);
26
+ } else if (event.type === 'error' && event.error) {
27
+ console.error(`\n\x1b[31m✗ Error\x1b[0m: ${event.error}`);
28
+ }
29
+ }
30
+
31
+ export async function runCommand(options: RunOptions): Promise<void> {
32
+ getProfile(options.profile);
33
+ const provider = options.provider;
34
+ if (!provider) {
35
+ console.error(
36
+ '\n\x1b[31mExecution Failed\x1b[0m: Theorum CLI does not create providers or read keys. Run turns from a host app with an explicit ModelProvider.\n',
37
+ );
38
+ return;
39
+ }
40
+
41
+ const prompt = options.prompt || 'Hello! Please introduce your capabilities.';
42
+ const tools: Record<string, boolean> = {};
43
+ if (options.search) tools.googleSearch = true;
44
+ if (options.map) tools.googleMaps = true;
45
+
46
+ const req: TurnRequest = {
47
+ profile: options.profile,
48
+ select: options.mode,
49
+ tools: Object.keys(tools).length > 0 ? tools : undefined,
50
+ input: { text: prompt },
51
+ };
52
+
53
+ console.log(`\n▶ [RUNNING TURN] Profile: ${options.profile} (${options.mode ?? 'default'})`);
54
+ console.log(`Prompt: "${prompt}"\n`);
55
+
56
+ try {
57
+ for await (const event of runTurn(req, provider)) {
58
+ handleRunEvent(event);
59
+ }
60
+ console.log('\n');
61
+ } catch (err) {
62
+ console.error(
63
+ `\n\x1b[31mExecution Failed\x1b[0m: ${err instanceof Error ? err.message : String(err)}\n`,
64
+ );
65
+ }
66
+ }
@@ -0,0 +1,195 @@
1
+ import { runTurn } from '../../kernel/engine/runner.ts';
2
+ import { getProfile, listProfiles } from '../../kernel/registry/profiles.ts';
3
+ import type { ModelProvider, Profile, TurnEvent, TurnRequest } from '../../kernel/types.ts';
4
+ import {
5
+ buildCustomTurnRequest,
6
+ type MatrixOptions,
7
+ synthesizeMatrixCombos,
8
+ } from '../matrix/synthesizer.ts';
9
+
10
+ export interface TestRunResult {
11
+ passed: boolean;
12
+ name: string;
13
+ durationSec: number;
14
+ tokensTotal?: number;
15
+ error?: string;
16
+ }
17
+
18
+ interface TestExecutionAccumulator {
19
+ totalTokens: number;
20
+ hasError: boolean;
21
+ errorMessage: string;
22
+ }
23
+
24
+ function printTestHeader(req: TurnRequest, testName: string): void {
25
+ const activeTools = Object.entries(req.tools ?? {})
26
+ .filter(([, v]) => Boolean(v))
27
+ .map(([k]) => k)
28
+ .join(', ');
29
+
30
+ console.log(`\n▶ [THEORUM TEST] ${testName}`);
31
+ console.log(` Profile: ${req.profile} (Mode: ${req.select ?? 'default'})`);
32
+ console.log(` Tools: ${activeTools || 'none'}`);
33
+ console.log(
34
+ ` Attachments: ${req.input?.attachments?.length ?? 0} file(s) | Voice: ${req.input?.voice?.length ? 'yes' : 'no'}`,
35
+ );
36
+ console.log(` ${'-'.repeat(60)}`);
37
+ }
38
+
39
+ function processTestEvent(event: TurnEvent, acc: TestExecutionAccumulator): void {
40
+ if (event.type === 'thought' && event.text) {
41
+ Deno.stdout.write(new TextEncoder().encode('.'));
42
+ } else if (event.type === 'tool' && event.tool) {
43
+ console.log(
44
+ `\n ⚡ [Tool Dispatched] ${event.tool.name}(${JSON.stringify(event.tool.arguments ?? {})})`,
45
+ );
46
+ } else if (event.type === 'structured') {
47
+ console.log(`\n ✓ [Structured Schema Validated]`);
48
+ } else if (event.type === 'media') {
49
+ console.log(`\n ✓ [Media Generated] (${event.media?.mimeType})`);
50
+ } else if (event.type === 'tokens' && event.tokens) {
51
+ acc.totalTokens = event.tokens.total;
52
+ } else if (event.type === 'error' && event.error) {
53
+ acc.hasError = true;
54
+ acc.errorMessage = event.error;
55
+ console.error(`\n [Test Error Detail]: ${event.error}`);
56
+ }
57
+ }
58
+
59
+ function printTestResult(
60
+ passed: boolean,
61
+ durationSec: number,
62
+ acc: TestExecutionAccumulator,
63
+ ): void {
64
+ if (passed) {
65
+ console.log(
66
+ `\n ✓ STATUS: PASSED (took ${durationSec.toFixed(2)}s, ${acc.totalTokens ? `${acc.totalTokens} tokens` : 'ok'})`,
67
+ );
68
+ } else {
69
+ console.log(`\n ✗ STATUS: FAILED: ${acc.errorMessage} (${durationSec.toFixed(2)}s)`);
70
+ }
71
+ }
72
+
73
+ export async function executeSingleTest(
74
+ req: TurnRequest,
75
+ testName: string,
76
+ provider?: ModelProvider,
77
+ ): Promise<TestRunResult> {
78
+ const start = Date.now();
79
+ getProfile(req.profile);
80
+ printTestHeader(req, testName);
81
+
82
+ const acc: TestExecutionAccumulator = {
83
+ totalTokens: 0,
84
+ hasError: false,
85
+ errorMessage: '',
86
+ };
87
+
88
+ try {
89
+ if (!provider) {
90
+ throw new Error(
91
+ 'Theorum CLI does not create providers or read keys. Pass an explicit ModelProvider from the host app.',
92
+ );
93
+ }
94
+ for await (const event of runTurn(req, provider)) {
95
+ processTestEvent(event, acc);
96
+ }
97
+ } catch (err) {
98
+ acc.hasError = true;
99
+ acc.errorMessage = err instanceof Error ? err.message : String(err);
100
+ }
101
+
102
+ const durationSec = (Date.now() - start) / 1000;
103
+ const passed = !acc.hasError;
104
+ printTestResult(passed, durationSec, acc);
105
+
106
+ return {
107
+ passed,
108
+ name: testName,
109
+ durationSec,
110
+ tokensTotal: acc.totalTokens,
111
+ error: acc.errorMessage,
112
+ };
113
+ }
114
+
115
+ function resolveTargetProfiles(
116
+ profileId: string | undefined,
117
+ all: boolean | undefined,
118
+ ): Profile[] | null {
119
+ if (all) {
120
+ return listProfiles();
121
+ }
122
+ if (profileId) {
123
+ try {
124
+ return [getProfile(profileId)];
125
+ } catch (err) {
126
+ console.error(`\n Error: ${err instanceof Error ? err.message : String(err)}\n`);
127
+ return null;
128
+ }
129
+ }
130
+ console.error(
131
+ 'Error: Please specify a profile ID (e.g. `theorum test --profile your-profile`) or `--all`.',
132
+ );
133
+ return null;
134
+ }
135
+
136
+ async function runProfileMatrix(
137
+ profile: Profile,
138
+ provider?: ModelProvider,
139
+ ): Promise<TestRunResult[]> {
140
+ const results: TestRunResult[] = [];
141
+ const combos = synthesizeMatrixCombos(profile);
142
+ for (const combo of combos) {
143
+ const res = await executeSingleTest(combo.req, `${profile.id} [${combo.name}]`, provider);
144
+ results.push(res);
145
+ }
146
+ return results;
147
+ }
148
+
149
+ async function runProfileSingle(
150
+ profile: Profile,
151
+ options: MatrixOptions,
152
+ provider?: ModelProvider,
153
+ ): Promise<TestRunResult> {
154
+ const req = buildCustomTurnRequest(profile, options);
155
+ const testName = options.lite ? `${profile.id} [Lite]` : `${profile.id} [Stress Combo]`;
156
+ return await executeSingleTest(req, testName, provider);
157
+ }
158
+
159
+ function printSummaryReport(results: TestRunResult[]): boolean {
160
+ console.log(`\n${'='.repeat(70)}`);
161
+ console.log(' TEST SUMMARY:');
162
+ console.log('='.repeat(70));
163
+ let allPassed = true;
164
+ for (const r of results) {
165
+ const status = r.passed ? '✓ PASSED' : '✗ FAILED';
166
+ console.log(` ${status.padEnd(10)} ${r.name.padEnd(45)} (${r.durationSec.toFixed(2)}s)`);
167
+ if (!r.passed) {
168
+ allPassed = false;
169
+ if (r.error) console.log(` Reason: ${r.error}`);
170
+ }
171
+ }
172
+ console.log(`${'='.repeat(70)}\n`);
173
+ return allPassed;
174
+ }
175
+
176
+ export async function testProfileCommand(
177
+ profileId?: string,
178
+ options: MatrixOptions & { all?: boolean; matrix?: boolean; provider?: ModelProvider } = {},
179
+ ): Promise<boolean> {
180
+ const targetProfiles = resolveTargetProfiles(profileId, options.all);
181
+ if (!targetProfiles || targetProfiles.length === 0) {
182
+ return false;
183
+ }
184
+
185
+ const results: TestRunResult[] = [];
186
+ for (const profile of targetProfiles) {
187
+ if (options.matrix) {
188
+ results.push(...(await runProfileMatrix(profile, options.provider)));
189
+ } else {
190
+ results.push(await runProfileSingle(profile, options, options.provider));
191
+ }
192
+ }
193
+
194
+ return printSummaryReport(results);
195
+ }
@@ -0,0 +1,161 @@
1
+ import { listProfilesCommand, showProfileCommand } from './commands/profile.ts';
2
+ import { runCommand } from './commands/run.ts';
3
+ import { testProfileCommand } from './commands/test.ts';
4
+
5
+ function printHelp(): void {
6
+ console.log(`
7
+ Theorum CLI - Profile Testing and Profile Inspection
8
+
9
+ USAGE:
10
+ theorum <command> [options]
11
+
12
+ COMMANDS:
13
+ test Run stress matrix or custom profile tests
14
+ --profile, -p <id> Target profile ID registered by your host app
15
+ --all, -a Test all registered profiles
16
+ --lite Minimal fast-path connectivity ping
17
+ --matrix Run all valid permutations for the profile
18
+ --mode <fast|smart> Reasoning mode override
19
+ --search Optional: set tool id googleSearch when allowlisted
20
+ --map Optional: set tool id googleMaps when allowlisted
21
+
22
+ run Execute a turn with real-time streaming output
23
+ --profile, -p <id> Target profile ID
24
+ --prompt <text> User prompt string
25
+ --mode <fast|smart> Reasoning mode
26
+ --search Optional: set tool id googleSearch when allowlisted
27
+ --map Optional: set tool id googleMaps when allowlisted
28
+
29
+ profile Inspect registered profile blueprints
30
+ list List all registered profiles
31
+ show <id> Show detailed JSON profile specification
32
+
33
+ help, --help, -h Show this help message
34
+ `);
35
+ }
36
+
37
+ interface ParsedFlags {
38
+ _: string[];
39
+ profile?: string;
40
+ p?: string;
41
+ prompt?: string;
42
+ mode?: string;
43
+ all?: boolean;
44
+ a?: boolean;
45
+ lite?: boolean;
46
+ matrix?: boolean;
47
+ search?: boolean;
48
+ map?: boolean;
49
+ help?: boolean;
50
+ [key: string]: unknown;
51
+ }
52
+
53
+ function parseLongFlag(arg: string, nextArg: string | undefined, flags: ParsedFlags): number {
54
+ const key = arg.slice(2);
55
+ if (nextArg && !nextArg.startsWith('-')) {
56
+ flags[key] = nextArg;
57
+ return 1;
58
+ }
59
+ flags[key] = true;
60
+ return 0;
61
+ }
62
+
63
+ function parseShortFlag(arg: string, nextArg: string | undefined, flags: ParsedFlags): number {
64
+ const key = arg.slice(1);
65
+ if (key === 'p' && nextArg) {
66
+ flags.profile = nextArg;
67
+ return 1;
68
+ }
69
+ if (key === 'a') flags.all = true;
70
+ else if (key === 'h') flags.help = true;
71
+ else flags[key] = true;
72
+ return 0;
73
+ }
74
+
75
+ function parseFlags(args: string[]): ParsedFlags {
76
+ const flags: ParsedFlags = { _: [] };
77
+ let i = 0;
78
+ while (i < args.length) {
79
+ const arg = args[i];
80
+ const next = args[i + 1];
81
+ if (arg.startsWith('--')) {
82
+ i += 1 + parseLongFlag(arg, next, flags);
83
+ } else if (arg.startsWith('-')) {
84
+ i += 1 + parseShortFlag(arg, next, flags);
85
+ } else {
86
+ flags._.push(arg);
87
+ i += 1;
88
+ }
89
+ }
90
+ return flags;
91
+ }
92
+
93
+ function extractProfileId(flags: ParsedFlags): string | undefined {
94
+ if (typeof flags.profile === 'string') return flags.profile;
95
+ if (typeof flags.p === 'string') return flags.p;
96
+ return undefined;
97
+ }
98
+
99
+ async function handleTest(flags: ParsedFlags): Promise<void> {
100
+ const profile = extractProfileId(flags);
101
+ const success = await testProfileCommand(profile, {
102
+ all: Boolean(flags.all || flags.a),
103
+ lite: Boolean(flags.lite),
104
+ matrix: Boolean(flags.matrix),
105
+ mode: typeof flags.mode === 'string' ? flags.mode : undefined,
106
+ search: flags.search ? true : undefined,
107
+ map: flags.map ? true : undefined,
108
+ });
109
+ if (!success) {
110
+ Deno.exit(1);
111
+ }
112
+ }
113
+
114
+ async function handleRun(flags: ParsedFlags): Promise<void> {
115
+ const profile = extractProfileId(flags);
116
+ if (!profile) {
117
+ console.error('Error: Profile ID required (e.g. `theorum run --profile your-profile`)');
118
+ Deno.exit(1);
119
+ }
120
+ const prompt = typeof flags.prompt === 'string' ? flags.prompt : flags._.slice(1).join(' ');
121
+ await runCommand({
122
+ profile,
123
+ prompt,
124
+ mode: typeof flags.mode === 'string' ? flags.mode : undefined,
125
+ search: Boolean(flags.search),
126
+ map: Boolean(flags.map),
127
+ });
128
+ }
129
+
130
+ function handleProfile(flags: ParsedFlags): void {
131
+ const sub = flags._[1] || 'list';
132
+ if (sub === 'list') {
133
+ listProfilesCommand();
134
+ return;
135
+ }
136
+ const id = sub === 'show' ? flags._[2] || flags.profile : sub;
137
+ if (typeof id !== 'string' || !id) {
138
+ console.error('Error: Profile ID required (e.g. `theorum profile show your-profile`)');
139
+ Deno.exit(1);
140
+ }
141
+ showProfileCommand(id);
142
+ }
143
+
144
+ export async function main(cliArgs = Deno.args): Promise<void> {
145
+ const flags = parseFlags(cliArgs);
146
+ const command = flags._[0] || (flags.help ? 'help' : 'help');
147
+
148
+ if (command === 'test') {
149
+ await handleTest(flags);
150
+ } else if (command === 'run') {
151
+ await handleRun(flags);
152
+ } else if (command === 'profile') {
153
+ handleProfile(flags);
154
+ } else {
155
+ printHelp();
156
+ }
157
+ }
158
+
159
+ if (import.meta.main) {
160
+ await main();
161
+ }