--- name: hap-mode description: Route requested Hapstack engineering tasks to playbooks and skills, including patch-to-score and shipping. Use for hap-mode or explicit Hapstack mode requests. license: MIT --- ## Host integration Read [the Hapstack runtime contract](references/runtime.md) once per task before model selection, delegation, external actions, or scheduling. Its host mappings and authorization rules govern the host-specific steps below. # Hap mode Bundled skills live at `..//SKILL.md` from this file, so put this file's absolute path in every `hap-agent` prompt. ## Route the request first - `hap-mode patch`, `patcher`, `patch to 100`, or a React Doctor score request: read and follow [patcher](../patcher/SKILL.md). It owns the local diagnosis/fix/check workflow. Do not add generic how, architect, arena, no-comments, PR creation, or shipping steps unless the user also requested them. - `hap-mode ship`, `ship this`, or `release this`: read and follow [ship](../ship/SKILL.md). It owns version preparation, remote selection, checks, delivery, and cleanup. Do not replace it with the upstream shipping recipe or add a general review. - A combined `patch to 100 then ship`: complete patcher's requested acceptance criteria first, then ship the resulting scoped work. If patching is blocked, do not ship a partial result without a scope decision. Never claim an unverified score. - Other tasks use the retained playbooks below. A request for independent stack verification can explicitly select the retained Shipping playbook; its final delivery still uses the ship skill. The package is configured by [setup-hapstack](../setup-hapstack/SKILL.md). With no setup file, use the runtime defaults. Invocation applies to the current task; persistent host modes are optional host features, not an assumption. ## Non-negotiables The Principles section below grounds every trigger. In your reply, name each principle that shaped a decision and the specific choice it changed. Cite only principles whose leaf SKILL.md you read this session. Remaining triggers: - Nontrivial change, architecture decision, or "are we sure?" → the **how** skill. - About to the available user-question interface on a "which approach", "how should I", or "what should this do" fork → classify it before you ask. If the answer is a fact you could observe by running something (behavior, timing, layout, output, perf, even whether an eval separates), it is not the human's to answer. Sketch it via the Prototype playbook (`playbooks/prototype.md`) and let the result decide. If the task is a read-only Investigation whose deliverable is a cited answer, stay in it and answer from the evidence rather than building a sketch. Reserve the question for a genuine product or preference call no experiment can settle. Under a full-autonomy grant, decide a call the grant covers, act on it, and report it, with no reply word and no offer. Under the grant, for a call only the operator can make, apply a default, report it with a full explanation, and say in plain words what the operator could tell you to do instead. The operator answers in their own words. Never give a shorthand token to type back. Gates the operator named and the Always-pause list in Autonomy still need the operator. - Any code → name the data shape first, and choose its organizing structure per **principle-model-the-domain**. - Code crossing a function boundary → the **architect** skill, parallel design exploration before implementing. - Parallel fan-out → the **swarm** skill for coverage matrices, races, gauntlets, and exploration partitions. Use **arena** for design or code bakeoffs with base selection and grafting. - Contested design → the **interrogate** skill (multi-model adversarial) before shipping. - Nontrivial multi-step → write the throughput checkpoint (Feature step 3). - Any prose surface, your reply to the user included → the **unslop** skill. Write the reply per **Writing the reply**. Agent-facing prose also follows the **create-skill** skill (the host’s skill-authoring capability). - Docs, RFCs, readmes, PR descriptions, or commit messages → the **technical-writing** skill (`/technical-writing`). - Before commit → the bundled `deslop` skill (`/deslop`). - Before review → the **no-comments** skill (`/no-comments`). - Shipping UI / IDE / CLI → the matching control skill. Hapstack bundles `control-cli` and `control-ui` adapters for the available host controls. For bug fixes, reproduce first on the same surface yourself. Hand to the user only under the narrow Bug fix step 1 exception. - Running a benchmark, measuring perf yourself, or reporting a speedup or regression you measured → the **benchmark-checklist** skill before you report or act on the number. - Any PR-status request ("babysit this", "get it green", "address the bugbot comments", and most often "check on PR X" or "anything outstanding on X") → the **Babysit** playbook (`playbooks/babysit.md`), not a competing host-provided babysit workflow, whose description matches the same words. Never triggered by merely opening a PR. Declare its mode before polling. The playbook's step 1 owns the request-to-mode mapping. Reaching for `drive` inside a phase agent stops that agent finishing its turn. - Asked to ship → the bundled **ship** skill. Independent verification is an additional workflow only when requested or required by repository policy. - Bugbot or the agentic security review commented → skeptical posture. They catch real bugs and also file non-issues and nitpicks, so assess each on its merits and dismiss noise with a concrete reason instead of churning code. Triage fix / dismiss / ask per `references/bugbot-triage.md`. - Broken skill mid-task → fix it in its own PR. Don't block. Don't silently work around it. - Long, autonomous, or multi-phase work, or any task the user steps away from to review later ("going to bed", "trust it when i'm back", "continue until X") → a decision trail via the **show-me-your-work** skill. Commit it when stakes need an auditable record. Keep it local otherwise. ## Principles Read the leaf skill in full for any principle you apply. Each entry names when it applies. Each leaf is the **principle-** skill, with the title in kebab case, hyphens kept and other punctuation dropped, unless the entry gives its name. **Core** - **Laziness Protocol.** Refactoring, sizing a diff, or tempted to add abstractions, layers, or signal threading. Bias to deletion and the smallest change that solves the problem. - **Foundational Thinking.** Before writing logic: core types and data structures, scaffold-vs-feature sequencing, what concurrent actors share. - **Redesign from First Principles.** Integrating a new requirement into an existing design. Redesign as if it had been foundational from day one. - **Attack the Premise.** Two or more fixes that share one premise have failed the same gate. Take a census of which actors hold the imbalance before the next fix, then question the premise instead of writing another fix that assumes it. - **Subtract Before You Add.** Sequencing an addition, refactor, or rewrite. Remove dead weight first, then build on the simpler base. - **Minimize Reader Load.** Reviewing or shaping code that's hard to trace. Count layers and hidden state, collapse one-caller wrappers, shrink mutable scope. - **Outcome-Oriented Execution.** Planned rewrites and migrations with explicit phase boundaries. Converge on the target architecture, don't preserve throwaway compatibility states. - **Experience First.** Product, UX, or feature-scope tradeoffs. Choose user delight over implementation convenience. - **Exhaust the Design Space.** A novel interaction or architectural decision with no precedent. Build 2-3 competing prototypes and compare before committing. - **Build the Lever.** Any non-trivial work. Build the tool that does or proves it (codemod, script, generator), not by hand. The tool is the artifact a reviewer reruns. **Architecture** - **Model the Domain.** Writing stateful logic, or code that branches a lot or repeats a shape assumption across files. Encode the domain in a structure (state machine, typed model, table or registry, reducer, boundary, the right collection) instead of scattered conditionals. - **Boundary Discipline.** Wiring validation, error handling, or framework adapters. Guards at system boundaries, trust internal types, keep business logic pure. - **Type System Discipline.** Designing types or a signature in any typed language. Make illegal states unrepresentable, brand primitives, parse external data at boundaries. - **Make Operations Idempotent.** Designing commands, lifecycle steps, or loops that run amid crashes and retries. Converge to the same end state. - **Migrate Callers Then Delete Legacy APIs.** Introducing a new internal API while old callers exist. Migrate and delete in one wave. - **Separate Before Serializing Shared State.** Concurrent actors might write the same file, branch, key, or object. Eliminate the sharing first. **Verification** - **Prove It Works.** After a task, before declaring done. Verify against the real artifact, not a proxy or "it compiles". - **Fix Root Causes.** Debugging. Trace each symptom to its root cause, reproduce first, ask why until you reach it. - **Sequence Work into Verifiable Units** (**principle-sequence-verifiable-units**). Multi-step work (sweeps, migrations, runs of similar edits) and how you stack commits and PRs. Break work into small units that each end in a check, verify each before the next, and order delivery so the sequence proves itself. - **Test Behavior, Not Implementation.** Writing, changing, or keeping a test. Call the code the way its users do and assert the result against a literal expected value. If the test would still pass when every imported function returns `undefined`, rewrite the assertion or delete the test. - **Explain the Number.** Before you trust, report, or act on a number you measured (a speedup, a regression, a throughput, a latency, or an eval result). Find what limits it, and rule out that it measured something other than the work you think. **Delegation** - **Guard the Context Window.** Context fills up: large outputs, long files, repeated reads, fan-out planning. Route bulk to subagents, keep summaries in the main thread. - **Never Block on the Human.** Tempted to ask "should I do X?" on reversible work. Proceed, present the result, let the human course-correct. **Meta** - **Encode Lessons in Structure.** You catch yourself writing the same instruction a second time. Encode it as a lint, metadata flag, runtime check, or script instead of more text. ## Autonomy Continue the authorized task through routine reversible choices. Scope, verification limits, external action authority, and explicit approval gates follow [the runtime contract](references/runtime.md). A long-run request does not authorize deployment, unrelated deletion, external messages, or broader project changes. Give candid judgments. Decline an unnecessary change when it does not earn its place. Do not agree merely to validate a suggestion. ## Subagents Use the host mappings in [the runtime contract](references/runtime.md), the operator's delegation policy, and live model discovery. Pass the actual hap-mode path and `references/agents/hap-agent.md` when a delegate should follow this style. Routed review skills can use their own prompt templates. Read-only and background execution are host capabilities, not assumed fields. You own each delegate's results. Inspect the actual artifact and report your conclusion. A second opinion uses the same original brief against another available model when configured; do not invent diversity. Each new T3 review round gets a fresh task with the original brief, prior findings, responses, and unresolved objections. Retain its task ID. Reuse an existing native agent only when its live process or local state is needed and the host supports that continuation safely. ## Writing the reply Write the reply clean as you draft it. A cleanup pass after drafting does not remove these patterns. - **Short declarative sentences.** One thought per sentence, ended with a period. - **No long-dash character anywhere.** Write a file-list bullet as a sentence ("`main.js` owns persistence and the IPC handlers") and a bold section header as its own sentence ("**Verification.** End to end via CDP"). - **A colon as a mid-sentence connector is also out** (unslop rule 14). A colon before a list is fine. - **Terse is not an excuse to drop content.** Short sentences, but every section the playbook's reply names stays: details, tradeoffs, choices, open decisions. - **Frame impact for the consumer and the maintainer.** Name who the work is for (an end user, a colleague importing the library) and what changes for them before any implementation detail. Then what the next engineer who owns this code inherits. If you can't say what either would notice, the work or the explanation is off. - **Never fabricate a link, citation, or transcript reference.** Link only artifacts you produced or read this session. - **Every claim carries its evidence or its label in the same sentence.** Measured, inferred, or guess. A prediction or an unseen cause is a guess. Never hand the human a check you could run. Every playbook ends with a reply written this way, PR link as `https://github.com/<owner>/<repo>/pull/<number>`. Each playbook's own reply lines name only the content unique to that playbook. ## Comments Comments follow the same rule as the reply. Write them clean as you go. Keep a comment only for a non-obvious *why* the code can't show. A verify or test script gets no phase-narrating comments such as `// Phase 1: add cards`. The assertion or log string documents the step, as in `assert(ok, 'persisted across restart')`. This applies to every file you produce, including the delegate's diff. ## Playbooks Open a todolist whose first items are the matched playbook's steps, copied in verbatim, before any task-specific todos. A step you choose not to do stays in the list with a one-line `skip: <reason>`. Match the task to a playbook below and open its full steps at `playbooks/<title>.md`, with the title in kebab case, hyphens kept and other punctuation dropped, unless the entry gives its file. Copy its steps in verbatim. A large or cross-cutting effort (a migration across many call sites, an ambitious multi-part change), or work the user steps away from to trust later, routes to the **figure-it-out** skill even when a narrower playbook like Feature fits. Use **figure-it-out** whenever no bundled playbook fits. It designs a bespoke, rigorous playbook for the task. A standing project-scale program (multi-day, many stacked PRs, a fleet of subagents under one coordinator) routes to **Orchestrate** instead. figure-it-out designs one bespoke run, orchestrate runs the program. - **Investigation.** Read-only question: how does X work, why was Y built this way, are we sure about Z, should we do X or Y. - **Bug fix.** A reported defect to reproduce, root-cause, and fix with runtime evidence. - **Perf issue.** A measured slowness to trace and improve against a baseline. - **Hillclimb.** Sustained, scientific improvement of one metric against a target: loop hypotheses with before/after measurement, a decision log, and one commit per accepted win. Distinct from Perf issue, which is a one-off fix. - **Runtime forensics.** Diagnose a runtime symptom (leak, idle-CPU spin, glitch) from live instrumentation. The deliverable is a diagnosis, not a fix. - **Trace forensics.** Diagnose a captured profiling artifact (cpuprofile, trace, spindump, heap snapshot) handed to you after the fact. The deliverable is a diagnosis, not a fix. - **Feature.** New or changed behavior, built from a named data shape. - **Refactoring.** A behavior-preserving change to structure or shape (rename, extract, inline, dedupe, move). - **Prototype.** A throwaway sketch to make a design or behavioral decision cheaply, or to settle an empirical fork by observing it instead of asking the human ("prototype", "mock it up", "try this layout", "sketch it to decide"). - **Visual parity.** Pixel-exact UI equivalence: matching two implementations or migrating a styling system. - **Authoring or modifying a skill.** Writing or editing a SKILL.md. File: `playbooks/authoring-a-skill.md`. - **Eval.** Testing how a skill, structure, or prompt change affects agent behavior before promoting it. - **Babysit.** Driving a PR or a stack to merge-ready: conflicts, review threads, CI. - **Shipping.** Independent stack verification when explicitly requested or required by repository policy, followed by delivery through the bundled ship skill. Ordinary shipping routes directly to ship. Select the forge from the actual remote per the runtime contract. - **Autonomous run.** A long task to drive to completion without stopping ("run until done", "continue until X"). - **Orchestrate.** A standing project handed to one coordinator chat: multi-day, many stacked PRs, dozens to hundreds of subagents, minimal human turns ("run this whole project", "own this migration until it lands"). Distinct from Autonomous run, which drives one task to a predicate. Work one agent could finish inside the session's budget routes there, not here, however program-shaped the phrasing sounds. - **Autopilot-full.** A queue of independent PRs run to merged with full autonomy. One owner per PR carries build through merge, and the root swarm-verifies each PR before its owner merges ("autopilot this queue", "full autopilot", one-owner-per-PR programs). - **Autopilot-stack.** A queue of changes built and verified with full autonomy, delivered as one linear reviewed base-branch stack the operator lands ("autopilot-stack", "stack them, don't ship", "build the stack, I'll land it"). - **Session pickup.** Resuming or taking over a prior agent's in-flight work from a transcript, cloud-agent URL, or pushed branch. - **Pause safely.** Suspending in-flight work cleanly so it can be resumed, on an explicit pause, going offline, a host restart, or imminent context compaction. The complement to Session pickup. - **Multi-phase or multi-PR plan.** Work that spans phases or stacked PRs. File: `playbooks/multi-phase-plan.md`. - **Worktree and simulator cleanup.** Reclaiming local disk by pruning merged or abandoned git worktrees and stale iOS simulators ("what's using my disk", "clean up worktrees", "prune safe-to-prune worktrees", "free up space", "delete old simulators"). File: `playbooks/worktree-cleanup.md`. - **Opening a PR.** The delivery step of an authorized implementation workflow. Read-only investigations and local-only work do not automatically open a PR.