@principles/codex-adapter 0.8.11 → 0.8.12

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.
@@ -87,6 +87,8 @@ export async function runGovernanceAdmission(args) {
87
87
  workspaceDir,
88
88
  logicalObservationKey: outcome.logicalObservationKey,
89
89
  canonicalPainId: outcome.canonicalPainId,
90
+ codexConversationIngestionEnabled: true,
91
+ // Legacy alias: an older installed host-runtime reads only this name.
90
92
  conversationIngestionEnabled: true,
91
93
  });
92
94
  if (!cont.ok) {
package/dist/pd-hook.d.ts CHANGED
@@ -23,19 +23,21 @@ export declare const CODEX_HOOK_TIMEOUT_MS = 5000;
23
23
  /** Reserved for Native packing, encoding and stdout after Adaptive is cut off. */
24
24
  export declare const CODEX_NATIVE_RESERVE_MS = 800;
25
25
  export declare const CODEX_ADAPTIVE_BUDGET_MS: number;
26
+ /** Maximum from sending a scoring request to validating its full response. */
27
+ export declare const CODEX_ADAPTIVE_DECISION_MS: 2000;
26
28
  export interface PdHookDeps {
27
29
  /** Test seam: replace the outbound transport without bypassing the hook entry. */
28
30
  readonly fetchImpl?: typeof fetch;
29
31
  readonly now?: () => number;
30
- readonly firstByteTimeoutMs?: number;
31
- readonly generationTimeoutMs?: number;
32
+ readonly requestTimeoutMs?: number;
32
33
  /** Test seam: effective adaptive budget inside the host hook window. */
33
34
  readonly hookBudgetMs?: number;
34
35
  /**
35
- * PRI-1181: remaining-budget floor for the pre-selection skip gate. Defaults
36
- * to the measured minimum; 0 keeps a cancellation scenario sending.
36
+ * PRI-1182: remaining-budget floor for the pre-selection skip gate. Defaults
37
+ * to the request's minimum executable envelope; 0 keeps a cancellation
38
+ * scenario sending.
37
39
  */
38
- readonly minRemainingBudgetMs?: number;
40
+ readonly minExecutableBudgetMs?: number;
39
41
  }
40
42
  export declare function processHookInvocation(rawStdin: string, _env?: EnvMap, cwd?: string, deps?: PdHookDeps): Promise<PdHookResult>;
41
43
  export {};
package/dist/pd-hook.js CHANGED
@@ -5,7 +5,7 @@ import path from 'node:path';
5
5
  import process from 'node:process';
6
6
  import { pathToFileURL, fileURLToPath } from 'node:url';
7
7
  import { appendEventLogLine, redactTelemetryString, isRuleHostEvaluatedEventData } from '@principles/core/runtime';
8
- import { createAdaptivePriorityProviderForConfig, createCodexRuleContextProvider, createProductionHostRuntime, loadPdConfigForPlugin, resolveHostToolSemanticsForHook, resolveNearestPdWorkspace } from '@principles/host-runtime';
8
+ import { ADAPTIVE_SELECTION_LIMITS, createAdaptivePriorityProviderForConfig, createCodexRuleContextProvider, createProductionHostRuntime, loadPdConfigForPlugin, resolveHostToolSemanticsForHook, resolveNearestPdWorkspace } from '@principles/host-runtime';
9
9
  import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from './tool-semantics.js';
10
10
  import { computeFeatureFlagsFromConfig } from '@principles/core/runtime';
11
11
  import { CodexHooksHostAdapter } from './host-adapter.js';
@@ -38,7 +38,15 @@ function adaptiveSelectionDiagnostic(line) {
38
38
  ? 'skipped'
39
39
  : 'degraded';
40
40
  const failures = line.failures.length > 0 ? line.failures.join('|') : 'none';
41
- return `[PD] status=${status} reason=adaptive_selection_${line.status}:${line.reason} stage=${line.stage} sends=${line.sends} firstByteAt=${line.firstByteAt ?? 'unknown'} generationEndedAt=${line.generationEndedAt ?? 'unknown'} cancelledAt=${line.cancelledAt ?? 'unknown'} httpStatus=${line.httpStatus ?? 'unknown'} finishReason=${line.finishReason} failures=${failures}`
41
+ // rc-8: bounded score projection — ids are `c1..cN` / `insufficient_context`,
42
+ // never prompt text, and at most 16 entries reach the line.
43
+ const scores = line.decision === null
44
+ ? 'none'
45
+ : Object.entries(line.decision.scores).slice(0, 16).map(([id, value]) => `${id}=${value}`).join(',');
46
+ const decision = line.decision === null
47
+ ? 'unknown'
48
+ : `${line.decision.status}:${line.decision.reason}:${line.decision.ref ?? 'none'}`;
49
+ return `[PD] status=${status} reason=adaptive_selection_${line.status}:${line.reason} stage=${line.stage} sends=${line.sends} requestSentAt=${line.requestSentAt ?? 'unknown'} firstByteAt=${line.firstByteAt ?? 'unknown'} generationEndedAt=${line.generationEndedAt ?? 'unknown'} validatedAt=${line.validatedAt ?? 'unknown'} cancelledAt=${line.cancelledAt ?? 'unknown'} httpStatus=${line.httpStatus ?? 'unknown'} finishReason=${line.finishReason} modelObserved=${line.modelObserved ?? 'unknown'} providerObserved=${line.providerObserved ?? 'absent'} decision=${decision} scores=${scores} failures=${failures}`
42
50
  .replace(/\s+/g, ' ')
43
51
  .trim()
44
52
  .slice(0, MAX_DIAGNOSTIC * 2);
@@ -222,6 +230,8 @@ export const CODEX_HOOK_TIMEOUT_MS = 5_000;
222
230
  /** Reserved for Native packing, encoding and stdout after Adaptive is cut off. */
223
231
  export const CODEX_NATIVE_RESERVE_MS = 800;
224
232
  export const CODEX_ADAPTIVE_BUDGET_MS = CODEX_HOOK_TIMEOUT_MS - CODEX_NATIVE_RESERVE_MS;
233
+ /** Maximum from sending a scoring request to validating its full response. */
234
+ export const CODEX_ADAPTIVE_DECISION_MS = ADAPTIVE_SELECTION_LIMITS.requestTimeoutMs;
225
235
  // stdin, env and cwd are the host CLI contract; `deps` is the optional transport
226
236
  // seam that lets integration tests drive the real entry point without a network.
227
237
  // eslint-disable-next-line @typescript-eslint/max-params
@@ -431,9 +441,8 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
431
441
  env: _env,
432
442
  ...(deps.fetchImpl ? { fetchImpl: deps.fetchImpl } : {}),
433
443
  ...(deps.now ? { now: deps.now } : {}),
434
- ...(deps.firstByteTimeoutMs !== undefined ? { firstByteTimeoutMs: deps.firstByteTimeoutMs } : {}),
435
- ...(deps.generationTimeoutMs !== undefined ? { generationTimeoutMs: deps.generationTimeoutMs } : {}),
436
- ...(deps.minRemainingBudgetMs !== undefined ? { minRemainingBudgetMs: deps.minRemainingBudgetMs } : {}),
444
+ requestTimeoutMs: deps.requestTimeoutMs ?? CODEX_ADAPTIVE_DECISION_MS,
445
+ ...(deps.minExecutableBudgetMs !== undefined ? { minExecutableBudgetMs: deps.minExecutableBudgetMs } : {}),
437
446
  outerDeadlineAt: adaptiveDeadlineAt,
438
447
  onDiagnostic: (line) => { adaptiveDiagnostics.push(adaptiveSelectionDiagnostic(line)); },
439
448
  });
@@ -458,13 +467,15 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
458
467
  ? toolSemanticsResolution.registry
459
468
  : CODEX_TOOL_SEMANTICS;
460
469
  const toolSemanticsDiagnostics = toolSemanticsResolution.ok
461
- ? []
470
+ // ADR-0030: a legacy persisted declaration still loads (degraded to
471
+ // defaults) and must be visible on stderr (rc-9).
472
+ ? toolSemanticsResolution.warnings.map((warning) => diagnostic(warning, 're-run this host so it refreshes its persisted tool declaration'))
462
473
  : [diagnostic(toolSemanticsResolution.reason, toolSemanticsResolution.nextAction)];
463
474
  const result = await createProductionHostRuntime({
464
475
  projectDir: requestedCwd,
465
476
  hostKind: 'codex',
466
477
  toolSemantics,
467
- ...(adaptivePriorityProvider ? { adaptivePriorityProvider } : {}),
478
+ ...(adaptivePriorityProvider ? { adaptiveGapProvider: adaptivePriorityProvider } : {}),
468
479
  ruleContextProvider: createCodexRuleContextProvider({
469
480
  workspaceDir: resolution.workspaceDir,
470
481
  projectDir: requestedCwd,
@@ -21,7 +21,11 @@
21
21
  import { buildToolSemanticRegistry } from '@principles/core/runtime';
22
22
  export const CODEX_TOOL_SEMANTIC_MAPPINGS = Object.freeze([
23
23
  { rawToolName: 'Bash', canonicalKind: 'execute' },
24
- { rawToolName: 'apply_patch', canonicalKind: 'write' },
24
+ // ADR-0030: apply_patch writes a `*** Begin Patch` envelope. The design gate
25
+ // must parse those file headers to know the target paths, and that encoding
26
+ // is not expressible via canonicalKind — declare it instead of matching the
27
+ // raw name downstream.
28
+ { rawToolName: 'apply_patch', canonicalKind: 'write', writePayloadFormat: 'file-header-patch' },
25
29
  ]);
26
30
  const built = buildToolSemanticRegistry(CODEX_TOOL_SEMANTIC_MAPPINGS);
27
31
  if (!built.ok) {
@@ -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, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime';
31
- import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, saveHostToolDeclaration, } from '@principles/host-runtime';
31
+ import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } 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';
@@ -179,6 +179,8 @@ export async function runCodexWorkspaceWorkerCycle(options) {
179
179
  // Step 3 — Slice B idempotent reconciliation (always runs; creates no LLM work).
180
180
  const reconcile = await reconcileGovernanceContinuation({
181
181
  workspaceDir,
182
+ codexConversationIngestionEnabled: flags.codex_conversation_ingestion?.enabled === true,
183
+ // Legacy alias for an older installed host-runtime (P2 review).
182
184
  conversationIngestionEnabled: flags.codex_conversation_ingestion?.enabled === true,
183
185
  });
184
186
  // Steps 4–6 — execution authority: internalization_auto_consumer.
@@ -355,7 +357,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
355
357
  // for host-neutral consumers) and thread the registry into the cycle so
356
358
  // activation-gate replay resolves Codex tool semantics (Bash, not bash).
357
359
  const declared = saveHostToolDeclaration(workspaceDir, {
358
- version: 1,
360
+ version: HOST_TOOL_DECLARATION_VERSION,
359
361
  hostKind: 'codex',
360
362
  mappings: CODEX_TOOL_SEMANTIC_MAPPINGS,
361
363
  declaredAt: new Date().toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/codex-adapter",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
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,9 +33,9 @@
33
33
  "lint": "eslint \"src/**/*.ts\""
34
34
  },
35
35
  "dependencies": {
36
- "@principles/core": "^7.3.2",
37
- "@principles/host-runtime": "^3.4.0",
38
- "@principles/install-layout": "^0.7.0"
36
+ "@principles/core": "^7.4.0",
37
+ "@principles/host-runtime": "^3.5.0",
38
+ "@principles/install-layout": "^0.8.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^26.6.6",
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "3d6e2af3cf55ad63b7bb388c005adf4b923eb383"
55
+ "gitHead": "5c7389e72a6409efb00891327a63dfc01a2009cb"
56
56
  }