Commit Graph

32 Commits

Author SHA1 Message Date
yoniebans
2f3405ba9c test(evals): evals, end-to-end suites, scripts and CI on the persistence interface
Evals, the end-to-end and conformance suites, scripts and CI reach the store through the interface.

scripts/ci/check_backend_imports.py, run by scripts/check, refuses an import of persistence.sqlite outside persistence/ and persistence_assembly.py (tests excepted). The two evals that instrumented the backend now reach it through the interface: the failure-ownership probe patches the message repository class of the store it opens, and the attachment bench meters whole-blob reads at the gateway attachment store.
2026-11-17 17:51:21 +01:00
alt-glitch
ec6827c388 fix(code-health): the packaged-imports scan is a guard, and it sees submodule imports
The scan that flags a package the wheel would drop read production
source from a test, which tests/AGENTS.md bans. It is now
scripts/check_packaged_imports.py, registered as `packaged-imports` in
scripts/check with its own lint.yml step, beside `tool-discovery`; the
hook fixture copies it like every guard. It uses only the standard
library: tomllib for the include patterns, the find_packages walk done
over `git ls-files` (a package is reachable only through parent
packages), and ast for imports.

`from acp_adapter import server` and `from . import server` now count
`acp_adapter.server` as imported, not only `acp_adapter`, so a submodule
turned into a folder is caught whichever form imports it.

tests/scripts/test_check_packaged_imports.py covers a root module turned
into a folder, both from-import forms, and a clean tree, on temporary
repos. On the real tree the guard passes, and fails with `toolsets` or
`acp_adapter.server` when either module becomes a folder.
2026-11-16 11:52:44 +05:30
alt-glitch
9f67098233 fix(code-health): carry the tool-discovery guard into the checker fixture
tests/scripts/test_code_health_cli.py builds fixture repos with a hand-kept
copy of every guard scripts/check runs; the new guard and what it imports
(tools/registry.py, hermes_constants.py) were missing, so three hook tests
failed on "can't open file". The guard drops its empty-scan branch, which
failed any tree with no tools, and exposes `unreached_registrations` so
tests/scripts/test_check_tool_discovery.py can prove it flags a module
registering outside `<pkg>/tool.py` on a temp repo.
2026-11-16 11:52:44 +05:30
alt-glitch
fd8a6c41ac test(code-health): fixture repos carry ruff.toml
The hook fixtures copied pyproject.toml for the ruff pin but not
ruff.toml, so their ruff check ran under pyproject's [tool.ruff] block,
the config a real checkout ignores. With that block deleted the fixtures
fell back to ruff's default rules and three hook tests failed. The
fixtures now copy and commit ruff.toml, the config a clone runs.
2026-11-15 14:02:40 +05:30
alt-glitch
08896446fe fix(code-health): read the AGENTS.md hint cap and the fixture support files where they live now
check_agents_md_size read agent/subdirectory_hints.py by its old path, and the code-health CLI
fixture copied that file from the old path, so both raise once agent/ moves. Both go through
current_path. The fixture keeps an empty MOVES, so its copies stay at their old paths.
2026-11-13 20:47:04 +00:00
alt-glitch
8ace916abd fix: make path-keyed guards follow MOVES so a chunk need not edit them
Scan roots and lists go through current_path (footguns --all roots, config reader/writer trees,
detached-spawn trees and root files, subprocess-stdin dirs, the gateway parity scan root, the
plugin validator's core-handle source globs). Keys written in old paths (install-root baseline
and its depth test, detached-spawn helper and baseline, stdin KNOWN_SAFE, config-reader foreign
files, boundary-lint baseline, code-health rule globs, CI lane tables, public-surface source
dirs, plugin public-API names) are looked up by original_path/original_module of the file or
import under inspection, so they stay valid and a moved file is not judged new.
Root-name sets gain hermes_agent and the old names in MOVES; the plugin audit's registry-call
table follows MOVES; update_downgrade_guard drops the stale src/ path (its test and the
code-health CLI fixture follow). With MOVES empty every guard is unchanged.
2026-11-13 20:47:04 +00:00
alt-glitch
130ff41f09 test(code-health): give the engine fixture the shims check inputs
The fixture tree lacked scripts/move/generate_shims.py, the compat package and
a .gitattributes shim block, so the shims job failed inside the fixture repos
(3 tests). The fixture now copies the generator and compat package, writes an
empty MOVES and an empty shim block.
2026-11-13 18:45:32 +00:00
Maciej Lisiewski
b5bf6c73e8 test(ci): carry check_dockerfile_downloads into the scripts/check hook fixture
The hook tests copy only _GUARD_SCRIPTS into their temp repo; registering
dockerfile-downloads in scripts/check without it failed three hook tests.
Also prove scripts/check --only dockerfile-downloads fails on a streamed download.
2026-11-12 19:57:30 +01:00
Teknium
9dc7e6a524 fix(ci): reject text files stored with CRLF line endings
.gitattributes asks git to store text with LF, but only a client that
honours it does: a GitHub web upload or an API commit lands bytes as sent.
plugin-catalog/board-insights.yaml arrived that way. Every fresh checkout
then showed it as modified, and the icon check (which needs a clean tree)
failed on every catalog PR until #154171 rewrote it.

- scripts/ci/check_line_endings.py reads `git ls-files --eol` and fails on
  any index blob that is crlf/mixed, except -text (binary) and eol=crlf
  (*.ps1) paths. `--fix` rewrites offenders with LF and stages them.
- Runs as a Repository guards step and as `scripts/check --only
  line-endings` (so the pre-push hook catches it locally too).
- `* text=auto` catch-all in .gitattributes, so text files outside the
  listed extensions are normalized at check-in too (renormalizing the
  whole tree with it changes nothing but the file below).
- Fixes the one remaining offender:
  contributors/emails/uperLu@users.noreply.github.com.

Co-authored-by: lancelotsh51sh <283335493+lancelotsh51sh@users.noreply.github.com>
2026-11-11 18:50:11 -08:00
kshitijk4poor
96d816a10f refactor(profiles): one entry point for profile create
`hermes profile create`, `POST /api/profiles` and the Desktop/TUI
`profiles.create` RPC each called `create_profile()` and then ran their own
post-create steps (skills, alias, credentials, model, MCP servers, skill
selection). The same "new profile" therefore came out different
depending on where it was started, and a fix to one surface missed the
other two.

Add `hermes_cli/profile_provision.py` with
`provision_profile(ProfileCreateRequest) -> ProvisionResult`. Every surface
now builds a request and renders the result. `create_profile()` keeps the
folder work (validate, copy, strip channels, stage, publish, notify);
`provision_profile` runs every later step in one fixed order. A failing
later step never undoes the create: it is a warning in the result, as the
dashboard and RPC already treated it.

- The dashboard's model / MCP / skill-selection writers and the RPC's
  launch-credential mirroring moved into the module; the routers import
  them. Every config read-modify-write during create now holds the
  dashboard's `_CONFIG_MUTATION_LOCK` (MCP servers, voice sections,
  endpoint seed and base_url restore were unlocked on main).
- Plugins get no step here: since main's 6933155eaf the core create calls
  the selected memory provider's on_profile_created hook, so every surface
  already gets the provider's per-profile files.
- `scripts/check_profile_create_entry.py` (scripts/check, lint.yml) scans
  every production Python file and fails on any use of `create_profile`
  outside its definition and the new module: calls, imports, aliases, the
  function passed as a value, getattr by name, and files that do not parse.

Behaviour is unchanged on purpose: each surface passes the options it used
before (only the RPC mirrors launch credentials). Two small differences,
both on failure paths: a failing post-create step in the CLI prints a
warning instead of a traceback, and the RPC writes SOUL.md during the core
create (as the dashboard already did), so a failed write fails the create
instead of returning soul_written=false.
2026-11-10 14:09:08 +05:30
alt-glitch
0e17aedc6d ci(paths): ratchet new __file__ install-root climbs and import-time sys.path edits
scripts/install_root_lint.py scans the shipped packages and root modules. It
counts __file__ path expressions that climb as many directories as the file
is deep (.parent, .parents[n], os.path.dirname, os.path.join with pardir),
and sys.path edits that run at import. Today's 106 climbs and 13 import-time
edits are the baseline; a file whose count rises fails, and the message names
hermes_cli._startup_fast.project_root_str() as the call to make instead.
Wired into scripts/check (install-root) and the lint workflow.
2026-11-07 01:17:21 -05:00
alt-glitch
e8d908b1c9 fix(ci): guards fail instead of passing when they cannot see a change
Three guards could report success while they checked nothing:

- The public-surface check listed only modified files, so a moved
  file (git reports a rename) was never compared. It now pairs each
  renamed file with its old path, and treats src/hermes_agent/ as
  source.
- The change classifier read file names from the compare API, which
  stops at 300 files without saying so and drops the old path of a
  rename. A list at the cap now runs every lane, and a rename counts
  under both of its paths.
- Tree guards skipped a scan root that did not exist. The config
  reader and writer checks, the subprocess stdin check and two guard
  tests now fail when a root they scan is missing.
2026-11-06 23:02:54 -05:00
Maciej Lisiewski
7062229090 chore(js): switch the workspaces from npm to pnpm
pnpm 12.15.0 (native executable) installs every JS workspace from one
pnpm-lock.yaml, imported from package-lock.json with the same resolved
versions. website/, the WhatsApp bridge and the photon sidecar stay separate
npm projects.

Configuration moves from .npmrc and the root manifest into
pnpm-workspace.yaml: the 14-day minimumReleaseAge and its excludes,
overrides, allowBuilds (the old allowScripts set, with strictDepBuilds
failing any unlisted build script), engineStrict, sideEffectsCache: false
(in-place rebuilds must not write into the store) and
verifyDepsBeforeRun: false (a `pnpm run` never installs).

The pnpm version is pinned in pm/lock.json and in root devEngines.
pmOnFail: ignore keeps that pin out of pnpm-lock.yaml: a leading pin
document makes osv-scanner read zero packages. scripts/build/node-deps.mjs
enforces the exact version instead, and every lock reader refuses a
multi-document lock. A root preinstall refuses `npm install`; devEngines
onFail is warn so npx (MCP servers, the tsc linter) keeps working inside
the checkout.

User-machine installs run --frozen-lockfile --trust-lockfile (release age is
checked when locking, in CI, not per user). node-deps removes npm-era
node_modules trees before the first pnpm install. Nix builds the store with
fetchPnpmDeps and a hash file that CI checks.
2026-11-06 04:08:24 +01:00
kshitijk4poor
d1cb5d5cbd ci(process): no new detached spawn outside spawn_owned without a reason
A child started in its own session or group (start_new_session, os.setsid /
setpgid / setpgrp, windows_detach_popen_kwargs) does not die with a SIGKILLed
Hermes: it reparents to init and runs forever. That is how every family this PR
migrates leaked. With the families on spawn_owned, this keeps the class closed.

scripts/check_detached_spawns.py (AST) flags those shapes in the production trees
unless the line, or the line above it, says `detached-spawn: ok — <why>`. It runs
in scripts/check ("detached-spawns") and as a blocking lint.yml step. The baseline
is empty: every remaining site is on spawn_owned / own_process_groups, or carries
its reason. The reasons this commit adds are the census verdicts:
- must outlive the starter on purpose: restart watchers, /update and the updater
  hand-offs, dashboard/desktop/service launches, cron and kanban workers
  (restart-safe), the update-custody watchdog itself;
- awaited with a group kill on timeout: cron scripts, rg search, the Browser Use
  CLI, update completion (holds the checkout lock fd);
- covered by its own parent guard: the compute host (compute_host._parent_guard_loop
  flushes sessions; a supervisor KILL could cut that short);
- not a spawn: the wake-word `start_new_session` config key and event field.

tests/scripts/test_check_detached_spawns.py: each shape flagged, non-detached and
commented/string shapes not, the marker opts out on its line or the line above
and nowhere else, tests and the helper are out of scope, main() fails on a new
unmarked spawn, and the repository scan is empty. Teeth: appending an unmarked
start_new_session Popen to tools/file_operations_search.py turns
`scripts/check --only detached-spawns` red (rc 1); restoring it turns it green.
2026-10-29 16:58:09 +05:30
kshitijk4poor
015f47a12b fix(config): keep auth's globals()-dispatched plugin status import; ship the reader gate to hook fixtures
Two regressions from earlier commits on this branch, caught by CI's Python tests:

- 8d7bff7615 dropped `get_plugin_oauth_auth_status` from hermes_cli.auth's imports as unused, but
  `_STATUS_BY_AUTH_TYPE` dispatches oauth_device_code / oauth_external plugin providers through
  `globals()[name]`, so every OAuth plugin provider's status raised KeyError
  (test_plugin_provider_picker_residue). Restored with a noqa naming the dynamic lookup.
- 7131eadb77 registered scripts/check_config_yaml_readers.py as the `config-readers` guard, but the
  code-health CLI tests copy only the listed guard scripts into their temp repos, so the installed
  hooks failed on the missing script. Added it to the fixture's _GUARD_SCRIPTS.
2026-10-25 18:54:09 -07:00
Teknium
9c5a59c63f feat(check): run the blob-size guard in scripts/check
The guard judges a diff, so it gets the same base/head as the ratchet:
--staged judges the index, --commit the pushed tip, and a plain run the
working tree plus untracked files against the merge-base with
origin/main. `python scripts/check --only blob-size` reproduces CI.
2026-10-11 17:16:57 -07:00
Teknium
e1ec584b57 feat(ci): cap every AGENTS.md chain below the context budget it is truncated at
scripts/ci/check_agents_md_size.py (in scripts/check and lint.yml): root <= 12k, every
AGENTS.md plus its ancestors <= 30k (the joined root->cwd block on a 128k window, minus
the per-file labels), every area file <= _MAX_HINT_CHARS read from the source so the two
cannot drift. On origin/main it reports the root and all 11 root-to-area chains over.
2026-10-04 23:05:42 -07:00
Teknium
9a98bd0165 fix(code-health): case-collision test stages blobs, not files
test_ci_only_guards_run_in_scripts_check wrote pkg/Notes.md and pkg/NOTES.md to disk,
which a case-insensitive filesystem (Windows, macOS) holds as one file, so the fixture
could not build its own premise. Each path is now staged from a blob with
`git hash-object -w` + `git update-index --cacheinfo`, which is what --staged judges.
2026-10-04 22:35:16 -07:00
Teknium
4249e5226d fix(code-health): staged-health test ignores elapsed time
test_staged_health_ignores_unstaged_policy_and_engine compared two reports byte for
byte, elapsed "(0.1s)" included, so it flaked whenever the two runs straddled a tenth
of a second (seen on native Windows). The comparison now drops the elapsed time.
2026-10-04 22:35:16 -07:00
Teknium
51483660d3 fix(code-health): git hooks work with MSYS path conversion off
The hooks' judge() built its private index and tree under `mktemp -d`, a POSIX /c/...
path in Git Bash, and passed it to native git.exe and python.exe through GIT_INDEX_FILE,
--prefix and the checker path. Hermes' Windows terminal exports MSYS_NO_PATHCONV=1 and
MSYS2_ARG_CONV_EXCL=*, so those paths arrived unconverted and the hook died
("Unable to create '/c/.../index.lock'") before any check ran. judge() now hands native
tools the `cygpath -m` spelling when cygpath exists; elsewhere nothing changes.
2026-10-04 22:35:16 -07:00
Teknium
baa07694a8 feat(code-health): heuristic rules warn until a frozen replay shows precision
HX001, HX003, HX010, HX012 and PS-P05/P06 now print as advisory findings instead of
blocking. Reviewers' samples put them between ~12% and ~60% precision, and the plan
ships weak rules as warnings first. Promote one by flipping it to blocking with replay
evidence in the PR. The ENFORCEMENT comment now says where the switch is read from.
Tests that used PS-P05 as a stand-in blocking violation now use a blind except.
2026-10-04 21:29:39 -07:00
Teknium
7ceedd731a style(code-health): wrap the long lines added by the lane-C fixes
No behaviour change: line wrapping in the hook text, parse_switch docstring,
commit_or_none and the new tests; the test helpers lose an unused env parameter.
2026-10-04 21:29:39 -07:00
Teknium
f91534efb9 fix(code-health): each hooked candidate is judged by its own scripts/check
JoaoMarcos44 (inline scripts/check:40): the hooks began with
`[ -f "$repo/scripts/check" ] || exit 0`, before reading the pushed SHAs, so the
checked-out branch decided whether another revision was checked. Pushing an
invalid checker-containing branch while an older branch was checked out succeeded
without judging it.

Eligibility is now decided from the candidate tree: pre-push runs
`git cat-file -e <local_sha>:scripts/check` per pushed ref (a candidate that
predates the checker is skipped, deletions are still skipped), pre-commit does the
same for the index tree. An eligible candidate is checked out alone into a temp
dir (private index + checkout-index; the worktree, index and stash are untouched)
and judged by its own scripts/check with GIT_DIR pointing at the repo - with the
previous commit's snapshot-bound health job, implementation, job table, config and
policy all come from the judged artifact, whatever is checked out. pre-commit
exports an absolute GIT_INDEX_FILE because git may hand hooks a relative one.
2026-10-04 21:29:39 -07:00
Teknium
f472161acb fix(code-health): hooks prefer the repo virtualenv; scripts/check refuses Python < 3.11
unsupportedpastels M5: both hooks ran whatever python3 came first on PATH, but
scripts/check imports ruff_runner, which imports tomllib (3.11+, the project
minimum). With Ubuntu 22.04's python3 3.10 every hooked commit or push died with
"ModuleNotFoundError: No module named 'tomllib'".

The hooks now use the repo's virtualenv interpreter when there is one (.venv/ or
venv/, bin/python or Scripts/python.exe; this worktree first, then the main
checkout) and fall back to python3, then python. scripts/check checks
sys.version_info before importing the engine and exits 2 with a one-line message
naming the virtualenv instead of a traceback. Verified with a real CPython 3.10.21:
exit 2 and the message, where 96bb97a crashed in ruff_runner.
2026-10-04 21:29:39 -07:00
Teknium
f8501a9328 fix(code-health): --staged/--commit run the ratchet from the judged snapshot
F20 (andrexibiza): in --staged/--commit mode the guard jobs ran inside the
snapshot root with the snapshot's git env, but the health job ran in the real
worktree. Its source was pinned to the index tree, yet its engine and policy were
not: Measurer reads scripts/ci/profile_scope_patterns.json from the repo it runs
in, so with an identical `git write-tree`, editing only the unstaged P05
path_regex turned PS-P05 / exit 1 into "ok" / exit 0 and back.

The health job now runs like every other job: cwd = the snapshot root with the
snapshot env, so `python -m scripts.code_health` imports the snapshot's own engine
and reads the snapshot's policy files and ruff pin. The ruff job resolves its pin
from the same root. Unstaged edits to the policy file or the engine no longer move
the verdict, and they stay untouched in the worktree; plain runs are unchanged
(root is the worktree).
2026-10-04 21:29:39 -07:00
Teknium
f98585d5cc fix(code-health): scripts/check also runs CI's case-collision, lazy-deps and profile-archive guards
unsupportedpastels m4: scripts/check says it runs the lint checks CI runs, but CI
also runs scripts/check-case-collisions.py, scripts/ci/check_lazy_deps_imports.py
and scripts/ci/check_profile_archive_boundary.py in workflows of their own
(case-collision-check.yml, lazy-deps-guard.yml, profile-artifact-check.yml). A
case-colliding pair passed scripts/check and failed CI.

All three are deterministic and local (git ls-files / an os.walk of the checkout;
measured here: 0.2 s, ~7 s, 0.1 s on the full tree), so they run as ordinary guard
jobs - in the snapshot root for --staged/--commit like the other guards - and are
selectable with --only case-collisions / lazy-deps / profile-archives.
2026-10-04 21:29:39 -07:00
Teknium
a6274687fd fix(code-health): parse ENFORCEMENT with ast and read it from the main tip locally
unsupportedpastels m3: (a) the switch was found by a regex that accepted only the
exact `ENFORCEMENT = "..."` spelling, so `ENFORCEMENT: str = "off"` silently stayed
blocking; (b) local runs and both hooks read it from the merge-base with
origin/main, so a flip on main reached a branch only after a rebase, contrary to
"CI and local hooks alike".

(a) parse_switch() reads the module-level plain or annotated assignment with ast
(last one wins, as at runtime); missing, unparseable or unknown values are
blocking. (b) Without --base, the base is still the merge-base of the head (a
--head commit, else HEAD) but the switch comes from origin/main when it resolves,
falling back to the base. An explicit --base pins both (CI passes HEAD^1, the
target tip). scripts/check --commit now hands the commit itself to the ratchet so
it derives that commit's merge-base. The head under test never supplies the switch.
(c) A test pins enforcement() on this tree to config.ENFORCEMENT.
2026-10-04 21:29:39 -07:00
Teknium
b76c3facdf fix(code-health): profile regex rules match executable code, not prose
F21 (andrexibiza): PS-P05/PS-P06 ran their regexes over raw source lines, so a
comment such as `# Avoid env = os.environ.copy(); use the scoped builder.`, the same
sentence in a docstring, or a comment warning against `os.getenv("DISCORD_TOKEN")`
produced a blocking hit although nothing builds an env or reads a credential.

Before the regexes run, comment tokens (tokenize) and string statements (ast:
docstrings and bare string examples) are blanked in place, preserving every line
number and line break. Ordinary string literals inside code are kept, so the
env-key argument of `os.getenv("DISCORD_TOKEN")` still matches; the real
`env = os.environ.copy()` / `dict(os.environ)` / platform getenv stay flagged. If
tokenizing fails, the raw lines are used (more hits, never fewer).
2026-10-04 21:29:39 -07:00
Teknium
7ef5f0e1f9 fix(code-health): an allow comment may separate its rules with spaces
banditburai (inline report.py:36): `# health: allow BLE001 S110 -- boundary` waived
neither rule and reported "allow comment ignored: it needs a reason", although the
reason is there. _ALLOW accepts spaces in the rule list, but apply_allows split it
on commas only, so "BLE001 S110" was looked up as one rule name.

The rule list is now split on commas and whitespace, so `BLE001 S110`,
`BLE001, S110` and `BLE001,S110` all waive both rules. A reason is still required.
2026-10-04 21:29:39 -07:00
Teknium
f970c226f3 fix(code-health): a failing measurement tool exits 2, not with a traceback
unsupportedpastels m5: when the pinned TypeScript is not cached, ts_measure runs
`npm install`; a failed or timed-out install raised CalledProcessError /
TimeoutExpired, which cli.main did not catch (it caught RuntimeError only). The run
then died with a traceback and exit 1, which reads like a finding.

cli.main now reports those as a broken run: one `code health: measurement tooling
failed: ...` line on stderr and exit 2, like every other environment error.
2026-10-04 21:29:39 -07:00
Teknium
15274dfb41 fix(code-health): --json prints JSON on every return path
JoaoMarcos44 (inline cli.py:64): the ENFORCEMENT="off" and "no measured files
changed" branches returned before the --json formatter, so
`python -m scripts.code_health --base HEAD --head HEAD --json` succeeded with prose
on stdout and json.loads() raised.

Both early successes now print the empty findings list `[]` on stdout and move
the human explanation to stderr; findings and zero-finding measured diffs were
already JSON. Exit codes are unchanged on all four paths.
2026-10-04 21:29:39 -07:00
Teknium
ac40898e2d fix(code-health): reject unknown or empty --only selectors
F22 (andrexibiza): `scripts/check --only heath`, `--only ,` and `--only heath,rof`
filtered the job table down to nothing and reported "0 checks, ok" / exit 0, and
`--only health,rof` silently dropped the unknown name. A typo in a developer or
automation command could claim success without running the requested check.

The whole selector set is now validated before any job is built or dispatched:
an empty selection or any unknown name is a usage error (exit 2) that lists the
valid names. A valid selector still runs its check and keeps its status.
2026-10-04 21:29:39 -07:00