feat(core): sense trigger supports arbitrary shell commands #315

Closed
opened 2026-05-02 09:44:08 +00:00 by xiaoju · 0 comments
Owner

What

Allow sense compute() to trigger an arbitrary shell command instead of only nerve workflows.

Why

Currently a sense can only trigger a workflow (WorkflowTrigger with name, maxRounds, prompt, dryRun). For simple reactive actions like restarting a service, this forces writing a full workflow (roles + moderator) just to run one command — too much ceremony.

Nerve workflows should be reserved for multi-step reasoning/orchestration. Simple "detect → react" should be a shell command.

Proposal

Extend SenseComputeReturn to support a discriminated union:

type ShellTrigger = {
  kind: "shell";
  cmd: string;
  args: string[];
  timeout: number | null;  // ms, null = default
};

type WorkflowTrigger = {
  kind: "workflow";
  name: string;
  maxRounds: number;
  prompt: string;
  dryRun: boolean;
};

type SenseTrigger = ShellTrigger | WorkflowTrigger;

Sense compute returns:

{ state, signal, workflow: SenseTrigger | null }

The engine executes shell triggers in an isolated subprocess (same process isolation as workflow workers), captures stdout/stderr/exit code, and logs the result.

Example

// sense: hermes-gateway-health
const workflow = shouldRestart
  ? { kind: "shell", cmd: "systemctl", args: ["--user", "restart", "hermes-gateway"], timeout: 30000 }
  : null;

return { state: nextState, signal, workflow };

No workflow directory, no roles, no moderator — just a command.

Backward Compatibility

Existing WorkflowTrigger (without kind) can default to kind: "workflow" for backward compat, or we do a breaking change (preferred per project conventions).


小橘 🍊(NEKO Team)

## What Allow sense `compute()` to trigger an arbitrary shell command instead of only nerve workflows. ## Why Currently a sense can only trigger a workflow (`WorkflowTrigger` with `name`, `maxRounds`, `prompt`, `dryRun`). For simple reactive actions like restarting a service, this forces writing a full workflow (roles + moderator) just to run one command — too much ceremony. Nerve workflows should be reserved for multi-step reasoning/orchestration. Simple "detect → react" should be a shell command. ## Proposal Extend `SenseComputeReturn` to support a discriminated union: ```typescript type ShellTrigger = { kind: "shell"; cmd: string; args: string[]; timeout: number | null; // ms, null = default }; type WorkflowTrigger = { kind: "workflow"; name: string; maxRounds: number; prompt: string; dryRun: boolean; }; type SenseTrigger = ShellTrigger | WorkflowTrigger; ``` Sense compute returns: ```typescript { state, signal, workflow: SenseTrigger | null } ``` The engine executes shell triggers in an isolated subprocess (same process isolation as workflow workers), captures stdout/stderr/exit code, and logs the result. ## Example ```typescript // sense: hermes-gateway-health const workflow = shouldRestart ? { kind: "shell", cmd: "systemctl", args: ["--user", "restart", "hermes-gateway"], timeout: 30000 } : null; return { state: nextState, signal, workflow }; ``` No workflow directory, no roles, no moderator — just a command. ## Backward Compatibility Existing `WorkflowTrigger` (without `kind`) can default to `kind: "workflow"` for backward compat, or we do a breaking change (preferred per project conventions). --- 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#315