@wrongstack/core 0.1.8 → 0.1.10

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 (73) hide show
  1. package/dist/agent-bridge-6KPqsFx6.d.ts +33 -0
  2. package/dist/compactor-B4mQZXf2.d.ts +17 -0
  3. package/dist/config-BU9f_5yH.d.ts +193 -0
  4. package/dist/{provider-txgB0Oq9.d.ts → context-BmM2xGUZ.d.ts} +532 -472
  5. package/dist/coordination/index.d.ts +694 -0
  6. package/dist/coordination/index.js +1995 -0
  7. package/dist/coordination/index.js.map +1 -0
  8. package/dist/defaults/index.d.ts +34 -2206
  9. package/dist/defaults/index.js +4116 -3790
  10. package/dist/defaults/index.js.map +1 -1
  11. package/dist/events-BMNaEFZl.d.ts +218 -0
  12. package/dist/execution/index.d.ts +260 -0
  13. package/dist/execution/index.js +1625 -0
  14. package/dist/execution/index.js.map +1 -0
  15. package/dist/index.d.ts +50 -12
  16. package/dist/index.js +6669 -5909
  17. package/dist/index.js.map +1 -1
  18. package/dist/infrastructure/index.d.ts +10 -0
  19. package/dist/infrastructure/index.js +575 -0
  20. package/dist/infrastructure/index.js.map +1 -0
  21. package/dist/input-reader-E-ffP2ee.d.ts +12 -0
  22. package/dist/kernel/index.d.ts +15 -4
  23. package/dist/kernel/index.js.map +1 -1
  24. package/dist/logger-BH6AE0W9.d.ts +24 -0
  25. package/dist/logger-BMQgxvdy.d.ts +12 -0
  26. package/dist/mcp-servers-Dzgg4x1w.d.ts +100 -0
  27. package/dist/memory-CEXuo7sz.d.ts +16 -0
  28. package/dist/mode-CV077NjV.d.ts +27 -0
  29. package/dist/models/index.d.ts +60 -0
  30. package/dist/models/index.js +621 -0
  31. package/dist/models/index.js.map +1 -0
  32. package/dist/models-registry-DqzwpBQy.d.ts +46 -0
  33. package/dist/models-registry-Y2xbog0E.d.ts +95 -0
  34. package/dist/multi-agent-fmkRHtof.d.ts +283 -0
  35. package/dist/observability/index.d.ts +353 -0
  36. package/dist/observability/index.js +691 -0
  37. package/dist/observability/index.js.map +1 -0
  38. package/dist/observability-BhnVLBLS.d.ts +67 -0
  39. package/dist/path-resolver-CPRj4bFY.d.ts +10 -0
  40. package/dist/path-resolver-DBjaoXFq.d.ts +54 -0
  41. package/dist/plugin-DJk6LL8B.d.ts +434 -0
  42. package/dist/renderer-rk_1Swwc.d.ts +158 -0
  43. package/dist/sdd/index.d.ts +206 -0
  44. package/dist/sdd/index.js +864 -0
  45. package/dist/sdd/index.js.map +1 -0
  46. package/dist/secret-scrubber-CicHLN4G.d.ts +31 -0
  47. package/dist/secret-scrubber-DF88luOe.d.ts +54 -0
  48. package/dist/secret-vault-DoISxaKO.d.ts +19 -0
  49. package/dist/security/index.d.ts +30 -0
  50. package/dist/security/index.js +524 -0
  51. package/dist/security/index.js.map +1 -0
  52. package/dist/selector-BbJqiEP4.d.ts +51 -0
  53. package/dist/session-reader-Drq8RvJu.d.ts +150 -0
  54. package/dist/skill-DhfSizKv.d.ts +72 -0
  55. package/dist/storage/index.d.ts +382 -0
  56. package/dist/storage/index.js +1530 -0
  57. package/dist/storage/index.js.map +1 -0
  58. package/dist/{system-prompt-vAB0F54-.d.ts → system-prompt-BC_8ypCG.d.ts} +1 -1
  59. package/dist/task-graph-BITvWt4t.d.ts +160 -0
  60. package/dist/tool-executor-CpuJPYm9.d.ts +97 -0
  61. package/dist/types/index.d.ts +26 -4
  62. package/dist/types/index.js +1787 -4
  63. package/dist/types/index.js.map +1 -1
  64. package/dist/utils/index.d.ts +49 -2
  65. package/dist/utils/index.js +100 -2
  66. package/dist/utils/index.js.map +1 -1
  67. package/package.json +34 -2
  68. package/skills/audit-log/SKILL.md +67 -0
  69. package/skills/bug-hunter/SKILL.md +87 -0
  70. package/skills/refactor-planner/SKILL.md +94 -0
  71. package/skills/security-scanner/SKILL.md +117 -0
  72. package/dist/mode-Pjt5vMS6.d.ts +0 -815
  73. package/dist/session-reader-9sOTgmeC.d.ts +0 -1087
@@ -0,0 +1,10 @@
1
+ export { D as DefaultLogger, a as DefaultLoggerOptions } from '../logger-BH6AE0W9.js';
2
+ export { D as DefaultPathResolver, a as DefaultTokenCounter } from '../path-resolver-DBjaoXFq.js';
3
+ export { C as ContextManagerAction, a as ContextManagerInput, b as ContextManagerResult, c as ContextManagerToolOptions, d as allServers, e as awsServer, f as blockServer, g as braveSearchServer, h as context7Server, i as contextManagerTool, j as createContextManagerTool, k as everArtServer, l as filesystemServer, m as githubServer, n as googleMapsServer, s as sentinelServer, o as slackServer } from '../mcp-servers-Dzgg4x1w.js';
4
+ import '../logger-BMQgxvdy.js';
5
+ import '../events-BMNaEFZl.js';
6
+ import '../context-BmM2xGUZ.js';
7
+ import '../models-registry-Y2xbog0E.js';
8
+ import '../path-resolver-CPRj4bFY.js';
9
+ import '../compactor-B4mQZXf2.js';
10
+ import '../config-BU9f_5yH.js';
@@ -0,0 +1,575 @@
1
+ import * as fs from 'fs';
2
+ import * as path2 from 'path';
3
+
4
+ // src/infrastructure/logger.ts
5
+
6
+ // src/utils/color.ts
7
+ var isColorTty = () => {
8
+ if (process.env.NO_COLOR) return false;
9
+ if (process.env.FORCE_COLOR) return true;
10
+ return Boolean(process.stdout?.isTTY);
11
+ };
12
+ var COLOR = isColorTty();
13
+ var wrap = (open, close) => (s) => COLOR ? `\x1B[${open}m${s}\x1B[${close}m` : s;
14
+ var color = {
15
+ reset: wrap("0", "0"),
16
+ bold: wrap("1", "22"),
17
+ dim: wrap("2", "22"),
18
+ italic: wrap("3", "23"),
19
+ underline: wrap("4", "24"),
20
+ red: wrap("31", "39"),
21
+ green: wrap("32", "39"),
22
+ yellow: wrap("33", "39"),
23
+ blue: wrap("34", "39"),
24
+ magenta: wrap("35", "39"),
25
+ cyan: wrap("36", "39"),
26
+ gray: wrap("90", "39"),
27
+ amber: wrap("38;5;214", "39"),
28
+ pink: wrap("38;5;205", "39"),
29
+ bgRed: wrap("41", "49"),
30
+ bgGreen: wrap("42", "49")
31
+ };
32
+
33
+ // src/infrastructure/logger.ts
34
+ var LEVEL_RANK = {
35
+ error: 0,
36
+ warn: 1,
37
+ info: 2,
38
+ debug: 3,
39
+ trace: 4
40
+ };
41
+ var COLORS = {
42
+ error: color.red,
43
+ warn: color.yellow,
44
+ info: color.cyan,
45
+ debug: color.gray,
46
+ trace: color.dim
47
+ };
48
+ var DefaultLogger = class _DefaultLogger {
49
+ level;
50
+ file;
51
+ bindings;
52
+ pretty;
53
+ constructor(opts = {}) {
54
+ this.level = opts.level ?? process.env.WRONGSTACK_LOG_LEVEL ?? "info";
55
+ this.file = opts.file;
56
+ this.bindings = opts.bindings ?? {};
57
+ this.pretty = opts.pretty ?? true;
58
+ if (this.file) {
59
+ try {
60
+ fs.mkdirSync(path2.dirname(this.file), { recursive: true });
61
+ } catch {
62
+ }
63
+ }
64
+ }
65
+ error(msg, ctx) {
66
+ this.log("error", msg, ctx);
67
+ }
68
+ warn(msg, ctx) {
69
+ this.log("warn", msg, ctx);
70
+ }
71
+ info(msg, ctx) {
72
+ this.log("info", msg, ctx);
73
+ }
74
+ debug(msg, ctx) {
75
+ this.log("debug", msg, ctx);
76
+ }
77
+ trace(msg, ctx) {
78
+ this.log("trace", msg, ctx);
79
+ }
80
+ child(bindings) {
81
+ return new _DefaultLogger({
82
+ level: this.level,
83
+ file: this.file,
84
+ pretty: this.pretty,
85
+ bindings: { ...this.bindings, ...bindings }
86
+ });
87
+ }
88
+ log(level, msg, ctx) {
89
+ const r = LEVEL_RANK[level];
90
+ const allowed = LEVEL_RANK[this.level];
91
+ if (r > allowed) return;
92
+ const ts = (/* @__PURE__ */ new Date()).toISOString();
93
+ const entry = { ts, level, msg, ...this.bindings };
94
+ if (ctx !== void 0) {
95
+ entry.ctx = ctx instanceof Error ? { message: ctx.message, stack: ctx.stack } : ctx;
96
+ }
97
+ if (this.file) {
98
+ try {
99
+ fs.appendFileSync(this.file, `${JSON.stringify(entry)}
100
+ `);
101
+ } catch {
102
+ }
103
+ }
104
+ if (r <= LEVEL_RANK.warn || this.level === "debug" || this.level === "trace") {
105
+ const head = `${color.dim(ts)} ${COLORS[level](level.toUpperCase().padEnd(5))} ${msg}`;
106
+ if (ctx !== void 0) {
107
+ process.stderr.write(`${head} ${formatCtx(ctx)}
108
+ `);
109
+ } else {
110
+ process.stderr.write(`${head}
111
+ `);
112
+ }
113
+ }
114
+ }
115
+ };
116
+ function formatCtx(ctx) {
117
+ if (ctx instanceof Error) return color.dim(ctx.message);
118
+ if (typeof ctx === "string") return color.dim(ctx);
119
+ try {
120
+ return color.dim(JSON.stringify(ctx));
121
+ } catch {
122
+ return color.dim(String(ctx));
123
+ }
124
+ }
125
+ var PROJECT_MARKERS = [
126
+ ".git",
127
+ "package.json",
128
+ "pnpm-workspace.yaml",
129
+ "go.mod",
130
+ "Cargo.toml",
131
+ "pyproject.toml",
132
+ ".wrongstack"
133
+ ];
134
+ var DefaultPathResolver = class {
135
+ projectRoot;
136
+ cwd;
137
+ constructor(cwd = process.cwd()) {
138
+ this.cwd = path2.resolve(cwd);
139
+ this.projectRoot = this.detectProjectRoot(this.cwd);
140
+ }
141
+ detectProjectRoot(start) {
142
+ let dir = path2.resolve(start);
143
+ const root = path2.parse(dir).root;
144
+ while (dir !== root) {
145
+ for (const marker of PROJECT_MARKERS) {
146
+ try {
147
+ fs.accessSync(path2.join(dir, marker));
148
+ return dir;
149
+ } catch {
150
+ }
151
+ }
152
+ const parent = path2.dirname(dir);
153
+ if (parent === dir) break;
154
+ dir = parent;
155
+ }
156
+ return path2.resolve(start);
157
+ }
158
+ resolve(input) {
159
+ const abs = path2.isAbsolute(input) ? input : path2.resolve(this.cwd, input);
160
+ let real;
161
+ try {
162
+ real = fs.realpathSync(abs);
163
+ } catch {
164
+ real = path2.normalize(abs);
165
+ }
166
+ return real;
167
+ }
168
+ isInsideRoot(absPath) {
169
+ const normalized = path2.normalize(absPath);
170
+ const root = path2.normalize(this.projectRoot);
171
+ if (normalized === root) return true;
172
+ const rel = path2.relative(root, normalized);
173
+ return !rel.startsWith("..") && !path2.isAbsolute(rel);
174
+ }
175
+ ensureInsideRoot(absPath) {
176
+ const resolved = this.resolve(absPath);
177
+ if (!this.isInsideRoot(resolved)) {
178
+ const display = path2.isAbsolute(absPath) ? path2.basename(absPath) : absPath;
179
+ const err = new Error(`Path "${display}" resolves outside the project root`);
180
+ err.fullPath = absPath;
181
+ err.projectRoot = this.projectRoot;
182
+ throw err;
183
+ }
184
+ return resolved;
185
+ }
186
+ };
187
+
188
+ // src/infrastructure/token-counter.ts
189
+ var DefaultTokenCounter = class {
190
+ input = 0;
191
+ output = 0;
192
+ cacheRead = 0;
193
+ cacheWrite = 0;
194
+ costInput = 0;
195
+ costOutput = 0;
196
+ registry;
197
+ providerId;
198
+ events;
199
+ priceCache = /* @__PURE__ */ new Map();
200
+ constructor(opts = {}) {
201
+ this.registry = opts.registry;
202
+ this.providerId = opts.providerId;
203
+ this.events = opts.events;
204
+ }
205
+ account(usage, model) {
206
+ this.input += usage.input;
207
+ this.output += usage.output;
208
+ this.cacheRead += usage.cacheRead ?? 0;
209
+ this.cacheWrite += usage.cacheWrite ?? 0;
210
+ const price = model ? this.priceCache.get(model) : void 0;
211
+ if (price) {
212
+ this.applyPrice(usage, price);
213
+ } else if (this.registry && this.providerId && model) {
214
+ void this.registry.getModel(this.providerId, model).then((m) => {
215
+ if (m) {
216
+ const p = priceFromModel(m);
217
+ this.priceCache.set(model, p);
218
+ this.applyPrice(usage, p);
219
+ }
220
+ }).catch(() => {
221
+ this.events?.emit("token.cost_estimate_unavailable", { model: model ?? "<unknown>" });
222
+ return void 0;
223
+ });
224
+ }
225
+ }
226
+ /** Synchronous variant for code paths that have already resolved the model. */
227
+ accountWithModel(usage, resolved) {
228
+ this.input += usage.input;
229
+ this.output += usage.output;
230
+ this.cacheRead += usage.cacheRead ?? 0;
231
+ this.cacheWrite += usage.cacheWrite ?? 0;
232
+ const price = priceFromModel(resolved);
233
+ this.priceCache.set(resolved.modelId, price);
234
+ this.applyPrice(usage, price);
235
+ }
236
+ total() {
237
+ return {
238
+ input: this.input,
239
+ output: this.output,
240
+ cacheRead: this.cacheRead,
241
+ cacheWrite: this.cacheWrite
242
+ };
243
+ }
244
+ estimateCost() {
245
+ return {
246
+ input: round4(this.costInput),
247
+ output: round4(this.costOutput),
248
+ total: round4(this.costInput + this.costOutput),
249
+ currency: "USD"
250
+ };
251
+ }
252
+ cacheStats() {
253
+ const denom = this.cacheRead + this.input;
254
+ return {
255
+ readTokens: this.cacheRead,
256
+ writeTokens: this.cacheWrite,
257
+ hitRatio: denom === 0 ? 0 : this.cacheRead / denom
258
+ };
259
+ }
260
+ /** Invalidate cached prices so the next account() call fetches fresh data. */
261
+ invalidateCache() {
262
+ this.priceCache.clear();
263
+ }
264
+ reset() {
265
+ this.input = 0;
266
+ this.output = 0;
267
+ this.cacheRead = 0;
268
+ this.cacheWrite = 0;
269
+ this.costInput = 0;
270
+ this.costOutput = 0;
271
+ }
272
+ applyPrice(usage, price) {
273
+ if (price.input) this.costInput += usage.input / 1e6 * price.input;
274
+ if (price.output) this.costOutput += usage.output / 1e6 * price.output;
275
+ if (usage.cacheRead && price.cacheRead) {
276
+ this.costInput += usage.cacheRead / 1e6 * price.cacheRead;
277
+ }
278
+ if (usage.cacheWrite && price.cacheWrite) {
279
+ this.costInput += usage.cacheWrite / 1e6 * price.cacheWrite;
280
+ }
281
+ }
282
+ };
283
+ function priceFromModel(m) {
284
+ return {
285
+ input: m.cost?.input,
286
+ output: m.cost?.output,
287
+ cacheRead: m.cost?.cache_read,
288
+ cacheWrite: m.cost?.cache_write
289
+ };
290
+ }
291
+ function round4(n) {
292
+ return Math.round(n * 1e4) / 1e4;
293
+ }
294
+
295
+ // src/infrastructure/mcp-servers.ts
296
+ var filesystemServer = () => ({
297
+ name: "filesystem",
298
+ description: "Read, write, and navigate the local filesystem (read-heavy tools)",
299
+ transport: "stdio",
300
+ command: "npx",
301
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
302
+ permission: "confirm"
303
+ });
304
+ var githubServer = () => ({
305
+ name: "github",
306
+ description: "GitHub API \u2014 issues, PRs, repos, search, file ops (requires GITHUB_PERSONAL_ACCESS_TOKEN)",
307
+ transport: "stdio",
308
+ command: "npx",
309
+ args: ["-y", "@modelcontextprotocol/server-github"],
310
+ env: { GITHUB_PERSONAL_ACCESS_TOKEN: process.env.GITHUB_PERSONAL_ACCESS_TOKEN ?? "" },
311
+ permission: "confirm"
312
+ });
313
+ var context7Server = () => ({
314
+ name: "context7",
315
+ description: "Codebase-aware documentation and Q&A (context7.ai)",
316
+ transport: "streamable-http",
317
+ url: "https://server.context7.ai/mcp",
318
+ permission: "confirm"
319
+ });
320
+ var braveSearchServer = () => ({
321
+ name: "brave-search",
322
+ description: "Web search (Brave). Requires BRAVE_SEARCH_API_KEY \u2014 free tier 2k queries/month",
323
+ transport: "stdio",
324
+ command: "npx",
325
+ args: ["-y", "@modelcontextprotocol/server-brave-search"],
326
+ env: { BRAVE_SEARCH_API_KEY: process.env.BRAVE_SEARCH_API_KEY ?? "" },
327
+ permission: "confirm"
328
+ });
329
+ var blockServer = () => ({
330
+ name: "block",
331
+ description: "Postgres database access via SQL (Block MCP server)",
332
+ transport: "stdio",
333
+ command: "npx",
334
+ args: ["-y", "@modelcontextprotocol/server-block"],
335
+ permission: "confirm"
336
+ });
337
+ var everArtServer = () => ({
338
+ name: "everart",
339
+ description: "AI image generation (EverArt). Requires EVERART_API_KEY",
340
+ transport: "stdio",
341
+ command: "npx",
342
+ args: ["-y", "@modelcontextprotocol/server-everart"],
343
+ env: { EVERART_API_KEY: process.env.EVERART_API_KEY ?? "" },
344
+ permission: "confirm"
345
+ });
346
+ var slackServer = () => ({
347
+ name: "slack",
348
+ description: "Slack \u2014 messaging, channels, search. Requires SLACK_BOT_TOKEN + SLACK_TEAM_ID",
349
+ transport: "stdio",
350
+ command: "npx",
351
+ args: ["-y", "@modelcontextprotocol/server-slack"],
352
+ env: {
353
+ SLACK_BOT_TOKEN: process.env.SLACK_BOT_TOKEN ?? "",
354
+ SLACK_TEAM_ID: process.env.SLACK_TEAM_ID ?? ""
355
+ },
356
+ permission: "confirm"
357
+ });
358
+ var awsServer = () => ({
359
+ name: "aws",
360
+ description: "AWS \u2014 EC2, S3, Lambda, IAM, CloudFormation, costs. Requires AWS credentials",
361
+ transport: "stdio",
362
+ command: "npx",
363
+ args: ["-y", "@modelcontextprotocol/server-aws"],
364
+ permission: "confirm"
365
+ });
366
+ var googleMapsServer = () => ({
367
+ name: "google-maps",
368
+ description: "Google Maps \u2014 directions, geocoding, places. Requires GOOGLE_MAPS_API_KEY",
369
+ transport: "stdio",
370
+ command: "npx",
371
+ args: ["-y", "@modelcontextprotocol/server-google-maps"],
372
+ env: { GOOGLE_MAPS_API_KEY: process.env.GOOGLE_MAPS_API_KEY ?? "" },
373
+ permission: "confirm"
374
+ });
375
+ var sentinelServer = () => ({
376
+ name: "sentinel",
377
+ description: "Security vulnerability scanning (Sentinel)",
378
+ transport: "streamable-http",
379
+ url: "https://mcp.sentinel.ai",
380
+ permission: "deny"
381
+ // security tool — require explicit confirmation
382
+ });
383
+ var allServers = () => ({
384
+ filesystem: { ...filesystemServer(), enabled: false },
385
+ github: { ...githubServer(), enabled: false },
386
+ context7: { ...context7Server(), enabled: false },
387
+ "brave-search": { ...braveSearchServer(), enabled: false },
388
+ block: { ...blockServer(), enabled: false },
389
+ everart: { ...everArtServer(), enabled: false },
390
+ slack: { ...slackServer(), enabled: false },
391
+ aws: { ...awsServer(), enabled: false },
392
+ "google-maps": { ...googleMapsServer(), enabled: false },
393
+ sentinel: { ...sentinelServer(), enabled: false }
394
+ });
395
+
396
+ // src/infrastructure/context-manager.ts
397
+ var CONTEXT_MANAGER_TOOL_NAME = "context_manager";
398
+ function roughEstimate(messages) {
399
+ let total = 0;
400
+ for (const m of messages) {
401
+ if (typeof m.content === "string") {
402
+ total += Math.ceil(m.content.length / 4);
403
+ } else if (Array.isArray(m.content)) {
404
+ for (const b of m.content) {
405
+ if (b.type === "text") total += Math.ceil(b.text.length / 4);
406
+ else if (b.type === "tool_use" || b.type === "tool_result") {
407
+ total += Math.ceil(JSON.stringify(b).length / 4);
408
+ }
409
+ }
410
+ }
411
+ }
412
+ return total;
413
+ }
414
+ function createContextManagerTool(opts = {}) {
415
+ return {
416
+ name: CONTEXT_MANAGER_TOOL_NAME,
417
+ description: 'Inspect or reorganize the conversation context window. Use "check" to see token budget. Use "summary" to collapse a message range into a concise note (provide "text" for custom summary). Use "prune" to remove specific messages by index. Use "add_note" to inject a summary note. Use "compact" to run aggressive compaction.',
418
+ inputSchema: {
419
+ type: "object",
420
+ properties: {
421
+ action: {
422
+ type: "string",
423
+ enum: ["check", "summary", "prune", "add_note", "compact"],
424
+ description: "The context operation to perform."
425
+ },
426
+ from: {
427
+ type: "number",
428
+ description: "Start index (inclusive) for summary/prune operations."
429
+ },
430
+ to: {
431
+ type: "number",
432
+ description: "End index (inclusive) for summary/prune operations."
433
+ },
434
+ text: {
435
+ type: "string",
436
+ description: 'Summary or note text. For "summary": the model-provided summary of the removed range. For "add_note": the note to inject.'
437
+ },
438
+ afterIndex: {
439
+ type: "number",
440
+ description: "Insert after this index (for add_note). Defaults to prepend (0)."
441
+ }
442
+ },
443
+ required: ["action"]
444
+ },
445
+ permission: "auto",
446
+ mutating: true,
447
+ async execute(input, ctx) {
448
+ const messages = ctx.messages;
449
+ const beforeTokens = roughEstimate(messages);
450
+ const applyMessages = (next) => {
451
+ if (ctx.state) {
452
+ ctx.state.replaceMessages(next);
453
+ } else {
454
+ messages.length = 0;
455
+ messages.splice(0, 0, ...next);
456
+ }
457
+ };
458
+ switch (input.action) {
459
+ case "check": {
460
+ return {
461
+ action: "check",
462
+ beforeTokens,
463
+ messageCount: messages.length,
464
+ notes: JSON.stringify({
465
+ messages: messages.length,
466
+ tokens: beforeTokens,
467
+ readFiles: ctx.readFiles.size,
468
+ todos: ctx.todos.length,
469
+ inProgress: ctx.todos.filter((t) => t.status === "in_progress").length
470
+ })
471
+ };
472
+ }
473
+ case "compact": {
474
+ if (!opts.compactor) {
475
+ return {
476
+ action: "compact",
477
+ beforeTokens,
478
+ messageCount: messages.length,
479
+ notes: "No compactor registered. Use /compact aggressive via slash command instead."
480
+ };
481
+ }
482
+ const report = await opts.compactor.compact(ctx);
483
+ return {
484
+ action: "compact",
485
+ beforeTokens,
486
+ afterTokens: report.after,
487
+ messageCount: messages.length
488
+ };
489
+ }
490
+ case "prune": {
491
+ const from = input.from ?? 0;
492
+ const to = input.to ?? messages.length - 1;
493
+ if (from < 0 || to >= messages.length || from > to) {
494
+ return {
495
+ action: "prune",
496
+ beforeTokens,
497
+ messageCount: messages.length,
498
+ notes: `Invalid range [${from}, ${to}] for ${messages.length} messages.`
499
+ };
500
+ }
501
+ const copy = [...messages];
502
+ const removed = copy.splice(from, to - from + 1);
503
+ applyMessages(copy);
504
+ const afterTokens = roughEstimate(copy);
505
+ return {
506
+ action: "prune",
507
+ beforeTokens,
508
+ afterTokens,
509
+ messageCount: copy.length,
510
+ removedCount: removed.length
511
+ };
512
+ }
513
+ case "add_note": {
514
+ const noteText = input.text ?? "(no summary)";
515
+ const afterIdx = Math.min(input.afterIndex ?? 0, messages.length);
516
+ const noteMsg = {
517
+ role: "system",
518
+ content: `[note: ${noteText}]`
519
+ };
520
+ const copy = [...messages];
521
+ copy.splice(afterIdx, 0, noteMsg);
522
+ applyMessages(copy);
523
+ const afterTokens = roughEstimate(copy);
524
+ return {
525
+ action: "add_note",
526
+ beforeTokens,
527
+ afterTokens,
528
+ messageCount: copy.length,
529
+ summary: noteText
530
+ };
531
+ }
532
+ case "summary": {
533
+ const from = input.from ?? 0;
534
+ const to = input.to ?? messages.length - 1;
535
+ if (from < 0 || to >= messages.length || from > to) {
536
+ return {
537
+ action: "summary",
538
+ beforeTokens,
539
+ messageCount: messages.length,
540
+ notes: `Invalid range [${from}, ${to}] for ${messages.length} messages.`
541
+ };
542
+ }
543
+ const summaryText = input.text ?? '[summary placeholder \u2014 provide "text" to record the summary]';
544
+ const summaryMsg = {
545
+ role: "system",
546
+ content: `[summary of messages ${from}\u2013${to}]: ${summaryText}`
547
+ };
548
+ const copy = [...messages];
549
+ copy.splice(from, to - from + 1, summaryMsg);
550
+ applyMessages(copy);
551
+ const afterTokens = roughEstimate(copy);
552
+ return {
553
+ action: "summary",
554
+ beforeTokens,
555
+ afterTokens,
556
+ messageCount: copy.length,
557
+ summary: summaryText
558
+ };
559
+ }
560
+ default:
561
+ return {
562
+ action: input.action,
563
+ beforeTokens,
564
+ messageCount: messages.length,
565
+ notes: `Unknown action: ${input.action}`
566
+ };
567
+ }
568
+ }
569
+ };
570
+ }
571
+ var contextManagerTool = createContextManagerTool();
572
+
573
+ export { DefaultLogger, DefaultPathResolver, DefaultTokenCounter, allServers, awsServer, blockServer, braveSearchServer, context7Server, contextManagerTool, createContextManagerTool, everArtServer, filesystemServer, githubServer, googleMapsServer, sentinelServer, slackServer };
574
+ //# sourceMappingURL=index.js.map
575
+ //# sourceMappingURL=index.js.map