Repository navigation
feat(mcpx): prompt-action advise hooks for exec (#5276) - #9021
Conversation
A hook entry declares exactly one action: the existing script, or a prompt with effect advise resolved through the configured internal/model provider. Placeholders are JSON-encoded data, advice rides the hook frame before the final frame and never transforms the outcome, and no provider is a deterministic warning fallback. Config and per-call declarations share the list; daemon resolves the layer per request, the CLI from the same model.* settings.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 9 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75b8c6540f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if prov, merr := s.modelLayer(r.Context(), req.Options.Session); merr != nil { | ||
| svc.ModelProviderErr = merr | ||
| } else { | ||
| svc.ModelProvider = prov |
There was a problem hiding this comment.
Resolve the model layer for every execution entry point
When execution enters through /v1/ask with kind: exec, runAsk in routes_proto.go calls s.ExecService().Run(...) directly and never reaches this initialization. Since ExecService leaves ModelProvider nil, prompt hooks on that route always report that no provider is configured, even with valid model.* settings. Script-backed tools in scriptview.go take the same direct path, so their config-declared prompt hooks are also unavailable. Move model initialization into a shared, context-aware service setup used by these execution entry points.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fd6d1e2: model-layer resolution now lives in Server.modelLayerForExec (daemon/routes_exec.go) and is applied by every execution entry point that can run config-declared prompt hooks: /v1/exec, /v1/ask kind:exec (runAsk in routes_proto.go), and script-backed tools (scriptview.go). Daemon tests in exec_model_layer_test.go pin the stamped provider/error for the configured, unbuildable, and absent cases.
| resp, err := prov.Generate(callCtx, model.Request{ | ||
| Model: h.Model, | ||
| Messages: []model.Message{ | ||
| {Role: "system", Content: promptHookSystem}, | ||
| {Role: "user", Content: rendered}, | ||
| }, |
There was a problem hiding this comment.
Apply the global model token budget to prompt hooks
When an operator sets a positive model.budget, this generation request still leaves MaxTokens at zero, bypassing the documented hard ceiling. Neither model.Resolve nor the provider applies the global setting automatically; the existing generation and repair paths explicitly cap requests with modelMaxTokens(..., pol.ModelBudget). For an OpenAI-compatible provider, zero causes the token-limit field to be omitted entirely, allowing hook advice to consume more tokens than configured. Carry the resolved global budget into the hook request and enforce it alongside any profile-local bound.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fd6d1e2: the prompt-hook generation request now carries Service.ModelMaxTokens, resolved as prompt.maxTokens capped by model.budget via execsvc.ModelTokenCap (the same rule as daemon modelMaxTokens). The daemon resolves it from the request policy in modelLayerForExec; the CLI resolves it from settings in localService. Covered by TestRunPromptHookAppliesTokenCap and TestModelTokenCap.
| out.Frame.Advice = advice | ||
| out.Frame.Model = resp.Model |
There was a problem hiding this comment.
Preserve prompt advice in structured execution responses
For /v1/exec requests using the default structured output, the handler passes a nil sink, which RunWith replaces with a no-op. Prompt advice is stored only in this hook frame, and the returned Result has no field retaining hook frames or advice. Consequently, these requests perform the model generation but discard its entire answer; provider-unavailable warnings are likewise discarded. Unlike script hooks, the new prompt action has no other output or effect, so it is unusable on the default response path. Preserve advice and hook warnings in the structured response without changing the script's result or error.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fd6d1e2: hook frames are retained on Result.Hooks in run order — runHooks appends each frame to the result as it emits it — so the structured /v1/exec response (nil sink) now carries prompt advice and hook warnings. The script result and error are untouched. Covered by the retained-frame assertion in TestRunHooksEmitsPromptFrameBeforeOutcome.
…p, advice in structured results (#5276) Dispositions the three Codex P2 findings on PR #9021: - Entry points (routes_exec.go comment): model-layer resolution moves into Server.modelLayerForExec, now used by /v1/exec, /v1/ask kind:exec (runAsk), and script-backed tools (scriptview.go) — those routes built their exec service bare, so config-declared prompt hooks there always reported no provider configured. Daemon tests pin the stamped provider, error, and cap. - Token budget (prompt_hooks.go): a prompt hook's generation now carries Service.ModelMaxTokens — prompt.maxTokens capped by model.budget via execsvc.ModelTokenCap (the modelMaxTokens rule); the daemon resolves it from the request policy and the CLI from settings in localService. A zero MaxTokens would have been omitted by the provider, silently bypassing a configured budget. - Structured advice (execsvc): hook frames are retained on Result.Hooks in run order (runHooks appends as it emits), so the default structured /v1/exec response — nil sink, no stream — carries a prompt hook's advice and warnings instead of generating and discarding them. Result and error are unchanged. Tests: execsvc cap table + provider-request cap + retained-frame assertions; daemon modelLayerForExec (configured, unbuildable, absent). go test ./internal/execsvc/ and the daemon model-layer tests pass.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd6d1e2f9d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| svc.ModelMaxTokens = execsvc.ModelTokenCap(set.Int("prompt.maxTokens"), set.Int("model.budget")) | ||
| return svc |
There was a problem hiding this comment.
Forward configured prompt hooks to the local CLI service
For a local mcpx exec or mcpx run with a prompt entry in script.hooks, resolving the provider here never results in the hook running: localService leaves svc.Hooks empty, and the caller in commands.go constructs execsvc.Options without Hooks. The existing ScriptPhase plumbing reads the separate legacy phase fields, not script.hooks; a search across internal/cli found no ScriptHooks conversion or hook-list assignment. Consequently, the newly documented config-declared prompt hooks are silently ignored on the default local execution path, even with a configured provider and hooks.autonomy=run. Populate the local service's hook list from the resolved configuration under the autonomy gate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e819507: localService (internal/cli/exec.go) now takes the run's config and populates svc.Hooks from cfg.ScriptHooks(), gated by hooks.autonomy at run exactly as the daemon gates config-declared hooks in routes_exec.go and as hookGate gates the legacy phases. The sole caller in commands.go passes its resolved cfg. Local mcpx exec / mcpx run runs now execute config-declared prompt (and script) hooks instead of silently ignoring script.hooks.
| s.modelLayerForExec(ctx, svc, opts.Session) | ||
| res, runErr := svc.Run(ctx, req, nil) |
There was a problem hiding this comment.
Include prompt-hook advice in script-backed tool responses
For a script-backed tool with a configured prompt hook, this path now invokes the model but still discards its answer. The nil sink delivers no frames, and the response construction below copies only stdout, replacement results, emits, and execution errors into MCP content; it never includes the newly retained res.Hooks. Thus both generated advice and provider-unavailable warnings disappear before reaching the tool caller. Include the retained hook advice and warnings in the tool response without replacing the script's own result.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e819507: runScriptView (internal/daemon/scriptview.go) now appends each retained res.Hooks frame to the MCP tool content — advice as "hook advice (phase): ..." and a frame error as "hook warning (phase): ..." — after stdout/replacement/emits, so prompt advice and provider-unavailable warnings reach the tool caller without replacing the script's own result.
| callCtx, cancel := context.WithTimeout(ctx, hookTimeout) | ||
| defer cancel() | ||
| resp, err := prov.Generate(callCtx, model.Request{ | ||
| Model: h.Model, |
There was a problem hiding this comment.
Apply the default model to sampling-backed prompt hooks
When model.provider is sampling or plugin, model.default is configured, and the hook omits its own model, this request sends an empty model instead of the configured default. Unlike the OpenAI provider and profile router, the sampling and plugin providers simply forward the request; samplingParams in daemon/consumer.go consequently omits modelPreferences entirely. The existing generateViaModel path explicitly supplies pol.ModelDefault before generation, but this path does not, so the answerer loses the operator's configured model preference despite Hook.Model promising that an empty value takes the configured default. Carry the default selection into the hook request while preserving explicit per-hook overrides.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e819507: execsvc.Service gains ModelDefault, stamped from the policy (daemon modelLayerForExec: pol.ModelDefault) and from settings (CLI localService: model.default). runPromptHook now sends h.Model when set, else s.ModelDefault, so sampling/plugin providers — which forward the request as given — receive the configured default; the frame's fallback model name uses the same resolved value. Covered by TestRunPromptHookAppliesDefaultModel (default applied, explicit hook model wins) and the ModelDefault assertion in TestModelLayerForExecStampsCapAndProvider.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e819507244
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for _, h := range cfg.ScriptHooks() { | ||
| svc.Hooks = append(svc.Hooks, execsvc.Hook{Phase: h.Phase, Script: h.Script, Prompt: h.Prompt, Effect: h.Effect, Model: h.Model, Name: h.Name}) |
There was a problem hiding this comment.
Surface prompt-hook advice in local CLI output
For local mcpx exec or mcpx run with configured prompt hooks and hooks.autonomy=run, the hooks now invoke the provider, but default text output and --json still discard their advice and warnings. In commands.go, the text path leaves the sink nil and only reports artifacts afterward; the JSON path also uses a nil sink and builds its response through runEnvelope, which never copies res.Hooks. Consequently, these calls incur model latency and cost without delivering the prompt hook's sole effect. Include retained hook frames in the JSON envelope and render advice/warnings on the text path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in db22dac: runEnvelope now carries res.Hooks as the envelope's hooks key when a run produced frames (pinned by TestRunEnvelopeCarriesHooks, including the no-hooks/no-key case), so the --json path delivers advice and warnings. The default text path now calls reportHooks alongside reportArtifacts: retained frames render to stderr as "mcpx: hook advice (phase): ..." / "mcpx: hook warning (phase): ...", keeping stdout as the script's own answer. The stream path already encodes hook frames live, and the structured path marshals res itself, hooks included.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db22dac059
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| } else if eo.Output != execsvc.OutputStream { | ||
| a.reportArtifacts(res) | ||
| a.reportHooks(res) |
There was a problem hiding this comment.
Render hook advice on the remote CLI text path too
For mcpx exec --remote or mcpx run --remote using default text output, configured prompt hooks invoke the model but their advice and warnings still disappear. This new reportHooks call only covers local execution: the remote branch returns earlier through execOnDaemon, then execRemote and renderExecResult, whose text branch prints stdout, emits and artifacts without inspecting res.Hooks. Call the helper from that shared remote renderer too, so remote text callers receive the prompt hook's output rather than paying for advice they cannot see.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9b39a59: renderExecResult's text branch now calls reportHooks next to reportArtifacts, so mcpx exec --remote / mcpx run --remote text callers receive prompt-hook advice and warnings from the retained frames. That renderer is the shared remote path (execRemote and the serve/call renderers go through it); its JSON/structured branch already marshals res with hooks included, and the stream path echoes hook frames as they arrive.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b39a59d4b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| defer func() { | ||
| out.Duration = time.Since(start) | ||
| out.Frame.DurationMs = out.Duration.Milliseconds() | ||
| }() |
There was a problem hiding this comment.
Populate hook timing before copying the return value
For prompt hooks that spend time waiting for a provider, including requests that time out, the returned timing remains zero. This function has an unnamed return value, so each return out copies the struct before the deferred callback updates the local out. Consequently, runHooks emits and retains a frame without durationMs, hiding the model latency. Use a named result or populate the timing before returning so callers receive the measured duration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 829d328: runPromptHook (internal/execsvc/prompt_hooks.go) now returns a named result, so the deferred timing callback updates the value the caller actually receives instead of a copy made at each return. Covered by TestRunPromptHookReportsDuration (a 25ms fake provider must yield run.Duration and frame durationMs of at least 25ms).
| s.modelLayerForExec(ctx, svc, opts.Session) | ||
| res, err := svc.Run(ctx, execsvc.Request{Source: req.Source, Opts: opts, RunID: run, CallSettings: callSettingsHeaderValue(callSettingsFrom(ctx))}, nil) |
There was a problem hiding this comment.
Attach prompt-hook sampling questions to the active ask call
When model.provider=sampling or plugin and a sampling-capable MCP host invokes mcpx_exec through native asking, the resolved brokerSamplerFor opens and awaits a completion question without recording it on the active askCall (consumer.go). However, daemonAsker.Begin routes this invocation through runAsk, and handleAskPoll exposes only questions from call.snapshot(), so the host never receives the prompt-hook request and the hook waits until timeout instead of providing advice. Associate these questions with the active ask/run, as Registry.sampleViaBroker does through Registry.attach for upstream sampling.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 829d328: the broker sampler (internal/daemon/consumer.go brokerSamplerFor) now records its question on the active interruptible ask call via the new Registry.attachSample (internal/daemon/routes_proto.go), and runAsk stamps the call id on the run context (withAskCall) like the other ask paths. handleAskPoll therefore surfaces the prompt hook's sampling/createMessage question to the host driving the call, which answers it through the broker by id. Outside an ask call attachSample is a no-op and broker answerers remain the route. Covered by TestBrokerSamplerAttachesQuestionToActiveAskCall (question appears on the call's snapshot; an ask answer returns the host's advice through the sampler).
| run.Frame.Original = applyHookResult(&run, phase, res) | ||
| run.Frame.Changed = run.Frame.Original != nil | ||
| var run hookRun | ||
| if h.Prompt != "" { |
There was a problem hiding this comment.
Dispatch hooks using the validated action predicate
When a hook contains a valid script and a whitespace-only prompt, validateHooks accepts it as script-only because action presence is checked with strings.TrimSpace. This dispatch instead treats any nonempty prompt as the selected action, so the script never executes and an accepted apply transformation or suffix cleanup is replaced by a prompt advice request. Both config resolution and wire options preserve that whitespace. Normalize the action fields or use the same trimmed predicate here so execution matches validation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 829d328: dispatch in runHooks (internal/execsvc/hooks.go) now selects the action with validation's trimmed predicate -- strings.TrimSpace(h.Prompt) != "" -- so a script hook carrying a whitespace-only prompt runs its script, exactly as validateHooks reads it. Covered by TestWhitespacePromptDoesNotHijackScriptHook (onSuccess script hook with Prompt " " applies its transform; frame action stays module).
…he validated predicate, keep hook timing (#5276)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 829d328ea3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // prompt hook's advice — its entire output — was generated and | ||
| // then discarded (Codex review, PR #9021). Retaining them here | ||
| // changes neither the script's result nor its error. | ||
| Hooks []HookFrame `json:"hooks,omitempty"` |
There was a problem hiding this comment.
Include retained hook advice in mcpx_exec responses
When an MCP host invokes mcpx_exec with config-declared prompt hooks, the model runs but its advice and warnings still disappear. Both mcpBackend.Exec in internal/cli/serve.go and the interruptible path in internal/cli/serve_ask.go pass the returned result through renderExec, which renders stdout, emits, replacement results and artifacts but never reads res.Hooks. Retaining frames here therefore fixes structured HTTP responses without delivering the prompt hook's sole output to MCP callers. Include hook advice and warnings in that shared MCP renderer while preserving the script's own outcome.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 037cc53 (PR #9021): renderExec now appends retained hook advice and provider warnings (hookAdviceText, same Advice/Error selection as the CLI text path's reportHooks) to the mcpx_exec tool result on the success path, to the error text on the failure path, and as the whole result when advice is all a run produced — so both mcpBackend.Exec and the interruptible serve_ask path deliver prompt-hook output to MCP callers while preserving the script's own outcome. Regression test: TestRenderExecCarriesHookAdvice in internal/cli/serve_hooks_test.go (oracle stated there). go test ./internal/execsvc ./internal/cli passes.
| if source == "" { | ||
| source = ropts.File |
There was a problem hiding this comment.
Load file-backed script contents for the source placeholder
For local mcpx run <file>, runScript in internal/cli/commands.go sets runner.Options.File and leaves Source empty, so this fallback substitutes the file's path rather than its source code into @source. The same prompt therefore receives code for an inline execution but only a filename for a file-backed execution. A model asked to review or explain @source cannot inspect that local file from the generation request, so file-backed runs produce advice without the requested code context. Resolve the file contents for this placeholder rather than substituting its path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 037cc53 (PR #9021): promptValues in internal/execsvc/prompt_hooks.go now resolves @source for a file-backed run by reading runner.Options.File's contents when Source is empty — the same code an inline run substitutes — and only falls back to the path when the file cannot be read. Regression test: TestPromptValuesSourceFromFile in internal/execsvc/prompt_hooks_test.go (contents case + unreadable-file fallback case). go test ./internal/execsvc ./internal/cli passes.
…from file contents (#5276)
…t-advise-hooks # Conflicts: # pkgs/mcpx/internal/cli/commands.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38a9fd04ff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| id, ok := ctx.Value(askCallKey{}).(string) | ||
| if !ok || id == "" { | ||
| return false |
There was a problem hiding this comment.
Resolve nested sampling questions through the owning run
When an interruptible mcpx_exec invokes a script-backed tool whose prompt hook uses sampling, the nested hook's question is never exposed to the host and waits until timeout. Unlike the fixed top-level runAsk path, the fresh evidence here is the nested /v1/call path: server.go:1195 restores only X-Mcpx-Run, and runDeclaredScript associates the nested execution through attachRunToRun (scriptview.go:325-326) without setting askCallKey. This early return therefore ignores an existing ask owner. Fall back to resolving the owner through the context's run ID before abandoning attachment.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b022e30: Registry.attachSample (internal/daemon/routes_proto.go) now falls back to resolving the owning ask call through the context's run id -- new askTable.forRun over the byRun registry (beginRun / attachRun / attachRunToRun) -- when no askCallKey is present, which is exactly the nested /v1/call shape: server.go restores only X-Mcpx-Run and runDeclaredScript attaches the script-backed tool's fresh run to the parent run. The question is therefore recorded on the interruptible call that owns the run and surfaces in its ask poll. Covered by TestBrokerSamplerAttachesQuestionThroughOwningRun (parent run on context; nested run attached to parent). go test ./internal/execsvc ./internal/daemon ./internal/settings passes; the one cli failure in the combined run (TestInlineDaemonCancelledWhileWaiting, a 5s timing budget) passes in 0.57s in isolation and this change touches no cli code.
| if cfg != nil && settings.AutonomyAtLeast(set.String("hooks.autonomy"), "run") { | ||
| for _, h := range cfg.ScriptHooks() { | ||
| svc.Hooks = append(svc.Hooks, execsvc.Hook{Phase: h.Phase, Script: h.Script, Prompt: h.Prompt, Effect: h.Effect, Model: h.Model, Name: h.Name}) |
There was a problem hiding this comment.
Collect local tool calls before enabling call-aware prompt hooks
For local mcpx exec or mcpx run with an outcome prompt referencing @calls, these hooks receive [] even when the script successfully called tools. localService never initializes svc.Calls, and RunWith populates its call snapshot only inside if s.Calls != nil; the actual calls execute through the separate daemon, with no forwarding into this local service. Consequently, the newly enabled local hooks can generate advice based on a false empty call history. Forward the run's daemon call records into the local hook context rather than presenting an uncollected history as no calls.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not fixed in this PR -- deferred with reason, split to issue #9349. The local path has no collection surface to forward from: execsvc.CallRegistry is a live, in-process, per-run sink registry (no retention, no query API), and a local run's tool calls are reported to the DAEMON process's registry via X-Mcpx-Run -- a different process from the CLI's localService, which never sees them. Populating @Calls locally therefore needs a new cross-process surface (daemon retention plus a run-calls query the CLI fetches before outcome hooks, or client-side reporting back into the local process): a design addition beyond this advise-hooks slice, and rushing it here would risk the exec paths this PR just stabilised. Daemon runs are unaffected (routes_exec stamps the shared registry; their @Calls is populated). Issue #9349 records the root cause, the design options, and the acceptance bar, including that an uncollected history must not be presented as an empty one. -- queue task 9174, lane any-c
…ice 1) (#11155) Implements the `propose` effect for prompt hooks at the script point, the second #1929 Approach C prompt slice after advise (#5276, PR #9021): - Validation: `effect: propose` is accepted at onSuccess and onError only. At before (nothing exists to propose against yet) and suffix (clamped to at most advise by 0001) it is refused with a named reason, in the existing refusal style. ask/apply/run stay refused as not implemented. - HookFrame gains a `propose` field (the proposed value, JSON). The reply is parsed as a hook output object: the `propose` key carries the proposed replacement (any JSON value); a reply that is not a JSON object is a plain-text proposal (a plan is a legitimate proposal per 0002) carried as a string value; an object naming no control keys is itself the proposal. Keys above the declared effect (apply, run) are dropped and named in the frame's `dropped` list — never honoured, never silent. - The run's result and error are never modified by a propose hook in any phase: the proposal rides in the frame beside the original, unapplied — the whole definition of the level (0002). - Propose gets its own system text (the reply is a proposal, carried beside the original), keeping advise's data-not-instructions guard for placeholder values. - No provider configured: the frame reports the proposal as unavailable and the run continues, exactly like advise — propose is not a gate and keeps the fail-soft contract. Tests (oracle: a propose hook can never change the outcome — only add a frame-carried proposal beside it): object reply with dropped apply/run keys, plain-text reply, onError beside the untouched error, validation refusals for before/suffix, no-provider frame, and the runHooks path retaining the proposal on the result with the result unchanged. Full execsvc package passes. Out of scope per the issue: ask/apply prompt effects, the run effect, script/module hook output keys, and the hooks.autonomy / autonomy.max registry ceiling track. Co-authored-by: repo-worker-tmp-code-b <fleet@developing.today>
What
Implements the first prompt-action slice for mcpx exec hooks (#1929 Approach C, issue #5276): a hook entry now declares exactly one action — the existing deterministic
script, or apromptwitheffect: advise(the default and the only effect in this slice).Hookgainsprompt/effect/model; validation refuses both-actions, neither-action, prompt effects above advise, and script effects that contradict the phase's fixed effect — invalid combinations fail loudly instead of silently doing nothing. Prompt hooks run through the newrunPromptHook(internal/execsvc/prompt_hooks.go): the template's@placeholders(built-ins@result,@error,@diagnostic,@calls,@artifacts,@source, plus the call's own placeholder values) are substituted JSON-encoded as data, never raw text, under a system prompt that states values are data, not instructions. The answer rides the hook frame asadvicewithmodel/providerrecorded, at the same frame position a script hook occupies (before the final result/error frame). Advice never transforms the result or error in any phase — prompt runs deliberately leavehookOutputempty so the onError advice-append path for script hooks cannot fire for them.Service.ModelProvidercarries the configuredinternal/modellayer. The daemon resolves it per request (modelLayerinhandleExec, so configured-but-unbuildable surfaces as a named error in the frame); the CLI's local service resolves the samemodel.*settings. No provider (the default) is a frame-level "advice unavailable" warning and the run continues deterministically — it is never an error and never blocks the run.CallInfoonly) so outcome/suffix hook contexts carry@calls; config-declared hooks (HookConfig) acceptprompt/effect/modeland the daemon's conversion forwards them, so configured and per-call declarations share the one list in declaration order.docs/exec.mdframe-order section documents the prompt action.Deferred, as scoped: effects
ask/propose/apply/run, prompt actions on non-script points, and the opencode plugin provider backend — all stay with #1929.Tests
internal/execsvc/prompt_hooks_test.go(validation table, placeholder data-delimiting with a hostile value, success / no-provider / provider-error paths, frame emission and unchanged outcome, per-hook model pass-through) andinternal/config/hooks_prompt_test.go(prompt entry resolution).go test ./internal/execsvc ./internal/daemon ./internal/cli— pass.internal/configandinternal/settingshave failures that reproduce identically on the unmodified tree at this commit (verified by stash):TestServerKeysAnotherHostWritesAreRecordedNotRefused,TestTheScriptEnvironmentIsWhatTheCodeSets,TestTheEnvironmentDocIsCurrent,TestEveryDocumentHasAChapter— pre-existing, unrelated to this change.Fixes #5276.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.