code60-transmission-server 0.1.0-staging.12 → 0.1.0-staging.16
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/INTENT.md +47 -0
- package/README.md +36 -345
- package/dist/src/acp.js +115 -0
- package/dist/src/contract.js +60 -0
- package/dist/src/engine.js +481 -0
- package/dist/src/main.js +70 -25
- package/dist/src/repository.js +94 -0
- package/dist/src/service.js +184 -0
- package/package.json +16 -35
- package/reference/openapi.json +423 -0
- package/README.engine.md +0 -463
- package/dist/src/broker/filesystem.js +0 -385
- package/dist/src/broker/index.js +0 -734
- package/dist/src/broker/native/README.md +0 -207
- package/dist/src/broker/native/build.js +0 -46
- package/dist/src/broker/native/command-helper.c +0 -93
- package/dist/src/broker/native/fs-helper.c +0 -529
- package/dist/src/broker/native/git-helper.c +0 -205
- package/dist/src/broker/policy.js +0 -149
- package/dist/src/broker/startup-lock.js +0 -14
- package/dist/src/broker/types.js +0 -11
- package/dist/src/cli/configure.js +0 -208
- package/dist/src/cli/daemon.js +0 -369
- package/dist/src/cli/helpers.js +0 -112
- package/dist/src/cli/main.js +0 -189
- package/dist/src/cli/runtime-build.js +0 -38
- package/dist/src/config/coding-policy.js +0 -4
- package/dist/src/config/deployment.js +0 -183
- package/dist/src/config/documents.js +0 -29
- package/dist/src/config/profile-validation.js +0 -129
- package/dist/src/config/schema-graph.js +0 -237
- package/dist/src/config/schema-loader.js +0 -185
- package/dist/src/config/validation-pool.js +0 -105
- package/dist/src/config/validation-protocol.js +0 -1
- package/dist/src/config/validation-worker.js +0 -106
- package/dist/src/config/workflow-language.js +0 -9
- package/dist/src/config/workflow-schema.json +0 -545
- package/dist/src/config/workflow-types.js +0 -1
- package/dist/src/config/workflow-validation.js +0 -95
- package/dist/src/engine/budgets.js +0 -50
- package/dist/src/engine/clocks.js +0 -27
- package/dist/src/engine/commands.js +0 -477
- package/dist/src/engine/contracts.js +0 -11
- package/dist/src/engine/drain-state.js +0 -31
- package/dist/src/engine/effective-permissions.js +0 -120
- package/dist/src/engine/instruction-pins.js +0 -205
- package/dist/src/engine/retries.js +0 -50
- package/dist/src/engine/state.js +0 -1
- package/dist/src/engine/timing.js +0 -23
- package/dist/src/engine/tool-observations.js +0 -87
- package/dist/src/engine/workflow-engine.js +0 -1862
- package/dist/src/mcp/catalog.js +0 -71
- package/dist/src/mcp/main.js +0 -26
- package/dist/src/mcp/server.js +0 -177
- package/dist/src/runtime/codex-app-server.js +0 -91
- package/dist/src/runtime/codex-executable.js +0 -50
- package/dist/src/runtime/containment.js +0 -82
- package/dist/src/runtime/engine-driver.js +0 -221
- package/dist/src/runtime/json-line-writer.js +0 -192
- package/dist/src/runtime/pinned-instruction-sources.js +0 -24
- package/dist/src/runtime/protocol-client.js +0 -264
- package/dist/src/runtime/protocol-pool.js +0 -183
- package/dist/src/runtime/protocol-projection.js +0 -393
- package/dist/src/runtime/protocol-types.js +0 -1
- package/dist/src/runtime/protocol-worker.js +0 -18
- package/dist/src/runtime/provider-bridge.js +0 -290
- package/dist/src/runtime/provider-credentials.js +0 -41
- package/dist/src/runtime/provider-transport.js +0 -406
- package/dist/src/runtime/runtime-broker.js +0 -213
- package/dist/src/runtime/workspace-instructions.js +0 -120
- package/dist/src/runtime/workspace-view.js +0 -74
- package/dist/src/server/api-contract.json +0 -11629
- package/dist/src/server/api-types.js +0 -1
- package/dist/src/server/application.js +0 -44
- package/dist/src/server/auth.js +0 -67
- package/dist/src/server/broker-handlers.js +0 -242
- package/dist/src/server/coding.js +0 -281
- package/dist/src/server/control-plane.js +0 -50
- package/dist/src/server/deployment.js +0 -249
- package/dist/src/server/errors.js +0 -22
- package/dist/src/server/history-handlers.js +0 -127
- package/dist/src/server/http.js +0 -124
- package/dist/src/server/paging.js +0 -56
- package/dist/src/server/publication.js +0 -119
- package/dist/src/server/tool-event-handler.js +0 -77
- package/dist/src/server/workspace-handlers.js +0 -34
- package/dist/src/storage/coordinator.js +0 -224
- package/dist/src/storage/startup-lock.js +0 -71
- package/dist/src/storage/store.js +0 -167
- package/dist/src/tools/check-worker.js +0 -81
- package/dist/src/tools/checks.js +0 -117
- package/dist/src/tools/command-check.js +0 -34
- package/dist/src/tools/commands.js +0 -312
- package/dist/src/tools/developer.js +0 -353
- package/dist/src/tools/dns.js +0 -248
- package/dist/src/tools/http-contract.js +0 -38
- package/dist/src/tools/http.js +0 -358
- package/dist/src/tools/index.js +0 -194
- package/dist/src/tools/worker-check.js +0 -73
- package/dist/src/workspaces/git.js +0 -227
- package/dist/src/workspaces/index.js +0 -937
- package/dist/src/workspaces/source.js +0 -295
- package/examples/deployment.local.json +0 -22
- package/scripts/postinstall.mjs +0 -26
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { closeSync, mkdirSync, openSync, readSync, realpathSync, renameSync, rmSync, statSync, } from 'node:fs';
|
|
4
|
+
import { join, sep } from 'node:path';
|
|
5
|
+
import { AcpHarness } from './acp.js';
|
|
6
|
+
import { terminal, verifierReply, workerReply, } from './contract.js';
|
|
7
|
+
import { repository, snapshot, writePatch } from './repository.js';
|
|
8
|
+
const diagnostic = (error) => error instanceof Error ? error.message : String(error);
|
|
9
|
+
export class Engine {
|
|
10
|
+
state;
|
|
11
|
+
factory;
|
|
12
|
+
db;
|
|
13
|
+
runs = new Map();
|
|
14
|
+
pumps = new Map();
|
|
15
|
+
agents = new Map();
|
|
16
|
+
pending = new Map();
|
|
17
|
+
closing = false;
|
|
18
|
+
settling = new Set();
|
|
19
|
+
constructor(state, factory = (hooks, cwd) => new AcpHarness(hooks, cwd)) {
|
|
20
|
+
this.state = state;
|
|
21
|
+
this.factory = factory;
|
|
22
|
+
mkdirSync(state, { recursive: true, mode: 0o700 });
|
|
23
|
+
this.db = new DatabaseSync(join(state, 'workflows.sqlite'));
|
|
24
|
+
this.db.exec(`PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;
|
|
25
|
+
CREATE TABLE IF NOT EXISTS runs(id TEXT PRIMARY KEY, caller_key TEXT UNIQUE NOT NULL, body TEXT NOT NULL);
|
|
26
|
+
CREATE TABLE IF NOT EXISTS events(sequence INTEGER PRIMARY KEY, run TEXT NOT NULL, time TEXT NOT NULL, kind TEXT NOT NULL, detail TEXT NOT NULL);
|
|
27
|
+
CREATE INDEX IF NOT EXISTS by_run ON events(run,sequence);`);
|
|
28
|
+
for (const row of this.db.prepare('SELECT body FROM runs').all()) {
|
|
29
|
+
const r = JSON.parse(String(row.body));
|
|
30
|
+
this.runs.set(r.id, r);
|
|
31
|
+
if (terminal(r.status))
|
|
32
|
+
continue;
|
|
33
|
+
if (r.worker || r.verifier) {
|
|
34
|
+
this.retireSessions(r);
|
|
35
|
+
r.feedback +=
|
|
36
|
+
'\nTransmission restarted. Inspect existing work and the outcome of consequential actions before repeating them. Ask if their outcome cannot be determined.';
|
|
37
|
+
this.save(r, 'task_resumed', { task: r.plan.tasks[r.index].name });
|
|
38
|
+
}
|
|
39
|
+
this.wake(r);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
dir(r) {
|
|
43
|
+
return join(this.state, r.id);
|
|
44
|
+
}
|
|
45
|
+
save(r, kind, detail = {}) {
|
|
46
|
+
this.db.exec('BEGIN IMMEDIATE');
|
|
47
|
+
try {
|
|
48
|
+
this.db
|
|
49
|
+
.prepare('INSERT INTO runs VALUES(?,?,?) ON CONFLICT(id) DO UPDATE SET body=excluded.body')
|
|
50
|
+
.run(r.id, r.plan.idempotencyKey, JSON.stringify(r));
|
|
51
|
+
this.event(r, kind, detail);
|
|
52
|
+
this.db.exec('COMMIT');
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.db.exec('ROLLBACK');
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
event(r, kind, detail) {
|
|
60
|
+
this.db
|
|
61
|
+
.prepare('INSERT INTO events(run,time,kind,detail) VALUES(?,?,?,?)')
|
|
62
|
+
.run(r.id, new Date().toISOString(), kind, JSON.stringify(detail));
|
|
63
|
+
}
|
|
64
|
+
get(id) {
|
|
65
|
+
const r = this.runs.get(id);
|
|
66
|
+
if (!r)
|
|
67
|
+
throw new Error('Unknown workflow.');
|
|
68
|
+
return r;
|
|
69
|
+
}
|
|
70
|
+
start(plan) {
|
|
71
|
+
const prior = this.db
|
|
72
|
+
.prepare('SELECT id FROM runs WHERE caller_key=?')
|
|
73
|
+
.get(plan.idempotencyKey);
|
|
74
|
+
if (prior) {
|
|
75
|
+
const r = this.get(String(prior.id));
|
|
76
|
+
if (JSON.stringify(r.plan) !==
|
|
77
|
+
JSON.stringify({ ...plan, repository: repository(plan.repository) }))
|
|
78
|
+
throw new Error('This key belongs to a different workflow.');
|
|
79
|
+
return this.status(r.id);
|
|
80
|
+
}
|
|
81
|
+
const root = repository(plan.repository);
|
|
82
|
+
const state = realpathSync(this.state);
|
|
83
|
+
if (state === root || state.startsWith(root + sep))
|
|
84
|
+
throw new Error('Keep Transmission state outside the target repository.');
|
|
85
|
+
if ([...this.runs.values()].some((r) => (!terminal(r.status) || this.settling.has(r.id)) &&
|
|
86
|
+
r.plan.repository === root))
|
|
87
|
+
throw new Error('A workflow is already active in this project.');
|
|
88
|
+
const id = randomUUID();
|
|
89
|
+
const r = {
|
|
90
|
+
id,
|
|
91
|
+
plan: { ...plan, repository: root },
|
|
92
|
+
baseline: snapshot(root, join(this.state, id)),
|
|
93
|
+
index: 0,
|
|
94
|
+
status: 'running',
|
|
95
|
+
phase: 'worker',
|
|
96
|
+
generation: 0,
|
|
97
|
+
repairsUsed: 0,
|
|
98
|
+
feedback: '',
|
|
99
|
+
messages: [],
|
|
100
|
+
guidance: [],
|
|
101
|
+
formatErrors: 0,
|
|
102
|
+
accepted: [],
|
|
103
|
+
attempts: [],
|
|
104
|
+
};
|
|
105
|
+
this.save(r, 'started');
|
|
106
|
+
this.runs.set(id, r);
|
|
107
|
+
this.wake(r);
|
|
108
|
+
return this.status(id);
|
|
109
|
+
}
|
|
110
|
+
status(id) {
|
|
111
|
+
const r = this.get(id);
|
|
112
|
+
return {
|
|
113
|
+
runId: id,
|
|
114
|
+
status: r.status,
|
|
115
|
+
task: r.plan.tasks[r.index]?.name,
|
|
116
|
+
phase: terminal(r.status) ? undefined : r.phase,
|
|
117
|
+
accepted: r.accepted,
|
|
118
|
+
decision: r.question,
|
|
119
|
+
reason: r.failure,
|
|
120
|
+
attempts: r.attempts,
|
|
121
|
+
...(r.status === 'completed'
|
|
122
|
+
? {
|
|
123
|
+
result: r.accepted.at(-1).result,
|
|
124
|
+
verdict: r.accepted.at(-1).verdict,
|
|
125
|
+
}
|
|
126
|
+
: {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
events(id, after) {
|
|
130
|
+
this.get(id);
|
|
131
|
+
return this.db
|
|
132
|
+
.prepare('SELECT sequence,time,kind,detail FROM events WHERE run=? AND sequence>? ORDER BY sequence LIMIT 100')
|
|
133
|
+
.all(id, after)
|
|
134
|
+
.map((e) => ({
|
|
135
|
+
sequence: Number(e.sequence),
|
|
136
|
+
time: String(e.time),
|
|
137
|
+
kind: String(e.kind),
|
|
138
|
+
detail: JSON.parse(String(e.detail)),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
diff(id, offset) {
|
|
142
|
+
const r = this.get(id), rev = r.accepted.at(-1)?.revision;
|
|
143
|
+
if (!rev)
|
|
144
|
+
return { content: '', nextOffset: null };
|
|
145
|
+
const path = join(this.dir(r), rev + '.patch'), size = statSync(path).size, fd = openSync(path, 'r');
|
|
146
|
+
try {
|
|
147
|
+
const b = Buffer.alloc(Math.max(0, Math.min(size - offset, 65536)));
|
|
148
|
+
const n = readSync(fd, b, 0, b.length, offset);
|
|
149
|
+
return {
|
|
150
|
+
content: b.subarray(0, n).toString('base64'),
|
|
151
|
+
nextOffset: offset + n < size ? offset + n : null,
|
|
152
|
+
revision: rev,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
closeSync(fd);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
answer(id, questionId, answer) {
|
|
160
|
+
const r = this.get(id);
|
|
161
|
+
if (r.lastAnswer?.id === questionId && r.lastAnswer.answer === answer)
|
|
162
|
+
return this.status(id);
|
|
163
|
+
if (r.status !== 'needs_input' || r.question?.id !== questionId)
|
|
164
|
+
throw new Error('This decision is no longer pending.');
|
|
165
|
+
if (r.question.options &&
|
|
166
|
+
!r.question.options.some((opt) => opt.id === answer))
|
|
167
|
+
throw new Error('Select one of the offered option IDs.');
|
|
168
|
+
const q = r.question, p = this.pending.get(id);
|
|
169
|
+
delete r.question;
|
|
170
|
+
r.lastAnswer = { id: questionId, answer };
|
|
171
|
+
r.status = 'running';
|
|
172
|
+
if (!p || p.id !== q.id)
|
|
173
|
+
r.guidance.push('Decision: ' + q.text + '\nUser answer: ' + answer);
|
|
174
|
+
this.save(r, 'answered', { question: q, answer });
|
|
175
|
+
this.pending.delete(id);
|
|
176
|
+
p?.resolve(answer);
|
|
177
|
+
this.wake(r);
|
|
178
|
+
return this.status(id);
|
|
179
|
+
}
|
|
180
|
+
message(id, message) {
|
|
181
|
+
const r = this.get(id);
|
|
182
|
+
if (terminal(r.status))
|
|
183
|
+
throw new Error('Workflow has ended.');
|
|
184
|
+
r.messages.push(message);
|
|
185
|
+
r.guidance.push(message);
|
|
186
|
+
this.save(r, 'message', { message });
|
|
187
|
+
return this.status(id);
|
|
188
|
+
}
|
|
189
|
+
async cancel(id) {
|
|
190
|
+
const r = this.get(id);
|
|
191
|
+
if (!terminal(r.status)) {
|
|
192
|
+
this.settling.add(id);
|
|
193
|
+
r.status = 'cancelled';
|
|
194
|
+
delete r.question;
|
|
195
|
+
this.save(r, 'cancelled');
|
|
196
|
+
try {
|
|
197
|
+
await this.dispose(r);
|
|
198
|
+
await this.pumps.get(id);
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
this.settling.delete(id);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return this.status(id);
|
|
205
|
+
}
|
|
206
|
+
async dispose(r) {
|
|
207
|
+
this.pending.get(r.id)?.resolve(undefined);
|
|
208
|
+
this.pending.delete(r.id);
|
|
209
|
+
const agent = this.agents.get(r.id);
|
|
210
|
+
this.agents.delete(r.id);
|
|
211
|
+
await agent?.close();
|
|
212
|
+
}
|
|
213
|
+
async close() {
|
|
214
|
+
this.closing = true;
|
|
215
|
+
await Promise.all([...this.runs.values()].map((r) => this.dispose(r)));
|
|
216
|
+
await Promise.all(this.pumps.values());
|
|
217
|
+
this.db.close();
|
|
218
|
+
}
|
|
219
|
+
wake(r) {
|
|
220
|
+
if (this.closing || r.status !== 'running' || this.pumps.has(r.id))
|
|
221
|
+
return;
|
|
222
|
+
const work = Promise.resolve()
|
|
223
|
+
.then(() => this.drive(r))
|
|
224
|
+
.finally(() => {
|
|
225
|
+
this.pumps.delete(r.id);
|
|
226
|
+
this.wake(r);
|
|
227
|
+
});
|
|
228
|
+
this.pumps.set(r.id, work);
|
|
229
|
+
}
|
|
230
|
+
retireSessions(r) {
|
|
231
|
+
delete r.worker;
|
|
232
|
+
delete r.verifier;
|
|
233
|
+
delete r.candidate;
|
|
234
|
+
r.phase = 'worker';
|
|
235
|
+
r.formatErrors = 0;
|
|
236
|
+
}
|
|
237
|
+
restart(r, reason) {
|
|
238
|
+
r.attempts.push(reason);
|
|
239
|
+
this.retireSessions(r);
|
|
240
|
+
r.repairsUsed = 0;
|
|
241
|
+
if (r.generation >= r.plan.retries) {
|
|
242
|
+
r.failure = reason + ' Fresh-session retry limit reached.';
|
|
243
|
+
r.status = 'failed';
|
|
244
|
+
delete r.question;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
r.generation++;
|
|
248
|
+
r.feedback = reason + ' Inspect existing work before continuing.';
|
|
249
|
+
r.status = 'running';
|
|
250
|
+
delete r.question;
|
|
251
|
+
}
|
|
252
|
+
this.save(r, 'attempt_ended', {
|
|
253
|
+
reason,
|
|
254
|
+
next: r.status,
|
|
255
|
+
retriesUsed: r.generation,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
ask(r, question) {
|
|
259
|
+
r.question = question;
|
|
260
|
+
r.status = 'needs_input';
|
|
261
|
+
this.save(r, 'needs_input', question);
|
|
262
|
+
}
|
|
263
|
+
client(r) {
|
|
264
|
+
let agent = this.agents.get(r.id);
|
|
265
|
+
if (agent)
|
|
266
|
+
return agent;
|
|
267
|
+
agent = this.factory({
|
|
268
|
+
tool: (session, detail) => this.event(r, 'tool', { session, detail }),
|
|
269
|
+
permission: async (request) => {
|
|
270
|
+
if (r.status !== 'running' || this.closing)
|
|
271
|
+
return undefined;
|
|
272
|
+
const once = request.options.find((o) => o.kind === 'allow_once');
|
|
273
|
+
if (r.plan.autoApprove && once) {
|
|
274
|
+
this.event(r, 'permission', {
|
|
275
|
+
session: request.sessionId,
|
|
276
|
+
selected: once.optionId,
|
|
277
|
+
});
|
|
278
|
+
return once.optionId;
|
|
279
|
+
}
|
|
280
|
+
const question = {
|
|
281
|
+
id: randomUUID(),
|
|
282
|
+
text: request.toolCall.title ?? 'Choose an agent permission.',
|
|
283
|
+
options: request.options.map((o) => ({
|
|
284
|
+
id: o.optionId,
|
|
285
|
+
name: o.name,
|
|
286
|
+
})),
|
|
287
|
+
};
|
|
288
|
+
this.ask(r, question);
|
|
289
|
+
return new Promise((resolve) => this.pending.set(r.id, { id: question.id, resolve }));
|
|
290
|
+
},
|
|
291
|
+
}, r.plan.repository);
|
|
292
|
+
this.agents.set(r.id, agent);
|
|
293
|
+
return agent;
|
|
294
|
+
}
|
|
295
|
+
async drive(r) {
|
|
296
|
+
try {
|
|
297
|
+
while (!this.closing && r.status === 'running') {
|
|
298
|
+
const harness = this.client(r), role = r.phase, task = r.plan.tasks[r.index];
|
|
299
|
+
if (!r[role]) {
|
|
300
|
+
const session = await harness.session(r.plan.repository);
|
|
301
|
+
if (this.closing || r.status !== 'running')
|
|
302
|
+
return;
|
|
303
|
+
r[role] = session;
|
|
304
|
+
this.save(r, 'session_started', {
|
|
305
|
+
role,
|
|
306
|
+
session,
|
|
307
|
+
task: task.name,
|
|
308
|
+
generation: r.generation,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
const session = r[role], messages = [...r.messages];
|
|
312
|
+
const data = {
|
|
313
|
+
task: role === 'verifier'
|
|
314
|
+
? task
|
|
315
|
+
: {
|
|
316
|
+
name: task.name,
|
|
317
|
+
instructions: task.instructions,
|
|
318
|
+
checks: task.checks,
|
|
319
|
+
},
|
|
320
|
+
incoming: messages,
|
|
321
|
+
priorTasks: r.accepted.slice(-8).map((a) => ({
|
|
322
|
+
name: a.name,
|
|
323
|
+
result: a.result.slice(0, 4096),
|
|
324
|
+
})),
|
|
325
|
+
feedback: r.feedback,
|
|
326
|
+
operatorGuidance: r.guidance.join('\n').slice(-65536),
|
|
327
|
+
...(role === 'verifier' ? { candidate: r.candidate } : {}),
|
|
328
|
+
};
|
|
329
|
+
const instructions = role === 'worker'
|
|
330
|
+
? 'Implement the assigned task using your normal tools in this project. Preserve prior edits, HEAD and staging. Install dependencies and run the relevant checks. Finish commands and stop temporary background services before submitting. Act on feedback from independent review. End with one line of JSON: {"kind":"result","summary":"result and executed checks"}.'
|
|
331
|
+
: 'Independently verify the candidate in the current repository against the verification prompt. Inspect and test it yourself. Leave the source unchanged. If task.checks are specified, run each command with your own harness and include a checks array in the final JSON with command (exact), passed (boolean), and evidence (observed output) for each. End with one line of JSON: {"kind":"verdict","decision":"accept" or "reject","reason":"specific evidence or actionable repair instructions"}.';
|
|
332
|
+
this.save(r, 'turn_started', { role, session, task: task.name });
|
|
333
|
+
const raw = await harness.prompt(session, instructions +
|
|
334
|
+
' Only for a genuine decision about intent or scope, end with {"kind":"question","question":"decision needed"}.\n' +
|
|
335
|
+
JSON.stringify(data));
|
|
336
|
+
if (this.closing || terminal(r.status))
|
|
337
|
+
return;
|
|
338
|
+
// Retain messages until a turn consumes them successfully.
|
|
339
|
+
r.messages.splice(0, messages.length);
|
|
340
|
+
const line = raw
|
|
341
|
+
.trim()
|
|
342
|
+
.replace(/^```(?:json)?\s*|\s*```$/g, '')
|
|
343
|
+
.trim();
|
|
344
|
+
let value;
|
|
345
|
+
try {
|
|
346
|
+
value = JSON.parse(line);
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
try {
|
|
350
|
+
value = JSON.parse(line.split('\n').at(-1));
|
|
351
|
+
}
|
|
352
|
+
catch { }
|
|
353
|
+
}
|
|
354
|
+
const reply = role === 'worker'
|
|
355
|
+
? workerReply.safeParse(value)
|
|
356
|
+
: verifierReply.safeParse(value);
|
|
357
|
+
if (!reply.success &&
|
|
358
|
+
role === 'verifier' &&
|
|
359
|
+
r.formatErrors < r.plan.repairs) {
|
|
360
|
+
r.formatErrors++;
|
|
361
|
+
r.feedback =
|
|
362
|
+
'Your verdict could not be parsed. Return the specified JSON verdict and evidence.';
|
|
363
|
+
this.save(r, 'invalid_verdict', { session });
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (!reply.success && role === 'verifier') {
|
|
367
|
+
this.restart(r, 'The verifier did not return a valid verdict.');
|
|
368
|
+
await this.dispose(r);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (!reply.success) {
|
|
372
|
+
await this.repair(r, 'Invalid ' +
|
|
373
|
+
role +
|
|
374
|
+
' response. Return the requested final JSON object.');
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
r.formatErrors = 0;
|
|
378
|
+
const v = reply.data;
|
|
379
|
+
if (v.kind === 'question') {
|
|
380
|
+
this.ask(r, { id: randomUUID(), text: v.question });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const revision = snapshot(r.plan.repository, this.dir(r));
|
|
384
|
+
if (v.kind === 'result') {
|
|
385
|
+
r.candidate = { summary: v.summary, revision };
|
|
386
|
+
delete r.verifier;
|
|
387
|
+
r.phase = 'verifier';
|
|
388
|
+
r.feedback = '';
|
|
389
|
+
this.save(r, 'submitted', { session, revision, summary: v.summary });
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
const candidate = r.candidate;
|
|
393
|
+
const missing = task.checks?.filter((command) => !v.checks?.some((c) => c.command === command && c.passed));
|
|
394
|
+
if (v.decision === 'accept' && missing?.length) {
|
|
395
|
+
v.decision = 'reject';
|
|
396
|
+
v.reason =
|
|
397
|
+
'Missing passing verifier evidence for ' +
|
|
398
|
+
missing.join(', ') +
|
|
399
|
+
'. ' +
|
|
400
|
+
v.reason;
|
|
401
|
+
}
|
|
402
|
+
this.save(r, 'verdict', {
|
|
403
|
+
worker: r.worker,
|
|
404
|
+
verifier: session,
|
|
405
|
+
revision: candidate.revision,
|
|
406
|
+
...v,
|
|
407
|
+
});
|
|
408
|
+
if (v.decision === 'reject' ||
|
|
409
|
+
candidate.revision !== revision ||
|
|
410
|
+
r.messages.length ||
|
|
411
|
+
messages.length) {
|
|
412
|
+
await this.repair(r, v.decision === 'reject'
|
|
413
|
+
? v.reason
|
|
414
|
+
: candidate.revision !== revision
|
|
415
|
+
? 'Source changed during verification. Submit the current candidate.'
|
|
416
|
+
: 'Address user guidance before resubmitting: ' +
|
|
417
|
+
[...messages, ...r.messages].join('\n'));
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const accepted = {
|
|
421
|
+
name: task.name,
|
|
422
|
+
result: candidate.summary,
|
|
423
|
+
revision,
|
|
424
|
+
worker: r.worker,
|
|
425
|
+
verifier: session,
|
|
426
|
+
verdict: {
|
|
427
|
+
decision: v.decision,
|
|
428
|
+
reason: v.reason,
|
|
429
|
+
...(v.checks ? { checks: v.checks } : {}),
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
const patch = join(this.dir(r), revision + '.patch'), tmp = patch + '.tmp', fd = openSync(tmp, 'w', 0o600);
|
|
433
|
+
try {
|
|
434
|
+
try {
|
|
435
|
+
writePatch(r.plan.repository, this.dir(r), r.baseline, revision, fd);
|
|
436
|
+
}
|
|
437
|
+
finally {
|
|
438
|
+
closeSync(fd);
|
|
439
|
+
}
|
|
440
|
+
renameSync(tmp, patch);
|
|
441
|
+
}
|
|
442
|
+
finally {
|
|
443
|
+
rmSync(tmp, { force: true });
|
|
444
|
+
}
|
|
445
|
+
r.accepted.push(accepted);
|
|
446
|
+
r.guidance = [];
|
|
447
|
+
r.index++;
|
|
448
|
+
r.phase = 'worker';
|
|
449
|
+
r.feedback = '';
|
|
450
|
+
r.repairsUsed = 0;
|
|
451
|
+
r.generation = 0;
|
|
452
|
+
delete r.worker;
|
|
453
|
+
delete r.verifier;
|
|
454
|
+
delete r.candidate;
|
|
455
|
+
if (r.index === r.plan.tasks.length)
|
|
456
|
+
r.status = 'completed';
|
|
457
|
+
this.save(r, 'task_accepted', accepted);
|
|
458
|
+
await this.dispose(r);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
if (this.closing || terminal(r.status))
|
|
463
|
+
return;
|
|
464
|
+
this.restart(r, diagnostic(error));
|
|
465
|
+
await this.dispose(r);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
async repair(r, reason) {
|
|
469
|
+
if (r.repairsUsed >= r.plan.repairs) {
|
|
470
|
+
this.restart(r, reason);
|
|
471
|
+
await this.dispose(r);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
r.repairsUsed++;
|
|
475
|
+
r.attempts.push(reason);
|
|
476
|
+
r.feedback = reason;
|
|
477
|
+
r.phase = 'worker';
|
|
478
|
+
delete r.verifier;
|
|
479
|
+
this.save(r, 'repair_requested', { worker: r.worker, reason });
|
|
480
|
+
}
|
|
481
|
+
}
|
package/dist/src/main.js
CHANGED
|
@@ -1,28 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
process.once('SIGINT', stop);
|
|
14
|
-
process.once('SIGTERM', stop);
|
|
15
|
-
try {
|
|
16
|
-
recordRuntimeBuild(input.stateDirectory);
|
|
17
|
-
await deployment.listen();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { operations, descriptions } from './contract.js';
|
|
7
|
+
import { call, ensure, serve } from './service.js';
|
|
8
|
+
const cmd = process.argv[2] ?? 'mcp';
|
|
9
|
+
async function main() {
|
|
10
|
+
if (cmd === 'engine') {
|
|
11
|
+
await serve();
|
|
12
|
+
return;
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await deployment.close();
|
|
23
|
-
throw error;
|
|
14
|
+
if (cmd === 'status' || cmd === 'stop') {
|
|
15
|
+
console.log(await call(cmd === 'status' ? 'health' : 'stop'));
|
|
16
|
+
return;
|
|
24
17
|
}
|
|
18
|
+
if (cmd === 'mcp-config') {
|
|
19
|
+
console.log(JSON.stringify({
|
|
20
|
+
mcpServers: {
|
|
21
|
+
transmission: {
|
|
22
|
+
command: process.execPath,
|
|
23
|
+
args: [process.argv[1], 'mcp'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}, null, 2));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (cmd !== 'mcp') {
|
|
30
|
+
throw new Error('Usage: code60 [mcp | mcp-config | status | stop]');
|
|
31
|
+
}
|
|
32
|
+
await ensure();
|
|
33
|
+
const server = new Server({ name: 'transmission', version: '1' }, {
|
|
34
|
+
capabilities: { tools: {} },
|
|
35
|
+
instructions: 'Design ordered tasks with independent verification criteria from the user’s goal. Present the workflow, obtain confirmation, then submit it once with start_workflow. Follow the same run. Ordinary repairs and retries run autonomously.',
|
|
36
|
+
});
|
|
37
|
+
server.setRequestHandler(ListToolsRequestSchema, () => ({
|
|
38
|
+
tools: Object.entries(operations).map(([name, schema]) => ({
|
|
39
|
+
name,
|
|
40
|
+
description: descriptions[name],
|
|
41
|
+
inputSchema: z.toJSONSchema(schema, { io: 'input' }),
|
|
42
|
+
})),
|
|
43
|
+
}));
|
|
44
|
+
server.setRequestHandler(CallToolRequestSchema, async ({ params }) => {
|
|
45
|
+
try {
|
|
46
|
+
if (!Object.hasOwn(operations, params.name))
|
|
47
|
+
throw new Error('Unknown workflow tool.');
|
|
48
|
+
const data = await call(params.name, params.arguments ?? {});
|
|
49
|
+
return {
|
|
50
|
+
structuredContent: data,
|
|
51
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
isError: true,
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
text: error instanceof Error
|
|
61
|
+
? error.message
|
|
62
|
+
: 'Workflow request failed.',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
await server.connect(new StdioServerTransport());
|
|
25
69
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
70
|
+
main().catch((error) => {
|
|
71
|
+
console.error(error.message);
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, realpathSync, rmSync, } from 'node:fs';
|
|
3
|
+
import { join, isAbsolute } from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
// A caller may itself be running inside a Git hook or a linked worktree.
|
|
6
|
+
function gitEnvironment() {
|
|
7
|
+
const env = { ...process.env };
|
|
8
|
+
for (const key of [
|
|
9
|
+
'GIT_DIR',
|
|
10
|
+
'GIT_COMMON_DIR',
|
|
11
|
+
'GIT_WORK_TREE',
|
|
12
|
+
'GIT_INDEX_FILE',
|
|
13
|
+
'GIT_OBJECT_DIRECTORY',
|
|
14
|
+
'GIT_ALTERNATE_OBJECT_DIRECTORIES',
|
|
15
|
+
'GIT_PREFIX',
|
|
16
|
+
])
|
|
17
|
+
delete env[key];
|
|
18
|
+
return env;
|
|
19
|
+
}
|
|
20
|
+
function git(root, args, env = gitEnvironment()) {
|
|
21
|
+
return execFileSync('git', [
|
|
22
|
+
'-C',
|
|
23
|
+
root,
|
|
24
|
+
'-c',
|
|
25
|
+
'core.hooksPath=/dev/null',
|
|
26
|
+
'-c',
|
|
27
|
+
'core.fsmonitor=false',
|
|
28
|
+
...args,
|
|
29
|
+
], {
|
|
30
|
+
env,
|
|
31
|
+
encoding: 'utf8',
|
|
32
|
+
timeout: 120000,
|
|
33
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
34
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
35
|
+
}).trimEnd();
|
|
36
|
+
}
|
|
37
|
+
export function repository(path) {
|
|
38
|
+
if (!isAbsolute(path))
|
|
39
|
+
throw new Error('Supply the absolute path of the existing project.');
|
|
40
|
+
return realpathSync(git(path, ['rev-parse', '--show-toplevel']));
|
|
41
|
+
}
|
|
42
|
+
function environment(root, dir) {
|
|
43
|
+
const objects = join(dir, 'objects');
|
|
44
|
+
mkdirSync(objects, { recursive: true });
|
|
45
|
+
return {
|
|
46
|
+
...gitEnvironment(),
|
|
47
|
+
GIT_OBJECT_DIRECTORY: objects,
|
|
48
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: JSON.stringify(git(root, [
|
|
49
|
+
'rev-parse',
|
|
50
|
+
'--path-format=absolute',
|
|
51
|
+
'--git-path',
|
|
52
|
+
'objects',
|
|
53
|
+
])),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Compare worktrees with Git's own ignore, mode, symlink and binary semantics.
|
|
57
|
+
// A disposable index and private objects leave staging and HEAD untouched.
|
|
58
|
+
export function snapshot(root, dir) {
|
|
59
|
+
const env = {
|
|
60
|
+
...environment(root, dir),
|
|
61
|
+
GIT_INDEX_FILE: join(dir, randomUUID() + '.index'),
|
|
62
|
+
};
|
|
63
|
+
const index = git(root, [
|
|
64
|
+
'rev-parse',
|
|
65
|
+
'--path-format=absolute',
|
|
66
|
+
'--git-path',
|
|
67
|
+
'index',
|
|
68
|
+
]);
|
|
69
|
+
try {
|
|
70
|
+
if (existsSync(index))
|
|
71
|
+
copyFileSync(index, env.GIT_INDEX_FILE);
|
|
72
|
+
git(root, ['add', '-A', '--', '.'], env);
|
|
73
|
+
return git(root, ['write-tree'], env);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
rmSync(env.GIT_INDEX_FILE, { force: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function writePatch(root, dir, baseline, revision, fd) {
|
|
80
|
+
execFileSync('git', [
|
|
81
|
+
'-C',
|
|
82
|
+
root,
|
|
83
|
+
'diff',
|
|
84
|
+
'--no-ext-diff',
|
|
85
|
+
'--no-textconv',
|
|
86
|
+
'--binary',
|
|
87
|
+
baseline,
|
|
88
|
+
revision,
|
|
89
|
+
], {
|
|
90
|
+
env: environment(root, dir),
|
|
91
|
+
stdio: ['ignore', fd, 'pipe'],
|
|
92
|
+
timeout: 120000,
|
|
93
|
+
});
|
|
94
|
+
}
|