@principles/codex-adapter 0.2.2 → 0.2.4
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/pd-hook.js +2 -1
- package/dist/tool-semantics.d.ts +20 -0
- package/dist/tool-semantics.js +27 -0
- package/dist/worker/workspace-worker.js +15 -1
- package/package.json +1 -1
package/dist/pd-hook.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs';
|
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { createProductionHostRuntime, loadPdConfigForPlugin, resolveNearestPdWorkspace } from '@principles/host-runtime';
|
|
6
|
+
import { CODEX_TOOL_SEMANTICS } from './tool-semantics.js';
|
|
6
7
|
import { computeFeatureFlagsFromConfig } from '@principles/core/runtime-v2';
|
|
7
8
|
import { CodexHooksHostAdapter } from './host-adapter.js';
|
|
8
9
|
import { CodexDecoderError, CodexEncoderError } from './codec/index.js';
|
|
@@ -117,7 +118,7 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
117
118
|
const ingestionDiagnostics = ingestionEnabled
|
|
118
119
|
? await runConversationIngestion({ rawPayload: parsed, kind: event.kind, workspaceDir: resolution.workspaceDir, env: _env })
|
|
119
120
|
: [];
|
|
120
|
-
const result = await createProductionHostRuntime({ hostKind: 'codex' }).dispatch(event);
|
|
121
|
+
const result = await createProductionHostRuntime({ hostKind: 'codex', toolSemantics: CODEX_TOOL_SEMANTICS }).dispatch(event);
|
|
121
122
|
const stderr = [...(result.warnings ?? []).slice(0, 16).map((warning) => diagnostic(warning, 'Inspect PD Workspace state and retry; the hook failed open.')), ...ingestionDiagnostics];
|
|
122
123
|
return { stdout: adapter.encodeOutput(result, event.kind), exitCode: 0, stderr };
|
|
123
124
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex Tool Semantic Declaration — PRI-634-F R2 (review P1-2)
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: the Codex host layer of the Tool Semantic Registry. Codex names
|
|
5
|
+
* its shell tool `Bash` (capitalized — evidenced by the codex-adapter
|
|
6
|
+
* integration fixtures), which the core baseline's lowercase `bash` never
|
|
7
|
+
* matches: rules generated against the baseline name could pass replay and
|
|
8
|
+
* never fire on a real Codex event.
|
|
9
|
+
*
|
|
10
|
+
* EVIDENCE BOUND: this declaration contains only names with in-repo
|
|
11
|
+
* evidence — the installer's hook matcher `Bash|apply_patch`
|
|
12
|
+
* (create-principles-disciple/src/installers/codex-host-installer.ts:203,
|
|
13
|
+
* locked by codex-plugin-bundle.test.ts). Extending it with the remaining
|
|
14
|
+
* Codex tool surface is tracked as PRI-657 — a wrong guess would be worse
|
|
15
|
+
* than a gap (the reliability check rejects undeclared names, forcing
|
|
16
|
+
* correct names).
|
|
17
|
+
*/
|
|
18
|
+
import { type ToolSemanticMappingV1, type ToolSemanticRegistry } from '@principles/core/runtime-v2';
|
|
19
|
+
export declare const CODEX_TOOL_SEMANTIC_MAPPINGS: readonly ToolSemanticMappingV1[];
|
|
20
|
+
export declare const CODEX_TOOL_SEMANTICS: ToolSemanticRegistry;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex Tool Semantic Declaration — PRI-634-F R2 (review P1-2)
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: the Codex host layer of the Tool Semantic Registry. Codex names
|
|
5
|
+
* its shell tool `Bash` (capitalized — evidenced by the codex-adapter
|
|
6
|
+
* integration fixtures), which the core baseline's lowercase `bash` never
|
|
7
|
+
* matches: rules generated against the baseline name could pass replay and
|
|
8
|
+
* never fire on a real Codex event.
|
|
9
|
+
*
|
|
10
|
+
* EVIDENCE BOUND: this declaration contains only names with in-repo
|
|
11
|
+
* evidence — the installer's hook matcher `Bash|apply_patch`
|
|
12
|
+
* (create-principles-disciple/src/installers/codex-host-installer.ts:203,
|
|
13
|
+
* locked by codex-plugin-bundle.test.ts). Extending it with the remaining
|
|
14
|
+
* Codex tool surface is tracked as PRI-657 — a wrong guess would be worse
|
|
15
|
+
* than a gap (the reliability check rejects undeclared names, forcing
|
|
16
|
+
* correct names).
|
|
17
|
+
*/
|
|
18
|
+
import { buildToolSemanticRegistry } from '@principles/core/runtime-v2';
|
|
19
|
+
export const CODEX_TOOL_SEMANTIC_MAPPINGS = Object.freeze([
|
|
20
|
+
{ rawToolName: 'Bash', canonicalKind: 'execute' },
|
|
21
|
+
{ rawToolName: 'apply_patch', canonicalKind: 'write' },
|
|
22
|
+
]);
|
|
23
|
+
const built = buildToolSemanticRegistry(CODEX_TOOL_SEMANTIC_MAPPINGS);
|
|
24
|
+
if (!built.ok) {
|
|
25
|
+
throw new Error(`[PD] Codex tool semantic declaration is invalid: ${built.errors.join('; ')}`);
|
|
26
|
+
}
|
|
27
|
+
export const CODEX_TOOL_SEMANTICS = built.registry;
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
import fs from 'node:fs';
|
|
25
25
|
import path from 'node:path';
|
|
26
26
|
import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime-v2';
|
|
27
|
-
import { loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, } from '@principles/host-runtime';
|
|
27
|
+
import { loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, saveHostToolDeclaration, } from '@principles/host-runtime';
|
|
28
28
|
import { catchUpCodexIngestion } from '../ingestion/catch-up.js';
|
|
29
|
+
import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from '../tool-semantics.js';
|
|
29
30
|
const WORKER_OWNER = 'companion-worker';
|
|
30
31
|
const DEFAULT_DIAG_CANDIDATE_LIMIT = 5;
|
|
31
32
|
function workerLogger(logger) {
|
|
@@ -194,11 +195,24 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
194
195
|
}
|
|
195
196
|
// Step 7 — ONE bounded downstream consumer cycle via the shared executor
|
|
196
197
|
// (same implementation the OpenClaw auto-consumer runs).
|
|
198
|
+
// PRI-634-F R2: persist the Codex tool declaration (workspace provenance
|
|
199
|
+
// for host-neutral consumers) and thread the registry into the cycle so
|
|
200
|
+
// activation-gate replay resolves Codex tool semantics (Bash, not bash).
|
|
201
|
+
const declared = saveHostToolDeclaration(workspaceDir, {
|
|
202
|
+
version: 1,
|
|
203
|
+
hostKind: 'codex',
|
|
204
|
+
mappings: CODEX_TOOL_SEMANTIC_MAPPINGS,
|
|
205
|
+
declaredAt: new Date().toISOString(),
|
|
206
|
+
});
|
|
207
|
+
if (!declared.ok) {
|
|
208
|
+
logger.warn?.(`[PD:CodexWorker] Failed to persist Codex tool declaration: ${declared.reason} — host-neutral consumers will not find it (rc-9)`);
|
|
209
|
+
}
|
|
197
210
|
const downstream = await runInternalizationConsumerCycle(workspaceDir, {
|
|
198
211
|
owner: WORKER_OWNER,
|
|
199
212
|
logLabel: 'CodexWorker',
|
|
200
213
|
logger,
|
|
201
214
|
emitEvent,
|
|
215
|
+
toolSemantics: CODEX_TOOL_SEMANTICS,
|
|
202
216
|
// No hostToolCatalog: PD has not declared a Codex tool catalog; a wrong
|
|
203
217
|
// (OpenClaw) catalog would be worse than none (PRI-630 follow-up).
|
|
204
218
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/codex-adapter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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",
|