Repository navigation
Overhaul hooks - #51
Conversation
✅ Deploy Preview for elph ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Caution
This PR introduces an infinite recursion (stack overflow) in the new TUI /mcp add dialog that crashes the shell the first time a user adds a brand-new MCP server, and that path never actually saves the server.
Reviewed changes
- Hooks —
beforeAgentnow appendssystemPrompt/additionalContextto the compiled prompt and can inject turn-only temporarymessages; a newcontexthook event replaces the provider-boundmessagesarray for a single request (redaction; not persisted).preToolUsesupportstoolInputreplacement passed through the hook chain then re-schema-validated before execution;postToolUse/postToolUseFailurecan replacecontent/details/isErrorand requestterminate. - Project trust —
defaultProjectTrust: ask(now the default) prompts on interactive TUI startup,neverrefuses untrusted projects, and no-subcommandelphlaunch is gated on trust. Added/untrust(explicitfalse, only when currently trusted) with state-aware/trust//untrustpalette. - MCP CLI — rewrote
mcp add/remove/enable/disable/list/doctorwith transport/scope/env/header support, name validation, JSON output, and live discovery probing; legacy flags preserved. - TUI — new
/settings(Ctrl+,) visual settings editor, new/mcp addquick dialog,/mcp listas a scroll dialog, thinking-level hints, model-picker Enter-from-filter. - Panic hook — reworked to allow an updateable logs dir (fallback → resolved), serialized JSONL writes, no re-entrant logging.
- Resources — skills/prompts keyed by
resource_path_identity; per-file filtering before conflict detection.
⚠️ Trust now gates the entire interactive launch, not just project hooks
The default default_project_trust is ask, and ensure_project_trust now refuses to launch elph (no subcommand) from an untrusted directory unless the user answers the prompt. Because confirm_project_trust returns false when stdin/stdout are not a TTY, a headless/scripted elph run in an untrusted directory now exits with EXIT_PERMISSION_DENIED under the default setting — a wider blast radius than the "gate project hooks only" contract the PR title suggests. This is deliberate and well-documented, so it reads less as a bug than as a scope decision worth confirming before merge: any existing automation that launched elph in a non-interactive context will start failing by default. If prompt-on-ask for the whole session is intended, consider making the headless fallback distinguish "declined" from "can't prompt" (e.g. only hard-fail on an explicit never), so non-TTY runs aren't silently blocked by a default.
Technical details
# Trust gate scope + headless behavior
## Affected sites
- crates/coding-agent/src/cli/mod.rs (ensure_project_trust + run) — gates no-subcommand startup on trust.
- crates/coding-agent/src/cli/interactive.rs (confirm_project_trust) — returns false when stdin/stdout are not terminals.
## Required outcome
- Confirm whether failing headless `elph` launches by default (ask) is intended; if not, only `never` should hard-fail non-interactive startup.ℹ️ Nitpicks
handle_shell_key(keys.rs) runs the settings handler andreturns unconditionally whensettings_open, even for keys the dialog doesn't act on — the always-truereturn value ofhandle_settings_keyis effectively dead.docs/settings.mdsays Esc-twice discards unsaved changes; inhandle_settings_keythe discard path clearspendingonly when the error is already the "Unsaved changes" hint — consistent, but worth a manual sanity-check that the second Esc fires with the hint still present when a save error (not a dirty flag) was the last message.
DeepSeek Flash | 𝕏
| } else { | ||
| let _ = state; | ||
| drop(pending_state); | ||
| return submit_mcp_add(pending, input, paths); |
There was a problem hiding this comment.
Infinite recursion when adding a brand-new server. In the McpAddField::Source branch, the not-existing case re-invokes submit_mcp_add; on re-entry step is still Form, field is still Source, and existing is still false, so it recurses forever — a stack overflow that crashes the TUI shell. The server is also never saved: the only upsert_server_in call lives in the ConfirmUpdate branch, which a new (non-existing) server never reaches.
| } else { | |
| let _ = state; | |
| drop(pending_state); | |
| return submit_mcp_add(pending, input, paths); | |
| } else { | |
| let scope = if state.project_scope { | |
| crate::platform::mcp::McpConfigScope::Project | |
| } else { | |
| crate::platform::mcp::McpConfigScope::Home | |
| }; | |
| let server = if state.source.trim().starts_with("http://") || state.source.trim().starts_with("https://") { | |
| McpServerConfig::http(state.source.trim()) | |
| } else { | |
| let mut parts = state.source.split_whitespace(); | |
| let Some(command) = parts.next() else { | |
| state.error = Some("Enter a command or URL before saving.".into()); | |
| return Ok(false); | |
| }; | |
| McpServerConfig::stdio(command, parts.map(str::to_string).collect()) | |
| }; | |
| crate::platform::mcp::upsert_server_in(paths, scope, &state.name, server).map_err(|error| error.to_string())?; | |
| state.step = McpAddStep::Done; | |
| state.error = None; | |
| state.result = Some(format!( | |
| "Saved '{}' to {} config.", | |
| state.name, | |
| if state.project_scope { "project" } else { "user" } | |
| )); | |
| return Ok(false); | |
| } |

Summary
Kind
Tested
Update
docs/in this PR if CLI, crate API, config, or user-visible behavior changed.