Your hive. Your direction.
+Mission board
+Assign a goal. Follow the work. Steer when it matters.
+Keep sight of every step.
++ Select a task to see its instructions, live output, + dependencies, and exact review artifacts. +
+Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-harness/patches/6d96f9f5be1e04be # omega-harness Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## Visual control desk for the supported Omega Harness providers open `6d96f9f5be1e04be` opened 2026-11-18 by `z6MkhL6jkVBvyZTg...` 1 commit · 14 files · 126239 bytes. Base `5eb9dc53978eecb222b7b0e4d05aaec4043e2556` . Applied head `0f94c40e20f3a032446dc7c6c35c91a599ba5c80`: the last commit this forge's own `git am` made on the base. It is in no repository; the owner applies the patch by hand. ``` Updated reference for Omega Harness issue #205. The external provider list is Claude, Codex, Grok and Muse. Local Omega and simulation are also available. Ten backend checks passed. The DOM workflow passed. No external model was contacted. This remains an experimental isolated controller. Its production authority, remote provider authentication and rendered layout are unqualified. Supersedes the imported visual reference #204. ``` ### Apply it ``` git checkout -b patch-6d96f9f5be1e04be 5eb9dc53978eecb222b7b0e4d05aaec4043e2556 curl -fsSL https://interplane.io/drakestapleton/omega-harness/patches/6d96f9f5be1e04be.patch | git am ``` Raw patch (mbox) · Diff ### Signature The author's key `did:key:z6MkhL6jkVBvyZTg9eMGkJWKQKjnKA1wbA7ym3PkTXt4M6Jd` signed this statement with `ssh-keygen -Y sign -n interplane-patch`; the forge checked the signature before it kept the patch. The lines are: format, repository, base, SHA-256 of the mbox, SHA-256 of the title, a line feed and the description. ``` interplane-patch 1 drakestapleton/omega-harness 5eb9dc53978eecb222b7b0e4d05aaec4043e2556 f7b68c8ed62f8e1155ee97d5da039430bfdad9f17a68d170394733228d1918d1 15db4a5965d447daadb9206153ad6cd1b0133fa5810d6d949a5d3fc0cd7b6e19 ``` ``` -----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgKr14kjS0/iq9b58nlxNgw6mfKH AuJfrl7JkSpYn5gmIAAAAQaW50ZXJwbGFuZS1wYXRjaAAAAAAAAAAGc2hhNTEyAAAAUwAA AAtzc2gtZWQyNTUxOQAAAEDVed+gE9qbKEKRRFCWYwP44XHmzJRPa7tyccYioKVBfhXG8P MXwK2YMVXFeYYQkfQ6WNkqrv3KvCG8xB6sUzgA -----END SSH SIGNATURE----- ``` ### Changes ``` diff --git a/control-desk/.gitignore b/control-desk/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2109548db0d64b2dda917ef485b206e6134b1658 --- /dev/null +++ b/control-desk/.gitignore @@ -0,0 +1,4 @@ +.state/ +config.local.json +artifacts/ +node_modules/ diff --git a/control-desk/README.md b/control-desk/README.md new file mode 100644 index 0000000000000000000000000000000000000000..44399bedac391b0e93b750e6304eb698cbd7a383 --- /dev/null +++ b/control-desk/README.md @@ -0,0 +1,187 @@ +# Omega control desk — host adapter candidate + +A local visual workbench for an operator-directed hive. It starts paused, connects only the routes +you enable, and keeps task decisions separate from agent transcripts. This initial implementation +is a Node.js host adapter with a browser UI. It is **not an Omega-native runtime or a replacement +for the canonical `spark-hive` task authority**. It owns only tasks created in this desk. + +## Run + +Requires Node.js 24+, Git, and Linux or macOS. No runtime packages to install. + +```sh +cd control-desk +npm test +node server.mjs --repo /absolute/path/to/your/repository +``` + +Open the local URL printed in the terminal. Its fragment contains a private control token. The +server binds to `127.0.0.1` only. Keep the tab and controller on the same machine; do not expose this +prototype through a public tunnel. The browser does not receive provider keys. + +For a separate simulation, without paid model calls: + +```sh +node server.mjs --demo --state /tmp/omega-desk-demo --port 8788 +``` + +Simulation is explicitly labeled. Real providers remain disabled until you enable them. The +simulation worker produces synthetic text and does not edit a repository. + +Options: `--state DIR` (default `control-desk/.state`), `--repo DIR`, `--port 8787`, +`--capacity 3`, and `--demo`. State must be on a local filesystem, not a network share. +Do not run as root. The state directory contains prompts, logs, source snapshots and results; +keep it private and out of Git. No telemetry or third-party frontend assets are loaded. + +## Connect your accounts + +Use the gear beside a connection to edit its command, endpoint, model, timeout, and slot limit. +Saving does not enable a disabled connection. Install and log into the relevant official tool +on the machine running the desk, then enable that connection. Executable detection is labeled +**login unverified**; authentication and quota are exercised by the actual task. + +| Connection | Included route | Authentication / scope | +| --- | --- | --- | +| Claude | `claude -p {prompt}` | Existing Claude Code login and permission policy | +| OpenAI | `codex exec --json --sandbox workspace-write {prompt}` | Existing Codex login and permission policy | +| Grok | `grok -p {prompt}` | Existing Grok Build login and permission policy | +| Muse | Custom command, initially empty | Your actual Muse adapter; no assumed undocumented endpoint | +| Omega | Chat-completions endpoint, initially disabled | Your configured local model; advisory text in this adapter | + +Commands are argument arrays passed directly to `spawn`, never interpolated into a shell. Each +`{prompt}` placeholder receives the full instruction as one argument. With no placeholder the +prompt is sent on stdin. A command inherits the controller's environment and the user's normal +CLI configuration. Never put secrets into command arguments: settings are visible in the UI. + +An account's subscription, regional availability, CLI access and API allowance are determined by +its provider. This desk does not convert web subscriptions into API credits or extract session +cookies. Sign in using each vendor's normal CLI flow; no automatic login changes or installations +are made. Default commands preserve the CLI's permission policy. A permission refusal can end +a headless task; inspect its output and deliberately configure the official tool before retrying. + +For a local or remote **OpenAI-compatible chat-completions** route, set the full endpoint URL, +model, and optionally a key environment variable name such as `OMEGA_API_KEY`. Export that variable +before starting the server. HTTPS is required except on loopback. Credentials in URLs and redirects +are refused. The native Anthropic API uses a different wire format. Use its CLI route or an +explicit adapter. Chat routes return advisory text; they do not run tools or modify files. + +You can bootstrap additional routes using a JSON array in `STATE_DIR/providers.json` before the +first saved connection change. After that, saved database settings take precedence. Example: + +```json +[ + { + "id": "muse", + "name": "Muse", + "kind": "command", + "command": ["/absolute/path/to/muse-adapter", "--prompt", "{prompt}"], + "enabled": false, + "limit": 1, + "timeoutSeconds": 900 + } +] +``` + +That array replaces the initial list; use the UI for ordinary changes. Command adapters must stay +in the foreground and terminate their children when stopped. Keep publishing, deployment and +remote mutations outside these workers. Existing workers keep their original connection settings +when you edit or disable a connection; disabling prevents new dispatch only. + +## Work as a hive + +1. Assign a task with a concrete goal and acceptance criteria. A **queen** task asks the chosen + model for a bounded JSON plan; a **worker** task performs one assignment. +2. Review a queen's plan and choose **Import plan**. The complete plan is validated and inserted + atomically. Import pauses new dispatch so you can inspect it. Existing workers continue. +3. Resume dispatch. Tasks with accepted dependencies run within both the global limit and the + provider's own limit. Disabled or unavailable providers retain their queued tasks. There is + no fallback to a different provider and no automatic retry of failed requests. +4. Watch output and select tasks to inspect the exact instruction and dependency states. Pause + blocks new work; **Stop active** also requests cancellation of current attempts. +5. To redirect an active worker, stop it, wait for settlement, add direction, and explicitly retry. + The successor starts in a fresh checkout. Earlier artifacts remain on disk. This initial + adapter does not claim provider-native mid-turn steering or automatic patch continuation. +6. Inspect the output and patch. **Accept this receipt** records your review of exact hashes and + releases dependents. Acceptance does not mean tests passed, merge changes, or deploy anything. + +Plan format (dependencies are indices of earlier tasks, starting at zero): + +```json +{"tasks":[ + {"title":"Inspect startup","prompt":"Find the startup failure and report evidence.","provider":"claude","dependsOn":[]}, + {"title":"Design the repair","prompt":"Use the accepted evidence to propose a minimal repair.","provider":"openai","dependsOn":[0]} +]} +``` + +Maximum 12 tasks per imported plan. Workers receive dependency receipt metadata and local artifact +paths. They do **not** automatically receive dependency patches in their checkout. Any integration +task must explicitly inspect and apply chosen patches, test the combined result, and submit its own +receipt. Advisory HTTP workers receive metadata only, not filesystem contents. + +## Isolation, recovery and evidence + +- Each CLI attempt clones the configured repository's committed `HEAD` into its own directory, + checks out that exact commit, and removes the origin remote. Source working-tree edits are not + copied. Git submodules and LFS payloads are not provisioned automatically. +- SQLite uses WAL and `synchronous=FULL`; state changes and events commit together. One controller + holds a state-directory lock. Revision checks reject stale task commands. Attempts carry a + generation so late completion cannot turn a stopped attempt into success. +- On restart, in-flight tasks become **interrupted** and dispatch remains paused. A crash can leave + a foreground adapter's subprocesses alive. Inspect them before removing a stale + `controller.lock`; the desk intentionally does not guess or kill arbitrary stored PIDs. An + interrupted retry requires the operator's explicit recovery acknowledgement. +- Stops send TERM then KILL to the local adapter process group. Remote effects may already have + occurred; detached daemons can escape that group. “Canceled” means the local adapter settled, + not that remote work was rolled back. Hard process containment requires the next sandbox phase. +- A successful adapter exit generates `result.txt`, `changes.patch`, and `receipt.json` under + `STATE_DIR/runs/TASK/ATTEMPT`. The patch is relative to the captured base and includes commits, + tracked edits, and nonignored untracked files. Ignored build outputs are not submitted. + Patches are stored and hashed as raw bytes; the browser shows a UTF-8 preview. For non-UTF-8 + content, inspect the original `changes.patch` artifact instead of copying the browser preview. +- Receipt inspection and acceptance recompute artifact hashes. This establishes byte identity, + not authorship, correctness, a passing test suite, or protection against a malicious same-user + process. Full output is bounded: the result keeps the last 200,000 characters; output events + retain at most 8,192 characters per chunk. A 2 MiB adapter output limit stops runaway output. +- Git operations have a 60-second deadline; inference has the configured deadline. Patches are + capped at 8 MiB. HTTP response bodies are capped at 2 MiB. The event API is cursor-paged at 200 + rows; the UI keeps 500 entries and displays 100. One state directory supports 1,000 tasks. + +The checkout is a collaboration boundary, **not an OS sandbox**. Provider tools retain their own +filesystem/network permissions. This candidate is for a trusted operator and trusted CLI tools +on one machine. The process can read the user's provider configuration and environment. Do not +infer hostile-code containment from the visual controls or the removed Git remote. + +## Next integration gates + +1. Wire this UI to canonical `spark-hive` through a versioned adapter after core issue + [925](https://github.com/aien-dev/aien-sovereign-core-mv/issues/925) supplies fenced claims and + artifact-bound submission. Retire this candidate's separate scheduler when that path is ready. + Do not mirror mutable task authority into crumbs, summaries, or a second live queue. +2. Add real per-provider conformance receipts on the operator's installed CLI versions: login, + streaming, permission refusal, quota exhaustion, cancellation, restart, and artifact recovery. +3. Add contained workers (namespaces/containers or native equivalent), resource limits, private + credential injection, and a separate publication actor. Add local disk quotas and archival. +4. Add native event adapters (ACP/app-server where supported) for tool cards, permission requests, + measured usage, mid-turn steering and reliable session continuation. Current output is bounded + text, which can include raw JSON from Codex; no token-price estimates are invented. +5. Add exact-base integration and independent verification receipts before a merge desk. Add + `.om` protocol validation against an actual compiler pin before claiming an Omega-native path. + +## Verification + +```sh +npm test +``` + +For the DOM workflow integration check, install development dependencies with `npm ci`, then run +`npm run test:ui`. This checks actual UI handlers against the backend; it does not render CSS. + +Tests exercise local HTTP control, stale revisions, exact receipt acceptance, dependencies, +atomic plan import, cancellation, timeout/provider isolation, restart recovery, connection +validation, and actual Git checkout isolation. They use synthetic workers, not paid providers. +See `VERIFICATION.md` for the observed run and current limitations. + +Provider command references inspected 2026-11-06: +[Claude](https://code.claude.com/docs/en/headless), +[Codex](https://developers.openai.com/codex/noninteractive), +[Grok Build](https://docs.x.ai/build/overview). diff --git a/control-desk/VERIFICATION.md b/control-desk/VERIFICATION.md new file mode 100644 index 0000000000000000000000000000000000000000..656feee08a106bba3e0e17153bc5f457567d73ec --- /dev/null +++ b/control-desk/VERIFICATION.md @@ -0,0 +1,41 @@ +# Control desk verification — 2026-11-06 + +Scope: initial host adapter candidate on Linux, Node.js v24.22.1. Base repository revision: +`bd107ca15c40b6cdfef0f23afb03a884fe3c8086`. This record describes the change containing this file; +it is not a qualification receipt for canonical `spark-hive`, Omega compiler code, or live models. + +| Check | Observed result | +| --- | --- | +| `npm test` | PASS: 9 tests, 0 failures | +| `npm run test:ui` (jsdom + actual local HTTP backend) | PASS: create task, dispatch, inspect receipt, accept, import dependency plan, pause, save Muse command; zero DOM runtime errors | +| JavaScript parse checks | PASS for server and browser entry points | +| Actual Git fixture worker | PASS: isolated clone gets generated files; submitted patch applies to a fresh clone and preserves non-UTF-8 bytes; source repository stays clean; worker clone has no origin remote | +| Wrong/missing access token and cross-origin request | Refused | +| Stale task revision, wrong receipt hashes, tampered receipt file | Refused | +| Self-dependent plan | Refused atomically; zero tasks inserted | +| Interrupted attempt | Preserved as interrupted; no automatic replay | +| Stop then steer and retry | Old attempt stays canceled; explicit retry has a new generation | +| Slow provider alongside another provider | Other provider proceeds within its slot; slow attempt fails on deadline | +| Real browser layout and mobile rendering | NOT_RUN: local browser startup failed on environment socket permissions; supplied cloud browser could not reach the loopback server | +| Live Claude, Codex, Grok, Muse or Omega execution | NOT_RUN: no operator login/model connection was exercised | +| Spark deployment, canonical task-authority integration, OS containment, native `.om` implementation | NOT_RUN / future integration gates | + +The browser test uses jsdom for DOM event handling, dialog shims, and Node's fetch against the +actual server. It is not a rendered-browser or screenshot test. It uses the explicitly simulated +provider. The separate backend Git fixture does execute a local synthetic command in a real clone. + +Reproduce: + +```sh +cd control-desk +npm ci +npm test +npm run test:ui +node --check server.mjs +node --check public/app.js +``` + +`jsdom` is a development-only dependency. Starting the desk uses Node built-ins and static assets; +it does not require installing those test dependencies. Run a real browser and one harmless task +with each installed provider before relying on that route for engineering work. Record CLI +versions and actual login, permission, quota, stop and resume behavior in subsequent receipts. diff --git a/control-desk/engine.mjs b/control-desk/engine.mjs new file mode 100644 index 0000000000000000000000000000000000000000..d0239a2fd3a6b427f4ff1b7ae0a4e81411efc531 --- /dev/null +++ b/control-desk/engine.mjs @@ -0,0 +1,406 @@ +import { spawn } from "node:child_process"; +import { mkdir, readFile, writeFile } from "node:fs/promises"; +import { createHash } from "node:crypto"; +import path from "node:path"; +import { readiness } from "./providers.mjs"; + +const hash = (s) => createHash("sha256").update(s).digest("hex"); +export function command(argv, cwd, signal, binary = false) { + return new Promise((resolve, reject) => { + const p = spawn(argv[0], argv.slice(1), { + cwd, + signal, + timeout: 60000, + killSignal: "SIGKILL", + stdio: ["ignore", "pipe", "pipe"], + env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, + }); + const chunks = []; + let err = "", + size = 0; + p.stdout.on("data", (b) => { + size += b.length; + if (size > 8 * 1024 * 1024) p.kill(); + else chunks.push(b); + }); + p.stderr.on("data", (b) => { + err = (err + b).slice(-8000); + }); + p.on("error", reject); + p.on("close", (code) => + code === 0 && size <= 8 * 1024 * 1024 + ? resolve( + binary + ? Buffer.concat(chunks) + : Buffer.concat(chunks).toString("utf8"), + ) + : reject(Error(err || `Command failed (${code}); output limit 8 MiB`)), + ); + }); +} +export class Engine { + constructor(store, { state, repo, providers, capacity = 3, demo = false }) { + Object.assign(this, { store, state, repo, providers, capacity, demo }); + this.active = new Map(); + this.paused = true; + this.ticking = false; + store.recover(); + } + async tick() { + if (this.paused || this.ticking) return; + this.ticking = true; + try { + const tasks = this.store.summaries().reverse(); + const statuses = new Map(tasks.map((t) => [t.id, t.status])); + for (const t of tasks) { + if (this.active.size >= this.capacity) break; + const p = this.providers.find((p) => p.id === t.provider); + if ( + t.status !== "queued" || + !p || + !p.enabled || + !["ready", "simulation"].some((x) => readiness(p).startsWith(x)) + ) + continue; + if (t.deps.some((id) => statuses.get(id) !== "accepted")) continue; + if ( + [...this.active.values()].filter((a) => a.provider === p.id).length >= + p.limit + ) + continue; + const claimed = this.store.change( + t.id, + t.revision, + (x) => { + x.status = "running"; + x.attempt++; + x.note = "Starting isolated attempt"; + x.receipt = null; + }, + "started", + ); + const a = { + provider: p.id, + attempt: claimed.attempt, + abort: new AbortController(), + process: null, + stopped: false, + }; + this.active.set(t.id, a); + this.run(claimed, structuredClone(p), a) + .catch((e) => this.finish(t.id, a, "failed", String(e.message))) + .finally(() => this.active.delete(t.id)); + } + } finally { + this.ticking = false; + } + } + finish(id, a, status, note, receipt = null) { + const t = this.store.get(id); + if (t.attempt !== a.attempt || t.status !== "running" || a.stopped) return; + this.store.change( + id, + t.revision, + (x) => { + x.status = status; + x.note = note; + x.receipt = receipt; + }, + status, + ); + } + stop(id) { + const t = this.store.get(id), + a = this.active.get(id); + if (t.status === "queued") + return this.store.change(id, t.revision, (x) => { + x.status = "canceled"; + x.note = "Canceled before dispatch"; + }); + if (!a || !["running", "stopping"].includes(t.status)) + throw Error("Task is not running"); + if (t.status === "stopping") return t; + a.stopped = true; + a.abort.abort(); + this.kill(a, "SIGTERM"); + const timer = setTimeout(() => this.kill(a, "SIGKILL"), 1500); + timer.unref(); + return this.store.change( + id, + t.revision, + (x) => { + x.status = "stopping"; + x.note = + "Stop requested; waiting for local adapter to settle. Remote effects may already exist."; + }, + "stop-requested", + ); + } + kill(a, signal) { + if (a.process?.pid) + try { + process.kill(-a.process.pid, signal); + } catch {} + } + async run(t, p, a) { + let timer; + const directory = path.join(this.state, "runs", t.id, String(a.attempt)); + try { + await mkdir(directory, { recursive: true, mode: 0o700 }); + const workspace = path.join(directory, "workspace"); + let base = null; + if (p.kind === "command") { + if (!this.repo) + throw Error( + "Start the desk with --repo /path/to/repository for coding tasks", + ); + base = ( + await command(["git", "rev-parse", "HEAD"], this.repo, a.abort.signal) + ).trim(); + // Separate object/index/config storage avoids competing writes to a shared working tree. + await command( + [ + "git", + "clone", + "--no-hardlinks", + "--no-local", + "--no-checkout", + "--", + this.repo, + workspace, + ], + directory, + a.abort.signal, + ); + await command( + ["git", "checkout", "--detach", base], + workspace, + a.abort.signal, + ); + await command( + ["git", "remote", "remove", "origin"], + workspace, + a.abort.signal, + ); + } + const dependencies = t.deps.map((id) => { + const d = this.store.get(id); + return { id: d.id, title: d.title, receipt: d.receipt }; + }); + const planInstruction = `Propose a bounded work plan as JSON {"tasks":[{"title":"...","prompt":"goal and acceptance criteria","provider":"provider-id","dependsOn":[]}]}. Maximum 12 tasks. dependsOn contains zero-based indices of earlier tasks. Available provider IDs: ${this.providers.map((p) => p.id).join(", ")}. Do not launch other agents or change task authority. The operator reviews and imports your plan.\n`; + const prompt = `Task: ${t.title}\nRole: ${t.role}\n${t.role === "queen" ? planInstruction : ""}${t.prompt}\n\nAccepted dependency receipts (source changes are not automatically integrated):\n${JSON.stringify(dependencies)}\n\nWork only in this isolated checkout. Follow its AGENTS.md. Do not push, deploy, publish, or alter other workspaces. Report checks actually run and remaining uncertainty. The operator reviews the result.`; + const started = this.store.get(t.id); + if (a.stopped) return; + this.store.change(t.id, started.revision, (x) => { + x.workspace = p.kind === "command" ? workspace : null; + x.note = "Adapter running"; + x.base = base; + }); + timer = setTimeout(() => { + a.timedOut = true; + a.abort.abort(); + this.kill(a, "SIGTERM"); + setTimeout(() => this.kill(a, "SIGKILL"), 1500).unref(); + }, p.timeoutSeconds * 1000); + let output = ""; + const emit = (text) => { + output = (output + text).slice(-200000); + this.store.event(t.id, "output", text); + }; + if (p.kind === "demo") { + for (const text of [ + "SIMULATION: reading the task contract.\n", + "SIMULATION: proposing isolated work and verification.\n", + "SIMULATION: result ready for operator review. No model or repository was changed.\n", + ]) { + await new Promise((resolve, reject) => { + const handle = setTimeout(resolve, 400); + a.abort.signal.addEventListener( + "abort", + () => { + clearTimeout(handle); + reject(Error("Stopped")); + }, + { once: true }, + ); + }); + emit(text); + } + } else if (p.kind === "chat") { + const key = p.keyEnv ? process.env[p.keyEnv] : null; + const response = await fetch(p.endpoint, { + method: "POST", + redirect: "error", + signal: a.abort.signal, + headers: { + "Content-Type": "application/json", + ...(key ? { Authorization: `Bearer ${key}` } : {}), + }, + body: JSON.stringify({ + model: p.model, + messages: [{ role: "user", content: prompt }], + stream: false, + max_tokens: 4096, + }), + }); + if (!response.ok) + throw Error( + `Provider HTTP ${response.status}; check login, quota and endpoint`, + ); + let body = "", + bytes = 0; + const decoder = new TextDecoder(); + for await (const chunk of response.body) { + bytes += chunk.length; + if (bytes > 2 * 1024 * 1024) { + a.abort.abort(); + throw Error("Provider response exceeds 2 MiB"); + } + body += decoder.decode(chunk, { stream: true }); + } + body += decoder.decode(); + const text = JSON.parse(body).choices?.[0]?.message?.content; + if (typeof text !== "string") + throw Error("Expected chat-completions text response"); + emit(text); + } else { + await new Promise((resolve, reject) => { + const argv = p.command.map((s) => s.replaceAll("{prompt}", prompt)); + const child = spawn(argv[0], argv.slice(1), { + cwd: workspace, + detached: true, + stdio: ["pipe", "pipe", "pipe"], + env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, + }); + a.process = child; + child.stdout.setEncoding("utf8"); + child.stderr.setEncoding("utf8"); + let bytes = 0; + const onData = (b) => { + bytes += Buffer.byteLength(b); + if (bytes > 2 * 1024 * 1024) { + this.kill(a, "SIGKILL"); + return; + } + emit(b.toString()); + }; + child.stdout.on("data", onData); + child.stderr.on("data", onData); + child.on("error", reject); + child.on("close", (code) => { + this.kill(a, "SIGKILL"); + code === 0 && bytes <= 2 * 1024 * 1024 + ? resolve() + : reject( + Error( + bytes > 2 * 1024 * 1024 + ? "Output limit exceeded" + : `Adapter exited ${code}; inspect output for permissions, login or quota`, + ), + ); + }); + child.stdin.on("error", () => {}); + child.stdin.end( + p.command.some((s) => s.includes("{prompt}")) ? "" : prompt, + ); + if (a.stopped || a.abort.signal.aborted) this.kill(a, "SIGTERM"); + }); + } + if (a.timedOut) throw Error("Adapter deadline exceeded"); + if (a.stopped) return; + let diff = "", + head = base; + if (p.kind === "command") { + await command( + ["git", "add", "-N", "--", "."], + workspace, + a.abort.signal, + ); + diff = await command( + ["git", "diff", "--binary", base, "--"], + workspace, + a.abort.signal, + true, + ); + head = ( + await command(["git", "rev-parse", "HEAD"], workspace, a.abort.signal) + ).trim(); + } + await writeFile(path.join(directory, "result.txt"), output, { + mode: 0o600, + }); + await writeFile(path.join(directory, "changes.patch"), diff, { + mode: 0o600, + }); + const receipt = { + attempt: a.attempt, + base, + head, + outputSha256: hash(output), + patchSha256: hash(diff), + directory, + simulation: p.kind === "demo", + advisory: p.kind === "chat", + finished: new Date().toISOString(), + }; + await writeFile( + path.join(directory, "receipt.json"), + JSON.stringify(receipt, null, 2), + { mode: 0o600 }, + ); + this.finish( + t.id, + a, + "review", + "Adapter finished. Inspect output and patch; exit success is not verification.", + receipt, + ); + } catch (e) { + this.finish( + t.id, + a, + "failed", + a.timedOut ? "Adapter deadline exceeded" : e.message, + ); + } finally { + clearTimeout(timer); + if (a.stopped) { + const x = this.store.get(t.id); + if (x.status === "stopping") + this.store.change( + t.id, + x.revision, + (v) => { + v.status = "canceled"; + v.note = + "Local adapter settled. Inspect workspace and remote effects before retry."; + }, + "stopped", + ); + } + } + } + async receipt(id) { + const t = this.store.get(id); + if (!t.receipt) throw Error("No completed receipt"); + const output = await readFile( + path.join(t.receipt.directory, "result.txt"), + "utf8", + ), + patch = await readFile(path.join(t.receipt.directory, "changes.patch")); + if ( + hash(output) !== t.receipt.outputSha256 || + hash(patch) !== t.receipt.patchSha256 + ) + throw Error("Receipt artifact hash mismatch"); + return { receipt: t.receipt, output, patch: patch.toString("utf8") }; + } + async shutdown() { + this.paused = true; + for (const id of this.active.keys()) + try { + this.stop(id); + } catch {} + while (this.active.size) await new Promise((r) => setTimeout(r, 50)); + } +} diff --git a/control-desk/package-lock.json b/control-desk/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..8b6ab2fef894fe2b4e9b8ae016f92d6c12afdf07 --- /dev/null +++ b/control-desk/package-lock.json @@ -0,0 +1,548 @@ +{ + "name": "omega-control-desk", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "omega-control-desk", + "version": "0.1.0", + "devDependencies": { + "jsdom": "26.1.0" + }, + "engines": { + "node": ">=24" + } + }, + "node_modules/@asamuzakjp/css-color": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.2.0.tgz", + "integrity": "sha512-K1A6z8tS3XsmCMM86xoWdn7Fkdn9m6RSVtocUrJYIwZnFVkng/PvkEoWtOWmP+Scc6saYWHWZYbndEEXxl24jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@csstools/css-calc": "^2.1.3", + "@csstools/css-color-parser": "^3.0.9", + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3", + "lru-cache": "^10.4.3" + } + }, + "node_modules/@csstools/color-helpers": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-5.1.0.tgz", + "integrity": "sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT-0", + "engines": { + "node": ">=18" + } + }, + "node_modules/@csstools/css-calc": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-2.1.4.tgz", + "integrity": "sha512-3N8oaj+0juUw/1H3YwmDDJXCgTB1gKU6Hc/bB502u9zR0q2vd786XJH9QfrKIEgFlZmhZiq6epXl4rHqhzsIgQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.5", + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-color-parser": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-3.1.0.tgz", + "integrity": "sha512-nbtKwh3a6xNVIp/VRuXV64yTKnb1IjTAEEh3irzS+HkKjAOYLTGNb9pmVNntZ8iVBHcWDA2Dof0QtPgFI1BaTA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "dependencies": { + "@csstools/color-helpers": "^5.1.0", + "@csstools/css-calc": "^2.1.4" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.5", + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-parser-algorithms": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.5.tgz", + "integrity": "sha512-DaDeUkXZKjdGhgYaHNJTV9pV7Y9B3b644jCLs9Upc3VeNGg6LWARAT6O+Q+/COo+2gg/bM5rhpMAtf70WqfBdQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-tokenizer": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-3.0.4.tgz", + "integrity": "sha512-Vd/9EVDiu6PPJt9yAh6roZP6El1xHrdvIVGjyBsHR0RYwNHgL7FJPyIIW4fANJNG6FtyZfvlRPpFI4ZM/lubvw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, + "node_modules/cssstyle": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.6.0.tgz", + "integrity": "sha512-2z+rWdzbbSZv6/rhtvzvqeZQHrBaqgogqt85sqFNbabZOuFbCVFb8kPeEtZjiKkbrm395irpNKiYeFeLiQnFPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/css-color": "^3.2.0", + "rrweb-cssom": "^0.8.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decimal.js": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz", + "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", + "dev": true, + "license": "MIT" + }, + "node_modules/entities": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz", + "integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsdom": { + "version": "26.1.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.1.0.tgz", + "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "cssstyle": "^4.2.1", + "data-urls": "^5.0.0", + "decimal.js": "^10.5.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.6", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.16", + "parse5": "^7.2.1", + "rrweb-cssom": "^0.8.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^5.1.1", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.1.1", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^3.0.0" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, + "node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/nwsapi": { + "version": "2.2.28", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.28.tgz", + "integrity": "sha512-IlVB7OS7qrOsVYlpnFIkETjMwT9jwvmocJmmM+GZU/PAB3uGi9Ezd7vcWhWBUnSc0ya4ppmQITOyP1ez9gg8cg==", + "dev": true, + "license": "MIT" + }, + "node_modules/parse5": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.3.0.tgz", + "integrity": "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^6.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/rrweb-cssom": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz", + "integrity": "sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw==", + "dev": true, + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true, + "license": "MIT" + }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true, + "license": "MIT" + }, + "node_modules/tldts": { + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz", + "integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^6.1.86" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz", + "integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA==", + "dev": true, + "license": "MIT" + }, + "node_modules/tough-cookie": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz", + "integrity": "sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^6.1.32" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "deprecated": "Use @exodus/bytes instead for a more spec-conformant and faster implementation", + "dev": true, + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/ws": { + "version": "8.22.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.1.tgz", + "integrity": "sha512-oyL6OPYme/CmiFvNuGzeoxCJ4nOrZE2O1FwM9MWM1AsGri6nLXB2pg+lNA8aLeXMSav0J6eIVS1j6vUPzUtK9g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/control-desk/package.json b/control-desk/package.json new file mode 100644 index 0000000000000000000000000000000000000000..7e0ff4f3bc9b091463e084de7faca96602ff418c --- /dev/null +++ b/control-desk/package.json @@ -0,0 +1,17 @@ +{ + "name": "omega-control-desk", + "private": true, + "version": "0.1.0", + "type": "module", + "engines": { + "node": ">=24" + }, + "scripts": { + "start": "node server.mjs", + "test": "node --test test/*.test.mjs", + "test:ui": "node test/ui-smoke.cjs" + }, + "devDependencies": { + "jsdom": "26.1.0" + } +} diff --git a/control-desk/providers.mjs b/control-desk/providers.mjs new file mode 100644 index 0000000000000000000000000000000000000000..81c3d554aefbcc7c781937db4086648f488234ef --- /dev/null +++ b/control-desk/providers.mjs @@ -0,0 +1,134 @@ +import { accessSync, constants } from "node:fs"; +import path from "node:path"; + +export const defaults = [ + { + id: "omega", + name: "Omega", + kind: "chat", + endpoint: "http://127.0.0.1:18091/v1/chat/completions", + model: "", + note: "Local model · advisory text only", + }, + { + id: "claude", + name: "Claude", + kind: "command", + command: ["claude", "-p", "{prompt}"], + note: "Claude Code · existing CLI login", + }, + { + id: "openai", + name: "OpenAI", + kind: "command", + command: [ + "codex", + "exec", + "--json", + "--sandbox", + "workspace-write", + "{prompt}", + ], + note: "Codex · existing CLI login", + }, + { + id: "grok", + name: "Grok", + kind: "command", + command: ["grok", "-p", "{prompt}"], + note: "Grok Build · existing CLI login", + }, + { + id: "muse", + name: "Muse", + kind: "command", + command: [], + note: "Supply your Muse command adapter", + }, +].map((p) => ({ ...p, enabled: false, limit: 1, timeoutSeconds: 900 })); + +export function installed(binary) { + if (!binary) return false; + return ( + binary.includes("/") + ? [binary] + : (process.env.PATH || "") + .split(path.delimiter) + .map((d) => path.join(d, binary)) + ).some((p) => { + try { + accessSync(p, constants.X_OK); + return true; + } catch { + return false; + } + }); +} +// Identify retired routes in configuration saved by older desks. +export function retiredRoute(p) { + const identifier = /(?:^|[^a-z0-9])(?:gemini|antigravity|agy)(?:$|[^a-z0-9])/i; + return [p?.id, p?.name, p?.model, p?.endpoint, ...(Array.isArray(p?.command) ? p.command : [])] + .some((value) => typeof value === "string" && (identifier.test(value) || + /(?:^|[/.])generativelanguage\.googleapis\.com(?:[/:]|$)/i.test(value))); +} + +export function validateProvider(p) { + if (!p || !/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) + throw Error("Invalid provider id"); + if (retiredRoute(p)) throw Error("Unsupported provider route"); + if (typeof p.name !== "string" || p.name.length > 60 || !p.name.trim()) + throw Error("Invalid provider name"); + if (!["command", "chat", "demo"].includes(p.kind)) + throw Error("Invalid provider kind"); + if (!Number.isInteger(p.limit) || p.limit < 1 || p.limit > 8) + throw Error("Provider limit must be 1–8"); + if ( + !Number.isInteger(p.timeoutSeconds) || + p.timeoutSeconds < 1 || + p.timeoutSeconds > 3600 + ) + throw Error("Timeout must be 1–3600 seconds"); + if ( + p.kind === "command" && + (!Array.isArray(p.command) || + p.command.length > 32 || + !p.command.every((a) => typeof a === "string" && a.length < 40000)) + ) + throw Error("Command must be an argv array"); + if (p.kind === "chat") { + const u = new URL(p.endpoint); + if (u.username || u.password || u.search || u.hash) + throw Error("Use keyEnv for credentials, not endpoint URLs"); + if ( + u.protocol !== "https:" && + !( + u.protocol === "http:" && + ["127.0.0.1", "localhost", "[::1]"].includes(u.hostname) + ) + ) + throw Error("Use HTTPS or loopback HTTP"); + if (p.keyEnv && !/^[A-Z_][A-Z0-9_]*$/.test(p.keyEnv)) + throw Error("Invalid key environment variable"); + if ( + typeof p.model !== "string" || + p.model.length > 200 || + p.endpoint.length > 2000 + ) + throw Error("Invalid model or endpoint"); + } + return p; +} +export function readiness(p) { + if (!p.enabled) return "disabled"; + if (p.kind === "command") + return installed(p.command?.[0]) + ? "ready · login unverified" + : "needs CLI / configuration"; + if (p.kind === "chat") + return !p.model + ? "needs model" + : p.keyEnv && !process.env[p.keyEnv] + ? "needs key environment" + : "ready · endpoint unverified"; + return "simulation"; +} diff --git a/control-desk/public/app.js b/control-desk/public/app.js new file mode 100644 index 0000000000000000000000000000000000000000..380d7580b28b6f0940610947a428d74372909a9b --- /dev/null +++ b/control-desk/public/app.js @@ -0,0 +1,345 @@ +const $ = (s) => document.querySelector(s), + esc = (s) => + String(s ?? "").replace( + /[&<>"']/g, + (c) => + ({ + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", + })[c], + ); +let token = location.hash.slice(1) || sessionStorage.getItem("omega-token"); +if (token) sessionStorage.setItem("omega-token", token); +history.replaceState(null, "", location.pathname); +let state, + selected, + detail, + filter = "all", + cursor = 0, + events = [], + receipt = null, + receiptKey = "", + busy = false, + online = false; +async function api(route, data) { + const r = await fetch("/api/" + route, { + method: data ? "POST" : "GET", + headers: { + "X-Omega-Token": token || "", + "Content-Type": "application/json", + }, + ...(data ? { body: JSON.stringify(data) } : {}), + }); + const result = await r.json(); + if (!r.ok) throw Error(result.error || `HTTP ${r.status}`); + return result; +} +function notice(text) { + $("#notice").hidden = !text; + $("#notice").textContent = text || ""; + document.querySelectorAll(".dialog-error").forEach((el) => el.remove()); + const dialog = document.querySelector("dialog[open]"); + if (text && dialog) { + const error = document.createElement("p"); + error.className = "dialog-error"; + error.setAttribute("role", "alert"); + error.textContent = text; + dialog.prepend(error); + } +} +async function act(fn) { + try { + await fn(); + notice(""); + await refresh(); + } catch (e) { + notice(e.message); + } +} +const label = (t) => { + if (t.status !== "queued") return t.status; + if ( + t.deps.some( + (id) => state.tasks.find((d) => d.id === id)?.status !== "accepted", + ) + ) + return "waiting"; + const p = state.providers.find((p) => p.id === t.provider); + if ( + !p?.enabled || + !["ready", "simulation"].some((s) => p.readiness.startsWith(s)) + ) + return "blocked"; + return "queued"; +}; +const reason = (t) => + label(t) === "blocked" + ? "Connection: " + + (state.providers.find((p) => p.id === t.provider)?.readiness || + "unavailable") + : label(t) === "waiting" + ? "Waiting for accepted dependency receipts" + : t.note || "Ready for an available worker slot"; +function render() { + $("#health").textContent = state.paused ? "Dispatch paused" : "Dispatch live"; + $("#health").className = state.paused ? "paused" : "live"; + $("#pause").textContent = state.paused ? "Resume dispatch" : "Pause dispatch"; + $("#mode").textContent = state.demo + ? "Simulation enabled · real routes stay opt-in" + : state.repo + ? "Repository connected" + : "No coding repository selected"; + $("#connection-count").textContent = + state.providers.filter((p) => p.enabled).length + + "/" + + state.providers.length; + $("#providers").innerHTML = state.providers + .map( + (p) => + `
${filter === "all" ? "Connect a worker, assign a concrete goal, and resume dispatch when you are ready." : ""}
Events appear here as you operate the hive.
'; +} +function renderInspector() { + const summary = state.tasks.find((t) => t.id === selected); + if (!summary) return; + const t = { + ...summary, + prompt: detail?.id === selected ? detail.prompt : "Loading instructions…", + }; + const running = ["running", "stopping"].includes(t.status), + retry = ["review", "failed", "canceled", "interrupted"].includes(t.status); + $("#inspector").innerHTML = + `${esc(reason(t))}
${esc(t.prompt)}${
+ t.deps.length
+ ? "${esc(
+ events
+ .filter((e) => e.task === t.id && e.kind === "output")
+ .slice(-20)
+ .map((e) => e.text)
+ .join("") || "No output received.",
+ )}${receipt && receiptKey === t.id + ":" + t.attempt ? `${t.receipt?.simulation ? "Simulation. No model was invoked." : t.receipt?.advisory ? "Advisory text only. No code was executed." : "Isolated checkout result."}
Patch SHA-256${esc(receipt.receipt.patchSha256)}${esc(receipt.output)}${esc(receipt.patch || "(No tracked or untracked patch changes)")}${t.status === "review" ? 'Acceptance records your review. It does not merge or deploy.
' : ""}Assign a goal. Follow the work. Steer when it matters.
++ Select a task to see its instructions, live output, + dependencies, and exact review artifacts. +
+