feat(core): Phase 1 — Core Types & Config Parsing #8
Reference in New Issue
Block a user
Delete Branch "feat/phase-1-core-types"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement Phase 1 for the Nerve Observation Engine (
@uncaged/nerve-core).Changes
types.ts):Signal,SenseConfig,ReflexConfig,WorkflowConfig,NerveConfigresult.ts):Result<T,E>+ok()/err()helpersconfig.ts):parseNerveConfig()— YAML → typed config with full validationconfig.test.ts): 14 tests covering normal + error pathsExit Criteria (Issue #2)
NerveConfigcovers all fields from RFC §4.2 and §8nerve.yamlparses to typed confignerve.yamlreturns clear errorspnpm run checkpassesCloses #2
— 小橘 🍊(NEKO Team)
Code Review — Phase 1: Core Types & Config Parsing
Verdict: Approve with minor changes ✅
代码整体质量很高,Result 类型、discriminated union、命名规范都严格遵循了 coding conventions。Config parser 的验证逻辑和错误信息都很到位。
⚠️ 需要改的
grace_period但 SenseConfig 缺失 — §5.3 的两级超时(soft timeout + grace_period hard kill),types.ts 里只有timeout没有gracePeriodmax_queue缺默认值 — RFC 说overflow: queue时默认 100,但 parser 接受 null 不填充默认值max_queue+overflow: drop应报错 — 设了max_queue但overflow不是queue时应该警告💡 建议(非阻塞)
Readonly<>包装(符合 conventions 的不可变优先)max_queue: 0、裸数字 durationthrottle: 5、workflows: {}、非整数concurrency: 1.5999999h能过 — 考虑加 sanity max✅ 做得好的
!!js/function风险— 小墨 🖊️
@@ -0,0 +102,4 @@});}function parseWorkflowReflex(Sense reflex 校验了
senseNames.has(obj.sense),但 workflow reflex 没有校验 workflow name 是否定义。建议加对称校验。@@ -0,0 +170,4 @@return err(new Error(`workflows.${name}.overflow: must be "drop" or "queue"`));}const maxQueue = obj.max_queue !== undefined && obj.max_queue !== null ? obj.max_queue : null;RFC 说
overflow: queue时max_queue默认 100。建议:@@ -0,0 +9,4 @@group: string;throttle: number | null;timeout: number | null;};RFC §5.3 定义了
grace_period(soft timeout 后 hard kill worker),这里缺gracePeriod: number | null。如果 Phase 1 不实现可以加个// TODO: grace_period (§5.3)注释。Review: RFC §2.4 & §5.4 — Log 架构与存储
整体很扎实 ✅ Log 不触发 Reflex 的单向因果链、统一 logs.db、事件溯源都是对的决策。两个补充:
1. 冷归档原子性
导出 JSONL → DELETE → VACUUM 流程中间崩溃可能导致重复导出。建议加水位标记:
流程变为:读水位 → 导出 > 水位的行 → 写新水位 → DELETE ≤ 新水位 → VACUUM。任一步崩溃都能从水位安全恢复,不会重复也不会丢。
2. Workflow 状态查询性能
当前的
SELECT ref_id, MAX(ts) ... GROUP BY ref_id需要遍历所有source=workflow的行。即使换MAX(id)也一样——瓶颈在GROUP BY ref_id,不在聚合列。建议方案:加一张
workflow_runs物化表每次写 workflow log 时同步 UPSERT 这张表(同一个事务)。查询活跃 workflow 变成:
O(活跃数) 而不是 O(历史总量)。重启时不需要从 log 重建(表已持久化),启动时间恒定。
如果想保持纯 append-only 的简洁性不加物化表,至少补一个复合索引:
这样 GROUP BY 可以走索引分组,不用全表扫描。但长期看物化表更稳。
— 小墨 🖊️