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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ Copy the files under [`examples`](examples) into a private Beacon home and repla
```text
~/.beacon/
├── config.yaml
├── runtime.env
├── runtime.env # optional shared keys for every Profile
├── secrets.json
├── profiles/
│ └── example/
│ └── profile.yaml
│ ├── profile.yaml
│ └── runtime.env # optional Profile-only keys (override shared)
└── playbook/
└── .beacon-profile/
├── persona.md
Expand All @@ -79,9 +80,11 @@ chmod 600 /Users/USERNAME/.beacon/secrets.json
```

`runtime.env` is optional. When present, Beacon loads every `KEY=VALUE` entry
once at startup and passes it to every Pi Run. This gives launchd deployments a
at startup. Each Profile may also have `profiles/<id>/runtime.env`. Merge order
is **shared first, then Profile** (Profile keys win on conflict). The effective
map is passed to that Profile's Pi Runs. This gives launchd deployments a
deterministic runtime environment without executing interactive shell files such
as `.zshrc`:
as `.zshrc`. Dashboard Profile detail lists **key names only** (never values).

```dotenv
GRAFANA_READER_TOKEN_PROD=replace-me
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.19",
"version": "0.8.20",
"description": "A single-host bridge from messaging and schedules to isolated agent runs",
"license": "Apache-2.0",
"repository": {
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/ProfilesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ function ProfileDetailPanel({ profile }: { profile: ProfileDetail }) {
</h3>
<p className="mt-1 text-sm text-zinc-600">{profile.secrets.note}</p>
</section>

<section>
<h3 className="text-xs font-semibold tracking-wide text-zinc-500 uppercase">
Runtime env ({profile.runtimeEnv.keys.length})
</h3>
<p className="mt-1 text-xs text-zinc-500">
Key names only · values are never shown · shared ∪ profile file
</p>
{profile.runtimeEnv.keys.length === 0 ? (
<p className="mt-2 text-sm text-zinc-500">No runtime.env keys.</p>
) : (
<ul className="mt-2 space-y-1 font-mono text-xs text-zinc-800">
{profile.runtimeEnv.keys.map((key) => (
<li key={key}>{key}</li>
))}
</ul>
)}
</section>
</div>
);
}
Expand Down
3 changes: 2 additions & 1 deletion docs/macmini-deploy-and-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
| Beacon home | `/Users/liuyi/.beacon` |
| 全局配置 | `/Users/liuyi/.beacon/config.yaml` |
| 全局飞书群渠道 | `/Users/liuyi/.beacon/channels.yaml`(仅群;admin 私聊在 Profile `admin.chat_id`) |
| Pi 运行环境 | `/Users/liuyi/.beacon/runtime.env` |
| Pi 运行环境(共享) | `/Users/liuyi/.beacon/runtime.env` |
| Pi 运行环境(Profile) | `/Users/liuyi/.beacon/profiles/<profile-id>/runtime.env`(可选;覆盖共享同名键) |
| Profile | `/Users/liuyi/.beacon/profiles/<profile-id>` |
| Profile workspace(可选) | `/Users/liuyi/.beacon/profiles/<profile-id>/workspace`(需 `config.yaml` 里 `profile_workspace.enabled: true`;默认 off) |
| 密钥 | `/Users/liuyi/.beacon/secrets.json` |
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 @@ -134,6 +134,11 @@ export type ProfileDetailView = {
/** Present when profile.yaml declares `skills`; omit/null = Pi default discovery. */
skills: ProfileSkillsView | null;
secrets: { present: false; note: string };
/**
* Effective runtime.env key names for this Profile (shared ∪ profile file).
* Values are never included.
*/
runtimeEnv: { keys: string[] };
};

/**
Expand Down
80 changes: 78 additions & 2 deletions services/daemon/src/config/runtime-environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import assert from "node:assert/strict";
import { chmod, mkdtemp, writeFile } from "node:fs/promises";
import { chmod, mkdir, mkdtemp, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";

import { loadRuntimeEnvironment } from "./runtime-environment.js";
import {
listMergedRuntimeEnvironmentKeys,
loadMergedRuntimeEnvironment,
loadRuntimeEnvironment,
profileRuntimeEnvironmentPath,
} from "./runtime-environment.js";

async function fixture(contents: string, mode = 0o600): Promise<string> {
const root = await mkdtemp(join(tmpdir(), "beacon-runtime-environment-"));
Expand Down Expand Up @@ -51,3 +56,74 @@ for (const [name, contents, pattern] of [
await assert.rejects(loadRuntimeEnvironment(path), pattern);
});
}

test("merges shared then profile with profile overriding same keys", async () => {
const root = await mkdtemp(join(tmpdir(), "beacon-runtime-merge-"));
const sharedPath = join(root, "runtime.env");
const profilePath = join(root, "profiles", "amr-galaxie", "runtime.env");
await writeFile(
sharedPath,
"SHARED_ONLY=shared-secret\nOVERLAP=from-shared\n",
{ mode: 0o600 },
);
await chmod(sharedPath, 0o600);
await mkdir(join(root, "profiles", "amr-galaxie"), { recursive: true });
await writeFile(
profilePath,
"PROFILE_ONLY=profile-secret\nOVERLAP=from-profile\n",
{ mode: 0o600 },
);
await chmod(profilePath, 0o600);

const merged = await loadMergedRuntimeEnvironment({
sharedPath,
profilePath,
});
assert.deepEqual(merged, {
SHARED_ONLY: "shared-secret",
OVERLAP: "from-profile",
PROFILE_ONLY: "profile-secret",
});

const keys = await listMergedRuntimeEnvironmentKeys({
sharedPath,
profilePath,
});
assert.deepEqual(keys, ["OVERLAP", "PROFILE_ONLY", "SHARED_ONLY"]);
const serialized = JSON.stringify({ keys });
assert.doesNotMatch(serialized, /shared-secret/);
assert.doesNotMatch(serialized, /profile-secret/);
assert.doesNotMatch(serialized, /from-shared/);
assert.doesNotMatch(serialized, /from-profile/);
});

test("merge treats missing shared or profile file as empty", async () => {
const root = await mkdtemp(join(tmpdir(), "beacon-runtime-merge-absent-"));
const sharedPath = join(root, "runtime.env");
const profilePath = join(root, "profiles", "solo", "runtime.env");
await mkdir(join(root, "profiles", "solo"), { recursive: true });
await writeFile(profilePath, "SOLO=only-here\n", { mode: 0o600 });
await chmod(profilePath, 0o600);

assert.deepEqual(
await loadMergedRuntimeEnvironment({ sharedPath, profilePath }),
{ SOLO: "only-here" },
);
assert.deepEqual(
await listMergedRuntimeEnvironmentKeys({
sharedPath: join(root, "missing-shared.env"),
profilePath: join(root, "missing-profile.env"),
}),
[],
);
});

test("profileRuntimeEnvironmentPath nests under the Profile directory", () => {
assert.equal(
profileRuntimeEnvironmentPath(
"/home/beacon/.beacon/profiles",
"amr-release",
),
join("/home/beacon/.beacon/profiles", "amr-release", "runtime.env"),
);
});
37 changes: 37 additions & 0 deletions services/daemon/src/config/runtime-environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, stat } from "node:fs/promises";
import { join } from "node:path";

const variableNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;

Expand Down Expand Up @@ -112,3 +113,39 @@ export async function loadRuntimeEnvironment(
}
return parseRuntimeEnvironment(raw, path);
}

/** Path to an optional per-Profile `runtime.env` under the Profile directory. */
export function profileRuntimeEnvironmentPath(
profilesDirectory: string,
profileId: string,
): string {
return join(profilesDirectory, profileId, "runtime.env");
}

/**
* Merge shared + Profile runtime.env for one Profile.
* Shared is the base; Profile keys override same-named shared keys.
* Either file may be absent (treated as `{}`).
*/
export async function loadMergedRuntimeEnvironment(options: {
sharedPath: string;
profilePath: string;
}): Promise<NodeJS.ProcessEnv> {
const shared = await loadRuntimeEnvironment(options.sharedPath);
const profile = await loadRuntimeEnvironment(options.profilePath);
return { ...shared, ...profile };
}

/**
* Key names only (sorted) for Dashboard / API — never returns values.
* Uses the same merge order as {@link loadMergedRuntimeEnvironment}.
*/
export async function listMergedRuntimeEnvironmentKeys(options: {
sharedPath: string;
profilePath: string;
}): Promise<string[]> {
const environment = await loadMergedRuntimeEnvironment(options);
return Object.keys(environment).sort((left, right) =>
left.localeCompare(right),
);
}
44 changes: 43 additions & 1 deletion services/daemon/src/dashboard/profiles.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
import { chmod, mkdir, mkdtemp, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
Expand Down Expand Up @@ -67,6 +67,20 @@ async function fixture(): Promise<string> {
},
}),
);
const sharedEnv = join(root, "runtime.env");
await writeFile(
sharedEnv,
"SHARED_TOKEN=shared-runtime-value\nOVERLAP=from-shared\n",
{ mode: 0o600 },
);
await chmod(sharedEnv, 0o600);
const profileEnv = join(profiles, "amr-release", "runtime.env");
await writeFile(
profileEnv,
"PROFILE_TOKEN=profile-runtime-value\nOVERLAP=from-profile\n",
{ mode: 0o600 },
);
await chmod(profileEnv, 0o600);
return profiles;
}

Expand Down Expand Up @@ -109,10 +123,38 @@ test("returns profile detail with channel notify references and no secrets", asy
assert.equal(detail.timeoutSeconds, null);
assert.equal(detail.secrets.present, false);
assert.match(detail.secrets.note, /secrets\.json/);
assert.deepEqual(detail.runtimeEnv.keys, [
"OVERLAP",
"PROFILE_TOKEN",
"SHARED_TOKEN",
]);
const serialized = JSON.stringify(detail);
assert.doesNotMatch(serialized, /super-secret-value/);
assert.doesNotMatch(serialized, /cli_0123456789abcdef/);
assert.doesNotMatch(serialized, /app_secret/);
assert.doesNotMatch(serialized, /shared-runtime-value/);
assert.doesNotMatch(serialized, /profile-runtime-value/);
assert.doesNotMatch(serialized, /from-shared/);
assert.doesNotMatch(serialized, /from-profile/);
});

test("profile detail runtimeEnv keys stay empty without runtime.env files", async () => {
const root = await mkdtemp(join(tmpdir(), "beacon-dashboard-no-env-"));
const profiles = join(root, "profiles");
await mkdir(join(profiles, "solo"), { recursive: true });
await writeFile(
join(profiles, "solo", "profile.yaml"),
[
"playbook: /tmp/workspace",
"runtime: pi",
"model:",
" provider: deepseek",
" id: deepseek-flash",
"",
].join("\n"),
);
const detail = await getProfileDetailView(profiles, "solo");
assert.deepEqual(detail?.runtimeEnv.keys, []);
});

test("accepts optional max_concurrent, max_queued, and timeout_seconds from profile.yaml", async () => {
Expand Down
16 changes: 15 additions & 1 deletion services/daemon/src/dashboard/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { join } from "node:path";
import { z } from "zod";

import { channelNamePattern } from "../config/channels.js";
import {
listMergedRuntimeEnvironmentKeys,
profileRuntimeEnvironmentPath,
} from "../config/runtime-environment.js";
import { parseStrictYaml } from "../config/yaml.js";

const profileIdPattern = /^[a-z0-9](?:[a-z0-9_-]{0,62})$/;
Expand Down Expand Up @@ -139,6 +143,7 @@ function toNotifyView(
function toDetailView(
profileId: string,
document: z.infer<typeof profileDocumentSchema>,
runtimeEnvKeys: string[],
): ProfileDetailView {
return {
id: profileId,
Expand Down Expand Up @@ -172,6 +177,7 @@ function toDetailView(
present: false,
note: "Feishu app credentials are stored in secrets.json and are not exposed by the dashboard.",
},
runtimeEnv: { keys: runtimeEnvKeys },
};
}

Expand Down Expand Up @@ -245,6 +251,7 @@ export async function listProfileViews(
export async function getProfileDetailView(
profilesDirectory: string,
profileId: string,
options?: { sharedRuntimeEnvironmentPath?: string | undefined },
): Promise<ProfileDetailView | null> {
if (!isProfileId(profileId)) return null;
const directory = join(profilesDirectory, profileId);
Expand All @@ -256,7 +263,14 @@ export async function getProfileDetailView(
}
try {
const document = await readProfileYaml(profilesDirectory, profileId);
return toDetailView(profileId, document);
const sharedPath =
options?.sharedRuntimeEnvironmentPath ??
join(profilesDirectory, "..", "runtime.env");
const runtimeEnvKeys = await listMergedRuntimeEnvironmentKeys({
sharedPath,
profilePath: profileRuntimeEnvironmentPath(profilesDirectory, profileId),
});
return toDetailView(profileId, document, runtimeEnvKeys);
} catch (error) {
throw new Error(
`Cannot load Profile ${profileId}: ${error instanceof Error ? error.message : String(error)}`,
Expand Down
17 changes: 17 additions & 0 deletions services/daemon/src/dashboard/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ test("serves profile list and detail JSON without secrets", async () => {
},
}),
);
const sharedEnv = join(profiles, "..", "runtime.env");
await writeFile(sharedEnv, "DASH_SHARED=shared-api-secret\n", {
mode: 0o600,
});
await chmod(sharedEnv, 0o600);
const profileEnv = join(profiles, "alpha", "runtime.env");
await writeFile(profileEnv, "DASH_PROFILE=profile-api-secret\n", {
mode: 0o600,
});
await chmod(profileEnv, 0o600);
const server = await startDashboard({
listen: "127.0.0.1",
port: 0,
Expand All @@ -293,6 +303,8 @@ test("serves profile list and detail JSON without secrets", async () => {
const detailText = await detail.text();
assert.doesNotMatch(detailText, /should-not-leak/);
assert.doesNotMatch(detailText, /app_secret/);
assert.doesNotMatch(detailText, /shared-api-secret/);
assert.doesNotMatch(detailText, /profile-api-secret/);
const detailBody = JSON.parse(detailText) as {
profile: {
id: string;
Expand All @@ -304,6 +316,7 @@ test("serves profile list and detail JSON without secrets", async () => {
notify: { kind: string; name?: string } | null;
}>;
secrets: { present: boolean };
runtimeEnv: { keys: string[] };
};
};
assert.equal(detailBody.profile.id, "alpha");
Expand All @@ -317,6 +330,10 @@ test("serves profile list and detail JSON without secrets", async () => {
"weekday-brief-group",
);
assert.equal(detailBody.profile.secrets.present, false);
assert.deepEqual(detailBody.profile.runtimeEnv.keys, [
"DASH_PROFILE",
"DASH_SHARED",
]);

const missing = await fetch(`${origin}/api/profiles/missing`);
assert.equal(missing.status, 404);
Expand Down
Loading
Loading