Skip to content

Add propose --learn-from to seed observations from Hermes run history - #11

Merged
JoeProAI merged 3 commits into
mainfrom
devin/1794361886-learn-from-history
Nov 11, 2026
Merged

JoeProAI merged 3 commits into
mainfrom
devin/1794361886-learn-from-history

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

hermes mandate propose <job> --learn-from <source> reads the job's existing Hermes history, stores the tool calls it finds as observations, and compiles a pending mandate. A job with history can get a proposal without waiting for 3 live observe runs. It never approves and never changes the job's mode.

How to run

hermes mandate propose nightly-triage --learn-from history          # this job's own cron history
hermes mandate propose nightly-triage --learn-from cron:a1b2c3       # cron job by id (or name)
hermes mandate propose nightly-triage --learn-from ~/.hermes/sessions/cron_a1b2c3_20261101_030000.jsonl
hermes mandate propose nightly-triage --learn-from ./transcripts/ --workdir /srv/repo
hermes mandate approve nightly-triage                                # unchanged: TTY or --yes

Grammar (in the README command table and mandate_core/history.py): history | cron:<name or id> | path to a session .jsonl or a directory of them. --workdir overrides the workdir (default: workdir from cron/jobs.json, then the live observations' root, then cwd).

What changed

  • mandate_core/history.py (new): resolves the source under $HERMES_HOME (default ~/.hermes). Cron runs are sessions named cron_<job_id>_* in sessions/*.jsonl and state.db (opened read-only). Takes assistant tool_calls (function.name + function.arguments), skips unparseable lines, bad tool_calls, calls with missing names or non-JSON args, and calls whose tool result says MANDATE BLOCKED. cron/output/<id>/*.md and cron/executions.db are only counted, so the CLI can say "Hermes knows N runs but only M left a transcript". Nothing is written to the Hermes dir.
  • Engine.shape_for(tool, args, cwd, root): the live pre_tool_call path and the importer now share one normalize + to_json (redaction) + root step, so a learned observation is byte-for-byte the same shape the live hook would store (tested).
  • Store: source TEXT NOT NULL DEFAULT 'hook' added to runs and observations (migrated in place on open). replace_history() writes learned runs as source='history' with run id history:<session_id>. Re-learning replaces those runs instead of stacking evidence.
  • Policy: Rule.history and Policy.history_runs. compile_policy(..., history=<run ids>) counts learned evidence separately. Render only changes when history is present:
    # Mandate for nightly-triage: generated from 4 run(s): 1 observed live, 3 learned from Hermes history.
    observed_runs: 4
    history_runs: 3
      - "git log --oneline -n"  # seen 4x, 3x from history
    Policies without history render exactly as before. parse round-trips the new fields.
  • CLI output adds # learned from history: ..., # skipped: ..., a thin-history warning, and a warning that learned rules reflect what the job did before Mandate was watching. With no usable calls it exits 1 with no usable Hermes history for <job> ... Nothing was written. and writes no job, observation, or policy rows. Leash Line tail shows N run(s) observed (H learned from Hermes history). watch mentions the shortcut.
  • Docs: README command table, quickstart (one commented line), and a short note under "What a mandate looks like". proof/ and the README results block are regenerated by make prove-all (second commit).

Tests

  • tests/test_history.py: parser (good and malformed rows, string/dict args, blocked calls, dedupe), source grammar, state.db + ledger reading, fixture history with zero live runs proposes, distinct source marking in store, YAML and Leash Line, learned calls redacted and identical to live shapes (no file contents, token, private key), determinism across two fresh stores plus re-learn is a no-op, no-history error, and --learn-from leaves an enforcing job's mode and active version alone while approve without TTY still refuses.
  • Real-Hermes scenario: a new history-triage cron job whose history is written by Hermes's own create_job, SessionDB.append_message, divert_session_transcript_jsonl and save_job_output, with one malformed row. propose --learn-from history through the real hermes mandate CLI gives history_runs: 3, stays OBSERVING with nothing approved, and an unknown job fails non-zero.
  • Ran locally: make prove-all: validate passed and 122 passed, 0 failed on both Hermes v0.23.0 and v0.23.1 (was 112). Pinned Hermes SHAs unchanged.

Gaps

  • Gateway-style cron sessions that don't use the cron_<job_id>_* id aren't picked up by history/cron:. Pass the transcript path instead.
  • Cron output .md files have no tool calls, so they're only used for run counts.
  • Learned history can't tell which calls were allowed by an older Mandate version vs. made with no Mandate at all, beyond skipping MANDATE BLOCKED results.

Link to Devin session: https://app.devin.ai/sessions/054a0222339047a686312c8e13750d29
Open in Devin Desktop: https://app.devin.ai/desktop/session/054a0222339047a686312c8e13750d29?variant=devin

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration Bot and others added 2 commits November 11, 2026 01:59
@JoeProAI
JoeProAI merged commit ea7321a into main Nov 11, 2026
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