code60-transmission-server 0.1.0-staging.2 → 0.1.0-staging.20

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 (94) hide show
  1. package/INTENT.md +47 -0
  2. package/README.md +58 -253
  3. package/dist/src/acp.js +115 -0
  4. package/dist/src/contract.js +108 -0
  5. package/dist/src/engine.js +596 -0
  6. package/dist/src/main.js +72 -22
  7. package/dist/src/repository.js +94 -0
  8. package/dist/src/service.js +188 -0
  9. package/package.json +16 -32
  10. package/reference/openapi.json +834 -0
  11. package/README.engine.md +0 -401
  12. package/dist/src/broker/filesystem.js +0 -385
  13. package/dist/src/broker/index.js +0 -734
  14. package/dist/src/broker/native/README.md +0 -192
  15. package/dist/src/broker/native/build.js +0 -43
  16. package/dist/src/broker/native/fs-helper.c +0 -529
  17. package/dist/src/broker/native/git-helper.c +0 -205
  18. package/dist/src/broker/policy.js +0 -149
  19. package/dist/src/broker/startup-lock.js +0 -14
  20. package/dist/src/broker/types.js +0 -11
  21. package/dist/src/cli/daemon.js +0 -365
  22. package/dist/src/cli/helpers.js +0 -104
  23. package/dist/src/cli/main.js +0 -180
  24. package/dist/src/config/deployment.js +0 -163
  25. package/dist/src/config/documents.js +0 -29
  26. package/dist/src/config/profile-validation.js +0 -123
  27. package/dist/src/config/schema-graph.js +0 -237
  28. package/dist/src/config/schema-loader.js +0 -185
  29. package/dist/src/config/validation-pool.js +0 -105
  30. package/dist/src/config/validation-protocol.js +0 -1
  31. package/dist/src/config/validation-worker.js +0 -106
  32. package/dist/src/config/workflow-language.js +0 -9
  33. package/dist/src/config/workflow-schema.json +0 -534
  34. package/dist/src/config/workflow-types.js +0 -1
  35. package/dist/src/config/workflow-validation.js +0 -95
  36. package/dist/src/engine/budgets.js +0 -50
  37. package/dist/src/engine/clocks.js +0 -27
  38. package/dist/src/engine/commands.js +0 -441
  39. package/dist/src/engine/contracts.js +0 -11
  40. package/dist/src/engine/drain-state.js +0 -31
  41. package/dist/src/engine/effective-permissions.js +0 -120
  42. package/dist/src/engine/instruction-pins.js +0 -205
  43. package/dist/src/engine/retries.js +0 -50
  44. package/dist/src/engine/state.js +0 -1
  45. package/dist/src/engine/timing.js +0 -23
  46. package/dist/src/engine/tool-observations.js +0 -87
  47. package/dist/src/engine/workflow-engine.js +0 -1807
  48. package/dist/src/mcp/catalog.js +0 -71
  49. package/dist/src/mcp/main.js +0 -24
  50. package/dist/src/mcp/server.js +0 -104
  51. package/dist/src/runtime/codex-app-server.js +0 -91
  52. package/dist/src/runtime/containment.js +0 -82
  53. package/dist/src/runtime/engine-driver.js +0 -212
  54. package/dist/src/runtime/json-line-writer.js +0 -192
  55. package/dist/src/runtime/pinned-instruction-sources.js +0 -24
  56. package/dist/src/runtime/protocol-client.js +0 -264
  57. package/dist/src/runtime/protocol-pool.js +0 -183
  58. package/dist/src/runtime/protocol-projection.js +0 -393
  59. package/dist/src/runtime/protocol-types.js +0 -1
  60. package/dist/src/runtime/protocol-worker.js +0 -18
  61. package/dist/src/runtime/provider-bridge.js +0 -288
  62. package/dist/src/runtime/provider-credentials.js +0 -41
  63. package/dist/src/runtime/provider-transport.js +0 -404
  64. package/dist/src/runtime/runtime-broker.js +0 -213
  65. package/dist/src/runtime/workspace-instructions.js +0 -120
  66. package/dist/src/runtime/workspace-view.js +0 -74
  67. package/dist/src/server/api-contract.json +0 -11078
  68. package/dist/src/server/api-types.js +0 -1
  69. package/dist/src/server/application.js +0 -38
  70. package/dist/src/server/auth.js +0 -67
  71. package/dist/src/server/broker-handlers.js +0 -242
  72. package/dist/src/server/control-plane.js +0 -50
  73. package/dist/src/server/deployment.js +0 -237
  74. package/dist/src/server/errors.js +0 -22
  75. package/dist/src/server/history-handlers.js +0 -113
  76. package/dist/src/server/http.js +0 -124
  77. package/dist/src/server/paging.js +0 -56
  78. package/dist/src/server/publication.js +0 -119
  79. package/dist/src/server/tool-event-handler.js +0 -77
  80. package/dist/src/server/workspace-handlers.js +0 -34
  81. package/dist/src/storage/coordinator.js +0 -224
  82. package/dist/src/storage/startup-lock.js +0 -71
  83. package/dist/src/storage/store.js +0 -167
  84. package/dist/src/tools/check-worker.js +0 -81
  85. package/dist/src/tools/checks.js +0 -106
  86. package/dist/src/tools/dns.js +0 -248
  87. package/dist/src/tools/http-contract.js +0 -38
  88. package/dist/src/tools/http.js +0 -358
  89. package/dist/src/tools/index.js +0 -177
  90. package/dist/src/tools/worker-check.js +0 -73
  91. package/dist/src/workspaces/git.js +0 -227
  92. package/dist/src/workspaces/index.js +0 -715
  93. package/examples/deployment.local.json +0 -22
  94. package/scripts/postinstall.mjs +0 -25
@@ -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
+ }
@@ -0,0 +1,188 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ import { createServer } from 'node:http';
3
+ import { randomBytes, randomUUID } from 'node:crypto';
4
+ import { execFileSync, spawn } from 'node:child_process';
5
+ import { closeSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
6
+ import { homedir } from 'node:os';
7
+ import { dirname, join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { setTimeout as delay } from 'node:timers/promises';
10
+ import {} from './engine.js';
11
+ import { operations } from './contract.js';
12
+ const main = fileURLToPath(new URL('./main.js', import.meta.url));
13
+ export const state = process.env.TRANSMISSION_STATE_DIR ??
14
+ join(homedir(), 'Library/Application Support/Code60 Transmission/workflows');
15
+ const addressFile = join(state, 'endpoint.json');
16
+ function atomic(path, content) {
17
+ const temp = path + '.' + randomUUID();
18
+ writeFileSync(temp, content, { mode: 0o600 });
19
+ renameSync(temp, path);
20
+ }
21
+ function address() {
22
+ return JSON.parse(readFileSync(addressFile, 'utf8'));
23
+ }
24
+ export async function call(op, args = {}, endpoint = address()) {
25
+ const resp = await fetch('http://127.0.0.1:' + endpoint.port + '/' + op, {
26
+ method: 'POST',
27
+ headers: { authorization: 'Bearer ' + endpoint.token },
28
+ body: JSON.stringify(args),
29
+ signal: AbortSignal.timeout(op === 'health' ? 2000 : 180000),
30
+ });
31
+ const body = await resp.json();
32
+ if (!resp.ok)
33
+ throw new Error(body.error ?? 'Transmission request failed.');
34
+ return body;
35
+ }
36
+ export async function dispatch(engine, op, args) {
37
+ switch (op) {
38
+ case 'start_workflow':
39
+ return engine.start(operations.start_workflow.parse(args));
40
+ case 'get_workflow':
41
+ return engine.status(operations.get_workflow.parse(args).runId);
42
+ case 'get_workflow_events': {
43
+ const a = operations.get_workflow_events.parse(args);
44
+ return { events: engine.events(a.runId, a.after) };
45
+ }
46
+ case 'get_workflow_diff': {
47
+ const a = operations.get_workflow_diff.parse(args);
48
+ return engine.diff(a.runId, a.offset);
49
+ }
50
+ case 'answer_workflow_question': {
51
+ const a = operations.answer_workflow_question.parse(args);
52
+ return engine.answer(a.runId, a.questionId, a.answer);
53
+ }
54
+ case 'send_workflow_message': {
55
+ const a = operations.send_workflow_message.parse(args);
56
+ return engine.message(a.runId, a.message);
57
+ }
58
+ case 'cancel_workflow':
59
+ return engine.cancel(operations.cancel_workflow.parse(args).runId);
60
+ case 'pause_workflow':
61
+ return engine.pause(operations.pause_workflow.parse(args).runId);
62
+ case 'resume_workflow':
63
+ return engine.resume(operations.resume_workflow.parse(args).runId);
64
+ default:
65
+ throw new Error('Unknown operation.');
66
+ }
67
+ }
68
+ export async function serve() {
69
+ process.umask(0o077);
70
+ mkdirSync(state, { recursive: true, mode: 0o700 });
71
+ // The OS releases the writer lock on process death. Startup races never create two execution owners.
72
+ const lock = new DatabaseSync(join(state, 'owner.sqlite'));
73
+ try {
74
+ // A reserved writer lock is sufficient and coexists with other starters'
75
+ // transient read locks. An exclusive lock can make both starters lose.
76
+ lock.exec('BEGIN IMMEDIATE');
77
+ }
78
+ catch (error) {
79
+ lock.close();
80
+ if (error.errcode === 5)
81
+ return;
82
+ throw error;
83
+ }
84
+ const { Engine } = await import('./engine.js');
85
+ const engine = new Engine(state), token = randomBytes(32).toString('hex');
86
+ let stopping = false;
87
+ async function stop() {
88
+ if (stopping)
89
+ return;
90
+ stopping = true;
91
+ server.close();
92
+ await engine.close();
93
+ rmSync(addressFile, { force: true });
94
+ lock.close();
95
+ }
96
+ const server = createServer(async (req, res) => {
97
+ res.setHeader('Content-Type', 'application/json');
98
+ if (stopping) {
99
+ res.writeHead(503).end(JSON.stringify({ error: 'Engine is stopping.' }));
100
+ return;
101
+ }
102
+ if (req.method !== 'POST' ||
103
+ req.headers.authorization !== 'Bearer ' + token) {
104
+ res.writeHead(403).end('{}');
105
+ return;
106
+ }
107
+ try {
108
+ let s = '', size = 0;
109
+ req.setEncoding('utf8');
110
+ for await (const chunk of req) {
111
+ size += Buffer.byteLength(chunk);
112
+ if (size > 16 * 1024 * 1024)
113
+ throw new Error('Workflow request too large.');
114
+ s += chunk;
115
+ }
116
+ const op = req.url?.slice(1) ?? '';
117
+ const result = op === 'health'
118
+ ? { ready: true, pid: process.pid }
119
+ : op === 'stop'
120
+ ? { stopping: true }
121
+ : await dispatch(engine, op, JSON.parse(s));
122
+ res.end(JSON.stringify(result));
123
+ if (op === 'stop')
124
+ await stop();
125
+ }
126
+ catch (error) {
127
+ res.writeHead(400).end(JSON.stringify({
128
+ error: error instanceof Error ? error.message : 'Request failed.',
129
+ }));
130
+ }
131
+ });
132
+ await new Promise((resolve, reject) => {
133
+ server.once('error', reject);
134
+ server.listen(0, '127.0.0.1', resolve);
135
+ });
136
+ const bound = server.address();
137
+ if (!bound || typeof bound === 'string')
138
+ throw new Error('Missing listener.');
139
+ atomic(addressFile, JSON.stringify({ port: bound.port, token }));
140
+ process.once('SIGTERM', () => void stop());
141
+ process.once('SIGINT', () => void stop());
142
+ }
143
+ function installLoginAgent() {
144
+ if (process.platform !== 'darwin' || process.env.TRANSMISSION_STATE_DIR)
145
+ return;
146
+ const file = join(homedir(), 'Library/LaunchAgents/com.codemanufactory.transmission.workflows.plist');
147
+ const env = Object.fromEntries(['PATH', 'CODEX_HOME', 'CODEX_PATH'].flatMap((key) => process.env[key] ? [[key, process.env[key]]] : []));
148
+ const spec = {
149
+ Label: 'com.codemanufactory.transmission.workflows',
150
+ ProgramArguments: [process.execPath, main, 'engine'],
151
+ RunAtLoad: true,
152
+ EnvironmentVariables: env,
153
+ StandardErrorPath: join(state, 'engine.log'),
154
+ };
155
+ const data = execFileSync('/usr/bin/plutil', ['-convert', 'xml1', '-o', '-', '--', '-'], { input: JSON.stringify(spec) });
156
+ mkdirSync(dirname(file), { recursive: true });
157
+ atomic(file, data);
158
+ }
159
+ export async function ensure() {
160
+ mkdirSync(state, { recursive: true, mode: 0o700 });
161
+ installLoginAgent();
162
+ try {
163
+ await call('health');
164
+ return;
165
+ }
166
+ catch { }
167
+ const log = openSync(join(state, 'engine.log'), 'a', 0o600);
168
+ try {
169
+ spawn(process.execPath, [main, 'engine'], {
170
+ detached: true,
171
+ stdio: ['ignore', log, log],
172
+ }).unref();
173
+ }
174
+ finally {
175
+ closeSync(log);
176
+ }
177
+ const until = Date.now() + 20000;
178
+ while (Date.now() < until) {
179
+ try {
180
+ await call('health');
181
+ return;
182
+ }
183
+ catch {
184
+ await delay(100);
185
+ }
186
+ }
187
+ throw new Error('Engine did not start. See ' + join(state, 'engine.log'));
188
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "code60-transmission-server",
3
- "version": "0.1.0-staging.2",
4
- "description": "Local workflow server and stdio MCP launcher for bounded coding-agent steps against Git workspaces.",
3
+ "version": "0.1.0-staging.20",
4
+ "description": "Run user-approved workflows with independent coding agents over ACP.",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
7
7
  "mcp",
@@ -19,52 +19,36 @@
19
19
  "node": ">=24.22.0 <25"
20
20
  },
21
21
  "bin": {
22
- "code60-transmission-server": "dist/src/cli/main.js",
23
- "code60": "dist/src/cli/main.js"
22
+ "code60": "dist/src/main.js",
23
+ "code60-transmission-server": "dist/src/main.js"
24
24
  },
25
25
  "files": [
26
- "dist/src/**/*.js",
27
- "dist/src/**/*.json",
28
- "dist/src/broker/native/fs-helper.c",
29
- "dist/src/broker/native/git-helper.c",
30
- "dist/src/broker/native/README.md",
31
- "!dist/src/broker/native/.build",
32
- "!dist/src/broker/native/.build/**",
33
- "examples/deployment.local.json",
34
- "scripts/postinstall.mjs",
26
+ "dist/src",
27
+ "reference/openapi.json",
35
28
  "LICENSE",
36
29
  "README.md",
37
- "README.engine.md"
30
+ "INTENT.md"
38
31
  ],
39
32
  "scripts": {
40
- "start": "node dist/src/main.js",
41
- "build": "tsc -p tsconfig.build.json && node scripts/build-native.mjs",
33
+ "build": "tsc -p tsconfig.build.json",
42
34
  "prepack": "npm run build",
43
- "postinstall": "node scripts/postinstall.mjs",
44
- "package:macos": "bash scripts/package-macos.sh",
45
- "docs:api": "docker run --rm -p 127.0.0.1:8080:8080 -e SWAGGER_JSON=/spec/openapi.yaml -v \"$PWD/reference/workflow-engine/api:/spec:ro\" docker.swagger.io/swaggerapi/swagger-ui",
46
- "example:hello-world": "node examples/hello-world/run.mjs",
47
- "example:pull-request": "node examples/pull-request/run.mjs",
48
- "smoke:native": "node scripts/smoke-native.mjs",
49
35
  "typecheck": "tsc --noEmit",
50
36
  "test": "npm run build && vitest run",
51
- "test:pilot": "npm run build && vitest run tests/pilot"
37
+ "acceptance:installed": "node scripts/acceptance/installed.mjs",
38
+ "package:macos": "bash scripts/package-macos.sh",
39
+ "contracts": "npm run build && node scripts/contracts.mjs",
40
+ "contracts:check": "npm run build && node scripts/contracts.mjs --check",
41
+ "prebuild": "node -e \"require('node:fs').rmSync('dist/src',{recursive:true,force:true})\""
52
42
  },
53
43
  "dependencies": {
54
- "@agentclientprotocol/sdk": "2.7.0",
44
+ "@agentclientprotocol/codex-acp": "2.9.0",
45
+ "@agentclientprotocol/sdk": "2.9.1",
55
46
  "@modelcontextprotocol/sdk": "1.32.2",
56
- "ajv": "8.20.0",
57
- "ajv-formats": "3.0.1",
58
- "better-sqlite3": "13.2.0",
59
- "fastify": "5.12.8",
60
- "yaml": "2.9.1"
47
+ "zod": "^4.0.0"
61
48
  },
62
49
  "devDependencies": {
63
- "@types/better-sqlite3": "9.6.0",
64
50
  "@types/node": "26.6.6",
65
- "eslint": "10.15.0",
66
51
  "typescript": "6.0.3",
67
- "typescript-eslint": "8.73.0",
68
52
  "vitest": "5.1.0"
69
53
  }
70
54
  }