@wrongstack/core 0.77.0 → 0.82.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-bridge-EWdqs8v6.d.ts → agent-bridge-C9P_HPez.d.ts} +2 -2
- package/dist/{agent-subagent-runner-D8qW8OSC.d.ts → agent-subagent-runner-2Aq0jOSj.d.ts} +107 -102
- package/dist/{compactor-D_ExJajC.d.ts → compactor-CJq7LQev.d.ts} +3 -3
- package/dist/{config-Dy0CK_o6.d.ts → config-_DZ7dN-T.d.ts} +77 -75
- package/dist/{context-y87Jc5ei.d.ts → context-ToHAp4-U.d.ts} +119 -90
- package/dist/coordination/index.d.ts +16 -16
- package/dist/coordination/index.js +318 -37
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +31 -31
- package/dist/defaults/index.js +419 -67
- package/dist/defaults/index.js.map +1 -1
- package/dist/{director-state-BmYi3DGA.d.ts → director-state-CgIc30qi.d.ts} +19 -19
- package/dist/{events-CYaoLN5_.d.ts → events-DnRqXaZ3.d.ts} +43 -42
- package/dist/execution/index.d.ts +53 -53
- package/dist/execution/index.js +67 -23
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +9 -9
- package/dist/extension/index.js +8 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{goal-store-C7jcumEh.d.ts → goal-store-DvWLNu52.d.ts} +4 -4
- package/dist/{index-DIxjTOga.d.ts → index-BNOLadHw.d.ts} +28 -28
- package/dist/{index-Dsda0uCn.d.ts → index-N0_c4bHQ.d.ts} +45 -45
- package/dist/index.d.ts +165 -165
- package/dist/index.js +593 -137
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +9 -9
- package/dist/infrastructure/index.js +13 -5
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/kernel/index.d.ts +14 -14
- package/dist/kernel/index.js +7 -0
- package/dist/kernel/index.js.map +1 -1
- package/dist/logger-B72yyPc6.d.ts +12 -0
- package/dist/{logger-BppKxDqZ.d.ts → logger-C_27pj9i.d.ts} +6 -7
- package/dist/{mcp-servers-T0O6UN_w.d.ts → mcp-servers-Dck3T85_.d.ts} +20 -20
- package/dist/{mode-BO4SEUIv.d.ts → mode-CHo2XtHs.d.ts} +4 -4
- package/dist/models/index.d.ts +10 -10
- package/dist/models/index.js +8 -2
- package/dist/models/index.js.map +1 -1
- package/dist/{models-registry-BcYJDKLm.d.ts → models-registry-Be3osGt5.d.ts} +28 -28
- package/dist/{models-registry-Cuq1C8V9.d.ts → models-registry-Boz639EI.d.ts} +12 -12
- package/dist/{multi-agent-coordinator-DpbG3wiy.d.ts → multi-agent-coordinator-DllpCVkF.d.ts} +12 -12
- package/dist/{null-fleet-bus-u5ys3lW_.d.ts → null-fleet-bus-BY0AN-sr.d.ts} +121 -121
- package/dist/observability/index.d.ts +41 -41
- package/dist/observability/index.js.map +1 -1
- package/dist/{observability-BhnVLBLS.d.ts → observability-CoSNZdhX.d.ts} +4 -4
- package/dist/{parallel-eternal-engine-Dn0P8Pbj.d.ts → parallel-eternal-engine-D402RASp.d.ts} +49 -49
- package/dist/{path-resolver-B32v2JIq.d.ts → path-resolver-UPFTsDyD.d.ts} +6 -6
- package/dist/{permission-V5BLOrY6.d.ts → permission-14CChMmO.d.ts} +10 -8
- package/dist/{permission-policy-CBVx-d-8.d.ts → permission-policy-gW5htOo1.d.ts} +7 -7
- package/dist/{plan-templates-BcUwLlMQ.d.ts → plan-templates-DRvPgkfZ.d.ts} +65 -32
- package/dist/{provider-runner-CSi_7l0h.d.ts → provider-runner-COAJM8tC.d.ts} +6 -6
- package/dist/{retry-policy-CG3qvH_e.d.ts → retry-policy-DSu6O6rD.d.ts} +4 -4
- package/dist/sdd/index.d.ts +47 -47
- package/dist/sdd/index.js +47 -22
- package/dist/sdd/index.js.map +1 -1
- package/dist/security/index.d.ts +6 -6
- package/dist/security/index.js +7 -1
- package/dist/security/index.js.map +1 -1
- package/dist/{selector-RvBR_YRW.d.ts → selector-11-fm95U.d.ts} +2 -2
- package/dist/{session-event-bridge-CDHxcmQU.d.ts → session-event-bridge-D0u-x576.d.ts} +7 -7
- package/dist/{session-reader-BIpwM60D.d.ts → session-reader-BQU-toaN.d.ts} +23 -23
- package/dist/{skill-CxuWrsKK.d.ts → skill-BJeF2DwY.d.ts} +1 -1
- package/dist/skills/index.d.ts +9 -9
- package/dist/skills/index.js +15 -3
- package/dist/skills/index.js.map +1 -1
- package/dist/storage/index.d.ts +15 -15
- package/dist/storage/index.js +378 -76
- package/dist/storage/index.js.map +1 -1
- package/dist/{system-prompt-CA11g6Jo.d.ts → system-prompt-C0rLCeyn.d.ts} +16 -11
- package/dist/{task-graph-D1YQbpxF.d.ts → task-graph-CikNdRTG.d.ts} +22 -22
- package/dist/types/index.d.ts +25 -25
- package/dist/types/index.js +45 -10
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +46 -45
- package/dist/utils/index.js +53 -12
- package/dist/utils/index.js.map +1 -1
- package/dist/{wstack-paths-D7evAFWM.d.ts → wstack-paths-BQMvEllz.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/logger-DDd5C--Z.d.ts +0 -12
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { N as TodoItem, M as Message, J as JSONSchema } from '../context-
|
|
2
|
-
export { W as WstackPathOptions, a as WstackPaths, p as projectHash, b as projectSlug, r as resolveWstackPaths } from '../wstack-paths-
|
|
3
|
-
import { M as ModelsDevPayload } from '../models-registry-
|
|
4
|
-
import { k as CustomModelDefinition } from '../config-
|
|
1
|
+
import { N as TodoItem, M as Message, J as JSONSchema } from '../context-ToHAp4-U.js';
|
|
2
|
+
export { W as WstackPathOptions, a as WstackPaths, p as projectHash, b as projectSlug, r as resolveWstackPaths } from '../wstack-paths-BQMvEllz.js';
|
|
3
|
+
import { M as ModelsDevPayload } from '../models-registry-Be3osGt5.js';
|
|
4
|
+
import { k as CustomModelDefinition } from '../config-_DZ7dN-T.js';
|
|
5
5
|
|
|
6
6
|
interface AtomicWriteOptions {
|
|
7
|
-
mode?: number;
|
|
8
|
-
encoding?: BufferEncoding;
|
|
7
|
+
mode?: number | undefined;
|
|
8
|
+
encoding?: BufferEncoding | undefined;
|
|
9
9
|
}
|
|
10
10
|
declare function atomicWrite(targetPath: string, content: string | Uint8Array, opts?: AtomicWriteOptions): Promise<void>;
|
|
11
11
|
declare function ensureDir(dir: string): Promise<void>;
|
|
12
12
|
|
|
13
13
|
interface SafeParseResult<T> {
|
|
14
14
|
ok: boolean;
|
|
15
|
-
value?: T;
|
|
16
|
-
error?: string;
|
|
15
|
+
value?: T | undefined;
|
|
16
|
+
error?: string | undefined;
|
|
17
17
|
}
|
|
18
18
|
declare function safeParse<T = unknown>(input: string, maxBytes?: number): SafeParseResult<T>;
|
|
19
19
|
declare function safeStringify(value: unknown, pretty?: boolean): string;
|
|
@@ -116,6 +116,33 @@ declare function onResize(cb: (size: {
|
|
|
116
116
|
* `if (input.isTTY) input.setRawMode(...)` ceremony at every call site.
|
|
117
117
|
*/
|
|
118
118
|
declare function setRawMode(input: NodeJS.ReadStream, mode: boolean): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Bracket installed by the interactive input reader while a `readline`
|
|
121
|
+
* prompt is on screen. Out-of-band terminal writes — logger WARN/INFO
|
|
122
|
+
* lines, async activity from the Telegram bridge, etc. — go to the same
|
|
123
|
+
* physical terminal as the half-typed prompt but readline has no idea they
|
|
124
|
+
* happened, so it never repaints. The result is the classic corruption the
|
|
125
|
+
* user sees: every async line strands the in-progress draft as a fresh
|
|
126
|
+
* scrollback row (sometimes with its cursor underline).
|
|
127
|
+
*
|
|
128
|
+
* The guard closes that gap. `suspend()` wipes the draft row so the message
|
|
129
|
+
* prints clean; `resume()` repaints the prompt + draft (cursor preserved).
|
|
130
|
+
* When no prompt is active the guard is `null` and writes pass straight
|
|
131
|
+
* through — so agent-turn output (spinner, renderer) is untouched.
|
|
132
|
+
*/
|
|
133
|
+
interface OutputLineGuard {
|
|
134
|
+
/** Clear the current input row right before an out-of-band write. */
|
|
135
|
+
suspend(): void;
|
|
136
|
+
/** Repaint the prompt + in-progress draft right after the write. */
|
|
137
|
+
resume(): void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Register (or clear, with `null`) the guard that brackets out-of-band
|
|
141
|
+
* writes. Installed by {@link writeOut}/{@link writeErr} consumers — in
|
|
142
|
+
* practice the CLI's readline input reader — only while a prompt is live.
|
|
143
|
+
* Idempotent; the most recent caller wins.
|
|
144
|
+
*/
|
|
145
|
+
declare function setOutputLineGuard(guard: OutputLineGuard | null): void;
|
|
119
146
|
/**
|
|
120
147
|
* Write `s` to `stream` (defaults to `process.stdout`). Returns `false`
|
|
121
148
|
* when the stream is missing or doesn't expose `write` so callers can
|
|
@@ -175,13 +202,6 @@ declare function writeErr(s: string, stream?: NodeJS.WriteStream): boolean;
|
|
|
175
202
|
*/
|
|
176
203
|
declare function formatTodosList(todos: TodoItem[]): string;
|
|
177
204
|
|
|
178
|
-
/**
|
|
179
|
-
* Minimal glob matcher for trust patterns.
|
|
180
|
-
* Supports: *, **, ?, character classes [abc], [a-z], negation [!...] or [^...].
|
|
181
|
-
*
|
|
182
|
-
* Compiled regexes are cached so repeated calls with the same pattern
|
|
183
|
-
* avoid recompilation overhead.
|
|
184
|
-
*/
|
|
185
205
|
declare function compileGlob(pattern: string): RegExp;
|
|
186
206
|
declare function matchGlob(pattern: string, input: string): boolean;
|
|
187
207
|
declare function matchAny(patterns: string[], input: string): boolean;
|
|
@@ -191,9 +211,9 @@ declare function matchAny(patterns: string[], input: string): boolean;
|
|
|
191
211
|
* Operates on arrays of lines (newline-terminated or stripped).
|
|
192
212
|
*/
|
|
193
213
|
interface UnifiedDiffOptions {
|
|
194
|
-
context?: number;
|
|
195
|
-
fromFile?: string;
|
|
196
|
-
toFile?: string;
|
|
214
|
+
context?: number | undefined;
|
|
215
|
+
fromFile?: string | undefined;
|
|
216
|
+
toFile?: string | undefined;
|
|
197
217
|
}
|
|
198
218
|
declare function unifiedDiff(oldText: string, newText: string, opts?: UnifiedDiffOptions): string;
|
|
199
219
|
|
|
@@ -218,9 +238,9 @@ declare function unifiedDiff(oldText: string, newText: string, opts?: UnifiedDif
|
|
|
218
238
|
*/
|
|
219
239
|
interface BuildChildEnvOptions {
|
|
220
240
|
/** Session ID to inject as WRONGSTACK_SESSION_ID. */
|
|
221
|
-
sessionId?: string;
|
|
241
|
+
sessionId?: string | undefined;
|
|
222
242
|
/** Additional env vars to merge (takes priority over filtered parent env). */
|
|
223
|
-
extra?: NodeJS.ProcessEnv;
|
|
243
|
+
extra?: NodeJS.ProcessEnv | undefined;
|
|
224
244
|
}
|
|
225
245
|
/**
|
|
226
246
|
* Build a filtered child-process environment suitable for bash, exec, and
|
|
@@ -234,8 +254,8 @@ declare function buildChildEnv(optsOrSessionId?: BuildChildEnvOptions | string):
|
|
|
234
254
|
* Extracted from Agent.executeTools to allow reuse and consistent output handling.
|
|
235
255
|
*/
|
|
236
256
|
interface ToolOutputSerializerOptions {
|
|
237
|
-
perIterationOutputCapBytes?: number;
|
|
238
|
-
estimator?: (text: string) => number;
|
|
257
|
+
perIterationOutputCapBytes?: number | undefined;
|
|
258
|
+
estimator?: ((text: string) => number) | undefined;
|
|
239
259
|
}
|
|
240
260
|
declare function createToolOutputSerializer(opts?: ToolOutputSerializerOptions): {
|
|
241
261
|
serialize: (value: unknown) => string;
|
|
@@ -246,25 +266,6 @@ declare function createToolOutputSerializer(opts?: ToolOutputSerializerOptions):
|
|
|
246
266
|
capBytes: number;
|
|
247
267
|
};
|
|
248
268
|
|
|
249
|
-
/**
|
|
250
|
-
* Shared token estimation with JSON.stringify caching.
|
|
251
|
-
* Avoids repeated stringification of tool input objects.
|
|
252
|
-
*
|
|
253
|
-
* ## Calibration
|
|
254
|
-
*
|
|
255
|
-
* `estimateRequestTokens` uses a fixed 3.5 chars/token heuristic — a
|
|
256
|
-
* conservative overestimate that prevents underestimation but reduces
|
|
257
|
-
* accuracy. After each API call, call `recordActualUsage()` with the
|
|
258
|
-
* real `usage.input` from the provider response. The module maintains a
|
|
259
|
-
* rolling average of `actual / estimated` ratio (EWM, α=0.3) and
|
|
260
|
-
* applies it to subsequent calls via `estimateRequestTokensCalibrated`.
|
|
261
|
-
*
|
|
262
|
-
* Calibration is per-module (shared across all callers), which is
|
|
263
|
-
* sufficient: the chars/token ratio is a property of the tokenizer,
|
|
264
|
-
* not the model. Uncalibrated calls (before any samples, or when
|
|
265
|
-
* `recordActualUsage` is not called) fall back to the uncalibrated
|
|
266
|
-
* estimate so nothing breaks.
|
|
267
|
-
*/
|
|
268
269
|
/**
|
|
269
270
|
* Estimate tokens for a tool_use block input.
|
|
270
271
|
* Caches the stringified result keyed by the stable string representation
|
|
@@ -286,7 +287,7 @@ declare function estimateTextTokens(text: string): number;
|
|
|
286
287
|
*/
|
|
287
288
|
declare function estimateToolDefTokens(tool: {
|
|
288
289
|
name: string;
|
|
289
|
-
description?: string;
|
|
290
|
+
description?: string | undefined;
|
|
290
291
|
inputSchema: unknown;
|
|
291
292
|
}): number;
|
|
292
293
|
/**
|
|
@@ -309,7 +310,7 @@ interface RequestTokenBreakdown {
|
|
|
309
310
|
}
|
|
310
311
|
declare function estimateRequestTokens(messages: unknown, systemPrompt: unknown, tools: {
|
|
311
312
|
name: string;
|
|
312
|
-
description?: string;
|
|
313
|
+
description?: string | undefined;
|
|
313
314
|
inputSchema: unknown;
|
|
314
315
|
}[]): RequestTokenBreakdown;
|
|
315
316
|
/**
|
|
@@ -345,7 +346,7 @@ declare function getCalibrationState(): {
|
|
|
345
346
|
*/
|
|
346
347
|
declare function estimateRequestTokensCalibrated(messages: unknown, systemPrompt: unknown, tools: {
|
|
347
348
|
name: string;
|
|
348
|
-
description?: string;
|
|
349
|
+
description?: string | undefined;
|
|
349
350
|
inputSchema: unknown;
|
|
350
351
|
}[]): RequestTokenBreakdown;
|
|
351
352
|
/**
|
|
@@ -489,4 +490,4 @@ declare function mergeModelsPayload(base: ModelsDevPayload, overlay: ModelsDevPa
|
|
|
489
490
|
*/
|
|
490
491
|
declare function mergeCustomModelDefs(providerCustomModels: Record<string, CustomModelDefinition> | undefined, configModels: Record<string, CustomModelDefinition> | undefined): Record<string, CustomModelDefinition> | undefined;
|
|
491
492
|
|
|
492
|
-
export { type AtomicWriteOptions, type BuildChildEnvOptions, type CompileFail, type CompileResult, type MessageRepairReport, type MessageRepairResult, type NewlineStyle, type RequestTokenBreakdown, type SafeParseResult, type ToolOutputSerializerOptions, type UnifiedDiffOptions, type ValidationError, type ValidationResult, atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, formatTodosList, getCalibrationState, getTermSize, isInteractive, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, recordActualUsage, repairToolUseAdjacency, resetCalibration, safeParse, safeStringify, sanitizeJsonString, setRawMode, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, writeErr, writeOut };
|
|
493
|
+
export { type AtomicWriteOptions, type BuildChildEnvOptions, type CompileFail, type CompileResult, type MessageRepairReport, type MessageRepairResult, type NewlineStyle, type OutputLineGuard, type RequestTokenBreakdown, type SafeParseResult, type ToolOutputSerializerOptions, type UnifiedDiffOptions, type ValidationError, type ValidationResult, atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, formatTodosList, getCalibrationState, getTermSize, isInteractive, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, recordActualUsage, repairToolUseAdjacency, resetCalibration, safeParse, safeStringify, sanitizeJsonString, setOutputLineGuard, setRawMode, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, writeErr, writeOut };
|
package/dist/utils/index.js
CHANGED
|
@@ -121,7 +121,7 @@ function escapeControlCharsInStrings(s) {
|
|
|
121
121
|
let inString = false;
|
|
122
122
|
let out = "";
|
|
123
123
|
for (let i = 0; i < s.length; i++) {
|
|
124
|
-
const c = s
|
|
124
|
+
const c = s.charAt(i);
|
|
125
125
|
if (c === '"' && (i === 0 || s[i - 1] !== "\\")) {
|
|
126
126
|
inString = !inString;
|
|
127
127
|
out += c;
|
|
@@ -159,12 +159,12 @@ function stripSingleLineComments(s) {
|
|
|
159
159
|
const chars = [];
|
|
160
160
|
let i = 0;
|
|
161
161
|
while (i < s.length) {
|
|
162
|
-
const c = s
|
|
163
|
-
if (c === '"' && (i === 0 || s
|
|
162
|
+
const c = s.charAt(i);
|
|
163
|
+
if (c === '"' && (i === 0 || s.charAt(i - 1) !== "\\")) {
|
|
164
164
|
inString = !inString;
|
|
165
165
|
chars.push(c);
|
|
166
|
-
} else if (c === "/" && s
|
|
167
|
-
while (i < s.length && s
|
|
166
|
+
} else if (c === "/" && s.charAt(i + 1) === "/" && !inString) {
|
|
167
|
+
while (i < s.length && s.charAt(i) !== "\n") i++;
|
|
168
168
|
} else {
|
|
169
169
|
chars.push(c);
|
|
170
170
|
}
|
|
@@ -244,9 +244,20 @@ function setRawMode(input, mode) {
|
|
|
244
244
|
input.setRawMode(mode);
|
|
245
245
|
return true;
|
|
246
246
|
}
|
|
247
|
+
var activeOutputGuard = null;
|
|
248
|
+
function setOutputLineGuard(guard) {
|
|
249
|
+
activeOutputGuard = guard;
|
|
250
|
+
}
|
|
247
251
|
function writeTo(s, stream) {
|
|
248
252
|
if (!stream || typeof stream.write !== "function") return false;
|
|
253
|
+
const guard = activeOutputGuard;
|
|
254
|
+
if (!guard) {
|
|
255
|
+
stream.write(s);
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
guard.suspend();
|
|
249
259
|
stream.write(s);
|
|
260
|
+
guard.resume();
|
|
250
261
|
return true;
|
|
251
262
|
}
|
|
252
263
|
function writeOut(s, stream = process.stdout) {
|
|
@@ -306,6 +317,12 @@ function formatTodosList(todos) {
|
|
|
306
317
|
}
|
|
307
318
|
|
|
308
319
|
// src/utils/glob-match.ts
|
|
320
|
+
function expectDefined(value) {
|
|
321
|
+
if (value === null || value === void 0) {
|
|
322
|
+
throw new Error("Expected value to be defined");
|
|
323
|
+
}
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
309
326
|
function escapeRegex(s) {
|
|
310
327
|
return s.replace(/[.+^${}()|\\]/g, "\\$&");
|
|
311
328
|
}
|
|
@@ -317,7 +334,7 @@ function getCachedGlob(pattern) {
|
|
|
317
334
|
if (COMPILED_GLOB_CACHE.size >= CACHE_MAX_SIZE) {
|
|
318
335
|
const keys = [...COMPILED_GLOB_CACHE.keys()];
|
|
319
336
|
for (let i = 0; i < Math.floor(CACHE_MAX_SIZE / 4); i++) {
|
|
320
|
-
COMPILED_GLOB_CACHE.delete(keys[i]);
|
|
337
|
+
COMPILED_GLOB_CACHE.delete(expectDefined(keys[i]));
|
|
321
338
|
}
|
|
322
339
|
}
|
|
323
340
|
const re = compileGlob(pattern);
|
|
@@ -718,6 +735,12 @@ function createToolOutputSerializer(opts = {}) {
|
|
|
718
735
|
}
|
|
719
736
|
|
|
720
737
|
// src/utils/token-estimate.ts
|
|
738
|
+
function expectDefined2(value) {
|
|
739
|
+
if (value === null || value === void 0) {
|
|
740
|
+
throw new Error("Expected value to be defined");
|
|
741
|
+
}
|
|
742
|
+
return value;
|
|
743
|
+
}
|
|
721
744
|
var RoughTokenEstimate = (text, charsPerToken = 3.5) => Math.max(1, Math.ceil(text.length / charsPerToken));
|
|
722
745
|
var _cal = {
|
|
723
746
|
ratio: 1,
|
|
@@ -738,7 +761,7 @@ function getCachedEstimate(key, compute) {
|
|
|
738
761
|
if (ESTIMATE_CACHE.size >= ESTIMATE_CACHE_MAX_SIZE) {
|
|
739
762
|
const keys = [...ESTIMATE_CACHE.keys()];
|
|
740
763
|
for (let i = 0; i < Math.floor(ESTIMATE_CACHE_MAX_SIZE / 4); i++) {
|
|
741
|
-
ESTIMATE_CACHE.delete(keys[i]);
|
|
764
|
+
ESTIMATE_CACHE.delete(expectDefined2(keys[i]));
|
|
742
765
|
}
|
|
743
766
|
}
|
|
744
767
|
const estimate = compute();
|
|
@@ -851,6 +874,12 @@ function resetCalibration() {
|
|
|
851
874
|
}
|
|
852
875
|
|
|
853
876
|
// src/utils/message-invariants.ts
|
|
877
|
+
function expectDefined3(value) {
|
|
878
|
+
if (value === null || value === void 0) {
|
|
879
|
+
throw new Error("Expected value to be defined");
|
|
880
|
+
}
|
|
881
|
+
return value;
|
|
882
|
+
}
|
|
854
883
|
function repairToolUseAdjacency(messages) {
|
|
855
884
|
const removedToolUses = [];
|
|
856
885
|
const removedToolResults = [];
|
|
@@ -858,7 +887,7 @@ function repairToolUseAdjacency(messages) {
|
|
|
858
887
|
let changed = false;
|
|
859
888
|
const out = [];
|
|
860
889
|
for (let i = 0; i < messages.length; i++) {
|
|
861
|
-
const original = messages[i];
|
|
890
|
+
const original = expectDefined3(messages[i]);
|
|
862
891
|
let msg = original;
|
|
863
892
|
if (hasToolUse(msg)) {
|
|
864
893
|
const nextIds = toolResultIds(messages[i + 1]);
|
|
@@ -1071,6 +1100,12 @@ function compileUserRegex(pattern, flags) {
|
|
|
1071
1100
|
};
|
|
1072
1101
|
}
|
|
1073
1102
|
}
|
|
1103
|
+
function expectDefined4(value) {
|
|
1104
|
+
if (value === null || value === void 0) {
|
|
1105
|
+
throw new Error("Expected value to be defined");
|
|
1106
|
+
}
|
|
1107
|
+
return value;
|
|
1108
|
+
}
|
|
1074
1109
|
var GLOB_CHARS = /* @__PURE__ */ new Set(["*", "?", "["]);
|
|
1075
1110
|
var IS_WINDOWS = process.platform === "win32";
|
|
1076
1111
|
var SEP = IS_WINDOWS ? "\\" : "/";
|
|
@@ -1084,7 +1119,7 @@ function globToRegex(pat) {
|
|
|
1084
1119
|
let i = 0;
|
|
1085
1120
|
let re = "^";
|
|
1086
1121
|
while (i < pat.length) {
|
|
1087
|
-
const c = pat[i];
|
|
1122
|
+
const c = expectDefined4(pat[i]);
|
|
1088
1123
|
if (c === "*") {
|
|
1089
1124
|
if (pat[i + 1] === "*") {
|
|
1090
1125
|
re += ".*";
|
|
@@ -1123,7 +1158,7 @@ function globToRegex(pat) {
|
|
|
1123
1158
|
}
|
|
1124
1159
|
function baseDir(pat) {
|
|
1125
1160
|
let i = pat.length - 1;
|
|
1126
|
-
while (i >= 0 && !GLOB_CHARS.has(pat[i]) && pat[i] !== SEP && pat[i] !== "/") i--;
|
|
1161
|
+
while (i >= 0 && !GLOB_CHARS.has(expectDefined4(pat[i])) && pat[i] !== SEP && pat[i] !== "/") i--;
|
|
1127
1162
|
const cut = i >= 0 ? pat.lastIndexOf(SEP, i) : pat.lastIndexOf("/", i);
|
|
1128
1163
|
return cut < 0 ? "." : pat.slice(0, cut);
|
|
1129
1164
|
}
|
|
@@ -1188,6 +1223,12 @@ async function expandGlob(pattern) {
|
|
|
1188
1223
|
}
|
|
1189
1224
|
|
|
1190
1225
|
// src/utils/json-repair.ts
|
|
1226
|
+
function expectDefined5(value) {
|
|
1227
|
+
if (value === null || value === void 0) {
|
|
1228
|
+
throw new Error("Expected value to be defined");
|
|
1229
|
+
}
|
|
1230
|
+
return value;
|
|
1231
|
+
}
|
|
1191
1232
|
function completePartialObject(s) {
|
|
1192
1233
|
if (!s.trim().startsWith("{")) return s;
|
|
1193
1234
|
if (tryParse(s).ok) return s;
|
|
@@ -1199,7 +1240,7 @@ function completePartialObject(s) {
|
|
|
1199
1240
|
let contentEnd = 0;
|
|
1200
1241
|
let stringBraceDepth = 0;
|
|
1201
1242
|
for (let i = 0; i < s.length; i++) {
|
|
1202
|
-
const ch = s[i];
|
|
1243
|
+
const ch = expectDefined5(s[i]);
|
|
1203
1244
|
if (inString) {
|
|
1204
1245
|
contentEnd = i + 1;
|
|
1205
1246
|
if (escaped) {
|
|
@@ -1356,6 +1397,6 @@ function mergeCustomModelDefs(providerCustomModels, configModels) {
|
|
|
1356
1397
|
return out;
|
|
1357
1398
|
}
|
|
1358
1399
|
|
|
1359
|
-
export { atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, formatTodosList, getCalibrationState, getTermSize, isInteractive, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, projectHash, projectSlug, recordActualUsage, repairToolUseAdjacency, resetCalibration, resolveWstackPaths, safeParse, safeStringify, sanitizeJsonString, setRawMode, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, writeErr, writeOut };
|
|
1400
|
+
export { atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, formatTodosList, getCalibrationState, getTermSize, isInteractive, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, projectHash, projectSlug, recordActualUsage, repairToolUseAdjacency, resetCalibration, resolveWstackPaths, safeParse, safeStringify, sanitizeJsonString, setOutputLineGuard, setRawMode, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, writeErr, writeOut };
|
|
1360
1401
|
//# sourceMappingURL=index.js.map
|
|
1361
1402
|
//# sourceMappingURL=index.js.map
|