@acpus/runtime 0.1.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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/artifacts.d.ts +30 -0
  4. package/dist/artifacts.d.ts.map +1 -0
  5. package/dist/artifacts.js +97 -0
  6. package/dist/artifacts.js.map +1 -0
  7. package/dist/client.d.ts +54 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +159 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/evaluator.d.ts +37 -0
  12. package/dist/evaluator.d.ts.map +1 -0
  13. package/dist/evaluator.js +101 -0
  14. package/dist/evaluator.js.map +1 -0
  15. package/dist/executors/agent.d.ts +74 -0
  16. package/dist/executors/agent.d.ts.map +1 -0
  17. package/dist/executors/agent.js +401 -0
  18. package/dist/executors/agent.js.map +1 -0
  19. package/dist/executors/mock-program.d.ts +24 -0
  20. package/dist/executors/mock-program.d.ts.map +1 -0
  21. package/dist/executors/mock-program.js +79 -0
  22. package/dist/executors/mock-program.js.map +1 -0
  23. package/dist/executors/program.d.ts +21 -0
  24. package/dist/executors/program.d.ts.map +1 -0
  25. package/dist/executors/program.js +178 -0
  26. package/dist/executors/program.js.map +1 -0
  27. package/dist/executors/types.d.ts +26 -0
  28. package/dist/executors/types.d.ts.map +1 -0
  29. package/dist/executors/types.js +2 -0
  30. package/dist/executors/types.js.map +1 -0
  31. package/dist/index.d.ts +18 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +25 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/interpreter.d.ts +186 -0
  36. package/dist/interpreter.d.ts.map +1 -0
  37. package/dist/interpreter.js +1500 -0
  38. package/dist/interpreter.js.map +1 -0
  39. package/dist/keys.d.ts +36 -0
  40. package/dist/keys.d.ts.map +1 -0
  41. package/dist/keys.js +59 -0
  42. package/dist/keys.js.map +1 -0
  43. package/dist/state-machine.d.ts +27 -0
  44. package/dist/state-machine.d.ts.map +1 -0
  45. package/dist/state-machine.js +87 -0
  46. package/dist/state-machine.js.map +1 -0
  47. package/dist/store.d.ts +46 -0
  48. package/dist/store.d.ts.map +1 -0
  49. package/dist/store.js +260 -0
  50. package/dist/store.js.map +1 -0
  51. package/dist/supervisor-app.d.ts +27 -0
  52. package/dist/supervisor-app.d.ts.map +1 -0
  53. package/dist/supervisor-app.js +548 -0
  54. package/dist/supervisor-app.js.map +1 -0
  55. package/dist/supervisor-discovery.d.ts +17 -0
  56. package/dist/supervisor-discovery.d.ts.map +1 -0
  57. package/dist/supervisor-discovery.js +186 -0
  58. package/dist/supervisor-discovery.js.map +1 -0
  59. package/dist/supervisor-entry.d.ts +11 -0
  60. package/dist/supervisor-entry.d.ts.map +1 -0
  61. package/dist/supervisor-entry.js +50 -0
  62. package/dist/supervisor-entry.js.map +1 -0
  63. package/dist/supervisor-lock.d.ts +26 -0
  64. package/dist/supervisor-lock.d.ts.map +1 -0
  65. package/dist/supervisor-lock.js +49 -0
  66. package/dist/supervisor-lock.js.map +1 -0
  67. package/dist/supervisor-runner.d.ts +11 -0
  68. package/dist/supervisor-runner.d.ts.map +1 -0
  69. package/dist/supervisor-runner.js +128 -0
  70. package/dist/supervisor-runner.js.map +1 -0
  71. package/dist/types.d.ts +230 -0
  72. package/dist/types.d.ts.map +1 -0
  73. package/dist/types.js +2 -0
  74. package/dist/types.js.map +1 -0
  75. package/dist/validate-input.d.ts +27 -0
  76. package/dist/validate-input.d.ts.map +1 -0
  77. package/dist/validate-input.js +56 -0
  78. package/dist/validate-input.js.map +1 -0
  79. package/package.json +66 -0
@@ -0,0 +1,230 @@
1
+ import type { IrNodeKind } from "@acpus/core";
2
+ /** The 7 states in the unified node state machine. */
3
+ export type NodeState = "pending" | "running" | "awaiting" | "completed" | "failed" | "paused" | "cancelled";
4
+ /** Run-level status (mirrors terminal node states + "running"). */
5
+ export type RunStatus = "running" | "completed" | "failed" | "paused" | "cancelled";
6
+ /** Dynamic dimensions that make a node key unique at runtime. */
7
+ export interface NodeKeyDynamic {
8
+ loopRound?: number;
9
+ fanoutItemId?: string;
10
+ laneId?: string;
11
+ parallelBranchId?: string;
12
+ }
13
+ export interface NodeExecutionState {
14
+ /** Resolved key string (e.g. "workflow/mapped/item:file-a/lane:0") */
15
+ nodeKey: string;
16
+ /** Original IR node id (e.g. "mapped") */
17
+ nodeId: string;
18
+ /** Node kind from IR */
19
+ kind: IrNodeKind;
20
+ /** Current state in the state machine */
21
+ state: NodeState;
22
+ /** How many times this node has been attempted */
23
+ attempt: number;
24
+ /** ISO timestamp when node entered running state */
25
+ startedAt?: string;
26
+ /** ISO timestamp when node entered a terminal state */
27
+ completedAt?: string;
28
+ /** Error message if state is "failed" */
29
+ error?: string;
30
+ /** Node output (validated against schema for agents) */
31
+ output?: unknown;
32
+ /** References to artifacts stored for this node */
33
+ artifactRefs?: string[];
34
+ /**
35
+ * Snapshot of the parent dynamic value-context this node executed under
36
+ * (fanout item / loop round). Persisted so retry/continuation can rebuild the
37
+ * expression context for command/prompt re-rendering. Only value context is
38
+ * stored — never large artifact payloads.
39
+ */
40
+ dynamicContext?: NodeDynamicContext;
41
+ /** The prompt after template evaluation at runtime (persisted for TUI display). */
42
+ renderedPrompt?: string;
43
+ }
44
+ /** Persisted parent value-context for a leaf node (fanout item / loop round). */
45
+ export interface NodeDynamicContext {
46
+ item?: unknown;
47
+ item_id?: string;
48
+ item_index?: number;
49
+ loop?: {
50
+ iter: number;
51
+ last?: unknown;
52
+ };
53
+ }
54
+ export interface RunState {
55
+ runId: string;
56
+ workflowName: string;
57
+ /** Catalog ref used to start this Run, when started from the Workflow Catalog. */
58
+ workflowRef?: string;
59
+ /** Absolute Workflow Spec path used to compile this Run. */
60
+ workflowSourcePath?: string;
61
+ status: RunStatus;
62
+ /** SHA-256 digest of the frozen IR JSON */
63
+ irDigest: string;
64
+ /** SHA-256 digest of the input JSON */
65
+ inputDigest: string;
66
+ createdAt: string;
67
+ updatedAt: string;
68
+ /** Run generation: starts at 1 and increments on each Run-level retry. */
69
+ runAttempt: number;
70
+ /** Node states included when inspecting a specific run (GET /runs/:runId) */
71
+ nodes?: NodeExecutionState[];
72
+ }
73
+ export interface ExpressionContext {
74
+ input: Record<string, unknown>;
75
+ /** Step outputs keyed by step id */
76
+ steps: Record<string, unknown>;
77
+ loop?: {
78
+ iter: number;
79
+ last?: unknown;
80
+ };
81
+ item?: unknown;
82
+ item_id?: string;
83
+ item_index?: number;
84
+ run_id: string;
85
+ }
86
+ /**
87
+ * Classification of an executor failure. Used by the interpreter to decide
88
+ * whether a node is non-recoverable (→ failed) and whether an agent response
89
+ * failure is retryable (parse/schema).
90
+ */
91
+ export type FailureKind = "parse" | "schema" | "spawn" | "timeout" | "killed" | "capture" | "exit" | "config";
92
+ export interface ExecutorResult {
93
+ output?: unknown;
94
+ exitCode?: number;
95
+ artifactRefs?: string[];
96
+ error?: string;
97
+ /** Fully rendered prompt/request text prepared for this executor call. */
98
+ prompt?: string;
99
+ /** Human-readable response text reconstructed from the executor protocol/output. */
100
+ responseText?: string;
101
+ /** Raw process stdout, captured as an artifact by the interpreter. */
102
+ stdout?: string;
103
+ /** Raw process stderr, captured as an artifact by the interpreter. */
104
+ stderr?: string;
105
+ /** Failure classification when execution did not succeed. */
106
+ failureKind?: FailureKind;
107
+ /** True if the executor was aborted mid-execution */
108
+ partial?: boolean;
109
+ /** The prompt after template evaluation at runtime. */
110
+ renderedPrompt?: string;
111
+ }
112
+ export interface ArtifactRef {
113
+ /** Full URI: artifact://runs/<runId>/nodes/<nodeKey>/<filename> */
114
+ uri: string;
115
+ runId: string;
116
+ nodeKey: string;
117
+ filename: string;
118
+ }
119
+ export interface InterpreterOptions {
120
+ /** Maximum concurrent node executions across the interpreter */
121
+ maxConcurrency?: number;
122
+ /** Absolute source roots that Workflow Spec file reads may resolve under. */
123
+ allowedSourceRoots?: string[];
124
+ /** Deterministic timestamp for now() in expressions (ISO string) */
125
+ nowTimestamp?: string;
126
+ /** Injectable sleep used for retry backoff (default: real setTimeout). */
127
+ sleep?: (ms: number) => Promise<void>;
128
+ }
129
+ export interface RunOptions {
130
+ /** Resolved input values */
131
+ input: Record<string, unknown>;
132
+ /** Unique run identifier (generated if not provided) */
133
+ runId?: string;
134
+ /** Catalog ref used to start this Run, when applicable. */
135
+ workflowRef?: string;
136
+ /** Absolute Workflow Spec path used to compile this Run. */
137
+ workflowSourcePath?: string;
138
+ }
139
+ export interface SupervisorConfig {
140
+ /** Port to listen on (0 = random) */
141
+ port?: number;
142
+ /** Host to bind (default "127.0.0.1") */
143
+ host?: string;
144
+ /** Base directory for .acpus/ state (default cwd) */
145
+ stateDir?: string;
146
+ /** Workspace root for Run execution and source-path validation. */
147
+ workspace?: string;
148
+ /** Idle shutdown timeout in milliseconds (default 5 min) */
149
+ idleTimeoutMs?: number;
150
+ }
151
+ export interface SupervisorMetadata {
152
+ schemaVersion: number;
153
+ workspace: string;
154
+ pid: number;
155
+ endpoint: string;
156
+ startedAt: string;
157
+ version: string;
158
+ }
159
+ export interface SupervisorHealth extends SupervisorMetadata {
160
+ ok: true;
161
+ runningCount: number;
162
+ activeClients: number;
163
+ }
164
+ export interface StartRunRequest {
165
+ /** YAML source of the workflow spec */
166
+ spec: string;
167
+ /** Resolved input values */
168
+ input?: Record<string, unknown>;
169
+ /** Absolute path to the spec file (for $include/subworkflow resolution) */
170
+ sourcePath?: string;
171
+ /** Catalog ref used to start this Run, when applicable. */
172
+ workflowRef?: string;
173
+ }
174
+ export interface RunSummary {
175
+ runId: string;
176
+ workflowName: string;
177
+ workflowRef?: string;
178
+ workflowSourcePath?: string;
179
+ status: RunStatus;
180
+ createdAt: string;
181
+ updatedAt: string;
182
+ }
183
+ export interface RunCleanItem {
184
+ runId: string;
185
+ status?: RunStatus;
186
+ bytes: number;
187
+ reason?: string;
188
+ }
189
+ export interface RunCleanResult {
190
+ dryRun: boolean;
191
+ deletedCount: number;
192
+ skippedCount: number;
193
+ bytesReclaimed: number;
194
+ deleted: RunCleanItem[];
195
+ skipped: RunCleanItem[];
196
+ }
197
+ export interface InputValidationError {
198
+ /** JSON pointer path, e.g. "/region" or "/tags/0" */
199
+ path: string;
200
+ /** Ajv keyword that triggered the error, e.g. "required", "type" */
201
+ keyword: string;
202
+ /** Human-readable error message */
203
+ message: string;
204
+ /** Expected type or value (when applicable) */
205
+ expected?: string;
206
+ /** Actual type or value (when applicable) */
207
+ actual?: string;
208
+ }
209
+ /** A single discrepancy found while replaying a persisted Run. */
210
+ export interface ReplayMismatch {
211
+ nodeKey: string;
212
+ /** What kind of discrepancy: a node reached in only one walk, or differing state. */
213
+ kind: "state" | "missing-in-replay" | "unexpected-in-replay";
214
+ /** Persisted (recorded) value. */
215
+ expected?: NodeState;
216
+ /** Value derived by the deterministic replay walk. */
217
+ actual?: NodeState;
218
+ }
219
+ /**
220
+ * Result of a deterministic replay: re-walking the frozen IR against recorded
221
+ * node outputs and verifying the reconstructed node topology (the set of reached
222
+ * node keys) matches what was persisted. No agents/programs are executed and no
223
+ * disk writes occur.
224
+ */
225
+ export interface ReplayResult {
226
+ runId: string;
227
+ ok: boolean;
228
+ mismatches: ReplayMismatch[];
229
+ }
230
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE7G,mEAAmE;AACnE,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAIpF,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAA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AmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,kEAAkE;AAClE,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,IAAI,EAAE,OAAO,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;IAC7D,kCAAkC;IAClC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,sDAAsD;IACtD,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ export interface InputValidationError {
2
+ /** JSON pointer path, e.g. "/region" or "/tags/0" */
3
+ path: string;
4
+ /** Ajv keyword that triggered the error, e.g. "required", "type" */
5
+ keyword: string;
6
+ /** Human-readable error message */
7
+ message: string;
8
+ /** Expected type or value (when applicable) */
9
+ expected?: string;
10
+ /** Actual type or value (when applicable) */
11
+ actual?: string;
12
+ }
13
+ export declare class InputValidationFailure extends Error {
14
+ readonly errors: InputValidationError[];
15
+ constructor(errors: InputValidationError[]);
16
+ }
17
+ /**
18
+ * Validate `input` against a compiled JSON Schema (from the IR's `input` field).
19
+ * When the schema declares defaults for missing optional properties, Ajv
20
+ * fills them in by mutating `input` in-place. On validation failure, throws
21
+ * {@link InputValidationFailure} with structured error details.
22
+ *
23
+ * An empty schema (`{}` or no `properties`) is treated as "no validation
24
+ * required" — the input passes through unchanged.
25
+ */
26
+ export declare function validateInput(schema: Record<string, unknown>, input: Record<string, unknown>): Record<string, unknown>;
27
+ //# sourceMappingURL=validate-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-input.d.ts","sourceRoot":"","sources":["../src/validate-input.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;aACnB,MAAM,EAAE,oBAAoB,EAAE;gBAA9B,MAAM,EAAE,oBAAoB,EAAE;CAK3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqCzB"}
@@ -0,0 +1,56 @@
1
+ import { Ajv } from "ajv";
2
+ /**
3
+ * Module-level Ajv singleton for input validation.
4
+ * `useDefaults: true` auto-fills missing optional properties with their
5
+ * declared `default` values (mutating the input object in-place).
6
+ * `strict: false` matches the compiler's Ajv configuration.
7
+ */
8
+ const ajv = new Ajv({ allErrors: true, strict: false, useDefaults: true });
9
+ export class InputValidationFailure extends Error {
10
+ errors;
11
+ constructor(errors) {
12
+ const summary = errors.map((e) => `${e.path}: ${e.message}`).join("; ");
13
+ super(`Input validation failed: ${summary}`);
14
+ this.errors = errors;
15
+ this.name = "InputValidationFailure";
16
+ }
17
+ }
18
+ /**
19
+ * Validate `input` against a compiled JSON Schema (from the IR's `input` field).
20
+ * When the schema declares defaults for missing optional properties, Ajv
21
+ * fills them in by mutating `input` in-place. On validation failure, throws
22
+ * {@link InputValidationFailure} with structured error details.
23
+ *
24
+ * An empty schema (`{}` or no `properties`) is treated as "no validation
25
+ * required" — the input passes through unchanged.
26
+ */
27
+ export function validateInput(schema, input) {
28
+ // No schema or empty schema → nothing to validate.
29
+ if (!schema ||
30
+ Object.keys(schema).length === 0 ||
31
+ (!schema.properties && !schema.required && !schema.$schema)) {
32
+ return input;
33
+ }
34
+ const validate = ajv.compile(schema);
35
+ const valid = validate(input);
36
+ if (valid) {
37
+ return input; // Ajv has already filled defaults in-place.
38
+ }
39
+ const errors = (validate.errors ?? []).map((err) => {
40
+ const mapped = {
41
+ path: err.instancePath || "/",
42
+ keyword: err.keyword,
43
+ message: err.message ?? "validation error",
44
+ };
45
+ if (err.keyword === "type" && err.params) {
46
+ mapped.expected = err.params.type;
47
+ mapped.actual = typeof input[err.instancePath.slice(1).split("/")[0] ?? ""];
48
+ }
49
+ if (err.keyword === "required" && err.params) {
50
+ mapped.expected = err.params.missingProperty;
51
+ }
52
+ return mapped;
53
+ });
54
+ throw new InputValidationFailure(errors);
55
+ }
56
+ //# sourceMappingURL=validate-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-input.js","sourceRoot":"","sources":["../src/validate-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AAe3E,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACnB;IAA5B,YAA4B,MAA8B;QACxD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,C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CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3G,CAAC;QAED,IAAI,GAAG,CAAC,OAAO,KAAK,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YAC7C,MAAM,CAAC,QAAQ,GAAI,GAAG,CAAC,MAAuC,CAAC,eAAe,CAAC;QACjF,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@acpus/runtime",
3
+ "version": "0.1.0",
4
+ "description": "Local durable runtime and Run Supervisor for Acpus workflows",
5
+ "keywords": [
6
+ "acp",
7
+ "acpx",
8
+ "workflow",
9
+ "runtime",
10
+ "orchestrator"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "kkkyran",
14
+ "homepage": "https://github.com/kelvinschen/acpus#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/kelvinschen/acpus.git",
18
+ "directory": "packages/runtime"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/kelvinschen/acpus/issues"
22
+ },
23
+ "type": "module",
24
+ "engines": {
25
+ "node": ">=22"
26
+ },
27
+ "exports": {
28
+ ".": {
29
+ "development": "./src/index.ts",
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "main": "./dist/index.js",
35
+ "types": "./dist/index.d.ts",
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "dependencies": {
45
+ "@hono/node-server": "^1.14.0",
46
+ "@marcbachmann/cel-js": "^7.6.1",
47
+ "acpx": "0.10.0",
48
+ "ajv": "^8.20.0",
49
+ "execa": "^9.6.0",
50
+ "hono": "^4.7.0",
51
+ "jsonrepair": "^3.14.0",
52
+ "p-limit": "^6.2.0",
53
+ "proper-lockfile": "^4.1.2",
54
+ "@acpus/core": "0.1.0"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^22.15.30",
58
+ "@types/proper-lockfile": "^4.1.4",
59
+ "@acpus/mock-agent": "0.1.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsc -p tsconfig.json",
63
+ "typecheck": "tsc -p tsconfig.json --noEmit",
64
+ "clean": "rm -rf dist"
65
+ }
66
+ }