@claude-flow/cli 3.58.1 → 3.59.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/helpers/.helpers-version +1 -1
- package/.claude/helpers/helpers.manifest.json +2 -2
- package/README.md +2 -0
- package/bin/cli.js +19 -1
- package/catalog-manifest.json +3 -3
- package/dist/src/commands/harness.d.ts +40 -0
- package/dist/src/commands/harness.js +142 -0
- package/dist/src/commands/index.js +1 -0
- package/dist/src/commands/init.js +116 -0
- package/dist/src/commands/memory.js +6 -1
- package/dist/src/commands/status.js +2 -2
- package/dist/src/commands/tui.js +9 -4
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +12 -2
- package/dist/src/init/grok-generator.d.ts +96 -0
- package/dist/src/init/grok-generator.js +371 -0
- package/dist/src/init/grok-templates.d.ts +11 -0
- package/dist/src/init/grok-templates.js +28 -0
- package/dist/src/init/index.d.ts +2 -0
- package/dist/src/init/index.js +2 -0
- package/dist/src/mcp-client.js +4 -0
- package/dist/src/mcp-tools/agent-execute-core.js +59 -12
- package/dist/src/mcp-tools/capability-brain.d.ts +1 -1
- package/dist/src/mcp-tools/capability-brain.js +5 -3
- package/dist/src/mcp-tools/embeddings-tools.js +11 -4
- package/dist/src/mcp-tools/index.d.ts +1 -0
- package/dist/src/mcp-tools/index.js +2 -0
- package/dist/src/mcp-tools/memory-tools.js +42 -4
- package/dist/src/mcp-tools/task-tools.js +7 -3
- package/dist/src/mcp-tools/team-tools.d.ts +15 -0
- package/dist/src/mcp-tools/team-tools.js +244 -0
- package/dist/src/memory/memory-bridge.d.ts +19 -0
- package/dist/src/memory/memory-bridge.js +163 -3
- package/dist/src/memory/memory-initializer.d.ts +4 -0
- package/dist/src/memory/memory-initializer.js +70 -37
- package/dist/src/memory/rabitq-index.d.ts +19 -0
- package/dist/src/memory/rabitq-index.js +117 -1
- package/dist/src/missions/schemas.d.ts +113 -113
- package/dist/src/mods/command-registry/schema.d.ts +193 -193
- package/dist/src/services/live-harness.d.ts +111 -0
- package/dist/src/services/live-harness.js +427 -0
- package/package.json +4 -3
- package/plugins/ruflo-metaharness/scripts/_similarity.mjs +62 -2
- package/plugins/ruflo-metaharness/scripts/audit-trend.mjs +5 -5
- package/plugins/ruflo-metaharness/scripts/similarity.mjs +1 -0
- package/plugins/ruflo-metaharness/scripts/test-similarity.mjs +63 -0
- package/templates/grok/agents/ruflo-architect.md +35 -0
- package/templates/grok/agents/ruflo-coder.md +34 -0
- package/templates/grok/agents/ruflo-reviewer.md +30 -0
- package/templates/grok/agents/ruflo-tester.md +26 -0
- package/templates/grok/config.toml +63 -0
- package/templates/grok/docs/README.md +186 -0
- package/templates/grok/hooks/subagent-stop-team.json +15 -0
- package/templates/grok/rules/ruflo-grok.md +132 -0
- package/templates/grok/scripts/grok-subagent-stop-hook.mjs +90 -0
- package/templates/grok/scripts/grok-team-bus.mjs +525 -0
- package/templates/grok/scripts/grok-team-store.mjs +287 -0
- package/templates/grok/scripts/host-statusline.mjs +281 -0
- package/templates/grok/skills/agent-teams-grok/SKILL.md +98 -0
|
@@ -147,6 +147,7 @@ function main() {
|
|
|
147
147
|
console.log(`| jaccard | ${components.jaccard.toFixed(4)} | ${weights.jaccard} | ${(components.jaccard * weights.jaccard).toFixed(4)} |`);
|
|
148
148
|
console.log('');
|
|
149
149
|
console.log(`**Overall:** ${payload.overall.toFixed(4)}`);
|
|
150
|
+
console.log(`**Verdict:** ${payload.verdict}`);
|
|
150
151
|
if (payload.alert) {
|
|
151
152
|
console.log('');
|
|
152
153
|
console.log(payload.alert.triggered ? `⚠ ALERT: ${payload.alert.reason}` : `✓ ${payload.alert.reason}`);
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
projectToVec, cosine, categoricalAgreement, jaccard, similarity,
|
|
26
|
+
normalizeCost, COST_BAND_USD, verdictFor, VERDICT_THRESHOLDS,
|
|
26
27
|
} from './_similarity.mjs';
|
|
27
28
|
// iter 64 — also test the iter-63 shared severity primitives
|
|
28
29
|
import { SEVERITY_RANK, rankSeverity, parseMcpScanText } from './_harness.mjs';
|
|
@@ -174,6 +175,68 @@ assert(typeof hf.contribution === 'number', 'perDimension has numeric contributi
|
|
|
174
175
|
const sNoPD = similarity(A, B);
|
|
175
176
|
assert(!('perDimension' in sNoPD), 'perDimension omitted by default');
|
|
176
177
|
|
|
178
|
+
console.log('\nPhase 7b — normalizeCost (vector index 8, ADR-152 Table 1)');
|
|
179
|
+
// The pre-fix transform was `log10(usd + 0.001) / log10(10)` clamped to
|
|
180
|
+
// [0,1]. `Math.log10(10)` is 1, so the division was a no-op and the raw
|
|
181
|
+
// log — negative for every cost below $0.999 — clamped to a flat 0. That
|
|
182
|
+
// dead zone covered the whole realistic per-run range, including ruflo's
|
|
183
|
+
// own $0.048 Phase-0 baseline.
|
|
184
|
+
assert(normalizeCost(COST_BAND_USD.min) === 0, 'band floor → 0');
|
|
185
|
+
assert(normalizeCost(COST_BAND_USD.max) === 1, 'band ceiling → 1');
|
|
186
|
+
assert(normalizeCost(50) === 1, 'above band ceiling clamps to 1');
|
|
187
|
+
assert(normalizeCost(0) === 0, 'zero cost clamps to 0');
|
|
188
|
+
assert(normalizeCost(-5) === 0, 'negative cost clamps to 0');
|
|
189
|
+
// The regression that motivated the fix: realistic costs must not collide.
|
|
190
|
+
assert(normalizeCost(0.048) !== normalizeCost(0.11),
|
|
191
|
+
'ruflo baseline $0.048 and $0.11 must not collapse to the same value (dead-zone regression)');
|
|
192
|
+
assert(normalizeCost(0.048) > 0,
|
|
193
|
+
'$0.048 (ruflo Phase-0 baseline) must be strictly inside the band');
|
|
194
|
+
// Monotonic non-decreasing across the band, sampled log-evenly.
|
|
195
|
+
const costSamples = [0.001, 0.005, 0.02, 0.048, 0.11, 0.5, 1, 5, 10];
|
|
196
|
+
const costVec = costSamples.map(normalizeCost);
|
|
197
|
+
assert(costVec.every((v, i) => i === 0 || v >= costVec[i - 1]),
|
|
198
|
+
'normalizeCost is monotonic non-decreasing across the band');
|
|
199
|
+
assert(costVec.every((v) => v >= 0 && v <= 1), 'normalizeCost bounded to [0, 1]');
|
|
200
|
+
// End-to-end: the dimension must now reach the composite. Two harnesses
|
|
201
|
+
// identical except for cost previously scored cosine === 1 because both
|
|
202
|
+
// collapsed to 0; they must now differ.
|
|
203
|
+
const costTwin = (usd) => ({
|
|
204
|
+
score: { ...A.score, estCostPerRunUsd: usd }, genome: A.genome,
|
|
205
|
+
});
|
|
206
|
+
const cheapTwin = similarity(costTwin(0.048), A);
|
|
207
|
+
const priceyTwin = similarity(costTwin(1), A);
|
|
208
|
+
assert(cheapTwin.components.cosine !== priceyTwin.components.cosine,
|
|
209
|
+
'cost now influences cosine (was a dead dimension below $0.999)');
|
|
210
|
+
assert(priceyTwin.components.cosine < cheapTwin.components.cosine,
|
|
211
|
+
'a same-shaped harness with a higher cost is less similar to a cheap one');
|
|
212
|
+
|
|
213
|
+
console.log('\nPhase 7c — verdictFor + VERDICT_THRESHOLDS (single source of truth)');
|
|
214
|
+
assert(VERDICT_THRESHOLDS.length === 4, 'four verdict bands');
|
|
215
|
+
assert(VERDICT_THRESHOLDS.every((b, i) => i === 0 || b.min < VERDICT_THRESHOLDS[i - 1].min),
|
|
216
|
+
'bands are ordered highest-first');
|
|
217
|
+
const LAST_BAND = VERDICT_THRESHOLDS[VERDICT_THRESHOLDS.length - 1];
|
|
218
|
+
assert(LAST_BAND.min === Number.NEGATIVE_INFINITY,
|
|
219
|
+
'final band is unbounded so verdictFor always returns a verdict');
|
|
220
|
+
assert(verdictFor(1) === 'near-identical', 'overall 1 → near-identical');
|
|
221
|
+
assert(verdictFor(0.95) === 'near-identical', 'boundary 0.95 → near-identical (inclusive)');
|
|
222
|
+
assert(verdictFor(0.9499) === 'minor-drift', 'just below 0.95 → minor-drift');
|
|
223
|
+
assert(verdictFor(0.85) === 'minor-drift', 'boundary 0.85 → minor-drift (inclusive, the documented floor)');
|
|
224
|
+
assert(verdictFor(0.8499) === 'moderate-drift', 'just below 0.85 → moderate-drift');
|
|
225
|
+
assert(verdictFor(0.5) === 'moderate-drift', 'boundary 0.5 → moderate-drift (inclusive)');
|
|
226
|
+
assert(verdictFor(0.4999) === 'major-drift', 'just below 0.5 → major-drift');
|
|
227
|
+
assert(verdictFor(0) === 'major-drift', 'overall 0 → major-drift');
|
|
228
|
+
// Regression: audit-trend.mjs used to inline a 0.80 minor-drift floor while
|
|
229
|
+
// docs/metaharness-user-guide.md documented 0.85. 0.80 must resolve to
|
|
230
|
+
// moderate-drift now that the bands live in one place.
|
|
231
|
+
assert(verdictFor(0.80) === 'moderate-drift',
|
|
232
|
+
'0.80 resolves via the shared bands (was a divergent inline 0.80 floor in audit-trend.mjs)');
|
|
233
|
+
|
|
234
|
+
console.log('\nPhase 7d — verdict on the similarity() return shape');
|
|
235
|
+
assert(typeof sAA.verdict === 'string', 'similarity() includes a verdict string');
|
|
236
|
+
assert(sAA.verdict === 'near-identical', 'self-match verdict is near-identical');
|
|
237
|
+
assert(sPD.verdict === verdictFor(sPD.overall),
|
|
238
|
+
'similarity().verdict agrees with verdictFor(overall)');
|
|
239
|
+
|
|
177
240
|
console.log('\nPhase 8 — round-trip with the iter-35 spike fixtures (regression anchor)');
|
|
178
241
|
// Hard-coded spike numbers from `_spike-similarity.mjs` — ANY change
|
|
179
242
|
// here means the production module drifted from the spike's frozen
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ruflo-architect
|
|
3
|
+
description: >
|
|
4
|
+
Ruflo swarm architect for Grok. Designs implementation blueprints, ADRs, and
|
|
5
|
+
file-level plans. Use for multi-file features before coding. Read-only by default;
|
|
6
|
+
hand off to ruflo-coder via team bus.
|
|
7
|
+
prompt_mode: full
|
|
8
|
+
permission_mode: plan
|
|
9
|
+
agents_md: true
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
You are the **architect** on a Ruflo Agent Team running under **Grok Build**.
|
|
13
|
+
|
|
14
|
+
This file is a session profile (`grok --agent-profile ruflo-architect` or `/agents`). On Grok Build 1.0.41, `spawn_subagent` does not select it. A spawned child is general-purpose, follows the spawn prompt, and must not call `spawn_subagent`.
|
|
15
|
+
|
|
16
|
+
## Comms protocol (mandatory)
|
|
17
|
+
|
|
18
|
+
- There is **no** Claude `SendMessage` tool.
|
|
19
|
+
- At start, drain your inbox:
|
|
20
|
+
`node scripts/grok-team-bus.mjs inbox --team <TEAM> --agent architect`
|
|
21
|
+
- When design is ready, hand off:
|
|
22
|
+
`node scripts/grok-team-bus.mjs send --team <TEAM> --to developer --from architect --summary "design-ready" --message "<paths + decisions>"`
|
|
23
|
+
- Prefer storing durable design under memory namespace `team:<TEAM>` when Ruflo MCP is available.
|
|
24
|
+
|
|
25
|
+
## Deliverable
|
|
26
|
+
|
|
27
|
+
Produce a decisive blueprint:
|
|
28
|
+
|
|
29
|
+
1. Patterns found (file:line)
|
|
30
|
+
2. Chosen architecture + trade-offs
|
|
31
|
+
3. Files to create/modify
|
|
32
|
+
4. Build sequence for developer → tester → reviewer
|
|
33
|
+
5. Risks / security notes
|
|
34
|
+
|
|
35
|
+
Do **not** implement code. Do not wait for Ruflo to execute — you design; the lead/developer executes.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ruflo-coder
|
|
3
|
+
description: >
|
|
4
|
+
Ruflo implementation agent for Grok. Writes production code from architect designs.
|
|
5
|
+
Prefer isolation=worktree when spawned. Handoffs via team bus, not SendMessage.
|
|
6
|
+
prompt_mode: full
|
|
7
|
+
agents_md: true
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
You are the **developer/coder** on a Ruflo Agent Team under **Grok Build**.
|
|
11
|
+
|
|
12
|
+
This file is a session profile (`grok --agent-profile ruflo-coder` or `/agents`). On Grok Build 1.0.41, `spawn_subagent` does not select it. A spawned child is general-purpose, follows the spawn prompt (worktree isolation when the plan says so), and must not call `spawn_subagent`.
|
|
13
|
+
|
|
14
|
+
## Comms protocol (mandatory)
|
|
15
|
+
|
|
16
|
+
- No Claude `SendMessage`.
|
|
17
|
+
- Start: `node scripts/grok-team-bus.mjs inbox --team <TEAM> --agent developer`
|
|
18
|
+
- If architect design is in the inbox or memory `team:<TEAM>`, follow it.
|
|
19
|
+
- When implementation is ready:
|
|
20
|
+
`node scripts/grok-team-bus.mjs send --team <TEAM> --to tester --from developer --summary "impl-ready" --message "<files changed + how to test>"`
|
|
21
|
+
- On stop: `node scripts/grok-team-bus.mjs on-stop --team <TEAM> --agent developer`
|
|
22
|
+
|
|
23
|
+
## Rules
|
|
24
|
+
|
|
25
|
+
- Prefer editing existing files; keep changes focused.
|
|
26
|
+
- Match project conventions (Claude.md / Agents.md / ADRs).
|
|
27
|
+
- Run available unit tests for touched areas when practical.
|
|
28
|
+
- If using a git worktree, leave a clear summary of the worktree path and branch for the lead to merge.
|
|
29
|
+
|
|
30
|
+
## Anti-patterns
|
|
31
|
+
|
|
32
|
+
- Waiting after `swarm_init` for code to appear by magic
|
|
33
|
+
- Inventing Claude Task / SendMessage APIs
|
|
34
|
+
- Parallel uncoordinated edits outside your worktree
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ruflo-reviewer
|
|
3
|
+
description: >
|
|
4
|
+
Ruflo code review agent for Grok. Reviews quality, security, and test evidence.
|
|
5
|
+
Read-oriented; reports findings to the team lead via team bus.
|
|
6
|
+
prompt_mode: full
|
|
7
|
+
permission_mode: plan
|
|
8
|
+
agents_md: true
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
You are the **reviewer** on a Ruflo Agent Team under **Grok Build**.
|
|
12
|
+
|
|
13
|
+
This file is a session profile (`grok --agent-profile ruflo-reviewer` or `/agents`). On Grok Build 1.0.41, `spawn_subagent` does not select it. A spawned child is general-purpose, follows the spawn prompt, and must not call `spawn_subagent`.
|
|
14
|
+
|
|
15
|
+
## Comms protocol
|
|
16
|
+
|
|
17
|
+
- Inbox: `node scripts/grok-team-bus.mjs inbox --team <TEAM> --agent reviewer`
|
|
18
|
+
- Final report to lead:
|
|
19
|
+
`node scripts/grok-team-bus.mjs send --team <TEAM> --to lead --from reviewer --summary "review-complete" --message "<findings>"`
|
|
20
|
+
(If `lead` mailbox is unused, print the full review as your final response for the parent session.)
|
|
21
|
+
- `node scripts/grok-team-bus.mjs on-stop --team <TEAM> --agent reviewer`
|
|
22
|
+
|
|
23
|
+
## Review focus
|
|
24
|
+
|
|
25
|
+
1. Correctness vs design handoff
|
|
26
|
+
2. Security (injection, secrets, path traversal)
|
|
27
|
+
3. Test evidence quality
|
|
28
|
+
4. Maintainability / ADR alignment
|
|
29
|
+
|
|
30
|
+
Severity: blocker / major / minor / nit. Blockers must be explicit.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ruflo-tester
|
|
3
|
+
description: >
|
|
4
|
+
Ruflo tester for Grok. Writes and runs tests from implementation handoffs.
|
|
5
|
+
Use worktree isolation when modifying the tree. Reports to reviewer via team bus.
|
|
6
|
+
prompt_mode: full
|
|
7
|
+
agents_md: true
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
You are the **tester** on a Ruflo Agent Team under **Grok Build**.
|
|
11
|
+
|
|
12
|
+
This file is a session profile (`grok --agent-profile ruflo-tester` or `/agents`). On Grok Build 1.0.41, `spawn_subagent` does not select it. A spawned child is general-purpose, follows the spawn prompt, and must not call `spawn_subagent`.
|
|
13
|
+
|
|
14
|
+
## Comms protocol
|
|
15
|
+
|
|
16
|
+
- Inbox: `node scripts/grok-team-bus.mjs inbox --team <TEAM> --agent tester`
|
|
17
|
+
- After tests:
|
|
18
|
+
`node scripts/grok-team-bus.mjs send --team <TEAM> --to reviewer --from tester --summary "tests-ready" --message "<commands, pass/fail, coverage gaps>"`
|
|
19
|
+
- `node scripts/grok-team-bus.mjs on-stop --team <TEAM> --agent tester`
|
|
20
|
+
|
|
21
|
+
## Deliverable
|
|
22
|
+
|
|
23
|
+
- Test plan + implemented tests
|
|
24
|
+
- Exact commands to run
|
|
25
|
+
- Failures with file:line
|
|
26
|
+
- Gaps you did not cover
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Ruflo on Grok Build — project-scoped host config
|
|
2
|
+
# Loaded by Grok when this folder is trusted (see ~/.grok/trusted_folders.toml).
|
|
3
|
+
#
|
|
4
|
+
# Goal: full harness (MCP + hooks + skills + agent teams path), not a thin CLI wrapper.
|
|
5
|
+
# See: .grok/rules/ruflo-grok.md and v3/docs/adr/ADR-402-host-agnostic-agent-teams.md
|
|
6
|
+
#
|
|
7
|
+
# After editing: restart Grok (or reload MCPs) so tool lists refresh.
|
|
8
|
+
|
|
9
|
+
# ---------------------------------------------------------------------------
|
|
10
|
+
# Ruflo MCP — orchestrator / ledger (memory, swarm, hooks, team bus, neural)
|
|
11
|
+
# `ruflo init --grok` pins this to the Ruflo version that ran it, because the
|
|
12
|
+
# team_* tools ship in that same release (an older @latest may lack them).
|
|
13
|
+
# From a source checkout it points at that checkout's bin/cli.js instead.
|
|
14
|
+
# Cold npx can exceed 30s; keep timeouts high.
|
|
15
|
+
# ---------------------------------------------------------------------------
|
|
16
|
+
[mcp_servers.ruflo]
|
|
17
|
+
command = {{RUFLO_MCP_COMMAND}}
|
|
18
|
+
args = {{RUFLO_MCP_ARGS}}
|
|
19
|
+
enabled = true
|
|
20
|
+
startup_timeout_sec = 120
|
|
21
|
+
tool_timeout_sec = 180
|
|
22
|
+
|
|
23
|
+
# ---------------------------------------------------------------------------
|
|
24
|
+
# Optional: RuvNet Brain grounding (search_ruvnet over embedded rUv source)
|
|
25
|
+
# Install: npx ruvnet-brain@latest → kb under ~/.cache/ruvnet-brain/kb
|
|
26
|
+
#
|
|
27
|
+
# forge-mcp-all defaults KB_DIR to process.cwd(). When Grok spawns MCP from the
|
|
28
|
+
# project root, search fails with "passages sidecar not found: ./agentdb…".
|
|
29
|
+
# Always set env.KB_DIR to the absolute kb path. tool_timeout_sec high for cold
|
|
30
|
+
# BGE model download (first big search can take minutes).
|
|
31
|
+
# init --grok fills in your home directory for the {{HOME}} paths below.
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
# [mcp_servers.ruvnet-brain]
|
|
34
|
+
# command = "node"
|
|
35
|
+
# args = ["{{HOME}}/.cache/ruvnet-brain/kb/forge-mcp-all.mjs"]
|
|
36
|
+
# env = { KB_DIR = "{{HOME}}/.cache/ruvnet-brain/kb" }
|
|
37
|
+
# enabled = true
|
|
38
|
+
# startup_timeout_sec = 90
|
|
39
|
+
# tool_timeout_sec = 600
|
|
40
|
+
|
|
41
|
+
# ---------------------------------------------------------------------------
|
|
42
|
+
# Permissions — allow Ruflo CLI + helpers without re-prompting every turn
|
|
43
|
+
# (deny still wins over allow; PreToolUse hooks can still block)
|
|
44
|
+
# ---------------------------------------------------------------------------
|
|
45
|
+
[permission]
|
|
46
|
+
allow = [
|
|
47
|
+
"Bash(npx ruflo*)",
|
|
48
|
+
"Bash(npx @claude-flow*)",
|
|
49
|
+
"Bash(npx claude-flow*)",
|
|
50
|
+
"Bash(node .claude/*)",
|
|
51
|
+
"Bash(npx -y ruflo*)",
|
|
52
|
+
"Bash(node scripts/grok-team-bus.mjs*)",
|
|
53
|
+
"MCPTool(ruflo__*)",
|
|
54
|
+
"MCPTool(ruvnet-brain__*)",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
# ---------------------------------------------------------------------------
|
|
58
|
+
# Subagent defaults are user-level on Grok Build 1.0.41.
|
|
59
|
+
# Project .grok/config.toml contributes only [mcp_servers], [plugins],
|
|
60
|
+
# [permission], and [mcp].max_output_bytes. A [subagents] table here is ignored.
|
|
61
|
+
# Put role defaults in ~/.grok/config.toml if you need them.
|
|
62
|
+
# Team children: pass host.grok.spawn from team_spawn (see docs/grok/README.md).
|
|
63
|
+
# ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Ruflo on Grok Build
|
|
2
|
+
|
|
3
|
+
How to run Ruflo inside [Grok Build](https://x.ai/) after `npx ruflo init --grok`.
|
|
4
|
+
|
|
5
|
+
**Host contract checked against Grok Build 1.0.41** (`grok 1.0.41`, macOS, 2026-09-27) and the user guide shipped with that binary (`~/.grok/docs/user-guide/`). Newer Grok builds change spawn arguments and which keys a project config may set. Run the check in [When Grok updates](#when-grok-updates) before treating this page as current.
|
|
6
|
+
|
|
7
|
+
Ruflo is the ledger: memory, swarm records, the team bus, hooks. Grok is the executor: it edits files, runs the shell, and calls `spawn_subagent`. After `team_create` or `swarm_init`, keep working. Those calls record coordination. They do not write the feature.
|
|
8
|
+
|
|
9
|
+
## What `init --grok` writes
|
|
10
|
+
|
|
11
|
+
| Path | Purpose |
|
|
12
|
+
|------|---------|
|
|
13
|
+
| `.grok/config.toml` | Project MCP server `ruflo` and permission allows |
|
|
14
|
+
| `.grok/rules/ruflo-grok.md` | Host doctrine loaded as a project rule |
|
|
15
|
+
| `.grok/agents/` | Session profiles (`ruflo-architect`, `ruflo-coder`, `ruflo-tester`, `ruflo-reviewer`) |
|
|
16
|
+
| `.grok/skills/agent-teams-grok/` | Skill the lead follows to spawn a pipeline |
|
|
17
|
+
| `.grok/hooks/subagent-stop-team.json` | `SubagentStop` → team bus idle-assign |
|
|
18
|
+
| `scripts/grok-team-bus.mjs`, `scripts/grok-team-store.mjs` | Team bus CLI (same store as the MCP `team_*` tools) |
|
|
19
|
+
| `scripts/grok-subagent-stop-hook.mjs` | Hook script: advances the plan when a teammate stops |
|
|
20
|
+
| `scripts/host-statusline.mjs` | The "what is loaded" line (see Loaded status) |
|
|
21
|
+
| `docs/grok/README.md` | This guide |
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
From the app you want Grok to work in (any repo, not only the Ruflo monorepo):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx -y ruflo@latest init --grok
|
|
29
|
+
# see what it would write, write nothing:
|
|
30
|
+
# npx -y ruflo@latest init --grok --dry-run
|
|
31
|
+
# overwrite an earlier scaffold:
|
|
32
|
+
# npx -y ruflo@latest init --grok --force
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`init --grok` writes only inside this project, and prints every path it wrote. It pins `[mcp_servers.ruflo]` to the Ruflo version that ran it (for example `ruflo@3.48.0`), because the `team_*` tools ship in that same release and an older `@latest` from a stale npx cache would lack them. Run from a Ruflo source checkout, it points the server at that checkout's `bin/cli.js` instead; re-run it from a published release before you commit `.grok/config.toml`.
|
|
36
|
+
|
|
37
|
+
Then:
|
|
38
|
+
|
|
39
|
+
1. Trust the folder. `/hooks-trust`, or launch with `grok --trust`. On 1.0.41 one grant covers project MCP, hooks, skills, and project rules together. The decision is stored in `~/.grok/trusted_folders.toml`.
|
|
40
|
+
2. Restart Grok with this folder as the workspace so `.grok/config.toml` loads.
|
|
41
|
+
3. Confirm the server:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
grok mcp list # ruflo (project)
|
|
45
|
+
grok mcp doctor ruflo # handshake ok; team_create present once this build is the server
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`init` writes the MCP block itself. To register by hand, scope it to the project. The default scope is your user config (`~/.grok/config.toml`), which would install Ruflo for every repo:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
grok mcp add ruflo --scope project -- npx -y ruflo@<version> mcp start
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use a version that ships `team_*` (the one `init --grok` pinned). `-s project` is the same flag. Cold `npx` often exceeds the 30s default startup timeout; the scaffold sets `startup_timeout_sec = 120`.
|
|
55
|
+
|
|
56
|
+
## Use it in a session
|
|
57
|
+
|
|
58
|
+
Grok does not put each Ruflo tool on the model as its own function. The model has `search_tool` and `use_tool`.
|
|
59
|
+
|
|
60
|
+
1. `search_tool` with a keyword (`team_create`, `memory_search`, `swarm_init`).
|
|
61
|
+
2. `use_tool` with the catalog key: `ruflo__team_create`, `ruflo__memory_search`.
|
|
62
|
+
3. Stay on a small subset. A full Ruflo server exposes hundreds of tools; keyword search is how the model reaches them.
|
|
63
|
+
|
|
64
|
+
MCP parameter names on the team tools are `team` and `agent`.
|
|
65
|
+
|
|
66
|
+
### Agent teams
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
team_create → team_plan → team_spawn → spawn_subagent → team_send / team_inbox → team_on_stop → team_shutdown
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`team_spawn` returns a plan. The lead calls `spawn_subagent` with the top-level `prompt` and **only** `host.grok.spawn`:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
spawn_subagent({
|
|
76
|
+
prompt: spawnPlan.prompt,
|
|
77
|
+
description: spawnPlan.host.grok.spawn.description,
|
|
78
|
+
background: spawnPlan.host.grok.spawn.background,
|
|
79
|
+
isolation: spawnPlan.host.grok.spawn.isolation
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`host.grok.advisory.capability_mode` and `subagent_type` describe the role. They are not arguments of `spawn_subagent` on 1.0.41. Passing them fails the call. The child is `general-purpose`. The prompt states the read-only constraint. `isolation: "worktree"` is the setting Grok enforces, and it is how writers avoid editing the lead's tree.
|
|
84
|
+
|
|
85
|
+
Only the lead spawns. A child that calls `spawn_subagent` hits the depth limit (1).
|
|
86
|
+
|
|
87
|
+
Pass `description` through unchanged. It is `<role>:<agent>@<team>`, and the `SubagentStop` hook parses it to mark that agent idle and advance that team's plan. If a description has no `@team`, the hook uses the one active team that lists the agent; when several do, it advances nothing and says so on stderr.
|
|
88
|
+
|
|
89
|
+
How the bus behaves:
|
|
90
|
+
|
|
91
|
+
- State and mail live in `.claude-flow/teams/<team>/` (`team.json`, `mailbox/<agent>/`). Mail is per team: `team_inbox` needs `team` and `agent`, and `team_status` counts only that team's mail.
|
|
92
|
+
- `team.json` changes take a lock and are written to a temp file and renamed, so parallel spawns and hooks do not drop updates.
|
|
93
|
+
- `team_spawn` refuses once the team has `maxAgents` members (re-spawning an existing member is fine).
|
|
94
|
+
- `team_shutdown` closes the team: spawn, send, broadcast, plan, and on-stop refuse afterwards. `team_inbox` and `team_status` still work so remaining mail can be drained. `team_create --force` reopens the name.
|
|
95
|
+
- A broadcast (`to: "*"`) goes to current members and is refused while the team has none.
|
|
96
|
+
- `priority` is an integer 0-999; lower is read first.
|
|
97
|
+
- Several teams can be active at once; every call names its team.
|
|
98
|
+
|
|
99
|
+
`.grok/agents/ruflo-coder.md` and the other profiles apply when you start Grok as that agent (`grok --agent-profile ruflo-coder` or `/agents`). Spawn does not select them.
|
|
100
|
+
|
|
101
|
+
CLI bus, same plan shape, no MCP required:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
node scripts/grok-team-bus.mjs create --name feature-x --topology hierarchical
|
|
105
|
+
node scripts/grok-team-bus.mjs plan --team feature-x \
|
|
106
|
+
--steps '["architect","developer","tester","reviewer"]'
|
|
107
|
+
node scripts/grok-team-bus.mjs spawn --team feature-x --agent architect --role architect \
|
|
108
|
+
--prompt "Design the feature." --next developer
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Map the printed `spawnPlan.host.grok.spawn` the same way. Skill: `agent-teams-grok`.
|
|
112
|
+
|
|
113
|
+
### What the project config loads
|
|
114
|
+
|
|
115
|
+
On 1.0.41, `.grok/config.toml` contributes:
|
|
116
|
+
|
|
117
|
+
- `[mcp_servers]`
|
|
118
|
+
- `[plugins]`
|
|
119
|
+
- `[permission]`
|
|
120
|
+
- `[mcp].max_output_bytes`
|
|
121
|
+
|
|
122
|
+
Other tables, including `[subagents]`, are read from `~/.grok/config.toml` only. The scaffold used to write `[subagents] enabled = true` into the project file. That key does nothing there. Subagents are on by default.
|
|
123
|
+
|
|
124
|
+
Permission allows in the scaffold use Grok's native forms, `Bash(...)` and `MCPTool(ruflo__*)`. Deny still beats allow.
|
|
125
|
+
|
|
126
|
+
### Hooks
|
|
127
|
+
|
|
128
|
+
`.grok/hooks/subagent-stop-team.json` runs on `SubagentStop` and calls `scripts/grok-subagent-stop-hook.mjs`. It runs only after the folder is trusted. `$CLAUDE_PROJECT_DIR` is set (alias of `GROK_WORKSPACE_ROOT`).
|
|
129
|
+
|
|
130
|
+
`UserPromptSubmit` hooks that allow the prompt do not inject stdout into the model on 1.0.41. If a route hook seems to vanish, read `.swarm/route-latest.md` or call the route tool. That is a host limit, not a missing Ruflo file.
|
|
131
|
+
|
|
132
|
+
## Loaded status
|
|
133
|
+
|
|
134
|
+
`scripts/host-statusline.mjs` is the shared "what loaded" line: `RuFlo loaded │ ruflo │ rules │ 4 agents │ skill │ hook │ trusted`, or the names of what is missing. Claude shows its own richer `statusLine`. Codex has no status row; `node scripts/host-statusline.mjs --host codex` prints the same facts.
|
|
135
|
+
|
|
136
|
+
Grok reads `[ui.status_line]` only from your user file, `~/.grok/config.toml`; a project config cannot set it. `init --grok` does not touch that file unless you ask. It prints the snippet to add, or with `--grok-statusline` it:
|
|
137
|
+
|
|
138
|
+
- copies the script to `~/.grok/ruflo/host-statusline.mjs`, and
|
|
139
|
+
- merges this into `~/.grok/config.toml` (parsed with a TOML parser; an existing `ui.status_line` in any form is left alone, and a file it cannot merge safely is not changed — you get the snippet instead):
|
|
140
|
+
|
|
141
|
+
```toml
|
|
142
|
+
[ui.status_line]
|
|
143
|
+
type = "command"
|
|
144
|
+
command = 'node "/home/you/.grok/ruflo/host-statusline.mjs"'
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The command is an absolute path to your own copy, so no repo can substitute a script of its own. It reports on whichever folder Grok is in. Restart Grok after the user file changes.
|
|
148
|
+
|
|
149
|
+
## Prove it
|
|
150
|
+
|
|
151
|
+
From a Ruflo checkout (this script is not copied by `init --grok`; run `init --grok` in the checkout first):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
node scripts/probe-host-live.mjs --host grok
|
|
155
|
+
node scripts/probe-host-live.mjs --host all --no-execute
|
|
156
|
+
node scripts/probe-host-live.mjs --host grok --live
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
One contract (discover, connect, SessionStart receipt, optional memory round trip) with a Grok, Claude, or Codex adapter. A check that CLI cannot answer is a skip, not a pass.
|
|
160
|
+
|
|
161
|
+
## When Grok updates
|
|
162
|
+
|
|
163
|
+
The July 2026 host work assumed Grok 1.0.34 and a spawn schema that accepted `subagent_type` and `capability_mode`. 1.0.41 dropped both from the model-facing tool and stopped applying `[subagents]` from project config. The same class of drift will happen again.
|
|
164
|
+
|
|
165
|
+
After `grok --version` changes:
|
|
166
|
+
|
|
167
|
+
1. Open `~/.grok/docs/user-guide/16-subagents.md` and read **Spawning Subagents**. The parameter table is the contract. Forward a key only if it is listed.
|
|
168
|
+
2. Open `26-config-reference.md` and confirm which sections a project `.grok/config.toml` may set (1.0.41: mcp servers, plugins, permission, mcp output cap).
|
|
169
|
+
3. Open `07-mcp-servers.md` and confirm `grok mcp add --scope` still defaults to `user`, and that tools are still `search_tool` / `use_tool` with `server__tool` names.
|
|
170
|
+
4. Open `10-hooks.md` and confirm `SubagentStop`, folder trust, and `$CLAUDE_PROJECT_DIR`.
|
|
171
|
+
5. Open `22-permissions-and-safety.md` and confirm `MCPTool(server__tool)` and `Bash(...)` still match the allows in `.grok/config.toml`.
|
|
172
|
+
6. Spawn once with `host.grok.spawn` only. If the tool rejects `background`, the user guide's name for that flag is `run_in_background` — use the name the live schema accepts.
|
|
173
|
+
7. Update the `contract` string in `team_spawn` / `scripts/grok-team-bus.mjs` and this page to the version you just checked.
|
|
174
|
+
|
|
175
|
+
`grok inspect` shows which rules, skills, and MCP servers the trusted folder actually loaded.
|
|
176
|
+
|
|
177
|
+
## Optional
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
npx -y ruflo@latest daemon start
|
|
181
|
+
npx -y ruflo@latest doctor
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
RuvNet Brain is off in the scaffold. Uncomment `[mcp_servers.ruvnet-brain]` in `.grok/config.toml` after `npx ruvnet-brain@latest`, and set `env.KB_DIR` to the absolute `~/.cache/ruvnet-brain/kb` path. `init --grok` fills in your home directory for those paths when it creates the file.
|
|
185
|
+
|
|
186
|
+
Architecture: ADR-402 (Host-Agnostic Agent Teams), in the Ruflo repo at `v3/docs/adr/ADR-402-host-agnostic-agent-teams.md`.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Ruflo on Grok — host doctrine
|
|
2
|
+
|
|
3
|
+
You are running **inside Grok Build**, not Claude Code. Ruflo is the harness (orchestrator/ledger). **You** execute.
|
|
4
|
+
|
|
5
|
+
## Division of labor
|
|
6
|
+
|
|
7
|
+
| Layer | Role |
|
|
8
|
+
|-------|------|
|
|
9
|
+
| **Grok** | Executor — edit files, shell, tests, `spawn_subagent`, synthesize |
|
|
10
|
+
| **Ruflo MCP/CLI** | Orchestrator — memory, swarm records, team bus, learning, security hooks |
|
|
11
|
+
|
|
12
|
+
After any `swarm_init` / `team_create` / `agent_spawn` / MCP coordination call: **immediately continue working**. Never wait for Ruflo to “build the feature.” It does not execute code.
|
|
13
|
+
|
|
14
|
+
## Tool map (Claude / CLAUDE.md → Grok)
|
|
15
|
+
|
|
16
|
+
| Claude / CLAUDE.md | Grok |
|
|
17
|
+
|--------------------|------|
|
|
18
|
+
| `Task(...)` / Agent Teams spawn | `spawn_subagent` (`background: true` for parallel) |
|
|
19
|
+
| `SendMessage` | Ruflo MCP `team_send` / `team_inbox` (host-agnostic bus) — until available: AgentDB memory namespace `team:{id}` or `collaboration` |
|
|
20
|
+
| `TodoWrite` | `todo_write` |
|
|
21
|
+
| `Bash` | `run_terminal_command` |
|
|
22
|
+
| `Read` / `Grep` / `Glob` | `read_file` / `grep` / `list_dir` |
|
|
23
|
+
| `Write` / `Edit` / `MultiEdit` | `write` / `search_replace` |
|
|
24
|
+
| `claude -p` workers | `spawn_subagent` or `grok -p` |
|
|
25
|
+
| `mcp__claude-flow__*` / `mcp__ruflo__*` | `search_tool` then `use_tool` with `ruflo__*` names |
|
|
26
|
+
| Haiku / Sonnet / Opus routing | Ignore Anthropic tiers; use Grok models / subagent `model` only when needed |
|
|
27
|
+
|
|
28
|
+
## MCP usage
|
|
29
|
+
|
|
30
|
+
1. Discover: `search_tool` with keywords (`memory_search`, `swarm_init`, `team_`, `hooks`).
|
|
31
|
+
2. Call: `use_tool` with the fully-qualified name (e.g. `ruflo__memory_search`).
|
|
32
|
+
3. Prefer memory + team/swarm subset over flooding with all 300+ tools.
|
|
33
|
+
|
|
34
|
+
## Before complex work (mandatory)
|
|
35
|
+
|
|
36
|
+
1. `memory_search` (namespace `patterns` when available) for similar past solutions.
|
|
37
|
+
2. If RuvNet Brain / `search_ruvnet` is available: ground stack choices in real rUv source **before** recommending Pinecone, pgvector, LangChain, or other training-prior defaults.
|
|
38
|
+
3. For multi-file / multi-role work: open a **named team** pipeline (see Agent Teams below).
|
|
39
|
+
|
|
40
|
+
## After success (mandatory)
|
|
41
|
+
|
|
42
|
+
Store what worked via `memory_store` (namespace `patterns`): approach, files, gotchas, commands.
|
|
43
|
+
|
|
44
|
+
## Agent Teams on Grok (comms-first)
|
|
45
|
+
|
|
46
|
+
Named agents coordinate via the **Ruflo team bus** (MCP), not proprietary Claude `SendMessage`.
|
|
47
|
+
|
|
48
|
+
### Preferred pipeline
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
lead (you)
|
|
52
|
+
→ spawn named subagents in ONE turn (background: true)
|
|
53
|
+
→ each agent handoff via team_send / memory key
|
|
54
|
+
→ SubagentStop / you assign next step
|
|
55
|
+
→ lead synthesizes
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Spawn contract (Grok Build 1.0.41)
|
|
59
|
+
|
|
60
|
+
`spawn_subagent` takes `prompt`, `description`, `background`, `isolation`, and optionally `cwd`, `resume_from`, and `model`. It does not take `subagent_type` or `capability_mode`. An omitted type is `general-purpose`. Nesting depth is 1, so only the lead spawns.
|
|
61
|
+
|
|
62
|
+
`team_spawn` returns `host.grok.spawn` for those arguments and `host.grok.advisory` for the role constraint. Pass `spawn` plus `prompt`. The prompt tells a read-only role not to edit. `isolation: "worktree"` is what Grok enforces for writers.
|
|
63
|
+
|
|
64
|
+
`.grok/agents/ruflo-*` are session profiles (`grok --agent-profile` or `/agents`). They are not spawn types.
|
|
65
|
+
|
|
66
|
+
Project `.grok/config.toml` contributes `[mcp_servers]`, `[plugins]`, `[permission]`, and `[mcp].max_output_bytes`. A `[subagents]` table in that file is ignored. Subagent defaults belong in `~/.grok/config.toml`.
|
|
67
|
+
|
|
68
|
+
Operator guide: `docs/grok/README.md`. If `grok --version` moves past 1.0.41, re-check `~/.grok/docs/user-guide/16-subagents.md` and `26-config-reference.md` before forwarding new spawn keys.
|
|
69
|
+
|
|
70
|
+
### Defaults
|
|
71
|
+
|
|
72
|
+
| Role | Prompt constraint | `isolation` |
|
|
73
|
+
|------|-------------------|-------------|
|
|
74
|
+
| researcher / architect / reviewer | read-only | `none` |
|
|
75
|
+
| coder / implementer | full tools | **`worktree`** |
|
|
76
|
+
| tester | full tools | **`worktree`** when writing tests |
|
|
77
|
+
|
|
78
|
+
- Always pass a clear **name/role** in the prompt (“You are architect on team feature-x”).
|
|
79
|
+
- Tell each agent **who to message next** and **what artifact to produce**.
|
|
80
|
+
- Prefer short cycles with verification gates over one giant agent.
|
|
81
|
+
- Hierarchical topology for coding swarms; max ~6–8 concurrent workers.
|
|
82
|
+
|
|
83
|
+
### Spawn pattern (all in one message)
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
spawn_subagent({ prompt, description, background: true, isolation: "none" })
|
|
87
|
+
architect → team_send to developer
|
|
88
|
+
spawn_subagent({ ..., isolation: "worktree" })
|
|
89
|
+
developer → tester → reviewer (reviewer isolation "none")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Use MCP team tools or memory handoffs. There is no `SendMessage` tool.
|
|
93
|
+
|
|
94
|
+
## Skills
|
|
95
|
+
|
|
96
|
+
- Prefer project skills under `.agents/skills/` and `.claude/skills/`.
|
|
97
|
+
- High-value first: swarm-orchestration, memory-management, sparc-methodology, security-audit, github-automation, hive-mind.
|
|
98
|
+
- Load a skill when the task matches its description; don’t dump all 100+ into context.
|
|
99
|
+
|
|
100
|
+
## Hooks (already in `.claude/settings.json`)
|
|
101
|
+
|
|
102
|
+
Grok loads Claude-compatible hooks when the folder is trusted. Expect:
|
|
103
|
+
|
|
104
|
+
- SessionStart: session restore + memory import
|
|
105
|
+
- UserPromptSubmit: route / intelligence context
|
|
106
|
+
- PreToolUse Bash: pre-bash safety
|
|
107
|
+
- PostToolUse edits: post-edit learning
|
|
108
|
+
- SubagentStop: post-task / idle assign
|
|
109
|
+
|
|
110
|
+
If route context does not appear in the transcript, call `hooks route` via CLI/MCP or read `.swarm/route-latest.md` when present.
|
|
111
|
+
|
|
112
|
+
## CLI fallback
|
|
113
|
+
|
|
114
|
+
When MCP is down:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npx -y ruflo@latest memory search --query "…"
|
|
118
|
+
npx -y ruflo@latest memory store --key "…" --value "…" --namespace patterns
|
|
119
|
+
npx -y ruflo@latest swarm init --topology hierarchical --max-agents 8
|
|
120
|
+
npx -y ruflo@latest doctor
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Team calls have their own fallback that needs no npx: `node scripts/grok-team-bus.mjs <command> --team <team> …` (same store as the `team_*` tools).
|
|
124
|
+
|
|
125
|
+
## Anti-patterns
|
|
126
|
+
|
|
127
|
+
- Waiting after `swarm start` for code to appear
|
|
128
|
+
- Calling Claude-only tools (`SendMessage`, Claude `Task` agent types as host APIs)
|
|
129
|
+
- Shared-tree parallel coders without worktrees (file races)
|
|
130
|
+
- Skipping memory_search / grounding on stack decisions
|
|
131
|
+
- Creating docs in repo root or committing secrets
|
|
132
|
+
)
|