@agentic-coding-framework/orchestrator-core 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.
package/dist/state.js ADDED
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ /**
3
+ * state.ts — STATE.json Type Definitions + Read / Write / Validate
4
+ *
5
+ * Maps directly to the Agentic Coding Protocol's STATE.json field specifications.
6
+ * All operations are synchronous file I/O — zero LLM tokens.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createInitialState = createInitialState;
10
+ exports.statePath = statePath;
11
+ exports.readState = readState;
12
+ exports.writeState = writeState;
13
+ exports.initState = initState;
14
+ exports.validate = validate;
15
+ exports.isTimedOut = isTimedOut;
16
+ exports.isMaxedOut = isMaxedOut;
17
+ exports.markRunning = markRunning;
18
+ exports.markCompleted = markCompleted;
19
+ const fs_1 = require("fs");
20
+ const path_1 = require("path");
21
+ // ─── Defaults ────────────────────────────────────────────────────────────────
22
+ /** Create a blank STATE.json for a new project */
23
+ function createInitialState(project) {
24
+ return {
25
+ project,
26
+ story: null,
27
+ step: "bootstrap",
28
+ attempt: 1,
29
+ max_attempts: 1,
30
+ status: "pending",
31
+ reason: null,
32
+ dispatched_at: null,
33
+ completed_at: null,
34
+ timeout_min: 5,
35
+ tests: null,
36
+ failing_tests: [],
37
+ lint_pass: null,
38
+ files_changed: [],
39
+ blocked_by: [],
40
+ human_note: null,
41
+ task_type: "story",
42
+ };
43
+ }
44
+ // ─── File I/O ────────────────────────────────────────────────────────────────
45
+ /** Resolve the STATE.json path for a project root */
46
+ function statePath(projectRoot) {
47
+ return (0, path_1.join)(projectRoot, ".ai", "STATE.json");
48
+ }
49
+ /** Read STATE.json from disk. Throws if file doesn't exist. */
50
+ function readState(projectRoot) {
51
+ const path = statePath(projectRoot);
52
+ if (!(0, fs_1.existsSync)(path)) {
53
+ throw new Error(`STATE.json not found at ${path}. Run initState() first.`);
54
+ }
55
+ const raw = (0, fs_1.readFileSync)(path, "utf-8");
56
+ const parsed = JSON.parse(raw);
57
+ validate(parsed);
58
+ return parsed;
59
+ }
60
+ /** Write STATE.json to disk. Creates .ai/ directory if needed. */
61
+ function writeState(projectRoot, state) {
62
+ validate(state);
63
+ const path = statePath(projectRoot);
64
+ const dir = (0, path_1.dirname)(path);
65
+ if (!(0, fs_1.existsSync)(dir)) {
66
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
67
+ }
68
+ (0, fs_1.writeFileSync)(path, JSON.stringify(state, null, 2) + "\n", "utf-8");
69
+ }
70
+ /** Initialize .ai/STATE.json for a new project. No-op if already exists. */
71
+ function initState(projectRoot, project) {
72
+ const path = statePath(projectRoot);
73
+ if ((0, fs_1.existsSync)(path)) {
74
+ return { created: false, state: readState(projectRoot) };
75
+ }
76
+ const state = createInitialState(project);
77
+ writeState(projectRoot, state);
78
+ return { created: true, state };
79
+ }
80
+ // ─── Validation ──────────────────────────────────────────────────────────────
81
+ const VALID_STEPS = new Set([
82
+ "bootstrap",
83
+ "bdd",
84
+ "sdd-delta",
85
+ "contract",
86
+ "review",
87
+ "scaffold",
88
+ "impl",
89
+ "verify",
90
+ "update-memory",
91
+ "custom",
92
+ "done",
93
+ ]);
94
+ const VALID_STATUSES = new Set([
95
+ "pending",
96
+ "running",
97
+ "pass",
98
+ "failing",
99
+ "needs_human",
100
+ "timeout",
101
+ ]);
102
+ const VALID_REASONS = new Set([
103
+ "constitution_violation",
104
+ "needs_clarification",
105
+ "nfr_missing",
106
+ "scope_warning",
107
+ "test_timeout",
108
+ ]);
109
+ /** Validate a State object. Throws on invalid fields. */
110
+ function validate(state) {
111
+ if (!state.project) {
112
+ throw new Error("State.project is required");
113
+ }
114
+ if (!VALID_STEPS.has(state.step)) {
115
+ throw new Error(`Invalid step: "${state.step}". Valid: ${[...VALID_STEPS].join(", ")}`);
116
+ }
117
+ if (!VALID_STATUSES.has(state.status)) {
118
+ throw new Error(`Invalid status: "${state.status}". Valid: ${[...VALID_STATUSES].join(", ")}`);
119
+ }
120
+ if (state.reason !== null && !VALID_REASONS.has(state.reason)) {
121
+ throw new Error(`Invalid reason: "${state.reason}". Valid: null, ${[...VALID_REASONS].join(", ")}`);
122
+ }
123
+ if (state.attempt < 0) {
124
+ throw new Error(`attempt must be >= 0, got ${state.attempt}`);
125
+ }
126
+ if (state.max_attempts < 1) {
127
+ throw new Error(`max_attempts must be >= 1, got ${state.max_attempts}`);
128
+ }
129
+ }
130
+ // ─── Convenience Helpers ─────────────────────────────────────────────────────
131
+ /** Check if a step has exceeded its timeout */
132
+ function isTimedOut(state) {
133
+ if (state.status !== "running" || !state.dispatched_at)
134
+ return false;
135
+ const elapsed = (Date.now() - new Date(state.dispatched_at).getTime()) / 60_000;
136
+ return elapsed > state.timeout_min;
137
+ }
138
+ /** Check if current step has exhausted all attempts */
139
+ function isMaxedOut(state) {
140
+ return state.attempt >= state.max_attempts;
141
+ }
142
+ /** Mark state as running with dispatch timestamp */
143
+ function markRunning(state) {
144
+ return {
145
+ ...state,
146
+ status: "running",
147
+ dispatched_at: new Date().toISOString(),
148
+ completed_at: null,
149
+ reason: null,
150
+ };
151
+ }
152
+ /** Mark state as completed (pass or failing) with timestamp */
153
+ function markCompleted(state, status, reason = null) {
154
+ return {
155
+ ...state,
156
+ status,
157
+ reason,
158
+ completed_at: new Date().toISOString(),
159
+ };
160
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@agentic-coding-framework/orchestrator-core",
3
+ "version": "0.1.0",
4
+ "description": "Zero-token orchestrator for the Agentic Coding Protocol — state machine, rules table, dispatch logic, CC integration",
5
+ "type": "commonjs",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "orchestrator": "dist/cli.js"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build",
14
+ "test": "vitest run",
15
+ "test:watch": "vitest"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "keywords": [
22
+ "agentic-coding",
23
+ "orchestrator",
24
+ "claude-code",
25
+ "ai-coding",
26
+ "state-machine",
27
+ "micro-waterfall"
28
+ ],
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/MaWeiChi/agentic-coding-orchestrator.git",
32
+ "directory": "agentic-coding-orchestrator"
33
+ },
34
+ "author": "MaWeiChi",
35
+ "license": "MIT",
36
+ "devDependencies": {
37
+ "@types/node": "^20.0.0",
38
+ "typescript": "^5.4.0",
39
+ "vitest": "^2.0.0"
40
+ }
41
+ }