Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG/v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **Dispatched subagents now inherit memory context ([#1068](https://github.com/robotrocketscience/aelfrice/issues/1068)).** Workers spawned via agent dispatch previously ran blind to the belief store — no SessionStart baseline, no per-prompt retrieval, and no locked constraints crossed the dispatch boundary. A new `PreToolUse:^(Agent|Task)$` hook (`aelf-agent-context-hook`) rewrites the worker's prompt through the harness's `updatedInput` channel, prepending a bounded `<aelfrice-worker-context>` block: L0 locked beliefs (with #1016 provenance-aware framing and reference-lock manifest bounding) plus beliefs relevant to the worker's task at the reduced auxiliary budget the Grep|Glob lane uses. Both harness channels were probed live before implementation (see the issue): `updatedInput` applies without a `permissionDecision` — so the hook never touches the user's permission flow — while `SubagentStart` was rejected for this lane (its payload carries no prompt text, so it cannot do query-aware retrieval). Fail-open everywhere (no store / malformed payload / retrieval error → byte-identical passthrough), idempotent on already-tagged prompts (nested dispatch never double-injects), and deterministic per #605. Installed by default via `aelf setup` (skip with `--no-agent-context`); runtime kill switch `AELFRICE_AGENT_CONTEXT=0`. Claude-host only for now — the Codex desired-set is unchanged pending #1056 live validation.

- **Codex host target for `setup` / `doctor` / `unsetup` ([#1052](https://github.com/robotrocketscience/aelfrice/issues/1052)).** `aelf setup --host codex` writes the portable aelfrice hook subset into `~/.codex/hooks.json` — merge-aware, idempotent, and refusing (without `--force`) to clobber an unparseable existing file — and prints the trust-approval steps (`/hooks` in a Codex session; `codex features enable codex_hooks`, since the upstream hooks surface is feature-flagged off by default). `aelf doctor --host codex` validates hooks.json shape, aelfrice event coverage, on-disk commands, the feature flag, and `[hooks.state]` trust coverage; `aelf unsetup --host codex` removes only aelfrice-owned entries. Trust hashes are never computed client-side — the upstream trust schema is explicitly slated to change. Compaction rebuild rides `SessionStart(source=="compact")`, the only injection channel Codex honors ([#1054](https://github.com/robotrocketscience/aelfrice/issues/1054) investigation). Bash-matcher tool hooks (memory-first shell search, pre-issue duplicate guard, commit ingest) ride along unchanged ([#1055](https://github.com/robotrocketscience/aelfrice/issues/1055)): Codex canonicalizes shell commands to `tool_name == "Bash"`, so the matchers are host-portable; only the `Grep|Glob` hook (tools that don't exist on Codex) and the host-specific memory mirror are excluded.

- **Persistent host-level auto-install opt-out ([#1053](https://github.com/robotrocketscience/aelfrice/issues/1053)).** A Codex-primary machine no longer needs `AELFRICE_NO_AUTO_INSTALL=1` inlined on every hook command: a new `opt_out_hosts` key in `~/.aelfrice/opt-out-hooks.json` (written automatically by `aelf setup --host codex` when the Claude host has no aelfrice hooks) gates the CLI-entry settings merge. Dual-host machines are left untouched; an explicit `aelf setup` clears the opt-out.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ aelf-transcript-logger = "aelfrice.transcript_logger:main"
aelf-pre-compact-hook = "aelfrice.hook:main_pre_compact"
aelf-commit-ingest = "aelfrice.hook_commit_ingest:main"
aelf-search-tool-hook = "aelfrice.hook_search_tool:main"
aelf-agent-context-hook = "aelfrice.hook_agent_context:main"
aelf-session-start-hook = "aelfrice.hook:main_session_start"
aelf-stop-hook = "aelfrice.hook:main_stop"
aelf-pre-issue-hook = "aelfrice.pre_issue_create_hook:main"
Expand Down
6 changes: 6 additions & 0 deletions src/aelfrice/auto_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from aelfrice.setup import (
SettingsScope,
USER_SETTINGS_PATH,
install_agent_context_hook,
install_claude_memory_mirror_hook,
install_commit_ingest_hook,
install_pre_issue_guard_hook,
Expand All @@ -60,6 +61,7 @@
install_stop_hook,
install_transcript_ingest_hooks,
install_user_prompt_submit_hook,
resolve_agent_context_command,
resolve_claude_memory_mirror_command,
resolve_commit_ingest_command,
resolve_hook_command,
Expand Down Expand Up @@ -396,6 +398,10 @@ def _atomic_write_json(path: Path, data: dict[str, object]) -> None:
resolve_claude_memory_mirror_command,
install_claude_memory_mirror_hook,
),
"agent_context": (
resolve_agent_context_command,
install_agent_context_hook,
),
}


Expand Down
56 changes: 56 additions & 0 deletions src/aelfrice/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
from aelfrice.scanner import scan_repo
from aelfrice.session_resolution import resolve_session_id
from aelfrice.setup import (
AGENT_CONTEXT_SCRIPT_NAME,
CLAUDE_MEMORY_MIRROR_SCRIPT_NAME,
COMMIT_INGEST_SCRIPT_NAME,
PRE_ISSUE_GUARD_SCRIPT_NAME,
Expand All @@ -144,6 +145,7 @@
clean_dangling_shims,
default_settings_path,
detect_default_scope,
install_agent_context_hook,
install_claude_memory_mirror_hook,
install_commit_ingest_hook,
install_pre_issue_guard_hook,
Expand All @@ -156,6 +158,7 @@
install_stop_hook,
install_transcript_ingest_hooks,
install_user_prompt_submit_hook,
resolve_agent_context_command,
resolve_claude_memory_mirror_command,
resolve_commit_ingest_command,
resolve_pre_issue_guard_command,
Expand All @@ -166,6 +169,7 @@
resolve_session_start_hook_command,
resolve_stop_hook_command,
resolve_transcript_logger_command,
uninstall_agent_context_hook,
uninstall_claude_memory_mirror_hook,
uninstall_commit_ingest_hook,
uninstall_pre_issue_guard_hook,
Expand Down Expand Up @@ -3586,6 +3590,23 @@ def _cmd_setup(args: argparse.Namespace, out: object) -> int:
f"mirror_claude_memory is set",
file=out, # type: ignore[arg-type]
)
if getattr(args, "agent_context", True):
ac_command = resolve_agent_context_command(scope)
ac_result = install_agent_context_hook(
path, command=ac_command, timeout=args.timeout,
)
if ac_result.already_present:
print(
f"agent-context hook already installed in {ac_result.path} "
f"(command={ac_command!r})",
file=out, # type: ignore[arg-type]
)
else:
print(
f"installed agent-context PreToolUse:Agent hook in "
f"{ac_result.path} (command={ac_command!r})",
file=out, # type: ignore[arg-type]
)
slash_dest = getattr(args, "slash_commands_dir", None)
slash_dest_path = Path(slash_dest) if slash_dest else None
sc_result = install_slash_commands(slash_dest_path)
Expand Down Expand Up @@ -3630,6 +3651,7 @@ def _cmd_setup(args: argparse.Namespace, out: object) -> int:
"search_tool": "search_tool",
"search_tool_bash": "search_tool_bash",
"pre_issue_guard": "pre_issue_guard",
"agent_context": "agent_context",
}


Expand Down Expand Up @@ -4001,6 +4023,21 @@ def _cmd_unsetup(args: argparse.Namespace, out: object) -> int:
f"{'y' if pig_result.removed == 1 else 'ies'} from {pig_result.path}",
file=out, # type: ignore[arg-type]
)
if getattr(args, "agent_context", True):
ac_result = uninstall_agent_context_hook(
path, command_basename=AGENT_CONTEXT_SCRIPT_NAME,
)
if ac_result.removed == 0:
print(
f"no agent-context hook in {ac_result.path}",
file=out, # type: ignore[arg-type]
)
else:
print(
f"removed {ac_result.removed} agent-context entr"
f"{'y' if ac_result.removed == 1 else 'ies'} from {ac_result.path}",
file=out, # type: ignore[arg-type]
)
slash_dest = getattr(args, "slash_commands_dir", None)
slash_dest_path = Path(slash_dest) if slash_dest else None
usc_result = uninstall_slash_commands(slash_dest_path)
Expand Down Expand Up @@ -7652,6 +7689,17 @@ def _positive_int(s: str) -> int:
"AELFRICE_NO_PRE_ISSUE_GUARD=1."
),
)
p_setup.add_argument(
"--agent-context", dest="agent_context",
action=argparse.BooleanOptionalAction, default=True,
help=(
"wire the PreToolUse:Agent hook so dispatched subagent prompts "
"carry the L0 locked beliefs plus prompt-relevant memory context "
"(injected via updatedInput). Default: ON. Pass "
"--no-agent-context to skip. Disable at runtime with "
"AELFRICE_AGENT_CONTEXT=0."
),
)
p_setup.set_defaults(func=_cmd_setup)

# Hidden: install lifecycle, surfaced by docs not by --help.
Expand Down Expand Up @@ -7827,6 +7875,14 @@ def _positive_int(s: str) -> int:
"Default: ON. Pass --no-pre-issue-guard to leave it in place."
),
)
p_unsetup.add_argument(
"--agent-context", dest="agent_context",
action=argparse.BooleanOptionalAction, default=True,
help=(
"remove the PreToolUse:Agent agent-context hook entry. "
"Default: ON. Pass --no-agent-context to leave it in place."
),
)
p_unsetup.set_defaults(func=_cmd_unsetup)

# Hidden: CI regression target. Humans run via `python -m aelfrice.benchmark`
Expand Down
8 changes: 8 additions & 0 deletions src/aelfrice/data/hook_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
"default_on": true,
"since": "3.7.0",
"description": "PostToolUse:Write|Edit|MultiEdit mirror of claude-memory writes into the belief graph; inert until AELFRICE_MIRROR_CLAUDE_MEMORY / [memory] mirror_claude_memory is set (#985)."
},
{
"name": "agent_context",
"basename": "aelf-agent-context-hook",
"installer": "agent_context",
"default_on": true,
"since": "3.9.0",
"description": "PreToolUse:Agent worker-context injection — carry L0 locks + prompt-relevant beliefs into dispatched subagent prompts via updatedInput; disable with AELFRICE_AGENT_CONTEXT=0 (#1068)."
}
]
}
1 change: 1 addition & 0 deletions src/aelfrice/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"<commit", "</commit>",
"<linked-issues>", "</linked-issues>",
"<belief", "</belief>",
"<aelfrice-worker-context>", "</aelfrice-worker-context>",
)


Expand Down
Loading
Loading