M1: 底座 —— @contracts 首版 + event / ledger / org / llm

@contracts 首版(§8.1 九个文件):
- id 品牌 ID / terminal 终态五名与归侧四标签 / envelope 信封六字段与四类事件
- card 工单两模式 + 对话卡族(形状对齐 2026-07-26 原型定稿)
- contract7 契约七件 / ledger 三级寻址与写三分 / process-package 流程包 DSL 与触发器三类
- manifest 活动包清单六区(含 CMMN·DMN·步序声明的资产形状)/ org / api 路由契约

模块(L1):
- event   信封存储、归属解析三级短路、投递五诺、监听注册表、三级消费裁定
- ledger  schema 自生长(最大化合并/最宽类型/只增不破坏)、任务视图叠加、写三分、冲突检查
- org     岗位授权(客体三类×动作三种)、停用前置检查、会话、种子播种
- llm     四元绑定、ModelGateway 三模式(live/record/replay)—— 两缝之一

app 装配:Hono 服务 + 鉴权中间件 + 治理台/工作台路由;drizzle 迁移;AES-256-GCM 凭证密封

ADR-007 工具链与门禁 · ADR-008 投递队列 · ADR-009 凭证加密
(ADR 编号自 007 续:编码规范 §14 已用到 006,README 写「从 005 续」是笔误)

门禁五道全绿;96 个测试通过,含对真实 PG 的 ledger 集成测试

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
JCAI Main Agent
2026-07-27 00:59:14 +08:00
co-authored by Claude Opus 5
parent 7cd664af3a
commit 14d4fa046a
120 changed files with 15236 additions and 78 deletions
+213
View File
@@ -0,0 +1,213 @@
/**
* 数据与台账(编码规范 §8.1 / §7.2;语义出处 OS 04 / 09,AM 10.3 / 11.1)。
*
* 三级寻址「数据域.数据对象.字段」+ 通用事务性接口 + 写三分(系统写 / 草稿写 / 放行写)。
* 写三分是 `ledger` 出口上的**三个不同方法**,不是一个带 flag 的方法 —— 调用方拿不到「绕门」的形态。
*/
import { z } from 'zod';
/**
* 数据域:活动自持域用活动名,共享域固定为 `shared`(AM 11.3 暗耦合禁令)。
* 活动间不得共享自持域的数据表;跨活动的事实只有两条路 —— 输出口载荷,或共享域。
*/
export declare const SHARED_DOMAIN = "shared";
export declare const ledgerAddressSchema: z.ZodObject<{
domain: z.ZodString;
object: z.ZodString;
field: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
export type LedgerAddress = z.infer<typeof ledgerAddressSchema>;
export declare function formatAddress(address: LedgerAddress): string;
export declare function parseAddress(text: string): LedgerAddress;
export declare function isSharedDomain(address: LedgerAddress): boolean;
/**
* 字段类型 —— 台账自生长的类型格。
* 「同名异型取能兼容双方的最宽类型」(放宽即增,不破坏);语义互斥才拦下(OS 04)。
*/
export declare const LEDGER_FIELD_TYPES: readonly ["text", "number", "integer", "boolean", "date", "timestamp", "json"];
export declare const ledgerFieldTypeSchema: z.ZodEnum<{
number: "number";
boolean: "boolean";
json: "json";
text: "text";
date: "date";
integer: "integer";
timestamp: "timestamp";
}>;
export type LedgerFieldType = z.infer<typeof ledgerFieldTypeSchema>;
/** 字段使用声明 —— 声明的是**活动要用什么字段**,不是对象该定义什么字段 */
export declare const fieldDeclarationSchema: z.ZodObject<{
name: z.ZodString;
type: z.ZodEnum<{
number: "number";
boolean: "boolean";
json: "json";
text: "text";
date: "date";
integer: "integer";
timestamp: "timestamp";
}>;
label: z.ZodOptional<z.ZodString>;
primaryKey: z.ZodDefault<z.ZodBoolean>;
masked: z.ZodDefault<z.ZodBoolean>;
}, z.core.$strip>;
export type FieldDeclaration = z.infer<typeof fieldDeclarationSchema>;
export declare const objectDeclarationSchema: z.ZodObject<{
domain: z.ZodString;
object: z.ZodString;
label: z.ZodOptional<z.ZodString>;
fields: z.ZodArray<z.ZodObject<{
name: z.ZodString;
type: z.ZodEnum<{
number: "number";
boolean: "boolean";
json: "json";
text: "text";
date: "date";
integer: "integer";
timestamp: "timestamp";
}>;
label: z.ZodOptional<z.ZodString>;
primaryKey: z.ZodDefault<z.ZodBoolean>;
masked: z.ZodDefault<z.ZodBoolean>;
}, z.core.$strip>>;
}, z.core.$strip>;
export type ObjectDeclaration = z.infer<typeof objectDeclarationSchema>;
export declare const ledgerRowSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
export type LedgerRow = z.infer<typeof ledgerRowSchema>;
export declare const ledgerKeySchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
export type LedgerKey = z.infer<typeof ledgerKeySchema>;
export declare const LEDGER_OPERATIONS: readonly ["insert", "update", "upsert", "delete"];
export declare const ledgerOperationSchema: z.ZodEnum<{
insert: "insert";
update: "update";
delete: "delete";
upsert: "upsert";
}>;
export type LedgerOperation = z.infer<typeof ledgerOperationSchema>;
export declare const ledgerMutationSchema: z.ZodObject<{
address: z.ZodObject<{
object: z.ZodString;
domain: z.ZodString;
}, z.core.$strip>;
operation: z.ZodEnum<{
insert: "insert";
update: "update";
delete: "delete";
upsert: "upsert";
}>;
key: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
values: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, z.core.$strip>;
export type LedgerMutation = z.infer<typeof ledgerMutationSchema>;
/** 查询:简单等值过滤 + 排序 + 分页(治理台数据管理的记录浏览也走这里) */
export declare const ledgerQuerySchema: z.ZodObject<{
address: z.ZodObject<{
object: z.ZodString;
domain: z.ZodString;
}, z.core.$strip>;
where: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
orderBy: z.ZodDefault<z.ZodArray<z.ZodObject<{
field: z.ZodString;
dir: z.ZodEnum<{
desc: "desc";
asc: "asc";
}>;
}, z.core.$strip>>>;
limit: z.ZodDefault<z.ZodNumber>;
offset: z.ZodDefault<z.ZodNumber>;
}, z.core.$strip>;
export type LedgerQuery = z.infer<typeof ledgerQuerySchema>;
export declare const ledgerPageSchema: z.ZodObject<{
rows: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
total: z.ZodNumber;
}, z.core.$strip>;
export type LedgerPage = z.infer<typeof ledgerPageSchema>;
/**
* ① system —— 系统写:入站归一、流转记录、留痕。登记世界已发生的事实,不过放行门,
* 写入正式版并**即时产生数据事件**。
* ② draft —— 草稿写:任务级草稿层(读己之写:本任务可见、正式版不可见、**不产生数据事件**)。
* ③ release —— 放行写:草稿层合并入正式版,**此刻才产生数据事件**。
*/
export declare const WRITE_KINDS: readonly ["system", "draft", "release"];
export declare const writeKindSchema: z.ZodEnum<{
draft: "draft";
system: "system";
release: "release";
}>;
export type WriteKind = z.infer<typeof writeKindSchema>;
export declare const WRITE_KIND_LABEL: Readonly<Record<WriteKind, string>>;
/** 三分的不变量,机检用:只有 draft 不抛数据事件 */
export declare function emitsDataEvent(kind: WriteKind): boolean;
/** 任务视图 = 正式版 + 本任务草稿层;环内推进读它,不依赖事件(OS 09) */
export declare const taskViewRequestSchema: z.ZodObject<{
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
query: z.ZodObject<{
address: z.ZodObject<{
object: z.ZodString;
domain: z.ZodString;
}, z.core.$strip>;
where: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
orderBy: z.ZodDefault<z.ZodArray<z.ZodObject<{
field: z.ZodString;
dir: z.ZodEnum<{
desc: "desc";
asc: "asc";
}>;
}, z.core.$strip>>>;
limit: z.ZodDefault<z.ZodNumber>;
offset: z.ZodDefault<z.ZodNumber>;
}, z.core.$strip>;
}, z.core.$strip>;
export type TaskViewRequest = z.infer<typeof taskViewRequestSchema>;
export declare const draftPatchSchema: z.ZodObject<{
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
address: z.ZodObject<{
object: z.ZodString;
domain: z.ZodString;
}, z.core.$strip>;
key: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
patch: z.ZodRecord<z.ZodString, z.ZodUnknown>;
tombstone: z.ZodDefault<z.ZodBoolean>;
}, z.core.$strip>;
export type DraftPatch = z.infer<typeof draftPatchSchema>;
/** 数据冲突检查(落地预检第五项):他单已改同一字段即预检不过(OS 7.3) */
export declare const draftConflictSchema: z.ZodObject<{
address: z.ZodObject<{
domain: z.ZodString;
object: z.ZodString;
field: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
key: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
field: z.ZodString;
draftValue: z.ZodUnknown;
officialValue: z.ZodUnknown;
baselineValue: z.ZodUnknown;
}, z.core.$strip>;
export type DraftConflict = z.infer<typeof draftConflictSchema>;
export declare const ACTION_INTENT_STATES: readonly ["drafted", "prechecked", "landed", "failed", "abandoned"];
export declare const actionIntentStateSchema: z.ZodEnum<{
failed: "failed";
drafted: "drafted";
prechecked: "prechecked";
landed: "landed";
abandoned: "abandoned";
}>;
export type ActionIntentState = z.infer<typeof actionIntentStateSchema>;
export declare const actionIntentSchema: z.ZodObject<{
id: z.ZodString;
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
tool: z.ZodString;
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
idempotencyKey: z.ZodString;
state: z.ZodEnum<{
failed: "failed";
drafted: "drafted";
prechecked: "prechecked";
landed: "landed";
abandoned: "abandoned";
}>;
label: z.ZodString;
detail: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
export type ActionIntent = z.infer<typeof actionIntentSchema>;