diff --git a/README.md b/README.md index e3166ac..766acbd 100644 --- a/README.md +++ b/README.md @@ -379,9 +379,16 @@ beacon serve [--config ] beacon doctor [--config ] beacon trigger [--config ] --profile --input - beacon schedule trigger [--config ] --profile --schedule +beacon feedback submit [--priority --summary ] beacon version ``` +`beacon feedback submit` is **Beacon Feedback** sugar over the same Outcome +socket/patch as `beacon outcome submit`. It only works inside a Beacon-managed +Run (`BEACON_OUTCOME_SOCKET` + `BEACON_RUN_TOKEN`). On current Pi fleets, +`submit_feedback` remains the primary DX; this CLI is the general submission +surface, not a skill replacement. + `serve`, `doctor`, `trigger`, and `schedule trigger` use `~/.beacon/config.yaml` in the current running user's home directory when `--config` is omitted, regardless of the working directory. An explicit override must be an absolute diff --git a/apps/cli/package.json b/apps/cli/package.json index edf799e..6a8b905 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,6 +1,6 @@ { "name": "@nettee/beacon", - "version": "0.8.14", + "version": "0.8.15", "description": "A single-host bridge from messaging and schedules to isolated agent runs", "license": "Apache-2.0", "repository": { diff --git a/apps/cli/src/cli-app.test.ts b/apps/cli/src/cli-app.test.ts index 9fa4cc5..3c64f44 100644 --- a/apps/cli/src/cli-app.test.ts +++ b/apps/cli/src/cli-app.test.ts @@ -26,6 +26,29 @@ test("parses the public CLI commands", () => { { command: "trigger", config: "/tmp/config.yaml", profile: "model-intel" }, ); assert.deepEqual(parseCli(["version"]), { command: "version" }); + assert.deepEqual(parseCli(["outcome", "submit"]), { + command: "outcome-submit", + }); + assert.deepEqual( + parseCli([ + "feedback", + "submit", + "--priority", + "high", + "--summary", + "GRAFANA_READER_TOKEN_PROD is unset.", + ]), + { + command: "feedback-submit", + item: { + priority: "high", + summary: "GRAFANA_READER_TOKEN_PROD is unset.", + }, + }, + ); + assert.deepEqual(parseCli(["feedback", "submit"]), { + command: "feedback-submit", + }); }); test("uses the running user's default config for service and operator commands", () => { @@ -95,6 +118,44 @@ test("usage documents the optional service config and shared default", () => { () => parseCli([]), /beacon serve \[--config \][\s\S]*Config defaults to ~\/\.beacon\/config.yaml/, ); + assert.throws( + () => parseCli([]), + /beacon feedback submit \[--priority --summary \][\s\S]*Pi submit_feedback remains the primary DX/, + ); +}); + +test("rejects invalid Beacon Feedback sugar", () => { + assert.throws( + () => + parseCli([ + "feedback", + "submit", + "--priority", + "low", + "--summary", + "nits", + ]), + /Usage/, + ); + assert.throws( + () => parseCli(["feedback", "submit", "--priority", "high"]), + /Usage/, + ); + assert.throws( + () => + parseCli([ + "feedback", + "submit", + "--priority", + "high", + "--summary", + "a", + "--extra", + "x", + ]), + /Usage/, + ); + assert.throws(() => parseCli(["feedback"]), /Usage/); }); test("serve resolves the user's home outside cwd and fails visibly without fallback", async (t) => { diff --git a/apps/cli/src/cli-app.ts b/apps/cli/src/cli-app.ts index 9deb585..f3b713a 100644 --- a/apps/cli/src/cli-app.ts +++ b/apps/cli/src/cli-app.ts @@ -3,6 +3,11 @@ import { isAbsolute, join } from "node:path"; export const defaultConfigPath = join(homedir(), ".beacon", "config.yaml"); +export type FeedbackCliItem = { + priority: "high" | "medium"; + summary: string; +}; + export type CliCommand = | { command: "serve"; config: string } | { command: "doctor"; config: string } @@ -14,7 +19,8 @@ export type CliCommand = schedule: string; } | { command: "version" } - | { command: "outcome-submit" }; + | { command: "outcome-submit" } + | { command: "feedback-submit"; item?: FeedbackCliItem }; function usage(): never { throw new Error(`Usage: @@ -22,10 +28,14 @@ function usage(): never { beacon doctor [--config ] beacon trigger [--config ] --profile --input - beacon schedule trigger [--config ] --profile --schedule + beacon feedback submit [--priority --summary ] beacon version Config defaults to ~/.beacon/config.yaml in the current user's home directory. -An explicit --config path must be absolute.`); +An explicit --config path must be absolute. +beacon feedback submit is sugar over beacon outcome submit for instruction feedback; +inside a Run it needs BEACON_OUTCOME_SOCKET and BEACON_RUN_TOKEN. Omit flags to +read { "items": [...] } from stdin. Pi submit_feedback remains the primary DX.`); } function options(args: string[]): Map { @@ -92,6 +102,31 @@ export function parseCli(args: string[]): CliCommand { if (command === "outcome" && rest.length === 1 && rest[0] === "submit") { return { command: "outcome-submit" }; } + if (command === "feedback" && rest[0] === "submit") { + const values = options(rest.slice(1)); + const priority = values.get("--priority"); + const summary = values.get("--summary"); + if ( + [...values.keys()].some( + (key) => !["--priority", "--summary"].includes(key), + ) + ) { + usage(); + } + if (priority === undefined && summary === undefined) { + return { command: "feedback-submit" }; + } + if ( + (priority !== "high" && priority !== "medium") || + summary === undefined + ) { + usage(); + } + return { + command: "feedback-submit", + item: { priority, summary }, + }; + } return usage(); } @@ -105,6 +140,7 @@ export type CliDependencies = { schedule: string, ): Promise; submitOutcome(): Promise; + submitFeedback(item?: FeedbackCliItem): Promise; version: string; }; @@ -136,5 +172,8 @@ export async function runCli( ); } if (command.command === "outcome-submit") return dependencies.submitOutcome(); + if (command.command === "feedback-submit") { + return dependencies.submitFeedback(command.item); + } console.log(dependencies.version); } diff --git a/apps/cli/src/cli.ts b/apps/cli/src/cli.ts index f173461..8c0fa84 100644 --- a/apps/cli/src/cli.ts +++ b/apps/cli/src/cli.ts @@ -14,6 +14,7 @@ async function main(): Promise { // Pi spawns `beacon outcome submit` for every Final Outcome. Keep that path // free of service/Feishu gateway imports so a partial package install cannot // turn an accepted `no_reply` into runtime_exit_failed (see #105). + // `beacon feedback submit` is sugar over the same light Outcome path. if (command.command === "outcome-submit") { const { submitOutcomeFromCli } = await import( "@nettee/beacon-daemon/outcome" @@ -21,6 +22,13 @@ async function main(): Promise { await submitOutcomeFromCli(); return; } + if (command.command === "feedback-submit") { + const { submitFeedbackFromCli } = await import( + "@nettee/beacon-daemon/outcome" + ); + await submitFeedbackFromCli(command.item); + return; + } if (command.command === "version") { console.log(packageVersion); @@ -44,6 +52,9 @@ async function main(): Promise { submitOutcome: async () => { throw new Error("outcome-submit must use the light import path"); }, + submitFeedback: async () => { + throw new Error("feedback-submit must use the light import path"); + }, version: packageVersion, }); } diff --git a/services/daemon/src/index.ts b/services/daemon/src/index.ts index f879a7d..22fcf31 100644 --- a/services/daemon/src/index.ts +++ b/services/daemon/src/index.ts @@ -1,6 +1,9 @@ export { runDoctor } from "./doctor.js"; export { runManualTrigger } from "./manual-trigger.js"; -export { submitOutcomeFromCli } from "./outcome/submit.js"; +export { + submitFeedbackFromCli, + submitOutcomeFromCli, +} from "./outcome/submit.js"; export type { RuntimeOptions } from "./runtime-options.js"; export { runScheduleTrigger } from "./schedule-trigger.js"; export { runBeacon } from "./service.js"; diff --git a/services/daemon/src/outcome/server.test.ts b/services/daemon/src/outcome/server.test.ts index 0848eaf..4141dfd 100644 --- a/services/daemon/src/outcome/server.test.ts +++ b/services/daemon/src/outcome/server.test.ts @@ -5,7 +5,7 @@ import { join } from "node:path"; import test from "node:test"; import { startOutcomeServer } from "./server.js"; -import { submitOutcome } from "./submit.js"; +import { submitFeedbackFromCli, submitOutcome } from "./submit.js"; test("stable outcome directory keeps the socket path across close/reopen", async () => { const directory = await mkdtemp(join(tmpdir(), "beacon-stable-outcomes-")); @@ -187,6 +187,35 @@ test("a Run Capability submits feedback without blocking reply", async () => { } }); +test("beacon feedback submit sugar uses the same Outcome socket", async () => { + const server = await startOutcomeServer(); + const previousSocket = process.env.BEACON_OUTCOME_SOCKET; + const previousToken = process.env.BEACON_RUN_TOKEN; + try { + const submission = server.openRun(); + process.env.BEACON_OUTCOME_SOCKET = submission.binding.socketPath; + process.env.BEACON_RUN_TOKEN = submission.binding.runToken; + await submitFeedbackFromCli({ + priority: "medium", + summary: "persona.md never says when to stop.", + }); + const feedback = submission.takeFeedback(); + assert.deepEqual(feedback?.items, [ + { + priority: "medium", + summary: "persona.md never says when to stop.", + }, + ]); + assert.equal(typeof feedback?.submittedAt, "string"); + } finally { + if (previousSocket === undefined) delete process.env.BEACON_OUTCOME_SOCKET; + else process.env.BEACON_OUTCOME_SOCKET = previousSocket; + if (previousToken === undefined) delete process.env.BEACON_RUN_TOKEN; + else process.env.BEACON_RUN_TOKEN = previousToken; + await server.close(); + } +}); + test("a Run Capability rejects a second feedback submission", async () => { const server = await startOutcomeServer(); try { diff --git a/services/daemon/src/outcome/submit.ts b/services/daemon/src/outcome/submit.ts index ff399c4..64a83df 100644 --- a/services/daemon/src/outcome/submit.ts +++ b/services/daemon/src/outcome/submit.ts @@ -112,4 +112,78 @@ export async function submitOutcomeFromCli(): Promise { console.log("Final Outcome accepted by Beacon"); } +export type FeedbackSubmitItem = { + priority: "high" | "medium"; + summary: string; +}; + +/** + * Beacon Feedback sugar over the same Outcome socket/patch as + * `beacon outcome submit`. Prefer Pi `submit_feedback` on current fleets. + */ +export async function submitFeedbackFromCli( + item?: FeedbackSubmitItem, +): Promise { + const socketPath = process.env.BEACON_OUTCOME_SOCKET; + const runToken = process.env.BEACON_RUN_TOKEN; + if (!socketPath || !runToken) { + throw new Error("This command must run inside a Beacon-managed Agent Run"); + } + + let patch: OutcomePatch; + if (item) { + try { + patch = parseOutcomePatch({ feedback: { items: [item] } }); + } catch (error) { + throw new Error( + "Feedback flags must be a valid high/medium item with a non-blank summary", + { cause: error }, + ); + } + } else { + process.stdin.setEncoding("utf8"); + let input = ""; + for await (const chunk of process.stdin) input += chunk; + let parsed: unknown; + try { + parsed = JSON.parse(input); + } catch (error) { + throw new Error( + 'Feedback stdin must be JSON: { "items": [...] } or a full outcome patch with feedback', + { cause: error }, + ); + } + try { + if ( + parsed && + typeof parsed === "object" && + "items" in parsed && + !("feedback" in parsed) && + !("reply" in parsed) && + !("notify" in parsed) && + !("observabilityFeedback" in parsed) + ) { + patch = parseOutcomePatch({ + feedback: parsed as { items: FeedbackSubmitItem[] }, + }); + } else { + patch = parseOutcomePatch(parsed); + } + } catch (error) { + throw new Error( + "Feedback stdin must be valid feedback items or outcome JSON", + { cause: error }, + ); + } + if (!patch.feedback) { + throw new Error( + "Feedback stdin must include feedback items (use beacon outcome submit for other patches)", + ); + } + } + + await submitOutcome(socketPath, runToken, patch); + console.log("Feedback accepted by Beacon"); +} + export { completeOutcome, mergeOutcome };