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(cost-tracker): P4 β€” encapsulate compact-context Node block as compact.mjs (v0.8.0)

Reuven8f580f207b31
diff --git a/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json b/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json
index defb26f01b..a54008ea81 100644
--- a/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json
+++ b/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "ruflo-cost-tracker",
"description": "Token usage tracking, model cost attribution per agent, budget alerts, and optimization recommendations β€” uses memory_* (namespace-routed) for cost-tracking and cost-patterns; pairs with federation budget circuit breaker (ADR-097)",
- "version": "0.7.0",
+ "version": "0.8.0",
"author": {
"name": "ruvnet",
"url": "https://github.com/ruvnet"
diff --git a/plugins/ruflo-cost-tracker/README.md b/plugins/ruflo-cost-tracker/README.md
index 502358f0e4..c5e2d72169 100644
--- a/plugins/ruflo-cost-tracker/README.md
+++ b/plugins/ruflo-cost-tracker/README.md
@@ -131,7 +131,7 @@ Reserved namespaces (`pattern`, `claude-memories`, `default`) MUST NOT be shadow
```bash
bash plugins/ruflo-cost-tracker/scripts/smoke.sh
-# Expected: "36 passed, 0 failed"
+# Expected: "37 passed, 0 failed"
```
## Architecture Decisions
diff --git a/plugins/ruflo-cost-tracker/scripts/compact.mjs b/plugins/ruflo-cost-tracker/scripts/compact.mjs
new file mode 100755
index 0000000000..60465884ad
--- /dev/null
+++ b/plugins/ruflo-cost-tracker/scripts/compact.mjs
@@ -0,0 +1,80 @@
+#!/usr/bin/env node
+// cost-compact β€” wraps getTokenOptimizer().getCompactContext() so the
+// cost-compact-context skill can invoke a single command instead of an
+// inlined Node one-liner. A proper MCP tool wrapping getTokenOptimizer is
+// still deferred (would require modifying @claude-flow/cli source); this
+// is the plugin-local equivalent.
+//
+// Resolution: must run from a directory where `@claude-flow/integration`
+// resolves (typically anywhere under `v3/`). The script resolves from
+// process.cwd() rather than from its own location so the user's `cd v3`
+// works without npm-installing the bridge into the plugin tree.
+//
+// Usage:
+// node scripts/compact.mjs "<query>"
+//
+// Optional env:
+// COMPACT_QUIET=1 emit JSON only (no markdown banner)
+
+import { createRequire } from 'node:module';
+import { pathToFileURL } from 'node:url';
+import { join } from 'node:path';
+
+async function main() {
+ const query = process.argv[2] || '';
+ if (!query) {
+ console.error('usage: compact.mjs "<query>"');
+ process.exit(2);
+ }
+
+ let mod;
+ try {
+ const requireFromCwd = createRequire(join(process.cwd(), 'package.json'));
+ const resolved = requireFromCwd.resolve('@claude-flow/integration/token-optimizer');
+ mod = await import(pathToFileURL(resolved).href);
+ } catch (err) {
+ const out = {
+ bridgeUnavailable: true,
+ reason: String(err.message || err).slice(0, 300),
+ memoriesRetrieved: 0,
+ tokensSaved: 0,
+ agenticFlowAvailable: false,
+ };
+ if (process.env.COMPACT_QUIET === '1') return console.log(JSON.stringify(out));
+ console.log(`# cost-compact-context\n\nbridge unavailable: ${out.reason}`);
+ console.log('Run from a directory where `@claude-flow/integration` resolves, e.g. `cd v3 && ...`.');
+ return;
+ }
+
+ const { getTokenOptimizer } = mod;
+ const opt = await getTokenOptimizer();
+ const ctx = await opt.getCompactContext(query);
+ const stats = opt.getStats();
+
+ const out = {
+ query,
+ memoriesRetrieved: ctx.memories?.length ?? 0,
+ tokensSaved: ctx.tokensSaved ?? 0,
+ agenticFlowAvailable: !!stats?.agenticFlowAvailable,
+ cacheHitRate: stats?.cacheHitRate || '0%',
+ upstreamReported: 'tokensSaved is bridge-reported (heuristic), not measured against a no-RAG baseline',
+ };
+
+ if (process.env.COMPACT_QUIET === '1') return console.log(JSON.stringify(out));
+ console.log(`# cost-compact-context β€” query: "${query}"`);
+ console.log('');
+ console.log('| Metric | Value |');
+ console.log('|---|---:|');
+ console.log(`| Memories retrieved | ${out.memoriesRetrieved} |`);
+ console.log(`| Tokens saved (bridge-reported) | ${out.tokensSaved} |`);
+ console.log(`| agentic-flow bridge available | ${out.agenticFlowAvailable} |`);
+ console.log(`| Cache hit rate | ${out.cacheHitRate} |`);
+ console.log('');
+ console.log(`> ${out.upstreamReported}`);
+ if (!out.agenticFlowAvailable) {
+ console.log('');
+ console.log('agentic-flow not installed β€” bridge returns inert results. No compact-context savings.');
+ }
+}
+
+main().catch((e) => { console.error('compact.mjs failed:', e.message || e); process.exit(1); });
diff --git a/plugins/ruflo-cost-tracker/scripts/smoke.sh b/plugins/ruflo-cost-tracker/scripts/smoke.sh
index f6d31d7c33..9507d8a044 100755
--- a/plugins/ruflo-cost-tracker/scripts/smoke.sh
+++ b/plugins/ruflo-cost-tracker/scripts/smoke.sh
@@ -8,10 +8,10 @@ step() { printf "β†’ %s ... " "$1"; }
ok() { printf "PASS\n"; PASS=$((PASS+1)); }
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
-step "1. plugin.json declares 0.7.0 with new keywords"
+step "1. plugin.json declares 0.8.0 with new keywords"
v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
-if [[ "$v" != "0.7.0" ]]; then
- bad "expected 0.7.0, got '$v'"
+if [[ "$v" != "0.8.0" ]]; then
+ bad "expected 0.8.0, got '$v'"
else
miss=""
for k in namespace-routing mcp agentic-flow agent-booster tier1-routing model-routing benchmarking verified telemetry budget; do
@@ -290,5 +290,17 @@ step "36. ruflo-cost.md documents 'cost outcome' subcommand"
grep -q "cost outcome" "$ROOT/commands/ruflo-cost.md" \
&& ok || bad "missing"
+step "37. compact.mjs replaces inline Node block in cost-compact-context"
+F1="$ROOT/scripts/compact.mjs"
+F2="$ROOT/skills/cost-compact-context/SKILL.md"
+miss=""
+[[ -x "$F1" ]] || miss="$miss compact-not-executable"
+node --check "$F1" 2>/dev/null || miss="$miss syntax-error"
+grep -q "createRequire" "$F1" || miss="$miss no-cwd-resolve"
+grep -q "compact\.mjs" "$F2" || miss="$miss skill-not-updated"
+# ensure the inlined Node one-liner is dropped (no `node --input-type=module -e` left)
+grep -q 'node --input-type=module -e' "$F2" && miss="$miss inline-node-still-present"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
printf "\n%s passed, %s failed\n" "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]] || exit 1
diff --git a/plugins/ruflo-cost-tracker/skills/cost-compact-context/SKILL.md b/plugins/ruflo-cost-tracker/skills/cost-compact-context/SKILL.md
index 106f3e1aea..d07af87cb6 100644
--- a/plugins/ruflo-cost-tracker/skills/cost-compact-context/SKILL.md
+++ b/plugins/ruflo-cost-tracker/skills/cost-compact-context/SKILL.md
@@ -15,29 +15,12 @@ Wraps `getTokenOptimizer().getCompactContext()` from `@claude-flow/integration`
2. **Invoke** β€” run from anywhere under `v3/` so `@claude-flow/integration` resolves:
```bash
- node --input-type=module -e '
- import("@claude-flow/integration/token-optimizer")
- .then(async ({ getTokenOptimizer }) => {
- const opt = await getTokenOptimizer();
- const out = await opt.getCompactContext(process.argv[1] || "");
- const stats = opt.getStats();
- console.log(JSON.stringify({
- memoriesRetrieved: out.memories?.length ?? 0,
- tokensSaved: out.tokensSaved ?? 0,
- agenticFlowAvailable: !!stats?.agenticFlowAvailable,
- cacheHitRate: stats?.cacheHitRate,
- }));
- })
- .catch((err) => console.log(JSON.stringify({
- memoriesRetrieved: 0, tokensSaved: 0, agenticFlowAvailable: false,
- bridgeUnavailable: true, reason: String(err?.message ?? err),
- })));
- ' -- "<QUERY>"
+ ( cd v3 && node ../plugins/ruflo-cost-tracker/scripts/compact.mjs "<QUERY>" )
```
- Use the canonical export `@claude-flow/integration/token-optimizer`. **Not** `dist/token-optimizer.js` β€” Node's `./*` exports rule will double the `.js` extension and the import will fail.
+ The script imports `@claude-flow/integration/token-optimizer` (canonical export β€” **not** `dist/token-optimizer.js`, which would double the `.js` extension via Node's `./*` exports rule), calls `getCompactContext(query)`, and prints a markdown summary plus a JSON line via `COMPACT_QUIET=1`.
-3. **Report** β€” `Context compacted: <N> memories, <K> tokens saved (bridge-reported, not measured against a no-RAG baseline). agentic-flow available: <bool>. Cache hit rate: <X%>`. On bridge-unavailable: `agentic-flow not available, no compact-context savings`.
+3. **Report** β€” markdown table with: memories retrieved, tokens saved (bridge-reported), agentic-flow availability, cache hit rate. The script also emits a "bridge-reported, not measured against a no-RAG baseline" disclaimer. On bridge-unavailable: prints "agentic-flow not installed β€” bridge returns inert results." and exits cleanly.
## Caveats β€” claimed upstream, not yet verified