The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore: files changed scripts/ci/check-process-statics.mjs,scripts/ci/process-statics.json
Steven Enamakelbbda6a1272c7
diff --git a/scripts/ci/check-process-statics.mjs b/scripts/ci/check-process-statics.mjsindex f49befa98e..2a1c00c2a6 100644--- a/scripts/ci/check-process-statics.mjs+++ b/scripts/ci/check-process-statics.mjs@@ -1,2 +1,111 @@-export function declarations() { return []; }-export function reviewChanges() { return []; }+#!/usr/bin/env node+import { execFileSync } from 'node:child_process';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { pathToFileURL } from 'node:url';+import { stripRustComments } from './check-crate-chain.mjs';++const CORE = 'crates/openhuman-core/src/';+const MANIFEST = 'scripts/ci/process-statics.json';+const production = (file) => file.startsWith(CORE) && file.endsWith('.rs') && !file.endsWith('_tests.rs');+const signature = (entry) => JSON.stringify([entry.file, entry.name, entry.type]);++/** Source declarations only: includes aliases and lazy_static!, not macro expansion. */+export function declarations(text, file) {+ const code = stripRustComments(text);+ const found = [];+ const pattern = /\bstatic\s+(?:(mut|ref)\s+)?([A-Za-z_][A-Za-z_0-9]*)\s*:/g;+ for (const match of code.matchAll(pattern)) {+ let end = match.index + match[0].length;+ const start = end;+ const stack = [];+ for (; end < code.length; end++) {+ const char = code[end];+ if (!stack.length && (char === '=' || char === ';')) break;+ if ('<([{'.includes(char)) stack.push(char);+ else if ('>)]}'.includes(char) && stack.length) {+ // An arrow inside a function type is not a generic closing bracket.+ if (char === '>' && code[end - 1] === '-') continue;+ const expected = { '>': '<', ')': '(', ']': '[', '}': '{' }[char];+ if (stack.at(-1) === expected) stack.pop();+ }+ }+ if (end === code.length) throw new Error(`${file}: cannot parse static ${match[2]}`);+ const type = code.slice(start, end).replace(/\s+/g, '');+ if (!type) throw new Error(`${file}: static ${match[2]} has no type`);+ found.push({file, name: match[2], type: (match[1] ? match[1]+' ' : '')+type,+ line: code.slice(0, match.index).split('\n').length});+ }+ return found;+}++function counts(entries) {+ const result = new Map();+ for (const entry of entries) {+ const key = signature(entry);+ result.set(key, (result.get(key) ?? 0)+1);+ }+ return result;+}++/** Require exact, non-stale ownership records for added or changed declaration types. */+export function reviewChanges(before, after, approvals) {+ if (!Array.isArray(approvals)) throw new Error('process-statics.json must contain an array');+ const oldCounts = counts(before);+ const newCounts = counts(after);+ const reviewed = new Map();+ const errors = [];+ for (const entry of approvals) {+ if (!entry || typeof entry !== 'object') { errors.push('Invalid ownership record'); continue; }+ const key = signature(entry);+ if (reviewed.has(key)) errors.push(`Duplicate ownership record: ${key}`);+ reviewed.set(key, entry);+ if (!production(entry.file ?? '') || typeof entry.name !== 'string' || !entry.name ||+ typeof entry.type !== 'string' || !entry.type ||+ !Number.isInteger(entry.count) || entry.count < 1 ||+ !['A','B','C','D'].includes(entry.category) ||+ !['reason','verification'].every((field) => typeof entry[field] === 'string' && entry[field].trim())) {+ errors.push(`Incomplete ownership record: ${key}`);+ }+ if (newCounts.get(key) !== entry.count) errors.push(`Stale ownership record: ${key}`);+ }+ for (const [key, count] of newCounts) {+ if (count > (oldCounts.get(key) ?? 0) && reviewed.get(key)?.count !== count) {+ errors.push(`New static requires an ownership record: ${key} (count ${count})`);+ }+ }+ return errors;+}++/** Compare tracked working sources with the merge base; missing history is a failure. */+export function checkRepository(root, baseRef) {+ const git = (args) => execFileSync('git', args, {cwd:root, encoding:'utf8', stdio:['ignore','pipe','pipe']}).trim();+ if (!baseRef) {+ if (process.env.GITHUB_BASE_REF) baseRef = `origin/${process.env.GITHUB_BASE_REF}`;+ else {+ try { git(['rev-parse','--verify','upstream/main^{commit}']); baseRef = 'upstream/main'; }+ catch { baseRef = 'origin/main'; }+ }+ }+ let base;+ try { base = git(['merge-base',baseRef,'HEAD']); }+ catch { throw new Error(`Cannot resolve merge base ${baseRef}; fetch the base with full history before running this gate.`); }+ const previousFiles = git(['ls-tree','-r','--name-only',base,'--',CORE]).split('\n').filter(production);+ const currentFiles = git(['ls-files','--',CORE]).split('\n').filter(production);+ if (!currentFiles.length) throw new Error('No tracked core production sources; refusing an empty scan.');+ const before = previousFiles.flatMap((file) => declarations(git(['show',`${base}:${file}`]),file));+ const after = currentFiles.flatMap((file) => declarations(readFileSync(resolve(root,file),'utf8'),file));+ const approvals = JSON.parse(readFileSync(resolve(root,MANIFEST),'utf8'));+ return {base, files:currentFiles.length, errors:reviewChanges(before,after,approvals)};+}++if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {+ try {+ const report = checkRepository(process.cwd(),process.argv[2]);+ if (report.errors.length) throw new Error(report.errors.join('\n'));+ console.log(`Process statics: ${report.files} core files checked against ${report.base}; ownership records valid.`);+ } catch (error) {+ console.error(`Process statics FAILED: ${error.message}`);+ process.exitCode = 1;+ }+}diff --git a/scripts/ci/process-statics.json b/scripts/ci/process-statics.jsonnew file mode 100644index 0000000000..fe51488c70--- /dev/null+++ b/scripts/ci/process-statics.json@@ -0,0 +1 @@+[]