Skip to content

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

13.0 KB
Raw Blame

Hooks in core, goal mode and continual learning as plugins, and the skill library becomes a plugin library

  • Date: 2026-08-29
  • Type: feature
  • Scope: core, plugins, server, web, cli, desktop, docs
  • PR: #542
  • Breaking: yes — the goal_state table is dropped by the first restart-only migration, and built-in goal mode is replaced by the goal plugin

中文版

The Session gained a generic hook mechanism: core codes the hook points — stop, the moment a Task ends, pre_tool_use and user_prompt — and the hooks themselves come from plugins as hook packages, plain Node scripts installed into agent_state/hooks/ beside agent_state/skills/. Goal mode moved out of core entirely and became the goal plugin's stop hook, ralph-loop style: a state file the hook reads and rewrites after every Task. A second hook package, continual-learning, hands a long task's findings to a background subagent. The skill library was reshaped into a plugin library — one npm package per plugin (@penguinharness/<name>), skills and hook packages inside, versions by date, loaded by @prismshadow/penguin-core — and @prismshadow/penguin-skills is deprecated.

Stop hooks

  • After every Task of a run call the Session consults the Agent's installed hook packages (top-level Sessions only), running each stop command as a subprocess with { hook, session_id, trace_path } on stdin — nothing more. Token usage, turn counts, how the Task ended and any state file are the script's to derive from the Trace.
  • A script answers continue (with the next Task's user text as input), stop, a subagent request ({ prompt, agent_id? } — the Session spawns a detached background child Session that inherits the run's approval callback, records its session id on the event and streams the child's session_meta right behind that event, so the server registers the child session — it gets a session row and appears with the other subagent sessions, without entering the parent's nested subagent view — instead of leaving an id nothing can open), or nothing. Every non-empty answer becomes one generic hook event message — hook, name (the package), decision, reason, scalar output — streamed and written to the Trace; the injected input is the user message that follows it, stamped sender: "harness" — the structural origin mark hosts render and key on, with no text protocol. The first continue drives the next Task inside the same run; after a cutoff or an aborted signal a continue is recorded but never run — the max_turns cap now counts as a cutoff (RunCutoff.kind: "max_turns", where the engine used to return null), so no hook can re-fire a Task the cap closed; a subagent round that hits its cap reports as failed with that cause instead of handing its notice over as an answer. A script that crashes, prints non-JSON or times out (default 60 s) is recorded and treated as no opinion.
  • A third hook point, user_prompt, expands a submitted prompt. Hooks run in core and nowhere else: the host triggers it through Session.runUserPromptHook when it accepts a prompt for the flow the package owns, and the answer's context is sent right behind the user's message, harness-stamped. Goal mode's start is the shipped use — the goal plugin's start.mjs is its user_prompt command.
  • A second hook point, pre_tool_use, runs before each tool call's approval (hooks.json pre_tool_use commands; stdin additionally carries tool_name, tool_call_id and the raw arguments JSON): deny refuses the call without consulting approval — the model reads the hook's name and reason as the tool's output — and allow approves without asking; the project command policy still outranks an allow (hook packages live in agent-writable state), and no built-in plugin ships one — the point is for custom guards.
  • SDK embedders can still register in-process hooks (SessionConfig.hooks.stop / .preToolUse); the subprocess runner (runHookScript) is exported for hosts that call a package's other scripts.
  • The trace page renders hook events; the CLI prints one dim line per non-goal hook answer.

Goal mode as the goal plugin

  • Core knows nothing about goals any more — session.run's goal option, the goal file helpers, goalOutcomeOf and the [goal] marker itself are gone (the goal-block marker module included). Round messages are plain user text: no protocol block, origin carried by the sender: "harness" stamp alone. The plugin (preinstalled on default_agent) ships start.mjs, which writes GOAL.json (objective, status, budget, round, tokens_used, and ended once the hook has acted on a terminal status) and composes round 1's protocol message, and stop.mjs, which after every Task reads the round's usage off the Trace (windowed from the round's injected input; completion notices share the stamp but are not boundaries), applies the same decision order as before (model verdict → cutoff → wrap-up → 100-round cap → budget → next round) and rewrites the file.
  • The server gates goal: { budget } on the package being installed (409 goal_plugin_not_installed), runs agent_state/hooks/goal/start.mjs, and submits your message exactly as typed (text and images) with the protocol message it prints right behind it, harness-stamped; later rounds restate the objective from the goal file. GET /goal reads GOAL.json (a live status while the Session is idle reads as aborted; the response no longer carries updatedAt). The plugin's start hook runs under the session lock after the idle check, so a second goal submitted over a running one is refused before it can overwrite the goal file. The goal_* server events, the chat banner, the /goal command and penguin run --goal behave as before — goal_round and the CLI's round line now count harness-injected inputs instead of parsing text; the CLI reads the outcome from the goal_finished server event. File attachments are refused. Fixed along the way: startGoal never published the seeded round-1 messages to the session channel (core never yields a run's initial input), so a second goal on the same session showed neither the user's message nor the protocol message — and no task boundary or stats row — until a reload; goal_round for round 1 is now actually emitted, counted off the seeded input.
  • The Web App shows a toast when a goal is started on an Agent without the plugin. Round messages render as a compact collapsed card ("Injected by the harness", the background notices' form, expanding to the full text) — the goal-round collapse ("Goal · round N") is gone; input history and the conversation outline skip harness-injected inputs by the stamp (background completion notices keep their turn).

The continual-learning plugin

  • Not preinstalled. When the Task that just ended ran more than 30 completed turns, its stop script condenses that Task (clipped user/assistant text, tool calls and outputs) and answers with a subagent request whose prompt asks the child to fold durable findings into the relevant SKILL.md files and bump their version. The window is the Task itself, so a Task triggers at most once — at its end — and short Tasks never do. An Agent with no installed skill never fires it.

The plugin library

  • Every plugin is its own npm package: @penguinharness/<name>, one workspace package per plugin under the repo root's plugins/ (plugin.json + icon.svg + skills/<name>/ + hooks/); the loader lives in @prismshadow/penguin-core (replacing packages/skills), reads the plugin names off the host package's dependency list and resolves each package through Node from its own location — the workspace, an npm install and the desktop app all land on their own copy (the desktop app declares the packages as dependencies, electron-builder collects them into the packed app, and the packed-app check verifies every one is there). Four merged multi-skill plugins: software-development (software-engineering + web-design), model-development (llamafactory + ollama + vllm), agent-development (penguin-sdk + unified-llm-api — renamed from agenthub-models — + penguin-config — renamed from penguin-cli — + penguin-orchestration) and agent-tuning (initialization + benchmark-design + evaluation + optimization); the rest stay single-plugin packages, preinstall unchanged; a plugin built around someone else's product carries a use- prefix — use-firecrawl, use-bento-slides, use-claude-code — so the package name says what it is for rather than claiming the product (the skills inside keep their names). Three categories: Office Productivity (the two hook packages included — goal mode and continual learning serve that audience), Software Development and AI App Development (agent-tuning included; the Agent Tuning and Session Hooks categories are gone). Versions are YYYY-MM-DD.N, and plugin.json is the single metadata holder — a library SKILL.md's frontmatter carries only name and description, with the plugin's short descriptions and version stamped into the installable copy by the loader (the installed frontmatter stays self-describing for update checks and the UI). The icon belongs to the plugin — icon.svg beside plugin.json, every built-in plugin ships one — and everything it ships inherits it: the loader stamps it onto each skill, an install writes it beside the skill's SKILL.md and beside the hook package's hooks.json, and the settings Skills and Hooks tabs, the composer's skill picker and the chat's skill chips show it. A subject with no icon falls back to one uniform mark for its kind — the book for a skill, the hook for a hook package, the puzzle piece for a plugin — the same puzzle piece that now marks the plugin library in the navigation (the open book stays the mark of skills). The natural-number version and the updated timestamp are gone.
  • Agent State: agent_state/hooks/<plugin>/ holds a hook package (hooks.json generated from the manifest — name, description, description_zh, version and one command list per hook point — plus the scripts) beside agent_state/skills/; installPlugin, installHook, removeHook and listInstalledHooks join the state layer. default_agent preinstalls every plugin not marked preinstall: false. Installing or uninstalling a hook package through the API invalidates the Agent's cached runtimes, since hooks are bound when a Session is built. The loader refuses to load with a declared plugin package missing or a broken plugin.json (a broken install, never a silently smaller library).
  • API: GET /api/plugins (categories → plugins with their skills' metadata and hook points), GET /api/plugins/:plugin/files (everything a plugin ships as text keyed by path: each skill's installable SKILL.md and reference files, the hook scripts), POST …/agents/:a/plugins { names } (whole-plugin install; reinstall = update), GET|DELETE …/agents/:a/hooks[/:name] (HookItem carries the plugin's icon; PluginItem carries no preinstall). GET /api/skills and POST …/skills { names } are gone; the installed-skill routes (list, archive import/export, uninstall) stay. Agent creation takes plugins instead of skills; AgentSummary reports hookCount and pluginUpdates (was skillUpdates); SkillMetadataItem.version is a string and updated is gone.
  • Web App: the skill library page is the plugin library (/plugins) — each card carries a semantic metadata line (v<version> · updated N days ago · used by N agents, the date parsed straight from the version) and opens a detail Modal: full description and hook points, then a file browser over everything the plugin ships in the benchmark case browser's shape — a tree on the left with one collapsible group per skill and one for the hook scripts (any number open at once) and a preview on the right, so opening a file never replaces the summary or the tree; install and update whole plugins; the Agent settings page gained a Hooks tab; the create dialog seeds plugins. CLI: penguin agent create --plugins.
  • The design spec was updated to match (penguin-harness-design #86).

Compatibility

Recorded in full in Backward compatibility: the goal_state table is dropped by migration 3 (drop-goal-state, the first restart-only migration — a hot push onto a running runtime is refused until it is restarted; a normal restart applies it at open), existing Agents get no hook packages (goal mode answers 409 goal_plugin_not_installed until goal is installed from the library), skills installed from the old library read as updatable once and keep their old icon until updated, old Traces' goal_finished records and [goal] rounds read as an unknown event and plain text, @prismshadow/penguin-skills is deprecated, and Agent creation's skills / --skills are plugins / --plugins.