axon-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.
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/client/cli.js +128 -0
- package/dist/client/cli.js.map +1 -0
- package/dist/client/http.js +72 -0
- package/dist/client/http.js.map +1 -0
- package/dist/config/deploy.js +55 -0
- package/dist/config/deploy.js.map +1 -0
- package/dist/contract/errors.js +9 -0
- package/dist/contract/errors.js.map +1 -0
- package/dist/contract/schema.js +90 -0
- package/dist/contract/schema.js.map +1 -0
- package/dist/controller/ledger.js +105 -0
- package/dist/controller/ledger.js.map +1 -0
- package/dist/executor/fake.js +30 -0
- package/dist/executor/fake.js.map +1 -0
- package/dist/executor/local.js +60 -0
- package/dist/executor/local.js.map +1 -0
- package/dist/executor/types.js +2 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/executor/workspace.js +70 -0
- package/dist/executor/workspace.js.map +1 -0
- package/dist/harness/adapter.js +132 -0
- package/dist/harness/adapter.js.map +1 -0
- package/dist/harness/budget.js +44 -0
- package/dist/harness/budget.js.map +1 -0
- package/dist/harness/child-env.js +12 -0
- package/dist/harness/child-env.js.map +1 -0
- package/dist/service/artifacts.js +39 -0
- package/dist/service/artifacts.js.map +1 -0
- package/dist/service/pool.js +221 -0
- package/dist/service/pool.js.map +1 -0
- package/dist/service/server.js +58 -0
- package/dist/service/server.js.map +1 -0
- package/dist/service/sweep.js +31 -0
- package/dist/service/sweep.js.map +1 -0
- package/dist/service/validate.js +35 -0
- package/dist/service/validate.js.map +1 -0
- package/dist/state/store.js +125 -0
- package/dist/state/store.js.map +1 -0
- package/dist/worker.js +46 -0
- package/dist/worker.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Equational Applications LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Axon Runtime
|
|
2
|
+
|
|
3
|
+
A distributed worker runtime for AI coding agents. A controller dispatches
|
|
4
|
+
goal-shaped jobs ("fix this test", "add this endpoint") to worker services on
|
|
5
|
+
other machines. Each worker runs its own tool-calling model loop inside a
|
|
6
|
+
disposable git worktree and returns a patch or a report, with telemetry and
|
|
7
|
+
cost accounting, under hard step, time, and spend limits.
|
|
8
|
+
|
|
9
|
+
Axon is how the [Equational Applications](https://equationalapplications.com)
|
|
10
|
+
agent fleet spreads spec-driven implementation work across spare laptops.
|
|
11
|
+
This repository is the generic runtime; machine inventory, tokens, and
|
|
12
|
+
network topology live in a separate private deployment repo.
|
|
13
|
+
|
|
14
|
+
**Status:** v0.1. Dispatch works end to end over SSH tunnels, with Linux and macOS
|
|
15
|
+
workers running under dedicated OS users. Windows onboarding and metrics-driven cross-node
|
|
16
|
+
placement are in progress.
|
|
17
|
+
|
|
18
|
+
## How it works
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
controller worker node (one per machine)
|
|
22
|
+
┌──────────────────────┐ SSH -L tunnel ┌──────────────────────────────────┐
|
|
23
|
+
│ axon CLI │ ─────────────────▶ │ Fastify service on 127.0.0.1 │
|
|
24
|
+
│ dispatch / status │ bearer token │ ├─ validate: contract, allowlist│
|
|
25
|
+
│ cancel / artifact │ │ │ size + spend ceilings │
|
|
26
|
+
│ │ ◀───────────────── │ ├─ JobPool: concurrency, cancel │
|
|
27
|
+
│ Ledger (SQLite) │ result envelope │ ├─ BudgetGuard: daily USD cap │
|
|
28
|
+
│ per-node metrics │ + telemetry │ ├─ git mirror → worktree per job│
|
|
29
|
+
└──────────────────────┘ │ ├─ Harness: model ⇄ run_shell │
|
|
30
|
+
│ └─ JobStore (SQLite), artifacts │
|
|
31
|
+
└──────────────────────────────────┘
|
|
32
|
+
│
|
|
33
|
+
▼
|
|
34
|
+
any OpenAI-compatible /chat/completions endpoint
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
1. The controller sends a versioned **job request**: repo, ref, goal, optional
|
|
38
|
+
context files, constraints (`max_harness_steps`, `timeout_seconds`,
|
|
39
|
+
`max_spend_usd`), and the output it wants (`patch` or `report`).
|
|
40
|
+
2. The worker validates it with Zod, checks the repo allowlist and the node's
|
|
41
|
+
ceilings, and admits it against the node's daily spend cap, or returns a
|
|
42
|
+
typed rejection (`repo_not_allowlisted`, `queue_full`, `budget_exhausted`, …).
|
|
43
|
+
3. The worker checks the ref out into a fresh worktree from a shared bare
|
|
44
|
+
mirror, then runs a tool loop against the configured model endpoint. The
|
|
45
|
+
only tool is `run_shell`, scoped to the worktree.
|
|
46
|
+
4. Every model step is written to a durable spend ledger before the job's
|
|
47
|
+
cost checkpoint, so the daily cap never undercounts, even across crashes.
|
|
48
|
+
5. The job ends in an **envelope**: status, exit reason (`completed`,
|
|
49
|
+
`step_cap`, `timeout`, `budget_exceeded`, `cancelled`, …), the diff (inline
|
|
50
|
+
or as an artifact), and telemetry (tokens, cost estimate, duration, model,
|
|
51
|
+
runtime and harness versions).
|
|
52
|
+
6. The controller records every dispatch and envelope in its own ledger.
|
|
53
|
+
Routing stays explicit: every dispatch names its target node.
|
|
54
|
+
|
|
55
|
+
## Security model
|
|
56
|
+
|
|
57
|
+
- **Loopback only.** Workers bind to `127.0.0.1`; the only way in is an SSH
|
|
58
|
+
port forward.
|
|
59
|
+
- **Bearer auth on every route** except `/healthz`, compared in constant time.
|
|
60
|
+
- **Allowlisted child environment.** The agent's shell sees only `PATH`, `HOME`,
|
|
61
|
+
`LANG`, `LC_ALL`, `TZ`, and `TMPDIR`. `SSH_AUTH_SOCK` is excluded on
|
|
62
|
+
purpose, so a job can't authenticate as the operator.
|
|
63
|
+
- **No push access.** Work comes back as a diff; the worker never pushes.
|
|
64
|
+
- **Secrets by reference.** Config files name environment variables
|
|
65
|
+
(`bearer_token_env`, `api_key_env`); secrets never live in config.
|
|
66
|
+
- **Bounded input and output.** Goal, context, and inline patch sizes are
|
|
67
|
+
capped per node.
|
|
68
|
+
- **Crash recovery.** On startup, jobs left `running` are marked
|
|
69
|
+
`interrupted`, orphaned worktrees are removed, and expired artifacts are
|
|
70
|
+
purged.
|
|
71
|
+
- **OS containment is left to the deployment.** Run the worker as a
|
|
72
|
+
dedicated, non-login OS user.
|
|
73
|
+
|
|
74
|
+
## Quick start
|
|
75
|
+
|
|
76
|
+
Requires Node.js 22+ and git.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm ci
|
|
80
|
+
npm run build
|
|
81
|
+
|
|
82
|
+
# Worker
|
|
83
|
+
export AXON_NODE_TOKEN=$(openssl rand -hex 32)
|
|
84
|
+
export AXON_ENDPOINT_KEY=sk-... # key for the endpoint in node.json
|
|
85
|
+
node dist/worker.js examples/node.json # listens on 127.0.0.1:8787 (AXON_PORT)
|
|
86
|
+
|
|
87
|
+
# Controller: forward a local port to the worker
|
|
88
|
+
ssh -N -L 18787:127.0.0.1:8787 worker-host &
|
|
89
|
+
export AXON_TOKEN_NODE_01=$AXON_NODE_TOKEN
|
|
90
|
+
export AXON_NODES=examples/nodes.json AXON_LEDGER=./ledger.db
|
|
91
|
+
|
|
92
|
+
echo "Make the failing date test pass" > goal.md
|
|
93
|
+
npx axon dispatch --node node-01 --repo git@github.com:your-org/your-repo.git \
|
|
94
|
+
--goal-file goal.md --wait
|
|
95
|
+
npx axon status --job <job_id>
|
|
96
|
+
npx axon artifact --job <job_id> -o patch.diff
|
|
97
|
+
npx axon metrics --node node-01
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Set `AXON_EXECUTOR=fake` on a worker to exercise the whole pipeline without
|
|
101
|
+
calling a model.
|
|
102
|
+
|
|
103
|
+
## Worker API
|
|
104
|
+
|
|
105
|
+
| Method | Path | Purpose |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| GET | `/healthz` | Liveness (no auth) |
|
|
108
|
+
| GET | `/nodeinfo` | Node ID, runtime and contract versions, capacity |
|
|
109
|
+
| POST | `/jobs` | Submit a job (idempotent on `job_id`) |
|
|
110
|
+
| GET | `/jobs/:id` | Current status or final envelope |
|
|
111
|
+
| POST | `/jobs/:id/cancel` | Cancel a running job |
|
|
112
|
+
| GET | `/jobs/:id/artifact?id=` | Fetch an artifact such as `patch.diff` |
|
|
113
|
+
|
|
114
|
+
The contract lives in [`src/contract/schema.ts`](src/contract/schema.ts)
|
|
115
|
+
(`CONTRACT_VERSION = 2`).
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm test # unit + in-process integration tests
|
|
121
|
+
npm run typecheck
|
|
122
|
+
AXON_SSH=1 npm test # also runs the real SSH tunnel round trip (needs key-based `ssh localhost`)
|
|
123
|
+
AXON_LIVE=1 npm test # also calls a real model endpoint
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Cost figures are estimates from fixed per-token rates in
|
|
127
|
+
`src/harness/adapter.ts`. Treat them as budget guards, not billing.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT © Equational Applications LLC
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { AxonClient, newJobId } from './http.js';
|
|
5
|
+
import { Ledger } from '../controller/ledger.js';
|
|
6
|
+
import { CONTRACT_VERSION } from '../contract/schema.js';
|
|
7
|
+
function loadNodes(path) {
|
|
8
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
9
|
+
}
|
|
10
|
+
function clientFor(nodeId, nodesPath) {
|
|
11
|
+
const entry = loadNodes(nodesPath).find((n) => n.node_id === nodeId);
|
|
12
|
+
if (!entry)
|
|
13
|
+
throw new Error(`axon: no node named ${nodeId} in ${nodesPath}`);
|
|
14
|
+
const token = process.env[entry.token_env];
|
|
15
|
+
if (!token)
|
|
16
|
+
throw new Error(`axon: ${entry.token_env} is not set`);
|
|
17
|
+
return { client: new AxonClient({ baseUrl: entry.base_url, token }), entry };
|
|
18
|
+
}
|
|
19
|
+
const program = new Command();
|
|
20
|
+
program
|
|
21
|
+
.name('axon')
|
|
22
|
+
.description('Dispatch subagent jobs to Axon worker nodes')
|
|
23
|
+
.option('--nodes <path>', 'controller node inventory', process.env.AXON_NODES ?? 'deploy/controller/nodes.json')
|
|
24
|
+
.option('--ledger <path>', 'controller ledger database', process.env.AXON_LEDGER ?? 'deploy/controller/ledger.db');
|
|
25
|
+
program
|
|
26
|
+
.command('dispatch')
|
|
27
|
+
.requiredOption('--node <node_id>')
|
|
28
|
+
.requiredOption('--repo <url>')
|
|
29
|
+
.option('--ref <ref>', 'branch, tag, or sha', 'main')
|
|
30
|
+
.requiredOption('--goal-file <path>')
|
|
31
|
+
.option('--output <mode>', 'patch | report', 'patch')
|
|
32
|
+
.option('--max-steps <n>', 'harness step cap', '40')
|
|
33
|
+
.option('--timeout <seconds>', 'wall clock cap', '1800')
|
|
34
|
+
.option('--max-spend <usd>', 'per-job spend cap', '2')
|
|
35
|
+
.option('--wait', 'poll until the job reaches a terminal status', false)
|
|
36
|
+
.action(async (opts) => {
|
|
37
|
+
const globals = program.opts();
|
|
38
|
+
const { client } = clientFor(opts.node, globals.nodes);
|
|
39
|
+
const job = {
|
|
40
|
+
contract_version: CONTRACT_VERSION,
|
|
41
|
+
job_id: newJobId(),
|
|
42
|
+
repo: opts.repo,
|
|
43
|
+
ref: opts.ref,
|
|
44
|
+
goal: readFileSync(opts.goalFile, 'utf8'),
|
|
45
|
+
context: [],
|
|
46
|
+
constraints: {
|
|
47
|
+
max_harness_steps: Number(opts.maxSteps),
|
|
48
|
+
timeout_seconds: Number(opts.timeout),
|
|
49
|
+
max_spend_usd: Number(opts.maxSpend),
|
|
50
|
+
},
|
|
51
|
+
output: opts.output,
|
|
52
|
+
};
|
|
53
|
+
const submitted = await client.dispatch(job);
|
|
54
|
+
const ledger = new Ledger(globals.ledger);
|
|
55
|
+
ledger.recordDispatch(job, opts.node);
|
|
56
|
+
if (submitted.status === 'rejected') {
|
|
57
|
+
console.error(JSON.stringify(submitted, null, 2));
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!opts.wait) {
|
|
62
|
+
console.log(JSON.stringify(submitted, null, 2));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const envelope = await client.wait(job.job_id);
|
|
66
|
+
ledger.recordEnvelope(envelope, opts.node);
|
|
67
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
68
|
+
});
|
|
69
|
+
program
|
|
70
|
+
.command('status')
|
|
71
|
+
.requiredOption('--job <job_id>')
|
|
72
|
+
.action(async (opts) => {
|
|
73
|
+
const globals = program.opts();
|
|
74
|
+
const ledger = new Ledger(globals.ledger);
|
|
75
|
+
const nodeId = ledger.nodeFor(opts.job);
|
|
76
|
+
if (!nodeId)
|
|
77
|
+
throw new Error(`axon: ledger has no node for job ${opts.job}`);
|
|
78
|
+
const { client } = clientFor(nodeId, globals.nodes);
|
|
79
|
+
console.log(JSON.stringify(await client.status(opts.job), null, 2));
|
|
80
|
+
});
|
|
81
|
+
program
|
|
82
|
+
.command('cancel')
|
|
83
|
+
.requiredOption('--job <job_id>')
|
|
84
|
+
.action(async (opts) => {
|
|
85
|
+
const globals = program.opts();
|
|
86
|
+
const nodeId = new Ledger(globals.ledger).nodeFor(opts.job);
|
|
87
|
+
if (!nodeId)
|
|
88
|
+
throw new Error(`axon: ledger has no node for job ${opts.job}`);
|
|
89
|
+
const { client } = clientFor(nodeId, globals.nodes);
|
|
90
|
+
console.log(JSON.stringify({ cancelled: await client.cancel(opts.job) }));
|
|
91
|
+
});
|
|
92
|
+
program
|
|
93
|
+
.command('nodes')
|
|
94
|
+
.description('list configured nodes with their last-known status')
|
|
95
|
+
.action(async () => {
|
|
96
|
+
const globals = program.opts();
|
|
97
|
+
for (const entry of loadNodes(globals.nodes)) {
|
|
98
|
+
try {
|
|
99
|
+
const { client } = clientFor(entry.node_id, globals.nodes);
|
|
100
|
+
console.log(entry.node_id, JSON.stringify(await client.nodeinfo()));
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
console.log(entry.node_id, 'unreachable:', err.message);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
program
|
|
108
|
+
.command('artifact')
|
|
109
|
+
.requiredOption('--job <job_id>')
|
|
110
|
+
.option('--id <artifact_id>', 'artifact name', 'patch.diff')
|
|
111
|
+
.requiredOption('-o, --out <path>')
|
|
112
|
+
.action(async (opts) => {
|
|
113
|
+
const globals = program.opts();
|
|
114
|
+
const nodeId = new Ledger(globals.ledger).nodeFor(opts.job);
|
|
115
|
+
if (!nodeId)
|
|
116
|
+
throw new Error(`axon: ledger has no node for job ${opts.job}`);
|
|
117
|
+
const { client } = clientFor(nodeId, globals.nodes);
|
|
118
|
+
writeFileSync(opts.out, await client.artifact(opts.job, opts.id), 'utf8');
|
|
119
|
+
console.log(`wrote ${opts.out}`);
|
|
120
|
+
});
|
|
121
|
+
program
|
|
122
|
+
.command('metrics')
|
|
123
|
+
.requiredOption('--node <node_id>')
|
|
124
|
+
.action(async (opts) => {
|
|
125
|
+
console.log(JSON.stringify(new Ledger(program.opts().ledger).metricsFor(opts.node), null, 2));
|
|
126
|
+
});
|
|
127
|
+
await program.parseAsync(process.argv);
|
|
128
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/client/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAC;AAS1E,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAgB,CAAC;AAC/D,CAAC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,SAAiB;IAClD,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;IACrE,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,OAAO,SAAS,EAAE,CAAC,CAA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+
export class AxonClient {
|
|
7
|
+
baseUrl;
|
|
8
|
+
token;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.baseUrl = opts.baseUrl.replace(/\/$/, '');
|
|
11
|
+
this.token = opts.token;
|
|
12
|
+
}
|
|
13
|
+
async call(path, init = {}) {
|
|
14
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
15
|
+
...init,
|
|
16
|
+
headers: {
|
|
17
|
+
...(init.headers ?? {}),
|
|
18
|
+
authorization: `Bearer ${this.token}`,
|
|
19
|
+
...(init.body ? { 'content-type': 'application/json' } : {}),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
if (res.status === 401)
|
|
23
|
+
throw new Error(`axon: 401 unauthorized against ${this.baseUrl}`);
|
|
24
|
+
return res;
|
|
25
|
+
}
|
|
26
|
+
async dispatch(job) {
|
|
27
|
+
const res = await this.call('/jobs', { method: 'POST', body: JSON.stringify(job) });
|
|
28
|
+
if (res.status !== 202 && res.status !== 400) {
|
|
29
|
+
throw new Error(`axon: unexpected ${res.status} dispatching job`);
|
|
30
|
+
}
|
|
31
|
+
return (await res.json());
|
|
32
|
+
}
|
|
33
|
+
async status(jobId) {
|
|
34
|
+
const res = await this.call(`/jobs/${jobId}`);
|
|
35
|
+
if (res.status === 404)
|
|
36
|
+
throw new Error(`axon: unknown job ${jobId}`);
|
|
37
|
+
const body = (await res.json());
|
|
38
|
+
if (body.status === 'running')
|
|
39
|
+
return { status: 'running' };
|
|
40
|
+
return EnvelopeSchema.parse(body);
|
|
41
|
+
}
|
|
42
|
+
async wait(jobId, opts = {}) {
|
|
43
|
+
const pollMs = opts.pollMs ?? 2000;
|
|
44
|
+
const deadline = Date.now() + (opts.timeoutMs ?? 3_600_000);
|
|
45
|
+
for (;;) {
|
|
46
|
+
try {
|
|
47
|
+
const current = await this.status(jobId);
|
|
48
|
+
if (current.status !== 'running')
|
|
49
|
+
return current;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// transient (job not visible yet / unknown): keep polling until the deadline
|
|
53
|
+
}
|
|
54
|
+
if (Date.now() >= deadline)
|
|
55
|
+
throw new Error(`axon: timed out waiting for job ${jobId}`);
|
|
56
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async cancel(jobId) {
|
|
60
|
+
return (await this.call(`/jobs/${jobId}/cancel`, { method: 'POST' })).status === 202;
|
|
61
|
+
}
|
|
62
|
+
async nodeinfo() {
|
|
63
|
+
return (await (await this.call('/nodeinfo')).json());
|
|
64
|
+
}
|
|
65
|
+
async artifact(jobId, artifactId) {
|
|
66
|
+
const res = await this.call(`/jobs/${jobId}/artifact?id=${encodeURIComponent(artifactId)}`);
|
|
67
|
+
if (!res.ok)
|
|
68
|
+
throw new Error(`axon: artifact ${artifactId} not found for job ${jobId}`);
|
|
69
|
+
return await res.text();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/client/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAkC,MAAM,uBAAuB,CAAC;AAKvF,MAAM,UAAU,QAAQ;IACtB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC;AAUD,MAAM,OAAO,UAAU;IACZ,OAAO,CAAS;IACR,KAAK,CAAS;IAE/B,YAAY,IAAwC;QAClD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IAEO,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,OAAoB,EAAE;QACrD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CA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C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,gBAAgB,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC5F,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,sBAAsB,KAAK,EAAE,CAAC,CAAC;QACxF,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ConstraintsSchema } from '../contract/schema.js';
|
|
4
|
+
const FileSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
node_id: z.string().min(1),
|
|
7
|
+
home: z.string().min(1),
|
|
8
|
+
bearer_token_env: z.string().min(1),
|
|
9
|
+
max_concurrent_jobs: z.number().int().positive(),
|
|
10
|
+
repo_allowlist: z.array(z.string().min(1)).min(1),
|
|
11
|
+
ceilings: ConstraintsSchema,
|
|
12
|
+
node_daily_spend_usd: z.number().positive(),
|
|
13
|
+
max_goal_bytes: z.number().int().positive().default(32_768),
|
|
14
|
+
max_context_bytes: z.number().int().positive().default(1_048_576),
|
|
15
|
+
max_inline_patch_bytes: z.number().int().positive().default(1_048_576),
|
|
16
|
+
artifact_ttl_days: z.number().int().positive().default(7),
|
|
17
|
+
endpoint: z
|
|
18
|
+
.object({
|
|
19
|
+
base_url: z.string().url(),
|
|
20
|
+
model: z.string().min(1),
|
|
21
|
+
api_key_env: z.string().min(1),
|
|
22
|
+
})
|
|
23
|
+
.strict(),
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
function requireEnv(env, name) {
|
|
27
|
+
if (!(name in env))
|
|
28
|
+
throw new Error(`deploy config names ${name}, but it is absent from the environment`);
|
|
29
|
+
const value = env[name];
|
|
30
|
+
if (value === '')
|
|
31
|
+
throw new Error(`deploy config names ${name}, but its environment value is an empty string`);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
export function loadDeployConfig(path, env) {
|
|
35
|
+
const parsed = FileSchema.parse(JSON.parse(readFileSync(path, 'utf8')));
|
|
36
|
+
return {
|
|
37
|
+
nodeId: parsed.node_id,
|
|
38
|
+
home: parsed.home,
|
|
39
|
+
bearerToken: requireEnv(env, parsed.bearer_token_env),
|
|
40
|
+
maxConcurrentJobs: parsed.max_concurrent_jobs,
|
|
41
|
+
repoAllowlist: parsed.repo_allowlist,
|
|
42
|
+
ceilings: parsed.ceilings,
|
|
43
|
+
nodeDailySpendUsd: parsed.node_daily_spend_usd,
|
|
44
|
+
maxGoalBytes: parsed.max_goal_bytes,
|
|
45
|
+
maxContextBytes: parsed.max_context_bytes,
|
|
46
|
+
maxInlinePatchBytes: parsed.max_inline_patch_bytes,
|
|
47
|
+
artifactTtlDays: parsed.artifact_ttl_days,
|
|
48
|
+
endpoint: {
|
|
49
|
+
baseUrl: parsed.endpoint.base_url,
|
|
50
|
+
model: parsed.endpoint.model,
|
|
51
|
+
apiKey: requireEnv(env, parsed.endpoint.api_key_env),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/config/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAoB,MAAM,uBAAuB,CAAC;AAE5E,MAAM,UAAU,GAAG,CAAC;KACjB,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,gB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AAO,WAAY,SAAQ,KAAK;IACf;IAArB,YAAqB,MAAoB,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,WAAM,GAAN,MAAM,CAAc;QAEvC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const CONTRACT_VERSION = 2;
|
|
3
|
+
export const JobStatusSchema = z.enum(['ok', 'error', 'timeout', 'rejected', 'interrupted']);
|
|
4
|
+
export const RejectReasonSchema = z.enum([
|
|
5
|
+
'repo_not_allowlisted',
|
|
6
|
+
'contract_unsupported',
|
|
7
|
+
'malformed_payload',
|
|
8
|
+
'limit_exceeded',
|
|
9
|
+
'queue_full',
|
|
10
|
+
'budget_exhausted',
|
|
11
|
+
]);
|
|
12
|
+
export const ExitReasonSchema = z.enum([
|
|
13
|
+
'completed',
|
|
14
|
+
'step_cap',
|
|
15
|
+
'timeout',
|
|
16
|
+
'budget_exceeded',
|
|
17
|
+
'cancelled',
|
|
18
|
+
'harness_error',
|
|
19
|
+
'endpoint_error',
|
|
20
|
+
'interrupted',
|
|
21
|
+
]);
|
|
22
|
+
export const ConstraintsSchema = z.object({
|
|
23
|
+
max_harness_steps: z.number().int().positive(),
|
|
24
|
+
timeout_seconds: z.number().int().positive(),
|
|
25
|
+
max_spend_usd: z.number().positive(),
|
|
26
|
+
});
|
|
27
|
+
export const ContextFileSchema = z.object({
|
|
28
|
+
path: z.string().min(1),
|
|
29
|
+
content: z.string(),
|
|
30
|
+
});
|
|
31
|
+
export const JobRequestSchema = z.object({
|
|
32
|
+
contract_version: z.number().int(),
|
|
33
|
+
job_id: z.string().uuid(),
|
|
34
|
+
repo: z.string().min(1),
|
|
35
|
+
ref: z.string().min(1),
|
|
36
|
+
goal: z.string().min(1),
|
|
37
|
+
context: z.array(ContextFileSchema).default([]),
|
|
38
|
+
constraints: ConstraintsSchema,
|
|
39
|
+
output: z.enum(['patch', 'report']),
|
|
40
|
+
});
|
|
41
|
+
export const TelemetrySchema = z.object({
|
|
42
|
+
started_at: z.string().datetime(),
|
|
43
|
+
ended_at: z.string().datetime(),
|
|
44
|
+
duration_ms: z.number().int().nonnegative(),
|
|
45
|
+
harness_steps: z.number().int().nonnegative(),
|
|
46
|
+
tokens_in: z.number().int().nonnegative(),
|
|
47
|
+
tokens_out: z.number().int().nonnegative(),
|
|
48
|
+
cost_estimate_usd: z.number().nonnegative(),
|
|
49
|
+
exit_reason: ExitReasonSchema,
|
|
50
|
+
node_id: z.string().min(1),
|
|
51
|
+
executor: z.enum(['fake', 'local']),
|
|
52
|
+
model_id: z.string(),
|
|
53
|
+
endpoint_base_url: z.string(),
|
|
54
|
+
runtime_version: z.string(),
|
|
55
|
+
harness_version: z.string(),
|
|
56
|
+
});
|
|
57
|
+
export const ResultSchema = z.object({
|
|
58
|
+
output: z.enum(['patch', 'report']),
|
|
59
|
+
patch: z.string().nullable(),
|
|
60
|
+
patch_artifact: z.string().nullable(),
|
|
61
|
+
summary: z.string(),
|
|
62
|
+
});
|
|
63
|
+
export const EnvelopeSchema = z
|
|
64
|
+
.object({
|
|
65
|
+
contract_version: z.literal(CONTRACT_VERSION),
|
|
66
|
+
job_id: z.string().uuid(),
|
|
67
|
+
node_id: z.string().min(1),
|
|
68
|
+
status: JobStatusSchema,
|
|
69
|
+
reason: RejectReasonSchema.nullable(),
|
|
70
|
+
error_detail: z.string().nullable(),
|
|
71
|
+
result: ResultSchema.nullable(),
|
|
72
|
+
telemetry: TelemetrySchema.nullable(),
|
|
73
|
+
})
|
|
74
|
+
.refine((e) => e.status === 'rejected'
|
|
75
|
+
? e.telemetry === null
|
|
76
|
+
: e.status === 'interrupted'
|
|
77
|
+
? true // 'interrupted' retains telemetry up to its last checkpoint — legitimately none after a crash
|
|
78
|
+
: e.telemetry !== null, {
|
|
79
|
+
message: 'telemetry is required on every terminal status except rejected and interrupted',
|
|
80
|
+
path: ['telemetry'],
|
|
81
|
+
})
|
|
82
|
+
.refine((e) => (e.status === 'rejected' ? e.reason !== null : e.reason === null), {
|
|
83
|
+
message: 'reason is set if and only if status is rejected',
|
|
84
|
+
path: ['reason'],
|
|
85
|
+
})
|
|
86
|
+
.refine((e) => (e.telemetry?.exit_reason === 'harness_error' ? e.error_detail !== null : e.error_detail === null), {
|
|
87
|
+
message: 'error_detail is set if and only if telemetry.exit_reason is harness_error',
|
|
88
|
+
path: ['error_detail'],
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/contract/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC;AAE3C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAE7F,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC;IACvC,sBAAsB;IACtB,sBAAsB;IACtB,mBAAmB;IACnB,gBAAgB;IAChB,YAAY;IACZ,kBAAkB;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC;IACrC,WAAW;IACX,UAAU;IACV,SAAS;IACT,iBAAiB;IACjB,WAAW;IACX,eAAe;IACf,gBAAgB;IAChB,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAC9C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,C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
|
+
CREATE TABLE IF NOT EXISTS jobs (
|
|
6
|
+
job_id TEXT PRIMARY KEY,
|
|
7
|
+
node_id TEXT NOT NULL,
|
|
8
|
+
repo TEXT,
|
|
9
|
+
ref TEXT,
|
|
10
|
+
output TEXT,
|
|
11
|
+
status TEXT,
|
|
12
|
+
reason TEXT,
|
|
13
|
+
exit_reason TEXT,
|
|
14
|
+
started_at TEXT,
|
|
15
|
+
ended_at TEXT,
|
|
16
|
+
duration_ms INTEGER,
|
|
17
|
+
tokens_in INTEGER,
|
|
18
|
+
tokens_out INTEGER,
|
|
19
|
+
cost_estimate_usd REAL,
|
|
20
|
+
model_id TEXT,
|
|
21
|
+
runtime_version TEXT,
|
|
22
|
+
harness_version TEXT,
|
|
23
|
+
envelope TEXT,
|
|
24
|
+
dispatched_at TEXT NOT NULL
|
|
25
|
+
);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS jobs_node ON jobs(node_id);
|
|
27
|
+
`;
|
|
28
|
+
export class Ledger {
|
|
29
|
+
db;
|
|
30
|
+
constructor(dbPath) {
|
|
31
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
32
|
+
this.db = new Database(dbPath);
|
|
33
|
+
this.db.pragma('journal_mode = WAL');
|
|
34
|
+
this.db.exec(SCHEMA);
|
|
35
|
+
}
|
|
36
|
+
recordDispatch(job, nodeId) {
|
|
37
|
+
this.db
|
|
38
|
+
.prepare(`INSERT INTO jobs (job_id, node_id, repo, ref, output, status, dispatched_at)
|
|
39
|
+
VALUES (?, ?, ?, ?, ?, 'dispatched', ?)
|
|
40
|
+
ON CONFLICT(job_id) DO NOTHING`)
|
|
41
|
+
.run(job.job_id, nodeId, job.repo, job.ref, job.output, new Date().toISOString());
|
|
42
|
+
}
|
|
43
|
+
recordEnvelope(env, nodeId) {
|
|
44
|
+
const t = env.telemetry;
|
|
45
|
+
this.db
|
|
46
|
+
.prepare(`INSERT INTO jobs (job_id, node_id, status, reason, exit_reason, started_at, ended_at,
|
|
47
|
+
duration_ms, tokens_in, tokens_out, cost_estimate_usd, model_id,
|
|
48
|
+
runtime_version, harness_version, envelope, dispatched_at)
|
|
49
|
+
VALUES (@job_id, @node_id, @status, @reason, @exit_reason, @started_at, @ended_at,
|
|
50
|
+
@duration_ms, @tokens_in, @tokens_out, @cost, @model_id,
|
|
51
|
+
@runtime_version, @harness_version, @envelope, @now)
|
|
52
|
+
ON CONFLICT(job_id) DO UPDATE SET
|
|
53
|
+
status = excluded.status, reason = excluded.reason, exit_reason = excluded.exit_reason,
|
|
54
|
+
started_at = excluded.started_at, ended_at = excluded.ended_at,
|
|
55
|
+
duration_ms = excluded.duration_ms, tokens_in = excluded.tokens_in,
|
|
56
|
+
tokens_out = excluded.tokens_out, cost_estimate_usd = excluded.cost_estimate_usd,
|
|
57
|
+
model_id = excluded.model_id, runtime_version = excluded.runtime_version,
|
|
58
|
+
harness_version = excluded.harness_version, envelope = excluded.envelope`)
|
|
59
|
+
.run({
|
|
60
|
+
job_id: env.job_id,
|
|
61
|
+
node_id: nodeId,
|
|
62
|
+
status: env.status,
|
|
63
|
+
reason: env.reason,
|
|
64
|
+
exit_reason: t?.exit_reason ?? null,
|
|
65
|
+
started_at: t?.started_at ?? null,
|
|
66
|
+
ended_at: t?.ended_at ?? null,
|
|
67
|
+
duration_ms: t?.duration_ms ?? null,
|
|
68
|
+
tokens_in: t?.tokens_in ?? null,
|
|
69
|
+
tokens_out: t?.tokens_out ?? null,
|
|
70
|
+
cost: t?.cost_estimate_usd ?? 0,
|
|
71
|
+
model_id: t?.model_id ?? null,
|
|
72
|
+
runtime_version: t?.runtime_version ?? null,
|
|
73
|
+
harness_version: t?.harness_version ?? null,
|
|
74
|
+
envelope: JSON.stringify(env),
|
|
75
|
+
now: new Date().toISOString(),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
nodeFor(jobId) {
|
|
79
|
+
const row = this.db.prepare('SELECT node_id FROM jobs WHERE job_id = ?').get(jobId);
|
|
80
|
+
return row?.node_id;
|
|
81
|
+
}
|
|
82
|
+
metricsFor(nodeId) {
|
|
83
|
+
const rows = this.db
|
|
84
|
+
.prepare('SELECT status, duration_ms, cost_estimate_usd FROM jobs WHERE node_id = ? AND status != ?')
|
|
85
|
+
.all(nodeId, 'dispatched');
|
|
86
|
+
const ok = rows.filter((r) => r.status === 'ok').length;
|
|
87
|
+
const rejected = rows.filter((r) => r.status === 'rejected').length;
|
|
88
|
+
const error = rows.length - ok - rejected;
|
|
89
|
+
const durations = rows.map((r) => r.duration_ms ?? 0).sort((a, b) => a - b);
|
|
90
|
+
return {
|
|
91
|
+
node_id: nodeId,
|
|
92
|
+
jobs: rows.length,
|
|
93
|
+
ok,
|
|
94
|
+
error,
|
|
95
|
+
rejected,
|
|
96
|
+
success_rate: rows.length === 0 ? 0 : ok / rows.length,
|
|
97
|
+
total_cost_usd: rows.reduce((sum, r) => sum + (r.cost_estimate_usd ?? 0), 0),
|
|
98
|
+
median_duration_ms: durations.length === 0 ? 0 : durations[Math.floor(durations.length / 2)],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
close() {
|
|
102
|
+
this.db.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=ledger.js.map
|