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
4 changes: 2 additions & 2 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ The reply and optional notify result explicitly submitted for a Run, or the expl
_Avoid_: Progress, trace, intermediate output

**Delivery Target**:
The exact reply location and optional notify location captured from a Trigger and bound to its Run; addresses are resolved and used only by Beacon. The Agent Runtime may choose which bound channel to use (`reply_text` / `reply_card` / `no_reply` / `notify_card`) but never supplies a `chat_id`.
The exact reply location and optional notify location captured from a Trigger and bound to its Run; addresses are resolved and used only by Beacon. The Agent Runtime may choose which bound channel to use (`reply_text` / `reply_card` / `no_reply` / `notify_admin` / `notify_card`) but never supplies a `chat_id`.
_Avoid_: Profile, destination prompt

**Delivery**:
An attempt to send a Final Outcome to a messaging destination using the Profile's application identity.
_Avoid_: Run, reply

**Schedule**:
A recurring rule that creates a Trigger for a Profile, replies to the Profile admin, and may name a group for `notify_card`.
A recurring rule that creates a Trigger for a Profile, may `notify_admin` the Profile admin, and may name a group for `notify_card`.
_Avoid_: launchd job, cron job

**Scheduled Occurrence**:
Expand Down
69 changes: 38 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Beacon

Beacon is a single-host service that turns Feishu messages, configured schedules, and subscribed CloudEvents into isolated Pi agent runs. Each accepted Trigger is durably claimed, produces an explicit Final Outcome, and may `reply_text` / `reply_card` to a person, `notify_card` a group, or stay silent on the admin channel.
Beacon is a single-host service that turns Feishu messages, configured schedules, and subscribed CloudEvents into isolated Pi agent runs. Each accepted Trigger is durably claimed, produces an explicit Final Outcome, and may `reply_text` / `reply_card` to the direct caller, `notify_admin` the Profile admin, `notify_card` a group, or stay silent with `no_reply`.

This repository currently implements the Feishu + Pi MVP described by the
[Zest Dev Spec](https://github.com/nettee/beacon/blob/main/specs/change/20260913-beacon-feishu-pi-mvp/spec.md).
Expand Down Expand Up @@ -68,8 +68,9 @@ back to `prompt.md`. If neither place has a complete pair, Profile load fails
and lists the missing paths. Both pairs may exist; the playbook pair wins.

Beacon prepends an English platform template for this Run: playbook limit,
inbound vs Schedule vs event vs manual capabilities, the `reply_text` / `reply_card` /
`no_reply` / `notify_card` contract, and optional `submit_feedback` (instruction gaps).
inbound vs Schedule vs event vs manual capabilities, the `reply_text` /
`reply_card` / `no_reply` / `notify_admin` / `notify_card` contract, and optional
`submit_feedback` (instruction gaps).

Protect the home and secret file before running Beacon:

Expand Down Expand Up @@ -206,11 +207,10 @@ under `notify` still loads so hosts can migrate one Profile at a time; new
`notify` entries should use `name`.

Each Schedule uses a five-field cron expression and an IANA timezone. Profile
`admin` is the private chat used for schedule `reply_text` /
`reply_card` / `no_reply` and for failure notices. Optional `notify` on a
Schedule is the group that receives `notify_card`. Beacon deliberately does not
infer or fall back to another destination. A newly discovered Schedule starts at
the current time.
`admin` is the private chat used for `notify_admin` (and for non-human failure
notices). Optional `notify` on a Schedule is the group that receives
`notify_card`. Beacon deliberately does not infer or fall back to another
destination. A newly discovered Schedule starts at the current time.
After sleep or restart, overdue occurrences are reconciled and coalesced to the
most recent one.

Expand Down Expand Up @@ -290,10 +290,11 @@ list, AND between `sources` and `types`**. There are no wildcards, regular
expressions, or filters inside `data`. A listener requires `admin`;
`listener.notify` is optional. Matching Profiles each receive one Trigger with
the complete event as input. Their `persona.md` and `task.md` define what to do.
`reply_text` and `reply_card` go to the configured admin; `no_reply` is allowed;
`notify_card` is available only when the listener has a notify target. The event
cannot choose a Profile, command, or delivery destination. All event fields
remain untrusted external data, even after producer authentication.
Prefer `no_reply` when there is no task result for the caller; use
`notify_admin` for admin short side-effect messages. `notify_card` is available
only when the listener has a notify target. The event cannot choose a Profile,
command, or delivery destination. All event fields remain untrusted external
data, even after producer authentication.

Restart Beacon after changing configuration or credentials. This example sends
one CloudEvents 1.0 structured JSON event. Set the token in your **sender's**
Expand Down Expand Up @@ -422,24 +423,29 @@ messages include the `run_id` whenever a Run record was created.

## Final Outcomes

An Agent closes the conversational channel with `reply_text`, `reply_card`, or
`no_reply`, and may also call `notify_card` when the Run has a notify target:

- `reply_text` sends plain text. Inbound Feishu messages quote-reply the user.
Schedules and event Runs message the Profile admin.
- `reply_card` sends an interactive card on the same conversational channel
(inbound quote-reply, or Schedule/event admin chat). It closes that channel by
itself.
- `no_reply` finishes without messaging the conversational channel. Its
`reason` is stored for audit and is never sent. Do not use it on inbound
messages.
An Agent closes the reply gate with `reply_text`, `reply_card`, or `no_reply`,
and may also call `notify_admin` and/or `notify_card` (when available):

- `reply_text` sends plain text as the task result to the direct caller.
Inbound Feishu messages quote-reply the user. Manual Runs print to the
operator. Prefer `notify_admin` for Schedule / Listener / on_failure admin
short messages.
- `reply_card` sends an interactive card as the task result on the
conversational channel (inbound quote-reply, or manual stdout). It closes
that channel by itself.
- `no_reply` finishes with no task result for the direct caller. Its `reason`
is stored for audit and is never sent. Do not use it on inbound messages.
- `notify_admin` sends a short plain-text side-effect / audit message to the
Profile admin private chat. Orthogonal to the reply gate; at most once per
Run. May be combined with `notify_card` and `no_reply`.
- `notify_card` posts an interactive card to the Schedule or listener's configured group.
Only valid when the Run has a notify target.

Which of `reply_text` / `reply_card` / `notify_card` / `no_reply` to use for a
business result is decided by the Profile persona/task (or the situation), not
hard-coded by Beacon beyond channel availability (`notify_card` needs a notify
target; inbound cannot `no_reply`).
Which of `reply_text` / `reply_card` / `notify_admin` / `notify_card` /
`no_reply` to use for a business result is decided by the Profile persona/task
(or the situation), not hard-coded by Beacon beyond channel availability
(`notify_card` needs a notify target; inbound cannot `no_reply`). During
migration, non-human `reply_text` is rewritten to `notify_admin` + `no_reply`.

The card tools accept a title, Feishu-compatible Markdown body, and up to five
HTTP(S) link buttons. The first button is styled as primary. The tools accept
Expand All @@ -466,10 +472,11 @@ these argument shapes:

Beacon binds destinations; the Agent never supplies a `chat_id`. Text remains
text. Cards are sent with Feishu's `interactive` message type and include the
card generation time. A Schedule or event `no_reply` without `notify_card` records a
successful Run with no Delivery. Failures `reply_text` a short error and never
notify a group. Manual local triggers print reply text/card and any notify card
as Markdown on stdout.
card generation time. A Schedule or event `no_reply` without notify records a
successful Run with no Delivery. Human-caller failures `reply_text` a short
error; non-human failures use `notify_admin` and never notify a business group.
Manual local triggers print reply text/card and any notify card/admin text as
Markdown on stdout.

## State and failure behavior

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.20",
"version": "0.8.21",
"description": "A single-host bridge from messaging and schedules to isolated agent runs",
"license": "Apache-2.0",
"repository": {
Expand Down
21 changes: 20 additions & 1 deletion apps/web/src/RunsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ function stateClass(state: string | null): string {
return "text-zinc-600";
}

/** Compact delivery labels so notify_card / notify_admin are not invisible. */
function deliveryLabel(row: RunRow): string {
const parts: string[] = [];
if (row.deliveryState) parts.push(`reply:${row.deliveryState}`);
if (row.notifyDeliveryState) {
parts.push(`notify:${row.notifyDeliveryState}`);
}
if (row.notifyAdminDeliveryState) {
parts.push(`admin:${row.notifyAdminDeliveryState}`);
}
return parts.length > 0 ? parts.join(" · ") : none;
}

function profilesFromSearch(search: string): string[] {
const params = new URLSearchParams(search);
return params
Expand Down Expand Up @@ -199,6 +212,9 @@ export function RunsPage() {
onChange={setFailure}
/>
</th>
<th className="px-3 py-2 text-[11px] font-semibold tracking-wide text-zinc-500 uppercase">
Delivery
</th>
<th className="px-3 py-2 text-[11px] font-semibold tracking-wide text-zinc-500 uppercase">
HTML
</th>
Expand Down Expand Up @@ -227,6 +243,9 @@ export function RunsPage() {
<td className="px-3 py-2 font-mono text-xs text-zinc-500">
{row.failureCode ?? none}
</td>
<td className="px-3 py-2 font-mono text-xs text-zinc-600">
{deliveryLabel(row)}
</td>
<td className="px-3 py-2">
{row.runId && row.hasSessionFile ? (
<a
Expand All @@ -244,7 +263,7 @@ export function RunsPage() {
</tr>
{feedbackRows.length > 0 ? (
<tr className="border-b border-zinc-200 bg-zinc-50/80">
<td colSpan={7} className="px-3 pt-0 pb-3">
<td colSpan={8} className="px-3 pt-0 pb-3">
<ul className="ml-1 space-y-1">
{feedbackRows.map((item) => {
const copyText = formatFeedbackCopy(
Expand Down
7 changes: 4 additions & 3 deletions docs/profile-prompt-writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ Beacon **先**拼英文平台模板,再拼接 `persona.md` 和 `task.md`。不
```text
[Beacon · English]
playbook = Profile yaml 的 playbook
this Run = inbound | schedule {id} | event | manual
this Run = inbound | schedule {id} | event | on_failure | manual
对话通道:入站用 reply_text 或 reply_card 恰好一次(禁止 no_reply)
定时/事件/手动:reply_text、reply_card 或 no_reply 恰好一次
定时/事件/级联/手动:reply_text、reply_card 或 no_reply 恰好一次(非人触发优先 no_reply)
notify_admin:Profile 有 admin 时允许一次(管理员私聊副作用/审计)
notify_card:仅当这次 Run 有 notify 目标时允许一次;否则不要调用
合同:投递工具是什么、不要填 chat_id、模型正文不投递;用哪种工具由 Profile 业务决定
可选:有指令/Skill/依赖/工具上的高/中优先级问题时,可调用一次 `submit_feedback`;没有就不要调
Expand All @@ -36,7 +37,7 @@ Beacon **先**拼英文平台模板,再拼接 `persona.md` 和 `task.md`。不
[task.md] ← 同上
```

英文前言只声明本 Run **可用**哪些通道工具。Profile **不要复述**工具定义、不填 `chat_id`、工作区路径。业务仍决定**何时开口**:有结果 / 空转 / 失败时用 `reply_text`、`reply_card`、`no_reply` 还是 `notify_card`,以及卡片标题和按钮。
英文前言只声明本 Run **可用**哪些通道工具。Profile **不要复述**工具定义、不填 `chat_id`、工作区路径。业务仍决定**何时开口**:有结果 / 空转 / 失败时用 `reply_text`、`reply_card`、`no_reply`、`notify_admin` 还是 `notify_card`,以及卡片标题和按钮。

## Agent 实际看到的用户输入

Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ export type RunRow = {
runId: string | null;
state: string | null;
failureCode: string | null;
/** Reply-channel delivery state (`reply_text` / `reply_card`). */
deliveryState: string | null;
/** Group `notify_card` delivery state when present. */
notifyDeliveryState: string | null;
/** Admin `notify_admin` delivery state when present. */
notifyAdminDeliveryState: string | null;
hasSessionFile: boolean;
feedback: Array<{ priority: "high" | "medium"; summary: string }> | null;
observabilityFeedback: Array<{
Expand Down
13 changes: 12 additions & 1 deletion services/daemon/src/dashboard/records.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ async function fixture(): Promise<{ profiles: string; sessions: string }> {
profileId: "alpha",
acceptedAt: "2026-01-02T00:00:00.000Z",
input: { kind: "schedule", scheduleId: "hourly" },
notifyTarget: { kind: "chat", chatId: "oc_group" },
run: {
runId: "run_ok",
state: "failed",
failure: { code: "runtime_timeout" },
sessionPath: join(sessions, "alpha", "run_ok"),
},
notifyDelivery: { deliveryId: "del_n", state: "delivered" },
notifyAdminDelivery: { deliveryId: "del_a", state: "delivered" },
}),
);
await writeFile(
Expand All @@ -60,6 +63,8 @@ test("lists runs newest first and notes missing session files", async () => {
hasNotifyTarget: row.hasNotifyTarget,
state: row.state,
failureCode: row.failureCode,
notifyDeliveryState: row.notifyDeliveryState,
notifyAdminDeliveryState: row.notifyAdminDeliveryState,
hasSessionFile: row.hasSessionFile,
systemPrompt: row.systemPrompt,
feedback: row.feedback,
Expand All @@ -70,9 +75,11 @@ test("lists runs newest first and notes missing session files", async () => {
runId: "run_ok",
kind: "schedule",
scheduleId: "hourly",
hasNotifyTarget: false,
hasNotifyTarget: true,
state: "failed",
failureCode: "runtime_timeout",
notifyDeliveryState: "delivered",
notifyAdminDeliveryState: "delivered",
hasSessionFile: true,
systemPrompt: undefined,
feedback: undefined,
Expand All @@ -85,13 +92,17 @@ test("lists runs newest first and notes missing session files", async () => {
hasNotifyTarget: false,
state: "succeeded",
failureCode: undefined,
notifyDeliveryState: undefined,
notifyAdminDeliveryState: undefined,
hasSessionFile: false,
systemPrompt: undefined,
feedback: undefined,
observabilityFeedback: undefined,
},
],
);
assert.equal(toRunListItem(rows[0]!).notifyDeliveryState, "delivered");
assert.equal(toRunListItem(rows[0]!).notifyAdminDeliveryState, "delivered");
});

test("exposes feedback items on the list payload only when present", async () => {
Expand Down
8 changes: 8 additions & 0 deletions services/daemon/src/dashboard/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type RunSummary = {
state: string | undefined;
failureCode: string | undefined;
deliveryState: string | undefined;
notifyDeliveryState: string | undefined;
notifyAdminDeliveryState: string | undefined;
sessionPath: string | undefined;
hasSessionFile: boolean;
systemPrompt: string | undefined;
Expand Down Expand Up @@ -85,6 +87,8 @@ function summarize(
const input = asRecord(record.input);
const run = asRecord(record.run);
const delivery = asRecord(record.delivery);
const notifyDelivery = asRecord(record.notifyDelivery);
const notifyAdminDelivery = asRecord(record.notifyAdminDelivery);
const failure = asRecord(run?.failure);
return {
profileId,
Expand All @@ -103,6 +107,8 @@ function summarize(
state: asString(run?.state),
failureCode: asString(failure?.code),
deliveryState: asString(delivery?.state),
notifyDeliveryState: asString(notifyDelivery?.state),
notifyAdminDeliveryState: asString(notifyAdminDelivery?.state),
sessionPath: asString(run?.sessionPath),
hasSessionFile,
systemPrompt: asString(run?.systemPrompt),
Expand Down Expand Up @@ -182,6 +188,8 @@ export function toRunListItem(row: RunSummary): RunRow {
state: row.state ?? null,
failureCode: row.failureCode ?? null,
deliveryState: row.deliveryState ?? null,
notifyDeliveryState: row.notifyDeliveryState ?? null,
notifyAdminDeliveryState: row.notifyAdminDeliveryState ?? null,
hasSessionFile: row.hasSessionFile,
feedback:
row.feedback && row.feedback.items.length > 0
Expand Down
26 changes: 17 additions & 9 deletions services/daemon/src/dashboard/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,29 @@ export function defaultUiDirectory(): string {
return join(dirname(fileURLToPath(import.meta.url)), "ui");
}

function triggerFromRunSummary(summary: RunSummary): AgentSystemPromptTrigger {
function triggerFromRunSummary(
summary: RunSummary,
options: { hasAdmin?: boolean | undefined } = {},
): AgentSystemPromptTrigger {
const notifyAdmin = options.hasAdmin === true;
if (summary.kind === "schedule") {
return {
kind: "schedule",
...(summary.scheduleId ? { scheduleId: summary.scheduleId } : {}),
notify: summary.hasNotifyTarget,
notifyAdmin,
};
}
if (summary.kind === "event") {
return { kind: "event", notify: summary.hasNotifyTarget };
return { kind: "event", notify: summary.hasNotifyTarget, notifyAdmin };
}
if (summary.kind === "feishu_message") {
return { kind: "feishu_message", notify: false };
return { kind: "feishu_message", notify: false, notifyAdmin };
}
if (summary.kind === "on_failure") {
return { kind: "on_failure", notify: summary.hasNotifyTarget };
return { kind: "on_failure", notify: summary.hasNotifyTarget, notifyAdmin };
}
return { kind: "manual", notify: summary.hasNotifyTarget };
return { kind: "manual", notify: summary.hasNotifyTarget, notifyAdmin };
}

async function beaconOwnedSystemPrompt(
Expand All @@ -189,12 +194,15 @@ async function beaconOwnedSystemPrompt(
try {
const channelsPath = defaultChannelsPath(dirname(profilesDirectory));
const channels = await loadChannelRegistry(channelsPath);
const profile = await loadProfile(summary.profileId, profilesDirectory, {
channels,
channelsPath,
});
return buildAgentSystemPrompt(
await loadProfile(summary.profileId, profilesDirectory, {
channels,
channelsPath,
profile,
triggerFromRunSummary(summary, {
hasAdmin: profile.admin?.chatId !== undefined,
}),
triggerFromRunSummary(summary),
);
} catch {
// Old runs without a stored prompt: reconstruction needs a readable Profile.
Expand Down
8 changes: 8 additions & 0 deletions services/daemon/src/domain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ export type CardContent = {
/** Text, silent, or a `reply_card` interactive message on the conversational channel. */
export type ReplyContent = TextReplyContent | NoReplyContent | CardContent;

/** Admin private-chat side effect from `notify_admin` (not a task-result reply). */
export type NotifyAdminContent = TextReplyContent;

export type FinalOutcomeContent = {
reply: ReplyContent;
/** Group card from `notify_card` → Schedule/Listener notify channel. */
notify?: CardContent | undefined;
/** Admin short text from `notify_admin` → Profile `admin.chat_id`. */
notifyAdmin?: NotifyAdminContent | undefined;
};

export const feedbackPriorities = ["high", "medium"] as const;
Expand Down Expand Up @@ -250,4 +256,6 @@ export type TriggerRecord = {
observabilityFeedback?: ObservabilityFeedbackRecord | undefined;
delivery?: DeliveryRecord | undefined;
notifyDelivery?: DeliveryRecord | undefined;
/** Delivery of `notify_admin` text to Profile `admin.chat_id`. */
notifyAdminDelivery?: DeliveryRecord | undefined;
};
Loading
Loading