code60-transmission-server 0.1.0-staging.12 → 0.1.0-staging.13
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/src/broker/index.js +53 -10
- package/dist/src/engine/workflow-engine.js +6 -4
- package/dist/src/server/api-contract.json +8 -0
- package/dist/src/server/application.js +1 -1
- package/dist/src/server/history-handlers.js +4 -1
- package/dist/src/tools/developer.js +6 -4
- package/package.json +1 -1
package/dist/src/broker/index.js
CHANGED
|
@@ -613,20 +613,26 @@ export class ActionBroker {
|
|
|
613
613
|
// No await/yield between committed active intent and invoking the protected effect.
|
|
614
614
|
// A reentrant pause inside execute sees active work and can only enter draining.
|
|
615
615
|
this.coordinator.assertOutsideTransaction();
|
|
616
|
-
|
|
617
|
-
|
|
616
|
+
let completed;
|
|
617
|
+
try {
|
|
618
|
+
effect = prepared.execute(id);
|
|
619
|
+
completed = await effect;
|
|
620
|
+
}
|
|
621
|
+
catch (error) {
|
|
622
|
+
// Only the trusted implementation can make this guarantee. Resource
|
|
623
|
+
// read scopes and source-read-only command flags are not sufficient.
|
|
624
|
+
if (!this.readOnlyEffect(action))
|
|
625
|
+
throw error;
|
|
626
|
+
const code = error instanceof BrokerError ? error.code :
|
|
627
|
+
['ENOENT', 'ENOTDIR', 'EISDIR', 'EACCES', 'EPERM', 'EIO', 'ERR_ENCODING_INVALID_ENCODED_DATA'].includes(error?.code ?? '') ? error.code : 'read_only_tool_failed';
|
|
628
|
+
completed = { success: false, text: `broker:${code}` };
|
|
629
|
+
}
|
|
630
|
+
const result = jsonCopy(completed);
|
|
618
631
|
if (typeof result.success !== "boolean" || typeof result.text !== "string")
|
|
619
632
|
throw new BrokerError("invalid_tool_result", 500);
|
|
620
633
|
// A completion projection failure must roll back even if its error
|
|
621
634
|
// carries the broker's authority-invalidation persist marker.
|
|
622
|
-
this.atomic(() => this.coordinator.atomic(() =>
|
|
623
|
-
this.db.prepare("UPDATE broker_dispatches SET state='completed',result=? WHERE id=?").run(canonical(result), id);
|
|
624
|
-
if (this.onToolCompletedSql)
|
|
625
|
-
runSqlCommitHook(this.onToolCompletedSql, Object.freeze({
|
|
626
|
-
binding: jsonCopy(admittedBinding), dispatch: { ...authorization }, result: { ...result },
|
|
627
|
-
}));
|
|
628
|
-
this.db.prepare("DELETE FROM broker_work WHERE run_id=? AND id=?").run(binding.runId, `effect:${id}`);
|
|
629
|
-
}));
|
|
635
|
+
this.atomic(() => this.coordinator.atomic(() => this.completeEffect(admittedBinding, authorization, result)));
|
|
630
636
|
return result;
|
|
631
637
|
}
|
|
632
638
|
catch (error) {
|
|
@@ -650,6 +656,43 @@ export class ActionBroker {
|
|
|
650
656
|
prepared.dispose?.();
|
|
651
657
|
}
|
|
652
658
|
}
|
|
659
|
+
completeEffect(binding, dispatch, result) {
|
|
660
|
+
this.db.prepare("UPDATE broker_dispatches SET state='completed',result=? WHERE id=?").run(canonical(result), dispatch.id);
|
|
661
|
+
if (this.onToolCompletedSql)
|
|
662
|
+
runSqlCommitHook(this.onToolCompletedSql, Object.freeze({
|
|
663
|
+
binding: jsonCopy(binding), dispatch: { ...dispatch }, result: { ...result },
|
|
664
|
+
}));
|
|
665
|
+
this.db.prepare("DELETE FROM broker_work WHERE run_id=? AND id=?").run(binding.runId, `effect:${dispatch.id}`);
|
|
666
|
+
}
|
|
667
|
+
readOnlyEffect(action) {
|
|
668
|
+
return this.tools.get(action.action.toolId)?.readOnly === true &&
|
|
669
|
+
action.action.resources.every(resource => resource.kind === 'filesystem' && resource.operation === 'read');
|
|
670
|
+
}
|
|
671
|
+
/** Trusted lifecycle settlement only after the runtime's physical stop barrier.
|
|
672
|
+
* Historical reads are settled as failed, never replayed or asserted successful.
|
|
673
|
+
* Mutation/command/network uncertainty remains held for reconciliation. */
|
|
674
|
+
reconcileReadOnlyEffects(runId, stopped) {
|
|
675
|
+
return this.atomic(() => this.coordinator.atomic(() => {
|
|
676
|
+
const reconciled = [];
|
|
677
|
+
const rows = this.rows("SELECT d.body FROM broker_dispatches d JOIN broker_work w ON w.id='effect:'||d.id WHERE w.run_id=? AND w.state='uncertain' AND d.state='uncertain' AND d.result IS NULL", runId);
|
|
678
|
+
for (const row of rows) {
|
|
679
|
+
const dispatch = JSON.parse(String(row.body));
|
|
680
|
+
if (!stopped.some(s => s.sessionId === dispatch.sessionId && s.epoch === dispatch.epoch))
|
|
681
|
+
continue;
|
|
682
|
+
const binding = this.read('broker_sessions', dispatch.sessionId), action = this.read('broker_actions', dispatch.actionRequestId);
|
|
683
|
+
if (binding.runId !== runId || binding.sessionId !== dispatch.sessionId || binding.epoch !== dispatch.epoch || binding.profileVersionId !== dispatch.profileVersionId || action.runId !== runId || action.state !== 'consumed' ||
|
|
684
|
+
action.stepExecutionId !== binding.stepExecutionId || !binding.configuredTools.includes(action.action.toolId) ||
|
|
685
|
+
action.sessionId !== binding.sessionId || action.epoch !== dispatch.epoch || action.profileVersionId !== dispatch.profileVersionId ||
|
|
686
|
+
action.actionDigest !== dispatch.actionDigest || action.resourceDigest !== dispatch.resourceDigest || !this.readOnlyEffect(action))
|
|
687
|
+
continue;
|
|
688
|
+
const result = { success: false, text: 'broker:read_only_effect_not_replayed_after_stop' };
|
|
689
|
+
this.completeEffect(binding, dispatch, result);
|
|
690
|
+
this.receipt(`read_only_recovery:${runId}`, dispatch.id, dispatch, { dispatchId: dispatch.id, sessionId: binding.sessionId, epoch: binding.epoch, observedAt: this.now(), result });
|
|
691
|
+
reconciled.push(dispatch.id);
|
|
692
|
+
}
|
|
693
|
+
return reconciled;
|
|
694
|
+
}));
|
|
695
|
+
}
|
|
653
696
|
bind(binding) {
|
|
654
697
|
const bound = jsonCopy(binding);
|
|
655
698
|
this.owned();
|
|
@@ -1638,7 +1638,7 @@ export class WorkflowEngine {
|
|
|
1638
1638
|
});
|
|
1639
1639
|
}
|
|
1640
1640
|
}
|
|
1641
|
-
|
|
1641
|
+
reconcileStoppedWork(runId) {
|
|
1642
1642
|
const work = this.store.coordinator.db.prepare("SELECT id FROM broker_work WHERE run_id=? AND state='uncertain'").all(runId);
|
|
1643
1643
|
this.store.coordinator.atomic(() => {
|
|
1644
1644
|
for (const { id } of work) {
|
|
@@ -1649,6 +1649,8 @@ export class WorkflowEngine {
|
|
|
1649
1649
|
this.store.coordinator.db.prepare("DELETE FROM broker_work WHERE run_id=? AND id=? AND state='uncertain'").run(runId, id);
|
|
1650
1650
|
}
|
|
1651
1651
|
});
|
|
1652
|
+
this.broker.reconcileReadOnlyEffects(runId, this.store.list('sessions', { runId, limit: Number.MAX_SAFE_INTEGER })
|
|
1653
|
+
.map(({ value }) => ({ sessionId: value.id, epoch: value.epoch })).filter(s => this.#stopped.has(s.sessionId)));
|
|
1652
1654
|
}
|
|
1653
1655
|
async recover(runId) {
|
|
1654
1656
|
let plan = this.commands.plan(runId);
|
|
@@ -1657,7 +1659,7 @@ export class WorkflowEngine {
|
|
|
1657
1659
|
return;
|
|
1658
1660
|
this.operationState(operationId, 'running');
|
|
1659
1661
|
await this.stopSessions(runId);
|
|
1660
|
-
this.
|
|
1662
|
+
this.reconcileStoppedWork(runId);
|
|
1661
1663
|
try {
|
|
1662
1664
|
this.options.reconcileCommands?.(runId);
|
|
1663
1665
|
}
|
|
@@ -1763,7 +1765,7 @@ export class WorkflowEngine {
|
|
|
1763
1765
|
async cancel(runId) {
|
|
1764
1766
|
const operationId = this.commands.plan(runId).cancelOperationId;
|
|
1765
1767
|
await this.stopSessions(runId);
|
|
1766
|
-
this.
|
|
1768
|
+
this.reconcileStoppedWork(runId);
|
|
1767
1769
|
if (!this.quiet(runId))
|
|
1768
1770
|
return;
|
|
1769
1771
|
this.store.coordinator.atomic(() => {
|
|
@@ -1783,7 +1785,7 @@ export class WorkflowEngine {
|
|
|
1783
1785
|
async finish(runId) {
|
|
1784
1786
|
let run = this.store.get('runs', runId);
|
|
1785
1787
|
await this.stopSessions(runId);
|
|
1786
|
-
this.
|
|
1788
|
+
this.reconcileStoppedWork(runId);
|
|
1787
1789
|
if (!this.quiet(runId))
|
|
1788
1790
|
return;
|
|
1789
1791
|
if (!terminal(run)) {
|
|
@@ -7373,6 +7373,14 @@
|
|
|
7373
7373
|
"Run": {
|
|
7374
7374
|
"type": "object",
|
|
7375
7375
|
"properties": {
|
|
7376
|
+
"inFlightWork": {
|
|
7377
|
+
"type": "array",
|
|
7378
|
+
"readOnly": true,
|
|
7379
|
+
"description": "Read-time snapshot of the complete work barrier, including uncertain tool effects during normal execution. executionControl.inFlightWork describes pause draining only. Omitted when no work remains.",
|
|
7380
|
+
"items": {
|
|
7381
|
+
"$ref": "#/components/schemas/InFlightWork"
|
|
7382
|
+
}
|
|
7383
|
+
},
|
|
7376
7384
|
"id": {
|
|
7377
7385
|
"$ref": "#/components/schemas/Id"
|
|
7378
7386
|
},
|
|
@@ -31,7 +31,7 @@ export function createApplication(services) {
|
|
|
31
31
|
const codingHandlers = coding?.handlers() ?? new Map(['getCodingReadiness', 'startCodingTask', 'getCodingTaskResult', 'sendTaskMessage', 'listTaskQuestions', 'answerTaskQuestion'].map(name => [name, () => { throw new ApiError(503, 'coding_unavailable', 'This deployment does not have coding services configured.'); }]));
|
|
32
32
|
const paging = new Paging(coordinator);
|
|
33
33
|
const handlers = new Map([...controlPlaneHandlers(store, publication, paging, checks),
|
|
34
|
-
...historyHandlers(store, auth, paging), ...brokerHandlers(store, broker, auth, paging, id => commands.binding(id), engine.projection),
|
|
34
|
+
...historyHandlers(store, auth, paging, id => engine.work(id)), ...brokerHandlers(store, broker, auth, paging, id => commands.binding(id), engine.projection),
|
|
35
35
|
...workspaceHandlers(store, workspaces, auth, paging), ...toolEventHandlers(store, auth, id => commands.binding(id)), ...commands.handlers(), ...codingHandlers]);
|
|
36
36
|
const app = createHttpServer({ auth, validation, handlers, requireComplete: true });
|
|
37
37
|
coordinator.setQuiescenceProbe(id => engine.quiet(id));
|
|
@@ -3,9 +3,12 @@ import { AuthService } from './auth.js';
|
|
|
3
3
|
import { Paging } from './paging.js';
|
|
4
4
|
import { ApiError } from './errors.js';
|
|
5
5
|
import { durationMs } from '../engine/timing.js';
|
|
6
|
-
export function historyHandlers(store, auth, paging) {
|
|
6
|
+
export function historyHandlers(store, auth, paging, work) {
|
|
7
7
|
const handlers = new Map();
|
|
8
8
|
const publicRun = (value) => {
|
|
9
|
+
const active = work?.(value.id);
|
|
10
|
+
if (active?.length)
|
|
11
|
+
value = { ...value, inFlightWork: active };
|
|
9
12
|
if (value.state !== 'cancelled' || value.executionControl.status !== 'paused' || value.executionControl.pausedAt)
|
|
10
13
|
return value;
|
|
11
14
|
// Older cancellations discarded the pause metadata required by the wire
|
|
@@ -27,6 +27,7 @@ export const DEVELOPER_DEFINITIONS = new Map([
|
|
|
27
27
|
['get_capabilities', { description: 'Inspect your actual tools, filesystem permissions, network policy, and remaining session limits.', inputSchema: schema({}) }],
|
|
28
28
|
]);
|
|
29
29
|
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
30
|
+
const readOnlyTools = new Set(['read_file', 'list_files', 'search_files', 'get_diff', 'get_context', 'get_capabilities', 'read_command_output']);
|
|
30
31
|
export class DeveloperTools {
|
|
31
32
|
options;
|
|
32
33
|
validators = new Map([...DEVELOPER_DEFINITIONS].map(([name, d]) => [name, new Ajv2020({ strict: false }).compile(d.inputSchema)]));
|
|
@@ -35,7 +36,7 @@ export class DeveloperTools {
|
|
|
35
36
|
constructor(options) {
|
|
36
37
|
this.options = options;
|
|
37
38
|
}
|
|
38
|
-
registry() { return new Map([...DEVELOPER_DEFINITIONS].map(([name, definition]) => [name, { name, ...definition, prepare: (input, binding) => this.prepare(name, input, binding) }])); }
|
|
39
|
+
registry() { return new Map([...DEVELOPER_DEFINITIONS].map(([name, definition]) => [name, { name, ...definition, ...(readOnlyTools.has(name) ? { readOnly: true } : {}), prepare: (input, binding) => this.prepare(name, input, binding) }])); }
|
|
39
40
|
refreshInputWait(runId) {
|
|
40
41
|
const run = this.options.store.find('runs', runId);
|
|
41
42
|
if (!run)
|
|
@@ -312,6 +313,7 @@ export class DeveloperTools {
|
|
|
312
313
|
return result({ matches, nextCursor: more ? cursor + matches.length : null });
|
|
313
314
|
}
|
|
314
315
|
return this.options.workspaces.sourceMutation(context, repo => {
|
|
316
|
+
const rejected = (code) => ({ success: false, text: `broker:${code}` });
|
|
315
317
|
const path = repo.safePath(String(args.path), true, ['apply_patch', 'write_file'].includes(name), ['delete_file', 'move_file'].includes(name)), atomicWrite = (content) => { const mode = existsSync(path) ? lstatSync(path).mode & 0o777 : 0o600, temporary = join(dirname(path), `.code60-${randomUUID()}`); try {
|
|
316
318
|
writeFileSync(temporary, content, { flag: 'wx', mode });
|
|
317
319
|
renameSync(temporary, path);
|
|
@@ -327,11 +329,11 @@ export class DeveloperTools {
|
|
|
327
329
|
else if (name === 'apply_patch') {
|
|
328
330
|
let content = readFileSync(path, 'utf8');
|
|
329
331
|
if (hash(content) !== args.expectedDigest)
|
|
330
|
-
|
|
332
|
+
return rejected('patch_precondition_failed');
|
|
331
333
|
for (const edit of args.edits) {
|
|
332
334
|
const offset = content.indexOf(edit.oldText);
|
|
333
335
|
if (offset < 0 || content.indexOf(edit.oldText, offset + 1) >= 0)
|
|
334
|
-
|
|
336
|
+
return rejected('patch_match_not_unique');
|
|
335
337
|
content = content.slice(0, offset) + edit.newText + content.slice(offset + edit.oldText.length);
|
|
336
338
|
}
|
|
337
339
|
atomicWrite(content);
|
|
@@ -341,7 +343,7 @@ export class DeveloperTools {
|
|
|
341
343
|
else if (name === 'move_file') {
|
|
342
344
|
const destination = repo.safePath(String(args.destination), true);
|
|
343
345
|
if (existsSync(destination))
|
|
344
|
-
|
|
346
|
+
return rejected('destination_exists');
|
|
345
347
|
renameSync(path, destination);
|
|
346
348
|
}
|
|
347
349
|
else
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code60-transmission-server",
|
|
3
|
-
"version": "0.1.0-staging.
|
|
3
|
+
"version": "0.1.0-staging.13",
|
|
4
4
|
"description": "Local workflow server and stdio MCP launcher for bounded coding-agent steps against Git workspaces.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|