Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

6.1 KB
Raw Blame

Hook packages follow the model context, and user_prompt hooks run on every prompt

  • Date: 2026-09-29
  • Type: feature
  • Scope: core, server, cli, plugins, docs
  • PR: #891
  • Breaking: yes — an in-process user_prompt hook (SessionConfig.hooks.userPrompt) runs on every prompt unless it is marked trigger: "host", and Session.runUserPromptHook finds only hooks so marked

中文版

Hook packages became part of what a model context is assembled from, read again each time a context opens, and the user_prompt hook point started running on every prompt the user submits. The change let a package that an agent writes into its own agent_state/hooks/ during a conversation take effect at that conversation's next compaction instead of in the next conversation, and the agent-initialization skill was rewritten to teach an agent how to create, install and import Skills and hook packages.

Details

  • Hooks follow the model context. Agent.assembleContext read agent_state/hooks/ and hooks.enabled whenever a context opened: at Session creation, in the context a compaction opens, and on resume. openNextContext returned the new context's hooks as SessionOpenedContext.hooks, and the Session replaced its whole set with them (adoptHooks), empty lists included, so uninstalling the last package reached a running conversation too. Every consult read the Session's hooks when it happened, so a compaction inside one run call handed the rest of the call to the new context's hooks. The server kept invalidating an agent's cached runtimes when a hook package was installed, imported or uninstalled through the API or hooks.enabled was written, which is what brought a library install into an open conversation on its next Task.
  • user_prompt on every prompt. The engine gained a consult seam, RunOptions.userPrompt (UserPromptFn), which Session.run wired for the call's first Task. It fired when the run's input carried a user text whose sender was absent or user; server, harness and parent_agent inputs, stop-hook continuations and steering did not fire it. Hooks ran in package-name order, then manifest order, with { hook: "user_prompt", session_id, trace_path, scratchpad_dir, prompt } on stdin (trace_path was new to this hook point; prompt is the user's texts joined by newlines, leading marker blocks stripped) and { "context": "…" } on stdout.
  • Where a context goes. Each non-empty context became a user text stamped sender: "harness": yielded on the stream, written to the Trace right behind the Prompt and ahead of the first run's bootstrap records, and appended to the first request's input. A success left no hook event. A failure — a non-zero exit, stdout that is not JSON, a timeout or a throw — was recorded at the same position as a hook event with hook: "user_prompt" and the error as its reason, and otherwise ignored; HookPayload.hook gained "user_prompt".
  • Host-triggered commands. A user_prompt command took an optional trigger: "prompt" (the default) or "host". A host command stayed out of the every-prompt consult and ran only through Session.runUserPromptHook(name, prompt, extras), which found a package's trigger: "host" hook only, returned null otherwise, and passed the Session's Trace path as well. The zip import route (POST …/hooks/archive) rejected any other trigger value. A manifest written before this change is read under a compatibility rule; see backward compatibility.
  • Hand-written manifests. hooks.json was read tolerantly (readHookManifest / readHookCommands in core's state/agent-state.ts), because a package is any directory under agent_state/hooks/ that carries one: a hook point the manifest leaves out reads as []; an entry without a string command, or whose command resolves outside the package directory, is dropped, and so are a timeout that is not a positive number and an unknown trigger; a manifest that is not a JSON object makes the directory no hook package; and display fields that are not strings read as absent. GET …/hooks stopped answering 500 for a manifest that lists only user_prompt.
  • Goal rounds. Core exported isHookContinue(msg), which recognizes a stop hook's continue event. The server's goal tap (goal_round events) and the CLI's goal rendering counted a harness-stamped input as a round only when a continue event announced it; round 1 stayed the seeded input on the server and the first hook input in the CLI. Another package's context riding a goal start therefore opened no round.
  • Plugins. goal moved to 2026.09.29.1 with its start.mjs marked trigger: "host". continual-learning moved to 2026.09.29.1: its task window opened at the first record of the input batch — the user's message, its images, and the harness texts right behind it — so the excerpt kept what the user asked. agent-tuning shipped a rewritten agent-initialization skill that teaches an agent how to create, install and import Skills and hook packages.
  • Web App and docs. The Hooks tab's chat-import prompt named the optional trigger, let an unused hook point be left out, and gave the user_prompt stdin with trace_path. The Agent Loop, Skills & Plugins, Goal Mode, The OmniMessage Protocol, Core Interfaces, Sessions & Traces and Configuration Reference pages described the new contract.

Compatibility

  • An in-process UserPromptHook registered through SessionConfig.hooks.userPrompt runs on every prompt the user submits, and Session.runUserPromptHook returns null for a hook that is not marked trigger: "host". An embedder whose hook belongs to a flow it starts itself adds trigger: "host" to that hook.
  • A hand-written hooks.json whose user_prompt command must run only when a host starts it adds "trigger": "host" to the command.
  • Hook packages installed before this change keep their old reading until they are updated; see backward compatibility. Update the goal plugin from the plugin library.