@nexus-cortex/core 4.124.39 → 4.124.41
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/.env.defaults +48 -0
- package/dist/config/effectiveConfig.d.ts.map +1 -1
- package/dist/config/effectiveConfig.js +6 -0
- package/dist/config/effectiveConfig.js.map +1 -1
- package/dist/middleware/HelperModelMiddleware.js +1 -1
- package/dist/middleware/HelperModelMiddleware.js.map +1 -1
- package/dist/orchestrator/CortexOrchestrator.d.ts +15 -0
- package/dist/orchestrator/CortexOrchestrator.d.ts.map +1 -1
- package/dist/orchestrator/CortexOrchestrator.js +94 -5
- package/dist/orchestrator/CortexOrchestrator.js.map +1 -1
- package/dist/orchestrator/pid1Guard.d.ts +35 -0
- package/dist/orchestrator/pid1Guard.d.ts.map +1 -0
- package/dist/orchestrator/pid1Guard.js +101 -0
- package/dist/orchestrator/pid1Guard.js.map +1 -0
- package/dist/orchestrator/plateauStop.d.ts +96 -0
- package/dist/orchestrator/plateauStop.d.ts.map +1 -0
- package/dist/orchestrator/plateauStop.js +180 -0
- package/dist/orchestrator/plateauStop.js.map +1 -0
- package/dist/orchestrator/turnStatus.d.ts +2 -0
- package/dist/orchestrator/turnStatus.d.ts.map +1 -1
- package/dist/orchestrator/turnStatus.js +2 -0
- package/dist/orchestrator/turnStatus.js.map +1 -1
- package/dist/training/DecisionStore.d.ts +1 -1
- package/dist/training/DecisionStore.d.ts.map +1 -1
- package/dist/training/DecisionStore.js.map +1 -1
- package/dist/training/endTurnResolver.d.ts +8 -1
- package/dist/training/endTurnResolver.d.ts.map +1 -1
- package/dist/training/endTurnResolver.js +10 -3
- package/dist/training/endTurnResolver.js.map +1 -1
- package/package.json +3 -3
|
@@ -20,7 +20,7 @@ import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
|
20
20
|
import { execSync } from 'node:child_process';
|
|
21
21
|
import { ENV_RECON_COMMAND, resolveLiftPlanConfig, parsePlannerResponse, bankPlanText } from '../training/liftPlanner.js';
|
|
22
22
|
import { clipIn, FULL_CAPS, HINTS, resolveInventory, resolveInventoryPath } from '../training/steerInputs.js';
|
|
23
|
-
import { resolveEndTurnResolverConfig, parseResolverVerdict, effectiveMaxRejects, budgetedVetoEscalation, decideVetoAction, shouldFinishConfirm, buildFinishConfirmMessage, buildMeetsConfirmMessage, gapHoldable, parseSpecChecks, groundSpecCheck, specFailFraction, applyVetoFloor, holdProgressed, planSimilarity, specCheckEvidence, specBlockForJudge, dropSpecEchoes, specBlockForWriter, vetoMessageLead } from '../training/endTurnResolver.js';
|
|
23
|
+
import { resolveEndTurnResolverConfig, parseResolverVerdict, effectiveMaxRejects, budgetedVetoEscalation, decideVetoAction, shouldFinishConfirm, buildFinishConfirmMessage, buildMeetsConfirmMessage, gapHoldable, parseSpecChecks, groundSpecCheck, specFailFraction, applyVetoFloor, holdProgressed, planSimilarity, specCheckEvidence, specBlockForJudge, dropSpecEchoes, specBlockForWriter, vetoMessageLead, RESOLVER_SCALE_CLAUSE } from '../training/endTurnResolver.js';
|
|
24
24
|
import { jevAvailable, jevNoul, buildGapHoldState, GAP_HOLD_QUESTIONS } from '../training/jevGate.js'; // R173b
|
|
25
25
|
import { resolveFrameConfig, FRAME_CONTRACT, FRAME_TOOL_NAME } from '../frames/frameConfig.js'; // R179
|
|
26
26
|
import { FrameRunner } from '../frames/frameRunner.js'; // R179
|
|
@@ -91,6 +91,8 @@ import { pruneAgedToolResults } from '../conversation/ToolResultPruner.js';
|
|
|
91
91
|
import { detectTailRepetition, tailLoopGuardEnabled } from './tailRepetitionDetector.js';
|
|
92
92
|
import { resolveEffortRamp, rampEffortFor } from './effortRamp.js';
|
|
93
93
|
import { resolveWallDrop, resolveOutputCap, dropWalledTurn, resolveWallSummary, extractWalledReasoning, clipReasoning, formatWallSummary } from './wallGuard.js';
|
|
94
|
+
import { resolvePid1Guard, detectPid1Note } from './pid1Guard.js'; // R209
|
|
95
|
+
import { PlateauStopTracker, plateauBootInstruction, plateauStatusSegment } from './plateauStop.js'; // R210
|
|
94
96
|
import { resolveComputeNudge, computeNudgeDecision, buildComputeNudgeLine, lastAssistantReasoningTokens } from './computeNudge.js';
|
|
95
97
|
import { classifyEmptyResponse, emptyResponseNudge, nudgeForbidsTools, emptyResponseNudgeFor, isReasoningExhaustion, stepDownEffort, effortLadderFor, resolveExhaustLadderMode, resolveReasoningExhaustBackoff } from './emptyResponseClassifier.js';
|
|
96
98
|
import { isImageRejectionError, stripRejectedImages } from './imageRejectionHeal.js'; // R154
|
|
@@ -214,6 +216,9 @@ export class CortexOrchestrator {
|
|
|
214
216
|
* exactly once, at the anchor-lift boundary. One-shot per orchestrator. */
|
|
215
217
|
deferredCorpusDelivered = false;
|
|
216
218
|
liftNudgeDelivered = false; // A′ proposal-1: lift-boundary SearchTools/AskForAdvice nudge, one-shot
|
|
219
|
+
pid1NoteChecked = false; // R209 HB-CONTAINER-PID1: PID 1 inspected once, at the first tool_result boundary
|
|
220
|
+
plateauInstructionDelivered = false; // R210 HB-PLATEAU-STOP: boot instruction, one-shot at the first tool_result boundary
|
|
221
|
+
plateauTracker = new PlateauStopTracker(); // R210: per-session PLATEAU_METRIC series
|
|
217
222
|
// CORTEX_LOOP_TOOL_BLOCK (hard loop intervention): when the ladder flags a
|
|
218
223
|
// non-converging same-approach loop, disable the looping tool's EXECUTOR for
|
|
219
224
|
// ONE turn (tools list unchanged → cache-safe); a call to it returns an
|
|
@@ -401,6 +406,75 @@ export class CortexOrchestrator {
|
|
|
401
406
|
return tools; // interactive: keep it
|
|
402
407
|
return tools.filter((t) => t.name !== 'AskUserQuestion');
|
|
403
408
|
}
|
|
409
|
+
/** R209 HB-CONTAINER-PID1 (CORTEX_PID1_GUARD=on, dark): at the first tool_result boundary (the boot observation), when PID 1 is not
|
|
410
|
+
* the harness, append ONE note naming PID 1 and the services it supervises — killing them stops the container and ends the session.
|
|
411
|
+
* Independent of the tool anchor. One-shot; Linux-only; fail-safe (no note on any error). Event pid1_guard when the note is added. */
|
|
412
|
+
deliverPid1NoteAtBoot() {
|
|
413
|
+
if (this.pid1NoteChecked || !resolvePid1Guard())
|
|
414
|
+
return;
|
|
415
|
+
try {
|
|
416
|
+
const lastMsg = this.messageHistory[this.messageHistory.length - 1];
|
|
417
|
+
if (lastMsg?.message?.content?.[0]?.type !== 'tool_result')
|
|
418
|
+
return; // not the boundary yet — leave the one-shot open
|
|
419
|
+
this.pid1NoteChecked = true;
|
|
420
|
+
const r = detectPid1Note();
|
|
421
|
+
if (!r)
|
|
422
|
+
return;
|
|
423
|
+
lastMsg.message.content.push({ type: 'text', text: `<system-reminder>\n${r.note}\n</system-reminder>` });
|
|
424
|
+
const store = this.getDecisionStore();
|
|
425
|
+
if (store)
|
|
426
|
+
void store.recordEvent({ sessionId: this.currentSessionId ?? 'unknown', kind: 'pid1_guard', detail: { noted: true, pid1Cmd: r.info.pid1Cmd, children: r.info.children, chars: r.note.length } }).catch(() => { });
|
|
427
|
+
if (this.config.debug)
|
|
428
|
+
console.log(`[Pid1Guard] boot note delivered (PID 1 = ${r.info.pid1Cmd}, ${r.info.children.length} child(ren))`);
|
|
429
|
+
}
|
|
430
|
+
catch { /* fail-safe: no note */ }
|
|
431
|
+
}
|
|
432
|
+
/** R210 HB-PLATEAU-STOP (CORTEX_PLATEAU_STOP=on, dark): at the first tool_result boundary (same carrier and boundary as the R209
|
|
433
|
+
* PID 1 note), append ONE system-reminder asking the model to print `PLATEAU_METRIC <name>=<number> dir=<max|min>` after every
|
|
434
|
+
* evaluation and keep the deliverable at its best result. Off → nothing. One-shot; fail-safe. */
|
|
435
|
+
deliverPlateauInstructionAtBoot() {
|
|
436
|
+
if (this.plateauInstructionDelivered)
|
|
437
|
+
return;
|
|
438
|
+
try {
|
|
439
|
+
const text = plateauBootInstruction();
|
|
440
|
+
if (!text)
|
|
441
|
+
return;
|
|
442
|
+
const lastMsg = this.messageHistory[this.messageHistory.length - 1];
|
|
443
|
+
if (lastMsg?.message?.content?.[0]?.type !== 'tool_result')
|
|
444
|
+
return; // not the boundary yet — leave the one-shot open
|
|
445
|
+
this.plateauInstructionDelivered = true;
|
|
446
|
+
lastMsg.message.content.push({ type: 'text', text: `<system-reminder>\n${text}\n</system-reminder>` });
|
|
447
|
+
if (this.config.debug)
|
|
448
|
+
console.log('[PlateauStop] boot instruction delivered');
|
|
449
|
+
}
|
|
450
|
+
catch { /* fail-safe: no instruction */ }
|
|
451
|
+
}
|
|
452
|
+
/** R210 HB-PLATEAU-STOP: scan this round's tool results for PLATEAU_METRIC reports and return the plateau reminder (or null) for
|
|
453
|
+
* the budget-steering signals line. Off → null without scanning. Events: plateau_metric_seen (first report of a metric name),
|
|
454
|
+
* plateau_stop (each firing, max 2 per session). Never throws. */
|
|
455
|
+
observePlateau(toolResults, iteration, streaming) {
|
|
456
|
+
try {
|
|
457
|
+
const r = this.plateauTracker.step(toolResults); // off → returns before touching the results
|
|
458
|
+
if (!r.newMetrics.length && !r.fire)
|
|
459
|
+
return null;
|
|
460
|
+
const store = this.getDecisionStore();
|
|
461
|
+
const sessionId = this.currentSessionId ?? 'unknown';
|
|
462
|
+
for (const m of r.newMetrics) {
|
|
463
|
+
if (store)
|
|
464
|
+
void store.recordEvent({ sessionId, kind: 'plateau_metric_seen', detail: { name: m.name, dir: m.dir, value: m.value, iteration, streaming } }).catch(() => { });
|
|
465
|
+
}
|
|
466
|
+
if (r.fire) {
|
|
467
|
+
if (store)
|
|
468
|
+
void store.recordEvent({ sessionId, kind: 'plateau_stop', detail: { ...r.fire, iteration, streaming } }).catch(() => { });
|
|
469
|
+
if (this.config.debug)
|
|
470
|
+
console.log(`[PlateauStop] ${r.fire.name} plateau (${r.fire.improvementPct}% over the window, ${r.fire.points} points) — firing ${r.fire.firing}`);
|
|
471
|
+
}
|
|
472
|
+
return r.signal;
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
404
478
|
/** A′ proposal-1: at the anchor-lift boundary, when deferred loading is on and
|
|
405
479
|
* CORTEX_LIFT_NUDGE is truthy, append a MINIMAL system-reminder pointing the model
|
|
406
480
|
* at SearchTools (to reach the tools the deferred filter hides — names come from
|
|
@@ -1290,6 +1364,9 @@ export class CortexOrchestrator {
|
|
|
1290
1364
|
// what it judged, not just counts — so a k=5 run can score the resolver's JUDGMENT QUALITY
|
|
1291
1365
|
// (was the GAP warranted? was the fix plan good? did it judge the right artifact?) and not
|
|
1292
1366
|
// merely that it fired. Bounded caps keep the decisions row sane. See HARNESS_IMPROVEMENT_BACKLOG.
|
|
1367
|
+
// R208 HB-VERIFY-AT-SCALE (CORTEX_VERIFY_SCALE=on, dark): the judge persona carried the scale rubric item on this adjudication.
|
|
1368
|
+
if (store && cfg.verifyScale)
|
|
1369
|
+
void store.recordEvent({ sessionId, kind: 'verify_scale_item', toolName: 'EndTurn', detail: { surface: 'endturn-resolver', clauseChars: RESOLVER_SCALE_CLAUSE.length, roundsUsed, meets: verdict.meets, parsed: verdict.parsed, confidence: verdict.confidence } }).catch(() => { });
|
|
1293
1370
|
if (store)
|
|
1294
1371
|
void store.recordEvent({
|
|
1295
1372
|
sessionId,
|
|
@@ -1309,6 +1386,7 @@ export class CortexOrchestrator {
|
|
|
1309
1386
|
derivation: cfg.derivation, derivationAgreement: derivationInfo?.agreement ?? null, derivationHeld: !!derivationHold, // R176
|
|
1310
1387
|
reqLedger: cfg.reqLedger, reqLines: reqCounts.lines, reqOpen: reqCounts.open, reqExercised: reqCounts.exercised, reqFailed: reqCounts.failed, reqUnverifiable: reqCounts.unverifiable, reqHeld: !!reqHold, reqHolds: this.reqLedgerHolds, reqGenLatencyMs: this.reqLedgerMeta.genLatencyMs, reqJev: cfg.reqLedgerJev, reqJevAsked: reqJev?.asked ?? 0, reqJevClosed: reqJev?.closed ?? [], reqJevLatencyMs: reqJev?.latencyMs ?? 0, // R187/R187b
|
|
1311
1388
|
reqFailVeto: !!reqFailVeto, reqFailVetoes: this.reqLedgerFailVetoes, reqFailedNow, reqFailJev, // R192
|
|
1389
|
+
verifyScale: cfg.verifyScale, // R208
|
|
1312
1390
|
reqBroken: [...this.reqLedgerBroken], reqLinesDetail: (this.reqLedger ?? []).map((e) => ({ id: e.id, kind: e.kind, status: e.status, check: !!e.check, runs: e.runs, last: (e.lastResult ?? '').split('\n').slice(0, 2).join(' / ').slice(0, 200) })), // R191: per-line outcomes so a false-failure read is possible from the decisions file
|
|
1313
1391
|
latencyMs, rawLen: (text ?? '').length,
|
|
1314
1392
|
deltaChars: workspaceDelta.length, checkRan: !!checkResult, checkPassed: checkResult ? /→ PASSED/.test(checkResult) : null,
|
|
@@ -3482,8 +3560,10 @@ export class CortexOrchestrator {
|
|
|
3482
3560
|
}
|
|
3483
3561
|
timeSignal = de?.signal || timeBudgetWarnNudge(Date.now() - loopStartMs, TURN_DEADLINE_MS);
|
|
3484
3562
|
}
|
|
3485
|
-
|
|
3486
|
-
|
|
3563
|
+
// R210 HB-PLATEAU-STOP (dark unless CORTEX_PLATEAU_STOP): PLATEAU_METRIC series → one stop reminder on a plateau (same carrier).
|
|
3564
|
+
const plateauSignal = this.observePlateau(toolResults, toolCallIteration, false);
|
|
3565
|
+
if (budgetSignal || diversityWarning || ladderSignal || timeSignal || budgetVisSignal || plateauSignal) {
|
|
3566
|
+
const signals = [budgetSignal, diversityWarning, ladderSignal, timeSignal, budgetVisSignal, plateauSignal].filter(Boolean).join('\n');
|
|
3487
3567
|
const lastMsg = this.messageHistory[this.messageHistory.length - 1];
|
|
3488
3568
|
if (lastMsg?.message?.content?.[0]?.type === 'tool_result') {
|
|
3489
3569
|
const block = lastMsg.message.content[0];
|
|
@@ -3502,6 +3582,7 @@ export class CortexOrchestrator {
|
|
|
3502
3582
|
ladderSignal ? (ladderPollSteer ? 'poll_steer' : 'ladder') : null,
|
|
3503
3583
|
timeSignal ? 'time' : null,
|
|
3504
3584
|
budgetVisSignal ? 'budget_visibility' : null,
|
|
3585
|
+
plateauSignal ? 'plateau' : null,
|
|
3505
3586
|
].filter(Boolean);
|
|
3506
3587
|
void store
|
|
3507
3588
|
.recordEvent({
|
|
@@ -3589,6 +3670,8 @@ export class CortexOrchestrator {
|
|
|
3589
3670
|
// Send tool results back to model and get continuation response
|
|
3590
3671
|
// Proactive context management - ensure history fits before continuation
|
|
3591
3672
|
await this.ensureHistoryFitsModel(effectiveModel);
|
|
3673
|
+
this.deliverPid1NoteAtBoot(); // R209 HB-CONTAINER-PID1 (dark unless CORTEX_PID1_GUARD): PID 1 note on the boot observation
|
|
3674
|
+
this.deliverPlateauInstructionAtBoot(); // R210 HB-PLATEAU-STOP (dark unless CORTEX_PLATEAU_STOP): PLATEAU_METRIC instruction
|
|
3592
3675
|
// Anchor lift (BASH_PLUS_SPEC.md P0): the first tool call has executed —
|
|
3593
3676
|
// this continuation is the first tool_result boundary, so the session's
|
|
3594
3677
|
// full profile applies from here. Rebuild from allTools because the
|
|
@@ -5316,8 +5399,10 @@ export class CortexOrchestrator {
|
|
|
5316
5399
|
}
|
|
5317
5400
|
timeSignal = de?.signal || timeBudgetWarnNudge(Date.now() - loopStartMs, TURN_DEADLINE_MS);
|
|
5318
5401
|
}
|
|
5319
|
-
|
|
5320
|
-
|
|
5402
|
+
// R210 HB-PLATEAU-STOP (streaming parity).
|
|
5403
|
+
const plateauSignal = this.observePlateau(toolResults, toolCallIteration, true);
|
|
5404
|
+
if (budgetSignal || diversityWarning || ladderSignal || timeSignal || budgetVisSignal || plateauSignal) {
|
|
5405
|
+
const signals = [budgetSignal, diversityWarning, ladderSignal, timeSignal, budgetVisSignal, plateauSignal].filter(Boolean).join('\n');
|
|
5321
5406
|
const lastMsg = this.messageHistory[this.messageHistory.length - 1];
|
|
5322
5407
|
if (lastMsg?.message?.content?.[0]?.type === 'tool_result') {
|
|
5323
5408
|
const block = lastMsg.message.content[0];
|
|
@@ -5333,6 +5418,7 @@ export class CortexOrchestrator {
|
|
|
5333
5418
|
ladderSignal ? (ladderPollSteer ? 'poll_steer' : 'ladder') : null,
|
|
5334
5419
|
timeSignal ? 'time' : null,
|
|
5335
5420
|
budgetVisSignal ? 'budget_visibility' : null,
|
|
5421
|
+
plateauSignal ? 'plateau' : null,
|
|
5336
5422
|
].filter(Boolean);
|
|
5337
5423
|
void store
|
|
5338
5424
|
.recordEvent({
|
|
@@ -5412,6 +5498,8 @@ export class CortexOrchestrator {
|
|
|
5412
5498
|
// Send continuation request with tool results
|
|
5413
5499
|
// Proactive context management - ensure history fits before streaming continuation
|
|
5414
5500
|
await this.ensureHistoryFitsModel(effectiveModel);
|
|
5501
|
+
this.deliverPid1NoteAtBoot(); // R209 HB-CONTAINER-PID1 — streaming mirror
|
|
5502
|
+
this.deliverPlateauInstructionAtBoot(); // R210 HB-PLATEAU-STOP — streaming mirror
|
|
5415
5503
|
// Anchor lift — streaming mirror of the sendMessage continuation path.
|
|
5416
5504
|
if (!this.anchorLifted &&
|
|
5417
5505
|
resolveToolAnchor(process.env, this.cardAnchorProfile) &&
|
|
@@ -6826,6 +6914,7 @@ export class CortexOrchestrator {
|
|
|
6826
6914
|
contextWindow: model.limits?.contextWindow ?? this.lastKnownContextWindow,
|
|
6827
6915
|
shells,
|
|
6828
6916
|
nowMs: now,
|
|
6917
|
+
plateau: plateauStatusSegment(this.plateauTracker), // R210: null when CORTEX_PLATEAU_STOP is off or no metric seen → line unchanged
|
|
6829
6918
|
});
|
|
6830
6919
|
if (appendStatusToNewestToolResult(this.messageHistory, line)) {
|
|
6831
6920
|
this.turnStatusLines++;
|