-
Notifications
You must be signed in to change notification settings - Fork 1
feat(bg): B-0440.1 — standing-by detector skeleton + no-op poll loop (slice 1 of 6) #3006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AceHack
merged 2 commits into
main
from
otto-b0440-1-standing-by-detector-skeleton-slice-1-impl-2026-05-13
May 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # tools/bg/ — Background services | ||
|
|
||
| Background services that mechanize substrate-engineering | ||
| disciplines so the foreground loop becomes OPTIONAL per the | ||
| architectural challenge in PR #2998. | ||
|
|
||
| ## Current services | ||
|
|
||
| | Service | Slice | Purpose | | ||
| |---------|-------|---------| | ||
| | `standing-by-detector.ts` | B-0440.1 (skeleton) | Detect idle-foreground + nudge via bus when full impl lands | | ||
|
|
||
| ## Planned services (per B-0440/0441/0442) | ||
|
|
||
| - `standing-by-detector.ts` — catches the Standing-by failure mode (B-0440) | ||
| - `backlog-ready-notifier.ts` — proactively assigns ready-to-grind rows (B-0441) | ||
| - `missed-substrate-detector.ts` — catches branch-vs-merged-PR drift (B-0442) | ||
|
|
||
| ## Composition | ||
|
|
||
| All services compose with: | ||
|
|
||
| - **B-0400 bus protocol** (`tools/bus/`) — transport for nudges + assignments + cascade alerts | ||
| - **Existing background infrastructure** — `com.zeta.claude-loop` launchd + cron heartbeat | ||
|
|
||
| ## Running | ||
|
|
||
| ```bash | ||
| # One-shot mode (cron-driven; recommended) | ||
| bun tools/bg/standing-by-detector.ts --once | ||
|
|
||
| # Loop mode (standalone daemon) | ||
| bun tools/bg/standing-by-detector.ts --poll-min 5 --idle-min 15 | ||
| ``` | ||
|
|
||
| ## Slice cadence | ||
|
|
||
| Each service decomposes into ~6 implementation slices per its backlog row's | ||
| "Decomposition into implementation slices" section. Slice 1 is the skeleton | ||
| with a no-op poll loop; later slices add real detection logic, bus | ||
| integration, and tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { DEFAULT_CONFIG, pollOnce, runDetector, type DetectorConfig } from "./standing-by-detector"; | ||
|
|
||
| describe("standing-by-detector slice 1", () => { | ||
| test("default config has sensible thresholds", () => { | ||
| expect(DEFAULT_CONFIG.pollIntervalMin).toBe(5); | ||
| expect(DEFAULT_CONFIG.idleThresholdMin).toBe(15); | ||
| expect(DEFAULT_CONFIG.once).toBe(false); | ||
| }); | ||
|
|
||
| test("pollOnce returns a result with no-op detection", () => { | ||
| const result = pollOnce(DEFAULT_CONFIG); | ||
| expect(result.idleDetected).toBe(false); | ||
| expect(result.note).toContain("slice-1 skeleton"); | ||
| expect(result.pollAt).toMatch(/^\d{4}-\d{2}-\d{2}T/); | ||
| }); | ||
|
|
||
| test("runDetector with once: true exits after one iteration", async () => { | ||
| const config: DetectorConfig = { ...DEFAULT_CONFIG, once: true }; | ||
| const results = await runDetector(config); | ||
| expect(results).toHaveLength(1); | ||
| expect(results[0].idleDetected).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // standing-by-detector.ts — B-0440 slice 1: skeleton + no-op poll loop | ||
| // | ||
| // Background service that detects when an agent has been "Standing by" for N | ||
| // consecutive autonomous-loop ticks without producing substrate. Future slices | ||
| // add commit-history polling, PR-activity polling, and bus integration to | ||
| // publish nudges via B-0400 protocol. | ||
| // | ||
| // This slice ships ONLY the skeleton: poll-loop scaffolding + configurable | ||
| // thresholds + log output. No real detection yet. | ||
| // | ||
| // Run: bun tools/bg/standing-by-detector.ts [--once] [--poll-min N] [--idle-min N] | ||
| // Compose with: B-0440 (this row) + B-0400 (bus) + B-0441 (proactive notifier). | ||
|
|
||
| export type DetectorConfig = { | ||
| /** How often to poll, in minutes */ | ||
| pollIntervalMin: number; | ||
| /** Idle threshold — if no activity in this many minutes, flag Standing-by */ | ||
| idleThresholdMin: number; | ||
| /** When true, run a single poll and exit (for testing / cron-driven mode) */ | ||
| once: boolean; | ||
| }; | ||
|
|
||
| export const DEFAULT_CONFIG: DetectorConfig = { | ||
| pollIntervalMin: 5, | ||
| idleThresholdMin: 15, | ||
| once: false, | ||
| }; | ||
|
|
||
| export type PollResult = { | ||
| pollAt: string; // ISO-8601 | ||
| idleDetected: boolean; | ||
| note: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Single poll iteration. Slice 1 returns a no-op result with a placeholder | ||
| * note. Future slices will implement actual commit-history + PR-activity | ||
| * checks. | ||
| */ | ||
| export function pollOnce(_config: DetectorConfig): PollResult { | ||
| return { | ||
| pollAt: new Date().toISOString(), | ||
| idleDetected: false, | ||
| note: "slice-1 skeleton — no detection yet; future slices add commit-history + PR-activity polls", | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Run the poll loop. When `once: true`, runs exactly one iteration and | ||
| * returns its result. Otherwise sleeps for pollIntervalMin between | ||
| * iterations and runs forever; results are NOT accumulated (the daemon | ||
| * cannot leak memory by retaining unbounded history). | ||
| */ | ||
| export async function runDetector(config: DetectorConfig = DEFAULT_CONFIG): Promise<PollResult[]> { | ||
| if (config.once) { | ||
| const result = pollOnce(config); | ||
| console.log(JSON.stringify(result)); | ||
| return [result]; | ||
| } | ||
|
|
||
| // Daemon mode: emit each result but discard after logging — never accumulate. | ||
| while (true) { | ||
| const result = pollOnce(config); | ||
| console.log(JSON.stringify(result)); | ||
| await new Promise(resolve => setTimeout(resolve, config.pollIntervalMin * 60 * 1000)); | ||
| } | ||
| } | ||
|
|
||
| function parsePositiveMinutes(raw: string | undefined, name: string): number { | ||
| if (raw === undefined) throw new Error(`${name} requires a value`); | ||
| const n = Number(raw); | ||
| if (!Number.isFinite(n) || n <= 0) { | ||
| throw new Error(`${name} must be a positive finite number; got "${raw}"`); | ||
| } | ||
| return n; | ||
| } | ||
|
|
||
| function parseArgs(argv: string[]): DetectorConfig { | ||
| const config: DetectorConfig = { ...DEFAULT_CONFIG }; | ||
|
|
||
| for (let i = 0; i < argv.length; i++) { | ||
| const arg = argv[i]; | ||
| if (arg === "--once") config.once = true; | ||
| else if (arg === "--poll-min") { | ||
| config.pollIntervalMin = parsePositiveMinutes(argv[++i], "--poll-min"); | ||
| } else if (arg === "--idle-min") { | ||
| config.idleThresholdMin = parsePositiveMinutes(argv[++i], "--idle-min"); | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| // CLI entry — only fires when invoked directly, not when imported by tests. | ||
| if (import.meta.main) { | ||
| const config = parseArgs(process.argv.slice(2)); | ||
| await runDetector(config); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.