@linnlabs/linnkit 0.33.0 → 0.35.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli.cjs +155 -28
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +155 -28
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager.cjs +54 -0
  7. package/dist/context-manager.cjs.map +1 -1
  8. package/dist/context-manager.js +54 -0
  9. package/dist/context-manager.js.map +1 -1
  10. package/dist/index.cjs +175 -43
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +175 -43
  13. package/dist/index.js.map +1 -1
  14. package/dist/quickstart.cjs +155 -28
  15. package/dist/quickstart.cjs.map +1 -1
  16. package/dist/quickstart.js +155 -28
  17. package/dist/quickstart.js.map +1 -1
  18. package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +5 -0
  19. package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +5 -0
  20. package/dist/runtime-kernel/graph-engine/functions/parseEngineCheckpoint.d.cts +6 -0
  21. package/dist/runtime-kernel/graph-engine/functions/parseEngineCheckpoint.d.ts +6 -0
  22. package/dist/runtime-kernel/graph-engine/index.d.cts +1 -0
  23. package/dist/runtime-kernel/graph-engine/index.d.ts +1 -0
  24. package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.cts +22 -4
  25. package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.ts +22 -4
  26. package/dist/runtime-kernel/run-supervisor/index.d.cts +1 -1
  27. package/dist/runtime-kernel/run-supervisor/index.d.ts +1 -1
  28. package/dist/runtime-kernel/run-supervisor/runSupervisor.d.cts +2 -1
  29. package/dist/runtime-kernel/run-supervisor/runSupervisor.d.ts +2 -1
  30. package/dist/runtime-kernel.cjs +172 -40
  31. package/dist/runtime-kernel.cjs.map +1 -1
  32. package/dist/runtime-kernel.d.cts +1 -0
  33. package/dist/runtime-kernel.d.ts +1 -0
  34. package/dist/runtime-kernel.js +172 -41
  35. package/dist/runtime-kernel.js.map +1 -1
  36. package/dist/testkit.cjs +172 -40
  37. package/dist/testkit.cjs.map +1 -1
  38. package/dist/testkit.js +172 -40
  39. package/dist/testkit.js.map +1 -1
  40. package/docs/integration/child-runs.md +8 -0
  41. package/docs/integration/persistence.md +1 -0
  42. package/docs/integration/run-supervisor.md +3 -0
  43. package/package.json +2 -2
@@ -126,10 +126,18 @@ Linnkit 只定义 child-run 原语和端口,不替 Host 选择全局实例。H
126
126
  此模式的异常向 Host 传播且不清理 checkpoint,由 Host 将 attempt 结算为暂停或明确终止。
127
127
  未配置 persistence 的现有嵌入调用仍使用短生命周期内存图。
128
128
 
129
+ Host 可在 admission 前保存 `initialInput: { turnId, request }`,再传给首次 invoke。
130
+ 该输入拥有原始 query、模型、预算、工具集及 Host 扩展的冻结内容;框架只补充唯一 child
131
+ user-input fact 的 `currentUserEventId`,不以当前默认配置覆盖它。query / promptKey 必须与
132
+ 本次调用相符。继续只读取 checkpoint 中的原 request;不重新读取 initialInput。
133
+
129
134
  Host 必须先保存父 tool call 到稳定 child identity 的映射、冻结 child Agent 定义,并复用
130
135
  原 child lifecycle / EventStore writer。仅注入持久 checkpoint 而每次注册新 child 不算恢复。
131
136
  同步 child 的待审批限制仍然存在;需要产品交互的工作交给 foreground run。
132
137
 
138
+ Host 激活原 child 时向 `resumePausedRun` 传入本次父 execution 的 `parentSignal`;
139
+ 旧父 signal 不能继续控制新 child attempt,新的父暂停或取消仍必须传递到 child。
140
+
133
141
  - 单测:父 agent 工具内 `invokeChildRun` → 父 run 的 `cost().childrenTotal.llmCost > 0`
134
142
  - 集成测:child run 内部调用工具时,`model.select` / `tool.allow` audit envelope 的 `scope.conversationId` 与注册 child run 的 conversationId 一致,`scope.runId` 是 child runId。
135
143
  - 单测:child run 的 `abortSignal` 在调用前或执行中触发时,即使 provider 抛普通 Error,`invokeChildRun` 仍 resolve 出 `cancelled:true`,而不是 reject 或写成 failed。
@@ -11,6 +11,7 @@
11
11
  ## 1. linnkit 给你的合同
12
12
 
13
13
  - `Checkpointer`(来自 `@linnlabs/linnkit/runtime-kernel`,在 `graph` namespace 下):`load` / `save` / `clear` 三个必需方法 + `peekMeta` / `list` 两个可选。
14
+ - JSON 持久化 adapter 使用 `graph.parseEngineCheckpoint` 解析读取结果,校验版本、执行位置、预算与事件合同并拒绝序列化能力对象;不能把 JSON 直接断言为 EngineState。Graph result 的 `stepCount` 是本 execution 增量,checkpoint `executorLocal.stepCount` 才是 durable run 的累计值;已 yielded 的继续返回零增量。
14
15
  - `Checkpointer` 的 key 参数叫 `checkpointKey`:它是 EngineState 快照索引。所有可独立运行的顶层、foreground、auxiliary、detached run 都必须使用稳定 `runId`;同步 child-run 使用自己的内部 run-scoped key。禁止用 `conversationId`,否则同会话并行 run 会互相覆盖。
15
16
  - `EventStore`(来自 `@linnlabs/linnkit/runtime-kernel`,在 `graph` namespace 下):`append` / `range` / `latestEventStoreId` 三个必需 + `truncate` 可选。配套 `createMonotonicEventStoreIdFactory()` 帮你生成单调 storage cursor。
16
17
  - `RunRegistryStore`(来自 `@linnlabs/linnkit/runtime-kernel`,在 `runSupervisor` namespace 下):run lifecycle 元数据落库。
@@ -40,6 +40,7 @@ const handle = await supervisor.registerRun({
40
40
  - runner 生命周期必须显式写:启动前 `markRunning()`,正常结束 `markCompleted()`,异常结束 `markFailed()`。取消请求先由 `handle.cancel({ reason })` 写 `cancelled` 并触发 abort;执行器取得真实结果后,再用第二个 lifecycle patch 补全 `currentNode / iterationsUsed`。
41
41
  - `WaitUserNode` 创建的 `requires_user_interaction` 是正式 pause 事实。它必须经 `RuntimeEventPublisher` 附着正式 `run_id / lane / visibility`,与其他事实一起发布和持久化。host runner 在 persistence drain 成功后才能调用 `markAwaitingUser()`,不得从 Graph 返回值 cherry-pick 后补发第二份事件。
42
42
  - HITL 恢复使用 `claimResume(runId, interaction, eventBus, signal)`。返回的 `RunResumeClaim` 先原子占用一次性 interaction,但保持 `awaiting_user`;host 只有在响应事实持久化成功后才能调用 `activate()`,持久化前失败调用 `release()`。这样并发/重复提交只有一个能激活,也不会在 runner 启动前留下半恢复的 running run。
43
+ - 可恢复 Host 通过 `activate({ executionId, inputEventIds, admissionCommit })` 把响应事实与激活状态放入同一事务。`metadata.resumeInputs` 保留已提交的响应引用及原 checkpoint revision;重启若 Graph 仍停在原等待边界,Host 读取这些事实完成原 response 的 resume,不能要求用户再次提交。只有瞬时能力在新 execution 中重新装配。
43
44
  - `RunResumeInteraction` 必须完整匹配 `interactionId / toolCallId / checkpointRevision / resumeToken`。host 必须让 GraphExecutor 用同一 `runId` 的 checkpoint 恢复,禁止注册替代 run 或按 conversation 查“最近 checkpoint”。
44
45
  - 多个 run 共享观察通道时,已发布事件必须带正式 `run_id`。`RunHandle.observe()` 只接收当前 run 的事实;缺少 run identity 是 publisher 边界错误,不能通过 metadata 别名或无差别透传补救。
45
46
  - `registerRun()` / `spawnDetached()` 会把 `AgentSpec` 与 request 作为注册时快照保存;`spawnDetached()` 的 executor 也读取这份快照。调用方后续修改原始对象不会改变已经注册的后台 run。
@@ -47,6 +48,8 @@ const handle = await supervisor.registerRun({
47
48
  - `spawnDetached()` 正常完成或失败后会释放 handle、abort controller 和 EventBus 监听。外部取消只先触发 abort;必须等 executor settlement 写入最终进度后,`waitForTerminal()` 才返回并释放资源。
48
49
  - `maxActiveRuns` 是拒绝式背压,不是队列。超限时 `registerRun()` / `spawnDetached()` 会抛 `RunConcurrencyLimitExceededError`,host 应在上层 orchestration 决定是提示用户、排队还是重试。
49
50
  - `concurrencyKey` 是 host 定义的进程内原子唯一键。适合表达 `conversation:<id>:foreground` 这类业务约束;允许并行的 auxiliary 不应复用 foreground key。禁止用“先 list/find、再 register”替代,因为两个请求可同时通过查询。
51
+ - 已暂停运行被新请求替代时,`registerRun` 使用 `replacesPausedRun` 的原 run / execution / updatedAt 身份,以及 `admissionCommit`。Host 必须在一个事务中核对旧记录、提交旧 cancelled、新 pending 和新请求必要输入;提交失败保留旧暂停运行及其并发名额。不能先取消旧运行再尝试保存新输入。普通注册也可通过同一 `admissionCommit` 原子保存身份与输入。
52
+ - 继续操作应同时提交 `expectedExecutionId` 与 `expectedUpdatedAt`;时间戳只表示暂停状态时间,不能独自防止同毫秒暂停、继续、再暂停后的旧命令重放。
50
53
  - 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
54
  - detached run 执行中如果 EventBus 提前 close,不会提前释放 active slot,避免后台 run 绕过并发限制;slot 会等 detached executor 终态 cleanup。
52
55
  - `pause()` 先持久化暂停意图,再以 `RunPauseRequested` 中断当前 attempt;此时 `status=paused` 且 `pausedAt` 缺失,表示仍在收口。Host 保存断点、收口当前 execution 后调用 `markPaused()`,才允许 `resumePausedRun()` 激活。它不创建用户消息,也不提交任何审批。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linnlabs/linnkit",
3
- "version": "0.33.0",
3
+ "version": "0.35.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",
@@ -109,7 +109,7 @@
109
109
  "vitest": "^4.1.11"
110
110
  },
111
111
  "linnkit": {
112
- "phase": "development (0.33.0 — explicit durable run continuation)",
112
+ "phase": "development (0.34.0 — atomic recovery admission)",
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)",