ark-runtime-kernel 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pedro Knigge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,328 @@
1
+ <div align="center">
2
+
3
+ # ๐Ÿ›๏ธ Ark โ€” Architectural Runtime Kernel
4
+
5
+ **Make your architecture a machine-readable, enforceable contract** โ€”<br/>
6
+ respected by AI agents at write time, CI at merge time, and the runtime itself.
7
+
8
+ [![CI](https://github.com/pedroknigge/ark/actions/workflows/ci.yml/badge.svg)](https://github.com/pedroknigge/ark/actions/workflows/ci.yml)
9
+ [![npm](https://img.shields.io/npm/v/ark-runtime-kernel?color=cb3837&label=npm)](https://www.npmjs.com/package/ark-runtime-kernel)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
11
+ ![Node](https://img.shields.io/badge/node-%3E%3D18-339933?logo=node.js)
12
+ ![TypeScript](https://img.shields.io/badge/TypeScript-first-3178c6?logo=typescript&logoColor=white)
13
+ ![Zero deps](https://img.shields.io/badge/dependencies-0-success)
14
+
15
+ **Zero runtime dependencies** ยท TypeScript-first ยท Hexagonal + Event-Driven + DDD governance kernel
16
+
17
+ [Quick Start](#60-second-setup) ยท [The Three Gates](#the-three-gates-visual) ยท [AI Write Gate](#ai-write-path-gate-ark-mcp) ยท [CI Gate](#ark-check--the-ci-gate) ยท [Docs](#documentation)
18
+
19
+ </div>
20
+
21
+ ---
22
+
23
+ ## The Three Gates (Visual)
24
+
25
+ ```mermaid
26
+ flowchart LR
27
+ A["โœ๏ธ Write Time<br/>AI Agents"] -->|ark-mcp + validate_code| B["๐Ÿšซ Blocked"]
28
+ A -->|valid| C["๐Ÿ’พ Disk"]
29
+
30
+ D["๐Ÿ”€ Merge Time<br/>CI / PRs"] -->|ark-check| E["โŒ Fail"]
31
+ D -->|valid| F["โœ… Merge"]
32
+
33
+ G["โš™๏ธ Runtime<br/>In-process"] -->|createArkKernel<br/>strict defaults| H["๐Ÿ›ก๏ธ Enforce<br/>contracts + layers"]
34
+ G --> I["๐Ÿ“Š Observability<br/>+ Manifest"]
35
+
36
+ style A fill:#e0f2fe,color:#0c4a6e
37
+ style D fill:#fef3c7,color:#92400e
38
+ style G fill:#dcfce7,color:#166534
39
+ ```
40
+
41
+ **One config. Three enforcement moments.**
42
+
43
+ | Gate | Tool | When it runs | What it enforces |
44
+ |--------------|---------------|-------------------------------|-----------------------------------------------|
45
+ | **Write** | `ark-mcp` | Agent PreToolUse (Write/Edit) | Layer rules, unknown intents, forbidden patterns |
46
+ | **Merge** | `ark-check` | CI (GitHub Actions etc.) | Cross-layer imports + intent references (real TS resolver) |
47
+ | **Runtime** | `createArkKernel()` | Running process | Intent registry, event contracts, observed layer flow, policies |
48
+
49
+ ---
50
+
51
+ ## 60-Second Setup
52
+
53
+ ```bash
54
+ npm install -D ark-runtime-kernel typescript
55
+ ```
56
+
57
+ ### 1. Bootstrap your config from reality
58
+
59
+ ```bash
60
+ npx ark-check --init # detects your folders and writes ark.config.json
61
+ ```
62
+
63
+ ### 2. Gate CI
64
+
65
+ ```bash
66
+ npx ark-check --root . --config ark.config.json --strict-config
67
+ ```
68
+
69
+ ### 3. Gate AI agents (write path)
70
+
71
+ ```bash
72
+ npx ark-mcp --root . --config ark.config.json
73
+ ```
74
+
75
+ Bind `--hook` mode to your agent's `PreToolUse` for Write/Edit (see full docs below).
76
+
77
+ > The same `ark.config.json` powers all three gates.
78
+
79
+ ---
80
+
81
+ ## What Ark Actually Does
82
+
83
+ Ark turns architecture from **diagrams + good intentions** into **executable contracts**.
84
+
85
+ ### Core Capabilities
86
+
87
+ - **Intent Registry** โ€” Semantic names (`Domain.Order.OrderPlaced`, `Application.PlaceOrder`) with declared produces/dependsOn relationships.
88
+ - **Policy Engine** โ€” Hard policies (throw) + soft policies (observe). Built-in clean-architecture matrix.
89
+ - **Strict Event Bus** โ€” Registered intents only, known sources, event contracts, add-only interceptors.
90
+ - **Observed Layer Flow** โ€” Runtime enforcement (`'hard' | 'soft' | 'off'`) of *actual* producer โ†’ event flows against your layer rules.
91
+ - **Event Contracts** โ€” Payload shape validation (including nested + enums).
92
+ - **11-Layer Profile** โ€” First-class support for proper Hexagonal/Event-Driven boundaries.
93
+ - **Manifest** โ€” `ark.manifest().toJSON()` โ†’ complete machine-readable contract for agents and tools.
94
+ - **Observability & Drift** โ€” Declared vs observed flow reports.
95
+ - **Audit / Outbox / Projections / Workflow (Saga)** โ€” Pluggable in-memory defaults + interfaces.
96
+ - **Static + AI Gates** โ€” `ark-check` (deep) + `ark-mcp` + ESLint plugin.
97
+
98
+ ### Enforcement Scope (Be Honest With Yourself)
99
+
100
+ **Hard at runtime (governed paths only):**
101
+ - Unregistered intents / bad names
102
+ - Unknown sources
103
+ - Contract violations
104
+ - Hard policy violations
105
+ - Observed layer flow violations (when `hard`)
106
+
107
+ **CI (with ark-check):**
108
+ - Cross-layer imports (real module resolution)
109
+ - Intent string references across boundaries
110
+ - Raw `publish()` calls
111
+ - Missing `source` on strict publishes
112
+
113
+ **Everything else is out of scope** unless you route it through Ark or cover it with config + CI.
114
+
115
+ ---
116
+
117
+ ## Quick Start โ€” Strict Kernel (Recommended)
118
+
119
+ ```ts
120
+ import { createArkKernel } from 'ark-runtime-kernel';
121
+
122
+ const ark = createArkKernel(); // or createStrictArkKernel()
123
+
124
+ // 1. Define intents
125
+ const OrderPlaced = ark.registry.define<
126
+ 'Domain.Order.OrderPlaced',
127
+ { orderId: string; amount: number }
128
+ >('Domain.Order.OrderPlaced');
129
+
130
+ ark.registry.define<'Application.PlaceOrder', { orderId: string }>(
131
+ 'Application.PlaceOrder',
132
+ { produces: ['Domain.Order.OrderPlaced'] }
133
+ );
134
+
135
+ // 2. Register contracts (optional but powerful)
136
+ ark.eventContracts.register({
137
+ intent: 'Domain.Order.OrderPlaced',
138
+ version: '1',
139
+ allowAdditionalFields: false,
140
+ schema: {
141
+ orderId: { type: 'string', required: true },
142
+ amount: { type: 'number', required: true },
143
+ },
144
+ });
145
+
146
+ // 3. Projections (read models)
147
+ ark.projections.register({
148
+ name: 'OrderIds',
149
+ sourceIntents: ['Domain.Order.OrderPlaced'],
150
+ initialState: { ids: [] as string[] },
151
+ project: (event, state) => ({
152
+ ids: [...state.ids, event.payload.orderId as string],
153
+ }),
154
+ });
155
+
156
+ // 4. Publish through source-bound publisher (recommended)
157
+ const publisher = ark.publisher('Application.PlaceOrder');
158
+
159
+ await publisher.publish(OrderPlaced, { orderId: 'o1', amount: 129 }, {
160
+ eventVersion: '1',
161
+ correlationId: 'corr-xyz',
162
+ });
163
+
164
+ console.log(await ark.projections.getState('OrderIds'));
165
+ console.log(ark.observability.report());
166
+ console.log(JSON.stringify(ark.manifest().toJSON(), null, 2));
167
+ ```
168
+
169
+ See `examples/basic/` for a runnable version.
170
+
171
+ ---
172
+
173
+ ## AI Write-Path Gate (`ark-mcp`)
174
+
175
+ **The killer feature for agentic coding.**
176
+
177
+ ### Pre-write hook (blocks bad code before disk)
178
+
179
+ In Claude Code (`.claude/settings.json`):
180
+
181
+ ```json
182
+ {
183
+ "hooks": {
184
+ "PreToolUse": [{
185
+ "matcher": "Write|Edit|MultiEdit",
186
+ "hooks": [{
187
+ "type": "command",
188
+ "command": "npx ark-mcp --hook --root \"$CLAUDE_PROJECT_DIR\""
189
+ }]
190
+ }]
191
+ }
192
+ }
193
+ ```
194
+
195
+ When blocked, the agent gets the violations back as feedback and can fix + retry.
196
+
197
+ ### Full MCP server
198
+
199
+ ```bash
200
+ npx ark-mcp --root . --config ark.config.json
201
+ ```
202
+
203
+ Exposes:
204
+ - Resource: `ark://manifest`
205
+ - Tool: `validate_code(source, layer?, filePath?)`
206
+
207
+ Register in `.mcp.json`.
208
+
209
+ ---
210
+
211
+ ## `ark-check` โ€” The CI Gate
212
+
213
+ ```bash
214
+ # Basic
215
+ npx ark-check --root . --config ark.config.json
216
+
217
+ # Fail on coverage gaps too
218
+ npx ark-check --root . --config ark.config.json --strict-config
219
+
220
+ # JSON for tools
221
+ npx ark-check --json
222
+ ```
223
+
224
+ **What it catches (via real TypeScript resolution):**
225
+ - Import/export violations (relative, aliases, packages, dynamic import, require)
226
+ - String intent references across forbidden layers
227
+ - Raw publish calls
228
+ - Missing source metadata
229
+ - Source-layer mismatch
230
+
231
+ `--init` generates a real config from the directories that *actually exist* in your project.
232
+
233
+ ---
234
+
235
+ ## ESLint Plugin (dev guardrails)
236
+
237
+ ```js
238
+ // eslint.config.js
239
+ import ark from 'ark-runtime-kernel/eslint';
240
+
241
+ export default [
242
+ ark.configs.recommended,
243
+ ];
244
+ ```
245
+
246
+ Rules:
247
+ - `ark/no-domain-infra-imports`
248
+ - `ark/no-raw-event-publish`
249
+ - `ark/require-publish-source`
250
+
251
+ ---
252
+
253
+ ## What Ark Is / Is Not
254
+
255
+ | โœ… Ark is | โŒ Ark is not |
256
+ |---------------------------------------|-------------------------------------------|
257
+ | Runtime + CI + AI governance kernel | Database or queue |
258
+ | Enforceable architectural contract | Full distributed workflow engine |
259
+ | Machine-readable manifest for agents | Replacement for your domain logic |
260
+ | Zero-dependency TypeScript library | Complete semantic / type analyzer |
261
+ | Observable drift + history | OpenTelemetry implementation |
262
+ | Focused, explicit, pluggable | Magic that covers code you never route |
263
+
264
+ ---
265
+
266
+ ## Architecture Profile (11 Layers)
267
+
268
+ The built-in profile + `ark.config.json` give you a sane default taxonomy:
269
+
270
+ `DomainModel โ†’ ApplicationOrchestration โ†’ PersistenceAdapters โ†’ ...` (and 8 more)
271
+
272
+ You can customize freely. Rules are deny-by-default except for a few explicitly allowed flows.
273
+
274
+ ---
275
+
276
+ ## Production Notes
277
+
278
+ All stores (`Audit`, `Outbox`, `Projections`, `Workflow`) default to in-memory.
279
+
280
+ See [docs/production-hardening.md](./docs/production-hardening.md) for the interface contracts you must implement for durability.
281
+
282
+ ---
283
+
284
+ ## Documentation
285
+
286
+ - [Agent Integration Guide](docs/agent-guide.md) โ€” wiring `ark-mcp` into Claude Code, Cursor, and other agent runtimes
287
+ - [Production Hardening](docs/production-hardening.md) โ€” durable store interfaces to implement (`AuditStore`, `OutboxStore`, โ€ฆ)
288
+ - [Example Config](docs/ark-check-example.json) โ€” a hand-curated `ark.config.json` starting point
289
+ - [Runnable Examples](examples/) โ€” `examples/basic/` (kernel tour) and `examples/publish-smoke/` (consumer smoke test)
290
+ - [Changelog](CHANGELOG.md)
291
+
292
+ ---
293
+
294
+ ## Development
295
+
296
+ ```bash
297
+ npm install
298
+ npm run typecheck
299
+ npm run check:architecture
300
+ npm test
301
+ npm run build
302
+ ```
303
+
304
+ **Release process (already scripted):**
305
+
306
+ ```bash
307
+ npm run release:npm # full verify + publish
308
+ npm run release:npm -- --dry # dry run
309
+ ```
310
+
311
+ The release script:
312
+ 1. Typechecks + runs all tests + self architecture check
313
+ 2. Builds
314
+ 3. Temporarily swaps in the minimal publish manifest
315
+ 4. Publishes
316
+ 5. Restores dev manifest
317
+
318
+ ---
319
+
320
+ ## License
321
+
322
+ MIT ยฉ Pedro Knigge
323
+
324
+ ---
325
+
326
+ **Ark doesn't generate architecture. It protects the architecture you already have โ€” at the exact moments it matters most.**
327
+
328
+ Built for teams that use AI heavily and refuse to let entropy win.