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-mods): toolHints option hooks tool.describe (default off); ADR-451 mod capability roadmap and API coverage table

ruva6486f371ff1
diff --git a/plugins/ruflo-mods/.claude-plugin/plugin.json b/plugins/ruflo-mods/.claude-plugin/plugin.json
index ed1bb4bee7..21f3f086cd 100644
--- a/plugins/ruflo-mods/.claude-plugin/plugin.json
+++ b/plugins/ruflo-mods/.claude-plugin/plugin.json
@@ -47,6 +47,13 @@
"required": false,
"default": false
},
+ "toolHints": {
+ "type": "boolean",
+ "title": "Usage hints on ruflo tools",
+ "description": "Add one short, static usage hint (restating the project's own CLAUDE.md) to the description of a few ruflo MCP tools, such as memory_search and swarm_init, so the model sees it at the tool. Appends text only, cached for the session. Off by default.",
+ "required": false,
+ "default": false
+ },
"modTrust": {
"type": "string",
"title": "Mod trust gate",
diff --git a/plugins/ruflo-mods/hooks/describe/hints.ts b/plugins/ruflo-mods/hooks/describe/hints.ts
new file mode 100644
index 0000000000..88ed969ee0
--- /dev/null
+++ b/plugins/ruflo-mods/hooks/describe/hints.ts
@@ -0,0 +1,37 @@
+/**
+ * One-line usage hints for ruflo's own MCP tools (ADR-451). Every hint
+ * restates what the project's CLAUDE.md already tells a person, so the model
+ * sees it at the tool instead of only in a file it may not have loaded.
+ * Static text only: `tool.describe` answers are cached for the session, and
+ * an answer that changes spends the prompt cache.
+ */
+export const HINTS: Readonly<Record<string, string>> = {
+ memory_search: 'Searches AgentDB only; memory_search_unified also covers Claude memories and patterns.',
+ memory_store: 'Stores the value with a 384-dim ONNX embedding; give it a namespace.',
+ swarm_init: 'For coding work use topology hierarchical, maxAgents 6-8, strategy specialized.',
+ agent_spawn: 'Records the agent in ruflo coordination; Claude Code agents do the actual work.',
+ hooks_route: 'Call before complex multi-file work to get the recommended agent and model tier.',
+ guidance_brain: 'Call with mode recommend before complex ruflo work to read the live tool registry.',
+}
+
+/** The separator that marks a description a hint was already added to. */
+export const MARK = '\n\nruflo: '
+
+export const MAX_HINT_CHARS = 160
+
+/** The server prefixes ruflo's MCP tools are listed under; nothing else is touched. */
+export const RUFLO_TOOL_NAME = /^mcp__(?:plugin_ruflo-core_ruflo|claude-flow|ruflo)__([a-z0-9_-]+)$/
+
+/** The hint for a tool as the model sees it by name, or undefined. */
+export function hintFor(tool: string): string | undefined {
+ const name = RUFLO_TOOL_NAME.exec(tool)?.[1]
+ const hint = name === undefined ? undefined : Object.hasOwn(HINTS, name) ? HINTS[name] : undefined
+ return hint !== undefined && hint.length <= MAX_HINT_CHARS ? hint : undefined
+}
+
+/** The description with the hint added once; anything unexpected is returned as it came. */
+export function withHint(tool: string, description: unknown): unknown {
+ if (typeof description !== 'string' || description.includes(MARK)) return description
+ const hint = hintFor(tool)
+ return hint === undefined ? description : `${description}${MARK}${hint}`
+}
diff --git a/plugins/ruflo-mods/hooks/describe/index.ts b/plugins/ruflo-mods/hooks/describe/index.ts
new file mode 100644
index 0000000000..88c906f0bd
--- /dev/null
+++ b/plugins/ruflo-mods/hooks/describe/index.ts
@@ -0,0 +1,23 @@
+import type { On } from 'claude-code'
+
+import type { ModState } from '../state'
+import { withHint } from './hints'
+
+/**
+ * `tool.describe` (ADR-451): adds one static usage hint to the description of
+ * a few ruflo MCP tools, once per tool per session. Off unless the
+ * `toolHints` option is on. It only appends text: placement (`isDeferred`)
+ * and the engine's own description are kept, and a tool not in the hint
+ * table, or from any other server, is left exactly as it came.
+ */
+export function registerDescribe(on: On, state: ModState) {
+ state.toolHints.enabled = true
+
+ on('tool.describe', { tool: /^mcp__(?:plugin_ruflo-core_ruflo|claude-flow|ruflo)__/ }, async (_$, e, next) => {
+ const result = await next(e)
+ const description = withHint(e.tool, result.description)
+ if (description === result.description || typeof description !== 'string') return result
+ state.toolHints.described.add(e.tool)
+ return { ...result, description }
+ })
+}
diff --git a/plugins/ruflo-mods/hooks/options.ts b/plugins/ruflo-mods/hooks/options.ts
index 59e6a42130..71dac24110 100644
--- a/plugins/ruflo-mods/hooks/options.ts
+++ b/plugins/ruflo-mods/hooks/options.ts
@@ -11,6 +11,7 @@ export type ModOptions = {
readonly statusLine: boolean
readonly costBudgetUsd?: number
readonly costHardStop: boolean
+ readonly toolHints: boolean
readonly modTrust: TrustPolicy
readonly modTrustAllow: ReadonlySet<string>
}
@@ -35,6 +36,7 @@ export function readOptions(options: PluginOptions | undefined): ModOptions {
statusLine: bool(o.statusLine, true),
costBudgetUsd: budgetOf(o.costBudgetUsd),
costHardStop: bool(o.costHardStop, false),
+ toolHints: bool(o.toolHints, false),
modTrust: TRUST.includes(o.modTrust as TrustPolicy) ? (o.modTrust as TrustPolicy) : 'observe',
modTrustAllow: names(o.modTrustAllow),
}
diff --git a/plugins/ruflo-mods/hooks/register.ts b/plugins/ruflo-mods/hooks/register.ts
index dcbff81e42..6c5a89e539 100644
--- a/plugins/ruflo-mods/hooks/register.ts
+++ b/plugins/ruflo-mods/hooks/register.ts
@@ -1,6 +1,7 @@
import type { Register } from 'claude-code'
import { registerCost } from './cost'
+import { registerDescribe } from './describe'
import { registerGuard } from './guard'
import { createGuidance } from './guidance'
import { registerLearn } from './learn'
@@ -35,4 +36,5 @@ export const register: Register = (on, options) => {
registerGuard(on, state, guidance)
registerLearn(on, state, guidance)
registerCost(on, state, opts)
+ if (opts.toolHints) registerDescribe(on, state)
}
diff --git a/plugins/ruflo-mods/hooks/state.ts b/plugins/ruflo-mods/hooks/state.ts
index d73093a95d..c97c8aa6e9 100644
--- a/plugins/ruflo-mods/hooks/state.ts
+++ b/plugins/ruflo-mods/hooks/state.ts
@@ -28,6 +28,8 @@ export type ModState = {
/** The research run (marker startedAt) whose first web call was already put to the person. */
researchAsked?: string
budget: { level: BudgetLevel; usd?: number; limit?: number }
+ /** `tool.describe` hints (ADR-451): whether the feature is on and which tools it described. */
+ toolHints: { enabled: boolean; described: Set<string> }
/** Other mods' status segments, by id (`$.ruflo.segment`). */
segments: Map<string, string>
/**
@@ -50,6 +52,7 @@ export function createState(): ModState {
editCount: 0,
policy: 'none',
budget: { level: 'OK' },
+ toolHints: { enabled: false, described: new Set() },
segments: new Map(),
draw: () => undefined,
}
@@ -132,6 +135,7 @@ export function report(s: ModState): string {
` edits: ${s.editCount} recorded, ${s.edits.length} pending write`,
` policy: ${s.policy}; ${s.tightened} call(s) tightened, ${s.observed} observed`,
` budget: ${budget}`,
+ ` tool hints: ${s.toolHints.enabled ? `${s.toolHints.described.size} tool(s) described` : 'off (set the toolHints option)'}`,
` segments: ${segments.join(', ') || 'none'}`,
` guidance: ${s.guidance.status}; ${s.guidance.saved} unverified observation(s), ${s.guidance.pending.length} pending, ${s.guidance.dropped} dropped`,
].join('\n')
diff --git a/plugins/ruflo-mods/scripts/smoke.sh b/plugins/ruflo-mods/scripts/smoke.sh
index cb9b9fbe5b..145375ee9c 100755
--- a/plugins/ruflo-mods/scripts/smoke.sh
+++ b/plugins/ruflo-mods/scripts/smoke.sh
@@ -32,7 +32,7 @@ hits=$(grep -rnE '\$\.(http|process|model|mcp)\.' "$HOOKS" || true)
step "5. only the documented events are hooked"
events=$(grep -rhoE "on\('[a-z.*]+'" "$HOOKS" | sort -u | tr '\n' ' ')
-expected="on('agent.spawn' on('command.run' on('engine.create' on('plugin.register' on('prompt.submit' on('session.end' on('session.measure' on('session.start' on('tool.call' on('tool.check' on('turn.complete' "
+expected="on('agent.spawn' on('command.run' on('engine.create' on('plugin.register' on('prompt.submit' on('session.end' on('session.measure' on('session.start' on('tool.call' on('tool.check' on('tool.describe' on('turn.complete' "
[[ "$events" == "$expected" ]] && ok || bad "got: $events"
step "6. tool.check merges with stricter() (tighten-only)"
diff --git a/plugins/ruflo-mods/tests/describe.test.ts b/plugins/ruflo-mods/tests/describe.test.ts
new file mode 100644
index 0000000000..66a7972a7d
--- /dev/null
+++ b/plugins/ruflo-mods/tests/describe.test.ts
@@ -0,0 +1,74 @@
+import { describe, expect, test, tier } from 'claude-code/testing'
+
+import { HINTS, MARK, MAX_HINT_CHARS } from '../hooks/describe/hints'
+import { consumer, run } from './fixtures/consumer'
+import { START, world } from './fixtures/world'
+
+tier('user')
+
+const ENGINE = { plugin: 'engine', tier: 'core' } as never
+const ask = (tool: string, description = 'Core description.') => ({ tool, description, provider: ENGINE })
+const SEARCH = 'mcp__plugin_ruflo-core_ruflo__memory_search'
+
+describe('tool.describe hints (ADR-451)', () => {
+ test('off by default: a ruflo tool keeps the description the engine computed', { plugins: [consumer] }, async ($, on) => {
+ world(on)
+ on('tool.describe', ($, e) => ({ description: e.description }))
+ on('command.run', () => ({ text: 'core' }))
+ await $.session.start(START)
+
+ expect((await $.tool.describe(ask(SEARCH))).description).toBe('Core description.')
+ expect((await $.command.run(run('ruflo-mods'))).text).toContain('tool hints: off')
+ })
+
+ test('on: a ruflo tool gets its one hint once, with placement and the core text kept', { options: { toolHints: true } }, async ($, on) => {
+ const w = world(on)
+ on('tool.describe', ($, e) => ({ description: e.description, isDeferred: true }))
+ on('command.run', () => ({ text: 'core' }))
+ await $.session.start(START)
+
+ const first = await $.tool.describe(ask(SEARCH))
+ expect(first.description).toBe(`Core description.${MARK}${HINTS.memory_search}`)
+ expect(first.isDeferred).toBe(true)
+ // asked again (a reload, an invalidate): the same text, never a doubled hint
+ expect((await $.tool.describe(ask(SEARCH, first.description))).description).toBe(first.description)
+ expect(w.logs.join('\n')).not.toMatch(/tool.describe/)
+ })
+
+ test('only ruflo servers and only tools in the table: everything else is byte-identical', { options: { toolHints: true } }, async ($, on) => {
+ world(on)
+ on('tool.describe', ($, e) => ({ description: e.description }))
+ await $.session.start(START)
+
+ for (const tool of [
+ 'mcp__evil__memory_search', // another server with a ruflo tool's name
+ 'mcp__plugin_ruflo-core_ruflo__memory_delete', // a ruflo tool with no hint
+ 'mcp__plugin_ruflo-core_ruflo__constructor', // an Object prototype name is not a hint
+ 'mcp__ruflo__memory_search_unified',
+ 'memory_search',
+ 'Bash',
+ ]) {
+ expect((await $.tool.describe(ask(tool))).description).toBe('Core description.')
+ }
+ for (const tool of ['mcp__claude-flow__swarm_init', 'mcp__ruflo__hooks_route']) {
+ expect((await $.tool.describe(ask(tool))).description).toContain(MARK)
+ }
+ })
+
+ test('/ruflo-mods counts the tools described', { options: { toolHints: true }, plugins: [consumer] }, async ($, on) => {
+ world(on)
+ on('tool.describe', ($, e) => ({ description: e.description }))
+ on('command.run', () => ({ text: 'core' }))
+ await $.session.start(START)
+ await $.tool.describe(ask(SEARCH))
+ await $.tool.describe(ask('mcp__ruflo__swarm_init'))
+ expect((await $.command.run(run('ruflo-mods'))).text).toContain('tool hints: 2 tool(s) described')
+ })
+
+ test('every hint is short, plain ASCII and one line', () => {
+ for (const [name, hint] of Object.entries(HINTS)) {
+ expect(hint.length, name).toBeLessThanOrEqual(MAX_HINT_CHARS)
+ expect(hint, name).toMatch(/^[\x20-\x7e]+$/)
+ }
+ })
+})
diff --git a/v3/docs/adr/ADR-451-mod-capability-roadmap.md b/v3/docs/adr/ADR-451-mod-capability-roadmap.md
new file mode 100644
index 0000000000..717460af34
--- /dev/null
+++ b/v3/docs/adr/ADR-451-mod-capability-roadmap.md
@@ -0,0 +1,269 @@
+# ADR 451: Mod capability roadmap: what the Claude Code mod API can do that ruflo does not use yet
+
+Status: Proposed
+
+Date: 2026-10-04
+
+Builds on: ADR-404 (ruflo as a mod), ADR-445 (AgentDB as a mod), ADR-446 (the plugin fleet as mods), ADR-447 (guidance observation loop)
+
+Evidence: `v3/docs/validation/mod-api-coverage-2026-10.md` (the full coverage table)
+
+## 1. Context
+
+ruflo ships 44 plugins with function-hook modules. The coverage table shows they use 18 of the 43
+engine events and none of the 33 `classic.*` events. The unused events are not random: they are
+the ones that change **what the model sees and spends** (`tool.describe`, `agent.offer`,
+`turn.step`, `session.compact`, `prompt.attachment`) and the ones that **screen what reaches the
+session** (`session.receive`, `session.send`, `session.append`). Of the `$` nouns, `model`,
+`agent.register/spawn` and `state` are unused, and `$.store` (kept between sessions) holds only view
+state. Today ruflo's mod guard covers tool permission and subagent spawns, and nothing else.
+
+Build under test: Claude Code 2.1.287. Where this ADR says "the d.ts", it means that build's
+`types/claude-code.d.ts`. Nothing here was checked against 2.1.277-2.1.286 declarations.
+
+## 2. Decision
+
+Adopt the roadmap in section 3 as the ordered backlog for the mod system. Every item is a new
+**option, default off**, behind the existing `userConfig` pattern, tighten-only where it touches a
+verdict, with a measurable acceptance test. Item 1 is prototyped in this change; the rest are not
+started.
+
+Ranking rule: expected value to a ruflo session, divided by the risk of changing the model's
+behaviour or the spend, with implementation cost as a tie-break. Impact figures are estimates unless
+marked measured; none of items 2-10 has been measured.
+
+## 3. Top 10, ranked
+
+### 1. `tool.describe` hints on ruflo's own MCP tools (PROTOTYPED, default off)
+
+- **Design.** `ruflo-mods` option `toolHints`. For tool names `mcp__(plugin_ruflo-core_ruflo|claude-flow|ruflo)__<name>`
+ where `<name>` is in a six-entry table, append `\n\nruflo: <one line>` to the description the
+ engine computed (`{ ...await next(e), description }`, so `isDeferred` is kept). Each line restates
+ what the project's CLAUDE.md already says (for example: `memory_search` searches AgentDB only,
+ `memory_search_unified` also covers Claude memories and patterns).
+- **Guard-rails.** Off by default. Static text only: the d.ts says a `tool.describe` answer is cached
+ for the session and "an unstable answer spends the model's prompt cache". Lines are at most 160
+ plain-ASCII characters (tested). Idempotent (a marked description is not marked twice). Other
+ servers, tools outside the table, and names like `constructor` are returned byte-identical
+ (tested). Appends text only; it cannot authorise or deny anything. Rollout flag: if the hooks module
+ is held off, nothing changes.
+- **Impact.** Unmeasured. The hint reaching the model is measured (validation doc section 7).
+- **Acceptance test.** A/B over 20 fixed prompts (10 where `memory_search_unified` is right, 10
+ where `memory_search` is), haiku and sonnet, option on versus off, `claude -p --output-format json`
+ with the real ruflo MCP server connected: the share of first-choice tools that match the label is
+ at least 15 points higher with hints on, and total input tokens rise by at most 1 percent. If not,
+ delete the table.
+- **Not done here.** The plugin version is not bumped and `ruflo-console`'s settings view does not
+ list the new option yet (it lists mod options in `hooks/settings.ts`). Both belong to the
+ integration owner.
+
+### 2. `agent.offer`: trim the agent listing to the types a project uses
+
+- **Design.** Hook `agent.offer`; return `{ isOffered: false }` for agent types outside an
+ allow-list built from `$.store` usage counts plus a pinned core set (`coder`, `reviewer`, `tester`,
+ `planner`, `researcher`, anything the user names). The engine offers every type "in the agent
+ listing and again at dispatch" (d.ts), so a hidden type is also refused at dispatch.
+- **Why it matters.** This session's Agent tool lists about 100 agent types; each costs tokens on
+ every request that carries the listing. The size in tokens is UNMEASURED.
+- **Guard-rails.** Option `agentTrim` default off, shows a one-time toast naming the count hidden,
+ `/ruflo-mods agents` lists and restores them, never hides a type used in the last 30 days or one the
+ prompt names. Fail open: any error offers the type.
+- **Acceptance test.** `claude -p --output-format json "reply ok"` input tokens, option on versus off,
+ in this repo: at least 3,000 fewer input tokens; zero failed `Agent` dispatches over a 20-task replay.
+
+### 3. `session.receive` and `session.send` screens for federation and peer messages
+
+- **Design.** `session.receive` fires "when a delivery reaches the session (a relay's event, a peer's
+ message, a Remote Control prompt), before it is queued" and accepts `{ consumed: reason }`. Run the
+ existing in-process pattern screen (`guidance/screen.ts` style, no model call) and, for a hit,
+ consume the delivery and toast the reason. `session.send` gets the same screen for outbound text
+ (secrets, PII) before it leaves for another agent.
+- **Guard-rails.** Tighten-only (consume or pass; never rewrite into trusted text). Option
+ `deliveryScreen`, default off; the matched rule id is shown, never the matched text. No network, no
+ model.
+- **Acceptance test.** A fixture corpus of 50 injection strings and 50 benign peer messages: at least
+ 90 percent of the first consumed, at most 2 percent of the second, and a consumed delivery never
+ reaches `session.append`.
+
+### 4. Call-time capability governor via op events (feasibility UNVERIFIED)
+
+- **Design.** The trust gate (ADR-404) judges a module at load. Op events (`model.complete`,
+ `http.fetch`, `process.run`) are hookable; if a user-tier hook sees other plugins' calls, a
+ governor can count and cap them per plugin (calls and dollars), turning "can do" into "did".
+- **Guard-rails.** Observe first (count and report in `/ruflo-mods`), enforce only behind
+ `modTrust: refuse-risky`, deny with a reason, never allow.
+- **Blocking unknown.** Whether another plugin's op calls pass through ruflo-mods' hooks is not
+ established (coverage doc 3b). First step is a two-plugin test, 1 hour, no product code.
+- **Acceptance test.** Plugin A calls `$.http.fetch` three times; the governor, with a cap of two,
+ denies the third and reports `A: 3 calls, 1 denied`.
+
+### 5. Capability probe and churn watchdog
+
+- **Design.** At `session.start` record `$.session.version()` (UNUSED today), the events the module
+ registered, and, per event, whether it fired this session, into the existing heartbeat file. `ruflo
+ mods doctor` flags "registered but never fired" and a version that changed since the last session.
+- **Guard-rails.** Read and write only the existing `.claude-flow/mods/session.json`; no new
+ permission. Always on is acceptable here because it spends nothing, but ship it as an option first.
+- **Acceptance test.** With the rollout switch off (or a build that does not load modules) doctor
+ reports `module not loaded` within one command; with it on, every registered event that fired shows
+ a count.
+
+### 6. `$.store` cross-session ledger plus a `session.end` rollup
+
+- **Design.** At `session.end` (budget from `next.budget`) append one record: routed prompts, edits,
+ tightened calls, final cost, route accuracy signals ADR-447 already collects. Keep a 200-entry ring
+ in `$.store` (4 MiB cap per the d.ts, so about 1 KiB per record is far under it). `/ruflo mods`
+ shows the trend; ruflo-intelligence can read it.
+- **Guard-rails.** Counters only, no prompt text (so nothing to screen); fail silent; honours the
+ 1.5 s SessionEnd budget the Claude Code hooks page documents (https://code.claude.com/docs/en/hooks).
+- **Acceptance test.** Three scripted sessions leave three records; kill -9 during the third leaves the
+ first two intact.
+
+### 7. `session.compact`: carry swarm and claims state through compaction
+
+- **Design.** Append (never replace) a short `instructions` block naming the live swarm id, topology,
+ open claims and last route, so the summary keeps them. Skip nothing.
+- **Guard-rails.** Append-only, 600 characters, option `compactKeep` default off; if the block would
+ exceed the cap, send nothing.
+- **Acceptance test.** Seed a canary swarm id, force `/compact`, ask for it: present with the option
+ on, absent (control) with it off.
+
+### 8. `turn.step` downshift at the budget rungs
+
+- **Design.** An async-generator hook; when the ladder (`ruflo-mods` cost) is at WARNING or higher,
+ `next({ ...e, effort: 'low' })`; at CRITICAL also a cheaper `model`. Never upshift.
+- **Guard-rails.** Option `costDownshift` default off; one toast per rung; the d.ts notes a streaming
+ hook's budget counts its own code only, and that a model change spends the prompt cache, so downshift
+ once per rung, not per step.
+- **Acceptance test.** A replay that crosses 75 percent shows the next request at the lower effort and
+ total cost for the remaining turns at least 20 percent lower than control; no step is ever raised.
+
+### 9. `$.model.classify` as a spend-gated route fallback
+
+- **Design.** When the lexical router's confidence is under 0.5, ask `$.model.classify(text, labels)`
+ (default: the engine's small fast model) to pick among the route labels.
+- **Guard-rails.** Option `classifyFallback` default off; at most N calls per session (default 20);
+ skipped at WARNING or higher; `classify` rejects on a failed request, so wrap and fall back to the
+ lexical route; prompt text is data only. It spends on the person's own session client.
+- **Acceptance test.** On a labelled set of 100 prompts, route accuracy rises by at least 10 points
+ with the fallback and the added cost is at most $0.02 per 100 prompts.
+
+### 10. `$.agent.register` swarm lanes and hash-pinned mod trust
+
+- **Design.** Two small items, ranked last because each needs a feasibility answer first.
+ (a) Register `ruflo:<role>` agent types from an `AgentSpec` with least-privilege `tools` and a
+ model tier per ADR-026, in place of 100 markdown agents. (b) Pin the trust gate to a hash of each
+ mod's source so a changed module is re-reviewed, as Codex does for hooks (section 5). The mod
+ environment has no Node, so hashing needs a host command (`$.process.run`), which the trust gate
+ itself flags; feasibility UNVERIFIED.
+- **Acceptance test.** (a) a spawn of `ruflo:coder` has no `Bash` when the spec omits it; (b) editing a
+ trusted mod changes its status to `needs review` at next load.
+
+## 4. Risks of API churn and the compatibility strategy
+
+Facts, with where they come from:
+
+| Fact | Source |
+|---|---|
+| 2.1.287 loads mods by default; 2.1.282 only with `CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1` | ADR-404 |
+| A server-side switch `tengu_plugin_hooks_modules`, cached in `~/.claude.json`, can hold modules off whatever the variable says; it "flipped between on and off several times in one afternoon, and between two accounts on this machine" | ADR-404 |
+| 2.1.277-2.1.286 stay off without the variable | plugins/ruflo-mods/README.md |
+| 2.1.283 ignores the testing kit's per-test `options`; a disposable copy that enables the feature at registration is the workaround | `plugins/ruflo-mods/scripts/native-guidance-smoke.sh` header |
+| A stale `claude` earlier on PATH (2.1.107 beside 2.1.287) decides which build runs | ADR-404 |
+| Managed or Team/Enterprise orgs seat `sec-default` outermost; it continues past the user tier on `prompt.context`, `prompt.section`, `prompt.compose`, `settings.read`, `classic.*` | ADR-404 |
+| The API is "early access and moves between releases: the declaration file is the authority" | bundled `reference.md` |
+
+Strategy:
+
+1. **Everything new is an option, default off, and removable.** The classic hook path stays the
+ default (ADR-404); a mod that is not loaded costs nothing and breaks nothing.
+2. **No feature depends on an event in `sec-default`'s pass-through list.** `tool.describe`,
+ `agent.offer`, `session.receive`, `session.compact` and `turn.step` are not on it, but whether a
+ managed org can still hold them off is UNVERIFIED; the doctor (item 5) is how a person finds out.
+3. **Probe, do not assume.** Item 5 records the engine version and which events fired. The d.ts is
+ regenerated by each build when `plugin-authoring` loads: add a CI job that extracts the event
+ and op names from it and diffs them against a checked-in manifest of the names ruflo hooks, so a
+ removed or renamed event fails a build before it fails a user.
+4. **Test against more than one build.** `claude plugin test` on the pinned build and on latest; for
+ behaviour that depends on options, use the disposable-copy approach (because of the 2.1.283
+ behaviour above). Run `echo hi | claude -p "say ok" --model haiku` once in a scratch dir first if
+ the test says the rollout switch is off.
+5. **Fail open.** A hook that fails is skipped and the chain continues (the bundled reference says so),
+ and `register` must not throw: new registrations sit behind `if (opts.<flag>)` as in this change.
+6. **Not verified here:** whether `on('<unknown event>')` throws on an older build. Item 5's CI diff
+ makes it moot; until then keep new events behind their flag.
+
+## 5. What comparable systems do better (with sources)
+
+Sources were fetched by a research pass on 2026-10-04; "summary-grade" means the page was read
+through a summarising fetch, not line by line.
+
+- **Typed, declarative hook decisions and per-handler budgets: Claude Code's own hooks.** Five
+ handler types (command, http, mcp_tool, prompt, agent), typed outputs (`permissionDecision` allow,
+ deny, ask, defer; `updatedInput`; `additionalContext`), a declarative `if` filter in permission-rule
+ syntax, per-type timeouts, fail-closed only for a PreToolUse timeout, a 1.5 s shared SessionEnd
+ budget. https://code.claude.com/docs/en/hooks (summary-grade). Lesson for ruflo: declare each
+ feature's failure mode and time budget explicitly (this ADR's guard-rails do).
+- **Hash-pinned trust and a review surface: OpenAI Codex hooks.** Non-managed hooks need explicit
+ trust recorded against the hook's content hash, so a changed hook is skipped until re-trusted;
+ `/hooks` lets a person inspect and disable; SessionEnd gets about 1 second.
+ https://learn.chatgpt.com/docs/hooks (summary-grade). Lesson: roadmap item 10(b).
+- **Model-level events: Gemini CLI hooks.** BeforeModel, AfterModel and BeforeToolSelection (filter
+ the tools offered), AfterAgent can force a retry. https://geminicli.com/docs/hooks/ (summary-grade).
+ ruflo already has the equivalents in the mod API (`turn.step`, `tool.describe`, `agent.offer`) and
+ does not use them: that is the gap this roadmap closes.
+- **In-process plugins that register tools: opencode.** TS/JS plugins with `tool.execute.before/after`
+ and a `tool()` helper that registers custom tools. https://opencode.ai/docs/plugins/ (summary-grade).
+ The mod API has `$.tool.register`; only ruflo-console uses it.
+- **Declared capabilities plus consent: VS Code.** `capabilities.untrustedWorkspaces` as `true`,
+ `false` or `'limited'` with a mandatory reason; no declaration defaults to disabled.
+ https://code.visualstudio.com/api/extension-guides/workspace-trust (summary-grade). Claude Code's
+ plugin manifest has typed `userConfig` and `sensitive` values but, in the page read, no capability
+ declaration (https://code.claude.com/docs/en/plugins-reference): ruflo's trust gate fills that gap
+ by reading the module source; item 4 extends it to call time.
+- **Guards that run beside the model: OpenAI Agents SDK guardrails.** Input guardrails run in
+ parallel with the agent by default, or blocking first to prevent spend and side effects; a tripwire
+ halts the run. https://openai.github.io/openai-agents-python/guardrails/ (summary-grade). Lesson:
+ each ruflo guard should state parallel versus blocking; `session.receive` screens (item 3) are
+ blocking by construction.
+- **Tool metadata and tool-list caching: MCP.** Tools carry `title`, `outputSchema`,
+ `structuredContent`, annotations (clients must treat them as untrusted unless the server is), a
+ `listChanged` notification and `ttlMs` caching with deterministic ordering "to protect prompt-cache
+ hits". https://modelcontextprotocol.io/specification/latest/server/tools (summary-grade). Supports
+ item 1's static-text rule.
+- **Elicitation: MCP.** A tool can ask the person through a form or URL mode, with accept, decline,
+ cancel. https://modelcontextprotocol.io/specification/latest/client/elicitation (summary-grade).
+ Hooks have no equivalent of a server asking the host; `$.ui.ask` is the nearest mod call.
+- **Capability negotiation: LSP.** `initialize` exchanges client and server capabilities.
+ https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
+ (cited by the research pass, not independently opened by me). Lesson: item 5.
+- **Tracing: OpenTelemetry GenAI conventions.** `invoke_agent` and `execute_tool` spans.
+ https://github.com/open-telemetry/semantic-conventions-genai . I saw no stability label, so whether
+ they are stable is UNVERIFIED; not on the roadmap for that reason.
+
+Thin or missing, said plainly: Cursor, Cline, Roo, Pi (pi-mono) and LangGraph middleware were not
+researched. Chrome MV3 permissions were not fetched (UNVERIFIED). MCP sampling, roots and tasks, and the
+Claude Code skills, subagents and changelog pages were not opened. Every source above is summary-grade,
+a fetch that returned a model summary rather than raw text. The Claude Code docs also carry a mods
+reference (`/docs/en/plugins/mods/reference`, named on the plugins-reference page); it was not read.
+
+## 6. The prototype in this change
+
+Files (all under `plugins/ruflo-mods/`): `hooks/describe/hints.ts` (table, matcher, `withHint`),
+`hooks/describe/index.ts` (the hook), `hooks/register.ts` (registers it only when the option is on),
+`hooks/options.ts`, `hooks/state.ts` (a `/ruflo-mods` line: `tool hints: off` or `N tool(s)
+described`), `.claude-plugin/plugin.json` (option `toolHints`, default false), `scripts/smoke.sh` (the
+documented-events list gains `tool.describe`), `tests/describe.test.ts` (5 tests).
+
+Verified: `claude plugin test` 33 pass, 0 fail (28 before, 5 new); `claude plugin validate` passes and
+lists `tool.describe{tool=/^mcp__(?:plugin_ruflo-core_ruflo|claude-flow|ruflo)__/}`; `scripts/smoke.sh`
+11 of 11; one live `claude -p` check, validation doc section 7.
+
+## 7. Consequences
+
+- Positive: a measured path to change what the model sees at ruflo's tools, at near-zero spend, with
+ a stop rule (delete the table if the A/B fails).
+- Cost: another option (a ninth) on `ruflo-mods`; a table of hints that can go stale when a tool is
+ renamed, like the string-matched guards ADR-446 notes. Mitigation: item 5's doctor, and a test that
+ every hint key exists in the CLI's tool registry (not written).
+- This ADR changes no default and enables nothing.
diff --git a/v3/docs/validation/mod-api-coverage-2026-10.md b/v3/docs/validation/mod-api-coverage-2026-10.md
new file mode 100644
index 0000000000..bea6e7c32e
--- /dev/null
+++ b/v3/docs/validation/mod-api-coverage-2026-10.md
@@ -0,0 +1,179 @@
+# Mod API coverage: what ruflo uses and what it does not (2026-10)
+
+Date: 2026-10-04
+Supports: ADR-451 (mod capability roadmap)
+Build measured: Claude Code **2.1.287** (`claude --version`), the only declaration file on this machine.
+
+## 1. Method, and what this does not show
+
+- **API surface** is read from `types/claude-code.d.ts` (20,116 lines) in the newest bundled
+ `plugin-authoring` skill folder (`bundled-skills/2.1.287/…/plugin-authoring/types/claude-code.d.ts`):
+ `EngineEventOf` (43 engine events, line 3715), `ClassicHookEvent` (33 classic events), `OpEventOf`
+ (line 6382) and `CoreEngineInterface` (the `$` nouns, line 2131).
+- **Usage** is what `claude plugin validate <plugin>` prints under `hooks:` and `calls:` for each of
+ the 44 ruflo plugins whose `hooks/hooks.json` names a module (the engine's own read of the source,
+ including calls reached through a helper, `(via hostOf)`), cross-checked with a literal grep for
+ `on('<event>'` and `$.<noun>.<method>` under `plugins/*/hooks`.
+- **Not shown:** whether an event fires in a given process (the rollout switch can hold modules off,
+ see ADR-451 section 4); behaviour differences between builds. Only the 2.1.287 declarations were
+ available, so **no event list for 2.1.277-2.1.286 was diffed** and none is claimed.
+- Event semantics come from the doc comment of each event in the d.ts. Rows marked "(name only)"
+ were not read beyond their name and signature.
+
+Reproduce (needs a `claude` on PATH, no network): `for d in $(grep -l modules plugins/*/hooks/hooks.json | xargs -n1 dirname | xargs -n1 dirname); do claude plugin validate "$d" | grep -E 'hooks: |calls: '; done`
+
+## 2. Summary
+
+| | In the d.ts | Hooked / called by a ruflo mod | UNUSED |
+|---|---|---|---|
+| Engine events | 43 | 18 (17, plus `tool.describe` from this change) | 25 |
+| Classic events (`classic.<Event>`) | 33 | 0 | 33 |
+| `$` nouns | 21 | 15 | 6 (`model`, `audio`, `state`, `telemetry`, `config`, `turn`) |
+| Op events (every `$` method is also hookable) | about 60 | 1 in production (`ui.close`: console, swarm) | the rest, section 3b |
+
+Fleet shape: the 39 generated mods (ADR-446) hook only `session.start`, `tool.call`, `command.run`.
+`ruflo-mods`, `ruflo-console` and `ruflo-swarm` hook the rest.
+
+## 3. Engine events (43)
+
+Used-by key: **mods** = ruflo-mods, **console** = ruflo-console, **swarm** = ruflo-swarm,
+**ruos** = ruflo-ruos, **agentdb** = ruflo-agentdb, **fleet** = the 39 ADR-446 mods.
+
+| Event | What it is (d.ts) | Used by |
+|---|---|---|
+| `tool.call` | before a tool runs; deny or answer | mods (edit recording), console, agentdb, fleet (guards) |
+| `tool.check` | permission verdict; tighten-only in ruflo | mods (dangerous commands, policy, ADR-440 research guard), console |
+| `tool.describe` | the description the model reads, once per tool per session, cached; may also set `isDeferred` | **mods, this change (option `toolHints`, default off)** |
+| `ui.render` | every component the engine draws | console, swarm |
+| `ui.resolve` | the surface's element-constructor table | UNUSED as a hook (console, swarm call `$.ui.resolve`) |
+| `ui.press` / `ui.input` / `ui.scroll` | input to a plugin-drawn element | console |
+| `ui.select` | a Select element raised a choice | UNUSED |
+| `ui.focus` | focus moved to or from a plugin element | UNUSED as a hook (console calls `$.ui.focus`) |
+| `ui.message` | a `Client` the plugin drew posted data | UNUSED |
+| `agent.offer` | the engine offers an agent type to the model; `{ isOffered: false }` hides it | UNUSED |
+| `agent.spawn` | a subagent is about to start | mods (cost hard stop), swarm |
+| `prompt.submit` | the prompt as submitted; adds context | mods (routing), console, agentdb, ruos |
+| `prompt.fill` | text about to enter the prompt box | UNUSED as a hook (console, swarm call `$.prompt.fill`) |
+| `prompt.suggest` | the dim "Tab to take" suggestion | UNUSED |
+| `prompt.edit` | the person edits the prompt box | UNUSED |
+| `prompt.section` | one named system-prompt section, cached | UNUSED |
+| `prompt.context` | context blocks of the first user message, once per conversation | UNUSED |
+| `prompt.compose` | the whole system prompt as `{ sections }`; a `session`-scope section can be appended | console |
+| `prompt.attachment` | each engine-injected reminder (todo, mode, mentioned file); `{ text: null }` drops it | UNUSED |
+| `command.run` | a slash command ran | mods, console, swarm, agentdb, fleet (`/<x>-mod`) |
+| `command.describe` | description and hint of a command in typeahead and `/help` | UNUSED |
+| `config.set` / `config.describe` | `/config` rows (`set`: name only) | UNUSED |
+| `telemetry.log` / `telemetry.mark` | a record about to be logged / a feature use marked; destination pinned | UNUSED |
+| `skill.prompt` | the expanded prompt of a skill | UNUSED |
+| `attribution.text` | commit or PR text the model is told to write | UNUSED |
+| `session.start` | once, session ready; awaited before the first prompt | mods, console, swarm, ruos, agentdb, fleet |
+| `session.receive` | a delivery (relay event, peer message, Remote Control prompt) reached the session; `{ consumed }` drops it | UNUSED |
+| `session.append` | every row a conversation keeps, before it is stored; can rewrite content | UNUSED |
+| `session.send` | a message leaves for another agent or session | UNUSED |
+| `session.compact` | a compaction is about to run; rewrite `instructions` or `messages`, or `{ skip }` | UNUSED |
+| `session.attach` / `session.detach` | a remote client joined / left (`detach`: name only) | UNUSED |
+| `session.measure` | after each main-thread turn: context, rate limits, cost | mods (budget ladder) |
+| `session.end` | once; shared short wall-clock bound, `next.budget` | mods (flush), console |
+| `plugin.register` | a plugin module is admitted | mods (trust gate), console |
+| `turn.start` | a model turn begins (observe only) | console, swarm |
+| `turn.step` | before each model request of a turn, main or subagent; an async generator; can send another `model` or `effort`, or answer without a request | UNUSED |
+| `turn.complete` | a turn ended; may add text beneath the answer | mods (flush), console, swarm |
+| `engine.create` | when `$` is built; a plugin can add a noun | mods (`$.ruflo`) |
+
+`ruflo-swarm` also hooks `*` (every event), which is how it feeds its live feed.
+
+### 3b. Op events
+
+`OpEventOf` types the argument of each `$` method as an event of the same name (`model.complete`,
+`model.classify`, `model.fork`, `audio.play`, `mcp.call`, `session.root`, `ui.toast`, `ui.close`,
+`fs.write`, `store.set`, `clock.now`, `http.fetch`, `process.run`, `settings.read`, and so on). A hook
+on one answers the call, as the test world in `plugins/ruflo-mods/tests/fixtures/world.ts` does with
+`on('fs.read', ...)` returning `{ value }` or `{ deny }`. In production only `ui.close` is hooked
+(console, swarm). Whether a user-tier hook on `model.complete` sees *other plugins'* calls, and in
+what order, is **UNVERIFIED**: the d.ts says the plugin chain nests in registration order (ADR-404
+relies on that for `plugin.register`), not that every op is exposed to every plugin.
+
+## 4. Classic events (`classic.<Event>`, 33), all UNUSED
+
+`ConfigChange CwdChanged DirectoryAdded Elicitation ElicitationResult FileChanged InstructionsLoaded
+MessageDisplay Notification PermissionDenied PermissionRequest PostCompact PostModelSwitch
+PostToolBatch PostToolUse PostToolUseFailure PreCompact PreModelSwitch PreToolUse SessionEnd
+SessionStart Setup Stop StopFailure SubagentStart SubagentStop TaskCompleted TaskCreated
+TeammateIdle UserPromptExpansion UserPromptSubmit WorktreeCreate WorktreeRemove`
+
+Each is hookable as a function and receives what the settings hook would get on stdin. ruflo's classic
+path is `hook-handler.cjs` (ADR-404): the mod owns `route` and `post-edit` through a handshake and
+leaves every other classic event to the helper. Candidates for a native twin: `PreCompact` and
+`PostCompact`, `TeammateIdle` and `TaskCompleted` (the agent-teams hooks in the project guidance),
+`StopFailure`. Not evaluated further.
+
+## 5. `$` nouns and methods
+
+| Noun.method | Used by | Note |
+|---|---|---|
+| `$.plugin` | validator only | name, dir |
+| `$.ui.toast / status / log / open / close / panes / invalidate / blit / focus / scroll / ask / resolve` | mods (`status`, `log`, `toast`), console (all), swarm (`toast`, `log`, `open`, `close`, `invalidate`, `resolve`) | |
+| `$.ui.notice`, `$.ui.copy` | UNUSED | a notice row; clipboard |
+| `$.model.complete` | **UNUSED** | one tool-less completion on the session's own client; a result, never a rejection unless the request is refused |
+| `$.model.classify` | **UNUSED** | picks one of N labels on the engine's small fast model; resolves `undefined` if none named |
+| `$.model.fork` | **UNUSED** | tool-less completion over the session's own transcript; the prefix comes from the prompt cache |
+| `$.audio.play / speak` | UNUSED | no player on a Linux terminal |
+| `$.mcp.call` | agentdb, goals, graph-intelligence, intelligence, iot-cognitum | |
+| `$.mcp.connect` | UNUSED | |
+| `$.session.root` | mods, agentdb, fleet | async |
+| `$.session.usage` | console, swarm | the figures `session.measure` pushes |
+| `$.session.cwd / model / turns / id / messages / repo / surface / surfaces / version` | UNUSED | `version()` answers the engine's `base` and `builtAt` |
+| `$.session.authorize` | UNUSED | an opaque credential handle, spent only on first-party hosts |
+| `$.session.append / send` | UNUSED | real appends of meta rows or notices; messages to agents |
+| `$.turn.abort` | UNUSED | |
+| `$.prompt.submit / fill` | console (both), swarm (`fill`) | |
+| `$.prompt.suggest / read` | UNUSED | |
+| `$.tool.list` | console, agentdb, 23 fleet mods | |
+| `$.tool.register` | console | model-callable tools, listed `mcp__<plugin>__<name>` |
+| `$.tool.call / check` | UNUSED as host calls | |
+| `$.command.register / list / run` | register: mods, console, swarm, agentdb, fleet; list, run: console | a plugin's markdown command cannot be re-registered |
+| `$.config.list` | UNUSED | |
+| `$.telemetry.log / mark` | UNUSED | |
+| `$.agent.list` | swarm | |
+| `$.agent.register / spawn` | **UNUSED** | `<plugin>:<name>` agent types from an `AgentSpec`; `spawn` answers with its `turn.complete` |
+| `$.fs.read / write / list / exists / stat` | mods, console, swarm, agentdb, fleet | |
+| `$.fs.ancestors` | UNUSED | walks `.md` files up a tree (AGENTS.md style) |
+| `$.store.get / set` | console, swarm | per-plugin JSON file in the user config dir, **kept between sessions and hot reloads**, 4 MiB cap, JSON values only |
+| `$.store.delete / keys` | UNUSED | |
+| `$.state.get / set` | **UNUSED** | host-held named values with versions, for drawings; `plugin` and `key` must be literals |
+| `$.clock.now / every / after / sleep` | now: nearly all; every: console, ruos, swarm; after: console, swarm; sleep: agentdb | `now` is async |
+| `$.http.fetch` | console | |
+| `$.process.run / spawn` | console, swarm | host commands; the trust gate watches these |
+| `$.settings.read` | mods, console | |
+| `$.env.get / set` | mods (`set` writes only `RUFLO_MODS_OWNS`) | |
+
+## 6. What this table implies
+
+1. `tool.describe`, `agent.offer` and `turn.step`, and the `$` nouns `model`, `agent.register/spawn`
+ and `state`, are all UNUSED. They are where a mod changes what the model *sees and spends* rather
+ than what the person sees.
+2. `$.store` is used only by the two UI mods, for view state. Nothing cross-session about ruflo's own
+ learning (route outcomes, cost, edits) is kept natively; the classic helper's files are the only
+ record.
+3. Seven events a mod can use to *protect* a session (`session.receive`, `session.send`,
+ `session.append`, `session.compact`, `prompt.attachment`, `agent.offer`, `turn.step`) are
+ unhooked, so ruflo's guard covers tool permission (`tool.check`) and subagent spawns
+ (`agent.spawn`, at the cost hard stop) and nothing else.
+4. Op events are a second, unused surface (section 3b): if a hook on `model.complete`, `http.fetch`
+ or `process.run` does see other plugins' calls, the load-time trust gate could become a call-time
+ one. That depends on the UNVERIFIED point above.
+
+## 7. Evidence for the prototype in this change
+
+`plugins/ruflo-mods` option `toolHints` (default `false`) hooks `tool.describe` for ruflo MCP tool
+names only. Live, with a throwaway stdio MCP server named `ruflo` (private scratch dir, haiku,
+`claude -p` 2.1.287, `--strict-mcp-config`, `--plugin-dir plugins/ruflo-mods`,
+`CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1`):
+
+- option on: the model quoted `mcp__ruflo__memory_search` as `Search memory.`, a blank line, then
+ `ruflo: Searches AgentDB only; memory_search_unified also covers Claude memories and patterns.`;
+ `mcp__ruflo__memory_delete` (no hint in the table) as `Delete memory.`;
+- option off: both quoted exactly as the server sent them.
+
+Measured: the hint reaches the model's tool listing. **Not measured:** whether it changes which tool
+the model picks. That is the acceptance test of roadmap item 1 in ADR-451.