This repository has been archived on 2026-06-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
xiaoju d81a30f051 chore(workflow): post-extraction cleanup
- IPC parse functions: replace whole-object 'as' casts with per-field narrowing
- WorkflowConfig: remove duplicate from core, re-export from @uncaged/workflow
- drainTimeoutMs: change from optional param to T | null convention
- Remove duplicate WorkflowWorkerOutboundMessage, keep WorkflowChildToParentMessage

Fixes #325
2026-05-05 13:52:03 +00:00
..

@uncaged/nerve-core

Shared types and configuration parser for the nerve observation engine.

What's Inside

  • Type definitionsSenseConfig, SenseInfo, SenseComputeFn, SenseModule, SenseTrigger, WorkflowConfig, NerveConfig, and related types
  • Config parserparseNerveConfig(yaml) validates and parses nerve.yaml into NerveConfig (top-level reflexes is rejected; use interval / on on each sense)
  • Sense triggersparseSenseTrigger validates { command: string } from sense compute results or worker IPC (trigger field on compute-result)
  • Daemon IPC protocol — request/response types (DaemonIpcRequest, DaemonIpcResponse, …) and parseDaemonIpcRequest for newline-delimited JSON on the CLI ↔ daemon socket
  • Workflow automaton typesSTART / END sentinel constants, WorkflowMessage, StartStep, RoleStep, ModeratorContext (start + steps; empty steps on first moderator call), Moderator (single context argument), WorkflowDefinition, Role, RoleResult, plus DEFAULT_ENGINE_MAX_ROUNDS
  • Result typeResult<T> with ok() / err() helpers for explicit error handling (no thrown exceptions for parse paths)

Usage

import { parseNerveConfig, ok, err } from "@uncaged/nerve-core";
import type { NerveConfig, Result } from "@uncaged/nerve-core";

const result: Result<NerveConfig> = parseNerveConfig(yamlString);
if (result.ok) {
  console.log(result.value.senses);
}

Sense trigger validation

import { parseSenseTrigger } from "@uncaged/nerve-core";

const parsed = parseSenseTrigger({ command: "echo hello" });
if (parsed.ok) {
  console.log(parsed.value.command);
}

Sense modules return { state, trigger } from compute(state); when trigger is non-null it must be exactly { command: string } (non-empty after trim). The daemon validates worker IPC with parseSenseTrigger. Workflows are started only via CLI / daemon IPC, not from this field.

Duration Format

Config fields like throttle, timeout, and interval accept human-readable durations:

  • 5s — 5 seconds
  • 10m — 10 minutes
  • 1h — 1 hour

Install

pnpm add @uncaged/nerve-core

License

MIT