sneakoscope 3.1.14 → 4.0.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.
Files changed (53) hide show
  1. package/README.md +26 -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/bin/sks.js +1 -1
  6. package/dist/cli/command-registry.js +6 -13
  7. package/dist/commands/doctor.js +29 -2
  8. package/dist/commands/proof.js +8 -0
  9. package/dist/core/build/build-once-runner.js +66 -0
  10. package/dist/core/codex/codex-config-readability.js +52 -38
  11. package/dist/core/commands/check-command.js +132 -0
  12. package/dist/core/commands/daemon-command.js +14 -0
  13. package/dist/core/commands/mad-sks-command.js +25 -3
  14. package/dist/core/commands/release-command.js +52 -0
  15. package/dist/core/commands/task-command.js +15 -0
  16. package/dist/core/commands/triwiki-command.js +38 -0
  17. package/dist/core/daemon/sksd-client.js +9 -0
  18. package/dist/core/daemon/sksd-ipc.js +9 -0
  19. package/dist/core/daemon/sksd.js +87 -0
  20. package/dist/core/doctor/doctor-dirty-planner.js +95 -0
  21. package/dist/core/doctor/doctor-transaction.js +13 -0
  22. package/dist/core/feature-fixtures.js +1 -0
  23. package/dist/core/fsx.js +1 -1
  24. package/dist/core/init.js +7 -1
  25. package/dist/core/probes/probe-memoization.js +80 -0
  26. package/dist/core/release/critical-path-ledger.js +12 -0
  27. package/dist/core/release/extreme-parallel-scheduler.js +86 -0
  28. package/dist/core/release/gate-pack-fixture-cache.js +39 -0
  29. package/dist/core/release/gate-pack-manifest.js +118 -0
  30. package/dist/core/release/gate-pack-runner.js +257 -0
  31. package/dist/core/release/release-gate-cache-v2.js +78 -16
  32. package/dist/core/release/release-gate-dag.js +89 -3
  33. package/dist/core/release/resource-class-budget.js +22 -0
  34. package/dist/core/release/sla-scheduler.js +22 -0
  35. package/dist/core/routes.js +5 -0
  36. package/dist/core/triwiki/triwiki-affected-graph.js +112 -0
  37. package/dist/core/triwiki/triwiki-cache-key.js +241 -0
  38. package/dist/core/triwiki/triwiki-gate-impact-map.js +124 -0
  39. package/dist/core/triwiki/triwiki-invalidation.js +81 -0
  40. package/dist/core/triwiki/triwiki-module-card.js +74 -0
  41. package/dist/core/triwiki/triwiki-proof-bank.js +210 -0
  42. package/dist/core/triwiki/triwiki-proof-card.js +73 -0
  43. package/dist/core/triwiki/triwiki-sla-certificate.js +53 -0
  44. package/dist/core/version.js +1 -1
  45. package/dist/core/zellij/zellij-launcher.js +13 -0
  46. package/dist/core/zellij/zellij-worker-pane-manager.js +68 -17
  47. package/dist/scripts/fixtures/fake-codex-config-loader.js +12 -1
  48. package/dist/scripts/release-4000-required-gates.js +36 -0
  49. package/dist/scripts/release-4001-required-gates.js +13 -0
  50. package/dist/scripts/release-gate-dag-runner.js +18 -0
  51. package/dist/scripts/release-speed-summary.js +9 -0
  52. package/dist/scripts/sizecheck.js +4 -2
  53. package/package.json +52 -7
@@ -0,0 +1,15 @@
1
+ import { checkCommand } from './check-command.js';
2
+ export async function taskCommand(args = []) {
3
+ const sub = args[0] && !args[0].startsWith('-') ? args[0] : 'run';
4
+ const rest = sub === args[0] ? args.slice(1) : args;
5
+ if (sub === 'run')
6
+ return checkCommand(['--tier', 'confidence', ...rest]);
7
+ if (sub === 'affected')
8
+ return checkCommand(['--tier', 'affected', ...rest]);
9
+ if (sub === 'instant')
10
+ return checkCommand(['--tier', 'instant', ...rest]);
11
+ console.error('Usage: sks task run|affected|instant [--sla 5m] [--json]');
12
+ process.exitCode = 1;
13
+ return null;
14
+ }
15
+ //# sourceMappingURL=task-command.js.map
@@ -0,0 +1,38 @@
1
+ import { flag } from '../../cli/args.js';
2
+ import { printJson } from '../../cli/output.js';
3
+ import { projectRoot } from '../fsx.js';
4
+ import { computeTriWikiAffectedGraph } from '../triwiki/triwiki-affected-graph.js';
5
+ import { buildTriWikiGateImpactMap } from '../triwiki/triwiki-gate-impact-map.js';
6
+ import { DEFAULT_TRIWIKI_MODULE_CARDS } from '../triwiki/triwiki-module-card.js';
7
+ import { summarizeTriWikiProofBank } from '../triwiki/triwiki-proof-bank.js';
8
+ export async function triwikiCommand(args = []) {
9
+ const root = await projectRoot();
10
+ const sub = args[0] && !args[0].startsWith('-') ? args[0] : 'index';
11
+ const json = flag(args, '--json');
12
+ let result;
13
+ if (sub === 'index') {
14
+ result = {
15
+ schema: 'sks.triwiki-index.v1',
16
+ ok: true,
17
+ modules: DEFAULT_TRIWIKI_MODULE_CARDS,
18
+ impact_map: buildTriWikiGateImpactMap(root),
19
+ proof_bank: summarizeTriWikiProofBank(root)
20
+ };
21
+ }
22
+ else if (sub === 'affected') {
23
+ result = computeTriWikiAffectedGraph({ root, tier: 'affected' });
24
+ }
25
+ else if (sub === 'proof-bank') {
26
+ result = summarizeTriWikiProofBank(root);
27
+ }
28
+ else {
29
+ console.error('Usage: sks triwiki index|affected|proof-bank [--json]');
30
+ process.exitCode = 1;
31
+ return null;
32
+ }
33
+ if (json)
34
+ return printJson(result);
35
+ console.log(JSON.stringify(result, null, 2));
36
+ return result;
37
+ }
38
+ //# sourceMappingURL=triwiki-command.js.map
@@ -0,0 +1,9 @@
1
+ import { sksdStatus, sksdStop, sksdWarm } from './sksd.js';
2
+ export function runSksdClient(root, action) {
3
+ if (action === 'warm')
4
+ return sksdWarm(root);
5
+ if (action === 'stop')
6
+ return sksdStop(root);
7
+ return sksdStatus(root);
8
+ }
9
+ //# sourceMappingURL=sksd-client.js.map
@@ -0,0 +1,9 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export function writeSksdIpcMessage(root, action) {
4
+ const file = path.join(root, '.sneakoscope', 'cache', 'sksd', 'last-message.json');
5
+ fs.mkdirSync(path.dirname(file), { recursive: true });
6
+ fs.writeFileSync(file, `${JSON.stringify({ schema: 'sks.sksd-ipc-message.v1', action, created_at: new Date().toISOString(), pid: process.pid }, null, 2)}\n`);
7
+ return file;
8
+ }
9
+ //# sourceMappingURL=sksd-ipc.js.map
@@ -0,0 +1,87 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export const SKSD_STATE_SCHEMA = 'sks.sksd-state.v1';
4
+ export function sksdStatus(root) {
5
+ const state = readState(root);
6
+ if (!state)
7
+ return emptyState(root);
8
+ if (state.pid && !pidAlive(state.pid)) {
9
+ const stopped = { ...emptyState(root), stale_cleaned: true };
10
+ writeState(root, stopped);
11
+ return stopped;
12
+ }
13
+ return state;
14
+ }
15
+ export function sksdWarm(root) {
16
+ const state = {
17
+ schema: SKSD_STATE_SCHEMA,
18
+ status: 'warm',
19
+ pid: process.pid,
20
+ warmed_at: new Date().toISOString(),
21
+ ipc_path: ipcPath(root),
22
+ proof_bank_ready: true,
23
+ build_proof_ready: fs.existsSync(path.join(root, 'dist', '.sks-build-proof.json')),
24
+ triwiki_index_ready: fs.existsSync(path.join(root, '.sneakoscope', 'wiki', 'context-pack.json')),
25
+ probe_memoization_ready: fs.existsSync(path.join(root, '.sneakoscope', 'cache', 'probes'))
26
+ };
27
+ writeState(root, state);
28
+ fs.writeFileSync(ipcPath(root), `${JSON.stringify({ schema: 'sks.sksd-ipc.v1', pid: process.pid, command: 'warm', at: new Date().toISOString() }, null, 2)}\n`);
29
+ return state;
30
+ }
31
+ export function sksdStop(root) {
32
+ const state = { ...emptyState(root), status: 'stopped' };
33
+ writeState(root, state);
34
+ try {
35
+ fs.rmSync(ipcPath(root), { force: true });
36
+ }
37
+ catch { }
38
+ return state;
39
+ }
40
+ function readState(root) {
41
+ const file = statePath(root);
42
+ try {
43
+ if (!fs.existsSync(file))
44
+ return null;
45
+ const json = JSON.parse(fs.readFileSync(file, 'utf8'));
46
+ return json.schema === SKSD_STATE_SCHEMA ? json : null;
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ }
52
+ function writeState(root, state) {
53
+ const file = statePath(root);
54
+ fs.mkdirSync(path.dirname(file), { recursive: true });
55
+ fs.writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`);
56
+ }
57
+ function statePath(root) {
58
+ return path.join(root, '.sneakoscope', 'cache', 'sksd-state.json');
59
+ }
60
+ function emptyState(root = process.cwd()) {
61
+ return {
62
+ schema: SKSD_STATE_SCHEMA,
63
+ status: 'stopped',
64
+ pid: null,
65
+ warmed_at: null,
66
+ ipc_path: ipcPath(root),
67
+ proof_bank_ready: false,
68
+ build_proof_ready: false,
69
+ triwiki_index_ready: false,
70
+ probe_memoization_ready: false
71
+ };
72
+ }
73
+ function ipcPath(root) {
74
+ const dir = path.join(root, '.sneakoscope', 'cache', 'sksd');
75
+ fs.mkdirSync(dir, { recursive: true });
76
+ return path.join(dir, 'sksd.ipc.json');
77
+ }
78
+ function pidAlive(pid) {
79
+ try {
80
+ process.kill(pid, 0);
81
+ return true;
82
+ }
83
+ catch {
84
+ return false;
85
+ }
86
+ }
87
+ //# sourceMappingURL=sksd.js.map
@@ -0,0 +1,95 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { hashJson } from '../triwiki/triwiki-cache-key.js';
4
+ export const DOCTOR_DIRTY_PLAN_SCHEMA = 'sks.doctor-dirty-plan.v1';
5
+ export function planDoctorDirtyRepair(root, phaseIds) {
6
+ const phases = phaseIds.map((id) => {
7
+ const marker = markerPath(root, id);
8
+ const inputHash = phaseInputHash(root, id);
9
+ const postcheckRequired = phaseRequiresPostcheck(id);
10
+ const markerState = readMarker(marker);
11
+ if (!markerState)
12
+ return { id, status: 'dirty', reason: 'no_clean_marker', input_hash: inputHash, last_clean_proof_id: null, postcheck_required: postcheckRequired };
13
+ if (markerState.input_hash !== inputHash) {
14
+ return { id, status: 'dirty', reason: 'input_hash_changed', input_hash: inputHash, last_clean_proof_id: markerState.proof_id, postcheck_required: postcheckRequired };
15
+ }
16
+ if (postcheckRequired && !markerState.postcheck_passed) {
17
+ return { id, status: 'dirty', reason: 'postcheck_required', input_hash: inputHash, last_clean_proof_id: markerState.proof_id, postcheck_required: true };
18
+ }
19
+ return { id, status: 'clean', reason: 'matching_clean_proof', input_hash: inputHash, last_clean_proof_id: markerState.proof_id, postcheck_required: postcheckRequired };
20
+ });
21
+ const plan = {
22
+ schema: DOCTOR_DIRTY_PLAN_SCHEMA,
23
+ root,
24
+ phases,
25
+ dirty_count: phases.filter((phase) => phase.status === 'dirty').length,
26
+ clean_count: phases.filter((phase) => phase.status === 'clean').length
27
+ };
28
+ writeDirtyPlan(root, plan);
29
+ return plan;
30
+ }
31
+ export function markDoctorPhaseClean(root, id) {
32
+ const file = markerPath(root, id);
33
+ fs.mkdirSync(path.dirname(file), { recursive: true });
34
+ fs.writeFileSync(file, `${JSON.stringify({ schema: 'sks.doctor-dirty-clean-proof.v1', proof_id: `doctor-${id}-${Date.now()}`, cleaned_at: new Date().toISOString(), input_hash: phaseInputHash(root, id), postcheck_passed: true }, null, 2)}\n`);
35
+ }
36
+ export function isDoctorPhaseClean(plan, id) {
37
+ return plan?.phases.find((phase) => phase.id === id)?.status === 'clean';
38
+ }
39
+ function markerPath(root, id) {
40
+ return path.join(root, '.sneakoscope', 'cache', 'doctor-dirty', `${id.replace(/[^a-zA-Z0-9._-]+/g, '_')}.clean`);
41
+ }
42
+ function readMarker(file) {
43
+ try {
44
+ if (!fs.existsSync(file))
45
+ return null;
46
+ const raw = fs.readFileSync(file, 'utf8');
47
+ if (!raw.trim().startsWith('{'))
48
+ return { proof_id: null, input_hash: null, postcheck_passed: false };
49
+ const json = JSON.parse(raw);
50
+ return { proof_id: json.proof_id || null, input_hash: json.input_hash || null, postcheck_passed: json.postcheck_passed === true };
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
56
+ function phaseInputHash(root, id) {
57
+ const files = phaseInputFiles(id).map((rel) => {
58
+ const file = path.join(root, rel);
59
+ if (!fs.existsSync(file))
60
+ return { rel, hash: 'missing' };
61
+ const stat = fs.statSync(file);
62
+ return { rel, hash: stat.isDirectory() ? `dir:${stat.mtimeMs}` : hashJson({ size: stat.size, mtimeMs: stat.mtimeMs, text: stat.size < 512_000 ? fs.readFileSync(file, 'utf8') : '' }) };
63
+ });
64
+ return hashJson({ id, files, env: phaseEnvPresence(id) });
65
+ }
66
+ function phaseInputFiles(id) {
67
+ if (id.includes('zellij'))
68
+ return ['src/core/zellij', 'src/core/doctor/doctor-zellij-repair.ts'];
69
+ if (id.includes('context7'))
70
+ return ['src/core/doctor/context7-mcp-repair.ts', '.codex/config.toml'];
71
+ if (id.includes('startup'))
72
+ return ['src/core/doctor/codex-startup-config-repair.ts', '.codex/config.toml'];
73
+ if (id.includes('supabase'))
74
+ return ['src/core/doctor/supabase-mcp-repair.ts', '.codex/config.toml'];
75
+ if (id.includes('skill'))
76
+ return ['.agents/skills', 'src/scripts/skill-registry-ledger-check.ts'];
77
+ if (id.includes('native'))
78
+ return ['src/core/codex-native', 'src/scripts/native-capability-postcheck-check.ts'];
79
+ if (id.includes('secret'))
80
+ return ['safety-mutation-allowlist.json', 'src/scripts/secret-preservation-check.ts'];
81
+ return ['package.json', 'src/core/doctor'];
82
+ }
83
+ function phaseEnvPresence(id) {
84
+ const keys = id.includes('supabase') ? ['SUPABASE_ACCESS_TOKEN'] : id.includes('context7') ? ['CONTEXT7_API_KEY'] : [];
85
+ return Object.fromEntries(keys.map((key) => [key, process.env[key] !== undefined]));
86
+ }
87
+ function phaseRequiresPostcheck(id) {
88
+ return /zellij|context7|startup|supabase|native|secret/i.test(id);
89
+ }
90
+ function writeDirtyPlan(root, plan) {
91
+ const file = path.join(root, '.sneakoscope', 'reports', 'doctor-dirty-plan.json');
92
+ fs.mkdirSync(path.dirname(file), { recursive: true });
93
+ fs.writeFileSync(file, `${JSON.stringify(plan, null, 2)}\n`);
94
+ }
95
+ //# sourceMappingURL=doctor-dirty-planner.js.map
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { nowIso, writeJsonAtomic } from '../fsx.js';
3
+ import { isDoctorPhaseClean, markDoctorPhaseClean } from './doctor-dirty-planner.js';
3
4
  export async function runDoctorFixTransaction(input) {
4
5
  const startedAt = nowIso();
5
6
  const phases = [];
@@ -18,6 +19,16 @@ export async function runDoctorFixTransaction(input) {
18
19
  artifact_path: null,
19
20
  started_at: phaseStarted
20
21
  };
22
+ if (isDoctorPhaseClean(input.dirtyPlan, definition.id)) {
23
+ phases.push({
24
+ ...phase,
25
+ ok: true,
26
+ warnings: ['dirty_plan_skipped_clean_phase'],
27
+ completed_at: nowIso(),
28
+ duration_ms: Math.max(0, Date.now() - startedMs)
29
+ });
30
+ continue;
31
+ }
21
32
  try {
22
33
  const result = await definition.run();
23
34
  phase = normalizePhase(definition, result, phase, startedMs);
@@ -48,6 +59,8 @@ export async function runDoctorFixTransaction(input) {
48
59
  }
49
60
  phase.completed_at = phase.completed_at || nowIso();
50
61
  phase.duration_ms = phase.duration_ms ?? Math.max(0, Date.now() - startedMs);
62
+ if (phase.ok)
63
+ markDoctorPhaseClean(input.root, definition.id);
51
64
  phases.push(phase);
52
65
  }
53
66
  const writeInput = {
@@ -21,6 +21,7 @@ const FIXTURES = Object.freeze({
21
21
  'cli-hooks': fixture('mock', 'sks hooks trust-report --json', [], 'pass'),
22
22
  'cli-features': fixture('execute', 'sks features check --json', [], 'pass'),
23
23
  'cli-commands': fixture('execute', 'sks commands --json', [], 'pass'),
24
+ 'cli-check': fixture('execute', 'sks check --tier confidence --sla 5m --plan --json', [], 'pass'),
24
25
  'cli-run': fixture('execute_and_validate_artifacts', 'sks run "fixture" --mock --json', ['run-classification.json', 'completion-proof.json', 'evidence-index.json', 'route-completion-contract.json', 'trust-report.json'], 'pass'),
25
26
  'cli-status': fixture('execute', 'sks status --json', [], 'pass'),
26
27
  'cli-usage': fixture('execute', 'sks usage overview', [], 'pass'),
package/dist/core/fsx.js CHANGED
@@ -5,7 +5,7 @@ import os from 'node:os';
5
5
  import crypto from 'node:crypto';
6
6
  import { spawn } from 'node:child_process';
7
7
  import { fileURLToPath } from 'node:url';
8
- export const PACKAGE_VERSION = '3.1.14';
8
+ export const PACKAGE_VERSION = '4.0.1';
9
9
  export const DEFAULT_PROCESS_TAIL_BYTES = 256 * 1024;
10
10
  export const DEFAULT_PROCESS_TIMEOUT_MS = 30 * 60 * 1000;
11
11
  export function nowIso() {
package/dist/core/init.js CHANGED
@@ -806,7 +806,13 @@ export async function initProject(root, opts = {}) {
806
806
  // Context7 credentials may live directly in this table as args/env/headers/url
807
807
  // depending on the user's MCP client setup. Seed the default only when absent;
808
808
  // never replace an existing Context7 block during setup/update.
809
- { table: 'mcp_servers.context7', text: context7ConfigToml().trim(), preserveExisting: true },
809
+ // Seed the REMOTE (streamable HTTP `url`) transport, not local stdio: Codex
810
+ // merges the global ~/.codex/config.toml and the project config per-key, so a
811
+ // local-stdio `command` here merging with a remote `url` in the global config
812
+ // yields a stdio server that also carries a `url` — which Codex 0.140 rejects
813
+ // with `url is not supported for stdio`. Remote is also the transport the doctor
814
+ // migrates everyone to (local stdio can block interactive Codex launch).
815
+ { table: 'mcp_servers.context7', text: context7ConfigToml('remote').trim(), preserveExisting: true },
810
816
  { table: 'agents.native_agent', text: agentConfigBlock('native_agent', 'Read-only SKS analysis agent.', './agents/native-agent-intake.toml', ['Analysis', 'Mapper']) },
811
817
  { table: 'agents.team_consensus', text: agentConfigBlock('team_consensus', 'SKS planning/debate agent.', './agents/team-consensus.toml', ['Consensus', 'Atlas']) },
812
818
  { table: 'agents.implementation_worker', text: agentConfigBlock('implementation_worker', 'SKS bounded implementation worker.', './agents/implementation-worker.toml', ['Builder', 'Mason']) },
@@ -0,0 +1,80 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { hashJson } from '../triwiki/triwiki-cache-key.js';
4
+ export const PROBE_MEMOIZATION_SCHEMA = 'sks.probe-memoization.v1';
5
+ export function memoizeProbe(input) {
6
+ const key = hashJson({
7
+ probe_id: input.probeId,
8
+ version: input.version,
9
+ env: envPresence(input.envAllowlist || []),
10
+ file_hash: input.fileHash || null
11
+ });
12
+ const file = probeCachePath(input.root, key);
13
+ const existing = readProbeRecord(file);
14
+ if (existing && new Date(existing.expires_at).getTime() > Date.now())
15
+ return { value: existing.value, reused: true, key };
16
+ const value = input.run();
17
+ const record = {
18
+ schema: PROBE_MEMOIZATION_SCHEMA,
19
+ key,
20
+ probe_id: input.probeId,
21
+ created_at: new Date().toISOString(),
22
+ expires_at: new Date(Date.now() + input.ttlMs).toISOString(),
23
+ value,
24
+ tool_version: input.version,
25
+ ...(input.fileHash ? { file_hash: input.fileHash } : {}),
26
+ env_allowlist_hash: hashJson(envPresence(input.envAllowlist || []))
27
+ };
28
+ fs.mkdirSync(path.dirname(file), { recursive: true });
29
+ fs.writeFileSync(file, `${JSON.stringify(record, null, 2)}\n`);
30
+ return { value, reused: false, key };
31
+ }
32
+ export async function memoizeProbeAsync(input) {
33
+ const key = hashJson({ probe_id: input.probeId, version: input.version, env: envPresence(input.envAllowlist || []), file_hash: input.fileHash || null });
34
+ const file = probeCachePath(input.root, key);
35
+ const existing = readProbeRecord(file);
36
+ if (existing && new Date(existing.expires_at).getTime() > Date.now()) {
37
+ writeProbeReport(input.root, { repeated_probe_count: 1, reused_probe_count: 1, saved_ms_estimate: Math.max(1, input.ttlMs / 1000) });
38
+ return { value: existing.value, reused: true, key };
39
+ }
40
+ const started = Date.now();
41
+ const value = await input.run();
42
+ const record = {
43
+ schema: PROBE_MEMOIZATION_SCHEMA,
44
+ key,
45
+ probe_id: input.probeId,
46
+ created_at: new Date().toISOString(),
47
+ expires_at: new Date(Date.now() + input.ttlMs).toISOString(),
48
+ value,
49
+ tool_version: input.version,
50
+ ...(input.fileHash ? { file_hash: input.fileHash } : {}),
51
+ env_allowlist_hash: hashJson(envPresence(input.envAllowlist || []))
52
+ };
53
+ fs.mkdirSync(path.dirname(file), { recursive: true });
54
+ fs.writeFileSync(file, `${JSON.stringify(record, null, 2)}\n`);
55
+ writeProbeReport(input.root, { repeated_probe_count: 1, reused_probe_count: 0, saved_ms_estimate: Math.max(0, Date.now() - started) });
56
+ return { value, reused: false, key };
57
+ }
58
+ function readProbeRecord(file) {
59
+ try {
60
+ if (!fs.existsSync(file))
61
+ return null;
62
+ const json = JSON.parse(fs.readFileSync(file, 'utf8'));
63
+ return json.schema === PROBE_MEMOIZATION_SCHEMA ? json : null;
64
+ }
65
+ catch {
66
+ return null;
67
+ }
68
+ }
69
+ function probeCachePath(root, key) {
70
+ return path.join(root, '.sneakoscope', 'cache', 'probes', `${key}.json`);
71
+ }
72
+ function envPresence(keys) {
73
+ return [...new Set(keys)].sort().map((name) => ({ name, present: process.env[name] !== undefined }));
74
+ }
75
+ function writeProbeReport(root, report) {
76
+ const file = path.join(root, '.sneakoscope', 'reports', 'probe-memoization.json');
77
+ fs.mkdirSync(path.dirname(file), { recursive: true });
78
+ fs.writeFileSync(file, `${JSON.stringify({ schema: 'sks.probe-memoization-report.v1', ...report }, null, 2)}\n`);
79
+ }
80
+ //# sourceMappingURL=probe-memoization.js.map
@@ -0,0 +1,12 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export function buildCriticalPathLedger(input) {
4
+ return { schema: 'sks.critical-path-ledger.v1', ...input };
5
+ }
6
+ export function writeCriticalPathLedger(root, ledger) {
7
+ const file = path.join(root, '.sneakoscope', 'reports', 'critical-path-ledger.json');
8
+ fs.mkdirSync(path.dirname(file), { recursive: true });
9
+ fs.writeFileSync(file, `${JSON.stringify(ledger, null, 2)}\n`);
10
+ return file;
11
+ }
12
+ //# sourceMappingURL=critical-path-ledger.js.map
@@ -0,0 +1,86 @@
1
+ import { buildGatePackManifest } from './gate-pack-manifest.js';
2
+ import { executeGatePack } from './gate-pack-runner.js';
3
+ import { buildCriticalPathLedger, writeCriticalPathLedger } from './critical-path-ledger.js';
4
+ import { computeResourceClassBudget } from './resource-class-budget.js';
5
+ export const EXTREME_PARALLEL_SCHEDULER_SCHEMA = 'sks.extreme-parallel-scheduler.v1';
6
+ export function planExtremeParallelSchedule(root, graph, budget = computeResourceClassBudget()) {
7
+ const manifest = buildGatePackManifest(root);
8
+ const selectedIds = new Set(graph?.gate_packs && graph.gate_packs.length ? graph.gate_packs : manifest.packs.map((pack) => pack.id));
9
+ const packs = manifest.packs.filter((pack) => selectedIds.has(pack.id)).sort((a, b) => b.estimated_ms - a.estimated_ms);
10
+ const laneCount = Math.max(1, Math.min(packs.length || 1, Math.max(4, budget.cpu_light)));
11
+ const lanes = Array.from({ length: laneCount }, () => ({ packs: [], estimated_ms: 0 }));
12
+ for (const pack of packs) {
13
+ const target = lanes.reduce((best, lane) => lane.estimated_ms < best.estimated_ms ? lane : best, lanes[0]);
14
+ target.packs.push(pack.id);
15
+ target.estimated_ms += pack.estimated_ms;
16
+ }
17
+ const batches = lanes
18
+ .filter((lane) => lane.packs.length > 0)
19
+ .map((lane, index) => ({ batch: index + 1, packs: lane.packs, estimated_ms: lane.estimated_ms }));
20
+ const sequential = packs.reduce((sum, pack) => sum + pack.estimated_ms, 0);
21
+ const critical = batches.reduce((max, batch) => Math.max(max, batch.estimated_ms), 0);
22
+ const ratio = sequential <= 0 ? 1 : critical / sequential;
23
+ const blockers = ratio <= 0.3 || packs.length <= 1 ? [] : ['critical_path_reduction_below_70_percent'];
24
+ return {
25
+ schema: EXTREME_PARALLEL_SCHEDULER_SCHEMA,
26
+ ok: blockers.length === 0,
27
+ batches,
28
+ sequential_ms: sequential,
29
+ critical_path_ms: critical,
30
+ reduction_ratio: Number(ratio.toFixed(4)),
31
+ budget,
32
+ blockers
33
+ };
34
+ }
35
+ export async function executeExtremeSchedule(input) {
36
+ const planned = planExtremeParallelSchedule(input.root, input.graph, input.budget);
37
+ const started = Date.now();
38
+ const runId = `xs-${new Date().toISOString().replace(/[:.]/g, '-')}-${process.pid}`;
39
+ const reports = [];
40
+ let reused = 0;
41
+ let executedGates = 0;
42
+ let failedPacks = 0;
43
+ for (const batch of planned.batches) {
44
+ const results = await Promise.all(batch.packs.map((packId) => executeGatePack({
45
+ root: input.root,
46
+ packId,
47
+ mode: 'execute',
48
+ maxParallel: Math.max(1, Math.min(4, input.budget.cpu_light))
49
+ })));
50
+ for (const report of results) {
51
+ reports.push(report);
52
+ reused += report.reused_proof_count || report.reused || 0;
53
+ executedGates += report.executed_gate_count || report.executed || 0;
54
+ if (!report.ok)
55
+ failedPacks += 1;
56
+ }
57
+ }
58
+ const wallMs = Math.max(0, Date.now() - started);
59
+ const criticalPathMs = reports.reduce((max, report) => Math.max(max, report.critical_path_ms || 0), planned.critical_path_ms);
60
+ const sequentialMs = reports.reduce((sum, report) => sum + (report.critical_path_ms || 0), planned.sequential_ms);
61
+ writeCriticalPathLedger(input.root, buildCriticalPathLedger({
62
+ run_id: runId,
63
+ sequential_ms: sequentialMs,
64
+ critical_path_ms: criticalPathMs,
65
+ wall_ms: wallMs,
66
+ parallelism_gain: wallMs > 0 ? Number((sequentialMs / wallMs).toFixed(2)) : 1,
67
+ resource_wait_ms: {},
68
+ top_blockers: reports.filter((report) => !report.ok).map((report) => ({ id: report.pack_id, wait_ms: 0, run_ms: report.critical_path_ms || 0 }))
69
+ }));
70
+ return {
71
+ ...planned,
72
+ ok: planned.ok && failedPacks === 0 && wallMs <= input.slaMs,
73
+ run_id: runId,
74
+ mode: 'execute',
75
+ executed_packs: reports.map((report) => report.pack_id),
76
+ reused_proof_count: reused,
77
+ executed_gate_count: executedGates,
78
+ failed_pack_count: failedPacks,
79
+ wall_ms: wallMs,
80
+ critical_path_ms: criticalPathMs,
81
+ sequential_ms: sequentialMs,
82
+ pack_reports: reports,
83
+ blockers: [...planned.blockers, ...(wallMs > input.slaMs ? ['sla_actual_exceeds_budget'] : []), ...(failedPacks ? ['pack_execution_failed'] : [])]
84
+ };
85
+ }
86
+ //# sourceMappingURL=extreme-parallel-scheduler.js.map
@@ -0,0 +1,39 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export const GATE_PACK_FIXTURE_SCHEMA = 'sks.gate-pack-fixture.v1';
4
+ export async function prepareGatePackFixture(input) {
5
+ const base = path.join(input.root, '.sneakoscope', 'fixture-cache', 'gate-packs', safe(input.packId), safe(input.fixtureVersion));
6
+ const reusedBase = fs.existsSync(path.join(base, 'fixture.json'));
7
+ fs.mkdirSync(base, { recursive: true });
8
+ if (!reusedBase) {
9
+ fs.writeFileSync(path.join(base, 'fixture.json'), `${JSON.stringify({ schema: GATE_PACK_FIXTURE_SCHEMA, pack_id: input.packId, fixture_version: input.fixtureVersion, created_at: new Date().toISOString() }, null, 2)}\n`);
10
+ }
11
+ const runPath = path.join(input.root, '.sneakoscope', 'fixture-cache', 'runs', `${safe(input.packId)}-${process.pid}-${Date.now()}`);
12
+ fs.mkdirSync(path.dirname(runPath), { recursive: true });
13
+ copyDir(base, runPath);
14
+ return {
15
+ schema: GATE_PACK_FIXTURE_SCHEMA,
16
+ root: input.root,
17
+ pack_id: input.packId,
18
+ fixture_version: input.fixtureVersion,
19
+ base_path: base,
20
+ run_path: runPath,
21
+ reused_base: reusedBase,
22
+ setup_count: reusedBase ? 0 : 1
23
+ };
24
+ }
25
+ function copyDir(from, to) {
26
+ fs.mkdirSync(to, { recursive: true });
27
+ for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
28
+ const src = path.join(from, entry.name);
29
+ const dst = path.join(to, entry.name);
30
+ if (entry.isDirectory())
31
+ copyDir(src, dst);
32
+ else if (entry.isFile())
33
+ fs.copyFileSync(src, dst);
34
+ }
35
+ }
36
+ function safe(value) {
37
+ return value.replace(/[^a-zA-Z0-9._-]+/g, '_');
38
+ }
39
+ //# sourceMappingURL=gate-pack-fixture-cache.js.map