@principles/codex-adapter 0.5.12 → 0.5.14

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.
@@ -145,6 +145,7 @@ export async function runGovernanceAdmission(args) {
145
145
  workspaceDir,
146
146
  logicalObservationKey: outcome.logicalObservationKey,
147
147
  canonicalPainId: outcome.canonicalPainId,
148
+ conversationIngestionEnabled: true,
148
149
  });
149
150
  if (!cont.ok) {
150
151
  push(cont.reason, cont.nextAction);
@@ -18,9 +18,21 @@ export type RecordOwnerStatementResult = {
18
18
  };
19
19
  /**
20
20
  * Persist one explicit Owner statement. The consent-gated conversation
21
- * ingestion flag does NOT gate this path (no conversation tables or transcript
22
- * CONTENT are read — only the path is validated for the rollout identity),
23
- * mirroring SPEC §6.4 rule 3.
21
+ * ingestion flag does NOT gate the REGISTRATION (no conversation tables or
22
+ * transcript CONTENT are read — only the path is validated for the rollout
23
+ * identity), mirroring SPEC §6.4 rule 3. It DOES gate evidence promotion:
24
+ *
25
+ * - `conversationIngestionEnabled: true` — the caller MUST have run the
26
+ * live observation ingestion for this same hook payload BEFORE calling
27
+ * this function: promotion requires the trigger observation
28
+ * (`codex|<rollout>|<turn>|user`) to already be persisted, otherwise the
29
+ * FIRST submission of a rollout degrades with rollout_not_found /
30
+ * trigger_not_found (the observation used to be written only by the
31
+ * ingestion pass that ran after the explicit registration).
32
+ * - `conversationIngestionEnabled: false` — no session observation exists
33
+ * and none may be written (privacy boundary), so promotion is SKIPPED
34
+ * and disclosed as `conversation_ingestion_disabled` instead of
35
+ * attempting it and misreporting a missing substrate.
24
36
  */
25
37
  export declare function recordExplicitOwnerStatement(args: {
26
38
  rawPayload: unknown;
@@ -29,4 +41,5 @@ export declare function recordExplicitOwnerStatement(args: {
29
41
  env?: {
30
42
  CODEX_HOME?: string | undefined;
31
43
  };
44
+ conversationIngestionEnabled: boolean;
32
45
  }): Promise<RecordOwnerStatementResult>;
@@ -26,9 +26,21 @@ import { extractFields } from './ingestion-fields.js';
26
26
  export { OWNER_STATEMENT_PREFIX as CODEX_OWNER_STATEMENT_PREFIX, MAX_OWNER_STATEMENT_CHARS, parseOwnerStatementPrefix } from '@principles/host-runtime';
27
27
  /**
28
28
  * Persist one explicit Owner statement. The consent-gated conversation
29
- * ingestion flag does NOT gate this path (no conversation tables or transcript
30
- * CONTENT are read — only the path is validated for the rollout identity),
31
- * mirroring SPEC §6.4 rule 3.
29
+ * ingestion flag does NOT gate the REGISTRATION (no conversation tables or
30
+ * transcript CONTENT are read — only the path is validated for the rollout
31
+ * identity), mirroring SPEC §6.4 rule 3. It DOES gate evidence promotion:
32
+ *
33
+ * - `conversationIngestionEnabled: true` — the caller MUST have run the
34
+ * live observation ingestion for this same hook payload BEFORE calling
35
+ * this function: promotion requires the trigger observation
36
+ * (`codex|<rollout>|<turn>|user`) to already be persisted, otherwise the
37
+ * FIRST submission of a rollout degrades with rollout_not_found /
38
+ * trigger_not_found (the observation used to be written only by the
39
+ * ingestion pass that ran after the explicit registration).
40
+ * - `conversationIngestionEnabled: false` — no session observation exists
41
+ * and none may be written (privacy boundary), so promotion is SKIPPED
42
+ * and disclosed as `conversation_ingestion_disabled` instead of
43
+ * attempting it and misreporting a missing substrate.
32
44
  */
33
45
  export async function recordExplicitOwnerStatement(args) {
34
46
  const fields = extractFields(args.rawPayload);
@@ -71,9 +83,33 @@ export async function recordExplicitOwnerStatement(args) {
71
83
  if (outcome.disposition === 'rate_limited') {
72
84
  return { status: 'rejected', reason: 'rate_limited', nextAction: 'The per-root-session correction quota (5/hour) is exhausted; resubmit later — the statement was NOT recorded.' };
73
85
  }
74
- // Task ensure is the receipt's hard guarantee; evidence promotion is
75
- // best-effort (SPEC §6.4.5 — a degraded promotion is disclosed, never a
76
- // failed receipt: the pain + task are durably recorded).
86
+ // Promotion runs BEFORE the task enqueue (deliberate): the durable task is
87
+ // the receipt's hard guarantee, and promoting first closes the window in
88
+ // which the background worker could start the first diagnosis before the
89
+ // already-available evidence window is promoted. Both steps are
90
+ // independently idempotent and recovered by reconcileGovernanceContinuation
91
+ // (Case A: task missing → created later; Case C: promotion missing →
92
+ // retried once the trigger observation arrives).
93
+ let promotionDegraded;
94
+ if (args.conversationIngestionEnabled) {
95
+ const promoted = promoteAdmittedGovernanceEvidence({
96
+ workspaceDir: args.workspaceDir,
97
+ rolloutIdentity: validated.rolloutIdentity,
98
+ triggerLogicalKey: candidate.logicalObservationKey,
99
+ canonicalPainId: outcome.canonicalPainId,
100
+ });
101
+ if (!promoted.ok) {
102
+ promotionDegraded = `${promoted.reason}`.slice(0, 160);
103
+ }
104
+ }
105
+ else {
106
+ // Ingestion is consent-gated OFF: no session observation was (or may be)
107
+ // written, so promotion is skipped by design, never attempted-and-failed.
108
+ promotionDegraded = 'conversation_ingestion_disabled';
109
+ }
110
+ // Task ensure is the receipt's hard guarantee (SPEC §6.4.5 — a degraded
111
+ // promotion is disclosed, never a failed receipt: the pain + task are
112
+ // durably recorded).
77
113
  const ensured = await ensureGovernanceDiagnosticianTask({
78
114
  workspaceDir: args.workspaceDir,
79
115
  logicalObservationKey: candidate.logicalObservationKey,
@@ -82,16 +118,6 @@ export async function recordExplicitOwnerStatement(args) {
82
118
  if (!ensured.ok) {
83
119
  return { status: 'rejected', reason: 'continuation_failed', nextAction: `${ensured.reason}: ${ensured.nextAction}`.slice(0, 400) };
84
120
  }
85
- let promotionDegraded;
86
- const promoted = promoteAdmittedGovernanceEvidence({
87
- workspaceDir: args.workspaceDir,
88
- rolloutIdentity: validated.rolloutIdentity,
89
- triggerLogicalKey: candidate.logicalObservationKey,
90
- canonicalPainId: outcome.canonicalPainId,
91
- });
92
- if (!promoted.ok) {
93
- promotionDegraded = `${promoted.reason}`.slice(0, 160);
94
- }
95
121
  return {
96
122
  status: 'received',
97
123
  painId: outcome.canonicalPainId,
package/dist/pd-hook.js CHANGED
@@ -267,39 +267,32 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
267
267
  return { stdout: adapter.encodeOutput({ decision: 'allow', source: event.source }, 'session_start'), exitCode: 0, stderr: [] };
268
268
  }
269
269
  // SPEC-CODEX-PAIN-CLOSURE-001 CR-07: the explicit Owner statement entry
270
- // runs FIRST for the current user prompt — before the generic correction
271
- // detection, so the same turn can never pass through two pain writers
272
- // (the shared unique observation key dedups any replay). Works regardless
273
- // of the codex_conversation_ingestion flag: only the transcript PATH is
274
- // validated (rollout identity), never conversation content.
270
+ // owns the current user prompt. The prefix parse runs FIRST (pure, zero
271
+ // I/O) so the single-writer suppression strategy is decided BEFORE any
272
+ // ingestion or admission runs — then, when the prefix matched, the live
273
+ // observation ingestion for this SAME payload runs BEFORE the explicit
274
+ // registration, because the registration's evidence promotion requires
275
+ // the trigger observation to already be persisted. Registering first and
276
+ // ingesting afterwards made every FIRST submission of a rollout degrade
277
+ // with rollout_not_found/trigger_not_found (the trigger row only appeared
278
+ // in the later ingestion pass). Works regardless of the
279
+ // codex_conversation_ingestion flag: flag-off skips the ingestion call
280
+ // entirely, and the registration discloses promotion as skipped
281
+ // (conversation_ingestion_disabled) instead of misreporting a missing
282
+ // substrate; only the transcript PATH is ever validated (rollout
283
+ // identity), never conversation content.
275
284
  let explicitReceiptContext;
276
- let explicitSuppressedGeneric = false;
277
285
  const explicitDiagnostics = [];
286
+ let explicitPrefixMatched = false;
287
+ let explicitStatementText = null;
288
+ let explicitRejectReason;
278
289
  if (event.kind === 'before_prompt_build') {
279
290
  const rawRecord = parsed;
280
291
  const prefixParse = parseOwnerStatementPrefix(typeof rawRecord?.prompt === 'string' ? rawRecord.prompt : undefined);
292
+ explicitPrefixMatched = prefixParse.matched;
281
293
  if (prefixParse.matched) {
282
- explicitSuppressedGeneric = true;
283
- if (prefixParse.text === null) {
284
- explicitDiagnostics.push(diagnostic(`owner_statement_${prefixParse.reason ?? 'rejected'}`, prefixParse.reason === 'statement_too_long'
285
- ? `The statement exceeds 500 characters; nothing was recorded. Resubmit within the limit.`
286
- : 'The prefix carried no statement text; nothing was recorded. Resubmit as PD记录痛苦:<反馈原文>.'));
287
- }
288
- else {
289
- const receipt = await recordExplicitOwnerStatement({
290
- rawPayload: parsed,
291
- workspaceDir: resolution.workspaceDir,
292
- statementText: prefixParse.text,
293
- env: _env,
294
- });
295
- if (receipt.status === 'received') {
296
- explicitReceiptContext = `[PD] 已收到痛苦反馈(painId=${receipt.painId}, taskId=${receipt.taskId}${receipt.disposition === 'already_admitted' ? ', 重复提交已合并为同一信号' : ''})。后台将自动诊断;请在回复中如实转述本回执,不要声称仍在等待用户输入,也不要虚构诊断结论。${receipt.promotionDegraded !== undefined ? `(注意:会话证据提升暂不可用:${receipt.promotionDegraded};诊断仍会基于你提交的陈述进行。)` : ''}`;
297
- explicitDiagnostics.push(diagnostic(`owner_statement_received:${receipt.painId}:${receipt.taskId}${receipt.promotionDegraded !== undefined ? `:promotion_degraded:${receipt.promotionDegraded}` : ''}`, 'Durable enqueue complete; the workspace worker continues diagnosis in the background.'));
298
- }
299
- else {
300
- explicitDiagnostics.push(diagnostic(`owner_statement_${receipt.reason}`, receipt.nextAction));
301
- }
302
- }
294
+ explicitStatementText = prefixParse.text;
295
+ explicitRejectReason = prefixParse.reason;
303
296
  }
304
297
  }
305
298
  const ingestionDiagnostics = ingestionEnabled
@@ -309,12 +302,40 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
309
302
  workspaceDir: resolution.workspaceDir,
310
303
  projectDir: requestedCwd,
311
304
  env: _env,
312
- // CR-07: the explicit path already handled this turn's user prompt —
313
- // suppress the generic correction candidate so exactly one writer
314
- // processed the observation (A17).
315
- ...(explicitSuppressedGeneric && event.kind === 'before_prompt_build' ? { suppressCorrectionCandidate: true } : {}),
305
+ // CR-07: the prefix parse above already decided this turn's user
306
+ // prompt belongs to the explicit path — suppress the generic
307
+ // correction candidate so exactly one writer processes the
308
+ // observation (A17), and the trigger observation is in place before
309
+ // the explicit registration promotes evidence around it.
310
+ ...(explicitPrefixMatched ? { suppressCorrectionCandidate: true } : {}),
316
311
  })
317
312
  : [];
313
+ if (explicitPrefixMatched) {
314
+ if (explicitStatementText === null) {
315
+ explicitDiagnostics.push(diagnostic(`owner_statement_${explicitRejectReason ?? 'rejected'}`, explicitRejectReason === 'statement_too_long'
316
+ ? `The statement exceeds 500 characters; nothing was recorded. Resubmit within the limit.`
317
+ : 'The prefix carried no statement text; nothing was recorded. Resubmit as PD记录痛苦:<反馈原文>.'));
318
+ }
319
+ else {
320
+ const receipt = await recordExplicitOwnerStatement({
321
+ rawPayload: parsed,
322
+ workspaceDir: resolution.workspaceDir,
323
+ statementText: explicitStatementText,
324
+ env: _env,
325
+ conversationIngestionEnabled: ingestionEnabled,
326
+ });
327
+ if (receipt.status === 'received') {
328
+ const promotionNotice = receipt.promotionDegraded === 'conversation_ingestion_disabled'
329
+ ? '会话证据提升已跳过:会话摄取未启用(按隐私边界未读取会话内容,也未写入会话观察)'
330
+ : `会话证据提升暂不可用:${receipt.promotionDegraded}`;
331
+ explicitReceiptContext = `[PD] 已收到痛苦反馈(painId=${receipt.painId}, taskId=${receipt.taskId}${receipt.disposition === 'already_admitted' ? ', 重复提交已合并为同一信号' : ''})。后台将自动诊断;请在回复中如实转述本回执,不要声称仍在等待用户输入,也不要虚构诊断结论。${receipt.promotionDegraded !== undefined ? `(注意:${promotionNotice};诊断仍会基于你提交的陈述进行。)` : ''}`;
332
+ explicitDiagnostics.push(diagnostic(`owner_statement_received:${receipt.painId}:${receipt.taskId}${receipt.promotionDegraded !== undefined ? `:promotion_degraded:${receipt.promotionDegraded}` : ''}`, 'Durable enqueue complete; the workspace worker continues diagnosis in the background.'));
333
+ }
334
+ else {
335
+ explicitDiagnostics.push(diagnostic(`owner_statement_${receipt.reason}`, receipt.nextAction));
336
+ }
337
+ }
338
+ }
318
339
  // PD v2 Phase 1: evidence context for this subprocess invocation. The
319
340
  // ledger flag follows the OpenClaw convention (principle_receipt_ledger
320
341
  // gates normalized evidence writes).
@@ -407,7 +428,7 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
407
428
  evidenceDiagnostics.push(diagnostic(`codex_evidence_deny_failed:${errorMessage(error)}`, 'The deny decision was already encoded; evidence replay from the durable source is safe.'));
408
429
  }
409
430
  }
410
- const stderr = [...(result.warnings ?? []).slice(0, 16).map((warning) => diagnostic(warning, 'Inspect PD Workspace state and retry; the hook failed open.')), ...evaluationDiagnostics, ...evidenceDiagnostics, ...explicitDiagnostics, ...ingestionDiagnostics];
431
+ const stderr = [...(result.warnings ?? []).slice(0, 16).map((warning) => diagnostic(warning, 'Inspect PD Workspace state and retry; the hook failed open.')), ...evaluationDiagnostics, ...evidenceDiagnostics, ...ingestionDiagnostics, ...explicitDiagnostics];
411
432
  return { stdout: encoded, exitCode: 0, stderr };
412
433
  }
413
434
  catch (error) {
@@ -205,7 +205,10 @@ export async function runCodexWorkspaceWorkerCycle(options) {
205
205
  port: options.port,
206
206
  });
207
207
  // Step 3 — Slice B idempotent reconciliation (always runs; creates no LLM work).
208
- const reconcile = await reconcileGovernanceContinuation({ workspaceDir });
208
+ const reconcile = await reconcileGovernanceContinuation({
209
+ workspaceDir,
210
+ conversationIngestionEnabled: flags.codex_conversation_ingestion?.enabled === true,
211
+ });
209
212
  // Steps 4–6 — execution authority: internalization_auto_consumer.
210
213
  let diagnostician = null;
211
214
  if (diagnosticianDisabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/codex-adapter",
3
- "version": "0.5.12",
3
+ "version": "0.5.14",
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",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@principles/core": "^1.296.0",
37
- "@principles/host-runtime": "^0.13.0",
37
+ "@principles/host-runtime": "^0.13.5",
38
38
  "@principles/install-layout": "^0.4.0"
39
39
  },
40
40
  "devDependencies": {