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

feat(ruflo-autopilot): mod (guard/status/command) as function hooks, ADR-445 pattern

ruvfda3fb4066fc
diff --git a/plugins/ruflo-autopilot/.claude-plugin/plugin.json b/plugins/ruflo-autopilot/.claude-plugin/plugin.json
index 22f94b541d..1b12443c95 100644
--- a/plugins/ruflo-autopilot/.claude-plugin/plugin.json
+++ b/plugins/ruflo-autopilot/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "ruflo-autopilot",
"description": "Autonomous /loop-driven task completion with learning, prediction, and progress tracking — wraps 10 autopilot_* MCP tools (status/enable/disable/config/reset/log/progress/learn/history/predict)",
- "version": "0.2.1",
+ "version": "0.3.0",
"author": {
"name": "ruvnet",
"url": "https://github.com/ruvnet"
@@ -17,6 +17,28 @@
"prediction",
"progress-tracking",
"cache-aware",
- "mcp"
- ]
+ "mcp",
+ "mod",
+ "function-hooks"
+ ],
+ "userConfig": {
+ "guard": {
+ "type": "string",
+ "title": "Autopilot guard",
+ "description": "Refuse the autopilot log and learned patterns (autopilot_log, autopilot_learn) and a runaway loop limit on autopilot_config (maxIterations over the cap) that hold a key, token or password, and a loop limit over the cap.",
+ "required": false,
+ "default": "on",
+ "options": [
+ "on",
+ "off"
+ ]
+ },
+ "iterationCap": {
+ "type": "number",
+ "title": "Iteration cap",
+ "description": "Refuse an autopilot_config maxIterations above this (10 to 100000).",
+ "required": false,
+ "default": 1000
+ }
+ }
}
diff --git a/plugins/ruflo-autopilot/README.md b/plugins/ruflo-autopilot/README.md
index 571ceafa8b..2168b2147a 100644
--- a/plugins/ruflo-autopilot/README.md
+++ b/plugins/ruflo-autopilot/README.md
@@ -74,3 +74,14 @@ bash plugins/ruflo-autopilot/scripts/smoke.sh
## Architecture Decisions
- [`ADR-0001` — ruflo-autopilot plugin contract](./docs/adrs/0001-autopilot-contract.md)
+
+## As a mod
+
+Autopilot also ships as a function-hook mod (ADR-445 pattern; hooks in `hooks/`, loaded with the plugin). No network, no process, no model call.
+
+- **Guard (default on)**: refuses an `autopilot_log` or `autopilot_learn` write that holds a key, token or password, and an `autopilot_config` `maxIterations` above `iterationCap`. It only tightens: it never allows anything the session would deny, and the refusal never repeats the secret. Turn it off with the `guard` option.
+- **`/autopilot-mod`**: answered locally. `/autopilot-mod status`, `/autopilot-mod scan <text>`, `/autopilot-mod limits`.
+- **Status file**: `.claude-flow/autopilot-mod/status.json` (`version`, `updatedMs`, counters), written at session start and whenever a call is refused; the console reads it.
+- **Options** (`userConfig`): `guard` (`on` by default), `iterationCap` (1000).
+
+Test: `claude plugin validate plugins/ruflo-autopilot`, `claude plugin test plugins/ruflo-autopilot`, and `bash plugins/ruflo-autopilot/scripts/smoke.sh`.
diff --git a/plugins/ruflo-autopilot/hooks/command.ts b/plugins/ruflo-autopilot/hooks/command.ts
new file mode 100644
index 0000000000..cd852a476a
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/command.ts
@@ -0,0 +1,31 @@
+import { scan } from './screen'
+import type { ModOptions } from './options'
+import type { Stats } from './status'
+
+/** `/autopilot-mod` is answered locally and takes no model turn. */
+export type CommandDeps = { readonly opts: ModOptions; readonly stats: Stats }
+
+const HELP = ['/autopilot-mod status', '/autopilot-mod scan <text>', '/autopilot-mod limits'].join('\n')
+
+export function answer(args: string, deps: CommandDeps): string {
+ const [verb = '', ...rest] = args.trim().split(/\s+/)
+ const arg = rest.join(' ')
+ const { opts, stats } = deps
+
+ if (verb === '' || verb === 'help') return HELP
+
+ if (verb === 'status') {
+ return `guard ${opts.guard ? 'on' : 'off'} · calls guarded ${stats.calls} · blocked ${stats.blocked}`
+ }
+
+ if (verb === 'scan') {
+ if (arg === '') return 'usage: /autopilot-mod scan <text>'
+ const found = scan(arg)
+ const parts = [found.secrets.length ? `secrets: ${found.secrets.join(', ')}` : '', found.injection.length ? `injection phrasing: ${found.injection.join(', ')}` : ''].filter(Boolean)
+ return parts.length ? `The guard would refuse a write of that (${parts.join('; ')}).` : 'Nothing found: the guard would let that through.'
+ }
+
+ if (verb === 'limits') return `iteration cap ${opts.iterationCap} (autopilot_config maxIterations above it is refused while the guard is on)`
+
+ return `Unknown: ${verb}\n${HELP}`
+}
diff --git a/plugins/ruflo-autopilot/hooks/guard.ts b/plugins/ruflo-autopilot/hooks/guard.ts
new file mode 100644
index 0000000000..a2305c3b4d
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/guard.ts
@@ -0,0 +1,36 @@
+import type { ModOptions } from './options'
+import { hasSecret } from './screen'
+
+/** `mcp__<server>__<tool>` into its two halves; tool names never hold a double underscore. */
+export function splitName(name: string): { server: string; tool: string } | undefined {
+ if (!name.startsWith('mcp__')) return undefined
+ const at = name.lastIndexOf('__')
+ return at > 5 ? { server: name.slice(5, at), tool: name.slice(at + 2) } : undefined
+}
+
+/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
+export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
+ if (budget.left <= 0 || depth > 6) return []
+ if (typeof input === 'string') {
+ budget.left -= input.length
+ return [input]
+ }
+ if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
+ if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
+ return []
+}
+
+/** True for the tool calls this plugin guards: the autopilot log and learned patterns (`autopilot_log`, `autopilot_learn`) and a runaway loop limit on `autopilot_config` (`maxIterations` over the cap). */
+export function owns(tool: string, input: unknown): boolean {
+ const parts = splitName(tool)
+ const name = parts?.tool ?? tool
+ return name === 'autopilot_log' || name === 'autopilot_learn' || name === 'autopilot_config'
+}
+
+/** The reason a call is refused, or undefined when it may go. Never names or echoes the secret. */
+export function verdict(tool: string, input: unknown, opts: ModOptions): string | undefined {
+ if (!owns(tool, input)) return undefined
+ const max = (input as { maxIterations?: unknown } | null)?.maxIterations
+ if (typeof max === 'number' && max > opts.iterationCap) return "ruflo-autopilot: maxIterations is over the cap set in this plugin (iterationCap). Lower it, or raise the cap in the plugin options."
+ return textsOf(input).some(hasSecret) ? "ruflo-autopilot: this autopilot write holds what looks like a secret (a key, token or password). Episodes are logged and learned from; record a reference, not the value." : undefined
+}
diff --git a/plugins/ruflo-autopilot/hooks/hooks.json b/plugins/ruflo-autopilot/hooks/hooks.json
new file mode 100644
index 0000000000..cbf920957e
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/hooks.json
@@ -0,0 +1,6 @@
+{
+ "description": "Autopilot as a mod (ADR-445 pattern): a tighten-only guard on the autopilot log and learned patterns (`autopilot_log`, `autopilot_learn`) and a runaway loop limit on `autopilot_config` (`maxIterations` over the cap), /autopilot-mod, and a status file the console reads.",
+ "modules": [
+ "./register.ts"
+ ]
+}
diff --git a/plugins/ruflo-autopilot/hooks/options.ts b/plugins/ruflo-autopilot/hooks/options.ts
new file mode 100644
index 0000000000..8bc0c91c95
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/options.ts
@@ -0,0 +1,23 @@
+import type { PluginOptions } from 'claude-code'
+
+/** The plugin's `userConfig`, validated: a bad value is the default (guard on). */
+export type ModOptions = {
+ readonly guard: boolean
+ readonly iterationCap: number
+}
+
+const flag = (value: unknown, fallback: boolean) =>
+ value === true || value === 'true' || value === 'on' ? true : value === false || value === 'false' || value === 'off' ? false : fallback
+
+const clamp = (value: unknown, min: number, max: number, fallback: number) => {
+ const n = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? Number(value) : Number.NaN
+ return Number.isFinite(n) ? Math.min(max, Math.max(min, Math.round(n))) : fallback
+}
+
+export function readOptions(options: PluginOptions | undefined): ModOptions {
+ const o = options ?? {}
+ return {
+ guard: flag(o.guard, true),
+ iterationCap: clamp(o.iterationCap, 10, 100_000, 1000),
+ }
+}
diff --git a/plugins/ruflo-autopilot/hooks/register.ts b/plugins/ruflo-autopilot/hooks/register.ts
new file mode 100644
index 0000000000..faf7bd35c8
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/register.ts
@@ -0,0 +1,57 @@
+import type { Hook, Register } from 'claude-code'
+
+import { answer } from './command'
+import { owns, verdict } from './guard'
+import { readOptions } from './options'
+import { newStats, STATUS_PATH, statusText, type Stats } from './status'
+import type { ModOptions } from './options'
+
+type Dollar = Parameters<Hook<'session.start'>>[0]
+
+/** Everything one session of the mod keeps: its settings, counters and the project root. */
+type Session = { readonly opts: ModOptions; readonly stats: Stats; root?: string }
+
+async function flush($: Dollar, s: Session): Promise<void> {
+ if (s.root === undefined) return
+ try {
+ await $.fs.write(`${s.root}/${STATUS_PATH}`, statusText(s.stats, s.opts, await $.clock.now()))
+ } catch {
+ /* the status file is a courtesy */
+ }
+}
+
+/**
+ * Autopilot as a mod (ADR-445 pattern): a tighten-only guard on the autopilot log and learned patterns (`autopilot_log`, `autopilot_learn`) and a runaway loop limit on `autopilot_config` (`maxIterations` over the cap), `/autopilot-mod`, and a status file the console reads.
+ * No network, no process: only the hooks API.
+ */
+export const register: Register = (on, options) => {
+ const s: Session = { opts: readOptions(options), stats: newStats() }
+
+ on('session.start', async ($, e, next) => {
+ const result = await next(e)
+ s.root = (await $.session.root()) as string | undefined
+ s.stats.startedMs = await $.clock.now()
+ try {
+ await $.command.register({ name: 'autopilot-mod', description: 'Autopilot mod: status, scan <text>, limits' })
+ } catch {
+ /* a name taken by another plugin must not stop the mod */
+ }
+ await flush($, s)
+ return result
+ })
+
+ if (s.opts.guard) {
+ on('tool.call', async ($, e, next) => {
+ if (!owns(e.tool, e)) return next(e)
+ s.stats.calls++
+ const reason = verdict(e.tool, e, s.opts)
+ if (reason === undefined) return next(e)
+ s.stats.blocked++
+ await flush($, s)
+ return { deny: reason }
+ })
+ }
+
+ /** `/autopilot-mod` (a markdown command of the plugin cannot be answered by a hook, so the mod owns this name). */
+ on('command.run', { command: 'autopilot-mod' }, async (_$, e) => ({ text: answer(typeof e.args === 'string' ? e.args : '', { opts: s.opts, stats: s.stats }) }))
+}
diff --git a/plugins/ruflo-autopilot/hooks/screen.ts b/plugins/ruflo-autopilot/hooks/screen.ts
new file mode 100644
index 0000000000..b3b107dbef
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/screen.ts
@@ -0,0 +1,50 @@
+/**
+ * Pure text screening for the AgentDB mod (ADR-445). Two jobs: find secrets (so none is stored) and find prompt-injection phrasing (so
+ * retrieved memory cannot instruct the model). Findings are NAMES only: the matched text is never returned, logged or counted by value.
+ */
+
+const SECRETS: readonly (readonly [string, RegExp])[] = [
+ ['private key', /-----BEGIN [A-Z ]*PRIVATE KEY-----/],
+ ['aws access key', /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/],
+ ['github token', /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})\b/],
+ ['slack token', /\bxox[abprs]-[A-Za-z0-9-]{10,}/],
+ ['google api key', /\bAIza[0-9A-Za-z_-]{35}\b/],
+ ['anthropic or openai key', /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{24,}/],
+ ['jwt', /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/],
+ ['bearer token', /\bBearer\s+[A-Za-z0-9._~+/=-]{24,}/],
+ ['key assignment', /\b(?:api[_-]?key|secret|token|passw(?:or)?d|credential)s?["']?\s*[:=]\s*["']?[A-Za-z0-9/+=_.-]{16,}/i],
+]
+
+const INJECTION: readonly (readonly [string, RegExp])[] = [
+ ['override instructions', /\b(?:ignore|disregard|forget|override)\b[^.\n]{0,40}\b(?:previous|prior|above|earlier|all|any|system)\b[^.\n]{0,30}\b(?:instructions?|rules?|prompts?|guidelines?)\b/i],
+ ['role reassignment', /\byou are (?:now|no longer)\b|\bact as (?:an? )?(?:unrestricted|jailbroken)\b/i],
+ ['new instructions', /\b(?:new|updated|real) (?:system )?instructions?\s*:/i],
+ ['fake role tags', /<\/?\s*(?:system|assistant|developer|instructions?)\s*>|^\s*(?:system|assistant)\s*:/im],
+ ['concealment', /\bdo not (?:tell|inform|mention|reveal)[^.\n]{0,30}\b(?:user|human|operator)\b/i],
+ ['exfiltration', /\b(?:exfiltrate|send|post|upload)\b[^.\n]{0,50}\b(?:secrets?|credentials?|tokens?|api keys?|\.env)\b/i],
+ ['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
+]
+
+// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters.
+const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+
+const bare = (text: string) => (text.length > 20_000 ? text.slice(0, 20_000) : text).replace(INVISIBLE, '')
+
+export type Findings = { readonly secrets: readonly string[]; readonly injection: readonly string[] }
+
+const names = (rules: readonly (readonly [string, RegExp])[], text: string) => rules.filter(([, re]) => re.test(text)).map(([name]) => name)
+
+/** Names of every secret shape and injection phrase found in `text`. Cost is linear in the capped input. */
+export function scan(text: string): Findings {
+ const bounded = bare(text)
+ return { secrets: names(SECRETS, bounded), injection: names(INJECTION, bounded) }
+}
+
+export const hasSecret = (text: string) => names(SECRETS, bare(text)).length > 0
+
+
+/** Makes stored text safe to show: no control or bidi characters, whitespace collapsed, at most `max` characters. */
+export function tidy(text: string, max: number): string {
+ const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
+ return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
+}
diff --git a/plugins/ruflo-autopilot/hooks/status.ts b/plugins/ruflo-autopilot/hooks/status.ts
new file mode 100644
index 0000000000..800704daeb
--- /dev/null
+++ b/plugins/ruflo-autopilot/hooks/status.ts
@@ -0,0 +1,11 @@
+/** Counters the mod keeps for the session and writes to `.claude-flow/autopilot-mod/status.json` for the console. */
+export type Stats = { calls: number; blocked: number; startedMs: number }
+
+export const newStats = (): Stats => ({ calls: 0, blocked: 0, startedMs: 0 })
+
+export const STATUS_PATH = '.claude-flow/autopilot-mod/status.json'
+
+/** The file's text; `version` lets the console refuse a shape it does not know. */
+export function statusText(stats: Stats, mode: { guard: boolean }, nowMs: number): string {
+ return `${JSON.stringify({ version: 1, updatedMs: nowMs, mod: 'autopilot', guard: mode.guard, ...stats }, null, 2)}\n`
+}
diff --git a/plugins/ruflo-autopilot/scripts/smoke.sh b/plugins/ruflo-autopilot/scripts/smoke.sh
index 56fddbb833..f00bf03173 100755
--- a/plugins/ruflo-autopilot/scripts/smoke.sh
+++ b/plugins/ruflo-autopilot/scripts/smoke.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-# Structural smoke test for ruflo-autopilot v0.2.1 (ADR-0001).
+# Structural smoke test for ruflo-autopilot v0.3.0 (ADR-0001).
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PASS=0
@@ -8,10 +8,10 @@ step() { printf "→ %s ... " "$1"; }
ok() { printf "PASS\n"; PASS=$((PASS+1)); }
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
-step "1. plugin.json declares 0.2.1 with new keywords"
+step "1. plugin.json declares 0.3.0 with new keywords"
v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
-if [[ "$v" != "0.2.1" ]]; then
- bad "expected 0.2.1, got '$v'"
+if [[ "$v" != "0.3.0" ]]; then
+ bad "expected 0.3.0, got '$v'"
else
miss=""
for k in prediction progress-tracking cache-aware mcp; do
@@ -72,5 +72,27 @@ for f in "$ROOT"/skills/*/SKILL.md; do
done
[[ -z "$bad_skills" ]] && ok || bad "wildcard:$bad_skills"
+# M1. The mod (ADR-445 pattern): hooks module registered, files within the 500-line rule
+step "M1. mod: hooks.json names register.ts, every hook file is present and under 500 lines"
+mod_ok=1
+grep -q '"./register.ts"' "$ROOT/hooks/hooks.json" || mod_ok=0
+for f in options screen guard command status register; do
+ [[ -f "$ROOT/hooks/$f.ts" ]] || mod_ok=0
+ [[ $(wc -l < "$ROOT/hooks/$f.ts" 2>/dev/null || echo 9999) -le 500 ]] || mod_ok=0
+done
+[[ $mod_ok -eq 1 ]] && ok || bad "mod hooks incomplete or too long"
+
+step "M2. mod: userConfig defaults are safe (guard on)"
+node -e '
+const c = require(process.argv[1]).userConfig || {}
+process.exit(c.guard && c.guard.default === "on" ? 0 : 1)
+' "$ROOT/.claude-plugin/plugin.json" && ok || bad "userConfig defaults wrong"
+
+step "M3. mod: hooks never touch the network or spawn a process"
+if grep -nE '\$\.(http|process)\.|child_process|fetch\(' "$ROOT"/hooks/*.ts >/dev/null; then bad "network or process call in hooks"; else ok; fi
+
+step "M4. mod: /autopilot-mod is registered and collides with no command or skill of the plugin"
+if grep -q "name: 'autopilot-mod'" "$ROOT/hooks/register.ts" && [[ ! -e "$ROOT/commands/autopilot-mod.md" && ! -e "$ROOT/skills/autopilot-mod" ]]; then ok; else bad "command name missing or taken"; fi
+
printf "\n%s passed, %s failed\n" "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]] || exit 1
diff --git a/plugins/ruflo-autopilot/tests/mod.test.ts b/plugins/ruflo-autopilot/tests/mod.test.ts
new file mode 100644
index 0000000000..48cc57324f
--- /dev/null
+++ b/plugins/ruflo-autopilot/tests/mod.test.ts
@@ -0,0 +1,99 @@
+import type { On } from 'claude-code'
+import { describe, expect, test, tier } from 'claude-code/testing'
+
+import { readOptions } from '../hooks/options'
+
+tier('user')
+
+const ROOT = '/work'
+const START = { surface: 'terminal', isInteractive: true, cwd: ROOT } as const
+const slash = (args: string) => ({ command: 'autopilot-mod', args, origin: { kind: 'composer' }, presentation: { isFullscreen: false, columns: 100 } }) as const
+const STATUS = `${ROOT}/.claude-flow/autopilot-mod/status.json`
+
+// Built at run time so no secret-shaped literal sits in the source.
+const ghp = `ghp_${'a1B2'.repeat(10)}`
+
+/** The world beneath the mod: a project root, a file map, command registration and a clock. */
+function world(on: On) {
+ const files = new Map<string, string>()
+ const commands: string[] = []
+ on('session.start', ($, e) => ({ cwd: e.cwd }))
+ on('session.root', () => ({ value: ROOT }))
+ on('command.register', ($, e) => (commands.push(e.name), { value: { command: e.name } }))
+ on('fs.write', ($, e) => (files.set(e.path, e.text), { value: undefined }))
+ on('clock.now', () => ({ value: Date.now() }))
+ return { files, commands }
+}
+const status = (files: Map<string, string>) => JSON.parse(files.get(STATUS) ?? '{}')
+
+describe('defaults', () => {
+ test('options: bad values fall back to the safe default', () => {
+ expect(readOptions(undefined).guard).toBe(true)
+ expect(readOptions({ guard: 'banana' }).guard).toBe(true)
+ expect(readOptions({ guard: 'off' }).guard).toBe(false)
+ expect(readOptions(undefined).iterationCap).toBe(1000)
+ expect(readOptions({ iterationCap: 'x' }).iterationCap).toBe(1000)
+ expect(readOptions({ iterationCap: 1 }).iterationCap).toBe(10)
+ })
+
+ test('session start registers /autopilot-mod and writes the status file', async ($, on) => {
+ const w = world(on)
+ await $.session.start(START)
+ expect(w.commands).toContain('autopilot-mod')
+ expect(status(w.files)).toMatchObject({ version: 1, mod: 'autopilot', guard: true, blocked: 0 })
+ expect(typeof status(w.files).updatedMs).toBe('number')
+ })
+})
+
+describe('guard', () => {
+ test('refuses a secret, passes a clean call, ignores tools it does not own, never echoes the secret', async ($, on) => {
+ const w = world(on)
+ on('tool.call', () => ({ result: 'went through' }))
+ await $.session.start(START)
+
+ const denied = await $.tool.call(({ tool: "mcp__plugin_ruflo-core_ruflo__autopilot_log", message: `used ${ghp}` }) as never).then(
+ r => r,
+ (e: unknown) => ({ text: String(e) }),
+ )
+ expect(JSON.stringify(denied)).toContain('secret')
+ expect(JSON.stringify(denied)).not.toContain('ghp_')
+ expect(JSON.stringify(await $.tool.call(({ tool: "mcp__plugin_ruflo-core_ruflo__autopilot_log", message: "finished task 3" }) as never))).toContain('went through')
+ expect(JSON.stringify(await $.tool.call(({ tool: "mcp__plugin_ruflo-core_ruflo__autopilot_status", note: `${ghp}` }) as never))).toContain('went through')
+ expect(status(w.files)).toMatchObject({ blocked: 1 })
+ })
+
+ test('guard: off lets the call through', { options: { guard: 'off' } }, async ($, on) => {
+ world(on)
+ on('tool.call', () => ({ result: 'went through' }))
+ await $.session.start(START)
+ expect(JSON.stringify(await $.tool.call(({ tool: "mcp__plugin_ruflo-core_ruflo__autopilot_log", message: `used ${ghp}` }) as never))).toContain('went through')
+ })
+
+ test('a loop limit over the cap is refused, one under it passes', async ($, on) => {
+ world(on)
+ on('tool.call', () => ({ result: 'went through' }))
+ await $.session.start(START)
+ const call = (maxIterations: number) => $.tool.call({ tool: 'mcp__plugin_ruflo-core_ruflo__autopilot_config', maxIterations } as never).then(r => r, (e: unknown) => ({ text: String(e) }))
+ expect(JSON.stringify(await call(1_000_000))).toContain('iterationCap')
+ expect(JSON.stringify(await call(50))).toContain('went through')
+ })
+})
+
+describe('/autopilot-mod', () => {
+ test('status and scan answer locally', async ($, on) => {
+ world(on)
+ await $.session.start(START)
+ expect((await $.command.run(slash('status'))).text).toContain('guard on')
+ expect((await $.command.run(slash(`scan key ${ghp}`))).text).toContain('github token')
+ expect((await $.command.run(slash(`scan key ${ghp}`))).text).not.toContain('ghp_')
+ expect((await $.command.run(slash('scan plain words'))).text).toContain('Nothing found')
+ expect((await $.command.run(slash('limits'))).text).toContain("iteration cap 1000")
+ })
+
+ test('an unknown verb gets the help, not a model turn', async ($, on) => {
+ world(on)
+ await $.session.start(START)
+ expect((await $.command.run(slash('what is this'))).text).toContain('/autopilot-mod status')
+ expect((await $.command.run(slash(''))).text).toContain('/autopilot-mod status')
+ })
+})
diff --git a/plugins/ruflo-autopilot/tsconfig.json b/plugins/ruflo-autopilot/tsconfig.json
new file mode 100644
index 0000000000..e4ba54993e
--- /dev/null
+++ b/plugins/ruflo-autopilot/tsconfig.json
@@ -0,0 +1,19 @@
+{
+ "//": "Self-contained on purpose: bundlers (vite/esbuild in the root CI vitest) load this file for every module they transform, so it must not extend a file that only exists after Claude Code (>= 2.1.287) has loaded the plugin. Claude Code writes its declarations to .claude-plugin/types/ (gitignored) on load or validate; tsc -p . then reads them through typeRoots.",
+ "compilerOptions": {
+ "target": "es2023",
+ "lib": ["es2023"],
+ "module": "esnext",
+ "moduleResolution": "bundler",
+ "strict": true,
+ "noUncheckedIndexedAccess": true,
+ "noEmit": true,
+ "skipLibCheck": true,
+ "jsx": "react",
+ "jsxFactory": "h",
+ "jsxFragmentFactory": "Fragment",
+ "typeRoots": ["./.claude-plugin/types"],
+ "types": ["claude-code", "claude-code-tools", "claude-code-mcp"]
+ },
+ "include": ["hooks", "tests"]
+}