mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
feat(ruflo-mods): agentModels — a model per agent type for spawns that chose none (0.16.1) (#4703)
agent.spawn routing for Claude Code 2.1.300+: 'Explore=haiku,general-purpose=sonnet' sets the model of a spawn whose call chose none, covering built-in and other plugins' types (definitions a person cannot edit) and workflow agents. A chosen model, forks and teammates are kept; malformed pairs are dropped; a failing hook passes the spawn through. Off by default; /ruflo-mods reports it. Co-authored-by: r <r@x>
This commit is contained in:
1 parent
45bf52cd86
commit
27dd1f1ac8
9 files changed
+130
-4
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ruflo-mods",
|
||||
"description": "ruflo as a Claude Code mod (function hooks, ADR-404): in-process prompt routing, edit learning signals, tighten-only tool checks from ruflo policy, the cost-tracker budget ladder, a mod trust gate for newly installed mods, and the $.ruflo noun other mods compose their status with. Opt-in and removable: the classic hook-handler hooks stay the default and take every event back whenever the mod is not loaded.",
|
||||
"version": "0.16.0",
|
||||
"version": "0.16.1",
|
||||
"author": {
|
||||
"name": "ruvnet",
|
||||
"url": "https://github.com/ruvnet"
|
||||
@@ -75,6 +75,13 @@
|
||||
"required": false,
|
||||
"default": ""
|
||||
},
|
||||
"agentModels": {
|
||||
"type": "string",
|
||||
"title": "Model per agent type",
|
||||
"description": "Comma-separated type=model pairs, for example Explore=haiku,general-purpose=sonnet. When a subagent of that type is spawned with no model chosen, it runs on this one (haiku, sonnet, opus, inherit, or a full claude- model id). Covers built-in types and other plugins' agents, whose definitions you cannot edit, and workflow agents (Claude Code 2.1.300 or later). A model the call already chose is kept; forks and teammates are left alone. Empty (the default) is off.",
|
||||
"required": false,
|
||||
"default": ""
|
||||
},
|
||||
"deliveryScreen": {
|
||||
"type": "boolean",
|
||||
"title": "Screen peer deliveries and outgoing messages",
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
Newest first. One `## <version> — <date>` heading per version, then `feat:`, `fix:`, `breaking:` and `chore:` bullets (ADR-478). Built from git history; older versions: `git log -- plugins/ruflo-mods`.
|
||||
|
||||
## 0.16.1 — 2026-11-04
|
||||
- feat: `agentModels` option (`Explore=haiku,general-purpose=sonnet`). An `agent.spawn` with no model chosen runs on the model named for its type. This covers built-in and other plugins' agent types, whose definitions a person cannot edit, and workflow agents, whose model a hook may set since Claude Code 2.1.300. A model the call or another hook chose is kept, and forks and teammates are left alone. A malformed pair is dropped, and a failing hook passes the spawn through unchanged. `/ruflo-mods` shows how many types are mapped and how many spawns were given a model. Empty, the default, is off.
|
||||
|
||||
## 0.16.0 — 2026-11-04
|
||||
- feat: the `tool.check` guard reads Claude Code 2.1.290–2.1.304 fields. A call the host marks `isReadOnly` (not WebFetch or WebSearch, which the research guard asks on) skips the policy-projection stat when a full check found no projection less than 2 s before; a write call, or the window passing, looks again, so a projection written mid-session is seen. A chain that already denies is returned without any file read. The dangerous-command list still applies on every path.
|
||||
- feat: every ask ruflo raises (its check failing, an unreadable projection, a policy `require_approval`, the research first-fetch) carries `decider: "person"` (2.1.304), so only the permission dialog or a host callback can approve it, never a classifier. A subagent's check (`agentId`, 2.1.290) is named on ruflo's reason; the organization's `ceiling` rides on a verdict ruflo tightened instead of being dropped.
|
||||
|
||||
@@ -125,6 +125,7 @@ Claude Code reads a plugin's options from `pluginConfigs["ruflo-mods@ruflo"].opt
|
||||
| `toolHints` | `false` | Add one short static hint, restating the project's own CLAUDE.md, to a few ruflo MCP tool descriptions. Live: hints appear on exactly the hinted tools, none when off. Evidence: [live validation](../../v3/docs/validation/ruflo-mods-live-2026-10.md) |
|
||||
| `agentTrim` | `false` | Keep agent types the project does not use out of the agent listing. Measured saving about 4,000 tokens per request (4,236 on a 69-type catalogue, one model); a hidden type the prompt does not name is refused at dispatch, one the prompt names can still be dispatched. Evidence: [trim measurement](../../v3/docs/validation/ruflo-mods-trim-measure-2026-10.md) |
|
||||
| `agentTrimKeep` | empty | Comma-separated agent type names `agentTrim` must keep offered. Evidence: [live validation](../../v3/docs/validation/ruflo-mods-live-2026-10.md) |
|
||||
| `agentModels` | empty | Comma-separated `type=model` pairs, e.g. `Explore=haiku,general-purpose=sonnet`. A subagent of that type spawned with no model chosen runs on it (`haiku`, `sonnet`, `opus`, `inherit` or a full `claude-` id). Covers built-in and other plugins' types and workflow agents (Claude Code 2.1.300+). A chosen model, forks and teammates are left alone. |
|
||||
| `deliveryScreen` | `false` | ADR-451 screen: drops peer, relay or webhook deliveries that carry injection phrasing and refuses outgoing messages that carry a secret shape; never screens your own Remote Control prompts; names the rule, never the text. Caught 76% of its own 50-injection test set before the rules were tuned on it (figure from the PR #3741 description, not a repo doc); the real-world rate is unknown. No live evidence doc yet; design in [ADR-451](../../v3/docs/adr/ADR-451-mod-capability-roadmap.md) item 3 |
|
||||
| `rureOffer` | `false` | `tool.call` + `turn.complete` (ADR-498): when the model reads or writes an executable, library, `.asar` or CUDA file in the project, adds one line beneath that answer saying ruRE can inspect it without running it, and how. Offer only: never runs ruRE, never denies or edits a call; at most 3 files a turn, 12 a session, each once; validated project-relative paths only; inert without a ruRE tool and on subagent answers. Design in [ADR-498](../../v3/docs/adr/ADR-498-mods-rure-offer.md) |
|
||||
| `learningLoop` | `true` | `prompt.submit` + `tool.call` + `turn.complete` (#4581, ADR-502): records each main-loop turn's tool calls and decides its outcome **only** from a recognised test, build, typecheck or lint command's exit status after the turn's last edit (`npm test`, `vitest`, `tsc`, `cargo test`, `pytest`, …; a masked status such as `npm test \|\| true` or a pipe verifies nothing); otherwise the turn is unverified. Turns go to `.claude-flow/data/verified-trajectories.jsonl` (500 lines); `ruflo hooks verified-ingest` (also run by `hooks_route` and `hooks_session-end`) trains SONA on verified turns only. Adds at most three cited lessons at or above the 0.6 routing gate to a prompt they match. A verified success carries taints when the turn edited a test file or a verifier config (`package.json`, `vitest.config.*`, `tsconfig*.json`, …) or narrowed its check (one test file, `-t`, `--passWithNoTests`, …); the CLI never trains a tainted turn unless `.claude-flow/config.json` `learningLoop.allowTaint` lists the class, can re-run a check at HEAD before training (`learningLoop.reverify`, off by default), and holds back lessons that look gamed ([ADR-503](../../v3/docs/adr/ADR-503-learning-loop-gaming-defences.md)). Never denies, rewrites or delays a call; runs no process; only in a ruflo project. Evidence: [learning loop live run](../../v3/docs/validation/ruflo-mods-learning-loop-2026-10.md); design in [ADR-502](../../v3/docs/adr/ADR-502-verified-outcome-learning-loop.md) |
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { On } from 'claude-code'
|
||||
|
||||
/**
|
||||
* `agentModels`: a per-project model for an agent type, applied in
|
||||
* `agent.spawn` when the call chose none. It covers types whose definition the
|
||||
* person cannot edit (the built-in `Explore` and `general-purpose`, another
|
||||
* plugin's agent) and workflow agents, whose model a hook may set since Claude
|
||||
* Code 2.1.300. It only fills a gap: a model the call or another hook set is
|
||||
* kept, and forks (which always inherit) and teammates are left alone.
|
||||
*/
|
||||
export type AgentModels = ReadonlyMap<string, string>
|
||||
|
||||
const TYPE = /^[A-Za-z0-9._:-]{1,64}$/
|
||||
const MODEL = /^(?:haiku|sonnet|opus|inherit|claude-[a-z0-9.-]{1,60})$/
|
||||
|
||||
/** `Explore=haiku, general-purpose=sonnet` (or an object of the same) → type (lower case) → model; a malformed pair is dropped. */
|
||||
export function readAgentModels(value: unknown): AgentModels {
|
||||
const pairs: [unknown, unknown][] =
|
||||
typeof value === 'string'
|
||||
? value.split(',').map(p => p.split('=').map(s => s.trim()) as [string, string])
|
||||
: value !== null && typeof value === 'object' && !Array.isArray(value)
|
||||
? Object.entries(value as Record<string, unknown>)
|
||||
: []
|
||||
const out = new Map<string, string>()
|
||||
for (const [type, model] of pairs) {
|
||||
if (typeof type !== 'string' || typeof model !== 'string' || !TYPE.test(type) || !MODEL.test(model)) continue
|
||||
out.set(type.toLowerCase(), model)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** The model this spawn should get, or undefined to leave it as it is. */
|
||||
export function modelFor(e: { subagentType?: unknown; model?: unknown; fork?: unknown; isTeammate?: unknown }, models: AgentModels): string | undefined {
|
||||
if (models.size === 0 || e.fork === true || e.isTeammate === true) return undefined
|
||||
if (typeof e.model === 'string' && e.model !== '') return undefined
|
||||
return typeof e.subagentType === 'string' ? models.get(e.subagentType.toLowerCase()) : undefined
|
||||
}
|
||||
|
||||
export function registerAgentModels(on: On, models: AgentModels, counter: { routed: number }) {
|
||||
// A matcher: the loader allows one bare on('agent.spawn') per plugin (cost/ has it). Every typed spawn matches; modelFor picks.
|
||||
on('agent.spawn', { subagentType: /^[\s\S]+$/ }, async ($, e, next) => {
|
||||
const model = modelFor(e, models)
|
||||
if (model === undefined) return next(e)
|
||||
counter.routed++
|
||||
return next({ ...e, model })
|
||||
}).catch(($, e, next) => next(e)) // a broken routing table never blocks a spawn
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type { PluginOptions } from 'claude-code'
|
||||
|
||||
import { budgetOf } from './cost/budget'
|
||||
import type { DelegationMode } from './context-delegate/plan'
|
||||
import { readAgentModels, type AgentModels } from './agents/models'
|
||||
import type { TrustPolicy } from './trust'
|
||||
|
||||
/** The plugin's `userConfig` options, validated: a bad value is the default. */
|
||||
@@ -16,6 +17,8 @@ export type ModOptions = {
|
||||
readonly toolHints: boolean
|
||||
readonly agentTrim: boolean
|
||||
readonly agentTrimKeep: ReadonlySet<string>
|
||||
/** Agent type → model for spawns that chose none (`agentModels`); empty is off. */
|
||||
readonly agentModels: AgentModels
|
||||
readonly deliveryScreen: boolean
|
||||
readonly compactCarry: boolean
|
||||
readonly compactSnapshot: boolean
|
||||
@@ -57,6 +60,7 @@ export function readOptions(options: PluginOptions | undefined): ModOptions {
|
||||
toolHints: bool(o.toolHints, false),
|
||||
agentTrim: bool(o.agentTrim, false),
|
||||
agentTrimKeep: keepNames(o.agentTrimKeep),
|
||||
agentModels: readAgentModels(o.agentModels),
|
||||
deliveryScreen: bool(o.deliveryScreen, false),
|
||||
compactCarry: bool(o.compactCarry, false),
|
||||
compactSnapshot: bool(o.compactSnapshot, true),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Register } from 'claude-code'
|
||||
|
||||
import { registerAgents } from './agents'
|
||||
import { registerAgentModels } from './agents/models'
|
||||
import { registerCompact } from './compact'
|
||||
import { registerCompactSnapshot } from './compact-snapshot'
|
||||
import { registerContextDelegate } from './context-delegate'
|
||||
@@ -50,6 +51,8 @@ export const register: Register = (on, options) => {
|
||||
registerCost(on, state, opts)
|
||||
if (opts.toolHints) registerDescribe(on, state)
|
||||
if (opts.agentTrim) registerAgents(on, state, opts)
|
||||
state.agentModels.types = opts.agentModels.size
|
||||
if (opts.agentModels.size > 0) registerAgentModels(on, opts.agentModels, state.agentModels)
|
||||
if (opts.deliveryScreen) registerDelivery(on, state)
|
||||
if (opts.compactCarry) registerCompact(on, state)
|
||||
if (opts.rureOffer) registerRureOffer(on, state)
|
||||
|
||||
@@ -40,6 +40,8 @@ export type ModState = {
|
||||
toolHints: { enabled: boolean; described: Set<string> }
|
||||
/** `agent.offer` trim (ADR-451): whether it is on, the types it hid, and the latest prompt (lower case). */
|
||||
agentTrim: { enabled: boolean; hidden: Set<string>; prompt: string; ledger?: Promise<Record<string, number>> }
|
||||
/** Spawns given a model by `agentModels`, and how many types it names (0: off). */
|
||||
agentModels: { routed: number; types: number }
|
||||
/** `session.receive`/`session.send` screen (ADR-451): whether it is on, deliveries consumed, sends refused. */
|
||||
delivery: { enabled: boolean; consumed: number; blocked: number }
|
||||
/** The ruRE offer (ADR-498): whether it is on, whether the session has a ruRE tool, files waiting for the turn's end, files already offered, and how many were. */
|
||||
@@ -84,6 +86,7 @@ export function createState(): ModState {
|
||||
budget: { level: 'OK' },
|
||||
toolHints: { enabled: false, described: new Set() },
|
||||
agentTrim: { enabled: false, hidden: new Set(), prompt: '' },
|
||||
agentModels: { routed: 0, types: 0 },
|
||||
delivery: { enabled: false, consumed: 0, blocked: 0 },
|
||||
compact: { enabled: false, carried: 0 },
|
||||
snapshot: snapshotState(),
|
||||
@@ -184,6 +187,7 @@ export function report(s: ModState): string {
|
||||
` budget: ${budget}`,
|
||||
` tool hints: ${s.toolHints.enabled ? `${s.toolHints.described.size} tool(s) described` : 'off (set the toolHints option)'}`,
|
||||
` agent trim: ${s.agentTrim.enabled ? `${s.agentTrim.hidden.size} type(s) hidden` : 'off (set the agentTrim option)'}`,
|
||||
` agent models: ${s.agentModels.types > 0 ? `${s.agentModels.types} type(s), ${s.agentModels.routed} spawn(s) given a model` : 'off (set the agentModels option)'}`,
|
||||
` delivery: ${s.delivery.enabled ? `${s.delivery.consumed} dropped, ${s.delivery.blocked} refused` : 'off (set the deliveryScreen option)'}`,
|
||||
` compact: ${s.compact.enabled ? `${s.compact.carried} compaction(s) carried a block` : 'off (set the compactCarry option)'}`,
|
||||
` snapshot: ${snapshotLine(s.snapshot)}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Structural + security smoke for ruflo-mods v0.16.0 (ADR-404, ADR-447).
|
||||
# Structural + security smoke for ruflo-mods v0.16.1 (ADR-404, ADR-447).
|
||||
# Static only: CI has no Claude Code, so the hooks module's behaviour is held
|
||||
# by v3/@claude-flow/cli/__tests__/mods/*.test.ts and, where function hooks are
|
||||
# on, by `claude plugin test plugins/ruflo-mods`.
|
||||
@@ -12,9 +12,9 @@ ok() { printf "PASS\n"; PASS=$((PASS+1)); }
|
||||
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
|
||||
HOOKS="$ROOT/hooks"
|
||||
|
||||
step "1. plugin.json declares ruflo-mods 0.16.0"
|
||||
step "1. plugin.json declares ruflo-mods 0.16.1"
|
||||
grep -q '"name": "ruflo-mods"' "$ROOT/.claude-plugin/plugin.json" \
|
||||
&& grep -q '"version": "0.16.0"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
|
||||
&& grep -q '"version": "0.16.1"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
|
||||
|
||||
step "2. hooks.json names exactly one module and no classic hook commands"
|
||||
grep -q '"modules": \["./register.ts"\]' "$HOOKS/hooks.json" && ! grep -q '"command"' "$HOOKS/hooks.json" \
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, test, tier } from 'claude-code/testing'
|
||||
|
||||
import { modelFor, readAgentModels } from '../hooks/agents/models'
|
||||
import { isKept, readUsage, USED_WINDOW_MS } from '../hooks/agents/trim'
|
||||
import { consumer, run } from './fixtures/consumer'
|
||||
import { START, world } from './fixtures/world'
|
||||
@@ -86,3 +87,59 @@ function memory(on: Parameters<typeof world>[0]) {
|
||||
})
|
||||
return store
|
||||
}
|
||||
|
||||
describe('agentModels: a model per agent type for spawns that chose none', () => {
|
||||
test('parses type=model pairs and drops malformed ones', () => {
|
||||
const m = readAgentModels('Explore=haiku, general-purpose = sonnet, bad type=opus, x=gpt-4, y=claude-sonnet-5-5,=haiku')
|
||||
expect([...m.entries()]).toEqual([['explore', 'haiku'], ['general-purpose', 'sonnet'], ['y', 'claude-sonnet-5-5']])
|
||||
expect(readAgentModels({ Explore: 'haiku', n: 3 }).get('explore')).toBe('haiku')
|
||||
expect(readAgentModels(undefined).size).toBe(0)
|
||||
expect(readAgentModels(['Explore=haiku']).size).toBe(0)
|
||||
})
|
||||
|
||||
test('fills only a missing model; forks, teammates and chosen models are kept', () => {
|
||||
const m = readAgentModels('Explore=haiku')
|
||||
expect(modelFor({ subagentType: 'Explore' }, m)).toBe('haiku')
|
||||
expect(modelFor({ subagentType: 'explore', model: '' }, m)).toBe('haiku')
|
||||
expect(modelFor({ subagentType: 'Explore', model: 'opus' }, m)).toBeUndefined()
|
||||
expect(modelFor({ subagentType: 'Explore', fork: true }, m)).toBeUndefined()
|
||||
expect(modelFor({ subagentType: 'Explore', isTeammate: true }, m)).toBeUndefined()
|
||||
expect(modelFor({ subagentType: 'coder' }, m)).toBeUndefined()
|
||||
expect(modelFor({ subagentType: 'Explore' }, readAgentModels(''))).toBeUndefined()
|
||||
})
|
||||
|
||||
test('on spawn the engine sees the mapped model, and /ruflo-mods counts it', { options: { agentModels: 'Explore=haiku' }, plugins: [consumer] }, async ($, on) => {
|
||||
world(on)
|
||||
memory(on)
|
||||
const seen: (string | undefined)[] = []
|
||||
on('agent.spawn', ($, e) => {
|
||||
seen.push(e.model)
|
||||
return { deny: 'test: no real spawn' }
|
||||
})
|
||||
on('command.run', () => ({ text: 'core' }))
|
||||
await $.session.start(START)
|
||||
|
||||
await $.agent.spawn({ tool_use_id: 't1', prompt: 'p', description: 'd', subagentType: 'Explore' } as never).catch(() => undefined)
|
||||
await $.agent.spawn({ tool_use_id: 't2', prompt: 'p', description: 'd', subagentType: 'Explore', model: 'opus' } as never).catch(() => undefined)
|
||||
await $.agent.spawn({ tool_use_id: 't3', prompt: 'p', description: 'd', subagentType: 'coder' } as never).catch(() => undefined)
|
||||
|
||||
expect(seen).toEqual(['haiku', 'opus', undefined])
|
||||
expect((await $.command.run(run('ruflo-mods'))).text).toContain('agent models: 1 type(s), 1 spawn(s) given a model')
|
||||
})
|
||||
|
||||
test('off by default: the spawn passes through', { plugins: [consumer] }, async ($, on) => {
|
||||
world(on)
|
||||
memory(on)
|
||||
const seen: (string | undefined)[] = []
|
||||
on('agent.spawn', ($, e) => {
|
||||
seen.push(e.model)
|
||||
return { deny: 'test: no real spawn' }
|
||||
})
|
||||
on('command.run', () => ({ text: 'core' }))
|
||||
await $.session.start(START)
|
||||
|
||||
await $.agent.spawn({ tool_use_id: 't1', prompt: 'p', description: 'd', subagentType: 'Explore' } as never).catch(() => undefined)
|
||||
expect(seen).toEqual([undefined])
|
||||
expect((await $.command.run(run('ruflo-mods'))).text).toContain('agent models: off')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user