@stigmer/runner 3.11.0 → 3.11.1-dev.20260812192248

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 (177) hide show
  1. package/README.md +2 -0
  2. package/dist/.build-fingerprint +1 -1
  3. package/dist/activities/discover-mcp-server.d.ts +7 -0
  4. package/dist/activities/discover-mcp-server.js +6 -4
  5. package/dist/activities/discover-mcp-server.js.map +1 -1
  6. package/dist/activities/emit-event.d.ts +14 -2
  7. package/dist/activities/emit-event.js +52 -17
  8. package/dist/activities/emit-event.js.map +1 -1
  9. package/dist/activities/execute-cursor/error-classifier.d.ts +19 -0
  10. package/dist/activities/execute-cursor/error-classifier.js +34 -3
  11. package/dist/activities/execute-cursor/error-classifier.js.map +1 -1
  12. package/dist/activities/execute-cursor/index.d.ts +46 -10
  13. package/dist/activities/execute-cursor/index.js +126 -36
  14. package/dist/activities/execute-cursor/index.js.map +1 -1
  15. package/dist/activities/execute-cursor/model-pricing-data.d.ts +2 -0
  16. package/dist/activities/execute-cursor/model-pricing-data.js +13 -3
  17. package/dist/activities/execute-cursor/model-pricing-data.js.map +1 -1
  18. package/dist/activities/execute-cursor/prompt-builder.d.ts +33 -0
  19. package/dist/activities/execute-cursor/prompt-builder.js +37 -0
  20. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
  21. package/dist/activities/execute-cursor/turn-recovery.d.ts +52 -0
  22. package/dist/activities/execute-cursor/turn-recovery.js +193 -0
  23. package/dist/activities/execute-cursor/turn-recovery.js.map +1 -0
  24. package/dist/activities/execute-deep-agent/setup.js +16 -7
  25. package/dist/activities/execute-deep-agent/setup.js.map +1 -1
  26. package/dist/activities/execute-deep-agent/shell-env.d.ts +5 -1
  27. package/dist/activities/execute-deep-agent/shell-env.js +7 -9
  28. package/dist/activities/execute-deep-agent/shell-env.js.map +1 -1
  29. package/dist/activities/execute-deep-agent/subagent-transformer.js +7 -1
  30. package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
  31. package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +17 -3
  32. package/dist/activities/execute-deep-agent/subagent-wiring.js +14 -2
  33. package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -1
  34. package/dist/activities/hydrate-workflow-execution.js +8 -5
  35. package/dist/activities/hydrate-workflow-execution.js.map +1 -1
  36. package/dist/activities/run-command.d.ts +5 -2
  37. package/dist/activities/run-command.js +22 -10
  38. package/dist/activities/run-command.js.map +1 -1
  39. package/dist/activities/run-env.d.ts +40 -0
  40. package/dist/activities/run-env.js +66 -0
  41. package/dist/activities/run-env.js.map +1 -0
  42. package/dist/bootstrap.js +5 -0
  43. package/dist/bootstrap.js.map +1 -1
  44. package/dist/client/stigmer-client.d.ts +83 -26
  45. package/dist/client/stigmer-client.js +88 -24
  46. package/dist/client/stigmer-client.js.map +1 -1
  47. package/dist/encryption/config.d.ts +41 -9
  48. package/dist/encryption/config.js +63 -23
  49. package/dist/encryption/config.js.map +1 -1
  50. package/dist/middleware/index.d.ts +3 -0
  51. package/dist/middleware/index.js +7 -0
  52. package/dist/middleware/index.js.map +1 -1
  53. package/dist/middleware/path-normalization.d.ts +57 -0
  54. package/dist/middleware/path-normalization.js +109 -0
  55. package/dist/middleware/path-normalization.js.map +1 -0
  56. package/dist/middleware/types.d.ts +8 -0
  57. package/dist/payload-codecs.d.ts +2 -1
  58. package/dist/payload-codecs.js +7 -3
  59. package/dist/payload-codecs.js.map +1 -1
  60. package/dist/runner-manager.js +17 -3
  61. package/dist/runner-manager.js.map +1 -1
  62. package/dist/runner.js +7 -3
  63. package/dist/runner.js.map +1 -1
  64. package/dist/shared/artifact-storage.d.ts +23 -1
  65. package/dist/shared/artifact-storage.js +51 -10
  66. package/dist/shared/artifact-storage.js.map +1 -1
  67. package/dist/shared/checkpointer/http-saver.d.ts +4 -20
  68. package/dist/shared/checkpointer/http-saver.js +15 -57
  69. package/dist/shared/checkpointer/http-saver.js.map +1 -1
  70. package/dist/shared/conversation-catchup.d.ts +9 -2
  71. package/dist/shared/conversation-catchup.js +39 -6
  72. package/dist/shared/conversation-catchup.js.map +1 -1
  73. package/dist/shared/grpc-retry.d.ts +5 -1
  74. package/dist/shared/grpc-retry.js +5 -1
  75. package/dist/shared/grpc-retry.js.map +1 -1
  76. package/dist/shared/http-retry.d.ts +51 -9
  77. package/dist/shared/http-retry.js +60 -9
  78. package/dist/shared/http-retry.js.map +1 -1
  79. package/dist/shared/mcp-manager.d.ts +8 -4
  80. package/dist/shared/mcp-manager.js +30 -4
  81. package/dist/shared/mcp-manager.js.map +1 -1
  82. package/dist/shared/mcp-schema-sanitizer.d.ts +70 -0
  83. package/dist/shared/mcp-schema-sanitizer.js +197 -0
  84. package/dist/shared/mcp-schema-sanitizer.js.map +1 -0
  85. package/dist/shared/model-client.d.ts +6 -0
  86. package/dist/shared/model-client.js +14 -3
  87. package/dist/shared/model-client.js.map +1 -1
  88. package/dist/shared/model-pricing-data.d.ts +2 -0
  89. package/dist/shared/model-pricing-data.js +13 -3
  90. package/dist/shared/model-pricing-data.js.map +1 -1
  91. package/dist/shared/model-registry.js +3 -2
  92. package/dist/shared/model-registry.js.map +1 -1
  93. package/dist/shared/plan-mode-permissions.d.ts +7 -0
  94. package/dist/shared/plan-mode-permissions.js +7 -0
  95. package/dist/shared/plan-mode-permissions.js.map +1 -1
  96. package/dist/shared/registry-endpoint.d.ts +20 -0
  97. package/dist/shared/registry-endpoint.js +25 -0
  98. package/dist/shared/registry-endpoint.js.map +1 -1
  99. package/dist/shared/runner-credential-keys.d.ts +24 -0
  100. package/dist/shared/runner-credential-keys.js +47 -0
  101. package/dist/shared/runner-credential-keys.js.map +1 -0
  102. package/dist/workflow-engine/resolve.d.ts +19 -1
  103. package/dist/workflow-engine/resolve.js +37 -2
  104. package/dist/workflow-engine/resolve.js.map +1 -1
  105. package/dist/workflows/connect-mcp-server.js +2 -0
  106. package/dist/workflows/connect-mcp-server.js.map +1 -1
  107. package/dist/workflows/types.d.ts +8 -0
  108. package/package.json +3 -4
  109. package/src/__test-utils__/__tests__/vitest-global-setup.test.ts +37 -0
  110. package/src/__test-utils__/vitest-global-setup.ts +50 -0
  111. package/src/__tests__/bootstrap.test.ts +43 -0
  112. package/src/__tests__/encryption-codec.test.ts +53 -0
  113. package/src/__tests__/preflight.test.ts +15 -0
  114. package/src/activities/__tests__/discover-mcp-server.test.ts +39 -1
  115. package/src/activities/__tests__/error-classifier.test.ts +94 -2
  116. package/src/activities/__tests__/run-command.test.ts +221 -0
  117. package/src/activities/discover-mcp-server.ts +16 -2
  118. package/src/activities/emit-event.ts +65 -21
  119. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +111 -2
  120. package/src/activities/execute-cursor/__tests__/model-pricing.test.ts +62 -1
  121. package/src/activities/execute-cursor/__tests__/turn-recovery.test.ts +160 -0
  122. package/src/activities/execute-cursor/error-classifier.ts +40 -3
  123. package/src/activities/execute-cursor/index.ts +154 -38
  124. package/src/activities/execute-cursor/model-pricing-data.ts +22 -3
  125. package/src/activities/execute-cursor/prompt-builder.ts +51 -0
  126. package/src/activities/execute-cursor/turn-recovery.ts +208 -0
  127. package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +174 -0
  128. package/src/activities/execute-deep-agent/__tests__/shell-env.test.ts +24 -10
  129. package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +22 -17
  130. package/src/activities/execute-deep-agent/setup.ts +16 -8
  131. package/src/activities/execute-deep-agent/shell-env.ts +8 -9
  132. package/src/activities/execute-deep-agent/subagent-transformer.ts +7 -1
  133. package/src/activities/execute-deep-agent/subagent-wiring.ts +26 -3
  134. package/src/activities/hydrate-workflow-execution.ts +8 -5
  135. package/src/activities/run-command.ts +25 -12
  136. package/src/activities/run-env.ts +79 -0
  137. package/src/bootstrap.ts +5 -0
  138. package/src/client/__tests__/stigmer-client.test.ts +104 -5
  139. package/src/client/stigmer-client.ts +128 -29
  140. package/src/encryption/config.ts +87 -23
  141. package/src/middleware/__tests__/path-normalization.test.ts +140 -0
  142. package/src/middleware/index.ts +8 -0
  143. package/src/middleware/path-normalization.ts +125 -0
  144. package/src/middleware/types.ts +11 -0
  145. package/src/payload-codecs.ts +8 -2
  146. package/src/runner-manager.ts +21 -3
  147. package/src/runner.ts +7 -3
  148. package/src/shared/__tests__/artifact-storage.test.ts +145 -2
  149. package/src/shared/__tests__/conversation-catchup.test.ts +24 -0
  150. package/src/shared/__tests__/http-retry.test.ts +5 -4
  151. package/src/shared/__tests__/mcp-manager.test.ts +53 -13
  152. package/src/shared/__tests__/mcp-schema-sanitizer.test.ts +267 -0
  153. package/src/shared/__tests__/model-client.test.ts +46 -0
  154. package/src/shared/__tests__/model-pricing.test.ts +62 -2
  155. package/src/shared/__tests__/model-registry.test.ts +22 -0
  156. package/src/shared/artifact-storage.ts +75 -10
  157. package/src/shared/checkpointer/http-saver.ts +15 -60
  158. package/src/shared/conversation-catchup.ts +39 -6
  159. package/src/shared/grpc-retry.ts +5 -1
  160. package/src/shared/http-retry.ts +98 -9
  161. package/src/shared/mcp-manager.ts +35 -4
  162. package/src/shared/mcp-schema-sanitizer.ts +224 -0
  163. package/src/shared/model-client.ts +21 -3
  164. package/src/shared/model-pricing-data.ts +22 -3
  165. package/src/shared/model-registry.ts +7 -2
  166. package/src/shared/plan-mode-permissions.ts +7 -0
  167. package/src/shared/registry-endpoint.ts +27 -0
  168. package/src/shared/runner-credential-keys.ts +46 -0
  169. package/src/workflow-engine/__tests__/tasks/emit-event.test.ts +127 -49
  170. package/src/workflow-engine/resolve.ts +48 -2
  171. package/src/workflows/__tests__/connect-mcp-server.test.ts +25 -0
  172. package/src/workflows/connect-mcp-server.ts +2 -0
  173. package/src/workflows/types.ts +8 -0
  174. package/dist/activities/execute-cursor/mcp-config.d.ts +0 -30
  175. package/dist/activities/execute-cursor/mcp-config.js +0 -39
  176. package/dist/activities/execute-cursor/mcp-config.js.map +0 -1
  177. package/src/activities/execute-cursor/mcp-config.ts +0 -66
@@ -1,32 +1,34 @@
1
1
  import { describe, it, expect, vi, afterEach, beforeEach } from "vitest";
2
- import { emitEventAction, type EmitEventConfig } from "../../../activities/emit-event.js";
3
-
4
- // ─── Temporal signal-delivery mocks ──────────────────────────────────────────
5
- // deliverSignal dynamically imports @temporalio/client and resolves the cluster
6
- // coordinates through loadConfig(). We mock both so the signal path is testable
7
- // without a live Temporal server, and so we can assert which address it dials.
8
- const mockConnect = vi.fn(async (_opts: { address: string }) => ({}));
9
- const mockSignal = vi.fn(async () => undefined);
10
- const mockGetHandle = vi.fn((_id: string) => ({ signal: mockSignal }));
11
- const mockClientCtor = vi.fn((_opts: { connection: unknown; namespace: string }) => ({
12
- workflow: { getHandle: mockGetHandle },
2
+ import { emitEventAction, type EmitEventConfig, type SignalDeliveryTarget } from "../../../activities/emit-event.js";
3
+
4
+ // ─── Server-mediated signal-delivery mocks ───────────────────────────────────
5
+ // deliverSignal routes through StigmerClient.sendWorkflowSignal (the server's
6
+ // SendSignal lane — oss#517). We mock the client so the signal path is testable
7
+ // without a live server, and so we can assert the addressing, the bounded call
8
+ // timeout, and the best-effort delivery_errors contract.
9
+ const mockSendWorkflowSignal = vi.fn(async (
10
+ _executionId: string,
11
+ _signalName: string,
12
+ _payload: unknown,
13
+ _options?: { timeoutMs?: number },
14
+ ) => ({}));
15
+ const mockClientCtor = vi.fn((_opts: { endpoint: string; token?: string | null }) => ({
16
+ sendWorkflowSignal: mockSendWorkflowSignal,
13
17
  }));
14
18
 
15
- vi.mock("@temporalio/client", () => ({
16
- Connection: { connect: (opts: { address: string }) => mockConnect(opts) },
17
- Client: vi.fn().mockImplementation((opts: { connection: unknown; namespace: string }) =>
18
- mockClientCtor(opts),
19
+ vi.mock("../../../client/stigmer-client.js", () => ({
20
+ StigmerClient: vi.fn().mockImplementation(
21
+ (opts: { endpoint: string; token?: string | null }) => mockClientCtor(opts),
19
22
  ),
20
23
  }));
21
24
 
22
- // Mutable so each test can vary what config.ts resolves. Mirrors the real
23
- // resolution where temporalAddress comes from TEMPORAL_SERVICE_ADDRESS.
24
- let mockTemporalAddress = "localhost:7233";
25
- let mockTemporalNamespace = "default";
25
+ // Mutable so each test can vary what config.ts resolves. deliverSignal builds
26
+ // its client from the canonical stigmerBackendEndpoint resolution.
27
+ let mockBackendEndpoint = "http://localhost:7234";
26
28
  vi.mock("../../../config.js", () => ({
27
29
  loadConfig: () => ({
28
- temporalAddress: mockTemporalAddress,
29
- temporalNamespace: mockTemporalNamespace,
30
+ stigmerBackendEndpoint: mockBackendEndpoint,
31
+ stigmerToken: null,
30
32
  }),
31
33
  }));
32
34
 
@@ -260,63 +262,139 @@ describe("emitEventAction", () => {
260
262
  });
261
263
  });
262
264
 
263
- describe("signal delivery (Temporal coordinates from config)", () => {
265
+ describe("signal delivery (server-mediated SendSignal lane)", () => {
264
266
  beforeEach(() => {
265
- mockConnect.mockClear();
266
- mockSignal.mockClear();
267
- mockGetHandle.mockClear();
267
+ mockSendWorkflowSignal.mockClear();
268
268
  mockClientCtor.mockClear();
269
- mockSignal.mockResolvedValue(undefined);
270
- mockTemporalAddress = "localhost:7233";
271
- mockTemporalNamespace = "default";
269
+ mockSendWorkflowSignal.mockResolvedValue({});
270
+ mockBackendEndpoint = "http://localhost:7234";
272
271
  });
273
272
 
274
- it("dials the Temporal address resolved by config, not a hardcoded localhost", async () => {
275
- // Regression for F1: deliverSignal previously read process.env.TEMPORAL_ADDRESS
276
- // and fell back to localhost — diverging from the canonical
277
- // TEMPORAL_SERVICE_ADDRESS the worker uses. It now goes through loadConfig().
278
- mockTemporalAddress = "stigmer-temporal-frontend:7233";
279
- mockTemporalNamespace = "stigmer-prod";
273
+ it("routes through the server resolved by config, addressed by execution_id", async () => {
274
+ mockBackendEndpoint = "https://api.stigmer.example.com";
280
275
 
281
276
  const config: EmitEventConfig = {
282
277
  event: { type: "approval.granted" },
283
278
  delivery: [
284
- { signal: { workflow_id: "wf-abc", signal_name: "approvalResolved" } },
279
+ { signal: { execution_id: "wfx_01ABC", signal_name: "approval_resolved" } },
285
280
  ],
286
281
  };
287
282
 
288
283
  const result = await emitEventAction(config, "exec-1");
289
284
 
290
- expect(mockConnect).toHaveBeenCalledWith({ address: "stigmer-temporal-frontend:7233" });
291
285
  expect(mockClientCtor).toHaveBeenCalledWith(
292
- expect.objectContaining({ namespace: "stigmer-prod" }),
286
+ expect.objectContaining({ endpoint: "https://api.stigmer.example.com" }),
293
287
  );
294
- expect(mockGetHandle).toHaveBeenCalledWith("wf-abc");
295
- expect(mockSignal).toHaveBeenCalledTimes(1);
296
- const [signalName, envelope] = mockSignal.mock.calls[0] as unknown as [
297
- string,
298
- Record<string, unknown>,
299
- ];
300
- expect(signalName).toBe("approvalResolved");
288
+ expect(mockSendWorkflowSignal).toHaveBeenCalledTimes(1);
289
+ const [executionId, signalName, envelope, options] =
290
+ mockSendWorkflowSignal.mock.calls[0] as unknown as [
291
+ string,
292
+ string,
293
+ Record<string, unknown>,
294
+ { timeoutMs?: number },
295
+ ];
296
+ expect(executionId).toBe("wfx_01ABC");
297
+ expect(signalName).toBe("approval_resolved");
301
298
  expect(envelope.type).toBe("approval.granted");
299
+ expect(envelope.specversion).toBe("1.0");
302
300
  expect(result.delivery_errors).toBeUndefined();
301
+ // Best-effort delivery must never consume the activity's 5m budget.
302
+ expect(options).toEqual({ timeoutMs: 30_000 });
303
303
  });
304
304
 
305
- it("keeps signal delivery best-effort: failures are collected, not thrown", async () => {
306
- mockSignal.mockRejectedValueOnce(new Error("temporal unavailable"));
305
+ it("keeps signal delivery best-effort: server refusals are collected, not thrown", async () => {
306
+ mockSendWorkflowSignal.mockRejectedValueOnce(
307
+ new Error("[failed_precondition] cannot send signal to execution in phase EXECUTION_COMPLETED"),
308
+ );
309
+
310
+ const config: EmitEventConfig = {
311
+ event: { type: "test" },
312
+ delivery: [
313
+ { signal: { execution_id: "wfx_done", signal_name: "ping" } },
314
+ ],
315
+ };
316
+
317
+ const result = await emitEventAction(config, "exec-1");
318
+
319
+ expect(result.delivery_errors).toHaveLength(1);
320
+ expect((result.delivery_errors as any)[0].target).toBe("signal:wfx_done/ping");
321
+ expect((result.delivery_errors as any)[0].error).toContain("failed_precondition");
322
+ });
307
323
 
324
+ it("refuses the pre-oss#517 workflow_id field by name, without calling the server", async () => {
308
325
  const config: EmitEventConfig = {
309
326
  event: { type: "test" },
310
327
  delivery: [
311
- { signal: { workflow_id: "wf-down", signal_name: "ping" } },
328
+ {
329
+ signal: {
330
+ workflow_id: "workflow-exec-wfx_01ABC",
331
+ signal_name: "ping",
332
+ } as unknown as SignalDeliveryTarget,
333
+ },
312
334
  ],
313
335
  };
314
336
 
315
337
  const result = await emitEventAction(config, "exec-1");
316
338
 
339
+ expect(mockSendWorkflowSignal).not.toHaveBeenCalled();
317
340
  expect(result.delivery_errors).toHaveLength(1);
318
- expect((result.delivery_errors as any)[0].target).toBe("signal:wf-down/ping");
319
- expect((result.delivery_errors as any)[0].error).toContain("temporal unavailable");
341
+ expect((result.delivery_errors as any)[0].error).toContain("'execution_id'");
342
+ expect((result.delivery_errors as any)[0].error).toContain("'workflow_id' is not supported");
343
+ });
344
+
345
+ it("refuses a signal target missing signal_name", async () => {
346
+ const config: EmitEventConfig = {
347
+ event: { type: "test" },
348
+ delivery: [
349
+ {
350
+ signal: {
351
+ execution_id: "wfx_01ABC",
352
+ } as unknown as SignalDeliveryTarget,
353
+ },
354
+ ],
355
+ };
356
+
357
+ const result = await emitEventAction(config, "exec-1");
358
+
359
+ expect(mockSendWorkflowSignal).not.toHaveBeenCalled();
360
+ expect(result.delivery_errors).toHaveLength(1);
361
+ expect((result.delivery_errors as any)[0].error).toContain("'signal_name'");
362
+ });
363
+
364
+ it("reuses one client across multiple signal targets", async () => {
365
+ const config: EmitEventConfig = {
366
+ event: { type: "fanout" },
367
+ delivery: [
368
+ { signal: { execution_id: "wfx_a", signal_name: "sig_a" } },
369
+ { signal: { execution_id: "wfx_b", signal_name: "sig_b" } },
370
+ ],
371
+ };
372
+
373
+ const result = await emitEventAction(config, "exec-1");
374
+
375
+ expect(mockClientCtor).toHaveBeenCalledTimes(1);
376
+ expect(mockSendWorkflowSignal).toHaveBeenCalledTimes(2);
377
+ expect(result.delivery_errors).toBeUndefined();
378
+ });
379
+
380
+ it("constructs no client for webhook-only delivery", async () => {
381
+ const originalFetch = globalThis.fetch;
382
+ globalThis.fetch = vi.fn(() =>
383
+ Promise.resolve(new Response(null, { status: 200 })),
384
+ ) as any;
385
+
386
+ try {
387
+ const config: EmitEventConfig = {
388
+ event: { type: "test" },
389
+ delivery: [{ webhook: { url: "https://events.example.com" } }],
390
+ };
391
+
392
+ await emitEventAction(config, "exec-1");
393
+
394
+ expect(mockClientCtor).not.toHaveBeenCalled();
395
+ } finally {
396
+ globalThis.fetch = originalFetch;
397
+ }
320
398
  });
321
399
  });
322
400
  });
@@ -158,6 +158,9 @@ function parsePath(path: string): (string | number)[] {
158
158
 
159
159
  const RUNTIME_PLACEHOLDER_RE = /\$\{\.(secrets|env_vars)\.\w+\}/;
160
160
 
161
+ /** Substitution form of {@link RUNTIME_PLACEHOLDER_RE} (global, capturing). */
162
+ const RUNTIME_PLACEHOLDER_SUB_RE = /\$\{\.(secrets|env_vars)\.(\w+)\}/g;
163
+
161
164
  /**
162
165
  * Checks whether a string contains a runtime placeholder that should
163
166
  * NOT be evaluated in the workflow (deterministic) phase. These are
@@ -172,7 +175,9 @@ export function isRuntimePlaceholder(value: string): boolean {
172
175
 
173
176
  /**
174
177
  * Resolves runtime placeholders (`${.secrets.KEY}`, `${.env_vars.KEY}`)
175
- * in a string using values from the runtime environment map.
178
+ * in a string using values from the runtime environment map. Missing
179
+ * keys resolve to `""` — callers that must fail loudly instead use
180
+ * {@link resolveRuntimePlaceholdersStrict}.
176
181
  *
177
182
  * This runs in activities only — never in the workflow sandbox.
178
183
  */
@@ -181,7 +186,7 @@ export function resolveRuntimePlaceholders(
181
186
  runtimeEnv: Record<string, unknown>,
182
187
  ): string {
183
188
  return value.replace(
184
- /\$\{\.(secrets|env_vars)\.(\w+)\}/g,
189
+ RUNTIME_PLACEHOLDER_SUB_RE,
185
190
  (_match, _ns: string, key: string) => {
186
191
  const resolved = runtimeEnv[key];
187
192
  return resolved !== undefined ? String(resolved) : "";
@@ -189,6 +194,47 @@ export function resolveRuntimePlaceholders(
189
194
  );
190
195
  }
191
196
 
197
+ /** Thrown by {@link resolveRuntimePlaceholdersStrict} for a missing key. */
198
+ export class RuntimePlaceholderResolutionError extends Error {
199
+ constructor(
200
+ public readonly variableName: string,
201
+ public readonly context?: string,
202
+ ) {
203
+ const where = context ? ` in ${context}` : "";
204
+ super(
205
+ `Unresolved runtime placeholder for "${variableName}"${where}: ` +
206
+ `variable is not present in the workflow's runtime environment`,
207
+ );
208
+ this.name = "RuntimePlaceholderResolutionError";
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Strict variant of {@link resolveRuntimePlaceholders}: a placeholder
214
+ * whose key is missing from the runtime environment throws instead of
215
+ * resolving to `""` — a silently-empty credential produces cryptic
216
+ * downstream failures, so declared-value consumers (the run task's env
217
+ * contract) fail fast with the variable named.
218
+ *
219
+ * This runs in activities only — never in the workflow sandbox.
220
+ */
221
+ export function resolveRuntimePlaceholdersStrict(
222
+ value: string,
223
+ runtimeEnv: Record<string, unknown>,
224
+ context?: string,
225
+ ): string {
226
+ return value.replace(
227
+ RUNTIME_PLACEHOLDER_SUB_RE,
228
+ (_match, _ns: string, key: string) => {
229
+ const resolved = runtimeEnv[key];
230
+ if (resolved === undefined) {
231
+ throw new RuntimePlaceholderResolutionError(key, context);
232
+ }
233
+ return String(resolved);
234
+ },
235
+ );
236
+ }
237
+
192
238
  /**
193
239
  * Recursively resolves all runtime placeholders in a nested object.
194
240
  * Walks maps, arrays, and strings. Non-string leaves pass through.
@@ -63,6 +63,7 @@ describe("ConnectMcpServerWorkflow", () => {
63
63
  expect(mockDiscoverActivity).toHaveBeenCalledWith({
64
64
  mcpServerId: "mcp-123",
65
65
  executionContextId: "ctx-abc",
66
+ executionContextToken: null,
66
67
  invokerIdentityAccountId: "user-1",
67
68
  });
68
69
 
@@ -88,6 +89,30 @@ describe("ConnectMcpServerWorkflow", () => {
88
89
  expect(mockDiscoverActivity).toHaveBeenCalledWith({
89
90
  mcpServerId: "mcp-min",
90
91
  executionContextId: null,
92
+ executionContextToken: null,
93
+ invokerIdentityAccountId: null,
94
+ });
95
+ });
96
+
97
+ it("forwards the payload-carried EC token to discovery (oss#535)", async () => {
98
+ // The OSS handler mints an execution-scoped token into the workflow
99
+ // input; discovery presents it on the EC read to receive decrypted
100
+ // credentials from the redact-by-default OSS server.
101
+ const { connectMcpServer } = await import("../connect-mcp-server.js");
102
+
103
+ mockDiscoverActivity.mockResolvedValue(makeDiscoveryResult({ tools: [] }));
104
+ mockClassifyActivity.mockResolvedValue([]);
105
+
106
+ await connectMcpServer({
107
+ mcp_server_id: "mcp-tok",
108
+ execution_context_id: "ctx-tok",
109
+ execution_context_token: "scoped-ec-token",
110
+ });
111
+
112
+ expect(mockDiscoverActivity).toHaveBeenCalledWith({
113
+ mcpServerId: "mcp-tok",
114
+ executionContextId: "ctx-tok",
115
+ executionContextToken: "scoped-ec-token",
91
116
  invokerIdentityAccountId: null,
92
117
  });
93
118
  });
@@ -201,6 +201,7 @@ export async function connectMcpServer(
201
201
  const discovery = await discover.DiscoverMcpServerCapabilities({
202
202
  mcpServerId: input.mcp_server_id,
203
203
  executionContextId: input.execution_context_id ?? null,
204
+ executionContextToken: input.execution_context_token ?? null,
204
205
  invokerIdentityAccountId: input.invoker_identity_account_id ?? null,
205
206
  });
206
207
 
@@ -288,6 +289,7 @@ export async function discoverMcpServerLegacy(
288
289
  const discovery = await discover.DiscoverMcpServerCapabilities({
289
290
  mcpServerId: input.mcp_server_id,
290
291
  executionContextId: input.execution_context_id ?? null,
292
+ executionContextToken: input.execution_context_token ?? null,
291
293
  invokerIdentityAccountId: input.invoker_identity_account_id ?? null,
292
294
  });
293
295
 
@@ -19,6 +19,14 @@
19
19
  export interface ConnectMcpServerWorkflowInput {
20
20
  mcp_server_id: string;
21
21
  execution_context_id?: string | null;
22
+ /**
23
+ * Execution-scoped token for reading the connect ExecutionContext's
24
+ * decrypted credentials (oss#535). Populated by the OSS Go handler, whose
25
+ * EC read RPCs redact secrets for tokenless callers; absent on cloud,
26
+ * where the discovery activity's ambient connect_sandbox credential
27
+ * decrypts on its own.
28
+ */
29
+ execution_context_token?: string | null;
22
30
  invoker_identity_account_id?: string | null;
23
31
  }
24
32
 
@@ -1,30 +0,0 @@
1
- /**
2
- * Cursor-specific MCP config mapping.
3
- *
4
- * Converts harness-agnostic ResolvedMcpServer into the Cursor SDK's
5
- * McpServerConfig shape for Agent.create(). The resolution logic lives
6
- * in shared/mcp-resolver.ts; this module only handles the final transform.
7
- */
8
- import type { ResolvedMcpServer } from "../../shared/mcp-resolver.js";
9
- export type { ResolvedMcpServer, McpResolutionResult } from "../../shared/mcp-resolver.js";
10
- export { resolveMcpServers, extractMcpServerSlugs, PlaceholderResolutionError, } from "../../shared/mcp-resolver.js";
11
- /**
12
- * Cursor SDK MCP server config shape (matches @cursor/sdk McpServerConfig).
13
- * Defined here to avoid tight coupling to the SDK's internal types.
14
- */
15
- export type CursorMcpServerConfig = {
16
- type?: "stdio";
17
- command: string;
18
- args?: string[];
19
- env?: Record<string, string>;
20
- cwd?: string;
21
- } | {
22
- type?: "http" | "sse";
23
- url: string;
24
- headers?: Record<string, string>;
25
- };
26
- /**
27
- * Transform resolved MCP servers into the Cursor SDK's mcpServers config
28
- * for Agent.create().
29
- */
30
- export declare function toCursorMcpConfig(servers: ResolvedMcpServer[]): Record<string, CursorMcpServerConfig>;
@@ -1,39 +0,0 @@
1
- /**
2
- * Cursor-specific MCP config mapping.
3
- *
4
- * Converts harness-agnostic ResolvedMcpServer into the Cursor SDK's
5
- * McpServerConfig shape for Agent.create(). The resolution logic lives
6
- * in shared/mcp-resolver.ts; this module only handles the final transform.
7
- */
8
- export { resolveMcpServers, extractMcpServerSlugs, PlaceholderResolutionError, } from "../../shared/mcp-resolver.js";
9
- /**
10
- * Transform resolved MCP servers into the Cursor SDK's mcpServers config
11
- * for Agent.create().
12
- */
13
- export function toCursorMcpConfig(servers) {
14
- const result = {};
15
- for (const server of servers) {
16
- if (server.connectionType === "stdio") {
17
- if (!server.command)
18
- continue;
19
- result[server.slug] = {
20
- type: "stdio",
21
- command: server.command,
22
- args: server.args,
23
- env: server.env,
24
- cwd: server.cwd,
25
- };
26
- }
27
- else {
28
- if (!server.url)
29
- continue;
30
- result[server.slug] = {
31
- type: server.connectionType,
32
- url: server.url,
33
- headers: server.headers,
34
- };
35
- }
36
- }
37
- return result;
38
- }
39
- //# sourceMappingURL=mcp-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-config.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/mcp-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAoBtC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA4B;IAE5B,MAAM,MAAM,GAA0C,EAAE,CAAC;IAEzD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,cAAc,KAAK,OAAO,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,OAAO;gBAAE,SAAS;YAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;gBACpB,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,GAAG,EAAE,MAAM,CAAC,GAAG;aAChB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,GAAG;gBAAE,SAAS;YAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;gBACpB,IAAI,EAAE,MAAM,CAAC,cAAc;gBAC3B,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,66 +0,0 @@
1
- /**
2
- * Cursor-specific MCP config mapping.
3
- *
4
- * Converts harness-agnostic ResolvedMcpServer into the Cursor SDK's
5
- * McpServerConfig shape for Agent.create(). The resolution logic lives
6
- * in shared/mcp-resolver.ts; this module only handles the final transform.
7
- */
8
-
9
- import type { ResolvedMcpServer } from "../../shared/mcp-resolver.js";
10
-
11
- export type { ResolvedMcpServer, McpResolutionResult } from "../../shared/mcp-resolver.js";
12
- export {
13
- resolveMcpServers,
14
- extractMcpServerSlugs,
15
- PlaceholderResolutionError,
16
- } from "../../shared/mcp-resolver.js";
17
-
18
- /**
19
- * Cursor SDK MCP server config shape (matches @cursor/sdk McpServerConfig).
20
- * Defined here to avoid tight coupling to the SDK's internal types.
21
- */
22
- export type CursorMcpServerConfig =
23
- | {
24
- type?: "stdio";
25
- command: string;
26
- args?: string[];
27
- env?: Record<string, string>;
28
- cwd?: string;
29
- }
30
- | {
31
- type?: "http" | "sse";
32
- url: string;
33
- headers?: Record<string, string>;
34
- };
35
-
36
- /**
37
- * Transform resolved MCP servers into the Cursor SDK's mcpServers config
38
- * for Agent.create().
39
- */
40
- export function toCursorMcpConfig(
41
- servers: ResolvedMcpServer[],
42
- ): Record<string, CursorMcpServerConfig> {
43
- const result: Record<string, CursorMcpServerConfig> = {};
44
-
45
- for (const server of servers) {
46
- if (server.connectionType === "stdio") {
47
- if (!server.command) continue;
48
- result[server.slug] = {
49
- type: "stdio",
50
- command: server.command,
51
- args: server.args,
52
- env: server.env,
53
- cwd: server.cwd,
54
- };
55
- } else {
56
- if (!server.url) continue;
57
- result[server.slug] = {
58
- type: server.connectionType,
59
- url: server.url,
60
- headers: server.headers,
61
- };
62
- }
63
- }
64
-
65
- return result;
66
- }