Skip to content

v5: Hermes-inspired learning loop (auto skill sedimentation)#3

Merged
LeoLin990405 merged 4 commits into
mainfrom
feature/v5-learning-loop
Apr 14, 2026
Merged

v5: Hermes-inspired learning loop (auto skill sedimentation)#3
LeoLin990405 merged 4 commits into
mainfrom
feature/v5-learning-loop

Conversation

@LeoLin990405

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in v5 learning loop to CivAgent, inspired by NousResearch/hermes-agent's autonomous skill creation and agent-curated memory. v4 was stateless per run; v5 persists per-civilization governance patterns across matches.

What's new

  • engine/v5/civ-memory.mjs — each regime gets isolated ~/.civagent/envs/<region>-<id>/ HOME with its own .claude/ subtree, so learned skills don't cross-contaminate between civilizations. Re-seeds CLAUDE.md when SOUL.md/IDENTITY.md changes.
  • engine/v5/skill-sediment.mjs — post-match pipeline: codex extracts ≤2 governance patterns from the transcript → gemini audits shape/quality → write regimes/<civ>/skills/learned-<date>-<topic>-<matchId>.md. Includes prompt-injection guard, provenance banner, ANSI/JSONL cleaning.
  • engine/v5/run-v5.mjs — new entry: HOME + XDG overrides, transcript capture to JSONL, auto-trigger sediment on exit.
  • bin/civagent--v5 opt-in flag on run, plus skills <regime> and match-log subcommands.
  • docs/V5-DESIGN.md — full design doc with MVP scope and known limitations.
  • ~/.claude/teams/civagent-v5/config.json (not committed; local) — Agent Team with judge + 4 civ-agents (tang / qin / athens / rome-republic), each pinned to a different backend via the cn:/gemini:/codex: dispatch agents.

Compatibility

v5 is fully opt-in via --v5. Without the flag, v4 behavior is unchanged.

Review trail

Three independent AI reviews on the same diff:

  1. Codex — caught: CLAUDE.md path wrong, team config model IDs, skill-file injection risk.
  2. Gemini (after API Key mode fix, see V5-DESIGN) — caught: XDG paths leaking, ANSI/JSONL wrapping wasting extractor tokens, Python shell injection in cmd_skills, regime path traversal, missing binary checks.
  3. Kimi — caught: CLAUDE.md seed freezing after first run, skill filename collisions on same-day same-topic, design-layer critique (regime-to-agent compression, time-dimension omission).

All actionable findings fixed across 4 commits.

Test plan

  • node -c on all 3 engine/v5 files
  • bash -n bin/civagent
  • Dry-test: synthetic唐朝三省六部 transcript → codex extracts 2 patterns (seasonal-frontier-risk-planning + quantified-cross-department-approval) → gemini APPROVEs → skill .md written with correct frontmatter
  • Re-run dry-test after matchId-suffix fix — confirmed no overwrite
  • Pending: real civagent run --v5 match (requires tester with stable CC auth in isolated HOME)
  • Pending: MVP 5-match tournament across tang/qin/athens/rome-republic

Risks

  • Sediment pipeline requires codex + gemini binaries in PATH; v5 degrades gracefully with a warning if either is missing.
  • claude spawned in isolated HOME will need credentials on first run per civ (one-time OAuth per isolated environment).
  • Design-layer concern: compressing a civilization to one agent's system prompt is lossy. Documented in V5-DESIGN; multi-department sub-agent split is a v5.2 candidate.

Introduces opt-in v5 runtime that persists per-civilization skills across
matches, inspired by NousResearch/hermes-agent's autonomous skill creation
and agent-curated memory patterns.

- engine/v5/civ-memory.mjs — isolated HOME per regime at
  ~/.civagent/envs/<region>-<id>/, seeded with regime identity, symlinks
  learned skills from regimes/<civ>/skills/
- engine/v5/skill-sediment.mjs — post-match pipeline: codex extracts
  governance patterns from transcript → gemini audits → write skill .md.
  Includes prompt-injection guard and provenance banner.
- engine/v5/run-v5.mjs — new entry: HOME override + stdout transcript
  capture to ~/.civagent/transcripts/, triggers sediment on exit
- bin/civagent — adds --v5 flag on run, plus skills/match-log subcommands
- docs/V5-DESIGN.md — full design with MVP scope (tang/qin/athens/rome)
- ~/.claude/teams/civagent-v5/config.json — Agent Team with team-lead
  judge + 4 civ-agents (backend metadata routes to cn:/gemini:/codex:
  dispatch agents; native model IDs kept valid)

v4 behavior preserved — v5 is opt-in via --v5 flag.
…tion guards

- engine/v5/civ-memory.mjs: add validateRegime() regex guard vs path traversal;
  handle pre-existing non-symlink destinations with warning instead of silent skip
- engine/v5/run-v5.mjs: override XDG_{CONFIG,DATA,CACHE}_HOME too, so any CC
  build that reads XDG paths independently of HOME also gets isolated
- engine/v5/skill-sediment.mjs: strip ANSI escapes and unwrap JSONL chunks
  before feeding codex (was wasting tokens + confusing extractor); require
  codex/gemini binaries via explicit hasBinary() check
- bin/civagent: fix Python shell injection in cmd_skills (f was interpolated
  into a Python string literal; now passed via sys.argv)
Gemini auditor often emits a chain-of-thought block before the final
APPROVE/REJECT verdict. Strict startsWith() rejected valid approvals.
Now checks the last non-empty line instead.
- civ-memory.mjs: re-seed CLAUDE.md when SOUL.md or IDENTITY.md is newer
  (was frozen on first run, blocking regime identity edits)
- skill-sediment.mjs: append matchId suffix to skill filenames so two
  matches on the same day with similar topics don't overwrite
- skill-sediment.mjs: clarify AUDIT_PROMPT — auditor has no transcript
  access and should only validate skill shape, not hallucinate verification
- docs/V5-DESIGN.md: document design limitations Kimi raised
  (regime-to-agent compression, time-dimension omission, seed semantics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant