sakura-infinity 0.0.0-stage → 0.1.1

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 (82) hide show
  1. package/AGENT-GUIDE.md +104 -0
  2. package/LICENSE +21 -0
  3. package/README.md +275 -2
  4. package/dist/bin/flags.js +110 -0
  5. package/dist/bin/infinity.js +98 -0
  6. package/dist/bin/load-task.js +39 -0
  7. package/dist/bin/model.js +37 -0
  8. package/dist/bin/scaffold.js +121 -0
  9. package/dist/src/agent-worker.js +157 -0
  10. package/dist/src/backoff.js +12 -0
  11. package/dist/src/budget.js +49 -0
  12. package/dist/src/capacity.js +103 -0
  13. package/dist/src/clock.js +16 -0
  14. package/dist/src/code-leaderboard.js +48 -0
  15. package/dist/src/code-report.js +157 -0
  16. package/dist/src/command-class.js +59 -0
  17. package/dist/src/command-limits.js +46 -0
  18. package/dist/src/commit-plugin.js +36 -0
  19. package/dist/src/component.js +1 -0
  20. package/dist/src/csv.js +8 -0
  21. package/dist/src/defaults.js +35 -0
  22. package/dist/src/error-cluster.js +20 -0
  23. package/dist/src/evaluation.js +84 -0
  24. package/dist/src/form.js +191 -0
  25. package/dist/src/gate.js +111 -0
  26. package/dist/src/gpu-shim.js +165 -0
  27. package/dist/src/handoff.js +12 -0
  28. package/dist/src/hidden-keeper.js +183 -0
  29. package/dist/src/host.js +180 -0
  30. package/dist/src/jsonl.js +30 -0
  31. package/dist/src/ladder.js +118 -0
  32. package/dist/src/launch.js +123 -0
  33. package/dist/src/lean-kit.js +42 -0
  34. package/dist/src/lean-runner.js +84 -0
  35. package/dist/src/lean-setup.js +23 -0
  36. package/dist/src/lean-tool.js +57 -0
  37. package/dist/src/leftover.js +59 -0
  38. package/dist/src/machine-config.js +43 -0
  39. package/dist/src/machine-sampler.js +103 -0
  40. package/dist/src/machine-summary.js +64 -0
  41. package/dist/src/mode-factory.js +25 -0
  42. package/dist/src/mode.js +1 -0
  43. package/dist/src/network.js +12 -0
  44. package/dist/src/orchestrator.js +375 -0
  45. package/dist/src/planner.js +98 -0
  46. package/dist/src/platform.js +21 -0
  47. package/dist/src/pool.js +73 -0
  48. package/dist/src/pressure-brake.js +26 -0
  49. package/dist/src/proc-readings.js +207 -0
  50. package/dist/src/prompts.js +46 -0
  51. package/dist/src/records.js +2 -0
  52. package/dist/src/report.js +81 -0
  53. package/dist/src/review-loop.js +141 -0
  54. package/dist/src/review-rules.js +104 -0
  55. package/dist/src/review-run.js +110 -0
  56. package/dist/src/review-schedule.js +53 -0
  57. package/dist/src/review-snapshot.js +150 -0
  58. package/dist/src/run-layout.js +29 -0
  59. package/dist/src/run-notes.js +61 -0
  60. package/dist/src/run-recorder.js +51 -0
  61. package/dist/src/run-state.js +17 -0
  62. package/dist/src/run-status.js +37 -0
  63. package/dist/src/rung-meter.js +39 -0
  64. package/dist/src/safety-review.js +43 -0
  65. package/dist/src/sakura-tools.js +130 -0
  66. package/dist/src/shell-kit.js +113 -0
  67. package/dist/src/slot-gate.js +136 -0
  68. package/dist/src/slot-leases.js +64 -0
  69. package/dist/src/stuck.js +47 -0
  70. package/dist/src/submit-tool.js +99 -0
  71. package/dist/src/task-mode.js +170 -0
  72. package/dist/src/task.js +85 -0
  73. package/dist/src/verifier.js +115 -0
  74. package/dist/src/work-repo.js +50 -0
  75. package/dist/src/worker-policy.js +16 -0
  76. package/dist/tasks/math-odd-sum/task.js +6 -0
  77. package/dist/tasks/math-parity/task.js +6 -0
  78. package/dist/viewer/index.html +397 -0
  79. package/dist/viewer/run-reader.js +600 -0
  80. package/dist/viewer/server.js +160 -0
  81. package/dist/viewer/view.js +50 -0
  82. package/package.json +53 -4
@@ -0,0 +1,160 @@
1
+ // HTTP server of the run viewer: Node http only, read-only (GET), JSON endpoints and one server-sent-events stream.
2
+ // By default it listens on 127.0.0.1 and answers only requests addressed to this machine. To show it elsewhere it needs a token: then it may listen on any
3
+ // address, any Host is accepted (a reverse proxy works as it is), and every request carries the token (`?token=` once, then a cookie; or a Bearer header).
4
+ import { readFileSync } from "node:fs";
5
+ import { timingSafeEqual } from "node:crypto";
6
+ import { createServer } from "node:http";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { isRunDir, listRuns, RunReader } from "./run-reader.js";
10
+ const PAGE = join(dirname(fileURLToPath(import.meta.url)), "index.html");
11
+ const LOOPBACK = ["127.0.0.1", "localhost", "[::1]", "::1"];
12
+ const COOKIE = "infinity_view";
13
+ const sameText = (a, b) => a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
14
+ /** The token a request carries: in the query (the first visit), the cookie, or an Authorization header. */
15
+ function tokenOf(req, url) {
16
+ const query = url.searchParams.get("token");
17
+ if (query)
18
+ return { token: query, fromQuery: true };
19
+ const cookie = (req.headers.cookie ?? "")
20
+ .split(";")
21
+ .map((part) => part.trim())
22
+ .find((part) => part.startsWith(`${COOKIE}=`));
23
+ if (cookie)
24
+ return { token: decodeURIComponent(cookie.slice(COOKIE.length + 1)), fromQuery: false };
25
+ const bearer = /^Bearer\s+(.+)$/i.exec(req.headers.authorization ?? "");
26
+ return { token: bearer?.[1] ?? "", fromQuery: false };
27
+ }
28
+ export async function startViewer(options) {
29
+ const listenHost = options.host ?? "127.0.0.1";
30
+ if (!LOOPBACK.includes(listenHost) && !options.token)
31
+ throw new Error(`the viewer listens on ${listenHost} only with a token (--token, or INFINITY_VIEW_TOKEN)`);
32
+ const single = isRunDir(options.root);
33
+ const readers = new Map();
34
+ const clients = new Map();
35
+ const pollMs = options.pollMs ?? 1000;
36
+ const runNames = () => (single ? [new RunReader(options.root).name] : listRuns(options.root).map((r) => r.name));
37
+ const resolve = (name) => {
38
+ let target = name;
39
+ if (target === null || target === "")
40
+ target = runNames()[0] ?? null;
41
+ if (target === null)
42
+ return null;
43
+ const known = single ? runNames() : listRuns(options.root).map((r) => r.name);
44
+ if (!known.includes(target))
45
+ return null;
46
+ let reader = readers.get(target);
47
+ if (!reader) {
48
+ const dir = single ? options.root : join(options.root, target);
49
+ reader = new RunReader(dir, { ...(options.machineFile ? { machineFile: options.machineFile } : {}), ...(options.now ? { now: options.now } : {}) });
50
+ readers.set(target, reader);
51
+ }
52
+ reader.poll();
53
+ return reader;
54
+ };
55
+ const json = (res, status, body) => {
56
+ res.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
57
+ res.end(JSON.stringify(body));
58
+ };
59
+ const handle = (req, res) => {
60
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
61
+ if (options.token) {
62
+ const given = tokenOf(req, url);
63
+ if (!sameText(given.token, options.token))
64
+ return json(res, 401, { error: "a token is needed: open the address with ?token=..." });
65
+ if (given.fromQuery)
66
+ res.setHeader("set-cookie", `${COOKIE}=${encodeURIComponent(options.token)}; HttpOnly; SameSite=Strict; Path=/`);
67
+ }
68
+ else {
69
+ // without a token only requests addressed to this machine are answered (a page elsewhere cannot read the runs through the browser)
70
+ const host = (req.headers.host ?? "").replace(/:\d+$/, "");
71
+ if (!LOOPBACK.includes(host))
72
+ return json(res, 403, { error: "host not allowed: open it as 127.0.0.1, or start the viewer with a token to use it through a proxy" });
73
+ }
74
+ if (req.method !== "GET" && req.method !== "HEAD") {
75
+ res.writeHead(405, { allow: "GET, HEAD" });
76
+ return res.end();
77
+ }
78
+ const path = url.pathname;
79
+ if (path === "/" || path === "/index.html") {
80
+ res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
81
+ return res.end(readFileSync(PAGE));
82
+ }
83
+ if (path === "/api/runs") {
84
+ const runs = single ? [{ name: runNames()[0], mtime: Date.now() }] : listRuns(options.root).map((r) => ({ name: r.name, mtime: r.mtime }));
85
+ return json(res, 200, { runs, current: runs[0]?.name ?? null });
86
+ }
87
+ if (!path.startsWith("/api/"))
88
+ return json(res, 404, { error: "not found" });
89
+ const reader = resolve(url.searchParams.get("run"));
90
+ if (!reader)
91
+ return json(res, 404, { error: "no such run" });
92
+ if (path === "/api/run")
93
+ return json(res, 200, reader.summary());
94
+ if (path === "/api/series") {
95
+ const max = Number(url.searchParams.get("max"));
96
+ return json(res, 200, reader.series(Number.isFinite(max) && max > 10 ? max : 2000));
97
+ }
98
+ if (path === "/api/agents")
99
+ return json(res, 200, reader.agentRows());
100
+ if (path === "/api/events") {
101
+ const since = Number(url.searchParams.get("since"));
102
+ const limit = Number(url.searchParams.get("limit"));
103
+ const types = (url.searchParams.get("type") ?? "").split(",").filter(Boolean);
104
+ return json(res, 200, reader.eventList({ ...(Number.isFinite(since) && since > 0 ? { since } : {}), types, ...(Number.isFinite(limit) && limit > 0 ? { limit } : {}) }));
105
+ }
106
+ if (path === "/api/stream") {
107
+ res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
108
+ const run = reader.name;
109
+ clients.set(res, { run, version: reader.summary().version });
110
+ res.write(`event: hello\ndata: ${JSON.stringify({ run, version: clients.get(res)?.version })}\n\n`);
111
+ req.on("close", () => clients.delete(res));
112
+ return;
113
+ }
114
+ return json(res, 404, { error: "not found" });
115
+ };
116
+ const server = createServer((req, res) => {
117
+ try {
118
+ handle(req, res);
119
+ }
120
+ catch (error) {
121
+ if (!res.headersSent)
122
+ json(res, 500, { error: String(error) });
123
+ else
124
+ res.end();
125
+ }
126
+ });
127
+ const timer = setInterval(() => {
128
+ if (clients.size === 0)
129
+ return;
130
+ for (const [res, client] of clients) {
131
+ const reader = resolve(client.run);
132
+ if (!reader)
133
+ continue;
134
+ const version = reader.summary().version;
135
+ if (version !== client.version) {
136
+ client.version = version;
137
+ res.write(`event: update\ndata: ${JSON.stringify({ run: client.run, version })}\n\n`);
138
+ }
139
+ else
140
+ res.write(": keep-alive\n\n");
141
+ }
142
+ }, pollMs);
143
+ timer.unref();
144
+ await new Promise((ok, fail) => {
145
+ server.once("error", fail);
146
+ server.listen(options.port ?? 0, listenHost, () => ok());
147
+ });
148
+ return {
149
+ server,
150
+ port: server.address().port,
151
+ close: () => new Promise((ok) => {
152
+ clearInterval(timer);
153
+ for (const res of clients.keys())
154
+ res.end();
155
+ clients.clear();
156
+ server.closeAllConnections();
157
+ server.close(() => ok());
158
+ }),
159
+ };
160
+ }
@@ -0,0 +1,50 @@
1
+ // Start the run viewer: node viewer/view.ts <runs dir or run dir> [--port N] [--host ADDR] [--token T] [--machine FILE]
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { isRunDir, listRuns } from "./run-reader.js";
5
+ import { startViewer } from "./server.js";
6
+ function usage() {
7
+ console.error("usage: infinity view <runs dir or run dir> [--port N] [--host ADDR --token T] [--machine FILE]\n" +
8
+ " --host ADDR listen on another address than 127.0.0.1 (needs a token)\n" +
9
+ " --token T every request must carry it (open the page once with ?token=T); INFINITY_VIEW_TOKEN works too and keeps it out of the process list");
10
+ process.exit(2);
11
+ }
12
+ /** Starts the viewer for the given arguments and returns when it is listening (the process then stays up until Ctrl-C). */
13
+ export async function runViewerCommand(args) {
14
+ let root = "";
15
+ let port = 4173;
16
+ let machineFile;
17
+ let host;
18
+ let token = process.env.INFINITY_VIEW_TOKEN || undefined;
19
+ for (let i = 0; i < args.length; i++) {
20
+ const a = args[i];
21
+ if (a === "--port")
22
+ port = Number(args[++i]);
23
+ else if (a === "--host")
24
+ host = args[++i];
25
+ else if (a === "--token")
26
+ token = args[++i];
27
+ else if (a === "--machine")
28
+ machineFile = resolve(args[++i] ?? "");
29
+ else if (a.startsWith("--"))
30
+ usage();
31
+ else
32
+ root = resolve(a);
33
+ }
34
+ if (root === "" || !Number.isInteger(port) || port < 0 || port > 65535)
35
+ usage();
36
+ if (!existsSync(root)) {
37
+ console.error(`not found: ${root}`);
38
+ process.exit(1);
39
+ }
40
+ if (!isRunDir(root) && listRuns(root).length === 0) {
41
+ console.error(`no run directory in ${root} (a run directory holds events.jsonl, ledger.jsonl or state.json)`);
42
+ process.exit(1);
43
+ }
44
+ const viewer = await startViewer({ root, port, ...(machineFile ? { machineFile } : {}), ...(host ? { host } : {}), ...(token ? { token } : {}) });
45
+ const runs = isRunDir(root) ? 1 : listRuns(root).length;
46
+ const address = `http://${host && host !== "0.0.0.0" ? host : "127.0.0.1"}:${viewer.port}/${token ? "?token=<your token>" : ""}`;
47
+ console.log(`Run viewer (read-only): ${address} (${runs} run${runs === 1 ? "" : "s"}; newest opens first; Ctrl-C stops)`);
48
+ }
49
+ if (import.meta.main)
50
+ await runViewerCommand(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "sakura-infinity",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Run many agents in parallel on one task and keep the best result: a code task scored by your evaluator, or a Lean 4 proof. Built on sakura-agent.",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "node": ">=22.18"
9
+ },
10
+ "scripts": {
11
+ "test": "vitest run",
12
+ "view": "node bin/infinity.ts view",
13
+ "coverage": "vitest run --coverage --coverage.provider=v8",
14
+ "typecheck": "tsc --noEmit -p tsconfig.json",
15
+ "lint": "biome lint",
16
+ "format": "biome format --write",
17
+ "format:check": "biome format",
18
+ "check": "npm run typecheck && npm run lint && npm run format:check && npm test",
19
+ "infinity": "node bin/infinity.ts",
20
+ "build": "node scripts/build.mjs",
21
+ "prepack": "npm run build"
22
+ },
23
+ "dependencies": {
24
+ "sakura-agent": "^0.2.3",
25
+ "sakura-agent-tools": "^0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@biomejs/biome": "^2.6.4",
29
+ "@types/node": "^24.0.0",
30
+ "@vitest/coverage-v8": "^3.2.7",
31
+ "typescript": "^5.9.0",
32
+ "vitest": "^3.2.0"
33
+ },
34
+ "bin": {
35
+ "infinity": "dist/bin/infinity.js"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/Vist233/infinity_Agents.git"
40
+ },
41
+ "keywords": [
42
+ "agents",
43
+ "llm",
44
+ "parallel",
45
+ "benchmark",
46
+ "lean4",
47
+ "sakura-agent"
48
+ ],
49
+ "files": [
50
+ "dist",
51
+ "README.md",
52
+ "AGENT-GUIDE.md",
53
+ "LICENSE"
54
+ ]
55
+ }