agentleFS
standardbeaglestandardbeagle/agnt/.claude/skills/daemon-health-check/SKILL.md

daemon-health-check

Skill22 starsChanged 11 months agoApache-2.0View on GitHub

Design and implement health check, doctor command, and reconciliation logic for the daemon

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when implementing or modifying health check, reconciliation, or doctor functionality.

    line 8
  2. Distinctive:

    Update daemon cache to match reality

    line 40
  3. Distinctive:

    CRITICAL: Never kill a process that is producing output, even error output.

    line 46
  4. Distinctive:

    No stdout/stderr output for stall threshold (default 120s)

    line 49
  5. Distinctive:

    When implementing health check:

    line 100

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Daemon Health Check & Doctor

Use this skill when implementing or modifying health check, reconciliation, or doctor functionality.

Reconciliation Algorithm

The daemon's in-memory state is a cache. Reconciliation verifies it against OS truth and fixes mismatches.

Step 1: Gather Expected State

  • Parse .agnt.kdl for all projects with running scripts
  • Build expected set: {script → process, proxy → target, port → owner}

Step 2: Gather Actual State (OS Truth)

Cross-platform requirement — every probe must go through internal/platform/:

ProbeLinux/macOSWindowsWSL
PID alivekill(pid, 0) or /proc/<pid>OpenProcesskill(pid, 0), cmd.exe for Windows-spawned
Port ownerss -tlnp / lsof -inetstat -anoss for Linux, netstat.exe for Windows
Proxy healthTCP connect / HTTP GETSameSame

Step 3: Diff Expected vs Actual

FindingState updateEvent
Process in daemon but PID deadMark DeadEmit ScriptStopped
Port in use but not by our processFlag rogueRecord PID in warning
Proxy in daemon but not respondingMark unhealthyEmit warning
Config expects proxy but none existsAttempt fallback-portEmit warning if no fallback
Process running, no URL detected, has fallback-portCreate proxy via fallbackLog proxy creation
Process producing error outputMark Running With ErrorsSurface to AI agent

Step 4: Reconcile

  • Update daemon cache to match reality
  • Emit events for each state change
  • Return diff report (for doctor command)

Stall Detection

CRITICAL: Never kill a process that is producing output, even error output.

A process is stalled ONLY when ALL are true:

  • No stdout/stderr output for stall threshold (default 120s)
  • AlertScanner has no recent classifications
  • Process is not in Starting state

Error output IS activity:

  • AlertScanner classifies: compile errors, panics, exceptions
  • Recent alerts → "Running With Errors", not stalled
  • "Running With Errors" → surface to AI agent for code fixes, NEVER kill

Stall detection is disabled during shutdown.

Doctor Command

MCP tool doctor (or action in overlay panel):

Input

{"action": "doctor", "project_path": "/optional/filter"}

Output Format (compact)

=== Doctor Report ===

HEALTHY (2)
  backend (pid 12345): running, port 6111 ✓, proxy api ✓
  frontend (pid 12346): running, port 6112 ✓, proxy web ✓

WARNINGS (1)
  api proxy: created via fallback-port (URL detection failed)

ERRORS (1)
  deck:dev (pid 0): dead, port 5173 held by rogue process (pid 34954)
    → action: kill rogue and restart, or skip

ACTIONS AVAILABLE
  [1] Kill rogue process on port 5173 and restart deck:dev
  [2] Create missing proxy for backend using fallback-port 6111

Output Format (raw JSON)

Full structured report with all fields for programmatic consumption.

Three Reconciliation Triggers

  1. On session connect: Full check before first query response. AI agent must receive verified state.
  2. Periodic (30s): Background check, emits events only. No developer output.
  3. Doctor command: Developer-initiated, returns full report with offered actions.

Implementation Checklist

When implementing health check:

  • Create platform-specific PID probe in internal/platform/
  • Create platform-specific port ownership probe in internal/platform/
  • Create proxy health probe (TCP connect with timeout)
  • Implement reconciliation loop in internal/daemon/
  • Wire periodic check into daemon startup (configurable interval)
  • Wire on-connect check into session registration
  • Implement doctor MCP tool in internal/tools/
  • Integrate AlertScanner classifications into stall detection
  • Implement fallback-port proxy creation in reconciliation
  • Add tests for each platform path
  • Add tests for stall vs error distinction
  • Add e2e test: script running with errors is NOT killed

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.