@principles/codex-adapter 0.4.6 → 0.4.8
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
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { readFileSync, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import process from 'node:process';
|
|
5
|
-
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
6
7
|
import { appendEventLogLine, redactTelemetryString, isRuleHostEvaluatedEventData } from '@principles/core/runtime-v2';
|
|
7
8
|
import { createProductionHostRuntime, loadPdConfigForPlugin, resolveNearestPdWorkspace } from '@principles/host-runtime';
|
|
8
9
|
import { CODEX_TOOL_SEMANTICS } from './tool-semantics.js';
|
|
@@ -195,11 +196,27 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
195
196
|
const nextAction = error instanceof CodexDecoderError ? error.nextAction : 'Inspect the Codex 0.147 hook payload.';
|
|
196
197
|
return { stdout: {}, exitCode: 0, stderr: [diagnostic(reason, nextAction)] };
|
|
197
198
|
}
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
// Workspace's hook into another Workspace's business state.
|
|
199
|
+
// Initializing the user workspace explicitly opts Codex into shared
|
|
200
|
+
// governance. Otherwise preserve the existing per-project resolution.
|
|
201
201
|
const requestedCwd = event.context.workspaceDir || cwd;
|
|
202
|
-
|
|
202
|
+
if (!path.isAbsolute(requestedCwd))
|
|
203
|
+
return { stdout: {}, exitCode: 0, stderr: [diagnostic('cwd_not_absolute', 'Provide the absolute Codex project directory.')] };
|
|
204
|
+
// Resolve like pd-locate.cjs does: a relative CODEX_HOME must yield the same
|
|
205
|
+
// absolute workspace for hooks and owner scripts, or resolveNearestPdWorkspace
|
|
206
|
+
// rejects it after the config check already accepted it.
|
|
207
|
+
const userWorkspace = path.join(path.resolve(_env.CODEX_HOME || path.join(os.homedir(), '.codex')), 'pd-workspace');
|
|
208
|
+
let userWorkspaceInitialized = false;
|
|
209
|
+
try {
|
|
210
|
+
userWorkspaceInitialized = statSync(path.join(userWorkspace, '.pd', 'config.yaml')).isFile();
|
|
211
|
+
if (!userWorkspaceInitialized)
|
|
212
|
+
return { stdout: {}, exitCode: 0, stderr: [diagnostic('user_workspace_config_invalid', 'Repair the user workspace .pd/config.yaml; project configuration was not used.')] };
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (!(error instanceof Error && Object.hasOwn(error, 'code') && Reflect.get(error, 'code') === 'ENOENT')) {
|
|
216
|
+
return { stdout: {}, exitCode: 0, stderr: [diagnostic('user_workspace_config_unreadable', 'Restore access to the user workspace .pd/config.yaml; project configuration was not used.')] };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const resolution = resolveNearestPdWorkspace(userWorkspaceInitialized ? userWorkspace : requestedCwd);
|
|
203
220
|
if (!resolution.ok)
|
|
204
221
|
return { stdout: {}, exitCode: 0, stderr: [diagnostic(resolution.reason, resolution.nextAction)] };
|
|
205
222
|
event = { ...event, context: { ...event.context, workspaceDir: resolution.workspaceDir } };
|
|
@@ -242,6 +259,7 @@ export async function processHookInvocation(rawStdin, _env = process.env, cwd =
|
|
|
242
259
|
// the Codex adapter stays independent of the OpenClaw plugin). The line
|
|
243
260
|
// writer appends synchronously — no flush/dispose needed for the subprocess.
|
|
244
261
|
const result = await createProductionHostRuntime({
|
|
262
|
+
projectDir: requestedCwd,
|
|
245
263
|
hostKind: 'codex',
|
|
246
264
|
toolSemantics: CODEX_TOOL_SEMANTICS,
|
|
247
265
|
events: codexEventEmitter(path.join(resolution.workspaceDir, '.state')),
|
|
@@ -290,6 +308,32 @@ async function main() {
|
|
|
290
308
|
process.stdout.write(`${JSON.stringify(result.stdout)}\n`);
|
|
291
309
|
process.exitCode = result.exitCode;
|
|
292
310
|
}
|
|
293
|
-
|
|
294
|
-
|
|
311
|
+
// PRI-892: Node resolves the main module through symlinks/junctions while
|
|
312
|
+
// argv[1] keeps the unresolved link path (npm/npx `.bin` shims, or a
|
|
313
|
+
// junctioned extensions dir), so the old raw comparison silently skipped
|
|
314
|
+
// main() on Windows. Try the raw URL first so an ordinary direct invocation
|
|
315
|
+
// never depends on a filesystem lookup succeeding, then canonicalize through
|
|
316
|
+
// realpath for the linked-path case.
|
|
317
|
+
function isMainModuleEntry() {
|
|
318
|
+
const [, entry] = process.argv;
|
|
319
|
+
if (!entry)
|
|
320
|
+
return false;
|
|
321
|
+
if (pathToFileURL(entry).href === import.meta.url)
|
|
322
|
+
return true;
|
|
323
|
+
try {
|
|
324
|
+
return pathToFileURL(realpathSync(entry)).href === import.meta.url;
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
// rc-9: realpath is unavailable or failed, so the link cannot be verified.
|
|
328
|
+
// If argv[1] still names this exact file, that is the entry — run main()
|
|
329
|
+
// and leave a bounded diagnostic instead of the silent no-op this ticket
|
|
330
|
+
// exists to remove. A test runner that merely imports this module never
|
|
331
|
+
// satisfies it, because its argv[1] is the runner, not pd-hook.
|
|
332
|
+
if (path.basename(entry) !== path.basename(fileURLToPath(import.meta.url)))
|
|
333
|
+
return false;
|
|
334
|
+
process.stderr.write(`${diagnostic(`entry_identity_unverified:${errorMessage(error)}`, 'Reinstall the Codex adapter; if it repeats, report this line together with the command that invoked the hook.')}\n`);
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (isMainModuleEntry())
|
|
295
339
|
void main();
|
|
@@ -13,6 +13,12 @@ export interface CodexWorkerCycleStepReport {
|
|
|
13
13
|
readonly errorCategory?: string;
|
|
14
14
|
/** PRI-638 P1-C: recovery action for capability-disabled pauses. */
|
|
15
15
|
readonly nextAction?: string;
|
|
16
|
+
/**
|
|
17
|
+
* PRI-917 v0.3.3 review fix (P2-2): candidates parked by the Reuse Review
|
|
18
|
+
* Gate (suspected duplicates awaiting the Owner). Forwarded per-candidate
|
|
19
|
+
* so the report shows WHAT awaits the Owner, not just a degraded status.
|
|
20
|
+
*/
|
|
21
|
+
readonly reuseReviewRequiredCandidateIds?: readonly string[];
|
|
16
22
|
} | null;
|
|
17
23
|
readonly downstream: InternalizationConsumerCycleOutcome | null;
|
|
18
24
|
}
|
|
@@ -156,11 +156,18 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
156
156
|
getEnvVar: (name) => process.env[name],
|
|
157
157
|
});
|
|
158
158
|
const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
|
|
159
|
+
// PRI-917 v0.3.3 review fix (P2-2): forward the parked-candidate
|
|
160
|
+
// dispositions so the Owner sees the pending items instead of a bare
|
|
161
|
+
// degraded status with no subject.
|
|
162
|
+
const reuseReviewRequired = (executed.candidateOutcomes ?? [])
|
|
163
|
+
.filter((outcome) => outcome.reason === 'reuse_review_required')
|
|
164
|
+
.map((outcome) => outcome.candidateId);
|
|
159
165
|
diagnostician = {
|
|
160
166
|
taskId: candidate.taskId,
|
|
161
167
|
status: executed.status,
|
|
162
168
|
...(executed.message !== undefined ? { message: executed.message.slice(0, 200) } : {}),
|
|
163
169
|
...(executed.errorCategory !== undefined ? { errorCategory: executed.errorCategory } : {}),
|
|
170
|
+
...(reuseReviewRequired.length > 0 ? { reuseReviewRequiredCandidateIds: reuseReviewRequired } : {}),
|
|
164
171
|
};
|
|
165
172
|
// The bridge stays cached per workspace (bounded: one per workspace
|
|
166
173
|
// per worker process, exactly like the OpenClaw plugin host) — no
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/codex-adapter",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
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",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"lint": "eslint \"src/**/*.ts\""
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@principles/core": "^1.
|
|
35
|
-
"@principles/host-runtime": "^0.7.
|
|
36
|
-
"@principles/install-layout": "^0.2.
|
|
34
|
+
"@principles/core": "^1.289.0",
|
|
35
|
+
"@principles/host-runtime": "^0.7.13",
|
|
36
|
+
"@principles/install-layout": "^0.2.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^26.4.1",
|