{"name":"agent-lifecycle","title":"Agent Lifecycle Visibility","description":"Add live child-agent visibility to something you are building — an orchestrator, CLI, desktop app or web UI: one event schema over several child runtimes, plus recovery of events missed across a disconnect or restart. Symptoms: show what my subagents are doing, stream agent status into the UI, normalise different child runtimes behind one interface, my agent events stop after a reconnect. This builds the feature; it is not a dispatch or routing policy.","compatibility":null,"allowedTools":null,"license":"MIT","kind":"signals","useWhen":"making delegated child agents observable, or reconciling what one of them actually did","group":null,"lifecycle":null,"version":null,"author":null,"install":["npx skills add crissmoldovan/agent-skills --skill agent-lifecycle"],"asks":["Show the current child lifecycle status. For every child include child ID,\nliteral state (running, waiting, completed, failed, cancelled, or lost), current\nactivity or tool, freshness, and transcript/result reference where safe.\nReconcile stale children before drawing a terminal conclusion.","Integrate agent-lifecycle into this orchestrator. Normalize child events, keep\nactivity separate from heartbeat, reconcile complete snapshots after reconnect,\nand preserve immutable terminal states. Prefer native child UI.","Render one active aggregate todo labelled display-only and one DISPLAY ONLY row\nper child with ID, state, activity/tool, and freshness. Treat those rows as a\nprojection only; edits must not change lifecycle state."],"commands":[],"documents":[{"path":"references/adapter-contract.md","slug":"adapter-contract","title":"Adapter Contract (v0.2.0)","body":"# Adapter Contract (v0.2.0)\n\nThis is the runtime boundary for live child-agent visibility. Keep runtime SDK\nobjects, process handles, and UI-framework types outside this contract. It\nmatches the schema-v1 primitives implemented by this repository; it does not\ncreate a native child in a host product.\n\n## Required Types\n\nUse equivalent names in the host language only if the semantics remain intact.\n\n```text\nChildState =\n  created | starting | running | waiting |\n  completed | failed | cancelled | lost\n\nCapability = known | unknown\n\nLineage {\n  rootChildId: string\n  attempt: non-negative integer\n  external: boolean\n  parentChildId?: string\n  adoptedAt?: RFC3339 UTC timestamp\n}\n\nLifecycleEvent {\n  schemaVersion: 1\n  eventId: string\n  source: string\n  sourceEpoch: string\n  childId: string\n  lineage: Lineage\n  kind: created | state_changed | activity | heartbeat |\n        terminal | reconciliation | diagnostic\n  state?: ChildState\n  observedAt: RFC3339 UTC timestamp\n  sequence?: non-negative integer\n  activity?: string\n  details?: JSON object\n  capabilities: {\n    history: Capability\n    heartbeat: Capability\n    snapshot: Capability\n    cancel: Capability\n    terminalCause: Capability\n  }\n}\n\nAuthoritativeSnapshot {\n  source: string\n  sourceEpoch: string\n  snapshotId: string\n  observedAt: RFC3339 UTC timestamp\n  complete: true\n  coverage: all | child-id list\n  children: [{ childId, state, sequence?, details? }]\n}\n```\n\n`created`, `state_changed`, and `terminal` require a state. `created` is always\nstate `created`; `terminal` is one of `completed`, `failed`, `cancelled`, or\n`lost`. `activity` and `heartbeat` do not carry state. `details` is additive;\nit must not be the sole source of identity, ordering, state, or liveness.\n\n## Adapter Interface\n\n```text\ninterface ChildLifecycleAdapter {\n  subscribe(onEvent: (event: LifecycleEvent) => void): Unsubscribe\n  getSnapshot(reason: session_open | reconnect | periodic): AuthoritativeSnapshot\n  cancel?(childId: string, reason?: string): CancelResult\n}\n```\n\n- `subscribe` may use callbacks, streams, polling differences, or JSONL.\n- `getSnapshot` is authoritative only if it declares complete coverage. An\n  incomplete source view must be represented separately and cannot prove an\n  omitted child absent.\n- `cancel` is optional. Never synthesize it for an externally adopted child\n  without documented, verified authority.\n- The adapter must make its own health and source limitations observable.\n\n## Projection Rules\n\n1. Allocate one `childId` per lifecycle; retries use a new child ID and share\n   `rootChildId` with an incremented attempt.\n2. Deduplicate a sequenced event by `(source, sourceEpoch, childId, sequence)`.\n   Without sequence, deduplicate only byte-equivalent `eventId` records.\n3. Track high sequence per source epoch. A forward gap is provisional; an old\n   sequence is out-of-order. A new source epoch permits a restarted counter.\n4. Terminal states are immutable. A complete authoritative snapshot may correct\n   a non-terminal projection and must emit an auditable correction; it cannot\n   revive a terminal outcome.\n5. Use activity for work context and heartbeat for liveness. A missed heartbeat\n   marks stale only after the configured deadline.\n6. Mark `lost` only after that stale child’s reconciliation attempt fails.\n7. On reconnect, obtain a snapshot before trusting resumed incrementals where a\n   gap cannot be ruled out.\n8. Process snapshot omission only when complete coverage is proven. Use a\n   consecutive-complete-miss grace policy before emitting stale/unknown intent.\n\n## JSONL Fallback and Journal\n\nOne complete UTF-8 line is one event object. Producers flush complete lines and\ndo not mix ordinary logs into the lifecycle stream.\n\n```json\n{\"schemaVersion\":1,\"eventId\":\"evt-7\",\"source\":\"worker-cli\",\"sourceEpoch\":\"start-2\",\"childId\":\"child-42\",\"lineage\":{\"rootChildId\":\"child-42\",\"attempt\":0,\"external\":false},\"kind\":\"state_changed\",\"state\":\"running\",\"observedAt\":\"2026-08-24T09:15:30.000Z\",\"sequence\":7}\n```\n\nConsumers must incrementally buffer partial lines, cap line size, validate\nbefore projection, and retain only bounded redacted diagnostics for malformed\ninput. EOF is not `completed`; reconcile or observe a runtime exit.\n\nFor an append-only journal, the reference implementation uses an atomic\nper-path lock directory around replay, sequence reservation, and append.\nConcurrent calls in one process serialize, and cooperating Node processes\nexclude one another. Lock acquisition has a bounded timeout; stale reclamation\nrequires both the configured age and a recorded PID that is demonstrably dead,\nand cleanup verifies the owner token. The journal becomes append-blocked if\nreplay detects malformed, oversized, truncated, or non-monotonic content.\nThis is cooperative advisory exclusion: programs that ignore the lock protocol\nand filesystems without atomic directory operations remain unsupported.\n\n## Hermes Adapter Foundation\n\nThe Hermes foundation maps delegation events and status snapshots into a\nhost-owned integration. It requests snapshots at session open, reconnect, and\nperiodically; overlapping requests coalesce. Complete Hermes snapshots may\ncorrect records by child ID. An omitted locally-running child generates a\nstale-unknown intent only after the configured consecutive complete-snapshot\ngrace (default two); incomplete snapshots never generate that intent.\n\nThis is not Hermes Desktop core integration. A host must supply source identity,\nlineage, capabilities, event persistence, audit rendering, and any approved UI\nintegration.\n\n## External Adoption Limits\n\n| Observable | What may be stated |\n| --- | --- |\n| PID/process presence only | Process was observed; history, agent state, intent, and cancellation are unknown. |\n| Process exit code | A process ended with that code; task success is not implied. |\n| Runtime status endpoint | Exposed current state can be projected; missed history remains unknown. |\n| Event stream plus complete snapshot | Visibility begins at adoption; pre-adoption history remains unknown unless supplied. |\n| Verified control API | Cancellation may be offered within the documented authority scope. |\n\nAlways retain `external: true`, adoption time, source identity, and verified\ncapabilities. Never turn observation into a claim that the orchestrator created,\nowns, or can safely terminate the child.\n","bodyHtml":"<h2 id=\"adapter-contract-v020\">Adapter Contract (v0.2.0)</h2>\n<p>This is the runtime boundary for live child-agent visibility. Keep runtime SDK\nobjects, process handles, and UI-framework types outside this contract. It\nmatches the schema-v1 primitives implemented by this repository; it does not\ncreate a native child in a host product.</p>\n<h3 id=\"required-types\">Required Types</h3>\n<p>Use equivalent names in the host language only if the semantics remain intact.</p>\n<pre><code class=\"language-text\">ChildState =\n  created | starting | running | waiting |\n  completed | failed | cancelled | lost\n\nCapability = known | unknown\n\nLineage {\n  rootChildId: string\n  attempt: non-negative integer\n  external: boolean\n  parentChildId?: string\n  adoptedAt?: RFC3339 UTC timestamp\n}\n\nLifecycleEvent {\n  schemaVersion: 1\n  eventId: string\n  source: string\n  sourceEpoch: string\n  childId: string\n  lineage: Lineage\n  kind: created | state_changed | activity | heartbeat |\n        terminal | reconciliation | diagnostic\n  state?: ChildState\n  observedAt: RFC3339 UTC timestamp\n  sequence?: non-negative integer\n  activity?: string\n  details?: JSON object\n  capabilities: {\n    history: Capability\n    heartbeat: Capability\n    snapshot: Capability\n    cancel: Capability\n    terminalCause: Capability\n  }\n}\n\nAuthoritativeSnapshot {\n  source: string\n  sourceEpoch: string\n  snapshotId: string\n  observedAt: RFC3339 UTC timestamp\n  complete: true\n  coverage: all | child-id list\n  children: [{ childId, state, sequence?, details? }]\n}\n</code></pre>\n<p><code>created</code>, <code>state_changed</code>, and <code>terminal</code> require a state. <code>created</code> is always\nstate <code>created</code>; <code>terminal</code> is one of <code>completed</code>, <code>failed</code>, <code>cancelled</code>, or\n<code>lost</code>. <code>activity</code> and <code>heartbeat</code> do not carry state. <code>details</code> is additive;\nit must not be the sole source of identity, ordering, state, or liveness.</p>\n<h3 id=\"adapter-interface\">Adapter Interface</h3>\n<pre><code class=\"language-text\">interface ChildLifecycleAdapter {\n  subscribe(onEvent: (event: LifecycleEvent) =&gt; void): Unsubscribe\n  getSnapshot(reason: session_open | reconnect | periodic): AuthoritativeSnapshot\n  cancel?(childId: string, reason?: string): CancelResult\n}\n</code></pre>\n<ul>\n<li><code>subscribe</code> may use callbacks, streams, polling differences, or JSONL.</li>\n<li><code>getSnapshot</code> is authoritative only if it declares complete coverage. An\nincomplete source view must be represented separately and cannot prove an\nomitted child absent.</li>\n<li><code>cancel</code> is optional. Never synthesize it for an externally adopted child\nwithout documented, verified authority.</li>\n<li>The adapter must make its own health and source limitations observable.</li>\n</ul>\n<h3 id=\"projection-rules\">Projection Rules</h3>\n<ol>\n<li>Allocate one <code>childId</code> per lifecycle; retries use a new child ID and share\n<code>rootChildId</code> with an incremented attempt.</li>\n<li>Deduplicate a sequenced event by <code>(source, sourceEpoch, childId, sequence)</code>.\nWithout sequence, deduplicate only byte-equivalent <code>eventId</code> records.</li>\n<li>Track high sequence per source epoch. A forward gap is provisional; an old\nsequence is out-of-order. A new source epoch permits a restarted counter.</li>\n<li>Terminal states are immutable. A complete authoritative snapshot may correct\na non-terminal projection and must emit an auditable correction; it cannot\nrevive a terminal outcome.</li>\n<li>Use activity for work context and heartbeat for liveness. A missed heartbeat\nmarks stale only after the configured deadline.</li>\n<li>Mark <code>lost</code> only after that stale child’s reconciliation attempt fails.</li>\n<li>On reconnect, obtain a snapshot before trusting resumed incrementals where a\ngap cannot be ruled out.</li>\n<li>Process snapshot omission only when complete coverage is proven. Use a\nconsecutive-complete-miss grace policy before emitting stale/unknown intent.</li>\n</ol>\n<h3 id=\"jsonl-fallback-and-journal\">JSONL Fallback and Journal</h3>\n<p>One complete UTF-8 line is one event object. Producers flush complete lines and\ndo not mix ordinary logs into the lifecycle stream.</p>\n<pre><code class=\"language-json\">{&quot;schemaVersion&quot;:1,&quot;eventId&quot;:&quot;evt-7&quot;,&quot;source&quot;:&quot;worker-cli&quot;,&quot;sourceEpoch&quot;:&quot;start-2&quot;,&quot;childId&quot;:&quot;child-42&quot;,&quot;lineage&quot;:{&quot;rootChildId&quot;:&quot;child-42&quot;,&quot;attempt&quot;:0,&quot;external&quot;:false},&quot;kind&quot;:&quot;state_changed&quot;,&quot;state&quot;:&quot;running&quot;,&quot;observedAt&quot;:&quot;2026-08-24T09:15:30.000Z&quot;,&quot;sequence&quot;:7}\n</code></pre>\n<p>Consumers must incrementally buffer partial lines, cap line size, validate\nbefore projection, and retain only bounded redacted diagnostics for malformed\ninput. EOF is not <code>completed</code>; reconcile or observe a runtime exit.</p>\n<p>For an append-only journal, the reference implementation uses an atomic\nper-path lock directory around replay, sequence reservation, and append.\nConcurrent calls in one process serialize, and cooperating Node processes\nexclude one another. Lock acquisition has a bounded timeout; stale reclamation\nrequires both the configured age and a recorded PID that is demonstrably dead,\nand cleanup verifies the owner token. The journal becomes append-blocked if\nreplay detects malformed, oversized, truncated, or non-monotonic content.\nThis is cooperative advisory exclusion: programs that ignore the lock protocol\nand filesystems without atomic directory operations remain unsupported.</p>\n<h3 id=\"hermes-adapter-foundation\">Hermes Adapter Foundation</h3>\n<p>The Hermes foundation maps delegation events and status snapshots into a\nhost-owned integration. It requests snapshots at session open, reconnect, and\nperiodically; overlapping requests coalesce. Complete Hermes snapshots may\ncorrect records by child ID. An omitted locally-running child generates a\nstale-unknown intent only after the configured consecutive complete-snapshot\ngrace (default two); incomplete snapshots never generate that intent.</p>\n<p>This is not Hermes Desktop core integration. A host must supply source identity,\nlineage, capabilities, event persistence, audit rendering, and any approved UI\nintegration.</p>\n<h3 id=\"external-adoption-limits\">External Adoption Limits</h3>\n<table>\n<thead>\n<tr>\n<th>Observable</th>\n<th>What may be stated</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>PID/process presence only</td>\n<td>Process was observed; history, agent state, intent, and cancellation are unknown.</td>\n</tr>\n<tr>\n<td>Process exit code</td>\n<td>A process ended with that code; task success is not implied.</td>\n</tr>\n<tr>\n<td>Runtime status endpoint</td>\n<td>Exposed current state can be projected; missed history remains unknown.</td>\n</tr>\n<tr>\n<td>Event stream plus complete snapshot</td>\n<td>Visibility begins at adoption; pre-adoption history remains unknown unless supplied.</td>\n</tr>\n<tr>\n<td>Verified control API</td>\n<td>Cancellation may be offered within the documented authority scope.</td>\n</tr>\n</tbody></table>\n<p>Always retain <code>external: true</code>, adoption time, source identity, and verified\ncapabilities. Never turn observation into a claim that the orchestrator created,\nowns, or can safely terminate the child.</p>\n","words":840},{"path":"references/model-routing-migration.md","slug":"model-routing-migration","title":"Relationship and Migration Note: Model Routing","body":"# Relationship and Migration Note: Model Routing\n\n`agent-lifecycle` complements `model-routing`; it does not select models,\nchange routing-profile ownership, or replace phase-boundary verification.\n`model-routing` decides **which child to dispatch** and with which exact model.\n`agent-lifecycle` defines **how that dispatched child is observed and reconciled**.\n\n## Load Order\n\nFor delegated work that needs live child visibility:\n\n1. Load `model-routing` to select exact role bindings and establish dispatch\n   ownership.\n2. Load `agent-lifecycle` before launch to establish `childId`, source/source\n   epoch, lineage, capability truth, and event/snapshot transport.\n3. Dispatch only when the host can publish lifecycle evidence or explicitly\n   report the unavailable capabilities.\n\nFor routing-only work that does not create observable child processes, this\nskill is not required.\n\n## Contract Boundary\n\n| Concern | `model-routing` owns | `agent-lifecycle` owns |\n| --- | --- | --- |\n| Exact model choice | Role bindings and user-approved model IDs | No model selection |\n| Delegation scope | Prompt structure and task ownership | Child identity, lineage, and runtime projection |\n| Child status | Structured final-result expectations | Events, activity, heartbeat, snapshots, and stale/lost handling |\n| Task metadata | Plan/task context | Never lifecycle-state authority |\n| External process | Dispatch limitations | Adoption labels and capability limits |\n\nA child’s final result is evidence for an outcome but not a substitute for a\nterminal lifecycle event, process-exit observation, or authoritative snapshot.\nConversely, heartbeat evidence does not establish result quality or completion.\n\n## v0.2.0 Integration Contract\n\nThe implemented lifecycle core expects schema-v1 identity and lineage:\n\n```text\nschemaVersion: 1\neventId: unique event identity\nsource: adapter/source name\nsourceEpoch: producer sequence-space identity\nchildId: one lifecycle identity\nlineage: root child, attempt, external/adoption truth\ncapabilities: known | unknown per observable\n```\n\nFor a source with ordering, sequence identity is\n`(source, sourceEpoch, childId, sequence)`. A routing retry should use a new\n`childId`, share the original `rootChildId`, and increment `attempt`. Do not\nreuse a terminal child ID for a retry.\n\nA visibility-enabled dispatch contract should state:\n\n- the owning adapter/source and its source-epoch policy;\n- parent/root/attempt lineage;\n- available activity, heartbeat, snapshot, cancel, history, and terminal-cause\n  capabilities;\n- event endpoint or JSONL stream, sequence behavior, and redaction boundary;\n- authoritative snapshot source, reconnect behavior, and complete-omission\n  grace; and\n- the evidence required before a stale child may become `lost`.\n\n## Hermes-Specific Boundary\n\nThe v0.2.0 Hermes module is an adapter foundation. It normalizes documented\nHermes delegation events and requests status snapshots on session open,\nreconnect, and periodic intervals. A host consumes its reconciliation inputs and\nintents, including a stale-unknown intent only after consecutive complete\nsnapshot omissions.\n\nIt does **not** make a child appear in Hermes Desktop’s native UI, modify\nHermes’s core lifecycle ownership, or claim that a general foreign-process\nadoption path is shipped.\n\n## Future Cross-Skill Work\n\nDo not change other skills automatically from this package. A host integration\nis complete only when it:\n\n1. carries lifecycle identity and capability truth in its child launch contract;\n2. renders normalized lifecycle state separately from todos and percentages;\n3. audits authoritative corrections and preserves terminal immutability;\n4. tests gaps, reconnect convergence, stale-then-lost, malformed JSONL, and\n   adoption with intentionally unknown capabilities; and\n5. states whether it is an adapter foundation, experimental integration, or a\n   supported host feature.\n\nExisting model-routing behavior must continue to work when live child\nvisibility is not requested.\n\nBefore rollout, verify the full new-session matrix for both an exact Opus model\nand an exact GPT model: explicit `-m` selection and implicit harness default,\neach with a matching routing profile and with no profile. In the no-profile\ncases, the model is runtime state only and delegation must pause for exact role\nselection. Also verify removal of active intent and a named profile leaves the\nharness model bindings and `agent-lifecycle` installation untouched.\n","bodyHtml":"<h2 id=\"relationship-and-migration-note-model-routing\">Relationship and Migration Note: Model Routing</h2>\n<p><code>agent-lifecycle</code> complements <code>model-routing</code>; it does not select models,\nchange routing-profile ownership, or replace phase-boundary verification.\n<code>model-routing</code> decides <strong>which child to dispatch</strong> and with which exact model.\n<code>agent-lifecycle</code> defines <strong>how that dispatched child is observed and reconciled</strong>.</p>\n<h3 id=\"load-order\">Load Order</h3>\n<p>For delegated work that needs live child visibility:</p>\n<ol>\n<li>Load <code>model-routing</code> to select exact role bindings and establish dispatch\nownership.</li>\n<li>Load <code>agent-lifecycle</code> before launch to establish <code>childId</code>, source/source\nepoch, lineage, capability truth, and event/snapshot transport.</li>\n<li>Dispatch only when the host can publish lifecycle evidence or explicitly\nreport the unavailable capabilities.</li>\n</ol>\n<p>For routing-only work that does not create observable child processes, this\nskill is not required.</p>\n<h3 id=\"contract-boundary\">Contract Boundary</h3>\n<table>\n<thead>\n<tr>\n<th>Concern</th>\n<th><code>model-routing</code> owns</th>\n<th><code>agent-lifecycle</code> owns</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Exact model choice</td>\n<td>Role bindings and user-approved model IDs</td>\n<td>No model selection</td>\n</tr>\n<tr>\n<td>Delegation scope</td>\n<td>Prompt structure and task ownership</td>\n<td>Child identity, lineage, and runtime projection</td>\n</tr>\n<tr>\n<td>Child status</td>\n<td>Structured final-result expectations</td>\n<td>Events, activity, heartbeat, snapshots, and stale/lost handling</td>\n</tr>\n<tr>\n<td>Task metadata</td>\n<td>Plan/task context</td>\n<td>Never lifecycle-state authority</td>\n</tr>\n<tr>\n<td>External process</td>\n<td>Dispatch limitations</td>\n<td>Adoption labels and capability limits</td>\n</tr>\n</tbody></table>\n<p>A child’s final result is evidence for an outcome but not a substitute for a\nterminal lifecycle event, process-exit observation, or authoritative snapshot.\nConversely, heartbeat evidence does not establish result quality or completion.</p>\n<h3 id=\"v020-integration-contract\">v0.2.0 Integration Contract</h3>\n<p>The implemented lifecycle core expects schema-v1 identity and lineage:</p>\n<pre><code class=\"language-text\">schemaVersion: 1\neventId: unique event identity\nsource: adapter/source name\nsourceEpoch: producer sequence-space identity\nchildId: one lifecycle identity\nlineage: root child, attempt, external/adoption truth\ncapabilities: known | unknown per observable\n</code></pre>\n<p>For a source with ordering, sequence identity is\n<code>(source, sourceEpoch, childId, sequence)</code>. A routing retry should use a new\n<code>childId</code>, share the original <code>rootChildId</code>, and increment <code>attempt</code>. Do not\nreuse a terminal child ID for a retry.</p>\n<p>A visibility-enabled dispatch contract should state:</p>\n<ul>\n<li>the owning adapter/source and its source-epoch policy;</li>\n<li>parent/root/attempt lineage;</li>\n<li>available activity, heartbeat, snapshot, cancel, history, and terminal-cause\ncapabilities;</li>\n<li>event endpoint or JSONL stream, sequence behavior, and redaction boundary;</li>\n<li>authoritative snapshot source, reconnect behavior, and complete-omission\ngrace; and</li>\n<li>the evidence required before a stale child may become <code>lost</code>.</li>\n</ul>\n<h3 id=\"hermes-specific-boundary\">Hermes-Specific Boundary</h3>\n<p>The v0.2.0 Hermes module is an adapter foundation. It normalizes documented\nHermes delegation events and requests status snapshots on session open,\nreconnect, and periodic intervals. A host consumes its reconciliation inputs and\nintents, including a stale-unknown intent only after consecutive complete\nsnapshot omissions.</p>\n<p>It does <strong>not</strong> make a child appear in Hermes Desktop’s native UI, modify\nHermes’s core lifecycle ownership, or claim that a general foreign-process\nadoption path is shipped.</p>\n<h3 id=\"future-cross-skill-work\">Future Cross-Skill Work</h3>\n<p>Do not change other skills automatically from this package. A host integration\nis complete only when it:</p>\n<ol>\n<li>carries lifecycle identity and capability truth in its child launch contract;</li>\n<li>renders normalized lifecycle state separately from todos and percentages;</li>\n<li>audits authoritative corrections and preserves terminal immutability;</li>\n<li>tests gaps, reconnect convergence, stale-then-lost, malformed JSONL, and\nadoption with intentionally unknown capabilities; and</li>\n<li>states whether it is an adapter foundation, experimental integration, or a\nsupported host feature.</li>\n</ol>\n<p>Existing model-routing behavior must continue to work when live child\nvisibility is not requested.</p>\n<p>Before rollout, verify the full new-session matrix for both an exact Opus model\nand an exact GPT model: explicit <code>-m</code> selection and implicit harness default,\neach with a matching routing profile and with no profile. In the no-profile\ncases, the model is runtime state only and delegation must pause for exact role\nselection. Also verify removal of active intent and a named profile leaves the\nharness model bindings and <code>agent-lifecycle</code> installation untouched.</p>\n","words":618}],"body":"# Agent Lifecycle Visibility\n\nUse the v0.2.0 lifecycle contract to make delegated agents visibly and honestly\nobservable. The package implements schema-v1 validation, projection, JSONL\nfallback safety, and a Hermes reconciliation adapter foundation. It does not\nship Hermes Desktop core integration, a task board, or native adoption of an\narbitrary foreign process.\n\n## When to Use\n\n- Adding live child-agent visibility to an orchestrator, desktop application,\n  CLI, or web UI.\n- Normalizing multiple child runtimes behind one lifecycle interface.\n- Repairing missed events after reconnect, silence, or a host restart.\n- Supporting a runtime that can emit JSON Lines but cannot provide callbacks.\n- Integrating Hermes delegation observations through a host-owned adapter.\n\nDon't use for task planning, Kanban/todo synchronization, or a one-time\npost-run summary. Those concerns must not substitute for lifecycle telemetry.\n\n## Prerequisites\n\n- Allocate a stable `childId` for the child lifetime, a stable `source`, and a\n  new `sourceEpoch` whenever a producer restarts its sequence space.\n- Generate unique `eventId` values. Supply a non-negative per-child `sequence`\n  only when the source can guarantee it within `(source, sourceEpoch, childId)`.\n- Define lineage: `rootChildId`, attempt number, and whether the child is\n  externally adopted. Preserve unknown capabilities rather than inferring them.\n- Choose one lifecycle owner and one authoritative snapshot source.\n- Load [the adapter contract](references/adapter-contract.md) before writing a\n  runtime adapter. For routed children, also read the\n  [model-routing relationship note](references/model-routing-migration.md).\n\n## Lifecycle Model\n\nUse exactly these states:\n\n```text\ncreated -> starting -> running <-> waiting -> completed | failed | cancelled | lost\n```\n\nThe actual legal edges are `created -> starting|cancelled|failed|lost`,\n`starting -> running|waiting|cancelled|failed|lost`, and from `running` or\n`waiting` to their documented successors. `completed`, `failed`, `cancelled`,\nand `lost` are terminal and immutable. `activity` and `heartbeat` refresh\ninformation only; they never transition state.\n\nEvery schema-v1 event includes `schemaVersion: 1`, `eventId`, `source`,\n`sourceEpoch`, `childId`, `lineage`, `kind`, and RFC3339 UTC `observedAt`.\nCapabilities are explicit `known | unknown` values for history, heartbeat,\nsnapshot, cancel, and terminal cause. Set `external: true` and `adoptedAt` for\nadoption; do not claim pre-adoption history or control authority.\n\n## Procedure\n\n1. **Normalize schema-v1 events.** Require canonical identity, lineage, kind,\n   timestamp, and state rules before projection. Redact secrets in `details`.\n   **Complete when:** invalid kinds/states/timestamps are rejected and omitted\n   capabilities become `unknown` rather than optimistic defaults.\n\n2. **Project ordered observations.** Deduplicate sequenced events by\n   `(source, sourceEpoch, childId, sequence)` and non-sequenced events only by\n   exact `eventId` content. Treat forward sequence gaps as provisional and old\n   sequence values as out of order. **Complete when:** replay gives the same\n   projection as live delivery while conflicts remain diagnosable.\n\n3. **Publish activity and heartbeats separately.** Put current-work text in an\n   `activity` event and liveness evidence in `heartbeat`; neither may invent a\n   transition. **Complete when:** quiet but alive work remains distinguishable\n   from a stopped child.\n\n4. **Use stale before lost.** After the configured freshness deadline, mark a\n   non-terminal child stale and request reconciliation. Mark it `lost` only if\n   that corresponding reconciliation fails; terminal loss happens once.\n   **Complete when:** one missed heartbeat never directly produces `lost`.\n\n5. **Reconcile authoritative complete snapshots.** Require `complete: true`,\n   `sourceEpoch`, `snapshotId`, coverage, and observed time. Correct only a\n   non-terminal projection and retain an `authoritative_snapshot` audit entry;\n   never revive a terminal record. **Complete when:** reconnect convergence is\n   visible and each correction is inspectable.\n\n6. **Handle omission only with proof and grace.** Do not conclude anything from\n   an incomplete snapshot omitting a child. If an adapter can establish complete\n   coverage, count consecutive complete misses and surface stale/unknown only\n   after a documented grace threshold. **Complete when:** an intermittent or\n   partial snapshot cannot silently complete or lose work.\n\n7. **Use JSONL as a bounded fallback.** Emit one complete UTF-8 event per line;\n   parse incrementally, retain valid surrounding records, and bound/redact\n   malformed diagnostics. Journal appends use a cooperative atomic lock\n   directory so concurrent calls and cooperating Node processes serialize;\n   lock acquisition times out behind live owners and only reclaims old locks\n   whose recorded PID is demonstrably dead. Programs that ignore the protocol\n   remain unsupported. **Complete when:** malformed, oversized, and truncated\n   lines do not mutate projection incorrectly.\n\n8. **Integrate Hermes honestly.** Map documented Hermes delegation events and\n   status snapshots through the adapter foundation. Request status at session\n   open, reconnect, and a bounded periodic interval; coalesce overlapping\n   fetches. **Complete when:** the host consumes its inputs/intents, applies\n   complete-snapshot omission grace, and does not claim Hermes Desktop core UI\n   integration is shipped.\n\n9. **Render lifecycle truth, not proxy work state.** Drive visible state from\n   the normalized projection; tasks and percent complete are auxiliary only.\n   **Complete when:** removing all task-board data leaves lifecycle status\n   correct.\n\n## Usage Examples\n\n### End-user status request\n\n```text\nShow the current child lifecycle status. For every child include child ID,\nliteral state (running, waiting, completed, failed, cancelled, or lost), current\nactivity or tool, freshness, and transcript/result reference where safe.\nReconcile stale children before drawing a terminal conclusion.\n```\n\n### Host integration request\n\n```text\nIntegrate agent-lifecycle into this orchestrator. Normalize child events, keep\nactivity separate from heartbeat, reconcile complete snapshots after reconnect,\nand preserve immutable terminal states. Prefer native child UI.\n```\n\n### Display fallback when native UI is unavailable\n\n```text\nRender one active aggregate todo labelled display-only and one DISPLAY ONLY row\nper child with ID, state, activity/tool, and freshness. Treat those rows as a\nprojection only; edits must not change lifecycle state.\n```\n\nIf no lifecycle evidence source exists, create no child rows and state exactly:\n`Background work visibility unavailable; state unknown.`\n\n## Quick Reference\n\n- Event identity: `eventId`, or `(source, sourceEpoch, childId, sequence)`.\n- Lineage: root/attempt/parent and adoption truth, not inferred ancestry.\n- Activity: material current-work information; heartbeat: liveness only.\n- Complete snapshot: authority to correct present non-terminal records.\n- Audit: record every authoritative correction.\n- Stale then lost: deadline first, failed reconciliation second.\n- JSONL: bounded transport fallback with cooperative cross-process journal locking.\n- Hermes: adapter foundation only; session-open/reconnect/periodic snapshots.\n\n## Pitfalls\n\n- **Todo/Kanban substitution:** task metadata can be missing or manually edited;\n  it is never lifecycle authority.\n- **Epoch blindness:** a producer restart can reuse a sequence number; scope\n  sequence identity by `sourceEpoch`.\n- **Snapshot overclaim:** incomplete coverage cannot establish absence.\n- **Heartbeat as progress:** liveness does not prove useful work or success.\n- **Terminal revival:** late event delivery and snapshots cannot rewrite a\n  terminal outcome.\n- **JSONL mixed with logs:** ordinary stdout logs make malformed diagnostics,\n  not lifecycle events.\n- **External-adoption overclaim:** PID presence does not provide history,\n  intent, heartbeat, terminal cause, or cancellation authority.\n\n## Verification\n\nFor Hermes routing/new-session rollout, also run the repository's\n`docs/testing/hermes-new-session-matrix.md`: Opus and GPT, explicit and implicit\nmodel selection, with and without routing profiles, plus safe routing-profile\nremoval. A configured or explicit runtime model without a routing profile is\nstill `UNPROFILED` and must not authorize delegation silently.\n\n1. Apply a legal path through `created`, `starting`, `running`, `waiting`, and a\n   terminal state; verify invalid transitions are rejected.\n2. Deliver exact duplicates, identity conflicts, an out-of-order sequence, and\n   a forward gap; verify their distinct results.\n3. Stop heartbeats beyond the deadline; verify stale state appears before one\n   failed reconciliation transitions the child to `lost`.\n4. Reconcile a complete snapshot that changes a non-terminal state; verify the\n   correction audit. Attempt to alter a terminal state; verify it is refused.\n5. Feed valid JSONL around malformed, oversized, and truncated data; verify\n   valid events remain and diagnostics are bounded/redacted.\n6. For Hermes, verify snapshots run on session open, reconnect, and elapsed\n   interval; verify incomplete omission does nothing and complete omission needs\n   the configured grace count.\n\nThe integration is ready only when every result comes from lifecycle evidence,\nnot optimistic UI defaults or task-board metadata.\n","bodyHtml":"<h2 id=\"agent-lifecycle-visibility\">Agent Lifecycle Visibility</h2>\n<p>Use the v0.2.0 lifecycle contract to make delegated agents visibly and honestly\nobservable. The package implements schema-v1 validation, projection, JSONL\nfallback safety, and a Hermes reconciliation adapter foundation. It does not\nship Hermes Desktop core integration, a task board, or native adoption of an\narbitrary foreign process.</p>\n<h3 id=\"when-to-use\">When to Use</h3>\n<ul>\n<li>Adding live child-agent visibility to an orchestrator, desktop application,\nCLI, or web UI.</li>\n<li>Normalizing multiple child runtimes behind one lifecycle interface.</li>\n<li>Repairing missed events after reconnect, silence, or a host restart.</li>\n<li>Supporting a runtime that can emit JSON Lines but cannot provide callbacks.</li>\n<li>Integrating Hermes delegation observations through a host-owned adapter.</li>\n</ul>\n<p>Don&#39;t use for task planning, Kanban/todo synchronization, or a one-time\npost-run summary. Those concerns must not substitute for lifecycle telemetry.</p>\n<h3 id=\"prerequisites\">Prerequisites</h3>\n<ul>\n<li>Allocate a stable <code>childId</code> for the child lifetime, a stable <code>source</code>, and a\nnew <code>sourceEpoch</code> whenever a producer restarts its sequence space.</li>\n<li>Generate unique <code>eventId</code> values. Supply a non-negative per-child <code>sequence</code>\nonly when the source can guarantee it within <code>(source, sourceEpoch, childId)</code>.</li>\n<li>Define lineage: <code>rootChildId</code>, attempt number, and whether the child is\nexternally adopted. Preserve unknown capabilities rather than inferring them.</li>\n<li>Choose one lifecycle owner and one authoritative snapshot source.</li>\n<li>Load <a href=\"references/adapter-contract.md\">the adapter contract</a> before writing a\nruntime adapter. For routed children, also read the\n<a href=\"references/model-routing-migration.md\">model-routing relationship note</a>.</li>\n</ul>\n<h3 id=\"lifecycle-model\">Lifecycle Model</h3>\n<p>Use exactly these states:</p>\n<pre><code class=\"language-text\">created -&gt; starting -&gt; running &lt;-&gt; waiting -&gt; completed | failed | cancelled | lost\n</code></pre>\n<p>The actual legal edges are <code>created -&gt; starting|cancelled|failed|lost</code>,\n<code>starting -&gt; running|waiting|cancelled|failed|lost</code>, and from <code>running</code> or\n<code>waiting</code> to their documented successors. <code>completed</code>, <code>failed</code>, <code>cancelled</code>,\nand <code>lost</code> are terminal and immutable. <code>activity</code> and <code>heartbeat</code> refresh\ninformation only; they never transition state.</p>\n<p>Every schema-v1 event includes <code>schemaVersion: 1</code>, <code>eventId</code>, <code>source</code>,\n<code>sourceEpoch</code>, <code>childId</code>, <code>lineage</code>, <code>kind</code>, and RFC3339 UTC <code>observedAt</code>.\nCapabilities are explicit <code>known | unknown</code> values for history, heartbeat,\nsnapshot, cancel, and terminal cause. Set <code>external: true</code> and <code>adoptedAt</code> for\nadoption; do not claim pre-adoption history or control authority.</p>\n<h3 id=\"procedure\">Procedure</h3>\n<ol>\n<li><p><strong>Normalize schema-v1 events.</strong> Require canonical identity, lineage, kind,\ntimestamp, and state rules before projection. Redact secrets in <code>details</code>.\n<strong>Complete when:</strong> invalid kinds/states/timestamps are rejected and omitted\ncapabilities become <code>unknown</code> rather than optimistic defaults.</p>\n</li>\n<li><p><strong>Project ordered observations.</strong> Deduplicate sequenced events by\n<code>(source, sourceEpoch, childId, sequence)</code> and non-sequenced events only by\nexact <code>eventId</code> content. Treat forward sequence gaps as provisional and old\nsequence values as out of order. <strong>Complete when:</strong> replay gives the same\nprojection as live delivery while conflicts remain diagnosable.</p>\n</li>\n<li><p><strong>Publish activity and heartbeats separately.</strong> Put current-work text in an\n<code>activity</code> event and liveness evidence in <code>heartbeat</code>; neither may invent a\ntransition. <strong>Complete when:</strong> quiet but alive work remains distinguishable\nfrom a stopped child.</p>\n</li>\n<li><p><strong>Use stale before lost.</strong> After the configured freshness deadline, mark a\nnon-terminal child stale and request reconciliation. Mark it <code>lost</code> only if\nthat corresponding reconciliation fails; terminal loss happens once.\n<strong>Complete when:</strong> one missed heartbeat never directly produces <code>lost</code>.</p>\n</li>\n<li><p><strong>Reconcile authoritative complete snapshots.</strong> Require <code>complete: true</code>,\n<code>sourceEpoch</code>, <code>snapshotId</code>, coverage, and observed time. Correct only a\nnon-terminal projection and retain an <code>authoritative_snapshot</code> audit entry;\nnever revive a terminal record. <strong>Complete when:</strong> reconnect convergence is\nvisible and each correction is inspectable.</p>\n</li>\n<li><p><strong>Handle omission only with proof and grace.</strong> Do not conclude anything from\nan incomplete snapshot omitting a child. If an adapter can establish complete\ncoverage, count consecutive complete misses and surface stale/unknown only\nafter a documented grace threshold. <strong>Complete when:</strong> an intermittent or\npartial snapshot cannot silently complete or lose work.</p>\n</li>\n<li><p><strong>Use JSONL as a bounded fallback.</strong> Emit one complete UTF-8 event per line;\nparse incrementally, retain valid surrounding records, and bound/redact\nmalformed diagnostics. Journal appends use a cooperative atomic lock\ndirectory so concurrent calls and cooperating Node processes serialize;\nlock acquisition times out behind live owners and only reclaims old locks\nwhose recorded PID is demonstrably dead. Programs that ignore the protocol\nremain unsupported. <strong>Complete when:</strong> malformed, oversized, and truncated\nlines do not mutate projection incorrectly.</p>\n</li>\n<li><p><strong>Integrate Hermes honestly.</strong> Map documented Hermes delegation events and\nstatus snapshots through the adapter foundation. Request status at session\nopen, reconnect, and a bounded periodic interval; coalesce overlapping\nfetches. <strong>Complete when:</strong> the host consumes its inputs/intents, applies\ncomplete-snapshot omission grace, and does not claim Hermes Desktop core UI\nintegration is shipped.</p>\n</li>\n<li><p><strong>Render lifecycle truth, not proxy work state.</strong> Drive visible state from\nthe normalized projection; tasks and percent complete are auxiliary only.\n<strong>Complete when:</strong> removing all task-board data leaves lifecycle status\ncorrect.</p>\n</li>\n</ol>\n<h3 id=\"usage-examples\">Usage Examples</h3>\n<h4 id=\"end-user-status-request\">End-user status request</h4>\n<pre><code class=\"language-text\">Show the current child lifecycle status. For every child include child ID,\nliteral state (running, waiting, completed, failed, cancelled, or lost), current\nactivity or tool, freshness, and transcript/result reference where safe.\nReconcile stale children before drawing a terminal conclusion.\n</code></pre>\n<h4 id=\"host-integration-request\">Host integration request</h4>\n<pre><code class=\"language-text\">Integrate agent-lifecycle into this orchestrator. Normalize child events, keep\nactivity separate from heartbeat, reconcile complete snapshots after reconnect,\nand preserve immutable terminal states. Prefer native child UI.\n</code></pre>\n<h4 id=\"display-fallback-when-native-ui-is-unavailable\">Display fallback when native UI is unavailable</h4>\n<pre><code class=\"language-text\">Render one active aggregate todo labelled display-only and one DISPLAY ONLY row\nper child with ID, state, activity/tool, and freshness. Treat those rows as a\nprojection only; edits must not change lifecycle state.\n</code></pre>\n<p>If no lifecycle evidence source exists, create no child rows and state exactly:\n<code>Background work visibility unavailable; state unknown.</code></p>\n<h3 id=\"quick-reference\">Quick Reference</h3>\n<ul>\n<li>Event identity: <code>eventId</code>, or <code>(source, sourceEpoch, childId, sequence)</code>.</li>\n<li>Lineage: root/attempt/parent and adoption truth, not inferred ancestry.</li>\n<li>Activity: material current-work information; heartbeat: liveness only.</li>\n<li>Complete snapshot: authority to correct present non-terminal records.</li>\n<li>Audit: record every authoritative correction.</li>\n<li>Stale then lost: deadline first, failed reconciliation second.</li>\n<li>JSONL: bounded transport fallback with cooperative cross-process journal locking.</li>\n<li>Hermes: adapter foundation only; session-open/reconnect/periodic snapshots.</li>\n</ul>\n<h3 id=\"pitfalls\">Pitfalls</h3>\n<ul>\n<li><strong>Todo/Kanban substitution:</strong> task metadata can be missing or manually edited;\nit is never lifecycle authority.</li>\n<li><strong>Epoch blindness:</strong> a producer restart can reuse a sequence number; scope\nsequence identity by <code>sourceEpoch</code>.</li>\n<li><strong>Snapshot overclaim:</strong> incomplete coverage cannot establish absence.</li>\n<li><strong>Heartbeat as progress:</strong> liveness does not prove useful work or success.</li>\n<li><strong>Terminal revival:</strong> late event delivery and snapshots cannot rewrite a\nterminal outcome.</li>\n<li><strong>JSONL mixed with logs:</strong> ordinary stdout logs make malformed diagnostics,\nnot lifecycle events.</li>\n<li><strong>External-adoption overclaim:</strong> PID presence does not provide history,\nintent, heartbeat, terminal cause, or cancellation authority.</li>\n</ul>\n<h3 id=\"verification\">Verification</h3>\n<p>For Hermes routing/new-session rollout, also run the repository&#39;s\n<code>docs/testing/hermes-new-session-matrix.md</code>: Opus and GPT, explicit and implicit\nmodel selection, with and without routing profiles, plus safe routing-profile\nremoval. A configured or explicit runtime model without a routing profile is\nstill <code>UNPROFILED</code> and must not authorize delegation silently.</p>\n<ol>\n<li>Apply a legal path through <code>created</code>, <code>starting</code>, <code>running</code>, <code>waiting</code>, and a\nterminal state; verify invalid transitions are rejected.</li>\n<li>Deliver exact duplicates, identity conflicts, an out-of-order sequence, and\na forward gap; verify their distinct results.</li>\n<li>Stop heartbeats beyond the deadline; verify stale state appears before one\nfailed reconciliation transitions the child to <code>lost</code>.</li>\n<li>Reconcile a complete snapshot that changes a non-terminal state; verify the\ncorrection audit. Attempt to alter a terminal state; verify it is refused.</li>\n<li>Feed valid JSONL around malformed, oversized, and truncated data; verify\nvalid events remain and diagnostics are bounded/redacted.</li>\n<li>For Hermes, verify snapshots run on session open, reconnect, and elapsed\ninterval; verify incomplete omission does nothing and complete omission needs\nthe configured grace count.</li>\n</ol>\n<p>The integration is ready only when every result comes from lifecycle evidence,\nnot optimistic UI defaults or task-board metadata.</p>\n","outline":["When to Use","Prerequisites","Lifecycle Model","Procedure","Usage Examples","Quick Reference","Pitfalls","Verification"],"words":1247}
