@principles/codex-adapter 0.16.2 → 0.17.1
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.
|
@@ -124,10 +124,20 @@ function collectVerifiedToolOutcomes(observations) {
|
|
|
124
124
|
previewParts.push(stderr);
|
|
125
125
|
if (typeof stdout === 'string' && stdout.length > 0)
|
|
126
126
|
previewParts.push(stdout);
|
|
127
|
+
const factRecord = facts;
|
|
128
|
+
const rawCommand = factRecord.command;
|
|
129
|
+
// The transcript stores the physical process argv (often a shell wrapper),
|
|
130
|
+
// while the live Bash hook receives the semantic command string. Project the
|
|
131
|
+
// transcript fact to the live shape; for wrapper argv the semantic command is
|
|
132
|
+
// the final argument in the Codex fixture contract.
|
|
133
|
+
const liveShapeCommand = Array.isArray(rawCommand) && rawCommand.every((part) => typeof part === 'string')
|
|
134
|
+
? rawCommand[rawCommand.length - 1]
|
|
135
|
+
: rawCommand;
|
|
127
136
|
outcomes.push({
|
|
128
137
|
toolUseId: observation.toolUseId,
|
|
138
|
+
...(observation.hostTurnId !== undefined ? { hostTurnId: observation.hostTurnId } : {}),
|
|
129
139
|
toolName,
|
|
130
|
-
params:
|
|
140
|
+
params: liveShapeCommand !== undefined ? { command: liveShapeCommand } : undefined,
|
|
131
141
|
exitCode,
|
|
132
142
|
...(previewParts.length > 0 ? { outputPreview: previewParts.join('\n') } : {}),
|
|
133
143
|
});
|
package/dist/pd-hook.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
6
6
|
import { appendEventLogLine, redactTelemetryString, isRuleHostEvaluatedEventData } from '@principles/core/runtime';
|
|
7
|
-
import { ADAPTIVE_SELECTION_LIMITS, createAdaptivePriorityProviderForConfig, createCodexRuleContextProvider, createProductionHostRuntime, environmentFactDigestOrNull, loadPdConfigForPlugin, renderAcceptedAdaptiveAppend, resolveHostToolSemanticsForHook, resolveNearestPdWorkspace } from '@principles/host-runtime';
|
|
7
|
+
import { ADAPTIVE_SELECTION_LIMITS, createAdaptivePriorityProviderForConfig, createCodexRuleContextProvider, createProductionHostRuntime, observeForwardTurnClose, environmentFactDigestOrNull, loadPdConfigForPlugin, renderAcceptedAdaptiveAppend, resolveHostToolSemanticsForHook, resolveNearestPdWorkspace, recordIdleAuditTurnCompleted } from '@principles/host-runtime';
|
|
8
8
|
import { resolvePdHome } from '@principles/install-layout';
|
|
9
9
|
import { classifyBashRisk } from '@principles/core/runtime/internalization/bash-risk';
|
|
10
10
|
import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from './tool-semantics.js';
|
|
@@ -429,6 +429,12 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
429
429
|
const adaptiveTiming = config.effective.config.adaptiveActivation?.timing === 'background' ? 'background' : 'sync';
|
|
430
430
|
const backgroundSelectionEnabled = flags['host.codex.adaptive_activation']?.enabled === true && adaptiveTiming === 'background';
|
|
431
431
|
if (event.kind === 'turn_complete') {
|
|
432
|
+
const closeWarnings = observeForwardTurnClose({
|
|
433
|
+
workspaceDir: resolution.workspaceDir,
|
|
434
|
+
hostKind: 'codex',
|
|
435
|
+
sessionId: event.context.sessionId,
|
|
436
|
+
...(event.context.turnId !== undefined ? { turnId: event.context.turnId } : {}),
|
|
437
|
+
}).map((warning) => diagnostic(warning, 'Inspect trajectory.db forward evidence; Stop ingestion and host output remain non-blocking.'));
|
|
432
438
|
// Withdraw the live turn context: once the turn completes, the
|
|
433
439
|
// agent-assisted explicit entry must fail closed (turn_context_missing)
|
|
434
440
|
// instead of binding an Owner statement to a finished turn. A withdrawal
|
|
@@ -449,8 +455,8 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
449
455
|
// turn on stderr — never stdout, and never on the per-tool events (that
|
|
450
456
|
// would be per-event noise).
|
|
451
457
|
const stderr = ingestionEnabled
|
|
452
|
-
? [...clearDiagnostics, ...await runConversationIngestion({ rawPayload: parsed, kind: event.kind, workspaceDir: resolution.workspaceDir, env: _env })]
|
|
453
|
-
: [...clearDiagnostics, diagnostic('feature_disabled', 'Enable bounded conversation ingestion in the selected Workspace .pd/config.yaml — in the existing "features:" block set codex_conversation_ingestion: {enabled: true} (one flat key, not nested).')];
|
|
458
|
+
? [...closeWarnings, ...clearDiagnostics, ...await runConversationIngestion({ rawPayload: parsed, kind: event.kind, workspaceDir: resolution.workspaceDir, env: _env })]
|
|
459
|
+
: [...closeWarnings, ...clearDiagnostics, diagnostic('feature_disabled', 'Enable bounded conversation ingestion in the selected Workspace .pd/config.yaml — in the existing "features:" block set codex_conversation_ingestion: {enabled: true} (one flat key, not nested).')];
|
|
454
460
|
// Clean up the background turn whenever THIS turn was tracked, even if the
|
|
455
461
|
// timing was switched back to `sync` mid-turn: the started marker outlives
|
|
456
462
|
// the setting, and leaving it behind would strand a late result (P1-2).
|
|
@@ -464,6 +470,15 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
464
470
|
if (hasAdaptiveAppendTurn(backgroundKey))
|
|
465
471
|
finalizeBackgroundTurn(backgroundKey);
|
|
466
472
|
}
|
|
473
|
+
if (ingestionEnabled) {
|
|
474
|
+
recordIdleAuditTurnCompleted({
|
|
475
|
+
workspaceDir: resolution.workspaceDir,
|
|
476
|
+
hostKind: 'codex',
|
|
477
|
+
sessionId: event.context.sessionId,
|
|
478
|
+
turnEndSource: 'stop_hook',
|
|
479
|
+
hasActiveRun: false,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
467
482
|
return { stdout: {}, exitCode: 0, stderr };
|
|
468
483
|
}
|
|
469
484
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TargetEvidenceReconcileReport } from '@principles/core/runtime';
|
|
2
|
-
import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult, type SignalLlmClassifier, type Stage2CorrectionCycleReport } from '@principles/host-runtime';
|
|
2
|
+
import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult, type SignalLlmClassifier, type Stage2CorrectionCycleReport, type RunIdleTurnAuditCycleReport, type IdleTurnAuditor } from '@principles/host-runtime';
|
|
3
3
|
import { type CodexCatchUpResult } from '../ingestion/catch-up.js';
|
|
4
4
|
import type { TranscriptPort } from '../ingestion/transcript-decoder.js';
|
|
5
5
|
export type CodexWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
|
|
@@ -47,6 +47,7 @@ export interface CodexWorkerCycleStepReport {
|
|
|
47
47
|
* the Diagnostician (bounded to ≤2 candidates / ≤60s aggregate).
|
|
48
48
|
*/
|
|
49
49
|
readonly stage2?: Stage2CorrectionCycleReport;
|
|
50
|
+
readonly idleAudit?: RunIdleTurnAuditCycleReport;
|
|
50
51
|
}
|
|
51
52
|
export interface CodexWorkerCycleResult {
|
|
52
53
|
readonly workspaceDir: string;
|
|
@@ -73,6 +74,8 @@ export interface CodexWorkerCycleOptions {
|
|
|
73
74
|
*/
|
|
74
75
|
readonly stage2Classifier?: SignalLlmClassifier | null;
|
|
75
76
|
readonly stage2AggregateBudgetMs?: number;
|
|
77
|
+
/** Test seam: undefined = production auditor resolution; null = explicitly unavailable. */
|
|
78
|
+
readonly idleTurnAuditor?: IdleTurnAuditor | null;
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* WHO drove this cycle (PRI-1264 attribution, Phase 2 extension). The
|
|
@@ -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, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, createConsentLedgerSourceMaterialAuthorization, resolveWorkspacePipelineHostDeps, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
|
|
31
|
+
import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, 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';
|
|
@@ -602,6 +602,24 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
602
602
|
...(options.now !== undefined ? { now: options.now } : {}),
|
|
603
603
|
onEvent: emitEvent,
|
|
604
604
|
});
|
|
605
|
+
// R5: one bounded idle-turn audit per worker cycle, after every
|
|
606
|
+
// higher-priority diagnosis/internalization step. Auditor unavailability is
|
|
607
|
+
// observable but does not degrade the whole worker cycle.
|
|
608
|
+
const idleResolution = options.idleTurnAuditor === undefined
|
|
609
|
+
? createIdleTurnAuditorForWorkspace(workspaceDir, {
|
|
610
|
+
log: (event, detail) => emitEvent(event, detail),
|
|
611
|
+
})
|
|
612
|
+
: null;
|
|
613
|
+
const idleAuditor = options.idleTurnAuditor !== undefined
|
|
614
|
+
? options.idleTurnAuditor
|
|
615
|
+
: (idleResolution?.ok === true ? idleResolution.auditor : null);
|
|
616
|
+
if (idleResolution !== null && !idleResolution.ok) {
|
|
617
|
+
emitEvent('IDLE_AUDIT_AUDITOR_UNAVAILABLE', JSON.stringify({ reason: idleResolution.reason, readiness: idleResolution.readiness }));
|
|
618
|
+
}
|
|
619
|
+
const idleAudit = await runIdleTurnAuditCycle({
|
|
620
|
+
workspaceDir,
|
|
621
|
+
auditor: idleAuditor,
|
|
622
|
+
});
|
|
605
623
|
// Aggregated mode: degraded overrides all (review P1). Any component
|
|
606
624
|
// degrading — catch-up, reconciliation, diagnostician or downstream —
|
|
607
625
|
// surfaces the workspace as degraded, with the highest-priority reason.
|
|
@@ -630,7 +648,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
630
648
|
...base,
|
|
631
649
|
mode: degradedReason !== undefined ? 'degraded' : 'ready',
|
|
632
650
|
...(degradedReason !== undefined ? { reason: degradedReason, nextAction: 'Inspect the Workspace .pd/config.yaml runtime profile and the per-step report above; the worker retries automatically on the next cycle.' } : {}),
|
|
633
|
-
report: { catchUp, reconcile, postProcessing, diagnostician, downstream, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}), stage2 },
|
|
651
|
+
report: { catchUp, reconcile, postProcessing, diagnostician, downstream, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}), stage2, idleAudit },
|
|
634
652
|
};
|
|
635
653
|
}
|
|
636
654
|
// Slice D (PRI-625): the mode authority moved to host-runtime so the CLI and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/codex-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
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": "^
|
|
37
|
-
"@principles/host-runtime": "^4.
|
|
36
|
+
"@principles/core": "^9.1.0",
|
|
37
|
+
"@principles/host-runtime": "^4.12.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": "
|
|
55
|
+
"gitHead": "e14270ad721ec3a3352d629bb8254be81842cc38"
|
|
56
56
|
}
|