@unblocklabs/unblock-codex-prompt 0.5.2 → 0.6.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.
- package/README.md +41 -12
- package/dist/adapter.js +46 -18
- package/dist/catalog.js +12 -11
- package/dist/codex-bridge-source.js +1 -1
- package/dist/codex-home.d.ts +5 -0
- package/dist/codex-home.js +49 -0
- package/dist/index.js +42 -33
- package/dist/manager.d.ts +8 -1
- package/dist/manager.js +47 -24
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.js +24 -7
- package/dist/skills.js +7 -17
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Unblock Codex Prompt
|
|
2
2
|
|
|
3
3
|
A small, explicit prompt-management bridge for dedicated OpenClaw Mac agents.
|
|
4
|
-
**Version 0.
|
|
4
|
+
**Version 0.6.0.** The bridge supports OpenClaw/Codex 2026.10.5 and newer
|
|
5
5
|
stable releases with a reviewed context-assembly layout, and agents running
|
|
6
6
|
through the Claude CLI backend, whose whole system prompt it replaces through
|
|
7
7
|
OpenClaw's public `before_prompt_build` hook without patching OpenClaw core.
|
|
@@ -30,8 +30,9 @@ skills in its system prompt instead, and that list is dropped with the rest of t
|
|
|
30
30
|
|
|
31
31
|
**The fleet policy is live too.** On Codex the generated file (fleet policy and memory
|
|
32
32
|
reference) replaces Codex's native base through `model_instructions_file`.
|
|
33
|
-
The patched adapter also sends
|
|
34
|
-
OpenClaw starts or resumes it
|
|
33
|
+
The patched adapter also sends it as each thread's `baseInstructions` when
|
|
34
|
+
OpenClaw starts or resumes it (only the policy prefix on lightweight turns).
|
|
35
|
+
Codex reads base instructions per session, not from
|
|
35
36
|
history, and OpenClaw fingerprints these requests, so a refreshed revision resumes an
|
|
36
37
|
existing thread on its next turn with the new base: no duplicate copy, nothing in
|
|
37
38
|
history, and compaction cannot revert it. If the adapter is ever missing, Codex still
|
|
@@ -41,7 +42,7 @@ developer instructions native children inherit, and suppresses the separate memo
|
|
|
41
42
|
contribution. Cron guidance remains in its existing parent-local carrier. The optional
|
|
42
43
|
managed model catalog removes native Default-mode prose.
|
|
43
44
|
|
|
44
|
-
There are no bundled system/developer templates
|
|
45
|
+
There are no bundled system/developer templates. Downloaded
|
|
45
46
|
policy and the memory reference are written only to
|
|
46
47
|
`<agentDir>/codex-home/unblock-codex-prompt.md`, outside the plugin directory.
|
|
47
48
|
Codex reads that generated file; the plugin package does not retain its own copy
|
|
@@ -61,6 +62,7 @@ files use private permissions.
|
|
|
61
62
|
|
|
62
63
|
- Codex: **OpenClaw and @openclaw/codex >=2026.10.5**. Every published release from
|
|
63
64
|
2026.10.5 through 2026.10.9 has the identical reviewed context-assembly functions.
|
|
65
|
+
**2026.11.5** has a separately reviewed layout.
|
|
64
66
|
Older layouts (2026.9.x and 2026.10.1–2026.10.4) are refused: 2026.9.x carries
|
|
65
67
|
persona in turn-scoped text native children never see. Nodes on those versions
|
|
66
68
|
stay on plugin 0.3.x until upgraded; restore still works for them. Once the Codex
|
|
@@ -68,8 +70,9 @@ files use private permissions.
|
|
|
68
70
|
without a restore. Bundle names
|
|
69
71
|
may change; fingerprints of the context-assembly functions must still match.
|
|
70
72
|
Changed assembly is refused pending review, rather than patched blindly.
|
|
71
|
-
- Local stdio Codex with an OpenClaw agent-scoped home
|
|
72
|
-
`appServer.command` and `appServer.args`
|
|
73
|
+
- Local stdio Codex with an OpenClaw agent-scoped home or an explicitly dedicated
|
|
74
|
+
user-scoped home. Operator-selected `appServer.command` and `appServer.args`
|
|
75
|
+
are supported and left unchanged.
|
|
73
76
|
The launcher must honor OpenClaw's `CODEX_HOME` and must not override the
|
|
74
77
|
managed `model_instructions_file`; status cannot attest to launcher behavior.
|
|
75
78
|
- One target agent per installation. Other agents use upstream behavior. Native
|
|
@@ -87,7 +90,10 @@ producer and moves two host-rendered contributions out of the parent-only and
|
|
|
87
90
|
refreshable carriers into the thread developer instructions, after the fleet policy:
|
|
88
91
|
the session's OpenClaw skills catalog (with OpenClaw's `skills_search`/`skills_read`
|
|
89
92
|
hints, exactly as upstream renders it, and nothing when upstream renders nothing), then
|
|
90
|
-
the persona (SOUL, IDENTITY, shared USER
|
|
93
|
+
the shared persona (SOUL, IDENTITY, shared USER). On 2026.11.5, the personal
|
|
94
|
+
`USER.md` remains in OpenClaw's parent-only inference request; connections without
|
|
95
|
+
that path do not receive it. Older reviewed layouts carry personal USER with
|
|
96
|
+
shared persona. The thread instructions are
|
|
91
97
|
rebuilt every turn: a catalog change or persona edit changes them, and Codex re-syncs
|
|
92
98
|
the existing thread on its next turn with a policy handoff. They survive compaction
|
|
93
99
|
and are inherited by native children. Native AGENTS and operational context remain
|
|
@@ -105,6 +111,15 @@ private seams and refuses unreviewed layouts.
|
|
|
105
111
|
The skills catalog is OpenClaw's own per-session snapshot, with its eligibility,
|
|
106
112
|
allowlist, visibility and size-limit logic; the plugin neither adds nor removes skills.
|
|
107
113
|
|
|
114
|
+
### Lightweight Codex turns
|
|
115
|
+
|
|
116
|
+
Use OpenClaw's native `lightContext: true` (for example, on `sessions_spawn`).
|
|
117
|
+
The managed Codex turn keeps the fleet policy and runtime instructions, but omits
|
|
118
|
+
workspace files, the OpenClaw skills catalog, and the bridge's memory reference.
|
|
119
|
+
Tool permissions, approvals, history, and independent plugin hooks are unchanged.
|
|
120
|
+
Use an isolated spawn when the worker should not inherit conversation history.
|
|
121
|
+
Claude CLI and `unblock-memory` prompt hooks do not receive the lightweight signal.
|
|
122
|
+
|
|
108
123
|
## Claude CLI agents
|
|
109
124
|
|
|
110
125
|
For agents whose models run through OpenClaw's `claude-cli` backend, the plugin
|
|
@@ -249,10 +264,23 @@ Codex sync after that starts fresh, may target a different Codex package, and re
|
|
|
249
264
|
the old receipt's backups. Otherwise sync and restore keep refusing foreign edits and
|
|
250
265
|
foreign backups.
|
|
251
266
|
|
|
252
|
-
Codex `appServer` settings (
|
|
267
|
+
Codex `appServer` settings (local stdio only) are checked by sync when
|
|
253
268
|
it selects Codex and reported by status as `codexConfigError` for a Codex
|
|
254
269
|
enrollment. They never block Claude-only enrollment, status or restore.
|
|
255
270
|
|
|
271
|
+
With `appServer.homeScope: "user"`, use a Gateway configured for one agent and
|
|
272
|
+
reserve the effective `CODEX_HOME` for that agent alone. OpenClaw uses the Gateway
|
|
273
|
+
environment (including `env.vars.CODEX_HOME`), or `~/.codex` when unset. In that
|
|
274
|
+
directory, create a regular `.unblock-codex-prompt-owner` file containing the
|
|
275
|
+
agent's absolute OpenClaw `agentDir`, one line. The home and marker must be owned
|
|
276
|
+
by the Gateway user and not group- or world-writable. Do not mark a home used by
|
|
277
|
+
other agents, Codex CLI, or Desktop. The launcher must honor the same `CODEX_HOME`.
|
|
278
|
+
|
|
279
|
+
Sync manages `config.toml` in the dedicated home; the prompt, receipts, and
|
|
280
|
+
backups stay in `<agentDir>/codex-home`. To switch homes, restore first. Restore
|
|
281
|
+
uses the recorded home, even if the current Gateway environment points elsewhere;
|
|
282
|
+
keep the ownership marker until restore finishes.
|
|
283
|
+
|
|
256
284
|
Claude CLI enrollment needs the hook to be registrable. OpenClaw registers
|
|
257
285
|
`before_prompt_build` for a non-bundled plugin only with
|
|
258
286
|
`hooks.allowConversationAccess: true`, and blocks it when `hooks.allowPromptInjection`
|
|
@@ -343,7 +371,7 @@ Claude CLI process. It uses a temporary state directory and changes nothing inst
|
|
|
343
371
|
npm ci
|
|
344
372
|
npm run preflight
|
|
345
373
|
npm pack
|
|
346
|
-
openclaw plugins install ./unblocklabs-unblock-codex-prompt-0.
|
|
374
|
+
openclaw plugins install ./unblocklabs-unblock-codex-prompt-0.6.0.tgz --force --accept-capabilities
|
|
347
375
|
```
|
|
348
376
|
|
|
349
377
|
Include the plugin in `plugins.allow` if applicable, then configure:
|
|
@@ -480,7 +508,8 @@ reports each runtime's policy revision and last successful `checkedAt` timestamp
|
|
|
480
508
|
policy text is never printed. A changed
|
|
481
509
|
revision reaches existing conversations on their next turn: Codex resumes the thread
|
|
482
510
|
with the new base instructions (`nextCodexTurn`), and Claude starts the next CLI
|
|
483
|
-
process with the new prompt
|
|
511
|
+
process with the new prompt (`nextClaudeProcess`). OpenClaw may replace a restricted
|
|
512
|
+
native Codex thread while carrying forward the OpenClaw conversation. Earlier
|
|
484
513
|
history is not rewritten. A live Codex incognito conversation cannot be resumed; it
|
|
485
514
|
keeps the revision it started with.
|
|
486
515
|
The plugin never restarts the Gateway automatically.
|
|
@@ -628,7 +657,7 @@ sync.
|
|
|
628
657
|
|
|
629
658
|
```sh
|
|
630
659
|
npm run preflight
|
|
631
|
-
npm run release:check -- v0.
|
|
660
|
+
npm run release:check -- v0.6.0
|
|
632
661
|
```
|
|
633
662
|
|
|
634
663
|
Tests cover compilation, explicit refresh, native/private-body exclusion,
|
|
@@ -638,7 +667,7 @@ proof and limits.
|
|
|
638
667
|
|
|
639
668
|
Install with
|
|
640
669
|
the packed archive above for an unreleased candidate. After publication, use
|
|
641
|
-
`openclaw plugins install npm:@unblocklabs/unblock-codex-prompt@0.
|
|
670
|
+
`openclaw plugins install npm:@unblocklabs/unblock-codex-prompt@0.6.0 --accept-capabilities`.
|
|
642
671
|
The existing [GitHub Release workflow](RELEASING.md) publishes npm only when a
|
|
643
672
|
GitHub Release is published. Normal pushes do not release the package.
|
|
644
673
|
|
package/dist/adapter.js
CHANGED
|
@@ -8,7 +8,7 @@ import { assertSupportedVersion, MINIMUM_OPENCLAW } from "./compatibility.js";
|
|
|
8
8
|
import { managedTargetSource } from "./managed-target.js";
|
|
9
9
|
import { codexBridgeSource } from "./codex-bridge-source.js";
|
|
10
10
|
const MARKER = "// unblock-codex-prompt bridge v1";
|
|
11
|
-
const BUNDLE_NAME = /^(?:thread-(?:lifecycle|requests|policy)|dynamic-tools|attempt-workspace-context|run-attempt)-[\w-]+\.m?js$/u;
|
|
11
|
+
const BUNDLE_NAME = /^(?:thread-(?:lifecycle|requests|policy)|dynamic-tools|attempt-workspace-context|run-attempt|native-skill-isolation)-[\w-]+\.m?js$/u;
|
|
12
12
|
const HASH = /^[a-f0-9]{64}$/u;
|
|
13
13
|
// Reviewed context producers/carriers, identical in every published @openclaw/codex 2026.10.5-2026.10.9.
|
|
14
14
|
const REFRESHABLE_CONTEXT_HASHES = {
|
|
@@ -21,6 +21,16 @@ const REFRESHABLE_CONTEXT_HASHES = {
|
|
|
21
21
|
refreshCodexThreadInstructions: "23068afa77e3286acc06885b7440d6a1b44ede4c93a6e322fbbbcd6df8fb8777",
|
|
22
22
|
restoreCodexThreadInstructionsAfterCompaction: "86d6f792175cfbc604f5408016e00b77ed1f7fbefa33b0210d6fbf8d56a2c0a4",
|
|
23
23
|
};
|
|
24
|
+
// 2026.11.5 moves workspace context, separates personal and shared persona, and
|
|
25
|
+
// makes turn/start assembly async. The rest of the reviewed carriers are unchanged.
|
|
26
|
+
const SPLIT_PERSONA_CONTEXT_HASHES = {
|
|
27
|
+
...REFRESHABLE_CONTEXT_HASHES,
|
|
28
|
+
buildDeveloperInstructions: "b394fae4fc72f0414bc7975c95d76a081dc24542fc7220d6c7aab631f008a38f",
|
|
29
|
+
buildCodexWorkspaceBootstrapContext: "4682a0a9242a1564870517eb27d5475ed83834574878575e830c93f8b16bcd99",
|
|
30
|
+
prepareCodexAttemptContext: "73822733885dff785b915694e0482b4d35b79af303592b6ada721dee22f6d5f6",
|
|
31
|
+
buildCodexThreadConfiguration: "f485f775aef22bbc670f2beeb6a6742a9f371736f464cd03fd070812c95aecc2",
|
|
32
|
+
splitCodexExtraSystemPrompt: "3c7c1f37252269c00218f7cbd4c21425a9d81014429dbd6b00f9252b6ea097a0",
|
|
33
|
+
};
|
|
24
34
|
function receiptPath(agentDir) { return join(agentDir, "codex-home", ".unblock-codex-prompt-adapter.json"); }
|
|
25
35
|
function receiptFiles(receipt) {
|
|
26
36
|
if (receipt.schema === 2)
|
|
@@ -124,11 +134,11 @@ function unblockRelay(params, part, text) {
|
|
|
124
134
|
}
|
|
125
135
|
function unblockBaseInstructions(params) {
|
|
126
136
|
if (!unblockManagedTarget(params)) return null;
|
|
127
|
-
return unblockLoadBridge().readCodexBaseInstructions(${JSON.stringify(agentDir)});
|
|
137
|
+
return unblockLoadBridge().readCodexBaseInstructions(${JSON.stringify(agentDir)}, params.config, params.bootstrapContextMode);
|
|
128
138
|
}
|
|
129
139
|
${managedTargetSource({ name: "unblockManagedTarget", agentId, targetChanged: "Frozen bridge target changed; restore and reinstall the adapter" })}function unblockFrozenPolicy(params) {
|
|
130
140
|
if (!unblockManagedTarget(params)) return null;
|
|
131
|
-
return unblockLoadBridge().readFrozenPolicy(${JSON.stringify(agentDir)});
|
|
141
|
+
return unblockLoadBridge().readFrozenPolicy(${JSON.stringify(agentDir)}, params.config);
|
|
132
142
|
}
|
|
133
143
|
`;
|
|
134
144
|
}
|
|
@@ -144,15 +154,16 @@ export function patchAdapterSources(sources, agentDir, agentId) {
|
|
|
144
154
|
return matches[0];
|
|
145
155
|
};
|
|
146
156
|
// Older layouts carry persona in turn-scoped collaboration text that native children never see.
|
|
147
|
-
if (functions.some(fn => fn.node.id?.name === "buildTurnScopedCollaborationInstructions")
|
|
148
|
-
!functions.some(fn => fn.node.id?.name === "buildCodexWorkspaceBootstrapContext")) {
|
|
157
|
+
if (functions.some(fn => fn.node.id?.name === "buildTurnScopedCollaborationInstructions")) {
|
|
149
158
|
throw new Error(`Unsupported Codex context layout; live agent context requires @openclaw/codex >=${MINIMUM_OPENCLAW}`);
|
|
150
159
|
}
|
|
160
|
+
const workspace = find("buildCodexWorkspaceBootstrapContext");
|
|
161
|
+
const splitPersona = sha256(sources[workspace.bundle].slice(workspace.node.start, workspace.node.end)) === SPLIT_PERSONA_CONTEXT_HASHES.buildCodexWorkspaceBootstrapContext;
|
|
151
162
|
const prefix = bridgePrefix(agentDir, agentId);
|
|
152
|
-
return patchOperationalAdapter(patchRefreshableAdapter(sources, find, prefix), prefix);
|
|
163
|
+
return patchOperationalAdapter(patchRefreshableAdapter(sources, find, prefix, splitPersona), prefix, splitPersona);
|
|
153
164
|
}
|
|
154
|
-
function patchRefreshableAdapter(sources, find, prefix) {
|
|
155
|
-
for (const [name, expected] of Object.entries(REFRESHABLE_CONTEXT_HASHES)) {
|
|
165
|
+
function patchRefreshableAdapter(sources, find, prefix, splitPersona) {
|
|
166
|
+
for (const [name, expected] of Object.entries(splitPersona ? SPLIT_PERSONA_CONTEXT_HASHES : REFRESHABLE_CONTEXT_HASHES)) {
|
|
156
167
|
const { node, bundle } = find(name);
|
|
157
168
|
if (sha256(sources[bundle].slice(node.start, node.end)) !== expected) {
|
|
158
169
|
throw new Error("Unsupported Codex context assembly: " + name + "; review the changed upstream function before syncing");
|
|
@@ -164,7 +175,7 @@ function patchRefreshableAdapter(sources, find, prefix) {
|
|
|
164
175
|
const thread = find("buildCodexThreadConfiguration");
|
|
165
176
|
const originalThread = sources[thread.bundle].slice(thread.node.start, thread.node.end)
|
|
166
177
|
.replace("function buildCodexThreadConfiguration(", "function unblockOriginalThreadConfiguration(");
|
|
167
|
-
// Thread start, resume and fork
|
|
178
|
+
// Thread start, resume and fork carry the verified base (policy only for lightweight runs).
|
|
168
179
|
// OpenClaw fingerprints these requests, so a refreshed policy resumes the thread on its next
|
|
169
180
|
// turn with the new base; Codex keeps base instructions out of history and compaction. The
|
|
170
181
|
// model_instructions_file pointer to the same file remains the fallback.
|
|
@@ -185,10 +196,12 @@ function patchRefreshableAdapter(sources, find, prefix) {
|
|
|
185
196
|
// every supported release) and relay their output on it:
|
|
186
197
|
// - skills: OpenClaw's per-session skills catalog with its skills_search/skills_read hints,
|
|
187
198
|
// exactly as upstream renders it (nothing when upstream renders nothing);
|
|
188
|
-
// - persona: SOUL, IDENTITY
|
|
199
|
+
// - persona: SOUL, IDENTITY and shared USER; on split-persona hosts the personal USER
|
|
200
|
+
// stays on the original parent-only inference route and is never persisted by the bridge.
|
|
189
201
|
// Memory stays suppressed at its producer; native AGENTS stays live.
|
|
190
202
|
const skillsWrapper = `function renderCodexSkillsInstructions(params) {
|
|
191
203
|
const policy = unblockFrozenPolicy(params.attempt);
|
|
204
|
+
if (policy !== null && params.attempt.bootstrapContextMode === "lightweight") return;
|
|
192
205
|
const skills = unblockOriginalSkillsInstructions(params);
|
|
193
206
|
if (policy === null) return skills;
|
|
194
207
|
unblockRelay(params.attempt, "skills", skills);
|
|
@@ -199,13 +212,20 @@ function patchRefreshableAdapter(sources, find, prefix) {
|
|
|
199
212
|
const policy = unblockFrozenPolicy(params.params);
|
|
200
213
|
const context = await unblockOriginalWorkspaceContext(params);
|
|
201
214
|
if (policy === null) return context;
|
|
202
|
-
|
|
203
|
-
return { ...context,
|
|
215
|
+
// OpenClaw skips bootstrap files, but can still carry cached workspace instructions.
|
|
216
|
+
if (params.params.bootstrapContextMode === "lightweight") return { ...context,
|
|
217
|
+
threadDeveloperInstructionFiles: [], threadDeveloperInstructions: undefined, promptContext: undefined,
|
|
218
|
+
personaInstructions: undefined, sharedPersonaInstructions: undefined, memoryInstructions: undefined };
|
|
219
|
+
unblockRelay(params.params, "persona", context.${splitPersona ? "sharedPersonaInstructions" : "personaInstructions"});
|
|
220
|
+
${splitPersona ? `const personal = context.personaFiles?.filter(file => file.personalUser === true) ?? [];
|
|
221
|
+
const personaInstructions = personal.length ? ["## Personal USER.md (current request only)", ...personal.map(file => "### " + file.path + "\\n\\n" + file.content)].join("\\n\\n") : undefined;` : "const personaInstructions = undefined;"}
|
|
222
|
+
return { ...context, personaInstructions, sharedPersonaInstructions: undefined, memoryInstructions: undefined };
|
|
204
223
|
}
|
|
205
224
|
`;
|
|
225
|
+
const additions = splitPersona ? "options.omitConversationTurnContext ? splitCodexExtraSystemPrompt(params).persistent : params.extraSystemPrompt" : "params.extraSystemPrompt";
|
|
206
226
|
const edits = [
|
|
207
227
|
{ bundle: developer.bundle, start: developer.node.body.start + 1, end: developer.node.body.start + 1,
|
|
208
|
-
text:
|
|
228
|
+
text: `\n\tconst unblockPolicy = unblockFrozenPolicy(params);\n\tif (unblockPolicy !== null) return [unblockPolicy, params[unblockLiveKey]?.skills, params[unblockLiveKey]?.persona, params.gitCoauthorPrompt, unblockNormalizeAdditions(${additions})].filter(section => typeof section === "string" && section.trim()).join("\\n\\n");` },
|
|
209
229
|
{ bundle: skills.bundle, start: skills.node.start, end: skills.node.end, text: skillsWrapper + originalSkills },
|
|
210
230
|
{ bundle: workspace.bundle, start: workspace.node.start, end: workspace.node.end, text: wrapper + originalWorkspace },
|
|
211
231
|
{ bundle: thread.bundle, start: thread.node.start, end: thread.node.end, text: threadWrapper + originalThread },
|
|
@@ -223,18 +243,22 @@ const OPERATIONAL_HASHES = {
|
|
|
223
243
|
resumeExistingCodexThread: "1b8d4038ee162b276095d9f3e1ad771f33c7cd794c47fb5088783dae9e7c1494",
|
|
224
244
|
refreshCodexThreadPolicy: "69d6e9903896c77e71542957dbadddaca5d3cbb4d7cd56b8ff0de2a5ca42b995",
|
|
225
245
|
};
|
|
226
|
-
function patchOperationalAdapter(sources, prefix) {
|
|
246
|
+
function patchOperationalAdapter(sources, prefix, splitPersona) {
|
|
227
247
|
const functionsByBundle = sources.map(source => parse(source, { ecmaVersion: "latest", sourceType: "module" }).body
|
|
228
248
|
.filter(node => node.type === "FunctionDeclaration"));
|
|
229
249
|
const names = functionsByBundle.flat().map(node => node.id?.name);
|
|
230
|
-
const
|
|
231
|
-
|
|
250
|
+
const hashes = splitPersona ? { ...OPERATIONAL_HASHES,
|
|
251
|
+
buildTurnStartParams: "734558ecc9adf1193ea338a848d032140a36a5a64cc4f8461a988b7c02771e1a",
|
|
252
|
+
resumeExistingCodexThread: "659dddc25b0aa3e1f3929d663879b421f6803c1bb66e9ba2f91f9d0a2dd85a61",
|
|
253
|
+
} : OPERATIONAL_HASHES;
|
|
254
|
+
const required = Object.keys(hashes);
|
|
255
|
+
if ((splitPersona || required.some(name => names.includes(name))) && required.some(name => names.filter(found => found === name).length !== 1)) {
|
|
232
256
|
throw new Error("Unsupported Codex operational context: missing or duplicate carrier; review before syncing");
|
|
233
257
|
}
|
|
234
258
|
return sources.map((source, bundle) => {
|
|
235
259
|
const functions = functionsByBundle[bundle];
|
|
236
260
|
const edits = [];
|
|
237
|
-
for (const [name, hash] of Object.entries(
|
|
261
|
+
for (const [name, hash] of Object.entries(hashes)) {
|
|
238
262
|
const matches = functions.filter(node => node.id?.name === name);
|
|
239
263
|
if (!matches.length)
|
|
240
264
|
continue; // Older carriers have no per-turn additional context.
|
|
@@ -242,6 +266,10 @@ function patchOperationalAdapter(sources, prefix) {
|
|
|
242
266
|
const original = source.slice(node.start, node.end);
|
|
243
267
|
if (matches.length !== 1 || sha256(original) !== hash)
|
|
244
268
|
throw new Error("Unsupported Codex operational context: " + name + "; review before syncing");
|
|
269
|
+
// The newer host's handoff already distinguishes generic policy from independent and
|
|
270
|
+
// parent-local instructions, and retains its own configuration/ownership checks.
|
|
271
|
+
if (splitPersona && (name === "resumeExistingCodexThread" || name === "refreshCodexThreadPolicy"))
|
|
272
|
+
continue;
|
|
245
273
|
let replacement;
|
|
246
274
|
if (name === "resumeExistingCodexThread") {
|
|
247
275
|
replacement = original.replace("await refreshCodexThreadPolicy({", "await refreshCodexThreadPolicy({\n\t\t\tunblockManaged: unblockFrozenPolicy(params.params) !== null,");
|
|
@@ -253,7 +281,7 @@ function patchOperationalAdapter(sources, prefix) {
|
|
|
253
281
|
const originalName = "unblockOriginal" + name;
|
|
254
282
|
const value = name === "buildTurnStartParams" ? "result.additionalContext" : "result";
|
|
255
283
|
const normalized = name === "buildTurnStartParams" ? "{ ...result, additionalContext: unblockNormalizeTurnContext(result.additionalContext) }" : "unblockNormalizeTurnContext(result)";
|
|
256
|
-
replacement =
|
|
284
|
+
replacement = `${node.async ? "async " : ""}function ${name}(params, options) {\n const managed = unblockFrozenPolicy(params) !== null;\n const result = ${node.async ? "await " : ""}${originalName}(params, options);\n return managed && ${value} ? ${normalized} : result;\n}\n` + original.replace(`function ${name}(`, `function ${originalName}(`);
|
|
257
285
|
}
|
|
258
286
|
edits.push({ start: node.start, end: node.end, text: replacement });
|
|
259
287
|
}
|
package/dist/catalog.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { join
|
|
1
|
+
import { join } from "node:path";
|
|
2
2
|
import { parseTOML, getStaticTOMLValue } from "toml-eslint-parser";
|
|
3
|
-
import { readOptional, replaceFile, sha256, withLock } from "./manager.js";
|
|
3
|
+
import { readEnrollment, recordedCodexHome, readOptional, replaceFile, sha256, withLock } from "./manager.js";
|
|
4
|
+
import { agentCodexHome } from "./codex-home.js";
|
|
4
5
|
import { readPromptPointer, setPromptPointer } from "./toml.js";
|
|
5
6
|
export const CATALOG_REFRESH_MS = 24 * 60 * 60 * 1000;
|
|
6
7
|
const KEY = "model_catalog_json";
|
|
7
8
|
function record(value) { return value !== null && typeof value === "object" && !Array.isArray(value); }
|
|
8
|
-
function files(agentDir) {
|
|
9
|
-
const home =
|
|
10
|
-
return {
|
|
9
|
+
async function files(agentDir) {
|
|
10
|
+
const home = agentCodexHome(agentDir);
|
|
11
|
+
return { config: join(await recordedCodexHome(agentDir), "config.toml"), catalog: join(home, "unblock-codex-models.json"), receipt: join(home, ".unblock-codex-catalog.json") };
|
|
11
12
|
}
|
|
12
13
|
function parseReceipt(source) {
|
|
13
14
|
if (source === null)
|
|
@@ -81,7 +82,7 @@ export async function fetchUpstreamCatalog(agentDir, configText, request = fetch
|
|
|
81
82
|
const url = new URL(provider.base_url.replace(/\/$/u, "") + "/models");
|
|
82
83
|
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.hash || url.search)
|
|
83
84
|
throw new Error("Unsupported catalog provider URL");
|
|
84
|
-
const cached = JSON.parse(await readOptional(join(
|
|
85
|
+
const cached = JSON.parse(await readOptional(join(await recordedCodexHome(agentDir), "models_cache.json")) ?? "null");
|
|
85
86
|
if (!record(cached) || typeof cached.client_version !== "string" || !/^\d+\.\d+\.\d+$/u.test(cached.client_version))
|
|
86
87
|
throw new Error("Managed Codex client version missing from its model cache");
|
|
87
88
|
url.searchParams.set("client_version", cached.client_version);
|
|
@@ -121,7 +122,7 @@ export async function fetchUpstreamCatalog(agentDir, configText, request = fetch
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
export async function catalogStatus(agentDir) {
|
|
124
|
-
const path = files(agentDir);
|
|
125
|
+
const path = await files(agentDir);
|
|
125
126
|
const receipt = parseReceipt(await readOptional(path.receipt));
|
|
126
127
|
const text = await readOptional(path.catalog);
|
|
127
128
|
return { enabled: receipt?.active === true, catalogPath: path.catalog, pointerMatches: readPromptPointer(await readOptional(path.config) ?? "", KEY) === path.catalog,
|
|
@@ -130,12 +131,12 @@ export async function catalogStatus(agentDir) {
|
|
|
130
131
|
}
|
|
131
132
|
export async function refreshCatalog(agentDir, options = {}) {
|
|
132
133
|
return withLock({ agentDir, prompt: "" }, async () => {
|
|
133
|
-
const path = files(agentDir);
|
|
134
|
+
const path = await files(agentDir);
|
|
134
135
|
const config = await readOptional(path.config) ?? "";
|
|
135
136
|
const previousReceipt = await readOptional(path.receipt);
|
|
136
137
|
const receipt = parseReceipt(previousReceipt);
|
|
137
|
-
const enrollment =
|
|
138
|
-
if (!
|
|
138
|
+
const enrollment = await readEnrollment(agentDir);
|
|
139
|
+
if (!enrollment?.active || !enrollment.runtimes.includes("codex") || (options.automatic && receipt?.active === false))
|
|
139
140
|
return { skipped: true, changed: false };
|
|
140
141
|
const pointer = readPromptPointer(config, KEY);
|
|
141
142
|
if (pointer !== null && pointer !== path.catalog)
|
|
@@ -159,7 +160,7 @@ export async function refreshCatalog(agentDir, options = {}) {
|
|
|
159
160
|
}
|
|
160
161
|
export async function restoreCatalog(agentDir) {
|
|
161
162
|
return withLock({ agentDir, prompt: "" }, async () => {
|
|
162
|
-
const path = files(agentDir);
|
|
163
|
+
const path = await files(agentDir);
|
|
163
164
|
const source = await readOptional(path.receipt);
|
|
164
165
|
const receipt = parseReceipt(source);
|
|
165
166
|
if (!receipt)
|