mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-09-14 14:01:28 +08:00
docs/chatgpt-plugin-reference
6 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
67ff9898c0 |
fix: resolve current runtime and verification defects for v3.32.36 (#2850)
* fix(cli): make runtime status and learning signals truthful * fix(metaharness): accept padded scan severities * fix(codex): make core hooks and status skill native * fix(security): make witness verification hermetic * fix(metrics): expose grounded learning outcomes * fix(hooks): deduplicate project and plugin events * fix(verification): preserve security audit payloads * fix(runtime): stabilize dual memory skills and MCP schemas * fix(cli): harden helper signing and reflexion health * test(release): align helper and container invariants * chore(release): prepare v3.32.36 * test(funnel): align gates with cold-start seed pool * fix(ci): document MCP environment precedence |
||
|
|
fac48c7b76 |
feat(memory): typed provenance in AgentDB (ADR-323, corrects dream-cycle #2804) (#2820)
* feat(memory): typed provenance in AgentDB (ADR-323) Corrects and implements the 2026-07-28 dream-cycle research proposal (PR #2804, closed as superseded) for typed memory provenance in AgentDB, addressing MemIR/MemSyco-Bench's "provenance-role collapse" and memory-induced sycophancy findings. The dream-cycle PR's proposed schema change targeted the wrong table (`vector_indexes`, which is per-namespace HNSW index metadata, not per-entry) and its filename collided with the already-merged `ADR-322-metaharness-flywheel-integration.md` (#2817) — both corrected here as ADR-323 against `memory_entries`, the real per-record table. - memory-initializer.ts: `provenance_type` column (user_claim | agent_output | system_observation | tool_result | unknown, default unknown) on `memory_entries`, migrated for existing DBs via `ensureSchemaColumns()`. `storeEntry()`/`searchEntries()` accept and validate `provenanceType`/`provenanceFilter`. - memory-bridge.ts: same wiring for the native better-sqlite3 AgentDB v3 path (`bridgeStoreEntry`/`bridgeSearchEntries`). - commands/memory.ts: `memory store --provenance <type>`, `memory search --provenance-filter <types>` (comma-separated, OR semantics). - mcp-tools/memory-tools.ts + cli-core/mcp-tools/memory-defs.ts: `memory_store`'s `provenance_type` param, `memory_search`'s `provenance_filter` param (kept in sync across both tool-def sets). Found and fixed during implementation: an initial design skipped the RaBitQ/HNSW acceleration paths entirely whenever a provenance filter was requested (neither carries provenance_type on their candidates). This reproducibly crashed the CLI process on exit (a libuv assertion on Windows) after printing correct results. Fixed by never skipping those paths — RaBitQ now fetches provenance_type in its existing per-candidate query, HNSW does one batched (namespace, key) lookup afterward — eliminating the crash across repeated runs. See ADR-323's "Implementation note" for detail. 7 new end-to-end tests (adr-323-memory-provenance.test.ts), including a repeated-run regression guard for the crash. Full existing memory suite re-verified with no regressions (one pre-existing, environment- specific #2558 test failure confirmed identical against unmodified main — better-sqlite3's native bridge is unavailable in this dev environment, unrelated to this change). Closes the follow-up from dream-cycle PR #2804 (closed as superseded). Co-Authored-By: claude-flow <ruv@ruv.net> * fix(memory): enforce provenance across retrieval paths * fix: document flywheel policy selection |
||
|
|
d0ac73d798 |
feat: Cognitum customer lifecycle funnel — ADR-301..310 + implementation (#2622)
* docs(adr): add ADR-301..305 — Cognitum customer lifecycle funnel New 300-series ADRs defining the ruflo → cognitum.one conversion funnel: - ADR-301: promotional status surface (rotating bottom status row; reaches existing installs via the ADR-174/177 signed helper auto-refresh channel) - ADR-302: one-time post-init capability enrollment prompt - ADR-303: contextual credit-exhaustion recovery/upgrade experience - ADR-304: optional local Meta LLM proxy (localhost:11435 → api.cognitum.one, OpenAI-compatible, local-first) - ADR-305: funnel overview, design principles, success + guardrail metrics Also indexes the new series in the ADR README. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_013FqZGy1zZ49JivKUSyqDKH * docs(adr): harden ADR-301..305 per review — trust and funnel-integrity gates - ADR-301: signed content boundaries — messages are schema-validated data only, length-bounded, URL-allowlisted, expiry-cached, and sanitized so copy can never emit terminal control sequences - ADR-302: split enrollment into four independent consent domains (account, proxy-install, telemetry, cloud-routing) with versioned consent receipts; acceptance authorizes auth login only - ADR-303: deterministic error taxonomy with explicit provider codes and a fail-closed classifier; no text-matching of provider messages - ADR-304: mandatory data-plane disclosure before cloud routing; proxy installs local-only, cloud routing off until explicit opt-in - ADR-305: attribution rules (event vocabulary, anonymous rotating funnel ID, 7/30-day attribution windows, 90-day retention, verifiable deletion), ordered gate hierarchy with hard integrity/ health/trust gates, automatic circuit breaker via the signed config channel, and an end-to-end acceptance test for existing installs Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_013FqZGy1zZ49JivKUSyqDKH * docs(adr): amend ADR-301/303/304/305, add ADR-306..310 — deployable funnel system Amendments: - ADR-301: existing-install disclosure gate (never promo before disclosure, once per user, decline disables all surfaces), 4:1 educational:promotional content ratio, 30-min repeat cap, no dark patterns, marquee off for screen readers/reduced motion, control precedence chain - ADR-303: Cognitum account service as sole credit authority (GET /v1/credits), canonical CreditErrorCode enum; only COGNITUM_CREDIT_EXHAUSTED triggers the funnel surface - ADR-304: retitled as the proxy *product* ADR; explicit relationship to the internal metallm dev-bridge (shared routing core, versioned compat layer, no implicit contract dependency); runtime deferred to ADR-307 - ADR-305: kill-switch claim corrected — release-bound vs opt-in freshness mechanisms with honest latencies, 24h revocation TTL, last-valid-signed-policy failure mode; normative control precedence (env > enterprise > user > default > remote); two measurement planes (CI release qualification enforces gates; production analytics measures adoption only) New ADRs: - ADR-306: Cognitum auth — PKCE + device flow, keychain-only refresh tokens, incremental scopes mapped 1:1 to consent domains - ADR-307: proxy runtime — Rust single binary, loopback bind + per-user token, platform user services, explicit lifecycle commands, signed no-self-update packaging - ADR-308: versioned public API contract — OpenAPI in both repos, idempotent event ingestion, normative client failure policy - ADR-309: governance — npm-policy commitments, GDPR/CCPA basis, constrained closed event schema with timestamp bucketing, content approval ownership - ADR-310: staged rollout phases 0-6, promotion criteria, three- package rollback discipline, CI gate matrix, final acceptance test Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_013FqZGy1zZ49JivKUSyqDKH * feat(funnel): implement ADR-301/302/303/305 funnel system with release gates Core module (v3/@claude-flow/cli/src/funnel/, local-only, zero network I/O): - precedence.ts: ADR-305 control chain (env > enterprise policy > user config > project config > package default > remote policy); a lower source can never re-enable a higher disable - disclosure.ts: ADR-301 existing-install disclosure gate (never_seen / disclosed_enabled / disclosed_disabled), 72h grace window before any message, decline disables all surfaces - messages.ts: signed-content boundaries: schema validation, 80-col grapheme-aware bound, exact-host URL allowlist, expiry, and hard drop of any C0/C1/ANSI/OSC/bidi sequence (drop, never repair) - rotation.ts: deterministic scheduler; promo only in 1-of-5 slots, 30-min repeat cap, educational fills all other slots - consent.ts: ADR-302 versioned receipts for 5 separate domains; grant AND decline recorded; stale policyVersion means re-ask, never carry forward - credit-errors.ts: ADR-303 CreditErrorCode enum + fail-closed classifier over machine-readable provider codes (never message text); only COGNITUM_CREDIT_EXHAUSTED fires the recovery surface, once per session - events.ts: ADR-309 closed event schema, daily timestamp buckets, bounded local queue, telemetry-consent-gated, opt-out deletes ID+queue - enrollment.ts + promo.ts: surface orchestrators Surface integrations: - hooks statusline --json now computes a promo field (all gates run server-side; failures never break the statusline) - generated statusline.cjs renders the bottom promo row with defense-in-depth re-sanitization + env/CI gates at render time; repo-root artifact regenerated (drift guard green) - init: one-time post-init capability enrollment (--no-signup flag, CI/non-TTY auto-skip, records only the account consent domain) - new command: ruflo funnel status|disable|enable|id - doctor gains a funnel component reporting effective state + deciding precedence source (enterprise audit verification) Contracts and gates: - v3/docs/api/cognitum-v1.openapi.yaml: ADR-308 v1 contract (8 endpoints, error taxonomy mirrored 1:1, normative failure policy, signed policy feed schema with 24h TTL cap) - .github/workflows/funnel-gates.yml: ADR-310 hard gates: invariant suite + runtime suppression proofs (promo in CI = 0, RUFLO_FUNNEL=0 suppression, opt-out persistence, non-interactive init) - __tests__/funnel.test.ts: 50 tests mapping 1:1 to the ADR-310 gate list Verified: cli-core/swarm/memory/neural/security/cli builds green; funnel suite 50/50; statusline-cost-display drift guard + runtime 8/8; init-wizard-bugs and p1-commands green; live smoke of the funnel lifecycle, statusline promo gates (fresh shows disclosure, CI shows nothing, RUFLO_FUNNEL=0 shows nothing, post-grace rotates educational), doctor component, and init under CI. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_013FqZGy1zZ49JivKUSyqDKH * fix(funnel-gates): mirror the green Build V3 setup (pnpm 8, frozen lockfile, workspace build) The runtime-suppression job failed on the PR because pnpm 9 with a filtered install resolved the bare-semver workspace deps (@claude-flow/cli-core etc.) from the npm registry instead of linking the workspace packages, so the cli tsc build could not find cli-core's dist. Copy the exact setup the passing Build V3 job in v3-ci.yml uses: pnpm/action-setup@v6 pinned to pnpm 8, pnpm install --frozen-lockfile over the full workspace, and a workspace-wide pnpm build. Also install pyyaml explicitly before the OpenAPI parse check. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_013FqZGy1zZ49JivKUSyqDKH * chore(helpers): pending-insights runaway-storage guard in intelligence.cjs Captured from the session's self-learning hook runtime: recordEdit now caps the append-only pending-insights file at ~512KB by keeping the most recent 2000 lines when consolidation has not drained it, so it can never grow unbounded. Non-fatal, statSync-per-edit cost only. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_013FqZGy1zZ49JivKUSyqDKH * feat(funnel): rotating sponsor disclosure, statusline redesign, auto-update ## Statusline (client render) Reorganized 4 rows by purpose (Architecture / Runtime / Health / AgentDB): - suppress zero/healthy fields; glyph-only for 🧠 memory % and 💾 RAM MB - drop DDD % duplicate, drop ADR denominator, drop opaque "◆ DB" marker - "Target 150x-12500x" → "Goal 150x-12500x" (plain language) - Health row hides on NONE; collapses to "✓ Security ✓ No CVEs" when clean, reads "N vulnerabilities" (not "CVE checks 0/3") on unfixed findings - kind-based row color: brightCyan for disclosure, brightPurple for promotional sponsor, yellow for educational — reads as *what it is* ## Funnel promo row (ADR-301/305/309) - Rotating disclosure: 3 copy variants on a deterministic 5-min slot with a shared Cognitum sponsor URL. Neutral framing — no "Sponsored by"/ "Powered by" (would read as advertising and lose OSS trust). - OSC 8 hyperlink wrapper: allowlist ships in renderer (cognitum.one hosts only), https-only, TMUX/CI/TERM=dumb suppression, kill-switch env var, defense-in-depth label re-sanitization. Broken URL / non-https / non-allowed host → plain label, never a raw escape. - Attribution: attributionUrl() decorates every outbound funnel link with utm_source=ruflo · utm_medium=statusline · utm_campaign=<kind> · utm_content=<msg-id>. Client-side link builder, ZERO runtime network call — API-down has no effect on render. `fid` (pseudonymous funnel ID) appended only under telemetry consent (ADR-309 privacy default). - Defense in depth: attributionUrl rejects non-https schemes at build time in addition to renderer's OSC 8 allowlist. ## Auto-update for existing installs - statusline.cjs added to CRITICAL_HELPERS + executor.ts + sign-helpers.mjs. - helper-refresh.ts fallback generates statusline.cjs when the installed package isn't resolvable. - Regen script scripts/regen-statusline-artifact.mjs keeps root artifact in lockstep with the generator (drift-guard test enforces). PUBLISH-TIME REQUIRED (only ruvnet-owned key can do): re-run scripts/sign-helpers.mjs with the Ed25519 signing key so helpers.manifest.json includes statusline.cjs's SHA-256. Without it, auto-refresh fail-closes (intended: tampered helper refuses install). ## Tests: 50 → 57 (+ statusline-cost-display drift guard passes) - parameterized invariant over every DISCLOSURE_TEXTS variant - sponsor URL shape (https + cognitum.one) - 5-min rotation determinism - attributionUrl: UTM shape, absent fid without consent, non-https rejection, malformed base URL verbatim - API-down design lock: promo.ts contains no fetch/https/XMLHttpRequest Co-Authored-By: RuFlo <ruv@ruv.net> * fix(statusline): promo row flicker — stale-while-revalidate cache The funnel promo row would appear on cache warm-up then vanish on the next render whenever the 60s cache TTL expired mid-session and the CLI call either failed, timed out, or was resolved to a bin that returned no promo. Root cause: getStatuslineData() fell through to buildLocalFallback() on CLI failure, and the fallback returned a stub object with no `promo` field. Fix: stale-while-revalidate on the /tmp cache. - readCache() now returns { fresh, data }. The TTL only decides whether the data is fresh; the payload comes back either way. - getStatuslineData(): fresh cache → return immediately. Else try the CLI. On CLI failure, if we have any prior cache data, re-apply local overlays and return it. Only if we've never had a good CLI response do we fall to buildLocalFallback(). Effect: the promo row survives CLI hiccups, timeouts, and cache-expiry mid-render. Live verified: cache backdated 5 min, all 3 CLI bins disabled — row still renders the last known disclosure. Test: pins the generator template shape so a future edit breaking the readCache freshness split or the stale-fallback path trips CI. 57 → 58. Co-Authored-By: RuFlo <ruv@ruv.net> * fix(statusline): 3-line design + persistent promo memo Two related fixes for observed live-session bugs. ## 3-line design (promo as line 1) Claude Code truncates the statusline past line 4 with the system-guidance / input-prompt line. The previous 6-row layout (header + separator + 4 purpose rows + promo) put the funnel row on line 6, so it was silently dropped by the viewport. New layout, exactly 3 lines: Line 1 — Promo / disclosure (funnel row, ADR-301 surface) Line 2 — Header (version · git · model · timing · ctx · cost) Line 3 — Compressed ops (Swarm · Hooks · 🧠 · 💾 · Health) Everything on the previous 4 individual rows is now on the ops line, dot- separated. Diagnostic detail (Domains, ADRs count, vectors, MCP count, DB marker) moves behind `ruflo status --verbose` per the earlier design discipline you documented ("Show healthy state only when it confirms readiness. Show zero values only when zero is actionable. Show failures immediately."). ## Persistent promo memo Even with stale-while-revalidate cache, promo would blink out when an older `@claude-flow/cli` cached by npx succeeded but returned JSON with NO promo field. Cause: the older version predates ADR-301, so its statusline JSON schema is missing our field. The cache path only fires when the CLI THROWS — a promoless success clean-writes. Fix: `~/.ruflo/statusline-promo.json` — a 6h-TTL memo of the last known good promo. Every successful render writes it. Every code path (fresh-cache / CLI-success / stale-cache / cold-fallback) calls `overlayMemoPromo(data)` which injects the memo IFF `data.promo` is missing. The funnel row now survives: - fresh cold cache + working CLI ← memo not needed - stale cache + CLI timeout ← stale-while-revalidate path - cache wiped + CLI down ← memo overlay (proven live) - working CLI, promoless response ← memo overlay (the new fix) Live proof: cache wiped, all 5 known `cli.js` bins renamed to `.disabled`, render still emits the 3-line output with promo on line 1. ## Tests: 58 → 60 in funnel suite, 66 → 68 total Pinned in the generator template: - 3-line ordering (promo push before header push before ops push) - PROMO_MEMO_FILE + readPromoMemo + overlayMemoPromo helpers exist - overlay is called on every code path (spot-checked by call count) Co-Authored-By: RuFlo <ruv@ruv.net> * fix(statusline): 3-line order — RuFlo header · ops · promo (top-to-bottom) Per user preference: RuFlo header must be line 1 (not the promo/disclosure row). Reordering the render: Line 1 — Header (▊ RuFlo · git · model · timing · ctx · cost) Line 2 — Ops (Swarm · Hooks · 🧠 · 💾 · Health) Line 3 — Promo (funnel disclosure / educational tip / sponsor) Promo stays within the visible 3-line viewport so Claude Code doesn't truncate it with the system-guidance line. Memo + stale-while-revalidate safety net from the previous commit is unchanged — promo remains visible even when the CLI returns a promoless response. Test invariant updated to pin the new order (header push < ops push < promo push in the generator source). 68/68 tests still pass. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(statusline): underline the promo label as a clickable CTA The sponsor / disclosure row currently reads as flat text — users don't know it's clickable. Two visual affordances added: 1. ANSI underline ([4m / [24m) on the label portion so terminals show it as a clickable link even when they don't render OSC 8 hyperlinks (a universal cue: underline = interactive text). Combined with the existing OSC 8 wrap, modern terminals get a real hyperlink; legacy terminals get a visual affordance. 2. The trailing "· disable: ruflo funnel disable" instruction now renders dim + non-underlined + outside the OSC 8 wrap. It reads as metadata ("here's how to turn it off") rather than as part of the link target (which would falsely imply that clicking anywhere on that text goes to Cognitum). Split happens on the exact anchor " · disable" — educational tips with no disable tail keep their whole text rendered plainly (no underline, no OSC 8, since they have no URL). Test locks the split-and-underline pattern in the generator template so a future refactor that reunifies the row trips CI. 60 → 61 funnel tests · 68 → 69 total. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(funnel): ADR-308 event transport + Cloud Function reference impl Phase 2 client-side telemetry + reference server. Wires the funnel event queue (v3/@claude-flow/cli/src/funnel/events.ts already exists) to the Cognitum analytics endpoint via a fail-silent HTTP batcher, plus an out-of-band credit-exhaustion notifier. ## Client transport (v3/@claude-flow/cli/src/funnel/event-transport.ts) ADR-308 contract: - POST /v1/events with Idempotency-Key header (UUIDv4 per batch) - Consent-gated: zero network activity when `telemetry` consent is off - Bounded batches (MAX_BATCH = 100), exponential backoff on failure, capped at 30x base interval (~30 min) - 4s POST timeout — telemetry never stalls the CLI - Rejects non-https endpoints inside the transport (defense in depth on top of the client-side allowlist) - Credit-exhaustion detection: 402 response OR body containing the exact ADR-303 machine-readable code triggers the notifier ## Credit notifier (v3/@claude-flow/cli/src/funnel/credit-notifier.ts) Persistent user-visible flag at ~/.ruflo/credit-status.json: - markCreditExhausted() — idempotent, stable `since` timestamp - clearCreditStatus() — stamps `cleared`, drops the exhausted flag - creditExhaustedNotice() — user-facing single line with humanized age - readCreditStatus() — inspector for status/tools ## Server reference (services/cognitum-analytics/) Cloud Function reference implementation: - index.js — POST /v1/events handler, Firestore writes to funnel_events + funnel_aggregates + funnel_credit + funnel_idem collections - package.json — Node 22 + functions-framework + Firestore SDK - deploy.sh — gcloud CLI deploy (gen2, us-central1, 402-on-cap ceiling) - sample-batch.json — fixture for smoke tests - README.md — layout, local run, deploy, verification DEPLOY IS HUMAN-DRIVEN. The autonomous loop does not run deploy.sh — that requires a live gcloud session with cloudfunctions.admin on cognitum-20260110 and is outside the hard-fence for automated actions. Everything up to the deploy is scripted; the human runs `./deploy.sh` when ready. ## Tests: 68 total funnel tests (61 → 68, +7 new) - Transport defaults (https + batch cap + backoff floor + timeout ceiling) - No-consent no-op (zero network activity) - Non-https endpoint rejected inside transport - markCreditExhausted idempotence (stable `since`) - clearCreditStatus stamps `cleared` - creditExhaustedNotice humanized age copy - Null return when not exhausted (no false surface) Co-Authored-By: RuFlo <ruv@ruv.net> * feat(funnel): funnel.ruv.io domain mapping for analytics endpoint The cognitum-analytics Cloud Function is now deployed on cognitum-20260110 and reachable at funnel.ruv.io/v1/events (Cloud Run domain mapping) as well as the raw Cloud Run URL. The client's DEFAULT_ENDPOINT points at the ruv.io subdomain so it: 1. survives Cloud Run hostname-hash changes on redeploy, 2. keeps analytics attribution on rUv's own domain (not cognitum.one, which is a separate product surface), 3. reads honestly to users: telemetry for the OSS CLI lives with the OSS author, not with the cognitum.one commercial product. DNS is a Cloudflare CNAME funnel.ruv.io → ghs.googlehosted.com, unproxied so Cloud Run terminates TLS directly. README documents the recreate-from-scratch flow using the CLOUDFLARE_API_TOKEN in Secret Manager on cognitum-20260110. Live infrastructure state: - Cloud Function cognitum-analytics deployed us-central1, revision 00001 - Firestore collections funnel_events / funnel_aggregates / funnel_credit / funnel_idem writing on first accepted batch - Smoke test at deploy time returned {"ok":true,"accepted":1} - Domain mapping created, DNS resolving, cert provisioning pending (Cloud Run polls hourly) Co-Authored-By: RuFlo <ruv@ruv.net> * docs(adr-311): funnel analytics — server-side split to dedicated repo Server implementation of the ADR-308 /v1/events endpoint has been extracted to its own repo: github.com/cognitum-one/ruflo-funnel-api Reasoning captured in ADR-311: - Commercial-side changes (rate limits, tenant model, BigQuery export) don't churn the OSS CLI PR history. - ADR-308 client contract remains the single source of truth for the wire format; the server can be forked or swapped without touching the CLI. - Server security surface (Firestore rules, IAM, key rotation) belongs with whoever runs the endpoint, not tangled with CLI release cadence. Also captures the concrete deployment decisions that came out of standing up the endpoint against cognitum-20260110: - Runtime: Cloud Function gen2, Node 22, us-central1, 256 MiB - Domain: funnel.ruv.io (Cloud Run mapping, Cloudflare CNAME unproxied) - Storage: 4 Firestore collections (funnel_events / _aggregates / _credit / _idem) with ADR-309 retention rules - Credit signal: HTTP 402 + body 'COGNITUM_CREDIT_EXHAUSTED' wires directly into the ADR-303 recovery surface via credit-notifier.ts services/cognitum-analytics/ in this repo is now a pointer README to the dedicated repo; the four source files were verbatim-committed as the initial commit there. Live-verified 8/8 API contract tests + Firestore writes across all 4 collections at time of adoption. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(funnel): remote-served message rotation + agentics.org sponsor + settings command Three linked changes to the funnel rotation surface. ## Remote-served messages (ADR-311 amendment) New client transport `message-transport.ts`: - GET https://funnel.ruv.io/v1/messages (raw: https://cognitum-analytics-63rzcdswba-uc.a.run.app/v1/messages) - 6h TTL local cache at ~/.ruflo/funnel-messages-cache.json - Every fetched message validated through ADR-301 isValidMessage() — schema, host allowlist, control-char strip, 80-col cap — before it can display - Best-effort: fetch failures leave cache intact; no network call blocks render (fire-and-forget from rotation.selectMessage) - Kill switch: RUFLO_FUNNEL_MESSAGES=0 or RUFLO_FUNNEL=0 - Bounded cache: ≤ 128 KiB, ≤ 200 messages - Non-https rejected at builder AND host allowlist (defense in depth) New pool merger `eligibleMessagesFromPools()` in messages.ts: - Remote pool authoritative (admin edits without a CLI release) - In-code pool fallback (cold starts, API-down, kill-switched) - Dedup by `id` — remote wins over in-code for the same id Rotation kicks a background refresh on every selectMessage() call so the first fresh render after CLI startup lands within seconds. ## Server side (cognitum-one/ruflo-funnel-api@521205a) - Added GET /v1/messages handler (single router by req.path in the same function; POST /v1/events unchanged) - Firestore collection funnel_messages with { id, class, text, url?, active } - Cache-Control: public, max-age=21600 for CDN + client caches - Firestore seeded with 23 initial messages (via seed-messages-rest.sh): 16 educational (ruflo tips + tricks) 4 promotional Cognitum 3 promotional agentics.org - Verified live: 200 OK, 23 messages, all 0 rejected by client pipeline ## Copy discipline + settings command - ALLOWED_URL_HOSTS + PROMO_LINK_HOSTS gain agentics.org (both wire layers need it for OSC 8 to render the link) - DISCLOSURE_TEXTS copy: "· disable: ruflo funnel disable" → "· manage: ruflo settings" — user-facing command surface no longer leaks the internal "funnel" term - New `ruflo settings` command (settings.ts) as a friendly wrapper over the existing funnel primitives: ruflo settings Overview + current state ruflo settings notices status Notices row state ruflo settings notices off Turn off (persistent) ruflo settings notices on Re-enable ruflo settings notices id Pseudonymous notices ID - getPromoRow split anchor moved from " · disable" → " · manage" (so only the linked label is OSC 8 wrapped, tail stays dim/plain) ## Tests: 68 → 76 (+8) - Every disclosure variant: no `\bfunnel\b`, contains `manage`, contains `ruflo settings`, ≤ 80 cols, Cognitum-attributed - Split anchor in generator: " · manage" (not " · disable") Co-Authored-By: RuFlo <ruv@ruv.net> * feat(funnel): impressions + click tracking + coarse geo (ADR-311 amend) Adds the analytics coverage that PR #2622's initial funnel work deferred: impressions, clicks, and coarse geo. Consent-gated end-to-end; nothing new about privacy — same closed vocabulary, same daily-bucket timestamps, same pseudonymous UUID discipline. Wired against the live Cloud Function on cognitum-20260110 + Firestore. ## Client — impression firing + click-tracked URLs - FunnelEventName vocabulary gains `promo_impression` + `promo_open` (matches server; ADR-305 amendment recorded in ADR-311 §6) - FunnelEvent schema gains optional `messageId` (≤ 64 chars, [a-z0-9-]) — the join key across impression → click → conversion - recordFunnelEvent() accepts an options object for `messageId` + `now` (backwards-compat with the Date positional form) - rotation.selectMessage() fires `promo_impression` for the selected message on every render — consent-gated, batched via existing transport - attribution.clickTrackedUrl() wraps promotional URLs in the server-side click-redirect so `promo_open` fires before the browser leaves. Disclosure/educational rows still use attributionUrl direct (no click tracking on disclosure) - promo.ts uses clickTrackedUrl for `msg.class === 'promotional'` ## Server (cognitum-one/ruflo-funnel-api@37f584b — deployed live) - KNOWN_EVENTS gains promo_impression + promo_open - validEvent() accepts optional messageId via MESSAGE_ID_RE allowlist - New `GET /v1/click/{messageId}?to=<https-url>` handler: - messageId validated against MESSAGE_ID_RE (prevents path-traversal or forged doc lookups) - `to` must be https AND host must be in CLICK_ALLOWED_HOSTS (cognitum.one + agentics.org variants — compiled in, not Firestore-editable; no open-redirect vector) - Coarse geo from CF-IPCountry / X-Appengine-Country (ISO-3166 alpha-2 country ONLY — never city, never lat/long; ADR-309 privacy invariant) - Firestore write: funnel_events doc + funnel_aggregates row keyed by (surface, event, day, release, messageId, country) - Firestore hiccup NEVER blocks the redirect — user intent > analytics - 302 with Cache-Control: no-store so aggregators see every click - Router extended to match /v1/click/{msgId} paths ## Verified live at commit | Test | Result | |---|---| | Click w/ good target + fake CF-IPCountry:US | 302 → cognitum.one; Firestore captured US | | Click w/ non-allowed target (evil.com) | 400 DISALLOWED_TARGET | | Click w/ http:// target | 400 DISALLOWED_TARGET | | Click w/ `..` path traversal | 405 (routed as method-not-allowed) | | POST promo_impression event | 200 accepted:1 | | POST promo_open event | 200 accepted:1 | | POST event w/ malformed messageId | 200 accepted:0 dropped:1 | Firestore verified: promo_open with `country: US`, `via: click-redirect`, `messageId: promo-cognitum-meta-llm`. Aggregate row present with `count: 1` keyed by messageId+country. ## Coverage summary (ADR-311 §8) - Impressions per message per day: `promo_impression` events + aggregates - Clicks per message per day: `promo_open` events + aggregates - CTR: ratio of the two above - Geo distribution: `country` field on `promo_open` - Conversions: existing `signup_opened` / `account_created` / `proxy_activated` - Notices disabled rate: existing `funnel_disabled` Zero PII, zero prompt content, zero paths — everything remains closed enum, allowlisted message id, ISO country code, or daily bucket. Co-Authored-By: RuFlo <ruv@ruv.net> * fix(statusline): style "ruflo settings" as bold command, not a dead link User feedback: "the area don't link to anything, manage: ruflo settings" — clarified they expected "manage: ruflo settings" to be clickable/actionable. It can't be a real link: a terminal has no safe way to execute a shell command from a click — that would let any server-served promo message run arbitrary commands on the user's machine. So instead of leaving it looking like inert plain text (which reads as broken/half-finished), it now gets its own visual treatment: ✨ <label, underlined + OSC 8 link> · manage: <ruflo settings, BOLD> - "manage: " stays dim (a connector word, no action implied) - "ruflo settings" renders BOLD, deliberately WITHOUT underline or OSC 8 — bold signals "this is the important bit, copy/type it" without the false affordance of "click me" that underline would carry Split changed from `text.indexOf(' · manage')` to the more precise `text.indexOf(' · manage: ')` so the exact command substring can be isolated for its own styling. getPromoRow() now returns three concatenated segments instead of two: label(+OSC8), dim connector, bold command. Test updated to assert: label sandwiched in UL_ON/UL_OFF + OSC8, connector in DIM_ON/DIM_OFF, command in BOLD_ON/BOLD_OFF, and — critically — that the command is NEVER wrapped in underline or safeTerminalLink (regression guard against accidentally making a "command" look clickable again). Verified via hex dump of the live render: ESC[1m immediately before "ruflo settings", ESC[22m immediately after, no ESC[4m or OSC 8 escape anywhere near it. Co-Authored-By: RuFlo <ruv@ruv.net> * fix(funnel): use raw Cloud Run URL until funnel.ruv.io cert lands funnel.ruv.io's TLS cert has not yet provisioned (Cloud Run domain mapping created 2026-07-10 18:33 UTC; Google's cert issuance is async and still pending as of this commit — verified: curl to funnel.ruv.io returns curl exit 35 / HTTP 000, raw Cloud Run URL returns 200). Every client fetch to messages/events/click was silently timing out (by design — fail-silent), so: - the remote 23-message pool never reached any installed CLI - message-transport's cache file never got created - rotation only ever showed the 3 static in-code disclosure variants All three endpoint defaults now point at the raw Cloud Run URL: https://cognitum-analytics-63rzcdswba-uc.a.run.app/v1/{events,messages,click} Marked TEMP in comments. Flip back to funnel.ruv.io once its cert is live (monitor: curl -o /dev/null -w '%{http_code}' https://funnel.ruv.io/v1/messages). ## Live verification performed this commit 1. Forced message-pool refresh — 23/23 messages accepted, 0 rejected 2. Selected messages across 8 consecutive 20s rotation slots — 8 distinct ids returned (7 educational + 1 promotional), confirming rotation moves 3. Impressions queued locally (8/8), consent-gated 4. Flushed queue to live server — 8/8 accepted, queue drained to 0 5. Fired the click-redirect for the selected promotional message with a forged CF-IPCountry: CA header — 302 to agentics.org with UTM+fid intact 6. Firestore confirmed both events landed: promo_impression messageId=promo-agentics-community promo_open messageId=promo-agentics-community country=CA via=click-redirect 7. Total promo_impression docs in funnel_events: 9 (8 new + 1 prior) Co-Authored-By: RuFlo <ruv@ruv.net> * feat(funnel): zero local promo content — fully remote-served, fail-closed Per explicit direction: no local promo content or URLs should ship in the CLI at all. This completes the ADR-311 remote-message architecture: disclosure text, educational tips, and promotional messages are now ALL served exclusively from the Cloud Function / Firestore feed. If the feed is unreachable and no prior fetch has succeeded, the promo row renders nothing — there is no local fallback content to degrade to. ## What changed - messages.ts: MESSAGES array emptied to []. Zero message text/URLs ship in the package. isValidMessage() extended to accept a new 'disclosure' class alongside educational/promotional, with an invariant that disclosure-class text must retain the exact " · manage: ruflo settings" tail (dropped, never repaired, if missing). - types.ts: FunnelMessageClass extended to 'educational' | 'promotional' | 'disclosure'. - disclosure.ts: removed the hardcoded DISCLOSURE_TEXTS/DISCLOSURE_TEXT/ DISCLOSURE_SPONSOR_URL constants and selectDisclosureText(). Replaced with selectDisclosureMessage() — deterministic 5-min-slot selection over the remote pool filtered to class==='disclosure', returning null when that pool is empty (cold start / API down). The disclosure state MACHINE (never_seen / disclosed_enabled / disclosed_disabled tracking) stays 100% local — that's app state, not promo content. - promo.ts: getFunnelPromo() now sources the disclosure row from selectDisclosureMessage(); returns null (fail-closed) when unavailable. Also wires the previously-defined-but-never-fired 'disclosure_shown' event so disclosure impressions are now tracked alongside promo_impression. - statusline-generator.ts: PROMO_LINK_HOSTS gains the click-redirect hosts (funnel.ruv.io + the raw Cloud Run hostname) — these are DIFFERENT from the final-destination hosts (cognitum.one/agentics.org); without this the renderer's independent host-allowlist check correctly refused to OSC-8- wrap click-tracked URLs, which was silently breaking every clickable link this session had just added. ## Server (cognitum-one/ruflo-funnel-api@698aa73 — deployed live) - All 16 educational tips now carry url: https://cognitum.one and a trailing 🔗 glyph (checked to fit the 80-col bound, max observed 78/78). - 3 disclosure-class messages seeded (disclosure-1/2/3), matching the copy this session iterated on, now server-authoritative instead of hardcoded. - promo.ts routes EVERY message with a url (not just class==='promotional') through the server click-redirect, so click tracking is uniform across the whole rotation. - Firestore funnel_messages collection: 26 total (16 educational + 7 promotional + 3 disclosure), all verified live via GET /v1/messages. ## Verified live end-to-end - GET /v1/messages returns 26 messages, 16/16 educational have url set. - Rendered statusline shows a real educational tip (edu-doctor) with a working OSC 8 hyperlink to the click-redirect, underline, 🔗ical suffix. - Click-redirect → 302 to cognitum.one with UTM + fid intact; Firestore captured both promo_impression and promo_open for the same messageId. - Fail-closed proven via test: selectMessage()/selectDisclosureMessage()/ getFunnelPromo() all return null when the remote cache is unseeded. ## Tests: 68 → 70 funnel (78 total incl. drift-guard), all green - New: "ships ZERO local messages" pins MESSAGES === []. - New: disclosure-class validation (manage tail required). - New: 3 fail-closed tests (selectDisclosureMessage / selectMessage / getFunnelPromo all null on unseeded cache). - Rewrote disclosure-variant + promo-orchestrator tests to seed a mock remote cache (matching message-transport.ts's on-disk shape) instead of asserting against removed local constants. Co-Authored-By: RuFlo <ruv@ruv.net> * docs(adr-312): usage-limit downtime prevention — researched, phased plan Direct instruction was to review Claude Code's actual CLI source (not just docs) to determine feasibility of detecting approaching/hit usage limits and surfacing a Cognitum meta-LLM proxy CTA as a downtime- prevention / session-extension mechanism. ## Research performed (grounded against @anthropic-ai/claude-code@2.1.107) Inspected /usr/lib/node_modules/@anthropic-ai/claude-code/cli.js directly. Findings: 1. A real internal rate-limit state object exists (module var, referred to in the ADR by its minified name since it will rename on any version bump): { status: allowed|allowed_warning|rejected, resetsAt (epoch sec), rateLimitType: five_hour|seven_day|seven_day_opus| seven_day_sonnet|overage, utilization (0-1 float), unifiedRateLimitFallbackAvailable, isUsingOverage }. 2. It's sourced from REAL Anthropic API response headers (anthropic-ratelimit-unified-status/-reset/-fallback/-{type}- utilization etc.) — confirmed via string match in the bundle. The exact "You've used N% of your session limit · resets HH:MM" banner text is generated from this exact object by a UI-only formatter. 3. This state is NOT exposed through any current extension point — checked exhaustively, empirically: - statusLine stdin JSON: confirmed absent (only model/context_window/ cost fields exist — verified against ruflo's own parser) - Hook events: 28 hook names exist, none confirmed to fire on rate-limit transitions - Debug logs: EMPIRICALLY checked an existing 11,424-line debug log at default level — zero occurrences of any rate-limit header - No CLI command / MCP resource surfaces it - The only consumer is an internal React hook wired to Claude Code's own TUI, unreachable from outside its process ## Decision: 3-phase plan - Phase 0 (buildable now): manual/self-reported flag — `ruflo settings notices rate-limited` — reusing the exact credit-notifier.ts pattern from ADR-303/311. Honest that this is user-reported, not detected. - Phase 1 (blocked on upstream): file a Claude Code feature request to expose the real signal via statusLine JSON or a new hook event. Explicitly does NOT recommend building against the current minified internal names — fragile, version-coupled, would silently break. - Phase 2 (once Phase 1 lands): wire the real signal into rotation with a priority override analogous to ADR-303's credit-exhaustion surface; new closed-vocabulary events rate_limit_warning_shown / rate_limit_exhausted_shown; same consent-gated click-tracking as every other promo message. No code changes in this commit — ADR only, per the explicit request. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(funnel): sponsored-downtime capacity via cognitum-one/meta-proxy (ADR-312/313) ADR-312 documents grounded research into detecting an approaching/hit Claude usage limit: direct inspection of the installed Claude Code CLI (v2.1.107) found the rate-limit state is populated from response headers (anthropic-ratelimit-unified-status/-reset/-fallback/-*-utilization) that are NOT exposed to hooks, the statusline JSON, or the debug log today (confirmed by grep — zero occurrences in an 11k-line debug log). Automatic detection is blocked on Anthropic exposing this state; documents a 3-phase plan (manual flag now, wait on upstream, auto-wire once available). ADR-313 implements Phase 0: a manually-set rate-limit flag (`ruflo settings notices rate-limited [--clear]`) that, once set, preempts normal promo rotation with a sponsored-capacity CTA — same precedent as ADR-303's credit-exhaustion override. Two states depending on consent: an enable CTA, or a quiet "active" confirmation once `ruflo proxy sponsor-enable --yes` has been run. Client-side (this commit): - funnel/rate-limit-notifier.ts — TTL'd flag read/write/clear, mirrors credit-notifier.ts's shape - funnel/promo.ts — priority-override hook, reachable only after the disclosure invariant is satisfied (ADR-301 compliance preserved) - commands/proxy.ts — sponsor-enable/disable/status/clear subcommands; writes both the consent receipt (source of truth) and a mirror flag into ~/.ruflo/proxy-config.toml, the file the Rust proxy binary reads - funnel/types.ts, consent.ts, events.ts — new 'sponsored-downtime' consent domain and sponsor_mode_enabled/disabled/capacity_exhausted events - 10 new tests (rate-limit notifier + priority override), 80/80 passing Server-side (separate private repo, already built/tested/pushed): cognitum-one/meta-proxy — Rust/axum binary routing local/cloud/sponsored data planes, per-user bearer token, loopback-only bind by default, never falls back to sponsored capacity implicitly. Verified end-to-end: the Rust binary correctly reads the same ~/.ruflo/proxy-config.toml this commit's `sponsor-enable` command writes. * docs(adr-313): addendum — proxy needed /v1/messages, not /v1/chat/completions Verification found the shipped meta-proxy scaffold spoke the wrong wire protocol for Claude Code (OpenAI chat-completions instead of the Anthropic Messages API Claude Code actually POSTs to). Fixed in cognitum-one/meta-proxy and verified live end-to-end with the real installed Claude Code CLI against the live apicompletions Cloud Run service. Documents the fix and the remaining gap (no automated sponsored-key provisioning yet). * docs(adr-313): addendum — fourth Passthrough plane preserves subscription usage Setting the env vars needed to reach the proxy at all previously meant giving up subscription-based auth entirely, all the time, not just when rate-limited. Documents the new default Passthrough plane (real Anthropic via the user's own OAuth token, read-only from Claude Code's own credentials file) and the live verification of all four planes switching correctly within one continuous session. * fix(statusline): trailing blank line so the input prompt gets breathing room The statusline's last row butted directly against Claude Code's input prompt with no visual separation. generateStatusline() now returns lines.join('\n') + '\n', so combined with console.log's own trailing newline the rendered output ends in exactly one blank line. Regenerated both committed .claude/helpers/statusline.cjs copies (root + package) so the drift-guard test stays in lockstep. Two new tests: a source-level pin on the generator (can't silently regress) and a runtime check on the actual rendered bytes (exactly one blank line — not zero, not two). * fix(helpers): re-sign manifest for the statusline trailing-newline fix The earlier statusline fix ( |
||
|
|
0bb7c4e3d7 |
fix: community bug batch — Windows path validation (#2352), trajectory-end feedback (#2351), init hooks settings (#2350) (#2355)
Three reproducible bugs reported by @grym3s, batched in the style of #2346. #2352 — hooks post-edit: Windows paths rejected, failure printed as [OK] - validatePath used the general SHELL_META set which includes `\`, so every absolute Windows path (E:\Repos\...) failed with "shell metacharacters". Claude Code hook events deliver absolute paths in tool_input.file_path, so all Windows users had silent learning loss. Path-specific PATH_SHELL_META drops `\` (still rejects ; & | ` $ etc.) and the sanitized output normalizes to forward slashes. - CLI post-edit action printed `Outcome recorded for ...` whenever the MCP call returned at all, ignoring `{success:false}`. Now checks result.success, surfaces the error, and exits non-zero. #2351 — trajectory-end: step-less feedback never distilled - When `trajectory-end` is called with `feedback` but no recorded steps, the feedback was persisted with the trajectory but never embedded as a searchable pattern — patternsExtracted always reported 0 and pattern-search never surfaced it. Step-less trajectories are the common case for LLM agents. Now routes feedback through the same bridge.bridgeStorePattern / store-fallback path that pattern-store uses, with modest default confidence (0.6 success / 0.4 failure) since step-less feedback hasn't been validated by execution evidence. Best-effort: distillation failures do not fail the trajectory-end call. #2350 — init hooks: subcommand writes no hooks block - settings-generator (#1744 fix) only emits the `hooks` block when `components.helpers` is true, because hooks point at the helper handler script. The `init hooks` subcommand was setting helpers:false, so the one subcommand whose purpose is "Initialize only hooks configuration" produced settings.json with no `hooks` key while reporting "N hooks enabled". Helpers must ship with hooks. Tests - v3/@claude-flow/cli/__tests__/validate-input-path-2352.test.ts (22 tests): pins Windows-path acceptance, POSIX-path acceptance, and rejection of shell metacharacters, traversal, empty/non-string/oversized input. - All existing validate-input, init-wizard-bugs, hooks-intelligence, and hooks-post-task tests still pass. |
||
|
|
5b71c7ac13 |
release(alpha.43+44): pin neural→sona@0.1.5, republish modules w/ standalone READMEs, add npm download badges everywhere (#2022)
This commit closes the chain started in |
||
|
|
ba92c56122 |
feat(cli-core): split cli into cli-core (lite) + cli (umbrella) — alpha.5 (#1764)
* feat(cli-core): scaffold @claude-flow/cli-core package + ADR-100 (#1748 Issue 3) First fire of the cli-core split (ADR-100). Establishes the package boundary, design doc, and skeleton entry point. Subsequent fires move memory + hooks source in, build, benchmark, and publish under the alpha tag. What lands in this fire: - v3/docs/adr/ADR-100-cli-core-split-lazy-load.md (Proposed) — full design rationale: the 1.8 MB / 999 files cold-cache problem from #1748 Issue 3, the cli-core ≤250KB target, the metapackage facade for the existing @claude-flow/cli, alpha-tag-then-promote versioning strategy, riskiest-assumption section, plan of work with 8-step roadmap, verification scaffold, migration path for plugin authors. - v3/@claude-flow/cli-core/package.json — alpha 3.7.0-alpha.0, type=module, bin=claude-flow-core, exports map for the surface, publishConfig tag=alpha (so npm publish defaults to alpha, never accidentally to latest before validation). - v3/@claude-flow/cli-core/README.md — what's included (memory + hooks), what's NOT (everything else — points at @claude-flow/cli), cold-cache verification snippet, ADR-100 cross-link. - v3/@claude-flow/cli-core/tsconfig.json — ES2022 + Node module resolution + strict (mirrors @claude-flow/cli config). - v3/@claude-flow/cli-core/src/index.ts — alpha-skeleton entry that responds to --version + --help and prints a "real surface lands in subsequent alphas" notice for any other command. This means the package can be npm-published immediately (non-empty surface) without breaking anything, and plugin authors can pin to it ahead of the actual feature landing. Next fire (per ADR-100 §"Plan of work"): Step 2 — move commands/memory.ts + commands/hooks.ts + mcp-tools/{memory,hooks}-tools.ts + output.ts + types.ts into cli-core/src/ Step 3 — build cli-core, smoke, fix any cross-package import misses Step 4 — update @claude-flow/cli's src/index.ts to re-export from cli-core + register lazy-loaded extras Step 5 — cold-cache benchmark old vs new, persist numbers Step 6 — bump versions to 3.7.0-alpha.1, npm publish --tag alpha Step 7 — PR + comment on #1748 with proof Do NOT promote alpha → latest until the cold-cache benchmark shows <5s and at least one external validator (the #1748 reporter is the target candidate) confirms MCP startup succeeds on a cold cache. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli-core): foundation surface (types, output, MCP tool types, validators) — ADR-100 Step 2 Second fire of the cli-core split. Foundation files copied from @claude-flow/cli with no internal dependencies on cli's heavier modules. Builds cleanly, dist is 136 KB / 20 files (vs cli's 9.6 MB / 777 files — 71× reduction). Files copied to v3/@claude-flow/cli-core/src/: - types.ts (CommandContext, Command, CommandResult, ParsedFlags) - output.ts (terminal formatting, tables, spinners, progress) - mcp-tools/types.ts (MCPTool, MCPToolInputSchema, MCPToolResult) - mcp-tools/validate-input.ts (input bounds + identifier guards) Deferred from foundation: - fs-secure.ts — depends on encryption/vault.ts (ADR-096 encryption- at-rest). Will be added if memory.ts/hooks.ts need it; for the pure foundation surface it's not load-bearing. Index.ts now exports a real foundation surface: import { CommandContext, MCPTool } from '@claude-flow/cli-core'; import { output, validateInput } from '@claude-flow/cli-core'; Programmatic smoke verified — exports include: CLIError, CommandNotFoundError, ConfigError, ValidationError, output (OutputFormatter, Progress, Spinner), validateInput (assertValid, validateIdentifier, validateAgentSpawn, ...) Binary --version and --help still work (alpha skeleton notice still shown for non-foundation commands until Step 3+ lands memory + hooks). Build: TS clean, no external errors. tsc --noEmit passes. Next fire (Step 3): copy mcp-tools/memory-tools.ts + mcp-tools/hooks-tools.ts (the MCP tool definitions — already use types.ts + validate-input.ts that are now in cli-core, so should build with minimal additional changes). Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli-core): foundation alpha.0 — defers memory/hooks tool deps to backend split (ADR-100 fire 3) Fire 3 attempted to copy memory-tools.ts + hooks-tools.ts into cli-core per the original plan and discovered both files have deep transitive ML dependencies that defeat the lite-bundle goal: memory-tools.ts → ../memory/memory-initializer.js (2830 LOC) → fs-secure.ts → encryption/vault.ts (ADR-096) hooks-tools.ts → 9 transitive imports across memory/{sona-optimizer, ewc-consolidation, memory-bridge} and ruvector/{moe-router, semantic-router, flash-attention, lora-adapter, enhanced-model-router} Pulling those in would balloon cli-core past the 250 KB target. Right architectural move (now documented in ADR-100 §"Discovery"): 1. Memory backend abstraction. cli-core defines a MemoryBackend interface and ships a JsonMemoryBackend (no SQLite/HNSW/ONNX, just a JSON file at .swarm/memory.json — the foundation case). cli ships SqliteHnswMemoryBackend (the existing heavy implementation) that swaps in via env or import map. 2. Tool-definition / handler split. MCPTool definitions (name, description, inputSchema — pure data, ~10 KB) go in cli-core. Handler implementations (the actual code) stay in cli's full module tree, accessed via dynamic-import only at request time. This is more work than fire 1 anticipated — 4-6 additional fires instead of the original "next fire" estimate. Net call: ship the foundation alpha.0 NOW (proves publish pipeline, gives plugin authors type imports + output utility); land backend abstraction in alpha.1 and tool/handler split in alpha.2. What's actually in alpha.0 (this commit): Foundation-only surface, 136 KB / 20 files dist, TS clean: - types.ts (CommandContext, Command, ParsedFlags, ...) - output.ts (terminal formatting, tables, spinners) - mcp-tools/types.ts (MCPTool, MCPToolInputSchema, ...) - mcp-tools/validate-input.ts (input validators) Programmatically: import { CommandContext, MCPTool, output, validateInput } from '@claude-flow/cli-core'; The Plan-of-work table in ADR-100 is updated with the new step ordering, status markers, and the Discovery section explaining why steps 3+4 changed shape. Co-Authored-By: RuFlo <ruv@ruv.net> * bench(cli-core): cold-cache 38× faster than @claude-flow/cli — alpha.0 published (ADR-100) Persisted cold-cache benchmark proving the cli-core split fixes #1748 Issue 3's 30s MCP-startup timeout race: | Package | Cold | Warm | Files | Packed | | @claude-flow/cli-core@3.7.0-alpha.0 | 671 ms | 361 ms | 22 | 22 KB | | @claude-flow/cli@3.6.30 | 25.5 s | 623 ms | 999 | 1.8 MB | Results: - 38× cold-cache speedup (25.5s → 0.67s) - 80× packed-size reduction (1.8 MB → 22.3 KB) - 45× file-count reduction (999 → 22) - Fits comfortably under Claude Code's 30s MCP-startup timeout (cli is borderline at 25.5s — slow networks race and lose) Caveats (also in the JSON's caveats array): - cli-core@alpha.0 is foundation-only — types + output + MCP-tool types + validate-input. Does NOT yet expose memory/hooks command surface. ADR-100 §Discovery documents the tool-def/handler split needed for alpha.1 + alpha.2. - The benchmark proves the COLD-CACHE thesis (smaller bundle = under timeout). It does NOT yet prove memory/hooks parity at speed — that requires the backend abstraction work in alpha.1. Persisted to v3/docs/benchmarks/cli-core-cold-cache.json so future regressions are visible. Published: @claude-flow/cli-core@3.7.0-alpha.0 with --tag alpha (latest also points to alpha.0 since this is the first publish). Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli-core): alpha.1 — MemoryBackend abstraction + working memory CLI (ADR-100 fire 4) The hard problem from ADR-100 §Discovery — memory-tools.ts had a 2830-LOC ML chain that defeated the lite-bundle goal. This commit implements the backend abstraction so cli-core can ship its own lite memory implementation without pulling sql.js / HNSW / ONNX. What lands in alpha.1: src/memory/backend.ts (~150 LOC) Defines MemoryBackend interface — store / retrieve / search / list / delete / stats. MemoryEntry, MemorySearchResult, StoreOptions / SearchOptions / ListOptions types. Contract every backend (lite + heavy) implements. src/memory/json-backend.ts (~190 LOC) JsonMemoryBackend — implements the full interface against a JSON file (default .swarm/memory.json, override CLAUDE_FLOW_MEMORY_PATH). Atomic writes via tmp file + rename. TTL handling, namespace isolation, tag filtering, substring search. NO SQLite, NO HNSW, NO ONNX — pure JSON, no transitive ML deps. src/commands/memory.ts (~210 LOC) `memory <subcommand>` CLI dispatcher wrapping the backend. Subcommands: store / retrieve / get / list / search / delete / rm / stats. Every subcommand supports --format=json for piping to jq, --namespace, and the relevant per-op flags (--tags, --ttl, --upsert, --limit, --threshold, --path). src/index.ts (updated) Re-exports MemoryBackend interface + JsonMemoryBackend impl. Bin entry now dispatches `memory <args>` to runMemoryCommand. Live verified end-to-end (smoke): ✓ store hello world → ✓ stored default::hello ✓ store --namespace=test foo "bar baz" --tags=a,b → stored test::foo ✓ retrieve hello → "world" ✓ list → 2 entries (default::hello + test::foo) ✓ search bar --format=json → returns test::foo with score ✓ stats → backend=json, 2 entries, 656 bytes ✓ delete hello → deleted ✓ list after delete → only test::foo remains Cold-cache via npm @ 3.7.0-alpha.1: rm -rf ~/.npm/_npx; npx @claude-flow/cli-core@alpha memory store ... → 2.71s wall-time Compare to @claude-flow/cli@3.6.30: 25.5s cold cache. **Cold-cache speedup with alpha.1's full memory surface: 9.4× faster.** (alpha.0's foundation-only was 38× — alpha.1 is heavier because it has the actual memory commands now, but still well under the 30s timeout.) dist size: 200 KB / 32 files (vs cli's 9.6 MB / 777 files = 48× reduction). Substrate trade-offs (honest): - Search degrades to substring matching (no semantic / vector). For real semantic search install @claude-flow/cli@alpha (heavy backend). The MemoryBackend interface is identical so call sites don't change. - Concurrent writers across processes: last-writer-wins. Acceptable for single-developer plugin workloads, not safe under high contention. - Atomic write via tmp+rename — no in-flight reader sees half-written JSON. exports map updated: '@claude-flow/cli-core/memory' → backend interface '@claude-flow/cli-core/memory/json-backend' → JsonMemoryBackend impl '@claude-flow/cli-core/commands/memory' → CLI dispatcher Published: @claude-flow/cli-core@3.7.0-alpha.1 with --tag alpha. Next fire (alpha.2): tool-def/handler split for hooks-tools.ts. Pure MCPTool definitions move to cli-core; handlers stay in @claude-flow/cli behind dynamic-import boundaries. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli-core): alpha.2 — MCP tool defs (memory + hooks subset, def-only) (ADR-100 fire 5) Tool-definition / handler split landed. cli-core now ships pure-data MCPTool definitions for the memory_* (6) + hooks_* (7) families an MCP server can register with `tools/list`. Handlers stay in @claude-flow/cli — dynamic- imported only at request time. What lands in alpha.2: src/mcp-tools/memory-defs.ts (~115 LOC) 6 memory_* MCPTool definitions: memory_store, memory_retrieve, memory_search, memory_delete, memory_list, memory_stats Descriptions match the 3.6.30 sharpening (#1748 Issue 4 — "Use when native X is wrong because Y" framing). src/mcp-tools/hooks-defs.ts (~120 LOC) 7 hooks_* MCPTool definitions (most-used subset): hooks_route, hooks_pre-task, hooks_post-task, hooks_post-edit, hooks_model-outcome, hooks_model-route, hooks_explain Remaining 30 hooks tools stay in @claude-flow/cli (they pull in sona-optimizer, ewc-consolidation, ruvector/* heavy ML deps). If a session needs one of those, fall through to cli@alpha. src/mcp-tools/index.ts (~25 LOC) Re-exports memoryToolDefs + hooksToolDefs + allToolDefs (concatenation, suitable for a single tools/list registration). src/index.ts (updated) Re-exports MCPToolDef type + the def arrays so consumers can `import { allToolDefs } from '@claude-flow/cli-core'`. package.json (updated) Version 3.7.0-alpha.1 → 3.7.0-alpha.2 New exports: ./mcp-tools, ./mcp-tools/memory-defs, ./mcp-tools/hooks-defs Live verified end-to-end via npm: rm -rf ~/.npm/_npx npx -y @claude-flow/cli-core@alpha --version → 2.3s cold Programmatic import: import { memoryToolDefs, hooksToolDefs, allToolDefs } from '@claude-flow/cli-core'; // memoryToolDefs.length: 6 // hooksToolDefs.length: 7 // allToolDefs.length: 13 dist: 256 KB / 44 files (still 38× smaller than cli's 9.6 MB / 777). Why this matters (the lazy-load thesis): An MCP server backed by cli-core can advertise these 13 tools to a Claude session in <2.5s on a cold cache (vs cli's 25s race). The model sees the tools listed, picks one, and the handler can be dynamic-imported from cli at request time — paying the heavy cost ONLY when actually used. This is the structural fix #1748 Issue 3 asked for. Next fire (alpha.3): wire dynamic-import handlers in @claude-flow/cli's metapackage so an MCP server using cli-core's defs can dispatch a real memory_search invocation through to the heavy backend on demand. Co-Authored-By: RuFlo <ruv@ruv.net> * docs(cli-core): MIGRATION.md + scan helper for plugin authors (ADR-100 fire 6) alpha.2 ships functional memory CLI + 13 MCPTool defs. This commit makes the alpha actually usable today by plugin authors who want to opt into the cold-cache speedup. What lands: v3/@claude-flow/cli-core/MIGRATION.md Concrete diff + env-flag pattern for switching plugin Bash blocks from @claude-flow/cli@latest to @claude-flow/cli-core@alpha. Tables of what's safe to migrate today (memory ops) vs what's deferred (hooks, neural, agent/swarm). Storage backend coexistence section documents the SQLite/HNSW vs JSON file split honestly. Reverting instructions. Adoption sequence. v3/@claude-flow/cli-core/README.md Adds prominent MIGRATION.md pointer in the documentation list + issue #1760 cross-reference for alpha tracking. v3/@claude-flow/cli-core/scripts/migrate-plugin-call-sites.mjs Conservative scanner — walks a plugin dir, finds @claude-flow/cli invocations, classifies each as [review] (memory ops, safe to migrate by hand) vs [skip] (hooks/neural/agent/swarm — deferred). Deliberately does NOT auto-rewrite (regex over Node argv arrays isn't safe enough to ship without human review). Exit code 1 when call sites need review; exit 0 only when fully clean. Smoke run on cost-tracker (the canonical heavy CLI consumer): 6 scripts flagged for memory migration: track.mjs, budget.mjs, conversation.mjs, export.mjs, federation.mjs, summary.mjs 1 script correctly skipped (outcome.mjs uses hooks — defer to alpha.3+) Migration recommendation summarized in MIGRATION.md: const cliPkg = process.env.CLI_CORE === '1' ? '@claude-flow/cli-core@alpha' // lite — JSON backend, ~2s cold : '@claude-flow/cli@latest'; // heavy — SQLite/HNSW, ~25s cold Plugin authors can opt in via env var, A/B test, then flip the default once they're confident the substring-search regression doesn't bite their use case. Honest trade-offs documented in MIGRATION.md: - Storage file changes (.swarm/memory.db → .swarm/memory.json) - Search degrades to substring (no semantic / vector) - Hooks operations not yet migrable (alpha.3+) - Storage convergence planned for alpha.3 or later No version bump in this commit (docs + scripts only). cli-core stays at 3.7.0-alpha.2. Next fire (alpha.3): wire dynamic-import handlers in @claude-flow/cli's metapackage so an MCP server using cli-core's defs can dispatch a real tools/call invocation through to the heavy backend on demand. After that, cost-tracker's hooks call sites become migrable too. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli-core): alpha.4 — bin-shim isMain fix + flag-form CLI compat + cost-tracker integration (ADR-100 fire 7) End-to-end validation. cli-core@alpha.4 is now actually usable from plugin scripts with the env-flag pattern. Two real bugs caught + fixed during integration testing. Bug 1: bin-shim isMain detection broken (alpha.0–alpha.2) Earlier alphas used: process.argv[1]?.endsWith('cli-core/dist/src/index.js') This fails when invoked via `npx @claude-flow/cli-core@alpha` because npx exposes the binary through a bin-shim symlink at ~/.npm/_npx/<hash>/node_modules/.bin/claude-flow-core, NOT the underlying dist/src/index.js. The endsWith check missed it, isMain returned false, the bin entry silently no-op'd. alpha.0/.1/.2 were effectively unusable as published binaries — --version returned empty, memory store wrote nowhere, exit 0. Fix: ESM-standard isMain via realpathSync comparison. argv[1] symlink-resolves to dist/src/index.js, which equals fileURLToPath(import.meta.url). Fallback heuristic for fringe cases (regex on argv[1] for claude-flow-core / cli-core/dist/). Bug 2: memory store argument-parsing incompatibility cli-core's memory store only accepted positional `<key> <value>` args; @claude-flow/cli accepts `--key K --value V` flag form too. Plugin scripts (track.mjs, summary.mjs, etc.) use the flag form, so cli-core was a non-drop-in replacement. Fix: accept BOTH forms. Same change applied to retrieve, get, delete, rm subcommands. Usage messages updated to show both. Cost-tracker integration (proves the alpha works end-to-end): plugins/ruflo-cost-tracker/scripts/track.mjs gains the env-flag pattern from MIGRATION.md: const cliPkg = process.env.CLI_CORE === '1' ? '@claude-flow/cli-core@alpha' // lite — JSON, ~2s cold : '@claude-flow/cli@latest'; // heavy — SQLite/HNSW, ~25s cold Live verified end-to-end on this session's data: rm -rf ~/.npm/_npx CLI_CORE=1 CLAUDE_FLOW_MEMORY_PATH=/tmp/test.json \ node plugins/ruflo-cost-tracker/scripts/track.mjs Result: | Persisted | `cli-core-test:session-1dba3b8c-1f1f-4718-bab4-9ffba5f49578` | /tmp/test.json: backend=json, 1 entry, $2578.69 total persisted CLI_CORE unset still uses cli@latest — backward compatible. Why this matters: alpha.0–alpha.3 *published* but the bin was broken; nobody pulling the alpha could actually run it. alpha.4 is the FIRST alpha that genuinely works through `npx`. The cold-cache benchmark numbers from fire 3 (38× speedup) were directionally right but under-reported because alpha.0's binary just exited 0 immediately — the real work was being skipped. With alpha.4's working bin, every operation is real. Published: @claude-flow/cli-core@3.7.0-alpha.4 with --tag alpha. Branch: feat/cli-core-split, 8 commits. Next fire: extend the env-flag pattern to remaining cost-tracker scripts (budget, summary, conversation, federation, export); validate each end-to-end; then the metapackage refactor for @claude-flow/cli. Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cost-tracker): apply CLI_CORE env-flag to all 5 remaining scripts Extends fire 7 (track.mjs) to budget/summary/conversation/federation/export. All cost-tracker scripts now route to @claude-flow/cli-core@alpha when CLI_CORE=1 is set, dropping cold-cache wall-time from ~25s to ~2s per spawnSync. Falls back to the heavy @claude-flow/cli@latest by default. Validated end-to-end against cli-core@3.7.0-alpha.4: - budget set/get/check (markdown + JSON) - summary --format json (cross-namespace list + retrieve) - conversation --format md (per-session timeline) - federation --format json (empty + non-empty paths) - export --prometheus (textfile-collector exposition) The 13 call sites all use a module-scoped CLI_PKG constant so the package resolution happens once at startup, not per spawn. Refs ADR-100, #1748 Issue 3, #1760 Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli-core): alpha.5 — add mcp-tools/types + validate-input subpath exports Adds two new package.json export entries: - ./mcp-tools/types (MCPTool, MCPToolInputSchema, MCPToolResult) - ./mcp-tools/validate-input (validators) These already shipped via the bundled ./mcp-tools index, but exposing them as direct subpath exports is the prereq for @claude-flow/cli to replace its 4 byte-identical local copies (types.ts, output.ts, mcp-tools/types.ts, mcp-tools/validate-input.ts — 1,229 LOC total) with single-line re-export shims pointing at cli-core. Verified via diff -q between cli and cli-core that all four files are currently identical. That follow-up PR is intentionally NOT bundled with alpha.5 because cli is 2.2 MB / 1146 files and the foundation refactor deserves proper review. This release just lays the wiring so the cli-side change is mechanical. Validated all 11 cli-core subpath exports resolve correctly via Node's ESM resolution. Build clean. Published @ alpha tag (latest stays at alpha.0 to preserve "alpha is opt-in" semantics). Refs ADR-100, #1748 Issue 3, #1760 Co-Authored-By: RuFlo <ruv@ruv.net> * feat(cli): re-export 4 foundation modules from cli-core@alpha.5 Replaces 4 byte-identical files in @claude-flow/cli with one-line re-export shims pointing at @claude-flow/cli-core. Net: -1,215 LOC of duplication, +31 LOC of shim. The shim files keep their original paths so the 60+ internal `import './types.js'`-style call sites continue to resolve unchanged. Files migrated (all confirmed byte-identical to cli-core via diff -q prior to refactor): - cli/src/types.ts (287 LOC → 14 LOC shim) - cli/src/output.ts (640 LOC → 9 LOC shim) - cli/src/mcp-tools/types.ts (46 LOC → 8 LOC shim) - cli/src/mcp-tools/validate-input.ts (256 LOC → 9 LOC shim) Wiring: - Added @claude-flow/cli-core: ^3.7.0-alpha.5 to cli's runtime deps - pnpm install resolved cli-core via the v3 monorepo workspace map (workspaces: ["@claude-flow/*"]); pnpm-lock.yaml updated accordingly Validation: - npm run build: clean, zero TypeScript errors - node bin/cli.js --version: ok (v3.6.30) - node bin/cli.js memory list: ok (full SQLite backend still works) - dynamic import of output.js: OutputFormatter, Progress, Spinner, output instance all reachable through the shim Future drift is now impossible — when cli-core's types change, cli picks them up automatically via the dep. The 4 files are no longer maintained in two places. NOT bumping cli's version in this commit. Let the change bake on the branch before publishing. Once external validation lands (#1748 reporter, cost-tracker bench-corpus parity), this can ship as part of the cli-core-split PR. Refs ADR-100, #1748 Issue 3, #1760 Co-Authored-By: RuFlo <ruv@ruv.net> * test(cli-core): cold-cache benchmark script (ADR-100 fire 11) Reproducible benchmark for the cli vs cli-core wall-time claim. Uses NPM_CONFIG_CACHE redirection so it never touches ~/.npm/_npx (per project memory feedback on destructive cache ops). Results captured on this run (N=3, macOS, mise/node v22): | Condition | Min | Mean | Max | |--------------------|------:|------:|------:| | cli cold-cache | 32.76 | 34.89 | 37.38 | | cli warm-cache | 16.56 | 16.69 | 16.89 | | core cold-cache | 1.38 | 1.53 | 1.80 | | core warm-cache | 1.33 | 1.36 | 1.42 | Speedup cold-cache: 22.9x (cli 34.89s vs core 1.53s) warm-cache: 12.3x (cli 16.69s vs core 1.36s) The cold-cache gap (~33s saved per spawn) is the user-visible win for plugin scripts that spawn the cli many times — exactly the problem #1748 issue 3 raised. Refs ADR-100, #1748 Issue 3, #1760 Co-Authored-By: RuFlo <ruv@ruv.net> * feat(ruflo-adr): apply CLI_CORE env-flag to verify + import scripts Extends the cli-core opt-in pattern from cost-tracker (fires 7+8) to ruflo-adr's CLI spawn sites — verify.mjs (list+retrieve) and import.mjs (store). With CLI_CORE=1, both route to @claude-flow/cli-core@alpha, dropping per-spawn cold-cache wall-time from ~25s to ~2s. import.mjs documents one behavior delta: cli-core's JsonMemoryBackend overwrites by default, collapsing the "exists"/UNIQUE-constraint signal to plain "ok". Re-runs become idempotent (records refreshed) rather than incremental (records skipped). The comment in import.mjs flags this so users who want incremental semantics know to leave CLI_CORE unset. Validated end-to-end with a single-ADR smoke test under /tmp: CLI_CORE=1 IMPORT_FORMAT=json node import.mjs → storedRecords: 1 CLI_CORE=1 VERIFY_FORMAT=json node verify.mjs → adrCount: 1 Refs ADR-100, #1748 Issue 3, #1760, #1764 Co-Authored-By: RuFlo <ruv@ruv.net> --------- Co-authored-by: Reuven <cohen@ruv-mac-mini.local> |