@claude-flow/cli 3.25.6 → 3.26.0
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/.proven-config-version +1 -0
- package/.claude/helpers/.helpers-version +1 -1
- package/.claude/helpers/helpers.manifest.json +5 -4
- package/.claude/helpers/hook-handler.cjs +129 -0
- package/.claude/helpers/statusline.cjs +771 -505
- package/.claude/proven-config.json +42 -0
- package/catalog-manifest.json +12 -0
- package/dist/src/commands/advisor.d.ts +15 -0
- package/dist/src/commands/advisor.js +94 -0
- package/dist/src/commands/doctor.js +77 -3
- package/dist/src/commands/funnel.d.ts +13 -0
- package/dist/src/commands/funnel.js +103 -0
- package/dist/src/commands/hooks.js +112 -46
- package/dist/src/commands/index.js +10 -0
- package/dist/src/commands/init.js +44 -0
- package/dist/src/commands/proxy.d.ts +21 -0
- package/dist/src/commands/proxy.js +310 -0
- package/dist/src/commands/security.js +29 -0
- package/dist/src/commands/settings.d.ts +19 -0
- package/dist/src/commands/settings.js +180 -0
- package/dist/src/commands/version.d.ts +42 -0
- package/dist/src/commands/version.js +106 -0
- package/dist/src/funnel/advisor-tip.d.ts +58 -0
- package/dist/src/funnel/advisor-tip.js +92 -0
- package/dist/src/funnel/attribution.d.ts +37 -0
- package/dist/src/funnel/attribution.js +101 -0
- package/dist/src/funnel/consent.d.ts +22 -0
- package/dist/src/funnel/consent.js +55 -0
- package/dist/src/funnel/credit-errors.d.ts +31 -0
- package/dist/src/funnel/credit-errors.js +88 -0
- package/dist/src/funnel/credit-notifier.d.ts +44 -0
- package/dist/src/funnel/credit-notifier.js +74 -0
- package/dist/src/funnel/disclosure.d.ts +46 -0
- package/dist/src/funnel/disclosure.js +97 -0
- package/dist/src/funnel/enrollment.d.ts +36 -0
- package/dist/src/funnel/enrollment.js +64 -0
- package/dist/src/funnel/environment.d.ts +17 -0
- package/dist/src/funnel/environment.js +39 -0
- package/dist/src/funnel/event-transport.d.ts +51 -0
- package/dist/src/funnel/event-transport.js +199 -0
- package/dist/src/funnel/events.d.ts +42 -0
- package/dist/src/funnel/events.js +150 -0
- package/dist/src/funnel/index.d.ts +20 -0
- package/dist/src/funnel/index.js +20 -0
- package/dist/src/funnel/insights.d.ts +49 -0
- package/dist/src/funnel/insights.js +120 -0
- package/dist/src/funnel/local-signals.d.ts +15 -0
- package/dist/src/funnel/local-signals.js +68 -0
- package/dist/src/funnel/message-transport.d.ts +51 -0
- package/dist/src/funnel/message-transport.js +149 -0
- package/dist/src/funnel/messages.d.ts +55 -0
- package/dist/src/funnel/messages.js +160 -0
- package/dist/src/funnel/power-saver-notifier.d.ts +44 -0
- package/dist/src/funnel/power-saver-notifier.js +92 -0
- package/dist/src/funnel/precedence.d.ts +16 -0
- package/dist/src/funnel/precedence.js +85 -0
- package/dist/src/funnel/promo.d.ts +41 -0
- package/dist/src/funnel/promo.js +144 -0
- package/dist/src/funnel/rate-limit-notifier.d.ts +55 -0
- package/dist/src/funnel/rate-limit-notifier.js +102 -0
- package/dist/src/funnel/rotation.d.ts +19 -0
- package/dist/src/funnel/rotation.js +70 -0
- package/dist/src/funnel/state.d.ts +13 -0
- package/dist/src/funnel/state.js +52 -0
- package/dist/src/funnel/toggle-cooldown.d.ts +17 -0
- package/dist/src/funnel/toggle-cooldown.js +32 -0
- package/dist/src/funnel/types.d.ts +86 -0
- package/dist/src/funnel/types.js +26 -0
- package/dist/src/init/executor.js +9 -3
- package/dist/src/init/helper-refresh.d.ts +33 -2
- package/dist/src/init/helper-refresh.js +102 -12
- package/dist/src/init/helpers-generator.js +52 -0
- package/dist/src/init/statusline-generator.js +282 -116
- package/dist/src/services/daemon-autostart.js +28 -5
- package/dist/src/services/fable-harness.d.ts +39 -0
- package/dist/src/services/fable-harness.js +41 -0
- package/package.json +13 -4
- package/dist/src/ruvector/lattice-wasm.d.ts +0 -14
- package/dist/src/ruvector/lattice-wasm.js +0 -144
- package/plugins/ruflo-metaharness/.claude-flow/daemon-state.json +0 -178
- package/plugins/ruflo-metaharness/.claude-flow/daemon.pid +0 -1
- package/plugins/ruflo-metaharness/.claude-flow/data/pending-insights.jsonl +0 -5
- package/plugins/ruflo-metaharness/.claude-flow/logs/daemon.log +0 -43
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/audit_1783604774864_ozbujc_prompt.log +0 -19
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/audit_1783604774864_ozbujc_result.log +0 -108
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/audit_1783605513587_ulvmpb_prompt.log +0 -19
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/audit_1783605513587_ulvmpb_result.log +0 -209
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/audit_1783606368867_ahysui_prompt.log +0 -19
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/audit_1783606368867_ahysui_result.log +0 -192
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/optimize_1783604894861_v6n3ut_prompt.log +0 -14
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/optimize_1783604894861_v6n3ut_result.log +0 -66
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/optimize_1783605934532_9h8ikb_prompt.log +0 -14
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/optimize_1783605934532_9h8ikb_result.log +0 -68
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/testgaps_1783605134860_9jssz9_prompt.log +0 -14
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/testgaps_1783605134860_9jssz9_result.log +0 -69
- package/plugins/ruflo-metaharness/.claude-flow/logs/headless/testgaps_1783606516743_zftbaa_prompt.log +0 -14
- package/plugins/ruflo-metaharness/.claude-flow/metrics/backup.json +0 -7
- package/plugins/ruflo-metaharness/.claude-flow/metrics/codebase-map.json +0 -11
- package/plugins/ruflo-metaharness/.claude-flow/metrics/consolidation.json +0 -16
- package/plugins/ruflo-metaharness/.claude-flow/metrics/harness-loop.json +0 -83
- package/plugins/ruflo-metaharness/.claude-flow/metrics/performance.json +0 -67
- package/plugins/ruflo-metaharness/.claude-flow/metrics/security-audit.json +0 -191
- package/plugins/ruflo-metaharness/.claude-flow/metrics/test-gaps.json +0 -68
- package/plugins/ruflo-metaharness/.claude-flow/neural/stats.json +0 -6
|
@@ -72,6 +72,28 @@ const CWD = process.cwd();
|
|
|
72
72
|
const CACHE_FILE = path.join(os.tmpdir(), 'ruflo-statusline-cache-' + require('crypto').createHash('md5').update(CWD).digest('hex').slice(0, 8) + '.json');
|
|
73
73
|
const CACHE_TTL_MS = 60000;
|
|
74
74
|
|
|
75
|
+
// The promo/insight row is designed to rotate on a 20s cadence (funnel/
|
|
76
|
+
// rotation.ts's ROTATION_SLOT_MS / funnel/promo.ts's insight-slot check —
|
|
77
|
+
// duplicated here as a bare number since this generated script has no
|
|
78
|
+
// runtime import of the funnel module; keep in sync if that constant ever
|
|
79
|
+
// changes). The rotation slot is only ever (re)computed SERVER-SIDE inside
|
|
80
|
+
// the CLI subprocess this file shells out to — so a general 60s data cache
|
|
81
|
+
// (correct and necessary for #2337) silently made that 20s design
|
|
82
|
+
// unreachable: cache.fresh stayed true across 2-3 whole rotation slots,
|
|
83
|
+
// so the row visibly "didn't rotate" (user report). Fix: track promo
|
|
84
|
+
// freshness on its OWN, tighter clock — when it lags behind the current
|
|
85
|
+
// slot, fall through to a real CLI call even though the REST of the
|
|
86
|
+
// cached data (security/swarm/system) is still within CACHE_TTL_MS. This
|
|
87
|
+
// does not touch or regress #2337's fix; it only adds a narrower check.
|
|
88
|
+
const PROMO_ROTATION_SLOT_MS = 20000;
|
|
89
|
+
|
|
90
|
+
// Persistent last-known-good promo record. Lives outside the /tmp cache so it
|
|
91
|
+
// survives a full cache wipe / cache write race / CLI failure combo. Written
|
|
92
|
+
// every time we successfully render a promo; read as a last resort so the row
|
|
93
|
+
// never blinks out mid-session (was: 'promo shows then hides' bug report).
|
|
94
|
+
const PROMO_MEMO_FILE = path.join(os.homedir(), '.ruflo', 'statusline-promo.json');
|
|
95
|
+
const PROMO_MEMO_TTL_MS = 6 * 60 * 60 * 1000; // 6h — long enough to bridge any hiccup, short enough that a real disable takes effect fast.
|
|
96
|
+
|
|
75
97
|
// #2337: resolve an already-installed @claude-flow/cli (or ruflo) bin so we
|
|
76
98
|
// can invoke it directly via \`node\`. The previous version called
|
|
77
99
|
// \`npx --yes @claude-flow/cli@latest\` on every uncached render, which forces
|
|
@@ -79,18 +101,30 @@ const CACHE_TTL_MS = 60000;
|
|
|
79
101
|
// multiple concurrent Claude Code sessions this storms the host (reporter
|
|
80
102
|
// saw load average 40-65 on a 12-core box).
|
|
81
103
|
//
|
|
82
|
-
// Returns
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
104
|
+
// Returns EVERY existing bin/cli.js candidate, in preference order (project,
|
|
105
|
+
// monorepo, plugin marketplace, global node_modules including custom-prefix
|
|
106
|
+
// layouts like ~/.npm-global) — mirrors getPkgVersion()'s own path probing.
|
|
107
|
+
//
|
|
108
|
+
// Returns a list, not a single winner: \`fs.existsSync\` only proves a file is
|
|
109
|
+
// present, not that it actually runs. A marketplace/npx-cached install can
|
|
110
|
+
// exist on disk but be broken (observed in practice: a stale marketplace
|
|
111
|
+
// checkout whose dist/ imports a workspace package, '@claude-flow/cli-core',
|
|
112
|
+
// that isn't bundled there — every invocation throws ERR_MODULE_NOT_FOUND).
|
|
113
|
+
// Picking the first EXISTING path and never falling through meant a single
|
|
114
|
+
// broken install silently killed the promo row for the entire session (the
|
|
115
|
+
// CLI call always failed, so the memo could never refresh and eventually
|
|
116
|
+
// expired). getStatuslineData() now walks this whole list and tries the next
|
|
117
|
+
// candidate on failure, so one broken install can't permanently wedge it.
|
|
118
|
+
function resolveCliBinCandidates() {
|
|
119
|
+
const candidates = [];
|
|
86
120
|
try {
|
|
87
121
|
const home = os.homedir();
|
|
88
|
-
|
|
122
|
+
candidates.push(
|
|
89
123
|
path.join(home, '.claude', 'plugins', 'marketplaces', 'ruflo', 'bin', 'cli.js'),
|
|
90
124
|
path.join(CWD, 'node_modules', '@claude-flow', 'cli', 'bin', 'cli.js'),
|
|
91
125
|
path.join(CWD, 'node_modules', 'ruflo', 'bin', 'cli.js'),
|
|
92
126
|
path.join(CWD, 'v3', '@claude-flow', 'cli', 'bin', 'cli.js'),
|
|
93
|
-
|
|
127
|
+
);
|
|
94
128
|
try {
|
|
95
129
|
const binDir = path.dirname(process.execPath);
|
|
96
130
|
const globalModuleDirs = [path.join(binDir, '..', 'lib', 'node_modules'), path.join(binDir, 'node_modules')];
|
|
@@ -104,27 +138,54 @@ function resolveCliBin() {
|
|
|
104
138
|
);
|
|
105
139
|
}
|
|
106
140
|
} catch { /* ignore */ }
|
|
107
|
-
for (const p of candidates) {
|
|
108
|
-
if (fs.existsSync(p)) return p;
|
|
109
|
-
}
|
|
110
141
|
} catch { /* ignore */ }
|
|
111
|
-
return
|
|
142
|
+
return candidates.filter((p) => { try { return fs.existsSync(p); } catch { return false; } });
|
|
112
143
|
}
|
|
113
144
|
|
|
145
|
+
// Return { fresh, promoFresh, data }. 'fresh' is true only if within the TTL
|
|
146
|
+
// — but data is returned regardless (stale-while-revalidate). This lets us
|
|
147
|
+
// serve last known state (specifically the promo row) when the CLI is
|
|
148
|
+
// slow/unavailable, so users don't see the funnel row flicker in and out on
|
|
149
|
+
// cache expiry. 'promoFresh' is a SEPARATE, tighter check on the same clock
|
|
150
|
+
// as PROMO_ROTATION_SLOT_MS — see that constant's comment for why the promo
|
|
151
|
+
// row needs its own freshness bound distinct from the general 60s TTL.
|
|
114
152
|
function readCache() {
|
|
115
153
|
try {
|
|
116
154
|
if (fs.existsSync(CACHE_FILE)) {
|
|
117
155
|
const raw = JSON.parse(fs.readFileSync(CACHE_FILE, 'utf-8'));
|
|
118
|
-
if (raw && raw._ts &&
|
|
119
|
-
|
|
156
|
+
if (raw && raw._ts && raw.data) {
|
|
157
|
+
const age = Date.now() - raw._ts;
|
|
158
|
+
return { fresh: age < CACHE_TTL_MS, promoFresh: age < PROMO_ROTATION_SLOT_MS, data: raw.data };
|
|
120
159
|
}
|
|
121
160
|
}
|
|
122
161
|
} catch { /* ignore */ }
|
|
123
|
-
return null;
|
|
162
|
+
return { fresh: false, promoFresh: false, data: null };
|
|
124
163
|
}
|
|
125
164
|
|
|
126
165
|
function writeCache(data) {
|
|
127
166
|
try { fs.writeFileSync(CACHE_FILE, JSON.stringify({ _ts: Date.now(), data }), 'utf-8'); } catch { /* ignore */ }
|
|
167
|
+
// Also memoize any promo we saw so the row can survive future CLI hiccups.
|
|
168
|
+
try {
|
|
169
|
+
if (data && data.promo && typeof data.promo === 'object') {
|
|
170
|
+
fs.mkdirSync(path.dirname(PROMO_MEMO_FILE), { recursive: true, mode: 0o700 });
|
|
171
|
+
fs.writeFileSync(PROMO_MEMO_FILE, JSON.stringify({ _ts: Date.now(), promo: data.promo }), { encoding: 'utf-8', mode: 0o600 });
|
|
172
|
+
}
|
|
173
|
+
} catch { /* ignore */ }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Last resort: read a memoized promo (up to 6h old). Used when no cache and
|
|
177
|
+
// no CLI response is available — the row still renders, so users don't see
|
|
178
|
+
// the disclosure blink out. Returns null when the memo is absent, expired,
|
|
179
|
+
// or malformed. Never throws.
|
|
180
|
+
function readPromoMemo() {
|
|
181
|
+
try {
|
|
182
|
+
if (!fs.existsSync(PROMO_MEMO_FILE)) return null;
|
|
183
|
+
const raw = JSON.parse(fs.readFileSync(PROMO_MEMO_FILE, 'utf-8'));
|
|
184
|
+
if (raw && raw._ts && (Date.now() - raw._ts) < PROMO_MEMO_TTL_MS && raw.promo) {
|
|
185
|
+
return raw.promo;
|
|
186
|
+
}
|
|
187
|
+
} catch { /* ignore */ }
|
|
188
|
+
return null;
|
|
128
189
|
}
|
|
129
190
|
|
|
130
191
|
/**
|
|
@@ -135,37 +196,65 @@ function writeCache(data) {
|
|
|
135
196
|
* (missed the .swarm/memory.db → AgentDB path), computed dddProgress wrong,
|
|
136
197
|
* and only counted ADRs in v3/implementation/adrs/ (missed v3/docs/adr/).
|
|
137
198
|
*/
|
|
199
|
+
// Overlay the memoized promo onto any data object that's missing one. This is
|
|
200
|
+
// the safety net that keeps the funnel row rendered when an OLDER cached CLI
|
|
201
|
+
// version is picked up by npx — that older CLI succeeds but omits promo, so
|
|
202
|
+
// the JSON round-trips clean but without our row. We patch it back here.
|
|
203
|
+
function overlayMemoPromo(data) {
|
|
204
|
+
if (data && !data.promo) {
|
|
205
|
+
const memoPromo = readPromoMemo();
|
|
206
|
+
if (memoPromo) data.promo = memoPromo;
|
|
207
|
+
}
|
|
208
|
+
return data;
|
|
209
|
+
}
|
|
210
|
+
|
|
138
211
|
function getStatuslineData() {
|
|
139
|
-
const
|
|
140
|
-
|
|
212
|
+
const cache = readCache();
|
|
213
|
+
// Both clocks must be satisfied to skip the CLI call entirely: the general
|
|
214
|
+
// 60s TTL (#2337 — don't re-spawn the CLI on every rapid re-render) AND the
|
|
215
|
+
// tighter promo-rotation clock (this fix — don't let a still-fresh 60s
|
|
216
|
+
// cache silently freeze the promo/insight row across multiple 20s slots).
|
|
217
|
+
if (cache.fresh && cache.promoFresh) return overlayMemoPromo(cache.data);
|
|
218
|
+
|
|
219
|
+
// #2337: prefer an already-installed CLI bin via direct \`node\` invocation —
|
|
220
|
+
// no npx, no registry round-trip, no @latest re-resolve per render. Try
|
|
221
|
+
// every candidate that actually EXISTS (not just the first) before falling
|
|
222
|
+
// back to \`npx --prefer-offline @claude-flow/cli\` (no @latest); an existing
|
|
223
|
+
// but broken install (e.g. a stale marketplace checkout missing a bundled
|
|
224
|
+
// workspace dep) must not block trying the next one.
|
|
225
|
+
const cmds = resolveCliBinCandidates()
|
|
226
|
+
.map((bin) => '"' + process.execPath + '" "' + bin + '" hooks statusline --json 2>/dev/null')
|
|
227
|
+
.concat(['npx --prefer-offline @claude-flow/cli hooks statusline --json 2>/dev/null']);
|
|
228
|
+
for (const cmd of cmds) {
|
|
229
|
+
try {
|
|
230
|
+
const raw = execSync(
|
|
231
|
+
cmd,
|
|
232
|
+
{ encoding: 'utf-8', timeout: 8000, stdio: ['pipe', 'pipe', 'pipe'], cwd: CWD }
|
|
233
|
+
).trim();
|
|
234
|
+
// The CLI may emit preamble lines before the JSON — find the first '{'.
|
|
235
|
+
const jsonStart = raw.indexOf('{');
|
|
236
|
+
if (jsonStart === -1) throw new Error('no JSON in CLI output');
|
|
237
|
+
const data = JSON.parse(raw.slice(jsonStart));
|
|
238
|
+
// Overlay every block the CLI JSON omits (adrs/agentdb/tests/hooks/integration)
|
|
239
|
+
// with real local reads, so those segments reflect actual state instead of 0.
|
|
240
|
+
applyLocalOverlays(data);
|
|
241
|
+
overlayMemoPromo(data);
|
|
242
|
+
writeCache(data);
|
|
243
|
+
return data;
|
|
244
|
+
} catch { /* this candidate unavailable, broken, or timed out — try the next */ }
|
|
245
|
+
}
|
|
141
246
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{ encoding: 'utf-8', timeout: 8000, stdio: ['pipe', 'pipe', 'pipe'], cwd: CWD }
|
|
154
|
-
).trim();
|
|
155
|
-
// The CLI may emit preamble lines before the JSON — find the first '{'.
|
|
156
|
-
const jsonStart = raw.indexOf('{');
|
|
157
|
-
if (jsonStart === -1) throw new Error('no JSON in CLI output');
|
|
158
|
-
const data = JSON.parse(raw.slice(jsonStart));
|
|
159
|
-
// Overlay every block the CLI JSON omits (adrs/agentdb/tests/hooks/integration)
|
|
160
|
-
// with real local reads, so those segments reflect actual state instead of 0.
|
|
161
|
-
applyLocalOverlays(data);
|
|
162
|
-
writeCache(data);
|
|
163
|
-
return data;
|
|
164
|
-
} catch { /* CLI unavailable or timed out */ }
|
|
165
|
-
|
|
166
|
-
// Fallback: use local file probes only (will be less accurate, but non-zero
|
|
167
|
-
// when CLI is available and accurate when it's not).
|
|
168
|
-
return buildLocalFallback();
|
|
247
|
+
// Stale-while-revalidate: if we have any cached data, keep serving it so the
|
|
248
|
+
// funnel row doesn't flicker on CLI hiccups. Overlay fresh local reads for
|
|
249
|
+
// the segments the CLI JSON doesn't populate; the promo row survives.
|
|
250
|
+
if (cache.data) {
|
|
251
|
+
applyLocalOverlays(cache.data);
|
|
252
|
+
overlayMemoPromo(cache.data);
|
|
253
|
+
return cache.data;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Last resort: local probes + memo. Users still see the funnel row.
|
|
257
|
+
return overlayMemoPromo(buildLocalFallback());
|
|
169
258
|
}
|
|
170
259
|
|
|
171
260
|
// Count ADRs from BOTH known directories (fix for ruflo#2195: old code missed
|
|
@@ -565,7 +654,11 @@ function generateStatusline() {
|
|
|
565
654
|
const modelName = getModelFromStdin() || (d.user && d.user.modelName) || 'Claude Code';
|
|
566
655
|
const ctxInfo = getContextFromStdin();
|
|
567
656
|
const costInfo = getCostFromStdin();
|
|
568
|
-
|
|
657
|
+
// Named RUFLO_VERSION (not pkgVersion) so the #1951 regression guard
|
|
658
|
+
// (scripts/audit-fix-invariants.mjs) can pin its presence in the emitted
|
|
659
|
+
// .cjs artifact — without it the header silently reverts to a hard-coded
|
|
660
|
+
// "RuFlo V3.5" for anyone whose install doesn't match the first probe path.
|
|
661
|
+
const RUFLO_VERSION = getPkgVersion();
|
|
569
662
|
|
|
570
663
|
const progress = d.v3Progress || {};
|
|
571
664
|
const security = d.security || {};
|
|
@@ -601,8 +694,14 @@ function generateStatusline() {
|
|
|
601
694
|
|
|
602
695
|
const lines = [];
|
|
603
696
|
|
|
604
|
-
//
|
|
605
|
-
|
|
697
|
+
// 3-line design (fits Claude Code's visible statusline area — line 4+ gets
|
|
698
|
+
// replaced by the system guidance / input prompt line):
|
|
699
|
+
// Line 1 — Header (RuFlo version · git · model · timing · context · cost)
|
|
700
|
+
// Line 2 — Compressed ops (Swarm · Hooks · 🧠 · 💾 · Health)
|
|
701
|
+
// Line 3 — Promo / disclosure row (funnel surface, ADR-301)
|
|
702
|
+
|
|
703
|
+
// ─── Line 1: header ────────────────────────────────────────────
|
|
704
|
+
let header = c.bold + c.brightPurple + '▊ RuFlo V' + RUFLO_VERSION + ' ' + c.reset;
|
|
606
705
|
header += (coordinationActive ? c.brightCyan : c.dim) + '● ' + c.brightCyan + git.name + c.reset;
|
|
607
706
|
if (git.gitBranch) {
|
|
608
707
|
header += ' ' + c.dim + '│' + c.reset + ' ' + c.brightBlue + '⏇ ' + git.gitBranch + c.reset;
|
|
@@ -629,81 +728,148 @@ function generateStatusline() {
|
|
|
629
728
|
}
|
|
630
729
|
lines.push(header);
|
|
631
730
|
|
|
632
|
-
//
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const domainsColor = domainsCompleted >= 3 ? c.brightGreen : domainsCompleted > 0 ? c.yellow : c.red;
|
|
637
|
-
let perfIndicator;
|
|
638
|
-
if (hasHnsw && vectorCount > 0) {
|
|
639
|
-
const speedup = vectorCount > 10000 ? '12500x' : vectorCount > 1000 ? '150x' : '10x';
|
|
640
|
-
perfIndicator = c.brightGreen + '⚡ HNSW ' + speedup + c.reset;
|
|
641
|
-
} else if (patternsLearned > 0) {
|
|
642
|
-
const pk = patternsLearned >= 1000 ? (patternsLearned / 1000).toFixed(1) + 'k' : String(patternsLearned);
|
|
643
|
-
perfIndicator = c.brightYellow + '📚 ' + pk + ' patterns' + c.reset;
|
|
644
|
-
} else {
|
|
645
|
-
perfIndicator = c.dim + '⚡ target: 150x-12500x' + c.reset;
|
|
646
|
-
}
|
|
647
|
-
lines.push(
|
|
648
|
-
c.brightCyan + '🏗️ DDD Domains' + c.reset + ' ' + progressBar(domainsCompleted, totalDomains) + ' ' +
|
|
649
|
-
domainsColor + domainsCompleted + c.reset + '/' + c.brightWhite + totalDomains + c.reset + ' ' + perfIndicator
|
|
650
|
-
);
|
|
651
|
-
|
|
652
|
-
// Line 2: Swarm + Hooks + CVE + Memory + Intelligence
|
|
653
|
-
const swarmInd = coordinationActive ? c.brightGreen + '◉' + c.reset : c.dim + '○' + c.reset;
|
|
654
|
-
const agentsColor = activeAgents > 0 ? c.brightGreen : c.red;
|
|
655
|
-
const secIcon = secStatus === 'CLEAN' ? '🟢' : (secStatus === 'IN_PROGRESS' || secStatus === 'STALE') ? '🟡' : (secStatus === 'NONE' ? '⚪' : '🔴');
|
|
656
|
-
const secColor = secStatus === 'CLEAN' ? c.brightGreen : (secStatus === 'IN_PROGRESS' || secStatus === 'STALE') ? c.brightYellow : (secStatus === 'NONE' ? c.dim : c.brightRed);
|
|
731
|
+
// ─── Line 2: compressed ops ────────────────────────────────────
|
|
732
|
+
// Everything actionable in one dense row. Show only what changes what you
|
|
733
|
+
// do next; diagnostic detail moves to \`ruflo status --verbose\`.
|
|
734
|
+
const agentsColor = activeAgents > 0 ? c.brightGreen : c.dim;
|
|
657
735
|
const hooksColor = hooksEnabled > 0 ? c.brightGreen : c.dim;
|
|
658
736
|
const intellColor = intelligencePct >= 80 ? c.brightGreen : intelligencePct >= 40 ? c.brightYellow : c.dim;
|
|
737
|
+
const swarmInd = coordinationActive ? c.brightGreen + '◉' + c.reset + ' ' : c.dim + '○' + c.reset + ' ';
|
|
738
|
+
const cvesClean = totalCves === 0 || cvesFixed === totalCves;
|
|
739
|
+
const healthAllGreen = (secStatus === 'CLEAN' || secStatus === 'NONE') && cvesClean;
|
|
740
|
+
const opsParts = [];
|
|
741
|
+
opsParts.push(c.cyan + 'Swarm ' + swarmInd + agentsColor + activeAgents + c.reset + '/' + c.brightWhite + maxAgents + c.reset);
|
|
742
|
+
if (subAgents > 0) opsParts.push(c.brightPurple + '👥 ' + subAgents + c.reset);
|
|
743
|
+
opsParts.push(c.cyan + 'Hooks ' + hooksColor + hooksEnabled + c.reset + '/' + c.brightWhite + hooksTotal + c.reset);
|
|
744
|
+
opsParts.push(intellColor + '🧠 ' + intelligencePct + '%' + c.reset);
|
|
745
|
+
opsParts.push(c.brightCyan + '💾 ' + memoryMB + 'MB' + c.reset);
|
|
746
|
+
// Health: one glyph when green, terse copy when there's something to act on.
|
|
747
|
+
if (healthAllGreen) {
|
|
748
|
+
opsParts.push(c.brightGreen + '🛡 ✓' + c.reset);
|
|
749
|
+
} else {
|
|
750
|
+
if (secStatus === 'PENDING') opsParts.push(c.brightYellow + '🛡 scan pending' + c.reset);
|
|
751
|
+
else if (secStatus === 'IN_PROGRESS') opsParts.push(c.brightYellow + '🛡 scanning…' + c.reset);
|
|
752
|
+
else if (secStatus === 'STALE') opsParts.push(c.brightYellow + '🛡 scan stale' + c.reset);
|
|
753
|
+
else if (secStatus !== 'NONE' && secStatus !== 'CLEAN') opsParts.push(c.brightRed + '🛡 ' + secStatus.toLowerCase() + c.reset);
|
|
754
|
+
if (totalCves > 0 && cvesFixed < totalCves) {
|
|
755
|
+
const unfixed = totalCves - cvesFixed;
|
|
756
|
+
opsParts.push(c.brightRed + '⚠ ' + unfixed + ' CVE' + (unfixed === 1 ? '' : 's') + c.reset);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
lines.push(opsParts.join(' ' + c.dim + '·' + c.reset + ' '));
|
|
760
|
+
|
|
761
|
+
// ─── Line 3: promo / disclosure / insight ───────────────────────
|
|
762
|
+
// Colored by content kind so it reads as *what it is*, not as noise:
|
|
763
|
+
// disclosure → brightCyan (announcement / capability link)
|
|
764
|
+
// promotional → brightPurple (Cognitum sponsor spot)
|
|
765
|
+
// educational → yellow (a tip)
|
|
766
|
+
// insight → brightRed (environment/task-aware, local, actionable —
|
|
767
|
+
// distinct from remote content on purpose)
|
|
768
|
+
const promoRow = getPromoRow(d);
|
|
769
|
+
if (promoRow) {
|
|
770
|
+
const kind = (d && d.promo && d.promo.kind) || 'disclosure';
|
|
771
|
+
const promoColor = kind === 'promotional' ? c.brightPurple
|
|
772
|
+
: kind === 'educational' ? c.yellow
|
|
773
|
+
: kind === 'insight' ? c.brightRed
|
|
774
|
+
: c.brightCyan;
|
|
775
|
+
lines.push(promoColor + promoRow + c.reset);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Trailing blank line so Claude Code's input prompt gets breathing room
|
|
779
|
+
// instead of butting directly against the last statusline row.
|
|
780
|
+
return lines.join('\\n') + '\\n';
|
|
781
|
+
}
|
|
659
782
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
783
|
+
// ─── Funnel promo row (ADR-301) ─────────────────────────────────
|
|
784
|
+
// Allowlist for OSC 8 hyperlink targets. Ships in code (not in payload) so
|
|
785
|
+
// no message can smuggle a link to an unapproved host.
|
|
786
|
+
//
|
|
787
|
+
// The final destination hosts (cognitum.one / agentics.org) AND the
|
|
788
|
+
// click-redirect host are both allowlisted here: promo.ts routes every
|
|
789
|
+
// clickable message through the server-side click-redirect (ADR-311 §7)
|
|
790
|
+
// so promo_open + geo are captured before the 302 to the real target —
|
|
791
|
+
// so the OSC 8 link the renderer emits points at the redirect host, not
|
|
792
|
+
// the final destination directly.
|
|
793
|
+
const PROMO_LINK_HOSTS = new Set([
|
|
794
|
+
'cognitum.one', 'www.cognitum.one', 'docs.cognitum.one',
|
|
795
|
+
// agentics.org — OSS foundation, distinct sponsor domain. Kept in sync
|
|
796
|
+
// with messages.ts ALLOWED_URL_HOSTS.
|
|
797
|
+
'agentics.org', 'www.agentics.org',
|
|
798
|
+
// Click-redirect host (funnel.ruv.io once its TLS cert is live; the raw
|
|
799
|
+
// Cloud Run hostname is allowlisted too since event-transport.ts /
|
|
800
|
+
// message-transport.ts / attribution.ts currently point at it as a TEMP
|
|
801
|
+
// fallback while the domain mapping's cert provisions).
|
|
802
|
+
'funnel.ruv.io',
|
|
803
|
+
'cognitum-analytics-63rzcdswba-uc.a.run.app',
|
|
804
|
+
]);
|
|
805
|
+
|
|
806
|
+
// Emit OSC 8 hyperlinks unless the environment is known-broken. tmux mangles
|
|
807
|
+
// raw OSC 8 (see anthropics/claude-code#27047) — opt in via env if wrapped.
|
|
808
|
+
function terminalSupportsHyperlinks() {
|
|
809
|
+
if (process.env.CI || process.env.GITHUB_ACTIONS) return false;
|
|
810
|
+
if (process.env.TERM === 'dumb') return false;
|
|
811
|
+
if (/^(0|false|off|no)$/i.test(String(process.env.RUFLO_STATUSLINE_HYPERLINKS || ''))) return false;
|
|
812
|
+
if (process.env.TMUX && !process.env.RUFLO_STATUSLINE_HYPERLINKS_TMUX) return false;
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// Wrap a label in an OSC 8 hyperlink escape sequence. Falls back to the raw
|
|
817
|
+
// label whenever the URL is not an allowlisted https target, when the terminal
|
|
818
|
+
// can't render hyperlinks, or when parsing fails — a broken link must never
|
|
819
|
+
// leave a raw URL or stray escape in the statusline output.
|
|
820
|
+
function safeTerminalLink(label, url) {
|
|
821
|
+
if (!terminalSupportsHyperlinks()) return label;
|
|
822
|
+
if (typeof url !== 'string' || url.length === 0) return label;
|
|
823
|
+
let parsed;
|
|
824
|
+
try { parsed = new URL(url); } catch { return label; }
|
|
825
|
+
if (parsed.protocol !== 'https:') return label;
|
|
826
|
+
if (!PROMO_LINK_HOSTS.has(parsed.hostname)) return label;
|
|
827
|
+
const cleanLabel = String(label).replace(/[\\u0000-\\u001f\\u007f-\\u009f\\u202a-\\u202e\\u2066-\\u2069]/g, '');
|
|
828
|
+
if (cleanLabel.length === 0) return label;
|
|
829
|
+
const ESC = '\\u001b';
|
|
830
|
+
return ESC + ']8;;' + parsed.href + ESC + '\\\\' + cleanLabel + ESC + ']8;;' + ESC + '\\\\';
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
function getPromoRow(d) {
|
|
834
|
+
try {
|
|
835
|
+
if (process.env.CI || process.env.GITHUB_ACTIONS) return null;
|
|
836
|
+
if (/^(0|false|off|no)$/i.test(String(process.env.RUFLO_FUNNEL || ''))) return null;
|
|
837
|
+
const promo = d && d.promo;
|
|
838
|
+
if (!promo || typeof promo.text !== 'string') return null;
|
|
839
|
+
// Strip control chars / ANSI / bidi overrides and hard-cap length —
|
|
840
|
+
// promo copy is data and must never emit its own terminal sequences.
|
|
841
|
+
const text = promo.text
|
|
842
|
+
.replace(/[\\u0000-\\u001f\\u007f-\\u009f\\u202a-\\u202e\\u2066-\\u2069]/g, '')
|
|
843
|
+
.slice(0, 100)
|
|
844
|
+
.trim();
|
|
845
|
+
if (text.length === 0) return null;
|
|
846
|
+
// Split the label from the trailing "· manage: ruflo settings" instruction
|
|
847
|
+
// so each part gets styling that matches what it actually IS:
|
|
848
|
+
// 1. label — OSC 8 hyperlink + underline. A real clickable link.
|
|
849
|
+
// 2. "manage:" — dim. Just a connector word, no action implied.
|
|
850
|
+
// 3. "ruflo settings" — bold/bright, NOT underlined. This is a shell
|
|
851
|
+
// command the user TYPES, not a link they CLICK — a terminal can
|
|
852
|
+
// never safely execute a command from a click (that would let any
|
|
853
|
+
// server-served message run arbitrary commands), so we deliberately
|
|
854
|
+
// avoid the underline/OSC8 cues that imply "clickable". Bold+bright
|
|
855
|
+
// instead signals "this is the important bit — copy/type it".
|
|
856
|
+
// Educational tips have no manage tail and no URL — plain text through.
|
|
857
|
+
const manageIdx = text.indexOf(' · manage: ');
|
|
858
|
+
const label = manageIdx > 0 ? text.slice(0, manageIdx) : text;
|
|
859
|
+
const manageWord = manageIdx > 0 ? ' · manage: ' : '';
|
|
860
|
+
const command = manageIdx > 0 ? text.slice(manageIdx + manageWord.length) : '';
|
|
861
|
+
const UL_ON = '\\u001b[4m';
|
|
862
|
+
const UL_OFF = '\\u001b[24m';
|
|
863
|
+
const DIM_ON = '\\u001b[2m';
|
|
864
|
+
const DIM_OFF = '\\u001b[22m';
|
|
865
|
+
const BOLD_ON = '\\u001b[1m';
|
|
866
|
+
const BOLD_OFF = '\\u001b[22m';
|
|
867
|
+
const linked = promo.url ? UL_ON + safeTerminalLink(label, promo.url) + UL_OFF : label;
|
|
868
|
+
if (!command) return linked;
|
|
869
|
+
return linked + DIM_ON + manageWord + DIM_OFF + BOLD_ON + command + BOLD_OFF;
|
|
870
|
+
} catch (e) {
|
|
871
|
+
return null; // the promo row must never break the statusline
|
|
694
872
|
}
|
|
695
|
-
if (integration.hasDatabase) integStr += (integStr ? ' ' : '') + c.brightGreen + '◆' + c.reset + 'DB';
|
|
696
|
-
if (!integStr) integStr = c.dim + '● none' + c.reset;
|
|
697
|
-
|
|
698
|
-
lines.push(
|
|
699
|
-
c.brightCyan + '📊 AgentDB' + c.reset + ' ' +
|
|
700
|
-
c.cyan + 'Vectors' + c.reset + ' ' + vectorColor + '●' + vectorCount + hnswInd + c.reset + ' ' + c.dim + '│' + c.reset + ' ' +
|
|
701
|
-
c.cyan + 'Size' + c.reset + ' ' + c.brightWhite + sizeDisp + c.reset + ' ' + c.dim + '│' + c.reset + ' ' +
|
|
702
|
-
c.cyan + 'Tests' + c.reset + ' ' + testColor + '●' + testFiles + c.reset + ' ' + c.dim + '(~' + testCases + ' cases)' + c.reset + ' ' + c.dim + '│' + c.reset + ' ' +
|
|
703
|
-
integStr
|
|
704
|
-
);
|
|
705
|
-
|
|
706
|
-
return lines.join('\\n');
|
|
707
873
|
}
|
|
708
874
|
|
|
709
875
|
// JSON output — delegates to CLI for accuracy; caller can use --json flag
|
|
@@ -10,7 +10,17 @@
|
|
|
10
10
|
* own lock + checkExistingDaemon() — so a race spawns at most one survivor,
|
|
11
11
|
* - bounded lifetime: the daemon self-terminates on TTL/idle (12h default,
|
|
12
12
|
* RUFLO_DAEMON_TTL_SECS) — auto-start never means "runs forever",
|
|
13
|
-
* - opt-out: RUFLO_DAEMON_AUTOSTART=0|false|no disables it entirely,
|
|
13
|
+
* - opt-out: RUFLO_DAEMON_AUTOSTART=0|false|no disables it entirely, OR a
|
|
14
|
+
* project-local `daemon.autostart: false` in claude-flow.config.json —
|
|
15
|
+
* the file-based opt-out exists because the env var only reaches a
|
|
16
|
+
* process that inherited it. A non-interactive shell (cron, CI, many
|
|
17
|
+
* tool-invoked shells — bash skips ~/.bashrc entirely for these; see
|
|
18
|
+
* its own `case $- in *i*) ;; *) return;; esac` guard) never re-sources
|
|
19
|
+
* a shell rc file per invocation, so `export RUFLO_DAEMON_AUTOSTART=0`
|
|
20
|
+
* in one such shell does NOT persist to the next one. A project config
|
|
21
|
+
* field has no such gap — it's read fresh from disk every time,
|
|
22
|
+
* independent of which shell (or whether any shell at all) launched
|
|
23
|
+
* the command,
|
|
14
24
|
* - cheap: a pidfile read + a signal-0 liveness check on the fast path,
|
|
15
25
|
* - best-effort + silent: never blocks or fails a command.
|
|
16
26
|
*
|
|
@@ -41,8 +51,21 @@ export function isDaemonAlive(projectRoot) {
|
|
|
41
51
|
return false;
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
/** Project-local opt-out: `{ "daemon": { "autostart": false } }` in claude-flow.config.json. */
|
|
55
|
+
function autostartDisabledByProjectConfig(projectRoot) {
|
|
56
|
+
try {
|
|
57
|
+
const raw = fs.readFileSync(path.join(projectRoot, 'claude-flow.config.json'), 'utf-8');
|
|
58
|
+
const cfg = JSON.parse(raw);
|
|
59
|
+
return cfg?.daemon?.autostart === false;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false; // absent/malformed config = not disabled
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function autostartDisabled(projectRoot) {
|
|
66
|
+
if (/^(0|false|no|off)$/i.test(process.env.RUFLO_DAEMON_AUTOSTART ?? ''))
|
|
67
|
+
return true;
|
|
68
|
+
return autostartDisabledByProjectConfig(projectRoot);
|
|
46
69
|
}
|
|
47
70
|
const defaultSpawn = (projectRoot) => {
|
|
48
71
|
const cliBin = process.argv[1]; // the running bin/cli.js
|
|
@@ -60,8 +83,8 @@ const defaultSpawn = (projectRoot) => {
|
|
|
60
83
|
*/
|
|
61
84
|
export function ensureDaemonRunning(projectRoot, opts = {}) {
|
|
62
85
|
try {
|
|
63
|
-
if (autostartDisabled())
|
|
64
|
-
return { started: false, reason: 'disabled (RUFLO_DAEMON_AUTOSTART=0)' };
|
|
86
|
+
if (autostartDisabled(projectRoot))
|
|
87
|
+
return { started: false, reason: 'disabled (RUFLO_DAEMON_AUTOSTART=0 or project config)' };
|
|
65
88
|
// Only in an initialized project (avoid scaffolding a daemon in a random dir).
|
|
66
89
|
if (!fs.existsSync(path.join(projectRoot, '.claude-flow')) && !fs.existsSync(path.join(projectRoot, '.claude'))) {
|
|
67
90
|
return { started: false, reason: 'not a ruflo project' };
|
|
@@ -79,6 +79,36 @@ export interface ReflectResult {
|
|
|
79
79
|
diagnosis: string;
|
|
80
80
|
mutationHint: string;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* ADR-316 — a compact, STRUCTURAL-ONLY snapshot of the current coding
|
|
84
|
+
* session for the statusline's co-pilot advisor tip. Every field here
|
|
85
|
+
* mirrors funnel/insights.ts's LocalInsightContext — no raw prompt/command/
|
|
86
|
+
* file content, ever (same bar as ADR-309, applied to a different, opt-in
|
|
87
|
+
* data flow). The model sees only what's already surfaced structurally
|
|
88
|
+
* elsewhere in the statusline.
|
|
89
|
+
*/
|
|
90
|
+
export interface CoPilotSnapshot {
|
|
91
|
+
security?: {
|
|
92
|
+
status: string;
|
|
93
|
+
cvesFixed: number;
|
|
94
|
+
totalCves: number;
|
|
95
|
+
};
|
|
96
|
+
swarm?: {
|
|
97
|
+
activeAgents: number;
|
|
98
|
+
maxAgents: number;
|
|
99
|
+
coordinationActive: boolean;
|
|
100
|
+
};
|
|
101
|
+
gitUncommittedCount?: number;
|
|
102
|
+
contextPctUsed?: number;
|
|
103
|
+
}
|
|
104
|
+
/** A single proactive suggestion for the insight ticker. */
|
|
105
|
+
export interface CoPilotTip {
|
|
106
|
+
/** Short enough for a single statusline row (caller truncates further). */
|
|
107
|
+
headline: string;
|
|
108
|
+
/** One actionable sentence of extra detail. */
|
|
109
|
+
detail: string;
|
|
110
|
+
confidence: number;
|
|
111
|
+
}
|
|
82
112
|
/** Result of a raw claude spawn. */
|
|
83
113
|
export interface ClaudeSpawnResult {
|
|
84
114
|
stdout: string;
|
|
@@ -147,6 +177,15 @@ export declare class FableHarness {
|
|
|
147
177
|
* discipline as judgeBatch. Returns [] when no budget cap is configured.
|
|
148
178
|
*/
|
|
149
179
|
reflectFailures(items: ReflectItem[]): Promise<ReflectResult[]>;
|
|
180
|
+
/**
|
|
181
|
+
* ADR-316 — one proactive co-pilot tip from a structural session snapshot
|
|
182
|
+
* (no raw prompt/command/file content). A single-item "batch" — same
|
|
183
|
+
* budget/cwd/parsing discipline as judgeBatch/reflectFailures, just with
|
|
184
|
+
* exactly one call instead of a loop. Returns null when disabled, over
|
|
185
|
+
* budget, or the model found nothing worth surfacing (an empty verdict
|
|
186
|
+
* array is a valid, non-error answer here, not a parse failure).
|
|
187
|
+
*/
|
|
188
|
+
adviseCoPilotTip(snapshot: CoPilotSnapshot): Promise<CoPilotTip | null>;
|
|
150
189
|
/** Build the argv for a `claude -p` call. Exposed shape for testability. */
|
|
151
190
|
buildArgv(systemPrompt: string): string[];
|
|
152
191
|
/**
|
|
@@ -79,6 +79,17 @@ const REFLECT_SYSTEM_PROMPT = [
|
|
|
79
79
|
'Reply with ONLY a JSON array, one object per input id, no prose:',
|
|
80
80
|
'[{"id":"...","failureClass":"<short label>","diagnosis":"<one sentence>","mutationHint":"<actionable>"}]',
|
|
81
81
|
].join('\n');
|
|
82
|
+
const ADVISOR_SYSTEM_PROMPT = [
|
|
83
|
+
"You are RuFlo's co-pilot advisor: ONE short, proactive, actionable tip for",
|
|
84
|
+
'a developer, based on a single JSON object describing STRUCTURAL signals',
|
|
85
|
+
'from their current coding session (security scan status, swarm/agent',
|
|
86
|
+
'state, count of uncommitted files, context-window usage). There is no',
|
|
87
|
+
'prompt, command, or file content in the input — never assume or invent any.',
|
|
88
|
+
'If nothing in the snapshot genuinely warrants a tip, say so by returning',
|
|
89
|
+
'an empty array. Never pad with generic advice not grounded in the snapshot.',
|
|
90
|
+
'Reply with ONLY a JSON array containing zero or one object, no prose:',
|
|
91
|
+
'[] or [{"headline":"<=60 chars","detail":"<one actionable sentence>","confidence":0.0-1.0}]',
|
|
92
|
+
].join('\n');
|
|
82
93
|
// ── Default spawner (real CLI) ───────────────────────────────────────────────
|
|
83
94
|
/**
|
|
84
95
|
* Default `claude -p` spawner. Pipes the prompt via stdin (never as an argv
|
|
@@ -213,6 +224,24 @@ export class FableHarness {
|
|
|
213
224
|
}
|
|
214
225
|
return out;
|
|
215
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* ADR-316 — one proactive co-pilot tip from a structural session snapshot
|
|
229
|
+
* (no raw prompt/command/file content). A single-item "batch" — same
|
|
230
|
+
* budget/cwd/parsing discipline as judgeBatch/reflectFailures, just with
|
|
231
|
+
* exactly one call instead of a loop. Returns null when disabled, over
|
|
232
|
+
* budget, or the model found nothing worth surfacing (an empty verdict
|
|
233
|
+
* array is a valid, non-error answer here, not a parse failure).
|
|
234
|
+
*/
|
|
235
|
+
async adviseCoPilotTip(snapshot) {
|
|
236
|
+
if (!this.isEnabled())
|
|
237
|
+
return null;
|
|
238
|
+
if (this.spentUsd >= this.maxBudgetUsd)
|
|
239
|
+
return null;
|
|
240
|
+
const parsed = await this.runBatch(ADVISOR_SYSTEM_PROMPT, [snapshot]);
|
|
241
|
+
if (parsed.length === 0)
|
|
242
|
+
return null;
|
|
243
|
+
return normalizeCoPilotTip(parsed[0]);
|
|
244
|
+
}
|
|
216
245
|
/** Build the argv for a `claude -p` call. Exposed shape for testability. */
|
|
217
246
|
buildArgv(systemPrompt) {
|
|
218
247
|
const perCallCap = Math.max(0, this.maxBudgetUsd - this.spentUsd);
|
|
@@ -321,6 +350,18 @@ function normalizeReflect(raw) {
|
|
|
321
350
|
mutationHint: typeof o.mutationHint === 'string' ? o.mutationHint : '',
|
|
322
351
|
};
|
|
323
352
|
}
|
|
353
|
+
function normalizeCoPilotTip(raw) {
|
|
354
|
+
if (!raw || typeof raw !== 'object')
|
|
355
|
+
return null;
|
|
356
|
+
const o = raw;
|
|
357
|
+
if (typeof o.headline !== 'string' || !o.headline.trim())
|
|
358
|
+
return null;
|
|
359
|
+
return {
|
|
360
|
+
headline: o.headline.slice(0, 80),
|
|
361
|
+
detail: typeof o.detail === 'string' ? o.detail.slice(0, 200) : '',
|
|
362
|
+
confidence: clamp01(typeof o.confidence === 'number' ? o.confidence : Number(o.confidence)),
|
|
363
|
+
};
|
|
364
|
+
}
|
|
324
365
|
function tryParseJson(s) {
|
|
325
366
|
try {
|
|
326
367
|
return JSON.parse(s);
|