@sema-agent/client-core 0.3.0 → 0.5.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 (69) hide show
  1. package/README.md +57 -4
  2. package/dist/adapt.d.ts +30 -3
  3. package/dist/adapt.js +490 -354
  4. package/dist/adapter/downstream/eventToSdkMessage.d.ts +81 -0
  5. package/dist/adapter/downstream/eventToSdkMessage.js +330 -0
  6. package/dist/adapter/downstream/terminalToSdkResult.d.ts +71 -0
  7. package/dist/adapter/downstream/terminalToSdkResult.js +370 -0
  8. package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +26 -0
  9. package/dist/adapter/downstream/turnUsageToModelUsage.js +12 -0
  10. package/dist/adapter/runStream.d.ts +38 -0
  11. package/dist/adapter/runStream.js +177 -0
  12. package/dist/adapter/types.d.ts +73 -0
  13. package/dist/adapter/types.js +23 -0
  14. package/dist/agentsWireCaps.d.ts +112 -0
  15. package/dist/agentsWireCaps.js +319 -0
  16. package/dist/attachmentsWireCaps.d.ts +47 -0
  17. package/dist/attachmentsWireCaps.js +46 -0
  18. package/dist/classifierVerdictWire.d.ts +45 -0
  19. package/dist/classifierVerdictWire.js +76 -0
  20. package/dist/clientContextWireCaps.d.ts +46 -0
  21. package/dist/clientContextWireCaps.js +48 -0
  22. package/dist/cloudConfigWireCaps.d.ts +110 -0
  23. package/dist/cloudConfigWireCaps.js +228 -0
  24. package/dist/controlRouter.d.ts +191 -0
  25. package/dist/controlRouter.js +244 -0
  26. package/dist/effortWire.d.ts +34 -0
  27. package/dist/effortWire.js +38 -0
  28. package/dist/engineWireSdk.d.ts +49 -0
  29. package/dist/engineWireSdk.js +61 -0
  30. package/dist/forkWireCaps.d.ts +25 -0
  31. package/dist/forkWireCaps.js +42 -0
  32. package/dist/hostEnv.d.ts +16 -0
  33. package/dist/hostEnv.js +17 -0
  34. package/dist/imagesWireCaps.d.ts +28 -0
  35. package/dist/imagesWireCaps.js +49 -0
  36. package/dist/index.d.ts +52 -0
  37. package/dist/index.js +62 -0
  38. package/dist/liveModelCatalog.d.ts +62 -0
  39. package/dist/liveModelCatalog.js +79 -0
  40. package/dist/mcpWireCaps.d.ts +41 -0
  41. package/dist/mcpWireCaps.js +51 -0
  42. package/dist/modelBudgetRule.d.ts +44 -0
  43. package/dist/modelBudgetRule.js +73 -0
  44. package/dist/modelWireCaps.d.ts +17 -0
  45. package/dist/modelWireCaps.js +16 -0
  46. package/dist/notifications.d.ts +150 -4
  47. package/dist/notifications.js +472 -0
  48. package/dist/permissionWireCaps.d.ts +37 -0
  49. package/dist/permissionWireCaps.js +46 -0
  50. package/dist/promptProfileWireCaps.d.ts +17 -0
  51. package/dist/promptProfileWireCaps.js +20 -0
  52. package/dist/retainBackgroundWireCaps.d.ts +50 -0
  53. package/dist/retainBackgroundWireCaps.js +58 -0
  54. package/dist/rewindWireCaps.d.ts +36 -0
  55. package/dist/rewindWireCaps.js +41 -0
  56. package/dist/seam.d.ts +97 -2
  57. package/dist/selfOrchestrationWireCaps.d.ts +40 -0
  58. package/dist/selfOrchestrationWireCaps.js +48 -0
  59. package/dist/sessionModelLatch.d.ts +35 -0
  60. package/dist/sessionModelLatch.js +63 -0
  61. package/dist/skillsWireCaps.d.ts +47 -0
  62. package/dist/skillsWireCaps.js +41 -0
  63. package/dist/sseIdleTriage.d.ts +94 -0
  64. package/dist/sseIdleTriage.js +142 -0
  65. package/dist/ultracodeWireCaps.d.ts +90 -0
  66. package/dist/ultracodeWireCaps.js +159 -0
  67. package/dist/webSearchWireCaps.d.ts +54 -0
  68. package/dist/webSearchWireCaps.js +76 -0
  69. package/package.json +2 -2
package/README.md CHANGED
@@ -23,8 +23,8 @@ Renamed from **`@sema-agent/wire-cc-adapter`** (0.1.x, deprecated — see *Migra
23
23
 
24
24
  ## Scope
25
25
 
26
- - **Today (0.2.0)** — the adapter seam plus the first half of the `adapt()` pipeline (detail
27
- below), migrated as-is from `wire-cc-adapter` 0.1.x.
26
+ - **Today (0.5.0)** — the adapter seam, the `adapt()` pipeline, the notification/caps/model
27
+ families, and the adapter kernel (stream driver + downstream projectors).
28
28
  - **Planned** — the shell's remaining shared session logic lands here in batches: the
29
29
  five-layer frame dispatch, the compensation arms, the notification/dedup ledgers, the
30
30
  fleet/panel projections. The TUI then keeps only its Ink rendering and keyboard interaction;
@@ -84,16 +84,69 @@ keys).
84
84
  0.2.0 is the repo/name migration: **no behaviour change**, both guard suites carried over and
85
85
  green (22 + 203 checks).
86
86
 
87
+ 0.3.0 moved in the **dependency-free pure functions and side-channel ledgers** (subagent content,
88
+ engine agent-panel, fleet panel projection, live question store, inline task stats, print
89
+ tool-result frame, caps cache, tool-label store, task-description projection) with 140 new
90
+ behaviour checks.
91
+
92
+ 0.4.0 moved in the **request-shaping gate family and the notification family**:
93
+
94
+ - `notifications.ts` absorbed the whole background-completion subsystem — the process-lifetime
95
+ dedup ledgers (model-notification vs completion-card are **separate key spaces**), the idle
96
+ completion watcher for workflow + background-agent runs, the outstanding-run counter with its
97
+ subscription, the own-run ledger used for frame ownership, the delivery-failure supplement, and
98
+ the `hook_notice` classifier half (ownership fail-closed mirrored from the server).
99
+ - 17 `*WireCaps` projections (attachments, client context, cloud config, fork, images, mcp, model,
100
+ permission, prompt profile, retain-background, rewind, self-orchestration, skills, ultracode,
101
+ web search, agents, plus the wire client factory), the SSE idle triage, the classifier-verdict
102
+ recogniser, the control router, and the model-budget/catalog/latch/effort rules.
103
+ - New `hostEnv.ts`: the single host-environment read port. The moved projections used to default
104
+ their `env` parameter to `process.env`, which throws in a browser; they now default to
105
+ `hostEnv()` (the very same object under Node, `{}` where there is no `process`).
106
+ - 🔴 One host assembly duty: `installNotificationQueuePort()`. Without it, task-notification
107
+ delivery is dropped — `notificationQueuePortMisses()` must stay 0.
108
+
109
+ 0.5.0 moved in the **adapter kernel** — the stream driver and the downstream projectors — and
110
+ grew the host context to carry what a non-Node host must supply:
111
+
112
+ - `AdapterContext` gained five optional ports (**minor, not breaking**): `log`, `probe`, `signal`,
113
+ `setTimer`/`clearTimer`, `coalesceIntervalMs`. Every one is native in a browser
114
+ (`console`, omit, `AbortController.signal`, `setTimeout`, a number) — no polyfill. Absent means
115
+ *that capability is off*, never a fallback: the kernel does not reach for `console`, `setTimeout`
116
+ or a filesystem probe on its own.
117
+ - `adapter/runStream.ts` + `adapter/downstream/*` + the runtime half of `adapter/types.ts` moved in.
118
+ The driver used to drag **1,571 files / 26 Node builtins / 412 react files** into its transitive
119
+ closure through two dynamic imports back into the shell; both are now `ChromeEvent` arms
120
+ (`last_turn_usage`, `plan_review_park`) with their host duty written on the arm. Measured closure
121
+ after the cut: **6 files, zero Node builtins, zero react**.
122
+ - Six stream-driver behaviours landed with it: the turn-open triple-clear (the third clear —
123
+ stale prompt suggestions — plus the fifth sub-flow cut-out), the 1.5 s IDLE-FLUSH race that
124
+ surfaces already-generated content while the model is emitting a long tool argument, manual
125
+ iterator cleanup, the abort branch, and the no-`result` tail leg.
126
+ - The coalescing **cadence** is now a host knob. CC itself runs two values in two hosts (its
127
+ desktop host coalesces single-frame deltas at 16 ms; the 2.1.207 CLI line we track uses 100 ms),
128
+ so the cadence is host render policy while the merge *semantics* stay here, in one place.
129
+
87
130
  Known intentional deltas from the CLI are enumerated in `ADAPTER_DIVERGENCES`.
88
131
 
89
132
  ## Guards
90
133
 
91
134
  ```bash
92
135
  npm install
93
- node scripts/run-client-core-pure-test.mjs # 22 consumer-view checks; no CLI tree needed
94
- node scripts/run-client-core-diff-test.mjs # 203 checks: differential + replay-id + ledger
136
+ node scripts/run-client-core-pure-test.mjs # 429 consumer-view checks (22 + 140 + 208 + 59); no CLI tree needed
137
+ node scripts/run-client-core-portability-test.mjs # 14 checks: kernel closure + browser bundle
138
+ node scripts/run-client-core-diff-test.mjs # 284 checks: differential + replay-id + ledger
95
139
  ```
96
140
 
141
+ Each suite carries a floor that only moves up — a refactor that stops executing a group of
142
+ assertions is a failure, not a quieter pass.
143
+
144
+ The portability guard walks the value-level import closure of the stream driver (asserting zero
145
+ Node builtins, zero react, zero shell debug edge, closure size under its ceiling) and then really
146
+ bundles it with esbuild `--platform=browser`. It carries its own **positive control**: a
147
+ deliberately poisoned file must be reported by the same scanner, otherwise the run exits 9
148
+ (the tool is broken) rather than green.
149
+
97
150
  The differential half needs the CLI tree (the reference bridge lives there). It is located via
98
151
  `SEMA_CLI_ROOT`, else a sibling checkout of the sema CLI source tree (internal reference bridge; not part of the published package); a pinned `SEMA_CLI_ROOT` without
99
152
  `src/sema/upstreamBridge.ts` fails loudly instead of falling back to another tree. With no CLI
package/dist/adapt.d.ts CHANGED
@@ -1,6 +1,31 @@
1
1
  import type { AdapterContext, AdapterOutput, WireToCcAdapter } from './seam.js';
2
- /** cli COALESCER 节流(207 口径;187 时代是 16ms)。宿主无关,时钟从 ctx.now() 取。 */
2
+ /**
3
+ * 活体增量攒批节拍的**默认值**(时钟从 ctx.now() 取;宿主可用 `ctx.coalesceIntervalMs` 覆盖)。
4
+ *
5
+ * 取值依据(两个都是实测,别把其中一个当"唯一真相"):
6
+ * · **100ms** = 我们对标的 CC 2.1.207 CLI 口径(187 时代是 16ms,207 提到 100ms 降重绘频率,
7
+ * 长回答滚动更稳)—— 壳是 207 fork,所以库的默认值取它,壳消费本包时行为零变化;
8
+ * · **16ms** = CC **桌面端**宿主 `makeStreamDeltaCoalescer` 的单帧攒批节拍(设计稿 R1 实测)。
9
+ * ⇒ 结论:**节拍是宿主渲染策略,不是 wire 语义** —— CC 自己两个端就是两个值。web/桌面宿主
10
+ * 想要 16ms 就传 `coalesceIntervalMs: 16`,合并**语义**(思考先于文本、段边界重开块、
11
+ * committed 恒随后)在库里,一份。
12
+ *
13
+ * 🔴 顺带钉一句反面事实(R1 证伪,别再写进任何注释/文档):**"UI 从不见裸 token" 是错的** ——
14
+ * CC 攒批后 flush 的载荷仍是 `stream_event` 增量 delta,CC 的 UI 照样消费增量;
15
+ * 完整 assistant 消息是 SDK 另发的一路。我们这里的 `stream_delta` chrome 臂同构。
16
+ */
3
17
  export declare const FLUSH_INTERVAL_MS = 100;
18
+ /**
19
+ * T40 IDLE-FLUSH 竞速窗(cli upstreamBridge `IDLE_FLUSH_MS` 逐字同值)。
20
+ *
21
+ * 病:模型转入长工具参数生成(大 Write 的 input_json 不经本桥)时 SSE 增量停摆,而 thinking/
22
+ * answerSegment 里**已经生成**的内容还押着陪等(pty 确证:11s 整屏 hash 恒定)。
23
+ * 修:增量停 ≥1.5s 且缓冲非空 ⇒ 先 drainLive()(活体预览语义不变),再提交思考+文本段
24
+ * (段序铁律不破:本来就该在下一张工具卡前 flush,这里只是提前)。
25
+ * 🔴 这是**过渡修**,正解在 core [817](wire 侧给事件);且**需要宿主定时器**:
26
+ * `ctx.setTimer` 缺席 ⇒ 整条竞速不启用(纯等下一帧),与 0.4.0 逐字同行为。
27
+ */
28
+ export declare const IDLE_FLUSH_MS = 1500;
4
29
  /** cli SUBAGENT_TOOL_NAMES / WORKFLOW_TOOL_NAMES 同源(判别资产,别各自重写)。 */
5
30
  export declare const SUBAGENT_TOOL_NAMES: ReadonlySet<string>;
6
31
  export declare const WORKFLOW_TOOL_NAMES: ReadonlySet<string>;
@@ -45,11 +70,13 @@ export declare const ADAPTER_COVERAGE: {
45
70
  readonly frames: readonly ["assistant", "user", "stream_event", "turn_usage", "result", "system", "task_notification", "workflow_complete", "diagnostics", "steering_injected", "workspace_changed", "retry_status", "tool_end_result(仅 response-id 复位 + 开卡台账出栈,不铸 tool_result)"];
46
71
  /** 已落码臂产出的 transcript 消息类目(差分守卫的比对域)。 */
47
72
  readonly transcriptKinds: readonly ["assistant_text", "assistant_thinking", "assistant_tool_use", "user_tool_result_decision", "user_task_notification", "system_passthrough"];
73
+ /** B3(0.5.0)新落码的臂/半场 —— 从 todo 移过来的,别再在 todo 里留同名条目。 */
74
+ readonly b3: readonly ["T38 三清第三清 + T57 第五处断闸:prompt_suggestions(turn 开场作废 + 子流断闸)", "T40 IDLE-FLUSH 1.5s 竞速(需 ctx.setTimer;缺席=不启用)", "T58 手动 iterator 的 finally cleanup(early break/throw 都要关上游生成器)", "T59 abort 半场(ctx.signal;中断后不产终答)", "T60 无 result 收尾腿(泄尾增量 → 清 liveness → 尾思考 → 尾文本段)"];
48
75
  /** 如实留白——写不动/依赖未搬运资产的臂,#52b 起分批接。 */
49
- readonly todo: readonly ["tool_end_result → user tool_result 正常路径(需搬 wireOutputToBody/structuredToToolUseResult/mock 合成器 + TodoWrite/ReportFindings 富卡片,约 600 行;workflow 轮询信封的人话投影已在 workflow.ts 就位,等这条接线)", "tool_end_result 的两个侧产物:Remember → memory_saved 系统消息、task/task-list structured → 面板台账全量同步", "result/turn 末的开卡兜底关闭(同上,依赖合成器)", "task_progress → 面板行绑定(bindTaskCard FIFO/显式父、inline stats、alias、resident 台账、SubagentStart hook、workflow lane 三级门)", "settlePanelTasks 三处 sweep(依赖上面的行台账)", "#117a bg Bash 回执探测(detectEngineBgShellReceipt 文案锚定探测器)", "abort/Esc 半场(AdapterContext signal 位——见 SEAM-GAP-4)", "IDLE_FLUSH 1.5s 竞速(件1 大 Write 静默窗;需 ctx 侧定时器能力)", "macrotask 让渡(cli 在提交前让出宏任务给 Ink;宿主渲染策略,不进库)"];
76
+ readonly todo: readonly ["tool_end_result → user tool_result 正常路径(需搬 wireOutputToBody/structuredToToolUseResult/mock 合成器 + TodoWrite/ReportFindings 富卡片,约 600 行;workflow 轮询信封的人话投影已在 workflow.ts 就位,等这条接线)", "tool_end_result 的两个侧产物:Remember → memory_saved 系统消息、task/task-list structured → 面板台账全量同步", "result/turn 末的开卡兜底关闭(同上,依赖合成器)", "task_progress → 面板行绑定(bindTaskCard FIFO/显式父、inline stats、alias、resident 台账、SubagentStart hook、workflow lane 三级门)", "settlePanelTasks 三处 sweep(依赖上面的行台账)", "#117a bg Bash 回执探测(detectEngineBgShellReceipt 文案锚定探测器)", "abort 半场里依赖行台账的两件:settlePanelTasks 兜底 sweep + 开卡合成器兜底关卡(见上面两条)", "macrotask 让渡(cli 在提交前让出宏任务给 Ink;宿主渲染策略,不进库)"];
50
77
  };
51
78
  /** 本批**已知的、有意的**行为分歧(差分守卫显式登记,绝不当等价) */
52
- export declare const ADAPTER_DIVERGENCES: readonly [string, string, string];
79
+ export declare const ADAPTER_DIVERGENCES: readonly [string, string, string, string];
53
80
  /** 有台账序列化位的适配器(seam 的 WireToCcAdapter 只定了 exportLedger——见 SEAM-GAP-1)。 */
54
81
  export interface WireToCcAdapterWithLedger extends WireToCcAdapter {
55
82
  exportLedger(): AdapterLedgerState & Record<string, unknown>;