@app-vitals/agent-lib 1.117.0 → 1.119.0

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 CHANGED
@@ -42,8 +42,6 @@ export const CHILD_ALLOWED_SECRET_ENV_VARS = [
42
42
  "GH_TOKEN",
43
43
  "SLACK_BOT_TOKEN",
44
44
  "SHIPWRIGHT_AGENT_API_KEY",
45
- // Tools-kind token for the model's process; passes through for now.
46
- "SHIPWRIGHT_AGENT_TOOLS_API_KEY",
47
45
  "SHIPWRIGHT_TASK_STORE_TOKEN",
48
46
  "SHIPWRIGHT_CHAT_SERVICE_TOKEN",
49
47
  // The shipped shipwright task-store skill still mints scoped tokens with
@@ -62,8 +60,33 @@ export const CHILD_ALLOWED_SECRET_ENV_VARS = [
62
60
  ] as const satisfies readonly SecretEnvVar[];
63
61
 
64
62
  /**
65
- * Copy `env`, drop every runtime-only key, then layer `extra` last so a
66
- * per-run override still wins.
63
+ * Secrets the child receives under a different name. The tools-kind token is
64
+ * handed to the child as SHIPWRIGHT_AGENT_API_KEY (the name skills read), and
65
+ * the tools variable itself is not passed on. The runtime keeps the pod's own
66
+ * SHIPWRIGHT_AGENT_API_KEY for its admin calls.
67
+ */
68
+ export const MAPPED_ENV_VARS = [
69
+ "SHIPWRIGHT_AGENT_TOOLS_API_KEY",
70
+ ] as const satisfies readonly SecretEnvVar[];
71
+
72
+ const TOOLS_KEY = "SHIPWRIGHT_AGENT_TOOLS_API_KEY";
73
+ const AGENT_KEY = "SHIPWRIGHT_AGENT_API_KEY";
74
+
75
+ let warnedMissingToolsKey = false;
76
+
77
+ /** Test hook: re-arm the once-per-process fallback warning. */
78
+ export function resetChildEnvWarning(): void {
79
+ warnedMissingToolsKey = false;
80
+ }
81
+
82
+ /**
83
+ * Copy `env`, drop every runtime-only key, map the tools token onto
84
+ * SHIPWRIGHT_AGENT_API_KEY, then layer `extra` last so a per-run override
85
+ * still wins.
86
+ *
87
+ * Phase A fallback: with no tools token the child keeps the old key and one
88
+ * warning is logged per process, so a runtime deployed before admin's backfill
89
+ * keeps working.
67
90
  */
68
91
  export function buildChildEnv(
69
92
  env: Record<string, string | undefined>,
@@ -71,5 +94,15 @@ export function buildChildEnv(
71
94
  ): Record<string, string | undefined> {
72
95
  const child: Record<string, string | undefined> = { ...env };
73
96
  for (const key of RUNTIME_ONLY_ENV_VARS) delete child[key];
97
+ const toolsKey = child[TOOLS_KEY];
98
+ delete child[TOOLS_KEY];
99
+ if (toolsKey) {
100
+ child[AGENT_KEY] = toolsKey;
101
+ } else if (!warnedMissingToolsKey) {
102
+ warnedMissingToolsKey = true;
103
+ console.warn(
104
+ `[child-env] ${TOOLS_KEY} is not set; the child keeps ${AGENT_KEY} (fallback)`,
105
+ );
106
+ }
74
107
  return { ...child, ...extra };
75
108
  }
@@ -1,8 +1,10 @@
1
- import { describe, expect, test } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
2
2
  import {
3
3
  buildChildEnv,
4
4
  CHILD_ALLOWED_SECRET_ENV_VARS,
5
+ MAPPED_ENV_VARS,
5
6
  RUNTIME_ONLY_ENV_VARS,
7
+ resetChildEnvWarning,
6
8
  } from "./child-env.ts";
7
9
  import { SECRET_ENV_VARS } from "./secret-env-vars.ts";
8
10
 
@@ -75,10 +77,59 @@ describe("buildChildEnv", () => {
75
77
  describe("secret classification", () => {
76
78
  const runtimeOnly: readonly string[] = RUNTIME_ONLY_ENV_VARS;
77
79
  const childAllowed: readonly string[] = CHILD_ALLOWED_SECRET_ENV_VARS;
80
+ const mapped: readonly string[] = MAPPED_ENV_VARS;
78
81
 
79
82
  test.each([...SECRET_ENV_VARS])("%s is in exactly one list", (name) => {
80
83
  const count =
81
- Number(runtimeOnly.includes(name)) + Number(childAllowed.includes(name));
84
+ Number(runtimeOnly.includes(name)) +
85
+ Number(childAllowed.includes(name)) +
86
+ Number(mapped.includes(name));
82
87
  expect(count).toBe(1);
83
88
  });
84
89
  });
90
+
91
+ describe("buildChildEnv tools-token mapping", () => {
92
+ let warn: ReturnType<typeof spyOn>;
93
+ beforeEach(() => {
94
+ resetChildEnvWarning();
95
+ warn = spyOn(console, "warn").mockImplementation(() => {});
96
+ });
97
+ afterEach(() => warn.mockRestore());
98
+
99
+ test("MAPPED_ENV_VARS is the tools key and is not also pass-through", () => {
100
+ expect([...MAPPED_ENV_VARS]).toEqual(["SHIPWRIGHT_AGENT_TOOLS_API_KEY"]);
101
+ for (const k of MAPPED_ENV_VARS)
102
+ expect(
103
+ (CHILD_ALLOWED_SECRET_ENV_VARS as readonly string[]).includes(k),
104
+ ).toBe(false);
105
+ });
106
+
107
+ test("with the tools key set, the child gets it as the agent key and not under its own name", () => {
108
+ const env = {
109
+ SHIPWRIGHT_AGENT_API_KEY: "pod-key",
110
+ SHIPWRIGHT_AGENT_TOOLS_API_KEY: "tools-key",
111
+ };
112
+ const child = buildChildEnv(env);
113
+ expect(child.SHIPWRIGHT_AGENT_API_KEY).toBe("tools-key");
114
+ expect("SHIPWRIGHT_AGENT_TOOLS_API_KEY" in child).toBe(false);
115
+ expect(env.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
116
+ expect(env.SHIPWRIGHT_AGENT_TOOLS_API_KEY).toBe("tools-key");
117
+ expect(warn).not.toHaveBeenCalled();
118
+ });
119
+
120
+ test("without the tools key, the child keeps the old key and warns once per process", () => {
121
+ const env = { SHIPWRIGHT_AGENT_API_KEY: "pod-key" };
122
+ expect(buildChildEnv(env).SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
123
+ expect(buildChildEnv(env).SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
124
+ expect(warn).toHaveBeenCalledTimes(1);
125
+ });
126
+
127
+ test("an empty tools key counts as absent", () => {
128
+ const child = buildChildEnv({
129
+ SHIPWRIGHT_AGENT_API_KEY: "pod-key",
130
+ SHIPWRIGHT_AGENT_TOOLS_API_KEY: "",
131
+ });
132
+ expect(child.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
133
+ expect("SHIPWRIGHT_AGENT_TOOLS_API_KEY" in child).toBe(false);
134
+ });
135
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-lib",
3
- "version": "1.117.0",
3
+ "version": "1.119.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",