/** * module: task —— 本模块要外界提供的能力(编码规范 §10.1 / §5.3)。 */ import type { BudgetCaps, Paradigm, StaffId, TaskId, TerminalState } from '@contracts'; import type { Consumption } from './internal/domain/harness.ts'; import type { Task } from './contract.ts'; export type Clock = { now(): Date }; export type IdGenerator = { next(): string }; export type TaskStore = { insert(task: Task): Promise; get(taskId: TaskId): Promise; listByOwner(ownerId: StaffId, openOnly: boolean): Promise; update(taskId: TaskId, patch: Partial): Promise; addConsumption(taskId: TaskId, delta: Partial): Promise; lastProgressAt(taskId: TaskId): Promise; markProgress(taskId: TaskId, at: Date): Promise; }; /** 活动装载 —— app 注入 `activity-registry`(L4) */ export type ActivityLoader = { load(activityId: string): Promise<{ paradigm: Paradigm; caps: BudgetCaps; envelope: Record; /** 输入 data 的 JSON Schema —— 缺项不得启动 */ inputSchema: Record; businessModel: unknown; stallAfter: string; }>; }; export type SchemaValidator = { validate(schema: Record, value: unknown): { ok: boolean; errors: string[] }; }; /** 范式引擎 —— loop / flow 在此汇流;对上层不可区分(§9 双层边界) */ export type ParadigmEngine = { load(taskId: TaskId, model: unknown): Promise; advance(taskId: TaskId): Promise<{ status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked'; reason?: string }>; onEvent( taskId: TaskId, event: { kind: 'data' | 'time' | 'human' | 'control'; ref: string; payload: Record }, ): Promise<{ status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked'; reason?: string }>; }; export type MemoryRecorder = { append(input: { taskId: TaskId; kind: 'engine-transition' | 'terminal' | 'observation'; title: string; detail?: Record; }): Promise; seal(taskId: TaskId): Promise; /** 终态封卷触发蒸馏钩子 —— 产出活动记忆候选条目 */ distill(input: { taskId: TaskId; activityId: string; trigger: 'terminal'; prompt: string }): Promise; hasHistory(taskId: TaskId): Promise; }; /** 监听在等?—— app 注入 `event`(L1):监听中是健康态,与停滞分别对待 */ export type ListenerProbe = { hasArmedListener(taskId: TaskId): Promise; }; /** 草稿层与运行时状态是否在 —— 断点续跑的三份持久状态 */ export type PersistenceProbe = { hasDrafts(taskId: TaskId): Promise; hasRuntimeState(taskId: TaskId): Promise; }; /** 控制事件与终态事件 —— app 注入 `event`(L1) */ export type TaskEventPublisher = { publishControl(taskId: TaskId, semantic: string, by: StaffId, reason?: string): Promise; publishTerminal(taskId: TaskId, terminal: TerminalState, reason: string): Promise; }; /** 改派通知 —— app 注入 `message`(L2):改派留痕并**通知双方** */ export type ReassignNotifier = { notify(input: { from: StaffId; to: StaffId; taskId: TaskId; title: string; by: StaffId }): Promise; }; /** 交互态 —— app 注入 `interaction`(L3):控制权按态转交 */ export type InteractionPhaseSetter = { setPhase(taskId: TaskId, phase: 'activating' | 'active' | 'awaiting-human' | 'awaiting-event' | 'transitioning' | 'terminal'): Promise; };