GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mcpx: prompt hooks effect ask (#15809) · developing-today/code@eb557b1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/mcpx/internal/execsvc
    • hooks.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/mcpx/internal/execsvc/hooks.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/execsvc/hooks.go
+22-5Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ var hookTimeout = defaults.ExecHookTimeout
7272
//
7373
// `Prompt` is prompt text with @placeholders, sent to the configured model
7474
// provider (prompt_hooks.go). Its implemented effects are advise (any
75-
// phase) and propose (the outcome phases only; #11141).
75+
// phase), propose (the outcome phases only; #11141) and ask (the
76+
// before phase only, fail-closed; #15809).
7677
type Hook struct {
7778
Phase string `json:"phase"`
7879
Script string `json:"script"`
7980
// Prompt is the prompt action's text. Mutually exclusive with Script.
8081
Prompt string `json:"prompt,omitempty"`
8182
// Effect declares what the hook's output may do. For a prompt hook it
82-
// must be empty (advise), advise, or propose at an outcome phase;
83+
// must be empty (advise), advise, propose at an outcome phase, or
84+
// ask at the before phase;
8385
// for a script hook it must agree with the phase's fixed effect when
8486
// set. Anything else is refused at validation rather than silently
8587
// ignored.
@@ -114,7 +116,12 @@ type HookFrame struct {
114116
// propose), carried beside the original result or error and
115117
// never applied by mcpx (0002). Empty for every other hook.
116118
Propose json.RawMessage `json:"propose,omitempty"`
117-
Error string `json:"error,omitempty"`
119+
// Ask is an ask prompt hook's question, raised through the
120+
// broker (effect ask, #15809). Refuse is its structured refusal
121+
// reason. Empty for every other hook.
122+
Ask string `json:"ask,omitempty"`
123+
Refuse string `json:"refuse,omitempty"`
124+
Error string `json:"error,omitempty"`
118125
// Model and Provider name what answered a prompt hook, as the model
119126
// layer reports them. Empty for script hooks.
120127
Model string `json:"model,omitempty"`
@@ -184,12 +191,16 @@ func validateHooks(hooks []Hook, origin string) error {
184191
if hasPrompt {
185192
switch h.Effect {
186193
case "", hookEffectAdvise:
194+
case hookEffectAsk:
195+
if h.Phase != HookBefore {
196+
return fmt.Errorf("exec: %s hook %d (%s): prompt effect %q is only available at %s: asking is a gate on an operation that has not run, and at %s the operation is already complete (0002)", origin, i, h.Phase, h.Effect, HookBefore, h.Phase)
197+
}
187198
case hookEffectPropose:
188199
if h.Phase != HookOnSuccess && h.Phase != HookOnError {
189200
return fmt.Errorf("exec: %s hook %d (%s): prompt effect %q is only available at %s and %s: a proposal needs a result or an error to propose against, and %s is clamped to at most %q (0001)", origin, i, h.Phase, h.Effect, HookOnSuccess, HookOnError, h.Phase, hookEffectAdvise)
190201
}
191202
default:
192-
return fmt.Errorf("exec: %s hook %d (%s): prompt effect %q is not implemented (only %q and %q are implemented for prompt hooks; the other dial levels stay with #1929)", origin, i, h.Phase, h.Effect, hookEffectAdvise, hookEffectPropose)
203+
return fmt.Errorf("exec: %s hook %d (%s): prompt effect %q is not implemented (only %q, %q and %q are implemented for prompt hooks; the other dial levels stay with #1929)", origin, i, h.Phase, h.Effect, hookEffectAdvise, hookEffectPropose, hookEffectAsk)
193204
}
194205
}
195206
if hasScript && h.Effect != "" && h.Effect != effectFor(h.Phase) {
@@ -233,6 +244,10 @@ type hookRun struct {
233244
// Failed is true when the hook itself did not run or did not produce a
234245
// JSON object. It is a result, not an error: the run carries on.
235246
Failed bool
247+
// Refusal is non-empty only for an ask prompt hook that refused
248+
// the run (#15809): RunWith honours it at the before phase by
249+
// never starting the script, with this text as the run's error.
250+
Refusal string
236251
}
237252

238253
// runHooks executes every hook of one phase and returns what they produced.
@@ -262,7 +277,9 @@ func (s *Service) runHooks(ctx context.Context, phase string, hooks []Hook, hctx
262277
// A prompt hook never transforms the outcome: advise and
263278
// propose both ride in its frame, and applyHookResult is
264279
// never consulted for it, so it cannot change the outcome
265-
// whatever phase it runs in.
280+
// whatever phase it runs in. An ask hook's refusal rides
281+
// on the hookRun instead: RunWith honours it at the
282+
// before phase by never starting the script.
266283
run = s.runPromptHook(ctx, phase, h, hctx, ropts, res)
267284
} else {
268285
run = s.runOneHook(ctx, phase, h, hctx, ropts, res, emit)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.