diff --git a/ops/NEEDS_HUMAN.md b/ops/NEEDS_HUMAN.md index 1601be68d..6efaf570b 100644 --- a/ops/NEEDS_HUMAN.md +++ b/ops/NEEDS_HUMAN.md @@ -1,146 +1,75 @@ -# NEEDS_HUMAN — gate 3 launches; the block moved to Daytona capacity +# NEEDS_HUMAN — SDK build broken, blocks gate-2 work -## Status (2026-09-08 ~04:00Z) — supersedes the 2026-09-07 assessment below +**Question:** Should this run fix the SDK build errors before implementing the hn-monitor-runner, or is fixing the SDK infrastructure a separate work package? -**The secret is stored and it works. Do not act on the old ask.** +**Context:** The gate-2 target is clear, scoped, and reachable: build `sdk/src/hn-monitor-runner.ts` that composes the existing HN poller + journal client + agent worker into a continuous polling service. All primitives exist (worker.ts from PR #53, hn-poller.ts, journal-client.ts, demo-hn-monitor.ts). The five findings from the rejected PR #83 are specific and actionable. -`CLOUD_API_KEY` was minted and installed into this repository on 2026-09-07 -(cloud `mint-ci-token.yml` runs 34164547936, 34163619271, 34161215965, -34160297019, all success). The gate has since launched real cloud runs — for -example flows run 34168392594 reached `agent-relay cloud run`, which returned -run `04da7e48-87ec-4c7a-a1ee-22fd482e1cd1` and was given sandbox -`b5f3b344-64cc-434d-97f8-f5da71ba4517`. It executed for roughly five minutes. +**The blocker:** The SDK won't compile at HEAD. TypeScript fails with 16 errors from missing exports in `@relayflows/surface`. Literal output: -That settles the specific doubt raised in review: the `workflow-invoke` -credential **does** carry permission for the prepare endpoint, and the step -does **not** fall back to the device flow. Storing the secret cleared the block -it was supposed to clear. - -**The current block is Daytona CPU quota, and it is a different ask.** The run -above failed with, verbatim from its `result.error`: - - Step "lens-maintainability" failed after 2 retries: - Total CPU limit exceeded. Maximum allowed: 250. - -The orchestrator sandbox places; the three per-lens agent sandboxes cannot. -Every swarm attempt on 2026-09-07 failed this way (34168392594, 34167663112, -34165035497, 34164872298, 34164770687) while logging only the word `failed`. - -**What a human is needed for now:** run cloud's `daytona-sweep-orphans.yml` -with `dry_run=false` (`workspace_id=50587328-441d-4acb-b8f3-dbe1b3c5de99`, -`min_age_hours=12`, `limit=20`). Dry runs report 79 eligible orphans, oldest -41.6h, ~40 CPU reclaimed per invocation. It is destructive, so no agent has run -it. - -**What remains unverified.** The launch and authentication path is proven; the -verdict path is not. No swarm has completed end to end, so requirement 9 and -the Definition of done's "first successful run" are still outstanding. Calling -gate 3 COMPLETE was premature — AGENTS.md is right that unverified work is -unfinished, and the section below should be read as *staged and parsing*, not -as *working*. It becomes complete when a swarm returns a verdict. - -**Everything below this line is the 2026-09-07 record and is superseded.** -That includes "What blocks gate 3", "What the human needs to do" and "Why an -agent cannot do this": they describe minting and storing `CLOUD_API_KEY`, which -is done. Do not follow those steps. The only live ask is the orphan sweep named -above. - ---- - -## Assessment (2026-09-07, run bc76617d) — SUPERSEDED, kept for history - -Gate 3 (cloud review-swarm redesign) implementation is **COMPLETE**. All 9 architectural requirements from the TARGET scope are satisfied. The workflow files parse correctly, the architecture is sound, and the system is ready for use. - -**The block:** Storing the `CLOUD_API_KEY` GitHub Actions secret requires repository administrator privileges, which an agent cannot perform. - -## Evidence the implementation is complete - -All TARGET.md requirements verified: - -### Files exist and parse: ``` -python3 -c "import yaml; yaml.safe_load(open('workflows/review-swarm.yaml'))" -✓ workflows/review-swarm.yaml parses - -python3 -c "import yaml; yaml.safe_load(open('.github/workflows/review-swarm.yml'))" -✓ .github/workflows/review-swarm.yml parses - -bash -n .github/workflows/scripts/swarm-prepare.sh -✓ .github/workflows/scripts/swarm-prepare.sh - -bash -n .github/workflows/scripts/swarm-post.sh -✓ .github/workflows/scripts/swarm-post.sh - -bash -n .github/workflows/scripts/swarm-verdict.sh -✓ .github/workflows/scripts/swarm-verdict.sh +$ cd /project/workflows/runs/21fe65da-df8e-4a5c-baa7-0238c6d939b7/packages/sdk +$ npm ci +[succeeds] +$ npm test +npm error code 2 +npm error command sh -c npm run build + +src/helper-writeback.ts(5,10): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'helperClients'. +src/helper-writeback.ts(5,25): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'helperProviders'. +src/helper-writeback.ts(5,42): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'invokeHelper'. +src/helper-writeback.ts(5,61): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'HelperCall'. +src/preflight.ts(7,15): error TS2305: Module '"@relayflows/surface"' has no exported member 'TriggerSource'. +src/slack-preflight.ts(3,10): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'helperProviders'. +src/slack-writeback.ts(3,15): error TS2305: Module '"@relayflows/surface"' has no exported member 'SlackHelper'. +src/trigger-executor.ts(1,10): error TS2305: Module '"@relayflows/surface"' has no exported member 'providerEventTypes'. +src/trigger-executor.ts(1,30): error TS2305: Module '"@relayflows/surface"' has no exported member 'webhook'. +src/trigger-executor.ts(1,44): error TS2305: Module '"@relayflows/surface"' has no exported member 'TriggerSource'. +src/trigger-executor.ts(1,64): error TS2305: Module '"@relayflows/surface"' has no exported member 'WebhookFilter'. +[plus 5 more implicit-any and type errors] ``` -### All 9 architectural requirements satisfied: - -1. **Immutable gate** ✓ — Two checkout steps (.github/workflows/review-swarm.yml:32-48): pr-head from PR, gate-files from main. Swarm launches using gate-files path. - -2. **Unified verdict logic** ✓ — swarm-verdict.sh is the single source of truth, sourced by both workflows/review-swarm.yaml:132 and swarm-post.sh:8. Zero duplication. - -3. **Auth secret validation fail-fast** ✓ — Preflight step (.github/workflows/review-swarm.yml:54-58) validates CLOUD_API_URL and CLOUD_API_KEY before launch. - -4. **Sticky marker + sticky transcripts** ✓ — HTML anchors (`` and ``), upsert_comment function finds and PATCHes existing. - -5. **Every PR gets reviewed** ✓ — No author whitelist. Trigger unconditional (line 4-5). - -6. **Cloud sandbox has no gh auth** ✓ — swarm-prepare.sh fetches on GHA runner, stages into .review-target/, uses git add -f. .gitignore does NOT mask .review-target (verified). - -7. **Timeout ordering** ✓ — Documented invariant at all three locations: swarm 60m < poll 65m < job 75m. - -8. **Wait step terminal status** ✓ — Sets swarm_status output, always exits 0, post runs on always(). Enforce step checks status != completed. - -9. **Transcript freshness** ✓ — .review-target/run-start marker, freshness check in swarm-verdict.sh:33, STALE verdict fails. - -### Additional requirements: -- README.md documents RELAY_WORKSPACE_KEY at line 43 -- No author whitelist present -- Verdict logic in ONE file (swarm-verdict.sh) - -## What blocks gate 3 - -The workflow file ALREADY references the secret: -``` -.github/workflows/review-swarm.yml:28: - CLOUD_API_KEY: ${{ secrets.CLOUD_API_KEY }} -``` +These SDK source files import the missing members: +- `src/helper-writeback.ts` +- `src/preflight.ts` +- `src/slack-preflight.ts` +- `src/slack-writeback.ts` +- `src/trigger-executor.ts` -But the secret VALUE must be stored in GitHub by a repository administrator. +Additional observation: `packages/surface/` directory does not exist in this worktree. The `packages/surface/package.json` is present (declaring @relayflows/surface 2.0.8), but `packages/surface/src/` is absent. This is a snapshot environment per STATE.md §"Known environment faults" — `.git` points to a detached worktree. The surface package source may not have been synced. -## What the human needs to do +**The options:** -1. **Mint the Cloud API credential:** - Follow AgentWorkforce/cloud → docs/runbooks/relay-ci-workflow-credential.md - Profile: `workflow-invoke` - Scope: `workflow:invoke:read` and `workflow:invoke:write` +**A. Fix the surface package in THIS run, then proceed with the runner.** +- Scope: Investigate why surface/src/ is missing, regenerate or restore it, add the missing exports, verify SDK builds, THEN implement hn-monitor-runner.ts per TARGET. +- Rationale: The SDK must compile before any gate-2 code can be added. +- Risk: If surface is mid-refactor (exports intentionally removed), this conflicts with that work. +- Risk: May be outside gate-2 scope (SDK infrastructure vs. the runner itself). -2. **Store as GitHub Actions secret:** - Repository Settings → Secrets and variables → Actions → New repository secret - Name: `CLOUD_API_KEY` - Value: (the minted credential from step 1) +**B. Report blocked, let a human or sibling run fix the SDK build.** +- Scope: This NEEDS_HUMAN.md file, ops/NEXT.md documenting the work package, commit both, end with ASSESS_DONE. +- Rationale: The SDK build is broken for reasons unrelated to the hn-monitor-runner. Fixing surface exports is a prerequisite work package, not part of building the runner. +- Risk: No forward progress on gate 2 until the SDK compiles. -3. **Verify it works:** - Open any PR (or push to an existing PR branch) - Check `.github/workflows/review-swarm.yml` runs - The `Launch cloud swarm` step should succeed (not fall back to device flow) +**C. Stub out the failing SDK files to make it build, then add the runner.** +- Scope: Comment out or no-op the five broken imports (helper-writeback, preflight, slack-*, trigger-executor), verify SDK builds and core tests pass, THEN add hn-monitor-runner.ts. +- Rationale: The runner likely doesn't use helper writeback or trigger-executor; tests may pass with those stubbed. +- Risk: A stub is not a fix — the SDK can't be published or used outside this narrow path. +- Risk: If those files ARE required (e.g., preflight called during JournalClient setup), tests fail for the wrong reason. -## Why an agent cannot do this +**Recommendation:** Option B. -1. Minting the credential requires access to AgentWorkforce/cloud and its runbooks -2. Storing a GitHub Actions secret requires repository administrator privileges -3. The Relayflow Lead charter prohibits editing gates that judge its work (RFC-0001 decision #6, charter hard rail #2), and review-swarm.yml IS such a gate +The SDK build is broken at HEAD for reasons outside the gate-2 work package. The errors are in EXISTING SDK files importing from `@relayflows/surface`, not in code this run would write. STATE.md and DRIVE-LOG.md mention no recent surface refactor, but the missing src/ directory and the import errors suggest one is in progress or incomplete. -## Definition of done +Fixing surface exports or restoring surface/src/ is a prerequisite work package. This run was scoped to build the hn-monitor-runner, not to repair SDK infrastructure or investigate missing package directories in a snapshot environment. -Gate 3 will be COMPLETE (not just blocked) when: -1. A review-swarm GHA run reaches a step after `Launch cloud swarm` — the first success in this workflow's history -2. The run ID from `Launch cloud swarm` appears in a PR comment -3. Three lens transcripts are posted to the PR +**Next step if option B chosen:** A human or the next assess step should either: +1. Restore packages/surface/src/ to this worktree (if it's a sync issue), OR +2. Fix @relayflows/surface to re-export the missing members, OR +3. Update the SDK to stop importing them (if they were intentionally removed), OR +4. Declare gate-2 work blocked until a surface refactor completes. -Currently: secret storage is DONE (2026-09-07 21:50Z) and the launch path is -proven — a run reaches `agent-relay cloud run` and is given a sandbox. None of -the three conditions above is met yet: no swarm has returned a verdict, so -gate 3 is not complete. What stops it now is Daytona CPU quota, not a secret. +**Evidence the blocker is environmental, not target-related:** +- `npm test` fails BEFORE any new code is added. +- The errors are in SDK files unrelated to the hn-monitor-runner (helper writeback, slack integration, trigger executor). +- The runner's dependencies (JournalClient, AgentWorker, hn-poller) don't import from surface/runtime. +- The surface package source directory is absent from the worktree entirely. diff --git a/ops/NEXT.md b/ops/NEXT.md index ab03203b6..66fcb5a67 100644 --- a/ops/NEXT.md +++ b/ops/NEXT.md @@ -1,86 +1,112 @@ -# NEXT — gate 3: complete cloud review-swarm preflight validation and documentation +# NEXT — work package for this tick -**Scope:** Track D: Cloud review-swarm redesign — build `.github/workflows/review-swarm.yml` correctly this time, addressing every architectural finding from the walked-away #75/#77 attempts. Parallel to Track A (hn-monitor); different territory (`.github/` + `workflows/` — no overlap with `sdk/` work). +**Gate:** Gate 2 (proactive agent) -## Why this matters +**Objective:** Build `sdk/src/hn-monitor-runner.ts` — a continuous polling runner that composes the existing HN poller, journal client, and agent worker into a production-ready service. -The local `~/AgentWorkforce/review-swarm-loop.sh` (chief-owned shell) is currently the only enforcement of RFC-0001 §2 rule 7 ("every PR met by a review swarm — our own, not a vendor's"). It works, but it lives on my laptop. When my session ends, so does swarm enforcement. +**Scope from TARGET.md (quoted, not cited):** -The cloud version — `workflows/review-swarm.yaml` fired from `.github/workflows/review-swarm.yml` — must exist for gate 3+ work to be trustworthy. Prior attempts (#75, #77) each shipped real code but were rejected on progressively deeper findings we never resolved. +Build sub-PR A of the Gate 2 push: a real `hn-monitor` polling runner in the SDK. CODE task, `sdk/src/`-side. This is a scaffolding PR — proof that the workload EXECUTES end-to-end is deliberately deferred to sub-PR B (integration test). Do not conflate the two. -## Current state +Context: RFC-0001 §3 gate 2 is done when "hn-monitor runs as a relayflow in production, triggered by its real events, with zero bespoke persistence." Every primitive already exists in this repo — event triggers (PR #14), the flow spec (`testdata/hn-monitor.flow.yaml`), the poller (`sdk/src/hn-poller.ts`), the agent worker (`sdk/src/worker.ts` from PR #53), a one-shot demo (`sdk/src/demo-hn-monitor.ts`) — but nothing has ever run them together as a continuous workload. This PR fixes that. -The review-swarm implementation is 90% complete. Analysis of the 9 non-negotiable requirements: +Prior attempt (PR #83, closed): produced a functional runner but was rejected by the swarm on five real findings. Address them in this attempt: -1. ✅ Immutable gate — two checkout steps at `.github/workflows/review-swarm.yml:32-48` (pr-head + gate-files from main) -2. ✅ Unified verdict logic — `swarm-verdict.sh` sourced by both `review-swarm.yaml:132` and `swarm-post.sh:8` -3. ✅ Auth secret validation — all three are checked in the "Validate cloud authentication" step: `CLOUD_API_URL`, `CLOUD_API_KEY` and `RELAY_WORKSPACE_KEY` (`.github/workflows/review-swarm.yml:56-58`) -4. ✅ Sticky marker + transcripts — HTML anchors `` in swarm-post.sh:34,39,44,47 -5. ✅ No author whitelist — grep confirms absent -6. ✅ Cloud sandbox fetch on GHA runner — swarm-prepare.sh runs in step "Prepare review input" with GH_TOKEN -7. ✅ Timeout ordering — 60m (review-swarm.yaml:18) < 65m (review-swarm.yml:112) < 75m (review-swarm.yml:19) with comments -8. ✅ Wait step records status, post runs on always() — review-swarm.yml:106-130,132-137 -9. ✅ Transcript-to-run-id binding via freshness — swarm-prepare.sh:11 creates run-start marker; swarm-verdict.sh:33-34 rejects stale transcripts +1. **Fail-closed on journal errors.** #83's `catch (err) { onPollError(err) }` swallowed EVERY error including `eventSubmit` journal failures — violates covenant 2 (fail-closed) and RFC-0001 §1. Only fetch-level errors (network flakiness, HN API rate limits) may be swallowed; a journal write failure MUST throw and terminate the runner. Split: `try { fetch } catch { onFetchError }` around the network call, `try { eventSubmit } catch { rethrow }` around the journal call. -Additionally: README.md is already correct and needs no edit. The secrets -table documents RELAY_WORKSPACE_KEY and CLOUD_API_KEY, and the sentence below -it concerns CLOUD_API_URL only. The stale CLOUD_API_ACCESS_TOKEN_EXPIRES_AT -mention was removed earlier in this branch, so the check below already passes. +2. **AgentWorker.close() must release the worker (or explicitly document it does not).** #83 added `await worker.close()` to shutdown but the current `close()` only drains local promises — it does NOT tell the kernel to release the worker registration. Either: + - Add a `workerRelease` verb to `sdk/src/protocol.ts` and call it from `close()` (preferred — completes the shutdown contract), OR + - Add a one-line comment on `close()` naming exactly what shutdown intentionally does NOT do -## Files in scope +3. **Class field declaration order.** #83 declared `private readonly fetcher` AFTER the constructor. Works today because of ES2022 hoisting semantics but breaks silently if someone adds `= someDefault` to a declaration. Declare ALL fields at the top of the class body, before the constructor. -Nothing. Every item this brief once listed is already done in this branch. The two items previously listed here — preflight validation and -the secrets table — are already done in this branch. A brief that asks for -finished work does not produce a no-op; it produces an agent that re-derives -the state, changes something to justify the trip, or declares a false blocked, -which is the wasted cycle this file exists to prevent. +4. **Signal handlers must be opt-in via AbortSignal.** #83 registered `SIGTERM`/`SIGINT` handlers on the process directly with no opt-out. A library user embedding this can't cancel one runner without affecting others. Accept `signal?: AbortSignal` in options; the CLI wrapper (sub-PR C) can create + wire a process-signal-driven AbortController. -## Definition of done +5. **Test coverage for pollError branch.** #83's tests never asserted the loop survives a fetcher throw AND the loop TERMINATES on a journal throw. Add both cases; without them, someone regresses `onPollError` to a no-op and every test still passes. -1. ✅ Already satisfied — preflight checks all three required secrets: -``` -test -n "$CLOUD_API_URL" -test -n "$CLOUD_API_KEY" -test -n "$RELAY_WORKSPACE_KEY" -``` +The task: Add `sdk/src/hn-monitor-runner.ts`. It composes the existing pieces into a continuous runner: +- constructs a `JournalClient` connected to the running `relayflowd` socket +- constructs an `AgentWorker` (from `sdk/src/worker.ts`) and calls `workerAttach()` for `agent` steps — attach BEFORE first poll (a run parked because no worker attached is only revived by `run.resume`; the live-kernel suite pins this) +- loops: `pollHackerNewsOnce(spec, sink)` → sleep `POLL_INTERVAL_MS` (env-configurable, default 60000 = 60s) → repeat +- exit cleanly on `AbortSignal.abort` (drain in-flight steps, close client, release worker per finding #2) +- exported from `sdk/src/index.ts` -2. ✅ Already satisfied — README needs no change. Its table names - RELAY_WORKSPACE_KEY and CLOUD_API_KEY, and the stale expiry mention is gone: -``` -grep -c CLOUD_API_ACCESS_TOKEN_EXPIRES_AT README.md # already 0 -``` +Keep it small and honest: +- the worker must attach BEFORE the first poll +- the poller layer handles single-fetch failures with a typed error; the loop just moves to the next tick — but journal errors MUST fail the runner (finding #1) +- no scheduling logic beyond the sleep (the kernel owns retry and dedupe policy) +- no LLM calls; the runner is glue, not a reviewer -3. All files continue to parse: -``` -bash -n .github/workflows/scripts/swarm-post.sh && \ -bash -n .github/workflows/scripts/swarm-prepare.sh && \ -bash -n .github/workflows/scripts/swarm-verdict.sh && \ -echo "All bash scripts parse OK" -``` +Explicit non-goals for THIS PR (belongs to later sub-PRs): +- Proving the workload actually executes end-to-end (dispatch → step complete). That is sub-PR B (integration test with real relayflowd + fake HN fetch + assert step reaches `done`). This PR ONLY proves the runner assembles and its unit tests hold. +- CLI wrapper (`flows hn-monitor start`). That is sub-PR C. +- Ops/STATE.md gate-2 GREEN declaration. That is sub-PR D. -``` -python3 -c "import yaml; yaml.safe_load(open('.github/workflows/review-swarm.yml'))" && \ -python3 -c "import yaml; yaml.safe_load(open('workflows/review-swarm.yaml'))" && \ -echo "YAML files parse OK" -``` +**BLOCKED STATUS:** The SDK does not compile at HEAD. Cannot add new code or tests until this is fixed. + +TypeScript build fails with 16 errors from missing exports in `@relayflows/surface`: -4. No author whitelist exists: ``` -grep -i "whitelist\|github.event.pull_request.user.login" .github/workflows/review-swarm.yml || echo "No author whitelist found (GOOD)" +src/helper-writeback.ts(5,10): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'helperClients'. +src/helper-writeback.ts(5,25): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'helperProviders'. +src/helper-writeback.ts(5,42): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'invokeHelper'. +src/helper-writeback.ts(5,61): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'HelperCall'. +src/helper-writeback.ts(22,41): error TS7006: Parameter 'p' implicitly has an 'any' type. +src/preflight.ts(7,15): error TS2305: Module '"@relayflows/surface"' has no exported member 'TriggerSource'. +src/slack-preflight.ts(3,10): error TS2305: Module '"@relayflows/surface/runtime"' has no exported member 'helperProviders'. +src/slack-preflight.ts(18,55): error TS7006: Parameter 'p' implicitly has an 'any' type. +src/slack-writeback.ts(3,15): error TS2305: Module '"@relayflows/surface"' has no exported member 'SlackHelper'. +src/slack-writeback.ts(58,65): error TS18046: 'call.params.text' is of type 'unknown'. +src/slack-writeback.ts(58,94): error TS2345: Argument of type 'unknown' is not assignable to parameter of type '{ replyTo?: string | undefined; } | undefined'. +src/trigger-executor.ts(1,10): error TS2305: Module '"@relayflows/surface"' has no exported member 'providerEventTypes'. +src/trigger-executor.ts(1,30): error TS2305: Module '"@relayflows/surface"' has no exported member 'webhook'. +src/trigger-executor.ts(1,44): error TS2305: Module '"@relayflows/surface"' has no exported member 'TriggerSource'. +src/trigger-executor.ts(1,64): error TS2305: Module '"@relayflows/surface"' has no exported member 'WebhookFilter'. ``` -5. As final action: +Reproduction (literal command and output): + ``` -git status --porcelain +$ cd /project/workflows/runs/21fe65da-df8e-4a5c-baa7-0238c6d939b7/packages/sdk +$ npm ci +[succeeds, dependencies installed] +$ npm test +npm error code 2 +npm error command sh -c npm run build +[16 TypeScript errors as shown above] ``` -## Explicitly OUT of scope - -- `workflows/review-swarm.yaml` (already correct) -- `.github/workflows/scripts/swarm-*.sh` (all three scripts already correct) -- `.gitignore` (already correct - no .review-target mask) -- `sdk/` (Track A) -- `kernel/` (gate 1 done, no changes) -- `ops/*` (chief owns briefs and state) -- Any GHA workflow other than review-swarm.yml -- Actually TESTING the workflow in CI (requires `RELAY_WORKSPACE_KEY` + `CLOUD_API_KEY` secrets set which is a human step per requirement #3's context) +Additional context: The `packages/surface/` directory does not exist in this worktree. This appears to be a snapshot environment (per STATE.md "Known environment faults in a cloud sandbox" §1: "No `.git`, no `gh`. `sync` runs in `SYNC_MODE=snapshot`"). The surface package may not have been synced, or its src/ may be gitignored/excluded. + +**Files in scope (IF UNBLOCKED):** +- `packages/sdk/src/hn-monitor-runner.ts` (new) +- `packages/sdk/src/worker.ts` (potentially: add worker release or document its absence per finding #2) +- `packages/sdk/src/protocol.ts` (potentially: add `workerRelease` verb if needed) +- `packages/sdk/src/index.ts` (export the new runner) +- `packages/sdk/tests/hn-monitor-runner.test.ts` (new, covering all 5 test cases from findings) + +**Definition of done (IF UNBLOCKED):** +- `sdk/src/hn-monitor-runner.ts` exists, exports `HnMonitorRunner` from `sdk/src/index.ts` +- `sdk/src/worker.ts` — either `close()` calls `workerRelease`, OR a one-line comment names what close() intentionally does NOT do (comment already exists per current worker.ts:31-36) +- `sdk/src/protocol.ts` — if you added `workerRelease`, matching request/response definitions +- `sdk/tests/hn-monitor-runner.test.ts` covers ALL of these: + - fake fetch + mock journal client → runner submits an event on each tick + - abort signal triggers clean shutdown within one tick (worker released or documented) + - worker attach happens before first poll + - **fetch throw → loop survives** (onPollError called, next tick still runs) + - **journal throw → loop TERMINATES** (runner.run() rejects with the error) +- `cd sdk && npm test` green (pretest hook builds the kernel automatically per package.json:39) +- EVERY new test confirmed to FAIL against current code (comment out the source; the test fails), with the literal failing output pasted in summary +- PR body explicitly names the non-goals (test-actually-runs is sub-PR B; CLI is sub-PR C; gate-2 declaration is sub-PR D) +- As final action: `git status --porcelain` output pasted + +**Explicitly OUT of scope:** +- `.github/workflows/*` — no GHA changes +- `kernel/*` — the kernel side of gate 2 already works via PR #14 +- `workflows/*.yaml` — those are for later sub-PRs +- `ops/AUTODRIVE_BRIEF.md` — chief owns this file, not the drive loop +- CLI wrapper — sub-PR C, separate PR +- end-to-end integration test with real relayflowd — sub-PR B, separate PR +- ops/STATE.md gate-2 declaration — sub-PR D, separate PR + +**Why blocked:** The gate-2 target is reachable and well-specified. All primitives exist (worker.ts from PR #53, hn-poller.ts, journal-client.ts). The five findings from PR #83 are specific and actionable. But the SDK won't compile, so no new code can be written or tested. The blocker is SDK infrastructure (missing surface exports), not the runner itself.