@pwrdrvr/agent-acp 0.11.0 → 0.12.1

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/dist/index.d.ts CHANGED
@@ -212,6 +212,22 @@ declare function normalizeAcpRuntimeCapabilities(params: {
212
212
  initialize?: AcpRuntimeCapabilities;
213
213
  }): AcpRuntimeCapabilities | undefined;
214
214
  declare function acpRuntimeSupportsSessionLoad(capabilities: AcpRuntimeCapabilities | undefined): boolean;
215
+ /** The configOption an agent uses to expose model choice (ACP `category:
216
+ * "model"`, falling back to a literal `model` id). Some agents (e.g. Kimi)
217
+ * advertise the active model HERE rather than via top-level
218
+ * `models.currentModelId`. */
219
+ declare function modelConfigOption(capabilities: AcpRuntimeCapabilities | undefined): AcpRuntimeConfigOption | undefined;
220
+ /** The effective model id the agent will run with, agnostic of HOW it advertises
221
+ * it. Prefers a protocol-confirmed `models.currentModelId`; falls back to the
222
+ * `model` configOption's `currentValue` for agents that expose model choice as a
223
+ * config option (Kimi). Returns undefined when the agent advertises no model at
224
+ * all — callers report that as "no model" rather than inventing one. */
225
+ declare function modelIdFromCapabilities(capabilities: AcpRuntimeCapabilities | undefined): string | undefined;
226
+ /** The full model list a host can render/cache, agnostic of advertisement style.
227
+ * Returns `models.availableModels` when present; otherwise derives the list from
228
+ * the `model` configOption's values (Kimi), preserving labels/descriptions and
229
+ * flagging the current value as default. `[]` when no model is advertised. */
230
+ declare function modelsFromCapabilities(capabilities: AcpRuntimeCapabilities | undefined): AcpRuntimeModel[];
215
231
  declare function acpSessionRuntimeStateFromCapabilities(capabilities: AcpRuntimeCapabilities | undefined, now: number): AcpSessionRuntimeState | undefined;
216
232
  /** Runtime-state change carried inside a session/update (mode/model/config). */
217
233
  declare function acpSessionRuntimeStateFromUpdate(update: Record<string, unknown>, now: number): AcpSessionRuntimeState | undefined;
@@ -414,10 +430,16 @@ declare class AcpAgentClient implements AgentBackend {
414
430
  private handlePermissionRequest;
415
431
  private setRuntimeOption;
416
432
  private setRuntimeOptionOnTransport;
417
- /** Map a neutral `reasoning` token onto an ACP runtime option. We try to match
418
- * it to an available MODE (by id or label, case-insensitively) and switch via
419
- * `session/set_mode`. ACP has no first-class "reasoning effort" concept, so if
420
- * no mode matches we leave it alone — the caller's `.catch` debug-logs. */
433
+ /** Map a neutral `reasoning` token onto an ACP runtime option. ACP has no
434
+ * first-class "reasoning effort" concept, so we map it to whatever the agent
435
+ * exposes, in order:
436
+ * 1. An available MODE whose id/label matches the token (set_mode).
437
+ * 2. A "thinking" config option (`category: "thought_level"`, or id
438
+ * `thinking`) — map low-effort tokens to its OFF-like value and
439
+ * high-effort tokens to its ON-like value (set_config_option). This is
440
+ * what lets a one-shot enrichment turn ("low") disable a reasoning
441
+ * model's thinking pass, which is dramatically faster.
442
+ * If nothing matches we leave it alone — the caller's `.catch` debug-logs. */
421
443
  private applyReasoning;
422
444
  /** Read an image file and build an ACP `image` content block (base64 + inferred
423
445
  * mimeType). Throws on read failure; the caller catches + skips. */
@@ -429,6 +451,12 @@ declare class AcpAgentClient implements AgentBackend {
429
451
  /** Whether the agent advertises session/load support (for hosts that resume). */
430
452
  supportsSessionLoad(): boolean;
431
453
  }
454
+ /** Pick the value to set on a "thinking" config option for a neutral reasoning
455
+ * token: low-effort → the OFF-like value, high-effort → the ON-like value.
456
+ * Returns undefined when the token isn't an effort signal we recognize, or the
457
+ * option has no value of the needed polarity (caller leaves the option alone).
458
+ * Exported for testing. */
459
+ declare function reasoningValueForThoughtLevel(reasoning: string, values: ReadonlyArray<AcpRuntimeConfigOptionValue>): string | undefined;
432
460
 
433
461
  type AcpAgentClientFactory = () => AcpAgentClient;
434
462
  type AcpAgentClientPoolOptions = {
@@ -792,4 +820,4 @@ declare class AcpRegistryService {
792
820
  declare function evaluateAcpDistributionPolicy(distribution: AcpRegistryDistribution, allowlist: AcpAllowlistDecision): AcpDistributionPolicy;
793
821
  declare function normalizeRegistry(raw: unknown): AcpRegistryAgent[];
794
822
 
795
- export { ACP_REGISTRY_URL, AcpAgentAllowlist, type AcpAgentAllowlistRule, AcpAgentClient, type AcpAgentClientFactory, type AcpAgentClientOptions, AcpAgentClientPool, type AcpAgentClientPoolOptions, type AcpAgentConnection, type AcpAgentConnectionHandle, type AcpAgentInstanceSource, type AcpAgentQuirks, type AcpAgentStrategy, type AcpAllowlistDecision, type AcpApplyContext, type AcpBinaryPlatformDistribution, AcpConnection, type AcpConnectionOptions, type AcpDiscoveryProbe, type AcpDistributionKind, type AcpDistributionPolicy, type AcpJsonRpcTransport, type AcpMcpServerConfig, type AcpNormalizeResult, type AcpNormalizerOptions, AcpOneShotClient, type AcpOneShotClientOptions, type AcpOneShotRequest, type AcpOneShotResponse, type AcpPackageDistribution, type AcpPathExecutableLister, type AcpPromptContentBlock, type AcpRegistryAgent, type AcpRegistryAgentWithPolicy, type AcpRegistryAuthDescriptor, type AcpRegistryAuthMethod, type AcpRegistryDistribution, type AcpRegistryFetch, AcpRegistryService, type AcpRegistryServiceOptions, type AcpRegistrySnapshot, type AcpRuntimeAgentCapabilities, type AcpRuntimeAgentInfo, type AcpRuntimeCapabilities, type AcpRuntimeCapabilitiesHandler, type AcpRuntimeCapabilitiesSource, type AcpRuntimeConfigOption, type AcpRuntimeConfigOptionValue, type AcpRuntimeMode, type AcpRuntimeModel, type AcpRuntimeModels, type AcpRuntimeModes, type AcpRuntimeOptionSource, AcpSessionNormalizer, type AcpSessionRuntimeState, type AcpSpawnSpec, type AcpStartThreadOptions, type AcpStartTurnOptions, type AcpTitleHandler, type AcpVerificationStatus, BANNED_ACP_REGISTRY_IDS, BUILT_IN_ACP_STRATEGIES, DEFAULT_ACP_AGENT_ALLOWLIST, type DiscoveredAcpAgent, type DiscoveredAcpAgentGroup, type DiscoveredAcpAgentInstance, type LocalAcpAgentProbe, type LocalAcpDiscoveryOptions, type LocalAcpProbeResult, acpRuntimeSupportsSessionLoad, acpSessionRuntimeStateFromCapabilities, acpSessionRuntimeStateFromUpdate, asRecord, buildAcpBackendId, buildStrategyTable, defaultAcpAgentAllowlist, defaultQuirks, discoverLocalAcpAgentInstances, discoverLocalAcpAgents, evaluateAcpDistributionPolicy, geminiStrategy, grokStrategy, isBannedAcpRegistryId, kimiStrategy, mergeAcpRuntimeState, modeLabelFor, normalizeAcpRuntimeCapabilities, normalizeRegistry, qwenStrategy, readAcpContentText, readBoolean, readContentText, readFirstLocationPath, readFirstString, readKind, readNonEmptyString, readNumber, readPromptText, readString, readToolCallId, readToolContentText, readToolOutput, readUpdateText, strategyByBackendId, strategyById, toolCallFromUpdate, wellKnownAgentBinDirs };
823
+ export { ACP_REGISTRY_URL, AcpAgentAllowlist, type AcpAgentAllowlistRule, AcpAgentClient, type AcpAgentClientFactory, type AcpAgentClientOptions, AcpAgentClientPool, type AcpAgentClientPoolOptions, type AcpAgentConnection, type AcpAgentConnectionHandle, type AcpAgentInstanceSource, type AcpAgentQuirks, type AcpAgentStrategy, type AcpAllowlistDecision, type AcpApplyContext, type AcpBinaryPlatformDistribution, AcpConnection, type AcpConnectionOptions, type AcpDiscoveryProbe, type AcpDistributionKind, type AcpDistributionPolicy, type AcpJsonRpcTransport, type AcpMcpServerConfig, type AcpNormalizeResult, type AcpNormalizerOptions, AcpOneShotClient, type AcpOneShotClientOptions, type AcpOneShotRequest, type AcpOneShotResponse, type AcpPackageDistribution, type AcpPathExecutableLister, type AcpPromptContentBlock, type AcpRegistryAgent, type AcpRegistryAgentWithPolicy, type AcpRegistryAuthDescriptor, type AcpRegistryAuthMethod, type AcpRegistryDistribution, type AcpRegistryFetch, AcpRegistryService, type AcpRegistryServiceOptions, type AcpRegistrySnapshot, type AcpRuntimeAgentCapabilities, type AcpRuntimeAgentInfo, type AcpRuntimeCapabilities, type AcpRuntimeCapabilitiesHandler, type AcpRuntimeCapabilitiesSource, type AcpRuntimeConfigOption, type AcpRuntimeConfigOptionValue, type AcpRuntimeMode, type AcpRuntimeModel, type AcpRuntimeModels, type AcpRuntimeModes, type AcpRuntimeOptionSource, AcpSessionNormalizer, type AcpSessionRuntimeState, type AcpSpawnSpec, type AcpStartThreadOptions, type AcpStartTurnOptions, type AcpTitleHandler, type AcpVerificationStatus, BANNED_ACP_REGISTRY_IDS, BUILT_IN_ACP_STRATEGIES, DEFAULT_ACP_AGENT_ALLOWLIST, type DiscoveredAcpAgent, type DiscoveredAcpAgentGroup, type DiscoveredAcpAgentInstance, type LocalAcpAgentProbe, type LocalAcpDiscoveryOptions, type LocalAcpProbeResult, acpRuntimeSupportsSessionLoad, acpSessionRuntimeStateFromCapabilities, acpSessionRuntimeStateFromUpdate, asRecord, buildAcpBackendId, buildStrategyTable, defaultAcpAgentAllowlist, defaultQuirks, discoverLocalAcpAgentInstances, discoverLocalAcpAgents, evaluateAcpDistributionPolicy, geminiStrategy, grokStrategy, isBannedAcpRegistryId, kimiStrategy, mergeAcpRuntimeState, modeLabelFor, modelConfigOption, modelIdFromCapabilities, modelsFromCapabilities, normalizeAcpRuntimeCapabilities, normalizeRegistry, qwenStrategy, readAcpContentText, readBoolean, readContentText, readFirstLocationPath, readFirstString, readKind, readNonEmptyString, readNumber, readPromptText, readString, readToolCallId, readToolContentText, readToolOutput, readUpdateText, reasoningValueForThoughtLevel, strategyByBackendId, strategyById, toolCallFromUpdate, wellKnownAgentBinDirs };
package/dist/index.js CHANGED
@@ -61,6 +61,45 @@ function sanitizeInboundStream(source) {
61
61
  })
62
62
  );
63
63
  }
64
+ function rewriteOutboundAcpLine(line) {
65
+ if (line.trim().length === 0) return line;
66
+ let message;
67
+ try {
68
+ message = JSON.parse(line);
69
+ } catch {
70
+ return line;
71
+ }
72
+ if (!isPlainObject(message) || message.method !== "_session/set_config_option") {
73
+ return line;
74
+ }
75
+ message.method = "session/set_config_option";
76
+ return JSON.stringify(message);
77
+ }
78
+ function rewriteOutboundStream(target) {
79
+ const decoder = new TextDecoder();
80
+ const encoder = new TextEncoder();
81
+ let buffer = "";
82
+ const transform = new TransformStream({
83
+ transform(chunk, controller) {
84
+ buffer += decoder.decode(chunk, { stream: true });
85
+ let nl = buffer.indexOf("\n");
86
+ while (nl !== -1) {
87
+ const line = buffer.slice(0, nl);
88
+ buffer = buffer.slice(nl + 1);
89
+ controller.enqueue(encoder.encode(rewriteOutboundAcpLine(line) + "\n"));
90
+ nl = buffer.indexOf("\n");
91
+ }
92
+ },
93
+ flush(controller) {
94
+ if (buffer.length > 0) {
95
+ controller.enqueue(encoder.encode(rewriteOutboundAcpLine(buffer)));
96
+ buffer = "";
97
+ }
98
+ }
99
+ });
100
+ void transform.readable.pipeTo(target).catch(() => void 0);
101
+ return transform.writable;
102
+ }
64
103
  var AcpConnection = class {
65
104
  constructor(options) {
66
105
  this.options = options;
@@ -130,7 +169,9 @@ var AcpConnection = class {
130
169
  const line = chunk.toString("utf8").trimEnd();
131
170
  if (line.length > 0) logger.debug("acp agent stderr", { line });
132
171
  });
133
- const toAgentStdin = Writable.toWeb(child.stdin);
172
+ const toAgentStdin = rewriteOutboundStream(
173
+ Writable.toWeb(child.stdin)
174
+ );
134
175
  const fromAgentStdout = sanitizeInboundStream(
135
176
  Readable.toWeb(child.stdout)
136
177
  );
@@ -716,6 +757,26 @@ function normalizeAcpRuntimeCapabilities(params) {
716
757
  function acpRuntimeSupportsSessionLoad(capabilities) {
717
758
  return capabilities?.agentCapabilities?.loadSession !== false;
718
759
  }
760
+ function modelConfigOption(capabilities) {
761
+ return capabilities?.configOptions?.find(
762
+ (option) => option.category === "model" || option.id === "model"
763
+ );
764
+ }
765
+ function modelIdFromCapabilities(capabilities) {
766
+ return capabilities?.models?.currentModelId ?? modelConfigOption(capabilities)?.currentValue;
767
+ }
768
+ function modelsFromCapabilities(capabilities) {
769
+ const advertised = capabilities?.models?.availableModels;
770
+ if (advertised !== void 0 && advertised.length > 0) return advertised;
771
+ const option = modelConfigOption(capabilities);
772
+ if (option === void 0) return [];
773
+ return option.values.map((value) => ({
774
+ id: value.value,
775
+ ...value.label !== void 0 ? { label: value.label } : {},
776
+ ...value.description !== void 0 ? { description: value.description } : {},
777
+ ...option.currentValue === value.value ? { isDefault: true } : {}
778
+ }));
779
+ }
719
780
  function acpSessionRuntimeStateFromCapabilities(capabilities, now) {
720
781
  if (!capabilities) {
721
782
  return void 0;
@@ -1160,7 +1221,7 @@ var AcpAgentClient = class {
1160
1221
  resumed: options.bindThreadId !== void 0
1161
1222
  });
1162
1223
  const out = { threadId };
1163
- const model = runtimeCapabilities?.models?.currentModelId;
1224
+ const model = modelIdFromCapabilities(runtimeCapabilities);
1164
1225
  if (model !== void 0) out.model = model;
1165
1226
  out.modelProvider = this.strategy.id;
1166
1227
  return out;
@@ -1508,21 +1569,45 @@ var AcpAgentClient = class {
1508
1569
  modelId: value
1509
1570
  });
1510
1571
  }
1511
- /** Map a neutral `reasoning` token onto an ACP runtime option. We try to match
1512
- * it to an available MODE (by id or label, case-insensitively) and switch via
1513
- * `session/set_mode`. ACP has no first-class "reasoning effort" concept, so if
1514
- * no mode matches we leave it alone — the caller's `.catch` debug-logs. */
1572
+ /** Map a neutral `reasoning` token onto an ACP runtime option. ACP has no
1573
+ * first-class "reasoning effort" concept, so we map it to whatever the agent
1574
+ * exposes, in order:
1575
+ * 1. An available MODE whose id/label matches the token (set_mode).
1576
+ * 2. A "thinking" config option (`category: "thought_level"`, or id
1577
+ * `thinking`) — map low-effort tokens to its OFF-like value and
1578
+ * high-effort tokens to its ON-like value (set_config_option). This is
1579
+ * what lets a one-shot enrichment turn ("low") disable a reasoning
1580
+ * model's thinking pass, which is dramatically faster.
1581
+ * If nothing matches we leave it alone — the caller's `.catch` debug-logs. */
1515
1582
  async applyReasoning(threadId, reasoning) {
1516
- const modes = this.runtimeCapabilities?.modes?.availableModes ?? [];
1517
1583
  const target = reasoning.toLowerCase();
1518
- const match = modes.find(
1584
+ const modes = this.runtimeCapabilities?.modes?.availableModes ?? [];
1585
+ const modeMatch = modes.find(
1519
1586
  (mode) => mode.id.toLowerCase() === target || typeof mode.label === "string" && mode.label.toLowerCase() === target
1520
1587
  );
1521
- if (match === void 0) {
1522
- this.logger.debug("acp reasoning has no matching mode \u2014 ignored", { reasoning });
1588
+ if (modeMatch !== void 0) {
1589
+ await this.setMode(threadId, modeMatch.id);
1523
1590
  return;
1524
1591
  }
1525
- await this.setMode(threadId, match.id);
1592
+ const thinking = this.runtimeCapabilities?.configOptions?.find(
1593
+ (option) => option.category === "thought_level" || option.id === "thinking"
1594
+ );
1595
+ if (thinking !== void 0) {
1596
+ const value = reasoningValueForThoughtLevel(target, thinking.values);
1597
+ if (value === void 0) {
1598
+ this.logger.debug("acp reasoning has no matching thought-level value \u2014 ignored", {
1599
+ reasoning
1600
+ });
1601
+ return;
1602
+ }
1603
+ if (value !== thinking.currentValue) {
1604
+ await this.setConfigOption(threadId, thinking.id, value);
1605
+ }
1606
+ return;
1607
+ }
1608
+ this.logger.debug("acp reasoning has no matching mode or thought-level option \u2014 ignored", {
1609
+ reasoning
1610
+ });
1526
1611
  }
1527
1612
  /** Read an image file and build an ACP `image` content block (base64 + inferred
1528
1613
  * mimeType). Throws on read failure; the caller catches + skips. */
@@ -1555,7 +1640,7 @@ var AcpAgentClient = class {
1555
1640
  }
1556
1641
  emitThreadSettings(session, capabilities, runtimeState) {
1557
1642
  const settings = { threadId: session.threadId };
1558
- const model = runtimeState?.currentModelId ?? capabilities?.models?.currentModelId;
1643
+ const model = runtimeState?.currentModelId ?? modelIdFromCapabilities(capabilities);
1559
1644
  if (model !== void 0) settings.model = model;
1560
1645
  settings.modelProvider = this.strategy.id;
1561
1646
  const modeId = runtimeState?.currentModeId ?? capabilities?.modes?.currentModeId;
@@ -1578,6 +1663,38 @@ var AcpAgentClient = class {
1578
1663
  return acpRuntimeSupportsSessionLoad(this.runtimeCapabilities);
1579
1664
  }
1580
1665
  };
1666
+ var LOW_EFFORT_TOKENS = /* @__PURE__ */ new Set([
1667
+ "off",
1668
+ "none",
1669
+ "minimal",
1670
+ "min",
1671
+ "minimum",
1672
+ "low",
1673
+ "fast"
1674
+ ]);
1675
+ var HIGH_EFFORT_TOKENS = /* @__PURE__ */ new Set([
1676
+ "on",
1677
+ "high",
1678
+ "medium",
1679
+ "max",
1680
+ "maximum",
1681
+ "full",
1682
+ "think"
1683
+ ]);
1684
+ function thoughtLevelPolarity(value) {
1685
+ const haystack = `${value.value} ${value.label ?? ""}`.toLowerCase();
1686
+ if (/\b(off|none|disabled?|no)\b/.test(haystack)) return "off";
1687
+ if (/\b(on|enabled?|high|full|yes)\b/.test(haystack)) return "on";
1688
+ return "other";
1689
+ }
1690
+ function reasoningValueForThoughtLevel(reasoning, values) {
1691
+ const token = reasoning.toLowerCase();
1692
+ const wantOff = LOW_EFFORT_TOKENS.has(token);
1693
+ const wantOn = HIGH_EFFORT_TOKENS.has(token);
1694
+ if (!wantOff && !wantOn) return void 0;
1695
+ const desired = wantOff ? "off" : "on";
1696
+ return values.find((value) => thoughtLevelPolarity(value) === desired)?.value;
1697
+ }
1581
1698
  function buildApprovalRequest(args) {
1582
1699
  const toolCall = asRecord2(args.params.toolCall) ?? {};
1583
1700
  const title = typeof toolCall.title === "string" && toolCall.title.trim() ? toolCall.title.trim() : "ACP tool call";
@@ -1967,8 +2084,8 @@ var AcpOneShotClient = class {
1967
2084
  async listModelsInner() {
1968
2085
  let models = [];
1969
2086
  const unsubscribe = this.client.onRuntimeCapabilities((event) => {
1970
- const observed = event.runtimeCapabilities.models?.availableModels;
1971
- if (observed !== void 0 && observed.length > 0) models = observed;
2087
+ const observed = modelsFromCapabilities(event.runtimeCapabilities);
2088
+ if (observed.length > 0) models = observed;
1972
2089
  });
1973
2090
  try {
1974
2091
  await this.client.startThread();
@@ -2692,6 +2809,9 @@ export {
2692
2809
  kimiStrategy,
2693
2810
  mergeAcpRuntimeState,
2694
2811
  modeLabelFor,
2812
+ modelConfigOption,
2813
+ modelIdFromCapabilities,
2814
+ modelsFromCapabilities,
2695
2815
  normalizeAcpRuntimeCapabilities,
2696
2816
  normalizeRegistry,
2697
2817
  qwenStrategy,
@@ -2709,6 +2829,7 @@ export {
2709
2829
  readToolContentText,
2710
2830
  readToolOutput,
2711
2831
  readUpdateText,
2832
+ reasoningValueForThoughtLevel,
2712
2833
  strategyByBackendId,
2713
2834
  strategyById,
2714
2835
  toolCallFromUpdate,