Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,16 @@ beacon serve [--config <absolute-path>]
beacon doctor [--config <absolute-path>]
beacon trigger [--config <absolute-path>] --profile <id> --input -
beacon schedule trigger [--config <absolute-path>] --profile <id> --schedule <id>
beacon feedback submit [--priority <high|medium> --summary <text>]
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
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
61 changes: 61 additions & 0 deletions apps/cli/src/cli-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -95,6 +118,44 @@ test("usage documents the optional service config and shared default", () => {
() => parseCli([]),
/beacon serve \[--config <absolute-path>\][\s\S]*Config defaults to ~\/\.beacon\/config.yaml/,
);
assert.throws(
() => parseCli([]),
/beacon feedback submit \[--priority <high\|medium> --summary <text>\][\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) => {
Expand Down
43 changes: 41 additions & 2 deletions apps/cli/src/cli-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -14,18 +19,23 @@ 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:
beacon serve [--config <absolute-path>]
beacon doctor [--config <absolute-path>]
beacon trigger [--config <absolute-path>] --profile <id> --input -
beacon schedule trigger [--config <absolute-path>] --profile <id> --schedule <id>
beacon feedback submit [--priority <high|medium> --summary <text>]
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<string, string> {
Expand Down Expand Up @@ -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();
}

Expand All @@ -105,6 +140,7 @@ export type CliDependencies = {
schedule: string,
): Promise<void>;
submitOutcome(): Promise<void>;
submitFeedback(item?: FeedbackCliItem): Promise<void>;
version: string;
};

Expand Down Expand Up @@ -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);
}
11 changes: 11 additions & 0 deletions apps/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ async function main(): Promise<void> {
// 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"
);
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);
Expand All @@ -44,6 +52,9 @@ async function main(): Promise<void> {
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,
});
}
Expand Down
5 changes: 4 additions & 1 deletion services/daemon/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
31 changes: 30 additions & 1 deletion services/daemon/src/outcome/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-"));
Expand Down Expand Up @@ -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 {
Expand Down
74 changes: 74 additions & 0 deletions services/daemon/src/outcome/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,78 @@ export async function submitOutcomeFromCli(): Promise<void> {
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<void> {
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 };
Loading