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
feat(ci): add check for core hosted free
Steven Enamakel1d6eaa126f73
diff --git a/scripts/__tests__/check-core-hosted-free.test.mjs b/scripts/__tests__/check-core-hosted-free.test.mjsnew file mode 100644index 0000000000..5c4001ac84--- /dev/null+++ b/scripts/__tests__/check-core-hosted-free.test.mjs@@ -0,0 +1,103 @@+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { dirname, join, resolve } from 'node:path';+import { test } from 'node:test';+import { fileURLToPath } from 'node:url';++import {+ CORE_SRC,+ checkRepository,+ formatReport,+ scanSource,+ stripRustComments,+} from '../ci/check-core-hosted-free.mjs';++const CHECKER = resolve(dirname(fileURLToPath(import.meta.url)), '../ci/check-core-hosted-free.mjs');++function fixture(files) {+ const root = mkdtempSync(join(tmpdir(), 'core-hosted-free-'));+ for (const [path, body] of Object.entries(files)) {+ const full = join(root, CORE_SRC, path);+ mkdirSync(dirname(full), { recursive: true });+ writeFileSync(full, body);+ }+ return root;+}++test('comments are ignored but string literals are scanned', () => {+ const src = [+ '// crate::backend in a line comment',+ '/// "https://api.tinyhumans.ai" in a doc comment',+ '/* /teams/me /* nested */ still a comment */',+ 'let ok = 1;',+ 'let url = "https://api.tinyhumans.ai/x";',+ 'let raw = r#"/voice-agent/start"#;',+ "let quote = '\"'; let route = \"/openai/v1/chat\";",+ ].join('\n');+ const hits = scanSource('x.rs', src);+ assert.deepEqual(+ hits.map(h => [h.line, h.name]),+ [+ [5, 'tinyhumans.ai'],+ [6, '/voice-agent'],+ [7, '/openai/v1'],+ ]+ );+});++test('every forbidden pattern is detected in code', () => {+ const code = [+ 'use crate::backend::BackendClient;',+ 'const A: &str = "agent-integrations/x";',+ 'const B: &str = "/telemetry/langfuse/ingestion";',+ 'const C: &str = "/memory/free-period";',+ 'const D: &str = "/teams/me/usage";',+ ].join('\n');+ assert.equal(scanSource('x.rs', code).length, 5);+});++test('stripping keeps line numbers', () => {+ const src = 'a\n/* one\ntwo */\nb\n';+ assert.equal(stripRustComments(src).split('\n').length, src.split('\n').length);+});++test('_tests.rs files are skipped and a clean tree passes', () => {+ const root = fixture({+ 'lib.rs': 'pub fn f() {}\n',+ 'thing/mod.rs': '// crate::backend was removed\n',+ 'thing/mod_tests.rs': 'const X: &str = "https://api.tinyhumans.ai";\n',+ });+ try {+ assert.deepEqual(checkRepository(root), []);+ const run = spawnSync('node', [CHECKER, root], { encoding: 'utf8' });+ assert.equal(run.status, 0, run.stdout + run.stderr);+ assert.match(run.stdout, /ok/);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});++test('a hosted reference fails the checker with file and line', () => {+ const root = fixture({ 'a/mod.rs': 'fn x() {}\nconst U: &str = "https://api.tinyhumans.ai";\n' });+ try {+ const hits = checkRepository(root);+ assert.equal(hits.length, 1);+ assert.match(formatReport(hits), /a\/mod\.rs:2: tinyhumans\.ai/);+ const run = spawnSync('node', [CHECKER, root], { encoding: 'utf8' });+ assert.equal(run.status, 1);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});++test('a missing core tree exits 2 instead of passing vacuously', () => {+ const root = mkdtempSync(join(tmpdir(), 'core-hosted-free-empty-'));+ try {+ const run = spawnSync('node', [CHECKER, root], { encoding: 'utf8' });+ assert.equal(run.status, 2);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});diff --git a/scripts/ci/check-core-hosted-free.mjs b/scripts/ci/check-core-hosted-free.mjsnew file mode 100644index 0000000000..62b37b00fa--- /dev/null+++ b/scripts/ci/check-core-hosted-free.mjs@@ -0,0 +1,153 @@+#!/usr/bin/env node+// Keeps the core free of anything TinyHumans-hosted.+//+// `crates/openhuman-core` has no backend module, no hosted port and no hosted+// route: the TinyHumans layer (`crates/openhuman-tinyhumans`) owns the+// transport, the authenticated client, the routes and the hosted providers,+// and plugs into the core only through generic registries. This check scans+// the core's Rust source (comments and `_tests.rs` files excluded) and fails+// on+// - `crate::backend` (the deleted module),+// - `tinyhumans.ai` (a hosted hostname), and+// - hosted route literals: `agent-integrations`, `/voice-agent`,+// `/openai/v1`, `/telemetry/langfuse`, `/memory/free-period`, `/teams/me`.+//+// Usage: check-core-hosted-free.mjs [repo-root]+// Exit 0 when clean, 1 on a violation, 2 when the source tree is unreadable.++import { existsSync, readdirSync, readFileSync } from 'node:fs';+import { dirname, join, relative, resolve } from 'node:path';+import { fileURLToPath, pathToFileURL } from 'node:url';++export const CORE_SRC = 'crates/openhuman-core/src';++export const FORBIDDEN = [+ { name: 'crate::backend', regex: /\bcrate::backend\b/ },+ { name: 'tinyhumans.ai', regex: /tinyhumans\.ai/ },+ { name: 'agent-integrations', regex: /agent-integrations/ },+ { name: '/voice-agent', regex: /\/voice-agent/ },+ { name: '/openai/v1', regex: /\/openai\/v1/ },+ { name: '/telemetry/langfuse', regex: /\/telemetry\/langfuse/ },+ { name: '/memory/free-period', regex: /\/memory\/free-period/ },+ { name: '/teams/me', regex: /\/teams\/me/ },+];++/**+ * Blank out Rust comments (`//`, nested block comments, doc comments) while+ * keeping string and char literals and every newline, so reported line numbers+ * stay true. Hosted literals live in strings, which must still be scanned.+ */+export function stripRustComments(src) {+ let out = '';+ let i = 0;+ const n = src.length;+ while (i < n) {+ const c = src[i];+ const next = src[i + 1];+ if (c === '/' && next === '/') {+ while (i < n && src[i] !== '\n') i++;+ continue;+ }+ if (c === '/' && next === '*') {+ let depth = 1;+ i += 2;+ while (i < n && depth > 0) {+ if (src[i] === '/' && src[i + 1] === '*') {+ depth++;+ i += 2;+ } else if (src[i] === '*' && src[i + 1] === '/') {+ depth--;+ i += 2;+ } else {+ if (src[i] === '\n') out += '\n';+ i++;+ }+ }+ continue;+ }+ // Raw string: r"..." / r#"..."# / br#"..."#.+ const raw = /^b?r(#*)"/.exec(src.slice(i, i + 40));+ if (raw && (i === 0 || !/[A-Za-z0-9_]/.test(src[i - 1]))) {+ const close = '"' + raw[1];+ const end = src.indexOf(close, i + raw[0].length);+ const stop = end === -1 ? n : end + close.length;+ out += src.slice(i, stop);+ i = stop;+ continue;+ }+ if (c === '"') {+ let j = i + 1;+ while (j < n && src[j] !== '"') j += src[j] === '\\' ? 2 : 1;+ out += src.slice(i, j + 1);+ i = j + 1;+ continue;+ }+ if (c === "'") {+ // A char literal ('"', '\'', 'x') versus a lifetime ('a).+ const lit = /^'(?:\\.[^']*|[^\\'])'/.exec(src.slice(i, i + 12));+ if (lit) {+ out += lit[0];+ i += lit[0].length;+ continue;+ }+ }+ out += c;+ i++;+ }+ return out;+}++/** Violations `[{ file, line, name, text }]` in one file's source. */+export function scanSource(file, src) {+ const hits = [];+ const lines = stripRustComments(src).split('\n');+ lines.forEach((text, idx) => {+ for (const { name, regex } of FORBIDDEN) {+ if (regex.test(text)) hits.push({ file, line: idx + 1, name, text: text.trim() });+ }+ });+ return hits;+}++function* rustFiles(dir) {+ for (const entry of readdirSync(dir, { withFileTypes: true })) {+ const path = join(dir, entry.name);+ if (entry.isDirectory()) yield* rustFiles(path);+ else if (entry.name.endsWith('.rs') && !entry.name.endsWith('_tests.rs')) yield path;+ }+}++/** Scan the whole core source tree under `root`. */+export function checkRepository(root) {+ const src = join(root, CORE_SRC);+ if (!existsSync(src)) throw new Error(`${CORE_SRC} not found under ${root}`);+ const hits = [];+ for (const file of rustFiles(src)) {+ hits.push(...scanSource(relative(root, file), readFileSync(file, 'utf8')));+ }+ return hits;+}++export function formatReport(hits) {+ if (hits.length === 0) return 'core-hosted-free: ok (no hosted references in the core)';+ return [+ 'core-hosted-free: FAILED. The core must not name the hosted backend.',+ ...hits.map(h => ` - ${h.file}:${h.line}: ${h.name}: ${h.text}`),+ 'Move hosted code into crates/openhuman-tinyhumans and plug it in through a generic core registry.',+ ].join('\n');+}++function main() {+ const root = resolve(process.argv[2] ?? resolve(dirname(fileURLToPath(import.meta.url)), '../..'));+ let hits;+ try {+ hits = checkRepository(root);+ } catch (error) {+ console.error(`core-hosted-free: cannot read the core source: ${error.message}`);+ process.exit(2);+ }+ console.log(formatReport(hits));+ process.exit(hits.length === 0 ? 0 : 1);+}++if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) main();