nexus-agents 2.81.3 → 2.82.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 (109) hide show
  1. package/dist/{child-mcp-config-LLLRMOTQ.js → child-mcp-config-BMSYR7VV.js} +2 -2
  2. package/dist/{chunk-ERWTZSAR.js → chunk-2R5UUBGA.js} +2 -2
  3. package/dist/{chunk-BMNWUPJO.js → chunk-2SQXJQTA.js} +3 -3
  4. package/dist/{chunk-755EZIUF.js → chunk-4XNVJS5A.js} +924 -376
  5. package/dist/{chunk-755EZIUF.js.map → chunk-4XNVJS5A.js.map} +1 -1
  6. package/dist/{chunk-LJIB6TNE.js → chunk-7VNVDFD5.js} +3 -13
  7. package/dist/{chunk-LJIB6TNE.js.map → chunk-7VNVDFD5.js.map} +1 -1
  8. package/dist/{chunk-PUSFT342.js → chunk-BL5IBHEY.js} +3 -3
  9. package/dist/{chunk-Q27M6KHP.js → chunk-C7P2HLJX.js} +4 -4
  10. package/dist/{chunk-P4W7PV6L.js → chunk-FTT2IYYX.js} +123 -96
  11. package/dist/chunk-FTT2IYYX.js.map +1 -0
  12. package/dist/{chunk-UZCDHAY3.js → chunk-G2DZBEMU.js} +2 -2
  13. package/dist/{chunk-WZGCVCRQ.js → chunk-GNG7URCR.js} +2 -2
  14. package/dist/{chunk-RLQZOEMX.js → chunk-HJUHDPXJ.js} +3 -3
  15. package/dist/{chunk-SVKH6ASN.js → chunk-HMXQKDUV.js} +36 -24
  16. package/dist/chunk-HMXQKDUV.js.map +1 -0
  17. package/dist/{chunk-PV3OEDLO.js → chunk-HVZ52LOL.js} +2 -2
  18. package/dist/{chunk-EKLY4LBJ.js → chunk-JM3R267Z.js} +28 -15
  19. package/dist/chunk-JM3R267Z.js.map +1 -0
  20. package/dist/{chunk-M66MYHBT.js → chunk-NTLJ3INA.js} +2 -2
  21. package/dist/{chunk-T7RGD5JW.js → chunk-OYDJ3C4N.js} +3 -3
  22. package/dist/{chunk-UTL2SFIN.js → chunk-PZESEBD3.js} +2 -2
  23. package/dist/{chunk-LIEFKEAO.js → chunk-QHL4KGNB.js} +2 -2
  24. package/dist/{chunk-WLAQXITV.js → chunk-S36LIUV2.js} +12 -23
  25. package/dist/chunk-S36LIUV2.js.map +1 -0
  26. package/dist/{chunk-YLYT7GSG.js → chunk-SBZVRH4S.js} +2 -2
  27. package/dist/{chunk-V2KWEIV5.js → chunk-SHWGK7X6.js} +9 -60
  28. package/dist/chunk-SHWGK7X6.js.map +1 -0
  29. package/dist/{chunk-6YQCLEHL.js → chunk-SXL744NF.js} +2 -2
  30. package/dist/{chunk-4OPS2AUD.js → chunk-TXIUCEFT.js} +4 -4
  31. package/dist/chunk-TXIUCEFT.js.map +1 -0
  32. package/dist/{chunk-PZEE6T5Y.js → chunk-U7JXQSEM.js} +3 -3
  33. package/dist/{chunk-SZ7VPIRA.js → chunk-W2AIGD35.js} +2 -2
  34. package/dist/{chunk-73K7575Z.js → chunk-WUUEKFKG.js} +2 -2
  35. package/dist/{chunk-PKBKWWPK.js → chunk-X3JR3GMT.js} +3 -3
  36. package/dist/{chunk-S77SLJ2J.js → chunk-XGUDCUMB.js} +2 -2
  37. package/dist/{cli-circuit-breaker-O5RV47BO.js → cli-circuit-breaker-BIJUQRQI.js} +4 -4
  38. package/dist/cli.js +148 -70
  39. package/dist/cli.js.map +1 -1
  40. package/dist/{composite-router-SKHVZ4UF.js → composite-router-FB7P22L5.js} +2 -2
  41. package/dist/{consensus-vote-VBXLXVFF.js → consensus-vote-KKAIFULI.js} +11 -11
  42. package/dist/{context-retriever-KLJ5X4TL.js → context-retriever-4JCGMWH7.js} +5 -5
  43. package/dist/{doctor-deep-IH4FG5YZ.js → doctor-deep-7YK4BZIJ.js} +3 -3
  44. package/dist/expert-bridge-DJM5GAWZ.js +11 -0
  45. package/dist/{factory-FTE7TDCT.js → factory-DOWBGVAL.js} +5 -5
  46. package/dist/{factory-CQUDIMIG.js → factory-PK4EZL7K.js} +4 -4
  47. package/dist/index.d.ts +13 -1
  48. package/dist/index.js +24 -24
  49. package/dist/index.js.map +1 -1
  50. package/dist/{init-opencode-MXZJKG32.js → init-opencode-QP5CAMWN.js} +5 -5
  51. package/dist/{issue-triage-H5VLNGWU.js → issue-triage-T3SKNBH5.js} +4 -4
  52. package/dist/{registry-command-ALVYOGQY.js → registry-command-TH7U6UMC.js} +2 -2
  53. package/dist/{repo-security-plan-VJCWWPWO.js → repo-security-plan-V257RYTW.js} +3 -3
  54. package/dist/{research-helpers-synthesize-XUTBDVI7.js → research-helpers-synthesize-Y3O76PY4.js} +3 -3
  55. package/dist/{routing-memory-QKQ3OGWW.js → routing-memory-AAH7NIHD.js} +2 -2
  56. package/dist/{session-memory-N76TNRSK.js → session-memory-MY6YS2VX.js} +3 -3
  57. package/dist/{setup-command-3VQHU7BZ.js → setup-command-B6EC3OJA.js} +10 -10
  58. package/dist/{setup-config-Y7KZSFX3.js → setup-config-HVO6ZSLW.js} +3 -3
  59. package/dist/{setup-custom-api-QEKHNYQJ.js → setup-custom-api-UOIKUQL4.js} +4 -4
  60. package/dist/{tool-memory-MFDLIJOB.js → tool-memory-T7ZYIUJ2.js} +4 -4
  61. package/dist/{weather-report-IXPYIYE4.js → weather-report-O3Z3BBAX.js} +2 -2
  62. package/package.json +1 -1
  63. package/dist/chunk-4OPS2AUD.js.map +0 -1
  64. package/dist/chunk-EKLY4LBJ.js.map +0 -1
  65. package/dist/chunk-P4W7PV6L.js.map +0 -1
  66. package/dist/chunk-SVKH6ASN.js.map +0 -1
  67. package/dist/chunk-V2KWEIV5.js.map +0 -1
  68. package/dist/chunk-WLAQXITV.js.map +0 -1
  69. package/dist/expert-bridge-EKPDZKMD.js +0 -11
  70. /package/dist/{child-mcp-config-LLLRMOTQ.js.map → child-mcp-config-BMSYR7VV.js.map} +0 -0
  71. /package/dist/{chunk-ERWTZSAR.js.map → chunk-2R5UUBGA.js.map} +0 -0
  72. /package/dist/{chunk-BMNWUPJO.js.map → chunk-2SQXJQTA.js.map} +0 -0
  73. /package/dist/{chunk-PUSFT342.js.map → chunk-BL5IBHEY.js.map} +0 -0
  74. /package/dist/{chunk-Q27M6KHP.js.map → chunk-C7P2HLJX.js.map} +0 -0
  75. /package/dist/{chunk-UZCDHAY3.js.map → chunk-G2DZBEMU.js.map} +0 -0
  76. /package/dist/{chunk-WZGCVCRQ.js.map → chunk-GNG7URCR.js.map} +0 -0
  77. /package/dist/{chunk-RLQZOEMX.js.map → chunk-HJUHDPXJ.js.map} +0 -0
  78. /package/dist/{chunk-PV3OEDLO.js.map → chunk-HVZ52LOL.js.map} +0 -0
  79. /package/dist/{chunk-M66MYHBT.js.map → chunk-NTLJ3INA.js.map} +0 -0
  80. /package/dist/{chunk-T7RGD5JW.js.map → chunk-OYDJ3C4N.js.map} +0 -0
  81. /package/dist/{chunk-UTL2SFIN.js.map → chunk-PZESEBD3.js.map} +0 -0
  82. /package/dist/{chunk-LIEFKEAO.js.map → chunk-QHL4KGNB.js.map} +0 -0
  83. /package/dist/{chunk-YLYT7GSG.js.map → chunk-SBZVRH4S.js.map} +0 -0
  84. /package/dist/{chunk-6YQCLEHL.js.map → chunk-SXL744NF.js.map} +0 -0
  85. /package/dist/{chunk-PZEE6T5Y.js.map → chunk-U7JXQSEM.js.map} +0 -0
  86. /package/dist/{chunk-SZ7VPIRA.js.map → chunk-W2AIGD35.js.map} +0 -0
  87. /package/dist/{chunk-73K7575Z.js.map → chunk-WUUEKFKG.js.map} +0 -0
  88. /package/dist/{chunk-PKBKWWPK.js.map → chunk-X3JR3GMT.js.map} +0 -0
  89. /package/dist/{chunk-S77SLJ2J.js.map → chunk-XGUDCUMB.js.map} +0 -0
  90. /package/dist/{cli-circuit-breaker-O5RV47BO.js.map → cli-circuit-breaker-BIJUQRQI.js.map} +0 -0
  91. /package/dist/{composite-router-SKHVZ4UF.js.map → composite-router-FB7P22L5.js.map} +0 -0
  92. /package/dist/{consensus-vote-VBXLXVFF.js.map → consensus-vote-KKAIFULI.js.map} +0 -0
  93. /package/dist/{context-retriever-KLJ5X4TL.js.map → context-retriever-4JCGMWH7.js.map} +0 -0
  94. /package/dist/{doctor-deep-IH4FG5YZ.js.map → doctor-deep-7YK4BZIJ.js.map} +0 -0
  95. /package/dist/{expert-bridge-EKPDZKMD.js.map → expert-bridge-DJM5GAWZ.js.map} +0 -0
  96. /package/dist/{factory-CQUDIMIG.js.map → factory-DOWBGVAL.js.map} +0 -0
  97. /package/dist/{factory-FTE7TDCT.js.map → factory-PK4EZL7K.js.map} +0 -0
  98. /package/dist/{init-opencode-MXZJKG32.js.map → init-opencode-QP5CAMWN.js.map} +0 -0
  99. /package/dist/{issue-triage-H5VLNGWU.js.map → issue-triage-T3SKNBH5.js.map} +0 -0
  100. /package/dist/{registry-command-ALVYOGQY.js.map → registry-command-TH7U6UMC.js.map} +0 -0
  101. /package/dist/{repo-security-plan-VJCWWPWO.js.map → repo-security-plan-V257RYTW.js.map} +0 -0
  102. /package/dist/{research-helpers-synthesize-XUTBDVI7.js.map → research-helpers-synthesize-Y3O76PY4.js.map} +0 -0
  103. /package/dist/{routing-memory-QKQ3OGWW.js.map → routing-memory-AAH7NIHD.js.map} +0 -0
  104. /package/dist/{session-memory-N76TNRSK.js.map → session-memory-MY6YS2VX.js.map} +0 -0
  105. /package/dist/{setup-command-3VQHU7BZ.js.map → setup-command-B6EC3OJA.js.map} +0 -0
  106. /package/dist/{setup-config-Y7KZSFX3.js.map → setup-config-HVO6ZSLW.js.map} +0 -0
  107. /package/dist/{setup-custom-api-QEKHNYQJ.js.map → setup-custom-api-UOIKUQL4.js.map} +0 -0
  108. /package/dist/{tool-memory-MFDLIJOB.js.map → tool-memory-T7ZYIUJ2.js.map} +0 -0
  109. /package/dist/{weather-report-IXPYIYE4.js.map → weather-report-O3Z3BBAX.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  OpenAIAdapter
3
- } from "./chunk-PKBKWWPK.js";
3
+ } from "./chunk-X3JR3GMT.js";
4
4
  import {
5
5
  ConfigError,
6
6
  createLogger,
@@ -9,7 +9,7 @@ import {
9
9
  getTimeProvider,
10
10
  lookupInTreeCapability,
11
11
  ok
12
- } from "./chunk-LJIB6TNE.js";
12
+ } from "./chunk-7VNVDFD5.js";
13
13
  import {
14
14
  getNexusDataDir
15
15
  } from "./chunk-I2HMWH4R.js";
@@ -307,4 +307,4 @@ export {
307
307
  discoverModels,
308
308
  buildOpenAICompatAdapters
309
309
  };
310
- //# sourceMappingURL=chunk-PUSFT342.js.map
310
+ //# sourceMappingURL=chunk-BL5IBHEY.js.map
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  resolveToken
3
- } from "./chunk-UZCDHAY3.js";
3
+ } from "./chunk-G2DZBEMU.js";
4
4
  import {
5
5
  GitHubProvider,
6
6
  ScmError
7
- } from "./chunk-UTL2SFIN.js";
7
+ } from "./chunk-PZESEBD3.js";
8
8
  import {
9
9
  err,
10
10
  ok
11
- } from "./chunk-LJIB6TNE.js";
11
+ } from "./chunk-7VNVDFD5.js";
12
12
 
13
13
  // src/scm/factory.ts
14
14
  async function createScmProvider(config) {
@@ -41,4 +41,4 @@ export {
41
41
  createScmProvider,
42
42
  createGitHubProvider
43
43
  };
44
- //# sourceMappingURL=chunk-Q27M6KHP.js.map
44
+ //# sourceMappingURL=chunk-C7P2HLJX.js.map
@@ -2,23 +2,23 @@ import {
2
2
  CUSTOM_API_BASE_URL_ENV,
3
3
  PROVIDER_ENV_KEYS,
4
4
  validateCustomApiBaseUrl
5
- } from "./chunk-M66MYHBT.js";
5
+ } from "./chunk-NTLJ3INA.js";
6
6
  import {
7
7
  AdapterModelError,
8
8
  BaseAdapter,
9
9
  createStream,
10
10
  requireApiKey,
11
11
  validateApiKeyPresence
12
- } from "./chunk-YLYT7GSG.js";
12
+ } from "./chunk-SBZVRH4S.js";
13
13
  import {
14
14
  getToolMemory
15
- } from "./chunk-PZEE6T5Y.js";
15
+ } from "./chunk-U7JXQSEM.js";
16
16
  import {
17
17
  getDefaultAvailableModelsCache
18
- } from "./chunk-73K7575Z.js";
18
+ } from "./chunk-WUUEKFKG.js";
19
19
  import {
20
20
  CUSTOM_API_DEFAULT_MODEL
21
- } from "./chunk-V2KWEIV5.js";
21
+ } from "./chunk-SHWGK7X6.js";
22
22
  import {
23
23
  createCliAdapter,
24
24
  createCliDetectionCache,
@@ -27,7 +27,7 @@ import {
27
27
  isCliAvailable,
28
28
  sanitizeOutput,
29
29
  withTimeout
30
- } from "./chunk-BMNWUPJO.js";
30
+ } from "./chunk-2SQXJQTA.js";
31
31
  import {
32
32
  AgentError,
33
33
  CACHE_TIMEOUTS,
@@ -70,7 +70,7 @@ import {
70
70
  resolveCliAlias,
71
71
  resolveVoteTimeout,
72
72
  toRateLimitError
73
- } from "./chunk-LJIB6TNE.js";
73
+ } from "./chunk-7VNVDFD5.js";
74
74
  import {
75
75
  ensureLearningDir,
76
76
  getNexusDataDir,
@@ -1792,7 +1792,7 @@ async function executeAndAudit(handler, sanitizedArgs, requestContext, requestLo
1792
1792
  }
1793
1793
  return result;
1794
1794
  } catch (error) {
1795
- const message = error instanceof Error ? error.message : "Unknown error";
1795
+ const rawMessage = error instanceof Error ? error.message : "Unknown error";
1796
1796
  requestLogger.error("Tool execution failed", error instanceof Error ? error : void 0);
1797
1797
  if (config.auditLogger) {
1798
1798
  emitToolAuditException(
@@ -1802,7 +1802,8 @@ async function executeAndAudit(handler, sanitizedArgs, requestContext, requestLo
1802
1802
  getTimeProvider().now() - execStartTime
1803
1803
  );
1804
1804
  }
1805
- return internalError(message, requestContext.requestId);
1805
+ const sanitized = sanitizeOutput2(rawMessage, requestLogger);
1806
+ return internalError(sanitized, requestContext.requestId);
1806
1807
  }
1807
1808
  }
1808
1809
 
@@ -7639,9 +7640,10 @@ import { z as z8 } from "zod";
7639
7640
  var logger6 = createLogger({ component: "correlation-persistence" });
7640
7641
  var VOTING_SUBDIR = "voting";
7641
7642
  var CORRELATIONS_FILE = "correlations.json";
7643
+ var CORRELATIONS_JSONL_FILE = "correlations.jsonl";
7642
7644
  var FILE_MODE = 384;
7643
7645
  var DIR_MODE = 448;
7644
- var SCHEMA_VERSION = 1;
7646
+ var SCHEMA_VERSION = 2;
7645
7647
  var PersistedVoteSchema = z8.object({
7646
7648
  agentId: z8.string(),
7647
7649
  decision: z8.enum(["approve", "reject", "abstain"]),
@@ -7661,6 +7663,9 @@ var PersistedCorrelationDataSchema = z8.object({
7661
7663
  function getCorrelationDataPath() {
7662
7664
  return nexusDataPath(VOTING_SUBDIR, CORRELATIONS_FILE);
7663
7665
  }
7666
+ function getCorrelationJsonlPath() {
7667
+ return nexusDataPath(VOTING_SUBDIR, CORRELATIONS_JSONL_FILE);
7668
+ }
7664
7669
  function ensureVotingDirectory() {
7665
7670
  const dirPath = nexusDataPath(VOTING_SUBDIR);
7666
7671
  try {
@@ -7671,116 +7676,137 @@ function ensureVotingDirectory() {
7671
7676
  return err(new Error(`Failed to create voting directory at ${dirPath}: ${error.message}`));
7672
7677
  }
7673
7678
  }
7674
- function mergeProposals(existingProposals, newProposals, maxProposals) {
7675
- const proposalMap = /* @__PURE__ */ new Map();
7676
- for (const proposal of existingProposals) {
7677
- proposalMap.set(proposal.proposalId, proposal);
7678
- }
7679
- for (const proposal of newProposals) {
7680
- proposalMap.set(proposal.proposalId, proposal);
7681
- }
7682
- const merged = Array.from(proposalMap.values());
7683
- merged.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
7684
- if (merged.length > maxProposals) {
7685
- return merged.slice(merged.length - maxProposals);
7686
- }
7687
- return merged;
7688
- }
7689
- function saveCorrelationData(proposals, config = DEFAULT_HIGHER_ORDER_CONFIG) {
7679
+ function saveCorrelationData(proposals, _config = DEFAULT_HIGHER_ORDER_CONFIG) {
7690
7680
  const dirResult = ensureVotingDirectory();
7691
7681
  if (!dirResult.ok) return dirResult;
7692
- const filePath = getCorrelationDataPath();
7693
- let existingProposals = [];
7694
- const loadResult = loadCorrelationData();
7695
- if (loadResult.ok) {
7696
- existingProposals = loadResult.value.proposals;
7697
- }
7698
- const merged = mergeProposals(existingProposals, proposals, config.maxProposals);
7699
- const data = {
7700
- version: SCHEMA_VERSION,
7701
- proposals: merged,
7702
- savedAt: (/* @__PURE__ */ new Date()).toISOString()
7703
- };
7704
- const json = JSON.stringify(data, null, 2);
7705
- const tempPath = `${filePath}.tmp.${String(process.pid)}`;
7682
+ if (proposals.length === 0) return ok(void 0);
7683
+ const filePath = getCorrelationJsonlPath();
7706
7684
  try {
7707
- fs.writeFileSync(tempPath, json, { encoding: "utf-8", mode: FILE_MODE });
7708
- fs.renameSync(tempPath, filePath);
7709
- logger6.info("Correlation data saved", {
7685
+ const lines = proposals.map((p) => JSON.stringify(p)).join("\n") + "\n";
7686
+ fs.appendFileSync(filePath, lines, { encoding: "utf-8", mode: FILE_MODE });
7687
+ logger6.info("Correlation proposals appended", {
7710
7688
  path: filePath,
7711
- proposalCount: merged.length
7689
+ proposalCount: proposals.length
7712
7690
  });
7713
7691
  return ok(void 0);
7714
7692
  } catch (cause) {
7715
- try {
7716
- fs.unlinkSync(tempPath);
7717
- } catch (cleanupErr) {
7718
- const msg = cleanupErr instanceof Error ? cleanupErr.message : String(cleanupErr);
7719
- logger6.debug("Failed to clean up temp file during correlation save", {
7720
- path: tempPath,
7721
- error: msg
7722
- });
7723
- }
7724
7693
  const error = cause instanceof Error ? cause : new Error(String(cause));
7725
- return err(new Error(`Failed to save correlation data: ${error.message}`));
7694
+ return err(new Error(`Failed to append correlation data: ${error.message}`));
7726
7695
  }
7727
7696
  }
7728
- function readAndParseFile(filePath) {
7729
- if (!fs.existsSync(filePath)) {
7730
- return err(new Error(`Correlation data file not found: ${filePath}`));
7731
- }
7697
+ function loadLegacyJsonProposals() {
7698
+ const filePath = getCorrelationDataPath();
7699
+ if (!fs.existsSync(filePath)) return [];
7732
7700
  let rawContent;
7733
7701
  try {
7734
7702
  rawContent = fs.readFileSync(filePath, { encoding: "utf-8" });
7735
7703
  } catch (cause) {
7736
- const error = cause instanceof Error ? cause : new Error(String(cause));
7737
- return err(new Error(`Failed to read correlation data: ${error.message}`));
7704
+ logger6.warn("Failed to read legacy correlations.json", {
7705
+ path: filePath,
7706
+ error: cause instanceof Error ? cause.message : String(cause)
7707
+ });
7708
+ return [];
7738
7709
  }
7710
+ let parsed;
7739
7711
  try {
7740
- return ok(JSON.parse(rawContent));
7712
+ parsed = JSON.parse(rawContent);
7741
7713
  } catch (cause) {
7742
- const error = cause instanceof Error ? cause : new Error(String(cause));
7743
- logger6.warn("Corrupt correlation data file, will start fresh", {
7714
+ logger6.warn("Corrupt legacy correlations.json \u2014 skipping", {
7744
7715
  path: filePath,
7745
- error: error.message
7716
+ error: cause instanceof Error ? cause.message : String(cause)
7746
7717
  });
7747
- return err(new Error(`Corrupt correlation data (invalid JSON): ${error.message}`));
7718
+ return [];
7748
7719
  }
7720
+ const result = PersistedCorrelationDataSchema.safeParse(parsed);
7721
+ if (!result.success) {
7722
+ logger6.warn("Invalid legacy correlations.json schema \u2014 skipping", {
7723
+ path: filePath,
7724
+ error: result.error.message
7725
+ });
7726
+ return [];
7727
+ }
7728
+ return result.data.proposals;
7749
7729
  }
7750
- function validateCorrelationData(parsed, filePath) {
7751
- const validation = PersistedCorrelationDataSchema.safeParse(parsed);
7752
- if (!validation.success) {
7753
- logger6.warn("Invalid correlation data schema, will start fresh", {
7730
+ function parseJsonlLine(line) {
7731
+ let parsed;
7732
+ try {
7733
+ parsed = JSON.parse(line);
7734
+ } catch (cause) {
7735
+ return {
7736
+ kind: "skip",
7737
+ reason: `JSON.parse: ${cause instanceof Error ? cause.message : String(cause)}`
7738
+ };
7739
+ }
7740
+ const result = PersistedProposalSchema.safeParse(parsed);
7741
+ if (!result.success) return { kind: "skip", reason: `schema: ${result.error.message}` };
7742
+ return { kind: "ok", proposal: result.data };
7743
+ }
7744
+ function loadJsonlProposals() {
7745
+ const filePath = getCorrelationJsonlPath();
7746
+ if (!fs.existsSync(filePath)) return [];
7747
+ let content;
7748
+ try {
7749
+ content = fs.readFileSync(filePath, { encoding: "utf-8" });
7750
+ } catch (cause) {
7751
+ logger6.warn("Failed to read correlations.jsonl", {
7754
7752
  path: filePath,
7755
- errors: validation.error.issues.map((issue) => issue.message)
7753
+ error: cause instanceof Error ? cause.message : String(cause)
7756
7754
  });
7757
- return err(new Error(`Invalid correlation data schema: ${validation.error.message}`));
7755
+ return [];
7756
+ }
7757
+ const lines = content.split("\n").filter((line) => line.trim() !== "");
7758
+ const proposals = [];
7759
+ let skippedCount = 0;
7760
+ let firstSkipReason;
7761
+ for (const line of lines) {
7762
+ const result = parseJsonlLine(line);
7763
+ if (result.kind === "ok") {
7764
+ proposals.push(result.proposal);
7765
+ } else {
7766
+ skippedCount++;
7767
+ firstSkipReason ??= result.reason;
7768
+ }
7758
7769
  }
7759
- if (validation.data.version > SCHEMA_VERSION) {
7760
- logger6.warn("Correlation data from newer version, will start fresh", {
7761
- fileVersion: validation.data.version,
7762
- currentVersion: SCHEMA_VERSION
7770
+ if (skippedCount > 0) {
7771
+ logger6.warn("Skipped malformed lines in correlations.jsonl", {
7772
+ path: filePath,
7773
+ skippedCount,
7774
+ totalLines: lines.length,
7775
+ firstSkipReason
7763
7776
  });
7764
- return err(
7765
- new Error(
7766
- `Unsupported schema version ${String(validation.data.version)} (current: ${String(SCHEMA_VERSION)})`
7767
- )
7768
- );
7769
7777
  }
7770
- return ok(validation.data);
7778
+ return proposals;
7771
7779
  }
7772
- function loadCorrelationData() {
7773
- const filePath = getCorrelationDataPath();
7774
- const parseResult = readAndParseFile(filePath);
7775
- if (!parseResult.ok) return parseResult;
7776
- const validateResult = validateCorrelationData(parseResult.value, filePath);
7777
- if (!validateResult.ok) return validateResult;
7780
+ function consolidate(legacyProposals, jsonlProposals, maxProposals) {
7781
+ const proposalMap = /* @__PURE__ */ new Map();
7782
+ for (const p of legacyProposals) proposalMap.set(p.proposalId, p);
7783
+ for (const p of jsonlProposals) proposalMap.set(p.proposalId, p);
7784
+ const all = Array.from(proposalMap.values()).sort(
7785
+ (a, b) => a.timestamp.localeCompare(b.timestamp)
7786
+ );
7787
+ return all.length > maxProposals ? all.slice(all.length - maxProposals) : all;
7788
+ }
7789
+ function loadCorrelationData(config = DEFAULT_HIGHER_ORDER_CONFIG) {
7790
+ const jsonlPath = getCorrelationJsonlPath();
7791
+ const legacyPath = getCorrelationDataPath();
7792
+ const jsonlExists = fs.existsSync(jsonlPath);
7793
+ const legacyExists = fs.existsSync(legacyPath);
7794
+ if (!jsonlExists && !legacyExists) {
7795
+ return err(new Error(`Correlation data file not found: ${jsonlPath}`));
7796
+ }
7797
+ const legacy = loadLegacyJsonProposals();
7798
+ const jsonl = loadJsonlProposals();
7799
+ const proposals = consolidate(legacy, jsonl, config.maxProposals);
7778
7800
  logger6.info("Correlation data loaded", {
7779
- path: filePath,
7780
- proposalCount: validateResult.value.proposals.length,
7781
- savedAt: validateResult.value.savedAt
7801
+ legacyCount: legacy.length,
7802
+ jsonlCount: jsonl.length,
7803
+ afterDedup: proposals.length
7804
+ });
7805
+ return ok({
7806
+ version: SCHEMA_VERSION,
7807
+ proposals,
7808
+ savedAt: (/* @__PURE__ */ new Date()).toISOString()
7782
7809
  });
7783
- return validateResult;
7784
7810
  }
7785
7811
  function replayProposals(tracker, proposals) {
7786
7812
  let replayed = 0;
@@ -7800,7 +7826,8 @@ function replayProposals(tracker, proposals) {
7800
7826
  }
7801
7827
  function createPersistentCorrelationTracker(config) {
7802
7828
  const tracker = createCorrelationTracker(config);
7803
- const loadResult = loadCorrelationData();
7829
+ const mergedConfig = { ...DEFAULT_HIGHER_ORDER_CONFIG, ...config };
7830
+ const loadResult = loadCorrelationData(mergedConfig);
7804
7831
  if (!loadResult.ok) {
7805
7832
  logger6.info("Starting with fresh correlation tracker", {
7806
7833
  reason: loadResult.error.message
@@ -7965,7 +7992,7 @@ function applyErrorPolicy(votes, policy) {
7965
7992
  }
7966
7993
 
7967
7994
  // src/orchestration/outcomes/outcome-store-persistence.ts
7968
- import { appendFileSync as appendFileSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync3 } from "fs";
7995
+ import { appendFileSync as appendFileSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync3 } from "fs";
7969
7996
  var PersistentOutcomeStore = class extends OutcomeStore {
7970
7997
  filePath;
7971
7998
  logger;
@@ -8075,7 +8102,7 @@ var PersistentOutcomeStore = class extends OutcomeStore {
8075
8102
  }
8076
8103
  persistLine(outcome) {
8077
8104
  try {
8078
- appendFileSync2(this.filePath, JSON.stringify(outcome) + "\n", "utf-8");
8105
+ appendFileSync3(this.filePath, JSON.stringify(outcome) + "\n", "utf-8");
8079
8106
  } catch (error) {
8080
8107
  const msg = getErrorMessage(error);
8081
8108
  this.logger.warn("Failed to persist outcome to disk", {
@@ -8678,7 +8705,7 @@ async function processVotesWithCascade(engineVotes, opts) {
8678
8705
  var CONTRARIAN_ESCALATION_THRESHOLD = 0.8;
8679
8706
  async function runContrarianCheck(proposal, log) {
8680
8707
  try {
8681
- const { executeExpert } = await import("./expert-bridge-EKPDZKMD.js");
8708
+ const { executeExpert } = await import("./expert-bridge-DJM5GAWZ.js");
8682
8709
  const prompt = [
8683
8710
  "You are a contrarian analyst. Your job is to find reasons this proposal should be REJECTED.",
8684
8711
  "Look for: YAGNI (not needed), MISALIGNED (wrong tech/architecture), SECURITY_RISK, SCOPE_CREEP.",
@@ -9095,4 +9122,4 @@ export {
9095
9122
  CONSENSUS_VOTE_OUTPUT_SCHEMA,
9096
9123
  registerConsensusVoteTool
9097
9124
  };
9098
- //# sourceMappingURL=chunk-P4W7PV6L.js.map
9125
+ //# sourceMappingURL=chunk-FTT2IYYX.js.map