domain-knowledge-kit 0.2.8 → 0.2.10
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 +34 -139
- package/dist/cli.js +10 -0
- package/dist/cli.js.map +1 -1
- package/dist/features/audit/commands/stats.d.ts +3 -0
- package/dist/features/audit/commands/stats.d.ts.map +1 -0
- package/dist/features/audit/commands/stats.js +90 -0
- package/dist/features/audit/commands/stats.js.map +1 -0
- package/dist/features/pipeline/commands/validate.d.ts.map +1 -1
- package/dist/features/pipeline/commands/validate.js +32 -13
- package/dist/features/pipeline/commands/validate.js.map +1 -1
- package/dist/features/query/commands/graph.d.ts +3 -0
- package/dist/features/query/commands/graph.d.ts.map +1 -0
- package/dist/features/query/commands/graph.js +86 -0
- package/dist/features/query/commands/graph.js.map +1 -0
- package/dist/features/query/commands/summary.d.ts +7 -0
- package/dist/features/query/commands/summary.d.ts.map +1 -0
- package/dist/features/query/commands/summary.js +43 -0
- package/dist/features/query/commands/summary.js.map +1 -0
- package/dist/features/refactor/commands/rename.d.ts +3 -0
- package/dist/features/refactor/commands/rename.d.ts.map +1 -0
- package/dist/features/refactor/commands/rename.js +152 -0
- package/dist/features/refactor/commands/rename.js.map +1 -0
- package/dist/features/refactor/commands/rm.d.ts +3 -0
- package/dist/features/refactor/commands/rm.d.ts.map +1 -0
- package/dist/features/refactor/commands/rm.js +93 -0
- package/dist/features/refactor/commands/rm.js.map +1 -0
- package/dist/features/scaffold/commands/add-item.d.ts +11 -0
- package/dist/features/scaffold/commands/add-item.d.ts.map +1 -1
- package/dist/features/scaffold/commands/add-item.js +119 -23
- package/dist/features/scaffold/commands/add-item.js.map +1 -1
- package/dist/features/scaffold/commands/new-adr.d.ts.map +1 -1
- package/dist/features/scaffold/commands/new-adr.js +19 -2
- package/dist/features/scaffold/commands/new-adr.js.map +1 -1
- package/dist/features/scaffold/commands/new-context.d.ts.map +1 -1
- package/dist/features/scaffold/commands/new-context.js +10 -0
- package/dist/features/scaffold/commands/new-context.js.map +1 -1
- package/dist/features/scaffold/commands/new-domain.d.ts.map +1 -1
- package/dist/features/scaffold/commands/new-domain.js +9 -0
- package/dist/features/scaffold/commands/new-domain.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,147 +1,42 @@
|
|
|
1
1
|
# Domain Knowledge Kit
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- **
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
EOF
|
|
29
|
-
|
|
30
|
-
# One file per domain item
|
|
31
|
-
cat > .dkk/domain/contexts/ordering/events/OrderPlaced.yml << 'EOF'
|
|
32
|
-
name: OrderPlaced
|
|
33
|
-
description: Raised when a customer order is confirmed.
|
|
34
|
-
raised_by: Order
|
|
35
|
-
EOF
|
|
36
|
-
|
|
37
|
-
cat > .dkk/domain/contexts/ordering/commands/PlaceOrder.yml << 'EOF'
|
|
38
|
-
name: PlaceOrder
|
|
39
|
-
description: Submit a new customer order.
|
|
40
|
-
handled_by: Order
|
|
41
|
-
EOF
|
|
42
|
-
|
|
43
|
-
cat > .dkk/domain/contexts/ordering/aggregates/Order.yml << 'EOF'
|
|
44
|
-
name: Order
|
|
45
|
-
description: Manages order state and invariants.
|
|
46
|
-
handles:
|
|
47
|
-
commands:
|
|
48
|
-
- PlaceOrder
|
|
49
|
-
emits:
|
|
50
|
-
events:
|
|
51
|
-
- OrderPlaced
|
|
52
|
-
EOF
|
|
53
|
-
|
|
54
|
-
# Register it in .dkk/domain/index.yml
|
|
55
|
-
# Add "- name: ordering" to the contexts array
|
|
56
|
-
|
|
57
|
-
# Validate and render
|
|
58
|
-
dkk validate
|
|
59
|
-
dkk render
|
|
60
|
-
|
|
61
|
-
# Explore
|
|
62
|
-
dkk search "order"
|
|
63
|
-
dkk show ordering.OrderPlaced
|
|
64
|
-
dkk related ordering.Order
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
→ **[Full Getting Started Guide](docs/getting-started.md)** — step-by-step walkthrough with examples.
|
|
3
|
+
> *Humans design the domain. AI agents align the codebase.*
|
|
4
|
+
|
|
5
|
+
## Philosophy
|
|
6
|
+
|
|
7
|
+
### AI agents love structure
|
|
8
|
+
|
|
9
|
+
Large language models thrive with well-structured, unambiguous context. A flat codebase gives them syntax; a structured domain model gives them **meaning**. DKK makes your domain a first-class, machine-readable citizen of your repository.
|
|
10
|
+
|
|
11
|
+
### Humans can define domain events easily
|
|
12
|
+
|
|
13
|
+
You don't need a diagram tool or a modeling session. Writing `OrderPlaced` in a YAML file — with a one-line description and a reference to the aggregate that emits it — is how humans naturally think in DDD. Defining events, commands, and policies in plain YAML reveals the bigger picture without drowning in implementation details.
|
|
14
|
+
|
|
15
|
+
### Reading domain models beats reading code
|
|
16
|
+
|
|
17
|
+
Business logic spread across services, handlers, and database schemas is hard to reason about holistically. A domain model is a curated, intentional view of *what your system does and why* — not *how* it does it. DKK keeps that view always up-to-date and always searchable.
|
|
18
|
+
|
|
19
|
+
### Keeping ADRs, even deprecated ones, preserves project memory
|
|
20
|
+
|
|
21
|
+
Architectural decisions aren't born in a vacuum. Understanding *why* a choice was made matters as much as knowing *what* the choice was. Deprecated ADRs aren't noise — they are the institutional memory that prevents teams (and AI agents) from relitigating past decisions.
|
|
22
|
+
|
|
23
|
+
### Easy-to-reach, detailed, colocated knowledge for AI agents
|
|
24
|
+
|
|
25
|
+
Knowledge that lives next to the code is knowledge that gets used. DKK colocates your domain model, ADRs, and generated docs inside the repository itself. AI agents can discover, query, and traverse this knowledge without leaving the codebase — making every interaction domain-aware.
|
|
26
|
+
|
|
27
|
+
---
|
|
68
28
|
|
|
69
29
|
## Documentation
|
|
70
30
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
|
74
|
-
|
|
75
|
-
| **[
|
|
76
|
-
| **[
|
|
77
|
-
| **[
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
dkk validate # Schema + cross-reference validation
|
|
83
|
-
dkk render # Validate → render docs → rebuild search index
|
|
84
|
-
dkk search "payment" # Full-text search with ranking
|
|
85
|
-
dkk show ordering.Order # Display full item definition
|
|
86
|
-
dkk related ordering.Order # Graph traversal of connected items
|
|
87
|
-
dkk list --type event # List all events across contexts
|
|
88
|
-
dkk init # Set up AI agent onboarding
|
|
89
|
-
dkk prime # Output agent context to stdout
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
→ **[Full CLI Reference](docs/cli-reference.md)**
|
|
93
|
-
|
|
94
|
-
## AI Agent Integration
|
|
95
|
-
|
|
96
|
-
DKK has first-class support for AI coding agents. Two commands get you set up:
|
|
97
|
-
|
|
98
|
-
```bash
|
|
99
|
-
dkk init # Add a DKK section to AGENTS.md (idempotent)
|
|
100
|
-
dkk prime # Output full domain context for AI consumption
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Agents can then search, show, and traverse your domain model — making domain-aware decisions when writing, reviewing, or refactoring code. DKK also ships with GitHub Copilot instructions, reusable agent prompts, and a portable agent skill.
|
|
104
|
-
|
|
105
|
-
→ **[AI Agent Integration Guide](docs/ai-agent-integration.md)**
|
|
106
|
-
|
|
107
|
-
## Directory Layout
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
.dkk/ # Domain model + generated + managed
|
|
111
|
-
domain/ # Domain model (YAML)
|
|
112
|
-
index.yml # Contexts + flows
|
|
113
|
-
actors.yml # Global actors
|
|
114
|
-
contexts/ # Bounded contexts (one dir each)
|
|
115
|
-
<name>/ # Context directory
|
|
116
|
-
context.yml # Context metadata + glossary
|
|
117
|
-
events/ # One .yml file per event
|
|
118
|
-
commands/ # One .yml file per command
|
|
119
|
-
aggregates/ # One .yml file per aggregate
|
|
120
|
-
policies/ # One .yml file per policy
|
|
121
|
-
read-models/ # One .yml file per read model
|
|
122
|
-
adr/ # Architecture Decision Records
|
|
123
|
-
docs/ # Generated docs (do not edit)
|
|
124
|
-
src/ # Source code (vertical slices)
|
|
125
|
-
tools/dkk/ # Schemas + templates
|
|
126
|
-
schema/ # JSON Schemas for validation
|
|
127
|
-
templates/ # Handlebars templates for rendering
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Contributing / Local Development
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
npm install
|
|
134
|
-
|
|
135
|
-
# Run directly via tsx (no build step needed)
|
|
136
|
-
npm run dev -- validate
|
|
137
|
-
npm run dev -- render
|
|
138
|
-
|
|
139
|
-
# Or build first
|
|
140
|
-
npm run build
|
|
141
|
-
npx dkk validate
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
The source code uses **vertical feature slices** — each feature (`query`, `adr`, `pipeline`, `agent`) owns its commands, logic, and tests. Cross-cutting infrastructure lives in `shared/`.
|
|
31
|
+
All technical details, CLI references, and integration guides live in the [`docs/`](docs/) folder.
|
|
32
|
+
|
|
33
|
+
| Guide | What It Covers |
|
|
34
|
+
|-------|----------------|
|
|
35
|
+
| **[Getting Started](docs/getting-started.md)** | Installation, first context, quality gates |
|
|
36
|
+
| **[Domain Modeling](docs/domain-modeling.md)** | YAML structure, item types, naming conventions |
|
|
37
|
+
| **[CLI Reference](docs/cli-reference.md)** | Every command and flag |
|
|
38
|
+
| **[ADR Guide](docs/adr-guide.md)** | Writing, linking, and querying ADRs |
|
|
39
|
+
| **[AI Agent Integration](docs/ai-agent-integration.md)** | Onboarding agents, context-efficient retrieval |
|
|
145
40
|
|
|
146
41
|
## License
|
|
147
42
|
|
package/dist/cli.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { registerList } from "./features/query/commands/list.js";
|
|
4
4
|
import { registerShow } from "./features/query/commands/show.js";
|
|
5
|
+
import { registerSummary } from "./features/query/commands/summary.js";
|
|
5
6
|
import { registerSearch } from "./features/query/commands/search.js";
|
|
6
7
|
import { registerRelated } from "./features/query/commands/related.js";
|
|
8
|
+
import { registerGraph } from "./features/query/commands/graph.js";
|
|
7
9
|
import { registerValidate } from "./features/pipeline/commands/validate.js";
|
|
8
10
|
import { registerRender } from "./features/pipeline/commands/render.js";
|
|
9
11
|
import { registerAdrShow } from "./features/adr/commands/adr-show.js";
|
|
@@ -14,6 +16,9 @@ import { registerNewDomain } from "./features/scaffold/commands/new-domain.js";
|
|
|
14
16
|
import { registerNewContext } from "./features/scaffold/commands/new-context.js";
|
|
15
17
|
import { registerNewAdr } from "./features/scaffold/commands/new-adr.js";
|
|
16
18
|
import { registerAddItem } from "./features/scaffold/commands/add-item.js";
|
|
19
|
+
import { registerRename } from "./features/refactor/commands/rename.js";
|
|
20
|
+
import { registerRm } from "./features/refactor/commands/rm.js";
|
|
21
|
+
import { registerStats } from "./features/audit/commands/stats.js";
|
|
17
22
|
import { formatCliError } from "./shared/errors.js";
|
|
18
23
|
/** Whether to show full stack traces (set DEBUG=1 in env). */
|
|
19
24
|
const DEBUG = Boolean(process.env.DEBUG);
|
|
@@ -26,12 +31,17 @@ program
|
|
|
26
31
|
// Top-level commands
|
|
27
32
|
registerList(program);
|
|
28
33
|
registerShow(program);
|
|
34
|
+
registerSummary(program);
|
|
29
35
|
registerSearch(program);
|
|
30
36
|
registerRelated(program);
|
|
37
|
+
registerGraph(program);
|
|
31
38
|
registerValidate(program);
|
|
32
39
|
registerRender(program);
|
|
33
40
|
registerInit(program);
|
|
34
41
|
registerPrime(program);
|
|
42
|
+
registerRename(program);
|
|
43
|
+
registerRm(program);
|
|
44
|
+
registerStats(program);
|
|
35
45
|
// ADR sub-command group
|
|
36
46
|
const adrCmd = program
|
|
37
47
|
.command("adr")
|
package/dist/c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AY,KAAK,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAC/C,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../../src/features/audit/commands/stats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAIhD,wBAAgB,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CA4EhD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { loadDomainModel } from "../../../shared/loader.js";
|
|
2
|
+
import { DomainGraph } from "../../../shared/graph.js";
|
|
3
|
+
export function registerStats(program) {
|
|
4
|
+
program
|
|
5
|
+
.command("stats")
|
|
6
|
+
.description("Print domain model statistics and potential orphaned items")
|
|
7
|
+
.option("-r, --root <path>", "Override repository root")
|
|
8
|
+
.action((opts) => {
|
|
9
|
+
const model = loadDomainModel({ root: opts.root });
|
|
10
|
+
const graph = DomainGraph.from(model);
|
|
11
|
+
const stats = {
|
|
12
|
+
contexts: 0,
|
|
13
|
+
events: 0,
|
|
14
|
+
commands: 0,
|
|
15
|
+
aggregates: 0,
|
|
16
|
+
policies: 0,
|
|
17
|
+
readModels: 0,
|
|
18
|
+
actors: 0,
|
|
19
|
+
adrs: 0,
|
|
20
|
+
flows: 0,
|
|
21
|
+
orphaned: []
|
|
22
|
+
};
|
|
23
|
+
for (const [id, node] of graph.nodes) {
|
|
24
|
+
switch (node.kind) {
|
|
25
|
+
case "context":
|
|
26
|
+
stats.contexts++;
|
|
27
|
+
break;
|
|
28
|
+
case "event":
|
|
29
|
+
stats.events++;
|
|
30
|
+
break;
|
|
31
|
+
case "command":
|
|
32
|
+
stats.commands++;
|
|
33
|
+
break;
|
|
34
|
+
case "aggregate":
|
|
35
|
+
stats.aggregates++;
|
|
36
|
+
break;
|
|
37
|
+
case "policy":
|
|
38
|
+
stats.policies++;
|
|
39
|
+
break;
|
|
40
|
+
case "read_model":
|
|
41
|
+
stats.readModels++;
|
|
42
|
+
break;
|
|
43
|
+
case "actor":
|
|
44
|
+
stats.actors++;
|
|
45
|
+
break;
|
|
46
|
+
case "adr":
|
|
47
|
+
stats.adrs++;
|
|
48
|
+
break;
|
|
49
|
+
case "flow":
|
|
50
|
+
stats.flows++;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
// Check for orphaned items (items with only 1 edge = "contains" from context,
|
|
54
|
+
// meaning they don't participate in handles/emits/triggers/etc with other items)
|
|
55
|
+
if (node.kind !== "context" && node.kind !== "actor" && node.kind !== "adr" && node.kind !== "flow" && node.kind !== "glossary") {
|
|
56
|
+
let connectionCount = 0;
|
|
57
|
+
for (const edge of graph.edges) {
|
|
58
|
+
if ((edge.from === id || edge.to === id) && edge.label !== "contains") {
|
|
59
|
+
connectionCount++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (connectionCount === 0) {
|
|
63
|
+
stats.orphaned.push(id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
console.log(`\n📊 Domain Model Statistics\n`);
|
|
68
|
+
console.log(` Contexts: ${stats.contexts}`);
|
|
69
|
+
console.log(` Events: ${stats.events}`);
|
|
70
|
+
console.log(` Commands: ${stats.commands}`);
|
|
71
|
+
console.log(` Aggregates: ${stats.aggregates}`);
|
|
72
|
+
console.log(` Policies: ${stats.policies}`);
|
|
73
|
+
console.log(` Read Models: ${stats.readModels}`);
|
|
74
|
+
console.log(` Actors: ${stats.actors}`);
|
|
75
|
+
console.log(` Flows: ${stats.flows}`);
|
|
76
|
+
console.log(` ADRs: ${stats.adrs}`);
|
|
77
|
+
console.log(`\n🔍 Health Check`);
|
|
78
|
+
if (stats.orphaned.length > 0) {
|
|
79
|
+
console.log(` Found ${stats.orphaned.length} potentially orphaned items (no relationships):`);
|
|
80
|
+
for (const orphan of stats.orphaned) {
|
|
81
|
+
console.log(` - ${orphan}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.log(` No orphaned items found! All clear.`);
|
|
86
|
+
}
|
|
87
|
+
console.log("");
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../../src/features/audit/commands/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,MAAM,UAAU,aAAa,CAAC,OAAY;IACxC,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,4DAA4D,CAAC;SACzE,MAAM,CAAC,mBAAmB,EAAE,0BAA0B,CAAC;SACvD,MAAM,CACL,CACE,IAAuB,EACvB,EAAE;QACF,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEtC,MAAM,KAAK,GAAG;YACV,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,CAAC;YACX,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE,CAAC;YACX,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,CAAC;YACT,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,CAAC;YACR,QAAQ,EAAE,EAAc;SAC3B,CAAC;QAEF,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACn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G,CAAC,uCAAuC,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/pipeline/commands/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAIhD,0CAA0C;AAC1C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/pipeline/commands/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAIhD,0CAA0C;AAC1C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAiEnD"}
|
|
@@ -3,40 +3,59 @@ import { validateDomainModel } from "../validator.js";
|
|
|
3
3
|
/** Register the `validate` subcommand. */
|
|
4
4
|
export function registerValidate(program) {
|
|
5
5
|
program
|
|
6
|
-
.command("validate")
|
|
6
|
+
.command("validate [id]")
|
|
7
7
|
.description("Validate domain YAML against schemas and cross-references")
|
|
8
8
|
.option("--warn-missing-fields", "Warn about events/commands with no fields")
|
|
9
9
|
.option("--json", "Output as JSON")
|
|
10
|
+
.option("--minify", "Minify JSON output (useful for AI agents)")
|
|
10
11
|
.option("-r, --root <path>", "Override repository root")
|
|
11
|
-
.action((opts) => {
|
|
12
|
+
.action((id, opts) => {
|
|
12
13
|
const model = loadDomainModel({ root: opts.root });
|
|
13
14
|
const result = validateDomainModel(model, {
|
|
14
15
|
warnMissingFields: opts.warnMissingFields,
|
|
15
16
|
});
|
|
17
|
+
let { valid, errors, warnings } = result;
|
|
18
|
+
if (id) {
|
|
19
|
+
const isMatch = (p) => {
|
|
20
|
+
if (!p)
|
|
21
|
+
return false;
|
|
22
|
+
if (p === `actor:${id}` || p === `adr:${id}` || p === `context:${id}`)
|
|
23
|
+
return true;
|
|
24
|
+
const [ctx, name] = id.split(".");
|
|
25
|
+
if (ctx && name) {
|
|
26
|
+
return p.startsWith(`context:${ctx}.`) && p.endsWith(`:${name}`);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
errors = errors.filter((e) => isMatch(e.path));
|
|
31
|
+
warnings = warnings.filter((w) => isMatch(w.path));
|
|
32
|
+
valid = errors.length === 0;
|
|
33
|
+
}
|
|
16
34
|
if (opts.json) {
|
|
17
|
-
|
|
18
|
-
valid
|
|
19
|
-
errors:
|
|
20
|
-
warnings:
|
|
21
|
-
}
|
|
22
|
-
|
|
35
|
+
const payload = {
|
|
36
|
+
valid,
|
|
37
|
+
errors: errors.map((e) => ({ message: e.message, path: e.path ?? null })),
|
|
38
|
+
warnings: warnings.map((w) => ({ message: w.message, path: w.path ?? null })),
|
|
39
|
+
};
|
|
40
|
+
console.log(JSON.stringify(payload, null, opts.minify ? 0 : 2));
|
|
41
|
+
if (!valid)
|
|
23
42
|
process.exit(1);
|
|
24
43
|
return;
|
|
25
44
|
}
|
|
26
45
|
// Print warnings
|
|
27
|
-
for (const w of
|
|
46
|
+
for (const w of warnings) {
|
|
28
47
|
const loc = w.path ? ` (${w.path})` : "";
|
|
29
48
|
console.warn(`\u26a0 ${w.message}${loc}`);
|
|
30
49
|
}
|
|
31
50
|
// Print errors
|
|
32
|
-
for (const e of
|
|
51
|
+
for (const e of errors) {
|
|
33
52
|
const loc = e.path ? ` (${e.path})` : "";
|
|
34
53
|
console.error(`\u2717 ${e.message}${loc}`);
|
|
35
54
|
}
|
|
36
55
|
// Summary
|
|
37
|
-
const warnCount =
|
|
38
|
-
const errCount =
|
|
39
|
-
if (
|
|
56
|
+
const warnCount = warnings.length;
|
|
57
|
+
const errCount = errors.length;
|
|
58
|
+
if (valid) {
|
|
40
59
|
console.log(`\n\u2713 Validation passed.${warnCount > 0 ? ` (${warnCount} warning(s))` : ""}\n`);
|
|
41
60
|
}
|
|
42
61
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/features/pipeline/commands/validate.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,0CAA0C;AAC1C,MAAM,UAAU,gBAAgB,CAAC,OAAY;IAC3C,OAAO;SACJ,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/features/pipeline/commands/validate.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,0CAA0C;AAC1C,MAAM,UAAU,gBAAgB,CAAC,OAAY;IAC3C,OAAO;SACJ,OAAO,CAAC,eAAe,CAAC;SACxB,WAAW,CAAC,2DAA2D,CAAC;SACxE,MAAM,CAAC,uBAAuB,EAAE,2CAA2C,CAAC;SAC5E,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC;SAClC,MAAM,CAAC,UAAU,EAAE,2CAA2C,CAAC;SAC/D,MAAM,CAAC,mBAAmB,EAAE,0BAA0B,CAAC;SACvD,MAAM,CAAC,CAAC,EAAsB,EAAE,IAAsF,EAAE,EAAE;QACzH,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,EAAE;YACxC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC1C,CAAC,CAAC;QAEH,IAAI,EAAE,KAAK,EAAE,MAAM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C,CAAC;QACnG,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,+BAA+B,QAAQ,cAAc,SAAS,gBAAgB,CAAC,CAAC;YAC9F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../../src/features/query/commands/graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAUhD,wBAAgB,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CA6EhD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { loadDomainModel } from "../../../shared/loader.js";
|
|
4
|
+
import { DomainGraph } from "../../../shared/graph.js";
|
|
5
|
+
function escapeMermaidId(id) {
|
|
6
|
+
return id.replace(/[\.\-]/g, "_");
|
|
7
|
+
}
|
|
8
|
+
export function registerGraph(program) {
|
|
9
|
+
program
|
|
10
|
+
.command("graph")
|
|
11
|
+
.description("Generate a Mermaid.js flowchart of the domain model")
|
|
12
|
+
.option("-o, --output <file>", "Output file path (default: .dkk/docs/graph.md)")
|
|
13
|
+
.option("-d, --depth <n>", "Maximum traversal depth for large graphs", parseInt, 3)
|
|
14
|
+
.option("-r, --root <path>", "Override repository root")
|
|
15
|
+
.action((opts) => {
|
|
16
|
+
const model = loadDomainModel({ root: opts.root });
|
|
17
|
+
const graph = DomainGraph.from(model);
|
|
18
|
+
const outPath = opts.output || (opts.root ? join(opts.root, ".dkk", "docs", "graph.md") : join(process.cwd(), ".dkk", "docs", "graph.md"));
|
|
19
|
+
const lines = ["```mermaid", "flowchart TD"];
|
|
20
|
+
// Write nodes
|
|
21
|
+
const writtenNodes = new Set();
|
|
22
|
+
for (const [id, node] of graph.nodes) {
|
|
23
|
+
const mId = escapeMermaidId(id);
|
|
24
|
+
writtenNodes.add(mId);
|
|
25
|
+
const label = node.name;
|
|
26
|
+
let shape = `[${label}]`;
|
|
27
|
+
switch (node.kind) {
|
|
28
|
+
case "event":
|
|
29
|
+
shape = `> ${label} ]`;
|
|
30
|
+
break;
|
|
31
|
+
case "command":
|
|
32
|
+
shape = `([${label}])`;
|
|
33
|
+
break;
|
|
34
|
+
case "aggregate":
|
|
35
|
+
shape = `[[${label}]]`;
|
|
36
|
+
break;
|
|
37
|
+
case "policy":
|
|
38
|
+
shape = `{{${label}}}`;
|
|
39
|
+
break;
|
|
40
|
+
case "read_model":
|
|
41
|
+
shape = `[(${label})]`;
|
|
42
|
+
break;
|
|
43
|
+
case "actor":
|
|
44
|
+
shape = `(( ${label} ))`;
|
|
45
|
+
break;
|
|
46
|
+
case "flow":
|
|
47
|
+
shape = `[[${label}]]`;
|
|
48
|
+
break;
|
|
49
|
+
case "adr":
|
|
50
|
+
shape = `[\\${label}\\]`;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
lines.push(` ${mId}${shape}`);
|
|
54
|
+
}
|
|
55
|
+
lines.push("\n %% Relationships");
|
|
56
|
+
// Write edges
|
|
57
|
+
for (const edge of graph.edges) {
|
|
58
|
+
// Filter out internal structural edges
|
|
59
|
+
if (edge.label === "contains" || edge.label === "flow_next" || edge.label === "adr_ref") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const from = escapeMermaidId(edge.from);
|
|
63
|
+
const to = escapeMermaidId(edge.to);
|
|
64
|
+
let link = `-->`;
|
|
65
|
+
if (edge.label === "subscribes_to" || edge.label === "used_by") {
|
|
66
|
+
link = `-.->`;
|
|
67
|
+
}
|
|
68
|
+
else if (edge.label === "handles") {
|
|
69
|
+
link = `==>`;
|
|
70
|
+
}
|
|
71
|
+
lines.push(` ${from} ${link}|${edge.label}| ${to}`);
|
|
72
|
+
}
|
|
73
|
+
lines.push("```\n");
|
|
74
|
+
const content = lines.join("\n");
|
|
75
|
+
try {
|
|
76
|
+
writeFileSync(outPath, content, "utf-8");
|
|
77
|
+
console.log(`Generated Mermaid graph at ${outPath}`);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
81
|
+
console.error(`Failed to write graph to ${outPath}:`, msg);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../../../src/features/query/commands/graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,SAAS,eAAe,CAAC,EAAU;IAC/B,OAAO,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAY;IACxC,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,qDAAqD,CAAC;SAClE,MAAM,CAAC,qBAAqB,EAAE,gDAAgD,CAAC;SAC/E,MAAM,CAAC,iBAAiB,EAAE,0CAA0C,EAAE,QAAQ,EAAE,CAAC,CAAC;SAClF,MAAM,CAAC,mBAAmB,EAAE,0BAA0B,CAAC;SACvD,MAAM,CACL,CACE,IAAuD,EACvD,EAAE;QACF,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CA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8BAA8B,OAAO,EAAE,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACnB,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,OAAO,CAAC,KAAK,CAAC,4BAA4B,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;YAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,CACF,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `domain summary <id>` command — concise overview of an item.
|
|
3
|
+
*/
|
|
4
|
+
import type { Command as Cmd } from "commander";
|
|
5
|
+
/** Register the `summary` subcommand. */
|
|
6
|
+
export declare function registerSummary(program: Cmd): void;
|
|
7
|
+
//# sourceMappingURL=summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../../src/features/query/commands/summary.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAIhD,yCAAyC;AACzC,wBAAgB,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAwClD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { loadDomainModel } from "../../../shared/loader.js";
|
|
2
|
+
import { DomainGraph } from "../../../shared/graph.js";
|
|
3
|
+
/** Register the `summary` subcommand. */
|
|
4
|
+
export function registerSummary(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("summary <id>")
|
|
7
|
+
.description("Show a concise summary of a domain item (useful for AI context)")
|
|
8
|
+
.option("--json", "Output as JSON")
|
|
9
|
+
.option("--minify", "Minify JSON output")
|
|
10
|
+
.option("-r, --root <path>", "Override repository root")
|
|
11
|
+
.action((id, opts) => {
|
|
12
|
+
const model = loadDomainModel({ root: opts.root });
|
|
13
|
+
const graph = DomainGraph.from(model);
|
|
14
|
+
const node = graph.nodes.get(id);
|
|
15
|
+
if (!node) {
|
|
16
|
+
if (opts.json) {
|
|
17
|
+
console.log(JSON.stringify({ error: `Item "${id}" not found` }, null, opts.minify ? 0 : 2));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.error(`Error: Item "${id}" not found.`);
|
|
21
|
+
}
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const related = Array.from(graph.getRelated(id, 1));
|
|
25
|
+
if (opts.json) {
|
|
26
|
+
const payload = {
|
|
27
|
+
id: node.id,
|
|
28
|
+
name: node.name,
|
|
29
|
+
kind: node.kind,
|
|
30
|
+
context: node.context,
|
|
31
|
+
related,
|
|
32
|
+
};
|
|
33
|
+
console.log(JSON.stringify(payload, null, opts.minify ? 0 : 2));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log(`\n# [${node.kind}] ${node.name}${node.context ? ` (Context: ${node.context})` : ""}\n`);
|
|
37
|
+
console.log(`Related (${related.length}):`);
|
|
38
|
+
for (const r of related)
|
|
39
|
+
console.log(` - ${r}`);
|
|
40
|
+
console.log();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../../../src/features/query/commands/summary.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,yCAAyC;AACzC,MAAM,UAAU,eAAe,CAAC,OAAY;IAC1C,OAAO;SACJ,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,iEAAiE,CAAC;SAC9E,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC;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