Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(mods): trust gate allow-list by provenance, no name-keyed self-exemption; fs.write is risky; strip CSI/OSC from segments

ruva0c4f99c2e37
diff --git a/plugins/ruflo-mods/.claude-plugin/plugin.json b/plugins/ruflo-mods/.claude-plugin/plugin.json
index 4149fb64bf..0d3415a41a 100644
--- a/plugins/ruflo-mods/.claude-plugin/plugin.json
+++ b/plugins/ruflo-mods/.claude-plugin/plugin.json
@@ -50,7 +50,7 @@
"modTrust": {
"type": "string",
"title": "Mod trust gate",
- "description": "How ruflo treats a hooks module installed or hot-reloaded after it (a mod Claude wrote, say). \"observe\" (default): name what it can do (host commands, network, environment, tool verdicts) in the transcript. \"refuse-risky\": refuse user-tier mods that can do any of those, unless named in modTrustAllow. \"off\": do not watch.",
+ "description": "How ruflo treats a hooks module installed or hot-reloaded after it (a mod Claude wrote, say). \"observe\" (default): name what it can do (host commands, network, environment, file writes, tool verdicts) in the transcript. \"refuse-risky\": refuse user-tier mods that can do any of those, unless listed in modTrustAllow. \"off\": do not watch.",
"required": false,
"default": "observe",
"options": [
@@ -61,8 +61,8 @@
},
"modTrustAllow": {
"type": "string",
- "title": "Trusted mods",
- "description": "Comma-separated plugin names the trust gate never refuses.",
+ "title": "Trusted mods (plugin ids)",
+ "description": "Comma-separated plugin ids as Claude Code keys them, name@marketplace (e.g. ruflo-swarm@ruflo), that the trust gate never refuses. Matched on where the plugin was installed from, not on the name it gives itself.",
"required": false,
"default": ""
}
diff --git a/plugins/ruflo-mods/hooks/options.ts b/plugins/ruflo-mods/hooks/options.ts
index 11adb7a3d6..c2bbb1f11c 100644
--- a/plugins/ruflo-mods/hooks/options.ts
+++ b/plugins/ruflo-mods/hooks/options.ts
@@ -18,10 +18,10 @@ const bool = (value: unknown, fallback: boolean) =>
const TRUST: readonly TrustPolicy[] = ['observe', 'refuse-risky', 'off']
-/** Plugin names, from a comma list or a string array; anything else is none. */
+/** Plugin ids (`name@marketplace`), from a comma list or a string array; anything else is none. */
function names(value: unknown): ReadonlySet<string> {
const list = typeof value === 'string' ? value.split(',') : Array.isArray(value) ? value : []
- return new Set(list.filter((v): v is string => typeof v === 'string').map(v => v.trim()).filter(v => /^[A-Za-z0-9._-]{1,64}$/.test(v)))
+ return new Set(list.filter((v): v is string => typeof v === 'string').map(v => v.trim()).filter(v => /^[A-Za-z0-9._-]{1,64}@[A-Za-z0-9._-]{1,64}$/.test(v)))
}
export function readOptions(options: PluginOptions | undefined): ModOptions {
diff --git a/plugins/ruflo-mods/hooks/state.ts b/plugins/ruflo-mods/hooks/state.ts
index 1dafcd3ef7..72be3fe379 100644
--- a/plugins/ruflo-mods/hooks/state.ts
+++ b/plugins/ruflo-mods/hooks/state.ts
@@ -71,6 +71,7 @@ export function setSegment(s: ModState, input: unknown): void {
text === null
? ''
: text
+ .replace(/\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?/g, '')
.replace(/[\u0000-\u001f\u007f-\u009f​-‏‪-‮⁠-⁩]/g, ' ')
.replace(/\s+/g, ' ')
.trim()
diff --git a/plugins/ruflo-mods/hooks/trust.ts b/plugins/ruflo-mods/hooks/trust.ts
index 26ca4e7419..363b9c94dd 100644
--- a/plugins/ruflo-mods/hooks/trust.ts
+++ b/plugins/ruflo-mods/hooks/trust.ts
@@ -28,6 +28,7 @@ const RISKY_CALLS: Record<string, string> = {
'process.run': 'runs host commands',
'http.fetch': 'makes network requests',
'env.set': 'changes the environment of later hooks and tools',
+ 'fs.write': 'writes files (settings, hooks, helpers included)',
}
/** Hooks that decide for, or over, everything else. */
@@ -55,11 +56,16 @@ export function riskOf(scan: ModuleScan): string[] {
export type TrustDecision = { readonly judged: boolean; readonly risk: readonly string[]; readonly refuse?: string }
/**
- * Judges one registering module. Only user-tier modules other than this one
- * and the allow-listed are judged; refusal only under `refuse-risky`.
+ * Judges one registering module: user-tier modules not on the allow-list;
+ * refusal only under `refuse-risky`. The allow-list matches the loader's
+ * `provenance` (`name@marketplace`, `name@inline`), never the module's own
+ * `name`, which is its manifest's word and a rename walks past. There is no
+ * self-exemption: a module only judges those admitted after it, so ruflo-mods
+ * never meets its own registration, and a mod calling itself "ruflo-mods" is
+ * judged like any other.
*/
export function judge(scan: ModuleScan, policy: TrustPolicy, allow: ReadonlySet<string>): TrustDecision {
- if (policy === 'off' || scan.tier !== 'user' || scan.name === 'ruflo-mods' || allow.has(scan.name)) {
+ if (policy === 'off' || scan.tier !== 'user' || allow.has(scan.provenance)) {
return { judged: false, risk: [] }
}
const risk = riskOf(scan)
@@ -67,7 +73,7 @@ export function judge(scan: ModuleScan, policy: TrustPolicy, allow: ReadonlySet<
? {
judged: true,
risk,
- refuse: `ruflo mod trust (modTrust=refuse-risky): ${scan.name} ${risk.join('; ')}; allow it by name in modTrustAllow`,
+ refuse: `ruflo mod trust (modTrust=refuse-risky): ${scan.name} ${risk.join('; ')}; allow it by provenance (${scan.provenance}) in modTrustAllow`,
}
: { judged: true, risk }
}
@@ -96,7 +102,7 @@ export function registerTrust(on: On, policy: TrustPolicy, allow: ReadonlySet<st
}).catch(($, e, next) =>
// Observing, a failure admits as Claude Code would without ruflo; set to
// refuse, the gate guards something, so a module it could not judge stays out.
- policy === 'refuse-risky' && e.tier === 'user' && e.name !== 'ruflo-mods' && !allow.has(e.name)
+ policy === 'refuse-risky' && e.tier === 'user' && !allow.has(e.provenance)
? { refuse: `ruflo mod trust could not judge ${e.name} (${next.error.message ?? next.error.kind}); refused (modTrust=refuse-risky)` }
: next(e),
)
diff --git a/plugins/ruflo-mods/tests/noun.test.ts b/plugins/ruflo-mods/tests/noun.test.ts
index 948be04f40..0f45b2a7ab 100644
--- a/plugins/ruflo-mods/tests/noun.test.ts
+++ b/plugins/ruflo-mods/tests/noun.test.ts
@@ -17,10 +17,10 @@ describe('noun', () => {
expect((await $.command.run(segment('ruos', 'ruOS 1/2 agents\u001b[31m · Work‮Desktop'))).text).toBe('ok')
expect((await $.command.run(segment('aaa', 'x'.repeat(200)))).text).toBe('ok')
- expect(w.statuses.at(-1)).toBe(`ruflo · tester 60% · ${'x'.repeat(47)}… · ruOS 1/2 agents [31m · Work Desktop`)
+ expect(w.statuses.at(-1)).toBe(`ruflo · tester 60% · ${'x'.repeat(47)}… · ruOS 1/2 agents · Work Desktop`)
await $.command.run(segment('aaa', null))
- expect(w.statuses.at(-1)).toBe('ruflo · tester 60% · ruOS 1/2 agents [31m · Work Desktop')
+ expect(w.statuses.at(-1)).toBe('ruflo · tester 60% · ruOS 1/2 agents · Work Desktop')
expect((await $.command.run(segment('bad id!', 'x'))).text).toMatch(/^error: /)
for (let i = 0; i < 7; i++) await $.command.run(segment(`s${i}`, 'y'))
diff --git a/plugins/ruflo-mods/tests/trust.test.ts b/plugins/ruflo-mods/tests/trust.test.ts
index 7813114bf9..cc147ef309 100644
--- a/plugins/ruflo-mods/tests/trust.test.ts
+++ b/plugins/ruflo-mods/tests/trust.test.ts
@@ -50,7 +50,7 @@ describe('trust', () => {
test(
'refuse-risky honours the allow-list',
- { plugins: [autoAllow], options: { modTrust: 'refuse-risky', modTrustAllow: 'auto-allow' } },
+ { plugins: [autoAllow], options: { modTrust: 'refuse-risky', modTrustAllow: 'auto-allow@claude-plugin-test' } },
async ($, on) => {
world(on)
on('tool.check', () => ({ decision: 'ask' }))
@@ -60,3 +60,13 @@ describe('trust', () => {
},
)
})
+
+describe('trust by provenance', () => {
+ // A mod calling itself ruflo-mods is covered by the harness suite: the kit
+ // refuses to load two plugins of one name.
+ test('the allow-list matches provenance, not the self-declared name', { plugins: [autoAllow], options: { modTrust: 'refuse-risky', modTrustAllow: 'nobody@inline' } }, async ($, on) => {
+ world(on)
+ on('tool.check', () => ({ decision: 'ask' }))
+ await expect($.session.start(START)).rejects.toThrow(/allow it by provenance \(auto-allow@/)
+ })
+})
diff --git a/v3/@claude-flow/cli/__tests__/mods/mods-noun-trust.test.ts b/v3/@claude-flow/cli/__tests__/mods/mods-noun-trust.test.ts
index 377dd04189..dd98ea34bb 100644
--- a/v3/@claude-flow/cli/__tests__/mods/mods-noun-trust.test.ts
+++ b/v3/@claude-flow/cli/__tests__/mods/mods-noun-trust.test.ts
@@ -23,7 +23,7 @@ describe('ADR-404 $.ruflo noun', () => {
const mod = loadMod(register, world);
const built = await mod.create();
await mod.dispatch('session.start', { cwd: '/work', surface: null, isInteractive: false }, (e) => ({ cwd: e.cwd }));
- await built.ruflo.segment({ id: 'ruos', text: 'a\u0007b‮\n\tc' });
+ await built.ruflo.segment({ id: 'ruos', text: 'a\u0007b‮\n\tc\u001b[31m\u001b]8;;http://x\u0007' });
await built.ruflo.segment({ id: 'aa', text: 'z'.repeat(100) });
expect(world.statuses.at(-1)).toBe(`ruflo · ${'z'.repeat(47)}… · a b c`);
await built.ruflo.segment({ id: 'aa', text: null });
@@ -61,15 +61,18 @@ describe('ADR-404 mod trust gate', () => {
'process.run (runs host commands)', 'http.fetch (makes network requests)', 'on tool.check (can answer tool permission verdicts)',
]);
expect(riskOf(scan({ uses: { events: 'nope', calls: [1] } as never }))).toEqual([]);
+ expect(riskOf(scan({ uses: { events: [], calls: ['fs.write'] } }))).toEqual(['fs.write (writes files (settings, hooks, helpers included))']);
});
it('judges only other user-tier modules; refuses only under refuse-risky', () => {
const risky = scan({ uses: { events: ['*'], calls: [] } });
expect(judge(risky, 'observe', new Set()).refuse).toBeUndefined();
expect(judge(risky, 'refuse-risky', new Set()).refuse).toMatch(/sees every event/);
- expect(judge(risky, 'refuse-risky', new Set(['m'])).judged).toBe(false);
+ expect(judge(risky, 'refuse-risky', new Set(['m@inline'])).judged).toBe(false); // provenance
+ expect(judge(risky, 'refuse-risky', new Set(['m'])).refuse).toBeDefined(); // a bare name is not trusted
expect(judge({ ...risky, tier: 'prepend' }, 'refuse-risky', new Set()).judged).toBe(false);
- expect(judge({ ...risky, name: 'ruflo-mods' }, 'refuse-risky', new Set()).judged).toBe(false);
+ // No self-exemption: a later module naming itself ruflo-mods is judged like any other.
+ expect(judge({ ...risky, name: 'ruflo-mods', provenance: 'ruflo-mods@inline' }, 'refuse-risky', new Set()).refuse).toMatch(/sees every event/);
expect(judge(risky, 'off', new Set()).judged).toBe(false);
});
diff --git a/v3/docs/adr/ADR-404-claude-code-mods-function-hooks.md b/v3/docs/adr/ADR-404-claude-code-mods-function-hooks.md
index eb1099ffef..a0f7daf53d 100644
--- a/v3/docs/adr/ADR-404-claude-code-mods-function-hooks.md
+++ b/v3/docs/adr/ADR-404-claude-code-mods-function-hooks.md
@@ -113,10 +113,10 @@ Tests run the real `hook-handler.cjs` and `ruflo-hook.cjs` with the environment
### The mod trust gate
-Self-modding means a Claude-written mod can be installed and run with Claude Code's access mid-session. The gate hooks `plugin.register`, first in registration order so it wraps everything else of ruflo's. It judges user-tier modules admitted after it, except itself and an allow-list, from the host's scan, never from the module's own claims.
+Self-modding means a Claude-written mod can be installed and run with Claude Code's access mid-session. The gate hooks `plugin.register`, first in registration order so it wraps everything else of ruflo's. It judges user-tier modules admitted after it, from the host's scan, never from the module's own claims. The allow-list matches the loader-keyed provenance (`name@marketplace`, e.g. `ruflo-swarm@ruflo`), never the self-declared `name`, which a rename walks past. There is no self-exemption: a module only judges modules admitted after it, so ruflo-mods never meets its own registration, and a later mod calling itself `ruflo-mods` is judged like any other.
- **What counts as risky.**
- - Calls: `process.run` (host commands), `http.fetch` (network), `env.set`.
+ - Calls: `process.run` (host commands), `http.fetch` (network), `env.set`, `fs.write` (any path, so settings, hooks and helpers included: a persistence route).
- Hooks: `tool.check`, `tool.call`, `*`, `classic.*`, `plugin.register`, `prompt.compose`.
- **Policy (`userConfig.modTrust`).**
- `observe` (default) names what the module can do in the transcript, or the debug log for a module with nothing risky.
@@ -128,6 +128,8 @@ Self-modding means a Claude-written mod can be installed and run with Claude Cod
The ruflo CLI's plugin trust policy (#3557) is Node code and cannot run inside the sandbox, so the gate applies its own scan-based rule rather than that policy.
+Sibling mods are risky by this rule: ruflo-swarm hooks `tool.call`, `agent.spawn` and an opt-in `*`; the ruOS mod hooks `tool.check`; the scaffold template calls `env.set`. Under the default `observe` they load unchanged. Under `refuse-risky` they must be allow-listed by provenance (`ruflo-swarm@ruflo`, and the ruOS mod's own id). Their lanes have been told.
+
### Tiers and `sec-default`
Ruflo loads in the user tier. Under `sec-default`: