Files
loki/scripts/hermes-dispatch.ts
T
xandClaude Opus 4.8 572ed08cca feat(hosted-runner): intentional dispatch SSOT + UI trigger + recent-activity context
Make Hermes usable on purpose, not just as an offline accident. Three changes,
one converging design (verified: tsc clean, eslint clean, gpt-4.1 run proven):

1. dispatchToHostedRunner() — SSOT for INTENTIONAL hosted dispatch (resolve
   project → enqueue → emit Activity event). The CLI (hermes-dispatch.ts) and the
   new API route both funnel through it, so resolution + attribution never drift.
   The inject-core auto-route stays the offline fallback.

2. UI trigger — POST /api/hermes/dispatch (thin shell over the SSOT) + a
   self-contained 'Run in cloud' button in Control's intent panel. Works
   regardless of local-runner state (the composer's Send only auto-routes to
   Hermes when the runner is OFFLINE) — this broadens hosted usage from
   offline-only to any-time-on-purpose.

3. Recent-activity context — getRecentProjectActivity() + a compact 'what was
   just done' block injected at the consumer (the single choke point for ALL
   hosted dispatches), so Hermes doesn't repeat or undo recent work.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 20:17:49 +02:00

51 lines
2.3 KiB
TypeScript

#!/usr/bin/env -S npx tsx
/**
* hermes-dispatch — send a coding task to the hosted Hermes runner ON PURPOSE.
*
* inject-core only routes to Hermes as an automatic fallback (a WORK dispatch
* queued while the local Fleet Runner is offline). This is the intentional path:
* queue a task for a project and let the hosted runner do it laptop-off.
*
* The task is enqueued as a `hosted_dispatch` command; the
* fleetcrown-hosted-runner.timer drains it (~≤1 min): clone → Hermes in its
* sandbox → commit on a branch → open a PR. Nothing auto-merges — you review it.
* Progress is visible in Activity (source="hosted-runner", adapter="hermes").
*
* Resolution + enqueue + Activity attribution are shared with the API route via
* dispatchToHostedRunner — this script only supplies the owner userId (the box
* has no session) and prints the result.
*
* Usage:
* DATABASE_URL=… npx tsx scripts/hermes-dispatch.ts <projectKey> "<task>" [model]
* Example:
* … scripts/hermes-dispatch.ts fleetcrown "Add a CONTRIBUTING.md with build + test steps"
*/
import { getSelfImprovementTarget } from "@/db/queries/frontier";
import { dispatchToHostedRunner } from "@/lib/hosted-runner/dispatch";
async function main() {
const [projectKey, task, model] = process.argv.slice(2);
if (!projectKey || !task) {
console.error('Usage: npx tsx scripts/hermes-dispatch.ts <projectKey> "<task>" [model]');
process.exit(1);
}
const target = await getSelfImprovementTarget();
if (!target) { console.error("No FleetCrown owner resolved — nothing to dispatch for."); process.exit(1); }
const res = await dispatchToHostedRunner({ userId: target.userId, projectKey, task, ...(model ? { model } : {}) });
if (!res.ok) {
console.error(`✗ ${res.error}`);
if (res.knownProjects?.length) console.error(` Known projects: ${res.knownProjects.join(", ")}`);
process.exit(1);
}
console.log(`✓ queued hosted Hermes dispatch ${res.hostedDispatchId}`);
console.log(` project: ${res.projectName} repo: ${res.gitUrl}`);
console.log(` task: ${task}`);
console.log(` Drained by fleetcrown-hosted-runner.timer (~≤1 min) → clone → Hermes → PR (never auto-merged).`);
console.log(` Watch: journalctl -u fleetcrown-hosted-runner -f | Activity (source=hosted-runner)`);
process.exit(0);
}
main();