diff --git a/plugins/memhub/.claude-plugin/plugin.json b/plugins/memhub/.claude-plugin/plugin.json index 3912b11c..3aff75df 100644 --- a/plugins/memhub/.claude-plugin/plugin.json +++ b/plugins/memhub/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "memhub", "description": "Auto-capture Claude Code sessions into MemHub team memory. A Stop hook ships each turn as it happens \u2014 sending only the transcript bytes written since the last successful flush, so a session is captured even if it never reaches a clean exit \u2014 alongside flushes on commit/PR events (PostToolUse hooks) and a SessionEnd backstop. The memhub MCP runs tool-aware (agentic) extraction of facts, episodes, and artifacts with watermark-based delta dedup, batching extraction so per-turn capture doesn't fragment episodes. A PreToolUse hook surfaces situated team directives (lessons/procedures) before each Edit/Write/Bash by firing the memhub recall_directives symbol-tripwire on the in-flight call and injecting any hits as context (a client-side precision gate drops directives whose triggers don't concretely match the call, e.g. an over-broad repo-name trigger). Includes skills for: plugin install/health (setup), plugin authentication with its own hook credential (login), repo brain creation and seeding (onboard), terminal artifact uploads (save-artifact), on-demand session import (import-session), team-memory recall (search-memory), teammate session handoff (handoff-session), git-authored spec development with ownership frontmatter (spec), Rulebook rule authoring (create-rule), rules proposed from CLAUDE.md and past sessions in one run (start-rulebook), and PR babysitting (pr-babysit) \u2014 a hook arms a self-paced loop after `gh pr create` that fixes review-bot findings and saves the fixing process to the repo's agent brain. Rules live in RULEBOOKS \u2014 containers with their own membership, so a rule reaches exactly the people its book binds, and one person can be bound by several (their org's book plus their team's): the authoring skills resolve which book a rule lands in and offer to create one when there is none, the hooks cache every book that binds you, and when two books fire on one call the wider book's rule is the one the per-call cap keeps. A PostToolUse hook reminds authors when an edited file belongs to a git-authored spec. Spec ownership frontmatter replaces the retired artifact map; the backend maintains read-only mirrors and opens bootstrap or audit PRs. Sessions are named with the title their own host shows \u2014 Claude Code's generated title, or on Codex the thread_name Codex generated (from the rollout, else ~/.codex/session_index.jsonl), passed through verbatim so MemHub's sessions list matches the editor's; a session its host never named falls back to a title derived from its first prompt \u2014 and route into the repo's own agent brain via a per-user room cache (~/.config/memhub-plugin/rooms.json, never written into the repo) \u2014 resolved once by /memhub:onboard and read by every writer, including the two automatic capture paths, so team memory lands in the repo's room instead of personal memory. Session \u2194 PR linking: after a call that addresses GitHub (`gh pr \u2026`, a `curl`/`gh api` REST request, or a GitHub MCP tool) whose output names exactly one pull request, a PostToolUse hook asks the backend one question and injects one instruction \u2014 a session that ran `gh pr create` \u2014 or the GitHub MCP create tool \u2014 links itself unconditionally (opening it is work the session did, and a PR has many sessions), while every other GitHub call, a hand-rolled `curl` POST included, leaves the authorship judgment to the agent, and an org with no GitHub integration is told once that connecting it is what links sessions to shipped code. The hook is stateless apart from one short-lived negative answer (an enabled org with GitHub disconnected, cached 30 minutes per credential, and never inferred from a reply that merely says the feature is off) and degrades to silence on every failure. Two skills complete it: link-pr (link this or a named session by hand \u2014 also the answer for a PR opened by a script or CI helper, which is deliberately not detected) and find-contributing-sessions (map your own unlinked PRs, or the ones you name, to the sessions on this machine that wrote their code: scan local session history once, rank the candidates per PR by the evidence that matched, and link the ones you approve). Every rulebook fire is now disclosed to the user in a fixed shape on two channels: the hook's own terminal line leads with `\ud83d\udccf Rule fired: ` (`\u26d4\ufe0f` when a gate actually blocked the call) above the detail line it already showed, and the agent is told to echo that same byte-identical line at the top of its reply so the fire reaches the transcript everything downstream reads. Session start now says what rules ARE \u2014 standing instructions from teammates carrying CLAUDE.md's weight \u2014 before listing them. The agent records ONE work type for a pull request it links (feat, fix, chore, docs, perf, refactor, other), and only when the PR has none yet \u2014 the first label is permanent, and asking again would cost the link, not just the type. Spec workflows: spec-work guides implementation, spec-check freshly reviews changes, and spec-maintain offers local/cloud bootstrap and reviewable Git or Brain proposals through the shared spec entry point. A companion animal draws what the plugin is doing in the band above the prompt: asleep while the session is idle, awake and watching while Claude answers or the person types, and up announcing each Rulebook rule that fires \u2014 crossly when one blocked the call. It needs Claude Code's function-hook runtime, which /memhub:companion turns on and persists.", - "version": "0.87.0", + "version": "0.88.0", "license": "Apache-2.0", "hooks": ["./hooks/claude-hooks.json", "./companion/hooks.json"], "author": { diff --git a/plugins/memhub/.codex-plugin/plugin.json b/plugins/memhub/.codex-plugin/plugin.json index 2db0cc19..0b5ee8ee 100644 --- a/plugins/memhub/.codex-plugin/plugin.json +++ b/plugins/memhub/.codex-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "memhub", "description": "XTrace MemHub team memory in Codex: automatic session capture, situated directive recall, artifact sync, plus skills for setup, login, onboarding, artifact upload, session import, search, handoff, spec-driven development, Rulebook rule authoring (create-rule) and a team's first Rulebook — tested starter rules fitted to the repo, and rules proposed from CLAUDE.md + past sessions (start-rulebook), and PR babysitting. A rule lives in a RULEBOOK \u2014 a container with its own membership, so it reaches exactly the people that book binds; the authoring skills resolve which book it lands in and offer to create one when there is none. Run memhub:setup to verify hook routing and authentication. Current desktop builds support bundled hooks; older hosts need the user bridge. Bundled handlers defer to matching installed user bridge handlers, which require trust. Codex's own threads are not captured as your sessions: spawned subagents, guardian action-reviews and memory consolidation are recognised from the rollout's thread_source and skipped by name, while every other kind \u2014 including a product surface we have not seen, since Codex's ThreadSource type is open-ended \u2014 is captured, because refusing an unknown kind would silently and unrecoverably drop real work. Every rule fire is reported under the same namespaced session id capture uploads, so a fire is linked to the Codex session it fired in. Session \u2194 PR linking: after a call that addresses GitHub (`gh pr \u2026`, a `curl`/`gh api` REST request, or a GitHub MCP tool) whose output names exactly one pull request, a PostToolUse hook asks the backend one question and injects one instruction \u2014 a session that ran `gh pr create` \u2014 or the GitHub MCP create tool \u2014 links itself unconditionally (opening it is work the session did, and a PR has many sessions), while every other GitHub call, a hand-rolled `curl` POST included, leaves the authorship judgment to the agent, and an org with no GitHub integration is told once that connecting it is what links sessions to shipped code. The hook is stateless apart from one short-lived negative answer (an enabled org with GitHub disconnected, cached 30 minutes per credential, and never inferred from a reply that merely says the feature is off) and degrades to silence on every failure. Two skills complete it: link-pr (link this or a named session by hand \u2014 also the answer for a PR opened by a script or CI helper, which is deliberately not detected) and find-contributing-sessions (map your own unlinked PRs, or the ones you name, to the sessions on this machine that wrote their code: scan local session history once, rank the candidates per PR by the evidence that matched, and link the ones you approve). The agent records ONE work type for a pull request it links (feat, fix, chore, docs, perf, refactor, other), and only when the PR has none yet \u2014 the first label is permanent, and asking again would cost the link, not just the type. Spec workflows: spec-work guides implementation, spec-check freshly reviews changes, and spec-maintain offers local/cloud bootstrap and reviewable Git or Brain proposals through the shared spec entry point. A companion animal draws what the plugin is doing in the band above the prompt: asleep while the session is idle, awake and watching while Claude answers or the person types, and up announcing each Rulebook rule that fires \u2014 crossly when one blocked the call. It needs Claude Code's function-hook runtime, which /memhub:companion turns on and persists.", - "version": "0.87.0", + "version": "0.88.0", "license": "Apache-2.0", "author": { "name": "XTrace", diff --git a/plugins/memhub/.cursor-plugin/plugin.json b/plugins/memhub/.cursor-plugin/plugin.json index dc001dd8..0aa1d59e 100644 --- a/plugins/memhub/.cursor-plugin/plugin.json +++ b/plugins/memhub/.cursor-plugin/plugin.json @@ -2,7 +2,7 @@ "name": "memhub", "displayName": "MemHub", "description": "XTrace MemHub team memory in Cursor: search_memory / save_artifact / import_conversation tools plus skills for setup, login, onboarding, artifact upload, session import, recall, handoff, spec-driven development, Rulebook rule authoring (create-rule) and a team's first Rulebook — tested starter rules fitted to the repo, and rules proposed from CLAUDE.md + past sessions (start-rulebook), and PR babysitting. A rule lives in a RULEBOOK \u2014 a container with its own membership, so it reaches exactly the people that book binds; the authoring skills resolve which book it lands in and offer to create one when there is none. Sessions are captured automatically. Session \u2194 PR linking ships as skills on Cursor: link-pr and find-contributing-sessions. Cursor's shell hooks are observational \u2014 `afterShellExecution` defines no reply the agent can see \u2014 so the automatic post-`gh pr create` link that Claude Code and Codex get is not available here. The agent records ONE work type for a pull request it links (feat, fix, chore, docs, perf, refactor, other), and only when the PR has none yet \u2014 the first label is permanent, and asking again would cost the link, not just the type. Spec workflows: spec-work guides implementation, spec-check freshly reviews changes, and spec-maintain offers local/cloud bootstrap and reviewable Git or Brain proposals through the shared spec entry point. A companion animal draws what the plugin is doing in the band above the prompt: asleep while the session is idle, awake and watching while Claude answers or the person types, and up announcing each Rulebook rule that fires \u2014 crossly when one blocked the call. It needs Claude Code's function-hook runtime, which /memhub:companion turns on and persists.", - "version": "0.87.0", + "version": "0.88.0", "license": "Apache-2.0", "author": { "name": "XTrace" diff --git a/plugins/memhub/.mcp.json b/plugins/memhub/.mcp.json index 7084379d..9f27eb87 100644 --- a/plugins/memhub/.mcp.json +++ b/plugins/memhub/.mcp.json @@ -4,7 +4,7 @@ "type": "http", "url": "https://api.memhub.xtrace.ai/mcp-server/mcp", "headers": { - "X-MemHub-Plugin-Version": "0.87.0" + "X-MemHub-Plugin-Version": "0.88.0" }, "headersHelper": "python3 -s -E \"${CLAUDE_PLUGIN_ROOT}/scripts/mcp_headers.py\"", "auth": { diff --git a/plugins/memhub/mcp.json b/plugins/memhub/mcp.json index 21076089..0c7e9753 100644 --- a/plugins/memhub/mcp.json +++ b/plugins/memhub/mcp.json @@ -5,7 +5,7 @@ "type": "streamable-http", "url": "https://api.memhub.xtrace.ai/mcp-server/mcp", "headers": { - "X-MemHub-Plugin-Version": "0.87.0" + "X-MemHub-Plugin-Version": "0.88.0" } } } diff --git a/plugins/memhub/plugin.json b/plugins/memhub/plugin.json index 8a4cec52..af3a53bf 100644 --- a/plugins/memhub/plugin.json +++ b/plugins/memhub/plugin.json @@ -2,7 +2,7 @@ "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "memhub", "description": "XTrace MemHub team memory: search_memory / save_artifact / import_conversation MCP tools plus skills for setup, login, onboarding, artifact upload, session import, team-memory recall, session handoff, spec-driven development, Rulebook rule authoring (create-rule) and a team's first Rulebook — tested starter rules fitted to the repo, and rules proposed from CLAUDE.md + past sessions (start-rulebook), and PR babysitting. A rule lives in a RULEBOOK \u2014 a container with its own membership, so it reaches exactly the people that book binds; the authoring skills resolve which book it lands in and offer to create one when there is none. Session auto-capture ships through the host-native plugin layer (hooks are outside the Agent Plugins spec). Session \u2194 PR linking: after a call that addresses GitHub (`gh pr \u2026`, a `curl`/`gh api` REST request, or a GitHub MCP tool) whose output names exactly one pull request, a PostToolUse hook asks the backend one question and injects one instruction \u2014 a session that ran `gh pr create` \u2014 or the GitHub MCP create tool \u2014 links itself unconditionally (opening it is work the session did, and a PR has many sessions), while every other GitHub call, a hand-rolled `curl` POST included, leaves the authorship judgment to the agent, and an org with no GitHub integration is told once that connecting it is what links sessions to shipped code. The hook is stateless apart from one short-lived negative answer (an enabled org with GitHub disconnected, cached 30 minutes per credential, and never inferred from a reply that merely says the feature is off) and degrades to silence on every failure. Two skills complete it: link-pr (link this or a named session by hand \u2014 also the answer for a PR opened by a script or CI helper, which is deliberately not detected) and find-contributing-sessions (map your own unlinked PRs, or the ones you name, to the sessions on this machine that wrote their code: scan local session history once, rank the candidates per PR by the evidence that matched, and link the ones you approve). The agent records ONE work type for a pull request it links (feat, fix, chore, docs, perf, refactor, other), and only when the PR has none yet \u2014 the first label is permanent, and asking again would cost the link, not just the type. Spec workflows: spec-work guides implementation, spec-check freshly reviews changes, and spec-maintain offers local/cloud bootstrap and reviewable Git or Brain proposals through the shared spec entry point. A companion animal draws what the plugin is doing in the band above the prompt: asleep while the session is idle, awake and watching while Claude answers or the person types, and up announcing each Rulebook rule that fires \u2014 crossly when one blocked the call. It needs Claude Code's function-hook runtime, which /memhub:companion turns on and persists.", - "version": "0.87.0", + "version": "0.88.0", "license": "Apache-2.0", "author": { "name": "XTrace", diff --git a/plugins/memhub/scripts/rulebook_hook.py b/plugins/memhub/scripts/rulebook_hook.py index a154f55c..70874475 100644 --- a/plugins/memhub/scripts/rulebook_hook.py +++ b/plugins/memhub/scripts/rulebook_hook.py @@ -1924,7 +1924,13 @@ def matcher_unsupported(m): _RX_KEYS = ("rx", "not_rx", "body_rx", "cmd_rx", "cmd_not_rx", "path_rx", "path_not_rx", "content_rx", "content_not_rx", "exclude_rx", "converted_rx") -_RX_MAX = 400 +# Length is a bound on what one rule can cost to compile and store, NOT the +# backtracking guard — `_RX_NESTED` below is. A 60-character pattern can stall +# and a 1,500-character alternation of literal paths cannot, so the bound is +# wide enough for the second. It was 400 before 0.88.0: a hook older than that +# drops any rule carrying a longer pattern, which is why the server floors such +# a rule at `min_hook_version` 0.88.0. +_RX_MAX = 2000 # (a+)+, (\d+)+$, (a|a)+, (.*), .*.* — the classic backtracking shapes. A # denylist, not a proof: stdlib `re` has no timeout, and a bounded matcher # (worker + wall clock) is the Phase 2 answer named in §5.1. @@ -1933,14 +1939,17 @@ def matcher_unsupported(m): def rx_ok(pat): """Load-time lint for a pattern that came off the wire (§5.1 fallback): - must compile, stay short, and avoid the nested-quantifier shapes that + must compile, stay under `_RX_MAX`, and avoid the nested-quantifier shapes that backtrack catastrophically. A rejected pattern drops the RULE, never the hook — a server book can advise, it cannot stall a tool call.""" if not isinstance(pat, str) or len(pat) > _RX_MAX or _RX_NESTED.search(pat): return False try: re.compile(pat) - except re.error: + except Exception: + # Not only `re.error`: a deeply nested pattern raises RecursionError + # and `a{99999999999}` raises OverflowError. Whatever the parser + # objects to, the answer is the same — this pattern does not load. return False return True diff --git a/plugins/memhub/skills/create-rule/SKILL.md b/plugins/memhub/skills/create-rule/SKILL.md index 967dfb22..6565f1e9 100644 --- a/plugins/memhub/skills/create-rule/SKILL.md +++ b/plugins/memhub/skills/create-rule/SKILL.md @@ -499,7 +499,7 @@ raised the subject. It exits non-zero until every case behaves. **Do not file a rule while it exits non-zero, and show the table to the user.** What each line means: -- **LOAD** — whether the hook would load the rule at all. A pattern over 400 +- **LOAD** — whether the hook would load the rule at all. A pattern over 2000 characters, one that does not compile, or one that backtracks is dropped *silently* on every teammate's machine: the rule exists, is active, and never fires. This line is the only warning you get. diff --git a/plugins/memhub/skills/start-rulebook/scripts/starter_rulebook.py b/plugins/memhub/skills/start-rulebook/scripts/starter_rulebook.py index e996c97f..bcaeb95a 100644 --- a/plugins/memhub/skills/start-rulebook/scripts/starter_rulebook.py +++ b/plugins/memhub/skills/start-rulebook/scripts/starter_rulebook.py @@ -49,7 +49,7 @@ # Written without a quantified group: the hook's load lint drops those. # `/usr/bin/git` is the same program: a path in front of it is not a way round every git rule. GIT = CMD + r"(?:sudo\s+)?(?:\S*/)?git\s+(?:-[cC]\s*\S+\s+)?" -RX_MAX = 400 +RX_MAX = 2000 # the hook's `_RX_MAX` since 0.88.0; the server floors a pattern over 400 at that version # Appended to a command pattern to make it a RECEIPT: the command, but not an invocation that exits 0 # having done none of the work — `pytest --version`, `eslint --help`, `pytest --collect-only`. _RAN_NOTHING = (r"\b(?![^|;&]*\s(?:--version|-V|--help|-h|--collect-only|--co|--fixtures|--markers|--setup-plan" @@ -96,7 +96,7 @@ def _alt(parts) -> str: def _fit(prefix: str, extras: list[str], suffix: str = "") -> str: """Append alternatives while the whole pattern stays loadable. The hook - drops a rule whose pattern passes 400 characters, silently, so a long + drops a rule whose pattern passes `RX_MAX` characters, silently, so a long repo-derived list is cut here rather than shipped dead.""" rx = prefix for e in extras: diff --git a/tests/rulebook_hook_test.py b/tests/rulebook_hook_test.py index 12c7143f..2f15d8d4 100644 --- a/tests/rulebook_hook_test.py +++ b/tests/rulebook_hook_test.py @@ -2622,6 +2622,32 @@ def pre(session, word): inert is not None and inert.get("mode") == "gate" and not inert.get("_degraded"), str(inert)) + # The length bound is not the backtracking guard, so it is wide enough + # for a long alternation of literals — and still a bound. + long_rx = "^(?:" + "|".join(f"src/pkg{i:03d}/mod\\.py" for i in range(60)) + ")$" + check("regex length: a pattern between the old 400 bound and _RX_MAX loads", + 400 < len(long_rx) <= H._RX_MAX + and H.to_hook_rule(_row("long-rx", {"event": "bash", "command_rx": long_rx})) + is not None, str(len(long_rx))) + check("regex length: a pattern at _RX_MAX loads and one past it drops the rule", + H.rx_ok("a" * H._RX_MAX) and not H.rx_ok("a" * (H._RX_MAX + 1)) + and H.to_hook_rule(_row("over-rx", {"event": "bash", + "command_rx": "a" * (H._RX_MAX + 1)})) + is None) + # Under the bound but past the parser's recursion limit: `re.compile` + # raises RecursionError, not re.error. The rule drops; nothing tracebacks. + deep_rx = "(" * 500 + "a" + ")" * 500 + check("regex length: a deeply nested pattern under _RX_MAX drops the rule, no traceback", + len(deep_rx) <= H._RX_MAX and not H.rx_ok(deep_rx) + and H.to_hook_rule(_row("deep-rx", {"event": "bash", "command_rx": deep_rx})) + is None) + # Short, and never caught by the length bound: the parser raises + # OverflowError for a repetition count it cannot hold. + check("regex: a repetition count too large for the parser drops the rule, no traceback", + not H.rx_ok("a{99999999999}") + and H.to_hook_rule(_row("big-rep", {"event": "bash", "command_rx": "a{99999999999}"})) + is None) + # An ordering rule needs its arming event first; this one says # `session`, so the session lane has to have run. run("session", {"session_id": "v1", "cwd": repo, diff --git a/tests/rulebook_verify_test.py b/tests/rulebook_verify_test.py index 407fbd6d..80d5fbfc 100644 --- a/tests/rulebook_verify_test.py +++ b/tests/rulebook_verify_test.py @@ -87,12 +87,18 @@ def main() -> int: rc == 1 and "SILENT FAIL" in out, out) # --- the silent-drop class -------------------------------------------- - rc, out = run(bash(command_rx="a" * 450), "--fires", "aaa") + rc, out = run(bash(command_rx="a" * 2050), "--fires", "aaa") check("a pattern over the hook's length bound is reported as a LOAD failure", rc == 1 and "LOAD FAIL" in out and "longer than" in out, out) rc, out = run(bash(command_rx="(a+)+$"), "--fires", "aaa") check("a catastrophically backtracking pattern is a LOAD failure", rc == 1 and "LOAD FAIL" in out, out) + rc, out = run(bash(command_rx="(" * 500 + "a" + ")" * 500), "--fires", "aaa") + check("a deeply nested pattern under the length bound is a LOAD failure, not a traceback", + rc == 1 and "LOAD FAIL" in out and "Traceback" not in out, out) + rc, out = run(bash(command_rx="a{" + "9" * 500 + "}"), "--fires", "aaa") + check("a repetition count the parser cannot hold is a LOAD failure, not a traceback", + rc == 1 and "LOAD FAIL" in out and "Traceback" not in out, out) rc, out = run(bash(command_rx="[unclosed"), "--fires", "x") check("a pattern that does not compile is a LOAD failure", rc == 1 and "LOAD FAIL" in out, out)