sneakoscope 3.1.4 → 3.1.5

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.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/crates/sks-core/Cargo.lock +1 -1
  3. package/crates/sks-core/Cargo.toml +1 -1
  4. package/crates/sks-core/src/main.rs +1 -1
  5. package/dist/.sks-build-stamp.json +4 -4
  6. package/dist/bin/sks.js +1 -1
  7. package/dist/cli/install-helpers.js +56 -4
  8. package/dist/commands/codex-lb.js +12 -9
  9. package/dist/core/codex-app/codex-agent-role-sync.js +63 -11
  10. package/dist/core/codex-app/codex-agent-type-probe.js +202 -0
  11. package/dist/core/codex-app/codex-app-execution-profile.js +15 -8
  12. package/dist/core/codex-app/codex-app-fast-ui-repair.js +7 -4
  13. package/dist/core/codex-app/codex-app-harness-matrix.js +78 -26
  14. package/dist/core/codex-app/codex-app-types.js +21 -0
  15. package/dist/core/codex-app/codex-hook-approval-probe.js +188 -0
  16. package/dist/core/codex-app/codex-hook-lifecycle.js +31 -10
  17. package/dist/core/codex-app/codex-init-deep.js +97 -4
  18. package/dist/core/codex-app/codex-skill-sync.js +75 -3
  19. package/dist/core/codex-app/lazycodex-analysis.js +31 -10
  20. package/dist/core/codex-app/lazycodex-interop-policy.js +13 -2
  21. package/dist/core/codex-app/lazycodex-live-analyzer.js +98 -0
  22. package/dist/core/commands/mad-sks-command.js +37 -2
  23. package/dist/core/commands/qa-loop-command.js +3 -2
  24. package/dist/core/commands/research-command.js +2 -2
  25. package/dist/core/doctor/doctor-zellij-repair.js +5 -1
  26. package/dist/core/feature-fixtures.js +1 -0
  27. package/dist/core/feature-registry.js +4 -1
  28. package/dist/core/fsx.js +1 -1
  29. package/dist/core/init.js +4 -1
  30. package/dist/core/loops/loop-continuation-enforcer.js +11 -3
  31. package/dist/core/loops/loop-planner.js +21 -4
  32. package/dist/core/loops/loop-worker-runtime.js +23 -7
  33. package/dist/core/naruto/naruto-loop-worker-router.js +11 -2
  34. package/dist/core/qa-loop.js +39 -4
  35. package/dist/core/research/research-cycle-runner.js +1 -0
  36. package/dist/core/research/research-stage-runner.js +9 -2
  37. package/dist/core/research.js +35 -1
  38. package/dist/core/version.js +1 -1
  39. package/dist/core/zellij/homebrew-policy.js +0 -1
  40. package/dist/core/zellij/zellij-self-heal-types.js +45 -0
  41. package/dist/core/zellij/zellij-self-heal.js +69 -8
  42. package/dist/core/zellij/zellij-update.js +9 -1
  43. package/dist/scripts/sks-3-1-5-directive-check-lib.js +347 -0
  44. package/package.json +26 -2
package/README.md CHANGED
@@ -35,7 +35,7 @@ Set up this agent project with Sneakoscope Codex. Use [[mandarange/Sneakoscope-C
35
35
 
36
36
  ## 🚀 Current Release
37
37
 
38
- SKS **3.1.4** makes `doctor --fix` a real Zellij dependency self-healer, lets `sks --mad` repair or explicitly run headless without contradictory optional/blocking messages, and adds Codex App Harness Matrix reporting for plugins, hooks, skills, agent roles, init-deep memory, and execution profile decisions.
38
+ SKS **3.1.5** productionizes the Codex App harness with typed probe surfaces, dry-run Zellij self-heal planning, hook approval and `agent_type` evidence, LazyCodex live-source analysis, init-deep directory memory hints, and execution profile routing across Loop, QA, Research, and Naruto artifacts.
39
39
 
40
40
  SKS 3.0.0 was the parallel-runtime stabilization release. The whole live-swarm experience — what you actually *see* while 5, 20, or 100 workers run — was rebuilt and proven end-to-end.
41
41
 
@@ -76,7 +76,7 @@ dependencies = [
76
76
 
77
77
  [[package]]
78
78
  name = "sks-core"
79
- version = "3.1.4"
79
+ version = "3.1.5"
80
80
  dependencies = [
81
81
  "serde_json",
82
82
  ]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sks-core"
3
- version = "3.1.4"
3
+ version = "3.1.5"
4
4
  edition = "2021"
5
5
 
6
6
  [dependencies]
@@ -4,7 +4,7 @@ use std::io::{self, Read, Seek, SeekFrom};
4
4
  fn main() {
5
5
  let mut args = std::env::args().skip(1);
6
6
  match args.next().as_deref() {
7
- Some("--version") => println!("sks-rs 3.1.4"),
7
+ Some("--version") => println!("sks-rs 3.1.5"),
8
8
  Some("compact-info") => {
9
9
  let mut input = String::new();
10
10
  let _ = io::stdin().read_to_string(&mut input);
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schema": "sks.dist-build-stamp.v1",
3
3
  "package_name": "sneakoscope",
4
- "package_version": "3.1.4",
5
- "source_digest": "47f6028f6b91151c205109059bff2ef5c51d2f084ae930063eca118d1888a8fc",
6
- "source_file_count": 2488,
7
- "built_at_source_time": 1781425289529
4
+ "package_version": "3.1.5",
5
+ "source_digest": "89b81e91ec4d82c33320922ae0dc33bd6562ccf37c58171858e7f703d7767e4b",
6
+ "source_file_count": 2518,
7
+ "built_at_source_time": 1781439913355
8
8
  }
package/dist/bin/sks.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const FAST_PACKAGE_VERSION = '3.1.4';
2
+ const FAST_PACKAGE_VERSION = '3.1.5';
3
3
  const args = process.argv.slice(2);
4
4
  try {
5
5
  if (args[0] === '--agent' && args[1] === 'worker') {
@@ -144,6 +144,8 @@ async function reportPostinstallCodexLbAuth() {
144
144
  console.log(`codex-lb auth: restored from existing Codex login cache into ${codexLbAuth.env_path}.`);
145
145
  else if (codexLbAuth.status === 'synced' || codexLbAuth.status === 'present' || codexLbAuth.status === 'repaired')
146
146
  console.log(`codex-lb auth: preserved from ${codexLbAuth.env_path}.`);
147
+ else if (codexLbAuth.status === 'present_unselected')
148
+ console.log('codex-lb auth: preserved but not selected; ChatGPT OAuth remains active.');
147
149
  else if (codexLbAuth.status === 'skipped')
148
150
  console.log(`codex-lb auth: skipped (${codexLbAuth.reason}).`);
149
151
  else if (codexLbAuth.status === 'missing_env_key')
@@ -284,6 +286,7 @@ async function capturePostinstallCodexLbConfigSnapshot(home = process.env.HOME |
284
286
  env_path: envPath,
285
287
  auth_path: authPath,
286
288
  base_url: baseUrl ? normalizeCodexLbBaseUrl(baseUrl) : null,
289
+ selected: hasTopLevelCodexLbSelected(config),
287
290
  auth_existed: authExisted,
288
291
  auth_text: authText
289
292
  };
@@ -294,7 +297,7 @@ async function restorePostinstallCodexLbConfigSnapshot(snapshot) {
294
297
  let configRestored = false;
295
298
  if (snapshot.base_url) {
296
299
  const current = await readText(snapshot.config_path, '');
297
- const next = normalizeCodexFastModeUiConfig(upsertCodexLbConfig(current, snapshot.base_url));
300
+ const next = normalizeCodexFastModeUiConfig(upsertCodexLbConfig(current, snapshot.base_url, snapshot.selected === true));
298
301
  const alreadyOk = next === ensureTrailingNewline(current) && codexLbProviderBaseUrl(current);
299
302
  if (!alreadyOk) {
300
303
  const safeWrite = await safeWriteCodexConfigToml(snapshot.config_path, current, next, 'codex-lb-restore');
@@ -488,6 +491,12 @@ export async function codexLbStatus(opts = {}) {
488
491
  const providerEnvKey = codexLbProviderEnvKey(config);
489
492
  const providerUsesCodexLbEnvAuth = providerConfigured && providerEnvKey === 'CODEX_LB_API_KEY' && providerOpenAiAuthDisabled;
490
493
  const codexAppUsableWithCodexLb = providerUsesCodexLbEnvAuth && envKeyConfigured && Boolean(baseUrl);
494
+ const launchEnvironment = await inspectCodexLbMacLaunchEnvironment(baseUrl, opts).catch((err) => ({
495
+ checked: true,
496
+ available: false,
497
+ status: 'inspect_failed',
498
+ error: err.message
499
+ }));
491
500
  return {
492
501
  ok: providerConfigured && envKeyConfigured && Boolean(baseUrl) && providerUsesCodexLbEnvAuth,
493
502
  config_path: configPath,
@@ -514,7 +523,8 @@ export async function codexLbStatus(opts = {}) {
514
523
  auth_path: authPath,
515
524
  auth_mode: authMode.mode,
516
525
  auth_usable_for_codex_app: authMode.codex_app_usable || codexAppUsableWithCodexLb,
517
- auth_summary: codexAppUsableWithCodexLb ? 'codex-lb provider uses CODEX_LB_API_KEY env_key; OpenAI OAuth not required' : authMode.summary
526
+ auth_summary: codexAppUsableWithCodexLb ? 'codex-lb provider uses CODEX_LB_API_KEY env_key; OpenAI OAuth not required' : authMode.summary,
527
+ launch_environment: launchEnvironment
518
528
  };
519
529
  }
520
530
  export function formatCodexLbStatusText(status = {}, opts = {}) {
@@ -541,12 +551,12 @@ export function formatCodexLbStatusText(status = {}, opts = {}) {
541
551
  lines.push('', 'Sign in to Codex App/CLI again, then run: sks codex-lb repair');
542
552
  else if (status.ok && !status.selected)
543
553
  lines.push('', 'Run: sks codex-lb repair to activate codex-lb for Codex App.');
554
+ else if (status.ok)
555
+ lines.push('', 'Status: codex-lb active; no repair needed.');
544
556
  else if (!status.ok && status.base_url && status.env_key_configured)
545
557
  lines.push('', 'Run: sks codex-lb repair to restore the upstream codex-lb provider block.');
546
558
  else if (!status.ok)
547
559
  lines.push('', 'Run: sks codex-lb setup --host <domain> --api-key <key>');
548
- else
549
- lines.push('', 'Repair provider auth: sks codex-lb repair');
550
560
  if (backupPresent)
551
561
  lines.push('Switch fully away from codex-lb: sks codex-lb release');
552
562
  return `${lines.join('\n')}\n`;
@@ -862,6 +872,17 @@ export async function ensureCodexLbAuthDuringInstall(opts = {}) {
862
872
  const status = await codexLbStatus(opts);
863
873
  if (!status.selected && !status.provider_configured && !status.env_file)
864
874
  return { status: 'not_configured', codex_lb: status };
875
+ if (status.ok && !status.selected && status.auth_mode === 'chatgpt_oauth') {
876
+ return {
877
+ ok: true,
878
+ status: 'present_unselected',
879
+ reason: 'chatgpt_oauth_active_codex_lb_unselected',
880
+ config_path: status.config_path,
881
+ env_path: status.env_path,
882
+ base_url: status.base_url,
883
+ codex_lb: status
884
+ };
885
+ }
865
886
  await migrateCodexAuthKeyFormat({ home: opts.home });
866
887
  if (status.ok && (!status.selected || !status.provider_uses_codex_lb_env_auth))
867
888
  return repairCodexLbAuth(opts);
@@ -1236,6 +1257,9 @@ export async function maybePromptCodexLbSetupForLaunch(args = [], opts = {}) {
1236
1257
  if (args.includes('--json') || args.includes('--skip-codex-lb') || process.env.SKS_SKIP_CODEX_LB_PROMPT === '1')
1237
1258
  return { status: 'skipped' };
1238
1259
  let status = await codexLbStatus(opts);
1260
+ if (status.env_key_configured && status.base_url && !status.selected && status.auth_mode === 'chatgpt_oauth') {
1261
+ return { status: 'continued_to_codex', ok: false, chain_health: null, codex_lb: status, reason: 'chatgpt_oauth_active_codex_lb_unselected' };
1262
+ }
1239
1263
  if (status.env_key_configured && status.base_url && (!status.provider_configured || !status.selected || !status.provider_uses_codex_lb_env_auth)) {
1240
1264
  let promptedRestore = false;
1241
1265
  if (!status.provider_configured && canAskYesNo()) {
@@ -1355,6 +1379,34 @@ async function syncCodexLbMacLaunchEnvironment(values = {}, opts = {}) {
1355
1379
  return { ok: false, status: 'launch_env_failed', variables: results.map((result) => result.key), failed, error: failed.map((result) => `${result.key}: ${result.error}`).join('; ') };
1356
1380
  return { ok: true, status: 'synced', variables: results.map((result) => result.key) };
1357
1381
  }
1382
+ async function inspectCodexLbMacLaunchEnvironment(baseUrl = '', opts = {}) {
1383
+ if (process.platform !== 'darwin' && !opts.forceLaunchEnv)
1384
+ return { checked: false, status: 'not_macos', skipped: true };
1385
+ const launchctl = opts.launchctlBin || await which('launchctl').catch(() => null) || await exists('/bin/launchctl').then((ok) => ok ? '/bin/launchctl' : null).catch(() => null);
1386
+ if (!launchctl)
1387
+ return { checked: true, available: false, status: 'launchctl_missing' };
1388
+ const readVar = async (key) => {
1389
+ const result = await runProcess(launchctl, ['getenv', key], { timeoutMs: 3000, maxOutputBytes: 8192 });
1390
+ return result.code === 0 ? String(result.stdout || '').trim() : '';
1391
+ };
1392
+ const currentBaseUrl = await readVar('CODEX_LB_BASE_URL');
1393
+ const currentApiKey = await readVar('CODEX_LB_API_KEY');
1394
+ const baseMatches = !baseUrl || currentBaseUrl === String(baseUrl || '').trim();
1395
+ const basePresent = Boolean(currentBaseUrl);
1396
+ const keyPresent = Boolean(currentApiKey);
1397
+ return {
1398
+ checked: true,
1399
+ available: true,
1400
+ status: basePresent && keyPresent && baseMatches ? 'synced' : basePresent || keyPresent ? 'partial' : 'missing',
1401
+ variables: [
1402
+ ...(keyPresent ? ['CODEX_LB_API_KEY'] : []),
1403
+ ...(basePresent ? ['CODEX_LB_BASE_URL'] : [])
1404
+ ],
1405
+ base_url_present: basePresent,
1406
+ base_url_matches: baseMatches,
1407
+ api_key_present: keyPresent
1408
+ };
1409
+ }
1358
1410
  async function maybeSyncCodexLbSharedLogin(apiKey, opts = {}) {
1359
1411
  if (!apiKey)
1360
1412
  return { ok: false, status: 'missing_env_key' };
@@ -302,16 +302,19 @@ async function resolveNewApiKey(args = []) {
302
302
  return '';
303
303
  }
304
304
  function shapeCodexLbStatus(status = {}) {
305
- const mode = status.env_loader?.api_key?.source === 'env-file'
306
- ? 'durable_env_file'
307
- : status.env_loader?.api_key?.source === 'keychain'
308
- ? 'durable_keychain'
309
- : status.env_loader?.api_key?.source === 'process.env'
310
- ? 'process_only_ephemeral'
311
- : 'none';
305
+ const modes = [];
306
+ if (status.env_file && status.env_key_configured)
307
+ modes.push('durable_env_file');
308
+ if (status.env_loader?.api_key?.source === 'keychain' || status.env_loader?.keychain?.status === 'present')
309
+ modes.push('durable_keychain');
310
+ if (status.launch_environment?.status === 'synced')
311
+ modes.push('durable_launchctl');
312
+ if (!modes.length && status.env_loader?.api_key?.source === 'process.env')
313
+ modes.push('process_only_ephemeral');
314
+ const mode = modes[0] || 'none';
312
315
  const persistence = codexLbPersistenceSummary({
313
- selectedModes: mode === 'none' ? [] : [mode],
314
- appliedModes: mode === 'none' ? ['none'] : [mode],
316
+ selectedModes: modes.length ? modes : [],
317
+ appliedModes: modes.length ? modes : mode === 'none' ? ['none'] : [mode],
315
318
  processOnly: mode === 'process_only_ephemeral'
316
319
  });
317
320
  return {
@@ -1,9 +1,9 @@
1
- // @ts-nocheck
2
1
  import fs from 'node:fs/promises';
3
2
  import path from 'node:path';
4
3
  import os from 'node:os';
5
4
  import { nowIso, writeJsonAtomic, writeTextAtomic, ensureDir } from '../fsx.js';
6
5
  import { repairAgentRoleConfigs } from '../agents/agent-role-config.js';
6
+ import { agentRolePayloadFor, probeCodexAgentTypeSupport } from './codex-agent-type-probe.js';
7
7
  const DIRECTIVE_ROLES = [
8
8
  'sks-explorer',
9
9
  'sks-planner',
@@ -15,6 +15,7 @@ const DIRECTIVE_ROLES = [
15
15
  ];
16
16
  export async function syncCodexAgentRoles(input) {
17
17
  const root = path.resolve(input.root);
18
+ const env = input.env || process.env;
18
19
  const codexHome = input.codexHome || process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
19
20
  const targetDir = path.join(codexHome, 'agents');
20
21
  const baseRepair = await repairAgentRoleConfigs({
@@ -22,46 +23,97 @@ export async function syncCodexAgentRoles(input) {
22
23
  apply: input.apply === true,
23
24
  codexHome,
24
25
  reportPath: path.join(root, '.sneakoscope', 'reports', 'agent-role-config-repair.json')
25
- }).catch((err) => ({ ok: false, blockers: [err?.message || String(err)] }));
26
+ }).catch((err) => ({ ok: false, blockers: [messageOf(err)] }));
27
+ const agentTypeProbe = input.agentTypeSupported === undefined
28
+ ? await probeCodexAgentTypeSupport(root, { env }).catch((err) => ({
29
+ schema: 'sks.codex-agent-type-probe.v1',
30
+ generated_at: nowIso(),
31
+ ok: false,
32
+ supported: false,
33
+ source: 'unknown',
34
+ spawn_tool_name: 'unknown',
35
+ schema_path: null,
36
+ evidence: [],
37
+ blockers: [messageOf(err)],
38
+ warnings: ['agent_type_probe_failed_message_role_fallback']
39
+ }))
40
+ : {
41
+ schema: 'sks.codex-agent-type-probe.v1',
42
+ generated_at: nowIso(),
43
+ ok: true,
44
+ supported: input.agentTypeSupported,
45
+ source: 'fixture',
46
+ spawn_tool_name: input.agentTypeSupported ? 'spawn_agent' : 'unknown',
47
+ schema_path: input.agentTypeSupported ? 'input.agentTypeSupported' : null,
48
+ evidence: [`input.agentTypeSupported=${input.agentTypeSupported}`],
49
+ blockers: [],
50
+ warnings: []
51
+ };
52
+ const rolePayloads = Object.fromEntries(DIRECTIVE_ROLES.map((role) => [role, agentRolePayloadFor(role, agentTypeProbe)]));
26
53
  const created = [];
27
54
  if (input.apply === true) {
28
55
  await ensureDir(targetDir);
29
56
  for (const role of DIRECTIVE_ROLES) {
30
57
  const file = path.join(targetDir, `${role}.toml`);
31
58
  const current = await fs.readFile(file, 'utf8').catch(() => '');
32
- if (current && !current.includes('SKS managed 3.1.4 directive role'))
59
+ if (current && !current.includes('SKS managed 3.1.4 directive role') && !current.includes('SKS managed 3.1.5 directive role'))
33
60
  continue;
34
- await writeTextAtomic(file, roleToml(role));
61
+ await writeTextAtomic(file, roleToml(role, rolePayloads[role]));
35
62
  created.push(file);
36
63
  }
37
64
  }
38
65
  const report = {
39
66
  schema: 'sks.codex-agent-role-sync.v1',
40
67
  generated_at: nowIso(),
41
- ok: baseRepair.ok !== false,
68
+ ok: recordOk(baseRepair) !== false && agentTypeProbe.ok !== false,
42
69
  apply: input.apply === true,
43
- agent_type_supported: input.agentTypeSupported === true || process.env.SKS_CODEX_AGENT_TYPE_SUPPORTED === '1',
44
- fallback: (input.agentTypeSupported === true || process.env.SKS_CODEX_AGENT_TYPE_SUPPORTED === '1') ? 'agent_type' : 'message-role',
70
+ agent_type_supported: agentTypeProbe.supported,
71
+ fallback: agentTypeProbe.supported ? 'agent_type' : 'message-role',
45
72
  codex_home: codexHome,
46
73
  directive_roles: DIRECTIVE_ROLES,
74
+ role_payloads: rolePayloads,
75
+ agent_type_probe: agentTypeProbe,
47
76
  created,
48
77
  base_repair: baseRepair,
49
- blockers: baseRepair.blockers || []
78
+ blockers: blockersOf(baseRepair)
50
79
  };
51
80
  await writeJsonAtomic(path.join(root, '.sneakoscope', 'reports', 'codex-agent-role-sync.json'), report).catch(() => undefined);
52
81
  return report;
53
82
  }
54
- function roleToml(role) {
83
+ function roleToml(role, payload) {
84
+ const strategyLine = payload?.strategy === 'agent_type'
85
+ ? `agent_type = "${payload.agent_type || role}"`
86
+ : `message_role_prefix = "${escapeToml(payload?.message_role_prefix || `Role: ${role}.`)}"`;
55
87
  return [
56
88
  `name = "${role}"`,
57
- `description = "SKS managed 3.1.4 directive role: ${role}"`,
89
+ `description = "SKS managed 3.1.5 directive role: ${role}"`,
90
+ strategyLine,
58
91
  'model_reasoning_effort = "medium"',
59
92
  role.includes('implementer') ? 'sandbox_mode = "workspace-write"' : 'sandbox_mode = "read-only"',
60
93
  'approval_policy = "never"',
61
94
  'developer_instructions = """',
62
- `You are ${role}. SKS managed 3.1.4 directive role. Respect bounded ownership and never clobber user files.`,
95
+ `You are ${role}. SKS managed 3.1.5 directive role.`,
96
+ 'Use the assigned scope only, cite concrete repo evidence, keep mutation surfaces bounded, and never clobber user files.',
97
+ 'Report blockers as evidence-backed findings and write route artifacts before claiming completion.',
98
+ `Execution role strategy: ${payload?.strategy || 'message-role'}. Probe: ${payload?.probe_artifact_path || '.sneakoscope/reports/codex-agent-type-probe.json'}.`,
63
99
  '"""',
64
100
  ''
65
101
  ].join('\n');
66
102
  }
103
+ function blockersOf(value) {
104
+ return Boolean(value) && typeof value === 'object' && Array.isArray(value.blockers)
105
+ ? (value.blockers).map((item) => String(item)).filter(Boolean)
106
+ : [];
107
+ }
108
+ function recordOk(value) {
109
+ return Boolean(value) && typeof value === 'object' && typeof value.ok === 'boolean'
110
+ ? value.ok
111
+ : undefined;
112
+ }
113
+ function escapeToml(value) {
114
+ return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
115
+ }
116
+ function messageOf(err) {
117
+ return err instanceof Error ? err.message : String(err);
118
+ }
67
119
  //# sourceMappingURL=codex-agent-role-sync.js.map
@@ -0,0 +1,202 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { findCodexBinary } from '../codex-adapter.js';
4
+ import { nowIso, runProcess, writeJsonAtomic } from '../fsx.js';
5
+ import { isRecord } from './codex-app-types.js';
6
+ export async function probeCodexAgentTypeSupport(root, input = {}) {
7
+ const env = input.env || process.env;
8
+ const fixture = await fixtureSchemaProbe(env);
9
+ if (fixture)
10
+ return persist(root, fixture, input.writeReport !== false);
11
+ const schema = await readSchemaFromEnv(env);
12
+ if (schema)
13
+ return persist(root, probeSchema(schema.value, schema.source, schema.schemaPath), input.writeReport !== false);
14
+ const doctor = await probeDoctorJson(input.codexBin, env);
15
+ if (doctor.source !== 'unknown')
16
+ return persist(root, doctor, input.writeReport !== false);
17
+ const help = await probeHelp(input.codexBin, env);
18
+ if (help.source !== 'unknown')
19
+ return persist(root, help, input.writeReport !== false);
20
+ const envProbe = envFallbackProbe(env);
21
+ if (envProbe)
22
+ return persist(root, envProbe, input.writeReport !== false);
23
+ return persist(root, {
24
+ schema: 'sks.codex-agent-type-probe.v1',
25
+ generated_at: nowIso(),
26
+ ok: true,
27
+ supported: false,
28
+ source: 'unknown',
29
+ spawn_tool_name: 'unknown',
30
+ schema_path: null,
31
+ evidence: [],
32
+ blockers: [],
33
+ warnings: ['agent_type_support_unknown_message_role_fallback']
34
+ }, input.writeReport !== false);
35
+ }
36
+ export function agentRolePayloadFor(role, probe) {
37
+ if (probe.supported)
38
+ return { strategy: 'agent_type', agent_type: role, probe_artifact_path: '.sneakoscope/reports/codex-agent-type-probe.json' };
39
+ return {
40
+ strategy: 'message-role',
41
+ message_role_prefix: `Role: ${role}. Use this as a message-level role because native agent_type is unavailable or unverified.`,
42
+ probe_artifact_path: '.sneakoscope/reports/codex-agent-type-probe.json'
43
+ };
44
+ }
45
+ async function fixtureSchemaProbe(env) {
46
+ const raw = env.SKS_CODEX_AGENT_TYPE_FIXTURE;
47
+ if (!raw)
48
+ return null;
49
+ const supported = raw === '1' || raw === 'supported' || raw === 'true';
50
+ return {
51
+ schema: 'sks.codex-agent-type-probe.v1',
52
+ generated_at: nowIso(),
53
+ ok: true,
54
+ supported,
55
+ source: 'fixture',
56
+ spawn_tool_name: supported ? 'spawn_agent' : 'unknown',
57
+ schema_path: supported ? 'fixture.spawn_agent.parameters.agent_type' : null,
58
+ evidence: [`fixture:${raw}`],
59
+ blockers: [],
60
+ warnings: []
61
+ };
62
+ }
63
+ async function readSchemaFromEnv(env) {
64
+ if (env.SKS_CODEX_TOOL_SCHEMA_FILE) {
65
+ const file = path.resolve(env.SKS_CODEX_TOOL_SCHEMA_FILE);
66
+ const text = await fs.readFile(file, 'utf8').catch(() => '');
67
+ if (text)
68
+ return { value: JSON.parse(text), source: 'codex-tool-schema', schemaPath: file };
69
+ }
70
+ if (env.SKS_CODEX_TOOL_SCHEMA_JSON) {
71
+ return { value: JSON.parse(env.SKS_CODEX_TOOL_SCHEMA_JSON), source: 'codex-tool-schema', schemaPath: 'env:SKS_CODEX_TOOL_SCHEMA_JSON' };
72
+ }
73
+ return null;
74
+ }
75
+ async function probeDoctorJson(codexBin, env) {
76
+ const bin = codexBin || env.CODEX_BIN || await findCodexBinary().catch(() => null);
77
+ if (!bin)
78
+ return unknownProbe(['codex_cli_missing']);
79
+ const run = await runProcess(bin, ['doctor', '--json'], { env, timeoutMs: 8000, maxOutputBytes: 256 * 1024 }).catch(() => null);
80
+ const text = `${run?.stdout || ''}${run?.stderr || ''}`.trim();
81
+ if (!run || run.code !== 0 || !text)
82
+ return unknownProbe(['codex_doctor_json_unavailable']);
83
+ try {
84
+ const parsed = JSON.parse(text);
85
+ const probed = probeSchema(parsed, 'codex-doctor-json', 'doctor-json');
86
+ return { ...probed, source: probed.supported ? 'codex-doctor-json' : 'unknown' };
87
+ }
88
+ catch {
89
+ return unknownProbe(['codex_doctor_json_parse_failed']);
90
+ }
91
+ }
92
+ async function probeHelp(codexBin, env) {
93
+ const bin = codexBin || env.CODEX_BIN || await findCodexBinary().catch(() => null);
94
+ if (!bin)
95
+ return unknownProbe(['codex_cli_missing']);
96
+ const run = await runProcess(bin, ['--help'], { env, timeoutMs: 5000, maxOutputBytes: 128 * 1024 }).catch(() => null);
97
+ const text = `${run?.stdout || ''}${run?.stderr || ''}`;
98
+ if (!run || run.code !== 0 || !text)
99
+ return unknownProbe(['codex_help_unavailable']);
100
+ const supported = /\bagent_type\b/.test(text) && /\bspawn_agent\b|\bmulti_agent_v2\b/.test(text);
101
+ return {
102
+ schema: 'sks.codex-agent-type-probe.v1',
103
+ generated_at: nowIso(),
104
+ ok: true,
105
+ supported,
106
+ source: supported ? 'codex-help' : 'unknown',
107
+ spawn_tool_name: text.includes('multi_agent_v2') ? 'multi_agent_v2' : supported ? 'spawn_agent' : 'unknown',
108
+ schema_path: supported ? 'codex --help' : null,
109
+ evidence: supported ? ['help_mentions_agent_type'] : [],
110
+ blockers: [],
111
+ warnings: supported ? [] : ['agent_type_not_found_in_help']
112
+ };
113
+ }
114
+ function envFallbackProbe(env) {
115
+ if (env.SKS_CODEX_AGENT_TYPE_SUPPORTED === undefined)
116
+ return null;
117
+ if (env.SKS_CODEX_AGENT_TYPE_ALLOW_ENV_FALLBACK !== '1' && env.NODE_ENV !== 'test') {
118
+ return {
119
+ schema: 'sks.codex-agent-type-probe.v1',
120
+ generated_at: nowIso(),
121
+ ok: true,
122
+ supported: false,
123
+ source: 'env',
124
+ spawn_tool_name: 'unknown',
125
+ schema_path: null,
126
+ evidence: [],
127
+ blockers: [],
128
+ warnings: ['env_agent_type_fallback_ignored_outside_test_mode']
129
+ };
130
+ }
131
+ const supported = env.SKS_CODEX_AGENT_TYPE_SUPPORTED === '1';
132
+ return {
133
+ schema: 'sks.codex-agent-type-probe.v1',
134
+ generated_at: nowIso(),
135
+ ok: true,
136
+ supported,
137
+ source: 'env',
138
+ spawn_tool_name: supported ? 'spawn_agent' : 'unknown',
139
+ schema_path: supported ? 'env:SKS_CODEX_AGENT_TYPE_SUPPORTED' : null,
140
+ evidence: [`env:SKS_CODEX_AGENT_TYPE_SUPPORTED=${env.SKS_CODEX_AGENT_TYPE_SUPPORTED}`],
141
+ blockers: [],
142
+ warnings: ['env_agent_type_fallback_test_only']
143
+ };
144
+ }
145
+ function probeSchema(value, source, schemaPath) {
146
+ const found = findAgentType(value);
147
+ return {
148
+ schema: 'sks.codex-agent-type-probe.v1',
149
+ generated_at: nowIso(),
150
+ ok: true,
151
+ supported: found.supported,
152
+ source,
153
+ spawn_tool_name: found.tool,
154
+ schema_path: found.path || schemaPath,
155
+ evidence: found.supported ? [`agent_type:${found.path || 'found'}`] : ['agent_type_absent'],
156
+ blockers: [],
157
+ warnings: found.supported ? [] : ['agent_type_not_supported_message_role_fallback']
158
+ };
159
+ }
160
+ function findAgentType(value, trail = []) {
161
+ if (Array.isArray(value)) {
162
+ for (let index = 0; index < value.length; index += 1) {
163
+ const found = findAgentType(value[index], [...trail, String(index)]);
164
+ if (found.supported)
165
+ return found;
166
+ }
167
+ return { supported: false, tool: 'unknown', path: null };
168
+ }
169
+ if (!isRecord(value))
170
+ return { supported: false, tool: 'unknown', path: null };
171
+ const name = String(value.name || value.tool || value.id || '');
172
+ const tool = name.includes('multi_agent_v2') ? 'multi_agent_v2' : name.includes('spawn_agent') ? 'spawn_agent' : 'unknown';
173
+ if ('agent_type' in value || isRecord(value.properties) && 'agent_type' in value.properties) {
174
+ return { supported: true, tool: tool === 'unknown' ? 'spawn_agent' : tool, path: [...trail, 'agent_type'].join('.') };
175
+ }
176
+ for (const [key, entry] of Object.entries(value)) {
177
+ const found = findAgentType(entry, [...trail, key]);
178
+ if (found.supported)
179
+ return { ...found, tool: found.tool === 'unknown' && tool !== 'unknown' ? tool : found.tool };
180
+ }
181
+ return { supported: false, tool, path: null };
182
+ }
183
+ function unknownProbe(blockers) {
184
+ return {
185
+ schema: 'sks.codex-agent-type-probe.v1',
186
+ generated_at: nowIso(),
187
+ ok: blockers.length === 0,
188
+ supported: false,
189
+ source: 'unknown',
190
+ spawn_tool_name: 'unknown',
191
+ schema_path: null,
192
+ evidence: [],
193
+ blockers,
194
+ warnings: ['agent_type_support_unknown_message_role_fallback']
195
+ };
196
+ }
197
+ async function persist(root, report, writeReport) {
198
+ if (writeReport)
199
+ await writeJsonAtomic(path.join(root, '.sneakoscope', 'reports', 'codex-agent-type-probe.json'), report).catch(() => undefined);
200
+ return report;
201
+ }
202
+ //# sourceMappingURL=codex-agent-type-probe.js.map
@@ -1,13 +1,14 @@
1
- // @ts-nocheck
2
1
  import path from 'node:path';
3
2
  import { nowIso, writeJsonAtomic } from '../fsx.js';
4
3
  import { buildCodexAppHarnessMatrix } from './codex-app-harness-matrix.js';
4
+ import { isCodexAppHarnessMatrix } from './codex-app-types.js';
5
5
  export async function resolveCodexAppExecutionProfile(input = { root: process.cwd() }) {
6
6
  const root = path.resolve(input.root || process.cwd());
7
- const matrix = input.matrix || await buildCodexAppHarnessMatrix({ root }).catch(() => null);
8
- const mode = !matrix?.codex_cli?.available
7
+ const maybeMatrix = input.matrix || await buildCodexAppHarnessMatrix({ root }).catch(() => null);
8
+ const matrix = isCodexAppHarnessMatrix(maybeMatrix) ? maybeMatrix : null;
9
+ const mode = !matrix?.codex_cli.available
9
10
  ? 'degraded-no-app'
10
- : matrix.app_features?.app_handoff_ready && matrix.app_features?.agent_type_supported
11
+ : matrix.app_features.app_handoff_ready && matrix.app_features.agent_type_supported
11
12
  ? 'codex-app-native'
12
13
  : matrix.codex_cli.available
13
14
  ? 'codex-cli-headless'
@@ -17,12 +18,18 @@ export async function resolveCodexAppExecutionProfile(input = { root: process.cw
17
18
  generated_at: nowIso(),
18
19
  ok: mode !== 'degraded-no-app',
19
20
  mode,
20
- agent_role_strategy: matrix?.app_features?.agent_type_supported ? 'agent_type' : 'message-role',
21
+ agent_role_strategy: matrix?.app_features.agent_type_supported ? 'agent_type' : 'message-role',
21
22
  hooks_assumed_running: false,
22
- hooks_approval_required: matrix?.app_features?.hook_approval_state_detectable !== true,
23
- app_handoff_ready: matrix?.app_features?.app_handoff_ready === true,
24
- image_path_exposure_ready: matrix?.app_features?.image_path_exposure_ready === true,
23
+ hooks_approval_required: matrix?.app_features.hook_approval_state !== 'approved',
24
+ hook_approval_state: matrix?.app_features.hook_approval_state || 'unknown',
25
+ app_handoff_ready: matrix?.app_features.app_handoff_ready === true,
26
+ image_path_exposure_ready: matrix?.app_features.image_path_exposure_ready === true,
27
+ plugin_mcp_inventory_ready: matrix?.app_features.mcp_inventory_ready === true,
25
28
  loop_mesh_app_profile_available: true,
29
+ artifact_path: '.sneakoscope/reports/codex-app-execution-profile.json',
30
+ matrix_artifact_path: '.sneakoscope/reports/codex-app-harness-matrix.json',
31
+ agent_type_probe_artifact_path: '.sneakoscope/reports/codex-agent-type-probe.json',
32
+ hook_approval_probe_artifact_path: '.sneakoscope/reports/codex-hook-approval-probe.json',
26
33
  blockers: mode === 'degraded-no-app' ? ['codex_cli_missing'] : [],
27
34
  warnings: matrix?.warnings || []
28
35
  };
@@ -4,8 +4,9 @@ import { ensureDir, nowIso, readText, sha256, writeJsonAtomic, writeTextAtomic }
4
4
  import { codexHome, scanProjectLocalForbiddenKeys, snapshotCodexAppUiState } from './codex-app-ui-state-snapshot.js';
5
5
  import { assertCodexAppUiMutationAllowed } from './codex-app-ui-clobber-guard.js';
6
6
  export const CODEX_APP_FAST_UI_REPAIR_SCHEMA = 'sks.codex-app-fast-ui-repair.v1';
7
- const HOST_OWNED_TOP_LEVEL_RE = /^\s*(openai_base_url|chatgpt_base_url|apps_mcp_product_sku|model_provider|notify|profile|experimental_realtime_ws_base_url|service_tier)\s*=/;
8
- const HOST_OWNED_TABLE_RE = /^\s*\[(model_providers(?:[.\]].*)?|profiles(?:[.\]].*)?|otel(?:[.\]].*)?|user\.fast_mode(?:[.\]].*)?)\]\s*$/;
7
+ const FAST_UI_TOP_LEVEL_RE = /^\s*service_tier\s*=/;
8
+ const FAST_UI_FEATURE_LINE_RE = /^\s*fast_mode\s*=/;
9
+ const FAST_UI_USER_TABLE_LINE_RE = /^\s*(enabled|visible|locked|hidden|disabled)\s*=/;
9
10
  const SKS_CAUSED_RE = /(?:SKS|Sneakoscope|codex-lb|sks-mad|sks fast)/i;
10
11
  export async function repairCodexAppFastUi(root = process.cwd(), input = {}) {
11
12
  const resolvedRoot = path.resolve(root);
@@ -124,8 +125,10 @@ function stripProjectLocalForbiddenKeys(text) {
124
125
  }
125
126
  function stripSksCausedHostOwnedLines(text) {
126
127
  return stripMatchingLines(text, (line, table, previous, next) => {
127
- const isHostOwned = HOST_OWNED_TOP_LEVEL_RE.test(line) || HOST_OWNED_TABLE_RE.test(line) || Boolean(table && /^(model_providers|profiles|otel|user\.fast_mode)/.test(table));
128
- return isHostOwned && (SKS_CAUSED_RE.test(line) || SKS_CAUSED_RE.test(previous) || SKS_CAUSED_RE.test(next));
128
+ const isFastUiLine = FAST_UI_TOP_LEVEL_RE.test(line)
129
+ || (table === 'features' && FAST_UI_FEATURE_LINE_RE.test(line))
130
+ || (table === 'user.fast_mode' && FAST_UI_USER_TABLE_LINE_RE.test(line));
131
+ return isFastUiLine && (SKS_CAUSED_RE.test(line) || SKS_CAUSED_RE.test(previous) || SKS_CAUSED_RE.test(next));
129
132
  });
130
133
  }
131
134
  function stripMatchingLines(text, shouldRemove) {