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(ruflo-mods): a parse error that quotes "ENOENT" no longer reads as an absent projection (#3793)

Dragan Spiridonovf661b83585dd
diff --git a/plugins/ruflo-mods/hooks/files.ts b/plugins/ruflo-mods/hooks/files.ts
index 14105d4b2d..c3da4b89f0 100644
--- a/plugins/ruflo-mods/hooks/files.ts
+++ b/plugins/ruflo-mods/hooks/files.ts
@@ -51,13 +51,29 @@ export function cachedFile<T>(pathOf: () => string, parse: (text: string) => T)
}
if (seen?.key === key) return seen.read
- let read: Read<T>
- try {
- read = { kind: 'ok', value: parse(await fs.read(path)) }
- } catch (error) {
- read = isMissing(error) ? { kind: 'absent' } : { kind: 'error', message: String((error as Error)?.message ?? error) }
- }
+ const read = await readAndParse(fs, path, parse)
seen = { key, read }
return read
}
}
+
+const messageOf = (error: unknown) => String((error as Error)?.message ?? error)
+
+/**
+ * Only the read may say "absent": a parse error's message can quote the file's
+ * own text (JSON.parse does), so a corrupt file containing "ENOENT" must still
+ * be an error and never read as "no file here".
+ */
+async function readAndParse<T>(fs: FileHost, path: string, parse: (text: string) => T): Promise<Read<T>> {
+ let text: string
+ try {
+ text = await fs.read(path)
+ } catch (error) {
+ return isMissing(error) ? { kind: 'absent' } : { kind: 'error', message: messageOf(error) }
+ }
+ try {
+ return { kind: 'ok', value: parse(text) }
+ } catch (error) {
+ return { kind: 'error', message: messageOf(error) }
+ }
+}
diff --git a/plugins/ruflo-mods/tests/register.test.ts b/plugins/ruflo-mods/tests/register.test.ts
index c378dd991d..6a9ce098cd 100644
--- a/plugins/ruflo-mods/tests/register.test.ts
+++ b/plugins/ruflo-mods/tests/register.test.ts
@@ -134,6 +134,24 @@ describe('register', () => {
expect((await $.tool.check({ tool: 'Read', input: { file_path: 'a.ts' } })).decision).toBe('ask')
})
+ test('tool.check: a parse error that quotes "ENOENT" is still unreadable, never "no policy"', async ($, on) => {
+ const PATH = `${ROOT}/.claude-flow/policy/claude-code.json`
+ const rule = { id: 'no-push', effect: 'deny', actions: ['claude-code.tool.Bash'], resources: ['git push*'] }
+ const w = world(on, {}, { [PATH]: JSON.stringify({ version: 1, mode: 'enforce', rules: [rule] }) })
+ on('tool.check', () => ({ decision: 'allow' }))
+ await $.session.start(START)
+ const push = { tool: 'Bash', input: { command: 'git push origin' } }
+ expect((await $.tool.check(push)).decision).toBe('deny')
+
+ // JSON.parse and the validator both put the file's own text in their message.
+ for (const text of ['{"version": 1, "mode": "enforce", ENOENT', JSON.stringify({ version: 'ENOENT', mode: 'enforce', rules: [rule] })]) {
+ w.files.set(PATH, text)
+ const out = await $.tool.check(push)
+ expect(out.decision, text).toBe('ask')
+ expect(out.reason).toContain('unreadable')
+ }
+ })
+
test('tool.check: a legacy or unknown-mode projection is unreadable, so the call asks; the report names the state (ADR-450 T10)', async ($, on) => {
const PATH = `${ROOT}/.claude-flow/policy/claude-code.json`
const rule = { id: 'no-push', effect: 'deny', actions: ['claude-code.tool.Bash'], resources: ['git push*'] }