@wrongstack/core 0.292.1 → 0.293.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 (51) hide show
  1. package/dist/coordination/index.js.map +2 -2
  2. package/dist/core/fallback-profile-manager.d.ts +0 -2
  3. package/dist/core/fallback-profile-manager.d.ts.map +1 -1
  4. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  5. package/dist/defaults/index.js +346 -317
  6. package/dist/defaults/index.js.map +4 -4
  7. package/dist/execution/compaction-core.d.ts +3 -0
  8. package/dist/execution/compaction-core.d.ts.map +1 -1
  9. package/dist/execution/compactor.d.ts +4 -0
  10. package/dist/execution/compactor.d.ts.map +1 -1
  11. package/dist/execution/index.js +133 -49
  12. package/dist/execution/index.js.map +4 -4
  13. package/dist/execution/intelligent-compactor.d.ts +5 -1
  14. package/dist/execution/intelligent-compactor.d.ts.map +1 -1
  15. package/dist/execution/selective-compactor.d.ts +4 -0
  16. package/dist/execution/selective-compactor.d.ts.map +1 -1
  17. package/dist/goal/phase-orchestrator.d.ts +4 -0
  18. package/dist/goal/phase-orchestrator.d.ts.map +1 -1
  19. package/dist/hooks/runner.d.ts +0 -2
  20. package/dist/hooks/runner.d.ts.map +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +116 -109
  24. package/dist/index.js.map +2 -2
  25. package/dist/models/alibaba-token-plan-catalog.d.ts +85 -0
  26. package/dist/models/alibaba-token-plan-catalog.d.ts.map +1 -0
  27. package/dist/models/index.d.ts +1 -0
  28. package/dist/models/index.d.ts.map +1 -1
  29. package/dist/models/index.js +200 -15
  30. package/dist/models/index.js.map +4 -4
  31. package/dist/models/llm-selector.d.ts +4 -0
  32. package/dist/models/llm-selector.d.ts.map +1 -1
  33. package/dist/models/models-registry.d.ts +8 -0
  34. package/dist/models/models-registry.d.ts.map +1 -1
  35. package/dist/security/index.js +0 -23
  36. package/dist/security/index.js.map +2 -2
  37. package/dist/security/permission-policy.d.ts +0 -23
  38. package/dist/security/permission-policy.d.ts.map +1 -1
  39. package/dist/storage/config-loader.d.ts.map +1 -1
  40. package/dist/storage/index.js +6 -5
  41. package/dist/storage/index.js.map +2 -2
  42. package/dist/tools/index.js.map +2 -2
  43. package/dist/types/config.d.ts +9 -16
  44. package/dist/types/config.d.ts.map +1 -1
  45. package/dist/types/index.js +2 -3
  46. package/dist/types/index.js.map +2 -2
  47. package/dist/utils/index.js +15 -0
  48. package/dist/utils/index.js.map +2 -2
  49. package/dist/utils/merge-models-payload.d.ts +9 -0
  50. package/dist/utils/merge-models-payload.d.ts.map +1 -1
  51. package/package.json +2 -2
@@ -1,5 +1,8 @@
1
1
  import type { Message } from '../types/messages.js';
2
+ import type { Logger } from '../types/logger.js';
2
3
  import { estimateMessageTokens } from '../utils/token-estimate.js';
4
+ /** Set the module-level compaction debug logger (called by compactor constructors). */
5
+ export declare function setCompactionDebugLogger(logger: Logger | undefined): void;
3
6
  /**
4
7
  * Token estimate for a message array (text + tool I/O). Re-exported from the
5
8
  * canonical `token-estimate` helper so compactors and the context-pressure
@@ -1 +1 @@
1
- {"version":3,"file":"compaction-core.d.ts","sourceRoot":"","sources":["../../src/execution/compaction-core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAEL,qBAAqB,EAItB,MAAM,4BAA4B,CAAC;AAmIpC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,8BAAwB,CAAC;AAStD;;;;;;;;;;;GAWG;AAEH,kDAAkD;AAClD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAGlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA8CzF;AAiCD,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,QAA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E,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAS/F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAczF"}
@@ -1,5 +1,6 @@
1
1
  import type { Context } from '../core/context.js';
2
2
  import type { CompactReport, Compactor } from '../types/compactor.js';
3
+ import type { Logger } from '../types/logger.js';
3
4
  export interface CompactorOptions {
4
5
  preserveK?: number | undefined;
5
6
  eliseThreshold?: number | undefined;
@@ -17,6 +18,8 @@ export interface CompactorOptions {
17
18
  * monitor agree on one number. Kept only for backward-compatible call sites.
18
19
  */
19
20
  estimator?: (((text: string) => number)) | undefined;
21
+ /** Structured logger. Defaults to noOpLogger (silent). */
22
+ logger?: Logger | undefined;
20
23
  }
21
24
  /**
22
25
  * Default tools config values shared across CLI and WebUI.
@@ -31,6 +34,7 @@ export declare class HybridCompactor implements Compactor {
31
34
  private readonly preserveK;
32
35
  private readonly eliseThreshold;
33
36
  private readonly smart;
37
+ private readonly logger;
34
38
  constructor(opts?: CompactorOptions);
35
39
  compact(ctx: Context, opts?: {
36
40
  aggressive?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"compactor.d.ts","sourceRoot":"","sources":["../../src/execution/compactor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAmBtE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE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AC;CAC7B;AAED;;;;;;;GAOG;AACH,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAEnH,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,YAAY,IAAI,GAAE,gBAAqB,EAMtC;IAEK,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,GAAE;QAAE,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAmEnG;IAED;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,oBAAoB;CAiD7B"}
@@ -82,6 +82,50 @@ async function renameWithRetry(from, to) {
82
82
  throw lastErr;
83
83
  }
84
84
 
85
+ // src/utils/term.ts
86
+ var hasStdout = () => typeof process !== "undefined" && !!process.stdout;
87
+ function isStdoutTTY() {
88
+ return hasStdout() && Boolean(process.stdout.isTTY);
89
+ }
90
+ var ESCAPE_TERMINATOR = Object.freeze({
91
+ BEL: "\x07",
92
+ // OSC 0 / OSC 2 (title)
93
+ ST: "\x1B\\"
94
+ // DCS / strict OSC
95
+ });
96
+
97
+ // src/utils/color.ts
98
+ var isColorTty = () => {
99
+ if (envFlag(process.env.NO_COLOR)) return false;
100
+ if (envFlag(process.env.FORCE_COLOR)) return true;
101
+ return isStdoutTTY();
102
+ };
103
+ function envFlag(value) {
104
+ if (value === void 0) return false;
105
+ if (value.trim() === "") return false;
106
+ return !/^(0|false|no|off)$/i.test(value.trim());
107
+ }
108
+ var COLOR = isColorTty();
109
+ var wrap = (open2, close) => (s) => COLOR ? `\x1B[${open2}m${s}\x1B[${close}m` : s;
110
+ var color = {
111
+ reset: wrap("0", "0"),
112
+ bold: wrap("1", "22"),
113
+ dim: wrap("2", "22"),
114
+ italic: wrap("3", "23"),
115
+ underline: wrap("4", "24"),
116
+ red: wrap("31", "39"),
117
+ green: wrap("32", "39"),
118
+ yellow: wrap("33", "39"),
119
+ blue: wrap("34", "39"),
120
+ magenta: wrap("35", "39"),
121
+ cyan: wrap("36", "39"),
122
+ gray: wrap("90", "39"),
123
+ amber: wrap("38;5;214", "39"),
124
+ pink: wrap("38;5;205", "39"),
125
+ bgRed: wrap("41", "49"),
126
+ bgGreen: wrap("42", "49")
127
+ };
128
+
85
129
  // src/types/blocks.ts
86
130
  function isTextBlock(b) {
87
131
  return b.type === "text";
@@ -2044,25 +2088,30 @@ var WHITESPACE_COLLAPSE_PATTERN = /\s+/g;
2044
2088
  function compactionDebugEnabled() {
2045
2089
  return process.env["NODE_ENV"] === "development" || process.env["WRONGSTACK_DEBUG"] === "1";
2046
2090
  }
2091
+ var _debugLogger;
2092
+ function setCompactionDebugLogger(logger) {
2093
+ _debugLogger = logger;
2094
+ }
2047
2095
  function emitCompactionMetrics(event, metrics) {
2048
2096
  if (!compactionDebugEnabled()) return;
2049
- console.log(
2050
- JSON.stringify({
2051
- level: "debug",
2052
- event,
2053
- messageCount: metrics.messageCount,
2054
- preserveStart: metrics.preserveStart,
2055
- fastPathIterations: metrics.fastPathIterations,
2056
- fastPathInnerIterations: metrics.fastPathInnerIterations,
2057
- // Ratios — anything > 2.0 indicates the inner loop is running more than expected
2058
- fastPathInnerPerOuter: metrics.fastPathIterations > 0 ? metrics.fastPathInnerIterations / metrics.fastPathIterations : 0,
2059
- fullPassIterations: metrics.fullPassIterations,
2060
- fullPassInnerIterations: metrics.fullPassInnerIterations,
2061
- fullPassInnerPerOuter: metrics.fullPassIterations > 0 ? metrics.fullPassInnerIterations / metrics.fullPassIterations : 0,
2062
- tokensSaved: metrics.tokensSaved,
2063
- changed: metrics.changed
2064
- })
2065
- );
2097
+ const ctx = {
2098
+ event,
2099
+ messageCount: metrics.messageCount,
2100
+ preserveStart: metrics.preserveStart,
2101
+ fastPathIterations: metrics.fastPathIterations,
2102
+ fastPathInnerIterations: metrics.fastPathInnerIterations,
2103
+ fastPathInnerPerOuter: metrics.fastPathIterations > 0 ? metrics.fastPathInnerIterations / metrics.fastPathIterations : 0,
2104
+ fullPassIterations: metrics.fullPassIterations,
2105
+ fullPassInnerIterations: metrics.fullPassInnerIterations,
2106
+ fullPassInnerPerOuter: metrics.fullPassIterations > 0 ? metrics.fullPassInnerIterations / metrics.fullPassIterations : 0,
2107
+ tokensSaved: metrics.tokensSaved,
2108
+ changed: metrics.changed
2109
+ };
2110
+ if (_debugLogger) {
2111
+ _debugLogger.debug(`compaction: ${event}`, ctx);
2112
+ } else {
2113
+ console.log(JSON.stringify({ level: "debug", ...ctx }));
2114
+ }
2066
2115
  }
2067
2116
  var estimateMessages = estimateMessageTokens;
2068
2117
  function hasTextContent(m) {
@@ -2094,18 +2143,20 @@ function findPreserveStart(messages, preserveK) {
2094
2143
  preserveStart--;
2095
2144
  }
2096
2145
  if (compactionDebugEnabled()) {
2097
- console.log(
2098
- JSON.stringify({
2099
- level: "debug",
2100
- event: "compaction.find_preserve_start.ended",
2101
- messageCount: messages.length,
2102
- preserveK,
2103
- preserveStart,
2104
- pairRepairIterations,
2105
- pairRepairInnerIterations,
2106
- pairRepairInnerPerOuter: pairRepairIterations > 0 ? pairRepairInnerIterations / pairRepairIterations : 0
2107
- })
2108
- );
2146
+ const ctx = {
2147
+ event: "compaction.find_preserve_start.ended",
2148
+ messageCount: messages.length,
2149
+ preserveK,
2150
+ preserveStart,
2151
+ pairRepairIterations,
2152
+ pairRepairInnerIterations,
2153
+ pairRepairInnerPerOuter: pairRepairIterations > 0 ? pairRepairInnerIterations / pairRepairIterations : 0
2154
+ };
2155
+ if (_debugLogger) {
2156
+ _debugLogger.debug("compaction: find_preserve_start.ended", ctx);
2157
+ } else {
2158
+ console.log(JSON.stringify({ level: "debug", ...ctx }));
2159
+ }
2109
2160
  }
2110
2161
  return preserveStart;
2111
2162
  }
@@ -2220,16 +2271,18 @@ function eliseOldToolResults(messages, opts) {
2220
2271
  if (compactionDebugEnabled()) {
2221
2272
  const ratio = fullPassInnerIterations / fullPassIterations;
2222
2273
  if (ratio > 10) {
2223
- console.error(
2224
- JSON.stringify({
2225
- level: "error",
2226
- event: "compaction.elision.regression",
2227
- message: `fullPassInnerPerOuter=${ratio.toFixed(2)} exceeds threshold 10 \u2014 possible O(n\xB7m) regression`,
2228
- messageCount: messages.length,
2229
- fullPassIterations,
2230
- fullPassInnerIterations
2231
- })
2232
- );
2274
+ const ctx = {
2275
+ event: "compaction.elision.regression",
2276
+ message: `fullPassInnerPerOuter=${ratio.toFixed(2)} exceeds threshold 10 \u2014 possible O(n\xB7m) regression`,
2277
+ messageCount: messages.length,
2278
+ fullPassIterations,
2279
+ fullPassInnerIterations
2280
+ };
2281
+ if (_debugLogger) {
2282
+ _debugLogger.error(`compaction: elision.regression \u2014 ratio ${ratio.toFixed(2)}`, ctx);
2283
+ } else {
2284
+ console.error(JSON.stringify({ level: "error", ...ctx }));
2285
+ }
2233
2286
  }
2234
2287
  }
2235
2288
  }
@@ -3248,15 +3301,43 @@ function resolveContextWindowPolicy(config = {}, overrideMode) {
3248
3301
  };
3249
3302
  }
3250
3303
 
3304
+ // src/infrastructure/logger.ts
3305
+ var COLORS = {
3306
+ error: color.red,
3307
+ warn: color.yellow,
3308
+ info: color.cyan,
3309
+ debug: color.gray,
3310
+ trace: color.dim
3311
+ };
3312
+ var noOpLogger = {
3313
+ // 'error' is the quietest level the Logger contract offers; the methods
3314
+ // discard everything regardless, this only matters to level checks.
3315
+ level: "error",
3316
+ error: () => {
3317
+ },
3318
+ warn: () => {
3319
+ },
3320
+ info: () => {
3321
+ },
3322
+ debug: () => {
3323
+ },
3324
+ trace: () => {
3325
+ },
3326
+ child: () => noOpLogger
3327
+ };
3328
+
3251
3329
  // src/execution/compactor.ts
3252
3330
  var HybridCompactor = class {
3253
3331
  preserveK;
3254
3332
  eliseThreshold;
3255
3333
  smart;
3334
+ logger;
3256
3335
  constructor(opts = {}) {
3257
3336
  this.preserveK = opts.preserveK ?? 5;
3258
3337
  this.eliseThreshold = opts.eliseThreshold ?? 2e3;
3259
3338
  this.smart = opts.smart ?? false;
3339
+ this.logger = opts.logger ?? noOpLogger;
3340
+ setCompactionDebugLogger(this.logger);
3260
3341
  }
3261
3342
  async compact(ctx, opts = {}) {
3262
3343
  const beforeTokens = estimateMessages(ctx.messages);
@@ -8188,6 +8269,7 @@ var IntelligentCompactor = class {
8188
8269
  summarizerPrompt;
8189
8270
  summarizerModel;
8190
8271
  oneShotOrchestrator;
8272
+ logger;
8191
8273
  constructor(opts) {
8192
8274
  this.provider = opts.provider;
8193
8275
  this.warnThreshold = opts.warnThreshold ?? 0.5;
@@ -8199,6 +8281,8 @@ var IntelligentCompactor = class {
8199
8281
  this.summarizerPrompt = opts.summarizerPrompt ?? readBundledInstructionText("llm/intelligent-compactor-summarizer.md");
8200
8282
  this.summarizerModel = opts.summarizerModel;
8201
8283
  this.oneShotOrchestrator = opts.oneShotOrchestrator;
8284
+ this.logger = opts.logger ?? noOpLogger;
8285
+ setCompactionDebugLogger(this.logger);
8202
8286
  }
8203
8287
  async compact(ctx, opts = {}) {
8204
8288
  const beforeTokens = estimateMessages(ctx.messages);
@@ -12840,11 +12924,13 @@ var LLMSelector = class {
12840
12924
  systemPrompt;
12841
12925
  maxOutputTokens;
12842
12926
  oneShotOrchestrator;
12927
+ logger;
12843
12928
  constructor(opts) {
12844
12929
  this.provider = opts.provider;
12845
12930
  this.model = opts.model ?? "unknown";
12931
+ this.logger = opts.logger ?? noOpLogger;
12846
12932
  if (this.model === "unknown" && (process.env["NODE_ENV"] === "development" || process.env["WRONGSTACK_DEBUG"] === "1")) {
12847
- console.warn(
12933
+ this.logger.warn(
12848
12934
  "[LLMSelector] model not set \u2014 selector will use the provider default. Set `model` explicitly in LLMSelectorOptions to silence this warning."
12849
12935
  );
12850
12936
  }
@@ -12894,14 +12980,9 @@ IMPORTANT: Total conversation (${totalTokens} tokens) exceeds budget (${effectiv
12894
12980
  }
12895
12981
  } catch (err) {
12896
12982
  if (err instanceof Error) {
12897
- console.warn(
12898
- JSON.stringify({
12899
- level: "warn",
12900
- event: "llm_selector.call_failed",
12901
- message: `selector call failed, using recency fallback: ${err.message}`,
12902
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
12903
- })
12904
- );
12983
+ this.logger.warn(`selector call failed, using recency fallback: ${err.message}`, {
12984
+ event: "llm_selector.call_failed"
12985
+ });
12905
12986
  }
12906
12987
  return this.fallbackSelect(messages, effectiveBudget);
12907
12988
  } finally {
@@ -13008,6 +13089,7 @@ var SelectiveCompactor = class {
13008
13089
  eliseThreshold;
13009
13090
  summarizerModel;
13010
13091
  summarizerPrompt;
13092
+ logger;
13011
13093
  constructor(opts) {
13012
13094
  this.provider = opts.provider;
13013
13095
  this.selector = opts.selector ?? new LLMSelector({ provider: opts.provider, model: opts.selectorModel, maxOutputTokens: opts.selectorMaxOutputTokens });
@@ -13018,8 +13100,10 @@ var SelectiveCompactor = class {
13018
13100
  this.preserveK = opts.preserveK ?? 4;
13019
13101
  this.eliseThreshold = opts.eliseThreshold ?? 300;
13020
13102
  this.summarizerModel = opts.summarizerModel ?? opts.selectorModel;
13103
+ this.logger = opts.logger ?? noOpLogger;
13104
+ setCompactionDebugLogger(this.logger);
13021
13105
  if (this.summarizerModel === void 0 && (process.env["NODE_ENV"] === "development" || process.env["WRONGSTACK_DEBUG"] === "1")) {
13022
- console.warn(
13106
+ this.logger.warn(
13023
13107
  "[SelectiveCompactor] summarizerModel not set \u2014 will fall back to ctx.model at summarize time. Set `summarizerModel` explicitly to silence this warning."
13024
13108
  );
13025
13109
  }