@linnlabs/linnkit 0.32.2 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/cli.cjs +312 -50
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +312 -50
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +1 -0
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +1 -0
- package/dist/context-manager.js.map +1 -1
- package/dist/contracts/agentSpec.d.cts +30 -30
- package/dist/contracts/agentSpec.d.ts +30 -30
- package/dist/contracts/audit.d.cts +32 -32
- package/dist/contracts/audit.d.ts +32 -32
- package/dist/contracts/contextPolicy.d.cts +36 -36
- package/dist/contracts/contextPolicy.d.ts +36 -36
- package/dist/contracts/events.d.cts +968 -968
- package/dist/contracts/events.d.ts +968 -968
- package/dist/contracts/execution.d.cts +8 -8
- package/dist/contracts/execution.d.ts +8 -8
- package/dist/contracts/messages.d.cts +204 -204
- package/dist/contracts/messages.d.ts +204 -204
- package/dist/contracts/sse.d.cts +891 -891
- package/dist/contracts/sse.d.ts +891 -891
- package/dist/contracts/sub-run-trace-payload.d.cts +26 -26
- package/dist/contracts/sub-run-trace-payload.d.ts +26 -26
- package/dist/contracts/token-accounting.d.cts +28 -28
- package/dist/contracts/token-accounting.d.ts +28 -28
- package/dist/index.cjs +383 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +383 -66
- package/dist/index.js.map +1 -1
- package/dist/quickstart/toolRuntime.d.cts +1 -1
- package/dist/quickstart/toolRuntime.d.ts +1 -1
- package/dist/quickstart/types.d.cts +1 -1
- package/dist/quickstart/types.d.ts +1 -1
- package/dist/quickstart.cjs +312 -50
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +312 -50
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +11 -0
- package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +11 -0
- package/dist/runtime-kernel/events/agentEvents.d.cts +98 -98
- package/dist/runtime-kernel/events/agentEvents.d.ts +98 -98
- package/dist/runtime-kernel/execution/eventBusEventPersistence.d.cts +15 -1
- package/dist/runtime-kernel/execution/eventBusEventPersistence.d.ts +15 -1
- package/dist/runtime-kernel/graph-engine/definitions/runContinuation.d.cts +34 -0
- package/dist/runtime-kernel/graph-engine/definitions/runContinuation.d.ts +34 -0
- package/dist/runtime-kernel/graph-engine/engine.d.cts +13 -2
- package/dist/runtime-kernel/graph-engine/engine.d.ts +13 -2
- package/dist/runtime-kernel/graph-engine/index.d.cts +2 -1
- package/dist/runtime-kernel/graph-engine/index.d.ts +2 -1
- package/dist/runtime-kernel/graph-engine/types.d.cts +8 -0
- package/dist/runtime-kernel/graph-engine/types.d.ts +8 -0
- package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.cts +14 -2
- package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.ts +14 -2
- package/dist/runtime-kernel/run-supervisor/memoryRunRegistryStore.d.cts +1 -0
- package/dist/runtime-kernel/run-supervisor/memoryRunRegistryStore.d.ts +1 -0
- package/dist/runtime-kernel/run-supervisor/runHandle.d.cts +9 -5
- package/dist/runtime-kernel/run-supervisor/runHandle.d.ts +9 -5
- package/dist/runtime-kernel/run-supervisor/runRegistryStorePort.d.cts +2 -0
- package/dist/runtime-kernel/run-supervisor/runRegistryStorePort.d.ts +2 -0
- package/dist/runtime-kernel/run-supervisor/runSupervisor.d.cts +7 -1
- package/dist/runtime-kernel/run-supervisor/runSupervisor.d.ts +7 -1
- package/dist/runtime-kernel.cjs +383 -66
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +2 -1
- package/dist/runtime-kernel.d.ts +2 -1
- package/dist/runtime-kernel.js +381 -67
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +383 -66
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +383 -66
- package/dist/testkit.js.map +1 -1
- package/docs/integration/01-installation.md +1 -1
- package/docs/integration/child-runs.md +12 -0
- package/docs/integration/persistence.md +23 -0
- package/docs/integration/run-supervisor.md +12 -2
- package/package.json +4 -4
|
@@ -46,7 +46,7 @@ CLI v0 只包含三个命令:
|
|
|
46
46
|
| peer | 说明 |
|
|
47
47
|
|---|---|
|
|
48
48
|
| `zod` (`^3.22.0`) | 必需。`@linnlabs/linnkit/contracts` 用 zod 定义所有消息/事件 schema,运行时也会校验 |
|
|
49
|
-
| `vitest` (`^2 \|\| ^3`) | 可选。**只有当你打算 import `@linnlabs/linnkit/testkit` 写测试时才需要装** |
|
|
49
|
+
| `vitest` (`^2 \|\| ^3 \|\| ^4`) | 可选。**只有当你打算 import `@linnlabs/linnkit/testkit` 写测试时才需要装** |
|
|
50
50
|
|
|
51
51
|
`@linnlabs/linnkit/testkit` 在源码顶层 `import { vi, expect } from 'vitest'`,所以生产代码 **绝对不能** import 这个子入口(详见 [constraints-and-pitfalls.md](./constraints-and-pitfalls.md))。
|
|
52
52
|
|
|
@@ -118,6 +118,18 @@ Linnkit 只定义 child-run 原语和端口,不替 Host 选择全局实例。H
|
|
|
118
118
|
|
|
119
119
|
## 6. 最小验证
|
|
120
120
|
|
|
121
|
+
### 同步 child 的持久继续
|
|
122
|
+
|
|
123
|
+
`ChildRunInvokeConfig.persistence` 显式注入持久 Checkpointer、ExecutionCheckpointPort
|
|
124
|
+
与 ToolRecoveryPort。首次调用持久化原 child 输入;继续传入同一 runId 和 expectedRevision,
|
|
125
|
+
保留原 turn、用户输入、请求与累计步数。已 yielded 的 child 只读取原结果,不再次调用模型。
|
|
126
|
+
此模式的异常向 Host 传播且不清理 checkpoint,由 Host 将 attempt 结算为暂停或明确终止。
|
|
127
|
+
未配置 persistence 的现有嵌入调用仍使用短生命周期内存图。
|
|
128
|
+
|
|
129
|
+
Host 必须先保存父 tool call 到稳定 child identity 的映射、冻结 child Agent 定义,并复用
|
|
130
|
+
原 child lifecycle / EventStore writer。仅注入持久 checkpoint 而每次注册新 child 不算恢复。
|
|
131
|
+
同步 child 的待审批限制仍然存在;需要产品交互的工作交给 foreground run。
|
|
132
|
+
|
|
121
133
|
- 单测:父 agent 工具内 `invokeChildRun` → 父 run 的 `cost().childrenTotal.llmCost > 0`
|
|
122
134
|
- 集成测:child run 内部调用工具时,`model.select` / `tool.allow` audit envelope 的 `scope.conversationId` 与注册 child run 的 conversationId 一致,`scope.runId` 是 child runId。
|
|
123
135
|
- 单测:child run 的 `abortSignal` 在调用前或执行中触发时,即使 provider 抛普通 Error,`invokeChildRun` 仍 resolve 出 `cancelled:true`,而不是 reject 或写成 failed。
|
|
@@ -57,4 +57,27 @@ UI 历史应由 `events` 派生为可重建 read model。read model 可以与事
|
|
|
57
57
|
|
|
58
58
|
## 6. 最小验证
|
|
59
59
|
|
|
60
|
+
### 可恢复执行的显式接入
|
|
61
|
+
|
|
62
|
+
`GraphExecutorConfig.executionCheckpointPort` 启用可恢复执行提交:Host 必须把 publisher
|
|
63
|
+
已接纳的本步骤 durable facts 与传入 checkpoint 放进同一短事务,并校验当前 activation
|
|
64
|
+
的写入权。普通 EventBus consumer 在此模式下暂存事实,由该提交释放;不能先独立落盘
|
|
65
|
+
再把两次写入称为原子提交。`RuntimeEventCommitPort` 的显式 durable-first 事实仍走原入口。
|
|
66
|
+
|
|
67
|
+
`EventBusEventPersistence.checkpointWriter` 在现有 consumer 内暂存本步骤事实;Graph 的
|
|
68
|
+
提交端口调用同实例 `commitCheckpoint`,writer 一次收到 facts 与 checkpoint。
|
|
69
|
+
离开 Graph 时调用 `finishCheckpointWrites` 作废未提交 attempt 并恢复普通 settlement
|
|
70
|
+
写入。`drain` 只等待已安排的事务,不能把 staged facts 当成已持久化。客户端以持久运行
|
|
71
|
+
状态确认完成,不把尚未提交的实时进度当作恢复凭据。
|
|
72
|
+
|
|
73
|
+
Graph 在节点调用前保存进度,每个工具 call 前保存执行意图、结束后保存结果与下一位置。
|
|
74
|
+
`continueSession` 只挂载新的临时能力,保留原请求、历史、模型和累计预算;不创建用户输入,
|
|
75
|
+
也不从 `user` 重启。`yielded` checkpoint 只返回已完成状态,不能重跑最终节点。
|
|
76
|
+
未决工具必须经 `ToolRecoveryPort` 查询 owner;无 owner 证明时抛 `RunRecoveryBlockedError`,
|
|
77
|
+
不按相同参数猜测成功。允许安全重试是 owner 的显式决定。
|
|
78
|
+
|
|
79
|
+
`RunPauseRequested` 是临时停止的 signal reason;它不等于取消,也不结算尚未执行的
|
|
80
|
+
工具为失败。Host 仍负责 RunDescriptor、权限重建、唯一 activation、生命周期和资源保留。
|
|
81
|
+
仅使用原 `Checkpointer` 的 Host 不会自动获得这些恢复保证。
|
|
82
|
+
|
|
60
83
|
linnkit 在内部对每个 port 都跑了 contract test。你的实现必须通过这些**等价的契约测试**。建议在 host 测试里 mirror linnkit 的 contract test,把 memory 实现 → 你的实现做参数化,确保行为 1:1。
|
|
@@ -49,7 +49,8 @@ const handle = await supervisor.registerRun({
|
|
|
49
49
|
- `concurrencyKey` 是 host 定义的进程内原子唯一键。适合表达 `conversation:<id>:foreground` 这类业务约束;允许并行的 auxiliary 不应复用 foreground key。禁止用“先 list/find、再 register”替代,因为两个请求可同时通过查询。
|
|
50
50
|
- transport `EventBus.close()` 不等于 run 终态。`awaiting_user` 会保留 handle/slot;恢复时 `claimResume.activate()` 把同一 RunHandle 换绑到新的 transport EventBus,并轮换 execution controller,`observeRun()` 可跨 transport 连续观察。同步 run 在 completed/failed/cancelled 后释放;detached 取消还必须等 executor settlement。
|
|
51
51
|
- detached run 执行中如果 EventBus 提前 close,不会提前释放 active slot,避免后台 run 绕过并发限制;slot 会等 detached executor 终态 cleanup。
|
|
52
|
-
- `
|
|
52
|
+
- `pause()` 先持久化暂停意图,再以 `RunPauseRequested` 中断当前 attempt;此时 `status=paused` 且 `pausedAt` 缺失,表示仍在收口。Host 保存断点、收口当前 execution 后调用 `markPaused()`,才允许 `resumePausedRun()` 激活。它不创建用户消息,也不提交任何审批。
|
|
53
|
+
- `resumePausedRun({ runId, expectedUpdatedAt, executionId, eventBus })` 保留同一 run 并轮换 execution identity / signal。Host 必须先完成前一 execution 的收口,之后再启动 Graph `continueSession`。原本抛 NotImplementedError 的 `RunHandle.resume()` 已移除,避免把“改状态”误当成“调度 Graph”。`runTree/handleFailure` 仍未实现。
|
|
53
54
|
|
|
54
55
|
## 3. RunHandle 完整 API(截至 0.5.0)
|
|
55
56
|
|
|
@@ -67,7 +68,16 @@ const handle = await supervisor.registerRun({
|
|
|
67
68
|
|
|
68
69
|
## 4. 进程恢复(recoverOnBoot)
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
Host 提供 `canRestoreRun(record)` 时,`recoverOnBoot()` 把具备 durable 输入的遗留运行重建为
|
|
72
|
+
`paused`,保留原等待交互及其 identity,并清除旧进程的临时 response claim。它不会调用
|
|
73
|
+
executor。Host 校验 descriptor 后用 `restoreRun()` 重建原 handle,等待用户的正式继续操作。
|
|
74
|
+
缺少恢复输入的旧运行仍以 `RUN_ABANDONED` 结算;已 cancelled/completed/failed 的运行不复活。
|
|
75
|
+
|
|
76
|
+
恢复装配必须实现 `RunRegistryStore.compareAndSwap(previous, next)`:状态转换以完整旧记录
|
|
77
|
+
为条件原子提交,冲突向调用方返回而不是覆盖。Host 同时必须持有工作区唯一 owner,并在
|
|
78
|
+
事件 / checkpoint 事务校验当前 `metadata.executionId`;Supervisor 的内存锁不能替代
|
|
79
|
+
存储 fence。RunHandle 拒绝与当前 execution identity 不一致的旧 owner lifecycle 写入。
|
|
80
|
+
`restoreRun` 不会从聊天记录猜 request:原 AgentSpec、请求和能力兼容性校验属于 Host descriptor。
|
|
71
81
|
|
|
72
82
|
## 5. Cost 统计
|
|
73
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linnlabs/linnkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A fine-grained context engineering framework for Agent applications — control every token sent to the model, with clear run lifecycle, audit records, and testable protocol boundaries.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"tiktoken": "^1.0.22"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
-
"vitest": "^2.0.0 || ^3.0.0",
|
|
95
|
+
"vitest": "^2.0.0 || ^3.0.0 || ^4.0.0",
|
|
96
96
|
"zod": "^3.22.0"
|
|
97
97
|
},
|
|
98
98
|
"peerDependenciesMeta": {
|
|
@@ -106,10 +106,10 @@
|
|
|
106
106
|
"rollup-plugin-dts": "6.5.1",
|
|
107
107
|
"tsup": "^8.0.0",
|
|
108
108
|
"typescript": "^5.5.4",
|
|
109
|
-
"vitest": "^
|
|
109
|
+
"vitest": "^4.1.11"
|
|
110
110
|
},
|
|
111
111
|
"linnkit": {
|
|
112
|
-
"phase": "development (0.
|
|
112
|
+
"phase": "development (0.33.0 — explicit durable run continuation)",
|
|
113
113
|
"sourceOfTruth": "CHANGELOG.md",
|
|
114
114
|
"notes": [
|
|
115
115
|
"子入口 ./runtime-kernel/events 是 browser-safe slim seam:仅暴露 events governance 纯函数,禁止扩展任何 Node-only 依赖(如 node:async_hooks / crypto / fs)",
|