@directive-run/knowledge 1.13.0 → 1.15.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 +2 -0
- package/ai/ai-agents-streaming.md +182 -149
- package/ai/ai-budget-resilience.md +299 -132
- package/ai/ai-communication.md +215 -197
- package/ai/ai-debug-observability.md +253 -173
- package/ai/ai-guardrails-memory.md +185 -153
- package/ai/ai-mcp-rag.md +199 -199
- package/ai/ai-multi-agent.md +247 -153
- package/ai/ai-orchestrator.md +344 -114
- package/ai/ai-security.md +282 -180
- package/ai/ai-tasks.md +3 -1
- package/ai/ai-testing-evals.md +357 -256
- package/core/anti-patterns.md +9 -2
- package/core/constraints.md +6 -2
- package/core/core-patterns.md +2 -0
- package/core/error-boundaries.md +2 -0
- package/core/history.md +2 -0
- package/core/multi-module.md +8 -3
- package/core/naming.md +15 -6
- package/core/plugins.md +2 -0
- package/core/react-adapter.md +250 -174
- package/core/resolvers.md +2 -0
- package/core/schema-types.md +2 -0
- package/core/system-api.md +2 -0
- package/core/testing.md +251 -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 +26 -3
- package/examples/debounce-constraints.ts +0 -95
- package/examples/multi-module.ts +0 -58
package/core/anti-patterns.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Anti-Patterns
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core` and `@directive-run/react` — hallucination-prone API patterns to avoid.
|
|
4
|
+
|
|
3
5
|
19 most common mistakes when generating Directive code, ranked by AI hallucination frequency. Every code generation MUST be checked against this list.
|
|
4
6
|
|
|
5
7
|
## 1. Unnecessary Type Casting on Facts/Derivations
|
|
@@ -113,11 +115,16 @@ createModule("timer", {
|
|
|
113
115
|
## 7. String-Based Event Dispatch
|
|
114
116
|
|
|
115
117
|
```typescript
|
|
116
|
-
// WRONG –
|
|
118
|
+
// WRONG – there is no two-argument string-keyed dispatch signature
|
|
117
119
|
system.dispatch("login", { token: "abc" });
|
|
118
120
|
|
|
119
|
-
// CORRECT – use the events accessor
|
|
121
|
+
// CORRECT – use the typed events accessor (preferred — autocomplete + payload typing)
|
|
120
122
|
system.events.login({ token: "abc" });
|
|
123
|
+
|
|
124
|
+
// ALSO VALID – the single-arg object form of dispatch() is supported when you
|
|
125
|
+
// need to forward a programmatically-built event. Prefer the events accessor
|
|
126
|
+
// for normal code.
|
|
127
|
+
system.dispatch({ type: "login", token: "abc" });
|
|
121
128
|
```
|
|
122
129
|
|
|
123
130
|
## 8. Direct Array/Object Mutation
|
package/core/constraints.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Constraints
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core` — constraint definition: `when` / `require`, async constraints with `deps`, priority, data-form predicates.
|
|
4
|
+
|
|
3
5
|
Constraints declare WHEN something is needed. They are the demand side of the constraint-resolver pattern. Constraints evaluate conditions against facts and emit requirements that resolvers fulfill.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "Should this be a constraint?"
|
|
@@ -22,8 +24,10 @@ constraints: {
|
|
|
22
24
|
// when() returns boolean – evaluated on every fact change
|
|
23
25
|
when: (facts) => facts.isAuthenticated && !facts.user,
|
|
24
26
|
|
|
25
|
-
// require – the requirement to emit when condition is true
|
|
26
|
-
|
|
27
|
+
// require – the requirement to emit when condition is true.
|
|
28
|
+
// Use the function form whenever you need to read facts —
|
|
29
|
+
// facts is NOT in scope inside the static object form.
|
|
30
|
+
require: (facts) => ({ type: "FETCH_USER", userId: facts.userId }),
|
|
27
31
|
},
|
|
28
32
|
},
|
|
29
33
|
```
|
package/core/core-patterns.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Core Patterns
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core` — modules, facts, derivations, effects, events, and the constraint-resolver loop.
|
|
4
|
+
|
|
3
5
|
How to think about building with Directive: modules, systems, and the constraint-resolver pattern.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "Where does this logic go?"
|
package/core/error-boundaries.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Error Boundaries
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core` — error boundaries, recovery strategies, lifecycle hooks, and circuit breakers.
|
|
4
|
+
|
|
3
5
|
How to handle errors in Directive: recovery strategies, error boundaries, lifecycle hooks, and the circuit breaker pattern.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "How should errors be handled?"
|
package/core/history.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# History & Snapshots
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core` — time-travel: snapshot, undo/redo, replay, export/import, changeset grouping.
|
|
4
|
+
|
|
3
5
|
Directive records fact changes as snapshots, enabling undo/redo, replay, export/import, and changeset grouping.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "Should I enable history?"
|
package/core/multi-module.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Multi-Module Systems
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core` — namespaced multi-module systems, cross-module deps, `facts.self.*`.
|
|
4
|
+
|
|
3
5
|
How to compose multiple modules into a namespaced system with cross-module type safety.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "Single or Multi-Module?"
|
|
@@ -303,13 +305,16 @@ system.registerModule("chat", chatModule.default);
|
|
|
303
305
|
|
|
304
306
|
## Cross-Module Events
|
|
305
307
|
|
|
306
|
-
Events are namespaced at the system level
|
|
308
|
+
Events are namespaced at the system level. **Prefer the typed events accessor** — it carries autocomplete and per-event payload typing.
|
|
307
309
|
|
|
308
310
|
```typescript
|
|
309
|
-
// Multi-module events
|
|
311
|
+
// Multi-module events — canonical form
|
|
310
312
|
system.events.auth.login({ token: "abc" });
|
|
311
313
|
system.events.cart.addItem({ id: "item-1", qty: 1 });
|
|
312
314
|
|
|
313
|
-
// dispatch()
|
|
315
|
+
// dispatch() is supported when you need to forward a programmatically-built
|
|
316
|
+
// event (e.g., replaying a serialized event). The string form
|
|
317
|
+
// (system.dispatch("login", payload)) does NOT exist — only the single-arg
|
|
318
|
+
// object form is valid.
|
|
314
319
|
system.dispatch({ type: "login", token: "abc" });
|
|
315
320
|
```
|
package/core/naming.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Naming Conventions
|
|
2
2
|
|
|
3
|
+
> Covers all `@directive-run/*` packages — terminology, parameter names, return-style rules.
|
|
4
|
+
|
|
3
5
|
Directive naming rules that AI coding assistants must follow. These are non-negotiable project conventions.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "What do I call this?"
|
|
@@ -68,14 +70,19 @@ resolve: async (req, ctx) => { /* ... */ },
|
|
|
68
70
|
|
|
69
71
|
## Return Style
|
|
70
72
|
|
|
71
|
-
### Always Use Braces
|
|
73
|
+
### Always Use Braces (for `if` blocks with `return`)
|
|
74
|
+
|
|
75
|
+
The brace rule applies to control-flow blocks — not to arrow-expression bodies.
|
|
72
76
|
|
|
73
|
-
|
|
77
|
+
**Arrow expressions** (single-line derivations, predicates, computed
|
|
78
|
+
requirements): the concise form is preferred. No braces, no explicit
|
|
79
|
+
`return`.
|
|
74
80
|
|
|
75
81
|
```typescript
|
|
76
|
-
//
|
|
82
|
+
// CORRECT — single-line arrow expressions stay concise
|
|
77
83
|
derive: {
|
|
78
84
|
isReady: (facts) => facts.phase === "ready",
|
|
85
|
+
greeting: (facts) => `Hi, ${facts.name}!`,
|
|
79
86
|
},
|
|
80
87
|
|
|
81
88
|
constraints: {
|
|
@@ -84,14 +91,16 @@ constraints: {
|
|
|
84
91
|
require: { type: "PROCESS" },
|
|
85
92
|
},
|
|
86
93
|
},
|
|
94
|
+
```
|
|
87
95
|
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
**Control-flow statements** (`if`, `for`, `while`): braces required, even
|
|
97
|
+
for single-line bodies. Single-line `if (x) return y` shapes are never used.
|
|
90
98
|
|
|
99
|
+
```typescript
|
|
91
100
|
// WRONG – single-line if return
|
|
92
101
|
if (facts.user) return "ready";
|
|
93
102
|
|
|
94
|
-
// CORRECT – always
|
|
103
|
+
// CORRECT – always wrap the body in braces
|
|
95
104
|
if (facts.user) {
|
|
96
105
|
return "ready";
|
|
97
106
|
}
|
package/core/plugins.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Plugins
|
|
2
2
|
|
|
3
|
+
> Covers `@directive-run/core/plugins` — plugin authoring + built-ins (logging, devtools, persistence, audit-ledger, observability, OTLP).
|
|
4
|
+
|
|
3
5
|
Plugins extend Directive systems with cross-cutting functionality like logging, persistence, devtools, and resilience patterns.
|
|
4
6
|
|
|
5
7
|
## Decision Tree: "Which plugin do I need?"
|