@principles/codex-adapter 0.8.12 → 0.10.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.
@@ -3,23 +3,25 @@
3
3
  * Slice A; ADR-0020 §11.2 + G1 probe report §9).
4
4
  *
5
5
  * The G1 contract baseline is: minimum supported Codex 0.148.0, verified
6
- * on-device at 0.150.1 and re-verified at 0.162.1 (PRI-953, 2026-10-13:
7
- * on-device probe against real codex-cli 0.162.1 — 125/125 captured hook
8
- * payloads decode, 8/8 real rollout transcripts ingest with only designed
9
- * unknown-record-type skips; sanitized fixtures:
10
- * tests/fixtures/g1-contract/hook-payloads/v0.162.1/ and
11
- * transcripts/v0.162.1-tool-final-turn.jsonl). The transcript itself carries
12
- * `session_meta.payload.cli_version`, which is the version signal available
13
- * inside a hook subprocess (hook payloads carry no version field — G1
14
- * fixture contract).
6
+ * on-device at 0.150.1, re-verified at 0.162.1 (PRI-953, 2026-10-13), and
7
+ * re-verified again at 0.167.0-alpha.4.1 (2026-11-13): the installed adapter
8
+ * decoded a real 4.4 MB rollout transcript (48 observations, including
9
+ * assistant turns) and a real Stop payload from that device, and the
10
+ * sanitized capture is pinned as
11
+ * tests/fixtures/g1-contract/transcripts/v0.167.0-alpha.4.1-tool-final-turn.jsonl.
12
+ * The transcript itself carries `session_meta.payload.cli_version`, which is
13
+ * the version signal available inside a hook subprocess (hook payloads carry
14
+ * no version field — G1 fixture contract).
15
15
  *
16
- * Older-than-minimum and newer-than-verified versions both degrade
17
- * explicitly; an unknown version must never silently guess record fields.
16
+ * Version comparison is on the core `MAJOR.MINOR.PATCH` triplet only:
17
+ * prerelease/build suffixes describe a distribution channel, not a different
18
+ * record contract, and the contract itself is pinned by the fixture probe.
19
+ * An unknown or malformed version must never silently guess record fields.
18
20
  * Adopting a newer Codex version requires re-running the contract probe and
19
21
  * refreshing the fixtures (G1 report §9 drift-detection boundary).
20
22
  */
21
23
  export declare const CODEX_INGESTION_MIN_VERSION = "0.148.0";
22
- export declare const CODEX_INGESTION_VERIFIED_VERSION = "0.162.1";
24
+ export declare const CODEX_INGESTION_VERIFIED_VERSION = "0.167.0";
23
25
  export type CodexVersionClassification = {
24
26
  status: 'supported';
25
27
  } | {
@@ -3,36 +3,35 @@
3
3
  * Slice A; ADR-0020 §11.2 + G1 probe report §9).
4
4
  *
5
5
  * The G1 contract baseline is: minimum supported Codex 0.148.0, verified
6
- * on-device at 0.150.1 and re-verified at 0.162.1 (PRI-953, 2026-10-13:
7
- * on-device probe against real codex-cli 0.162.1 — 125/125 captured hook
8
- * payloads decode, 8/8 real rollout transcripts ingest with only designed
9
- * unknown-record-type skips; sanitized fixtures:
10
- * tests/fixtures/g1-contract/hook-payloads/v0.162.1/ and
11
- * transcripts/v0.162.1-tool-final-turn.jsonl). The transcript itself carries
12
- * `session_meta.payload.cli_version`, which is the version signal available
13
- * inside a hook subprocess (hook payloads carry no version field — G1
14
- * fixture contract).
6
+ * on-device at 0.150.1, re-verified at 0.162.1 (PRI-953, 2026-10-13), and
7
+ * re-verified again at 0.167.0-alpha.4.1 (2026-11-13): the installed adapter
8
+ * decoded a real 4.4 MB rollout transcript (48 observations, including
9
+ * assistant turns) and a real Stop payload from that device, and the
10
+ * sanitized capture is pinned as
11
+ * tests/fixtures/g1-contract/transcripts/v0.167.0-alpha.4.1-tool-final-turn.jsonl.
12
+ * The transcript itself carries `session_meta.payload.cli_version`, which is
13
+ * the version signal available inside a hook subprocess (hook payloads carry
14
+ * no version field — G1 fixture contract).
15
15
  *
16
- * Older-than-minimum and newer-than-verified versions both degrade
17
- * explicitly; an unknown version must never silently guess record fields.
16
+ * Version comparison is on the core `MAJOR.MINOR.PATCH` triplet only:
17
+ * prerelease/build suffixes describe a distribution channel, not a different
18
+ * record contract, and the contract itself is pinned by the fixture probe.
19
+ * An unknown or malformed version must never silently guess record fields.
18
20
  * Adopting a newer Codex version requires re-running the contract probe and
19
21
  * refreshing the fixtures (G1 report §9 drift-detection boundary).
20
22
  */
21
23
  export const CODEX_INGESTION_MIN_VERSION = '0.148.0';
22
- export const CODEX_INGESTION_VERIFIED_VERSION = '0.162.1';
24
+ export const CODEX_INGESTION_VERIFIED_VERSION = '0.167.0';
23
25
  export const CODEX_VERSION_NEXT_ACTION = 'rerun the Codex contract probe / update supported fixtures (docs/architecture/CODEX_G1_CONTRACT_PROBE_REPORT.md §9)';
24
- function isDigits(value) {
25
- return value.length > 0 && /^[0-9]+$/.test(value);
26
- }
26
+ /** `1.2.3`, optional `-prerelease` / `+build`; anything else is not a version signal we trust. */
27
+ const SEMVER_PATTERN = /^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
27
28
  function parseSemver(value) {
28
- const parts = value.trim().split('.');
29
- if (parts.length < 3)
29
+ const match = SEMVER_PATTERN.exec(value.trim());
30
+ if (match === null)
30
31
  return null;
31
- const [major, minor, patch] = parts;
32
+ const [, major, minor, patch] = match;
32
33
  if (major === undefined || minor === undefined || patch === undefined)
33
34
  return null;
34
- if (!isDigits(major) || !isDigits(minor) || !isDigits(patch))
35
- return null;
36
35
  return { major: Number(major), minor: Number(minor), patch: Number(patch) };
37
36
  }
38
37
  function compareSemver(a, b) {
@@ -1,4 +1,4 @@
1
- import { ingestGovernanceObservations, recordVerifiedToolOutcomes, runConversationIngestion, } from '@principles/host-runtime';
1
+ import { CODEX_INGESTION_DISCLOSURE_VERSION, ingestGovernanceObservations, readConversationIngestionConsent, recordVerifiedToolOutcomes, resolveTextPolicy, runConversationIngestion, } from '@principles/host-runtime';
2
2
  import { createNodeTranscriptPort } from './transcript-decoder.js';
3
3
  import { createCodexTranscriptSource } from './transcript-source.js';
4
4
  import { resolveCodexHome } from './codex-home.js';
@@ -13,6 +13,19 @@ export function setCodexTranscriptPortForTest(port) {
13
13
  function activeTranscriptPort(options) {
14
14
  return options.port ?? activePort ?? createNodeTranscriptPort();
15
15
  }
16
+ /**
17
+ * PRI-1179: the consent-tiered `visible_text` bound for Codex. The full tier is
18
+ * reachable ONLY from a record that is `granted` against the CURRENT frozen
19
+ * disclosure (`CODEX_INGESTION_DISCLOSURE_VERSION`); an absent, unreadable,
20
+ * revoked or older-disclosure record resolves to the bounded tier. An
21
+ * unreadable ledger resolves narrow on purpose — the health surface reports the
22
+ * malformed record loudly, and no content is lost by staying bounded.
23
+ */
24
+ function resolveCodexTextPolicy(workspaceDir) {
25
+ const read = readConversationIngestionConsent(workspaceDir, 'codex');
26
+ const record = read.ok ? read.record : null;
27
+ return resolveTextPolicy({ decision: record?.decision ?? 'not_present', disclosureVersion: record?.disclosureVersion ?? null }, CODEX_INGESTION_DISCLOSURE_VERSION);
28
+ }
16
29
  function ingestLiveObservation({ fields, rolloutIdentity, workspaceDir, now }) {
17
30
  const nowIso = now.toISOString();
18
31
  let observation = null;
@@ -54,6 +67,11 @@ function ingestLiveObservation({ fields, rolloutIdentity, workspaceDir, now }) {
54
67
  }
55
68
  const result = ingestGovernanceObservations({
56
69
  workspaceDir,
70
+ // PRI-1179 P1: the LIVE path must apply the same consent-tiered bound as
71
+ // the transcript replay. A narrower live bound stores a truncated
72
+ // user_turn, and the replay then sees a content mismatch on the same
73
+ // logical key — a lineage conflict that stalls the checkpoint forever.
74
+ maxVisibleTextChars: resolveCodexTextPolicy(workspaceDir).maxChars,
57
75
  observations: [observation],
58
76
  now,
59
77
  });
@@ -147,11 +165,14 @@ function ingestTranscriptDelta({ fallbackRootSessionId, transcriptPath, workspac
147
165
  // codex_conversation_ingestion) is checked by pd-hook / catch-up BEFORE
148
166
  // this module is entered, and the consent LEDGER remains the governance
149
167
  // record the setup flow enforces (v2 authority model — the runtime gate
150
- // reads only the flags). The pipeline's consent gate therefore receives
151
- // the setup-flow invariant 'granted' until the P3 full-text batch wires
152
- // the real v3 record + disclosureVersion tier.
168
+ // reads only the flags). The pipeline's consent gate therefore keeps
169
+ // receiving the setup-flow invariant 'granted'.
153
170
  flags: { ingestionEnabled: true },
154
171
  consent: { decision: 'granted' },
172
+ // PRI-1179: the STORED TEXT bound is a separate fact from the gate above —
173
+ // it comes from the recorded v3 consent record, so a stale disclosure or a
174
+ // revoke can only ever narrow what is stored, never widen it.
175
+ textPolicy: resolveCodexTextPolicy(workspaceDir),
155
176
  now,
156
177
  port,
157
178
  degradeTexts: CODEX_PIPELINE_DEGRADE_TEXTS,
@@ -10,9 +10,11 @@
10
10
  * execution facts anchored on the `event_msg item_completed
11
11
  * CommandExecution` record whose `item.id` IS the hook `tool_use_id` id
12
12
  * space (the G1-verified bridge; the model-level `call_id` is a different
13
- * space). Hidden reasoning, system/developer prompts, world_state,
14
- * host-injected context, and unknown record bodies are identified by shape
15
- * and dropped before persistence — never projected, logged, or emitted.
13
+ * space). Hidden reasoning BODIES (encrypted_content) are never read — only the
14
+ * optional plaintext `summary` is projected as a `reasoning` observation
15
+ * (PRI-1179). System/developer prompts, world_state, host-injected context,
16
+ * and unknown record bodies are identified by shape and dropped before
17
+ * persistence — never projected, logged, or emitted.
16
18
  *
17
19
  * Failure classes are distinct (SPEC §14): an incomplete final line (no
18
20
  * trailing newline at EOF) is a transient append/flush boundary — the
@@ -10,9 +10,11 @@
10
10
  * execution facts anchored on the `event_msg item_completed
11
11
  * CommandExecution` record whose `item.id` IS the hook `tool_use_id` id
12
12
  * space (the G1-verified bridge; the model-level `call_id` is a different
13
- * space). Hidden reasoning, system/developer prompts, world_state,
14
- * host-injected context, and unknown record bodies are identified by shape
15
- * and dropped before persistence — never projected, logged, or emitted.
13
+ * space). Hidden reasoning BODIES (encrypted_content) are never read — only the
14
+ * optional plaintext `summary` is projected as a `reasoning` observation
15
+ * (PRI-1179). System/developer prompts, world_state, host-injected context,
16
+ * and unknown record bodies are identified by shape and dropped before
17
+ * persistence — never projected, logged, or emitted.
16
18
  *
17
19
  * Failure classes are distinct (SPEC §14): an incomplete final line (no
18
20
  * trailing newline at EOF) is a transient append/flush boundary — the
@@ -123,6 +125,28 @@ function joinItemText(item) {
123
125
  }
124
126
  return parts.length > 0 ? parts.join('') : null;
125
127
  }
128
+ /**
129
+ * PRI-1179: the storable face of a Codex reasoning record. The rollout stores
130
+ * the reasoning body encrypted (`encrypted_content`, never read) and an
131
+ * optional `summary: [{ type: 'summary_text', text }]`. Only that summary text
132
+ * is evidence; no summary means nothing is stored (not a degradation).
133
+ */
134
+ function joinReasoningSummary(payload) {
135
+ const summary = own(payload, 'summary');
136
+ if (!Array.isArray(summary))
137
+ return null;
138
+ const parts = [];
139
+ for (const entry of summary) {
140
+ if (!isRecord(entry))
141
+ continue;
142
+ if (own(entry, 'type') !== 'summary_text')
143
+ continue;
144
+ const text = own(entry, 'text');
145
+ if (typeof text === 'string' && text.trim().length > 0)
146
+ parts.push(text);
147
+ }
148
+ return parts.length > 0 ? parts.join('\n') : null;
149
+ }
126
150
  function observationBase(context, turnId) {
127
151
  return {
128
152
  hostKind: 'codex',
@@ -156,8 +180,33 @@ function projectRecord(context, record) {
156
180
  }
157
181
  if (type === 'response_item') {
158
182
  const payloadType = own(payload, 'type');
159
- if (payloadType === 'reasoning')
160
- return; // hidden/encrypted reasoning — never projected
183
+ if (payloadType === 'reasoning') {
184
+ // PRI-1179: the rollout carries the hidden reasoning ONLY as
185
+ // `encrypted_content` plus an OPTIONAL plaintext `summary` array. The
186
+ // encrypted blob is never read; the summary is the one storable face.
187
+ const summaryText = joinReasoningSummary(payload);
188
+ if (summaryText === null)
189
+ return; // no summary → nothing to store
190
+ const itemId = own(payload, 'id');
191
+ const turnId = metadataTurnId(payload) ?? context.currentTurnId;
192
+ if (turnId === null || typeof itemId !== 'string' || itemId.length === 0) {
193
+ warnBounded(context, `observation_skipped_missing_identity:${ordinal}`);
194
+ return;
195
+ }
196
+ context.observations.push({
197
+ ...observationBase(context, turnId),
198
+ kind: 'reasoning',
199
+ logicalObservationKey: `codex|${context.rolloutIdentity}|${turnId}|reasoning:${itemId}`,
200
+ transcriptRecordKey: `codex|${context.rolloutIdentity}|${ordinal}`,
201
+ recordOrdinal: ordinal,
202
+ recordByteStart,
203
+ visibleText: summaryText,
204
+ source: 'transcript',
205
+ completeness: 'complete',
206
+ observedAt,
207
+ });
208
+ return;
209
+ }
161
210
  if (payloadType === 'custom_tool_call' || payloadType === 'function_call') {
162
211
  const turnId = metadataTurnId(payload);
163
212
  const callId = own(payload, 'call_id');
@@ -205,6 +254,12 @@ function projectRecord(context, record) {
205
254
  }
206
255
  if (type === 'event_msg') {
207
256
  const payloadType = own(payload, 'type');
257
+ // PRI-1179: turn identity for records that cannot carry their own (the
258
+ // reasoning response_item). Transcript order makes the latest event-level
259
+ // turn the enclosing one.
260
+ const eventTurnId = own(payload, 'turn_id');
261
+ if (typeof eventTurnId === 'string' && eventTurnId.length > 0)
262
+ context.currentTurnId = eventTurnId;
208
263
  if (payloadType === 'item_completed') {
209
264
  const item = own(payload, 'item');
210
265
  if (!isRecord(item))
@@ -367,6 +422,7 @@ export function decodeTranscriptWindow(input) {
367
422
  observations: [],
368
423
  meta: { rootSessionId: null, cliVersion: null, parentRolloutIdentity: null, agentIdentity: null, agentDepth: null },
369
424
  modelCallsByTurn: new Map(),
425
+ currentTurnId: null,
370
426
  compactionTimestamp: null,
371
427
  rollbackTurns: [],
372
428
  warnings: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/codex-adapter",
3
- "version": "0.8.12",
3
+ "version": "0.10.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": "^7.4.0",
37
- "@principles/host-runtime": "^3.5.0",
36
+ "@principles/core": "^7.6.0",
37
+ "@principles/host-runtime": "^4.1.0",
38
38
  "@principles/install-layout": "^0.8.0"
39
39
  },
40
40
  "devDependencies": {
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "5c7389e72a6409efb00891327a63dfc01a2009cb"
55
+ "gitHead": "d70d277260da6f9ef2fcbecb622501cea504a12c"
56
56
  }