Skip to content

Overhaul hooks - #51

Merged
riipandi merged 13 commits into
mainfrom
overhaul-hooks
Aug 30, 2026
Merged

riipandi merged 13 commits into
mainfrom
overhaul-hooks

Conversation

@riipandi

Copy link
Copy Markdown
Owner

Summary

Kind

  • Bug fix
  • Feature
  • Docs
  • Other (CI / refactor / pi port)

Tested

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

@netlify

netlify Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for elph ready!

Name Link
🔨 Latest commit 48c2b93
🔍 Latest deploy log https://app.netlify.com/projects/elph/deploys/6a93e14208572200088b50e7
😎 Deploy Preview https://deploy-preview-51--elph.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@riipandi
riipandi merged commit 2d90076 into main Aug 30, 2026
7 of 8 checks passed
@riipandi
riipandi deleted the overhaul-hooks branch August 30, 2026 07:52

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — beforeAgent now appends systemPrompt/additionalContext to the compiled prompt and can inject turn-only temporary messages; a new context hook event replaces the provider-bound messages array for a single request (redaction; not persisted). preToolUse supports toolInput replacement passed through the hook chain then re-schema-validated before execution; postToolUse/postToolUseFailure can replace content/details/isError and request terminate.
  • Project trust — defaultProjectTrust: ask (now the default) prompts on interactive TUI startup, never refuses untrusted projects, and no-subcommand elph launch is gated on trust. Added /untrust (explicit false, only when currently trusted) with state-aware /trust//untrust palette.
  • MCP CLI — rewrote mcp add/remove/enable/disable/list/doctor with 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 add quick dialog, /mcp list as 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 and returns unconditionally when settings_open, even for keys the dialog doesn't act on — the always-true return value of handle_settings_key is effectively dead.
  • docs/settings.md says Esc-twice discards unsaved changes; in handle_settings_key the discard path clears pending only 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash | 𝕏

Comment on lines +298 to +301
} else {
let _ = state;
drop(pending_state);
return submit_mcp_add(pending, input, paths);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
} 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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant