@intent-driven/runtime-local 0.2.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 Ignat Dubovsky
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,66 @@
1
+ # @intent-driven/runtime-local
2
+
3
+ Standalone Fold-runtime для локального quickstart'а. Принимает ontology.js (сгенерированный `idf full-bootstrap`), поднимает HTTP-сервер с эндпоинтами, которые ожидает `@intent-driven/mcp-server` для подключения к Claude Desktop / Cursor / Zed.
4
+
5
+ > **Статус:** v0.1 — skeleton. Поддерживает `/api/health`, `/api/typemap`, `/api/agent/:domain/schema` (discovery). Полный agent/exec, approvals lifecycle, /api/state/* — в следующих релизах (см. roadmap fold-15min).
6
+
7
+ ## Зачем
8
+
9
+ До этого пакета чтобы поднять Fold-runtime локально нужно было `git clone idf` + `npm install` + `npm run server` в host-репе. Это блокер коробочности: пользователь не должен знать про host. После этого пакета:
10
+
11
+ ```bash
12
+ idf serve --ontology ./ontology.js # планируется в @intent-driven/cli
13
+ # или программно:
14
+ import { createRuntime } from '@intent-driven/runtime-local';
15
+ const runtime = createRuntime({ ontology: require('./ontology.js') });
16
+ await runtime.start();
17
+ ```
18
+
19
+ ## Установка
20
+
21
+ ```bash
22
+ npm install @intent-driven/runtime-local
23
+ ```
24
+
25
+ Peer-зависимость: `@intent-driven/core@>=0.49.0` (нужен для будущих релизов с validator/fold; в v0.1 не требуется в runtime, но указан как peer для forward-compat).
26
+
27
+ ## API
28
+
29
+ ### `createRuntime(opts)`
30
+
31
+ Создаёт runtime-инстанс. Не стартует сервер — для этого вызови `.start()`.
32
+
33
+ | Опция | Тип | Default | Описание |
34
+ |---|---|---|---|
35
+ | `ontology` | object | **required** | IDF ontology — `{ entities, intents, roles, projections, ... }`. |
36
+ | `port` | number | `3001` | Порт. `0` = random (для тестов). |
37
+ | `host` | string | `'127.0.0.1'` | Bind-адрес. |
38
+
39
+ Возвращает `{ app, ontology, domain, start(), stop() }`.
40
+
41
+ ### `runtime.start()` → `Promise<{url, port, host}>`
42
+
43
+ Поднимает Express-сервер. Возвращает actual URL/port (полезно при `port: 0`).
44
+
45
+ ### `runtime.stop()` → `Promise<void>`
46
+
47
+ Закрывает сервер.
48
+
49
+ ## Эндпоинты (v0.1)
50
+
51
+ | Метод | Путь | Назначение |
52
+ |---|---|---|
53
+ | `GET` | `/api/health` | Liveness check для `idf doctor` и MCP-server. Возвращает `{status, domain, runtime, version}`. |
54
+ | `GET` | `/api/typemap` | Сводка ontology: entities/intents/roles names. |
55
+ | `GET` | `/api/agent/:domain/schema` | Full ontology snapshot для MCP discovery. 503 если domain не совпадает с зарегистрированным. |
56
+
57
+ ## Roadmap (следующие PR)
58
+
59
+ - v0.2: in-memory Φ-store + `GET /api/state/at` + `GET /api/state/diff`
60
+ - v0.3: `POST /api/agent/:domain/exec/:intentId` — ingest с invariant validation, ApprovalRequest auto-injection через `lifecycleAugmenter`
61
+ - v0.4: `GET /api/approvals/pending` + `POST /api/approvals/:id/approve|reject` + timer-driven expiry
62
+ - v0.5: SSE-стрим `/api/approvals/stream` для `idf approvals --watch`
63
+
64
+ ## Лицензия
65
+
66
+ MIT. © Ignat Dubovsky.
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@intent-driven/runtime-local",
3
+ "version": "0.2.0",
4
+ "description": "Standalone Fold-runtime для local quickstart: stateful Φ + agent/exec + approvals + state — то, что делает host idf/server, но как npm-пакет",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.js"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "dependencies": {
15
+ "cors": "^2.8.5",
16
+ "express": "^4.21.2"
17
+ },
18
+ "devDependencies": {
19
+ "vitest": "^4.1.0",
20
+ "@intent-driven/core": "0.116.0"
21
+ },
22
+ "peerDependencies": {
23
+ "@intent-driven/core": ">=0.49.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "license": "MIT",
29
+ "author": "Игнат Дубовский <dubovskyy.im@gmail.com>",
30
+ "homepage": "https://github.com/DubovskiyIM/idf-sdk/tree/main/packages/runtime-local",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/DubovskiyIM/idf-sdk.git",
34
+ "directory": "packages/runtime-local"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/DubovskiyIM/idf-sdk/issues"
38
+ },
39
+ "keywords": [
40
+ "intent-driven",
41
+ "idf",
42
+ "runtime",
43
+ "local",
44
+ "fold",
45
+ "phi",
46
+ "approval",
47
+ "agent",
48
+ "quickstart"
49
+ ],
50
+ "scripts": {
51
+ "test": "vitest run",
52
+ "test:watch": "vitest"
53
+ }
54
+ }
@@ -0,0 +1,99 @@
1
+ import express from "express";
2
+ import cors from "cors";
3
+ import { readFileSync } from "node:fs";
4
+ import { fileURLToPath } from "node:url";
5
+ import { dirname, join } from "node:path";
6
+
7
+ const PKG_VERSION = (() => {
8
+ try {
9
+ const here = dirname(fileURLToPath(import.meta.url));
10
+ const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
11
+ return pkg.version;
12
+ } catch {
13
+ return "0.0.0";
14
+ }
15
+ })();
16
+
17
+ export function createRuntime(opts = {}) {
18
+ const { ontology, port = 3001, host = "127.0.0.1" } = opts;
19
+
20
+ if (!ontology || typeof ontology !== "object") {
21
+ throw new Error("createRuntime: ontology is required");
22
+ }
23
+
24
+ const domain = ontology.name || "default";
25
+
26
+ const app = express();
27
+ app.use(cors());
28
+ app.use(express.json({ limit: "10mb" }));
29
+
30
+ app.get("/api/health", (_req, res) => {
31
+ res.json({
32
+ status: "ok",
33
+ domain,
34
+ runtime: "@intent-driven/runtime-local",
35
+ version: PKG_VERSION,
36
+ });
37
+ });
38
+
39
+ app.get("/api/typemap", (_req, res) => {
40
+ res.json({
41
+ domain,
42
+ entities: Object.keys(ontology.entities || {}),
43
+ intents: Object.keys(ontology.intents || {}),
44
+ roles: Object.keys(ontology.roles || {}),
45
+ });
46
+ });
47
+
48
+ app.get("/api/agent/:domain/schema", (req, res) => {
49
+ if (req.params.domain !== domain) {
50
+ return res.status(503).json({
51
+ error: "ontology_unavailable",
52
+ domain: req.params.domain,
53
+ message: `Ontology for '${req.params.domain}' is not registered. Runtime serves '${domain}'.`,
54
+ });
55
+ }
56
+ res.json({
57
+ domain,
58
+ entities: ontology.entities || {},
59
+ intents: ontology.intents || {},
60
+ roles: ontology.roles || {},
61
+ });
62
+ });
63
+
64
+ let server = null;
65
+
66
+ return {
67
+ app,
68
+ ontology,
69
+ domain,
70
+
71
+ async start() {
72
+ if (server) {
73
+ throw new Error("runtime already started");
74
+ }
75
+ return await new Promise((resolve, reject) => {
76
+ const s = app.listen(port, host, () => {
77
+ server = s;
78
+ const addr = s.address();
79
+ const actualPort = typeof addr === "object" && addr ? addr.port : port;
80
+ resolve({
81
+ url: `http://${host}:${actualPort}`,
82
+ port: actualPort,
83
+ host,
84
+ });
85
+ });
86
+ s.once("error", reject);
87
+ });
88
+ },
89
+
90
+ async stop() {
91
+ if (!server) return;
92
+ const s = server;
93
+ server = null;
94
+ await new Promise((resolve, reject) => {
95
+ s.close((err) => (err ? reject(err) : resolve()));
96
+ });
97
+ },
98
+ };
99
+ }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createRuntime } from "./createRuntime.js";