sneakoscope 6.1.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +35 -11
  2. package/crates/sks-core/Cargo.lock +1 -1
  3. package/crates/sks-core/Cargo.toml +1 -1
  4. package/dist/bin/fast-inline.js +18 -9
  5. package/dist/bin/sks-dispatch.js +2 -2
  6. package/dist/cli/args.js +2 -0
  7. package/dist/cli/command-manifest-lite.js +2 -3
  8. package/dist/cli/command-registry.js +3 -4
  9. package/dist/cli/help-fast.js +1 -1
  10. package/dist/cli/install-helpers.js +116 -306
  11. package/dist/cli/install-tool-helpers.js +287 -0
  12. package/dist/cli/router.js +40 -4
  13. package/dist/commands/codex-lb.js +51 -20
  14. package/dist/commands/codex.js +39 -1
  15. package/dist/commands/doctor.js +242 -20
  16. package/dist/commands/tmux.js +5 -1
  17. package/dist/commands/zellij-monitor-pane.js +2 -0
  18. package/dist/commands/zellij-viewport-pane.js +3 -1
  19. package/dist/commands/zellij.js +1 -1
  20. package/dist/config/skills-manifest.json +59 -59
  21. package/dist/core/agent-bridge/agent-manifest.js +48 -0
  22. package/dist/core/agents/agent-command-surface.js +2 -1
  23. package/dist/core/agents/agent-effort-policy.js +38 -35
  24. package/dist/core/agents/agent-plan.js +100 -21
  25. package/dist/core/agents/agent-role-config.js +43 -46
  26. package/dist/core/agents/agent-runner-codex-exec.js +16 -3
  27. package/dist/core/agents/agent-schema.js +3 -2
  28. package/dist/core/agents/native-cli-session-swarm.js +1 -1
  29. package/dist/core/agents/zellij-right-lane-cockpit.js +2 -2
  30. package/dist/core/codex/agent-config-file-repair.js +94 -193
  31. package/dist/core/codex/codex-cli-update.js +723 -0
  32. package/dist/core/codex/codex-config-guard.js +185 -9
  33. package/dist/core/codex/codex-config-readability.js +21 -8
  34. package/dist/core/codex/codex-config-toml.js +14 -11
  35. package/dist/core/codex/codex-project-config-policy.js +3 -6
  36. package/dist/core/codex/codex-startup-config-postcheck.js +52 -42
  37. package/dist/core/codex-adapter.js +35 -22
  38. package/dist/core/codex-app/codex-agent-role-sync.js +13 -54
  39. package/dist/core/codex-app/codex-app-launcher.js +48 -17
  40. package/dist/core/codex-app/codex-app-restart.js +23 -2
  41. package/dist/core/codex-app/mcp-manager.js +679 -0
  42. package/dist/core/codex-app/sks-menubar.js +533 -8
  43. package/dist/core/codex-control/codex-0139-image-path-real-probe.js +15 -4
  44. package/dist/core/codex-control/codex-0139-web-search-probe.js +17 -6
  45. package/dist/core/codex-control/codex-lb-launch-recovery.js +293 -0
  46. package/dist/core/codex-control/codex-reliability-shield.js +89 -29
  47. package/dist/core/codex-control/codex-sdk-adapter.js +44 -8
  48. package/dist/core/codex-control/codex-task-runner.js +62 -9
  49. package/dist/core/codex-control/python-codex-sdk-adapter.js +30 -3
  50. package/dist/core/codex-exec-output-schema.js +35 -6
  51. package/dist/core/codex-lb/codex-lb-env.js +1 -1
  52. package/dist/core/codex-lb/codex-lb-tool-output-recovery.js +291 -0
  53. package/dist/core/codex-native/codex-native-feature-broker.js +9 -16
  54. package/dist/core/codex-native/codex-native-repair-transaction.js +1 -1
  55. package/dist/core/codex-native/core-skill-manifest.js +8 -4
  56. package/dist/core/codex-runtime/codex-desktop-config-policy.js +2 -3
  57. package/dist/core/commands/agent-bridge-command.js +23 -2
  58. package/dist/core/commands/agent-command.js +19 -5
  59. package/dist/core/commands/basic-cli.js +47 -6
  60. package/dist/core/commands/command-utils.js +1 -1
  61. package/dist/core/commands/mad-sks-command.js +76 -10
  62. package/dist/core/commands/menubar-command.js +94 -0
  63. package/dist/core/commands/naruto-command.js +645 -1156
  64. package/dist/core/commands/research-command.js +293 -231
  65. package/dist/core/commands/run-command.js +100 -23
  66. package/dist/core/commands/team-command.js +2 -3
  67. package/dist/core/commands/team-legacy-observe-command.js +94 -359
  68. package/dist/core/commands/wiki-command.js +11 -5
  69. package/dist/core/db-safety.js +2 -2
  70. package/dist/core/decision-lattice.js +6 -6
  71. package/dist/core/doctor/codex-startup-config-repair.js +8 -3
  72. package/dist/core/doctor/doctor-codex-startup-repair.js +6 -141
  73. package/dist/core/feature-fixture-executor.js +71 -7
  74. package/dist/core/feature-fixture-runner.js +53 -12
  75. package/dist/core/feature-fixtures.js +47 -14
  76. package/dist/core/feature-registry.js +28 -27
  77. package/dist/core/fsx.js +1 -0
  78. package/dist/core/harness-conflicts.js +18 -9
  79. package/dist/core/hooks-runtime/code-pack-freshness-preflight.js +14 -8
  80. package/dist/core/hooks-runtime/hook-io.js +8 -4
  81. package/dist/core/hooks-runtime/light-turn.js +70 -0
  82. package/dist/core/hooks-runtime/naruto-decision-gate.js +184 -0
  83. package/dist/core/hooks-runtime/payload-signals.js +270 -0
  84. package/dist/core/hooks-runtime/stop-repeat-guard.js +89 -0
  85. package/dist/core/hooks-runtime/team-digest.js +0 -1
  86. package/dist/core/hooks-runtime/tool-output-quarantine.js +93 -0
  87. package/dist/core/hooks-runtime.js +438 -354
  88. package/dist/core/init/skills.js +16 -30
  89. package/dist/core/init.js +144 -36
  90. package/dist/core/managed-assets/managed-assets-manifest.js +566 -10
  91. package/dist/core/mission.js +24 -1
  92. package/dist/core/pipeline-internals/runtime-core.js +570 -177
  93. package/dist/core/pipeline-internals/runtime-gates.js +174 -48
  94. package/dist/core/preflight/parallel-preflight-engine.js +66 -4
  95. package/dist/core/proof/route-adapter.js +1 -1
  96. package/dist/core/proof/route-proof-gate.js +7 -2
  97. package/dist/core/proof/selftest-proof-fixtures.js +3 -5
  98. package/dist/core/proof-field.js +1 -1
  99. package/dist/core/provider/model-router.js +42 -31
  100. package/dist/core/recallpulse/policy.js +12 -28
  101. package/dist/core/recallpulse.js +11 -6
  102. package/dist/core/release/npm-pack-proof.js +247 -0
  103. package/dist/core/release/package-dist-snapshot.js +151 -0
  104. package/dist/core/release/package-size-budget.js +4 -1
  105. package/dist/core/release/release-authorization-snapshot.js +115 -0
  106. package/dist/core/release/release-gate-affected-selector.js +14 -2
  107. package/dist/core/release/release-gate-cache-v2.js +30 -0
  108. package/dist/core/release/release-gate-contract.js +161 -0
  109. package/dist/core/release/release-gate-dag.js +1 -0
  110. package/dist/core/release/release-real-contract.js +90 -10
  111. package/dist/core/release-parallel-full-coverage.js +31 -143
  112. package/dist/core/research/claim-evidence-matrix.js +41 -6
  113. package/dist/core/research/experiment-plan.js +14 -10
  114. package/dist/core/research/falsification.js +9 -2
  115. package/dist/core/research/implementation-blueprint-densifier.js +82 -60
  116. package/dist/core/research/implementation-blueprint.js +32 -26
  117. package/dist/core/research/mock-result.js +122 -11
  118. package/dist/core/research/replication-pack.js +15 -8
  119. package/dist/core/research/research-adversarial-review.js +1068 -0
  120. package/dist/core/research/research-claim-builder.js +69 -17
  121. package/dist/core/research/research-claim-synthesizer.js +343 -0
  122. package/dist/core/research/research-cycle-runner.js +53 -3
  123. package/dist/core/research/research-falsification-runner.js +176 -0
  124. package/dist/core/research/research-final-reviewer.js +44 -125
  125. package/dist/core/research/research-plan-markdown.js +123 -0
  126. package/dist/core/research/research-realistic-report.js +14 -6
  127. package/dist/core/research/research-review-artifact-digest.js +66 -0
  128. package/dist/core/research/research-source-evidence.js +144 -0
  129. package/dist/core/research/research-source-layer-catalog.js +68 -0
  130. package/dist/core/research/research-source-ledger-merge.js +250 -12
  131. package/dist/core/research/research-source-shards.js +26 -70
  132. package/dist/core/research/research-stage-runner.js +237 -247
  133. package/dist/core/research/research-super-search.js +188 -0
  134. package/dist/core/research/research-synthesis-prompt.js +20 -1
  135. package/dist/core/research/research-synthesis-writer.js +86 -5
  136. package/dist/core/research/research-work-graph.js +25 -18
  137. package/dist/core/research/source-quality-report.js +21 -0
  138. package/dist/core/research.js +424 -390
  139. package/dist/core/retention.js +70 -2
  140. package/dist/core/routes/constants.js +1 -1
  141. package/dist/core/routes/dollar-manifest-lite.js +11 -11
  142. package/dist/core/routes.js +149 -69
  143. package/dist/core/runtime/task-profile.js +66 -0
  144. package/dist/core/runtime/verification-budget.js +12 -0
  145. package/dist/core/security/high-risk-contracts.js +6 -6
  146. package/dist/core/stop-gate/stop-gate-check.js +49 -12
  147. package/dist/core/subagents/agent-catalog.js +287 -0
  148. package/dist/core/subagents/model-policy.js +259 -0
  149. package/dist/core/subagents/naruto-help-contract.js +47 -0
  150. package/dist/core/subagents/official-subagent-config.js +488 -0
  151. package/dist/core/subagents/official-subagent-preparation.js +297 -0
  152. package/dist/core/subagents/official-subagent-prompt.js +159 -0
  153. package/dist/core/subagents/official-subagent-runner.js +129 -0
  154. package/dist/core/subagents/subagent-evidence.js +663 -0
  155. package/dist/core/subagents/terminology.js +16 -0
  156. package/dist/core/subagents/thread-budget.js +21 -0
  157. package/dist/core/subagents/triwiki-attention.js +168 -0
  158. package/dist/core/super-search/runtime-helpers.js +173 -19
  159. package/dist/core/super-search/runtime.js +140 -15
  160. package/dist/core/super-search/source-records.js +49 -8
  161. package/dist/core/team-review-policy.js +15 -0
  162. package/dist/core/triwiki/code-pack-head-freshness.js +291 -0
  163. package/dist/core/triwiki/triwiki-module-card.js +1 -1
  164. package/dist/core/triwiki-wrongness/wrongness-ledger.js +9 -2
  165. package/dist/core/version-manager.js +51 -1
  166. package/dist/core/version.js +1 -1
  167. package/dist/core/work-order-ledger.js +40 -1
  168. package/dist/core/zellij/zellij-fake-adapter.js +3 -1
  169. package/dist/core/zellij/zellij-launcher.js +49 -10
  170. package/dist/core/zellij/zellij-layout-builder.js +14 -5
  171. package/dist/core/zellij/zellij-official-subagent-activity.js +477 -0
  172. package/dist/core/zellij/zellij-official-subagent-telemetry.js +264 -0
  173. package/dist/core/zellij/zellij-pane-proof.js +9 -1
  174. package/dist/core/zellij/zellij-slot-pane-renderer.js +17 -5
  175. package/dist/core/zellij/zellij-slot-telemetry.js +15 -3
  176. package/dist/core/zellij/zellij-ui-mode.js +1 -1
  177. package/dist/core/zellij/zellij-update.js +14 -1
  178. package/dist/core/zellij/zellij-viewport-binder.js +3 -0
  179. package/dist/scripts/agent-role-config-repair-check.js +14 -16
  180. package/dist/scripts/architecture-guard-check.js +8 -1
  181. package/dist/scripts/canonical-test-runner.js +7 -1
  182. package/dist/scripts/check-route-modularity.js +0 -1
  183. package/dist/scripts/check-ts-contracts.js +1 -1
  184. package/dist/scripts/codex-control-all-pipelines-check.js +7 -3
  185. package/dist/scripts/codex-control-tool-output-continuity-audit-check.js +27 -0
  186. package/dist/scripts/codex-lb-fast-mode-truth-check.js +11 -1
  187. package/dist/scripts/codex-lb-fast-ui-preservation-check.js +9 -2
  188. package/dist/scripts/codex-lb-gpt56-fast-profile-check.js +13 -2
  189. package/dist/scripts/codex-native-agent-role-content-check.js +27 -7
  190. package/dist/scripts/codex-native-repair-transaction-check.js +3 -1
  191. package/dist/scripts/codex-sdk-all-pipelines-check.js +7 -4
  192. package/dist/scripts/codex-sdk-backend-router-check.js +2 -0
  193. package/dist/scripts/codex-sdk-research-pipeline-check.js +30 -8
  194. package/dist/scripts/db-route-materialization-check.js +33 -0
  195. package/dist/scripts/docs-truthfulness-check.js +3 -1
  196. package/dist/scripts/doctor-codex-startup-repair-check.js +12 -15
  197. package/dist/scripts/doctor-fix-production-blackbox.js +12 -2
  198. package/dist/scripts/doctor-startup-config-repair-blackbox.js +8 -2
  199. package/dist/scripts/doctor-startup-config-repair-check.js +12 -2
  200. package/dist/scripts/install-update-preserves-config-check.js +6 -1
  201. package/dist/scripts/lib/codex-sdk-gate-lib.js +4 -0
  202. package/dist/scripts/mad-sks-app-ui-no-mutation-check.js +0 -1
  203. package/dist/scripts/managed-role-manifest-parity-check.js +5 -4
  204. package/dist/scripts/naruto-codex-e2e-check.js +14 -7
  205. package/dist/scripts/naruto-shadow-clone-swarm-check.js +4 -201
  206. package/dist/scripts/npm-publish-performance-check.js +20 -12
  207. package/dist/scripts/official-subagent-workflow-check.js +145 -0
  208. package/dist/scripts/package-published-contract-check.js +6 -29
  209. package/dist/scripts/packlist-performance-check.js +18 -21
  210. package/dist/scripts/parallel-verification-engine-check.js +2 -2
  211. package/dist/scripts/prepublish-release-check-or-fast.js +23 -86
  212. package/dist/scripts/python-codex-sdk-all-pipelines-check.js +8 -0
  213. package/dist/scripts/release-affected-selector-check.js +74 -1
  214. package/dist/scripts/release-check-stamp.js +153 -248
  215. package/dist/scripts/release-dag-full-coverage-check.js +7 -15
  216. package/dist/scripts/release-dynamic-presets-check.js +2 -1
  217. package/dist/scripts/release-gate-dag-runner-check.js +0 -1
  218. package/dist/scripts/release-gate-dag-runner.js +12 -1
  219. package/dist/scripts/release-gate-existence-audit.js +1 -2
  220. package/dist/scripts/release-parallel-full-coverage-check.js +12 -6
  221. package/dist/scripts/release-parallel-speed-budget-check.js +18 -2
  222. package/dist/scripts/release-real-check.js +26 -4
  223. package/dist/scripts/release-registry-check.js +61 -16
  224. package/dist/scripts/research-blueprint-densifier-check.js +2 -2
  225. package/dist/scripts/research-real-cycle-no-legacy-final-md-check.js +11 -7
  226. package/dist/scripts/sizecheck.js +2 -2
  227. package/dist/scripts/sks-3-1-4-directive-check-lib.js +8 -2
  228. package/dist/scripts/sks-3-1-5-directive-check-lib.js +3 -2
  229. package/dist/scripts/sks-3-1-6-directive-check-lib.js +5 -3
  230. package/dist/scripts/sks-menubar-install-check.js +14 -1
  231. package/dist/scripts/super-search-provider-interface-check.js +31 -18
  232. package/dist/scripts/trust-fixture-check.js +32 -10
  233. package/dist/scripts/wrongness-fixture-check.js +1 -1
  234. package/dist/scripts/zellij-layout-valid-check.js +5 -5
  235. package/dist/scripts/zellij-spawn-on-demand-layout-check.js +3 -3
  236. package/docs/demo.tape +1 -1
  237. package/infra-harness-gates.json +1486 -0
  238. package/package.json +15 -10
  239. package/release-gates.v2.json +4060 -0
  240. package/runtime-required-scripts.json +9 -0
  241. package/dist/commands/db.js +0 -6
  242. package/dist/core/commands/db-command.js +0 -146
  243. package/dist/core/research/prompt.js +0 -15
  244. package/dist/scripts/codex-0139-feature-probes-check.js +0 -30
  245. package/dist/scripts/codex-0139-marketplace-source-check.js +0 -13
  246. package/dist/scripts/codex-control-tool-call-sequence-repair-check.js +0 -14
@@ -1,227 +1,128 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import { ensureDir, nowIso, writeJsonAtomic, writeTextAtomic } from '../fsx.js';
4
- import { managedAgentRoleConfigForFile, managedAgentRoleConfigForRole } from '../agents/agent-role-config.js';
5
- import { isUnmanagedProjectCodexConfig, writeCodexConfigGuarded } from './codex-config-guard.js';
3
+ import { nowIso, readJson, writeJsonAtomic } from '../fsx.js';
4
+ import { backupInvalidToml, inspectOfficialSubagentToml, mergeOfficialSubagentConfig, officialSubagentConfigOwnershipProof, officialSubagentConfigWarnings, readInheritedOfficialSubagentConfigText } from '../subagents/official-subagent-config.js';
5
+ import { writeCodexConfigGuarded } from './codex-config-guard.js';
6
+ /**
7
+ * Compatibility entrypoint retained for doctor callers. It repairs the
8
+ * official project [agents] settings and removes only exact legacy SKS child
9
+ * tables after ownership has been proven. User-authored child tables remain.
10
+ */
6
11
  export async function repairAgentConfigFileReferences(input) {
7
12
  const root = path.resolve(input.root);
8
13
  const configPath = path.join(root, '.codex', 'config.toml');
9
14
  const configExists = await fs.stat(configPath).then((stat) => stat.isFile()).catch(() => false);
10
- const original = configExists ? await fs.readFile(configPath, 'utf8').catch(() => '') : minimalManagedConfigToml();
11
- if (input.apply && configExists && isUnmanagedProjectCodexConfig(root, configPath, original)) {
12
- const report = {
15
+ const original = configExists ? await fs.readFile(configPath, 'utf8').catch(() => '') : '';
16
+ const manifest = await readJson(path.join(root, '.sneakoscope', 'manifest.json'), null);
17
+ const migrationReceipt = await readJson(path.join(root, '.sneakoscope', 'update', 'migration-receipt.json'), null);
18
+ const ownershipProof = officialSubagentConfigOwnershipProof({
19
+ text: original,
20
+ manifest,
21
+ migrationReceipt
22
+ });
23
+ const originalValidation = inspectOfficialSubagentToml(original);
24
+ if (configExists && !originalValidation.ok) {
25
+ const backupPath = input.apply
26
+ ? await backupInvalidToml(configPath, original, 'doctor-project-config-invalid')
27
+ : null;
28
+ return writeReport(input.reportPath, root, {
13
29
  schema: 'sks.agent-config-file-repair.v1',
14
30
  generated_at: nowIso(),
15
31
  ok: false,
16
- apply: true,
32
+ apply: input.apply === true,
17
33
  config_path: configPath,
34
+ backup_path: backupPath,
18
35
  repaired_paths: [],
19
36
  created_files: [],
20
37
  removed_unsupported_fields: [],
21
38
  skipped_unmanaged_paths: [],
22
39
  manual_required: true,
23
- blockers: ['user_owned_file_without_sks_marker']
24
- };
25
- if (input.reportPath !== null)
26
- await writeJsonAtomic(input.reportPath || path.join(root, '.sneakoscope', 'reports', 'agent-config-file-repair.json'), report).catch(() => undefined);
27
- return report;
28
- }
29
- const createdFiles = [];
30
- const repairedPaths = [];
31
- const removedUnsupportedFields = [];
32
- const skippedUnmanagedPaths = [];
33
- const edits = [];
34
- let text = original;
35
- for (const block of tomlBlocks(original)) {
36
- const managed = managedBlockTarget(root, block);
37
- const currentConfigFile = stringValue(block.text, 'config_file');
38
- if (!managed) {
39
- if (currentConfigFile && !path.isAbsolute(currentConfigFile))
40
- skippedUnmanagedPaths.push(currentConfigFile);
41
- continue;
42
- }
43
- const target = path.join(root, '.codex', 'agents', managed.file);
44
- let replacement = removeKey(block.text, 'message_role_prefix', removedUnsupportedFields);
45
- replacement = replaceOrInsertKey(replacement, 'config_file', `"${escapeToml(target)}"`);
46
- if (replacement !== block.text) {
47
- edits.push({ start: block.start, end: block.end, replacement });
48
- repairedPaths.push(target);
49
- }
50
- if (input.apply) {
51
- const exists = await fs.stat(target).then((stat) => stat.isFile()).catch(() => false);
52
- if (!exists) {
53
- await ensureDir(path.dirname(target));
54
- await writeTextAtomic(target, managed.content);
55
- createdFiles.push(target);
56
- }
57
- }
40
+ blockers: [
41
+ 'project_official_subagent_config_toml_parse_failed',
42
+ ...(!ownershipProof.owned ? ['user_owned_file_without_sks_marker'] : [])
43
+ ],
44
+ warnings: [],
45
+ ownership_proof: ownershipProof
46
+ });
58
47
  }
59
- if (edits.length)
60
- text = applyEdits(original, edits);
61
- if (input.apply && !configExists) {
62
- await ensureDir(path.dirname(configPath));
63
- await writeCodexConfigGuarded({
64
- root,
65
- configPath,
66
- before: '',
67
- cause: 'agent-config-file-repair',
68
- mutate: () => text.replace(/\n{3,}/g, '\n\n').replace(/\s*$/, '\n')
48
+ if (input.apply && configExists && !ownershipProof.owned) {
49
+ return writeReport(input.reportPath, root, {
50
+ schema: 'sks.agent-config-file-repair.v1',
51
+ generated_at: nowIso(),
52
+ ok: false,
53
+ apply: true,
54
+ config_path: configPath,
55
+ backup_path: null,
56
+ repaired_paths: [],
57
+ created_files: [],
58
+ removed_unsupported_fields: [],
59
+ skipped_unmanaged_paths: [],
60
+ manual_required: true,
61
+ blockers: ['user_owned_file_without_sks_marker'],
62
+ warnings: [],
63
+ ownership_proof: ownershipProof
69
64
  });
70
- createdFiles.push(configPath);
71
65
  }
72
- else if (input.apply && text !== original) {
73
- await writeCodexConfigGuarded({
66
+ const inheritedText = await readInheritedOfficialSubagentConfigText(configPath, {
67
+ ...(input.home ? { home: input.home } : {}),
68
+ ...(input.codexHome ? { codexHome: input.codexHome } : {})
69
+ });
70
+ const merged = mergeOfficialSubagentConfig(original, {
71
+ sksOwned: ownershipProof.owned,
72
+ inheritedText
73
+ });
74
+ const validation = inspectOfficialSubagentToml(merged);
75
+ const warnings = officialSubagentConfigWarnings(merged, inheritedText);
76
+ const blockers = [];
77
+ let changed = merged !== original;
78
+ let writeSucceeded = input.apply !== true;
79
+ let backupPath = null;
80
+ if (input.apply) {
81
+ const guarded = await writeCodexConfigGuarded({
74
82
  root,
75
83
  configPath,
76
84
  before: original,
77
- cause: 'agent-config-file-repair',
78
- mutate: () => text.replace(/\n{3,}/g, '\n\n').replace(/\s*$/, '\n')
85
+ cause: 'official-subagent-config-repair',
86
+ ownershipVerified: ownershipProof.owned,
87
+ mutate: () => merged
79
88
  });
89
+ writeSucceeded = guarded.ok;
90
+ changed = guarded.ok && guarded.changed;
91
+ backupPath = guarded.backup_path;
92
+ if (!guarded.ok)
93
+ blockers.push(`config_write_guard:${guarded.status}`);
94
+ }
95
+ else if (!validation.ok) {
96
+ blockers.push('project_official_subagent_config_toml_parse_failed');
80
97
  }
81
- const effectiveText = input.apply ? await fs.readFile(configPath, 'utf8').catch(() => text) : text;
82
- const missing = await missingAgentConfigFiles(effectiveText);
83
- const unsupportedManagedFields = managedAgentBlocks(effectiveText)
84
- .flatMap((block) => block.text.split(/\r?\n/).filter((line) => /^\s*message_role_prefix\s*=/.test(line)));
85
98
  const report = {
86
99
  schema: 'sks.agent-config-file-repair.v1',
87
100
  generated_at: nowIso(),
88
- ok: missing.length === 0 && !/^\s*message_role_prefix\s*=/m.test(text),
101
+ ok: blockers.length === 0,
89
102
  apply: input.apply === true,
90
103
  config_path: configPath,
91
- repaired_paths: repairedPaths,
92
- created_files: createdFiles,
93
- removed_unsupported_fields: removedUnsupportedFields,
94
- skipped_unmanaged_paths: skippedUnmanagedPaths,
95
- manual_required: skippedUnmanagedPaths.length > 0,
96
- blockers: [
97
- ...missing.map((file) => `missing_agent_config_file:${file}`),
98
- ...unsupportedManagedFields.map(() => 'unsupported_message_role_prefix_field')
99
- ]
104
+ backup_path: backupPath,
105
+ repaired_paths: changed && writeSucceeded ? [configPath] : [],
106
+ created_files: input.apply === true && !configExists && changed && writeSucceeded ? [configPath] : [],
107
+ removed_unsupported_fields: [],
108
+ skipped_unmanaged_paths: [],
109
+ manual_required: blockers.length > 0,
110
+ blockers,
111
+ warnings,
112
+ ownership_proof: ownershipProof
100
113
  };
101
- report.ok = report.blockers.length === 0;
102
- if (input.reportPath !== null)
103
- await writeJsonAtomic(input.reportPath || path.join(root, '.sneakoscope', 'reports', 'agent-config-file-repair.json'), report).catch(() => undefined);
104
- return report;
114
+ return writeReport(input.reportPath, root, report);
105
115
  }
106
- export async function missingAgentConfigFiles(text) {
107
- const rows = managedAgentBlocks(text)
108
- .map((block) => stringValue(block.text, 'config_file'))
109
- .filter((file) => Boolean(file));
110
- const missing = [];
111
- for (const file of rows) {
112
- if (!path.isAbsolute(file)) {
113
- missing.push(file);
114
- continue;
115
- }
116
- const ok = await fs.stat(file).then((stat) => stat.isFile()).catch(() => false);
117
- if (!ok)
118
- missing.push(file);
119
- }
120
- return missing;
116
+ // Retained for compatibility with the startup postcheck API. Official custom
117
+ // agents are discovered from .codex/agents and do not require config_file
118
+ // references; legacy references are intentionally ignored and preserved.
119
+ export async function missingAgentConfigFiles(_text) {
120
+ return [];
121
121
  }
122
- function tomlBlocks(text) {
123
- const source = String(text || '');
124
- const matches = [...source.matchAll(/(^|\n)\s*\[([^\]]+)\]\s*(?:#.*)?(?:\n|$)/g)];
125
- return matches.map((match, index) => {
126
- const start = Number(match.index || 0) + (match[1] ? 1 : 0);
127
- const next = matches[index + 1];
128
- const end = next ? Number(next.index || 0) + (next[1] ? 1 : 0) : source.length;
129
- return {
130
- header: String(match[2] || '').trim(),
131
- start,
132
- end,
133
- text: source.slice(start, end)
134
- };
135
- });
136
- }
137
- function managedAgentBlocks(text) {
138
- return tomlBlocks(text).filter((block) => Boolean(managedBlockTarget(process.cwd(), block)));
139
- }
140
- function managedBlockTarget(root, block) {
141
- if (!block.header.startsWith('agents.'))
142
- return null;
143
- const role = block.header.slice('agents.'.length);
144
- const byRole = managedAgentRoleConfigForRole(role);
145
- if (byRole)
146
- return byRole;
147
- const configFile = stringValue(block.text, 'config_file');
148
- if (configFile) {
149
- const content = managedAgentRoleConfigForFile(configFile);
150
- if (content)
151
- return { file: path.basename(configFile), content };
122
+ async function writeReport(reportPath, root, report) {
123
+ if (reportPath !== null) {
124
+ await writeJsonAtomic(reportPath || path.join(root, '.sneakoscope', 'reports', 'agent-config-file-repair.json'), report).catch(() => undefined);
152
125
  }
153
- if (/SKS managed|sks_/i.test(block.text)) {
154
- const fallback = managedAgentRoleConfigForRole(role);
155
- if (fallback)
156
- return fallback;
157
- }
158
- void root;
159
- return null;
160
- }
161
- function stringValue(text, key) {
162
- const match = text.match(new RegExp(`^\\s*${escapeRegExp(key)}\\s*=\\s*"([^"]*)"`, 'm'));
163
- return match && typeof match[1] === 'string' ? match[1] : null;
164
- }
165
- function removeKey(text, key, removed) {
166
- return text.split(/\r?\n/).filter((line) => {
167
- const match = new RegExp(`^\\s*${escapeRegExp(key)}\\s*=`).test(line);
168
- if (match)
169
- removed.push(line.trim());
170
- return !match;
171
- }).join('\n');
172
- }
173
- function replaceOrInsertKey(text, key, encodedValue) {
174
- const lines = text.replace(/\s*$/, '').split('\n');
175
- const re = new RegExp(`^\\s*${escapeRegExp(key)}\\s*=`);
176
- const index = lines.findIndex((line) => re.test(line));
177
- if (index >= 0)
178
- lines[index] = `${key} = ${encodedValue}`;
179
- else
180
- lines.push(`${key} = ${encodedValue}`);
181
- return `${lines.join('\n')}\n`;
182
- }
183
- function applyEdits(text, edits) {
184
- return [...edits]
185
- .sort((a, b) => b.start - a.start)
186
- .reduce((current, edit) => `${current.slice(0, edit.start)}${edit.replacement}${current.slice(edit.end)}`, text);
187
- }
188
- function escapeToml(value) {
189
- return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
190
- }
191
- function escapeRegExp(value) {
192
- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
193
- }
194
- function minimalManagedConfigToml() {
195
- return [
196
- 'service_tier = "fast"',
197
- '',
198
- '[features]',
199
- 'hooks = true',
200
- 'multi_agent = true',
201
- 'fast_mode = true',
202
- 'apps = true',
203
- '',
204
- '[mcp_servers.context7]',
205
- 'url = "https://mcp.context7.com/mcp"',
206
- '',
207
- agentConfigBlock('native_agent', 'SKS native agent with bounded write capability.', './agents/native-agent-intake.toml', ['Analysis', 'Mapper']),
208
- '',
209
- agentConfigBlock('team_consensus', 'SKS planning/debate agent with bounded write capability.', './agents/team-consensus.toml', ['Consensus', 'Atlas']),
210
- '',
211
- agentConfigBlock('implementation_worker', 'SKS bounded implementation worker.', './agents/implementation-worker.toml', ['Builder', 'Mason']),
212
- '',
213
- agentConfigBlock('db_safety_reviewer', 'DB safety reviewer with bounded write capability.', './agents/db-safety-reviewer.toml', ['Sentinel', 'Ledger']),
214
- '',
215
- agentConfigBlock('qa_reviewer', 'QA reviewer with bounded write capability.', './agents/qa-reviewer.toml', ['Verifier', 'Reviewer']),
216
- ''
217
- ].join('\n');
218
- }
219
- function agentConfigBlock(table, description, configFile, nicknames = []) {
220
- return [
221
- `[agents.${table}]`,
222
- `description = "${description}"`,
223
- `config_file = "${configFile}"`,
224
- `nickname_candidates = [${nicknames.map((name) => `"${name}"`).join(', ')}]`
225
- ].join('\n');
126
+ return report;
226
127
  }
227
128
  //# sourceMappingURL=agent-config-file-repair.js.map