sneakoscope 10.6.2 → 10.7.1
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 +28 -6
- package/config/perf-budgets.v1.json +1 -2
- package/config/skills-hash-ledger.v1.json +7 -2
- package/crates/sks-core/Cargo.lock +1 -1
- package/crates/sks-core/Cargo.toml +1 -1
- package/dist/bin/sks-dispatch.js +6 -3
- package/dist/cli/args.js +3 -1
- package/dist/cli/command-manifest-lite.js +48 -114
- package/dist/cli/command-registry.js +1 -18
- package/dist/cli/commands-fast.js +11 -4
- package/dist/cli/help-fast.js +11 -22
- package/dist/cli/help.js +3 -3
- package/dist/cli/install-helpers-codex-lb-config.js +11 -8
- package/dist/cli/install-helpers.js +1 -1
- package/dist/cli/router.js +12 -26
- package/dist/commands/codex-app.js +2 -2
- package/dist/commands/doctor-helpers.js +1 -1
- package/dist/commands/mad-sks.js +2 -2
- package/dist/config/skills-manifest.json +13 -8
- package/dist/core/agent-bridge/async-command.js +2 -2
- package/dist/core/agents/agent-recursion-guard.js +0 -2
- package/dist/core/agents/agent-role-config.js +6 -2
- package/dist/core/agents/sks-model-pin-hygiene.js +150 -0
- package/dist/core/auto-review.js +15 -172
- package/dist/core/code-structure.js +0 -1
- package/dist/core/codex/codex-config-guard.js +18 -13
- package/dist/core/codex-app/codex-app-ui-state-snapshot.js +7 -1
- package/dist/core/codex-control/codex-reliability-shield.js +64 -15
- package/dist/core/codex-control/codex-sdk-adapter.js +38 -5
- package/dist/core/codex-lb/bridge-contracts.js +5 -0
- package/dist/core/codex-lb/combined-catalog/builder.js +4 -2
- package/dist/core/codex-lb/combined-catalog/latest-generation.js +7 -34
- package/dist/core/codex-lb/combined-catalog/normalize.js +3 -1
- package/dist/core/codex-lb/desktop-bridge/codex-lb-turn-state.js +35 -0
- package/dist/core/codex-lb/desktop-bridge/compaction-adapter.js +3 -0
- package/dist/core/codex-lb/desktop-bridge/header-policy.js +10 -4
- package/dist/core/codex-lb/desktop-bridge/http-forward.js +92 -30
- package/dist/core/codex-lb/desktop-bridge/provider-handoff.js +79 -0
- package/dist/core/codex-lb/desktop-bridge/responses-websocket.js +57 -13
- package/dist/core/codex-lb/desktop-bridge/security.js +101 -55
- package/dist/core/codex-lb/desktop-bridge/server.js +10 -2
- package/dist/core/codex-lb/desktop-bridge/types.js +3 -0
- package/dist/core/codex-lb/desktop-bridge/websocket-forward.js +3 -0
- package/dist/core/codex-lb/desktop-controller-v3/catalog.js +13 -0
- package/dist/core/codex-lb/desktop-controller-v3/provider-commands.js +0 -9
- package/dist/core/codex-lb/desktop-service.js +10 -13
- package/dist/core/codex-lb/request-route-resolver.js +1 -1
- package/dist/core/codex-runtime/codex-desktop-config-policy.js +0 -1
- package/dist/core/commands/agent-bridge-command.js +1 -1
- package/dist/core/commands/basic-cli.js +60 -233
- package/dist/core/commands/command-utils.js +1 -1
- package/dist/core/commands/gc-command.js +30 -29
- package/dist/core/commands/image-ux-review-command.js +1 -1
- package/dist/core/commands/install-package-command.js +1 -1
- package/dist/core/commands/intent-normalization/normalizer.js +2 -2
- package/dist/core/commands/pipeline-command.js +13 -5
- package/dist/core/commands/plan-command.js +2 -3
- package/dist/core/commands/research-command.js +0 -3
- package/dist/core/commands/review-command.js +1 -1
- package/dist/core/commands/seo-command.js +27 -20
- package/dist/core/commands/status-command.js +8 -2
- package/dist/core/doctor/command-alias-cleanup.js +6 -6
- package/dist/core/evaluation.js +1 -1
- package/dist/core/feature-fixtures.js +9 -43
- package/dist/core/feature-registry.js +9 -27
- package/dist/core/git-hygiene/shared-memory-publish.js +1 -1
- package/dist/core/hooks-runtime/jev-spawn-routing.js +1 -5
- package/dist/core/hooks-runtime/parent-orchestration-gate.js +6 -8
- package/dist/core/hooks-runtime/stop-repeat-guard.js +0 -13
- package/dist/core/hooks-runtime.js +13 -9
- package/dist/core/init/skills.js +27 -16
- package/dist/core/init.js +0 -9
- package/dist/core/install/installed-package-smoke.js +3 -1
- package/dist/core/perf/import-graph-budget.js +0 -1
- package/dist/core/perf/release-latency-slo.js +2 -30
- package/dist/core/pipeline-internals/pipeline-stage-builder.js +2 -4
- package/dist/core/pipeline-internals/runtime-core.js +2 -38
- package/dist/core/proof/route-proof-policy.js +2 -4
- package/dist/core/proof/runtime-truth-matrix.js +2 -2
- package/dist/core/proof-field.js +104 -39
- package/dist/core/provider/provider-context.js +4 -1
- package/dist/core/questions.js +11 -7
- package/dist/core/release/gate-affected-globs.js +0 -2
- package/dist/core/research/research-reviewer-contract.js +34 -0
- package/dist/core/research/research-work-graph.js +1 -1
- package/dist/core/research.js +1 -1
- package/dist/core/routes/constants.js +0 -1
- package/dist/core/routes/diagnostic-allowlist.js +1 -3
- package/dist/core/routes/light-routes.js +1 -2
- package/dist/core/routes.js +1 -1
- package/dist/core/safety/command-contract/contracts.js +5 -1
- package/dist/core/search/context.js +2 -2
- package/dist/core/search-visibility/marketing-truthfulness.js +10 -7
- package/dist/core/search-visibility/marketing.js +194 -149
- package/dist/core/skill-forge.js +1 -361
- package/dist/core/strategy/adhd-orchestrating-gate.js +3 -3
- package/dist/core/triwiki/context-graph/extractors/topology/commands.js +2 -6
- package/dist/core/triwiki-wrongness/wrongness-cli.js +9 -27
- package/dist/core/update/update-migration-state.js +10 -40
- package/dist/core/version.js +1 -1
- package/package.json +2 -3
- package/release-gates.v2.json +1 -32
- package/dist/cli/recallpulse-command.js +0 -144
- package/dist/commands/auto-review.js +0 -5
- package/dist/commands/codex-native.js +0 -77
- package/dist/commands/recallpulse.js +0 -5
- package/dist/core/codex-native/codex-native-interop-policy.js +0 -127
- package/dist/core/commands/autoresearch-command.js +0 -4
- package/dist/core/commands/code-structure-command.js +0 -52
- package/dist/core/commands/goal-command.js +0 -43
- package/dist/core/commands/recallpulse-command.js +0 -4
- package/dist/core/commands/remote-command.js +0 -119
- package/dist/core/commands/skill-dream-command.js +0 -43
- package/dist/core/commands/wrongness-command.js +0 -2
- package/dist/core/goal-workflow.js +0 -80
- package/dist/core/mcp/mcp-tool-name-normalizer.js +0 -28
- package/dist/core/recallpulse/policy.js +0 -207
- package/dist/core/recallpulse.js +0 -947
- package/dist/core/remote/audit-idempotency.js +0 -241
- package/dist/core/remote/index.js +0 -10
- package/dist/core/remote/machine-registry.js +0 -167
- package/dist/core/remote/owner-proof.js +0 -216
- package/dist/core/remote/protocol.js +0 -249
- package/dist/core/remote/readiness.js +0 -156
- package/dist/core/remote/session-index.js +0 -61
- package/dist/core/remote/session-snapshot.js +0 -197
- package/dist/core/remote/ssh-worker-client.js +0 -377
- package/dist/core/remote/types.js +0 -10
- package/dist/core/remote/worker.js +0 -360
- package/dist/core/search/context-graph-seeds.js +0 -15
- package/dist/core/verification/context-graph-affected.js +0 -312
- package/dist/core/verification/verification-artifact-lock.js +0 -21
- package/dist/core/verification/verification-dag.js +0 -89
- package/dist/core/verification/verification-result.js +0 -19
- package/dist/core/verification/verification-worker-pool.js +0 -204
package/dist/core/auto-review.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import { ensureDir,
|
|
4
|
+
import { ensureDir, readText, writeTextAtomic } from './fsx.js';
|
|
5
5
|
import { writeCodexConfigGuarded } from './codex/codex-config-guard.js';
|
|
6
6
|
import { CODEX_FAST_SERVICE_TIER_ID } from './codex/codex-service-tier.js';
|
|
7
7
|
import { inspectConfinedPath, removeManagedPathVerified } from './managed-path-safety.js';
|
|
@@ -9,42 +9,9 @@ import { RETIRED_AUTO_REVIEW_POLICY_TEXTS, RETIRED_SKS_CONFIG_PROFILE_NAMES } fr
|
|
|
9
9
|
import { escapeRegExp } from './text/regex.js';
|
|
10
10
|
export { RETIRED_SKS_CONFIG_PROFILE_NAMES } from './doctor/retired-auto-review-config.js';
|
|
11
11
|
export const AUTO_REVIEW_REVIEWER = 'auto_review';
|
|
12
|
-
export const LEGACY_AUTO_REVIEW_REVIEWER = 'guardian_subagent';
|
|
13
|
-
export const AUTO_REVIEW_PROFILE = 'sks-auto-review';
|
|
14
|
-
export const AUTO_REVIEW_HIGH_PROFILE = 'sks-auto-review-high';
|
|
15
12
|
export const MAD_HIGH_PROFILE = 'sks-mad-high';
|
|
13
|
+
const LEGACY_AUTO_REVIEW_REVIEWER = 'guardian_subagent';
|
|
16
14
|
export const AUTO_REVIEW_POLICY_TEXT = 'In MAD-SKS launches, allow only scoped high-risk work approved for the active invocation and keep catastrophic DB wipe/all-row safeguards active. The explicit $MAD-SKS or sks mad-sks sql|apply-migration invocation is the SQL-plane approval boundary: execute requested execute_sql/apply_migration mutations with mission-local write transport, read-back proof, and final read-only restoration. Supabase project/account/billing/credential control-plane actions remain denied.';
|
|
17
|
-
export const REVIEW_NATIVE_AGENT_PLAN = Object.freeze({
|
|
18
|
-
schema: 'sks.review-native-agent-plan.v1',
|
|
19
|
-
backend: 'native_multi_session_agent_kernel',
|
|
20
|
-
central_ledger: 'agents/agent-events.jsonl',
|
|
21
|
-
personas: [
|
|
22
|
-
{
|
|
23
|
-
id: 'review_safety',
|
|
24
|
-
role: 'safety',
|
|
25
|
-
label: 'Review Safety',
|
|
26
|
-
read_only: true,
|
|
27
|
-
mandate: 'Review permission, DB, destructive action, and unrequested fallback risks before approval.'
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
id: 'review_verifier',
|
|
31
|
-
role: 'verifier',
|
|
32
|
-
label: 'Review Verifier',
|
|
33
|
-
read_only: true,
|
|
34
|
-
mandate: 'Check claims, tests, and route evidence before approval.'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: 'review_integrator',
|
|
38
|
-
role: 'integrator',
|
|
39
|
-
label: 'Review Integrator',
|
|
40
|
-
read_only: true,
|
|
41
|
-
mandate: 'Close approval only after ledger, session cleanup, and proof graph pass.'
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
safety_personas_read_only_by_default: true,
|
|
45
|
-
manual_agent_count_syntax: 'sks auto-review fixture --json and sks naruto run "$Review <review task>" --agents 5 --max-threads 4 --json',
|
|
46
|
-
dynamic_effort: 'parent assigns high effort to safety/integrator lanes and medium or higher to verification lanes when proof risk is present'
|
|
47
|
-
});
|
|
48
15
|
export function codexHome(env = process.env) {
|
|
49
16
|
return path.resolve(env.CODEX_HOME || path.join(env.HOME || os.homedir(), '.codex'));
|
|
50
17
|
}
|
|
@@ -54,57 +21,6 @@ export function codexConfigPath(env = process.env) {
|
|
|
54
21
|
export function codexProfileConfigPath(profile, env = process.env) {
|
|
55
22
|
return path.join(codexHome(env), `${String(profile || '').trim()}.config.toml`);
|
|
56
23
|
}
|
|
57
|
-
export function autoReviewProfileName(opts = {}) {
|
|
58
|
-
return opts.high ? AUTO_REVIEW_HIGH_PROFILE : AUTO_REVIEW_PROFILE;
|
|
59
|
-
}
|
|
60
|
-
export async function autoReviewStatus(opts = {}) {
|
|
61
|
-
const configPath = opts.configPath || codexConfigPath(opts.env || process.env);
|
|
62
|
-
const text = await readText(configPath, '');
|
|
63
|
-
const profileText = await readText(path.join(path.dirname(configPath), `${AUTO_REVIEW_PROFILE}.config.toml`), '');
|
|
64
|
-
const highProfileText = await readText(path.join(path.dirname(configPath), `${AUTO_REVIEW_HIGH_PROFILE}.config.toml`), '');
|
|
65
|
-
const approvalsReviewer = readTomlString(text, 'approvals_reviewer');
|
|
66
|
-
const profileReviewer = readTomlString(profileText, 'approvals_reviewer');
|
|
67
|
-
const highProfileReviewer = readTomlString(highProfileText, 'approvals_reviewer');
|
|
68
|
-
const legacyReviewProfile = readTableString(text, `profiles.${AUTO_REVIEW_PROFILE}`, 'approvals_reviewer');
|
|
69
|
-
const legacyHighProfile = readTableString(text, `profiles.${AUTO_REVIEW_HIGH_PROFILE}`, 'approvals_reviewer');
|
|
70
|
-
return {
|
|
71
|
-
config_path: configPath,
|
|
72
|
-
exists: await exists(configPath),
|
|
73
|
-
approvals_reviewer: approvalsReviewer,
|
|
74
|
-
enabled: approvalsReviewer === AUTO_REVIEW_REVIEWER,
|
|
75
|
-
profile: profileReviewer === AUTO_REVIEW_REVIEWER,
|
|
76
|
-
high_profile: highProfileReviewer === AUTO_REVIEW_REVIEWER,
|
|
77
|
-
legacy_invalid: [approvalsReviewer, profileReviewer, highProfileReviewer, legacyReviewProfile, legacyHighProfile].includes(LEGACY_AUTO_REVIEW_REVIEWER),
|
|
78
|
-
policy: readTableString(text, 'auto_review', 'policy') || '',
|
|
79
|
-
native_agent_plan: REVIEW_NATIVE_AGENT_PLAN
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export async function enableAutoReview(opts = {}) {
|
|
83
|
-
const configPath = opts.configPath || codexConfigPath(opts.env || process.env);
|
|
84
|
-
const high = Boolean(opts.high);
|
|
85
|
-
await ensureDir(path.dirname(configPath));
|
|
86
|
-
const current = await readText(configPath, '');
|
|
87
|
-
let next = current || '';
|
|
88
|
-
next = upsertTopLevelString(next, 'approvals_reviewer', AUTO_REVIEW_REVIEWER);
|
|
89
|
-
next = removeLegacyProfileConfig(next, AUTO_REVIEW_PROFILE);
|
|
90
|
-
next = removeLegacyProfileConfig(next, AUTO_REVIEW_HIGH_PROFILE);
|
|
91
|
-
next = upsertAutoReviewPolicy(next);
|
|
92
|
-
if (!next.endsWith('\n'))
|
|
93
|
-
next += '\n';
|
|
94
|
-
await writeCodexConfigGuarded({
|
|
95
|
-
configPath,
|
|
96
|
-
before: current,
|
|
97
|
-
cause: 'auto-review-enable',
|
|
98
|
-
mutate: () => next
|
|
99
|
-
});
|
|
100
|
-
await writeProfileConfig(configPath, AUTO_REVIEW_PROFILE, profileConfigBlock({ effort: 'medium' }));
|
|
101
|
-
await writeProfileConfig(configPath, AUTO_REVIEW_HIGH_PROFILE, profileConfigBlock({ effort: 'high' }));
|
|
102
|
-
return {
|
|
103
|
-
...(await autoReviewStatus({ configPath })),
|
|
104
|
-
profile_name: autoReviewProfileName({ high }),
|
|
105
|
-
launch_args: ['--profile', autoReviewProfileName({ high })]
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
24
|
export const SKS_CONFIG_PROFILES = [
|
|
109
25
|
{ name: 'sks-task-low', stripTable: true, block: sksProfileFileBlock({ effort: 'low' }) },
|
|
110
26
|
{ name: 'sks-task-medium', stripTable: true, block: sksProfileFileBlock({ effort: 'medium' }) },
|
|
@@ -230,68 +146,9 @@ export function buildMadHighLaunchProfileNoWrite(opts = {}) {
|
|
|
230
146
|
writes_user_codex_config: false
|
|
231
147
|
};
|
|
232
148
|
}
|
|
233
|
-
export async function ensureMadHighProfileForSetupOrRepair(opts = {}) {
|
|
234
|
-
const configPath = opts.configPath || codexConfigPath(opts.env || process.env);
|
|
235
|
-
const env = opts.env || process.env;
|
|
236
|
-
await ensureDir(path.dirname(configPath));
|
|
237
|
-
const current = await readText(configPath, '');
|
|
238
|
-
let next = removeLegacyProfileConfig(current, MAD_HIGH_PROFILE);
|
|
239
|
-
next = upsertAutoReviewPolicy(next);
|
|
240
|
-
if (!next.endsWith('\n'))
|
|
241
|
-
next += '\n';
|
|
242
|
-
await writeCodexConfigGuarded({
|
|
243
|
-
configPath,
|
|
244
|
-
before: current,
|
|
245
|
-
cause: 'mad-high-profile-setup',
|
|
246
|
-
mutate: () => next
|
|
247
|
-
});
|
|
248
|
-
await migrateSksProfilesToPerFile({ configPath, env });
|
|
249
|
-
await writeProfileConfig(configPath, MAD_HIGH_PROFILE, profileConfigBlock({
|
|
250
|
-
effort: 'xhigh',
|
|
251
|
-
approvalPolicy: 'never',
|
|
252
|
-
sandboxMode: 'danger-full-access'
|
|
253
|
-
}));
|
|
254
|
-
return {
|
|
255
|
-
config_path: configPath,
|
|
256
|
-
profile_config_path: path.join(path.dirname(configPath), `${MAD_HIGH_PROFILE}.config.toml`),
|
|
257
|
-
profile_name: MAD_HIGH_PROFILE,
|
|
258
|
-
launch_args: ['--profile', MAD_HIGH_PROFILE, '--sandbox', 'danger-full-access', '--ask-for-approval', 'never', '-c', `service_tier=${CODEX_FAST_SERVICE_TIER_ID}`, '-c', 'model_reasoning_effort=xhigh'],
|
|
259
|
-
sandbox_mode: 'danger-full-access',
|
|
260
|
-
approval_policy: 'never',
|
|
261
|
-
approvals_reviewer: AUTO_REVIEW_REVIEWER,
|
|
262
|
-
model_reasoning_effort: 'xhigh',
|
|
263
|
-
service_tier: 'fast',
|
|
264
|
-
scope: 'setup_or_repair_only',
|
|
265
|
-
writes_user_codex_config: true
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
export async function enableMadHighProfile(opts = {}) {
|
|
269
|
-
if (opts.allowUserConfigWrite !== true) {
|
|
270
|
-
throw new Error('enableMadHighProfile writes Codex user config; use buildMadHighLaunchProfileNoWrite for sks --mad');
|
|
271
|
-
}
|
|
272
|
-
return ensureMadHighProfileForSetupOrRepair(opts);
|
|
273
|
-
}
|
|
274
149
|
export function madHighProfileName() {
|
|
275
150
|
return MAD_HIGH_PROFILE;
|
|
276
151
|
}
|
|
277
|
-
export async function disableAutoReview(opts = {}) {
|
|
278
|
-
const configPath = opts.configPath || codexConfigPath(opts.env || process.env);
|
|
279
|
-
const current = await readText(configPath, '');
|
|
280
|
-
let next = upsertTopLevelString(current, 'approvals_reviewer', 'user');
|
|
281
|
-
next = removeLegacyProfileConfig(next, AUTO_REVIEW_PROFILE);
|
|
282
|
-
next = removeLegacyProfileConfig(next, AUTO_REVIEW_HIGH_PROFILE);
|
|
283
|
-
if (!next.endsWith('\n'))
|
|
284
|
-
next += '\n';
|
|
285
|
-
await writeCodexConfigGuarded({
|
|
286
|
-
configPath,
|
|
287
|
-
before: current,
|
|
288
|
-
cause: 'auto-review-disable',
|
|
289
|
-
mutate: () => next
|
|
290
|
-
});
|
|
291
|
-
await writeProfileConfig(configPath, AUTO_REVIEW_PROFILE, profileConfigBlock({ effort: 'medium', reviewer: 'user' }));
|
|
292
|
-
await writeProfileConfig(configPath, AUTO_REVIEW_HIGH_PROFILE, profileConfigBlock({ effort: 'high', reviewer: 'user' }));
|
|
293
|
-
return autoReviewStatus({ configPath });
|
|
294
|
-
}
|
|
295
152
|
function readTomlString(text, key) {
|
|
296
153
|
const re = new RegExp(`^${escapeRegExp(key)}\\s*=\\s*"([^"]*)"\\s*$`, 'm');
|
|
297
154
|
return text.match(re)?.[1] || null;
|
|
@@ -324,33 +181,6 @@ function topLevelBody(text) {
|
|
|
324
181
|
const firstTable = lines.findIndex((line) => /^\s*\[.+\]\s*$/.test(line));
|
|
325
182
|
return (firstTable === -1 ? lines : lines.slice(0, firstTable)).join('\n');
|
|
326
183
|
}
|
|
327
|
-
function upsertTopLevelString(text, key, value) {
|
|
328
|
-
const line = `${key} = "${value}"`;
|
|
329
|
-
const lines = String(text || '').split('\n');
|
|
330
|
-
const firstTable = lines.findIndex((x) => /^\s*\[.+\]\s*$/.test(x));
|
|
331
|
-
const end = firstTable === -1 ? lines.length : firstTable;
|
|
332
|
-
for (let i = 0; i < end; i++) {
|
|
333
|
-
if (new RegExp(`^\\s*${escapeRegExp(key)}\\s*=`).test(lines[i] || '')) {
|
|
334
|
-
lines[i] = line;
|
|
335
|
-
return lines.join('\n').replace(/\n+$/, '\n');
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
lines.splice(end, 0, line);
|
|
339
|
-
return lines.join('\n').replace(/^\n+/, '').replace(/\n{3,}/g, '\n\n');
|
|
340
|
-
}
|
|
341
|
-
function profileConfigBlock(opts = {}) {
|
|
342
|
-
const effort = opts.effort || 'medium';
|
|
343
|
-
const reviewer = opts.reviewer || AUTO_REVIEW_REVIEWER;
|
|
344
|
-
const approvalPolicy = opts.approvalPolicy || 'on-request';
|
|
345
|
-
const sandboxMode = opts.sandboxMode || 'workspace-write';
|
|
346
|
-
return [
|
|
347
|
-
'service_tier = "fast"',
|
|
348
|
-
`approval_policy = "${approvalPolicy}"`,
|
|
349
|
-
`approvals_reviewer = "${reviewer}"`,
|
|
350
|
-
`sandbox_mode = "${sandboxMode}"`,
|
|
351
|
-
`model_reasoning_effort = "${effort}"`
|
|
352
|
-
].join('\n');
|
|
353
|
-
}
|
|
354
184
|
async function writeProfileConfig(configPath, profile, text) {
|
|
355
185
|
const file = path.join(path.dirname(configPath), `${profile}.config.toml`);
|
|
356
186
|
await writeTextAtomic(file, `${String(text || '').replace(/\s+$/, '')}\n`);
|
|
@@ -423,6 +253,19 @@ function normalizeGeneratedProfileText(text) {
|
|
|
423
253
|
.filter(Boolean)
|
|
424
254
|
.join('\n');
|
|
425
255
|
}
|
|
256
|
+
function profileConfigBlock(opts = {}) {
|
|
257
|
+
const effort = opts.effort || 'medium';
|
|
258
|
+
const reviewer = opts.reviewer || AUTO_REVIEW_REVIEWER;
|
|
259
|
+
const approvalPolicy = opts.approvalPolicy || 'on-request';
|
|
260
|
+
const sandboxMode = opts.sandboxMode || 'workspace-write';
|
|
261
|
+
return [
|
|
262
|
+
'service_tier = "fast"',
|
|
263
|
+
`approval_policy = "${approvalPolicy}"`,
|
|
264
|
+
`approvals_reviewer = "${reviewer}"`,
|
|
265
|
+
`sandbox_mode = "${sandboxMode}"`,
|
|
266
|
+
`model_reasoning_effort = "${effort}"`
|
|
267
|
+
].join('\n');
|
|
268
|
+
}
|
|
426
269
|
function managedRetiredProfileBodies() {
|
|
427
270
|
return new Set([
|
|
428
271
|
sksProfileFileBlock({ effort: 'medium' }),
|
|
@@ -574,7 +574,6 @@ function buildSemanticReview(input) {
|
|
|
574
574
|
function isLeanOwnedTypeSafetyPath(file) {
|
|
575
575
|
return [
|
|
576
576
|
'src/core/code-structure.ts',
|
|
577
|
-
'src/core/commands/code-structure-command.ts',
|
|
578
577
|
'src/core/lean-engineering-policy.ts',
|
|
579
578
|
'src/core/codex-control/gpt-final-arbiter.ts',
|
|
580
579
|
'src/core/codex-control/gpt-final-review-schema.ts',
|
|
@@ -585,19 +585,24 @@ export function removeLegacyTopLevelCodexModeLocks(text = '') {
|
|
|
585
585
|
const lines = String(ensureTrailingNewline(text) || '').split('\n');
|
|
586
586
|
const firstTable = lines.findIndex((x) => /^\s*\[.+\]\s*$/.test(x));
|
|
587
587
|
const end = firstTable === -1 ? lines.length : firstTable;
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
588
|
+
const drop = new Set();
|
|
589
|
+
for (let index = 0; index < end; index += 1) {
|
|
590
|
+
if (!/^\s*(?:model|model_reasoning_effort)\s*=/.test(lines[index] || ''))
|
|
591
|
+
continue;
|
|
592
|
+
const marker = sksModeLockProvenance(lines, index);
|
|
593
|
+
if (marker === null)
|
|
594
|
+
continue;
|
|
595
|
+
drop.add(index);
|
|
596
|
+
if (marker >= 0)
|
|
597
|
+
drop.add(marker);
|
|
598
|
+
}
|
|
599
|
+
return ensureTrailingNewline(lines.filter((_, index) => !drop.has(index)).join('\n').replace(/^\n+/, '').replace(/\n{3,}/g, '\n\n'));
|
|
595
600
|
}
|
|
596
|
-
function
|
|
601
|
+
function sksModeLockProvenance(lines, index) {
|
|
597
602
|
const current = String(lines[index] || '');
|
|
598
603
|
const inlineComment = current.includes('#') ? current.slice(current.indexOf('#')) : '';
|
|
599
604
|
if (isSksModeLockMarker(inlineComment))
|
|
600
|
-
return
|
|
605
|
+
return -1;
|
|
601
606
|
const allowedManagedKeys = new Set([
|
|
602
607
|
'service_tier', 'model', 'model_reasoning_effort', 'model_provider',
|
|
603
608
|
'approval_policy', 'sandbox_mode', 'web_search', 'notify', 'preferred_auth_method'
|
|
@@ -609,17 +614,17 @@ function hasSksModeLockProvenance(lines, index) {
|
|
|
609
614
|
continue;
|
|
610
615
|
if (candidate.startsWith('#')) {
|
|
611
616
|
if (isSksModeLockMarker(candidate))
|
|
612
|
-
return
|
|
617
|
+
return cursor;
|
|
613
618
|
continue;
|
|
614
619
|
}
|
|
615
620
|
const key = candidate.match(/^([A-Za-z0-9_-]+)\s*=/)?.[1] || '';
|
|
616
621
|
if (!allowedManagedKeys.has(key))
|
|
617
|
-
return
|
|
622
|
+
return null;
|
|
618
623
|
}
|
|
619
|
-
return
|
|
624
|
+
return null;
|
|
620
625
|
}
|
|
621
626
|
function isSksModeLockMarker(value = '') {
|
|
622
|
-
return /^#\s*(?:SKS|Sneakoscope)\b.*(?:
|
|
627
|
+
return /^#\s*(?:SKS|Sneakoscope)\b.*(?:forced fast UI|managed (?:Codex )?(?:model|reasoning)|codex-lb (?:model|reasoning))/i.test(String(value || '').trim());
|
|
623
628
|
}
|
|
624
629
|
function mergeLostFastUiKeys(before, nextInput) {
|
|
625
630
|
let next = String(nextInput || '');
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { exists, nowIso, readText, sha256, writeJsonAtomic } from '../fsx.js';
|
|
5
|
+
import { HISTORICAL_DESKTOP_COMPAT_MARKER, HISTORICAL_OAUTH_SELECTION_MARKER, HISTORICAL_PROVIDER_SELECTION_MARKER } from '../codex-lb/desktop-bridge-migration/historical-toml.js';
|
|
5
6
|
export const CODEX_APP_UI_STATE_SNAPSHOT_SCHEMA = 'sks.codex-app-ui-state-snapshot.v1';
|
|
6
7
|
export const PROJECT_LOCAL_FORBIDDEN_CODEX_KEYS = [
|
|
7
8
|
'openai_base_url',
|
|
@@ -14,6 +15,9 @@ export const PROJECT_LOCAL_FORBIDDEN_CODEX_KEYS = [
|
|
|
14
15
|
const HOST_OWNED_KEY_RE = /^(?:model|model_reasoning_effort|openai_base_url|chatgpt_base_url|apps_mcp_product_sku|model_provider|model_providers(?:\.|$)|notify|profile|profiles(?:\.|$)|experimental_realtime_ws_base_url|otel(?:\.|$)|features\.fast_mode|service_tier|user\.fast_mode(?:\.|$))/;
|
|
15
16
|
const SECRET_KEY_RE = /(?:key|token|secret|password|credential|cookie|authorization|auth|bearer|refresh|access|headers?|env)/i;
|
|
16
17
|
const SKS_GLOBAL_UI_LOCK_KEYS = new Set(['model_provider', 'model', 'model_reasoning_effort']);
|
|
18
|
+
const RETIRED_SKS_SELECTION_MARKERS = new Set([
|
|
19
|
+
HISTORICAL_DESKTOP_COMPAT_MARKER, HISTORICAL_PROVIDER_SELECTION_MARKER, HISTORICAL_OAUTH_SELECTION_MARKER
|
|
20
|
+
]);
|
|
17
21
|
const SKS_GLOBAL_UI_LOCK_CONTEXT_KEYS = new Set([
|
|
18
22
|
'service_tier', 'model_provider', 'model', 'model_reasoning_effort',
|
|
19
23
|
'approval_policy', 'sandbox_mode', 'web_search', 'notify', 'preferred_auth_method'
|
|
@@ -155,6 +159,8 @@ export function isSksOwnedGlobalUiLock(lines, index) {
|
|
|
155
159
|
const inlineComment = current.includes('#') ? current.slice(current.indexOf('#')) : '';
|
|
156
160
|
if (isSksGlobalUiLockMarker(inlineComment))
|
|
157
161
|
return true;
|
|
162
|
+
if (key === 'model_provider' && RETIRED_SKS_SELECTION_MARKERS.has(String(lines[index - 1] || '').trim()))
|
|
163
|
+
return true;
|
|
158
164
|
const lowerBound = Math.max(0, index - 16);
|
|
159
165
|
for (let cursor = index - 1; cursor >= lowerBound; cursor -= 1) {
|
|
160
166
|
const candidate = String(lines[cursor] || '').trim();
|
|
@@ -174,7 +180,7 @@ export function isSksOwnedGlobalUiLock(lines, index) {
|
|
|
174
180
|
return false;
|
|
175
181
|
}
|
|
176
182
|
function isSksGlobalUiLockMarker(value) {
|
|
177
|
-
return /^#\s*(?:SKS|Sneakoscope)\b.*(?:
|
|
183
|
+
return /^#\s*(?:SKS|Sneakoscope)\b.*(?:forced fast UI|legacy (?:provider|model|reasoning) lock|managed (?:Codex )?(?:provider|model|reasoning)|codex-lb (?:provider|model|reasoning))/i.test(String(value || '').trim());
|
|
178
184
|
}
|
|
179
185
|
export function scanProjectLocalForbiddenKeys(text) {
|
|
180
186
|
const { signals } = scanTomlSignals(text);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { nowIso } from '../fsx.js';
|
|
2
2
|
export const CODEX_RELIABILITY_SHIELD_SCHEMA = 'sks.codex-reliability-shield.v1';
|
|
3
|
+
const DEFAULT_CAPACITY_BACKOFF_MS = [15_000, 45_000, 90_000];
|
|
4
|
+
const MODEL_CAPACITY_RE = /selected model is at capacity|model(?:\s+[\w.-]+)?\s+is\s+at\s+capacity|try a different model|capacity(?:\s+is)?\s+exhausted|temporarily at capacity/i;
|
|
5
|
+
const USAGE_LIMIT_RE = /hit your usage limit|usage limit (?:has been )?reached/i;
|
|
6
|
+
const NON_WORK_ITEM_TYPES = new Set(['error', 'reasoning']);
|
|
3
7
|
export function codexTimeoutClassForRoute(route, fallback = 'standard') {
|
|
4
8
|
return /^\$?naruto$/i.test(String(route || '').trim()) ? 'long' : fallback;
|
|
5
9
|
}
|
|
@@ -7,19 +11,28 @@ export function normalizeCodexReliabilityPolicy(input) {
|
|
|
7
11
|
const policy = input.reliabilityPolicy || {};
|
|
8
12
|
const timeoutClass = codexTimeoutClassForRoute(input.route, policy.timeoutClass || (input.tier === 'orchestrator' ? 'long' : 'standard'));
|
|
9
13
|
const fallbackIdle = timeoutClass === 'short' ? 20_000 : timeoutClass === 'long' ? 180_000 : 60_000;
|
|
14
|
+
const backoff = (Array.isArray(policy.capacityBackoffMs) && policy.capacityBackoffMs.length
|
|
15
|
+
? policy.capacityBackoffMs
|
|
16
|
+
: DEFAULT_CAPACITY_BACKOFF_MS).slice(0, 5).map((wait, index) => clampInt(wait, DEFAULT_CAPACITY_BACKOFF_MS[index] ?? 90_000, 0, 10 * 60_000));
|
|
10
17
|
return {
|
|
11
18
|
maxEmptyResultRetries: clampInt(policy.maxEmptyResultRetries, 1, 0, 3),
|
|
19
|
+
maxCapacityRetries: clampInt(policy.maxCapacityRetries, backoff.length, 0, backoff.length),
|
|
20
|
+
capacityBackoffMs: backoff,
|
|
21
|
+
retryCapacityAfterWork: input.sandboxPolicy === 'read-only',
|
|
12
22
|
idleTimeoutMs: clampInt(policy.idleTimeoutMs, fallbackIdle, 1_000, 15 * 60_000),
|
|
13
23
|
timeoutClass
|
|
14
24
|
};
|
|
15
25
|
}
|
|
16
26
|
export async function runWithCodexReliabilityShield(input, runAttempt) {
|
|
17
27
|
const policy = normalizeCodexReliabilityPolicy(input);
|
|
28
|
+
const deadlineEpochMs = Number(input.reliabilityPolicy?.deadlineEpochMs);
|
|
18
29
|
const attempts = [];
|
|
19
30
|
let selected = null;
|
|
20
31
|
let selectedAttempt = 0;
|
|
32
|
+
let emptyRetries = 0;
|
|
33
|
+
let capacityRetries = 0;
|
|
21
34
|
const controls = {};
|
|
22
|
-
for (let attempt = 1
|
|
35
|
+
for (let attempt = 1;; attempt += 1) {
|
|
23
36
|
const raw = await runAttempt(attempt, controls);
|
|
24
37
|
const continuity = auditToolOutputContinuity(Array.isArray(raw.events) ? raw.events : []);
|
|
25
38
|
const heartbeats = buildKeepaliveHeartbeats(continuity.events);
|
|
@@ -37,6 +50,18 @@ export async function runWithCodexReliabilityShield(input, runAttempt) {
|
|
|
37
50
|
missing_tool_result_count: continuity.missingToolResultCount,
|
|
38
51
|
heartbeat_count: heartbeats.length
|
|
39
52
|
};
|
|
53
|
+
let capacityWaitMs = null;
|
|
54
|
+
if (report.model_capacity_error) {
|
|
55
|
+
capacityWaitMs = report.retryable ? nextCapacityWaitMs(policy, capacityRetries, deadlineEpochMs) : null;
|
|
56
|
+
if (capacityWaitMs === null) {
|
|
57
|
+
report.retryable = false;
|
|
58
|
+
report.retry_reason = null;
|
|
59
|
+
report.blockers = [...report.blockers, 'codex_model_capacity_unavailable'];
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
report.capacity_wait_ms = capacityWaitMs;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
40
65
|
attempts.push(report);
|
|
41
66
|
selected = {
|
|
42
67
|
...raw,
|
|
@@ -47,11 +72,20 @@ export async function runWithCodexReliabilityShield(input, runAttempt) {
|
|
|
47
72
|
selectedAttempt = attempt;
|
|
48
73
|
if (report.retryable && report.mcp_auth_error)
|
|
49
74
|
controls.noMcp = true;
|
|
50
|
-
if (!report.retryable
|
|
75
|
+
if (!report.retryable)
|
|
51
76
|
break;
|
|
77
|
+
if (capacityWaitMs !== null) {
|
|
78
|
+
capacityRetries += 1;
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, capacityWaitMs));
|
|
80
|
+
}
|
|
81
|
+
else if (emptyRetries < policy.maxEmptyResultRetries) {
|
|
82
|
+
emptyRetries += 1;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
52
87
|
}
|
|
53
88
|
const blockers = attempts.flatMap((attempt) => attempt.blockers);
|
|
54
|
-
const modelCapacityRetryCount = attempts.filter((attempt) => attempt.model_capacity_error && attempt.retryable).length;
|
|
55
89
|
const report = {
|
|
56
90
|
schema: CODEX_RELIABILITY_SHIELD_SCHEMA,
|
|
57
91
|
generated_at: nowIso(),
|
|
@@ -61,6 +95,7 @@ export async function runWithCodexReliabilityShield(input, runAttempt) {
|
|
|
61
95
|
timeout_class: policy.timeoutClass,
|
|
62
96
|
idle_timeout_ms: policy.idleTimeoutMs,
|
|
63
97
|
max_empty_result_retries: policy.maxEmptyResultRetries,
|
|
98
|
+
max_capacity_retries: policy.maxCapacityRetries,
|
|
64
99
|
attempts,
|
|
65
100
|
selected_attempt: selectedAttempt,
|
|
66
101
|
retry_count: Math.max(0, selectedAttempt - 1),
|
|
@@ -68,8 +103,8 @@ export async function runWithCodexReliabilityShield(input, runAttempt) {
|
|
|
68
103
|
repaired_tool_result_count: attempts.reduce((sum, attempt) => sum + attempt.repaired_tool_result_count, 0),
|
|
69
104
|
missing_tool_result_count: attempts.reduce((sum, attempt) => sum + attempt.missing_tool_result_count, 0),
|
|
70
105
|
no_duplicate_streamed_output: attempts.slice(0, -1).every((attempt) => attempt.meaningful_event_count === 0),
|
|
71
|
-
model_capacity_retry_count:
|
|
72
|
-
selected_model_capacity_fallback:
|
|
106
|
+
model_capacity_retry_count: capacityRetries,
|
|
107
|
+
selected_model_capacity_fallback: capacityRetries > 0 && attempts[attempts.length - 1]?.model_capacity_error === false,
|
|
73
108
|
blockers
|
|
74
109
|
};
|
|
75
110
|
const selectedResult = selected || { ok: false, events: [], blockers: ['codex_sdk_attempt_missing'] };
|
|
@@ -92,8 +127,6 @@ export function evaluateCodexReliabilityAttempt(result, events, policy, attempt)
|
|
|
92
127
|
const blockers = [];
|
|
93
128
|
let retryable = false;
|
|
94
129
|
let retryReason = null;
|
|
95
|
-
if (modelCapacity)
|
|
96
|
-
blockers.push('codex_model_capacity_unavailable');
|
|
97
130
|
if (mcpAuth)
|
|
98
131
|
blockers.push('codex_reliability_mcp_auth_error');
|
|
99
132
|
if (!modelCapacity && idle && partial)
|
|
@@ -108,11 +141,17 @@ export function evaluateCodexReliabilityAttempt(result, events, policy, attempt)
|
|
|
108
141
|
retryable = true;
|
|
109
142
|
retryReason = 'mcp_auth_error_retry_no_mcp';
|
|
110
143
|
}
|
|
111
|
-
else if (
|
|
144
|
+
else if (modelCapacity) {
|
|
145
|
+
if (meaningful.length === 0 || policy.retryCapacityAfterWork) {
|
|
146
|
+
retryable = true;
|
|
147
|
+
retryReason = 'model_capacity_backoff_retry';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (!fatal && idle && meaningful.length === 0) {
|
|
112
151
|
retryable = true;
|
|
113
152
|
retryReason = 'stream_idle_before_meaningful_event';
|
|
114
153
|
}
|
|
115
|
-
else if (!
|
|
154
|
+
else if (!fatal && empty) {
|
|
116
155
|
retryable = true;
|
|
117
156
|
retryReason = 'empty_sdk_result_before_meaningful_event';
|
|
118
157
|
}
|
|
@@ -128,6 +167,7 @@ export function evaluateCodexReliabilityAttempt(result, events, policy, attempt)
|
|
|
128
167
|
fatal_error: fatal,
|
|
129
168
|
mcp_auth_error: mcpAuth,
|
|
130
169
|
model_capacity_error: modelCapacity,
|
|
170
|
+
capacity_wait_ms: null,
|
|
131
171
|
capacity_fallback_hint: null,
|
|
132
172
|
repaired_tool_result_count: 0,
|
|
133
173
|
missing_tool_result_count: 0,
|
|
@@ -136,8 +176,15 @@ export function evaluateCodexReliabilityAttempt(result, events, policy, attempt)
|
|
|
136
176
|
};
|
|
137
177
|
}
|
|
138
178
|
export function isCodexModelCapacityError(result, events) {
|
|
139
|
-
|
|
140
|
-
|
|
179
|
+
return MODEL_CAPACITY_RE.test(collectFailureSignalText(result, events));
|
|
180
|
+
}
|
|
181
|
+
function nextCapacityWaitMs(policy, retriesDone, deadlineEpochMs) {
|
|
182
|
+
const base = policy.capacityBackoffMs[retriesDone];
|
|
183
|
+
if (retriesDone >= policy.maxCapacityRetries || base === undefined)
|
|
184
|
+
return null;
|
|
185
|
+
const wait = Math.round(base * (0.75 + Math.random() * 0.5));
|
|
186
|
+
const hasDeadline = Number.isFinite(deadlineEpochMs) && deadlineEpochMs > 0;
|
|
187
|
+
return hasDeadline && deadlineEpochMs - Date.now() <= wait ? null : wait;
|
|
141
188
|
}
|
|
142
189
|
export function isMissingToolOutputProtocolError(result, events) {
|
|
143
190
|
return /\[No tool output found for (?:custom\s+)?tool call\s+[^\]]+\]/i.test(collectText(result, events));
|
|
@@ -175,8 +222,9 @@ export function buildKeepaliveHeartbeats(events) {
|
|
|
175
222
|
function isMeaningfulEvent(event) {
|
|
176
223
|
const type = String(event?.type || '');
|
|
177
224
|
const itemType = String(event?.item?.type || '');
|
|
225
|
+
if (type === 'item.completed' && !NON_WORK_ITEM_TYPES.has(itemType))
|
|
226
|
+
return true;
|
|
178
227
|
return type === 'turn.completed'
|
|
179
|
-
|| type === 'item.completed'
|
|
180
228
|
|| itemType === 'agent_message'
|
|
181
229
|
|| itemType === 'file_change'
|
|
182
230
|
|| itemType === 'command_execution'
|
|
@@ -185,8 +233,9 @@ function isMeaningfulEvent(event) {
|
|
|
185
233
|
function hasFatalError(result, events) {
|
|
186
234
|
if (isMcpAuthError(result, events))
|
|
187
235
|
return false;
|
|
188
|
-
const text =
|
|
189
|
-
return /\b(?:4\d\d|fatal|unauthorized|forbidden|authrequired|invalid oauth|side-effect applied|partial patch applied)\b/i.test(text)
|
|
236
|
+
const text = collectFailureSignalText(result, events);
|
|
237
|
+
return /\b(?:4\d\d|fatal|unauthorized|forbidden|authrequired|invalid oauth|side-effect applied|partial patch applied)\b/i.test(text)
|
|
238
|
+
|| USAGE_LIMIT_RE.test(text);
|
|
190
239
|
}
|
|
191
240
|
function isMcpAuthError(result, events) {
|
|
192
241
|
const text = collectText(result, events);
|
|
@@ -206,7 +255,7 @@ function collectText(result, events) {
|
|
|
206
255
|
].filter(Boolean).join('\n'))
|
|
207
256
|
].join('\n');
|
|
208
257
|
}
|
|
209
|
-
function
|
|
258
|
+
function collectFailureSignalText(result, events) {
|
|
210
259
|
return [
|
|
211
260
|
...(Array.isArray(result.blockers) ? result.blockers : []),
|
|
212
261
|
...events
|
|
@@ -87,8 +87,24 @@ export async function runRealCodexSdkTask(input, policy) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
|
-
if (!timedOut && controller.signal.aborted !== true && String(err?.name || '') !== 'AbortError')
|
|
91
|
-
|
|
90
|
+
if (!timedOut && controller.signal.aborted !== true && String(err?.name || '') !== 'AbortError') {
|
|
91
|
+
const reported = codexReportedFailure(events);
|
|
92
|
+
if (!reported)
|
|
93
|
+
throw err;
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
sdkThreadId: String(thread.id || events.find((event) => event?.type === 'thread.started')?.thread_id || ''),
|
|
97
|
+
sdkRunId: extractRunId(events),
|
|
98
|
+
events,
|
|
99
|
+
finalResponse,
|
|
100
|
+
structuredOutput: null,
|
|
101
|
+
blockers: [`codex_sdk_run_failed:${reported.message || 'turn_failed'} (${firstLine(err)})`],
|
|
102
|
+
liveEventsWritten,
|
|
103
|
+
runtimeIdentity: runtime.identity,
|
|
104
|
+
executionPolicy,
|
|
105
|
+
raw: { failed_event: reported.event, exec_error: String(err?.message || err) }
|
|
106
|
+
};
|
|
107
|
+
}
|
|
92
108
|
return {
|
|
93
109
|
ok: false,
|
|
94
110
|
sdkThreadId: String(thread.id || events.find((event) => event?.type === 'thread.started')?.thread_id || ''),
|
|
@@ -106,7 +122,7 @@ export async function runRealCodexSdkTask(input, policy) {
|
|
|
106
122
|
finally {
|
|
107
123
|
clearTimeout(timer);
|
|
108
124
|
}
|
|
109
|
-
const failed = events
|
|
125
|
+
const failed = codexReportedFailure(events);
|
|
110
126
|
if (failed) {
|
|
111
127
|
return {
|
|
112
128
|
ok: false,
|
|
@@ -115,11 +131,11 @@ export async function runRealCodexSdkTask(input, policy) {
|
|
|
115
131
|
events,
|
|
116
132
|
finalResponse,
|
|
117
133
|
structuredOutput: null,
|
|
118
|
-
blockers: ['codex_turn_failed'],
|
|
134
|
+
blockers: [failed.message ? `codex_turn_failed:${failed.message}` : 'codex_turn_failed'],
|
|
119
135
|
liveEventsWritten,
|
|
120
136
|
runtimeIdentity: runtime.identity,
|
|
121
137
|
executionPolicy,
|
|
122
|
-
raw: { failed_event: failed }
|
|
138
|
+
raw: { failed_event: failed.event }
|
|
123
139
|
};
|
|
124
140
|
}
|
|
125
141
|
const structuredOutput = parseStructuredOutput(finalResponse, Boolean(input.outputSchema));
|
|
@@ -137,6 +153,23 @@ export async function runRealCodexSdkTask(input, policy) {
|
|
|
137
153
|
raw: { item_count: events.filter((event) => String(event?.type || '').startsWith('item.')).length }
|
|
138
154
|
};
|
|
139
155
|
}
|
|
156
|
+
export function codexReportedFailure(events) {
|
|
157
|
+
let first = null;
|
|
158
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
159
|
+
const event = events[index];
|
|
160
|
+
const type = event?.type;
|
|
161
|
+
if (type !== 'turn.failed' && type !== 'error')
|
|
162
|
+
continue;
|
|
163
|
+
const message = String((type === 'turn.failed' ? event?.error?.message : event?.message) || '').replace(/\s+/g, ' ').trim();
|
|
164
|
+
if (message)
|
|
165
|
+
return { event, message: message.slice(0, 300) };
|
|
166
|
+
first = event;
|
|
167
|
+
}
|
|
168
|
+
return first ? { event: first, message: '' } : null;
|
|
169
|
+
}
|
|
170
|
+
function firstLine(err) {
|
|
171
|
+
return String(err?.message || err).trim().split('\n')[0].trim().slice(0, 200);
|
|
172
|
+
}
|
|
140
173
|
export async function resolveCodexSdkRuntime(_input) {
|
|
141
174
|
return resolveOfficialCodexPackageRuntime({ requestedBy: 'codex-sdk-adapter' });
|
|
142
175
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export const MANAGED_ROUTING_RUNTIME = 'desktop-bridge';
|
|
2
2
|
export const BRIDGE_PROVIDER_IDS = ['codex-lb', 'openrouter'];
|
|
3
3
|
export const BRIDGE_OFFICIAL_ROUTE_ID = 'openai';
|
|
4
|
+
export const BRIDGE_REMOTE_COMPACTION = Object.freeze({
|
|
5
|
+
openai: 'native',
|
|
6
|
+
'codex-lb': 'native',
|
|
7
|
+
openrouter: 'bridge_summary',
|
|
8
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildBridgeRouteIndex, sha256Stable } from '../route-index.js';
|
|
2
2
|
import { COMBINED_BRIDGE_CATALOG_SCHEMA } from './contracts.js';
|
|
3
|
-
import { normalizeProviderCatalog, providerCatalogStatus, routeProviderState } from './normalize.js';
|
|
3
|
+
import { OPENROUTER_PRIORITY_BASE, normalizeProviderCatalog, providerCatalogStatus, routeProviderState } from './normalize.js';
|
|
4
4
|
import { pinCatalogToLatestGenerations } from './latest-generation.js';
|
|
5
5
|
import { compareModels, unique } from './shared.js';
|
|
6
6
|
import { applyBridgeModelSelection, availableModelRows, emptyBridgeModelSelection } from './model-selection.js';
|
|
@@ -11,7 +11,9 @@ export function buildCombinedBridgeCatalog(registry, options) {
|
|
|
11
11
|
openrouter: normalizeProviderCatalog(options.catalogs.openrouter)
|
|
12
12
|
};
|
|
13
13
|
const selection = options.selection || emptyBridgeModelSelection(createdAt);
|
|
14
|
-
|
|
14
|
+
let openRouterIndex = 0;
|
|
15
|
+
const allModels = pinCatalogToLatestGenerations([...normalized['codex-lb'].models, ...normalized.openrouter.models].sort(compareModels)).map((model) => model.provider_id === 'openrouter' ? { ...model, priority: OPENROUTER_PRIORITY_BASE + openRouterIndex++ } : model)
|
|
16
|
+
.sort((left, right) => left.priority - right.priority || left.slug.localeCompare(right.slug) || compareModels(left, right));
|
|
15
17
|
const availableOpenRouterModels = availableModelRows(allModels, selection);
|
|
16
18
|
const models = options.selection ? applyBridgeModelSelection(allModels, selection) : allModels;
|
|
17
19
|
const routeBuild = buildBridgeRouteIndex({
|