@principles/codex-adapter 0.4.7 → 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,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync, realpathSync } 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
6
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
@@ -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')),
|
|
@@ -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,8 +31,8 @@
|
|
|
31
31
|
"lint": "eslint \"src/**/*.ts\""
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@principles/core": "^1.
|
|
35
|
-
"@principles/host-runtime": "^0.7.
|
|
34
|
+
"@principles/core": "^1.289.0",
|
|
35
|
+
"@principles/host-runtime": "^0.7.13",
|
|
36
36
|
"@principles/install-layout": "^0.2.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|