Description
Two near-identical helper functions exist in different crates/modules for constructing the hook environment map:
crates/zeph-subagent/src/agent_loop.rs:32 — make_hook_env(task_id, agent_name, tool_name, tool_input)
crates/zeph-core/src/agent/tool_execution/tier_loop.rs:27 — make_tool_hook_env(tool_name, tool_input, session_id)
Both functions: serialize tool_input to JSON, apply the 64 KiB truncation with floor_char_boundary, and insert ZEPH_TOOL_NAME + ZEPH_TOOL_ARGS_JSON. The differences are:
agent_loop.rs version adds ZEPH_AGENT_ID and ZEPH_AGENT_NAME (subagent-specific)
tier_loop.rs version adds ZEPH_SESSION_ID (main-agent-specific)
The truncation logic and constant (TOOL_ARGS_JSON_LIMIT = 64 * 1024) are duplicated byte-for-byte.
Expected Behavior
A single shared function in zeph-subagent (where HookDef and fire_hooks already live) should build the base env, with optional extra fields added by callers.
Actual Behavior
Two independent implementations that must be kept in sync when the limit or truncation logic changes.
Environment
Logs / Evidence
crates/zeph-subagent/src/agent_loop.rs:30-59 — make_hook_env
crates/zeph-core/src/agent/tool_execution/tier_loop.rs:21-54 — make_tool_hook_env (const TOOL_ARGS_JSON_LIMIT also duplicated)
Description
Two near-identical helper functions exist in different crates/modules for constructing the hook environment map:
crates/zeph-subagent/src/agent_loop.rs:32—make_hook_env(task_id, agent_name, tool_name, tool_input)crates/zeph-core/src/agent/tool_execution/tier_loop.rs:27—make_tool_hook_env(tool_name, tool_input, session_id)Both functions: serialize
tool_inputto JSON, apply the 64 KiB truncation withfloor_char_boundary, and insertZEPH_TOOL_NAME+ZEPH_TOOL_ARGS_JSON. The differences are:agent_loop.rsversion addsZEPH_AGENT_IDandZEPH_AGENT_NAME(subagent-specific)tier_loop.rsversion addsZEPH_SESSION_ID(main-agent-specific)The truncation logic and constant (
TOOL_ARGS_JSON_LIMIT = 64 * 1024) are duplicated byte-for-byte.Expected Behavior
A single shared function in
zeph-subagent(whereHookDefandfire_hooksalready live) should build the base env, with optional extra fields added by callers.Actual Behavior
Two independent implementations that must be kept in sync when the limit or truncation logic changes.
Environment
Logs / Evidence