Rules Schema
Status boundary:§1 记录 2026-06 Task V2 rules inventory;§2–§5 是历史 proposal。当前 selected Target 由 Task V3 Product / Domain Contract 定义,实施与环境状态见 Task V3 Rollout 状态快照。V2/V2+ 内容保留为 point-in-time compatibility context。
2026-06 snapshot sources(当时 verified 2026-06-01):
callytics-common/src/utils/due-at.ts— SLA / priority windows / business hours / timezonecallytics-common/src/db/schema/task-ui.ts— backlog days / AI assignable categoriescallytics-common/src/db/schema/store-config.ts— store_config 表(pricing JSONB / leadEmails)callytics-common/src/db/schema/operating-schedules.ts+operating-overrides.ts+blackout-periods.ts— 营业时间 / 单日覆盖 / SLA 黑名单时段callytics-infrastructure/lambda/contacts-analyzer/src/core/prompt-builder.ts— attempt threshold(prompt 内硬编码)studio-website-monorepo/apps/api/src/routes/tasks/list.ts— due_soon 24h(SQL 硬编码) Historical Task V2+ audit: 工程审计与设计建议 Task V3 selected Target: Task V3 Product / Domain Contract Current rollout evidence boundary: Task V3 Rollout 状态快照 Historical proposal:../tasks-feature/design/task-pipeline-deliverable-codex.md§6 + §7 + §14 阅读顺序: Task V3 contract / rollout status → Task V2 inventory (§1) → historical proposal (§2–§5)。
0. Rules 到底是什么(读之前必看)
Rules 不是一张 DB 表。它是 6 类物理位置的混合体,共同决定 Tasks / Lead Tracker / Dashboard / AI prompt 的行为。
Target Task 状态:Task-specific rules 不再由 global typeCategory / progressType / closeResult 三组 allowed set 定义,而由 versioned Task Policy Catalog 驱动 prompt/tool schema、backend validation、UI options 与 reporting。下文 storePolicy 和 store_config.rules 是历史 proposal,不能直接实施。
1. Current Schema(2026-06-01 live)
1.1 Lead First Response — Lead Outreach SLA
来源: callytics-common/src/utils/due-at.ts:27。Lead Outreach task dueAt = createdAt + SLA,倒计时只在营业时段内走。
⚠️ 可配置范围(SLA 1-30 min / Due Soon 1-5 min)是 v1 设计意图,代码里没有 store-level override 通道。所有 store 共用
DEFAULT_SLA_MINUTES = 5。
1.2 Task Deadline by Priority — Follow-up 截止窗口
来源: callytics-common/src/utils/due-at.ts:20-24 PRIORITY_WINDOW_MINUTES。
⚠️ Task Due Soon 漂移:
studio-api/.../tasks/list.ts:95-103注释直接写(24h threshold),SQL 是t.due_at BETWEEN NOW() AND NOW() + INTERVAL '24 hours',不读任何 store config。Rules UI 文档里写 1h 是设计意图,代码现状是 24h。
1.3 Business Hours — 营业时段(SLA 窗口推迟基准)
来源: callytics-common/src/utils/due-at.ts:30-36 默认值 + DB 表 store-level 覆盖。
store-level operating_schedules / overrides / blackouts 是 DB-stored,跟 due-at.ts 的 hardcoded default 是两套并行机制。SLA 计算何时读哪个仍在演进。
1.4 Revenue Benchmarks — 营收归因基准(设计常量,代码未实现)
来源: v1 设计文档。callytics-common / callytics-infrastructure / studio-website-monorepo 全仓搜不到 $149 / 0.60 / 0.70 / 0.75 常量。Dashboard 的 Impacted Revenue 目前不按此算。
这一节记录的是目标设计,实施前需先决定:落 code const 还是落
store_config.pricingJSONB(已有字段,目前空对象)。
1.5 Lead Thresholds — Attempt 边界
来源: callytics-infrastructure/lambda/contacts-analyzer/src/core/prompt-builder.ts:331 的 prompt 文本。
⚠️ Prompt 内硬编码,Rules UI 不可调: prompt 文本里明写
Lead attempt threshold = 3 contact attempts (Phase 2 lost_contact, Phase 3 unreachable/neglected boundary)。修改它必须改prompt-builder.ts+ redeploy,UI 上 Rules 页改 Attempt Threshold 数字不会影响 AI 判定。
1.6 Backlog 视窗 — 多少天没动算 backlog
来源: callytics-common/src/db/schema/task-ui.ts:94-96。
studio-api/.../tasks/list.ts:120-121, 135-136 直接 inline 这两个常量进 SQL。
1.7 AI Assignable Categories — AI 能创建哪些 typeCategory
来源: callytics-common/src/db/schema/task-ui.ts:105。
不是 AI 能力限制,是入口分工: lead_outreach 标签意思就是"新 lead 第一次联系",只能由 lead-tracking 入口创建。
1.8 store_config 表 — DB-stored store-level 配置(非 rules 但相关)
来源: callytics-common/src/db/schema/store-config.ts。这是当前唯一的 store-level 配置 DB 表,但目前不存 SLA / threshold / benchmark。
pricingJSONB 已有字段,但 Revenue Benchmarks 没接进来。Final 可能扩展此 JSONB 而不新建 rules 表。
1.9 Quiet Hours — 法律硬约束
不在代码 const 也不在 DB,是产品规则。
落入静默时段的 dueAt 自动推到下一个可联系时刻。注意: DEFAULT_BUSINESS_HOURS 是 8 AM–9 PM(due-at.ts:30-33),刚好是 Quiet Hours 的补集,但语义不同: business hours 是"营业时段"(SLA 推迟基准),Quiet Hours 是"法律不可拨打时段"。代码里只实现了前者。
2. Historical proposed schema(不是 Target)
设计原则: rules 仍主要是 code constant + prompt input,不强制落新表。Task Orchestrator 把 6 类来源拼成 storePolicy 注入 prompt。需要 store-level override 的 config(SLA / Attempt Threshold / Revenue Benchmark)扩展 store_config JSONB,不新建 rules 表。
2.1 Lead First Response — Lead Outreach SLA
2.2 Task Deadline by Priority
2.3 Business Hours / Operating Schedules
无变化。继续以 operating_schedules + operating_overrides + blackout_periods DB 表为 store-level 主源,DEFAULT_BUSINESS_HOURS const 仅 fallback。
2.4 Revenue Benchmarks(目标: 接线 + 可配置)
2.5 Lead Thresholds(目标: 移出 prompt 文本)
来源: codex doc §14 "lead retry threshold | 默认 3 次 meaningful attempts,但按 task type 可配置"。
2.6 AI Assignable Categories — 按 lifecycle 动态收窄(新增)
来源: codex doc §7 "typeCategory allowed set"。
Static set 仍是 AI_ASSIGNABLE_CATEGORIES(8 values),dynamic set 是 static set 与 lifecycle policy 的交集。
2.7 storePolicy — Prompt input shape(新)
来源: codex doc §6 "Prompt input should include"。Task Orchestrator 把 rules 拼成 JSON 注入 prompt,prompt 不直接访问 store_config / lifecycle。
2.8 store_config 表 — 扩展 JSONB(新字段)
新增 rules 列(jsonb)集中存所有可 store-level override 的 rules:
shape 待最终拍板;新增字段不破坏现有 pricing / leadEmails。
3. Historical proposal delta(Current → 旧 proposed Final)
3.1 Added(新增字段 / 新表 / 新 const / 新 prompt input)
3.2 Removed / Moved(从硬编码搬到 const + override)
3.3 Modified
3.4 Unchanged(明确保留)
DEFAULT_BUSINESS_HOURSconst +operating_schedules/operating_overrides/blackout_periods表 — 三层 fallback 链路不变- Quiet Hours TCPA 硬约束 — 不可配置
store_config已有列(alias/activatedAt/leadEmails/pricing)— 不动LEAD_CATEGORIES/LEAD_BACKLOG_DAYS/DEFAULT_BACKLOG_DAYSconst 值不变,只是允许 store override
4. Legacy Prompt Output ↔ Rules 字段对照
Reviewer 用本表验证 prompt 是否正确消费 rules 并遵守 allowed set。
5. Historical Open Product Policy
来源: historical Codex doc §14。本表不属于 V3 Target scope。
6. Appendix A — Re-verification commands
2026-06-01 verified。文档 stale 时(>30 天)重跑下方命令并比对。
7. Cross-References
- Selected Target: Task V3 Product / Domain Contract
- Current rollout boundary: Task V3 Rollout 状态快照
- Historical Task V2+ audit: 工程审计与设计建议
- Historical Task design: ../tasks-feature/design/task-pipeline-deliverable-codex.md §6 / §7 / §14
- Historical unified pipeline: ../unified-pipeline/unified-pipeline-final.md
- V2 compatibility entry: ../tasks-feature/tasks-schema.md
- All 7 prompts: ../unified-pipeline/prompts/
- TCPA: 47 U.S.C. § 227(b)(1)
- 2026-06 snapshot sources:
callytics-common/src/utils/due-at.tscallytics-common/src/db/schema/task-ui.tscallytics-common/src/db/schema/store-config.tscallytics-common/src/db/schema/operating-schedules.tscallytics-common/src/db/schema/operating-overrides.tscallytics-common/src/db/schema/blackout-periods.tscallytics-infrastructure/lambda/contacts-analyzer/src/core/prompt-builder.tsstudio-website-monorepo/apps/api/src/routes/tasks/list.ts