@app-vitals/agent-lib 1.114.1 → 1.115.1

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 ADDED
@@ -0,0 +1,59 @@
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
+ /** Secrets only the runtime (or the services it talks to) consumes. Never passed to a child. */
16
+ export const RUNTIME_ONLY_ENV_VARS = [
17
+ "GH_APP_PRIVATE_KEY",
18
+ "GH_APP_CLIENT_SECRET",
19
+ "SLACK_SIGNING_SECRET",
20
+ "SLACK_APP_TOKEN",
21
+ "SLACK_CLIENT_SECRET",
22
+ "SLACK_ADMIN_TOKEN",
23
+ "SHIPWRIGHT_ADMIN_API_KEYS",
24
+ "SHIPWRIGHT_ENCRYPTION_KEY",
25
+ "SHIPWRIGHT_SESSION_SECRET",
26
+ "SHIPWRIGHT_ADMIN_VAPID_PRIVATE_KEY",
27
+ "SHIPWRIGHT_ADMIN_PUSH_WEBHOOK_TOKEN",
28
+ "SHIPWRIGHT_CHAT_PUSH_WEBHOOK_TOKEN",
29
+ "SHIPWRIGHT_CHAT_SERVICE_ADMIN_TOKEN",
30
+ "GOOGLE_CLIENT_SECRET",
31
+ ] as const satisfies readonly SecretEnvVar[];
32
+
33
+ /** Secrets the child legitimately uses (skills, the claude CLI itself). Kept in the child env. */
34
+ export const CHILD_ALLOWED_SECRET_ENV_VARS = [
35
+ "ANTHROPIC_API_KEY",
36
+ "CLAUDE_CODE_OAUTH_TOKEN",
37
+ "GH_TOKEN",
38
+ "SLACK_BOT_TOKEN",
39
+ "SHIPWRIGHT_AGENT_API_KEY",
40
+ "SHIPWRIGHT_TASK_STORE_TOKEN",
41
+ "SHIPWRIGHT_CHAT_SERVICE_TOKEN",
42
+ // The shipped shipwright task-store skill still mints scoped tokens with
43
+ // this admin token. Move it back to RUNTIME_ONLY_ENV_VARS once that skill
44
+ // stops using it (follow-up).
45
+ "SHIPWRIGHT_TASK_STORE_ADMIN_TOKEN",
46
+ ] as const satisfies readonly SecretEnvVar[];
47
+
48
+ /**
49
+ * Copy `env`, drop every runtime-only key, then layer `extra` last so a
50
+ * per-run override still wins.
51
+ */
52
+ export function buildChildEnv(
53
+ env: Record<string, string | undefined>,
54
+ extra?: Record<string, string>,
55
+ ): Record<string, string | undefined> {
56
+ const child: Record<string, string | undefined> = { ...env };
57
+ for (const key of RUNTIME_ONLY_ENV_VARS) delete child[key];
58
+ return { ...child, ...extra };
59
+ }
@@ -0,0 +1,51 @@
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("keeps SHIPWRIGHT_TASK_STORE_ADMIN_TOKEN for the task-store skill", () => {
22
+ const child = buildChildEnv({ SHIPWRIGHT_TASK_STORE_ADMIN_TOKEN: "admin" });
23
+ expect(child.SHIPWRIGHT_TASK_STORE_ADMIN_TOKEN).toBe("admin");
24
+ });
25
+
26
+ test("extra is applied last and wins, even over a runtime-only key", () => {
27
+ const child = buildChildEnv(
28
+ { A: "1", GH_APP_PRIVATE_KEY: "k" },
29
+ { A: "2", GH_APP_PRIVATE_KEY: "override" },
30
+ );
31
+ expect(child.A).toBe("2");
32
+ expect(child.GH_APP_PRIVATE_KEY).toBe("override");
33
+ });
34
+
35
+ test("does not mutate the input env", () => {
36
+ const env = { SLACK_SIGNING_SECRET: "s" };
37
+ buildChildEnv(env);
38
+ expect(env.SLACK_SIGNING_SECRET).toBe("s");
39
+ });
40
+ });
41
+
42
+ describe("secret classification", () => {
43
+ const runtimeOnly: readonly string[] = RUNTIME_ONLY_ENV_VARS;
44
+ const childAllowed: readonly string[] = CHILD_ALLOWED_SECRET_ENV_VARS;
45
+
46
+ test.each([...SECRET_ENV_VARS])("%s is in exactly one list", (name) => {
47
+ const count =
48
+ Number(runtimeOnly.includes(name)) + Number(childAllowed.includes(name));
49
+ expect(count).toBe(1);
50
+ });
51
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-lib",
3
- "version": "1.114.1",
3
+ "version": "1.115.1",
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",