Skip to content

[Task]: Adopt @rivus/agent-kit #92

Description

@PerfectPan

Problem

@rivus/agent-kit 0.7.0 / @rivus/agent-kit-collab 0.7.0 now maintain the coding-agent knowledge this package duplicates, and the copies have drifted (agent-presence #85 timeout units, #86 Gemini event names):

  • Usage scanning for 6 sources in src/usage/ (scan-claude.ts, scan-codex.ts, scan-gemini.ts, scan-opencode.ts, scan-pi.ts, scan-dsh.ts), with dedup / replay-skip / cache-split / reasoning-fold rules in read-jsonl.ts and index.ts.
  • The pricing formula in src/usage/pricing.ts next to the committed LiteLLM snapshot src/usage/litellm-pricing.json.
  • Hook payload dialects for six agents in src/hooks/ and lifecycle reduce in src/state.ts (normalizeEvent / applyAgentEvent).
  • Install / uninstall / verify across agents: src/installers.ts, the scripts/install-* / uninstall-* scripts, orchestrated by src/setup.ts, JSON editing in src/json-file.ts.
  • Two hand-rolled locks: the mkdir lock withStateLock in src/state.ts and the hardlink owner-token lock in src/log-retention.ts.

src/cli/app.ts statically imports the setup command, so every hook invocation loads all installer code (plain tsc build, no bundling).

Proposed Solution

Adoption per the kit's docs/development/adoption.md ("Presence"), pinning both packages at 0.7.0 (lockstep release) in the lockfile, split into PRs by kit area. Each PR replaces the old code it covers, deletes it and carries its own old/new evidence; PRs are reviewed and merged by the owner one at a time. The repo's lint-config v0.6.0 and Vite+ issues land first, and this repo is finished before the next one starts.

Before starting: settle the open PRs that touch the same code (#83 dsh lifecycle mapping, #84 pricing snapshot). Order:

  1. lint-config v0.6.0 ([Task]: Adopt lint-config v0.6.0 #90).
  2. Vite+ ([Task]: Move the toolchain to Vite+ #91): vp pack replaces the tsc build; keep dist/src/cli.js (the bin target and the legacy hook marker dist/src/cli.js hook).
  3. Process lock: step 5 below (first kit dependency, so it also bumps engines.node and adds minimumReleaseAgeExclude if the repo has a release-age rule).
  4. Usage and pricing: step 1.
  5. Hook/setup build split: step 2.
  6. Hook events: step 3.
  7. Setup through /harness: step 4 (closes [Bug]: Claude Code hooks get a 5000-second timeout #85, [Bug]: Gemini CLI hooks use Claude Code event names #86; [Bug]: Cursor may block every tool call through the Claude PreToolUse hook #89 across 6 and 7).
  8. After merge: the owner merges the release PR; real-home upgrade and real Cursor/Codex checks only with the owner's go.

Steps:

  1. Replace the five agent scanners with /transcript/usage (scanUsage, decodeUsage, listUsageSources) and the pricing formula with /cost (createPricing, costOf). The dsh scanner stays — it reads presence's own usage-events protocol, which the kit does not cover; the kit adds Grok, which presence does not scan today. Keep the LiteLLM snapshot, scripts/update-pricing.mjs and the weekly workflow, injecting the table into /cost; persist UsageScanState with the same since window across scans.
  2. Split hook and setup build outputs first (today plain tsc): bundle a hook entry whose import graph contains neither setup nor effect, and measure its cold start. A static setup import anywhere in the hook graph defeats the split.
  3. Hook: use /harness/events (readHookEvent, reduceLifecycle, heartbeatSignal, builtinHookDialects) in place of src/hooks/*; keep the online-state policy in src/state.ts; respect the dialect's permission semantics — an observer must not silently block a gate.
  4. Setup: use /harness — planInstall (display changes, commands, expectedTrustPrompts, droppedHooks; resolve only allowed conflicts; re-plan after restart) then applyInstall with the same plan handle; expose verify, doctor, inventory, uninstall. Supply the Bundle (owner, version, digest, hooks/skills, legacy command markers) so old hooks are replaced, and keep the shim command stable with {agent}. This is the only Effect touchpoint: a one-shot Effect.runPromiseExit mapping failure to the CLI exit code, with effect@4.0.1 as the exact peer.
  5. Replace the mkdir withStateLock with collab /process-lock (acquireProcessLock, handle ProcessLockHeld, release on exit); the log-retention lock can follow.
  6. Stays in presence: dsh source plugin and usage-events log, badge/window rendering and the state cache, source-plugin mechanism, provider backends, keyring, power watcher.

Acceptance Criteria

  • usage-ccusage-parity, usage-scan*, usage-pricing tests pass ported onto the kit entries.
  • On real local logs, old and new token and cost totals are equal per agent over the same window and price table — covering self-reported cost, one-hour cache writes and the priority multiplier — after accounting for scan finalization of still-running sources.
  • Install / verify / uninstall pass under an isolated HOME; old hooks are replaced; verify and doctor report no new/legacy duplicate hooks.
  • Downgrade check under isolated HOME: new install → new uninstall → old install/setup fires each event once; Codex does not re-ask trust after an upgrade; the Cursor gate issue [Bug]: Cursor may block every tool call through the Claude PreToolUse hook #89 is checked and handled.
  • Hook cold start is measured and not slower than today; the hook dist imports no setup or effect code.
  • Two processes contending for the state lock: one holder, the other gets ProcessLockHeld; recovery after the holder is killed.
  • The duplicated modules are deleted: src/usage/scan-{claude,codex,gemini,opencode,pi}.ts, src/usage/pricing.ts, src/hooks/*, src/installers.ts, scripts/install-*/uninstall-*, the mkdir lock.
  • engines.node bumped to >=22.13 (kit's Node adapters requirement; the repo currently allows >=22).

Activity

  1. added
    taskMaintenance, refactoring, dependency, or tooling work
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    taskMaintenance, refactoring, dependency, or tooling work

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions