Files
ruflo/plugins/ruflo-cost-tracker/scripts/outcome.mjs
T
ReuvenandRuFlo 333e6338d9 feat(cost-tracker): P3 — auto-emit hooks_model-outcome (v0.7.0)
cost-optimize step 8 was documented but manual; an agent would have to
hand-construct the JSON and shell-quote correctly. Now wired to a tight
wrapper script that takes (task, model, outcome) as positional args and
spawns hooks_model-outcome with explicit argv.

What lands:

- scripts/outcome.mjs — validates outcome ∈ {success, escalated, failure}
  and shells `npx @claude-flow/cli hooks model-outcome -t <task> -m <model> -o <outcome>`
  with spawnSync (no shell-escape risks)
- skills/cost-optimize/SKILL.md step 8 — replaced manual JSON
  instruction with a copy-pasteable command pattern that uses outcome.mjs
- `cost outcome <task> <model> <outcome>` subcommand
- 3 new smoke checks (now 36/36): cost-optimize references outcome.mjs,
  outcome.mjs has spawnSync + validation, command is documented

Live verified: emitted "convert var to const in src/utils.ts" with
model=haiku, outcome=success. Router responded:
  [OK] Outcome recorded for haiku: success

This closes the routing feedback loop documented in ruflo-intelligence
ADR-0001 §"Neutral" (legacy routing-outcomes namespace migration).

Version bump: 0.6.0 → 0.7.0. Keywords: + model-outcome.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-04 23:55:36 -04:00

44 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
// cost-outcome — thin wrapper around `hooks model-outcome` so cost-optimize
// recommendations can be emitted as pre-formatted shell commands. The agent
// (or human) runs this once per applied recommendation and the router learns.
//
// Usage:
// node scripts/outcome.mjs <task-description> <model> <outcome>
// outcome ∈ { success, escalated, failure }
//
// Example:
// node scripts/outcome.mjs "format imports" haiku success
// node scripts/outcome.mjs "design auth flow" sonnet escalated
//
// Why a wrapper: `hooks model-outcome` takes `-t -m -o` and quoting through
// shell pipelines is error-prone. This script uses spawnSync with explicit
// argv so a task description with quotes/newlines is preserved.
import { spawnSync } from 'node:child_process';
const ALLOWED = new Set(['success', 'escalated', 'failure']);
function main() {
const [task, model, outcome] = process.argv.slice(2);
if (!task || !model || !outcome) {
console.error('usage: outcome.mjs <task-description> <model> <outcome>');
console.error(' outcome ∈ {success, escalated, failure}');
process.exit(2);
}
if (!ALLOWED.has(outcome)) {
console.error(`invalid outcome '${outcome}' — must be one of: success, escalated, failure`);
process.exit(2);
}
const r = spawnSync('npx', [
'@claude-flow/cli@latest', 'hooks', 'model-outcome',
'-t', task, '-m', model, '-o', outcome,
], { stdio: 'inherit' });
if (r.status !== 0) {
console.error(`emit failed (exit ${r.status})`);
process.exit(r.status || 1);
}
}
main();