@nexus-cortex/core 4.108.4 → 4.108.7

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 (33) hide show
  1. package/.env.defaults +9 -0
  2. package/dist/config/RuntimeConfigRegistry.d.ts.map +1 -1
  3. package/dist/config/RuntimeConfigRegistry.js +1 -0
  4. package/dist/config/RuntimeConfigRegistry.js.map +1 -1
  5. package/dist/config/SettingsLoader.d.ts.map +1 -1
  6. package/dist/config/SettingsLoader.js +1 -0
  7. package/dist/config/SettingsLoader.js.map +1 -1
  8. package/dist/config/SettingsSchema.d.ts +1 -0
  9. package/dist/config/SettingsSchema.d.ts.map +1 -1
  10. package/dist/config/SettingsSchema.js +9 -0
  11. package/dist/config/SettingsSchema.js.map +1 -1
  12. package/dist/config/effectiveConfig.d.ts.map +1 -1
  13. package/dist/config/effectiveConfig.js +1 -0
  14. package/dist/config/effectiveConfig.js.map +1 -1
  15. package/dist/orchestrator/CortexOrchestrator.d.ts.map +1 -1
  16. package/dist/orchestrator/CortexOrchestrator.js +27 -6
  17. package/dist/orchestrator/CortexOrchestrator.js.map +1 -1
  18. package/dist/orchestrator/compactionResume.d.ts +10 -0
  19. package/dist/orchestrator/compactionResume.d.ts.map +1 -1
  20. package/dist/orchestrator/compactionResume.js +41 -0
  21. package/dist/orchestrator/compactionResume.js.map +1 -1
  22. package/dist/utils/ContextResolver.d.ts.map +1 -1
  23. package/dist/utils/ContextResolver.js +3 -2
  24. package/dist/utils/ContextResolver.js.map +1 -1
  25. package/dist/utils/index.d.ts +1 -0
  26. package/dist/utils/index.d.ts.map +1 -1
  27. package/dist/utils/index.js +1 -0
  28. package/dist/utils/index.js.map +1 -1
  29. package/dist/utils/stateDir.d.ts +23 -0
  30. package/dist/utils/stateDir.d.ts.map +1 -0
  31. package/dist/utils/stateDir.js +93 -0
  32. package/dist/utils/stateDir.js.map +1 -0
  33. package/package.json +3 -3
@@ -38,8 +38,9 @@ import { toolFactory } from '../tools/ToolFactory.js';
38
38
  import { resolveToolProfile, resolveToolAnchor, resolveFrameProfile, resolveLiftNudge, resolveLiftPlan, resolveEndTurnResolver, resolveHeadlessDropAskUser, resolveDeferredLoading, isNarrowProfile, isToolAllowedByProfile, applyToolProfile, webToolBlocked, resolveVisionHelperModel, resolveVisionHandoffMax, resolveSliceNudge, resolveSliceBlock, resolveSliceBlockAt, resolveSliceBlockMax } from '../tools/ToolProfile.js';
39
39
  import { sliceReadFile, decideSliceBlock } from './sliceBlock.js';
40
40
  import { TurnEvidence, evaluateEndTurnGates, buildMissingEndTurnReminder } from './endTurnGates.js';
41
- import { resolveCompactionResume, pickDropped, buildCompactionResumeReminder, isCompactionResumeMessage, resolveTaskText, resumeMemoryTargetTokens, coversAll, buildRollingSeedMessage, memoryIndexLine, upsertMemoryIndex } from './compactionResume.js';
41
+ import { resolveCompactionResume, pickDropped, buildCompactionResumeReminder, isCompactionResumeMessage, resolveTaskText, resumeMemoryTargetTokens, coversAll, buildRollingSeedMessage, memoryIndexLine, upsertMemoryIndex, scaleEstimateToRequestView, approxCharsOf } from './compactionResume.js';
42
42
  import { renderResumeMemoryPrompt, buildRebuildInstructions, resolveCheckpointBand, resolveRearmBand } from './compactionResumeTemplate.js';
43
+ import { resolveCortexStateDir, cortexStatePath } from '../utils/stateDir.js';
43
44
  import { collectWorkspaceDelta, detectCheckCommand, runCheck, resolveJudgeGroundingConfig } from '../training/judgeEvidence.js';
44
45
  import { resolveMentorRoleConfig, describeMentorWire, describeMentorDelivery, mentorSurfaceTimeoutMs } from '../training/mentorRole.js';
45
46
  import { resolveOuterToolDeadlineMs } from './outerToolTimeout.js';
@@ -2245,7 +2246,7 @@ export class CortexOrchestrator {
2245
2246
  // orchestrator (config.projectPath is unset there → was landing
2246
2247
  // at the server's cwd).
2247
2248
  const recRoot = process.env.PROJECT_ROOT || this.config.projectPath || this.config.workingDirectory || process.cwd();
2248
- const recPath = pathJoin(recRoot, '.cortex', 'training', 'cortex-samples.jsonl');
2249
+ const recPath = cortexStatePath(recRoot, 'training', 'cortex-samples.jsonl');
2249
2250
  appendJsonlRotating(recPath, JSON.stringify(sample));
2250
2251
  }
2251
2252
  catch (recErr) {
@@ -5692,7 +5693,7 @@ export class CortexOrchestrator {
5692
5693
  /** HB-COMPACTION-RESUME: best-effort write of the resume memory to .cortex/memory/resume-<session>.md (synchronous fs). */
5693
5694
  writeResumeMemoryFile(text, why) {
5694
5695
  try {
5695
- const cortexDir = pathJoin(this.config.projectPath || process.cwd(), '.cortex');
5696
+ const cortexDir = resolveCortexStateDir(this.config.projectPath || process.cwd()).dir;
5696
5697
  const dir = pathJoin(cortexDir, 'memory');
5697
5698
  mkdirSync(dir, { recursive: true });
5698
5699
  const name = `resume-${this.currentSessionId}`;
@@ -5742,7 +5743,26 @@ export class CortexOrchestrator {
5742
5743
  // Thinking blocks are NEVER stripped — stripping mutates messageHistory,
5743
5744
  // breaks prompt-cache prefix continuity, and causes model confusion.
5744
5745
  // Context overflow is handled by compaction (whole-message removal).
5745
- const currentTokens = this.contextBudgetManager.estimateTotalTokens(this.messageHistory);
5746
+ const rawEstimate = this.contextBudgetManager.estimateTotalTokens(this.messageHistory);
5747
+ // 4.108.5 (R129, TB4.0 cad-model): the stored history can weigh 1M+ "tokens" of raw tool output while the REQUEST carries the
5748
+ // aged-pruned view (68K real tokens). Compaction must judge what the request sends, or the checkpoint rung and the proactive drop
5749
+ // fire on a false reading and re-fire every iteration (tokensAfter stays above the threshold). Scale the estimate by the
5750
+ // pruned-view/raw char ratio; below the pruner's 50%-utilization gate the ratio is 1 and nothing changes.
5751
+ let requestRatio = 1;
5752
+ let currentTokens = rawEstimate;
5753
+ try {
5754
+ const rawChars = approxCharsOf(this.messageHistory);
5755
+ const prunedChars = approxCharsOf(this.convertToCanonicalMessages(this.messageHistory));
5756
+ currentTokens = scaleEstimateToRequestView(rawEstimate, rawChars, prunedChars);
5757
+ requestRatio = rawEstimate > 0 ? currentTokens / rawEstimate : 1;
5758
+ if (this.config.debug && requestRatio < 1) {
5759
+ console.log(`[Orchestrator Context] request-view estimate: ${currentTokens} of ${rawEstimate} stored tokens (ratio ${requestRatio.toFixed(3)})`);
5760
+ }
5761
+ }
5762
+ catch {
5763
+ currentTokens = rawEstimate;
5764
+ requestRatio = 1;
5765
+ }
5746
5766
  // Budget overrides: use actual token counts instead of hardcoded estimates.
5747
5767
  // - actualToolTokens: real tool schema size (tools are NOT in messageHistory)
5748
5768
  // - actualSystemTokens: 0 because system messages are embedded as <system-reminder>
@@ -5807,7 +5827,7 @@ export class CortexOrchestrator {
5807
5827
  // Select messages that fit within budget (standard path — no thinking stripping)
5808
5828
  const selectedMessages = this.contextBudgetManager.selectMessages(this.messageHistory, budget.availableForHistory, { strategy, preserveToolCalls: true }, model);
5809
5829
  const removedCount = this.messageHistory.length - selectedMessages.length;
5810
- const newTokenCount = this.contextBudgetManager.estimateTotalTokens(selectedMessages);
5830
+ const newTokenCount = Math.max(1, Math.round(this.contextBudgetManager.estimateTotalTokens(selectedMessages) * requestRatio));
5811
5831
  if (this.config.debug) {
5812
5832
  console.log(`[OK] Context managed: ${this.messageHistory.length} -> ${selectedMessages.length} messages`);
5813
5833
  console.log(` Token reduction: ${currentTokens} -> ${newTokenCount} tokens (removed ${currentTokens - newTokenCount})`);
@@ -7704,7 +7724,8 @@ export class CortexOrchestrator {
7704
7724
  }
7705
7725
  if (!this.decisionStore) {
7706
7726
  const root = this.config.projectPath || process.cwd();
7707
- const storePath = `${root}/.cortex/decisions.jsonl`;
7727
+ // 4.108.6 (R131): state root resolves to a WRITABLE location (read-only workdirs fall back; never fatal)
7728
+ const storePath = cortexStatePath(root, 'decisions.jsonl');
7708
7729
  this.decisionStore = new DecisionStore(storePath);
7709
7730
  }
7710
7731
  return this.decisionStore;