@wrongstack/core 0.148.0 → 0.236.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.
- package/dist/{agent-bridge-r9y6gdn4.d.ts → agent-bridge-Cimv7bK7.d.ts} +1 -1
- package/dist/{agent-subagent-runner-1GeQE_L0.d.ts → agent-subagent-runner-C658wj_c.d.ts} +9 -8
- package/dist/{brain-Cp_3GIS2.d.ts → brain-sCZ3lCjq.d.ts} +28 -2
- package/dist/{compactor-BueGt7LG.d.ts → compactor-BRfg3QPd.d.ts} +1 -1
- package/dist/{config-BaVThgnT.d.ts → config-Koq6f3fs.d.ts} +2 -2
- package/dist/{context-C7G_MtLV.d.ts → context-CLz3z_E8.d.ts} +126 -2
- package/dist/coordination/index.d.ts +70 -13
- package/dist/coordination/index.js +2126 -151
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +27 -27
- package/dist/defaults/index.js +1328 -354
- package/dist/defaults/index.js.map +1 -1
- package/dist/execution/index.d.ts +45 -16
- package/dist/execution/index.js +367 -59
- package/dist/execution/index.js.map +1 -1
- package/dist/execution/prompt-enhancer.d.ts +86 -0
- package/dist/execution/prompt-enhancer.js +125 -0
- package/dist/execution/prompt-enhancer.js.map +1 -0
- package/dist/extension/index.d.ts +6 -6
- package/dist/extension/index.js +3 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{goal-preamble-CYJLg0wk.d.ts → goal-preamble-CnbzyVvl.d.ts} +19 -10
- package/dist/{index-BZdezm3g.d.ts → index-BlMqh5GO.d.ts} +8 -8
- package/dist/{index-CPweVoFM.d.ts → index-C2eSNPsB.d.ts} +7 -5
- package/dist/index.d.ts +439 -129
- package/dist/index.js +5206 -905
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +7 -7
- package/dist/infrastructure/index.js +72 -15
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/kernel/index.d.ts +9 -9
- package/dist/kernel/index.js +7 -1
- package/dist/kernel/index.js.map +1 -1
- package/dist/{llm-selector-CP72f1lC.d.ts → llm-selector-D22R4AFz.d.ts} +2 -2
- package/dist/logger-DmmQhf4P.d.ts +65 -0
- package/dist/{mcp-servers-Bl5LTvQg.d.ts → mcp-servers-DFbirBv6.d.ts} +11 -4
- package/dist/models/index.d.ts +5 -5
- package/dist/models/index.js +89 -9
- package/dist/models/index.js.map +1 -1
- package/dist/{models-registry-D90K9UnM.d.ts → models-registry-CnJRjTXc.d.ts} +1 -1
- package/dist/{multi-agent-coordinator-QWEzJDlm.d.ts → multi-agent-coordinator-60weDZoA.d.ts} +8 -8
- package/dist/{null-fleet-bus-BUyfqh23.d.ts → null-fleet-bus-1068dEnr.d.ts} +7 -7
- package/dist/observability/index.d.ts +2 -2
- package/dist/package-outdated-watcher-pzJ5w7y8.d.ts +560 -0
- package/dist/{parallel-eternal-engine-C75QuhAI.d.ts → parallel-eternal-engine-DtG1fjc9.d.ts} +13 -9
- package/dist/{path-resolver-DRjQBkoO.d.ts → path-resolver-CA1ULU0J.d.ts} +3 -3
- package/dist/{permission-B7nKnEvQ.d.ts → permission-DbWPbuoA.d.ts} +1 -1
- package/dist/{permission-policy-8-6zBmfA.d.ts → permission-policy-AOk0LVsV.d.ts} +2 -2
- package/dist/pipeline-DsmlwTXu.d.ts +493 -0
- package/dist/{plan-templates-CkKNPU3I.d.ts → plan-templates-DPABrDvy.d.ts} +19 -8
- package/dist/{provider-runner-BNpuIyOL.d.ts → provider-runner-D0HgUqwV.d.ts} +3 -3
- package/dist/{retry-policy-rutAfVeR.d.ts → retry-policy-BVnkbMET.d.ts} +1 -1
- package/dist/sdd/index.d.ts +8 -8
- package/dist/sdd/index.js +358 -85
- package/dist/sdd/index.js.map +1 -1
- package/dist/{secret-vault-DoISxaKO.d.ts → secret-vault-BJDY28ev.d.ts} +7 -1
- package/dist/{secret-vault-BTcC_T5v.d.ts → secret-vault-CeVNiy_f.d.ts} +4 -3
- package/dist/security/index.d.ts +6 -5
- package/dist/security/index.js +214 -35
- package/dist/security/index.js.map +1 -1
- package/dist/{selector-4vDFZKt3.d.ts → selector-Cb4_9-hf.d.ts} +1 -1
- package/dist/{session-event-bridge-DWlvglC2.d.ts → session-event-bridge-BhtkkFFy.d.ts} +4 -2
- package/dist/{session-reader-BAtCxdaw.d.ts → session-reader-CCOssnBS.d.ts} +1 -1
- package/dist/skills/index.js +171 -21
- package/dist/skills/index.js.map +1 -1
- package/dist/storage/index.d.ts +151 -13
- package/dist/storage/index.js +1117 -256
- package/dist/storage/index.js.map +1 -1
- package/dist/types/index.d.ts +68 -21
- package/dist/types/index.js +616 -74
- package/dist/types/index.js.map +1 -1
- package/dist/utils/expect-defined.js +3 -1
- package/dist/utils/expect-defined.js.map +1 -1
- package/dist/utils/index.d.ts +80 -4
- package/dist/utils/index.js +100 -15
- package/dist/utils/index.js.map +1 -1
- package/dist/{wstack-paths-DD50Omgn.d.ts → wstack-paths-CJjEwPXn.d.ts} +14 -1
- package/package.json +7 -3
- package/skills/chimera/SKILL.md +105 -0
- package/skills/research-web/SKILL.md +342 -0
- package/dist/logger-B9J5puGM.d.ts +0 -32
- package/dist/pipeline-BG7UgbDc.d.ts +0 -239
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/utils/expect-defined.ts
|
|
2
2
|
function expectDefined(value, label) {
|
|
3
3
|
if (value === null || value === void 0) {
|
|
4
|
-
|
|
4
|
+
const err = new Error(label ? `Expected ${label} to be defined` : "Expected value to be defined");
|
|
5
|
+
err.name = "ExpectDefinedError";
|
|
6
|
+
throw err;
|
|
5
7
|
}
|
|
6
8
|
return value;
|
|
7
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/expect-defined.ts"],"names":[],"mappings":";AAIO,SAAS,aAAA,CAAiB,OAA6B,KAAA,EAAmB;AAC/E,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,EAAW;AACzC,IAAA,MAAM,IAAI,KAAA,CAAM,
|
|
1
|
+
{"version":3,"sources":["../../src/utils/expect-defined.ts"],"names":[],"mappings":";AAIO,SAAS,aAAA,CAAiB,OAA6B,KAAA,EAAmB;AAC/E,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,EAAW;AACzC,IAAA,MAAM,MAAM,IAAI,KAAA,CAAM,QAAQ,CAAA,SAAA,EAAY,KAAK,mBAAmB,8BAA8B,CAAA;AAChG,IAAA,GAAA,CAAI,IAAA,GAAO,oBAAA;AACX,IAAA,MAAM,GAAA;AAAA,EACR;AACA,EAAA,OAAO,KAAA;AACT","file":"expect-defined.js","sourcesContent":["/** Assert a value is neither null nor undefined. Throws if it is.\n * Useful after optional chaining and indexed access when the\n * control flow guarantees the value exists but TypeScript can't\n * prove it (e.g. after a check on a related field). */\nexport function expectDefined<T>(value: T | null | undefined, label?: string): T {\n if (value === null || value === undefined) {\n const err = new Error(label ? `Expected ${label} to be defined` : 'Expected value to be defined');\n err.name = 'ExpectDefinedError';\n throw err;\n }\n return value;\n}\n"]}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { s as TodoItem, M as Message, J as JSONSchema } from '../context-
|
|
1
|
+
import { s as TodoItem, M as Message, J as JSONSchema } from '../context-CLz3z_E8.js';
|
|
2
2
|
export { T as TaskItem, c as computeTaskItemProgress, f as formatTaskList, a as formatTaskProgress } from '../task-format-vGOIftmK.js';
|
|
3
|
-
export { a as WstackPathOptions, W as WstackPaths, p as projectHash, b as projectSlug, r as resolveWstackPaths } from '../wstack-paths-
|
|
3
|
+
export { a as WstackPathOptions, W as WstackPaths, p as projectHash, b as projectSlug, r as resolveWstackPaths, w as wstackGlobalRoot } from '../wstack-paths-CJjEwPXn.js';
|
|
4
4
|
export { expectDefined } from './expect-defined.js';
|
|
5
|
-
import { a as ModelsDevPayload, t as CustomModelDefinition } from '../config-
|
|
5
|
+
import { a as ModelsDevPayload, t as CustomModelDefinition } from '../config-Koq6f3fs.js';
|
|
6
6
|
export { a as TaskPriority, b as TaskStatus, T as TaskType } from '../task-graph-u1q9Jkyk.js';
|
|
7
7
|
|
|
8
8
|
interface AtomicWriteOptions {
|
|
@@ -275,6 +275,70 @@ declare function sleep(ms: number): Promise<void>;
|
|
|
275
275
|
*/
|
|
276
276
|
declare function assertNever(x: never, message?: string): never;
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Deep merge utility — safely merges nested objects with configurable
|
|
280
|
+
* conflict resolution, array merging, and prototype-pollution guarding.
|
|
281
|
+
*
|
|
282
|
+
* Used by:
|
|
283
|
+
* - config-loader (config layer merging with primitive-array concatenation)
|
|
284
|
+
* - secret-vault (config patching)
|
|
285
|
+
* - json-path (json_merge tool with prefer-base / prefer-patch semantics)
|
|
286
|
+
*
|
|
287
|
+
* @module utils/deep-merge
|
|
288
|
+
*/
|
|
289
|
+
declare const FORBIDDEN_PROTO_KEYS: Set<string>;
|
|
290
|
+
/** True when every element is a primitive or null (no nested objects/arrays). */
|
|
291
|
+
declare function isPrimitiveArray(a: unknown[]): boolean;
|
|
292
|
+
interface DeepMergeOptions {
|
|
293
|
+
/**
|
|
294
|
+
* Which side wins on collision for scalars and arrays.
|
|
295
|
+
*
|
|
296
|
+
* - `'prefer-patch'` (default): patch value replaces base value.
|
|
297
|
+
* - `'prefer-base'`: base value is kept, patch value is ignored.
|
|
298
|
+
*/
|
|
299
|
+
conflictResolution?: 'prefer-base' | 'prefer-patch';
|
|
300
|
+
/**
|
|
301
|
+
* How to handle array values.
|
|
302
|
+
*
|
|
303
|
+
* - `'replace'` (default): patch array replaces base array entirely.
|
|
304
|
+
* - `'concat-primitives'`: when both values are primitive arrays,
|
|
305
|
+
* they are concatenated and deduped (via Set). Non-primitive
|
|
306
|
+
* arrays still replace the base wholesale.
|
|
307
|
+
*/
|
|
308
|
+
arrayMode?: 'replace' | 'concat-primitives';
|
|
309
|
+
/**
|
|
310
|
+
* Skip prototype-pollution keys (`__proto__`, `constructor`, etc.).
|
|
311
|
+
* Enabled by default. Only disable when you control both inputs
|
|
312
|
+
* and the keyset (e.g. when merging trusted JSON schemas).
|
|
313
|
+
*/
|
|
314
|
+
protectProto?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Optional callback fired when a non-primitive (object) array is
|
|
317
|
+
* replaced wholesale (only relevant with `arrayMode: 'concat-primitives'`).
|
|
318
|
+
* Receives the key name, existing array length, and patch array length.
|
|
319
|
+
* Used by config-loader for debug logging.
|
|
320
|
+
*/
|
|
321
|
+
onNonPrimitiveArrayReplace?: (key: string, existingLen: number, patchLen: number) => void;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Recursively merge `patch` into `base`, returning a new object.
|
|
325
|
+
*
|
|
326
|
+
* - Nested plain objects are merged recursively.
|
|
327
|
+
* - Arrays are handled per `options.arrayMode`.
|
|
328
|
+
* - Scalar collisions are resolved per `options.conflictResolution`.
|
|
329
|
+
* - `null` and non-object values in `patch` replace the base value
|
|
330
|
+
* (unless `conflictResolution` is `'prefer-base'`).
|
|
331
|
+
* - Keys in `base` that are absent from `patch` are preserved.
|
|
332
|
+
* - `FORBIDDEN_PROTO_KEYS` are skipped in the patch (unless
|
|
333
|
+
* `options.protectProto` is set to `false`).
|
|
334
|
+
*
|
|
335
|
+
* The function is generic over `T extends Record<string, unknown>` for
|
|
336
|
+
* callers that pass typed config objects, but the runtime signature
|
|
337
|
+
* also accepts `unknown` inputs (used by the json-path plugin).
|
|
338
|
+
*/
|
|
339
|
+
declare function deepMerge<T extends Record<string, unknown>>(base: T, patch: Record<string, unknown>, options?: DeepMergeOptions): T;
|
|
340
|
+
declare function deepMerge(base: unknown, patch: unknown, options?: DeepMergeOptions): unknown;
|
|
341
|
+
|
|
278
342
|
/**
|
|
279
343
|
* Tool output serialization utilities.
|
|
280
344
|
* Extracted from Agent.executeTools to allow reuse and consistent output handling.
|
|
@@ -306,11 +370,23 @@ declare function estimateToolResultTokens(content: string | unknown): number;
|
|
|
306
370
|
* Estimate tokens for a text block.
|
|
307
371
|
*/
|
|
308
372
|
declare function estimateTextTokens(text: string): number;
|
|
373
|
+
/**
|
|
374
|
+
* Compute and cache the token estimate for a single message. This is the
|
|
375
|
+
* canonical per-message estimator — called once by ConversationState on
|
|
376
|
+
* append/replace so the O(n·m) content-block walk happens at mutation time,
|
|
377
|
+
* not on every context-pressure check.
|
|
378
|
+
*/
|
|
379
|
+
declare function computeMessageTokens(msg: Message): number;
|
|
309
380
|
/**
|
|
310
381
|
* Estimate tokens for an array of messages (text + tool I/O), using the shared
|
|
311
382
|
* 3.5 chars/token basis. This is the single canonical message-array estimator —
|
|
312
383
|
* compactors, the context_manager tool, and the `/context` display all route
|
|
313
384
|
* through it so the number a user sees matches the number compaction decides on.
|
|
385
|
+
*
|
|
386
|
+
* When a message carries a pre-computed `_estTokens` field (set by
|
|
387
|
+
* ConversationState on append/replace), it is used directly instead of
|
|
388
|
+
* re-walking the content blocks — turning the O(n·m) scan into an O(n)
|
|
389
|
+
* sum for fully-cached arrays.
|
|
314
390
|
*/
|
|
315
391
|
declare function estimateMessageTokens(messages: readonly Message[]): number;
|
|
316
392
|
/**
|
|
@@ -517,4 +593,4 @@ declare function mergeModelsPayload(base: ModelsDevPayload, overlay: ModelsDevPa
|
|
|
517
593
|
*/
|
|
518
594
|
declare function mergeCustomModelDefs(providerCustomModels: Record<string, CustomModelDefinition> | undefined, configModels: Record<string, CustomModelDefinition> | undefined): Record<string, CustomModelDefinition> | undefined;
|
|
519
595
|
|
|
520
|
-
export { type AtomicWriteOptions, type BuildChildEnvOptions, type CompileFail, type CompileResult, type FileLockOptions, type MessageRepairReport, type MessageRepairResult, type NewlineStyle, type OutputLineGuard, type RequestTokenBreakdown, type SafeParseResult, type ToolOutputSerializerOptions, type UnifiedDiffOptions, type ValidationError, type ValidationResult, assertNever, atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateMessageTokens, 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, sleep, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, withFileLock, writeErr, writeOut };
|
|
596
|
+
export { type AtomicWriteOptions, type BuildChildEnvOptions, type CompileFail, type CompileResult, type DeepMergeOptions, FORBIDDEN_PROTO_KEYS, type FileLockOptions, type MessageRepairReport, type MessageRepairResult, type NewlineStyle, type OutputLineGuard, type RequestTokenBreakdown, type SafeParseResult, type ToolOutputSerializerOptions, type UnifiedDiffOptions, type ValidationError, type ValidationResult, assertNever, atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, computeMessageTokens, createToolOutputSerializer, deepMerge, detectNewlineStyle, ensureDir, estimateMessageTokens, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, formatTodosList, getCalibrationState, getTermSize, isInteractive, isPrimitiveArray, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, recordActualUsage, repairToolUseAdjacency, resetCalibration, safeParse, safeStringify, sanitizeJsonString, setOutputLineGuard, setRawMode, sleep, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, withFileLock, writeErr, writeOut };
|
package/dist/utils/index.js
CHANGED
|
@@ -476,7 +476,9 @@ function formatTaskList(tasks) {
|
|
|
476
476
|
// src/utils/expect-defined.ts
|
|
477
477
|
function expectDefined(value, label) {
|
|
478
478
|
if (value === null || value === void 0) {
|
|
479
|
-
|
|
479
|
+
const err = new Error(label ? `Expected ${label} to be defined` : "Expected value to be defined");
|
|
480
|
+
err.name = "ExpectDefinedError";
|
|
481
|
+
throw err;
|
|
480
482
|
}
|
|
481
483
|
return value;
|
|
482
484
|
}
|
|
@@ -719,9 +721,13 @@ function projectSlug(absRoot) {
|
|
|
719
721
|
function slugify(name) {
|
|
720
722
|
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || "project";
|
|
721
723
|
}
|
|
724
|
+
function wstackGlobalRoot() {
|
|
725
|
+
const fromEnv = process.env["WRONGSTACK_HOME"];
|
|
726
|
+
if (fromEnv && fromEnv.trim().length > 0) return path2.resolve(fromEnv);
|
|
727
|
+
return path2.join(os.homedir(), ".wrongstack");
|
|
728
|
+
}
|
|
722
729
|
function resolveWstackPaths(opts) {
|
|
723
|
-
const
|
|
724
|
-
const globalRoot = opts.globalRoot ?? path2.join(home, ".wrongstack");
|
|
730
|
+
const globalRoot = opts.globalRoot ?? (opts.userHome ? path2.join(opts.userHome, ".wrongstack") : wstackGlobalRoot());
|
|
725
731
|
const hash = projectHash(opts.projectRoot);
|
|
726
732
|
const slug = projectSlug(opts.projectRoot);
|
|
727
733
|
const projectDir = path2.join(globalRoot, "projects", slug);
|
|
@@ -823,7 +829,7 @@ function buildChildEnv(optsOrSessionId) {
|
|
|
823
829
|
const passthrough = hasOwn && process.env["WRONGSTACK_CHILD_ENV_PASSTHROUGH"] === "1" || legacyHasOwn && process.env["WRONGSTACK_BASH_ENV_PASSTHROUGH"] === "1";
|
|
824
830
|
if (passthrough && !process.env["CI"]) {
|
|
825
831
|
console.warn(
|
|
826
|
-
"[
|
|
832
|
+
"[agent] WARNING: WRONGSTACK_*_ENV_PASSTHROUGH=1 is active \u2014\n all parent env vars (including API keys) forwarded to child processes.\n Do not use on shared or multi-tenant systems."
|
|
827
833
|
);
|
|
828
834
|
}
|
|
829
835
|
const out = {};
|
|
@@ -839,7 +845,11 @@ function buildChildEnv(optsOrSessionId) {
|
|
|
839
845
|
continue;
|
|
840
846
|
}
|
|
841
847
|
if (looksSecret(upper)) continue;
|
|
842
|
-
if (upper.startsWith("NODE_") || upper.startsWith("NPM_") || upper.startsWith("PNPM_") || upper.startsWith("YARN_") || upper.startsWith("GIT_") || upper.startsWith("CI") || upper.startsWith("XDG_") ||
|
|
848
|
+
if (upper.startsWith("NODE_") || upper.startsWith("NPM_") || upper.startsWith("PNPM_") || upper.startsWith("YARN_") || upper.startsWith("GIT_") || upper.startsWith("CI") || upper.startsWith("XDG_") || // Our own non-secret knobs (WRONGSTACK_HOME, WRONGSTACK_SESSION_ID, …).
|
|
849
|
+
// Secrets never live in WRONGSTACK_* env vars (they're in the encrypted
|
|
850
|
+
// vault). Forwarding keeps child wstack processes — e.g. ones spawned
|
|
851
|
+
// by the test suite — inside the same redirected global root.
|
|
852
|
+
upper.startsWith("WRONGSTACK_") || upper === "EDITOR" || upper === "VISUAL" || upper === "PAGER") {
|
|
843
853
|
out[k] = v;
|
|
844
854
|
}
|
|
845
855
|
}
|
|
@@ -857,9 +867,70 @@ function sleep(ms) {
|
|
|
857
867
|
|
|
858
868
|
// src/utils/assert-never.ts
|
|
859
869
|
function assertNever(x, message) {
|
|
860
|
-
|
|
870
|
+
const err = new Error(
|
|
861
871
|
message ?? `Unhandled case: ${JSON.stringify(x)}`
|
|
862
872
|
);
|
|
873
|
+
err.name = "AssertNeverError";
|
|
874
|
+
throw err;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/utils/deep-merge.ts
|
|
878
|
+
var FORBIDDEN_PROTO_KEYS = /* @__PURE__ */ new Set([
|
|
879
|
+
"__proto__",
|
|
880
|
+
"constructor",
|
|
881
|
+
"prototype",
|
|
882
|
+
"__defineGetter__",
|
|
883
|
+
"__defineSetter__",
|
|
884
|
+
"__lookupGetter__",
|
|
885
|
+
"__lookupSetter__"
|
|
886
|
+
]);
|
|
887
|
+
function isPrimitiveArray(a) {
|
|
888
|
+
return a.every((v) => v === null || typeof v !== "object" && typeof v !== "function");
|
|
889
|
+
}
|
|
890
|
+
function deepMerge(base, patch, options = {}) {
|
|
891
|
+
const {
|
|
892
|
+
conflictResolution = "prefer-patch",
|
|
893
|
+
arrayMode = "replace",
|
|
894
|
+
protectProto = true,
|
|
895
|
+
onNonPrimitiveArrayReplace
|
|
896
|
+
} = options;
|
|
897
|
+
if (typeof base !== "object" || base === null) {
|
|
898
|
+
return conflictResolution === "prefer-patch" ? patch : base;
|
|
899
|
+
}
|
|
900
|
+
if (typeof patch !== "object" || patch === null) {
|
|
901
|
+
return conflictResolution === "prefer-patch" ? patch : base;
|
|
902
|
+
}
|
|
903
|
+
if (Array.isArray(base) && Array.isArray(patch)) {
|
|
904
|
+
if (arrayMode === "concat-primitives" && isPrimitiveArray(base) && isPrimitiveArray(patch)) {
|
|
905
|
+
return [.../* @__PURE__ */ new Set([...base, ...patch])];
|
|
906
|
+
}
|
|
907
|
+
return conflictResolution === "prefer-patch" ? patch : base;
|
|
908
|
+
}
|
|
909
|
+
if (Array.isArray(base) || Array.isArray(patch)) {
|
|
910
|
+
return conflictResolution === "prefer-patch" ? patch : base;
|
|
911
|
+
}
|
|
912
|
+
const baseObj = base;
|
|
913
|
+
const patchObj = patch;
|
|
914
|
+
const out = { ...baseObj };
|
|
915
|
+
for (const [k, v] of Object.entries(patchObj)) {
|
|
916
|
+
if (protectProto && FORBIDDEN_PROTO_KEYS.has(k)) continue;
|
|
917
|
+
const existing = out[k];
|
|
918
|
+
if (v !== null && typeof v === "object" && !Array.isArray(v) && existing !== null && typeof existing === "object" && !Array.isArray(existing)) {
|
|
919
|
+
out[k] = deepMerge(existing, v, options);
|
|
920
|
+
} else if (Array.isArray(v) && Array.isArray(existing)) {
|
|
921
|
+
if (onNonPrimitiveArrayReplace && !isPrimitiveArray(v)) {
|
|
922
|
+
onNonPrimitiveArrayReplace(k, existing.length, v.length);
|
|
923
|
+
}
|
|
924
|
+
out[k] = deepMerge(existing, v, options);
|
|
925
|
+
} else if (v !== void 0) {
|
|
926
|
+
if (onNonPrimitiveArrayReplace && Array.isArray(v) && !isPrimitiveArray(v)) {
|
|
927
|
+
const existingLen = Array.isArray(existing) ? existing.length : 0;
|
|
928
|
+
onNonPrimitiveArrayReplace(k, existingLen, v.length);
|
|
929
|
+
}
|
|
930
|
+
out[k] = v;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return out;
|
|
863
934
|
}
|
|
864
935
|
|
|
865
936
|
// src/utils/tool-output-serializer.ts
|
|
@@ -951,22 +1022,31 @@ function estimateToolResultTokens(content) {
|
|
|
951
1022
|
function estimateTextTokens(text) {
|
|
952
1023
|
return RoughTokenEstimate(text);
|
|
953
1024
|
}
|
|
1025
|
+
function computeMessageTokens(msg) {
|
|
1026
|
+
if (typeof msg.content === "string") return estimateTextTokens(msg.content);
|
|
1027
|
+
let total = 0;
|
|
1028
|
+
for (const b of msg.content) {
|
|
1029
|
+
if (b.type === "text") total += estimateTextTokens(b.text);
|
|
1030
|
+
else if (b.type === "tool_use") total += estimateToolInputTokens(b.input);
|
|
1031
|
+
else if (b.type === "tool_result") total += estimateToolResultTokens(b.content);
|
|
1032
|
+
else total += RoughTokenEstimate(JSON.stringify(b));
|
|
1033
|
+
}
|
|
1034
|
+
return total;
|
|
1035
|
+
}
|
|
954
1036
|
function estimateMessageTokens(messages) {
|
|
955
1037
|
let total = 0;
|
|
956
1038
|
for (const m of messages) {
|
|
957
|
-
if (typeof m.
|
|
958
|
-
total +=
|
|
959
|
-
|
|
960
|
-
for (const b of m.content) {
|
|
961
|
-
if (b.type === "text") total += estimateTextTokens(b.text);
|
|
962
|
-
else if (b.type === "tool_use") total += estimateToolInputTokens(b.input);
|
|
963
|
-
else if (b.type === "tool_result") total += estimateToolResultTokens(b.content);
|
|
964
|
-
}
|
|
1039
|
+
if (typeof m._estTokens === "number" && m._estTokens > 0) {
|
|
1040
|
+
total += m._estTokens;
|
|
1041
|
+
continue;
|
|
965
1042
|
}
|
|
1043
|
+
total += computeMessageTokens(m);
|
|
966
1044
|
}
|
|
967
1045
|
return total;
|
|
968
1046
|
}
|
|
969
1047
|
function estimateToolDefTokens(tool) {
|
|
1048
|
+
const cached = tool._estDefTokens;
|
|
1049
|
+
if (typeof cached === "number" && cached > 0) return cached;
|
|
970
1050
|
return RoughTokenEstimate(tool.name) + RoughTokenEstimate(tool.description ?? "") + RoughTokenEstimate(JSON.stringify(tool.inputSchema));
|
|
971
1051
|
}
|
|
972
1052
|
function estimateRequestTokens(messages, systemPrompt, tools, calibrationKey = CALIBRATION_GLOBAL_KEY) {
|
|
@@ -976,6 +1056,11 @@ function estimateRequestTokens(messages, systemPrompt, tools, calibrationKey = C
|
|
|
976
1056
|
} else if (Array.isArray(messages)) {
|
|
977
1057
|
for (const m of messages) {
|
|
978
1058
|
if (typeof m === "object" && m !== null && "content" in m) {
|
|
1059
|
+
const cached = m._estTokens;
|
|
1060
|
+
if (typeof cached === "number" && cached > 0) {
|
|
1061
|
+
messagesTokens += cached;
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
979
1064
|
const content = m.content;
|
|
980
1065
|
if (typeof content === "string") {
|
|
981
1066
|
messagesTokens += RoughTokenEstimate(content);
|
|
@@ -1566,6 +1651,6 @@ function mergeCustomModelDefs(providerCustomModels, configModels) {
|
|
|
1566
1651
|
return out;
|
|
1567
1652
|
}
|
|
1568
1653
|
|
|
1569
|
-
export { assertNever, atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, computeTaskItemProgress, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateMessageTokens, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, expectDefined, formatTaskList, formatTaskProgress, formatTodosList, getCalibrationState, getTermSize, isInteractive, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, projectHash, projectSlug, recordActualUsage, repairToolUseAdjacency, resetCalibration, resolveWstackPaths, safeParse, safeStringify, sanitizeJsonString, setOutputLineGuard, setRawMode, sleep, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, withFileLock, writeErr, writeOut };
|
|
1654
|
+
export { FORBIDDEN_PROTO_KEYS, assertNever, atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, computeMessageTokens, computeTaskItemProgress, createToolOutputSerializer, deepMerge, detectNewlineStyle, ensureDir, estimateMessageTokens, estimateRequestTokens, estimateRequestTokensCalibrated, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, expandGlob, expectDefined, formatTaskList, formatTaskProgress, formatTodosList, getCalibrationState, getTermSize, isInteractive, isPrimitiveArray, isStdinTTY, isStdoutTTY, matchAny, matchGlob, mergeCustomModelDefs, mergeModelsPayload, normalizeToLf, onResize, projectHash, projectSlug, recordActualUsage, repairToolUseAdjacency, resetCalibration, resolveWstackPaths, safeParse, safeStringify, sanitizeJsonString, setOutputLineGuard, setRawMode, sleep, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema, withFileLock, writeErr, writeOut, wstackGlobalRoot };
|
|
1570
1655
|
//# sourceMappingURL=index.js.map
|
|
1571
1656
|
//# sourceMappingURL=index.js.map
|