@unblocklabs/unblock-codex-prompt 0.6.1 → 0.7.2

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.
@@ -1,4 +1,5 @@
1
- import { type ClaudePolicy } from "./manager.js";
1
+ import { type ClaudePolicy, type StoredPolicy } from "./manager.js";
2
+ import type { CodexModelFamily } from "./model-family.js";
2
3
  export declare function openclawRoot(): Promise<string>;
3
4
  /**
4
5
  * Compile the prompt file and bundle for the enrolled runtimes. Skills are never compiled: both
@@ -9,7 +10,11 @@ export declare function openclawRoot(): Promise<string>;
9
10
  * - Claude only (`base` null): nothing Codex-specific is built. The file holds just the agent
10
11
  * context, so its hash still anchors the bundle and refresh has no prefix to replace.
11
12
  */
12
- export declare function compilePrompt(base: string | null, workspaceDir: string, claude?: ClaudePolicy): Promise<{
13
+ export declare function compilePrompt(base: string | null, workspaceDir: string, claude?: ClaudePolicy, codexPolicies?: {
14
+ default: StoredPolicy;
15
+ gpt62: StoredPolicy;
16
+ primaryFamily: CodexModelFamily;
17
+ }): Promise<{
13
18
  prompt: string;
14
19
  bundle: {
15
20
  claudePolicy: {
@@ -37,12 +42,61 @@ export declare function compilePrompt(base: string | null, workspaceDir: string,
37
42
  checkedAt: number;
38
43
  };
39
44
  agentContext: string;
45
+ codexDefaultPolicy: {
46
+ text: string;
47
+ url: string;
48
+ revision: string;
49
+ checkedAt: number;
50
+ };
51
+ codexGpt62Policy: {
52
+ text: string;
53
+ url: string;
54
+ revision: string;
55
+ checkedAt: number;
56
+ };
57
+ codexPrimaryFamily: CodexModelFamily;
58
+ schema: 1;
59
+ policy: string;
60
+ basePromptLength: number;
61
+ } | {
62
+ claudePolicy?: never;
63
+ agentContext?: never;
64
+ codexDefaultPolicy: {
65
+ text: string;
66
+ url: string;
67
+ revision: string;
68
+ checkedAt: number;
69
+ };
70
+ codexGpt62Policy: {
71
+ text: string;
72
+ url: string;
73
+ revision: string;
74
+ checkedAt: number;
75
+ };
76
+ codexPrimaryFamily: CodexModelFamily;
77
+ schema: 1;
78
+ policy: string;
79
+ basePromptLength: number;
80
+ } | {
81
+ claudePolicy: {
82
+ text: string;
83
+ url: string;
84
+ revision: string;
85
+ checkedAt: number;
86
+ };
87
+ agentContext: string;
88
+ codexDefaultPolicy?: never;
89
+ codexGpt62Policy?: never;
90
+ codexPrimaryFamily?: never;
40
91
  schema: 1;
41
92
  policy: string;
42
93
  basePromptLength: number;
43
94
  } | {
44
95
  claudePolicy?: never;
45
96
  agentContext?: never;
97
+ codexDefaultPolicy?: never;
98
+ codexGpt62Policy?: never;
99
+ codexPrimaryFamily?: never;
46
100
  schema: 1;
47
101
  policy: string;
48
102
  basePromptLength: number;
@@ -50,14 +104,15 @@ export declare function compilePrompt(base: string | null, workspaceDir: string,
50
104
  }>;
51
105
  /**
52
106
  * Everything a sync needs before it may write: every enrolled runtime's policy is fetched first
53
- * (Codex without `runtime`, Claude with runtime=claude). Any failure throws here, so nothing has
54
- * been written.
107
+ * (Codex: standard without `runtime` plus GPT-6.2 with `runtime=codex-gpt-6.2`; Claude: with
108
+ * `runtime=claude`). Any failure throws here, so nothing has been written.
55
109
  */
56
110
  export declare function fetchAndCompile(options: {
57
111
  codex: boolean;
58
112
  claude: boolean;
59
113
  promptUrl: string;
60
114
  workspaceDir: string;
115
+ primaryFamily?: CodexModelFamily;
61
116
  request?: typeof fetch;
62
117
  now?: number;
63
118
  }): Promise<{
@@ -89,12 +144,61 @@ export declare function fetchAndCompile(options: {
89
144
  checkedAt: number;
90
145
  };
91
146
  agentContext: string;
147
+ codexDefaultPolicy: {
148
+ text: string;
149
+ url: string;
150
+ revision: string;
151
+ checkedAt: number;
152
+ };
153
+ codexGpt62Policy: {
154
+ text: string;
155
+ url: string;
156
+ revision: string;
157
+ checkedAt: number;
158
+ };
159
+ codexPrimaryFamily: CodexModelFamily;
160
+ schema: 1;
161
+ policy: string;
162
+ basePromptLength: number;
163
+ } | {
164
+ claudePolicy?: never;
165
+ agentContext?: never;
166
+ codexDefaultPolicy: {
167
+ text: string;
168
+ url: string;
169
+ revision: string;
170
+ checkedAt: number;
171
+ };
172
+ codexGpt62Policy: {
173
+ text: string;
174
+ url: string;
175
+ revision: string;
176
+ checkedAt: number;
177
+ };
178
+ codexPrimaryFamily: CodexModelFamily;
179
+ schema: 1;
180
+ policy: string;
181
+ basePromptLength: number;
182
+ } | {
183
+ claudePolicy: {
184
+ text: string;
185
+ url: string;
186
+ revision: string;
187
+ checkedAt: number;
188
+ };
189
+ agentContext: string;
190
+ codexDefaultPolicy?: never;
191
+ codexGpt62Policy?: never;
192
+ codexPrimaryFamily?: never;
92
193
  schema: 1;
93
194
  policy: string;
94
195
  basePromptLength: number;
95
196
  } | {
96
197
  claudePolicy?: never;
97
198
  agentContext?: never;
199
+ codexDefaultPolicy?: never;
200
+ codexGpt62Policy?: never;
201
+ codexPrimaryFamily?: never;
98
202
  schema: 1;
99
203
  policy: string;
100
204
  basePromptLength: number;
@@ -104,6 +208,19 @@ export declare function fetchAndCompile(options: {
104
208
  url: string;
105
209
  revision: string;
106
210
  } | undefined;
211
+ codexPolicies: {
212
+ primaryFamily: CodexModelFamily;
213
+ default: {
214
+ url: string;
215
+ revision: string;
216
+ checkedAt: number;
217
+ };
218
+ "gpt-6.2": {
219
+ url: string;
220
+ revision: string;
221
+ checkedAt: number;
222
+ };
223
+ } | undefined;
107
224
  claudePolicy: {
108
225
  url: string;
109
226
  revision: string;
package/dist/compiler.js CHANGED
@@ -36,28 +36,48 @@ function agentContextText(workspaceDir) {
36
36
  * - Claude only (`base` null): nothing Codex-specific is built. The file holds just the agent
37
37
  * context, so its hash still anchors the bundle and refresh has no prefix to replace.
38
38
  */
39
- export async function compilePrompt(base, workspaceDir, claude) {
39
+ export async function compilePrompt(base, workspaceDir, claude, codexPolicies) {
40
40
  if (base === null && !claude)
41
41
  throw new Error("compilePrompt needs a Codex base, a Claude policy, or both");
42
42
  const agentContext = agentContextText(workspaceDir);
43
43
  const claudeFields = claude ? { claudePolicy: { ...claude, text: claude.text.trim() }, agentContext } : {};
44
+ const codexFields = codexPolicies ? {
45
+ codexDefaultPolicy: { ...codexPolicies.default, text: codexPolicies.default.text.trim() },
46
+ codexGpt62Policy: { ...codexPolicies.gpt62, text: codexPolicies.gpt62.text.trim() },
47
+ codexPrimaryFamily: codexPolicies.primaryFamily,
48
+ } : {};
44
49
  if (base === null)
45
50
  return { prompt: agentContext, bundle: { schema: 1, policy: "", ...claudeFields } };
46
51
  return { prompt: `${base.trim()}\n\n${agentContext}\n`, bundle: { schema: 1, policy: "",
47
- basePromptLength: base.trim().length, ...claudeFields } };
52
+ basePromptLength: base.trim().length, ...codexFields, ...claudeFields } };
48
53
  }
49
54
  /**
50
55
  * Everything a sync needs before it may write: every enrolled runtime's policy is fetched first
51
- * (Codex without `runtime`, Claude with runtime=claude). Any failure throws here, so nothing has
52
- * been written.
56
+ * (Codex: standard without `runtime` plus GPT-6.2 with `runtime=codex-gpt-6.2`; Claude: with
57
+ * `runtime=claude`). Any failure throws here, so nothing has been written.
53
58
  */
54
59
  export async function fetchAndCompile(options) {
55
60
  const fetchers = policyFetchers(options.promptUrl, options.request);
56
- const [remote, claudeRemote] = await Promise.all([options.codex ? fetchers.codex() : undefined, options.claude ? fetchers.claude() : undefined]);
61
+ const [codexDefaultRemote, codexGpt62Remote, claudeRemote] = await Promise.all([
62
+ options.codex ? fetchers.codex() : undefined,
63
+ options.codex ? fetchers.codexGpt62() : undefined,
64
+ options.claude ? fetchers.claude() : undefined,
65
+ ]);
57
66
  const checkedAt = options.now ?? Date.now();
67
+ const primaryFamily = options.primaryFamily ?? "default";
68
+ const codexDefault = codexDefaultRemote ? { text: codexDefaultRemote.prompt, ...codexDefaultRemote.source, checkedAt } : undefined;
69
+ const codexGpt62 = codexGpt62Remote ? { text: codexGpt62Remote.prompt, ...codexGpt62Remote.source, checkedAt } : undefined;
70
+ const fileRemote = codexDefaultRemote && codexGpt62Remote
71
+ ? (primaryFamily === "gpt-6.2" ? codexGpt62Remote : codexDefaultRemote)
72
+ : codexDefaultRemote;
58
73
  const claudePolicy = claudeRemote ? { text: claudeRemote.prompt, ...claudeRemote.source, checkedAt } : undefined;
59
- const compiled = await compilePrompt(remote?.prompt ?? null, options.workspaceDir, claudePolicy);
60
- if (remote)
61
- Object.assign(compiled.bundle, { remotePrompt: { ...remote.source, checkedAt } });
62
- return { compiled, remote: remote?.source, claudePolicy: claudePolicy && { url: claudePolicy.url, revision: claudePolicy.revision, checkedAt } };
74
+ const compiled = await compilePrompt(fileRemote?.prompt ?? null, options.workspaceDir, claudePolicy, codexDefault && codexGpt62 ? { default: codexDefault, gpt62: codexGpt62, primaryFamily } : undefined);
75
+ if (fileRemote)
76
+ Object.assign(compiled.bundle, { remotePrompt: { ...fileRemote.source, checkedAt } });
77
+ const codexPolicies = codexDefault && codexGpt62 ? {
78
+ primaryFamily,
79
+ default: { url: codexDefault.url, revision: codexDefault.revision, checkedAt },
80
+ "gpt-6.2": { url: codexGpt62.url, revision: codexGpt62.revision, checkedAt },
81
+ } : undefined;
82
+ return { compiled, remote: fileRemote?.source, codexPolicies, claudePolicy: claudePolicy && { url: claudePolicy.url, revision: claudePolicy.revision, checkedAt } };
63
83
  }
package/dist/index.js CHANGED
@@ -10,7 +10,8 @@ import { managedTargetAgent } from "./managed-target.js";
10
10
  import { readClaudeManagedContext, readFrozenPolicy } from "./runtime.js";
11
11
  import { detectConfiguredRuntimes, runtimePolicyResolver } from "./runtimes.js";
12
12
  import { policyFetchers } from "./remote.js";
13
- import { parseClaudePolicy, readOptional } from "./manager.js";
13
+ import { parseClaudePolicy, parseStoredPolicy, readOptional } from "./manager.js";
14
+ import { configuredCodexModelFamily } from "./model-family.js";
14
15
  import { isAbsolute, join } from "node:path";
15
16
  import { CATALOG_REFRESH_MS, catalogStatus, refreshCatalog, restoreCatalog, startCatalogRefresh } from "./catalog.js";
16
17
  import { codexSkillsStatus, refreshCodexSkills, removeCodexSkills } from "./skills.js";
@@ -29,6 +30,27 @@ function claudePolicyReceipt(bundle) {
29
30
  return null;
30
31
  }
31
32
  }
33
+ function codexPoliciesReceipt(bundle) {
34
+ if (!bundle || typeof bundle !== "object")
35
+ return null;
36
+ const parse = (key, label) => {
37
+ if (!(key in bundle))
38
+ return null;
39
+ try {
40
+ const { url, revision, checkedAt } = parseStoredPolicy(bundle[key], label);
41
+ return { url, revision, checkedAt };
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ };
47
+ const standard = parse("codexDefaultPolicy", "Codex default policy");
48
+ const gpt62 = parse("codexGpt62Policy", "Codex GPT-6.2 policy");
49
+ if (!standard && !gpt62)
50
+ return null;
51
+ const primaryFamily = "codexPrimaryFamily" in bundle && bundle.codexPrimaryFamily === "gpt-6.2" ? "gpt-6.2" : "default";
52
+ return { primaryFamily, ...standard ? { default: standard } : {}, ...gpt62 ? { "gpt-6.2": gpt62 } : {} };
53
+ }
32
54
  async function refresh(target, automatic = false) {
33
55
  const failures = [];
34
56
  const enrollment = await readEnrollment(target.agentDir);
@@ -47,8 +69,9 @@ async function refresh(target, automatic = false) {
47
69
  failures.push(refreshFailure("catalog", error));
48
70
  }
49
71
  }
72
+ const primaryFamily = configuredCodexModelFamily(target.config, target.settings.agentId);
50
73
  try {
51
- prompt = await refreshSharedPrompt(target.agentDir, policyFetchers(target.settings.promptUrl));
74
+ prompt = await refreshSharedPrompt(target.agentDir, policyFetchers(target.settings.promptUrl), Date.now(), { primaryFamily });
52
75
  }
53
76
  catch (error) {
54
77
  failures.push(refreshFailure("shared prompt", error));
@@ -150,9 +173,13 @@ async function status(config) {
150
173
  const bundle = await readOptional(join(target.agentDir, "codex-home", ".unblock-codex-prompt-bundle.json"));
151
174
  const receipt = bundle ? JSON.parse(bundle) : null;
152
175
  const remotePrompt = receipt && typeof receipt === "object" && "remotePrompt" in receipt ? receipt.remotePrompt : null;
176
+ const codexPolicies = runtimes.includes("codex") ? codexPoliciesReceipt(receipt) : null;
153
177
  const claudePolicy = runtimes.includes("claude-cli") ? claudePolicyReceipt(receipt) : null;
178
+ const configuredCodexFamily = runtimes.includes("codex") ? configuredCodexModelFamily(config, target.settings.agentId) : undefined;
154
179
  return { ...disk, frozen: true, ready, adapter, error, ...codexConfigError ? { codexConfigError } : {}, ...claude ? { claude } : {},
155
- ...legacyClaudeCore.state !== "absent" ? { legacyClaudeCore } : {}, configuredPromptUrl: target.settings.promptUrl, remotePrompt, ...runtimes.includes("claude-cli") ? { claudePolicy } : {} };
180
+ ...legacyClaudeCore.state !== "absent" ? { legacyClaudeCore } : {}, configuredPromptUrl: target.settings.promptUrl,
181
+ ...configuredCodexFamily ? { configuredCodexFamily } : {}, remotePrompt,
182
+ ...codexPolicies ? { codexPolicies } : {}, ...runtimes.includes("claude-cli") ? { claudePolicy } : {} };
156
183
  }
157
184
  export default definePluginEntry({
158
185
  id: PLUGIN_ID,
@@ -200,8 +227,13 @@ export default definePluginEntry({
200
227
  // The oldest check among the enrolled runtimes' policies decides when the next refresh is due.
201
228
  const remote = result.remotePrompt;
202
229
  const codexChecked = remote && typeof remote === "object" && "checkedAt" in remote && typeof remote.checkedAt === "number" ? remote.checkedAt : 0;
230
+ const codexDefaultChecked = result.codexPolicies?.default?.checkedAt ?? codexChecked;
231
+ const codexGpt62Checked = result.codexPolicies?.["gpt-6.2"]?.checkedAt ?? codexChecked;
203
232
  const claudeChecked = result.claudePolicy?.checkedAt ?? 0;
204
- const checkedAt = Math.min(...[codex ? codexChecked : Infinity, result.claudePolicy !== undefined ? claudeChecked : Infinity]);
233
+ const checkedAt = Math.min(...[
234
+ codex ? Math.min(codexChecked, codexDefaultChecked, codexGpt62Checked) : Infinity,
235
+ result.claudePolicy !== undefined ? claudeChecked : Infinity,
236
+ ]);
205
237
  const nextAt = Math.min(codex && target.settings.suppressExplicitDelegationPrompt ? catalog?.nextRefreshAt ?? 0 : Infinity, checkedAt ? checkedAt + CATALOG_REFRESH_MS : 0, Date.now() + CATALOG_REFRESH_MS);
206
238
  stopCatalogRefresh = startCatalogRefresh(async () => {
207
239
  const refreshed = await refresh(target, true);
@@ -312,10 +344,11 @@ export default definePluginEntry({
312
344
  catch (error) {
313
345
  throw new Error(`Cannot remove the 0.4 Claude CLI core patch: ${errorMessage(error)}`);
314
346
  }
315
- // Every enrolled runtime's policy is fetched before anything is written: Codex without
316
- // `runtime` (any Worker version), Claude with runtime=claude. Claude-only never reads the
317
- // Codex artifact. Skills are not compiled: both runtimes get the session catalog live.
318
- const { compiled, remote, claudePolicy } = await fetchAndCompile({ codex, claude, promptUrl: target.settings.promptUrl, workspaceDir: target.workspaceDir });
347
+ // Every enrolled runtime's policy is fetched before anything is written: Codex fetches both
348
+ // standard (no `runtime`) and GPT-6.2 (`runtime=codex-gpt-6.2`); Claude fetches `runtime=claude`.
349
+ // Claude-only never reads Codex artifacts. Skills are not compiled: both runtimes get the session catalog live.
350
+ const primaryFamily = configuredCodexModelFamily(config, target.settings.agentId);
351
+ const { compiled, remote, codexPolicies, claudePolicy } = await fetchAndCompile({ codex, claude, promptUrl: target.settings.promptUrl, workspaceDir: target.workspaceDir, primaryFamily });
319
352
  const runtimes = [...codex ? ["codex"] : [], ...claude ? ["claude-cli"] : []];
320
353
  const result = await syncPrompt({ ...target, ...compiled, ...codexHome ? { codexHome } : {} }, { adopt: options.adopt === true, runtimes });
321
354
  const adapter = codexPlan ? await installAdapter(target.agentDir, codexPlan) : undefined;
@@ -326,7 +359,7 @@ export default definePluginEntry({
326
359
  ? `${result.activation} The 0.4 Claude CLI patch was removed from OpenClaw core: restart the Gateway to reload the restored core.`
327
360
  : result.activation;
328
361
  console.log(JSON.stringify({ ...result, activation, adapter, detection: { resolver: detection.resolver, models: detection.detections },
329
- ...remote ? { remotePrompt: remote } : {}, ...claudePolicy ? { claudePolicy } : {}, catalog, codexSkills,
362
+ ...remote ? { remotePrompt: remote } : {}, ...codexPolicies ? { codexPolicies } : {}, ...claudePolicy ? { claudePolicy } : {}, catalog, codexSkills,
330
363
  ...legacyClaudeCoreRestored ? { legacyClaudeCoreRestored, restartRequired: true } : {} }, null, 2));
331
364
  });
332
365
  root.command("restore").description("Restore owned prompt components; pause automatic management and retain files")
package/dist/manager.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { CodexModelFamily } from "./model-family.js";
1
2
  export declare const RUNTIMES: readonly ["codex", "claude-cli"];
2
3
  export type ManagedRuntime = typeof RUNTIMES[number];
3
4
  /** previousPointer is Codex's original model_instructions_file; unused by Claude-only enrollment. */
@@ -13,14 +14,16 @@ export type PolicyReceipt = {
13
14
  revision: string;
14
15
  checkedAt: number;
15
16
  };
16
- export type ClaudePolicy = PolicyReceipt & {
17
+ export type StoredPolicy = PolicyReceipt & {
17
18
  text: string;
18
19
  };
20
+ export type ClaudePolicy = StoredPolicy;
19
21
  /**
20
22
  * `policy` stays "" (0.3 runtimes require the field; they read only `schema`, `policy` and
21
- * `promptSha256`). The Codex policy is the prompt-file prefix, with `basePromptLength` and
22
- * `remotePrompt` describing it. Claude's policy and the shared agent context live in the bundle
23
- * itself, so Claude never reads the Codex artifact.
23
+ * `promptSha256`). The primary Codex policy is the prompt-file prefix, with `basePromptLength`
24
+ * and `remotePrompt` describing it. Both Codex model-family policies (`codexDefaultPolicy`,
25
+ * `codexGpt62Policy`) and Claude's policy live in the bundle so each turn picks the right
26
+ * artifact for its active model without re-syncing.
24
27
  */
25
28
  export type FrozenBundle = {
26
29
  schema: 1;
@@ -31,6 +34,9 @@ export type FrozenBundle = {
31
34
  revision: string;
32
35
  checkedAt?: number;
33
36
  };
37
+ codexDefaultPolicy?: StoredPolicy;
38
+ codexGpt62Policy?: StoredPolicy;
39
+ codexPrimaryFamily?: CodexModelFamily;
34
40
  claudePolicy?: ClaudePolicy;
35
41
  agentContext?: string;
36
42
  };
@@ -42,6 +48,8 @@ export declare const MEMORY_REFERENCE_HEADER = "\n\n## Memory reference\n";
42
48
  */
43
49
  export declare const CONTEXT_BOUNDARY_HEADERS: readonly ["\n\n## Memory reference\n", "\n\n## Agent context\n", "\n\n## Frozen agent context\n"];
44
50
  export declare function isCodexPolicyBoundary(prompt: string, boundary: unknown): boundary is number;
51
+ /** Strict shape check for a stored policy; throws on anything else. */
52
+ export declare function parseStoredPolicy(value: unknown, label?: string): StoredPolicy;
45
53
  /** Strict shape check for a stored Claude policy; throws on anything else. */
46
54
  export declare function parseClaudePolicy(value: unknown): ClaudePolicy;
47
55
  export type PromptTarget = {
@@ -126,13 +134,17 @@ export type FetchedPolicy = () => Promise<{
126
134
  */
127
135
  export declare function refreshSharedPrompt(agentDir: string, fetchers: {
128
136
  codex?: FetchedPolicy;
137
+ codexGpt62?: FetchedPolicy;
129
138
  claude?: FetchedPolicy;
130
- }, now?: number): Promise<{
139
+ }, now?: number, options?: {
140
+ primaryFamily?: CodexModelFamily;
141
+ }): Promise<{
131
142
  changed: boolean;
132
143
  skipped: boolean;
133
144
  } | {
134
145
  claudeRevision?: string;
135
146
  nextClaudeProcess?: boolean;
147
+ codexGpt62Revision?: string;
136
148
  revision?: string;
137
149
  nextCodexTurn?: boolean;
138
150
  changed: boolean;
package/dist/manager.js CHANGED
@@ -16,14 +16,18 @@ export function isCodexPolicyBoundary(prompt, boundary) {
16
16
  CONTEXT_BOUNDARY_HEADERS.some(header => prompt.startsWith(header, boundary));
17
17
  }
18
18
  function record(value) { return !!value && typeof value === "object" && !Array.isArray(value); }
19
- /** Strict shape check for a stored Claude policy; throws on anything else. */
20
- export function parseClaudePolicy(value) {
19
+ /** Strict shape check for a stored policy; throws on anything else. */
20
+ export function parseStoredPolicy(value, label = "Stored policy") {
21
21
  if (!record(value) || typeof value.text !== "string" || !value.text.trim() || typeof value.url !== "string" || !value.url ||
22
22
  typeof value.revision !== "string" || !value.revision || typeof value.checkedAt !== "number" || !Number.isFinite(value.checkedAt)) {
23
- throw new Error("Claude policy missing or invalid; run codex-prompt sync");
23
+ throw new Error(`${label} missing or invalid; run codex-prompt sync`);
24
24
  }
25
25
  return { text: value.text, url: value.url, revision: value.revision, checkedAt: value.checkedAt };
26
26
  }
27
+ /** Strict shape check for a stored Claude policy; throws on anything else. */
28
+ export function parseClaudePolicy(value) {
29
+ return parseStoredPolicy(value, "Claude policy");
30
+ }
27
31
  function paths(agentDir) {
28
32
  const home = agentCodexHome(agentDir);
29
33
  return {
@@ -264,7 +268,7 @@ export async function restorePrompt(target) {
264
268
  * older sync keeps its frozen skills catalog tail until the next sync rewrites the file;
265
269
  * - Claude: only `claudePolicy` in the bundle is replaced; the prompt file is not touched for it.
266
270
  */
267
- export async function refreshSharedPrompt(agentDir, fetchers, now = Date.now()) {
271
+ export async function refreshSharedPrompt(agentDir, fetchers, now = Date.now(), options = {}) {
268
272
  const target = { agentDir, prompt: "" };
269
273
  return withLock(target, async () => {
270
274
  const s = await snapshot(target);
@@ -291,26 +295,55 @@ export async function refreshSharedPrompt(agentDir, fetchers, now = Date.now())
291
295
  if (typeof bundle.agentContext !== "string" || !bundle.agentContext.trim())
292
296
  throw new Error("Valid enrolled remote snapshot required; run codex-prompt sync");
293
297
  }
298
+ let previousCodexDefault;
299
+ if (codex && "codexDefaultPolicy" in bundle && bundle.codexDefaultPolicy !== undefined) {
300
+ try {
301
+ previousCodexDefault = parseStoredPolicy(bundle.codexDefaultPolicy, "Codex default policy");
302
+ }
303
+ catch {
304
+ throw new Error("Valid enrolled remote snapshot required; run codex-prompt sync");
305
+ }
306
+ }
307
+ let previousCodexGpt62;
308
+ if (codex && "codexGpt62Policy" in bundle && bundle.codexGpt62Policy !== undefined) {
309
+ try {
310
+ previousCodexGpt62 = parseStoredPolicy(bundle.codexGpt62Policy, "Codex GPT-6.2 policy");
311
+ }
312
+ catch {
313
+ throw new Error("Valid enrolled remote snapshot required; run codex-prompt sync");
314
+ }
315
+ }
294
316
  // Every remote snapshot records its prefix length (0.1.0 onwards); the agent context after it
295
317
  // starts with one of the accepted boundary headings (current, 0.4 branch or 0.3).
296
318
  const boundary = bundle.basePromptLength;
297
319
  if (codex && !isCodexPolicyBoundary(s.prompt, boundary)) {
298
320
  throw new Error("Frozen context boundary is ambiguous; run codex-prompt sync");
299
321
  }
300
- const [codexRemote, claudeRemote] = await Promise.all([codex ? fetchers.codex?.() : undefined, claude ? fetchers.claude?.() : undefined]);
322
+ const [codexRemote, codexGpt62Remote, claudeRemote] = await Promise.all([
323
+ codex ? fetchers.codex?.() : undefined,
324
+ codex ? fetchers.codexGpt62?.() : undefined,
325
+ claude ? fetchers.claude?.() : undefined,
326
+ ]);
301
327
  if ((codex && !codexRemote) || (claude && !claudeRemote))
302
328
  throw new Error("Invalid shared prompt revision");
303
- for (const remote of [codexRemote, claudeRemote]) {
329
+ for (const remote of [codexRemote, codexGpt62Remote, claudeRemote]) {
304
330
  if (remote && (!remote.prompt.trim() || remote.source.revision !== sha256(remote.prompt)))
305
331
  throw new Error("Invalid shared prompt revision");
306
332
  }
307
333
  if (await readOptional(s.files.config) !== s.config || await readOptional(s.files.state) !== s.state)
308
334
  throw new Error("Enrollment or configuration changed during refresh");
309
- const prompt = codexRemote ? codexRemote.prompt.trim() + s.prompt.slice(boundary) : s.prompt;
335
+ const primaryFamily = options.primaryFamily ?? (bundle.codexPrimaryFamily === "gpt-6.2" ? "gpt-6.2" : "default");
336
+ const fileRemote = codexRemote ? (primaryFamily === "gpt-6.2" && codexGpt62Remote ? codexGpt62Remote : codexRemote) : undefined;
337
+ const prompt = fileRemote ? fileRemote.prompt.trim() + s.prompt.slice(boundary) : s.prompt;
338
+ const codexDefaultPolicy = codexRemote ? { text: codexRemote.prompt.trim(), url: codexRemote.source.url,
339
+ revision: codexRemote.source.revision, checkedAt: now } : undefined;
340
+ const codexGpt62Policy = codexGpt62Remote ? { text: codexGpt62Remote.prompt.trim(), url: codexGpt62Remote.source.url,
341
+ revision: codexGpt62Remote.source.revision, checkedAt: now } : undefined;
310
342
  const claudePolicy = claudeRemote ? { text: claudeRemote.prompt.trim(), url: claudeRemote.source.url,
311
343
  revision: claudeRemote.source.revision, checkedAt: now } : undefined;
312
344
  const nextBundle = `${JSON.stringify({ ...bundle,
313
- ...codexRemote ? { basePromptLength: codexRemote.prompt.trim().length, remotePrompt: { ...codexRemote.source, checkedAt: now } } : {},
345
+ ...fileRemote ? { basePromptLength: fileRemote.prompt.trim().length, remotePrompt: { ...fileRemote.source, checkedAt: now } } : {},
346
+ ...codexDefaultPolicy && codexGpt62Policy ? { codexDefaultPolicy, codexGpt62Policy, codexPrimaryFamily: primaryFamily } : {},
314
347
  ...claudePolicy ? { claudePolicy } : {}, promptSha256: sha256(prompt) }, null, 2)}\n`;
315
348
  const changed = await replaceFile(s.files.prompt, s.prompt, prompt);
316
349
  try {
@@ -322,11 +355,15 @@ export async function refreshSharedPrompt(agentDir, fetchers, now = Date.now())
322
355
  await replaceFile(s.files.prompt, prompt, s.prompt);
323
356
  throw error;
324
357
  }
358
+ const codexDefaultChanged = codexDefaultPolicy !== undefined && previousCodexDefault !== undefined && codexDefaultPolicy.text !== previousCodexDefault.text;
359
+ const codexGpt62Changed = codexGpt62Policy !== undefined && (previousCodexGpt62 === undefined || codexGpt62Policy.text !== previousCodexGpt62.text);
360
+ const codexChanged = changed || codexDefaultChanged || codexGpt62Changed;
325
361
  const claudeChanged = claudePolicy !== undefined && claudePolicy.text !== previousClaude?.text;
326
362
  // Codex's reviewed bridge resends the base file as each thread's base instructions, so a change
327
363
  // re-syncs existing threads on their next turn; Claude's prompt hook reads the policy every turn.
328
- return { changed: changed || claudeChanged, checkedAt: now,
329
- ...codexRemote ? { revision: codexRemote.source.revision, nextCodexTurn: changed } : {},
364
+ return { changed: codexChanged || claudeChanged, checkedAt: now,
365
+ ...fileRemote ? { revision: fileRemote.source.revision, nextCodexTurn: codexChanged } : {},
366
+ ...codexGpt62Remote ? { codexGpt62Revision: codexGpt62Remote.source.revision } : {},
330
367
  ...claudeRemote ? { claudeRevision: claudeRemote.source.revision, nextClaudeProcess: claudeChanged } : {} };
331
368
  });
332
369
  }
@@ -0,0 +1,9 @@
1
+ export type CodexModelFamily = "default" | "gpt-6.2";
2
+ /** Primary model ref configured for an agent in openclaw.json (agent override, else defaults). */
3
+ export declare function primaryConfiguredModel(config: unknown, agentId: string): string | undefined;
4
+ /**
5
+ * Strip any provider prefix (e.g. `openai/gpt-6.2-astra` -> `gpt-6.2-astra`) and classify
6
+ * whether a Codex model belongs to the GPT-6.2 family (`gpt-6.2`, `gpt-6.2-astra`, `gpt-6.2-sol`, ...).
7
+ */
8
+ export declare function classifyCodexModel(modelId: unknown): CodexModelFamily;
9
+ export declare function configuredCodexModelFamily(config: unknown, agentId: string): CodexModelFamily;
@@ -0,0 +1,41 @@
1
+ function record(value) {
2
+ return !!value && typeof value === "object" && !Array.isArray(value);
3
+ }
4
+ function agentEntry(config, agentId) {
5
+ const agents = record(config) ? config.agents : undefined;
6
+ if (!record(agents))
7
+ return undefined;
8
+ if (Array.isArray(agents.list)) {
9
+ const entry = agents.list.find((item) => record(item) && item.id === agentId);
10
+ return record(entry) ? entry : undefined;
11
+ }
12
+ return record(agents.entries) && record(agents.entries[agentId]) ? agents.entries[agentId] : undefined;
13
+ }
14
+ function primaryOf(model) {
15
+ const value = typeof model === "string" ? model : record(model) ? model.primary : undefined;
16
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
17
+ }
18
+ /** Primary model ref configured for an agent in openclaw.json (agent override, else defaults). */
19
+ export function primaryConfiguredModel(config, agentId) {
20
+ const agents = record(config) ? config.agents : undefined;
21
+ const defaults = record(agents) && record(agents.defaults) ? agents.defaults : undefined;
22
+ const agent = agentEntry(config, agentId);
23
+ return primaryOf(agent?.model) ?? primaryOf(defaults?.model);
24
+ }
25
+ /**
26
+ * Strip any provider prefix (e.g. `openai/gpt-6.2-astra` -> `gpt-6.2-astra`) and classify
27
+ * whether a Codex model belongs to the GPT-6.2 family (`gpt-6.2`, `gpt-6.2-astra`, `gpt-6.2-sol`, ...).
28
+ */
29
+ export function classifyCodexModel(modelId) {
30
+ if (typeof modelId !== "string")
31
+ return "default";
32
+ const trimmed = modelId.trim();
33
+ if (!trimmed)
34
+ return "default";
35
+ const slash = trimmed.lastIndexOf("/");
36
+ const bare = (slash >= 0 ? trimmed.slice(slash + 1) : trimmed).trim();
37
+ return /^gpt-6\.2(?:$|[-_.@])/iu.test(bare) ? "gpt-6.2" : "default";
38
+ }
39
+ export function configuredCodexModelFamily(config, agentId) {
40
+ return classifyCodexModel(primaryConfiguredModel(config, agentId));
41
+ }
@@ -18,6 +18,8 @@ const SAFE_CAUSES = new Set([
18
18
  "Frozen context boundary is ambiguous; run codex-prompt sync",
19
19
  "Prompt endpoint returned HTTP 400 for runtime=claude; deploy the fleet-prompt Worker with runtime support first",
20
20
  "Prompt endpoint did not confirm runtime=claude; deploy the fleet-prompt Worker with runtime support first",
21
+ "Prompt endpoint returned HTTP 400 for runtime=codex-gpt-6.2; deploy the fleet-prompt Worker with runtime support first",
22
+ "Prompt endpoint did not confirm runtime=codex-gpt-6.2; deploy the fleet-prompt Worker with runtime support first",
21
23
  "Prompt endpoint must return plain text", "Prompt exceeds 256 KiB limit",
22
24
  "Prompt is empty or contains NUL bytes", "Prompt revision does not match response body",
23
25
  "The managed codex skills block in config.toml is damaged; restore its BEGIN/END markers or remove it",
package/dist/remote.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  export declare const WORKER_RUNTIME_HINT = "deploy the fleet-prompt Worker with runtime support first";
2
+ export type RemoteRuntime = "claude" | "codex-gpt-6.2";
2
3
  /**
3
4
  * Explicit sync and daily shared-prompt refresh validate before changing local state.
4
- * Without `runtime` the configured URL is fetched exactly as written (the Codex artifact, which
5
- * every Worker version serves). `runtime: "claude"` adds the parameter with the URL API, keeping
6
- * `channel` and any other parameters, and requires the Worker to confirm it in X-Prompt-Runtime.
5
+ * Without `runtime` the configured URL is fetched exactly as written (the standard Codex artifact,
6
+ * which every Worker version serves). Passing `runtime` (`claude` or `codex-gpt-6.2`) adds the
7
+ * parameter with the URL API, keeping `channel` and any other parameters, and requires the Worker
8
+ * to confirm it in X-Prompt-Runtime.
7
9
  */
8
10
  export declare function fetchPrompt(url: string, request?: typeof fetch, options?: {
9
- runtime?: "claude";
11
+ runtime?: RemoteRuntime;
10
12
  }): Promise<{
11
13
  prompt: string;
12
14
  source: {
@@ -14,7 +16,7 @@ export declare function fetchPrompt(url: string, request?: typeof fetch, options
14
16
  revision: string;
15
17
  };
16
18
  }>;
17
- /** Per-runtime fetchers for one configured promptUrl; Codex never sends `runtime`. */
19
+ /** Per-runtime fetchers for one configured promptUrl; standard Codex never sends `runtime`. */
18
20
  export declare function policyFetchers(url: string, request?: typeof fetch): {
19
21
  codex: () => Promise<{
20
22
  prompt: string;
@@ -23,6 +25,13 @@ export declare function policyFetchers(url: string, request?: typeof fetch): {
23
25
  revision: string;
24
26
  };
25
27
  }>;
28
+ codexGpt62: () => Promise<{
29
+ prompt: string;
30
+ source: {
31
+ url: string;
32
+ revision: string;
33
+ };
34
+ }>;
26
35
  claude: () => Promise<{
27
36
  prompt: string;
28
37
  source: {
package/dist/remote.js CHANGED
@@ -4,9 +4,10 @@ const MAX_BYTES = 256 * 1024;
4
4
  export const WORKER_RUNTIME_HINT = "deploy the fleet-prompt Worker with runtime support first";
5
5
  /**
6
6
  * Explicit sync and daily shared-prompt refresh validate before changing local state.
7
- * Without `runtime` the configured URL is fetched exactly as written (the Codex artifact, which
8
- * every Worker version serves). `runtime: "claude"` adds the parameter with the URL API, keeping
9
- * `channel` and any other parameters, and requires the Worker to confirm it in X-Prompt-Runtime.
7
+ * Without `runtime` the configured URL is fetched exactly as written (the standard Codex artifact,
8
+ * which every Worker version serves). Passing `runtime` (`claude` or `codex-gpt-6.2`) adds the
9
+ * parameter with the URL API, keeping `channel` and any other parameters, and requires the Worker
10
+ * to confirm it in X-Prompt-Runtime.
10
11
  */
11
12
  export async function fetchPrompt(url, request = fetch, options = {}) {
12
13
  const target = validatePromptUrl(url);
@@ -55,7 +56,11 @@ export async function fetchPrompt(url, request = fetch, options = {}) {
55
56
  throw new Error("Prompt revision does not match response body");
56
57
  return { prompt, source: { url: options.runtime ? target.href : url, revision } };
57
58
  }
58
- /** Per-runtime fetchers for one configured promptUrl; Codex never sends `runtime`. */
59
+ /** Per-runtime fetchers for one configured promptUrl; standard Codex never sends `runtime`. */
59
60
  export function policyFetchers(url, request) {
60
- return { codex: () => fetchPrompt(url, request), claude: () => fetchPrompt(url, request, { runtime: "claude" }) };
61
+ return {
62
+ codex: () => fetchPrompt(url, request),
63
+ codexGpt62: () => fetchPrompt(url, request, { runtime: "codex-gpt-6.2" }),
64
+ claude: () => fetchPrompt(url, request, { runtime: "claude" }),
65
+ };
61
66
  }