@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.
- package/README.md +50 -15
- package/ai/ai-adapters.md +7 -0
- package/ai/ai-agents-streaming.md +187 -149
- package/ai/ai-budget-resilience.md +305 -132
- package/ai/ai-communication.md +220 -197
- package/ai/ai-debug-observability.md +259 -173
- package/ai/ai-guardrails-memory.md +191 -153
- package/ai/ai-mcp-rag.md +204 -199
- package/ai/ai-multi-agent.md +254 -153
- package/ai/ai-orchestrator.md +353 -114
- package/ai/ai-security.md +287 -180
- package/ai/ai-tasks.md +8 -1
- package/ai/ai-testing-evals.md +363 -256
- package/core/anti-patterns.md +18 -2
- package/core/constraints.md +13 -2
- package/core/core-patterns.md +12 -0
- package/core/error-boundaries.md +8 -0
- package/core/history.md +7 -0
- package/core/multi-module.md +15 -3
- package/core/naming.md +128 -90
- package/core/plugins.md +7 -0
- package/core/react-adapter.md +256 -174
- package/core/resolvers.md +10 -0
- package/core/schema-types.md +8 -0
- package/core/system-api.md +10 -0
- package/core/testing.md +257 -143
- package/examples/checkers.ts +15 -16
- package/examples/contact-form.ts +2 -2
- package/examples/counter-react.ts +1 -1
- package/examples/counter-svelte.ts +1 -1
- package/examples/counter-vue.ts +1 -1
- package/examples/counter.ts +1 -1
- package/examples/data-triggers.ts +4 -4
- package/examples/feature-flags.ts +2 -2
- package/examples/form-wizard.ts +2 -2
- package/examples/newsletter.ts +2 -2
- package/examples/server.ts +2 -2
- package/examples/shopping-cart.ts +1 -1
- package/examples/topic-guard.ts +1 -1
- package/package.json +3 -3
- package/sitemap.md +17 -11
- package/examples/debounce-constraints.ts +0 -95
- package/examples/multi-module.ts +0 -58
package/examples/counter-vue.ts
CHANGED
package/examples/counter.ts
CHANGED
|
@@ -98,10 +98,10 @@ const trafficLight = createModule("traffic", {
|
|
|
98
98
|
transition: {
|
|
99
99
|
requirement: "TRANSITION",
|
|
100
100
|
key: ["to"],
|
|
101
|
-
resolve: async (req,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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 (
|
|
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 (
|
|
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
|
);
|
package/examples/form-wizard.ts
CHANGED
|
@@ -227,7 +227,7 @@ export const wizardModule = createModule("wizard", {
|
|
|
227
227
|
resolvers: {
|
|
228
228
|
advanceStep: {
|
|
229
229
|
requirement: "ADVANCE_STEP",
|
|
230
|
-
resolve: async (
|
|
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 (
|
|
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;
|
package/examples/newsletter.ts
CHANGED
|
@@ -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 (
|
|
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 (
|
|
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 = "";
|
package/examples/server.ts
CHANGED
|
@@ -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 (
|
|
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 (
|
|
165
|
+
} catch (_error) {
|
|
166
166
|
res.status(500).json({ error: "Verification failed" });
|
|
167
167
|
} finally {
|
|
168
168
|
system.destroy();
|
package/examples/topic-guard.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directive-run/knowledge",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
55
|
-
"@directive-run/ai": "1.
|
|
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
|
-
###
|
|
68
|
-
- [
|
|
69
|
-
- [
|
|
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
|
-
- [
|
|
75
|
-
|
|
76
|
-
|
|
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
|
package/examples/multi-module.ts
DELETED
|
@@ -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");
|