@salesforce/sfdx-agent-harness-claude 0.6.0 → 0.8.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/README.md CHANGED
@@ -50,14 +50,14 @@ prompt source:
50
50
  - `'plan'` — planning mode; the model proposes actions without executing.
51
51
 
52
52
  `'default'`, `'dontAsk'`, and `'auto'` are intentionally excluded because they require a prompt UI the harness does not
53
- provide. For human-in-the-loop gating, set `StreamOptions.requireToolApproval: true` per-call instead — the harness will
54
- override `permissionMode` to `'default'` for that turn and route each tool call through the SDK's
55
- `tool-approval-request` flow.
53
+ provide. For human-in-the-loop gating, set `StreamOptions.requireToolApproval: true` per-call instead — the harness
54
+ installs a `PreToolUse` SDK hook for that turn that gates every tool call through the SDK's `tool-approval-request`
55
+ flow regardless of the factory-pinned permission mode.
56
56
 
57
57
  ### Tool approval
58
58
 
59
59
  When `StreamOptions.requireToolApproval: true` is set on `chatSession.send()`/`stream()`, the harness installs a
60
- `canUseTool` callback that:
60
+ `PreToolUse` hook that:
61
61
 
62
62
  1. Emits a `tool-approval-request` event on `ChatStreamResult.eventStream` carrying
63
63
  `{ toolCall: { toolCallId, toolName, args } }`.
@@ -98,12 +98,11 @@ single `error` event (no `finish`) and the underlying Claude subprocess is kille
98
98
 
99
99
  #### Approval timeout
100
100
 
101
- Each pending approval is auto-denied with `interrupt: true` after `ClaudeHarnessFactoryConfig.toolApprovalTimeoutMs`
102
- (default `600_000`, i.e. 10 minutes — matching the Mastra MCP timeout default). When the timeout fires:
101
+ Each pending approval is auto-denied after `ClaudeHarnessFactoryConfig.toolApprovalTimeoutMs` (default `600_000`, i.e.
102
+ 10 minutes — matching the Mastra MCP timeout default). When the timeout fires:
103
103
 
104
- - The parked permission Promise resolves with
105
- `{ behavior: 'deny', message: 'Tool approval timed out.', interrupt: true }`, killing the underlying Claude
106
- subprocess.
104
+ - The parked `PreToolUse` hook Promise resolves with `permissionDecision: 'deny'` plus `decision: 'block'` so the
105
+ agentic loop terminates instead of letting the model retry the timed-out call.
107
106
  - An `error` event with `code: 'tool-approval-timeout'` is emitted on the consumer's currently-active per-turn stream,
108
107
  then that stream ends.
109
108
  - Any subsequent `approveToolCall` / `declineToolCall` for the timed-out tool throws because the pending approval is no
@@ -1,6 +1,19 @@
1
1
  import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';
2
- import type { ChatEvent, MessagePart } from '@salesforce/sfdx-agent-sdk';
2
+ import type { ChatEvent, McpToolAnnotations, MessagePart } from '@salesforce/sfdx-agent-sdk';
3
3
  import type { LogBus } from '@salesforce/agentic-common';
4
+ /**
5
+ * Resolves the originating MCP server name and (optional) annotations for a
6
+ * Claude-namespaced tool name (`mcp__<server>__<tool>`). Returns `undefined`
7
+ * for non-MCP tools (built-ins like `Bash`, in-process bridges that aren't in
8
+ * the host-owned MCP catalog) so the adapter leaves both fields off the
9
+ * emitted ChatEvent — matching Mastra's shape on consumer-declared / workspace
10
+ * tools. See `claude-harness.ts` → `lookupMcpToolMetadata` for the wiring
11
+ * site.
12
+ */
13
+ export type McpToolMetadataLookup = (toolName: string) => {
14
+ serverName: string;
15
+ annotations?: McpToolAnnotations;
16
+ } | undefined;
4
17
  export declare class ClaudeEventAdapter {
5
18
  private started;
6
19
  private stepIndex;
@@ -20,7 +33,8 @@ export declare class ClaudeEventAdapter {
20
33
  */
21
34
  private deferredStepFinish?;
22
35
  private readonly logBus?;
23
- constructor(logBus?: LogBus);
36
+ private readonly lookupMcpToolMetadata?;
37
+ constructor(logBus?: LogBus, lookupMcpToolMetadata?: McpToolMetadataLookup);
24
38
  mapMessage(msg: SDKMessage): ChatEvent[];
25
39
  /**
26
40
  * Native (non-MCP) tool results arrive on `user`-typed SDKMessages whose
@@ -33,6 +47,16 @@ export declare class ClaudeEventAdapter {
33
47
  private mapStreamEvent;
34
48
  private mapContentBlockStart;
35
49
  private mapContentBlockStop;
50
+ /**
51
+ * Looks up the originating MCP server name and (optional) annotations for
52
+ * a tool name and returns them in the shape consumers spread onto a
53
+ * tool-call / tool-result / tool-approval-request ChatEvent. When no
54
+ * lookup is wired (e.g. unit tests that construct the adapter without
55
+ * one) or the tool is not in the agent's MCP catalog (built-ins,
56
+ * in-process bridges, consumer-declared tools), returns an empty object
57
+ * so the spread is a no-op and both fields stay `undefined`.
58
+ */
59
+ private enrichmentFor;
36
60
  private mapMessageDelta;
37
61
  /**
38
62
  * Decrement the outstanding-tool-result set for `toolCallId` and, when
@@ -21,8 +21,10 @@ export class ClaudeEventAdapter {
21
21
  */
22
22
  deferredStepFinish;
23
23
  logBus;
24
- constructor(logBus) {
24
+ lookupMcpToolMetadata;
25
+ constructor(logBus, lookupMcpToolMetadata) {
25
26
  this.logBus = logBus;
27
+ this.lookupMcpToolMetadata = lookupMcpToolMetadata;
26
28
  }
27
29
  mapMessage(msg) {
28
30
  const events = [];
@@ -66,6 +68,7 @@ export class ClaudeEventAdapter {
66
68
  toolName,
67
69
  result: block.content,
68
70
  isError: block.is_error,
71
+ ...this.enrichmentFor(toolName),
69
72
  });
70
73
  this.consumePendingToolResult(block.tool_use_id, events);
71
74
  }
@@ -133,6 +136,7 @@ export class ClaudeEventAdapter {
133
136
  toolName,
134
137
  result: block.content,
135
138
  isError: block.is_error,
139
+ ...this.enrichmentFor(toolName),
136
140
  });
137
141
  this.consumePendingToolResult(block.tool_use_id, events);
138
142
  }
@@ -157,8 +161,27 @@ export class ClaudeEventAdapter {
157
161
  toolCallId: pending.id,
158
162
  toolName: pending.name,
159
163
  args,
164
+ ...this.enrichmentFor(pending.name),
160
165
  });
161
166
  }
167
+ /**
168
+ * Looks up the originating MCP server name and (optional) annotations for
169
+ * a tool name and returns them in the shape consumers spread onto a
170
+ * tool-call / tool-result / tool-approval-request ChatEvent. When no
171
+ * lookup is wired (e.g. unit tests that construct the adapter without
172
+ * one) or the tool is not in the agent's MCP catalog (built-ins,
173
+ * in-process bridges, consumer-declared tools), returns an empty object
174
+ * so the spread is a no-op and both fields stay `undefined`.
175
+ */
176
+ enrichmentFor(toolName) {
177
+ const metadata = this.lookupMcpToolMetadata?.(toolName);
178
+ if (!metadata)
179
+ return {};
180
+ return {
181
+ serverName: metadata.serverName,
182
+ ...(metadata.annotations ? { annotations: metadata.annotations } : {}),
183
+ };
184
+ }
162
185
  mapMessageDelta(event, events) {
163
186
  const stepFinish = {
164
187
  type: 'step-finish',
@@ -1 +1 @@
1
- {"version":3,"file":"claude-event-adapter.js","sourceRoot":"","sources":["../src/claude-event-adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,MAAM,OAAO,kBAAkB;IACnB,OAAO,GAAG,KAAK,CAAC;IAChB,SAAS,GAAG,CAAC,CAAC;IACd,gBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;IACtD,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAClD;;;;;OAKG;IACK,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9C;;;;OAIG;IACK,kBAAkB,CAAmB;IAC5B,MAAM,CAAU;IAEjC,YAAY,MAAe;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,UAAU,CAAC,GAAe;QACtB,MAAM,MAAM,GAAgB,EAAE,CAAC;QAE/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;QAED,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAC9B,IAAI,CAAC,cAAc,CAAC,GAAyB,EAAE,MAAM,CAAC,CAAC;QAC3D,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,M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BACD,MAAM;YACV,KAAK,aAAa;gBACd,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;oBACpB,KAAK,CAAC,IAAI,CAAC;wBACP,IAAI,EAAE,aAAa;wBACnB,UAAU,EAAE,KAAK,CAAC,WAAW;wBAC7B,QAAQ,EAAE,EAAE;wBACZ,MAAM,EAAE,KAAK,CAAC,OAAO;qBACxB,CAAC,CAAC;gBACP,CAAC;gBACD,MAAM;YACV;gBACI,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAC9D,CAAC"}
@@ -144,6 +144,21 @@ export declare class ClaudeHarness implements AgentHarness {
144
144
  * non-empty paths.
145
145
  */
146
146
  private destroyThreadBestEffort;
147
+ /**
148
+ * Pattern of upstream-Bedrock SSE-truncation strings the gateway
149
+ * occasionally surfaces as the assistant's `result.result` text instead
150
+ * of throwing. Observed empirically against the Salesforce LLM Gateway's
151
+ * Bedrock-Claude path: the same string also surfaces as a late-throw on
152
+ * the chat-stream path (see PR #424). When `summarize()` sees this
153
+ * pattern in the result body it retries instead of returning the error
154
+ * string verbatim as the "summary."
155
+ *
156
+ * Temporary workaround for an upstream LLM Gateway regression (#396 /
157
+ * #453 / #479). Remove together with the `stream()` post-finish
158
+ * swallow once the gateway team confirms the trailing-JSON shape is
159
+ * fixed end-to-end — cleanup tracked by #474.
160
+ */
161
+ private static readonly UPSTREAM_TRUNCATION_PATTERN;
147
162
  /**
148
163
  * Issue a single non-agentic model call (`maxTurns: 1`) for one-shot
149
164
  * summarization. Used internally by `compactThread()`; not part of the
@@ -154,6 +169,14 @@ export declare class ClaudeHarness implements AgentHarness {
154
169
  * don't want the summary call leaking into the harness store.
155
170
  * - no MCP servers, no consumer tools, no rules append, no
156
171
  * `canUseTool` broker — the task is text-in / text-out.
172
+ *
173
+ * Retries up to 2 times on the upstream Bedrock SSE-truncation pattern
174
+ * (see {@link UPSTREAM_TRUNCATION_PATTERN}). The Salesforce LLM Gateway's
175
+ * Bedrock-Claude path occasionally returns a successful `result` whose
176
+ * body is the upstream truncation error string rather than a real
177
+ * summary; without retry the harness would happily seed the new thread
178
+ * with that error string. Each retry uses a fresh ephemeral session id
179
+ * and fresh `query()` invocation.
157
180
  */
158
181
  private summarize;
159
182
  /**
@@ -166,12 +189,26 @@ export declare class ClaudeHarness implements AgentHarness {
166
189
  stream(agentId: string, threadId: string, message: string, streamOptions?: StreamOptions): Promise<ChatStreamResult>;
167
190
  /**
168
191
  * Build the per-stream MCP bridge configs the Claude subprocess will
169
- * receive on `query({ options.mcpServers })`. Each entry wraps a
170
- * host-owned `Client` in a fresh `McpServer` instance whose `tools/list`
171
- * returns the cached catalog and whose `tools/call` forwards into the
172
- * client. Only `Connected` servers contribute — `Connecting` and `Error`
173
- * servers are skipped so the model doesn't see tools we can't actually
174
- * invoke yet (or at all).
192
+ * receive on `query({ options.mcpServers })`. Each external-server
193
+ * entry wraps a host-owned `Client` in a fresh `McpServer` instance
194
+ * whose `tools/list` returns the cached catalog and whose `tools/call`
195
+ * forwards into the client. Only `Connected` external servers contribute
196
+ * — `Connecting` and `Error` servers are skipped so the model doesn't
197
+ * see tools we can't actually invoke yet (or at all).
198
+ *
199
+ * When `config.skills` produced a non-empty skill catalog at
200
+ * `createAgent` time, the in-process `skill_bridge` SDK MCP server is
201
+ * appended to the map so `mcp__skill_bridge__load_skill` enters the
202
+ * model's tool surface. The skill server has no transport — it lives
203
+ * entirely in the harness process and is GC-collected when the
204
+ * `query()` invocation finishes. See `claude-skill-mcp-server.ts` for
205
+ * the rationale.
206
+ *
207
+ * When `consumerToolsBridge` is supplied (per-stream), it's appended
208
+ * under its own server name so consumer-declared `AgentConfig.tools`
209
+ * surface as `mcp__<consumer_tools>__<tool>` to the model. Built via
210
+ * `claude-consumer-tool-bridge.ts`; settled by the per-stream
211
+ * `ConsumerToolBroker` when `submitToolResult()` is called.
175
212
  */
176
213
  private buildBridgeConfigsForStream;
177
214
  /**
@@ -14,6 +14,8 @@ import { ConsumerToolBroker } from './consumer-tool-broker.js';
14
14
  import { buildMcpClients, hasEnabledServers } from './mcp-client-factory.js';
15
15
  import { buildMcpErrorDetail, sanitizeMcpErrorMessage } from './mcp-error-classifier.js';
16
16
  import { composeRulesAppend } from './rule-composer.js';
17
+ import { buildSkillMap } from './skill-loader.js';
18
+ import { buildSkillMcpServer } from './claude-skill-mcp-server.js';
17
19
  import { DiskBackedSessionStore } from './disk-backed-session-store.js';
18
20
  import { ThreadContextStore } from './thread-context-store.js';
19
21
  import { teeTextStream } from './text-stream.js';
@@ -121,6 +123,12 @@ export class ClaudeHarness {
121
123
  // `config` (not folded into it) so consumer-facing `getAgentConfig()`
122
124
  // keeps reflecting what was passed in.
123
125
  const rulesAppend = await composeRulesAppend(config.rules);
126
+ // Build the skill catalog eagerly for the same reason — a typo in
127
+ // `config.skills` should reject createAgent loud at registration
128
+ // time rather than silently dropping the skill on every turn. The
129
+ // logBus surfaces collision warnings (first-writer-wins is by
130
+ // design; silent drops would burn debugging time).
131
+ const skillMap = await buildSkillMap(config.skills, this.buses.getLogBus());
124
132
  // Resolve symlinks once at registration so the host-side projectRoot
125
133
  // matches whatever the Claude SDK realpath-resolves the subprocess cwd
126
134
  // to. Without this, macOS's `/var → /private/var` symlink causes the
@@ -201,6 +209,7 @@ export class ClaudeHarness {
201
209
  projectRoot: resolvedProjectRoot,
202
210
  config,
203
211
  rulesAppend,
212
+ skillMap,
204
213
  modelId: llmGatewayClient.getModel().name,
205
214
  threads,
206
215
  mcpServers,
@@ -559,6 +568,21 @@ export class ClaudeHarness {
559
568
  ?.warn(`Best-effort destroyThread failed during compactThread for thread "${threadId}" on agent "${agentId}": ${getErrorMessage(err)}`, { agentId, threadId }, err instanceof Error ? err : new Error(String(err)));
560
569
  }
561
570
  }
571
+ /**
572
+ * Pattern of upstream-Bedrock SSE-truncation strings the gateway
573
+ * occasionally surfaces as the assistant's `result.result` text instead
574
+ * of throwing. Observed empirically against the Salesforce LLM Gateway's
575
+ * Bedrock-Claude path: the same string also surfaces as a late-throw on
576
+ * the chat-stream path (see PR #424). When `summarize()` sees this
577
+ * pattern in the result body it retries instead of returning the error
578
+ * string verbatim as the "summary."
579
+ *
580
+ * Temporary workaround for an upstream LLM Gateway regression (#396 /
581
+ * #453 / #479). Remove together with the `stream()` post-finish
582
+ * swallow once the gateway team confirms the trailing-JSON shape is
583
+ * fixed end-to-end — cleanup tracked by #474.
584
+ */
585
+ static UPSTREAM_TRUNCATION_PATTERN = /API Error: Truncated event message received\.?/i;
562
586
  /**
563
587
  * Issue a single non-agentic model call (`maxTurns: 1`) for one-shot
564
588
  * summarization. Used internally by `compactThread()`; not part of the
@@ -569,6 +593,14 @@ export class ClaudeHarness {
569
593
  * don't want the summary call leaking into the harness store.
570
594
  * - no MCP servers, no consumer tools, no rules append, no
571
595
  * `canUseTool` broker — the task is text-in / text-out.
596
+ *
597
+ * Retries up to 2 times on the upstream Bedrock SSE-truncation pattern
598
+ * (see {@link UPSTREAM_TRUNCATION_PATTERN}). The Salesforce LLM Gateway's
599
+ * Bedrock-Claude path occasionally returns a successful `result` whose
600
+ * body is the upstream truncation error string rather than a real
601
+ * summary; without retry the harness would happily seed the new thread
602
+ * with that error string. Each retry uses a fresh ephemeral session id
603
+ * and fresh `query()` invocation.
572
604
  */
573
605
  async summarize(agent, prompt) {
574
606
  if (!agent.config.orgJwt) {
@@ -589,34 +621,58 @@ export class ClaudeHarness {
589
621
  'Preserve numeric values, dates, and proper names verbatim. ' +
590
622
  'Do not invent details that are not present in the transcript.',
591
623
  };
592
- const options = this.optionsBuilder.build(agent.projectRoot, summaryConfig, { maxSteps: 1 }, env, undefined, nativeModelId, undefined, undefined, undefined);
593
- // Override post-build: ephemeral session, no persistence, no
594
- // sessionStore (rejected together with persistSession:false).
595
- options.persistSession = false;
596
- delete options.sessionStore;
597
- delete options.resume;
598
- delete options.sessionId;
599
- const summaryQuery = query({ prompt, options: options });
600
- let resultText;
601
- try {
602
- for await (const msg of summaryQuery) {
603
- if (msg.type === 'result' && msg.subtype === 'success') {
604
- resultText = msg.result;
624
+ const buildOptions = () => {
625
+ const options = this.optionsBuilder.build(agent.projectRoot, summaryConfig, { maxSteps: 1 }, env, undefined, nativeModelId, undefined, undefined, undefined);
626
+ // Override post-build: ephemeral session, no persistence, no
627
+ // sessionStore (rejected together with persistSession:false).
628
+ options.persistSession = false;
629
+ delete options.sessionStore;
630
+ delete options.resume;
631
+ delete options.sessionId;
632
+ return options;
633
+ };
634
+ const MAX_ATTEMPTS = 3;
635
+ let lastFailureReason;
636
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
637
+ const summaryQuery = query({ prompt, options: buildOptions() });
638
+ let resultText;
639
+ let upstreamThrow;
640
+ try {
641
+ for await (const msg of summaryQuery) {
642
+ if (msg.type === 'result' && msg.subtype === 'success') {
643
+ resultText = msg.result;
644
+ }
605
645
  }
606
646
  }
607
- }
608
- finally {
609
- try {
610
- summaryQuery.close?.();
647
+ catch (err) {
648
+ upstreamThrow = err;
611
649
  }
612
- catch {
613
- /* iterator already closed */
650
+ finally {
651
+ try {
652
+ summaryQuery.close?.();
653
+ }
654
+ catch {
655
+ /* iterator already closed */
656
+ }
614
657
  }
658
+ const truncatedThrow = upstreamThrow !== undefined &&
659
+ ClaudeHarness.UPSTREAM_TRUNCATION_PATTERN.test(getErrorMessage(upstreamThrow));
660
+ const truncatedBody = resultText !== undefined && ClaudeHarness.UPSTREAM_TRUNCATION_PATTERN.test(resultText);
661
+ if (truncatedThrow || truncatedBody) {
662
+ lastFailureReason = truncatedThrow
663
+ ? getErrorMessage(upstreamThrow)
664
+ : `result body was upstream truncation: ${resultText}`;
665
+ continue;
666
+ }
667
+ if (upstreamThrow !== undefined) {
668
+ throw upstreamThrow;
669
+ }
670
+ if (!resultText || resultText.length === 0) {
671
+ throw new Error('Summary call produced no result text');
672
+ }
673
+ return resultText;
615
674
  }
616
- if (!resultText || resultText.length === 0) {
617
- throw new Error('Summary call produced no result text');
618
- }
619
- return resultText;
675
+ throw new Error(`Summary call hit upstream Bedrock SSE truncation on all ${MAX_ATTEMPTS} attempts. Last failure: ${lastFailureReason}`);
620
676
  }
621
677
  /**
622
678
  * Two-pass summarization for transcripts above the char budget. The
@@ -651,7 +707,14 @@ export class ClaudeHarness {
651
707
  const contextConfig = pendingContext.length > 0
652
708
  ? { ...config, instructions: this.buildContextPrompt(config.instructions, pendingContext) }
653
709
  : config;
654
- const adapter = new ClaudeEventAdapter(this.buses.getLogBus());
710
+ // Closure over `agentState.mcpServers` so the adapter and broker can
711
+ // enrich `tool-call` / `tool-result` / `tool-approval-request` events
712
+ // with `serverName` + `annotations` for MCP-bridged tools (#466).
713
+ // Non-MCP tools (built-ins like `Bash`, the in-process
714
+ // `consumer_tools` / `skill_bridge` servers) return undefined and the
715
+ // events stay un-enriched, matching Mastra's shape on the same paths.
716
+ const lookup = (toolName) => lookupMcpToolMetadata(agentState.mcpServers, toolName);
717
+ const adapter = new ClaudeEventAdapter(this.buses.getLogBus(), lookup);
655
718
  const controller = new AbortController();
656
719
  let broker;
657
720
  if (streamOptions?.requireToolApproval) {
@@ -661,6 +724,7 @@ export class ClaudeHarness {
661
724
  adapter,
662
725
  toolApprovalTimeoutMs: this.toolApprovalTimeoutMs,
663
726
  abortController: controller,
727
+ lookupMcpToolMetadata: lookup,
664
728
  });
665
729
  this.brokers.set(key, broker);
666
730
  }
@@ -685,7 +749,7 @@ export class ClaudeHarness {
685
749
  // set; the bridge is plumbing the Claude subprocess uses to reach
686
750
  // those clients via in-process JSON-RPC.
687
751
  const bridgeConfigs = this.buildBridgeConfigsForStream(agentState, consumerToolsBridge);
688
- const options = this.optionsBuilder.build(projectRoot, contextConfig, streamOptions, env, sessionOptions, nativeModelId, broker?.canUseTool, bridgeConfigs, rulesAppend.length > 0 ? rulesAppend : undefined);
752
+ const options = this.optionsBuilder.build(projectRoot, contextConfig, streamOptions, env, sessionOptions, nativeModelId, broker?.preToolUseHook, bridgeConfigs, rulesAppend.length > 0 ? rulesAppend : undefined);
689
753
  options.abortController = controller;
690
754
  // Mirror subprocess writes into the harness-owned store. With this
691
755
  // set, the host-side `getSessionMessages` / `deleteSession` calls
@@ -750,13 +814,45 @@ export class ClaudeHarness {
750
814
  })();
751
815
  return teeTextStream(consumerToolBroker.initialSink().generator());
752
816
  }
817
+ const logBus = this.buses.getLogBus();
753
818
  async function* eventStream() {
819
+ let terminalEmitted = false;
754
820
  try {
755
821
  for await (const msg of queryResult) {
756
- yield* adapter.mapMessage(msg);
822
+ for (const event of adapter.mapMessage(msg)) {
823
+ if (event.type === 'finish') {
824
+ terminalEmitted = true;
825
+ }
826
+ yield event;
827
+ }
757
828
  }
758
829
  }
759
830
  catch (err) {
831
+ // The Salesforce LLM Gateway's Bedrock-Claude path
832
+ // (`/invoke-with-response-stream`) intermittently appends a
833
+ // JSON error envelope after the terminal eventstream frame
834
+ // on otherwise-successful responses. The Anthropic SDK's
835
+ // strict eventstream parser then reads the trailing bytes
836
+ // as a multi-GB frame length and throws "Truncated event
837
+ // message received" AFTER the success `result` message has
838
+ // been delivered and a terminal `finish` ChatEvent has
839
+ // already been yielded downstream. Re-yielding error +
840
+ // finish('error') here would violate the SDK invariant
841
+ // ("exactly one terminal FinishEvent per chat turn") and
842
+ // surface the turn as `chat-stream-error` instead of
843
+ // `chat-stream-completed`. Swallow tear-down noise that
844
+ // arrives after the terminal finish.
845
+ // See https://github.com/forcedotcom/agentic-dx/issues/396
846
+ // (originally fixed by #424, reverted in #448 when the
847
+ // gateway team declared the fix shipped, regressed again
848
+ // in late May 2026 with a trailing-JSON shape the original
849
+ // fix happens to also cover).
850
+ if (terminalEmitted) {
851
+ logBus?.warn('Claude harness swallowed post-finish stream error', {
852
+ error: err instanceof Error ? err.message : String(err),
853
+ });
854
+ return;
855
+ }
760
856
  if (controller.signal.aborted) {
761
857
  // When the consumer-supplied AbortSignal fires, the
762
858
  // harness forwards it onto its local controller and the
@@ -781,12 +877,26 @@ export class ClaudeHarness {
781
877
  }
782
878
  /**
783
879
  * Build the per-stream MCP bridge configs the Claude subprocess will
784
- * receive on `query({ options.mcpServers })`. Each entry wraps a
785
- * host-owned `Client` in a fresh `McpServer` instance whose `tools/list`
786
- * returns the cached catalog and whose `tools/call` forwards into the
787
- * client. Only `Connected` servers contribute — `Connecting` and `Error`
788
- * servers are skipped so the model doesn't see tools we can't actually
789
- * invoke yet (or at all).
880
+ * receive on `query({ options.mcpServers })`. Each external-server
881
+ * entry wraps a host-owned `Client` in a fresh `McpServer` instance
882
+ * whose `tools/list` returns the cached catalog and whose `tools/call`
883
+ * forwards into the client. Only `Connected` external servers contribute
884
+ * — `Connecting` and `Error` servers are skipped so the model doesn't
885
+ * see tools we can't actually invoke yet (or at all).
886
+ *
887
+ * When `config.skills` produced a non-empty skill catalog at
888
+ * `createAgent` time, the in-process `skill_bridge` SDK MCP server is
889
+ * appended to the map so `mcp__skill_bridge__load_skill` enters the
890
+ * model's tool surface. The skill server has no transport — it lives
891
+ * entirely in the harness process and is GC-collected when the
892
+ * `query()` invocation finishes. See `claude-skill-mcp-server.ts` for
893
+ * the rationale.
894
+ *
895
+ * When `consumerToolsBridge` is supplied (per-stream), it's appended
896
+ * under its own server name so consumer-declared `AgentConfig.tools`
897
+ * surface as `mcp__<consumer_tools>__<tool>` to the model. Built via
898
+ * `claude-consumer-tool-bridge.ts`; settled by the per-stream
899
+ * `ConsumerToolBroker` when `submitToolResult()` is called.
790
900
  */
791
901
  buildBridgeConfigsForStream(agent, consumerToolsBridge) {
792
902
  const out = {};
@@ -799,6 +909,10 @@ export class ClaudeHarness {
799
909
  if (consumerToolsBridge) {
800
910
  out[CONSUMER_TOOLS_BRIDGE_SERVER_NAME] = consumerToolsBridge;
801
911
  }
912
+ const skillServer = buildSkillMcpServer(agent.skillMap);
913
+ if (skillServer) {
914
+ out[skillServer.name] = skillServer;
915
+ }
802
916
  return Object.keys(out).length > 0 ? out : undefined;
803
917
  }
804
918
  /**
@@ -1048,6 +1162,51 @@ export class ClaudeHarness {
1048
1162
  function isDisposedError(err) {
1049
1163
  return err instanceof AgentSDKError && err.type === AgentSDKErrorType.DISPOSED;
1050
1164
  }
1165
+ /**
1166
+ * Resolve the originating MCP server name and (optional) annotations for a
1167
+ * Claude-namespaced tool name (`mcp__<server>__<tool>`). Returns `undefined`
1168
+ * for tools that aren't in any MCP server's catalog (built-ins like `Bash`,
1169
+ * the in-process `consumer_tools` / `skill_bridge` SDK MCP servers, or any
1170
+ * tool name that doesn't carry the `mcp__` prefix).
1171
+ *
1172
+ * Selects the **longest matching prefix whose catalog actually contains the
1173
+ * tool**. The `__` separator makes single-underscore prefix collisions
1174
+ * impossible (`mcp__foo__` is not a prefix of `mcp__foo_extra__`), but a
1175
+ * server name that itself contains `__` does collide with a shorter sibling:
1176
+ * `mcp__foo__bar__baz` could come from server `foo` + tool `bar__baz` or
1177
+ * from server `foo__bar` + tool `baz`. The existence check on the
1178
+ * candidate's `tools` array picks the server that actually catalogs the
1179
+ * tool; the longest-prefix tiebreak handles the rarer case where both
1180
+ * legitimately catalog a tool that resolves to the same fully-namespaced
1181
+ * name.
1182
+ *
1183
+ * Mirrors `lookupMcpToolMetadata` in the Mastra harness so the cross-harness
1184
+ * `serverName` / `annotations` enrichment contract has identical observable
1185
+ * behavior on both harnesses.
1186
+ */
1187
+ function lookupMcpToolMetadata(mcpServers, namespacedToolName) {
1188
+ if (!namespacedToolName.startsWith('mcp__'))
1189
+ return undefined;
1190
+ let best;
1191
+ for (const [serverName, state] of mcpServers) {
1192
+ const prefix = `mcp__${serverName}__`;
1193
+ if (!namespacedToolName.startsWith(prefix))
1194
+ continue;
1195
+ const bareName = namespacedToolName.slice(prefix.length);
1196
+ const tool = state.tools.find((t) => t.name === bareName);
1197
+ if (!tool)
1198
+ continue;
1199
+ if (!best || serverName.length > best.serverName.length) {
1200
+ best = { serverName, tool };
1201
+ }
1202
+ }
1203
+ if (!best)
1204
+ return undefined;
1205
+ return {
1206
+ serverName: best.serverName,
1207
+ ...(best.tool.annotations ? { annotations: best.tool.annotations } : {}),
1208
+ };
1209
+ }
1051
1210
  /**
1052
1211
  * Race a promise against an `AbortSignal` so a wedged operation (e.g. a
1053
1212
  * stuck stdio MCP child during `connect()` or `listTools()`) cannot block