@agent-assembly/sdk 0.0.1-beta.2 → 0.0.1-beta.4

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.
Files changed (56) hide show
  1. package/dist/cjs/core/gateway-resolver.js +124 -9
  2. package/dist/cjs/core/init-assembly.js +165 -34
  3. package/dist/cjs/gateway/client.js +64 -1
  4. package/dist/cjs/gateway/index.js +2 -1
  5. package/dist/cjs/hooks/ai-sdk.js +3 -5
  6. package/dist/cjs/hooks/langchain.js +12 -3
  7. package/dist/cjs/hooks/mastra.js +10 -6
  8. package/dist/cjs/hooks/openai-agents.js +1 -3
  9. package/dist/cjs/native/client.js +70 -25
  10. package/dist/cjs/op-control.js +55 -1
  11. package/dist/cjs/runtime.js +73 -7
  12. package/dist/esm/core/gateway-resolver.js +123 -9
  13. package/dist/esm/core/gateway-resolver.js.map +1 -1
  14. package/dist/esm/core/init-assembly.js +163 -33
  15. package/dist/esm/core/init-assembly.js.map +1 -1
  16. package/dist/esm/gateway/client.js +63 -1
  17. package/dist/esm/gateway/client.js.map +1 -1
  18. package/dist/esm/gateway/index.js +1 -1
  19. package/dist/esm/gateway/index.js.map +1 -1
  20. package/dist/esm/hooks/ai-sdk.js +3 -5
  21. package/dist/esm/hooks/ai-sdk.js.map +1 -1
  22. package/dist/esm/hooks/langchain.js +12 -3
  23. package/dist/esm/hooks/langchain.js.map +1 -1
  24. package/dist/esm/hooks/mastra.js +10 -6
  25. package/dist/esm/hooks/mastra.js.map +1 -1
  26. package/dist/esm/hooks/openai-agents.js +1 -3
  27. package/dist/esm/hooks/openai-agents.js.map +1 -1
  28. package/dist/esm/native/client.js +68 -24
  29. package/dist/esm/native/client.js.map +1 -1
  30. package/dist/esm/op-control.js +53 -1
  31. package/dist/esm/op-control.js.map +1 -1
  32. package/dist/esm/runtime.js +72 -7
  33. package/dist/esm/runtime.js.map +1 -1
  34. package/dist/types/core/gateway-resolver.d.ts +33 -4
  35. package/dist/types/core/gateway-resolver.d.ts.map +1 -1
  36. package/dist/types/core/init-assembly.d.ts +6 -1
  37. package/dist/types/core/init-assembly.d.ts.map +1 -1
  38. package/dist/types/gateway/client.d.ts +24 -1
  39. package/dist/types/gateway/client.d.ts.map +1 -1
  40. package/dist/types/gateway/index.d.ts +1 -1
  41. package/dist/types/gateway/index.d.ts.map +1 -1
  42. package/dist/types/hooks/ai-sdk.d.ts.map +1 -1
  43. package/dist/types/hooks/langchain.d.ts +11 -0
  44. package/dist/types/hooks/langchain.d.ts.map +1 -1
  45. package/dist/types/hooks/mastra.d.ts.map +1 -1
  46. package/dist/types/hooks/openai-agents.d.ts.map +1 -1
  47. package/dist/types/native/client.d.ts +33 -0
  48. package/dist/types/native/client.d.ts.map +1 -1
  49. package/dist/types/op-control.d.ts +29 -2
  50. package/dist/types/op-control.d.ts.map +1 -1
  51. package/dist/types/runtime.d.ts +27 -5
  52. package/dist/types/runtime.d.ts.map +1 -1
  53. package/dist/types/types/assembly-config.d.ts +14 -0
  54. package/dist/types/types/assembly-config.d.ts.map +1 -1
  55. package/native/aa-ffi-node/index.d.ts +74 -0
  56. package/package.json +7 -7
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NativeDisconnectError = exports.NativeQueryPolicyError = exports.NativeSendEventError = exports.NativeConnectError = void 0;
6
+ exports.NativeDisconnectError = exports.NativeRegisterError = exports.NativeQueryPolicyError = exports.NativeSendEventError = exports.NativeConnectError = void 0;
7
7
  exports.createNativeClient = createNativeClient;
8
8
  const node_module_1 = require("node:module");
9
9
  const node_path_1 = __importDefault(require("node:path"));
@@ -11,6 +11,7 @@ const NATIVE_BINDING_SINGLETON_KEY = Symbol.for("@agent-assembly/sdk/native-bind
11
11
  const ERROR_CONNECT = "AA_ERR_CONNECT";
12
12
  const ERROR_SEND_EVENT = "AA_ERR_SEND_EVENT";
13
13
  const ERROR_QUERY_POLICY = "AA_ERR_QUERY_POLICY";
14
+ const ERROR_REGISTER = "AA_ERR_REGISTER";
14
15
  const ERROR_DISCONNECT = "AA_ERR_DISCONNECT";
15
16
  class NativeConnectError extends Error {
16
17
  code = ERROR_CONNECT;
@@ -24,10 +25,33 @@ class NativeQueryPolicyError extends Error {
24
25
  code = ERROR_QUERY_POLICY;
25
26
  }
26
27
  exports.NativeQueryPolicyError = NativeQueryPolicyError;
28
+ class NativeRegisterError extends Error {
29
+ code = ERROR_REGISTER;
30
+ }
31
+ exports.NativeRegisterError = NativeRegisterError;
27
32
  class NativeDisconnectError extends Error {
28
33
  code = ERROR_DISCONNECT;
29
34
  }
30
35
  exports.NativeDisconnectError = NativeDisconnectError;
36
+ /**
37
+ * Translate the native `{decision, reason}` verdict into the SDK's
38
+ * `PolicyResult`. Only `"deny"` blocks; `"pending"` routes to the approval
39
+ * path; `"allow"` / `"redact"` / any unrecognized value proceed. This mirrors
40
+ * the shared enforcement contract across the Python / Go / Node SDKs.
41
+ *
42
+ * The native primitive already fails open (returns `"allow"`) when the runtime
43
+ * is unreachable or too slow, so a missing or degraded runtime never blocks.
44
+ */
45
+ function mapDecisionToPolicyResult(verdict) {
46
+ switch (verdict.decision) {
47
+ case "deny":
48
+ return { denied: true, pending: false, reason: verdict.reason };
49
+ case "pending":
50
+ return { denied: false, pending: true, reason: verdict.reason };
51
+ default:
52
+ return { denied: false, pending: false };
53
+ }
54
+ }
31
55
  function mapNativeError(error) {
32
56
  if (!(error instanceof Error)) {
33
57
  return new Error(String(error));
@@ -43,6 +67,9 @@ function mapNativeError(error) {
43
67
  if (code === ERROR_QUERY_POLICY) {
44
68
  return new NativeQueryPolicyError(detail);
45
69
  }
70
+ if (code === ERROR_REGISTER) {
71
+ return new NativeRegisterError(detail);
72
+ }
46
73
  if (code === ERROR_DISCONNECT) {
47
74
  return new NativeDisconnectError(detail);
48
75
  }
@@ -51,9 +78,7 @@ function mapNativeError(error) {
51
78
  function loadNativeBinding() {
52
79
  const shouldUseCache = process.env.VITEST !== "true";
53
80
  const globalObject = globalThis;
54
- const cachedBinding = shouldUseCache
55
- ? globalObject[NATIVE_BINDING_SINGLETON_KEY]
56
- : undefined;
81
+ const cachedBinding = shouldUseCache ? globalObject[NATIVE_BINDING_SINGLETON_KEY] : undefined;
57
82
  if (cachedBinding) {
58
83
  return cachedBinding;
59
84
  }
@@ -85,7 +110,11 @@ function createNativeClient(options) {
85
110
  mode,
86
111
  close: async () => undefined,
87
112
  sendEvent: () => undefined,
88
- queryPolicy: async () => ({ denied: false, pending: false })
113
+ queryPolicy: async () => ({ denied: false, pending: false }),
114
+ // No native session to register against off the in-process path; the
115
+ // gRPC sidecar registers the agent in its own process. Resolve neutrally
116
+ // so init never blocks on a transport that does not own a handle.
117
+ register: async () => ""
89
118
  };
90
119
  }
91
120
  const binding = loadNativeBinding();
@@ -94,19 +123,17 @@ function createNativeClient(options) {
94
123
  let activeHandle;
95
124
  let pendingSendError;
96
125
  const getHandle = async () => {
97
- if (!handlePromise) {
98
- handlePromise = binding
99
- .connect(socketPath)
100
- .then((handle) => {
101
- activeHandle = handle;
102
- return handle;
103
- })
104
- .catch((error) => {
105
- handlePromise = undefined;
106
- activeHandle = undefined;
107
- throw mapNativeError(error);
108
- });
109
- }
126
+ handlePromise ??= binding
127
+ .connect(socketPath)
128
+ .then((handle) => {
129
+ activeHandle = handle;
130
+ return handle;
131
+ })
132
+ .catch((error) => {
133
+ handlePromise = undefined;
134
+ activeHandle = undefined;
135
+ throw mapNativeError(error);
136
+ });
110
137
  return handlePromise;
111
138
  };
112
139
  return {
@@ -145,18 +172,36 @@ function createNativeClient(options) {
145
172
  pendingSendError = mapNativeError(error);
146
173
  });
147
174
  },
148
- queryPolicy: async () => {
175
+ queryPolicy: async (action) => {
149
176
  if (pendingSendError) {
150
177
  const error = pendingSendError;
151
178
  pendingSendError = undefined;
152
179
  throw error;
153
180
  }
154
- // The SDK is not a policy authority. Ensure the session is connected
155
- // (surfacing any connect error), then defer: authoritative policy and
156
- // approval are enforced server-side (gateway / runtime). The native shim
157
- // no longer synthesizes a decision, so this always resolves neutral.
158
- await getHandle();
159
- return { denied: false, pending: false };
181
+ // Connect (surfacing any connect error as a genuine local fault), then
182
+ // ask the runtime for an authoritative verdict via the native primitive.
183
+ // The native `queryPolicy` is async it offloads its blocking wait to a
184
+ // worker thread, so awaiting it never blocks the Node event loop — and it
185
+ // already fails open (returns `"allow"`) when the runtime is unreachable
186
+ // or too slow, so a missing or degraded runtime never blocks the agent.
187
+ const handle = await getHandle();
188
+ const verdict = await binding.queryPolicy(handle, action);
189
+ return mapDecisionToPolicyResult(verdict);
190
+ },
191
+ register: async (options) => {
192
+ // Register on the same session the queryPolicy path uses, so the token
193
+ // the gateway issues is stored on this handle and attached to every
194
+ // subsequent query. This is the only direct SDK→gateway gRPC call
195
+ // (ADR 0004); CheckAction still flows through aa-runtime.
196
+ if (binding.register === undefined) {
197
+ // A binding without `register` predates AAASM-3400; the agent simply
198
+ // runs unregistered rather than failing init.
199
+ return "";
200
+ }
201
+ const handle = await getHandle();
202
+ return binding.register(handle, options).catch((error) => {
203
+ throw mapNativeError(error);
204
+ });
160
205
  }
161
206
  };
162
207
  }
@@ -22,9 +22,63 @@
22
22
  */
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.OpControlSubscriber = void 0;
25
+ exports.gatewayHostOf = gatewayHostOf;
26
+ exports.resolveOpControlCredentials = resolveOpControlCredentials;
25
27
  const grpc_js_1 = require("@grpc/grpc-js");
26
28
  const op_terminated_error_js_1 = require("./errors/op-terminated-error.js");
27
29
  const policy_js_1 = require("./proto/generated/policy.js");
30
+ /**
31
+ * Hosts treated as loopback for the secure-by-default transport decision.
32
+ * A loopback gateway is the local dev-mode CP, where plaintext gRPC is the
33
+ * documented default; anything else is presumed remote and must be encrypted.
34
+ */
35
+ const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
36
+ /**
37
+ * Extract the bare host from a gRPC target (`host:port`, a bare host, or a
38
+ * URL-style `scheme://host:port`). Returns the lowercased host with any
39
+ * surrounding IPv6 brackets preserved so it can be matched against
40
+ * {@link LOOPBACK_HOSTS}.
41
+ */
42
+ function gatewayHostOf(gatewayUrl) {
43
+ let target = gatewayUrl.trim();
44
+ const schemeIdx = target.indexOf("://");
45
+ if (schemeIdx !== -1)
46
+ target = target.slice(schemeIdx + 3);
47
+ // Drop a path/query suffix if a URL form was passed.
48
+ const slashIdx = target.indexOf("/");
49
+ if (slashIdx !== -1)
50
+ target = target.slice(0, slashIdx);
51
+ if (target.startsWith("[")) {
52
+ // Bracketed IPv6: keep the bracketed form, strip only the trailing :port.
53
+ const close = target.indexOf("]");
54
+ return close === -1 ? target.toLowerCase() : target.slice(0, close + 1).toLowerCase();
55
+ }
56
+ const colonIdx = target.indexOf(":");
57
+ if (colonIdx !== -1)
58
+ target = target.slice(0, colonIdx);
59
+ return target.toLowerCase();
60
+ }
61
+ function isLoopbackTarget(gatewayUrl) {
62
+ return LOOPBACK_HOSTS.has(gatewayHostOf(gatewayUrl));
63
+ }
64
+ /**
65
+ * Pick channel credentials for the op-control stream, secure by default.
66
+ *
67
+ * Precedence: an explicit `credentials` override wins; otherwise a loopback
68
+ * target gets plaintext (local dev gateway), a remote target gets TLS, and a
69
+ * remote target is only allowed plaintext when the caller sets `allowInsecure`.
70
+ *
71
+ * @throws never — returns the chosen {@link ChannelCredentials}.
72
+ */
73
+ function resolveOpControlCredentials(gatewayUrl, opts) {
74
+ if (opts.credentials)
75
+ return opts.credentials;
76
+ if (isLoopbackTarget(gatewayUrl))
77
+ return grpc_js_1.credentials.createInsecure();
78
+ if (opts.allowInsecure)
79
+ return grpc_js_1.credentials.createInsecure();
80
+ return grpc_js_1.credentials.createSsl();
81
+ }
28
82
  class OpControlSubscriber {
29
83
  client;
30
84
  agent;
@@ -44,7 +98,7 @@ class OpControlSubscriber {
44
98
  };
45
99
  const client = opts.clientFactory
46
100
  ? opts.clientFactory()
47
- : new policy_js_1.PolicyServiceClient(gatewayUrl, opts.credentials ?? grpc_js_1.credentials.createInsecure());
101
+ : new policy_js_1.PolicyServiceClient(gatewayUrl, resolveOpControlCredentials(gatewayUrl, opts));
48
102
  const subscriber = new OpControlSubscriber(client, agent);
49
103
  subscriber.start();
50
104
  return subscriber;
@@ -9,9 +9,10 @@
9
9
  * flow with `import { initAssembly } from "@agent-assembly/sdk/runtime"`.
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.INSTALL_HINT = exports.RUNTIME_SUBPACKAGE = exports.RUNTIME_LOG_FILENAME = exports.DOCKER_BASE_BIN = exports.USER_LOCAL_BIN = exports.DEFAULT_RUNTIME_HOST = exports.DEFAULT_PORT = exports.BINARY_NAME = void 0;
12
+ exports.INSTALL_HINT = exports.RUNTIME_SUBPACKAGE = exports.RUNTIME_LOG_FILENAME = exports.DOCKER_BASE_BIN = exports.USER_LOCAL_BIN = exports.ENV_AUTO_START = exports.DEFAULT_RUNTIME_HOST = exports.DEFAULT_PORT = exports.BINARY_NAME = void 0;
13
13
  exports.findAasmBinary = findAasmBinary;
14
14
  exports.isRunning = isRunning;
15
+ exports.assertSafeBinaryPath = assertSafeBinaryPath;
15
16
  exports.startRuntime = startRuntime;
16
17
  exports.initAssembly = initAssembly;
17
18
  const node_child_process_1 = require("node:child_process");
@@ -24,6 +25,13 @@ const node_process_1 = require("node:process");
24
25
  exports.BINARY_NAME = "aasm";
25
26
  exports.DEFAULT_PORT = 7878;
26
27
  exports.DEFAULT_RUNTIME_HOST = "127.0.0.1";
28
+ /**
29
+ * Opt-in gate for spawning the `aasm` sidecar. Auto-start runs a binary
30
+ * discovered from `$PATH` / the filesystem, so it is a privileged side effect
31
+ * that must be explicitly enabled rather than triggered silently by every
32
+ * `initAssembly()` call. Set to `1`/`true`/`yes` to permit auto-start.
33
+ */
34
+ exports.ENV_AUTO_START = "AA_AUTO_START";
27
35
  exports.USER_LOCAL_BIN = (0, node_path_1.join)((0, node_os_1.homedir)(), ".local", "bin");
28
36
  exports.DOCKER_BASE_BIN = "/usr/local/bin";
29
37
  exports.RUNTIME_LOG_FILENAME = ".aasm-runtime.log";
@@ -100,6 +108,51 @@ function isRunning(port = exports.DEFAULT_PORT, host = exports.DEFAULT_RUNTIME_H
100
108
  socket.once("error", () => settle(false));
101
109
  });
102
110
  }
111
+ /** Truthy values that enable {@link ENV_AUTO_START}. */
112
+ function autoStartEnabled() {
113
+ const raw = node_process_1.env[exports.ENV_AUTO_START]?.trim().toLowerCase();
114
+ return raw === "1" || raw === "true" || raw === "yes";
115
+ }
116
+ /**
117
+ * Install roots an auto-started `aasm` binary is permitted to live in, in
118
+ * addition to the npm-bundled `node_modules/@agent-assembly/runtime-*` path
119
+ * (which is trusted because it ships with the SDK install). This blocks a
120
+ * `$PATH`-injected `./aasm` or a binary planted in an arbitrary writable
121
+ * directory from being spawned.
122
+ */
123
+ function allowedInstallDirs() {
124
+ const home = (0, node_os_1.homedir)();
125
+ return [
126
+ "/usr/local/bin",
127
+ "/usr/bin",
128
+ "/opt/homebrew/bin",
129
+ exports.USER_LOCAL_BIN,
130
+ (0, node_path_1.join)(home, ".cargo", "bin"),
131
+ "/usr/local/cargo/bin",
132
+ exports.DOCKER_BASE_BIN,
133
+ ];
134
+ }
135
+ /**
136
+ * Throw `Error` unless `binaryPath` is safe to spawn: it must be absolute and
137
+ * either resolve inside an allow-listed install dir (see
138
+ * {@link allowedInstallDirs}) or be the npm-bundled runtime binary. This is the
139
+ * integrity gate for the auto-start subprocess — without it the SDK would
140
+ * execute whatever `aasm` happened to be first on `$PATH`.
141
+ */
142
+ function assertSafeBinaryPath(binaryPath) {
143
+ if (!(0, node_path_1.isAbsolute)(binaryPath)) {
144
+ throw new Error(`Refusing to auto-start a non-absolute 'aasm' path: ${binaryPath}`);
145
+ }
146
+ const resolved = (0, node_path_1.resolve)(binaryPath);
147
+ const bundled = bundledRuntimeBinaryPath();
148
+ if (bundled !== null && (0, node_path_1.resolve)(bundled) === resolved)
149
+ return;
150
+ const ok = allowedInstallDirs().some((dir) => resolved.startsWith((0, node_path_1.resolve)(dir) + "/"));
151
+ if (!ok) {
152
+ throw new Error(`Refusing to auto-start 'aasm' from an untrusted location: ${resolved}. ` +
153
+ `Install it under one of: ${allowedInstallDirs().join(", ")}.`);
154
+ }
155
+ }
103
156
  /**
104
157
  * Spawn `aasm serve --port <port>` as a detached background subprocess.
105
158
  *
@@ -126,19 +179,32 @@ function startRuntime(binaryPath, port = exports.DEFAULT_PORT, logDir = (0, node
126
179
  * 2. Resolve the binary via {@link findAasmBinary}.
127
180
  * 3. Spawn the sidecar via {@link startRuntime}.
128
181
  *
129
- * `agentId` is accepted to keep the ticket-specified signature stable;
130
- * actual register-and-connect is performed by the existing gateway-aware
131
- * `@agent-assembly/sdk` `initAssembly` once the sidecar is reachable.
182
+ * `_agentId` is accepted to keep the ticket-specified signature stable but is
183
+ * intentionally not consumed at this lifecycle layer; actual register-and-connect
184
+ * is performed by the existing gateway-aware `@agent-assembly/sdk` `initAssembly`
185
+ * once the sidecar is reachable.
186
+ *
187
+ * Auto-start is **opt-in**: when the sidecar is not already running, this
188
+ * throws unless `AA_AUTO_START` is enabled. When it does spawn, the resolved
189
+ * binary path is logged and integrity-checked via {@link assertSafeBinaryPath}.
132
190
  *
133
- * Throws `Error` with {@link INSTALL_HINT} when no binary is found.
191
+ * Throws `Error` with {@link INSTALL_HINT} when no binary is found, and a
192
+ * descriptive `Error` when auto-start is not opted in or the resolved binary
193
+ * fails the integrity check.
134
194
  */
135
- async function initAssembly(agentId, port = exports.DEFAULT_PORT) {
136
- void agentId; // not consumed at the lifecycle layer; see jsdoc
195
+ async function initAssembly(_agentId, port = exports.DEFAULT_PORT) {
137
196
  if (await isRunning(port))
138
197
  return;
198
+ if (!autoStartEnabled()) {
199
+ throw new Error(`No aasm sidecar running on port ${port} and auto-start is disabled. ` +
200
+ `Start it with 'aasm serve --port ${port}', or set ${exports.ENV_AUTO_START}=1 ` +
201
+ "to allow the SDK to auto-start it.");
202
+ }
139
203
  const binary = findAasmBinary();
140
204
  if (binary === null) {
141
205
  throw new Error(exports.INSTALL_HINT);
142
206
  }
207
+ assertSafeBinaryPath(binary);
208
+ console.info(`[agent-assembly] auto-starting aasm sidecar from ${binary}`);
143
209
  startRuntime(binary, port);
144
210
  }
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
- import { join, resolve as resolvePath } from "node:path";
4
+ import { isAbsolute, join, resolve as resolvePath } from "node:path";
5
5
  import { ConfigurationError, GatewayError } from "../errors/index.js";
6
6
  /**
7
7
  * Resolve the gateway URL and API key for ``initAssembly``.
@@ -14,17 +14,109 @@ import { ConfigurationError, GatewayError } from "../errors/index.js";
14
14
  * Resolution precedence (highest first):
15
15
  *
16
16
  * 1. Explicit field on the AssemblyConfig
17
- * 2. Environment variable (AAASM_GATEWAY_URL / AAASM_API_KEY)
17
+ * 2. Environment variable canonical ``AA_GATEWAY_URL`` / ``AA_API_KEY``,
18
+ * with the legacy ``AAASM_GATEWAY_URL`` / ``AAASM_API_KEY`` names accepted
19
+ * as deprecated aliases (a one-time warning is logged when a legacy name
20
+ * supplies the value)
18
21
  * 3. Config file (~/.aasm/config.yaml, optional js-yaml soft dep)
19
- * 4. Local default: probe http://localhost:7391, auto-start if absent
22
+ * 4. Local default: probe http://localhost:7391; when absent, auto-start the
23
+ * local `aasm` gateway ONLY if `AA_AUTO_START` is opted in and the binary
24
+ * resolves to an allow-listed install dir — otherwise raise an error.
20
25
  */
21
26
  export const DEFAULT_GATEWAY_URL = "http://localhost:7391";
22
27
  export const DEFAULT_HEALTHZ_PATH = "/healthz";
23
28
  export const DEFAULT_PROBE_TIMEOUT_MS = 500;
24
29
  export const DEFAULT_AUTO_START_TIMEOUT_MS = 5000;
25
30
  export const DEFAULT_CONFIG_FILE_PATH = "~/.aasm/config.yaml";
26
- export const ENV_GATEWAY_URL = "AAASM_GATEWAY_URL";
27
- export const ENV_API_KEY = "AAASM_API_KEY";
31
+ export const ENV_GATEWAY_URL = "AA_GATEWAY_URL";
32
+ export const ENV_API_KEY = "AA_API_KEY";
33
+ /**
34
+ * Opt-in gate for auto-starting a local gateway. Auto-start spawns the `aasm`
35
+ * binary resolved from `$PATH`, so it is gated behind an explicit opt-in rather
36
+ * than running silently: a `$PATH` entry an attacker can write to would
37
+ * otherwise be executed by any process that calls `initAssembly()`. Set to
38
+ * `1`/`true`/`yes` to permit auto-start.
39
+ */
40
+ export const ENV_AUTO_START = "AA_AUTO_START";
41
+ /** Truthy values that enable {@link ENV_AUTO_START}. */
42
+ function autoStartEnabled() {
43
+ const raw = process.env[ENV_AUTO_START]?.trim().toLowerCase();
44
+ return raw === "1" || raw === "true" || raw === "yes";
45
+ }
46
+ /**
47
+ * Directories an auto-started `aasm` binary is permitted to live in. The
48
+ * resolved path must be absolute and sit inside one of these install roots,
49
+ * which blocks a `$PATH`-injected `./aasm` (cwd) or a binary planted in an
50
+ * arbitrary writable directory from being spawned. Mirrors the documented
51
+ * install locations (Homebrew, system, user-local, cargo).
52
+ */
53
+ function allowedInstallDirs() {
54
+ const home = homedir();
55
+ return [
56
+ "/usr/local/bin",
57
+ "/usr/bin",
58
+ "/opt/homebrew/bin",
59
+ join(home, ".local", "bin"),
60
+ join(home, ".cargo", "bin"),
61
+ "/usr/local/cargo/bin",
62
+ ];
63
+ }
64
+ /**
65
+ * Throw {@link ConfigurationError} unless `aasmPath` is an absolute path inside
66
+ * an allow-listed install directory (see {@link allowedInstallDirs}). This is
67
+ * the integrity gate for the auto-start subprocess — without it the SDK would
68
+ * execute whatever `aasm` happened to be first on `$PATH`.
69
+ */
70
+ export function assertAllowedAasmPath(aasmPath) {
71
+ if (!isAbsolute(aasmPath)) {
72
+ throw new ConfigurationError(`Refusing to auto-start a non-absolute 'aasm' path: ${aasmPath}. ` +
73
+ `Set ${ENV_GATEWAY_URL} to an already-running gateway instead.`);
74
+ }
75
+ const resolved = resolvePath(aasmPath);
76
+ const ok = allowedInstallDirs().some((dir) => resolved.startsWith(dir + "/"));
77
+ if (!ok) {
78
+ throw new ConfigurationError(`Refusing to auto-start 'aasm' from an untrusted location: ${resolved}. ` +
79
+ `Install it under one of: ${allowedInstallDirs().join(", ")}, ` +
80
+ `or set ${ENV_GATEWAY_URL} to an already-running gateway.`);
81
+ }
82
+ }
83
+ /**
84
+ * Deprecated environment-variable names, kept as backwards-compatible aliases.
85
+ *
86
+ * When one of these supplies a value (and the canonical ``AA_*`` name is unset)
87
+ * a one-time deprecation warning is emitted via ``readEnvWithDeprecation``.
88
+ */
89
+ export const LEGACY_ENV_GATEWAY_URL = "AAASM_GATEWAY_URL";
90
+ export const LEGACY_ENV_API_KEY = "AAASM_API_KEY";
91
+ /**
92
+ * Tracks which legacy env-var names have already produced a deprecation
93
+ * warning so the message is logged at most once per name per process.
94
+ */
95
+ const _warnedLegacyEnv = new Set();
96
+ /**
97
+ * Read an environment variable preferring the canonical ``AA_*`` name and
98
+ * falling back to a deprecated ``AAASM_*`` alias.
99
+ *
100
+ * Returns ``undefined`` when neither name is set. When the value comes from
101
+ * the legacy alias, a deprecation warning is logged exactly once per legacy
102
+ * name (guarded by ``_warnedLegacyEnv``) directing the user to the canonical
103
+ * name.
104
+ */
105
+ function readEnvWithDeprecation(canonicalName, legacyName) {
106
+ const canonical = process.env[canonicalName];
107
+ if (canonical)
108
+ return canonical;
109
+ const legacy = process.env[legacyName];
110
+ if (legacy) {
111
+ if (!_warnedLegacyEnv.has(legacyName)) {
112
+ _warnedLegacyEnv.add(legacyName);
113
+ console.warn(`[agent-assembly] ${legacyName} is deprecated and will be removed in a ` +
114
+ `future release. Use ${canonicalName} instead.`);
115
+ }
116
+ return legacy;
117
+ }
118
+ return undefined;
119
+ }
28
120
  export const AASM_AUTO_START_ARGV = ["start", "--mode", "local", "--foreground"];
29
121
  /**
30
122
  * Return true if a gateway responds with a 2xx status at ``{baseUrl}/healthz``.
@@ -72,7 +164,11 @@ export async function waitForHealthz(baseUrl, timeoutMs = DEFAULT_AUTO_START_TIM
72
164
  return probeHealthz(baseUrl);
73
165
  }
74
166
  function expandHome(p) {
75
- return p.startsWith("~") ? resolvePath(homedir(), p.slice(p.startsWith("~/") ? 2 : 1)) : p;
167
+ if (!p.startsWith("~")) {
168
+ return p;
169
+ }
170
+ const prefixLength = p.startsWith("~/") ? 2 : 1;
171
+ return resolvePath(homedir(), p.slice(prefixLength));
76
172
  }
77
173
  /**
78
174
  * Load ``~/.aasm/config.yaml`` if present.
@@ -141,7 +237,12 @@ const _seams = {
141
237
  loadConfigFile: loadConfigFile,
142
238
  autoStartGateway: autoStartGateway,
143
239
  };
144
- export const __testing = { _seams };
240
+ export const __testing = {
241
+ _seams,
242
+ resetLegacyEnvWarnings: () => {
243
+ _warnedLegacyEnv.clear();
244
+ },
245
+ };
145
246
  /**
146
247
  * Spawn ``aasm start --mode local --foreground`` and wait until ``/healthz``
147
248
  * responds.
@@ -159,6 +260,11 @@ export async function autoStartGateway(baseUrl = DEFAULT_GATEWAY_URL, timeoutMs
159
260
  throw new ConfigurationError(`No gateway found at ${baseUrl} and 'aasm' is not on PATH. ` +
160
261
  "Install it with: npm install -g @agent-assembly/cli (or pnpm add -g)");
161
262
  }
263
+ // Integrity gate: only spawn an absolute path from an allow-listed install
264
+ // dir, and surface the resolved path so the operator can see exactly which
265
+ // binary the SDK is about to execute.
266
+ assertAllowedAasmPath(aasmPath);
267
+ console.info(`[agent-assembly] auto-starting gateway from ${aasmPath}`);
162
268
  _seams.spawnAasm(aasmPath);
163
269
  if (!(await waitForHealthz(baseUrl, timeoutMs))) {
164
270
  throw new GatewayError(`Auto-started gateway at ${baseUrl} did not become ready ` +
@@ -176,7 +282,7 @@ export async function autoStartGateway(baseUrl = DEFAULT_GATEWAY_URL, timeoutMs
176
282
  export async function resolveGatewayUrl(explicit) {
177
283
  if (explicit)
178
284
  return explicit;
179
- const fromEnv = process.env[ENV_GATEWAY_URL];
285
+ const fromEnv = readEnvWithDeprecation(ENV_GATEWAY_URL, LEGACY_ENV_GATEWAY_URL);
180
286
  if (fromEnv)
181
287
  return fromEnv;
182
288
  const config = await _seams.loadConfigFile();
@@ -189,6 +295,14 @@ export async function resolveGatewayUrl(explicit) {
189
295
  if (await _seams.probeHealthz(DEFAULT_GATEWAY_URL)) {
190
296
  return DEFAULT_GATEWAY_URL;
191
297
  }
298
+ // Auto-start is opt-in: spawning the local `aasm` binary is a privileged
299
+ // side effect, so a missing gateway is a hard error unless the operator has
300
+ // explicitly enabled AA_AUTO_START.
301
+ if (!autoStartEnabled()) {
302
+ throw new ConfigurationError(`No gateway found at ${DEFAULT_GATEWAY_URL}. Start one with 'aasm start ` +
303
+ `--mode local', set ${ENV_GATEWAY_URL} to a running gateway, or set ` +
304
+ `${ENV_AUTO_START}=1 to allow the SDK to auto-start a local gateway.`);
305
+ }
192
306
  await _seams.autoStartGateway(DEFAULT_GATEWAY_URL);
193
307
  return DEFAULT_GATEWAY_URL;
194
308
  }
@@ -202,7 +316,7 @@ export async function resolveGatewayUrl(explicit) {
202
316
  export async function resolveApiKey(explicit) {
203
317
  if (explicit)
204
318
  return explicit;
205
- const fromEnv = process.env[ENV_API_KEY];
319
+ const fromEnv = readEnvWithDeprecation(ENV_API_KEY, LEGACY_ENV_API_KEY);
206
320
  if (fromEnv)
207
321
  return fromEnv;
208
322
  const config = await _seams.loadConfigFile();
@@ -1 +1 @@
1
- {"version":3,"file":"gateway-resolver.js","sourceRoot":"","sources":["../../../src/core/gateway-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;A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