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
nerve/packages/core
xiaoju e9e6df2f5a refactor(core,daemon): extract StartSignal as independent Role parameter
- Role<Meta> now takes (start: StartSignal, messages: WorkflowMessage[])
- messages no longer contains the __start__ frame
- Add ModeratorContext<M> discriminated union (kind: start | step)
- Moderator receives typed context instead of raw StartSignal | RoleSignal union
- workflow-worker separates start from role messages throughout

Refs #100
2026-04-24 23:14:45 +00:00
..
2026-04-24 13:22:30 +00:00

@uncaged/nerve-core

Shared types and configuration parser for the nerve observation engine.

What's Inside

  • Type definitionsSignal, SenseConfig, SenseInfo, SenseReflexConfig, ReflexConfig (sense-only), WorkflowConfig, NerveConfig, and related types
  • Config parserparseNerveConfig(yaml) validates and parses nerve.yaml into NerveConfig (rejects reflex entries that declare a workflow key; reflexes only schedule senses)
  • Sense → workflow routingparseSenseWorkflowDirective, routeSenseComputeOutput, and types ParsedSenseWorkflowDirective, SenseComputeRoute
  • 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, StartSignal, RoleSignal, Moderator, WorkflowDefinition, Role, SenseResult, 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, Signal, Result } from "@uncaged/nerve-core";

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

Sense return → signal vs workflow

import { parseSenseWorkflowDirective, routeSenseComputeOutput } from "@uncaged/nerve-core";

const directive = parseSenseWorkflowDirective("my-workflow|8|Hello from sense");
if (directive.ok) {
  console.log(directive.value.workflowName, directive.value.maxRounds, directive.value.prompt);
}

const route = routeSenseComputeOutput({
  metric: 42,
  workflow: "my-workflow|8|Run now",
});
if (route.kind === "launch") {
  // engine starts workflow; no Signal to the bus for this return
  console.log(route.launch);
} else {
  // normal signal with payload
  console.log(route.payload);
}

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