@app-vitals/agent-lib 1.115.0 → 1.115.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/child-env.ts +73 -0
- package/child-env.unit.test.ts +84 -0
- package/package.json +2 -1
- package/secret-env-vars.ts +3 -0
- package/secret-env-vars.unit.test.ts +3 -1
package/child-env.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/child-env.ts
|
|
3
|
+
* Env filter for processes the runtime spawns on the model's behalf (the
|
|
4
|
+
* `claude -p` CLI and cron preChecks). The runtime's process.env holds every
|
|
5
|
+
* secret the config sync copied in; the child only needs the ones skills use.
|
|
6
|
+
*
|
|
7
|
+
* Denylist, not allowlist: operators define arbitrary per-agent env vars that
|
|
8
|
+
* skills read directly, and an allowlist would silently break them.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { SECRET_ENV_VARS } from "./secret-env-vars.ts";
|
|
12
|
+
|
|
13
|
+
type SecretEnvVar = (typeof SECRET_ENV_VARS)[number];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Vars only the runtime consumes: credentials for the runtime's own Slack,
|
|
17
|
+
* GitHub App and voice integrations, plus the Sentry client DSN. Never passed
|
|
18
|
+
* to a child. Entries are secret-shaped (and so also in SECRET_ENV_VARS)
|
|
19
|
+
* except SENTRY_DSN, a client DSN that is not secret but must not let a spawned
|
|
20
|
+
* session (or any `bun test` it runs) build a real Sentry client.
|
|
21
|
+
*/
|
|
22
|
+
export const RUNTIME_ONLY_ENV_VARS = [
|
|
23
|
+
"GH_APP_PRIVATE_KEY",
|
|
24
|
+
"GH_APP_CLIENT_SECRET",
|
|
25
|
+
"SLACK_APP_TOKEN",
|
|
26
|
+
"SLACK_SIGNING_SECRET",
|
|
27
|
+
"SLACK_CLIENT_SECRET",
|
|
28
|
+
"SENTRY_DSN",
|
|
29
|
+
"GROQ_API_KEY",
|
|
30
|
+
"ELEVENLABS_API_KEY",
|
|
31
|
+
] as const satisfies readonly (SecretEnvVar | "SENTRY_DSN")[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Secrets that pass through to the child. Some the child uses directly (skills,
|
|
35
|
+
* the claude CLI itself). The rest belong to the admin, chat or task-store
|
|
36
|
+
* services: the platform never writes them onto an agent, so one present on an
|
|
37
|
+
* agent was set there on purpose by an operator and is kept.
|
|
38
|
+
*/
|
|
39
|
+
export const CHILD_ALLOWED_SECRET_ENV_VARS = [
|
|
40
|
+
"ANTHROPIC_API_KEY",
|
|
41
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
42
|
+
"GH_TOKEN",
|
|
43
|
+
"SLACK_BOT_TOKEN",
|
|
44
|
+
"SHIPWRIGHT_AGENT_API_KEY",
|
|
45
|
+
"SHIPWRIGHT_TASK_STORE_TOKEN",
|
|
46
|
+
"SHIPWRIGHT_CHAT_SERVICE_TOKEN",
|
|
47
|
+
// The shipped shipwright task-store skill still mints scoped tokens with
|
|
48
|
+
// this admin token.
|
|
49
|
+
"SHIPWRIGHT_TASK_STORE_ADMIN_TOKEN",
|
|
50
|
+
// Service-side secrets, never provisioned onto an agent (operator-set only).
|
|
51
|
+
"SLACK_ADMIN_TOKEN",
|
|
52
|
+
"SHIPWRIGHT_ADMIN_API_KEYS",
|
|
53
|
+
"SHIPWRIGHT_ENCRYPTION_KEY",
|
|
54
|
+
"SHIPWRIGHT_SESSION_SECRET",
|
|
55
|
+
"SHIPWRIGHT_ADMIN_VAPID_PRIVATE_KEY",
|
|
56
|
+
"SHIPWRIGHT_ADMIN_PUSH_WEBHOOK_TOKEN",
|
|
57
|
+
"SHIPWRIGHT_CHAT_PUSH_WEBHOOK_TOKEN",
|
|
58
|
+
"SHIPWRIGHT_CHAT_SERVICE_ADMIN_TOKEN",
|
|
59
|
+
"GOOGLE_CLIENT_SECRET",
|
|
60
|
+
] as const satisfies readonly SecretEnvVar[];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Copy `env`, drop every runtime-only key, then layer `extra` last so a
|
|
64
|
+
* per-run override still wins.
|
|
65
|
+
*/
|
|
66
|
+
export function buildChildEnv(
|
|
67
|
+
env: Record<string, string | undefined>,
|
|
68
|
+
extra?: Record<string, string>,
|
|
69
|
+
): Record<string, string | undefined> {
|
|
70
|
+
const child: Record<string, string | undefined> = { ...env };
|
|
71
|
+
for (const key of RUNTIME_ONLY_ENV_VARS) delete child[key];
|
|
72
|
+
return { ...child, ...extra };
|
|
73
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
buildChildEnv,
|
|
4
|
+
CHILD_ALLOWED_SECRET_ENV_VARS,
|
|
5
|
+
RUNTIME_ONLY_ENV_VARS,
|
|
6
|
+
} from "./child-env.ts";
|
|
7
|
+
import { SECRET_ENV_VARS } from "./secret-env-vars.ts";
|
|
8
|
+
|
|
9
|
+
describe("buildChildEnv", () => {
|
|
10
|
+
test("removes every runtime-only key and keeps all others", () => {
|
|
11
|
+
const env: Record<string, string> = { PATH: "/bin", MY_OPERATOR_VAR: "x" };
|
|
12
|
+
for (const k of RUNTIME_ONLY_ENV_VARS) env[k] = "secret";
|
|
13
|
+
for (const k of CHILD_ALLOWED_SECRET_ENV_VARS) env[k] = "ok";
|
|
14
|
+
const child = buildChildEnv(env);
|
|
15
|
+
for (const k of RUNTIME_ONLY_ENV_VARS) expect(k in child).toBe(false);
|
|
16
|
+
for (const k of CHILD_ALLOWED_SECRET_ENV_VARS) expect(child[k]).toBe("ok");
|
|
17
|
+
expect(child.PATH).toBe("/bin");
|
|
18
|
+
expect(child.MY_OPERATOR_VAR).toBe("x");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("RUNTIME_ONLY_ENV_VARS is exactly the runtime-consumed set", () => {
|
|
22
|
+
expect([...(RUNTIME_ONLY_ENV_VARS as readonly string[])].sort()).toEqual(
|
|
23
|
+
[
|
|
24
|
+
"GH_APP_PRIVATE_KEY",
|
|
25
|
+
"GH_APP_CLIENT_SECRET",
|
|
26
|
+
"SLACK_APP_TOKEN",
|
|
27
|
+
"SLACK_SIGNING_SECRET",
|
|
28
|
+
"SLACK_CLIENT_SECRET",
|
|
29
|
+
"SENTRY_DSN",
|
|
30
|
+
"GROQ_API_KEY",
|
|
31
|
+
"ELEVENLABS_API_KEY",
|
|
32
|
+
].sort(),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("service-side secrets pass through when an operator set them on the agent", () => {
|
|
37
|
+
const names = [
|
|
38
|
+
"SLACK_ADMIN_TOKEN",
|
|
39
|
+
"SHIPWRIGHT_ADMIN_API_KEYS",
|
|
40
|
+
"SHIPWRIGHT_ENCRYPTION_KEY",
|
|
41
|
+
"SHIPWRIGHT_SESSION_SECRET",
|
|
42
|
+
"SHIPWRIGHT_ADMIN_VAPID_PRIVATE_KEY",
|
|
43
|
+
"SHIPWRIGHT_ADMIN_PUSH_WEBHOOK_TOKEN",
|
|
44
|
+
"SHIPWRIGHT_CHAT_PUSH_WEBHOOK_TOKEN",
|
|
45
|
+
"SHIPWRIGHT_TASK_STORE_ADMIN_TOKEN",
|
|
46
|
+
"SHIPWRIGHT_CHAT_SERVICE_ADMIN_TOKEN",
|
|
47
|
+
"GOOGLE_CLIENT_SECRET",
|
|
48
|
+
];
|
|
49
|
+
const env = Object.fromEntries(names.map((n) => [n, "v"]));
|
|
50
|
+
const child = buildChildEnv(env);
|
|
51
|
+
for (const n of names) expect(child[n]).toBe("v");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("drops SENTRY_DSN, which is runtime-only but not a secret-shaped var", () => {
|
|
55
|
+
const child = buildChildEnv({ SENTRY_DSN: "https://x@sentry.invalid/1" });
|
|
56
|
+
expect("SENTRY_DSN" in child).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("extra is applied last and wins, even over a runtime-only key", () => {
|
|
60
|
+
const child = buildChildEnv(
|
|
61
|
+
{ A: "1", GH_APP_PRIVATE_KEY: "k" },
|
|
62
|
+
{ A: "2", GH_APP_PRIVATE_KEY: "override" },
|
|
63
|
+
);
|
|
64
|
+
expect(child.A).toBe("2");
|
|
65
|
+
expect(child.GH_APP_PRIVATE_KEY).toBe("override");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("does not mutate the input env", () => {
|
|
69
|
+
const env = { SLACK_SIGNING_SECRET: "s" };
|
|
70
|
+
buildChildEnv(env);
|
|
71
|
+
expect(env.SLACK_SIGNING_SECRET).toBe("s");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("secret classification", () => {
|
|
76
|
+
const runtimeOnly: readonly string[] = RUNTIME_ONLY_ENV_VARS;
|
|
77
|
+
const childAllowed: readonly string[] = CHILD_ALLOWED_SECRET_ENV_VARS;
|
|
78
|
+
|
|
79
|
+
test.each([...SECRET_ENV_VARS])("%s is in exactly one list", (name) => {
|
|
80
|
+
const count =
|
|
81
|
+
Number(runtimeOnly.includes(name)) + Number(childAllowed.includes(name));
|
|
82
|
+
expect(count).toBe(1);
|
|
83
|
+
});
|
|
84
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-lib",
|
|
3
|
-
"version": "1.115.
|
|
3
|
+
"version": "1.115.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
"./admin-types": "./admin-types.ts",
|
|
16
16
|
"./chat-notify": "./chat-notify.ts",
|
|
17
|
+
"./child-env": "./child-env.ts",
|
|
17
18
|
"./claude-timeout": "./claude-timeout.ts",
|
|
18
19
|
"./cli-flags": "./cli-flags.ts",
|
|
19
20
|
"./clone-plan": "./clone-plan.ts",
|
package/secret-env-vars.ts
CHANGED
|
@@ -38,4 +38,7 @@ export const SECRET_ENV_VARS = [
|
|
|
38
38
|
// var name (chat-side vs. admin-side).
|
|
39
39
|
"SHIPWRIGHT_CHAT_PUSH_WEBHOOK_TOKEN",
|
|
40
40
|
"GOOGLE_CLIENT_SECRET",
|
|
41
|
+
// Voice provider keys, written onto the agent pod when voice is configured.
|
|
42
|
+
"GROQ_API_KEY",
|
|
43
|
+
"ELEVENLABS_API_KEY",
|
|
41
44
|
] as const;
|
|
@@ -31,6 +31,8 @@ describe("SECRET_ENV_VARS", () => {
|
|
|
31
31
|
"SHIPWRIGHT_ADMIN_PUSH_WEBHOOK_TOKEN",
|
|
32
32
|
"SHIPWRIGHT_CHAT_PUSH_WEBHOOK_TOKEN",
|
|
33
33
|
"GOOGLE_CLIENT_SECRET",
|
|
34
|
+
"GROQ_API_KEY",
|
|
35
|
+
"ELEVENLABS_API_KEY",
|
|
34
36
|
];
|
|
35
37
|
|
|
36
38
|
for (const entry of expectedEntries) {
|
|
@@ -39,7 +41,7 @@ describe("SECRET_ENV_VARS", () => {
|
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
test("has exactly the expected number of entries (catches accidental additions/removals)", () => {
|
|
42
|
-
expect(SECRET_ENV_VARS.length).toBe(
|
|
44
|
+
expect(SECRET_ENV_VARS.length).toBe(24);
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
test("every entry is a non-empty string", () => {
|