@subimpact/e 0.99.12 → 0.100.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/bundle/chunks/anthropic-messages-BGDBSRR2.js +6 -0
  3. package/dist/bundle/chunks/azure-openai-responses-ZCNWFVTX.js +2 -0
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +3 -3
  5. package/dist/bundle/chunks/chunk-35AZPBGE.js +11 -0
  6. package/dist/bundle/chunks/{chunk-C47CLQZK.js → chunk-CMZY6PM7.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-XVIZD2L5.js → chunk-DOSAFY5Y.js} +3 -3
  8. package/dist/bundle/chunks/{chunk-SVKJCAH2.js → chunk-FBZU53S6.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-GYREDKZT.js → chunk-HKQXO4IQ.js} +1 -1
  10. package/dist/bundle/chunks/chunk-K4O5WZC5.js +11 -0
  11. package/dist/bundle/chunks/{chunk-XZYVF4BW.js → chunk-QSDAQKAU.js} +53 -52
  12. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-NHSAQJW5.js → cloudflare-workers-ai-system-one-6FXZDK6A.js} +1 -1
  13. package/dist/bundle/chunks/github-copilot.js +1 -1
  14. package/dist/bundle/chunks/{google-generative-ai-ON7RPJHF.js → google-generative-ai-VJA5IOK3.js} +1 -1
  15. package/dist/bundle/chunks/{google-vertex-6YO5GV2H.js → google-vertex-TI6AJXT2.js} +1 -1
  16. package/dist/bundle/chunks/{mistral-conversations-NN33SMJ6.js → mistral-conversations-XTWEX6FG.js} +1 -1
  17. package/dist/bundle/chunks/openai-codex-responses-YOLBMQOC.js +10 -0
  18. package/dist/bundle/chunks/openai-completions-GXGEEHZH.js +7 -0
  19. package/dist/bundle/chunks/openai-responses-NLSL5UY4.js +3 -0
  20. package/dist/bundle/chunks/{typesafe-system-one-PRR5K6CI.js → typesafe-system-one-3OTHQPDL.js} +1 -1
  21. package/dist/bundle/chunks/{virtual-modules-6MDPJKNE.js → virtual-modules-YQUQNKDN.js} +1 -1
  22. package/dist/bundle/cli-runtime.js +1 -1
  23. package/dist/bundle/index.js +1 -1
  24. package/dist/bundle/rpc-entry.js +1 -1
  25. package/dist/core/agent-session.d.ts +13 -35
  26. package/dist/core/agent-session.d.ts.map +1 -1
  27. package/dist/core/agent-session.js +37 -145
  28. package/dist/core/agent-session.js.map +1 -1
  29. package/dist/core/compaction/compaction.js +2 -2
  30. package/dist/core/compaction/compaction.js.map +1 -1
  31. package/dist/core/extensions/compat-check.d.ts +26 -0
  32. package/dist/core/extensions/compat-check.d.ts.map +1 -0
  33. package/dist/core/extensions/compat-check.js +129 -0
  34. package/dist/core/extensions/compat-check.js.map +1 -0
  35. package/dist/core/extensions/index.d.ts +1 -1
  36. package/dist/core/extensions/index.d.ts.map +1 -1
  37. package/dist/core/extensions/index.js.map +1 -1
  38. package/dist/core/extensions/loader.d.ts.map +1 -1
  39. package/dist/core/extensions/loader.js +22 -0
  40. package/dist/core/extensions/loader.js.map +1 -1
  41. package/dist/core/extensions/types.d.ts +3 -49
  42. package/dist/core/extensions/types.d.ts.map +1 -1
  43. package/dist/core/extensions/types.js.map +1 -1
  44. package/dist/core/package-manager.d.ts +5 -0
  45. package/dist/core/package-manager.d.ts.map +1 -1
  46. package/dist/core/package-manager.js +34 -0
  47. package/dist/core/package-manager.js.map +1 -1
  48. package/dist/core/session-manager.d.ts.map +1 -1
  49. package/dist/core/session-manager.js +16 -2
  50. package/dist/core/session-manager.js.map +1 -1
  51. package/dist/index.d.ts +1 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js.map +1 -1
  54. package/dist/package-manager-cli.d.ts.map +1 -1
  55. package/dist/package-manager-cli.js +3 -0
  56. package/dist/package-manager-cli.js.map +1 -1
  57. package/package.json +1 -1
  58. package/dist/bundle/chunks/anthropic-messages-EGJT3PY6.js +0 -6
  59. package/dist/bundle/chunks/azure-openai-responses-JEEXH6HK.js +0 -2
  60. package/dist/bundle/chunks/chunk-IOJUMBW3.js +0 -11
  61. package/dist/bundle/chunks/chunk-KJUDFE6Y.js +0 -11
  62. package/dist/bundle/chunks/openai-codex-responses-CPSVXTKM.js +0 -10
  63. package/dist/bundle/chunks/openai-completions-T7GN33JE.js +0 -7
  64. package/dist/bundle/chunks/openai-responses-GPE3ZQ46.js +0 -3
@@ -133,12 +133,6 @@ export class AgentSession {
133
133
  _cwd;
134
134
  _extensionRunnerRef;
135
135
  _initialActiveToolNames;
136
- /**
137
- * Tools of the restored or reloaded loadout that are not registered yet. They are activated when
138
- * they are registered, and dropped when `setActiveToolsByName()` deactivates a tool or the next
139
- * agent run starts.
140
- */
141
- _pendingToolNames = new Set();
142
136
  _usesDefaultTools;
143
137
  _allowedToolNames;
144
138
  _excludedToolNames;
@@ -157,8 +151,6 @@ export class AgentSession {
157
151
  _toolRegistry = new Map();
158
152
  /** Created on the first `ctx.executeTool()` call. */
159
153
  _nestedToolCalls;
160
- /** Declared tools whose declarations requests leave out, from `prepareLoadout` hooks. */
161
- _hiddenDeclarations = new Set();
162
154
  _toolDefinitions = new Map();
163
155
  _toolPromptSnippets = new Map();
164
156
  _toolPromptGuidelines = new Map();
@@ -192,14 +184,13 @@ export class AgentSession {
192
184
  this._installAgentNextTurnRefresh();
193
185
  this._installAgentRequestProjection();
194
186
  this._installAgentBoundaryHooks();
195
- this._installHiddenDeclarationsProjection();
196
187
  this._installAgentForcedPromptProjection();
197
188
  this._buildRuntime({
198
189
  activeToolNames: this._initialActiveToolNames,
199
190
  includeAllExtensionTools: true,
200
191
  });
201
192
  if (this._initialActiveToolNames === undefined)
202
- this._restoreToolsFromTranscript();
193
+ this._restoreActiveTools();
203
194
  }
204
195
  get modelRuntime() {
205
196
  return this._modelRuntime;
@@ -535,7 +526,7 @@ export class AgentSession {
535
526
  toolSnippets: { ...this._baseSystemPromptOptions.toolSnippets, ...runOptions.toolSnippets },
536
527
  toolGuidelines: { ...this._baseSystemPromptOptions.toolGuidelines, ...runOptions.toolGuidelines },
537
528
  });
538
- const updateMessage = this._preparePromptAndToolLoadout(options, nextContext.messages);
529
+ const updateMessage = this._preparePromptUpdate(options, nextContext.messages);
539
530
  // Keep session.systemPrompt and ctx.getSystemPrompt() in step with what the provider sees.
540
531
  this._runSystemPromptOptions = options;
541
532
  return {
@@ -1063,7 +1054,6 @@ export class AgentSession {
1063
1054
  description: definition.description,
1064
1055
  parameters: definition.parameters,
1065
1056
  promptGuidelines: definition.promptGuidelines,
1066
- exposure: this._getToolExposure(definition.name),
1067
1057
  ...(definition.namespace ? { namespace: definition.namespace } : {}),
1068
1058
  ...(definition.annotations ? { annotations: { ...definition.annotations } } : {}),
1069
1059
  sourceInfo,
@@ -1079,82 +1069,29 @@ export class AgentSession {
1079
1069
  * Changes take effect on the next agent turn.
1080
1070
  */
1081
1071
  setActiveToolsByName(toolNames) {
1082
- const previous = this.getActiveToolNames();
1083
1072
  this._setActiveTools(toolNames);
1084
- // A loadout that deactivates a tool replaces the restored one, whose pending tools are dropped.
1085
- const active = new Set(this.getActiveToolNames());
1086
- if (previous.some((name) => !active.has(name)))
1087
- this._pendingToolNames.clear();
1088
1073
  }
1089
1074
  _setActiveTools(toolNames) {
1090
- const tools = this._applyToolLoadout(toolNames);
1091
- for (const tool of tools)
1092
- this._pendingToolNames.delete(tool.name);
1075
+ const tools = [];
1076
+ for (const name of [...new Set(toolNames)]) {
1077
+ const tool = this._toolRegistry.get(name);
1078
+ if (tool)
1079
+ tools.push(tool);
1080
+ }
1081
+ this.agent.state.tools = tools;
1093
1082
  this._rebuildSystemPrompt(tools.map((tool) => tool.name));
1094
1083
  }
1095
1084
  _isAllowedTool(name) {
1096
1085
  return (!this._allowedToolNames || this._allowedToolNames.has(name)) && !this._excludedToolNames?.has(name);
1097
1086
  }
1098
- _getToolExposure(name) {
1099
- return this._toolDefinitions.get(name)?.definition.exposure ?? "direct";
1100
- }
1101
- /** Tools callable through `ctx.executeTool()`: the active `direct` tools. */
1087
+ /** Tools callable through `ctx.executeTool()`: the active registered tools. */
1102
1088
  _getCallableTools(active = new Set(this.getActiveToolNames())) {
1103
- return [...this._toolRegistry.values()].filter((tool) => this._getToolExposure(tool.name) === "direct" && active.has(tool.name));
1089
+ return [...this._toolRegistry.values()].filter((tool) => active.has(tool.name));
1104
1090
  }
1105
1091
  /**
1106
- * Set the agent's tools for the given active tool names and return them. The active tools are
1107
- * the registered, non-hidden ones; they are declared to the model. Active tools with a
1108
- * `prepareLoadout` hook can change the declared descriptions and hide declarations from
1109
- * requests (see {@link _installHiddenDeclarationsProjection}).
1092
+ * Set the agent's tools for the given active tool names. The active tools are the registered
1093
+ * ones; they are the tools the model sees, full list, every request.
1110
1094
  */
1111
- _applyToolLoadout(toolNames) {
1112
- const tools = [...new Set(toolNames)].flatMap((name) => {
1113
- const tool = this._toolRegistry.get(name);
1114
- return tool && this._getToolExposure(name) !== "hidden" ? [tool] : [];
1115
- });
1116
- const hooks = tools.flatMap((tool) => {
1117
- const entry = this._toolDefinitions.get(tool.name);
1118
- return entry?.definition.prepareLoadout ? [entry] : [];
1119
- });
1120
- const hidden = new Set();
1121
- let declared = tools;
1122
- if (hooks.length > 0) {
1123
- const loadout = {
1124
- declared: tools,
1125
- callable: this._getCallableTools(new Set(tools.map((tool) => tool.name))),
1126
- registered: [...this._toolRegistry.values()],
1127
- getExposure: (name) => this._getToolExposure(name),
1128
- getNamespace: (name) => this._toolDefinitions.get(name)?.definition.namespace,
1129
- };
1130
- const descriptions = new Map();
1131
- for (const { definition, sourceInfo } of hooks) {
1132
- try {
1133
- const changes = definition.prepareLoadout?.(loadout);
1134
- for (const [name, description] of Object.entries(changes?.descriptions ?? {})) {
1135
- descriptions.set(name, description);
1136
- }
1137
- for (const name of changes?.hiddenDeclarations ?? [])
1138
- hidden.add(name);
1139
- }
1140
- catch (error) {
1141
- this._extensionRunner.emitError({
1142
- extensionPath: sourceInfo.path,
1143
- event: "prepare_loadout",
1144
- error: error instanceof Error ? error.message : String(error),
1145
- stack: error instanceof Error ? error.stack : undefined,
1146
- });
1147
- }
1148
- }
1149
- declared = tools.map((tool) => {
1150
- const description = descriptions.get(tool.name);
1151
- return description === undefined ? tool : { ...tool, description };
1152
- });
1153
- }
1154
- this._hiddenDeclarations = hidden;
1155
- this.agent.state.tools = declared;
1156
- return declared;
1157
- }
1158
1095
  /** Whether compaction or branch summarization is currently running */
1159
1096
  get isCompacting() {
1160
1097
  return (this._autoCompactionAbortController !== undefined ||
@@ -1224,8 +1161,7 @@ export class AgentSession {
1224
1161
  const toolSnippets = {};
1225
1162
  for (const name of this._toolRegistry.keys()) {
1226
1163
  const snippet = this._toolPromptSnippets.get(name);
1227
- // Tools without a snippet are not listed. Hidden tools are only callable through another tool.
1228
- if (snippet && !this._hiddenDeclarations.has(name))
1164
+ if (snippet)
1229
1165
  toolSnippets[name] = snippet;
1230
1166
  }
1231
1167
  const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
@@ -1245,19 +1181,17 @@ export class AgentSession {
1245
1181
  });
1246
1182
  }
1247
1183
  /**
1248
- * Apply a prompt and tool loadout for the next request. Sets the executable tools and
1249
- * returns a system message patching the prompt sections the model currently has (replayed
1250
- * from `messages`), or undefined when the prompt is unchanged. Tool changes are declared by
1251
- * the agent loop before the request.
1184
+ * Set the executable tools for the next request and returns a system message patching the
1185
+ * prompt sections the model currently has (replayed from `messages`), or undefined when the
1186
+ * prompt is unchanged. Tool changes are declared by the agent loop before the request.
1252
1187
  *
1253
1188
  * A forced prompt does not affect the transcript: the structured sections are still diffed
1254
1189
  * and persisted, and the forced text is projected onto the request by
1255
1190
  * {@link _installAgentForcedPromptProjection}.
1256
1191
  */
1257
- _preparePromptAndToolLoadout(options, messages = this.agent.state.messages) {
1258
- options.selectedTools = this._applyToolLoadout(options.selectedTools).map((tool) => tool.name);
1259
- // The tool list must match the declarations the request carries, so hidden tools are not listed.
1260
- options.toolSnippets = Object.fromEntries(Object.entries(options.toolSnippets).filter(([name]) => !this._hiddenDeclarations.has(name)));
1192
+ _preparePromptUpdate(options, messages = this.agent.state.messages) {
1193
+ this._setActiveTools(options.selectedTools);
1194
+ options.selectedTools = this.agent.state.tools.map((tool) => tool.name);
1261
1195
  const sections = diffSystemPromptSections(getCurrentSystemMessage(messages)?.sections ?? {}, buildSystemPromptSections(options));
1262
1196
  return sections ? { role: "system", content: "", sections, timestamp: Date.now() } : undefined;
1263
1197
  }
@@ -1268,35 +1202,8 @@ export class AgentSession {
1268
1202
  * head of the request; a mid-conversation system message would leave the original prompt
1269
1203
  * in place. The forced text is a rendering of the current prompt, so the transcript keeps
1270
1204
  * its structured sections and the request is projected instead: the system messages
1271
- * collapse into one head holding the forced text and the current tools. Runs after the
1272
- * `context` extension handlers.
1273
- */
1274
- /**
1275
- * Remove the declarations that `prepareLoadout` hooks hide from every request. The whole
1276
- * transcript is filtered with the current set, so the projected declarations stay consistent
1277
- * across requests and only change when the loadout does.
1205
+ * collapse into one head holding the forced text. Runs after the `context` extension handlers.
1278
1206
  */
1279
- _installHiddenDeclarationsProjection() {
1280
- const previousTransformContext = this.agent.transformContext;
1281
- this.agent.transformContext = async (messages, signal) => {
1282
- const transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;
1283
- const hidden = this._hiddenDeclarations;
1284
- if (hidden.size === 0)
1285
- return transformed;
1286
- return transformed.map((message) => {
1287
- if (message.role !== "system" || (!message.toolsAdded && !message.toolsRemoved))
1288
- return message;
1289
- const { toolsAdded, toolsRemoved, ...rest } = message;
1290
- const added = toolsAdded?.filter((tool) => !hidden.has(tool.name)) ?? [];
1291
- const removed = toolsRemoved?.filter((tool) => !hidden.has(tool.name)) ?? [];
1292
- return {
1293
- ...rest,
1294
- ...(added.length > 0 ? { toolsAdded: added } : {}),
1295
- ...(removed.length > 0 ? { toolsRemoved: removed } : {}),
1296
- };
1297
- });
1298
- };
1299
- }
1300
1207
  _installAgentForcedPromptProjection() {
1301
1208
  const previousTransformContext = this.agent.transformContext;
1302
1209
  this.agent.transformContext = async (messages, signal) => {
@@ -1308,25 +1215,23 @@ export class AgentSession {
1308
1215
  const head = {
1309
1216
  role: "system",
1310
1217
  content: forced,
1311
- ...(current?.toolsAdded ? { toolsAdded: current.toolsAdded } : {}),
1218
+ ...(current?.tools ? { tools: current.tools } : {}),
1312
1219
  timestamp: current?.timestamp ?? Date.now(),
1313
1220
  };
1314
1221
  return [head, ...transformed.filter((message) => message.role !== "system")];
1315
1222
  };
1316
1223
  }
1317
1224
  /**
1318
- * Restore the active tool loadout declared by the session transcript, if it declares one.
1319
- * Tools reachable only from other tools are never declared, but they do not depend on the active
1320
- * set, so the transcript's declarations are the whole loadout.
1225
+ * Restore the active tools declared by the session transcript, if it declares one. Tools that
1226
+ * register later are activated when they register; the transcript's snapshot only names the
1227
+ * active set.
1321
1228
  */
1322
- _restoreToolsFromTranscript() {
1323
- this._pendingToolNames.clear();
1229
+ _restoreActiveTools() {
1324
1230
  const current = getCurrentSystemMessage(this.sessionManager.buildSessionContext().messages);
1325
1231
  if (!current)
1326
1232
  return;
1327
- const names = (current.toolsAdded ?? []).map((tool) => tool.name);
1328
- this._pendingToolNames = new Set(names.filter((name) => this._isAllowedTool(name)));
1329
- this._setActiveTools(names);
1233
+ const names = current.tools?.map((tool) => tool.name) ?? [];
1234
+ this._setActiveTools(names.filter((name) => this._isAllowedTool(name)));
1330
1235
  }
1331
1236
  // =========================================================================
1332
1237
  // Prompting
@@ -1336,9 +1241,6 @@ export class AgentSession {
1336
1241
  // Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
1337
1242
  this._failedResponse = undefined;
1338
1243
  this._recordSelection();
1339
- // The run records the loadout in the transcript; restored tools that did not register by now
1340
- // are dropped, so a tool that never registers does not stay pending.
1341
- this._pendingToolNames.clear();
1342
1244
  this._isAgentRunActive = true;
1343
1245
  try {
1344
1246
  await this.agent.prompt(messages);
@@ -1577,7 +1479,7 @@ export class AgentSession {
1577
1479
  timestamp: Date.now(),
1578
1480
  });
1579
1481
  }
1580
- const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
1482
+ const updateMessage = this._preparePromptUpdate(result.systemPromptOptions);
1581
1483
  this._runSystemPromptOptions = result.systemPromptOptions;
1582
1484
  if (updateMessage)
1583
1485
  messages.unshift(updateMessage);
@@ -2759,8 +2661,8 @@ export class AgentSession {
2759
2661
  });
2760
2662
  }
2761
2663
  _refreshToolRegistry(options) {
2762
- // Tools that were already activated on registration. A tool whose exposure changes to
2763
- // `direct` or `model-only` (for example from `hidden`) is activated like a new tool.
2664
+ // Tools that were already activated on registration. A tool whose defaultActive changes to
2665
+ // active (for example from false) is activated like a new tool.
2764
2666
  const previousActivatedOnRegistration = new Set([...this._toolRegistry.keys()].filter((name) => this._isActivatedOnRegistration(name)));
2765
2667
  const previousActiveToolNames = this.getActiveToolNames();
2766
2668
  const allowedToolNames = this._allowedToolNames;
@@ -2819,9 +2721,8 @@ export class AgentSession {
2819
2721
  if (allowedToolNames) {
2820
2722
  for (const toolName of this._toolRegistry.keys()) {
2821
2723
  // Naming a tool activates it even when it is not active by default.
2822
- if (allowedToolNames.has(toolName) && this._isDeclarable(toolName)) {
2724
+ if (allowedToolNames.has(toolName))
2823
2725
  nextActiveToolNames.push(toolName);
2824
- }
2825
2726
  }
2826
2727
  }
2827
2728
  else if (options?.includeAllExtensionTools) {
@@ -2837,18 +2738,11 @@ export class AgentSession {
2837
2738
  }
2838
2739
  }
2839
2740
  }
2840
- // Pending tools that are registered now become active.
2841
- nextActiveToolNames.push(...this._pendingToolNames);
2842
2741
  this._setActiveTools([...new Set(nextActiveToolNames)]);
2843
2742
  }
2844
- /** Whether activating the tool declares it to the model. */
2845
- _isDeclarable(name) {
2846
- const exposure = this._getToolExposure(name);
2847
- return exposure === "direct" || exposure === "model-only";
2848
- }
2849
- /** Whether registering the tool activates it, which declares it to the model. */
2743
+ /** Whether registering the tool activates it. */
2850
2744
  _isActivatedOnRegistration(name) {
2851
- return this._isDeclarable(name) && this._toolDefinitions.get(name)?.definition.defaultActive !== false;
2745
+ return this._toolDefinitions.get(name)?.definition.defaultActive !== false;
2852
2746
  }
2853
2747
  _buildRuntime(options) {
2854
2748
  const autoResizeImages = this.settingsManager.getImageAutoResize();
@@ -2900,11 +2794,9 @@ export class AgentSession {
2900
2794
  const addedDefaultTools = this._usesDefaultTools
2901
2795
  ? (this.settingsManager.getDefaultTools() ?? DEFAULT_TOOL_NAMES).filter((name) => !previousDefaultTools.has(name))
2902
2796
  : [];
2903
- // Tools the new extensions register later are pending until then.
2904
- for (const name of this.getActiveToolNames())
2905
- this._pendingToolNames.add(name);
2797
+ const activeToolNames = [...this.getActiveToolNames(), ...addedDefaultTools];
2906
2798
  this._buildRuntime({
2907
- activeToolNames: [...this.getActiveToolNames(), ...addedDefaultTools],
2799
+ activeToolNames,
2908
2800
  flagValues: previousFlagValues,
2909
2801
  includeAllExtensionTools: true,
2910
2802
  });
@@ -3290,7 +3182,7 @@ export class AgentSession {
3290
3182
  }
3291
3183
  // Update finalized context from the canonical session projection.
3292
3184
  this._refreshFinalizedContext();
3293
- this._restoreToolsFromTranscript();
3185
+ this._restoreActiveTools();
3294
3186
  // Emit session_tree event
3295
3187
  await this._extensionRunner.emit({
3296
3188
  type: "session_tree",