Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

1.8 KB
Raw Blame
#!/usr/bin/env node
// Starts a goal — the plugin's user_prompt hook: writes the Session's GOAL.json and prints
// the round-1 protocol message as the prompt's expansion context. The manifest marks it
// `trigger: "host"`: it runs when the host starts a goal, never on an ordinary prompt.
//
// stdin:  { "hook": "user_prompt", "session_id", "trace_path", "scratchpad_dir", "prompt",
//           "budget" }
//         prompt = the user's text with leading marker blocks stripped (the objective later
//         rounds restate and the file records); budget = tokens for the whole goal, -1 or
//         absent = none.
// stdout: { "context": "<round-1 protocol message>" } — the host sends it right AFTER the
//         user's own message (and any images), stamped `sender: "harness"`; the protocol
//         text points back at that message as the objective.
//
// The host runs this when a user submits the prompt that starts a goal (the harness server
// does so for the `goal` field of POST /tasks); the stop hook (stop.mjs) drives every
// later round.
import path from "node:path";
import { GOAL_FILE, readInput, roundMessage, writeGoal } from "./lib.mjs";

const input = readInput();
const scratchpadDir = String(input.scratchpad_dir || "");
const objective = String(input.prompt || "").trim();
if (!scratchpadDir || !objective) {
  process.stderr.write("start.mjs: scratchpad_dir and a non-empty prompt are required\n");
  process.exit(1);
}
const budget = Number.isFinite(input.budget) && input.budget > 0 ? Math.round(input.budget) : -1;
const goalFile = path.join(scratchpadDir, GOAL_FILE);
const goal = { objective, status: "active", budget, round: 1, tokens_used: 0 };
writeGoal(goalFile, goal);
process.stdout.write(
  `${JSON.stringify({ context: roundMessage(goal, goalFile, { firstRound: true }) })}\n`,
);