@principles/codex-adapter 0.17.2 → 0.17.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.
@@ -43,7 +43,7 @@ export interface CodexWorkerCycleStepReport {
43
43
  */
44
44
  readonly targetEvidenceReconcile?: TargetEvidenceReconcileReport;
45
45
  /**
46
- * Phase B Stage-2 review step. Always the LAST step so it can never starve
46
+ * Phase B Stage-2 review step. Runs after downstream so it can never starve
47
47
  * the Diagnostician (bounded to ≤2 candidates / ≤60s aggregate).
48
48
  */
49
49
  readonly stage2?: Stage2CorrectionCycleReport;
@@ -74,6 +74,9 @@ export interface CodexWorkerCycleOptions {
74
74
  */
75
75
  readonly stage2Classifier?: SignalLlmClassifier | null;
76
76
  readonly stage2AggregateBudgetMs?: number;
77
+ /** Test seams for the bounded, consent-gated correction optimization tail. */
78
+ readonly correctionObserverMinIntervalMs?: number;
79
+ readonly correctionObserverTimeoutMs?: number;
77
80
  /** Test seam: undefined = production auditor resolution; null = explicitly unavailable. */
78
81
  readonly idleTurnAuditor?: IdleTurnAuditor | null;
79
82
  }
@@ -28,7 +28,7 @@
28
28
  import fs from 'node:fs';
29
29
  import path from 'node:path';
30
30
  import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, pickDiagnosticianCandidate, reconcileWaitingTargetEvidenceTasks, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, PDRuntimeError, } from '@principles/core/runtime';
31
- import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, executeQueuedDiagnosisWithInboxRecovery, runInternalizationConsumerCycle, runStage2CorrectionCycle, runIdleTurnAuditCycle, createIdleTurnAuditorForWorkspace, createSignalClassifierForWorkspace, createConsentLedgerSourceMaterialAuthorization, resolveWorkspacePipelineHostDeps, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
31
+ import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, executeQueuedDiagnosisWithInboxRecovery, runInternalizationConsumerCycle, runStage2CorrectionCycle, runCorrectionObserverOptimizationCycle, openGovernanceCorrectionTrajectory, updateSignalHealth, runIdleTurnAuditCycle, createIdleTurnAuditorForWorkspace, createSignalClassifierForWorkspace, createConsentLedgerSourceMaterialAuthorization, resolveWorkspacePipelineHostDeps, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
32
32
  import { catchUpCodexIngestion } from '../ingestion/catch-up.js';
33
33
  import { readCodexTargetTurnEvidence } from '../ingestion/pain-receipt-fallback.js';
34
34
  import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from '../tool-semantics.js';
@@ -244,6 +244,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
244
244
  // about whether a driver is actually alive.
245
245
  lastCycleDriver: codexWorkerCycleDriver(),
246
246
  });
247
+ const sourceMaterialAuthorization = createConsentLedgerSourceMaterialAuthorization(workspaceDir);
247
248
  const consumerFlag = loadFeatureFlagFromConfig(workspaceDir, 'internalization_auto_consumer', { info: (m) => logger.info(m), warn: (m) => logger.warn(m) });
248
249
  // PRI-638 P1-C: the Diagnostician capability gate is resolved from the same
249
250
  // canonical authority the runtime factory uses. An Owner-disabled agent is
@@ -327,7 +328,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
327
328
  targetEvidenceReconcile = await reconcileWaitingTargetEvidenceTasks({
328
329
  stateManager: handle.stateManager,
329
330
  readTargetTurnEvidence: (sessionId, turnId) => readCodexTargetTurnEvidence(path.resolve(workspaceDir), sessionId, turnId),
330
- sourceMaterialAuthorization: createConsentLedgerSourceMaterialAuthorization(path.resolve(workspaceDir)),
331
+ sourceMaterialAuthorization,
331
332
  hostKind: 'codex',
332
333
  nowIso: new Date().toISOString(),
333
334
  });
@@ -350,6 +351,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
350
351
  const hostDeps = resolveWorkspacePipelineHostDeps({
351
352
  workspaceDir,
352
353
  effectiveConfig: config.effective,
354
+ sourceMaterialAuthorization,
353
355
  telemetryPersistenceFailureHandler: (detail) => {
354
356
  try {
355
357
  emitEvent('CODEX_WORKER_CRITICAL_TELEMETRY_PERSIST_FAILED', detail);
@@ -467,6 +469,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
467
469
  const hostDeps = resolveWorkspacePipelineHostDeps({
468
470
  workspaceDir,
469
471
  effectiveConfig: config.effective,
472
+ sourceMaterialAuthorization,
470
473
  telemetryPersistenceFailureHandler: (detail) => {
471
474
  try {
472
475
  emitEvent('CODEX_WORKER_CRITICAL_TELEMETRY_PERSIST_FAILED', detail);
@@ -583,7 +586,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
583
586
  // No hostToolCatalog: PD has not declared a Codex tool catalog; a wrong
584
587
  // (OpenClaw) catalog would be worse than none (PRI-630 follow-up).
585
588
  });
586
- // Step 8 (SPEC v0.3.1 §2) — bounded Stage-2 correction review, ALWAYS last:
589
+ // Step 8 (SPEC v0.3.1 §2) — bounded Stage-2 correction review, after downstream:
587
590
  // the Diagnostician has already run, so this step cannot starve it. ≤2
588
591
  // candidates, ≤60s aggregate, single 60s classification timeout.
589
592
  const stage2Resolution = options.stage2Classifier === undefined
@@ -647,6 +650,31 @@ export async function runCodexWorkspaceWorkerCycle(options) {
647
650
  ...(degradedReason !== undefined ? { lastDegradedReason: degradedReason } : {}),
648
651
  ...invocationIdLivenessPatch(),
649
652
  });
653
+ // Optional optimization is outside the outcome/heartbeat calculation.
654
+ // An eligible one-shot worker awaits only its bounded tail, so a late model
655
+ // response cannot strand the main cycle or degrade liveness.
656
+ if (flags.correction_observer?.enabled === true) {
657
+ const stateDir = path.join(workspaceDir, '.state');
658
+ try {
659
+ await runCorrectionObserverOptimizationCycle({
660
+ workspaceDir,
661
+ stateDir,
662
+ hostKind: 'codex',
663
+ logger,
664
+ openTrajectory: () => openGovernanceCorrectionTrajectory({
665
+ workspaceDir, hostKind: 'codex', sourceMaterialAuthorization,
666
+ }),
667
+ minIntervalMs: options.correctionObserverMinIntervalMs ?? 15 * 60_000,
668
+ timeoutMs: options.correctionObserverTimeoutMs ?? 10_000,
669
+ ...(options.now === undefined ? {} : { now: () => options.now ?? new Date() }),
670
+ });
671
+ }
672
+ catch {
673
+ // Shared cycle owns ordinary failures; also isolate an unexpected
674
+ // exception (including a failed optional diagnostic logger).
675
+ updateSignalHealth(stateDir, (health) => { health.observerConsecutiveFailures += 1; });
676
+ }
677
+ }
650
678
  return {
651
679
  ...base,
652
680
  mode: degradedReason !== undefined ? 'degraded' : 'ready',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/codex-adapter",
3
- "version": "0.17.2",
3
+ "version": "0.17.3",
4
4
  "description": "Codex CLI host adapter for Principles Disciple — implements HostAdapter interface for OpenAI Codex CLI's stdin/stdout JSON hook model (ADR-0020).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,8 +33,8 @@
33
33
  "lint": "eslint \"src/**/*.ts\""
34
34
  },
35
35
  "dependencies": {
36
- "@principles/core": "^10.0.0",
37
- "@principles/host-runtime": "^5.0.0",
36
+ "@principles/core": "^10.0.1",
37
+ "@principles/host-runtime": "^5.1.0",
38
38
  "@principles/install-layout": "^0.12.0"
39
39
  },
40
40
  "devDependencies": {
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "293825348a6f4a40cc561f6a59fc42c64d532766"
55
+ "gitHead": "a6798ad286b1584b8d6e2da6fd9b81e9b99609cf"
56
56
  }