@wrongstack/core 0.313.0 → 0.313.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.
Files changed (182) hide show
  1. package/dist/chronicle/index.js +84 -6391
  2. package/dist/chronicle/project-server.js +84 -4868
  3. package/dist/chunk-2BUUIMQB.js +225 -0
  4. package/dist/chunk-2FK4WTFF.js +207 -0
  5. package/dist/chunk-2FQL4PDC.js +292 -0
  6. package/dist/chunk-2KKODIQU.js +2256 -0
  7. package/dist/chunk-2YU4WVBW.js +134 -0
  8. package/dist/chunk-3E244UDA.js +356 -0
  9. package/dist/chunk-3XPVB7BA.js +135 -0
  10. package/dist/chunk-4LJJYBAU.js +388 -0
  11. package/dist/chunk-4VWO3ZXL.js +342 -0
  12. package/dist/chunk-4XV6IR37.js +187 -0
  13. package/dist/chunk-4ZHTKJHM.js +183 -0
  14. package/dist/chunk-52RTVH4M.js +361 -0
  15. package/dist/chunk-57GEWK5X.js +26 -0
  16. package/dist/chunk-5DSMEVA4.js +931 -0
  17. package/dist/chunk-5RP3QTRL.js +1223 -0
  18. package/dist/chunk-5S437PRC.js +50 -0
  19. package/dist/chunk-5XDUGTKN.js +511 -0
  20. package/dist/chunk-62V2AFVG.js +422 -0
  21. package/dist/chunk-65RDIOR2.js +2470 -0
  22. package/dist/chunk-6AKOTGLM.js +597 -0
  23. package/dist/chunk-7ZHZE5EO.js +28 -0
  24. package/dist/chunk-A455ATZB.js +140 -0
  25. package/dist/chunk-AD7ZFZCS.js +46 -0
  26. package/dist/chunk-AI4LLQ2U.js +856 -0
  27. package/dist/chunk-ASX6AW36.js +789 -0
  28. package/dist/chunk-AT4V4XGI.js +3522 -0
  29. package/dist/chunk-AWNQ6ED6.js +311 -0
  30. package/dist/chunk-B4AMLZPB.js +9 -0
  31. package/dist/chunk-BAKVJLEV.js +417 -0
  32. package/dist/chunk-BJHVULHO.js +55 -0
  33. package/dist/chunk-CB2HFKTP.js +9 -0
  34. package/dist/chunk-CE4ZOCOI.js +1640 -0
  35. package/dist/chunk-CQQL4ZOQ.js +151 -0
  36. package/dist/chunk-DEIQMBD2.js +65 -0
  37. package/dist/chunk-E6I5RXVK.js +58 -0
  38. package/dist/chunk-EFEHDQGY.js +1589 -0
  39. package/dist/chunk-EODDVJBM.js +82 -0
  40. package/dist/chunk-EPC3GZD4.js +308 -0
  41. package/dist/chunk-FAYRX2AD.js +13 -0
  42. package/dist/chunk-FFSX2QDQ.js +362 -0
  43. package/dist/chunk-FHAMQS7Q.js +5856 -0
  44. package/dist/chunk-FIV4IJL7.js +2263 -0
  45. package/dist/chunk-FNXVT7HF.js +52 -0
  46. package/dist/chunk-FSWCWSTS.js +395 -0
  47. package/dist/chunk-FW5LDDMJ.js +16464 -0
  48. package/dist/chunk-FXQLIX3K.js +211 -0
  49. package/dist/chunk-G5AAKEEZ.js +228 -0
  50. package/dist/chunk-G5S3S5ZN.js +38 -0
  51. package/dist/chunk-GAZEWQEZ.js +231 -0
  52. package/dist/chunk-GFJOMSHG.js +125 -0
  53. package/dist/chunk-GFXZTHNI.js +158 -0
  54. package/dist/chunk-GM54GJBU.js +960 -0
  55. package/dist/chunk-GPQ3NJPR.js +900 -0
  56. package/dist/chunk-GTCU6DZ3.js +1 -0
  57. package/dist/chunk-H5E77KUJ.js +15 -0
  58. package/dist/chunk-H72H4XDU.js +1023 -0
  59. package/dist/chunk-HA4ZYA6T.js +178 -0
  60. package/dist/chunk-I45KAW2N.js +5020 -0
  61. package/dist/chunk-IQ35HMQL.js +1396 -0
  62. package/dist/chunk-IYFBFX34.js +86 -0
  63. package/dist/chunk-JJPMWPB6.js +109 -0
  64. package/dist/chunk-JTHKOYWU.js +663 -0
  65. package/dist/chunk-JVGPR3TS.js +365 -0
  66. package/dist/chunk-JVKB2TBL.js +48 -0
  67. package/dist/chunk-JX7VBZDK.js +31 -0
  68. package/dist/chunk-K3G6JBUC.js +5232 -0
  69. package/dist/chunk-K4YUNKU7.js +589 -0
  70. package/dist/chunk-KBZGE6LN.js +710 -0
  71. package/dist/chunk-KDQJCT2J.js +45 -0
  72. package/dist/chunk-KI4L2DUL.js +560 -0
  73. package/dist/chunk-KJ2ZTQSL.js +47 -0
  74. package/dist/chunk-KSJ5UTP7.js +154 -0
  75. package/dist/chunk-LHOA5DWA.js +28 -0
  76. package/dist/chunk-LX5QWLBL.js +27 -0
  77. package/dist/chunk-LZDDLNCZ.js +279 -0
  78. package/dist/chunk-M2WF6AXG.js +115 -0
  79. package/dist/chunk-M7BS2K6U.js +1 -0
  80. package/dist/chunk-NDBIPFNY.js +102 -0
  81. package/dist/chunk-NEMIWEXC.js +1199 -0
  82. package/dist/chunk-NFAYHPRH.js +323 -0
  83. package/dist/chunk-O37BQ65S.js +21 -0
  84. package/dist/chunk-O74MJHXU.js +187 -0
  85. package/dist/chunk-OJZEX73F.js +112 -0
  86. package/dist/chunk-PAAWLLZX.js +74 -0
  87. package/dist/chunk-PFXFQQRT.js +339 -0
  88. package/dist/chunk-PFZO3C6H.js +14 -0
  89. package/dist/chunk-PHH7LD45.js +113 -0
  90. package/dist/chunk-QRTG4XTI.js +188 -0
  91. package/dist/chunk-QVOVMXJR.js +1351 -0
  92. package/dist/chunk-RCQYT2I4.js +757 -0
  93. package/dist/chunk-RD6DEE36.js +1178 -0
  94. package/dist/chunk-RJIZEJ42.js +30 -0
  95. package/dist/chunk-RPOA7IAE.js +150 -0
  96. package/dist/chunk-SN2DQRL6.js +1172 -0
  97. package/dist/chunk-SQJVFEBV.js +41 -0
  98. package/dist/chunk-SQP64RCS.js +5391 -0
  99. package/dist/chunk-SVT4RNTR.js +49 -0
  100. package/dist/chunk-SWUFN7XM.js +43 -0
  101. package/dist/chunk-SXMVYC5H.js +174 -0
  102. package/dist/chunk-SZ6AYUIZ.js +23 -0
  103. package/dist/chunk-T3KGZBU5.js +3171 -0
  104. package/dist/chunk-TBRL2RCC.js +9 -0
  105. package/dist/chunk-TRT2HRWZ.js +18 -0
  106. package/dist/chunk-TYW2GI5I.js +1077 -0
  107. package/dist/chunk-UIWONWVG.js +4959 -0
  108. package/dist/chunk-VB3H5WWB.js +151 -0
  109. package/dist/chunk-W4A6QA3D.js +258 -0
  110. package/dist/chunk-WBPVKEEE.js +227 -0
  111. package/dist/chunk-WEBMSQP2.js +123 -0
  112. package/dist/chunk-WOEZV3Q4.js +333 -0
  113. package/dist/chunk-WQQON3SV.js +473 -0
  114. package/dist/chunk-WQTOVMGV.js +119 -0
  115. package/dist/chunk-WZO23AWO.js +2779 -0
  116. package/dist/chunk-XBDP4QPW.js +7 -0
  117. package/dist/chunk-XEBHSJLT.js +103 -0
  118. package/dist/chunk-XQ2ECNK3.js +1 -0
  119. package/dist/chunk-XQ2XGIBF.js +2086 -0
  120. package/dist/chunk-Y2GE5TSI.js +355 -0
  121. package/dist/chunk-YBUJCZ57.js +351 -0
  122. package/dist/chunk-YNCVSFGF.js +149 -0
  123. package/dist/chunk-YUPMXOGP.js +282 -0
  124. package/dist/chunk-YY6APYUM.js +49 -0
  125. package/dist/chunk-Z2IJUO45.js +691 -0
  126. package/dist/chunk-ZEHUCJHY.js +129 -0
  127. package/dist/chunk-ZYU2YOJ6.js +1496 -0
  128. package/dist/chunk-ZZ4V3WIZ.js +163 -0
  129. package/dist/coordination/agents/index.js +145 -6260
  130. package/dist/coordination/index.js +365 -34324
  131. package/dist/coordination/mailbox-project-server.js +48 -3276
  132. package/dist/coordination/provider-status-tracker.d.ts +4 -0
  133. package/dist/core/agent.d.ts +14 -1
  134. package/dist/core/index.js +267 -12480
  135. package/dist/core/model-ref.js +5 -23
  136. package/dist/core/provider-runner.d.ts +36 -1
  137. package/dist/design/index.js +50 -1087
  138. package/dist/execution/index.d.ts +1 -1
  139. package/dist/execution/index.js +1599 -21888
  140. package/dist/execution/prompt-enhancer.js +16 -535
  141. package/dist/execution/retry-policy.d.ts +31 -1
  142. package/dist/extension/index.js +7 -311
  143. package/dist/goal/index.js +33 -3435
  144. package/dist/hooks/index.js +14 -1138
  145. package/dist/hq/index.js +112 -5139
  146. package/dist/hq/protocol.js +21 -668
  147. package/dist/index.js +1410 -92656
  148. package/dist/infrastructure/index.js +64 -4811
  149. package/dist/kernel/events/provider-events.d.ts +15 -0
  150. package/dist/kernel/index.js +14 -992
  151. package/dist/models/index.js +40 -1117
  152. package/dist/notifications/index.js +3 -108
  153. package/dist/observability/index.js +17 -279
  154. package/dist/plugin/index.js +584 -14835
  155. package/dist/prompts/index.js +14 -948
  156. package/dist/registry/index.js +9 -822
  157. package/dist/registry-R23UBE7H.js +14 -0
  158. package/dist/replay/index.js +6 -84
  159. package/dist/review-finding-store-DKAV3AS6.js +21 -0
  160. package/dist/review-report-store-OWY3EC3N.js +19 -0
  161. package/dist/security/index.js +114 -2202
  162. package/dist/session-catalog/index.js +36 -2103
  163. package/dist/session-catalog/project-server.js +42 -1435
  164. package/dist/skills/index.js +35 -1578
  165. package/dist/storage/index.js +182 -15600
  166. package/dist/tasking/index.js +10 -676
  167. package/dist/tools/index.js +52 -9590
  168. package/dist/types/config/autonomy.d.ts +5 -0
  169. package/dist/types/config/ui.d.ts +1 -1
  170. package/dist/types/errors.d.ts +18 -0
  171. package/dist/types/index.js +121 -1342
  172. package/dist/types/provider-runner.d.ts +8 -0
  173. package/dist/types/session-markers.js +8 -144
  174. package/dist/utils/error.js +3 -4
  175. package/dist/utils/expect-defined.js +3 -9
  176. package/dist/utils/heap-watchdog.js +6 -706
  177. package/dist/utils/index.js +269 -5685
  178. package/dist/utils/sage-output-block.js +5 -42
  179. package/dist/wiring/proxy-rewrite.d.ts +18 -0
  180. package/dist/wiring/proxy-rewrite.js +18 -121
  181. package/dist/worktree/index.js +6 -887
  182. package/package.json +4 -4
@@ -0,0 +1,45 @@
1
+ // src/types/prompt.ts
2
+ var BUILTIN_PROMPT_CATEGORIES = [
3
+ "coding",
4
+ "debugging",
5
+ "refactoring",
6
+ "testing",
7
+ "code-review",
8
+ "architecture",
9
+ "devops",
10
+ "documentation",
11
+ "data-analysis",
12
+ "writing",
13
+ "research",
14
+ "product",
15
+ "agentic-workflows",
16
+ "meta-prompting",
17
+ "uncategorized"
18
+ ];
19
+ var PROMPT_CATEGORY_LABELS = {
20
+ coding: "Coding",
21
+ debugging: "Debugging",
22
+ refactoring: "Refactoring",
23
+ testing: "Testing",
24
+ "code-review": "Code Review",
25
+ architecture: "Architecture",
26
+ devops: "DevOps",
27
+ documentation: "Documentation",
28
+ "data-analysis": "Data Analysis",
29
+ writing: "Writing",
30
+ research: "Research",
31
+ product: "Product",
32
+ "agentic-workflows": "Agentic Workflows",
33
+ "meta-prompting": "Meta-Prompting",
34
+ uncategorized: "Uncategorized"
35
+ };
36
+ function isBuiltinCategory(value) {
37
+ return BUILTIN_PROMPT_CATEGORIES.includes(value);
38
+ }
39
+
40
+ export {
41
+ BUILTIN_PROMPT_CATEGORIES,
42
+ PROMPT_CATEGORY_LABELS,
43
+ isBuiltinCategory
44
+ };
45
+ //# sourceMappingURL=chunk-KDQJCT2J.js.map
@@ -0,0 +1,560 @@
1
+ import {
2
+ applyToolDescriptionModeToTool,
3
+ normalizeToolDescriptionMode
4
+ } from "./chunk-WQTOVMGV.js";
5
+ import {
6
+ estimateToolDefTokens
7
+ } from "./chunk-FSWCWSTS.js";
8
+ import {
9
+ ERROR_CODES,
10
+ WrongStackError
11
+ } from "./chunk-WOEZV3Q4.js";
12
+ import {
13
+ toErrorMessage
14
+ } from "./chunk-TBRL2RCC.js";
15
+
16
+ // src/registry/provider-registry.ts
17
+ var ProviderRegistry = class {
18
+ factories = /* @__PURE__ */ new Map();
19
+ /**
20
+ * Register a provider factory. If a factory with the same type already
21
+ * exists, it is replaced. Use this for both initial registration and
22
+ * runtime overrides (e.g. from plugins or CLI flags).
23
+ */
24
+ register(f) {
25
+ this.factories.set(f.type, f);
26
+ }
27
+ /**
28
+ * Bulk-register multiple provider factories at once.
29
+ */
30
+ registerAll(factories) {
31
+ for (const f of factories) this.register(f);
32
+ }
33
+ /**
34
+ * Override an existing factory. Throws if no factory is registered
35
+ * for the given type. Use this to safely replace a provider at runtime
36
+ * (e.g. in tests or when a plugin provides a custom implementation).
37
+ */
38
+ override(type, f) {
39
+ if (!this.factories.has(type)) {
40
+ throw new Error(`Provider type "${type}" not registered; cannot override`);
41
+ }
42
+ this.factories.set(type, f);
43
+ }
44
+ has(type) {
45
+ return this.factories.has(type);
46
+ }
47
+ /**
48
+ * Unregister a provider factory by type. Returns true if a factory was
49
+ * removed, false if none was registered for that type.
50
+ */
51
+ unregister(type) {
52
+ return this.factories.delete(type);
53
+ }
54
+ create(cfg, factoryType = cfg.type) {
55
+ const f = this.factories.get(factoryType);
56
+ if (!f) {
57
+ throw new Error(
58
+ `Provider type "${factoryType}" not registered. Available: ${Array.from(this.factories.keys()).join(", ")}`
59
+ );
60
+ }
61
+ return f.create(cfg);
62
+ }
63
+ list() {
64
+ return Array.from(this.factories.keys());
65
+ }
66
+ };
67
+
68
+ // src/registry/slash-command-registry.ts
69
+ var SlashCommandRegistry = class {
70
+ cmds = /* @__PURE__ */ new Map();
71
+ /**
72
+ * Register a command.
73
+ *
74
+ * Trust tiers, by `owner` and `opts.official`:
75
+ *
76
+ * - **Built-ins** (`owner === 'core'`) and **official plugins**
77
+ * (`opts.official === true`, set by the host only for first-party plugins
78
+ * loaded from the built-in factory list) claim the **bare** command name
79
+ * (`/prompts`). They may override one another — last write wins — so an
80
+ * official plugin can replace a built-in. Official plugins are *also*
81
+ * reachable under their `owner:name` namespace.
82
+ * - **External plugins** (any other `owner`) are isolated under the
83
+ * `owner:name` namespace: invocable only as `/owner:cmd`, never by bare
84
+ * name, and unable to shadow or override a built-in or official command.
85
+ *
86
+ * Officiality is supplied by the host based on the plugin's load source, not
87
+ * self-declared by the plugin — an external plugin cannot name itself into
88
+ * the official tier.
89
+ */
90
+ register(cmd, owner = "core", opts) {
91
+ const isPlugin = owner !== "core";
92
+ const official = !isPlugin || opts?.official === true;
93
+ if (official) {
94
+ const existing = this.cmds.get(cmd.name);
95
+ if (existing) {
96
+ const existingIsOfficialPlugin = existing.official && existing.owner !== "core";
97
+ if (!isPlugin && existingIsOfficialPlugin) {
98
+ return;
99
+ }
100
+ if (!isPlugin && existing.owner === "core") return;
101
+ }
102
+ this.cmds.set(cmd.name, { cmd, owner, official });
103
+ for (const a of cmd.aliases ?? []) {
104
+ this.cmds.set(a, { cmd, owner, official });
105
+ }
106
+ }
107
+ if (isPlugin) {
108
+ this.cmds.set(`${owner}:${cmd.name}`, { cmd, owner, official });
109
+ for (const a of cmd.aliases ?? []) {
110
+ this.cmds.set(`${owner}:${a}`, { cmd, owner, official });
111
+ }
112
+ }
113
+ }
114
+ unregister(name) {
115
+ const entry = this.cmds.get(name);
116
+ if (!entry) return false;
117
+ for (const [key, e] of this.cmds.entries()) {
118
+ if (e.cmd === entry.cmd) this.cmds.delete(key);
119
+ }
120
+ return true;
121
+ }
122
+ /**
123
+ * Bulk-register multiple slash commands at once.
124
+ */
125
+ registerAll(cmds, owner = "core") {
126
+ for (const cmd of cmds) this.register(cmd, owner);
127
+ }
128
+ get(name) {
129
+ return this.cmds.get(name)?.cmd;
130
+ }
131
+ ownerOf(name) {
132
+ return this.cmds.get(name)?.owner;
133
+ }
134
+ list() {
135
+ const seen = /* @__PURE__ */ new Set();
136
+ const out = [];
137
+ for (const { cmd } of this.cmds.values()) {
138
+ if (!seen.has(cmd)) {
139
+ seen.add(cmd);
140
+ out.push(cmd);
141
+ }
142
+ }
143
+ return out;
144
+ }
145
+ listWithOwner() {
146
+ const seen = /* @__PURE__ */ new Set();
147
+ const out = [];
148
+ for (const [fullName, { cmd, owner }] of this.cmds.entries()) {
149
+ if (!seen.has(cmd)) {
150
+ seen.add(cmd);
151
+ out.push({ cmd, owner, fullName });
152
+ }
153
+ }
154
+ return out;
155
+ }
156
+ /**
157
+ * Parse a slash command line. Accepts both:
158
+ * `/cmd args` → builtin command (owner=core)
159
+ * `/pluginName:cmd args` → plugin command
160
+ * The command name is split at the first `:` if the prefix matches a known owner.
161
+ */
162
+ async dispatch(line, ctx) {
163
+ if (!line.startsWith("/")) return null;
164
+ const trimmed = line.slice(1);
165
+ const spaceIdx = trimmed.indexOf(" ");
166
+ const firstColonIdx = trimmed.indexOf(":");
167
+ let name;
168
+ let args;
169
+ if (firstColonIdx !== -1 && (spaceIdx === -1 || firstColonIdx < spaceIdx)) {
170
+ const prefix = trimmed.slice(0, firstColonIdx);
171
+ name = trimmed.slice(0, spaceIdx === -1 ? void 0 : spaceIdx);
172
+ args = spaceIdx === -1 ? "" : trimmed.slice(spaceIdx + 1);
173
+ const entry2 = this.cmds.get(name);
174
+ if (!entry2 || entry2.owner !== prefix) {
175
+ name = trimmed.slice(0, spaceIdx === -1 ? void 0 : spaceIdx);
176
+ args = spaceIdx === -1 ? "" : trimmed.slice(spaceIdx + 1);
177
+ }
178
+ } else {
179
+ name = trimmed.slice(0, spaceIdx === -1 ? void 0 : spaceIdx);
180
+ args = spaceIdx === -1 ? "" : trimmed.slice(spaceIdx + 1);
181
+ }
182
+ const entry = this.cmds.get(name);
183
+ if (!entry) {
184
+ return { message: `Unknown command "/${name}". Type /help for a list.` };
185
+ }
186
+ try {
187
+ const res = await entry.cmd.run(args, ctx);
188
+ return res ?? {};
189
+ } catch (err) {
190
+ const msg = toErrorMessage(err);
191
+ return { message: `Command "/${name}" failed: ${msg}` };
192
+ }
193
+ }
194
+ };
195
+
196
+ // src/registry/tool-registry.ts
197
+ var ToolRegistry = class _ToolRegistry {
198
+ tools = /* @__PURE__ */ new Map();
199
+ descriptionModes = /* @__PURE__ */ new Map();
200
+ /**
201
+ * Set of tool names that are disabled (hidden from list(), get() and all
202
+ * other public accessors). The underlying tool data stays in `_tools` so
203
+ * re-enable is a constant-time operation.
204
+ */
205
+ _disabled = /* @__PURE__ */ new Set();
206
+ /** Monotonic version bumped on every registry mutation. */
207
+ _version = 0;
208
+ /** Cached `list()` result, frozen after build. Invalidated on _version change. */
209
+ _listSnapshot;
210
+ _listSnapshotVersion = -1;
211
+ /**
212
+ * Optional direct provider surface. `undefined` preserves the legacy
213
+ * behaviour (every enabled catalog tool is direct); when set, `list()` still
214
+ * exposes the complete executable catalog while `listForProvider()` returns
215
+ * only these names. This keeps lazy tools discoverable by tool_search/tool_use.
216
+ */
217
+ _providerToolNames;
218
+ _providerListSnapshot;
219
+ _providerListSnapshotVersion = -1;
220
+ /** Pre-compute tool definition token estimate once at registration time. */
221
+ _stampDefTokens(tool) {
222
+ if (tool._estDefTokens === void 0) {
223
+ tool._estDefTokens = estimateToolDefTokens(tool);
224
+ }
225
+ }
226
+ /** Apply the description mode transform and stamp token estimates. */
227
+ _prepareForStorage(tool) {
228
+ const mode = this.descriptionModes.get(tool.name) ?? "extend";
229
+ return applyToolDescriptionModeToTool(tool, mode);
230
+ }
231
+ register(tool, owner = "core") {
232
+ if (this.tools.has(tool.name)) {
233
+ throw new WrongStackError({
234
+ message: `Tool "${tool.name}" already registered`,
235
+ code: ERROR_CODES.REGISTRY_DUPLICATE,
236
+ subsystem: "container",
237
+ context: { tool: tool.name }
238
+ });
239
+ }
240
+ if (!tool.inputSchema || typeof tool.inputSchema !== "object") {
241
+ throw new WrongStackError({
242
+ message: `Tool "${tool.name}" has an invalid or missing inputSchema`,
243
+ code: ERROR_CODES.REGISTRY_INVALID,
244
+ subsystem: "container",
245
+ context: { tool: tool.name }
246
+ });
247
+ }
248
+ const stored = this._prepareForStorage(tool);
249
+ this._stampDefTokens(stored);
250
+ this.tools.set(tool.name, { tool: stored, owner });
251
+ this._version++;
252
+ }
253
+ /**
254
+ * Attempt to register a tool. Returns true if successful, false if a tool
255
+ * with the same name is already registered. Useful in multi-agent or plugin
256
+ * scenarios where duplicate registration may be intentional.
257
+ */
258
+ tryRegister(tool, owner = "core") {
259
+ if (this.tools.has(tool.name)) return false;
260
+ if (!tool.inputSchema || typeof tool.inputSchema !== "object") {
261
+ return false;
262
+ }
263
+ const stored = this._prepareForStorage(tool);
264
+ this._stampDefTokens(stored);
265
+ this.tools.set(tool.name, { tool: stored, owner });
266
+ this._version++;
267
+ return true;
268
+ }
269
+ /**
270
+ * Bulk-register multiple tools at once. Each tool that conflicts with an
271
+ * existing registration is silently skipped — use `registerAllOrThrow`
272
+ * if you want it to throw on conflicts.
273
+ */
274
+ registerAll(tools, owner = "core") {
275
+ for (const tool of tools) this.tryRegister(tool, owner);
276
+ }
277
+ /**
278
+ * Bulk-register and throw on the first conflict. Use when you need
279
+ * strict registration (e.g. at boot time).
280
+ */
281
+ registerAllOrThrow(tools, owner = "core") {
282
+ for (const tool of tools) this.register(tool, owner);
283
+ }
284
+ /**
285
+ * Register a tool as a default. If the tool name is already registered,
286
+ * this is a no-op — the existing registration (from core or another
287
+ * plugin) takes precedence. Use `override` to intentionally replace.
288
+ */
289
+ registerDefault(tool, owner = "core") {
290
+ if (this.tools.has(tool.name)) return;
291
+ const stored = this._prepareForStorage(tool);
292
+ this._stampDefTokens(stored);
293
+ this.tools.set(tool.name, { tool: stored, owner });
294
+ this._version++;
295
+ }
296
+ unregister(name) {
297
+ const deleted = this.tools.delete(name);
298
+ if (deleted) this._version++;
299
+ return deleted;
300
+ }
301
+ /**
302
+ * Override an existing tool. Throws if the tool is not already registered.
303
+ * Plugins use this to replace built-in tools with custom implementations.
304
+ */
305
+ override(name, tool, owner = "core") {
306
+ if (!this.tools.has(name)) {
307
+ throw new WrongStackError({
308
+ message: `Tool "${name}" not registered; cannot override`,
309
+ code: ERROR_CODES.REGISTRY_NOT_FOUND,
310
+ subsystem: "container",
311
+ context: { tool: name }
312
+ });
313
+ }
314
+ const stored = this._prepareForStorage(tool);
315
+ this._stampDefTokens(stored);
316
+ this.tools.set(name, { tool: stored, owner });
317
+ this._version++;
318
+ }
319
+ /**
320
+ * Wrap (decorate) an existing tool. The wrapper receives the current
321
+ * tool and must return a new tool — typically the same tool with a
322
+ * wrapped `execute` or `executeStream`. Throws if the tool is not
323
+ * registered.
324
+ *
325
+ * Multiple wraps stack: each wrapper gets the output of the previous.
326
+ *
327
+ * @example
328
+ * registry.wrap('bash', (t) => ({ ...t, permission: 'confirm' }));
329
+ */
330
+ wrap(name, wrapper, owner = "core") {
331
+ const entry = this.tools.get(name);
332
+ if (!entry) {
333
+ throw new WrongStackError({
334
+ message: `Tool "${name}" not registered; cannot wrap`,
335
+ code: ERROR_CODES.REGISTRY_NOT_FOUND,
336
+ subsystem: "container",
337
+ context: { tool: name }
338
+ });
339
+ }
340
+ const current = applyToolDescriptionModeToTool(entry.tool, "extend");
341
+ const wrapped = this._prepareForStorage(wrapper(current));
342
+ wrapped._estDefTokens = void 0;
343
+ this._stampDefTokens(wrapped);
344
+ this.tools.set(name, { tool: wrapped, owner: `${entry.owner}+${owner}` });
345
+ this._version++;
346
+ }
347
+ setDescriptionMode(name, mode) {
348
+ const normalized = normalizeToolDescriptionMode(mode);
349
+ if (!normalized) return false;
350
+ const entry = this.tools.get(name);
351
+ if (!entry) return false;
352
+ if (normalized === "extend") {
353
+ this.descriptionModes.delete(name);
354
+ } else {
355
+ this.descriptionModes.set(name, normalized);
356
+ }
357
+ const stored = applyToolDescriptionModeToTool(entry.tool, normalized);
358
+ stored._estDefTokens = void 0;
359
+ this._stampDefTokens(stored);
360
+ this.tools.set(name, { ...entry, tool: stored });
361
+ this._version++;
362
+ return true;
363
+ }
364
+ getDescriptionMode(name) {
365
+ return this.descriptionModes.get(name) ?? "extend";
366
+ }
367
+ applyDescriptionModes(modes = {}) {
368
+ const missing = [];
369
+ let applied = 0;
370
+ for (const [name, rawMode] of Object.entries(modes)) {
371
+ const mode = normalizeToolDescriptionMode(rawMode);
372
+ if (!mode) continue;
373
+ if (this.tools.has(name)) {
374
+ if (this.setDescriptionMode(name, mode)) applied++;
375
+ } else {
376
+ if (mode === "simple") this.descriptionModes.set(name, mode);
377
+ else this.descriptionModes.delete(name);
378
+ missing.push(name);
379
+ }
380
+ }
381
+ return { applied, missing };
382
+ }
383
+ get(name) {
384
+ if (this._disabled.has(name)) return void 0;
385
+ return this.tools.get(name)?.tool;
386
+ }
387
+ ownerOf(name) {
388
+ return this.tools.get(name)?.owner;
389
+ }
390
+ // ── Disable / enable ────────────────────────────────────────────
391
+ /**
392
+ * Disable a tool by name. The tool is removed from all public accessors
393
+ * (list(), get(), listByCategory(), listWithOwner()) so it does NOT
394
+ * appear in the system prompt or provider request. The underlying
395
+ * registration is preserved in memory — use `enable()` to restore it.
396
+ *
397
+ * @returns `true` if the tool was found and disabled; `false` if the
398
+ * tool is not registered or is already disabled.
399
+ */
400
+ disable(name) {
401
+ if (!this.tools.has(name) || this._disabled.has(name)) return false;
402
+ this._disabled.add(name);
403
+ this._version++;
404
+ return true;
405
+ }
406
+ /**
407
+ * Re-enable a previously disabled tool. The tool reappears in all
408
+ * public accessors and will be included in the next system prompt /
409
+ * provider request.
410
+ *
411
+ * @returns `true` if the tool was disabled and is now re-enabled;
412
+ * `false` if the tool was not disabled.
413
+ */
414
+ enable(name) {
415
+ if (!this._disabled.has(name)) return false;
416
+ this._disabled.delete(name);
417
+ this._version++;
418
+ return true;
419
+ }
420
+ /**
421
+ * Re-enable ALL currently disabled tools at once. Returns the number
422
+ * of tools that were re-enabled.
423
+ */
424
+ enableAll() {
425
+ const count = this._disabled.size;
426
+ if (count === 0) return 0;
427
+ this._disabled.clear();
428
+ this._version++;
429
+ return count;
430
+ }
431
+ /**
432
+ * Check whether a tool is currently disabled.
433
+ */
434
+ isDisabled(name) {
435
+ return this._disabled.has(name);
436
+ }
437
+ /**
438
+ * Apply a list of tool names to disable. Tools not in the registry
439
+ * are silently ignored so config can reference future tools without
440
+ * error. Returns the number of tools actually disabled.
441
+ */
442
+ applyDisabled(names) {
443
+ let count = 0;
444
+ for (const name of names) {
445
+ if (this.disable(name)) count++;
446
+ }
447
+ return count;
448
+ }
449
+ /**
450
+ * Return the list of all disabled tool entries (tool + owner). Useful
451
+ * for the /tools slash command to show disabled tools alongside
452
+ * enabled ones.
453
+ */
454
+ listDisabled() {
455
+ return Array.from(this._disabled).map((name) => {
456
+ const entry = this.tools.get(name);
457
+ return entry ? { tool: entry.tool, owner: entry.owner } : null;
458
+ }).filter((e) => e !== null);
459
+ }
460
+ list() {
461
+ if (this._listSnapshot && this._version === this._listSnapshotVersion) {
462
+ return this._listSnapshot;
463
+ }
464
+ const arr = Array.from(this.tools.entries()).filter(([name]) => !this._disabled.has(name)).map(([, entry]) => entry.tool);
465
+ this._listSnapshot = arr;
466
+ this._listSnapshotVersion = this._version;
467
+ return arr;
468
+ }
469
+ /** Replace the direct provider surface. Pass `undefined` to expose the catalog. */
470
+ setProviderToolNames(names) {
471
+ this._providerToolNames = names ? new Set(names) : void 0;
472
+ this._version++;
473
+ }
474
+ /** Add registered or future tool names to the direct provider surface. */
475
+ exposeToProvider(names) {
476
+ if (!this._providerToolNames) return;
477
+ for (const name of typeof names === "string" ? [names] : names) {
478
+ this._providerToolNames.add(name);
479
+ }
480
+ this._version++;
481
+ }
482
+ /** Tools serialized into provider requests and described by the system prompt. */
483
+ listForProvider() {
484
+ if (!this._providerToolNames) return this.list();
485
+ if (this._providerListSnapshot && this._version === this._providerListSnapshotVersion) {
486
+ return this._providerListSnapshot;
487
+ }
488
+ const arr = Array.from(this.tools.entries()).filter(([name]) => !this._disabled.has(name) && this._providerToolNames?.has(name) === true).map(([, entry]) => entry.tool);
489
+ this._providerListSnapshot = arr;
490
+ this._providerListSnapshotVersion = this._version;
491
+ return arr;
492
+ }
493
+ /**
494
+ * Whether an enabled catalog tool is part of the direct provider surface.
495
+ *
496
+ * This is intentionally different from `get()`/`list()`: a tool can remain
497
+ * executable through a lazy gateway while its schema is omitted from the
498
+ * next provider request. Disabled and unknown tools always return false.
499
+ */
500
+ isExposedToProvider(name) {
501
+ if (this._disabled.has(name) || !this.tools.has(name)) return false;
502
+ return this._providerToolNames?.has(name) ?? true;
503
+ }
504
+ /**
505
+ * Group tools by their `category` field. Tools without a category
506
+ * are placed under the key `""` (empty string). Returns a Map of
507
+ * category → tools, sorted by registration order within each category.
508
+ */
509
+ listByCategory() {
510
+ const map = /* @__PURE__ */ new Map();
511
+ for (const [name, { tool }] of this.tools) {
512
+ if (this._disabled.has(name)) continue;
513
+ const cat = tool.category ?? "";
514
+ let group = map.get(cat);
515
+ if (!group) {
516
+ group = [];
517
+ map.set(cat, group);
518
+ }
519
+ group.push(tool);
520
+ }
521
+ return map;
522
+ }
523
+ listWithOwner() {
524
+ return Array.from(this.tools.entries()).filter(([name]) => !this._disabled.has(name)).map(([, entry]) => entry);
525
+ }
526
+ clear() {
527
+ this.tools.clear();
528
+ this.descriptionModes.clear();
529
+ this._disabled.clear();
530
+ this._providerToolNames = void 0;
531
+ this._version++;
532
+ }
533
+ /**
534
+ * Return a new ToolRegistry with the same registered tools and owners.
535
+ * Useful for creating filtered copies in multi-agent scenarios.
536
+ */
537
+ clone() {
538
+ const copy = new _ToolRegistry();
539
+ copy.descriptionModes.clear();
540
+ for (const [name, mode] of this.descriptionModes) {
541
+ copy.descriptionModes.set(name, mode);
542
+ }
543
+ for (const [name, { tool, owner }] of this.tools) {
544
+ copy.tools.set(name, { tool, owner });
545
+ }
546
+ for (const name of this._disabled) {
547
+ copy._disabled.add(name);
548
+ }
549
+ copy._providerToolNames = this._providerToolNames ? new Set(this._providerToolNames) : void 0;
550
+ copy._version = this._version;
551
+ return copy;
552
+ }
553
+ };
554
+
555
+ export {
556
+ ProviderRegistry,
557
+ SlashCommandRegistry,
558
+ ToolRegistry
559
+ };
560
+ //# sourceMappingURL=chunk-KI4L2DUL.js.map
@@ -0,0 +1,47 @@
1
+ // src/types/config/runtime.ts
2
+ function normalizeTokenSavingTier(val) {
3
+ if (val === void 0) return "off";
4
+ if (typeof val === "boolean") return val ? "medium" : "off";
5
+ if (val === "auto") return "medium";
6
+ const validTiers = /* @__PURE__ */ new Set([
7
+ "off",
8
+ "minimal",
9
+ "light",
10
+ "medium",
11
+ "aggressive"
12
+ ]);
13
+ return validTiers.has(val) ? val : "off";
14
+ }
15
+ function resolveTokenSavingTier(val, maxContext) {
16
+ if (val === "auto") {
17
+ if (typeof maxContext !== "number" || !Number.isFinite(maxContext) || maxContext <= 0) {
18
+ return "off";
19
+ }
20
+ if (maxContext < 32e3) return "medium";
21
+ if (maxContext < 128e3) return "light";
22
+ return "minimal";
23
+ }
24
+ return normalizeTokenSavingTier(val);
25
+ }
26
+ var DEFAULT_TUI_THINKING_WORD = "thinking";
27
+ var MAX_TUI_THINKING_WORD_LENGTH = 16;
28
+ var MAX_WRONGPROXY_URL_LENGTH = 2048;
29
+ function normalizeTuiThinkingWord(value) {
30
+ if (typeof value !== "string") return DEFAULT_TUI_THINKING_WORD;
31
+ const word = value.trim();
32
+ if (word.length === 0 || word.length > MAX_TUI_THINKING_WORD_LENGTH) {
33
+ return DEFAULT_TUI_THINKING_WORD;
34
+ }
35
+ if (!/^[\p{L}\p{N}_-]+$/u.test(word)) return DEFAULT_TUI_THINKING_WORD;
36
+ return word;
37
+ }
38
+
39
+ export {
40
+ normalizeTokenSavingTier,
41
+ resolveTokenSavingTier,
42
+ DEFAULT_TUI_THINKING_WORD,
43
+ MAX_TUI_THINKING_WORD_LENGTH,
44
+ MAX_WRONGPROXY_URL_LENGTH,
45
+ normalizeTuiThinkingWord
46
+ };
47
+ //# sourceMappingURL=chunk-KJ2ZTQSL.js.map