M4: 范式引擎与任务运行时
skill-engine(L4):载方法不载权力(白名单外工具即拒)、结晶片段经 ToolInvoker 留痕、 装配入信封、技能目录渐进披露 flow-engine(L5):四种步型、确定性谓词跳步、重试与声明给定的兜底、 异步步即监听(时限必配)、写类工具登记动作意向、步序位置持久 loop-engine(L5):自研 CMMN 子集解析器(表外构件直接报错,子集封顶可机器证明)、 两副标准生命周期与迁移拓扑(引擎不得私改)、Enabled ≠ Active、 语义性前提标待裁量评估(引擎不代裁量)、DMN 确定性求值 + 命中行留痕、 DRD 缺口演绎与拓扑序、双向驱动与交集导航(断点即人环)、三型行动、 终局唯放行与 Harness task(L6):终态五名裁定(released 唯一成功)、Harness 预算环外强制与停滞熔断 (监听中是健康态)、控制三语义(叫停不是终态,记最重档纠正)、改派留痕通知双方、 断点续跑三份持久状态、封卷触发蒸馏钩子 301 个测试通过,门禁五道全绿 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
co-authored by
Claude Opus 5
parent
2850e6d4ef
commit
3c974d2860
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* module: task —— 对外类型(编码规范 §10.1;语义出处 OS 04,AM 01/10)。
|
||||
*
|
||||
* 任务运行时:生命周期与**终态五名裁定**、Harness 预算执行器 / 停滞熔断、
|
||||
* 控制三语义、改派、断点续跑。范式(loop / flow)在此汇流 —— 对流程层与交互层不可区分。
|
||||
*/
|
||||
import type { BudgetCaps, ControlSemantic, Paradigm, StaffId, TaskId, TaskRuntimeState, TerminalState } from '@contracts';
|
||||
import type { BudgetBreach, Consumption, HarnessVerdict } from './internal/domain/harness.ts';
|
||||
import type { ControlOutcome, ResumeReadiness, TaskSnapshot, TerminalCause } from './internal/domain/lifecycle.ts';
|
||||
export type { BudgetBreach, BudgetCaps, Consumption, ControlOutcome, ControlSemantic, HarnessVerdict, Paradigm, ResumeReadiness, TaskRuntimeState, TaskSnapshot, TerminalCause, TerminalState, };
|
||||
export declare class TaskNotFoundError extends Error {
|
||||
readonly taskId: TaskId;
|
||||
constructor(taskId: TaskId);
|
||||
}
|
||||
export declare class TaskAlreadyTerminalError extends Error {
|
||||
readonly taskId: TaskId;
|
||||
readonly terminal: TerminalState;
|
||||
constructor(taskId: TaskId, terminal: TerminalState);
|
||||
}
|
||||
/** 一单任务 —— 活动的运行时实例;**恰有一名负责人** */
|
||||
export type Task = {
|
||||
readonly id: TaskId;
|
||||
readonly activityId: string;
|
||||
readonly paradigm: Paradigm;
|
||||
/** 起单来源:工作流节点;登记触发的直起单为 undefined */
|
||||
readonly workflowId?: string;
|
||||
readonly nodeId?: string;
|
||||
readonly ownerId: StaffId;
|
||||
readonly title: string;
|
||||
readonly runtime: TaskRuntimeState;
|
||||
readonly terminal?: TerminalState;
|
||||
readonly reason?: string;
|
||||
/** 装载信封:包版本 + 各资产生效版 —— 行为可归因 */
|
||||
readonly envelope: Readonly<Record<string, unknown>>;
|
||||
readonly caps: BudgetCaps;
|
||||
readonly used: Consumption;
|
||||
readonly startedAt: string;
|
||||
readonly finishedAt?: string;
|
||||
};
|
||||
export type StartTaskInput = {
|
||||
readonly activityId: string;
|
||||
readonly ownerId: StaffId;
|
||||
readonly title: string;
|
||||
readonly workflowId?: string;
|
||||
readonly nodeId?: string;
|
||||
/** 输入:data(按 schema 校验,缺项不得启动)+ message(委托消息,可为空) */
|
||||
readonly data: Record<string, unknown>;
|
||||
readonly message?: string;
|
||||
};
|
||||
export type TickOutcome = {
|
||||
readonly task: Task;
|
||||
readonly verdict: HarnessVerdict;
|
||||
readonly progressed: boolean;
|
||||
};
|
||||
export type TaskService = {
|
||||
/** 起单:装载 → 校验输入 → 建任务记忆 → 首个回合 */
|
||||
start(input: StartTaskInput): Promise<Task>;
|
||||
get(taskId: TaskId): Promise<Task>;
|
||||
listByOwner(ownerId: StaffId, openOnly?: boolean): Promise<Task[]>;
|
||||
/** org 停用前置检查要问的「在途任务」 */
|
||||
openTasksOf(ownerId: StaffId): Promise<Array<{
|
||||
taskId: string;
|
||||
title: string;
|
||||
}>>;
|
||||
/** 推进一拍:**预算在环外先扣先判**,再交范式引擎 */
|
||||
tick(taskId: TaskId): Promise<TickOutcome>;
|
||||
/** 事件驱动续跑 —— 挂起期间事件不丢,恢复即补投 */
|
||||
deliver(taskId: TaskId, event: {
|
||||
kind: 'data' | 'time' | 'human' | 'control';
|
||||
ref: string;
|
||||
payload: Record<string, unknown>;
|
||||
}): Promise<TickOutcome>;
|
||||
/** 控制三语义:暂停 / 叫停 / 终止 */
|
||||
control(taskId: TaskId, semantic: ControlSemantic, by: StaffId, reason?: string): Promise<ControlOutcome>;
|
||||
resume(taskId: TaskId, by: StaffId): Promise<Task>;
|
||||
/** 改派:在途任务的负责人变更,**留痕并通知双方** */
|
||||
reassign(taskId: TaskId, to: StaffId, by: StaffId): Promise<Task>;
|
||||
/** 终态裁定 —— 完成由框架裁定,终态由系统命名 */
|
||||
finish(taskId: TaskId, cause: TerminalCause): Promise<Task>;
|
||||
/** 断点续跑的三份持久状态是否齐备 */
|
||||
resumeReadiness(taskId: TaskId): Promise<ResumeReadiness>;
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* module: task —— 唯一出口。只做 re-export,不写逻辑(编码规范 §10.1)。
|
||||
*/
|
||||
export type { BudgetBreach, BudgetCaps, Consumption, ControlOutcome, ControlSemantic, HarnessVerdict, Paradigm, ResumeReadiness, StartTaskInput, Task, TaskRuntimeState, TaskService, TaskSnapshot, TerminalCause, TerminalState, TickOutcome, } from './contract.ts';
|
||||
export { TaskAlreadyTerminalError, TaskNotFoundError } from './contract.ts';
|
||||
export type { ActivityLoader, Clock, IdGenerator, InteractionPhaseSetter, ListenerProbe, MemoryRecorder, ParadigmEngine, PersistenceProbe, ReassignNotifier, SchemaValidator, TaskEventPublisher, TaskStore, } from './port.ts';
|
||||
export type { TaskServiceDeps } from './internal/usecase/task-service.ts';
|
||||
export { createTaskService } from './internal/usecase/task-service.ts';
|
||||
export { budgetBreaches, durationMs, isStalled, judge, terminalOf, ZERO_CONSUMPTION, } from './internal/domain/harness.ts';
|
||||
export { applyControl, decideTerminal, isPassiveOpen, isSuccess, isTerminalControl, landingBlocked, RESUME_SOURCES, rejectionKeepsRunning, resumeReadiness, triggersFailureDisposition, } from './internal/domain/lifecycle.ts';
|
||||
export { createTaskStore } from './internal/adapter/task-store.ts';
|
||||
export { taskTable } from './internal/adapter/task-schema.ts';
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 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<void>;
|
||||
get(taskId: TaskId): Promise<Task | undefined>;
|
||||
listByOwner(ownerId: StaffId, openOnly: boolean): Promise<Task[]>;
|
||||
update(taskId: TaskId, patch: Partial<Task>): Promise<Task>;
|
||||
addConsumption(taskId: TaskId, delta: Partial<Consumption>): Promise<Consumption>;
|
||||
lastProgressAt(taskId: TaskId): Promise<Date | undefined>;
|
||||
markProgress(taskId: TaskId, at: Date): Promise<void>;
|
||||
};
|
||||
/** 活动装载 —— app 注入 `activity-registry`(L4) */
|
||||
export type ActivityLoader = {
|
||||
load(activityId: string): Promise<{
|
||||
paradigm: Paradigm;
|
||||
caps: BudgetCaps;
|
||||
envelope: Record<string, unknown>;
|
||||
/** 输入 data 的 JSON Schema —— 缺项不得启动 */
|
||||
inputSchema: Record<string, unknown>;
|
||||
businessModel: unknown;
|
||||
stallAfter: string;
|
||||
}>;
|
||||
};
|
||||
export type SchemaValidator = {
|
||||
validate(schema: Record<string, unknown>, value: unknown): {
|
||||
ok: boolean;
|
||||
errors: string[];
|
||||
};
|
||||
};
|
||||
/** 范式引擎 —— loop / flow 在此汇流;对上层不可区分(§9 双层边界) */
|
||||
export type ParadigmEngine = {
|
||||
load(taskId: TaskId, model: unknown): Promise<void>;
|
||||
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<string, unknown>;
|
||||
}): 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<string, unknown>;
|
||||
}): Promise<void>;
|
||||
seal(taskId: TaskId): Promise<void>;
|
||||
/** 终态封卷触发蒸馏钩子 —— 产出活动记忆候选条目 */
|
||||
distill(input: {
|
||||
taskId: TaskId;
|
||||
activityId: string;
|
||||
trigger: 'terminal';
|
||||
prompt: string;
|
||||
}): Promise<unknown>;
|
||||
hasHistory(taskId: TaskId): Promise<boolean>;
|
||||
};
|
||||
/** 监听在等?—— app 注入 `event`(L1):监听中是健康态,与停滞分别对待 */
|
||||
export type ListenerProbe = {
|
||||
hasArmedListener(taskId: TaskId): Promise<boolean>;
|
||||
};
|
||||
/** 草稿层与运行时状态是否在 —— 断点续跑的三份持久状态 */
|
||||
export type PersistenceProbe = {
|
||||
hasDrafts(taskId: TaskId): Promise<boolean>;
|
||||
hasRuntimeState(taskId: TaskId): Promise<boolean>;
|
||||
};
|
||||
/** 控制事件与终态事件 —— app 注入 `event`(L1) */
|
||||
export type TaskEventPublisher = {
|
||||
publishControl(taskId: TaskId, semantic: string, by: StaffId, reason?: string): Promise<void>;
|
||||
publishTerminal(taskId: TaskId, terminal: TerminalState, reason: string): Promise<void>;
|
||||
};
|
||||
/** 改派通知 —— app 注入 `message`(L2):改派留痕并**通知双方** */
|
||||
export type ReassignNotifier = {
|
||||
notify(input: {
|
||||
from: StaffId;
|
||||
to: StaffId;
|
||||
taskId: TaskId;
|
||||
title: string;
|
||||
by: StaffId;
|
||||
}): Promise<void>;
|
||||
};
|
||||
/** 交互态 —— app 注入 `interaction`(L3):控制权按态转交 */
|
||||
export type InteractionPhaseSetter = {
|
||||
setPhase(taskId: TaskId, phase: 'activating' | 'active' | 'awaiting-human' | 'awaiting-event' | 'transitioning' | 'terminal'): Promise<void>;
|
||||
};
|
||||
Reference in New Issue
Block a user