@principles/codex-adapter 0.6.3 → 0.8.0
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/dist/ingestion/admission.d.ts +5 -10
- package/dist/ingestion/admission.js +19 -77
- package/dist/ingestion/explicit-owner-statement.d.ts +6 -0
- package/dist/ingestion/explicit-owner-statement.js +7 -1
- package/dist/ingestion/ingestion.d.ts +0 -2
- package/dist/ingestion/ingestion.js +6 -4
- package/dist/pd-hook.js +10 -9
- package/dist/worker/workspace-worker.d.ts +13 -1
- package/dist/worker/workspace-worker.js +26 -3
- package/package.json +5 -4
|
@@ -29,17 +29,12 @@ export declare function buildLiveCorrectionCandidate(args: {
|
|
|
29
29
|
fields: PayloadFields;
|
|
30
30
|
rolloutIdentity: string;
|
|
31
31
|
}): GovernanceSignalCandidate | null;
|
|
32
|
-
/** Live PostToolUse payload → tool-failure candidate (logical key mirrors the observation). */
|
|
33
|
-
export declare function buildLiveToolCandidate(args: {
|
|
34
|
-
fields: PayloadFields;
|
|
35
|
-
rolloutIdentity: string;
|
|
36
|
-
projectDir?: string;
|
|
37
|
-
}): GovernanceSignalCandidate | null;
|
|
38
32
|
/**
|
|
39
|
-
* Decoded transcript observations → candidates.
|
|
40
|
-
* tool
|
|
41
|
-
* the
|
|
42
|
-
*
|
|
33
|
+
* Decoded transcript observations → candidates. Only user turns produce
|
|
34
|
+
* candidates: tool-call observations remain technical trajectory (recorded by
|
|
35
|
+
* the workflow's own writers), never a behavioral-deviation Pain by themselves.
|
|
36
|
+
* The logical keys are the decoded ones, so a replay of an already-admitted
|
|
37
|
+
* live event is an observation-level no-op (SPEC §10).
|
|
43
38
|
*/
|
|
44
39
|
export declare function buildTranscriptCandidates(observations: readonly GovernanceObservationInput[]): readonly GovernanceSignalCandidate[];
|
|
45
40
|
/**
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
* authority exists here.
|
|
15
15
|
*/
|
|
16
16
|
import { admitGovernanceSignals, ensureGovernanceContinuation, } from '@principles/host-runtime';
|
|
17
|
-
import { isRecord, own } from './ingestion-fields.js';
|
|
18
|
-
/** The live host-event source used by the identity derivation (parity with the dispatch handler). */
|
|
19
|
-
const CODEX_POST_TOOL_USE_SOURCE = 'codex:post_tool_use';
|
|
20
17
|
/** Live UserPromptSubmit payload → correction candidate (logical key mirrors the observation). */
|
|
21
18
|
export function buildLiveCorrectionCandidate(args) {
|
|
22
19
|
const { fields } = args;
|
|
@@ -33,85 +30,30 @@ export function buildLiveCorrectionCandidate(args) {
|
|
|
33
30
|
observedAt: new Date().toISOString(),
|
|
34
31
|
};
|
|
35
32
|
}
|
|
36
|
-
/** Live PostToolUse payload → tool-failure candidate (logical key mirrors the observation). */
|
|
37
|
-
export function buildLiveToolCandidate(args) {
|
|
38
|
-
const { fields } = args;
|
|
39
|
-
if (fields.turnId === null || fields.toolUseId === null)
|
|
40
|
-
return null;
|
|
41
|
-
return {
|
|
42
|
-
kind: 'tool_failure',
|
|
43
|
-
hostKind: 'codex',
|
|
44
|
-
logicalObservationKey: `codex|${args.rolloutIdentity}|${fields.toolUseId}`,
|
|
45
|
-
rolloutIdentity: args.rolloutIdentity,
|
|
46
|
-
rootSessionId: fields.sessionId,
|
|
47
|
-
hostTurnId: fields.turnId,
|
|
48
|
-
toolName: fields.toolName ?? '',
|
|
49
|
-
source: CODEX_POST_TOOL_USE_SOURCE,
|
|
50
|
-
// Merge semantics (WorkBuddy × SPEC-CODEX-PAIN-CLOSURE-001): the same host
|
|
51
|
-
// `tool_use_id` feeds TWO consumers, so the candidate carries both views.
|
|
52
|
-
// I1 identity parity — the live handler derives the canonical pain from the
|
|
53
|
-
// same tool_use_id, so `toolCallId` must be present (one real call → one
|
|
54
|
-
// canonical pain across the admission + dispatch deliveries).
|
|
55
|
-
toolCallId: fields.toolUseId,
|
|
56
|
-
// CR-01 — `toolUseId` is recorded into tool_calls.tool_use_id and used for
|
|
57
|
-
// the admission dedup join against the live PostToolUse row.
|
|
58
|
-
toolUseId: fields.toolUseId,
|
|
59
|
-
...(args.projectDir !== undefined ? { projectDir: args.projectDir } : {}),
|
|
60
|
-
...(fields.toolInput !== undefined ? { toolInput: fields.toolInput } : {}),
|
|
61
|
-
...(fields.toolResponse !== undefined ? { toolOutput: fields.toolResponse } : {}),
|
|
62
|
-
observedAt: new Date().toISOString(),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
33
|
/**
|
|
66
|
-
* Decoded transcript observations → candidates.
|
|
67
|
-
* tool
|
|
68
|
-
* the
|
|
69
|
-
*
|
|
34
|
+
* Decoded transcript observations → candidates. Only user turns produce
|
|
35
|
+
* candidates: tool-call observations remain technical trajectory (recorded by
|
|
36
|
+
* the workflow's own writers), never a behavioral-deviation Pain by themselves.
|
|
37
|
+
* The logical keys are the decoded ones, so a replay of an already-admitted
|
|
38
|
+
* live event is an observation-level no-op (SPEC §10).
|
|
70
39
|
*/
|
|
71
40
|
export function buildTranscriptCandidates(observations) {
|
|
72
41
|
const candidates = [];
|
|
73
42
|
for (const observation of observations) {
|
|
74
|
-
if (observation.kind
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else if (observation.kind === 'tool_call') {
|
|
89
|
-
const facts = observation.toolFacts;
|
|
90
|
-
if (!isRecord(facts))
|
|
91
|
-
continue;
|
|
92
|
-
const toolName = own(facts, 'toolName');
|
|
93
|
-
const exitCode = own(facts, 'exitCode');
|
|
94
|
-
candidates.push({
|
|
95
|
-
kind: 'tool_failure',
|
|
96
|
-
hostKind: 'codex',
|
|
97
|
-
logicalObservationKey: observation.logicalObservationKey,
|
|
98
|
-
rolloutIdentity: observation.rolloutIdentity,
|
|
99
|
-
rootSessionId: observation.rootSessionId,
|
|
100
|
-
hostTurnId: observation.hostTurnId,
|
|
101
|
-
toolName: typeof toolName === 'string' ? toolName : '',
|
|
102
|
-
source: CODEX_POST_TOOL_USE_SOURCE,
|
|
103
|
-
// Merge semantics: both merged views of the same host tool_use_id.
|
|
104
|
-
// I1 identity parity — the decoded observation carries the same
|
|
105
|
-
// tool_use_id the live delivery derived its canonical pain from, so a
|
|
106
|
-
// transcript replay converges on that pain instead of a second one.
|
|
107
|
-
...(typeof observation.toolUseId === 'string' && observation.toolUseId.length > 0 ? { toolCallId: observation.toolUseId } : {}),
|
|
108
|
-
// CR-01 — recorded into tool_calls.tool_use_id for the dedup join.
|
|
109
|
-
...(observation.toolUseId !== undefined ? { toolUseId: observation.toolUseId } : {}),
|
|
110
|
-
toolInput: own(facts, 'command') ?? null,
|
|
111
|
-
...(exitCode !== undefined ? { toolOutput: { exitCode, stdout: own(facts, 'stdout') ?? null, stderr: own(facts, 'stderr') ?? null } } : {}),
|
|
112
|
-
observedAt: observation.observedAt,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
43
|
+
if (observation.kind !== 'user_turn')
|
|
44
|
+
continue;
|
|
45
|
+
if (observation.visibleText === undefined)
|
|
46
|
+
continue;
|
|
47
|
+
candidates.push({
|
|
48
|
+
kind: 'user_correction',
|
|
49
|
+
hostKind: 'codex',
|
|
50
|
+
logicalObservationKey: observation.logicalObservationKey,
|
|
51
|
+
rolloutIdentity: observation.rolloutIdentity,
|
|
52
|
+
rootSessionId: observation.rootSessionId,
|
|
53
|
+
hostTurnId: observation.hostTurnId,
|
|
54
|
+
text: observation.visibleText,
|
|
55
|
+
observedAt: observation.observedAt,
|
|
56
|
+
});
|
|
115
57
|
}
|
|
116
58
|
return candidates;
|
|
117
59
|
}
|
|
@@ -11,6 +11,12 @@ export type RecordOwnerStatementResult = {
|
|
|
11
11
|
* rollout to promote from). The receipt discloses it instead of failing.
|
|
12
12
|
*/
|
|
13
13
|
promotionDegraded?: string;
|
|
14
|
+
/**
|
|
15
|
+
* PainIngress warning when the Owner statement legitimately degraded
|
|
16
|
+
* (e.g. ingestion OFF → no persisted observation to use as behavior
|
|
17
|
+
* evidence). The Pain + task still exist; the receipt discloses the basis.
|
|
18
|
+
*/
|
|
19
|
+
ingressWarning?: string;
|
|
14
20
|
} | {
|
|
15
21
|
status: 'rejected';
|
|
16
22
|
reason: 'statement_empty' | 'statement_too_long' | 'transcript_unavailable' | 'lineage_invalid' | 'rate_limited' | 'continuation_failed';
|
|
@@ -78,12 +78,17 @@ export async function recordExplicitOwnerStatement(args) {
|
|
|
78
78
|
if (outcome === undefined || !('disposition' in outcome)) {
|
|
79
79
|
return { status: 'rejected', reason: 'continuation_failed', nextAction: 'The governance admission returned no disposition; nothing was recorded.' };
|
|
80
80
|
}
|
|
81
|
-
if (outcome.disposition === 'not_a_signal'
|
|
81
|
+
if (outcome.disposition === 'not_a_signal') {
|
|
82
82
|
return { status: 'rejected', reason: 'continuation_failed', nextAction: 'reason' in outcome ? String(outcome.reason) : 'the signal was not admitted' };
|
|
83
83
|
}
|
|
84
84
|
if (outcome.disposition === 'rate_limited') {
|
|
85
85
|
return { status: 'rejected', reason: 'rate_limited', nextAction: 'The per-root-session correction quota (5/hour) is exhausted; resubmit later — the statement was NOT recorded.' };
|
|
86
86
|
}
|
|
87
|
+
if (outcome.disposition !== 'admitted' && outcome.disposition !== 'already_admitted') {
|
|
88
|
+
// An explicit Owner statement bypasses keyword detection entirely, so it
|
|
89
|
+
// can never legitimately land in the Stage-2 review state machine.
|
|
90
|
+
return { status: 'rejected', reason: 'continuation_failed', nextAction: `unexpected admission disposition for an explicit statement: ${outcome.disposition}` };
|
|
91
|
+
}
|
|
87
92
|
// Promotion runs BEFORE the task enqueue (deliberate): the durable task is
|
|
88
93
|
// the receipt's hard guarantee, and promoting first closes the window in
|
|
89
94
|
// which the background worker could start the first diagnosis before the
|
|
@@ -126,5 +131,6 @@ export async function recordExplicitOwnerStatement(args) {
|
|
|
126
131
|
disposition: outcome.disposition === 'already_admitted' ? 'already_admitted' : 'admitted',
|
|
127
132
|
logicalObservationKey: candidate.logicalObservationKey,
|
|
128
133
|
...(promotionDegraded !== undefined ? { promotionDegraded } : {}),
|
|
134
|
+
...(ensured.ingressWarning !== undefined ? { ingressWarning: ensured.ingressWarning } : {}),
|
|
129
135
|
};
|
|
130
136
|
}
|
|
@@ -23,8 +23,6 @@ import { type GovernanceSignalCandidate } from '@principles/host-runtime';
|
|
|
23
23
|
import { type TranscriptPort } from './transcript-decoder.js';
|
|
24
24
|
export interface CodexIngestionOptions {
|
|
25
25
|
readonly workspaceDir: string;
|
|
26
|
-
/** Native live-hook cwd; intentionally omitted for transcript catch-up. */
|
|
27
|
-
readonly projectDir?: string;
|
|
28
26
|
readonly env?: {
|
|
29
27
|
CODEX_HOME?: string | undefined;
|
|
30
28
|
};
|
|
@@ -4,7 +4,7 @@ import { validateCodexTranscriptPath } from './transcript-path.js';
|
|
|
4
4
|
import { classifyCodexVersion, CODEX_VERSION_NEXT_ACTION } from './codex-version.js';
|
|
5
5
|
import { decodeTranscriptWindow, createNodeTranscriptPort, CODEX_INGESTION_MAX_BATCH_BYTES, TranscriptReplacedError } from './transcript-decoder.js';
|
|
6
6
|
import { extractFields } from './ingestion-fields.js';
|
|
7
|
-
import { buildLiveCorrectionCandidate,
|
|
7
|
+
import { buildLiveCorrectionCandidate, buildTranscriptCandidates } from './admission.js';
|
|
8
8
|
let activePort = null;
|
|
9
9
|
/** Test seam: inject/inspect the transcript filesystem boundary (zero-read proofs). */
|
|
10
10
|
export function setCodexTranscriptPortForTest(port) {
|
|
@@ -13,7 +13,7 @@ export function setCodexTranscriptPortForTest(port) {
|
|
|
13
13
|
function activeTranscriptPort(options) {
|
|
14
14
|
return options.port ?? activePort ?? createNodeTranscriptPort();
|
|
15
15
|
}
|
|
16
|
-
function ingestLiveObservation({ fields, rolloutIdentity, workspaceDir,
|
|
16
|
+
function ingestLiveObservation({ fields, rolloutIdentity, workspaceDir, now }) {
|
|
17
17
|
const nowIso = now.toISOString();
|
|
18
18
|
let observation = null;
|
|
19
19
|
if (fields.turnId !== null && fields.prompt !== null) {
|
|
@@ -61,9 +61,11 @@ function ingestLiveObservation({ fields, rolloutIdentity, workspaceDir, projectD
|
|
|
61
61
|
return { status: 'degraded', reason: result.reason ?? 'governance_write_failed', nextAction: result.nextAction ?? 'inspect the workspace trajectory database.', warnings: result.warnings };
|
|
62
62
|
// Slice B: hand the live observation to the admission pass as a normalized
|
|
63
63
|
// candidate (SPEC §12) — the caller (pd-hook) runs detection/admission.
|
|
64
|
+
// Phase A: tool-call observations stay technical trajectory only; they never
|
|
65
|
+
// become a behavioral-deviation Pain candidate by themselves.
|
|
64
66
|
const candidate = observation.kind === 'user_turn'
|
|
65
67
|
? buildLiveCorrectionCandidate({ fields, rolloutIdentity })
|
|
66
|
-
:
|
|
68
|
+
: null;
|
|
67
69
|
return {
|
|
68
70
|
status: 'ok', inserted: result.inserted, enriched: result.enriched, duplicates: result.duplicates, warnings: result.warnings, lagBytes: 0,
|
|
69
71
|
admissionCandidates: candidate !== null ? [candidate] : [],
|
|
@@ -258,7 +260,7 @@ export function ingestCodexConversation(rawPayload, kind, options) {
|
|
|
258
260
|
return { status: 'degraded', reason: validated.reason, nextAction: validated.nextAction, warnings: [] };
|
|
259
261
|
const now = options.now ?? new Date();
|
|
260
262
|
if (kind === 'before_prompt_build' || kind === 'after_tool_call') {
|
|
261
|
-
return ingestLiveObservation({ fields, rolloutIdentity: validated.rolloutIdentity, workspaceDir: options.workspaceDir,
|
|
263
|
+
return ingestLiveObservation({ fields, rolloutIdentity: validated.rolloutIdentity, workspaceDir: options.workspaceDir, now });
|
|
262
264
|
}
|
|
263
265
|
return ingestTranscriptDelta({
|
|
264
266
|
fallbackRootSessionId: fields.sessionId,
|
package/dist/pd-hook.js
CHANGED
|
@@ -151,17 +151,16 @@ function recordRuleHostEvaluations(stateDir, sessionId, evaluations) {
|
|
|
151
151
|
// Runs only when BOTH host.codex and codex_conversation_ingestion are
|
|
152
152
|
// enabled — the flag gate below happens BEFORE any transcript path
|
|
153
153
|
// validation or filesystem I/O, so flag-off means the transcript boundary
|
|
154
|
-
// receives zero calls (SPEC §10 hard privacy invariant). Admission
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
// then converges to a no-op (exactly one pain per real tool call).
|
|
154
|
+
// receives zero calls (SPEC §10 hard privacy invariant). Admission covers
|
|
155
|
+
// Owner corrections only: tool-call facts stay technical trajectory and never
|
|
156
|
+
// become a behavioral-deviation Pain by themselves (Phase A).
|
|
158
157
|
async function runConversationIngestion(args) {
|
|
159
|
-
const { rawPayload, kind, workspaceDir,
|
|
158
|
+
const { rawPayload, kind, workspaceDir, env } = args;
|
|
160
159
|
if (kind !== 'turn_complete' && kind !== 'before_prompt_build' && kind !== 'after_tool_call')
|
|
161
160
|
return [];
|
|
162
161
|
const diagnostics = [];
|
|
163
162
|
try {
|
|
164
|
-
const outcome = ingestCodexConversation(rawPayload, kind, { workspaceDir,
|
|
163
|
+
const outcome = ingestCodexConversation(rawPayload, kind, { workspaceDir, env });
|
|
165
164
|
if (outcome.status === 'degraded') {
|
|
166
165
|
diagnostics.push(diagnostic(outcome.reason, outcome.nextAction));
|
|
167
166
|
}
|
|
@@ -334,7 +333,6 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
334
333
|
rawPayload: parsed,
|
|
335
334
|
kind: event.kind,
|
|
336
335
|
workspaceDir: resolution.workspaceDir,
|
|
337
|
-
projectDir: requestedCwd,
|
|
338
336
|
env: _env,
|
|
339
337
|
// CR-07: the prefix parse above already decided this turn's user
|
|
340
338
|
// prompt belongs to the explicit path — suppress the generic
|
|
@@ -362,8 +360,11 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
362
360
|
const promotionNotice = receipt.promotionDegraded === 'conversation_ingestion_disabled'
|
|
363
361
|
? '会话证据提升已跳过:会话摄取未启用(按隐私边界未读取会话内容,也未写入会话观察)'
|
|
364
362
|
: `会话证据提升暂不可用:${receipt.promotionDegraded}`;
|
|
365
|
-
|
|
366
|
-
|
|
363
|
+
const ingressNotice = receipt.ingressWarning !== undefined
|
|
364
|
+
? `行为证据缺失,已按 Owner 陈述降级准入:${receipt.ingressWarning}`
|
|
365
|
+
: undefined;
|
|
366
|
+
explicitReceiptContext = `[PD] 已收到痛苦反馈(painId=${receipt.painId}, taskId=${receipt.taskId}${receipt.disposition === 'already_admitted' ? ', 重复提交已合并为同一信号' : ''})。后台将自动诊断;请在回复中如实转述本回执,不要声称仍在等待用户输入,也不要虚构诊断结论。${receipt.promotionDegraded !== undefined ? `(注意:${promotionNotice};诊断仍会基于你提交的陈述进行。)` : ''}${ingressNotice !== undefined ? `(注意:${ingressNotice};诊断仍会基于你提交的陈述进行。)` : ''}`;
|
|
367
|
+
explicitDiagnostics.push(diagnostic(`owner_statement_received:${receipt.painId}:${receipt.taskId}${receipt.promotionDegraded !== undefined ? `:promotion_degraded:${receipt.promotionDegraded}` : ''}${receipt.ingressWarning !== undefined ? `:ingress_degraded:${receipt.ingressWarning}` : ''}`, 'Durable enqueue complete; the workspace worker continues diagnosis in the background.'));
|
|
367
368
|
}
|
|
368
369
|
else {
|
|
369
370
|
explicitDiagnostics.push(diagnostic(`owner_statement_${receipt.reason}`, receipt.nextAction));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult } from '@principles/host-runtime';
|
|
1
|
+
import { type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult, type SignalLlmClassifier, type Stage2CorrectionCycleReport } from '@principles/host-runtime';
|
|
2
2
|
import { type CodexCatchUpResult } from '../ingestion/catch-up.js';
|
|
3
3
|
import type { TranscriptPort } from '../ingestion/transcript-decoder.js';
|
|
4
4
|
export type CodexWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
|
|
@@ -34,6 +34,11 @@ export interface CodexWorkerCycleStepReport {
|
|
|
34
34
|
readonly reuseReviewRequiredCandidateIds?: readonly string[];
|
|
35
35
|
} | null;
|
|
36
36
|
readonly downstream: InternalizationConsumerCycleOutcome | null;
|
|
37
|
+
/**
|
|
38
|
+
* Phase B Stage-2 review step. Always the LAST step so it can never starve
|
|
39
|
+
* the Diagnostician (bounded to ≤2 candidates / ≤60s aggregate).
|
|
40
|
+
*/
|
|
41
|
+
readonly stage2?: Stage2CorrectionCycleReport;
|
|
37
42
|
}
|
|
38
43
|
export interface CodexWorkerCycleResult {
|
|
39
44
|
readonly workspaceDir: string;
|
|
@@ -53,6 +58,13 @@ export interface CodexWorkerCycleOptions {
|
|
|
53
58
|
readonly port?: TranscriptPort;
|
|
54
59
|
/** Cap on diagnostician candidates inspected per cycle (default 5). */
|
|
55
60
|
readonly diagnosticianCandidateLimit?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Stage-2 classifier injection (tests). `undefined` = resolve the
|
|
63
|
+
* signalCollector profile from the workspace config; `null` = explicitly
|
|
64
|
+
* unavailable (candidates with a durable review result still settle).
|
|
65
|
+
*/
|
|
66
|
+
readonly stage2Classifier?: SignalLlmClassifier | null;
|
|
67
|
+
readonly stage2AggregateBudgetMs?: number;
|
|
56
68
|
}
|
|
57
69
|
export declare function readCodexWorkerLiveness(workspaceDir: string): Record<string, unknown> | null;
|
|
58
70
|
/**
|
|
@@ -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, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime-v2';
|
|
31
|
-
import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, saveHostToolDeclaration, } from '@principles/host-runtime';
|
|
31
|
+
import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, saveHostToolDeclaration, } from '@principles/host-runtime';
|
|
32
32
|
import { catchUpCodexIngestion } from '../ingestion/catch-up.js';
|
|
33
33
|
import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from '../tool-semantics.js';
|
|
34
34
|
const WORKER_OWNER = 'companion-worker';
|
|
@@ -419,6 +419,28 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
419
419
|
// No hostToolCatalog: PD has not declared a Codex tool catalog; a wrong
|
|
420
420
|
// (OpenClaw) catalog would be worse than none (PRI-630 follow-up).
|
|
421
421
|
});
|
|
422
|
+
// Step 8 (SPEC v0.3.1 §2) — bounded Stage-2 correction review, ALWAYS last:
|
|
423
|
+
// the Diagnostician has already run, so this step cannot starve it. ≤2
|
|
424
|
+
// candidates, ≤60s aggregate, single 60s classification timeout.
|
|
425
|
+
const stage2Resolution = options.stage2Classifier === undefined
|
|
426
|
+
? createSignalClassifierForWorkspace(workspaceDir)
|
|
427
|
+
: null;
|
|
428
|
+
const stage2Classifier = options.stage2Classifier !== undefined
|
|
429
|
+
? options.stage2Classifier
|
|
430
|
+
: (stage2Resolution?.ok === true ? stage2Resolution.classifier : null);
|
|
431
|
+
const stage2ClassifierState = options.stage2Classifier === null
|
|
432
|
+
? 'disabled'
|
|
433
|
+
: stage2Classifier === null
|
|
434
|
+
? (stage2Resolution !== null && !stage2Resolution.ok && stage2Resolution.readiness === 'disabled' ? 'disabled' : 'unavailable')
|
|
435
|
+
: 'used';
|
|
436
|
+
const stage2 = await runStage2CorrectionCycle({
|
|
437
|
+
workspaceDir,
|
|
438
|
+
classifier: stage2Classifier,
|
|
439
|
+
classifierState: stage2ClassifierState,
|
|
440
|
+
...(options.stage2AggregateBudgetMs !== undefined ? { aggregateBudgetMs: options.stage2AggregateBudgetMs } : {}),
|
|
441
|
+
...(options.now !== undefined ? { now: options.now } : {}),
|
|
442
|
+
onEvent: emitEvent,
|
|
443
|
+
});
|
|
422
444
|
// Aggregated mode: degraded overrides all (review P1). Any component
|
|
423
445
|
// degrading — catch-up, reconciliation, diagnostician or downstream —
|
|
424
446
|
// surfaces the workspace as degraded, with the highest-priority reason.
|
|
@@ -429,7 +451,8 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
429
451
|
: diagnostician?.status === 'failed' && diagnostician.errorCategory !== 'lease_conflict' ? `diagnostician_failed:${diagnostician.message ?? 'max_attempts_exceeded'}`
|
|
430
452
|
: diagnostician?.status === 'degraded' ? `diagnostician_degraded:${diagnostician.message ?? 'unknown'}`
|
|
431
453
|
: downstream.skipReason === 'runtime_config_error' || downstream.skipReason === 'cycle_error' || downstream.skipReason === 'config_malformed' ? `downstream:${downstream.skipReason}`
|
|
432
|
-
:
|
|
454
|
+
: !stage2.ok ? `stage2:${stage2.reason ?? 'failed'}`
|
|
455
|
+
: undefined;
|
|
433
456
|
writeLiveness(workspaceDir, {
|
|
434
457
|
runningStage: null,
|
|
435
458
|
stageDeadline: null,
|
|
@@ -442,7 +465,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
442
465
|
...base,
|
|
443
466
|
mode: degradedReason !== undefined ? 'degraded' : 'ready',
|
|
444
467
|
...(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.' } : {}),
|
|
445
|
-
report: { catchUp, reconcile, postProcessing, diagnostician, downstream },
|
|
468
|
+
report: { catchUp, reconcile, postProcessing, diagnostician, downstream, stage2 },
|
|
446
469
|
};
|
|
447
470
|
}
|
|
448
471
|
// 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.8.0",
|
|
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": "^0.
|
|
36
|
+
"@principles/core": "^3.0.0",
|
|
37
|
+
"@principles/host-runtime": "^1.0.0",
|
|
38
38
|
"@principles/install-layout": "^0.4.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
@@ -51,5 +51,6 @@
|
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
|
+
"gitHead": "94d353a428b6fc27dd41ff63b767bf915b9ed147"
|
|
55
56
|
}
|