@davoodmehraban89 / VELYQOR / commits / e336e5d
Fork 0

Intelligence, Advanced Charting & Trading Platform

safety(p0): add non-destructive review gate for Navasan and order policy

davoodmehraban89 committed Oct 13, 2026 at 13:14 UTC e336e5dccbf39cf218d8d136d00f212092df0578
1 file changed +57
scripts/check-p0-safety.mjs new
+57
@@ -0,0 +1,57 @@
1 +// P0 repository guard: static, read-only and deliberately fail-closed.
2 +// Not a legal-license validation, runtime security audit or production deployment gate.
3 +import { readFile, readdir } from 'node:fs/promises';
4 +import { dirname, join, resolve } from 'node:path';
5 +import { fileURLToPath } from 'node:url';
6 +
7 +const ownRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
8 +const MIGRATION_BLOCK_PATTERN = /navasan_ohlc|ohlcSearch|candle_source_provenance|chartnova_navasan_candle_audit/i;
9 +
10 +export async function evaluateP0Safety(root = ownRoot) {
11 + const violations = [];
12 + const migrationDir = join(root, 'db', 'migrations');
13 + let migrations;
14 + try {
15 + migrations = (await readdir(migrationDir)).filter((name) => name.endsWith('.sql'));
16 + } catch {
17 + return { ok: false, violations: ['Cannot enumerate db/migrations; safety review required.'] };
18 + }
19 + for (const filename of migrations) {
20 + const contents = await readFile(join(migrationDir, filename), 'utf8');
21 + if (filename === '0005_navasan_private_daily_ohlc.sql' || MIGRATION_BLOCK_PATTERN.test(contents)) {
22 + violations.push(filename + ': Navasan/OHLC migration HOLD; verify exact units, quote-side, license, provenance and review before changing this guard.');
23 + }
24 + }
25 +
26 + try {
27 + const adapter = await readFile(join(root, 'packages', 'market-domain', 'src', 'adapters', 'navasan.mjs'), 'utf8');
28 + if (!/rawUnit:\s*['"]IRR_PER_USD['"]/.test(adapter) || !/rawUnit:\s*['"]IRR_PER_GRAM['"]/.test(adapter)) {
29 + violations.push('Navasan adapter raw-unit contract changed; manual unit/quote-side review required.');
30 + }
31 + } catch {
32 + violations.push('Navasan adapter missing or unreadable; manual review required.');
33 + }
34 +
35 + try {
36 + const agentRules = await readFile(join(root, 'AGENTS.md'), 'utf8');
37 + if (!/AI\/signals may never directly execute an order\./.test(agentRules)) {
38 + violations.push('AI-to-live-order prohibition in AGENTS.md changed or missing.');
39 + }
40 + } catch {
41 + violations.push('AGENTS.md missing or unreadable; manual review required.');
42 + }
43 +
44 + return { ok: violations.length === 0, violations };
45 +}
46 +
47 +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
48 + const root = process.argv[2] ? resolve(process.argv[2]) : ownRoot;
49 + const outcome = await evaluateP0Safety(root);
50 + if (outcome.ok) {
51 + console.log('P0 static guard: PASS (no blocked migration detected; baseline contracts present).');
52 + } else {
53 + for (const item of outcome.violations) console.error('P0 static guard: BLOCK - ' + item);
54 + process.exitCode = 1;
55 + }
56 + console.log('Reminder: PASS does not establish market-data licensing, valid live feeds or trading safety.');
57 +}