🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
test(mods): tripwire against forwarding a mod status file into model context (ADR-450 T7)
ruv8d32e0f64293
diff --git a/scripts/check-status-forwarding.mjs b/scripts/check-status-forwarding.mjsnew file mode 100644index 0000000000..ace6c461d5--- /dev/null+++ b/scripts/check-status-forwarding.mjs@@ -0,0 +1,66 @@+#!/usr/bin/env node+// check-status-forwarding — tripwire for ADR-450 T7 (cross-mod injection by forwarding).+// A mod hook module that attaches text to the model's input (`context:`, `instructions:`, `additionalContext`, `describe`)+// must not also read another mod's status file (`.claude-flow/<x>-mod/status.json`), or one mod's output reaches the next+// mod's prompt. Grep-level: a path built from pieces defeats it. It holds the line, it is not a proof.+//+// node scripts/check-status-forwarding.mjs [--root <dir>]+//+// Allowlist: scripts/status-forwarding.allow.json, "<plugin>/hooks/<file>.ts" -> one-line reason.+// Exit: 0 clean · 1 violations · 3 scanned zero sink modules (fail loud, layout drift).++import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';+import { dirname, join, relative } from 'node:path';+import { fileURLToPath, pathToFileURL } from 'node:url';++const HERE = dirname(fileURLToPath(import.meta.url));+const SINK = /\b(?:context|instructions|additionalContext|describe)\s*:|\.describe\b/;+const READ = /\b(?:fs\.read|readFile\w*|readBounded|readJson\w*)\s*\(/;+const LITERAL = /-mod\/|\bstatus\.json\b/;+const IDENT = /\b[A-Z][A-Z_]*STATUS[A-Z_]*(?:PATH|FILE)\b/;+const OWN_IMPORT = /import\s*\{[^}]*\bSTATUS_\w+[^}]*\}\s*from\s*['"]\.\/status['"]/;++function walk(dir, out = []) {+ if (!existsSync(dir)) return out;+ for (const n of readdirSync(dir)) {+ const p = join(dir, n);+ if (statSync(p).isDirectory()) { if (n !== 'node_modules') walk(p, out); } else if (n.endsWith('.ts') && !n.endsWith('.d.ts')) out.push(p);+ }+ return out;+}++/** Why `source` forwards a status file into model context, or null. Exported for tests. */+export function violation(source) {+ if (!SINK.test(source) || !READ.test(source)) return null;+ if (LITERAL.test(source)) return 'reads a status-file path';+ if (IDENT.test(source) && !OWN_IMPORT.test(source)) return 'reads a status-path constant it did not import from its own ./status';+ return null;+}++export function check(root, allow = {}) {+ const bad = []; let sinks = 0;+ const plugins = join(root, 'plugins');+ for (const plugin of existsSync(plugins) ? readdirSync(plugins) : []) {+ for (const file of walk(join(plugins, plugin, 'hooks'))) {+ const src = readFileSync(file, 'utf8');+ if (!SINK.test(src)) continue;+ sinks++;+ const why = violation(src);+ const rel = relative(plugins, file).split('\\').join('/');+ if (why && !allow[rel]) bad.push({ file: rel, why });+ }+ }+ return { bad, sinks };+}++if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {+ const i = process.argv.indexOf('--root');+ const root = i > 0 ? process.argv[i + 1] : dirname(HERE);+ const allowPath = join(HERE, 'status-forwarding.allow.json');+ const allow = existsSync(allowPath) ? JSON.parse(readFileSync(allowPath, 'utf8')) : {};+ const { bad, sinks } = check(root, allow);+ if (!sinks) { console.error('check-status-forwarding: no sink modules found; the check is broken. Failing.'); process.exit(3); }+ for (const b of bad) console.error(`check-status-forwarding: ${b.file} ${b.why} while attaching model context (ADR-450 T7)`);+ if (bad.length) process.exit(1);+ console.log(`check-status-forwarding: ${sinks} context-bearing modules scanned, none forward a status file.`);+}diff --git a/scripts/status-forwarding.allow.json b/scripts/status-forwarding.allow.jsonnew file mode 100644index 0000000000..0967ef424b--- /dev/null+++ b/scripts/status-forwarding.allow.json@@ -0,0 +1 @@+{}diff --git a/tests/check-status-forwarding.test.mjs b/tests/check-status-forwarding.test.mjsnew file mode 100644index 0000000000..6eb04091f8--- /dev/null+++ b/tests/check-status-forwarding.test.mjs@@ -0,0 +1,50 @@+// node --test tests/check-status-forwarding.test.mjs+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { check, violation } from '../scripts/check-status-forwarding.mjs';++const ROOT = fileURLToPath(new URL('..', import.meta.url));+const FIXTURE = fileURLToPath(new URL('./fixtures/status-forwarding', import.meta.url));+const SCRIPT = fileURLToPath(new URL('../scripts/check-status-forwarding.mjs', import.meta.url));+const allow = JSON.parse(readFileSync(new URL('../scripts/status-forwarding.allow.json', import.meta.url), 'utf8'));++test('the real tree forwards no status file into model context', () => {+ const { bad, sinks } = check(ROOT, allow);+ assert.ok(sinks > 0, 'scanned zero context-bearing modules');+ assert.deepEqual(bad, []);+});++test('the console only reads status files for display: its readers attach no model context', () => {+ // Proof for the empty allowlist: every console module that names a -mod/ path has no sink, so none needs an entry.+ for (const f of ['data/mods.ts', 'data/files.ts', 'data/agentdb-mod.ts', 'data/snapshot.ts', 'views/mods.ts']) {+ const src = readFileSync(`${ROOT}/plugins/ruflo-console/hooks/${f}`, 'utf8');+ assert.equal(violation(src), null, f);+ assert.doesNotMatch(src, /\b(?:context|instructions|additionalContext)\s*:/, `${f} attaches model context`);+ }+});++test('the bad fixture fails: context plus a neighbour status read', () => {+ const { bad } = check(FIXTURE, {});+ assert.equal(bad.length, 1);+ assert.match(bad[0].file, /ruflo-bad\/hooks\/register\.ts$/);+ const r = spawnSync(process.execPath, [SCRIPT, '--root', FIXTURE], { encoding: 'utf8' });+ assert.equal(r.status, 1);+});++test('an allowlist entry silences the fixture', () => {+ assert.deepEqual(check(FIXTURE, { 'ruflo-bad/hooks/register.ts': 'test' }).bad, []);+});++test('own-status writers and display readers are not flagged', () => {+ assert.equal(violation("import { STATUS_PATH } from './status'\nawait $.fs.write(STATUS_PATH, x)\nreturn { context: [a] }\nawait $.fs.read(p)"), null);+ assert.equal(violation("await $.fs.read('.claude-flow/x-mod/status.json')"), null); // no sink+ assert.match(violation("return { instructions: s }\nawait $.fs.read(`${r}/.claude-flow/x-mod/status.json`)"), /status-file path/);+});++test('an empty tree fails loud', () => {+ const r = spawnSync(process.execPath, [SCRIPT, '--root', ROOT + '/tests/fixtures/none'], { encoding: 'utf8' });+ assert.equal(r.status, 3);+});diff --git a/tests/fixtures/status-forwarding/plugins/ruflo-bad/hooks/register.ts b/tests/fixtures/status-forwarding/plugins/ruflo-bad/hooks/register.tsnew file mode 100644index 0000000000..e4fe5be1f3--- /dev/null+++ b/tests/fixtures/status-forwarding/plugins/ruflo-bad/hooks/register.ts@@ -0,0 +1,5 @@+// Deliberately bad fixture for check-status-forwarding: forwards a neighbour's status file into prompt context.+export async function onPrompt($: any) {+ const raw = await $.fs.read('.claude-flow/agentdb-mod/status.json')+ return { context: [raw] }+}