KeiSeiKit-1.0/hooks
Parfii-bot 883e2ca938 feat(sleep-sync): mirror time-metrics + ledger snapshots, surface in Phase B report
User pushback: "что теперь делает сон? все связано?" — Sleep Phase B
was reading only `traces/`, ignoring the four tracking journals shipped
in the previous commit. Cloud agent had a partial view of what happened.

This commit closes the loop. Sleep now sees everything that's tracked.

PUSH SIDE — `kei-sleep-sync.sh` (called on every Stop event)

Now mirrors the full observability surface into the memory-repo:

  ~/.claude/memory/time-metrics/sessions.jsonl       → time-metrics/
  ~/.claude/memory/time-metrics/tasks.jsonl          → time-metrics/
  ~/.claude/memory/time-metrics/numeric-claims.jsonl → time-metrics/
  ~/.claude/memory/time-metrics/agent-toolstats.jsonl→ time-metrics/
  ~/.claude/agents/ledger.sqlite agents table        → ledger/agents.jsonl
  ~/.claude/agents/ledger.sqlite skill_invocations   → ledger/skill_invocations.jsonl

Format: JSONL (one row per object). The two ledger tables are dumped
via `sqlite3 + json_object()` so cloud agents can stream-parse into
pandas / duckdb without binary-file handling.

First sync moved 6 files / 638 rows from local to remote — verified
by `git show --stat` of the resulting `memory: session traces` commit.

CONSUME SIDE — `phase-b-rem.sh` REM-consolidation report

Each nightly `reports/sleep-YYYY-MM-DD.md` now ends with a "Tracking
observability (last 7 days)" section containing four jq-aggregated
digests:

  1. Agent outcomes — per-model: n, functional/partial/scaffolding/fail
     counts + total_cost_usd. Lets the agent see whether the model-tier
     refactor (50c9e76) actually paid off and whether Sonnet success
     rate justifies routing more task classes to it.

  2. Skill success rates — per-skill: n, successes, rate_pct. Drives
     Phase D nightly decisions (archive unused / re-extract failing /
     mark validated). Empty until Skill tool is invoked in the next
     session.

  3. Numeric-claims tier breakdown — REAL / FROM-JOURNAL / ESTIMATE-HTC
     counts. High ESTIMATE-HTC ratio = orchestrator under-calibrated.
     Cloud agent's job: spot frequent ESTIMATE-HTC categories and
     propose conversion to FROM-JOURNAL via measured runs.

  4. Agent tool-call patterns — mean tool_use_count, mean duration_ms,
     per-tool total calls. Lets the agent see "this code-implementer
     spawn made 30 Read but 1 Edit — was tier-allocation correct?".

All four sections gracefully skip if the source JSONL is missing or
empty. jq is the only new dependency (already present per existing
phase-b checks).

What is NOT yet automated:

  - The cloud agent's prompt template doesn't yet INSTRUCT it to act
    on these digests. Currently the digest is data; whether the agent
    proposes rule + hook codification based on it depends on the
    free-text instructions in the schedule. Follow-up: codify a Phase B
    instruction block that maps each digest to a recommendation pattern.

  - Idempotency on `cp` for time-metrics: I use plain `cp` (not `cp -n`)
    so the latest local state always overwrites remote. The journals are
    append-only on the local side, so this is safe — but if two machines
    ever share one memory-repo it would corrupt. Out of scope for
    single-machine setup.

=== STATUS-TRUTH MARKER ===
shipped: functional
stubs: 0
cargo-check: NOT-RUN  (pure shell)
behaviour-verified: yes
follow-up-required:
  - Phase B prompt template — instruct cloud agent to act on the four
    digests (codify recurring patterns, calibrate ESTIMATE-HTC).
  - skill_invocations.jsonl will populate from next session onward.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 04:02:28 +08:00
..
_lib KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
affect-live-scan.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-capability-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-capability-verify.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-fork-done.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-fork-logger.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-heartbeat-tick.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-outcome-backfill.sh feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
agent-stub-scan.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
alignment-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
assemble-agents.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
assemble-validate.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
auto-dev-guard.sh feat(frontend-loop): kei-db-contract primitive + frontend-validator agent + auto-dev-guard hook 2026-05-01 15:34:39 +08:00
auto-encyclopedia-refresh.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
auto-register-on-edit.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
block-dangerous.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
check-error-patterns.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
citation-verify.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
decompose-rules-on-edit.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
destructive-guard.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
disk-headroom-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
disk-reclaim.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
error-spike-detector.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
extract-task-durations.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
hooks.json feat(frontend-loop): kei-db-contract primitive + frontend-validator agent + auto-dev-guard hook 2026-05-01 15:34:39 +08:00
milestone-commit-hook.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
no-downgrade.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
no-hand-edit-agents.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
no-python-without-approval.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
numeric-claims-guard.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
numeric-claims-record.sh feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
orchestrator-branch-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
orchestrator-dirty-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
phase-b-rem.sh feat(sleep-sync): mirror time-metrics + ledger snapshots, surface in Phase B report 2026-05-02 04:02:28 +08:00
post-commit-audit.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
post-write-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
recurrence-suggest.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
rust-first.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
safety-guard.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
session-end-dump.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
site-wysiwyd-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
skill-record.sh feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
stop-verify.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
task-timer.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
tomd-preread.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00