@directive-run/knowledge 1.14.0 → 1.16.0

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 (43) hide show
  1. package/README.md +50 -15
  2. package/ai/ai-adapters.md +7 -0
  3. package/ai/ai-agents-streaming.md +187 -149
  4. package/ai/ai-budget-resilience.md +305 -132
  5. package/ai/ai-communication.md +220 -197
  6. package/ai/ai-debug-observability.md +259 -173
  7. package/ai/ai-guardrails-memory.md +191 -153
  8. package/ai/ai-mcp-rag.md +204 -199
  9. package/ai/ai-multi-agent.md +254 -153
  10. package/ai/ai-orchestrator.md +353 -114
  11. package/ai/ai-security.md +287 -180
  12. package/ai/ai-tasks.md +8 -1
  13. package/ai/ai-testing-evals.md +363 -256
  14. package/core/anti-patterns.md +18 -2
  15. package/core/constraints.md +13 -2
  16. package/core/core-patterns.md +12 -0
  17. package/core/error-boundaries.md +8 -0
  18. package/core/history.md +7 -0
  19. package/core/multi-module.md +15 -3
  20. package/core/naming.md +128 -90
  21. package/core/plugins.md +7 -0
  22. package/core/react-adapter.md +256 -174
  23. package/core/resolvers.md +10 -0
  24. package/core/schema-types.md +8 -0
  25. package/core/system-api.md +10 -0
  26. package/core/testing.md +257 -143
  27. package/examples/checkers.ts +15 -16
  28. package/examples/contact-form.ts +2 -2
  29. package/examples/counter-react.ts +1 -1
  30. package/examples/counter-svelte.ts +1 -1
  31. package/examples/counter-vue.ts +1 -1
  32. package/examples/counter.ts +1 -1
  33. package/examples/data-triggers.ts +4 -4
  34. package/examples/feature-flags.ts +2 -2
  35. package/examples/form-wizard.ts +2 -2
  36. package/examples/newsletter.ts +2 -2
  37. package/examples/server.ts +2 -2
  38. package/examples/shopping-cart.ts +1 -1
  39. package/examples/topic-guard.ts +1 -1
  40. package/package.json +3 -3
  41. package/sitemap.md +17 -11
  42. package/examples/debounce-constraints.ts +0 -95
  43. package/examples/multi-module.ts +0 -58
@@ -49,7 +49,7 @@ export const counterModule = createModule("counter", {
49
49
  resolvers: {
50
50
  clamp: {
51
51
  requirement: "CLAMP_TO_ZERO",
52
- resolve: async (req, context) => {
52
+ resolve: async (_req, context) => {
53
53
  context.facts.count = 0;
54
54
  },
55
55
  },
@@ -49,7 +49,7 @@ export const counterModule = createModule("counter", {
49
49
  resolvers: {
50
50
  clamp: {
51
51
  requirement: "CLAMP_TO_ZERO",
52
- resolve: async (req, context) => {
52
+ resolve: async (_req, context) => {
53
53
  context.facts.count = 0;
54
54
  },
55
55
  },
@@ -69,7 +69,7 @@ export const counterModule = createModule("counter", {
69
69
  resolvers: {
70
70
  clamp: {
71
71
  requirement: "CLAMP_TO_ZERO",
72
- resolve: async (req, context) => {
72
+ resolve: async (_req, context) => {
73
73
  context.facts.count = 0;
74
74
  },
75
75
  },
@@ -98,10 +98,10 @@ const trafficLight = createModule("traffic", {
98
98
  transition: {
99
99
  requirement: "TRANSITION",
100
100
  key: ["to"],
101
- resolve: async (req, ctx) => {
102
- ctx.facts.phase = req.to;
103
- ctx.facts.elapsed = 0;
104
- ctx.facts.transitionCount = ctx.facts.transitionCount + 1;
101
+ resolve: async (req, context) => {
102
+ context.facts.phase = req.to;
103
+ context.facts.elapsed = 0;
104
+ context.facts.transitionCount = context.facts.transitionCount + 1;
105
105
  },
106
106
  },
107
107
  },
@@ -162,14 +162,14 @@ export const featureFlagsModule = createModule("feature-flags", {
162
162
  resolvers: {
163
163
  enableBrandSwitcher: {
164
164
  requirement: "ENABLE_BRAND_SWITCHER",
165
- resolve: async (req, context) => {
165
+ resolve: async (_req, context) => {
166
166
  context.facts.brandSwitcherEnabled = true;
167
167
  },
168
168
  },
169
169
 
170
170
  logMaintenanceWarning: {
171
171
  requirement: "LOG_MAINTENANCE_WARNING",
172
- resolve: async (req, context) => {
172
+ resolve: async (_req, _context) => {
173
173
  console.warn(
174
174
  "[feature-flags] Maintenance mode is active. Chat, search, playground, and vote API are disabled.",
175
175
  );
@@ -227,7 +227,7 @@ export const wizardModule = createModule("wizard", {
227
227
  resolvers: {
228
228
  advanceStep: {
229
229
  requirement: "ADVANCE_STEP",
230
- resolve: async (req, context) => {
230
+ resolve: async (_req, context) => {
231
231
  context.facts.currentStep = context.facts.currentStep + 1;
232
232
  context.facts.advanceRequested = false;
233
233
  },
@@ -236,7 +236,7 @@ export const wizardModule = createModule("wizard", {
236
236
  submitForm: {
237
237
  requirement: "SUBMIT_FORM",
238
238
  timeout: 10000,
239
- resolve: async (req, context) => {
239
+ resolve: async (_req, context) => {
240
240
  // Simulate API submission
241
241
  await new Promise((resolve) => setTimeout(resolve, 800));
242
242
  context.facts.submitted = true;
@@ -151,7 +151,7 @@ const newsletter = createModule("newsletter", {
151
151
  // Simulated submission — no API account needed
152
152
  subscribe: {
153
153
  requirement: "SUBSCRIBE",
154
- resolve: async (req, context) => {
154
+ resolve: async (_req, context) => {
155
155
  addLog(`Subscribing: ${context.facts.email}`);
156
156
 
157
157
  // Simulate network delay
@@ -175,7 +175,7 @@ const newsletter = createModule("newsletter", {
175
175
 
176
176
  resetAfterDelay: {
177
177
  requirement: "RESET_AFTER_DELAY",
178
- resolve: async (req, context) => {
178
+ resolve: async (_req, context) => {
179
179
  addLog("Auto-resetting in 5 seconds...");
180
180
  await new Promise((resolve) => setTimeout(resolve, 5000));
181
181
  context.facts.email = "";
@@ -109,7 +109,7 @@ app.get("/snapshot/:userId", async (req, res) => {
109
109
  snapshotCache.set(userId, { snapshot, cachedAt: Date.now() });
110
110
 
111
111
  res.json({ source: "fresh", snapshot });
112
- } catch (error) {
112
+ } catch (_error) {
113
113
  res.status(500).json({ error: "Failed to settle system" });
114
114
  } finally {
115
115
  system.destroy();
@@ -162,7 +162,7 @@ app.post("/snapshot/:userId/verify", async (req, res) => {
162
162
  signedSnapshot: signed,
163
163
  });
164
164
  }
165
- } catch (error) {
165
+ } catch (_error) {
166
166
  res.status(500).json({ error: "Verification failed" });
167
167
  } finally {
168
168
  system.destroy();
@@ -193,7 +193,7 @@ export const cartModule = createModule("cart", {
193
193
  return sub * (facts.self.couponDiscount / 100);
194
194
  },
195
195
 
196
- tax: (facts, derived) => {
196
+ tax: (_facts, derived) => {
197
197
  const sub = derived.subtotal;
198
198
  const disc = derived.discount;
199
199
 
@@ -106,7 +106,7 @@ export const topicGuardModule = createModule("topic-guard", {
106
106
  .length;
107
107
  },
108
108
 
109
- blockRate: (facts, derived) => {
109
+ blockRate: (_facts, derived) => {
110
110
  const total = derived.messageCount;
111
111
  if (total === 0) {
112
112
  return "0%";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directive-run/knowledge",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Knowledge files, examples, and validation for Directive — the constraint-driven TypeScript runtime.",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "author": "Jason Comes",
@@ -51,8 +51,8 @@
51
51
  "tsx": "^4.19.2",
52
52
  "typescript": "^5.7.2",
53
53
  "vitest": "^3.0.0",
54
- "@directive-run/core": "1.14.0",
55
- "@directive-run/ai": "1.14.0"
54
+ "@directive-run/core": "1.16.0",
55
+ "@directive-run/ai": "1.16.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsx scripts/generate-api-skeleton.ts && tsx scripts/generate-sitemap.ts && tsx scripts/extract-examples.ts && tsup",
package/sitemap.md CHANGED
@@ -64,18 +64,15 @@ Website: https://directive.run
64
64
  - [Error Boundaries](https://directive.run/docs/advanced/errors)
65
65
  - [Definition Meta](https://directive.run/docs/advanced/meta)
66
66
 
67
- ### Analysis & Tooling
68
- - [Predicate Backtest (replay-under)](https://directive.run/docs/replay-under)
69
- - [Parameter Sweep (tune)](https://directive.run/docs/tune)
70
- - [Rules Diff](https://directive.run/docs/rules-diff)
67
+ ### Predicate Tools
68
+ - [predicateFromIntent (LLM emit)](https://directive.run/docs/predicate-from-intent)
69
+ - [describePredicate (prose)](https://directive.run/docs/describe-predicate)
71
70
  - [Predicate Codegen (SQL/Mongo/PostgREST)](https://directive.run/docs/predicate-codegen)
72
71
  - [predict()](https://directive.run/docs/predict)
73
72
  - [doctor.checkAgainst()](https://directive.run/docs/doctor)
74
- - [describePredicate (prose)](https://directive.run/docs/describe-predicate)
75
-
76
- ### LLM Integration
77
- - [predicateFromIntent](https://directive.run/docs/predicate-from-intent)
78
- - [Audit Ledger](https://directive.run/docs/audit-ledger)
73
+ - [Predicate Backtest (replay-under)](https://directive.run/docs/replay-under)
74
+ - [Parameter Sweep (tune)](https://directive.run/docs/tune)
75
+ - [Rules Diff](https://directive.run/docs/rules-diff)
79
76
 
80
77
  ### Plugins
81
78
  - [Overview](https://directive.run/docs/plugins/overview)
@@ -85,9 +82,18 @@ Website: https://directive.run
85
82
  - [Persistence](https://directive.run/docs/plugins/persistence)
86
83
  - [Performance](https://directive.run/docs/plugins/performance)
87
84
  - [Circuit Breaker](https://directive.run/docs/plugins/circuit-breaker)
85
+ - [Audit Ledger](https://directive.run/docs/audit-ledger)
88
86
  - [Observability](https://directive.run/docs/plugins/observability)
89
87
  - [Custom Plugins](https://directive.run/docs/plugins/custom)
90
88
 
89
+ ### Packages
90
+ - [Timeline (test REPL)](https://directive.run/docs/packages/timeline)
91
+ - [Mutator (typed mutations)](https://directive.run/docs/packages/mutator)
92
+ - [Optimistic (auto-rollback)](https://directive.run/docs/packages/optimistic)
93
+ - [Query (data fetching)](https://directive.run/docs/packages/query)
94
+ - [Vite Dev Proxy](https://directive.run/docs/packages/vite-dev-proxy)
95
+ - [Composing all four](https://directive.run/docs/packages/composing-packages)
96
+
91
97
  ### Testing
92
98
  - [Overview](https://directive.run/docs/testing/overview)
93
99
  - [Mock Resolvers](https://directive.run/docs/testing/mock-resolvers)
@@ -121,8 +127,6 @@ Website: https://directive.run
121
127
  - [Role-Based Permissions](https://directive.run/docs/guides/permissions)
122
128
  - [Batch Mutations](https://directive.run/docs/guides/batch-mutations)
123
129
 
124
- ## AI
125
-
126
130
  ### Integration Guides
127
131
  - [Overview](https://directive.run/docs/works-with/overview)
128
132
  - [Redux](https://directive.run/docs/works-with/redux)
@@ -131,6 +135,8 @@ Website: https://directive.run
131
135
  - [React Query](https://directive.run/docs/works-with/react-query)
132
136
  - [Web Worker](https://directive.run/docs/works-with/worker)
133
137
 
138
+ ## AI
139
+
134
140
  ### Foundations
135
141
  - [Overview](https://directive.run/ai/overview)
136
142
  - [Running Agents](https://directive.run/ai/running-agents)
@@ -1,95 +0,0 @@
1
- // Example: debounce-constraints
2
- // Source: examples/debounce-constraints/src/main.ts
3
- // Extracted for AI rules — DOM wiring stripped
4
-
5
- /**
6
- * Debounce Constraints — DOM Rendering & System Wiring
7
- *
8
- * Creates the Directive system, subscribes to state changes,
9
- * renders the search input, debounce progress bar, results list,
10
- * stats, config sliders, and event timeline.
11
- * A 100ms timer drives reactive debounce countdown.
12
- */
13
-
14
- import { createSystem } from "@directive-run/core";
15
- import { devtoolsPlugin } from "@directive-run/core/plugins";
16
- import { el } from "@directive-run/el";
17
- import {
18
- debounceSearchModule,
19
- debounceSearchSchema,
20
- } from "./debounce-search.js";
21
-
22
- // ============================================================================
23
- // System
24
- // ============================================================================
25
-
26
- const system = createSystem({
27
- module: debounceSearchModule,
28
- trace: true,
29
- plugins: [devtoolsPlugin({ name: "debounce-constraints" })],
30
- });
31
- system.start();
32
-
33
- const allKeys = [
34
- ...Object.keys(debounceSearchSchema.facts),
35
- ...Object.keys(debounceSearchSchema.derivations),
36
- ];
37
-
38
- // ============================================================================
39
- // DOM References
40
- // ============================================================================
41
-
42
- // Status bar
43
-
44
- // Search form
45
- "dc-search-input",
46
-
47
- // Progress bar
48
-
49
- // Query display
50
-
51
- // Results
52
-
53
- // Stats
54
-
55
- // Config sliders
56
- "dc-debounce-delay",
57
- "dc-api-delay",
58
- "dc-min-chars",
59
-
60
- // Timeline
61
-
62
- // ============================================================================
63
- // Render
64
- // ============================================================================
65
-
66
-
67
- // ============================================================================
68
- // Subscribe
69
- // ============================================================================
70
-
71
- system.subscribe(allKeys, render);
72
-
73
- // Timer — tick every 100ms for smooth debounce progress bar
74
- const tickInterval = setInterval(() => {
75
- system.events.tick();
76
- }, 100);
77
-
78
- // ============================================================================
79
- // Controls
80
- // ============================================================================
81
-
82
- // Search input — fire on every keystroke
83
-
84
- // Clear
85
-
86
- // Sliders
87
-
88
-
89
- // ============================================================================
90
- // Initial Render
91
- // ============================================================================
92
-
93
- render();
94
-
95
- // Signal to tests that the module script has fully initialized
@@ -1,58 +0,0 @@
1
- // Example: multi-module
2
- // Source: examples/multi-module/src/main.ts
3
- // Extracted for AI rules — DOM wiring stripped
4
-
5
- /**
6
- * Multi-Module Example - Main Entry Point
7
- *
8
- * Demonstrates the NEW namespaced module access:
9
- * - `system.facts.auth.token` instead of `system.facts.auth_token`
10
- * - `system.derive.data.userCount` instead of `system.derive.data_userCount`
11
- * - `system.events.auth.login({ token })` instead of `dispatch({ type: "auth_login", token })`
12
- *
13
- * Cross-module constraints work automatically:
14
- * - Data fetches when auth succeeds
15
- * - No asCombined() helper needed
16
- */
17
-
18
- import { el } from "@directive-run/el";
19
- import { getFacts, system } from "./system";
20
-
21
- // DOM Elements
22
-
23
- // Start the system
24
- system.start();
25
-
26
- // Update UI function
27
-
28
- // Subscribe to derivation changes using namespaced keys
29
- // Note: The internal keys are still prefixed (auth_status), so we use those for subscribe
30
- system.subscribe(
31
- [
32
- "auth_status",
33
- "auth_displayName",
34
- "data_status",
35
- "data_userCount",
36
- "ui_hasNotifications",
37
- ],
38
- () => {
39
- updateUI();
40
- },
41
- );
42
-
43
- // Also update on fact changes via polling (simple approach for this demo)
44
-
45
- // Event handlers using namespaced events accessor
46
-
47
-
48
- // Initial render
49
- updateUI();
50
-
51
- // Log to console for debugging
52
- console.log("Multi-Module Example Started (Namespaced Mode)");
53
- console.log("Try clicking Login to see the cross-module constraint in action:");
54
- console.log("1. Auth module validates token via facts.auth.*");
55
- console.log(
56
- "2. Data module automatically fetches users when facts.auth.isAuthenticated",
57
- );
58
- console.log("3. UI module effects react to facts.data.* changes");