@wrongstack/core 0.9.19 → 0.10.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 (73) hide show
  1. package/README.md +37 -33
  2. package/dist/{agent-bridge-DMVOX0cF.d.ts → agent-bridge-DBBGP5O4.d.ts} +1 -1
  3. package/dist/{agent-subagent-runner-C4qt9e5Y.d.ts → agent-subagent-runner-KwufTWwn.d.ts} +3 -4
  4. package/dist/compactor-D1RHFRmF.d.ts +41 -0
  5. package/dist/{config-CWva0qoL.d.ts → config-CJXBka2r.d.ts} +38 -2
  6. package/dist/{context-BRNbHmRM.d.ts → context-7u93AcGD.d.ts} +140 -0
  7. package/dist/coordination/index.d.ts +13 -13
  8. package/dist/coordination/index.js +786 -200
  9. package/dist/coordination/index.js.map +1 -1
  10. package/dist/{default-config-Uzla85H-.d.ts → default-config-DEXI4jsl.d.ts} +10 -1
  11. package/dist/defaults/index.d.ts +24 -24
  12. package/dist/defaults/index.js +1612 -528
  13. package/dist/defaults/index.js.map +1 -1
  14. package/dist/{events-CiG9qUM_.d.ts → events-Bw1K5E6K.d.ts} +49 -1
  15. package/dist/execution/index.d.ts +46 -32
  16. package/dist/execution/index.js +663 -169
  17. package/dist/execution/index.js.map +1 -1
  18. package/dist/extension/index.d.ts +6 -6
  19. package/dist/extension/index.js.map +1 -1
  20. package/dist/goal-store-BeRsj7YX.d.ts +188 -0
  21. package/dist/{index-p95HQ22A.d.ts → index-DIt5TIaF.d.ts} +8 -8
  22. package/dist/{index-aizK8olO.d.ts → index-DgQWnZxP.d.ts} +11 -8
  23. package/dist/index.d.ts +338 -41
  24. package/dist/index.js +2747 -787
  25. package/dist/index.js.map +1 -1
  26. package/dist/infrastructure/index.d.ts +6 -6
  27. package/dist/infrastructure/index.js +36 -0
  28. package/dist/infrastructure/index.js.map +1 -1
  29. package/dist/kernel/index.d.ts +9 -9
  30. package/dist/kernel/index.js +57 -8
  31. package/dist/kernel/index.js.map +1 -1
  32. package/dist/{mcp-servers-BkVEqkRe.d.ts → mcp-servers-BgINZzuo.d.ts} +25 -3
  33. package/dist/models/index.d.ts +3 -3
  34. package/dist/models/index.js +164 -11
  35. package/dist/models/index.js.map +1 -1
  36. package/dist/models-registry-gwMAo6E3.d.ts +86 -0
  37. package/dist/{multi-agent-3ZnTB1aT.d.ts → multi-agent-C1O8EFzb.d.ts} +77 -24
  38. package/dist/{multi-agent-coordinator-bRaI_aD1.d.ts → multi-agent-coordinator-DoVSBFNx.d.ts} +20 -2
  39. package/dist/{null-fleet-bus-DKM3Iy9d.d.ts → null-fleet-bus-T-s3JaOt.d.ts} +413 -110
  40. package/dist/observability/index.d.ts +2 -2
  41. package/dist/{path-resolver-TcJfc29Y.d.ts → path-resolver-BfyK-I7w.d.ts} +2 -2
  42. package/dist/{permission-bPuzAy4x.d.ts → permission-B6sldrSp.d.ts} +1 -1
  43. package/dist/{permission-policy-BUQSutpl.d.ts → permission-policy-CtNscWOA.d.ts} +10 -9
  44. package/dist/{plan-templates-fkQTyz3U.d.ts → plan-templates-BWs6Je7j.d.ts} +8 -8
  45. package/dist/{provider-runner-BEpikbbN.d.ts → provider-runner-BmPe2RuU.d.ts} +3 -3
  46. package/dist/{retry-policy-BYkq0ugs.d.ts → retry-policy-KF18W4dg.d.ts} +1 -1
  47. package/dist/sdd/index.d.ts +9 -10
  48. package/dist/sdd/index.js +350 -122
  49. package/dist/sdd/index.js.map +1 -1
  50. package/dist/security/index.d.ts +65 -4
  51. package/dist/security/index.js +67 -19
  52. package/dist/security/index.js.map +1 -1
  53. package/dist/{selector-pox8abg0.d.ts → selector-DmXxpFyM.d.ts} +1 -1
  54. package/dist/{session-reader-CSWcb5Ga.d.ts → session-reader-CCSBfQmd.d.ts} +2 -2
  55. package/dist/skills/index.d.ts +1 -1
  56. package/dist/skills/index.js +1 -1
  57. package/dist/skills/index.js.map +1 -1
  58. package/dist/storage/index.d.ts +392 -8
  59. package/dist/storage/index.js +796 -40
  60. package/dist/storage/index.js.map +1 -1
  61. package/dist/{system-prompt-Bs-Wliab.d.ts → system-prompt-CM6zOhd2.d.ts} +19 -1
  62. package/dist/{tool-executor-Boo3dekH.d.ts → tool-executor-D7RxLtg4.d.ts} +9 -4
  63. package/dist/types/index.d.ts +16 -16
  64. package/dist/types/index.js +404 -14
  65. package/dist/types/index.js.map +1 -1
  66. package/dist/utils/index.d.ts +40 -8
  67. package/dist/utils/index.js +127 -57
  68. package/dist/utils/index.js.map +1 -1
  69. package/dist/{wstack-paths-BCgmTNlG.d.ts → wstack-paths-eMXnY1_X.d.ts} +8 -0
  70. package/package.json +1 -1
  71. package/dist/compactor-DVTKL7XD.d.ts +0 -23
  72. package/dist/goal-store-C7jcumEh.d.ts +0 -96
  73. package/dist/models-registry-OG_30xqZ.d.ts +0 -46
@@ -1,5 +1,6 @@
1
- import { N as TodoItem, M as Message, J as JSONSchema } from '../context-BRNbHmRM.js';
2
- export { W as WstackPathOptions, a as WstackPaths, p as projectHash, r as resolveWstackPaths } from '../wstack-paths-BCgmTNlG.js';
1
+ import { N as TodoItem, M as Message, J as JSONSchema } from '../context-7u93AcGD.js';
2
+ export { W as WstackPathOptions, a as WstackPaths, p as projectHash, r as resolveWstackPaths } from '../wstack-paths-eMXnY1_X.js';
3
+ import { M as ModelsDevPayload } from '../models-registry-BcYJDKLm.js';
3
4
 
4
5
  interface AtomicWriteOptions {
5
6
  mode?: number;
@@ -255,13 +256,44 @@ declare function compileUserRegex(pattern: string, flags: string): CompileResult
255
256
 
256
257
  /**
257
258
  * Attempt to close an incomplete JSON object string by auto-closing braces
258
- * and completing any unclosed double-quoted string values. This handles the
259
- * common streaming truncation case where the JSON stream ends mid-object
260
- * (e.g. `{"old_string": "line1\nline2` without the closing `"}` and `}`).
259
+ * and completing any unclosed double-quoted string values.
261
260
  *
262
- * Returns the completed string on best-effort, or the original if no useful
263
- * salvage was possible.
261
+ * Strategy:
262
+ * 1. Compute origOpen from the ORIGINAL input (how many braces are unclosed).
263
+ * 2. Add that many closing braces. If result is now valid JSON → return it.
264
+ * 3. If still invalid: trim trailing whitespace, strip trailing backslash.
265
+ * 4. Walk backwards to detect an unclosed string value.
266
+ * - Quote followed by `:` → key-name, skip
267
+ * - Quote followed by `,` `}` or end-of-string → toggle in/out of string
268
+ * 5. If we end INSIDE a string (unclosed opening `"`), append `"` + origOpen `}`.
269
+ *
270
+ * Known limitations:
271
+ * - Strings whose content ends with a `"` character cannot be repaired
272
+ * (algorithm can't distinguish content-`"` from string-terminator `"`).
273
+ * - Input ending in bare `:` (incomplete value expression) can't be meaningfully repaired.
274
+ * - Bare `{` returns unchanged.
275
+ * - If origOpen=0 (braces balanced) but string is unclosed, repair is skipped
276
+ * (the input would be valid JSON per JSON.parse, so it's returned as-is).
264
277
  */
265
278
  declare function completePartialObject(s: string): string;
266
279
 
267
- 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, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, formatTodosList, matchAny, matchGlob, normalizeToLf, repairToolUseAdjacency, safeParse, safeStringify, sanitizeJsonString, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema };
280
+ /**
281
+ * Deep-merge a curated `overlay` payload on top of a `base` payload (both in
282
+ * the models.dev `api.json` shape). The overlay always wins: it can add
283
+ * providers/models the base lacks and override fields the base gets wrong.
284
+ *
285
+ * Precedence rules:
286
+ * - Provider present in both → scalar fields (`name`, `npm`, `api`, `env`,
287
+ * `doc`) come from the overlay when set; `models` maps merge by model id.
288
+ * - Provider only in the overlay → added wholesale.
289
+ * - Model present in both → overlay model fields override base model fields
290
+ * (`{ ...base, ...overlay }`), with the nested `limit` / `cost` /
291
+ * `modalities` objects merged one level deeper so an overlay can fix just
292
+ * `limit.context` without restating the rest of the model.
293
+ * - Model only in the overlay → added.
294
+ *
295
+ * Pure: never mutates its inputs.
296
+ */
297
+ declare function mergeModelsPayload(base: ModelsDevPayload, overlay: ModelsDevPayload): ModelsDevPayload;
298
+
299
+ 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, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, formatTodosList, matchAny, matchGlob, mergeModelsPayload, normalizeToLf, repairToolUseAdjacency, safeParse, safeStringify, sanitizeJsonString, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema };
@@ -498,9 +498,11 @@ function resolveWstackPaths(opts) {
498
498
  globalPrompts: path2.join(globalRoot, "prompts"),
499
499
  cacheDir: path2.join(globalRoot, "cache"),
500
500
  modelsCache: path2.join(globalRoot, "cache", "models.dev.json"),
501
+ modelsOverlayCache: path2.join(globalRoot, "cache", "models-overlay.json"),
501
502
  historyFile: path2.join(globalRoot, "history"),
502
503
  logFile: path2.join(globalRoot, "logs", "wrongstack.log"),
503
504
  projectDir,
505
+ projectCodebaseIndex: path2.join(projectDir, "codebase-index"),
504
506
  projectMemory: path2.join(projectDir, "memory.md"),
505
507
  projectSessions: path2.join(projectDir, "sessions"),
506
508
  projectTrust: path2.join(projectDir, "trust.json"),
@@ -959,80 +961,85 @@ function compileUserRegex(pattern, flags) {
959
961
 
960
962
  // src/utils/json-repair.ts
961
963
  function completePartialObject(s) {
962
- let result = s;
963
- const trimmed = result.trim();
964
- if (!trimmed.startsWith("{")) return s;
965
- for (let pass = 0; pass < 3; pass++) {
966
- let braceDepth = 0;
967
- let inString2 = false;
968
- let escaped2 = false;
969
- let foundClose = false;
970
- for (const ch of result) {
971
- if (escaped2) {
972
- escaped2 = false;
964
+ if (!s.trim().startsWith("{")) return s;
965
+ if (tryParse(s).ok) return s;
966
+ const stack = [];
967
+ let inString = false;
968
+ let escaped = false;
969
+ let sawKey = false;
970
+ let prevSig = "";
971
+ let contentEnd = 0;
972
+ let stringBraceDepth = 0;
973
+ for (let i = 0; i < s.length; i++) {
974
+ const ch = s[i];
975
+ if (inString) {
976
+ contentEnd = i + 1;
977
+ if (escaped) {
978
+ escaped = false;
973
979
  continue;
974
980
  }
975
981
  if (ch === "\\") {
976
- escaped2 = true;
982
+ escaped = true;
977
983
  continue;
978
984
  }
979
985
  if (ch === '"') {
980
- inString2 = !inString2;
986
+ inString = false;
987
+ prevSig = '"';
988
+ stringBraceDepth = 0;
981
989
  continue;
982
990
  }
983
- if (inString2) continue;
984
- if (ch === "{") {
985
- braceDepth++;
986
- foundClose = false;
987
- } else if (ch === "}") {
988
- braceDepth--;
989
- if (braceDepth === 0) foundClose = true;
990
- }
991
- }
992
- if (foundClose || braceDepth <= 0) break;
993
- result += "}".repeat(braceDepth);
994
- }
995
- if (tryParse(result).ok) return result;
996
- let inString = false;
997
- let escaped = false;
998
- for (let i = result.length - 1; i >= 0; i--) {
999
- const ch = result[i];
1000
- if (escaped) {
1001
- escaped = false;
1002
- continue;
1003
- }
1004
- if (ch === "\\") {
1005
- escaped = true;
991
+ if (ch === "{") stringBraceDepth++;
992
+ else if (ch === "}" && stringBraceDepth > 0) stringBraceDepth--;
1006
993
  continue;
1007
994
  }
995
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r") continue;
996
+ contentEnd = i + 1;
1008
997
  if (ch === '"') {
1009
- let nextNonWs;
1010
- for (let j = i + 1; j < result.length; j++) {
1011
- const nc = result[j];
1012
- if (nc === " " || nc === " " || nc === "\n" || nc === "\r") continue;
1013
- nextNonWs = result[j];
1014
- break;
1015
- }
1016
- if (nextNonWs === ":") {
1017
- continue;
1018
- } else {
1019
- inString = !inString;
1020
- continue;
1021
- }
998
+ inString = true;
999
+ sawKey = true;
1000
+ stringBraceDepth = 0;
1001
+ prevSig = '"';
1002
+ } else if (ch === "{" || ch === "[") {
1003
+ stack.push(ch);
1004
+ prevSig = ch;
1005
+ } else if (ch === "}" || ch === "]") {
1006
+ stack.pop();
1007
+ prevSig = ch;
1008
+ } else {
1009
+ prevSig = ch;
1022
1010
  }
1023
1011
  }
1012
+ if (!sawKey && !inString) return s;
1013
+ let result = s.slice(0, contentEnd);
1024
1014
  if (inString) {
1025
- result = result.trimEnd();
1026
- if (result.endsWith("\\")) result = result.slice(0, -1);
1027
- let depth = 0;
1028
- for (const ch of result) {
1029
- if (ch === "{") depth++;
1030
- else if (ch === "}") depth = Math.max(0, depth - 1);
1015
+ if (escaped) {
1016
+ result = result.slice(0, -1);
1017
+ } else if (endsWithInvalidEscape(result)) {
1018
+ result = result.slice(0, -2);
1031
1019
  }
1032
- result += '"' + "}".repeat(Math.max(1, depth));
1020
+ if (stringBraceDepth > 0) result += "}".repeat(stringBraceDepth);
1021
+ result += '"';
1022
+ } else if (prevSig === ":") {
1023
+ result += "null";
1024
+ }
1025
+ for (let k = stack.length - 1; k >= 0; k--) {
1026
+ result += stack[k] === "{" ? "}" : "]";
1027
+ }
1028
+ if (!tryParse(result).ok) {
1029
+ const patched = result.replace(/:(\s*)([}\]])/g, ":null$2");
1030
+ if (tryParse(patched).ok) result = patched;
1033
1031
  }
1034
1032
  return result;
1035
1033
  }
1034
+ var VALID_ESCAPE = /* @__PURE__ */ new Set(['"', "\\", "/", "b", "f", "n", "r", "t", "u"]);
1035
+ function endsWithInvalidEscape(str) {
1036
+ const last = str[str.length - 1];
1037
+ if (str[str.length - 2] !== "\\" || last === void 0) return false;
1038
+ if (VALID_ESCAPE.has(last)) return false;
1039
+ let backslashes = 0;
1040
+ for (let k = str.length - 2; k >= 0 && str[k] === "\\"; k--) backslashes++;
1041
+ return backslashes % 2 === 1;
1042
+ }
1036
1043
  function tryParse(s) {
1037
1044
  try {
1038
1045
  return { ok: true, value: JSON.parse(s) };
@@ -1041,6 +1048,69 @@ function tryParse(s) {
1041
1048
  }
1042
1049
  }
1043
1050
 
1044
- export { atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateRequestTokens, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, formatTodosList, matchAny, matchGlob, normalizeToLf, projectHash, repairToolUseAdjacency, resolveWstackPaths, safeParse, safeStringify, sanitizeJsonString, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema };
1051
+ // src/utils/merge-models-payload.ts
1052
+ function mergeModelsPayload(base, overlay) {
1053
+ const out = {};
1054
+ for (const [id, provider] of Object.entries(base)) {
1055
+ out[id] = cloneProvider(provider);
1056
+ }
1057
+ for (const [id, ovProvider] of Object.entries(overlay)) {
1058
+ const existing = out[id];
1059
+ out[id] = existing ? mergeProvider(existing, ovProvider) : cloneProvider(ovProvider);
1060
+ }
1061
+ return out;
1062
+ }
1063
+ function mergeProvider(base, overlay) {
1064
+ const models = {};
1065
+ for (const [mid, m] of Object.entries(base.models ?? {})) {
1066
+ models[mid] = { ...m };
1067
+ }
1068
+ for (const [mid, ovModel] of Object.entries(overlay.models ?? {})) {
1069
+ const existing = models[mid];
1070
+ models[mid] = existing ? mergeModel(existing, ovModel) : { ...ovModel };
1071
+ }
1072
+ return {
1073
+ ...base,
1074
+ // Overlay scalar fields win when explicitly provided; otherwise keep base.
1075
+ ...stripUndefined({
1076
+ id: overlay.id,
1077
+ name: overlay.name,
1078
+ npm: overlay.npm,
1079
+ api: overlay.api,
1080
+ env: overlay.env,
1081
+ doc: overlay.doc
1082
+ }),
1083
+ models
1084
+ };
1085
+ }
1086
+ function mergeModel(base, overlay) {
1087
+ const merged = { ...base, ...overlay };
1088
+ if (base.limit || overlay.limit) {
1089
+ merged.limit = { ...base.limit, ...overlay.limit };
1090
+ }
1091
+ if (base.cost || overlay.cost) {
1092
+ merged.cost = { ...base.cost, ...overlay.cost };
1093
+ }
1094
+ if (base.modalities || overlay.modalities) {
1095
+ merged.modalities = { ...base.modalities, ...overlay.modalities };
1096
+ }
1097
+ return merged;
1098
+ }
1099
+ function cloneProvider(p) {
1100
+ const models = {};
1101
+ for (const [mid, m] of Object.entries(p.models ?? {})) {
1102
+ models[mid] = { ...m };
1103
+ }
1104
+ return { ...p, models };
1105
+ }
1106
+ function stripUndefined(obj) {
1107
+ const out = {};
1108
+ for (const [k, v] of Object.entries(obj)) {
1109
+ if (v !== void 0) out[k] = v;
1110
+ }
1111
+ return out;
1112
+ }
1113
+
1114
+ export { atomicWrite, buildChildEnv, color, compileGlob, compileUserRegex, completePartialObject, createToolOutputSerializer, detectNewlineStyle, ensureDir, estimateRequestTokens, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, formatTodosList, matchAny, matchGlob, mergeModelsPayload, normalizeToLf, projectHash, repairToolUseAdjacency, resolveWstackPaths, safeParse, safeStringify, sanitizeJsonString, stripAnsi, toStyle, unifiedDiff, validateAgainstSchema };
1045
1115
  //# sourceMappingURL=index.js.map
1046
1116
  //# sourceMappingURL=index.js.map