@anycon/protocol 0.1.1 → 0.2.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.
@@ -6,12 +6,21 @@ export type AgentStatus = ("ready" | "disabled" | "not_installed" | "not_authent
6
6
  */
7
7
  export type LinkBlock = "hidden" | "sensitive" | "workspace" | "data_dir" | "filesystem_root";
8
8
  export type DeviceKind = "daemon" | "web" | "cli" | "sdk";
9
+ /**
10
+ * 一项配置能不能被远程客户端改(ADR-43)。
11
+ */
12
+ export type ConfigEditable = "any" | "tighten_only" | "no";
13
+ /**
14
+ * 配置值的类型,客户端据此选控件。
15
+ */
16
+ export type ConfigValueKind = "bool" | "int" | "duration" | "enum" | "text";
9
17
  /**
10
18
  * 控制消息集合。方向见注释:D = 设备,H = hub。
11
19
  */
12
20
  export type Control = {
13
21
  client: ClientInfo;
14
22
  device_token?: string | null;
23
+ preview_token?: string | null;
15
24
  protocol_version: number;
16
25
  type: "auth";
17
26
  } | {
@@ -79,6 +88,10 @@ export type Control = {
79
88
  } | {
80
89
  device: string;
81
90
  type: "peer_offline";
91
+ } | {
92
+ label: string;
93
+ peer: string;
94
+ type: "preview_peer";
82
95
  } | {
83
96
  seq: number;
84
97
  to: string;
@@ -100,6 +113,7 @@ export type Control = {
100
113
  type: "dropped";
101
114
  } | {
102
115
  retry_after_ms: number;
116
+ to?: string | null;
103
117
  type: "rate_limited";
104
118
  } | {
105
119
  quota: Quota;
@@ -256,7 +270,18 @@ export type Event = {
256
270
  title: string;
257
271
  type: "permission";
258
272
  } | {
273
+ /**
274
+ * 设备答复时带的 `answers`(kind = question:`{ [question_id]: 字符串或字符串数组 }`),原样记下,
275
+ * 客户端据此在历史里显示问题和回答。daemon 自己答复的(超时、取消、自动拒绝)没有。
276
+ */
277
+ answers?: {
278
+ [k: string]: unknown;
279
+ } | null;
259
280
  by_device: string;
281
+ /**
282
+ * 设备答复时附的话(拒绝的理由、跳过问题时的说明)。daemon 自己答复的没有。
283
+ */
284
+ message?: string | null;
260
285
  option_id?: string | null;
261
286
  request_id: string;
262
287
  type: "permission_resolved";
@@ -305,6 +330,79 @@ export type Event = {
305
330
  message: string;
306
331
  recoverable: boolean;
307
332
  type: "error";
333
+ } | {
334
+ /**
335
+ * workflow 里的各个 agent,按 `index` 升序;非 workflow 为空。
336
+ */
337
+ agents?: TaskAgent[];
338
+ /**
339
+ * agent 给任务的 id(Claude Code 的 `task_id`;Codex 子 agent 的 thread id)。会话内唯一。
340
+ */
341
+ id: string;
342
+ kind: TaskKind;
343
+ /**
344
+ * 任务最近一次调用的工具名。
345
+ */
346
+ last_tool?: string | null;
347
+ /**
348
+ * workflow 的阶段,按 `index` 升序;非 workflow 为空。
349
+ */
350
+ phases?: TaskPhase[];
351
+ status: TaskStatus;
352
+ /**
353
+ * agent 给的进度 / 结果摘要。
354
+ */
355
+ summary?: string | null;
356
+ /**
357
+ * workflow 的名字 / 任务描述。
358
+ */
359
+ title: string;
360
+ /**
361
+ * 启动这个任务的 `tool_call` 的 `id`(Claude Code 的 `tool_use_id`;Codex 的 collab agent 调用 item id)。
362
+ * 客户端据此把进度挂在那个工具块上;对不上时单独成块。
363
+ */
364
+ tool_id?: string | null;
365
+ type: "task";
366
+ usage?: TaskUsage | null;
367
+ } | {
368
+ code: string;
369
+ level: NoticeLevel;
370
+ /**
371
+ * agent 给的原文(通常是英文),可能是空串。`command_output` 里是本地命令的输出,可能多行。
372
+ */
373
+ message: string;
374
+ /**
375
+ * `code = model_fallback`:原来的模型。
376
+ */
377
+ model_from?: string | null;
378
+ /**
379
+ * `code = model_fallback`:实际使用的模型。
380
+ */
381
+ model_to?: string | null;
382
+ /**
383
+ * `code = rate_limit`:限额恢复的时间。
384
+ */
385
+ resets_at_ms?: number | null;
386
+ type: "notice";
387
+ } | {
388
+ /**
389
+ * `retrying`:这是第几次重试(从 1 开始)。
390
+ */
391
+ attempt?: number | null;
392
+ /**
393
+ * `retrying`:距下一次重试的毫秒数。
394
+ */
395
+ delay_ms?: number | null;
396
+ /**
397
+ * `retrying`:最多重试几次。
398
+ */
399
+ max_attempts?: number | null;
400
+ /**
401
+ * `retrying`:触发重试的错误摘要,如 `529 overloaded_error`。
402
+ */
403
+ reason?: string | null;
404
+ state: ActivityState;
405
+ type: "activity";
308
406
  };
309
407
  export type ToolCategory = "shell" | "file_edit" | "file_read" | "search" | "web" | "subagent" | "mcp" | "other";
310
408
  export type EditKind = "edit" | "write" | "delete" | "move";
@@ -321,6 +419,32 @@ export type SessionStatus = ("starting" | "running" | "waiting_permission" | "id
321
419
  * `Event::Git` 的动作。
322
420
  */
323
421
  export type GitAction = ("sync_up_to_date" | "sync_merged" | "sync_conflicts" | "sync_aborted") | "worktree_created" | "worktree_failed" | "worktree_removed" | "worktree_kept" | "worktree_restored" | "worktree_missing";
422
+ /**
423
+ * workflow 里一个 agent 的状态。
424
+ */
425
+ export type TaskAgentState = ("running" | "done" | "failed") | "queued" | "skipped";
426
+ /**
427
+ * `Event::Task` 的任务种类。
428
+ */
429
+ export type TaskKind = "other" | "workflow" | "subagent" | "shell";
430
+ /**
431
+ * `Event::Task` 的任务状态。`Running` 以外的三个是收尾状态(终态):Claude Code 的任务进入终态后不会再变;
432
+ * Codex 的子 agent 是一个可以再收到输入的 thread,`Completed` 之后收到新输入、开始新 turn 就会回到 `Running`。
433
+ * 所以终态只说明「这一刻不在跑」,不保证同一个 `id` 以后不会再有快照;客户端始终以最新的一条为准。
434
+ */
435
+ export type TaskStatus = ("running" | "completed" | "failed") | "cancelled";
436
+ /**
437
+ * `Event::Notice` 的级别。
438
+ */
439
+ export type NoticeLevel = "info" | "warning";
440
+ /**
441
+ * `Event::Activity` 的状态。
442
+ */
443
+ export type ActivityState = "none" | "retrying" | "compacting";
444
+ /**
445
+ * `fs.read` 返回内容的方式。
446
+ */
447
+ export type FsReadEncoding = "text" | "base64";
324
448
  /**
325
449
  * 信封种类。hub 对每种的处理见 docs/protocol.md § 3。
326
450
  */
@@ -329,11 +453,34 @@ export type Kind = "handshake" | "data" | "notify" | "control";
329
453
  * 节点配置 `worktree.default` 的取值,也是 `SessionWorkspace` 的两种模式。
330
454
  */
331
455
  export type SessionWorkspaceMode = "local" | "worktree";
456
+ /**
457
+ * 日志级别,`node.logs` 的最低级别过滤。
458
+ */
459
+ export type NodeLogLevel = "trace" | "debug" | "info" | "warn" | "error";
332
460
  /**
333
461
  * `node.security_event.kind`。
334
462
  */
335
463
  export type SecurityEventKind = "device_enrolled" | "password_failures" | "password_locked" | "password_changed" | "settings_changed";
336
464
  export type NotifyCategory = ("permission_requested" | "turn_finished" | "error" | "session_idle") | "enroll_requested" | "security";
465
+ /**
466
+ * 隧道里响应体的编码。`gzip`:`DATA` 帧拼起来是 gzip 流,预览页要先解压;`headers` 里已经去掉
467
+ * `content-encoding` / `content-length`。
468
+ */
469
+ export type PreviewBodyEncoding = "identity" | "gzip";
470
+ /**
471
+ * 端口探测是否可用。`unavailable`:这台机器上没有可用的探测手段(如没有 `lsof`),只能预览配置里允许的端口。
472
+ */
473
+ export type PreviewDetection = "ok" | "unavailable";
474
+ export type PreviewGoawayCode = "expired" | "closed" | "revoked" | "disabled" | "port_not_allowed" | "shutdown";
475
+ /**
476
+ * 这个端口为什么允许预览(spec/daemon.md § 19.3)。
477
+ */
478
+ export type PreviewPortSource = "session" | "workspace" | "config";
479
+ /**
480
+ * daemon 拒绝隧道握手的原因(握手回复 `0x01` 后面的 UTF-8 串)。这一条不受 Noise 保护,只能当提示用。
481
+ */
482
+ export type PreviewRejectReason = ("expired" | "port_not_allowed" | "disabled" | "malformed") | "unknown_ticket" | "label_mismatch" | "busy";
483
+ export type PreviewResetCode = "internal" | "refused" | "timeout" | "too_large" | "cancelled" | "flow_control" | "protocol" | "limit";
337
484
  /**
338
485
  * 项目从哪来。
339
486
  */
@@ -397,6 +544,10 @@ export interface ProtocolSchema {
397
544
  blob_put_chunk_params: BlobPutChunkParams;
398
545
  browse_entry: BrowseEntry;
399
546
  client_info: ClientInfo;
547
+ config_change: ConfigChange;
548
+ config_editable: ConfigEditable;
549
+ config_item: ConfigItem;
550
+ config_value_kind: ConfigValueKind;
400
551
  control: Control;
401
552
  diff_against: DiffAgainst;
402
553
  diff_file: DiffFile;
@@ -417,6 +568,7 @@ export interface ProtocolSchema {
417
568
  event: Event;
418
569
  fs_list_params: FsListParams;
419
570
  fs_list_result: FsListResult;
571
+ fs_read_encoding: FsReadEncoding;
420
572
  fs_read_params: FsReadParams;
421
573
  fs_read_result: FsReadResult;
422
574
  git_action: GitAction;
@@ -428,6 +580,7 @@ export interface ProtocolSchema {
428
580
  link_block: LinkBlock;
429
581
  node_audit_params: NodeAuditParams;
430
582
  node_audit_result: NodeAuditResult;
583
+ node_config_result: NodeConfigResult;
431
584
  node_devices_result: NodeDevicesResult;
432
585
  node_doctor_result: NodeDoctorResult;
433
586
  node_enroll_approve_params: NodeEnrollApproveParams;
@@ -438,11 +591,15 @@ export interface ProtocolSchema {
438
591
  node_enroll_resolved: NodeEnrollResolved;
439
592
  node_enroll_status_result: NodeEnrollStatusResult;
440
593
  node_info: NodeInfo;
594
+ node_log_level: NodeLogLevel;
595
+ node_logs_params: NodeLogsParams;
596
+ node_logs_result: NodeLogsResult;
441
597
  node_pair_begin_params: NodePairBeginParams;
442
598
  node_pair_begin_result: NodePairBeginResult;
443
599
  node_revoke_device_params: NodeRevokeDeviceParams;
444
600
  node_security_event: NodeSecurityEvent;
445
601
  node_set_agent_defaults_params: NodeSetAgentDefaultsParams;
602
+ node_set_config_params: NodeSetConfigParams;
446
603
  node_set_enroll_enabled_params: NodeSetEnrollEnabledParams;
447
604
  node_set_enroll_password_params: NodeSetEnrollPasswordParams;
448
605
  node_stats: NodeStats;
@@ -455,6 +612,26 @@ export interface ProtocolSchema {
455
612
  permission_request: PermissionRequest;
456
613
  permission_resolved: PermissionResolved;
457
614
  permission_respond_params: PermissionRespondParams;
615
+ preview_body_encoding: PreviewBodyEncoding;
616
+ preview_close_params: PreviewCloseParams;
617
+ preview_detection: PreviewDetection;
618
+ preview_goaway: PreviewGoaway;
619
+ preview_goaway_code: PreviewGoawayCode;
620
+ preview_hello: PreviewHello;
621
+ preview_info: PreviewInfo;
622
+ preview_launch: PreviewLaunch;
623
+ preview_list_result: PreviewListResult;
624
+ preview_open_params: PreviewOpenParams;
625
+ preview_open_result: PreviewOpenResult;
626
+ preview_port: PreviewPort;
627
+ preview_port_source: PreviewPortSource;
628
+ preview_ports_params: PreviewPortsParams;
629
+ preview_ports_result: PreviewPortsResult;
630
+ preview_reject_reason: PreviewRejectReason;
631
+ preview_request_head: PreviewRequestHead;
632
+ preview_reset: PreviewReset;
633
+ preview_reset_code: PreviewResetCode;
634
+ preview_response_head: PreviewResponseHead;
458
635
  project: Project;
459
636
  project_kind: ProjectKind;
460
637
  pull_request_info: PullRequestInfo;
@@ -506,6 +683,7 @@ export interface ProtocolSchema {
506
683
  workspace_name_params: WorkspaceNameParams;
507
684
  workspace_remove_worktree_params: WorkspaceRemoveWorktreeParams;
508
685
  workspace_rename_params: WorkspaceRenameParams;
686
+ workspace_root_info: WorkspaceRootInfo;
509
687
  workspace_trash_id_params: WorkspaceTrashIdParams;
510
688
  workspace_trash_list_result: WorkspaceTrashListResult;
511
689
  workspace_worktrees_params: WorkspaceWorktreesParams;
@@ -556,7 +734,8 @@ export interface AgentInfo {
556
734
  }
557
735
  export interface AgentCapabilities {
558
736
  /**
559
- * 可接受的附件 mime,如 `image/png`。
737
+ * agent **原生**收的附件 mime,如 `image/png`。其它附件(非图片、这里没列出的图片格式)不受它限制:daemon 把它们落到
738
+ * 会话工作目录并在文字里附上路径(ADR-44)。
560
739
  */
561
740
  attachments?: string[];
562
741
  /**
@@ -657,7 +836,7 @@ export interface AgentListResult {
657
836
  not_modified?: boolean;
658
837
  }
659
838
  /**
660
- * 消息里的一个附件(ADR-35):指向 daemon 上已经传完的 blob。客户端从 `blob.put_end` 拿到它、原样放进
839
+ * 消息里的一个附件(ADR-35、ADR-44):指向 daemon 上已经传完的 blob(图片或任意文件)。客户端从 `blob.put_end` 拿到它、原样放进
661
840
  * `session.send` / `session.create`;daemon 以自己记录的元数据为准写进 `user_message` 事件。
662
841
  */
663
842
  export interface AttachmentRef {
@@ -667,7 +846,7 @@ export interface AttachmentRef {
667
846
  mime: string;
668
847
  name: string;
669
848
  /**
670
- * 图片像素宽高(daemon 读文件头得出;读不出来时省略)。客户端用来在下载前占好位置。
849
+ * 图片像素宽高(daemon 读文件头得出;读不出来、不是图片时省略)。客户端用来在下载前占好位置。
671
850
  */
672
851
  width?: number | null;
673
852
  }
@@ -705,11 +884,13 @@ export interface BlobIdParams {
705
884
  */
706
885
  export interface BlobPutBeginParams {
707
886
  /**
708
- * 只接受 `image/png` `image/jpeg` `image/gif` `image/webp`,其它 → `unsupported`。
887
+ * 任意 `type/subtype`:不合法或空的按 `application/octet-stream` 记录(不报错),大小写和 `;` 之后的参数规整掉。
888
+ * 声明为 `image/png` `image/jpeg` `image/gif` `image/webp` 的才校验文件头、读宽高。
709
889
  */
710
890
  mime: string;
711
891
  /**
712
- * 展示用的文件名(1–255 字节,不能含 `/` `\` 和控制字符)。daemon 不用它拼路径。
892
+ * 展示用的文件名(1–255 字节,不能含 `/` `\` 和控制字符)。非图片的存储扩展名取自它(清洗过),落到工作目录时也用它
893
+ * 作文件名;daemon 不用它拼出别的路径。
713
894
  */
714
895
  name: string;
715
896
  /**
@@ -791,6 +972,47 @@ export interface ClientInfo {
791
972
  */
792
973
  version: string;
793
974
  }
975
+ /**
976
+ * `node.set_config` 的一项改动。
977
+ */
978
+ export interface ConfigChange {
979
+ key: string;
980
+ /**
981
+ * 新值,JSON 类型要和该键的 `kind` 一致(布尔、整数、字符串)。
982
+ */
983
+ value: unknown;
984
+ }
985
+ /**
986
+ * `node.get_config` 的一项:一个可以远程查看的配置键。
987
+ */
988
+ export interface ConfigItem {
989
+ editable: ConfigEditable;
990
+ /**
991
+ * 被 `ANYCON_*` 环境变量覆盖(`log.level` 还包括 `ANYCON_LOG` / `RUST_LOG`)。为真时 `editable` 一定是 `no`。
992
+ */
993
+ env_override?: boolean;
994
+ /**
995
+ * 点分隔的键,和 `config.toml` 一致(`sessions.max_concurrent`)。
996
+ */
997
+ key: string;
998
+ kind: ConfigValueKind;
999
+ /**
1000
+ * 取值上限:`int` 是数值,`duration` 是毫秒,`text` 是字符数。
1001
+ */
1002
+ max?: number | null;
1003
+ /**
1004
+ * 取值下限:`int` 是数值,`duration` 是毫秒,`text` 不用。
1005
+ */
1006
+ min?: number | null;
1007
+ /**
1008
+ * `kind = enum` 时允许的取值。
1009
+ */
1010
+ options?: string[];
1011
+ /**
1012
+ * 当前生效的值(默认值 → 文件 → 环境变量合并后的结果):布尔、整数或字符串,类型见 `kind`。
1013
+ */
1014
+ value: unknown;
1015
+ }
794
1016
  export interface Quota {
795
1017
  connections: number;
796
1018
  connections_max?: number | null;
@@ -935,12 +1157,22 @@ export interface PermissionDetail {
935
1157
  * kind = tool
936
1158
  */
937
1159
  tool?: ToolPermissionDetail | null;
1160
+ /**
1161
+ * kind = other:要用户在浏览器里打开的链接(MCP server 的 URL 模式 elicitation)。只会是 `http` / `https`;
1162
+ * 客户端只对这两种协议提供「打开」入口,并且显示完整 URL。
1163
+ */
1164
+ url?: string | null;
938
1165
  }
939
1166
  export interface Question {
940
1167
  choices?: QuestionChoice[];
941
1168
  free_text?: boolean;
942
1169
  id: string;
943
1170
  multi?: boolean;
1171
+ /**
1172
+ * 可以不答:客户端允许留空提交,答复里就没有这一题的答案。默认 `false`(必答),
1173
+ * 所以 AskUserQuestion 这类每题都要答的行为不变;MCP elicitation 表单里 schema 没列进 `required` 的字段是 `true`。
1174
+ */
1175
+ optional?: boolean;
944
1176
  text: string;
945
1177
  }
946
1178
  export interface QuestionChoice {
@@ -972,6 +1204,15 @@ export interface PermissionOption {
972
1204
  export interface Usage {
973
1205
  cache_read_tokens?: number | null;
974
1206
  cache_write_tokens?: number | null;
1207
+ /**
1208
+ * turn 结束时上下文已经占用的 token:最近一次模型请求的输入 + 缓存读写。和 `input_tokens` 等
1209
+ * 累计用量不同,它是「此刻窗口里有多少」,客户端拿它和 `context_window` 算占用比例。agent 不报就缺省。
1210
+ */
1211
+ context_tokens?: number | null;
1212
+ /**
1213
+ * 模型的上下文窗口大小(token)。agent 不报就缺省。
1214
+ */
1215
+ context_window?: number | null;
975
1216
  cost_usd?: number | null;
976
1217
  duration_ms: number;
977
1218
  input_tokens?: number | null;
@@ -1004,6 +1245,56 @@ export interface SessionSettings {
1004
1245
  */
1005
1246
  thinking?: string | null;
1006
1247
  }
1248
+ /**
1249
+ * workflow 里的一个 agent。
1250
+ */
1251
+ export interface TaskAgent {
1252
+ /**
1253
+ * 第几次尝试(重试过才有)。
1254
+ */
1255
+ attempt?: number | null;
1256
+ /**
1257
+ * 结果来自缓存,没有真的运行。
1258
+ */
1259
+ cached?: boolean | null;
1260
+ duration_ms?: number | null;
1261
+ /**
1262
+ * `state = failed` 时的错误信息。
1263
+ */
1264
+ error?: string | null;
1265
+ /**
1266
+ * 在 workflow 里的序号,同一个任务内唯一。
1267
+ */
1268
+ index: number;
1269
+ label: string;
1270
+ /**
1271
+ * 最近一次调用的工具名。
1272
+ */
1273
+ last_tool?: string | null;
1274
+ model?: string | null;
1275
+ /**
1276
+ * 所属阶段的 `TaskPhase.index`。
1277
+ */
1278
+ phase_index?: number | null;
1279
+ state: TaskAgentState;
1280
+ tokens?: number | null;
1281
+ tool_calls?: number | null;
1282
+ }
1283
+ /**
1284
+ * workflow 的一个阶段。
1285
+ */
1286
+ export interface TaskPhase {
1287
+ index: number;
1288
+ title: string;
1289
+ }
1290
+ /**
1291
+ * 任务的用量。每个字段 agent 不报就缺省。
1292
+ */
1293
+ export interface TaskUsage {
1294
+ duration_ms?: number | null;
1295
+ tool_calls?: number | null;
1296
+ total_tokens?: number | null;
1297
+ }
1007
1298
  export interface FsListParams {
1008
1299
  /**
1009
1300
  * `<项目名>/<项目内的相对路径>`,如 `my-app/src`。第一段是关联项目的名字时,其余部分相对那个目录解析,
@@ -1022,21 +1313,50 @@ export interface FsEntry {
1022
1313
  }
1023
1314
  export interface FsReadParams {
1024
1315
  /**
1025
- * 默认 1 MiB,上限 10 MiB。
1316
+ * 缺省 `text`。
1317
+ */
1318
+ encoding?: FsReadEncoding & string;
1319
+ /**
1320
+ * 读多少**原始字节**。`encoding = text`:默认 1 MiB,上限 10 MiB。`encoding = base64`:一次最多一块(512 KiB,和
1321
+ * `blob.get` 一样),缺省就是一块,超过的按一块算(不报错);`0` 只回大小、不带数据。
1026
1322
  */
1027
1323
  max_bytes?: number | null;
1324
+ /**
1325
+ * 从文件的第几个字节读起,缺省 0。只有 `encoding = base64` 能用:大文件按块一块一块读,一个响应不会长时间占住设备到 daemon
1326
+ * 那条有序的传输。`text` 模式下 `offset > 0` 是 `invalid`。
1327
+ */
1328
+ offset?: number;
1028
1329
  /**
1029
1330
  * 解析规则同 `FsListParams.path`。
1030
1331
  */
1031
1332
  path: string;
1032
1333
  }
1033
1334
  export interface FsReadResult {
1335
+ /**
1336
+ * `text` 模式:文件是二进制(不返回内容)。`base64` 模式:按**这一块**的内容判断(前 8 KiB 里有 NUL、或不是合法的
1337
+ * UTF-8),只有 `offset = 0` 的那一块说明整个文件;从中间读起的块可能从半个字符开始,客户端不要依赖它。
1338
+ */
1034
1339
  binary: boolean;
1340
+ /**
1341
+ * 文件的总字节数(不是读到的)。分块读的时候每一块都带着它:总数变了说明文件在读的过程中被改写过。
1342
+ */
1035
1343
  bytes: number;
1036
1344
  /**
1037
- * UTF-8 文本;二进制文件 `text` 为空且 `binary = true`。
1345
+ * `encoding = base64` 时读到的字节(至多一块;`offset` 在文件末尾或之后时为空串);`text` 模式没有这个字段。
1346
+ */
1347
+ data_base64?: string | null;
1348
+ /**
1349
+ * `encoding = base64` 时 `data_base64` 从文件的第几个字节开始(原样回显请求的 `offset`);`text` 模式没有这个字段。
1350
+ * 不认识 `offset` 的旧 daemon 不会带它,客户端据此知道分块读不能用。
1351
+ */
1352
+ offset?: number | null;
1353
+ /**
1354
+ * UTF-8 文本;二进制文件 `text` 为空且 `binary = true`。`encoding = base64` 时恒为空。
1038
1355
  */
1039
1356
  text: string;
1357
+ /**
1358
+ * 文件在读到的这一段**之后**还有内容(`offset + 读到的字节数 < bytes`)。
1359
+ */
1040
1360
  truncated: boolean;
1041
1361
  }
1042
1362
  export interface JobCancelParams {
@@ -1072,6 +1392,12 @@ export interface AuditEntry {
1072
1392
  target?: string | null;
1073
1393
  ts_ms: number;
1074
1394
  }
1395
+ /**
1396
+ * `node.get_config` / `node.set_config` 的结果:白名单里的全部配置项(顺序固定,按段分组)。
1397
+ */
1398
+ export interface NodeConfigResult {
1399
+ items: ConfigItem[];
1400
+ }
1075
1401
  export interface NodeDevicesResult {
1076
1402
  devices: PeerDevice[];
1077
1403
  }
@@ -1160,6 +1486,10 @@ export interface NodeEnrollStatusResult {
1160
1486
  * `node.info` 结果。
1161
1487
  */
1162
1488
  export interface NodeInfo {
1489
+ /**
1490
+ * `capabilities.blobs` 为 true 时给出。
1491
+ */
1492
+ attachment_limits?: NodeAttachmentLimits | null;
1163
1493
  capabilities: NodeCapabilities;
1164
1494
  name: string;
1165
1495
  node_id: string;
@@ -1167,16 +1497,49 @@ export interface NodeInfo {
1167
1497
  protocol_version: number;
1168
1498
  started_at_ms: number;
1169
1499
  version: string;
1500
+ /**
1501
+ * 主根。多个根时看 `workspace_roots`。
1502
+ */
1170
1503
  workspace_root?: string | null;
1504
+ /**
1505
+ * 所有 workspace 根,主根在最前,额外根按配置顺序。老版本的 daemon 不给,客户端当作只有 `workspace_root` 一个。
1506
+ */
1507
+ workspace_roots?: WorkspaceRootInfo[];
1171
1508
  /**
1172
1509
  * `capabilities.worktree` 为 true 时给出。
1173
1510
  */
1174
1511
  worktree?: NodeWorktreeSettings | null;
1175
1512
  }
1513
+ /**
1514
+ * 附件的上限(`node.info`),客户端据此在上传之前就拒绝明显超限的文件。
1515
+ */
1516
+ export interface NodeAttachmentLimits {
1517
+ /**
1518
+ * 单个附件的字节上限(`sessions.max_attachment_bytes`,热加载;这里是 `node.info` 被调用那一刻的值)。
1519
+ */
1520
+ max_bytes: number;
1521
+ /**
1522
+ * 一条消息的附件字节合计上限。
1523
+ */
1524
+ max_message_bytes: number;
1525
+ /**
1526
+ * 一条消息至多带几个附件。
1527
+ */
1528
+ max_per_message: number;
1529
+ }
1176
1530
  export interface NodeCapabilities {
1177
1531
  audit: boolean;
1178
1532
  blobs: boolean;
1533
+ /**
1534
+ * daemon 能把任意类型的文件交给任何会话的 agent(非图片、agent 不原生收的图片落到会话工作目录,ADR-44)。
1535
+ * 为 false(旧 daemon)时客户端只能上传图片。
1536
+ */
1537
+ file_attachments?: boolean;
1179
1538
  fs: boolean;
1539
+ /**
1540
+ * 支持 dev server 预览(`preview.*`,ADR-39),且节点配置 `preview.enabled = true`。
1541
+ */
1542
+ preview?: boolean;
1180
1543
  search: boolean;
1181
1544
  /**
1182
1545
  * 有 workspace(文件夹即项目)。SDK 节点可能没有。
@@ -1187,6 +1550,24 @@ export interface NodeCapabilities {
1187
1550
  */
1188
1551
  worktree?: boolean;
1189
1552
  }
1553
+ /**
1554
+ * 一个 workspace 根(ADR-45)。每个根下的一级子文件夹都是项目。
1555
+ */
1556
+ export interface WorkspaceRootInfo {
1557
+ /**
1558
+ * 现在能用:daemon 启动时它是一个存在的目录,并且现在还在。不可用的根下的项目不出现在列表里,也不能在上面新建 / 克隆;
1559
+ * 配置只在启动时读,修好(挂上外接盘)之后要重启 daemon。
1560
+ */
1561
+ available: boolean;
1562
+ /**
1563
+ * canonical 绝对路径(根不可用时是展开后的配置值)。`workspace.create` / `clone` 的 `root` 取这里的值。
1564
+ */
1565
+ path: string;
1566
+ /**
1567
+ * 主根:放 `.scratch/`,不指定 `root` 时新项目建在这里。恰好有一个。
1568
+ */
1569
+ primary: boolean;
1570
+ }
1190
1571
  /**
1191
1572
  * 节点的 worktree 配置(`config.toml` 的 `[worktree]`),客户端据此决定新建会话的初始选择和分支名预览。
1192
1573
  */
@@ -1200,6 +1581,32 @@ export interface NodeWorktreeSettings {
1200
1581
  */
1201
1582
  default_mode: SessionWorkspaceMode;
1202
1583
  }
1584
+ /**
1585
+ * `node.logs` 参数。
1586
+ */
1587
+ export interface NodeLogsParams {
1588
+ /**
1589
+ * 最低级别:只返回这个级别及更高级别的行。缺省 = 不过滤。
1590
+ */
1591
+ level?: NodeLogLevel | null;
1592
+ /**
1593
+ * 最多返回多少行,缺省 200,最大 1000(超出按 1000)。
1594
+ */
1595
+ lines?: number | null;
1596
+ }
1597
+ /**
1598
+ * `node.logs` 结果。
1599
+ */
1600
+ export interface NodeLogsResult {
1601
+ /**
1602
+ * 日志行,旧的在前、新的在后;每行最多 2 KiB(超出的截断,行尾加 `…`)。
1603
+ */
1604
+ lines: string[];
1605
+ /**
1606
+ * 还有更早的行没有返回(行数到了上限,或扫描的日志量到了上限)。
1607
+ */
1608
+ truncated: boolean;
1609
+ }
1203
1610
  export interface NodePairBeginParams {
1204
1611
  /**
1205
1612
  * `true`(缺省)= 16 位短码(约 79 bit;链接、二维码、默认都是它);`false` = 8 位(约 40 bit),
@@ -1261,6 +1668,15 @@ export interface NodeSetAgentDefaultsParams {
1261
1668
  } | null;
1262
1669
  thinking?: string | null;
1263
1670
  }
1671
+ /**
1672
+ * `node.set_config` 参数。所有改动先校验,任何一项不合法就一项都不写。
1673
+ *
1674
+ * 错误:键不在白名单、被环境变量覆盖、想放宽只能收紧的键 → `forbidden`(`data.field` 是键,`data.reason` 是
1675
+ * `not_editable` / `env_override` / `tighten_only`);值的类型或取值不合法、键重复、`changes` 为空 → `invalid`(`data.field` 是键)。
1676
+ */
1677
+ export interface NodeSetConfigParams {
1678
+ changes: ConfigChange[];
1679
+ }
1264
1680
  /**
1265
1681
  * `node.set_enroll_enabled` 参数:写 `[enroll]` 配置。`password: true` 同时解除锁定、失败计数清零。
1266
1682
  */
@@ -1373,7 +1789,171 @@ export interface PermissionRespondParams {
1373
1789
  request_id: string;
1374
1790
  }
1375
1791
  /**
1376
- * 一个项目 = workspace 根目录下的一个一级子文件夹,或一个关联的本机目录(`kind = linked`)。
1792
+ * `preview.close` 参数:作废这个 label 的全部票据,断开它的全部隧道。
1793
+ */
1794
+ export interface PreviewCloseParams {
1795
+ label: string;
1796
+ }
1797
+ /**
1798
+ * 隧道 `GOAWAY` 帧的载荷(msgpack,只有 daemon 发,stream 0):daemon 要关掉这条隧道,之后不再处理它的帧。
1799
+ */
1800
+ export interface PreviewGoaway {
1801
+ code: PreviewGoawayCode;
1802
+ message?: string | null;
1803
+ }
1804
+ /**
1805
+ * 隧道握手第二条消息(daemon → 预览页)的 payload,JSON。到这一条预览页才确认对端持有票据、是钉住的 daemon。
1806
+ */
1807
+ export interface PreviewHello {
1808
+ expires_at_ms: number;
1809
+ port: number;
1810
+ session_id?: string | null;
1811
+ }
1812
+ /**
1813
+ * `preview.list` 的一项:一张未过期的票据。
1814
+ */
1815
+ export interface PreviewInfo {
1816
+ created_at_ms: number;
1817
+ /**
1818
+ * 签发这张票据的设备。
1819
+ */
1820
+ created_by: string;
1821
+ created_by_name: string;
1822
+ expires_at_ms: number;
1823
+ label: string;
1824
+ port: number;
1825
+ session_id?: string | null;
1826
+ ticket_id: string;
1827
+ /**
1828
+ * 此刻用这张票据建立的隧道数。
1829
+ */
1830
+ tunnels: number;
1831
+ }
1832
+ /**
1833
+ * 预览页的启动参数。Web UI 把它序列化成 JSON、再 base64url(无填充),放进
1834
+ * `<预览 origin>/__anycon/enter#<…>` 的 fragment(浏览器不会把 fragment 发给 hub)。引导页读出后存进预览 origin 的
1835
+ * IndexedDB,立即从地址栏抹掉。
1836
+ */
1837
+ export interface PreviewLaunch {
1838
+ /**
1839
+ * 票据和令牌里较早的那个过期时间。
1840
+ */
1841
+ expires_at_ms: number;
1842
+ label: string;
1843
+ /**
1844
+ * daemon 的设备 id。
1845
+ */
1846
+ node: string;
1847
+ /**
1848
+ * daemon 的 Noise 静态公钥,64 个小写 hex。预览页用它做 NK 握手(钉住 daemon)。
1849
+ */
1850
+ node_public: string;
1851
+ /**
1852
+ * 打开后先导航到的路径(以 `/` 开头,可带查询串)。
1853
+ */
1854
+ path: string;
1855
+ port: number;
1856
+ psk: string;
1857
+ ticket_id: string;
1858
+ /**
1859
+ * hub 签发的预览令牌(`POST /api/preview/tokens`),预览连接凭它向 hub 认证。
1860
+ */
1861
+ token: string;
1862
+ /**
1863
+ * 格式版本,目前是 1。
1864
+ */
1865
+ v: number;
1866
+ }
1867
+ export interface PreviewListResult {
1868
+ previews: PreviewInfo[];
1869
+ }
1870
+ /**
1871
+ * `preview.open` 参数:为本机 `port` 签发一张预览票据。
1872
+ */
1873
+ export interface PreviewOpenParams {
1874
+ port: number;
1875
+ /**
1876
+ * 从哪个会话发起(只用于界面展示和审计;端口是否允许不看它,见 spec/daemon.md § 19.3)。
1877
+ */
1878
+ session_id?: string | null;
1879
+ }
1880
+ /**
1881
+ * `preview.open` 结果。`psk` 是票据的密钥,只交给预览页(放进 [`PreviewLaunch`]),不要写日志、不要发给 hub。
1882
+ */
1883
+ export interface PreviewOpenResult {
1884
+ expires_at_ms: number;
1885
+ /**
1886
+ * 这个端口固定的预览 label(26 位小写 base32),预览 origin 是 `<label>.<预览域名>`。
1887
+ */
1888
+ label: string;
1889
+ port: number;
1890
+ /**
1891
+ * 票据密钥,64 个小写 hex(32 字节),Noise PSK。
1892
+ */
1893
+ psk: string;
1894
+ session_id?: string | null;
1895
+ /**
1896
+ * 票据 id,32 个小写 hex(16 字节)。
1897
+ */
1898
+ ticket_id: string;
1899
+ }
1900
+ export interface PreviewPort {
1901
+ pid?: number | null;
1902
+ port: number;
1903
+ /**
1904
+ * 进程名(可执行文件名,不含参数)。
1905
+ */
1906
+ process?: string | null;
1907
+ session_id?: string | null;
1908
+ source: PreviewPortSource;
1909
+ }
1910
+ /**
1911
+ * `preview.ports` 参数。带 `session_id` 只列这个会话的端口(外加配置里允许的端口)。
1912
+ */
1913
+ export interface PreviewPortsParams {
1914
+ session_id?: string | null;
1915
+ }
1916
+ export interface PreviewPortsResult {
1917
+ detection: PreviewDetection;
1918
+ ports: PreviewPort[];
1919
+ }
1920
+ /**
1921
+ * 隧道 `REQUEST` 帧的载荷(msgpack,字段名为键)。
1922
+ */
1923
+ export interface PreviewRequestHead {
1924
+ /**
1925
+ * 请求头,按原顺序,名字小写。`cookie` 来自预览页自己的 cookie jar;daemon 转发前改写哪些头见
1926
+ * spec/daemon.md § 19.5。
1927
+ */
1928
+ headers: [string, string][];
1929
+ method: string;
1930
+ /**
1931
+ * 以 `/` 开头,可带查询串;不含 scheme 和主机。
1932
+ */
1933
+ path: string;
1934
+ /**
1935
+ * `true`:这是一个 WebSocket 升级请求(`method` 为 `GET`,子协议在 `sec-websocket-protocol` 头里)。
1936
+ */
1937
+ websocket?: boolean;
1938
+ }
1939
+ /**
1940
+ * 隧道 `RESET` 帧的载荷(msgpack):终止这个 stream 的两个方向。
1941
+ */
1942
+ export interface PreviewReset {
1943
+ code: PreviewResetCode;
1944
+ message?: string | null;
1945
+ }
1946
+ /**
1947
+ * 隧道 `RESPONSE` 帧的载荷(msgpack)。WebSocket 流里 `status = 101` 表示升级成功,其他状态码表示被拒,
1948
+ * 后面跟普通响应体。
1949
+ */
1950
+ export interface PreviewResponseHead {
1951
+ encoding?: PreviewBodyEncoding & string;
1952
+ headers: [string, string][];
1953
+ status: number;
1954
+ }
1955
+ /**
1956
+ * 一个项目 = 某个 workspace 根目录下的一个一级子文件夹,或一个关联的本机目录(`kind = linked`)。
1377
1957
  * 元数据全部推导;只有「关联了哪些目录」存在 daemon 的库里。
1378
1958
  */
1379
1959
  export interface Project {
@@ -1395,13 +1975,18 @@ export interface Project {
1395
1975
  missing?: boolean;
1396
1976
  modified_at_ms: number;
1397
1977
  /**
1398
- * 项目名。根目录下的项目和关联的项目共用一个命名空间,客户端的所有操作都用它。
1978
+ * 项目名。所有 workspace 根下的项目和关联的项目共用一个命名空间,客户端的所有操作都用它。
1399
1979
  */
1400
1980
  name: string;
1401
1981
  /**
1402
1982
  * 绝对路径,仅展示用。
1403
1983
  */
1404
1984
  path: string;
1985
+ /**
1986
+ * 文件夹项目所在的 workspace 根(canonical 绝对路径,等于 `node.info.workspace_roots` 里的某一项的 `path`);
1987
+ * 关联项目没有。老版本的 daemon 不给,客户端当作主根。
1988
+ */
1989
+ root?: string | null;
1405
1990
  }
1406
1991
  export interface GitMeta {
1407
1992
  branch?: string | null;
@@ -1524,7 +2109,8 @@ export interface SessionWorktree {
1524
2109
  export interface SessionCreateParams {
1525
2110
  agent: string;
1526
2111
  /**
1527
- * 第一条消息的附件(`blob.put_end` 的结果)。agent 的 `capabilities.attachments` 不含其 mime → `unsupported`。
2112
+ * 第一条消息的附件(`blob.put_end` 的结果)。agent 原生收的 mime(`capabilities.attachments`)交给 adapter,
2113
+ * 其余落到会话工作目录、路径写在交给 agent 的文字里(ADR-44)。
1528
2114
  */
1529
2115
  attachments?: AttachmentRef[];
1530
2116
  /**
@@ -1740,26 +2326,45 @@ export interface SessionRenameParams {
1740
2326
  title: string;
1741
2327
  }
1742
2328
  export interface SessionSearchParams {
2329
+ /**
2330
+ * 最多返回几条命中,默认 20,上限 200。
2331
+ */
1743
2332
  limit?: number | null;
2333
+ /**
2334
+ * 只搜这个项目里的会话。
2335
+ */
1744
2336
  project?: string | null;
2337
+ /**
2338
+ * 空白分隔的若干个词,每个词按前缀匹配、都要出现在同一段文字里;不能为空(`invalid`)。
2339
+ */
1745
2340
  query: string;
1746
2341
  }
1747
2342
  export interface SessionSearchResult {
1748
2343
  hits: SearchHit[];
1749
2344
  }
1750
2345
  export interface SearchHit {
2346
+ /**
2347
+ * 命中的那段文字开始处的事件 seq:用户消息就是 `user_message` 的 seq;assistant 文字是那一段第一个 `text_delta` 的 seq
2348
+ * (长文字每 32 KiB 切一段索引,所以同一条回复可以有几个不同的 seq)。
2349
+ */
1751
2350
  seq: number;
1752
2351
  session_id: string;
1753
2352
  /**
1754
- * 带 `<mark>` 的片段。
2353
+ * 命中处的片段。除了包住命中词的字面 `<mark>` / `</mark>`,里面没有 HTML:会话文字里原有的
2354
+ * `<` `>` `&` 已转义成 `&lt;` `&gt;` `&amp;`,客户端按 `<mark>` 切开后把这三个实体还原成字符、
2355
+ * 当纯文本显示即可,不要当 HTML 解析。
1755
2356
  */
1756
2357
  snippet: string;
2358
+ /**
2359
+ * 会话当前的标题。
2360
+ */
1757
2361
  title: string;
1758
2362
  ts_ms: number;
1759
2363
  }
1760
2364
  export interface SessionSendParams {
1761
2365
  /**
1762
- * `blob.put_end` 的结果,每条至多 20 个。agent 的 `capabilities.attachments` 不含其 mime → `unsupported`。
2366
+ * `blob.put_end` 的结果,每条至多 20 个。agent 原生收的 mime(`capabilities.attachments`)交给 adapter,
2367
+ * 其余落到会话工作目录、路径写在交给 agent 的文字里(ADR-44)。
1763
2368
  */
1764
2369
  attachments?: AttachmentRef[];
1765
2370
  /**
@@ -1824,10 +2429,14 @@ export interface SessionSyncBaseResult {
1824
2429
  export interface TrashEntry {
1825
2430
  bytes: number;
1826
2431
  /**
1827
- * `.trash/` 下的目录名,如 `my-app-20261011T120000Z`。
2432
+ * `.trash/` 下的目录名,如 `my-app-20261011T120000Z`。每个根有自己的 `.trash/`,id 在所有根之间唯一。
1828
2433
  */
1829
2434
  id: string;
1830
2435
  original_name: string;
2436
+ /**
2437
+ * 条目所在(也是 `restore` 还原到)的 workspace 根。老版本的 daemon 不给,客户端当作主根。
2438
+ */
2439
+ root?: string | null;
1831
2440
  trashed_at_ms: number;
1832
2441
  }
1833
2442
  /**
@@ -1924,6 +2533,10 @@ export interface RenamedProject {
1924
2533
  }
1925
2534
  export interface WorkspaceCloneParams {
1926
2535
  name?: string | null;
2536
+ /**
2537
+ * 克隆到哪个 workspace 根下,规则同 `WorkspaceCreateParams.root`。
2538
+ */
2539
+ root?: string | null;
1927
2540
  /**
1928
2541
  * 只允许 `https://`、`ssh://`、`git@host:path` 三种形式。
1929
2542
  */
@@ -1932,6 +2545,11 @@ export interface WorkspaceCloneParams {
1932
2545
  export interface WorkspaceCreateParams {
1933
2546
  git_init?: boolean;
1934
2547
  name: string;
2548
+ /**
2549
+ * 在哪个 workspace 根下新建。必须是 `node.info.workspace_roots` 里的某一项的 `path`;缺省 = 主根;
2550
+ * 不在列表里 → `invalid`,在列表里但现在不可用(`available = false`)→ `not_found`。
2551
+ */
2552
+ root?: string | null;
1935
2553
  }
1936
2554
  /**
1937
2555
  * `workspace.link`:把本机一个已有目录关联为项目。
@@ -1949,6 +2567,9 @@ export interface WorkspaceLinkParams {
1949
2567
  }
1950
2568
  export interface WorkspaceListResult {
1951
2569
  projects: Project[];
2570
+ /**
2571
+ * 主根(`node.info.workspace_roots` 里 `primary` 的那一项)。其余根下的项目看 `Project.root`。
2572
+ */
1952
2573
  root: string;
1953
2574
  }
1954
2575
  export interface WorkspaceNameParams {