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 e789c7bb34 refactor(core): stateful sense types — remove Signal, add initialState
Phase 1 of RFC #308: Stateful Sense refactor.

- SenseComputeFn<S> now takes state and returns { state, workflow }
- SenseModule<S> exports compute + initialState (no more table)
- Removed: Signal type, ComputeResult, RoutedSenseOutput,
  routeSenseComputeOutput, retention/DEFAULT_SENSE_SIGNAL_RETENTION
- Updated isSenseInfo (removed lastSignalTimestamp)

Refs #308, closes #309
2026-05-01 09:43:13 +00:00
..

@uncaged/nerve-core

Shared types and configuration parser for the nerve observation engine.

What's Inside

  • Type definitionsSignal, SenseConfig, SenseInfo, 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 routingparseWorkflowTrigger, routeSenseComputeOutput, and types WorkflowTrigger, RoutedSenseOutput
  • 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, 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 { parseWorkflowTrigger, routeSenseComputeOutput } from "@uncaged/nerve-core";

const directive = parseWorkflowTrigger({
  name: "my-workflow",
  maxRounds: 8,
  prompt: "Hello from sense",
  dryRun: false,
});
if (directive.ok) {
  console.log(directive.value.name, directive.value.maxRounds, directive.value.prompt);
}

const route = routeSenseComputeOutput({
  signal: { metric: 42 },
  workflow: {
    name: "my-workflow",
    maxRounds: 8,
    prompt: "Run now",
    dryRun: false,
  },
});
if (route.ok && route.value.workflow !== null) {
  console.log(route.value.workflow);
} else if (route.ok) {
  console.log(route.value.signal);
}

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