refactor: Stateful Sense (RFC #308) #312

Merged
xiaomo merged 6 commits from refactor/308-stateful-sense into main 2026-05-01 10:20:46 +00:00
Owner

Stateful Sense refactor. Fixes #308

Stateful Sense refactor. Fixes #308
xiaoju added 6 commits 2026-05-01 10:11:25 +00:00
Add Workflow Naming to CLAUDE.md and strengthen planner prompts for develop-workflow and develop-sense.

Fixes #285

Made-with: Cursor
Cover non-ok HTTP response (500) and network failure (ECONNREFUSED).
Per review feedback from 星月 🌙 on PR #278.
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
Phase 2 of RFC #308: Stateful Sense refactor.

- SenseRuntime uses JSON file persistence instead of SQLite/Drizzle
- Sense compute now receives state and returns { state, workflow }
- IPC: replaced SignalMessage with ComputeResultMessage
- Removed Signal Bus entirely (on[] now uses reverse-index in scheduler)
- sense-scheduler.onSenseCompleted() triggers dependent senses
- kernel no longer constructs Signal objects or calls routeSenseComputeOutput
- Removed drizzle-orm dependency from daemon package

Refs #308, closes #310
Phase 3 of RFC #308: Stateful Sense refactor.

- Examples (cpu-usage, nerve-health) use initialState + compute(state)
- CLI create/init templates generate stateful sense (no SQLite/Drizzle)
- Removed: sense query, sense schema commands (no more per-sense SQLite)
- Removed: sense-sqlite.ts, schema templates, migration templates
- Updated all CLI tests for new sense structure

Refs #308, closes #311
Phase 4 of RFC #308: Stateful Sense refactor.

- CLAUDE.md: updated diagram, tables, examples (no more Signal)
- Cleaned stale Signal Bus / DrizzleDB / _signals / retention refs
  across READMEs, .cursor rules, copilot instructions, .knowledge
- Removed drizzle-orm from core package.json (no longer used)
- Updated pnpm-lock.yaml

Refs #308
xiaomo approved these changes 2026-05-01 10:20:39 +00:00
xiaomo left a comment
Owner

Review: Stateful Sense (RFC #308)

净删 2900+ 行,架构大幅简化。整体执行质量很高。

👍 亮点

  • compute(state) => { state, workflow } 签名设计干净,泛型 S 保证输入输出类型一致
  • T | null 规范完全遵守,无 ?: 违规
  • Signal Bus 移除彻底,无悬挂引用
  • Drizzle/SQLite 依赖从 core 完全解耦
  • 调度器重构好onSubscribers map 比 bus 订阅更直接;stopped guard 是好的防御
  • 所有删除文件都合理,无误删
  • CLI 脚手架、示例、文档同步更新到位

⚠️ 建议(非阻塞,可后续跟进)

  1. 非原子写入writeFileSync 写到一半 crash 会导致 JSON 损坏。建议后续改为 write-to-temp + rename 模式
  2. readState 静默吞错误 — 所有异常(包括权限错误、磁盘故障)都回退到 initialState,可能掩盖数据丢失。建议至少 log warn
  3. State 内存/磁盘不一致runtime.statewriteState 之前就已更新,写失败会导致内存和磁盘状态分叉
  4. SenseInfo.triggers 应为 ReadonlyArray<string> — 与其他配置数组(如 KnowledgeConfig.exclude)保持一致
  5. 缺少 JSON state 持久化文档data/senses/<name>.json 在 layout 表中提及但无详细说明

建议 1-3 开个 follow-up issue 追踪。

## Review: Stateful Sense (RFC #308) ✅ 净删 2900+ 行,架构大幅简化。整体执行质量很高。 ### 👍 亮点 - **`compute(state) => { state, workflow }` 签名设计干净**,泛型 `S` 保证输入输出类型一致 - **`T | null` 规范完全遵守**,无 `?:` 违规 - **Signal Bus 移除彻底**,无悬挂引用 - **Drizzle/SQLite 依赖从 core 完全解耦** - **调度器重构好** — `onSubscribers` map 比 bus 订阅更直接;`stopped` guard 是好的防御 - **所有删除文件都合理**,无误删 - **CLI 脚手架、示例、文档同步更新到位** ### ⚠️ 建议(非阻塞,可后续跟进) 1. **非原子写入** — `writeFileSync` 写到一半 crash 会导致 JSON 损坏。建议后续改为 write-to-temp + rename 模式 2. **`readState` 静默吞错误** — 所有异常(包括权限错误、磁盘故障)都回退到 `initialState`,可能掩盖数据丢失。建议至少 log warn 3. **State 内存/磁盘不一致** — `runtime.state` 在 `writeState` 之前就已更新,写失败会导致内存和磁盘状态分叉 4. **`SenseInfo.triggers` 应为 `ReadonlyArray<string>`** — 与其他配置数组(如 `KnowledgeConfig.exclude`)保持一致 5. **缺少 JSON state 持久化文档** — `data/senses/<name>.json` 在 layout 表中提及但无详细说明 建议 1-3 开个 follow-up issue 追踪。
xiaomo merged commit eb7de9954f into main 2026-05-01 10:20:46 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#312