@sema-agent/client-core 0.11.4 → 0.11.6
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/dist/index.d.ts +1 -0
- package/dist/index.js +10 -0
- package/dist/seatContract.d.ts +441 -0
- package/dist/seatContract.js +398 -0
- package/package.json +8 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -279,3 +279,13 @@ export * from './compensations.js';
|
|
|
279
279
|
// 去重键**不出第二个名字**:print 侧那份手写算法废除,直接用 `taskNotificationDedupKeyFromWire`。
|
|
280
280
|
// 请求面同批补上可执行判据 `unregisteredRequestKeys`(见 request/taskRequest.ts 文件末)。
|
|
281
281
|
export * from './request/printNotification.js';
|
|
282
|
+
// ── B18 批:desktop/web 座位 IPC 契约单一真源(design/159,2026-07-29)────────────────────────
|
|
283
|
+
// 修的是一条**静默漂移通道**:同一份座位契约此前有两份声明(desktop `shared/localSessions.ts`
|
|
284
|
+
// 15 型生产端 / web `lib/desktop/local-sessions-transport.ts` 9 型 `Seat*` 消费端),两边名字零重合
|
|
285
|
+
// ⇒ 编译器永远不会告诉你它们漂了。实测已漂,其中 `LocalSessionEvent.outcome` 在 web 镜像里整位
|
|
286
|
+
// 缺席 = [1947] 红③ 一直销不掉账的机制原因(宿主发了词,消费端连接词的位都没有)。
|
|
287
|
+
// 🔴 纯类型 + 常量 + 纯谓词,**零 import** —— portability 门的三个 EXPECTED_PACKAGES 一个字不变。
|
|
288
|
+
// 🔴 防再漂钉在文件末:`LocalSessionsApi` 的 verb/store 名由类型结构式派生 → 名字常量(编译期钉)
|
|
289
|
+
// → `LOCAL_SESSIONS_SPEC` 键集(run-seat-contract-keys-test 运行期对账)。加 verb 忘了加 SPEC
|
|
290
|
+
// 的后果不是报错而是 preload 不注册 channel、渲染端读到 undefined(假 affordance 家族)。
|
|
291
|
+
export * from './seatContract.js';
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seatContract — desktop/web **座位 IPC 契约的单一真源**(design/159 B18,2026-07-29)。
|
|
3
|
+
*
|
|
4
|
+
* 搬迁前的形:同一份契约有**两份声明**,而且跨仓名字零重合 ——
|
|
5
|
+
* · `sema-desktop/src/shared/localSessions.ts` = 15 个类型 + 3 个词表常量 + 6 个校验器 + SPEC(生产端)
|
|
6
|
+
* · `sema-web-client/ui/lib/desktop/local-sessions-transport.ts` = 9 个 `Seat*` 本地重声明(消费端)
|
|
7
|
+
* 两边名字不同 ⇒ **编译器永远不会告诉你它们漂了**。实测已经漂了(见下「漂移清单」),其中
|
|
8
|
+
* `LocalSessionEvent.outcome` 那一条是真 bug:宿主发了词、消费端的镜像里根本没有这个位,
|
|
9
|
+
* 于是「拒绝 / TTL 到点 / 人点了允许」在屏上长得一模一样 —— 正是 localSessions 自己在
|
|
10
|
+
* 「接缝记账」里写下的第 1 条,它一直没被销账的原因就是没有任何机制会让它红。
|
|
11
|
+
*
|
|
12
|
+
* 落点为什么是本包:desktop 与 web 都已经依赖 `@sema-agent/client-core`(0.11.5),而本文件是
|
|
13
|
+
* **纯类型 + 常量 + 纯谓词**,零 import、零 Node 内建 ⇒ 不动本包的可移植闭包(portability 门的
|
|
14
|
+
* `EXPECTED_PACKAGES_INDEX` 一个字不变)。
|
|
15
|
+
*
|
|
16
|
+
* ── 搬迁时按「真源为准」收敛的漂移(逐条,web 侧镜像 → 本文件)────────────────────────────
|
|
17
|
+
* 🔴 D1 `LocalSessionEvent.outcome` —— web 镜像整位缺席 ⇒ `tool_permission_resolved` 只会清面,
|
|
18
|
+
* 不会告诉用户为什么工具没跑。**真 bug**,本批只做「位补回来」;把词渲成可见痕迹是渲染面的活。
|
|
19
|
+
* D2 `SendMessageRequest.permissionMode` —— web 镜像是裸 `string`,真源是闭集 `PermissionModeIntent`,
|
|
20
|
+
* 而宿主入站门 `requireOptionalPermissionMode` 是**会抛的闭集门**。今日两边词表逐字相等
|
|
21
|
+
* (web `ComposerMode` 五档 ≡ `PERMISSION_MODE_INTENTS` 五档,已核),所以是**潜伏**不是现症:
|
|
22
|
+
* ComposerMode 哪天加一档,裸 string 一路放行到宿主门口才抛。收敛成闭集后当天编译红。
|
|
23
|
+
* D3 `AttachmentUploadReceipt.sha256` / `ToolPermissionRequest.createdAt` / `StartSessionOptions.cwd`
|
|
24
|
+
* / `.excludeTools` / `LocalSessionRecord.queuedMessages`·`model`·`engineSessionId` ——
|
|
25
|
+
* web 镜像缺位。都是「没接线」不是「接错线」(web 侧今日无消费点,已核),收敛后位在、待接。
|
|
26
|
+
* D4 `LocalSessionEvent.request` —— 真源有这个位,**宿主从不发**(session-host 零处写 `request:`);
|
|
27
|
+
* web 镜像没有它反而与运行时事实一致。真源保留该位(CC `fQe` 的 form 位),记在这里免得
|
|
28
|
+
* 下一棒把「web 没有」当成漏。
|
|
29
|
+
* D5 `EipcStoreClient.getStateSync` web 侧是 optional、真源是 required;`SeatSessionDirectoryRow.createdAt`
|
|
30
|
+
* web 侧 optional、真源 required。两条都是「更弱」方向,收敛到真源即可(宿主校验器
|
|
31
|
+
* `isLocalSessionRecord` 本来就要求 createdAt 在场,运行时保证一直成立)。
|
|
32
|
+
* · web 侧**没有**镜像、因而至今拿不到的面:队列三动词 / setFocusedSession / setModel /
|
|
33
|
+
* focusedSessionState / settingsState / `CHROME_EVENT_KINDS` / `ATTACHMENT_IDS_PER_TASK_CAP`。
|
|
34
|
+
* 本文件导出后它们对 web 首次可见(接不接线是渲染面的决定)。
|
|
35
|
+
*
|
|
36
|
+
* ── 沿革(以下正文自 sema-desktop/src/shared/localSessions.ts 逐字迁入)──────────────────────
|
|
37
|
+
* LocalSessions — the desktop host's session service contract, FORM-ported from the CC desktop
|
|
38
|
+
* app's `claude.web / LocalSessions` eipc interface (212 methods there; FIRST BATCH here = the four
|
|
39
|
+
* families clay scoped: session lifecycle / event subscription / interrupt / approvals).
|
|
40
|
+
*
|
|
41
|
+
* Naming: CC ns `claude.web` → `sema.web` (brand table). Method names kept verbatim where the CC
|
|
42
|
+
* method exists (`start`/`stop`/`interrupt`/`sendMessage`/`onEvent`/`onToolPermissionRequest`/
|
|
43
|
+
* `respondToToolPermission` are all real CC LocalSessions methods — see the 854-channel census).
|
|
44
|
+
*
|
|
45
|
+
* Event payload contract: ported in FORM from CC's `onEvent` runtime validator `fQe`
|
|
46
|
+
* (unpack `.vite/build/index.chunk-CnWKsyE_.js:369773`). The load-bearing property we keep
|
|
47
|
+
* byte-faithful ([1832] axiom 2, independently proven by CC's own code): on an otherwise
|
|
48
|
+
* fully-schema'd IPC surface, the `message`/`messages` fields (= CC session-vocabulary SDKMessage
|
|
49
|
+
* bodies, our transcript plane) are UNVALIDATED passthrough positions, while every other field is a
|
|
50
|
+
* neutral typed position. Our implementation体 differs (sema wire via @sema-agent/sdk +
|
|
51
|
+
* @sema-agent/client-core), the contract shape does not.
|
|
52
|
+
*/
|
|
53
|
+
export type EipcMethodKind = "invoke" | "event";
|
|
54
|
+
export interface EipcMethodSpec {
|
|
55
|
+
kind: EipcMethodKind;
|
|
56
|
+
/** invoke: validates the impl's RESULT before it crosses back to the renderer (CC's outbound
|
|
57
|
+
* schema gate — `Result from method "<m>" in interface "<S>" failed to pass validation`).
|
|
58
|
+
* event: validates the PAYLOAD before `webContents.send` (CC's dispatcher-side validator, the
|
|
59
|
+
* `fQe` position for `LocalSessions.onEvent`). Absent = any result/payload passes (CC has
|
|
60
|
+
* `void`-returning methods with trivially-true validators). */
|
|
61
|
+
validate?: (value: unknown) => boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface EipcStoreSpec {
|
|
64
|
+
/** Validates the STATE payload both on read replies and on update pushes (fail-closed like the
|
|
65
|
+
* method gates). Absent = any state passes. */
|
|
66
|
+
validate?: (state: unknown) => boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface EipcServiceSpec {
|
|
69
|
+
ns: string;
|
|
70
|
+
service: string;
|
|
71
|
+
methods: Record<string, EipcMethodSpec>;
|
|
72
|
+
/** `$store$` reactive states owned by this service (CC codegen form; see eipcStoreChannel). */
|
|
73
|
+
stores?: Record<string, EipcStoreSpec>;
|
|
74
|
+
}
|
|
75
|
+
/** Neutral session record (CC's `session` position is schema-gated by `aM`; ours is this shape). */
|
|
76
|
+
export interface LocalSessionRecord {
|
|
77
|
+
/** Host-minted stable session id — the id every event carries (CC form: sessionId on every event). */
|
|
78
|
+
sessionId: string;
|
|
79
|
+
/** Engine (service)-minted session id, known after the first reply; absent before it. */
|
|
80
|
+
engineSessionId?: string;
|
|
81
|
+
model?: string;
|
|
82
|
+
title?: string;
|
|
83
|
+
isRunning: boolean;
|
|
84
|
+
createdAt: string;
|
|
85
|
+
lastActivityAt?: string;
|
|
86
|
+
/** Host-side deferred queue (CC `deferredSends` seat, in submit order — drives the queued-message
|
|
87
|
+
* bar). Present (possibly empty) whenever the host projects the record during a running turn. */
|
|
88
|
+
queuedMessages?: Array<{
|
|
89
|
+
uuid: string;
|
|
90
|
+
text: string;
|
|
91
|
+
}>;
|
|
92
|
+
}
|
|
93
|
+
/** HITL request row (CC's `request` position is schema-gated by `S1`; ours is this shape, projected
|
|
94
|
+
* from the sema wire's PendingCheckpoint — see session-host). */
|
|
95
|
+
export interface ToolPermissionRequest {
|
|
96
|
+
/** Stable request key — echo back on respondToToolPermission. FOUR id domains, prefix-tagged
|
|
97
|
+
* (the prefix is what routes the decision back to the right wire verb — see session-host):
|
|
98
|
+
* `live:<approvalId>` = LIVE in-band tool-approval face (frame rides the token
|
|
99
|
+
* stream; unanswered → engine fail-CLOSED deny at its TTL);
|
|
100
|
+
* `durable:<engineSessionId>:<callId>` = the durable checkpoint class (approvals inbox);
|
|
101
|
+
* `question:<questionId>` = LIVE `AskUserQuestion` (the agent's own structured ask;
|
|
102
|
+
* unanswered → engine fail-OPEN: the model takes the
|
|
103
|
+
* headless default `{answers:[]}` at the 5-min TTL, which is
|
|
104
|
+
* why leaving this family unrendered is silent, [1947] 红④);
|
|
105
|
+
* `elicit:<elicitationId>` = LIVE inbound-MCP elicitation (a server asks the user for
|
|
106
|
+
* form input mid-tool-call).
|
|
107
|
+
* The three LIVE domains are same-replica + non-durable: a late/duplicate decision 404s, which the
|
|
108
|
+
* host treats as "already released" (dismiss), never as a retryable error. */
|
|
109
|
+
requestId: string;
|
|
110
|
+
sessionId: string;
|
|
111
|
+
/** For the two ask families this is the CC tool vocabulary name the renderer branches on:
|
|
112
|
+
* `AskUserQuestion` (question domain) / `McpElicitation` (elicit domain). */
|
|
113
|
+
toolName?: string | null;
|
|
114
|
+
/** The ENGINE's tool-call id (`call_…`) — the SAME id the assistant message's `tool_use` block
|
|
115
|
+
* carries, so a renderer can key the approval onto the tool card that actually raised it.
|
|
116
|
+
* Present on tool-approval rows from server ≥1.307; `null` when the wire did not offer one
|
|
117
|
+
* (old server, or the ask families, which have no tool call of their own). NEVER synthesized. */
|
|
118
|
+
toolCallId?: string | null;
|
|
119
|
+
/** UNTRUSTED, service-redacted tool args / question payload (render-only, never re-fed). */
|
|
120
|
+
input?: unknown;
|
|
121
|
+
/** UNTRUSTED, service-redacted engine ask text (live face only) — display only. */
|
|
122
|
+
message?: string;
|
|
123
|
+
/** design/80 D-1 TOCTOU binding pair (durable face only) — echo VERBATIM into the decision.
|
|
124
|
+
* 🔴 出站**只读**位:回程的 verbatim 回显由宿主自己的登记表做(session-host 的
|
|
125
|
+
* `row.boundCallId/boundInputHash`),`ToolPermissionDecision` 因此没有对应席位 —— 渲染端
|
|
126
|
+
* 拿到它只为展示,绝不需要(也不该)自己回传。 */
|
|
127
|
+
boundCallId?: string;
|
|
128
|
+
boundInputHash?: string;
|
|
129
|
+
createdAt?: number;
|
|
130
|
+
}
|
|
131
|
+
export interface LocalSessionEvent {
|
|
132
|
+
type: string;
|
|
133
|
+
sessionId: string;
|
|
134
|
+
/** 🔴 transcript-plane passthrough (SDKMessage body) — deliberately UNVALIDATED (fQe posture). */
|
|
135
|
+
message?: unknown;
|
|
136
|
+
/** 🔴 transcript-plane passthrough batch — array-checked only, elements unvalidated (fQe posture). */
|
|
137
|
+
messages?: unknown[];
|
|
138
|
+
error?: string;
|
|
139
|
+
errorCategory?: string;
|
|
140
|
+
code?: number;
|
|
141
|
+
/** CC `fQe` 的 form 位。🔴 **本宿主从不发这个位**(session-host 零处写 `request:`;HITL 行走
|
|
142
|
+
* 独立的 `onToolPermissionRequest` 通道)—— 位保留是为了与 CC 的 fQe 逐位同形,消费端不该
|
|
143
|
+
* 为它写分支(见文件头 D4)。 */
|
|
144
|
+
request?: ToolPermissionRequest;
|
|
145
|
+
data?: string;
|
|
146
|
+
sources?: string[];
|
|
147
|
+
permissionMode?: string;
|
|
148
|
+
session?: LocalSessionRecord;
|
|
149
|
+
userMessageUuid?: string;
|
|
150
|
+
hasPreClearSession?: boolean;
|
|
151
|
+
/** On `tool_permission_resolved`: which request settled (so a native notification for it can be
|
|
152
|
+
* dismissed — CC `closePermissionNotification(requestId)`). */
|
|
153
|
+
requestId?: string;
|
|
154
|
+
/**
|
|
155
|
+
* On `tool_permission_resolved`: HOW it settled ([1947] 红③). Without this the renderer only ever
|
|
156
|
+
* learned that a card should disappear — a TTL expiry, a disconnect-settle and a human's own
|
|
157
|
+
* "allow" were indistinguishable, so a REFUSAL rendered as a card silently vanishing and the user
|
|
158
|
+
* was never told why the tool did not run.
|
|
159
|
+
*
|
|
160
|
+
* Words currently emitted (see HITL_RESOLUTION_OUTCOMES): the tool-approval wire's own
|
|
161
|
+
* `allowed`/`denied`/`expired`, the question wire's `answered`/`unanswered`, the elicitation
|
|
162
|
+
* wire's `accept`/`decline`/`cancel`. ABSENT is meaningful and honest: the durable inbox sweep
|
|
163
|
+
* learns only that a row is gone, never why.
|
|
164
|
+
*
|
|
165
|
+
* 🔴 Validated as a plain string, NOT against a closed set, deliberately: the words originate on
|
|
166
|
+
* the wire, and a fail-closed gate keyed to today's vocabulary would DROP THE WHOLE EVENT (card
|
|
167
|
+
* stuck on screen forever) the day the server adds an outcome word. Renderers branch on the words
|
|
168
|
+
* they know and treat an unknown one as "settled, reason unknown".
|
|
169
|
+
*/
|
|
170
|
+
outcome?: string;
|
|
171
|
+
/** On `chrome_event`: one client-core ChromeEvent arm (the NEUTRAL typed chrome vocabulary —
|
|
172
|
+
* [1832] axiom 2's non-transcript half). Only the renderer-wired arm kinds cross the wire
|
|
173
|
+
* (see CHROME_EVENT_KINDS); the outbound gate checks kind membership + the laneProof discipline. */
|
|
174
|
+
chrome?: {
|
|
175
|
+
kind: string;
|
|
176
|
+
laneProof?: unknown;
|
|
177
|
+
[k: string]: unknown;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The resolution words the host currently puts on `tool_permission_resolved.outcome` ([1947] 红③).
|
|
182
|
+
* DOCUMENTARY + test anchor only — the gate does NOT enforce membership (see the field's doc: a
|
|
183
|
+
* closed set would fail-close the whole event on the day the wire grows a word). Grouped by family:
|
|
184
|
+
* - tool approval (wire `ToolApprovalFrame.outcome`, + our own settle sweep): allowed/denied/expired
|
|
185
|
+
* - question (wire `QuestionFrame.outcome`): answered/unanswered
|
|
186
|
+
* - elicitation (wire `ElicitationFrame.action`): accept/decline/cancel
|
|
187
|
+
*/
|
|
188
|
+
export declare const HITL_RESOLUTION_OUTCOMES: readonly string[];
|
|
189
|
+
/**
|
|
190
|
+
* 接缝记账 — what the HOST now guarantees vs what a RENDERER still owes ([1947] 红③/红④ split).
|
|
191
|
+
*
|
|
192
|
+
* The host half is done and pinned by desktop's `scripts/run-hitl-frame-transit-fence-test.mjs`:
|
|
193
|
+
* every live ask family reaches `onToolPermissionRequest` with its own requestId domain, every
|
|
194
|
+
* resolution reaches `onEvent` with an `outcome`, and every decision routes to the right wire verb.
|
|
195
|
+
*
|
|
196
|
+
* The renderer half is where these become VISIBLE, and until it lands the data is present but
|
|
197
|
+
* unread (stating it plainly so nobody reads "the host emits it" as "the user sees it"):
|
|
198
|
+
* 1. `tool_permission_resolved.outcome` — an `expired` / `denied` / `unanswered` resolution must
|
|
199
|
+
* leave a visible refusal trace. Today the seat transport clears the surface and drops the
|
|
200
|
+
* word, so a refusal is still indistinguishable from an approval on screen.
|
|
201
|
+
* 🔴 B18(2026-07-29)查明这条一直不销账的**机制原因**:web 侧的镜像类型里连 `outcome` 这个
|
|
202
|
+
* 位都没有,所以「没读」在两边都编译得过。本批把位收进真源 = 让它至少可见于类型面。
|
|
203
|
+
* 2. `toolCallId` — now real (not null), so an approval can be anchored to the tool card that
|
|
204
|
+
* raised it instead of "the most recent tool_start" (an anchor that lands on the wrong card
|
|
205
|
+
* when a prior tool is still running).
|
|
206
|
+
* 3. `question:` rows need NO new renderer code: they arrive as `toolName: "AskUserQuestion"` with
|
|
207
|
+
* `input.questions`, which is exactly what the seat's ask-user-question surface already reads,
|
|
208
|
+
* and its answer envelope is exactly what this host expects back.
|
|
209
|
+
* 4. 座位 wire 补齐批 (2026-07-28) closed two entries that used to live here as "如实,未做":
|
|
210
|
+
* `permissionMode` now has a seat on `sendMessage` (was: the composer's Plan badge never
|
|
211
|
+
* crossed and the turn ran with the engine default), and the attachment BYTE channel exists
|
|
212
|
+
* (`uploadAttachment` + `sendMessage.attachmentIds`) — so a seat renderer no longer has to
|
|
213
|
+
* simulate "attachment ready" for a file nothing received. What is still NOT here, stated
|
|
214
|
+
* plainly: plan REVISE feedback text (the decide face has no `reason` seat, so revise maps to
|
|
215
|
+
* a bare deny) and a per-session `permissionMode` write (the wire's is per-TURN only).
|
|
216
|
+
* 5. `elicit:` rows have no dedicated surface yet: they fall through to the generic approval card,
|
|
217
|
+
* which shows the MCP server's prompt and can accept/decline but CANNOT collect form values.
|
|
218
|
+
* A real form surface (built from `input.requestedSchema`) is the renderer's remaining piece;
|
|
219
|
+
* until then an approve carries no content — the host never invents form values. That generic
|
|
220
|
+
* card also offers "Always allow (this session)", which this domain has no concept of: the host
|
|
221
|
+
* ignores `remember` here rather than pretend, so the renderer should hide that control for
|
|
222
|
+
* `elicit:` rows (a button that changes nothing is the false-affordance family again).
|
|
223
|
+
*/
|
|
224
|
+
/** Chrome arms wired to the renderer position (batch 4); other arms stay host-side on the ring. */
|
|
225
|
+
export declare const CHROME_EVENT_KINDS: readonly string[];
|
|
226
|
+
export interface StartSessionOptions {
|
|
227
|
+
model?: string;
|
|
228
|
+
title?: string;
|
|
229
|
+
/** Working directory for the session's hand tools (TaskRequest.cwd). Default = a per-session dir
|
|
230
|
+
* under the host's workspace base. A UI that picks a project directory passes it here — CC desktop
|
|
231
|
+
* form (session.cwd / worktreePath). Honored only on the local host-adapter engine. */
|
|
232
|
+
cwd?: string;
|
|
233
|
+
/** Wire TRUE-UNMOUNT list (TaskRequest.excludeTools, server ≥1.221): named tools' schemas never
|
|
234
|
+
* reach the model for ANY turn of this session. Tighten-only. */
|
|
235
|
+
excludeTools?: string[];
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* PERMISSION MODE INTENT — the RAW mode the composer is showing, carried verbatim to the engine as
|
|
239
|
+
* `TaskRequest.permissionMode` (SDK types.d.ts:259; the SERVICE interprets it, axis-aware and
|
|
240
|
+
* tighten-only: `plan` ⇒ mount `present_plan` + read-only hands = CC EnterPlanMode).
|
|
241
|
+
*
|
|
242
|
+
* 🔴 Why this seat exists at all (红批注 web#1): without it, a user who switched the composer to
|
|
243
|
+
* Plan mode inside the desktop seat got a turn that ran with the engine's DEFAULT mode — the badge
|
|
244
|
+
* said "plan", the engine was never told, and the agent happily edited files. A mode the UI shows
|
|
245
|
+
* but never sends is the false-affordance family with teeth.
|
|
246
|
+
*
|
|
247
|
+
* The vocabulary is the wire's own (identical to the web client's `ComposerMode`), so the seat
|
|
248
|
+
* passes the word through unchanged rather than re-deriving core fields locally — one interpretation
|
|
249
|
+
* across TUI + web + desktop. 🔴 B18 起 web 侧的镜像位也是这个闭集(此前是裸 `string`):
|
|
250
|
+
* ComposerMode 加一档而宿主闭集门不认的那天,红在编译期而不是用户提交那一刻。
|
|
251
|
+
*/
|
|
252
|
+
export type PermissionModeIntent = "default" | "plan" | "acceptEdits" | "bypassPermissions" | "auto";
|
|
253
|
+
/** The closed set the inbound gate checks. CLOSED deliberately, unlike `outcome` above: this word
|
|
254
|
+
* ORIGINATES in our own renderer and goes OUT to a wire that 400s on anything else, so an unknown
|
|
255
|
+
* value is a local bug we want reported at the door — not an unknown future wire word we must
|
|
256
|
+
* tolerate. (The direction of travel is what decides open vs closed, not the field's shape.) */
|
|
257
|
+
export declare const PERMISSION_MODE_INTENTS: readonly PermissionModeIntent[];
|
|
258
|
+
/** Per-task attachment cap — the server's own limit (`attachmentIds` > 16 ⇒ 400). Gated here so the
|
|
259
|
+
* seat gets a precise local error instead of a wire 400 halfway through a turn. */
|
|
260
|
+
export declare const ATTACHMENT_IDS_PER_TASK_CAP = 16;
|
|
261
|
+
export interface SendMessageRequest {
|
|
262
|
+
sessionId: string;
|
|
263
|
+
text: string;
|
|
264
|
+
model?: string;
|
|
265
|
+
/** Client-supplied echo key for the user message (CC form: userMessageUuid); minted if absent. */
|
|
266
|
+
userMessageUuid?: string;
|
|
267
|
+
/** Composer permission mode for THIS turn → `TaskRequest.permissionMode`. Omit/`default` ⇒ no stamp. */
|
|
268
|
+
permissionMode?: PermissionModeIntent;
|
|
269
|
+
/** Pre-uploaded attachment handles (`uploadAttachment` receipts) → `TaskRequest.attachmentIds`.
|
|
270
|
+
* Bytes never ride this call: they went up once through the dedicated verb and the engine
|
|
271
|
+
* materializes them into the run's `attachments/` dir. */
|
|
272
|
+
attachmentIds?: string[];
|
|
273
|
+
}
|
|
274
|
+
/** `uploadAttachment` receipt — the SDK's `AttachmentInfo` verbatim (server POST /v1/attachments 201).
|
|
275
|
+
* `name` is the SERVER's sanitized basename, not the local filename: it is the name the engine
|
|
276
|
+
* materializes, so the renderer must display THAT one. */
|
|
277
|
+
export interface AttachmentUploadReceipt {
|
|
278
|
+
id: string;
|
|
279
|
+
name: string;
|
|
280
|
+
mime: string;
|
|
281
|
+
sha256: string;
|
|
282
|
+
sizeBytes: number;
|
|
283
|
+
}
|
|
284
|
+
/** One row of the seat's model catalog (`GET /v1/models`, non-secret projection: the service already
|
|
285
|
+
* strips baseUrl/apiKey/headers). `contextWindow`/`maxOutputTokens` are soft-degrade extras. */
|
|
286
|
+
export interface SeatModelInfo {
|
|
287
|
+
id: string;
|
|
288
|
+
name?: string;
|
|
289
|
+
provider?: string;
|
|
290
|
+
contextWindow?: number;
|
|
291
|
+
maxOutputTokens?: number;
|
|
292
|
+
}
|
|
293
|
+
/** `listModels` envelope. `defaultId` = the deployment's resolved default model id (display only —
|
|
294
|
+
* the per-turn choice always rides `sendMessage({model})`). */
|
|
295
|
+
export interface SeatModelCatalog {
|
|
296
|
+
models: SeatModelInfo[];
|
|
297
|
+
defaultId?: string;
|
|
298
|
+
}
|
|
299
|
+
export interface SendMessageAck {
|
|
300
|
+
sessionId: string;
|
|
301
|
+
userMessageUuid: string;
|
|
302
|
+
/** true = a turn was running, the message entered the deferred queue (CC sendMessage semantics)
|
|
303
|
+
* instead of starting a turn; absent/false = the turn started immediately. */
|
|
304
|
+
queued?: boolean;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* One decision, four wire verbs — the requestId's domain picks which (session-host routes it):
|
|
308
|
+
* `live:` → POST /v1/tool-approvals/:id/respond (allow | allow_session | deny)
|
|
309
|
+
* `durable:` → POST /v1/approvals/:sessionId/decide (+ the TOCTOU binding pair, echoed verbatim)
|
|
310
|
+
* `question:` → POST /v1/questions/:id/respond (approve ⇒ `answer`; deny ⇒ `{answers:[]}`,
|
|
311
|
+
* the wire's own NO_HUMAN — releases the ask NOW instead of hanging it to its TTL)
|
|
312
|
+
* `elicit:` → POST /v1/elicitations/:id/respond (approve ⇒ accept + `updatedInput` as the
|
|
313
|
+
* form content; deny ⇒ decline)
|
|
314
|
+
*/
|
|
315
|
+
export interface ToolPermissionDecision {
|
|
316
|
+
sessionId: string;
|
|
317
|
+
requestId: string;
|
|
318
|
+
decision: "approve" | "deny";
|
|
319
|
+
/** AskUserQuestion answer (approve only) — `{answers:[{header, selected: string[], note?}]}`,
|
|
320
|
+
* keyed by the question's HEADER, `selected` echoing the EXACT option labels the user saw (core
|
|
321
|
+
* fences `selected ⊆ options`). Malformed shapes are refused at the door, never coerced: a
|
|
322
|
+
* silently emptied answer is the user's choice being thrown away without anyone noticing. */
|
|
323
|
+
answer?: unknown;
|
|
324
|
+
/** Approve-with-edit rewritten args (design/37 last-wins). On the `elicit:` domain this position
|
|
325
|
+
* carries the submitted FORM CONTENT — a flat record of `string|number|boolean|string[]`
|
|
326
|
+
* (the only shape the wire accepts; anything else is refused, not filtered). */
|
|
327
|
+
updatedInput?: unknown;
|
|
328
|
+
/** "Don't ask again this session" (approve only). */
|
|
329
|
+
remember?: "session";
|
|
330
|
+
}
|
|
331
|
+
/** Renderer-side `$store$` client (CC form: read + subscribe; `update` channel is the push). */
|
|
332
|
+
export interface EipcStoreClient<T> {
|
|
333
|
+
getState(): Promise<T>;
|
|
334
|
+
getStateSync(): T;
|
|
335
|
+
onStateChange(cb: (state: T) => void): () => void;
|
|
336
|
+
}
|
|
337
|
+
export interface SettingsState {
|
|
338
|
+
defaultModel: string | null;
|
|
339
|
+
engineVersion?: string;
|
|
340
|
+
dataRoot?: string;
|
|
341
|
+
}
|
|
342
|
+
export interface SessionSearchResult {
|
|
343
|
+
sessionId: string;
|
|
344
|
+
title?: string;
|
|
345
|
+
matches: Array<{
|
|
346
|
+
snippet: string;
|
|
347
|
+
}>;
|
|
348
|
+
}
|
|
349
|
+
/** Renderer-facing surface exposed by the mainView preload as `sema.web.LocalSessions`. */
|
|
350
|
+
export interface LocalSessionsApi {
|
|
351
|
+
start(opts?: StartSessionOptions): Promise<LocalSessionRecord>;
|
|
352
|
+
sendMessage(req: SendMessageRequest): Promise<SendMessageAck>;
|
|
353
|
+
interrupt(req: {
|
|
354
|
+
sessionId: string;
|
|
355
|
+
}): Promise<{
|
|
356
|
+
interrupted: boolean;
|
|
357
|
+
}>;
|
|
358
|
+
stop(req: {
|
|
359
|
+
sessionId: string;
|
|
360
|
+
}): Promise<{
|
|
361
|
+
stopped: boolean;
|
|
362
|
+
}>;
|
|
363
|
+
respondToToolPermission(req: ToolPermissionDecision): Promise<{
|
|
364
|
+
ok: boolean;
|
|
365
|
+
}>;
|
|
366
|
+
/** Queue family (CC LocalSessionManager semantics; booleans, false = too-late/no-op form). */
|
|
367
|
+
cancelQueuedMessage(sessionId: string, userMessageUuid: string): Promise<boolean>;
|
|
368
|
+
/** CC signature: (sessionId, uuid, TARGET uuid) — position the message relative to the target
|
|
369
|
+
* (after it when moving down, before it when moving up); NOT an index. */
|
|
370
|
+
reorderQueuedMessage(sessionId: string, userMessageUuid: string, targetUserMessageUuid: string): Promise<boolean>;
|
|
371
|
+
promoteQueuedMessage(sessionId: string, userMessageUuid: string): Promise<boolean>;
|
|
372
|
+
/** CC census verbs (batch 4). setFocusedSession(null) clears focus. */
|
|
373
|
+
setFocusedSession(sessionId: string | null): Promise<{
|
|
374
|
+
ok: boolean;
|
|
375
|
+
}>;
|
|
376
|
+
setModel(sessionId: string, model: string): Promise<boolean>;
|
|
377
|
+
getTranscript(sessionId: string): Promise<{
|
|
378
|
+
sessionId: string;
|
|
379
|
+
messages: unknown[];
|
|
380
|
+
}>;
|
|
381
|
+
searchSessions(query: string): Promise<{
|
|
382
|
+
results: SessionSearchResult[];
|
|
383
|
+
}>;
|
|
384
|
+
/** Attachment BYTE channel (红批注 web#1 的另一半). Upload first, then reference the receipt id
|
|
385
|
+
* from `sendMessage({attachmentIds})`. Rejects (413/415/501 → thrown typed error) surface to the
|
|
386
|
+
* renderer as-is: a shelf row that says "ready" for a file the engine never received is the
|
|
387
|
+
* same lie as a mode badge that never crossed the wire. */
|
|
388
|
+
uploadAttachment(req: {
|
|
389
|
+
name: string;
|
|
390
|
+
mimeType?: string;
|
|
391
|
+
bytes: Uint8Array;
|
|
392
|
+
}): Promise<AttachmentUploadReceipt>;
|
|
393
|
+
/** Read-only model catalog (engine `GET /v1/models`). Empty `models` = the deployment offers no
|
|
394
|
+
* catalog; the renderer must degrade honestly rather than fall back to a fixture list. */
|
|
395
|
+
listModels(): Promise<SeatModelCatalog>;
|
|
396
|
+
onEvent(cb: (ev: LocalSessionEvent) => void): () => void;
|
|
397
|
+
onToolPermissionRequest(cb: (req: ToolPermissionRequest) => void): () => void;
|
|
398
|
+
/** `$store$` reactive states (read + subscribe; writes go through the verbs above). */
|
|
399
|
+
sessionsStateStore: EipcStoreClient<{
|
|
400
|
+
sessions: LocalSessionRecord[];
|
|
401
|
+
}>;
|
|
402
|
+
focusedSessionStateStore: EipcStoreClient<{
|
|
403
|
+
sessionId: string | null;
|
|
404
|
+
}>;
|
|
405
|
+
settingsStateStore: EipcStoreClient<SettingsState>;
|
|
406
|
+
}
|
|
407
|
+
export declare function isLocalSessionRecord(s: unknown): s is LocalSessionRecord;
|
|
408
|
+
export declare function isToolPermissionRequest(r: unknown): r is ToolPermissionRequest;
|
|
409
|
+
/**
|
|
410
|
+
* onEvent payload validator — line-for-line FORM port of CC's `fQe`
|
|
411
|
+
* (`.vite/build/index.chunk-CnWKsyE_.js:369773`). Field-by-field mapping:
|
|
412
|
+
* - `type`/`sessionId`: required strings (same);
|
|
413
|
+
* - `message`: CC's minified source reads `typeof e.message<"u"` inside a comma expression whose
|
|
414
|
+
* value is discarded — i.e. NO validation, a deliberate transcript-plane passthrough. Same here.
|
|
415
|
+
* - `messages`: array-checked, elements `every(t=>!0)` (constant true) — array shape only. Same here.
|
|
416
|
+
* - `error`/`errorCategory`: optional strings (same); `code`: optional number (same);
|
|
417
|
+
* - `request`: CC gates with `S1` (ToolPermissionRequest schema) → our isToolPermissionRequest;
|
|
418
|
+
* - `session`: CC gates with `aM` (SessionRecord schema) → our isLocalSessionRecord;
|
|
419
|
+
* - `data`: optional string / `sources`: optional string[] / `permissionMode`: optional string /
|
|
420
|
+
* `userMessageUuid`: optional string / `hasPreClearSession`: optional boolean (same);
|
|
421
|
+
* - CC fields we do not emit in this batch (`tccFolderKind`/`initializationStatus`/`fsFile`/
|
|
422
|
+
* `localMcpServers`/`refusalFallbackPrompt`) are not carried — their positions return when the
|
|
423
|
+
* corresponding service families are ported.
|
|
424
|
+
*/
|
|
425
|
+
export declare function isLocalSessionEvent(v: unknown): v is LocalSessionEvent;
|
|
426
|
+
export declare function isAttachmentUploadReceipt(v: unknown): v is AttachmentUploadReceipt;
|
|
427
|
+
export declare function isSeatModelCatalog(v: unknown): v is SeatModelCatalog;
|
|
428
|
+
export declare function isSendMessageAck(v: unknown): v is SendMessageAck;
|
|
429
|
+
export declare const LOCAL_SESSIONS_SPEC: EipcServiceSpec;
|
|
430
|
+
/** verb 名清单 = `LOCAL_SESSIONS_SPEC.methods` 应有的键集(逐元素相等,门里断言)。 */
|
|
431
|
+
export declare const SEAT_METHOD_NAMES: readonly ["start", "sendMessage", "interrupt", "stop", "respondToToolPermission", "cancelQueuedMessage", "reorderQueuedMessage", "promoteQueuedMessage", "setFocusedSession", "setModel", "getTranscript", "searchSessions", "uploadAttachment", "listModels", "onEvent", "onToolPermissionRequest"];
|
|
432
|
+
/** `$store$` 属性名清单;SPEC 的 store 键 + `"Store"` 必须逐条等于这里的名字(门里断言)。 */
|
|
433
|
+
export declare const SEAT_STORE_PROPS: readonly ["sessionsStateStore", "focusedSessionStateStore", "settingsStateStore"];
|
|
434
|
+
/** 事件式(main→renderer push)的 verb —— SPEC 里 `kind: "event"` 的那一撮,门里逐元素对账。 */
|
|
435
|
+
export declare const SEAT_EVENT_METHOD_NAMES: readonly ["onEvent", "onToolPermissionRequest"];
|
|
436
|
+
export declare const LOCAL_SESSION_EVENT_KEYS: readonly ["type", "sessionId", "message", "messages", "error", "errorCategory", "code", "request", "data", "sources", "permissionMode", "session", "userMessageUuid", "hasPreClearSession", "requestId", "outcome", "chrome"];
|
|
437
|
+
export declare const TOOL_PERMISSION_REQUEST_KEYS: readonly ["requestId", "sessionId", "toolName", "toolCallId", "input", "message", "boundCallId", "boundInputHash", "createdAt"];
|
|
438
|
+
export declare const LOCAL_SESSION_RECORD_KEYS: readonly ["sessionId", "engineSessionId", "model", "title", "isRunning", "createdAt", "lastActivityAt", "queuedMessages"];
|
|
439
|
+
export declare const SEND_MESSAGE_REQUEST_KEYS: readonly ["sessionId", "text", "model", "userMessageUuid", "permissionMode", "attachmentIds"];
|
|
440
|
+
export declare const TOOL_PERMISSION_DECISION_KEYS: readonly ["sessionId", "requestId", "decision", "answer", "updatedInput", "remember"];
|
|
441
|
+
export declare const START_SESSION_OPTION_KEYS: readonly ["model", "title", "cwd", "excludeTools"];
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seatContract — desktop/web **座位 IPC 契约的单一真源**(design/159 B18,2026-07-29)。
|
|
3
|
+
*
|
|
4
|
+
* 搬迁前的形:同一份契约有**两份声明**,而且跨仓名字零重合 ——
|
|
5
|
+
* · `sema-desktop/src/shared/localSessions.ts` = 15 个类型 + 3 个词表常量 + 6 个校验器 + SPEC(生产端)
|
|
6
|
+
* · `sema-web-client/ui/lib/desktop/local-sessions-transport.ts` = 9 个 `Seat*` 本地重声明(消费端)
|
|
7
|
+
* 两边名字不同 ⇒ **编译器永远不会告诉你它们漂了**。实测已经漂了(见下「漂移清单」),其中
|
|
8
|
+
* `LocalSessionEvent.outcome` 那一条是真 bug:宿主发了词、消费端的镜像里根本没有这个位,
|
|
9
|
+
* 于是「拒绝 / TTL 到点 / 人点了允许」在屏上长得一模一样 —— 正是 localSessions 自己在
|
|
10
|
+
* 「接缝记账」里写下的第 1 条,它一直没被销账的原因就是没有任何机制会让它红。
|
|
11
|
+
*
|
|
12
|
+
* 落点为什么是本包:desktop 与 web 都已经依赖 `@sema-agent/client-core`(0.11.5),而本文件是
|
|
13
|
+
* **纯类型 + 常量 + 纯谓词**,零 import、零 Node 内建 ⇒ 不动本包的可移植闭包(portability 门的
|
|
14
|
+
* `EXPECTED_PACKAGES_INDEX` 一个字不变)。
|
|
15
|
+
*
|
|
16
|
+
* ── 搬迁时按「真源为准」收敛的漂移(逐条,web 侧镜像 → 本文件)────────────────────────────
|
|
17
|
+
* 🔴 D1 `LocalSessionEvent.outcome` —— web 镜像整位缺席 ⇒ `tool_permission_resolved` 只会清面,
|
|
18
|
+
* 不会告诉用户为什么工具没跑。**真 bug**,本批只做「位补回来」;把词渲成可见痕迹是渲染面的活。
|
|
19
|
+
* D2 `SendMessageRequest.permissionMode` —— web 镜像是裸 `string`,真源是闭集 `PermissionModeIntent`,
|
|
20
|
+
* 而宿主入站门 `requireOptionalPermissionMode` 是**会抛的闭集门**。今日两边词表逐字相等
|
|
21
|
+
* (web `ComposerMode` 五档 ≡ `PERMISSION_MODE_INTENTS` 五档,已核),所以是**潜伏**不是现症:
|
|
22
|
+
* ComposerMode 哪天加一档,裸 string 一路放行到宿主门口才抛。收敛成闭集后当天编译红。
|
|
23
|
+
* D3 `AttachmentUploadReceipt.sha256` / `ToolPermissionRequest.createdAt` / `StartSessionOptions.cwd`
|
|
24
|
+
* / `.excludeTools` / `LocalSessionRecord.queuedMessages`·`model`·`engineSessionId` ——
|
|
25
|
+
* web 镜像缺位。都是「没接线」不是「接错线」(web 侧今日无消费点,已核),收敛后位在、待接。
|
|
26
|
+
* D4 `LocalSessionEvent.request` —— 真源有这个位,**宿主从不发**(session-host 零处写 `request:`);
|
|
27
|
+
* web 镜像没有它反而与运行时事实一致。真源保留该位(CC `fQe` 的 form 位),记在这里免得
|
|
28
|
+
* 下一棒把「web 没有」当成漏。
|
|
29
|
+
* D5 `EipcStoreClient.getStateSync` web 侧是 optional、真源是 required;`SeatSessionDirectoryRow.createdAt`
|
|
30
|
+
* web 侧 optional、真源 required。两条都是「更弱」方向,收敛到真源即可(宿主校验器
|
|
31
|
+
* `isLocalSessionRecord` 本来就要求 createdAt 在场,运行时保证一直成立)。
|
|
32
|
+
* · web 侧**没有**镜像、因而至今拿不到的面:队列三动词 / setFocusedSession / setModel /
|
|
33
|
+
* focusedSessionState / settingsState / `CHROME_EVENT_KINDS` / `ATTACHMENT_IDS_PER_TASK_CAP`。
|
|
34
|
+
* 本文件导出后它们对 web 首次可见(接不接线是渲染面的决定)。
|
|
35
|
+
*
|
|
36
|
+
* ── 沿革(以下正文自 sema-desktop/src/shared/localSessions.ts 逐字迁入)──────────────────────
|
|
37
|
+
* LocalSessions — the desktop host's session service contract, FORM-ported from the CC desktop
|
|
38
|
+
* app's `claude.web / LocalSessions` eipc interface (212 methods there; FIRST BATCH here = the four
|
|
39
|
+
* families clay scoped: session lifecycle / event subscription / interrupt / approvals).
|
|
40
|
+
*
|
|
41
|
+
* Naming: CC ns `claude.web` → `sema.web` (brand table). Method names kept verbatim where the CC
|
|
42
|
+
* method exists (`start`/`stop`/`interrupt`/`sendMessage`/`onEvent`/`onToolPermissionRequest`/
|
|
43
|
+
* `respondToToolPermission` are all real CC LocalSessions methods — see the 854-channel census).
|
|
44
|
+
*
|
|
45
|
+
* Event payload contract: ported in FORM from CC's `onEvent` runtime validator `fQe`
|
|
46
|
+
* (unpack `.vite/build/index.chunk-CnWKsyE_.js:369773`). The load-bearing property we keep
|
|
47
|
+
* byte-faithful ([1832] axiom 2, independently proven by CC's own code): on an otherwise
|
|
48
|
+
* fully-schema'd IPC surface, the `message`/`messages` fields (= CC session-vocabulary SDKMessage
|
|
49
|
+
* bodies, our transcript plane) are UNVALIDATED passthrough positions, while every other field is a
|
|
50
|
+
* neutral typed position. Our implementation体 differs (sema wire via @sema-agent/sdk +
|
|
51
|
+
* @sema-agent/client-core), the contract shape does not.
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* The resolution words the host currently puts on `tool_permission_resolved.outcome` ([1947] 红③).
|
|
55
|
+
* DOCUMENTARY + test anchor only — the gate does NOT enforce membership (see the field's doc: a
|
|
56
|
+
* closed set would fail-close the whole event on the day the wire grows a word). Grouped by family:
|
|
57
|
+
* - tool approval (wire `ToolApprovalFrame.outcome`, + our own settle sweep): allowed/denied/expired
|
|
58
|
+
* - question (wire `QuestionFrame.outcome`): answered/unanswered
|
|
59
|
+
* - elicitation (wire `ElicitationFrame.action`): accept/decline/cancel
|
|
60
|
+
*/
|
|
61
|
+
export const HITL_RESOLUTION_OUTCOMES = [
|
|
62
|
+
"allowed",
|
|
63
|
+
"denied",
|
|
64
|
+
"expired",
|
|
65
|
+
"answered",
|
|
66
|
+
"unanswered",
|
|
67
|
+
"accept",
|
|
68
|
+
"decline",
|
|
69
|
+
"cancel",
|
|
70
|
+
];
|
|
71
|
+
/**
|
|
72
|
+
* 接缝记账 — what the HOST now guarantees vs what a RENDERER still owes ([1947] 红③/红④ split).
|
|
73
|
+
*
|
|
74
|
+
* The host half is done and pinned by desktop's `scripts/run-hitl-frame-transit-fence-test.mjs`:
|
|
75
|
+
* every live ask family reaches `onToolPermissionRequest` with its own requestId domain, every
|
|
76
|
+
* resolution reaches `onEvent` with an `outcome`, and every decision routes to the right wire verb.
|
|
77
|
+
*
|
|
78
|
+
* The renderer half is where these become VISIBLE, and until it lands the data is present but
|
|
79
|
+
* unread (stating it plainly so nobody reads "the host emits it" as "the user sees it"):
|
|
80
|
+
* 1. `tool_permission_resolved.outcome` — an `expired` / `denied` / `unanswered` resolution must
|
|
81
|
+
* leave a visible refusal trace. Today the seat transport clears the surface and drops the
|
|
82
|
+
* word, so a refusal is still indistinguishable from an approval on screen.
|
|
83
|
+
* 🔴 B18(2026-07-29)查明这条一直不销账的**机制原因**:web 侧的镜像类型里连 `outcome` 这个
|
|
84
|
+
* 位都没有,所以「没读」在两边都编译得过。本批把位收进真源 = 让它至少可见于类型面。
|
|
85
|
+
* 2. `toolCallId` — now real (not null), so an approval can be anchored to the tool card that
|
|
86
|
+
* raised it instead of "the most recent tool_start" (an anchor that lands on the wrong card
|
|
87
|
+
* when a prior tool is still running).
|
|
88
|
+
* 3. `question:` rows need NO new renderer code: they arrive as `toolName: "AskUserQuestion"` with
|
|
89
|
+
* `input.questions`, which is exactly what the seat's ask-user-question surface already reads,
|
|
90
|
+
* and its answer envelope is exactly what this host expects back.
|
|
91
|
+
* 4. 座位 wire 补齐批 (2026-07-28) closed two entries that used to live here as "如实,未做":
|
|
92
|
+
* `permissionMode` now has a seat on `sendMessage` (was: the composer's Plan badge never
|
|
93
|
+
* crossed and the turn ran with the engine default), and the attachment BYTE channel exists
|
|
94
|
+
* (`uploadAttachment` + `sendMessage.attachmentIds`) — so a seat renderer no longer has to
|
|
95
|
+
* simulate "attachment ready" for a file nothing received. What is still NOT here, stated
|
|
96
|
+
* plainly: plan REVISE feedback text (the decide face has no `reason` seat, so revise maps to
|
|
97
|
+
* a bare deny) and a per-session `permissionMode` write (the wire's is per-TURN only).
|
|
98
|
+
* 5. `elicit:` rows have no dedicated surface yet: they fall through to the generic approval card,
|
|
99
|
+
* which shows the MCP server's prompt and can accept/decline but CANNOT collect form values.
|
|
100
|
+
* A real form surface (built from `input.requestedSchema`) is the renderer's remaining piece;
|
|
101
|
+
* until then an approve carries no content — the host never invents form values. That generic
|
|
102
|
+
* card also offers "Always allow (this session)", which this domain has no concept of: the host
|
|
103
|
+
* ignores `remember` here rather than pretend, so the renderer should hide that control for
|
|
104
|
+
* `elicit:` rows (a button that changes nothing is the false-affordance family again).
|
|
105
|
+
*/
|
|
106
|
+
/** Chrome arms wired to the renderer position (batch 4); other arms stay host-side on the ring. */
|
|
107
|
+
export const CHROME_EVENT_KINDS = [
|
|
108
|
+
"panel_task",
|
|
109
|
+
"notification_terminal",
|
|
110
|
+
"prompt_suggestions",
|
|
111
|
+
"subagent_lifecycle",
|
|
112
|
+
];
|
|
113
|
+
/** The closed set the inbound gate checks. CLOSED deliberately, unlike `outcome` above: this word
|
|
114
|
+
* ORIGINATES in our own renderer and goes OUT to a wire that 400s on anything else, so an unknown
|
|
115
|
+
* value is a local bug we want reported at the door — not an unknown future wire word we must
|
|
116
|
+
* tolerate. (The direction of travel is what decides open vs closed, not the field's shape.) */
|
|
117
|
+
export const PERMISSION_MODE_INTENTS = [
|
|
118
|
+
"default",
|
|
119
|
+
"plan",
|
|
120
|
+
"acceptEdits",
|
|
121
|
+
"bypassPermissions",
|
|
122
|
+
"auto",
|
|
123
|
+
];
|
|
124
|
+
/** Per-task attachment cap — the server's own limit (`attachmentIds` > 16 ⇒ 400). Gated here so the
|
|
125
|
+
* seat gets a precise local error instead of a wire 400 halfway through a turn. */
|
|
126
|
+
export const ATTACHMENT_IDS_PER_TASK_CAP = 16;
|
|
127
|
+
// ───────────────────────────── validators (CC dual-gate posture) ─────────────────────────────
|
|
128
|
+
export function isLocalSessionRecord(s) {
|
|
129
|
+
const e = s;
|
|
130
|
+
return !(!e ||
|
|
131
|
+
typeof e !== "object" ||
|
|
132
|
+
typeof e.sessionId !== "string" ||
|
|
133
|
+
(typeof e.engineSessionId !== "undefined" && typeof e.engineSessionId !== "string") ||
|
|
134
|
+
(typeof e.model !== "undefined" && typeof e.model !== "string") ||
|
|
135
|
+
(typeof e.title !== "undefined" && typeof e.title !== "string") ||
|
|
136
|
+
typeof e.isRunning !== "boolean" ||
|
|
137
|
+
typeof e.createdAt !== "string" ||
|
|
138
|
+
(typeof e.lastActivityAt !== "undefined" && typeof e.lastActivityAt !== "string") ||
|
|
139
|
+
(typeof e.queuedMessages !== "undefined" &&
|
|
140
|
+
!(Array.isArray(e.queuedMessages) &&
|
|
141
|
+
e.queuedMessages.every((q) => !!q && typeof q.uuid === "string" && typeof q.text === "string"))));
|
|
142
|
+
}
|
|
143
|
+
export function isToolPermissionRequest(r) {
|
|
144
|
+
const e = r;
|
|
145
|
+
return !(!e ||
|
|
146
|
+
typeof e !== "object" ||
|
|
147
|
+
typeof e.requestId !== "string" ||
|
|
148
|
+
typeof e.sessionId !== "string" ||
|
|
149
|
+
(typeof e.toolName !== "undefined" && e.toolName !== null && typeof e.toolName !== "string") ||
|
|
150
|
+
(typeof e.toolCallId !== "undefined" && e.toolCallId !== null && typeof e.toolCallId !== "string") ||
|
|
151
|
+
// `input` is the untrusted redacted payload — passthrough (render-only), like CC's request args.
|
|
152
|
+
(typeof e.message !== "undefined" && typeof e.message !== "string") ||
|
|
153
|
+
(typeof e.boundCallId !== "undefined" && typeof e.boundCallId !== "string") ||
|
|
154
|
+
(typeof e.boundInputHash !== "undefined" && typeof e.boundInputHash !== "string") ||
|
|
155
|
+
(typeof e.createdAt !== "undefined" && typeof e.createdAt !== "number"));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* onEvent payload validator — line-for-line FORM port of CC's `fQe`
|
|
159
|
+
* (`.vite/build/index.chunk-CnWKsyE_.js:369773`). Field-by-field mapping:
|
|
160
|
+
* - `type`/`sessionId`: required strings (same);
|
|
161
|
+
* - `message`: CC's minified source reads `typeof e.message<"u"` inside a comma expression whose
|
|
162
|
+
* value is discarded — i.e. NO validation, a deliberate transcript-plane passthrough. Same here.
|
|
163
|
+
* - `messages`: array-checked, elements `every(t=>!0)` (constant true) — array shape only. Same here.
|
|
164
|
+
* - `error`/`errorCategory`: optional strings (same); `code`: optional number (same);
|
|
165
|
+
* - `request`: CC gates with `S1` (ToolPermissionRequest schema) → our isToolPermissionRequest;
|
|
166
|
+
* - `session`: CC gates with `aM` (SessionRecord schema) → our isLocalSessionRecord;
|
|
167
|
+
* - `data`: optional string / `sources`: optional string[] / `permissionMode`: optional string /
|
|
168
|
+
* `userMessageUuid`: optional string / `hasPreClearSession`: optional boolean (same);
|
|
169
|
+
* - CC fields we do not emit in this batch (`tccFolderKind`/`initializationStatus`/`fsFile`/
|
|
170
|
+
* `localMcpServers`/`refusalFallbackPrompt`) are not carried — their positions return when the
|
|
171
|
+
* corresponding service families are ported.
|
|
172
|
+
*/
|
|
173
|
+
export function isLocalSessionEvent(v) {
|
|
174
|
+
const e = v;
|
|
175
|
+
return !(!e ||
|
|
176
|
+
typeof e !== "object" ||
|
|
177
|
+
typeof e.type !== "string" ||
|
|
178
|
+
typeof e.sessionId !== "string" ||
|
|
179
|
+
// `message`: intentionally unvalidated passthrough (see doc above — CC fQe does the same).
|
|
180
|
+
(typeof e.messages !== "undefined" && !Array.isArray(e.messages)) ||
|
|
181
|
+
(typeof e.error !== "undefined" && typeof e.error !== "string") ||
|
|
182
|
+
(typeof e.errorCategory !== "undefined" && typeof e.errorCategory !== "string") ||
|
|
183
|
+
(typeof e.code !== "undefined" && typeof e.code !== "number") ||
|
|
184
|
+
(typeof e.request !== "undefined" && !isToolPermissionRequest(e.request)) ||
|
|
185
|
+
(typeof e.data !== "undefined" && typeof e.data !== "string") ||
|
|
186
|
+
(typeof e.sources !== "undefined" &&
|
|
187
|
+
!(Array.isArray(e.sources) && e.sources.every((t) => typeof t === "string"))) ||
|
|
188
|
+
(typeof e.permissionMode !== "undefined" && typeof e.permissionMode !== "string") ||
|
|
189
|
+
(typeof e.session !== "undefined" && !isLocalSessionRecord(e.session)) ||
|
|
190
|
+
(typeof e.userMessageUuid !== "undefined" && typeof e.userMessageUuid !== "string") ||
|
|
191
|
+
(typeof e.hasPreClearSession !== "undefined" && typeof e.hasPreClearSession !== "boolean") ||
|
|
192
|
+
(typeof e.requestId !== "undefined" && typeof e.requestId !== "string") ||
|
|
193
|
+
// `outcome`: type-checked only, NOT membership-checked (see the field doc — an unknown future
|
|
194
|
+
// wire word must reach the renderer as "settled, reason unknown", never take the event down).
|
|
195
|
+
(typeof e.outcome !== "undefined" && typeof e.outcome !== "string") ||
|
|
196
|
+
(typeof e.chrome !== "undefined" &&
|
|
197
|
+
!(!!e.chrome &&
|
|
198
|
+
typeof e.chrome === "object" &&
|
|
199
|
+
typeof e.chrome.kind === "string" &&
|
|
200
|
+
CHROME_EVENT_KINDS.includes(e.chrome.kind) &&
|
|
201
|
+
// lane discipline first-class ([1617] family): a chrome arm always carries its LaneProof.
|
|
202
|
+
!!e.chrome.laneProof)));
|
|
203
|
+
}
|
|
204
|
+
export function isAttachmentUploadReceipt(v) {
|
|
205
|
+
const e = v;
|
|
206
|
+
return !(!e ||
|
|
207
|
+
typeof e !== "object" ||
|
|
208
|
+
typeof e.id !== "string" ||
|
|
209
|
+
typeof e.name !== "string" ||
|
|
210
|
+
typeof e.mime !== "string" ||
|
|
211
|
+
typeof e.sha256 !== "string" ||
|
|
212
|
+
typeof e.sizeBytes !== "number");
|
|
213
|
+
}
|
|
214
|
+
export function isSeatModelCatalog(v) {
|
|
215
|
+
const e = v;
|
|
216
|
+
return !(!e ||
|
|
217
|
+
typeof e !== "object" ||
|
|
218
|
+
!Array.isArray(e.models) ||
|
|
219
|
+
!e.models.every((m) => !!m &&
|
|
220
|
+
typeof m === "object" &&
|
|
221
|
+
typeof m.id === "string" &&
|
|
222
|
+
["undefined", "string"].includes(typeof m.name) &&
|
|
223
|
+
["undefined", "string"].includes(typeof m.provider) &&
|
|
224
|
+
["undefined", "number"].includes(typeof m.contextWindow) &&
|
|
225
|
+
["undefined", "number"].includes(typeof m.maxOutputTokens)) ||
|
|
226
|
+
(typeof e.defaultId !== "undefined" && typeof e.defaultId !== "string"));
|
|
227
|
+
}
|
|
228
|
+
export function isSendMessageAck(v) {
|
|
229
|
+
const e = v;
|
|
230
|
+
return !(!e ||
|
|
231
|
+
typeof e !== "object" ||
|
|
232
|
+
typeof e.sessionId !== "string" ||
|
|
233
|
+
typeof e.userMessageUuid !== "string" ||
|
|
234
|
+
(typeof e.queued !== "undefined" && typeof e.queued !== "boolean"));
|
|
235
|
+
}
|
|
236
|
+
// ───────────────────────────── service spec (eipc registration table) ─────────────────────────────
|
|
237
|
+
export const LOCAL_SESSIONS_SPEC = {
|
|
238
|
+
ns: "sema.web",
|
|
239
|
+
service: "LocalSessions",
|
|
240
|
+
methods: {
|
|
241
|
+
start: { kind: "invoke", validate: isLocalSessionRecord },
|
|
242
|
+
sendMessage: { kind: "invoke", validate: isSendMessageAck },
|
|
243
|
+
interrupt: {
|
|
244
|
+
kind: "invoke",
|
|
245
|
+
validate: (v) => !!v && typeof v.interrupted === "boolean",
|
|
246
|
+
},
|
|
247
|
+
stop: {
|
|
248
|
+
kind: "invoke",
|
|
249
|
+
validate: (v) => !!v && typeof v.stopped === "boolean",
|
|
250
|
+
},
|
|
251
|
+
respondToToolPermission: {
|
|
252
|
+
kind: "invoke",
|
|
253
|
+
validate: (v) => !!v && typeof v.ok === "boolean",
|
|
254
|
+
},
|
|
255
|
+
// Queue family — CC returns bare booleans (false = too-late/no-op), same here.
|
|
256
|
+
cancelQueuedMessage: { kind: "invoke", validate: (v) => typeof v === "boolean" },
|
|
257
|
+
reorderQueuedMessage: { kind: "invoke", validate: (v) => typeof v === "boolean" },
|
|
258
|
+
promoteQueuedMessage: { kind: "invoke", validate: (v) => typeof v === "boolean" },
|
|
259
|
+
setFocusedSession: {
|
|
260
|
+
kind: "invoke",
|
|
261
|
+
validate: (v) => !!v && typeof v.ok === "boolean",
|
|
262
|
+
},
|
|
263
|
+
setModel: { kind: "invoke", validate: (v) => typeof v === "boolean" },
|
|
264
|
+
getTranscript: {
|
|
265
|
+
kind: "invoke",
|
|
266
|
+
// messages = the transcript-plane passthrough batch (fQe `messages` posture: array-checked,
|
|
267
|
+
// elements deliberately unvalidated — they are CC SDKMessage bodies).
|
|
268
|
+
validate: (v) => !!v &&
|
|
269
|
+
typeof v.sessionId === "string" &&
|
|
270
|
+
Array.isArray(v.messages),
|
|
271
|
+
},
|
|
272
|
+
searchSessions: {
|
|
273
|
+
kind: "invoke",
|
|
274
|
+
validate: (v) => !!v &&
|
|
275
|
+
Array.isArray(v.results) &&
|
|
276
|
+
v.results.every((r) => !!r &&
|
|
277
|
+
typeof r.sessionId === "string" &&
|
|
278
|
+
Array.isArray(r.matches) &&
|
|
279
|
+
r.matches.every((m) => !!m && typeof m.snippet === "string")),
|
|
280
|
+
},
|
|
281
|
+
uploadAttachment: { kind: "invoke", validate: isAttachmentUploadReceipt },
|
|
282
|
+
listModels: { kind: "invoke", validate: isSeatModelCatalog },
|
|
283
|
+
onEvent: { kind: "event", validate: isLocalSessionEvent },
|
|
284
|
+
onToolPermissionRequest: { kind: "event", validate: isToolPermissionRequest },
|
|
285
|
+
},
|
|
286
|
+
stores: {
|
|
287
|
+
sessionsState: {
|
|
288
|
+
validate: (v) => !!v &&
|
|
289
|
+
Array.isArray(v.sessions) &&
|
|
290
|
+
v.sessions.every((s) => isLocalSessionRecord(s)),
|
|
291
|
+
},
|
|
292
|
+
focusedSessionState: {
|
|
293
|
+
validate: (v) => {
|
|
294
|
+
const s = v;
|
|
295
|
+
return !!v && (s.sessionId === null || typeof s.sessionId === "string");
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
settingsState: {
|
|
299
|
+
validate: (v) => {
|
|
300
|
+
const s = v;
|
|
301
|
+
return (!!v &&
|
|
302
|
+
(s.defaultModel === null || typeof s.defaultModel === "string") &&
|
|
303
|
+
(typeof s.engineVersion === "undefined" || typeof s.engineVersion === "string") &&
|
|
304
|
+
(typeof s.dataRoot === "undefined" || typeof s.dataRoot === "string"));
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
/** verb 名清单 = `LOCAL_SESSIONS_SPEC.methods` 应有的键集(逐元素相等,门里断言)。 */
|
|
310
|
+
export const SEAT_METHOD_NAMES = [
|
|
311
|
+
"start",
|
|
312
|
+
"sendMessage",
|
|
313
|
+
"interrupt",
|
|
314
|
+
"stop",
|
|
315
|
+
"respondToToolPermission",
|
|
316
|
+
"cancelQueuedMessage",
|
|
317
|
+
"reorderQueuedMessage",
|
|
318
|
+
"promoteQueuedMessage",
|
|
319
|
+
"setFocusedSession",
|
|
320
|
+
"setModel",
|
|
321
|
+
"getTranscript",
|
|
322
|
+
"searchSessions",
|
|
323
|
+
"uploadAttachment",
|
|
324
|
+
"listModels",
|
|
325
|
+
"onEvent",
|
|
326
|
+
"onToolPermissionRequest",
|
|
327
|
+
];
|
|
328
|
+
/** `$store$` 属性名清单;SPEC 的 store 键 + `"Store"` 必须逐条等于这里的名字(门里断言)。 */
|
|
329
|
+
export const SEAT_STORE_PROPS = [
|
|
330
|
+
"sessionsStateStore",
|
|
331
|
+
"focusedSessionStateStore",
|
|
332
|
+
"settingsStateStore",
|
|
333
|
+
];
|
|
334
|
+
/** 事件式(main→renderer push)的 verb —— SPEC 里 `kind: "event"` 的那一撮,门里逐元素对账。 */
|
|
335
|
+
export const SEAT_EVENT_METHOD_NAMES = ["onEvent", "onToolPermissionRequest"];
|
|
336
|
+
// ── payload 键集镜像(与各自 interface 之间有类型钉,不可能漂)────────────────────────────────
|
|
337
|
+
export const LOCAL_SESSION_EVENT_KEYS = [
|
|
338
|
+
"type",
|
|
339
|
+
"sessionId",
|
|
340
|
+
"message",
|
|
341
|
+
"messages",
|
|
342
|
+
"error",
|
|
343
|
+
"errorCategory",
|
|
344
|
+
"code",
|
|
345
|
+
"request",
|
|
346
|
+
"data",
|
|
347
|
+
"sources",
|
|
348
|
+
"permissionMode",
|
|
349
|
+
"session",
|
|
350
|
+
"userMessageUuid",
|
|
351
|
+
"hasPreClearSession",
|
|
352
|
+
"requestId",
|
|
353
|
+
"outcome",
|
|
354
|
+
"chrome",
|
|
355
|
+
];
|
|
356
|
+
export const TOOL_PERMISSION_REQUEST_KEYS = [
|
|
357
|
+
"requestId",
|
|
358
|
+
"sessionId",
|
|
359
|
+
"toolName",
|
|
360
|
+
"toolCallId",
|
|
361
|
+
"input",
|
|
362
|
+
"message",
|
|
363
|
+
"boundCallId",
|
|
364
|
+
"boundInputHash",
|
|
365
|
+
"createdAt",
|
|
366
|
+
];
|
|
367
|
+
export const LOCAL_SESSION_RECORD_KEYS = [
|
|
368
|
+
"sessionId",
|
|
369
|
+
"engineSessionId",
|
|
370
|
+
"model",
|
|
371
|
+
"title",
|
|
372
|
+
"isRunning",
|
|
373
|
+
"createdAt",
|
|
374
|
+
"lastActivityAt",
|
|
375
|
+
"queuedMessages",
|
|
376
|
+
];
|
|
377
|
+
export const SEND_MESSAGE_REQUEST_KEYS = [
|
|
378
|
+
"sessionId",
|
|
379
|
+
"text",
|
|
380
|
+
"model",
|
|
381
|
+
"userMessageUuid",
|
|
382
|
+
"permissionMode",
|
|
383
|
+
"attachmentIds",
|
|
384
|
+
];
|
|
385
|
+
export const TOOL_PERMISSION_DECISION_KEYS = [
|
|
386
|
+
"sessionId",
|
|
387
|
+
"requestId",
|
|
388
|
+
"decision",
|
|
389
|
+
"answer",
|
|
390
|
+
"updatedInput",
|
|
391
|
+
"remember",
|
|
392
|
+
];
|
|
393
|
+
export const START_SESSION_OPTION_KEYS = ["model", "title", "cwd", "excludeTools"];
|
|
394
|
+
const _seatContractPins = [
|
|
395
|
+
true, true, true, true, true, true, true, true, true,
|
|
396
|
+
true, true, true, true, true, true, true, true,
|
|
397
|
+
];
|
|
398
|
+
void _seatContractPins;
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/client-core",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
4
4
|
"description": "Client-side session runtime shared by every sema human client (TUI / web / desktop): sema wire frames (AgentEvent) -> CC session vocabulary (SDKMessage) with dual-plane output (transcript/chrome), deterministic transcript ids, lane discipline as a type, and the notification/dedup ledgers. Every CC-skin shape is collected here so the wire itself stays neutral. Blackboard [1832] design axioms; [1651]/[1652]/[1653] signed seam design. Renamed from @sema-agent/wire-cc-adapter (0.1.x).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
9
15
|
"repository": "github:sema-agent/sema-client-core",
|
|
10
16
|
"files": [
|
|
11
17
|
"dist",
|
|
@@ -14,7 +20,7 @@
|
|
|
14
20
|
"sideEffects": false,
|
|
15
21
|
"scripts": {
|
|
16
22
|
"build": "tsc -p tsconfig.json",
|
|
17
|
-
"test": "node scripts/run-client-core-
|
|
23
|
+
"test": "node scripts/run-client-core-all-gates.mjs"
|
|
18
24
|
},
|
|
19
25
|
"dependencies": {
|
|
20
26
|
"diff": "^9.0.0"
|