@nexus-cortex/core 4.88.1 → 4.88.3

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.
@@ -1199,6 +1199,9 @@ export class CortexOrchestrator {
1199
1199
  // read this turn (verifyCoordinates). Stage-2-grounded citations are the
1200
1200
  // trusted baseline a coordinate must map to.
1201
1201
  let lastEndTurnCitations;
1202
+ // EFFORT TAIL one-shot (def-efdbb67fd8): the first EndTurn of this turn has
1203
+ // been bounced for a high-effort re-attestation cycle.
1204
+ let effortTailBounced = false;
1202
1205
  let endTurnLastToolName; // for the cortex training record
1203
1206
  // R60: the ROUTING decision = the FIRST real tool called in response to the
1204
1207
  // user prompt, WITH ITS ACTUAL INPUT ARGS. Previously the router sample's
@@ -2031,6 +2034,32 @@ export class CortexOrchestrator {
2031
2034
  if (tr.tool_name !== 'EndTurn')
2032
2035
  continue;
2033
2036
  const etUse = toolUseBlocks.find((t) => t.name === 'EndTurn');
2037
+ // EFFORT TAIL (def-efdbb67fd8, finish-discipline half): the FIRST
2038
+ // EndTurn is the model's own "I'm done" declaration — generated at
2039
+ // body effort. Bounce it ONCE ("verify at depth") and arm the effort
2040
+ // pulse so the re-attestation cycle runs elevated: structure forces
2041
+ // the check (the gate), effort funds it (the pulse). One-shot per
2042
+ // turn; skipped when a thrash pulse is already active (chain already
2043
+ // elevated). Rides the same is_error rejection channel as Stages
2044
+ // 2/4/5; liveness bounded by the gate's existing fallback-accept.
2045
+ // Requires CORTEX_ENDTURN_GATE (EndTurn must be offered). Ship dark.
2046
+ if (process.env.CORTEX_EFFORT_TAIL === 'true' &&
2047
+ !effortTailBounced &&
2048
+ this.effortPulseRemaining <= 0) {
2049
+ effortTailBounced = true;
2050
+ const tailTurns = Math.max(1, parseInt(process.env.CORTEX_EFFORT_TAIL_TURNS || '2', 10) || 2);
2051
+ this.effortPulseRemaining = tailTurns;
2052
+ tr.is_error = true;
2053
+ tr.content =
2054
+ 'Before finishing: verify at depth. Re-read the original task statement; ' +
2055
+ 're-open and check each requirement against the ACTUAL files/outputs you produced this turn ' +
2056
+ '(do not rely on memory of them); fix anything that does not match; then call EndTurn again ' +
2057
+ 'with the verified attestation.';
2058
+ if (this.config.debug) {
2059
+ console.log(`[EffortTail] first EndTurn bounced — re-attestation at elevated effort (${this.effortPulseRemaining} continuation(s))`);
2060
+ }
2061
+ continue;
2062
+ }
2034
2063
  const cits = etUse?.input?.citations;
2035
2064
  lastEndTurnCitations = Array.isArray(cits) ? cits : undefined; // Stage 3 baseline
2036
2065
  const verdict = verifyCitationsGrounded(cits, thisTurnToolOutputs.join('\n'));
@@ -2385,7 +2414,7 @@ export class CortexOrchestrator {
2385
2414
  temperature: options.parameters?.temperature,
2386
2415
  maxTokens: options.parameters?.maxTokens,
2387
2416
  topP: options.parameters?.topP,
2388
- reasoningEffort: options.parameters?.reasoningEffort, // GPT-5.1 reasoning level
2417
+ reasoningEffort: this.consumeEffortPulse() ?? options.parameters?.reasoningEffort, // effort pulse > request param > card
2389
2418
  stream: options.streaming,
2390
2419
  staticSystemPrompt: this.currentStaticSystemPrompt, // R28
2391
2420
  conversationId: this.currentConversationId, // R28b
@@ -4009,7 +4038,7 @@ export class CortexOrchestrator {
4009
4038
  temperature: options.parameters?.temperature,
4010
4039
  maxTokens: options.parameters?.maxTokens,
4011
4040
  topP: options.parameters?.topP,
4012
- reasoningEffort: options.parameters?.reasoningEffort, // GPT-5.1 reasoning level
4041
+ reasoningEffort: this.consumeEffortPulse() ?? options.parameters?.reasoningEffort, // effort pulse > request param > card
4013
4042
  stream: true, // STREAMING continuation
4014
4043
  staticSystemPrompt: this.currentStaticSystemPrompt, // R28
4015
4044
  conversationId: this.currentConversationId, // R28b
@@ -6887,6 +6916,17 @@ export class CortexOrchestrator {
6887
6916
  return undefined; // fail-open: never let the thrash read break a turn
6888
6917
  }
6889
6918
  }
6919
+ /** EFFORT PULSE (ablation 'think harder' arm, def-efdbb67fd8): continuations
6920
+ * remaining at elevated reasoning effort after a cumulative-thrash trigger. */
6921
+ effortPulseRemaining = 0;
6922
+ /** While the pulse is armed, continuation requests run at the elevated level
6923
+ * (CORTEX_EFFORT_PULSE_LEVEL, default 'high'); decrements per consumed request. */
6924
+ consumeEffortPulse() {
6925
+ if (this.effortPulseRemaining <= 0)
6926
+ return undefined;
6927
+ this.effortPulseRemaining -= 1;
6928
+ return (process.env.CORTEX_EFFORT_PULSE_LEVEL || 'high');
6929
+ }
6890
6930
  /** Honored AskForAdvice consults per session (rate-limit + rung state; persists across turns). */
6891
6931
  mentorConsultCounts = new Map();
6892
6932
  /**
@@ -7070,6 +7110,39 @@ export class CortexOrchestrator {
7070
7110
  }
7071
7111
  }
7072
7112
  }
7113
+ // EFFORT PULSE trigger (def-efdbb67fd8, 'think harder' ablation arm): on
7114
+ // cumulative thrash, escalate reasoning effort for the next N continuation
7115
+ // requests — deep deliberation bought exactly at the stuck point. The
7116
+ // introspective CONTRAST to the mentor's decorrelative consult: same
7117
+ // trigger, same rstan gate (cumulative threshold), INDEPENDENT of
7118
+ // CORTEX_MENTOR_AUTO so each ablation arm isolates cleanly. Ship dark.
7119
+ if (process.env.CORTEX_EFFORT_PULSE === 'true' && outcome.status !== 'ok') {
7120
+ const cfgP = resolveThrashConfig();
7121
+ const [pOutcomes, pPrior] = await Promise.all([
7122
+ store.recentOutcomes(cfgP.window),
7123
+ store.failureCount(this.currentSessionId ?? 'unknown'),
7124
+ ]);
7125
+ pOutcomes.push(false);
7126
+ const pCum = pPrior + 1;
7127
+ const pState = resolveThrashState(pOutcomes, pCum, cfgP, pCum);
7128
+ if (pState.thrashing) {
7129
+ const turns = Math.max(1, parseInt(process.env.CORTEX_EFFORT_PULSE_TURNS || '2', 10) || 2);
7130
+ if (this.effortPulseRemaining < turns)
7131
+ this.effortPulseRemaining = turns;
7132
+ if (this.config.debug) {
7133
+ console.log(`[EffortPulse] armed (trigger: ${pState.trigger}, cumFails: ${pCum}) — next ${this.effortPulseRemaining} continuation(s) at elevated effort`);
7134
+ }
7135
+ // Mechanism-engagement evidence (bench adjudication rule): bank the
7136
+ // arm-fired fact in the decision store — console logs are not
7137
+ // harvested, so without this the pulse arm cannot prove it fired.
7138
+ void store.recordEvent({
7139
+ sessionId: this.currentSessionId ?? 'unknown',
7140
+ kind: 'effort_pulse',
7141
+ toolName: toolUse.name,
7142
+ detail: { trigger: pState.trigger, cumFailures: pCum, turns: this.effortPulseRemaining, level: process.env.CORTEX_EFFORT_PULSE_LEVEL || 'high' },
7143
+ }).catch(() => { });
7144
+ }
7145
+ }
7073
7146
  }
7074
7147
  catch (err) {
7075
7148
  if (this.config.debug) {