amplifier-agent-ts 0.4.0 → 0.5.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.
@@ -14,7 +14,7 @@ export interface AssembleArgvInput {
14
14
  sessionId: string;
15
15
  /** Final user prompt — emitted last as a positional argument. */
16
16
  prompt: string;
17
- /** Protocol version the wrapper speaks (e.g. "0.1.0"). */
17
+ /** Protocol version the wrapper speaks (e.g. "0.2.0"). */
18
18
  protocolVersion: string;
19
19
  /** When true, emit `--resume` instead of `--fresh`. */
20
20
  resume?: boolean;
@@ -22,25 +22,22 @@ export interface AssembleArgvInput {
22
22
  cwd?: string;
23
23
  /** Provider override; emits `--provider <providerOverride>`. */
24
24
  providerOverride?: string;
25
- /**
26
- * Path to the MCP config JSON file, pre-spilled by `resolveMcpConfigPath`.
27
- * Passed to the engine as `--mcp-config-path <path>`; the engine sets
28
- * `AMPLIFIER_MCP_CONFIG` so the tool-mcp module loads it during mount.
29
- */
30
- mcpConfigPath?: string;
31
- /** Host capabilities object — emitted as `--host-capabilities <JSON>`. */
32
- hostCapabilities?: unknown;
33
- /** Allowlisted env variable names — emits `--env-allowlist <comma-joined>`. */
34
- envAllowlist?: string[];
35
- /** Extra env entries — emitted as `--env-extra <JSON>`. */
36
- envExtra?: Record<string, string>;
37
- /** When true, emit `--allow-protocol-skew`. */
38
- allowProtocolSkew?: boolean;
39
25
  }
40
26
  /**
41
27
  * Build the argv array for `amplifier-agent run`.
42
28
  *
43
29
  * Pure function: no I/O, no env reads, no globals. Order is canonical and
44
30
  * stable so wrapper integration tests can pin against it.
31
+ *
32
+ * Removed argv flags (no longer emitted by this wrapper):
33
+ * - `--mcp-config-path` (engine PR #29): MCP config is now forwarded via the
34
+ * `AMPLIFIER_MCP_CONFIG` env var injected into the engine's subprocess
35
+ * environment at spawn time (or via `host_config["mcp"]["configPath"]` in
36
+ * the host's config file).
37
+ * - `--env-allowlist`, `--env-extra` (engine PR #27): env composition is
38
+ * the host's responsibility. Hosts either set `$AMPLIFIER_AGENT_CONFIG`
39
+ * in the subprocess env or pass `--config <path>` per turn.
40
+ * - `--allow-protocol-skew` (engine PR #27): the unsafe override moved to
41
+ * `host_config.allowProtocolSkew: true` in the JSON config file.
45
42
  */
46
43
  export declare function assembleArgv(input: AssembleArgvInput): string[];
@@ -14,6 +14,17 @@
14
14
  *
15
15
  * Pure function: no I/O, no env reads, no globals. Order is canonical and
16
16
  * stable so wrapper integration tests can pin against it.
17
+ *
18
+ * Removed argv flags (no longer emitted by this wrapper):
19
+ * - `--mcp-config-path` (engine PR #29): MCP config is now forwarded via the
20
+ * `AMPLIFIER_MCP_CONFIG` env var injected into the engine's subprocess
21
+ * environment at spawn time (or via `host_config["mcp"]["configPath"]` in
22
+ * the host's config file).
23
+ * - `--env-allowlist`, `--env-extra` (engine PR #27): env composition is
24
+ * the host's responsibility. Hosts either set `$AMPLIFIER_AGENT_CONFIG`
25
+ * in the subprocess env or pass `--config <path>` per turn.
26
+ * - `--allow-protocol-skew` (engine PR #27): the unsafe override moved to
27
+ * `host_config.allowProtocolSkew: true` in the JSON config file.
17
28
  */
18
29
  export function assembleArgv(input) {
19
30
  const argv = [];
@@ -26,23 +37,8 @@ export function assembleArgv(input) {
26
37
  if (input.providerOverride !== undefined) {
27
38
  argv.push("--provider", input.providerOverride);
28
39
  }
29
- if (input.mcpConfigPath !== undefined) {
30
- argv.push("--mcp-config-path", input.mcpConfigPath);
31
- }
32
- if (input.hostCapabilities !== undefined) {
33
- argv.push("--host-capabilities", JSON.stringify(input.hostCapabilities));
34
- }
35
- if (input.envAllowlist !== undefined && input.envAllowlist.length > 0) {
36
- argv.push("--env-allowlist", input.envAllowlist.join(","));
37
- }
38
- if (input.envExtra !== undefined) {
39
- argv.push("--env-extra", JSON.stringify(input.envExtra));
40
- }
41
40
  argv.push("--output", "json");
42
41
  argv.push("--protocol-version", input.protocolVersion);
43
- if (input.allowProtocolSkew === true) {
44
- argv.push("--allow-protocol-skew");
45
- }
46
42
  // SC-C: wrapper enforces auto-allow at the bundle layer.
47
43
  argv.push("-y");
48
44
  // Prompt is the final positional argument.
package/dist/index.d.ts CHANGED
@@ -14,8 +14,8 @@ export type { EngineVersionPayload } from "./spawn.js";
14
14
  import { SessionHandle } from "./session.js";
15
15
  import type { DisplayEvent } from "./session.js";
16
16
  import type { ApprovalResponse } from "./approval.js";
17
- import type { McpServerConfig, HostCapabilities } from "./types.js";
18
- export type { McpServerConfig, HostCapabilities } from "./types.js";
17
+ import type { McpServerConfig } from "./types.js";
18
+ export type { McpServerConfig } from "./types.js";
19
19
  /**
20
20
  * The protocol version that this TypeScript wrapper requires.
21
21
  * Forwarded to the engine via `--protocol-version` on every `submit()`.
@@ -48,14 +48,14 @@ export interface SpawnAgentParams {
48
48
  onEvent?: (event: DisplayEvent) => void;
49
49
  subagentEvents?: "all" | "none";
50
50
  };
51
- /** Default false; opt out of D6 strict-refuse version check. */
52
- allowProtocolSkew?: boolean;
53
- /** Optional MCP servers to forward via `--mcp-servers` (A1). */
51
+ /**
52
+ * Optional MCP servers. Spilled to a 0600 tmpfile per submit and forwarded
53
+ * to the engine via the `AMPLIFIER_MCP_CONFIG` env var injected into the
54
+ * subprocess environment. The former `--mcp-config-path` argv flag was
55
+ * removed; `tool-mcp` reads the env var natively via its config-discovery
56
+ * priority chain.
57
+ */
54
58
  mcpServers?: Record<string, McpServerConfig>;
55
- /** Optional host envelope forwarded via `--host-capabilities` (A1). */
56
- host?: {
57
- capabilities?: HostCapabilities;
58
- };
59
59
  /** Per-submit timeout in ms (default: 10 minutes). */
60
60
  timeoutMs?: number;
61
61
  /** Replaces the real resolveBinaryPath() call. */
package/dist/index.js CHANGED
@@ -77,10 +77,9 @@ export async function spawnAgent(params) {
77
77
  extra,
78
78
  });
79
79
  // 4. Return a SessionHandle. NO subprocess spawned here — the engine is
80
- // launched per submit() (amendment §5.2). NOTE: `version.ts` /
81
- // `checkProtocolVersion` are unused in Mode A v2 (skew is enforced via
82
- // argv `--protocol-version` + `--allow-protocol-skew` at the engine
83
- // side); flagged for Task-9 cleanup.
80
+ // launched per submit() (amendment §5.2). Skew override now lives in
81
+ // `host_config.allowProtocolSkew: true` in the host config file (engine
82
+ // PR #27); the wrapper no longer forwards an argv flag for it.
84
83
  return new SessionHandle({
85
84
  binaryPath,
86
85
  sessionId: params.sessionId,
@@ -88,17 +87,9 @@ export async function spawnAgent(params) {
88
87
  ...(params.resume !== undefined ? { resume: params.resume } : {}),
89
88
  ...(params.cwd !== undefined ? { cwd: params.cwd } : {}),
90
89
  ...(params.mcpServers !== undefined ? { mcpServers: params.mcpServers } : {}),
91
- ...(params.host?.capabilities !== undefined
92
- ? { hostCapabilities: params.host.capabilities }
93
- : {}),
94
- envAllowlist: allowlist,
95
- envExtra: extra,
96
90
  ...(params.providerOverride !== undefined
97
91
  ? { providerOverride: params.providerOverride }
98
92
  : {}),
99
- ...(params.allowProtocolSkew !== undefined
100
- ? { allowProtocolSkew: params.allowProtocolSkew }
101
- : {}),
102
93
  protocolVersion: PROTOCOL_VERSION_REQUIRED_BY_WRAPPER,
103
94
  ...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs } : {}),
104
95
  });
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Result of resolving the `--mcp-config-path` flag value.
2
+ * Result of spilling the MCP servers map to a tmpfile.
3
3
  *
4
4
  * - When `mcpServers` is null/undefined/empty: `configPath` is `null`.
5
5
  * - When servers are present: `configPath` points at the 0600 spill file.
6
6
  * The file contains `{"mcpServers": <map>}` in the format that
7
7
  * amplifier-module-tool-mcp expects when reading `AMPLIFIER_MCP_CONFIG`.
8
+ * The caller injects the path into the engine's subprocess environment
9
+ * as `AMPLIFIER_MCP_CONFIG`.
8
10
  */
9
11
  export interface McpSpillResult {
10
12
  configPath: string | null;
package/dist/mcp-spill.js CHANGED
@@ -4,9 +4,11 @@
4
4
  * The wrapper always spills the MCP server map to a 0600 tmpfile under
5
5
  * `${XDG_RUNTIME_DIR || os.tmpdir()}/amplifier-agent/<sessionId>/mcp.json`.
6
6
  * The file is written in the format documented by amplifier-module-tool-mcp:
7
- * a top-level `{"mcpServers": <map>}` object. The engine receives the plain
8
- * file path via `--mcp-config-path` and sets `AMPLIFIER_MCP_CONFIG`; the
9
- * module reads it via its standard config discovery (config.py priority chain).
7
+ * a top-level `{"mcpServers": <map>}` object. The caller (`SessionHandle`)
8
+ * injects the spilled path into the engine's subprocess environment as
9
+ * `AMPLIFIER_MCP_CONFIG`; the module reads it via its standard config
10
+ * discovery (config.py priority chain). The former `--mcp-config-path` argv
11
+ * flag was dropped — the env var is the single forwarding mechanism.
10
12
  *
11
13
  * `cleanupSpillFile` is the matching teardown — idempotent unlink that
12
14
  * swallows ENOENT so callers can call it unconditionally on every exit path.
package/dist/session.d.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  * - `dispose()` is a synonym for `cancel()`.
24
24
  */
25
25
  import type { ChildProcess } from "node:child_process";
26
- import type { McpServerConfig, HostCapabilities } from "./types.js";
26
+ import type { McpServerConfig } from "./types.js";
27
27
  /**
28
28
  * A display event yielded by `SessionHandle.submit()`.
29
29
  *
@@ -89,19 +89,16 @@ export interface SessionHandleParams {
89
89
  resume?: boolean;
90
90
  /** Working directory for the subprocess. */
91
91
  cwd?: string;
92
- /** MCP servers to forward via `--mcp-config-path` (CR-A spill applies). */
92
+ /**
93
+ * MCP servers to forward to the engine. CR-A spill applies: the map is
94
+ * written to a 0600 tmpfile and the path is injected into the engine's
95
+ * subprocess environment as `AMPLIFIER_MCP_CONFIG`. The former
96
+ * `--mcp-config-path` argv flag was removed.
97
+ */
93
98
  mcpServers?: Record<string, McpServerConfig>;
94
- /** Host capabilities forwarded via `--host-capabilities`. */
95
- hostCapabilities?: HostCapabilities;
96
- /** Allowlisted env variable names forwarded via `--env-allowlist`. */
97
- envAllowlist?: string[];
98
- /** Extra env entries forwarded via `--env-extra`. */
99
- envExtra?: Record<string, string>;
100
99
  /** Provider override forwarded via `--provider`. */
101
100
  providerOverride?: string;
102
- /** When true, append `--allow-protocol-skew` to argv. */
103
- allowProtocolSkew?: boolean;
104
- /** Protocol version the wrapper speaks (e.g. "0.1.0"). */
101
+ /** Protocol version the wrapper speaks (e.g. "0.2.0"). */
105
102
  protocolVersion: string;
106
103
  /** Per-submit timeout in milliseconds. Defaults to 10 minutes. */
107
104
  timeoutMs?: number;
@@ -133,8 +130,10 @@ export declare class SessionHandle {
133
130
  /**
134
131
  * Async generator implementing the §5.2 iterable behavior:
135
132
  * (i) yield `{type:'init', sessionId}` synchronously (SC-1);
136
- * (ii) CR-A: resolve `--mcp-config-path` (always spill to tmpfile);
137
- * (iii) build argv via `assembleArgv`;
133
+ * (ii) CR-A: spill MCP servers to a 0600 tmpfile (when provided);
134
+ * (iii) build argv via `assembleArgv` and the subprocess env (injecting
135
+ * `AMPLIFIER_MCP_CONFIG` for the spilled path when present — the
136
+ * former `--mcp-config-path` argv flag was removed);
138
137
  * (iv) SC-B: spawn with `detached:true` so PID == PGID for group signals;
139
138
  * (v) accumulate stdout/stderr from chunks;
140
139
  * (vi) start a 2s activity ticker → queue;
package/dist/session.js CHANGED
@@ -121,8 +121,10 @@ export class SessionHandle {
121
121
  /**
122
122
  * Async generator implementing the §5.2 iterable behavior:
123
123
  * (i) yield `{type:'init', sessionId}` synchronously (SC-1);
124
- * (ii) CR-A: resolve `--mcp-config-path` (always spill to tmpfile);
125
- * (iii) build argv via `assembleArgv`;
124
+ * (ii) CR-A: spill MCP servers to a 0600 tmpfile (when provided);
125
+ * (iii) build argv via `assembleArgv` and the subprocess env (injecting
126
+ * `AMPLIFIER_MCP_CONFIG` for the spilled path when present — the
127
+ * former `--mcp-config-path` argv flag was removed);
126
128
  * (iv) SC-B: spawn with `detached:true` so PID == PGID for group signals;
127
129
  * (v) accumulate stdout/stderr from chunks;
128
130
  * (vi) start a 2s activity ticker → queue;
@@ -135,14 +137,17 @@ export class SessionHandle {
135
137
  async *makeIterable(prompt) {
136
138
  // (i) SC-1: yield init synchronously, BEFORE any async work.
137
139
  yield { type: "init", sessionId: this.params.sessionId };
138
- // (ii) CR-A: resolve --mcp-config-path (always spill to 0600 tmpfile).
140
+ // (ii) CR-A: spill MCP servers to a 0600 tmpfile (configPath is null when
141
+ // mcpServers is null/empty).
139
142
  // Cast through `unknown`: McpServerConfig is the schema-validated wire type
140
143
  // (no index signature), while resolveMcpConfigPath's McpServerLike has an
141
144
  // open index signature. The two are runtime-compatible but TS rightly
142
145
  // rejects assignability without the cast.
143
146
  const spill = await resolveMcpConfigPath((this.params.mcpServers ?? null), this.params.sessionId);
144
147
  this.mcpSpillPath = spill.configPath;
145
- // (iii) build argv (pure function — no I/O).
148
+ // (iii) build argv (pure function — no I/O). The MCP config path is
149
+ // forwarded to the engine via AMPLIFIER_MCP_CONFIG (subprocess env)
150
+ // rather than via an argv flag.
146
151
  const argv = assembleArgv({
147
152
  sessionId: this.params.sessionId,
148
153
  prompt,
@@ -150,17 +155,22 @@ export class SessionHandle {
150
155
  resume: this.params.resume,
151
156
  cwd: this.params.cwd,
152
157
  providerOverride: this.params.providerOverride,
153
- mcpConfigPath: spill.configPath ?? undefined,
154
- hostCapabilities: this.params.hostCapabilities,
155
- envAllowlist: this.params.envAllowlist,
156
- envExtra: this.params.envExtra,
157
- allowProtocolSkew: this.params.allowProtocolSkew,
158
158
  });
159
+ // Build the subprocess env. When we spilled an MCP config, set
160
+ // AMPLIFIER_MCP_CONFIG so tool-mcp reads it natively via its
161
+ // config-discovery priority chain. We copy the params env into a fresh
162
+ // object so the stored SessionHandle env is never mutated.
163
+ const subprocessEnv = {
164
+ ...this.params.subprocessEnv,
165
+ };
166
+ if (spill.configPath !== null) {
167
+ subprocessEnv.AMPLIFIER_MCP_CONFIG = spill.configPath;
168
+ }
159
169
  // (iv) SC-B: spawn detached → new session group → PID == PGID.
160
170
  const child = childSpawn(this.params.binaryPath, argv, {
161
171
  detached: true,
162
172
  stdio: ["ignore", "pipe", "pipe"],
163
- env: this.params.subprocessEnv,
173
+ env: subprocessEnv,
164
174
  ...(this.params.cwd !== undefined ? { cwd: this.params.cwd } : {}),
165
175
  });
166
176
  this.subprocess = child;
package/dist/types.d.ts CHANGED
@@ -85,22 +85,6 @@ export interface ErrorNotification {
85
85
  message: string;
86
86
  recoverable: boolean;
87
87
  }
88
- /**
89
- * Capabilities advertised by the host to the agent (design §4.10.1).
90
- */
91
- export interface HostCapabilities {
92
- supports_steering?: boolean;
93
- supports_structured_errors?: boolean;
94
- }
95
- /**
96
- * ``initialize.params.host`` envelope for host-side capability advertisement.
97
- */
98
- export interface InitializeHostParams {
99
- capabilities?: HostCapabilities;
100
- }
101
- /**
102
- * Capabilities advertised by the host to the agent (design §4.10.1).
103
- */
104
88
  /**
105
89
  * Parameters for the ``initialize`` JSON-RPC method.
106
90
  */
@@ -114,35 +98,11 @@ export interface InitializeParams {
114
98
  resume?: boolean;
115
99
  providerOverride?: string;
116
100
  cwd?: string;
117
- mcpServers?: {
118
- [k: string]: McpServerConfig;
119
- };
120
- host?: InitializeHostParams;
101
+ mcpConfigPath?: string;
121
102
  }
122
103
  /**
123
104
  * Identity of the connecting client.
124
105
  */
125
- /**
126
- * Per-server MCP configuration passed via ``initialize.params.mcpServers``.
127
- */
128
- export interface McpServerConfig {
129
- transport: string;
130
- command?: string;
131
- args?: string[];
132
- env?: {
133
- [k: string]: string;
134
- };
135
- url?: string;
136
- headers?: {
137
- [k: string]: string;
138
- };
139
- }
140
- /**
141
- * ``initialize.params.host`` envelope for host-side capability advertisement.
142
- */
143
- /**
144
- * Capabilities advertised by the host to the agent (design §4.10.1).
145
- */
146
106
  /**
147
107
  * Result returned by the ``initialize`` JSON-RPC method.
148
108
  */
@@ -170,6 +130,18 @@ export interface SessionState {
170
130
  /**
171
131
  * Per-server MCP configuration passed via ``initialize.params.mcpServers``.
172
132
  */
133
+ export interface McpServerConfig {
134
+ transport: string;
135
+ command?: string;
136
+ args?: string[];
137
+ env?: {
138
+ [k: string]: string;
139
+ };
140
+ url?: string;
141
+ headers?: {
142
+ [k: string]: string;
143
+ };
144
+ }
173
145
  /**
174
146
  * Arbitrary progress update. ``percent`` is optional (0-100).
175
147
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amplifier-agent-ts",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript SDK for the Amplifier agent. Spawns and drives the amplifier-agent Python CLI over a stdio protocol.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,6 +51,6 @@
51
51
  "json-schema-to-typescript": "^15.0.0",
52
52
  "tsx": "^4.7.0",
53
53
  "typescript": "^5.4.0",
54
- "vitest": "^1.4.0"
54
+ "vitest": "^4.1.0"
55
55
  }
56
56
  }