@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.
package/src/generated.ts CHANGED
@@ -10,6 +10,14 @@ export type AgentStatus =
10
10
  */
11
11
  export type LinkBlock = "hidden" | "sensitive" | "workspace" | "data_dir" | "filesystem_root";
12
12
  export type DeviceKind = "daemon" | "web" | "cli" | "sdk";
13
+ /**
14
+ * 一项配置能不能被远程客户端改(ADR-43)。
15
+ */
16
+ export type ConfigEditable = "any" | "tighten_only" | "no";
17
+ /**
18
+ * 配置值的类型,客户端据此选控件。
19
+ */
20
+ export type ConfigValueKind = "bool" | "int" | "duration" | "enum" | "text";
13
21
  /**
14
22
  * 控制消息集合。方向见注释:D = 设备,H = hub。
15
23
  */
@@ -17,6 +25,7 @@ export type Control =
17
25
  | {
18
26
  client: ClientInfo;
19
27
  device_token?: string | null;
28
+ preview_token?: string | null;
20
29
  protocol_version: number;
21
30
  type: "auth";
22
31
  }
@@ -102,6 +111,11 @@ export type Control =
102
111
  device: string;
103
112
  type: "peer_offline";
104
113
  }
114
+ | {
115
+ label: string;
116
+ peer: string;
117
+ type: "preview_peer";
118
+ }
105
119
  | {
106
120
  seq: number;
107
121
  to: string;
@@ -128,6 +142,7 @@ export type Control =
128
142
  }
129
143
  | {
130
144
  retry_after_ms: number;
145
+ to?: string | null;
131
146
  type: "rate_limited";
132
147
  }
133
148
  | {
@@ -325,7 +340,18 @@ export type Event =
325
340
  type: "permission";
326
341
  }
327
342
  | {
343
+ /**
344
+ * 设备答复时带的 `answers`(kind = question:`{ [question_id]: 字符串或字符串数组 }`),原样记下,
345
+ * 客户端据此在历史里显示问题和回答。daemon 自己答复的(超时、取消、自动拒绝)没有。
346
+ */
347
+ answers?: {
348
+ [k: string]: unknown;
349
+ } | null;
328
350
  by_device: string;
351
+ /**
352
+ * 设备答复时附的话(拒绝的理由、跳过问题时的说明)。daemon 自己答复的没有。
353
+ */
354
+ message?: string | null;
329
355
  option_id?: string | null;
330
356
  request_id: string;
331
357
  type: "permission_resolved";
@@ -380,6 +406,82 @@ export type Event =
380
406
  message: string;
381
407
  recoverable: boolean;
382
408
  type: "error";
409
+ }
410
+ | {
411
+ /**
412
+ * workflow 里的各个 agent,按 `index` 升序;非 workflow 为空。
413
+ */
414
+ agents?: TaskAgent[];
415
+ /**
416
+ * agent 给任务的 id(Claude Code 的 `task_id`;Codex 子 agent 的 thread id)。会话内唯一。
417
+ */
418
+ id: string;
419
+ kind: TaskKind;
420
+ /**
421
+ * 任务最近一次调用的工具名。
422
+ */
423
+ last_tool?: string | null;
424
+ /**
425
+ * workflow 的阶段,按 `index` 升序;非 workflow 为空。
426
+ */
427
+ phases?: TaskPhase[];
428
+ status: TaskStatus;
429
+ /**
430
+ * agent 给的进度 / 结果摘要。
431
+ */
432
+ summary?: string | null;
433
+ /**
434
+ * workflow 的名字 / 任务描述。
435
+ */
436
+ title: string;
437
+ /**
438
+ * 启动这个任务的 `tool_call` 的 `id`(Claude Code 的 `tool_use_id`;Codex 的 collab agent 调用 item id)。
439
+ * 客户端据此把进度挂在那个工具块上;对不上时单独成块。
440
+ */
441
+ tool_id?: string | null;
442
+ type: "task";
443
+ usage?: TaskUsage | null;
444
+ }
445
+ | {
446
+ code: string;
447
+ level: NoticeLevel;
448
+ /**
449
+ * agent 给的原文(通常是英文),可能是空串。`command_output` 里是本地命令的输出,可能多行。
450
+ */
451
+ message: string;
452
+ /**
453
+ * `code = model_fallback`:原来的模型。
454
+ */
455
+ model_from?: string | null;
456
+ /**
457
+ * `code = model_fallback`:实际使用的模型。
458
+ */
459
+ model_to?: string | null;
460
+ /**
461
+ * `code = rate_limit`:限额恢复的时间。
462
+ */
463
+ resets_at_ms?: number | null;
464
+ type: "notice";
465
+ }
466
+ | {
467
+ /**
468
+ * `retrying`:这是第几次重试(从 1 开始)。
469
+ */
470
+ attempt?: number | null;
471
+ /**
472
+ * `retrying`:距下一次重试的毫秒数。
473
+ */
474
+ delay_ms?: number | null;
475
+ /**
476
+ * `retrying`:最多重试几次。
477
+ */
478
+ max_attempts?: number | null;
479
+ /**
480
+ * `retrying`:触发重试的错误摘要,如 `529 overloaded_error`。
481
+ */
482
+ reason?: string | null;
483
+ state: ActivityState;
484
+ type: "activity";
383
485
  };
384
486
  export type ToolCategory = "shell" | "file_edit" | "file_read" | "search" | "web" | "subagent" | "mcp" | "other";
385
487
  export type EditKind = "edit" | "write" | "delete" | "move";
@@ -404,6 +506,32 @@ export type GitAction =
404
506
  | "worktree_kept"
405
507
  | "worktree_restored"
406
508
  | "worktree_missing";
509
+ /**
510
+ * workflow 里一个 agent 的状态。
511
+ */
512
+ export type TaskAgentState = ("running" | "done" | "failed") | "queued" | "skipped";
513
+ /**
514
+ * `Event::Task` 的任务种类。
515
+ */
516
+ export type TaskKind = "other" | "workflow" | "subagent" | "shell";
517
+ /**
518
+ * `Event::Task` 的任务状态。`Running` 以外的三个是收尾状态(终态):Claude Code 的任务进入终态后不会再变;
519
+ * Codex 的子 agent 是一个可以再收到输入的 thread,`Completed` 之后收到新输入、开始新 turn 就会回到 `Running`。
520
+ * 所以终态只说明「这一刻不在跑」,不保证同一个 `id` 以后不会再有快照;客户端始终以最新的一条为准。
521
+ */
522
+ export type TaskStatus = ("running" | "completed" | "failed") | "cancelled";
523
+ /**
524
+ * `Event::Notice` 的级别。
525
+ */
526
+ export type NoticeLevel = "info" | "warning";
527
+ /**
528
+ * `Event::Activity` 的状态。
529
+ */
530
+ export type ActivityState = "none" | "retrying" | "compacting";
531
+ /**
532
+ * `fs.read` 返回内容的方式。
533
+ */
534
+ export type FsReadEncoding = "text" | "base64";
407
535
  /**
408
536
  * 信封种类。hub 对每种的处理见 docs/protocol.md § 3。
409
537
  */
@@ -412,6 +540,10 @@ export type Kind = "handshake" | "data" | "notify" | "control";
412
540
  * 节点配置 `worktree.default` 的取值,也是 `SessionWorkspace` 的两种模式。
413
541
  */
414
542
  export type SessionWorkspaceMode = "local" | "worktree";
543
+ /**
544
+ * 日志级别,`node.logs` 的最低级别过滤。
545
+ */
546
+ export type NodeLogLevel = "trace" | "debug" | "info" | "warn" | "error";
415
547
  /**
416
548
  * `node.security_event.kind`。
417
549
  */
@@ -419,6 +551,27 @@ export type SecurityEventKind =
419
551
  "device_enrolled" | "password_failures" | "password_locked" | "password_changed" | "settings_changed";
420
552
  export type NotifyCategory =
421
553
  ("permission_requested" | "turn_finished" | "error" | "session_idle") | "enroll_requested" | "security";
554
+ /**
555
+ * 隧道里响应体的编码。`gzip`:`DATA` 帧拼起来是 gzip 流,预览页要先解压;`headers` 里已经去掉
556
+ * `content-encoding` / `content-length`。
557
+ */
558
+ export type PreviewBodyEncoding = "identity" | "gzip";
559
+ /**
560
+ * 端口探测是否可用。`unavailable`:这台机器上没有可用的探测手段(如没有 `lsof`),只能预览配置里允许的端口。
561
+ */
562
+ export type PreviewDetection = "ok" | "unavailable";
563
+ export type PreviewGoawayCode = "expired" | "closed" | "revoked" | "disabled" | "port_not_allowed" | "shutdown";
564
+ /**
565
+ * 这个端口为什么允许预览(spec/daemon.md § 19.3)。
566
+ */
567
+ export type PreviewPortSource = "session" | "workspace" | "config";
568
+ /**
569
+ * daemon 拒绝隧道握手的原因(握手回复 `0x01` 后面的 UTF-8 串)。这一条不受 Noise 保护,只能当提示用。
570
+ */
571
+ export type PreviewRejectReason =
572
+ ("expired" | "port_not_allowed" | "disabled" | "malformed") | "unknown_ticket" | "label_mismatch" | "busy";
573
+ export type PreviewResetCode =
574
+ "internal" | "refused" | "timeout" | "too_large" | "cancelled" | "flow_control" | "protocol" | "limit";
422
575
  /**
423
576
  * 项目从哪来。
424
577
  */
@@ -486,6 +639,10 @@ export interface ProtocolSchema {
486
639
  blob_put_chunk_params: BlobPutChunkParams;
487
640
  browse_entry: BrowseEntry;
488
641
  client_info: ClientInfo;
642
+ config_change: ConfigChange;
643
+ config_editable: ConfigEditable;
644
+ config_item: ConfigItem;
645
+ config_value_kind: ConfigValueKind;
489
646
  control: Control;
490
647
  diff_against: DiffAgainst;
491
648
  diff_file: DiffFile;
@@ -506,6 +663,7 @@ export interface ProtocolSchema {
506
663
  event: Event;
507
664
  fs_list_params: FsListParams;
508
665
  fs_list_result: FsListResult;
666
+ fs_read_encoding: FsReadEncoding;
509
667
  fs_read_params: FsReadParams;
510
668
  fs_read_result: FsReadResult;
511
669
  git_action: GitAction;
@@ -517,6 +675,7 @@ export interface ProtocolSchema {
517
675
  link_block: LinkBlock;
518
676
  node_audit_params: NodeAuditParams;
519
677
  node_audit_result: NodeAuditResult;
678
+ node_config_result: NodeConfigResult;
520
679
  node_devices_result: NodeDevicesResult;
521
680
  node_doctor_result: NodeDoctorResult;
522
681
  node_enroll_approve_params: NodeEnrollApproveParams;
@@ -527,11 +686,15 @@ export interface ProtocolSchema {
527
686
  node_enroll_resolved: NodeEnrollResolved;
528
687
  node_enroll_status_result: NodeEnrollStatusResult;
529
688
  node_info: NodeInfo;
689
+ node_log_level: NodeLogLevel;
690
+ node_logs_params: NodeLogsParams;
691
+ node_logs_result: NodeLogsResult;
530
692
  node_pair_begin_params: NodePairBeginParams;
531
693
  node_pair_begin_result: NodePairBeginResult;
532
694
  node_revoke_device_params: NodeRevokeDeviceParams;
533
695
  node_security_event: NodeSecurityEvent;
534
696
  node_set_agent_defaults_params: NodeSetAgentDefaultsParams;
697
+ node_set_config_params: NodeSetConfigParams;
535
698
  node_set_enroll_enabled_params: NodeSetEnrollEnabledParams;
536
699
  node_set_enroll_password_params: NodeSetEnrollPasswordParams;
537
700
  node_stats: NodeStats;
@@ -544,6 +707,26 @@ export interface ProtocolSchema {
544
707
  permission_request: PermissionRequest;
545
708
  permission_resolved: PermissionResolved;
546
709
  permission_respond_params: PermissionRespondParams;
710
+ preview_body_encoding: PreviewBodyEncoding;
711
+ preview_close_params: PreviewCloseParams;
712
+ preview_detection: PreviewDetection;
713
+ preview_goaway: PreviewGoaway;
714
+ preview_goaway_code: PreviewGoawayCode;
715
+ preview_hello: PreviewHello;
716
+ preview_info: PreviewInfo;
717
+ preview_launch: PreviewLaunch;
718
+ preview_list_result: PreviewListResult;
719
+ preview_open_params: PreviewOpenParams;
720
+ preview_open_result: PreviewOpenResult;
721
+ preview_port: PreviewPort;
722
+ preview_port_source: PreviewPortSource;
723
+ preview_ports_params: PreviewPortsParams;
724
+ preview_ports_result: PreviewPortsResult;
725
+ preview_reject_reason: PreviewRejectReason;
726
+ preview_request_head: PreviewRequestHead;
727
+ preview_reset: PreviewReset;
728
+ preview_reset_code: PreviewResetCode;
729
+ preview_response_head: PreviewResponseHead;
547
730
  project: Project;
548
731
  project_kind: ProjectKind;
549
732
  pull_request_info: PullRequestInfo;
@@ -595,6 +778,7 @@ export interface ProtocolSchema {
595
778
  workspace_name_params: WorkspaceNameParams;
596
779
  workspace_remove_worktree_params: WorkspaceRemoveWorktreeParams;
597
780
  workspace_rename_params: WorkspaceRenameParams;
781
+ workspace_root_info: WorkspaceRootInfo;
598
782
  workspace_trash_id_params: WorkspaceTrashIdParams;
599
783
  workspace_trash_list_result: WorkspaceTrashListResult;
600
784
  workspace_worktrees_params: WorkspaceWorktreesParams;
@@ -645,7 +829,8 @@ export interface AgentInfo {
645
829
  }
646
830
  export interface AgentCapabilities {
647
831
  /**
648
- * 可接受的附件 mime,如 `image/png`。
832
+ * agent **原生**收的附件 mime,如 `image/png`。其它附件(非图片、这里没列出的图片格式)不受它限制:daemon 把它们落到
833
+ * 会话工作目录并在文字里附上路径(ADR-44)。
649
834
  */
650
835
  attachments?: string[];
651
836
  /**
@@ -746,7 +931,7 @@ export interface AgentListResult {
746
931
  not_modified?: boolean;
747
932
  }
748
933
  /**
749
- * 消息里的一个附件(ADR-35):指向 daemon 上已经传完的 blob。客户端从 `blob.put_end` 拿到它、原样放进
934
+ * 消息里的一个附件(ADR-35、ADR-44):指向 daemon 上已经传完的 blob(图片或任意文件)。客户端从 `blob.put_end` 拿到它、原样放进
750
935
  * `session.send` / `session.create`;daemon 以自己记录的元数据为准写进 `user_message` 事件。
751
936
  */
752
937
  export interface AttachmentRef {
@@ -756,7 +941,7 @@ export interface AttachmentRef {
756
941
  mime: string;
757
942
  name: string;
758
943
  /**
759
- * 图片像素宽高(daemon 读文件头得出;读不出来时省略)。客户端用来在下载前占好位置。
944
+ * 图片像素宽高(daemon 读文件头得出;读不出来、不是图片时省略)。客户端用来在下载前占好位置。
760
945
  */
761
946
  width?: number | null;
762
947
  }
@@ -794,11 +979,13 @@ export interface BlobIdParams {
794
979
  */
795
980
  export interface BlobPutBeginParams {
796
981
  /**
797
- * 只接受 `image/png` `image/jpeg` `image/gif` `image/webp`,其它 → `unsupported`。
982
+ * 任意 `type/subtype`:不合法或空的按 `application/octet-stream` 记录(不报错),大小写和 `;` 之后的参数规整掉。
983
+ * 声明为 `image/png` `image/jpeg` `image/gif` `image/webp` 的才校验文件头、读宽高。
798
984
  */
799
985
  mime: string;
800
986
  /**
801
- * 展示用的文件名(1–255 字节,不能含 `/` `\` 和控制字符)。daemon 不用它拼路径。
987
+ * 展示用的文件名(1–255 字节,不能含 `/` `\` 和控制字符)。非图片的存储扩展名取自它(清洗过),落到工作目录时也用它
988
+ * 作文件名;daemon 不用它拼出别的路径。
802
989
  */
803
990
  name: string;
804
991
  /**
@@ -880,6 +1067,47 @@ export interface ClientInfo {
880
1067
  */
881
1068
  version: string;
882
1069
  }
1070
+ /**
1071
+ * `node.set_config` 的一项改动。
1072
+ */
1073
+ export interface ConfigChange {
1074
+ key: string;
1075
+ /**
1076
+ * 新值,JSON 类型要和该键的 `kind` 一致(布尔、整数、字符串)。
1077
+ */
1078
+ value: unknown;
1079
+ }
1080
+ /**
1081
+ * `node.get_config` 的一项:一个可以远程查看的配置键。
1082
+ */
1083
+ export interface ConfigItem {
1084
+ editable: ConfigEditable;
1085
+ /**
1086
+ * 被 `ANYCON_*` 环境变量覆盖(`log.level` 还包括 `ANYCON_LOG` / `RUST_LOG`)。为真时 `editable` 一定是 `no`。
1087
+ */
1088
+ env_override?: boolean;
1089
+ /**
1090
+ * 点分隔的键,和 `config.toml` 一致(`sessions.max_concurrent`)。
1091
+ */
1092
+ key: string;
1093
+ kind: ConfigValueKind;
1094
+ /**
1095
+ * 取值上限:`int` 是数值,`duration` 是毫秒,`text` 是字符数。
1096
+ */
1097
+ max?: number | null;
1098
+ /**
1099
+ * 取值下限:`int` 是数值,`duration` 是毫秒,`text` 不用。
1100
+ */
1101
+ min?: number | null;
1102
+ /**
1103
+ * `kind = enum` 时允许的取值。
1104
+ */
1105
+ options?: string[];
1106
+ /**
1107
+ * 当前生效的值(默认值 → 文件 → 环境变量合并后的结果):布尔、整数或字符串,类型见 `kind`。
1108
+ */
1109
+ value: unknown;
1110
+ }
883
1111
  export interface Quota {
884
1112
  connections: number;
885
1113
  connections_max?: number | null;
@@ -1023,12 +1251,22 @@ export interface PermissionDetail {
1023
1251
  * kind = tool
1024
1252
  */
1025
1253
  tool?: ToolPermissionDetail | null;
1254
+ /**
1255
+ * kind = other:要用户在浏览器里打开的链接(MCP server 的 URL 模式 elicitation)。只会是 `http` / `https`;
1256
+ * 客户端只对这两种协议提供「打开」入口,并且显示完整 URL。
1257
+ */
1258
+ url?: string | null;
1026
1259
  }
1027
1260
  export interface Question {
1028
1261
  choices?: QuestionChoice[];
1029
1262
  free_text?: boolean;
1030
1263
  id: string;
1031
1264
  multi?: boolean;
1265
+ /**
1266
+ * 可以不答:客户端允许留空提交,答复里就没有这一题的答案。默认 `false`(必答),
1267
+ * 所以 AskUserQuestion 这类每题都要答的行为不变;MCP elicitation 表单里 schema 没列进 `required` 的字段是 `true`。
1268
+ */
1269
+ optional?: boolean;
1032
1270
  text: string;
1033
1271
  }
1034
1272
  export interface QuestionChoice {
@@ -1060,6 +1298,15 @@ export interface PermissionOption {
1060
1298
  export interface Usage {
1061
1299
  cache_read_tokens?: number | null;
1062
1300
  cache_write_tokens?: number | null;
1301
+ /**
1302
+ * turn 结束时上下文已经占用的 token:最近一次模型请求的输入 + 缓存读写。和 `input_tokens` 等
1303
+ * 累计用量不同,它是「此刻窗口里有多少」,客户端拿它和 `context_window` 算占用比例。agent 不报就缺省。
1304
+ */
1305
+ context_tokens?: number | null;
1306
+ /**
1307
+ * 模型的上下文窗口大小(token)。agent 不报就缺省。
1308
+ */
1309
+ context_window?: number | null;
1063
1310
  cost_usd?: number | null;
1064
1311
  duration_ms: number;
1065
1312
  input_tokens?: number | null;
@@ -1092,6 +1339,56 @@ export interface SessionSettings {
1092
1339
  */
1093
1340
  thinking?: string | null;
1094
1341
  }
1342
+ /**
1343
+ * workflow 里的一个 agent。
1344
+ */
1345
+ export interface TaskAgent {
1346
+ /**
1347
+ * 第几次尝试(重试过才有)。
1348
+ */
1349
+ attempt?: number | null;
1350
+ /**
1351
+ * 结果来自缓存,没有真的运行。
1352
+ */
1353
+ cached?: boolean | null;
1354
+ duration_ms?: number | null;
1355
+ /**
1356
+ * `state = failed` 时的错误信息。
1357
+ */
1358
+ error?: string | null;
1359
+ /**
1360
+ * 在 workflow 里的序号,同一个任务内唯一。
1361
+ */
1362
+ index: number;
1363
+ label: string;
1364
+ /**
1365
+ * 最近一次调用的工具名。
1366
+ */
1367
+ last_tool?: string | null;
1368
+ model?: string | null;
1369
+ /**
1370
+ * 所属阶段的 `TaskPhase.index`。
1371
+ */
1372
+ phase_index?: number | null;
1373
+ state: TaskAgentState;
1374
+ tokens?: number | null;
1375
+ tool_calls?: number | null;
1376
+ }
1377
+ /**
1378
+ * workflow 的一个阶段。
1379
+ */
1380
+ export interface TaskPhase {
1381
+ index: number;
1382
+ title: string;
1383
+ }
1384
+ /**
1385
+ * 任务的用量。每个字段 agent 不报就缺省。
1386
+ */
1387
+ export interface TaskUsage {
1388
+ duration_ms?: number | null;
1389
+ tool_calls?: number | null;
1390
+ total_tokens?: number | null;
1391
+ }
1095
1392
  export interface FsListParams {
1096
1393
  /**
1097
1394
  * `<项目名>/<项目内的相对路径>`,如 `my-app/src`。第一段是关联项目的名字时,其余部分相对那个目录解析,
@@ -1110,21 +1407,50 @@ export interface FsEntry {
1110
1407
  }
1111
1408
  export interface FsReadParams {
1112
1409
  /**
1113
- * 默认 1 MiB,上限 10 MiB。
1410
+ * 缺省 `text`。
1411
+ */
1412
+ encoding?: FsReadEncoding & string;
1413
+ /**
1414
+ * 读多少**原始字节**。`encoding = text`:默认 1 MiB,上限 10 MiB。`encoding = base64`:一次最多一块(512 KiB,和
1415
+ * `blob.get` 一样),缺省就是一块,超过的按一块算(不报错);`0` 只回大小、不带数据。
1114
1416
  */
1115
1417
  max_bytes?: number | null;
1418
+ /**
1419
+ * 从文件的第几个字节读起,缺省 0。只有 `encoding = base64` 能用:大文件按块一块一块读,一个响应不会长时间占住设备到 daemon
1420
+ * 那条有序的传输。`text` 模式下 `offset > 0` 是 `invalid`。
1421
+ */
1422
+ offset?: number;
1116
1423
  /**
1117
1424
  * 解析规则同 `FsListParams.path`。
1118
1425
  */
1119
1426
  path: string;
1120
1427
  }
1121
1428
  export interface FsReadResult {
1429
+ /**
1430
+ * `text` 模式:文件是二进制(不返回内容)。`base64` 模式:按**这一块**的内容判断(前 8 KiB 里有 NUL、或不是合法的
1431
+ * UTF-8),只有 `offset = 0` 的那一块说明整个文件;从中间读起的块可能从半个字符开始,客户端不要依赖它。
1432
+ */
1122
1433
  binary: boolean;
1434
+ /**
1435
+ * 文件的总字节数(不是读到的)。分块读的时候每一块都带着它:总数变了说明文件在读的过程中被改写过。
1436
+ */
1123
1437
  bytes: number;
1124
1438
  /**
1125
- * UTF-8 文本;二进制文件 `text` 为空且 `binary = true`。
1439
+ * `encoding = base64` 时读到的字节(至多一块;`offset` 在文件末尾或之后时为空串);`text` 模式没有这个字段。
1440
+ */
1441
+ data_base64?: string | null;
1442
+ /**
1443
+ * `encoding = base64` 时 `data_base64` 从文件的第几个字节开始(原样回显请求的 `offset`);`text` 模式没有这个字段。
1444
+ * 不认识 `offset` 的旧 daemon 不会带它,客户端据此知道分块读不能用。
1445
+ */
1446
+ offset?: number | null;
1447
+ /**
1448
+ * UTF-8 文本;二进制文件 `text` 为空且 `binary = true`。`encoding = base64` 时恒为空。
1126
1449
  */
1127
1450
  text: string;
1451
+ /**
1452
+ * 文件在读到的这一段**之后**还有内容(`offset + 读到的字节数 < bytes`)。
1453
+ */
1128
1454
  truncated: boolean;
1129
1455
  }
1130
1456
  export interface JobCancelParams {
@@ -1160,6 +1486,12 @@ export interface AuditEntry {
1160
1486
  target?: string | null;
1161
1487
  ts_ms: number;
1162
1488
  }
1489
+ /**
1490
+ * `node.get_config` / `node.set_config` 的结果:白名单里的全部配置项(顺序固定,按段分组)。
1491
+ */
1492
+ export interface NodeConfigResult {
1493
+ items: ConfigItem[];
1494
+ }
1163
1495
  export interface NodeDevicesResult {
1164
1496
  devices: PeerDevice[];
1165
1497
  }
@@ -1248,6 +1580,10 @@ export interface NodeEnrollStatusResult {
1248
1580
  * `node.info` 结果。
1249
1581
  */
1250
1582
  export interface NodeInfo {
1583
+ /**
1584
+ * `capabilities.blobs` 为 true 时给出。
1585
+ */
1586
+ attachment_limits?: NodeAttachmentLimits | null;
1251
1587
  capabilities: NodeCapabilities;
1252
1588
  name: string;
1253
1589
  node_id: string;
@@ -1255,16 +1591,49 @@ export interface NodeInfo {
1255
1591
  protocol_version: number;
1256
1592
  started_at_ms: number;
1257
1593
  version: string;
1594
+ /**
1595
+ * 主根。多个根时看 `workspace_roots`。
1596
+ */
1258
1597
  workspace_root?: string | null;
1598
+ /**
1599
+ * 所有 workspace 根,主根在最前,额外根按配置顺序。老版本的 daemon 不给,客户端当作只有 `workspace_root` 一个。
1600
+ */
1601
+ workspace_roots?: WorkspaceRootInfo[];
1259
1602
  /**
1260
1603
  * `capabilities.worktree` 为 true 时给出。
1261
1604
  */
1262
1605
  worktree?: NodeWorktreeSettings | null;
1263
1606
  }
1607
+ /**
1608
+ * 附件的上限(`node.info`),客户端据此在上传之前就拒绝明显超限的文件。
1609
+ */
1610
+ export interface NodeAttachmentLimits {
1611
+ /**
1612
+ * 单个附件的字节上限(`sessions.max_attachment_bytes`,热加载;这里是 `node.info` 被调用那一刻的值)。
1613
+ */
1614
+ max_bytes: number;
1615
+ /**
1616
+ * 一条消息的附件字节合计上限。
1617
+ */
1618
+ max_message_bytes: number;
1619
+ /**
1620
+ * 一条消息至多带几个附件。
1621
+ */
1622
+ max_per_message: number;
1623
+ }
1264
1624
  export interface NodeCapabilities {
1265
1625
  audit: boolean;
1266
1626
  blobs: boolean;
1627
+ /**
1628
+ * daemon 能把任意类型的文件交给任何会话的 agent(非图片、agent 不原生收的图片落到会话工作目录,ADR-44)。
1629
+ * 为 false(旧 daemon)时客户端只能上传图片。
1630
+ */
1631
+ file_attachments?: boolean;
1267
1632
  fs: boolean;
1633
+ /**
1634
+ * 支持 dev server 预览(`preview.*`,ADR-39),且节点配置 `preview.enabled = true`。
1635
+ */
1636
+ preview?: boolean;
1268
1637
  search: boolean;
1269
1638
  /**
1270
1639
  * 有 workspace(文件夹即项目)。SDK 节点可能没有。
@@ -1275,6 +1644,24 @@ export interface NodeCapabilities {
1275
1644
  */
1276
1645
  worktree?: boolean;
1277
1646
  }
1647
+ /**
1648
+ * 一个 workspace 根(ADR-45)。每个根下的一级子文件夹都是项目。
1649
+ */
1650
+ export interface WorkspaceRootInfo {
1651
+ /**
1652
+ * 现在能用:daemon 启动时它是一个存在的目录,并且现在还在。不可用的根下的项目不出现在列表里,也不能在上面新建 / 克隆;
1653
+ * 配置只在启动时读,修好(挂上外接盘)之后要重启 daemon。
1654
+ */
1655
+ available: boolean;
1656
+ /**
1657
+ * canonical 绝对路径(根不可用时是展开后的配置值)。`workspace.create` / `clone` 的 `root` 取这里的值。
1658
+ */
1659
+ path: string;
1660
+ /**
1661
+ * 主根:放 `.scratch/`,不指定 `root` 时新项目建在这里。恰好有一个。
1662
+ */
1663
+ primary: boolean;
1664
+ }
1278
1665
  /**
1279
1666
  * 节点的 worktree 配置(`config.toml` 的 `[worktree]`),客户端据此决定新建会话的初始选择和分支名预览。
1280
1667
  */
@@ -1288,6 +1675,32 @@ export interface NodeWorktreeSettings {
1288
1675
  */
1289
1676
  default_mode: SessionWorkspaceMode;
1290
1677
  }
1678
+ /**
1679
+ * `node.logs` 参数。
1680
+ */
1681
+ export interface NodeLogsParams {
1682
+ /**
1683
+ * 最低级别:只返回这个级别及更高级别的行。缺省 = 不过滤。
1684
+ */
1685
+ level?: NodeLogLevel | null;
1686
+ /**
1687
+ * 最多返回多少行,缺省 200,最大 1000(超出按 1000)。
1688
+ */
1689
+ lines?: number | null;
1690
+ }
1691
+ /**
1692
+ * `node.logs` 结果。
1693
+ */
1694
+ export interface NodeLogsResult {
1695
+ /**
1696
+ * 日志行,旧的在前、新的在后;每行最多 2 KiB(超出的截断,行尾加 `…`)。
1697
+ */
1698
+ lines: string[];
1699
+ /**
1700
+ * 还有更早的行没有返回(行数到了上限,或扫描的日志量到了上限)。
1701
+ */
1702
+ truncated: boolean;
1703
+ }
1291
1704
  export interface NodePairBeginParams {
1292
1705
  /**
1293
1706
  * `true`(缺省)= 16 位短码(约 79 bit;链接、二维码、默认都是它);`false` = 8 位(约 40 bit),
@@ -1349,6 +1762,15 @@ export interface NodeSetAgentDefaultsParams {
1349
1762
  } | null;
1350
1763
  thinking?: string | null;
1351
1764
  }
1765
+ /**
1766
+ * `node.set_config` 参数。所有改动先校验,任何一项不合法就一项都不写。
1767
+ *
1768
+ * 错误:键不在白名单、被环境变量覆盖、想放宽只能收紧的键 → `forbidden`(`data.field` 是键,`data.reason` 是
1769
+ * `not_editable` / `env_override` / `tighten_only`);值的类型或取值不合法、键重复、`changes` 为空 → `invalid`(`data.field` 是键)。
1770
+ */
1771
+ export interface NodeSetConfigParams {
1772
+ changes: ConfigChange[];
1773
+ }
1352
1774
  /**
1353
1775
  * `node.set_enroll_enabled` 参数:写 `[enroll]` 配置。`password: true` 同时解除锁定、失败计数清零。
1354
1776
  */
@@ -1461,7 +1883,171 @@ export interface PermissionRespondParams {
1461
1883
  request_id: string;
1462
1884
  }
1463
1885
  /**
1464
- * 一个项目 = workspace 根目录下的一个一级子文件夹,或一个关联的本机目录(`kind = linked`)。
1886
+ * `preview.close` 参数:作废这个 label 的全部票据,断开它的全部隧道。
1887
+ */
1888
+ export interface PreviewCloseParams {
1889
+ label: string;
1890
+ }
1891
+ /**
1892
+ * 隧道 `GOAWAY` 帧的载荷(msgpack,只有 daemon 发,stream 0):daemon 要关掉这条隧道,之后不再处理它的帧。
1893
+ */
1894
+ export interface PreviewGoaway {
1895
+ code: PreviewGoawayCode;
1896
+ message?: string | null;
1897
+ }
1898
+ /**
1899
+ * 隧道握手第二条消息(daemon → 预览页)的 payload,JSON。到这一条预览页才确认对端持有票据、是钉住的 daemon。
1900
+ */
1901
+ export interface PreviewHello {
1902
+ expires_at_ms: number;
1903
+ port: number;
1904
+ session_id?: string | null;
1905
+ }
1906
+ /**
1907
+ * `preview.list` 的一项:一张未过期的票据。
1908
+ */
1909
+ export interface PreviewInfo {
1910
+ created_at_ms: number;
1911
+ /**
1912
+ * 签发这张票据的设备。
1913
+ */
1914
+ created_by: string;
1915
+ created_by_name: string;
1916
+ expires_at_ms: number;
1917
+ label: string;
1918
+ port: number;
1919
+ session_id?: string | null;
1920
+ ticket_id: string;
1921
+ /**
1922
+ * 此刻用这张票据建立的隧道数。
1923
+ */
1924
+ tunnels: number;
1925
+ }
1926
+ /**
1927
+ * 预览页的启动参数。Web UI 把它序列化成 JSON、再 base64url(无填充),放进
1928
+ * `<预览 origin>/__anycon/enter#<…>` 的 fragment(浏览器不会把 fragment 发给 hub)。引导页读出后存进预览 origin 的
1929
+ * IndexedDB,立即从地址栏抹掉。
1930
+ */
1931
+ export interface PreviewLaunch {
1932
+ /**
1933
+ * 票据和令牌里较早的那个过期时间。
1934
+ */
1935
+ expires_at_ms: number;
1936
+ label: string;
1937
+ /**
1938
+ * daemon 的设备 id。
1939
+ */
1940
+ node: string;
1941
+ /**
1942
+ * daemon 的 Noise 静态公钥,64 个小写 hex。预览页用它做 NK 握手(钉住 daemon)。
1943
+ */
1944
+ node_public: string;
1945
+ /**
1946
+ * 打开后先导航到的路径(以 `/` 开头,可带查询串)。
1947
+ */
1948
+ path: string;
1949
+ port: number;
1950
+ psk: string;
1951
+ ticket_id: string;
1952
+ /**
1953
+ * hub 签发的预览令牌(`POST /api/preview/tokens`),预览连接凭它向 hub 认证。
1954
+ */
1955
+ token: string;
1956
+ /**
1957
+ * 格式版本,目前是 1。
1958
+ */
1959
+ v: number;
1960
+ }
1961
+ export interface PreviewListResult {
1962
+ previews: PreviewInfo[];
1963
+ }
1964
+ /**
1965
+ * `preview.open` 参数:为本机 `port` 签发一张预览票据。
1966
+ */
1967
+ export interface PreviewOpenParams {
1968
+ port: number;
1969
+ /**
1970
+ * 从哪个会话发起(只用于界面展示和审计;端口是否允许不看它,见 spec/daemon.md § 19.3)。
1971
+ */
1972
+ session_id?: string | null;
1973
+ }
1974
+ /**
1975
+ * `preview.open` 结果。`psk` 是票据的密钥,只交给预览页(放进 [`PreviewLaunch`]),不要写日志、不要发给 hub。
1976
+ */
1977
+ export interface PreviewOpenResult {
1978
+ expires_at_ms: number;
1979
+ /**
1980
+ * 这个端口固定的预览 label(26 位小写 base32),预览 origin 是 `<label>.<预览域名>`。
1981
+ */
1982
+ label: string;
1983
+ port: number;
1984
+ /**
1985
+ * 票据密钥,64 个小写 hex(32 字节),Noise PSK。
1986
+ */
1987
+ psk: string;
1988
+ session_id?: string | null;
1989
+ /**
1990
+ * 票据 id,32 个小写 hex(16 字节)。
1991
+ */
1992
+ ticket_id: string;
1993
+ }
1994
+ export interface PreviewPort {
1995
+ pid?: number | null;
1996
+ port: number;
1997
+ /**
1998
+ * 进程名(可执行文件名,不含参数)。
1999
+ */
2000
+ process?: string | null;
2001
+ session_id?: string | null;
2002
+ source: PreviewPortSource;
2003
+ }
2004
+ /**
2005
+ * `preview.ports` 参数。带 `session_id` 只列这个会话的端口(外加配置里允许的端口)。
2006
+ */
2007
+ export interface PreviewPortsParams {
2008
+ session_id?: string | null;
2009
+ }
2010
+ export interface PreviewPortsResult {
2011
+ detection: PreviewDetection;
2012
+ ports: PreviewPort[];
2013
+ }
2014
+ /**
2015
+ * 隧道 `REQUEST` 帧的载荷(msgpack,字段名为键)。
2016
+ */
2017
+ export interface PreviewRequestHead {
2018
+ /**
2019
+ * 请求头,按原顺序,名字小写。`cookie` 来自预览页自己的 cookie jar;daemon 转发前改写哪些头见
2020
+ * spec/daemon.md § 19.5。
2021
+ */
2022
+ headers: [string, string][];
2023
+ method: string;
2024
+ /**
2025
+ * 以 `/` 开头,可带查询串;不含 scheme 和主机。
2026
+ */
2027
+ path: string;
2028
+ /**
2029
+ * `true`:这是一个 WebSocket 升级请求(`method` 为 `GET`,子协议在 `sec-websocket-protocol` 头里)。
2030
+ */
2031
+ websocket?: boolean;
2032
+ }
2033
+ /**
2034
+ * 隧道 `RESET` 帧的载荷(msgpack):终止这个 stream 的两个方向。
2035
+ */
2036
+ export interface PreviewReset {
2037
+ code: PreviewResetCode;
2038
+ message?: string | null;
2039
+ }
2040
+ /**
2041
+ * 隧道 `RESPONSE` 帧的载荷(msgpack)。WebSocket 流里 `status = 101` 表示升级成功,其他状态码表示被拒,
2042
+ * 后面跟普通响应体。
2043
+ */
2044
+ export interface PreviewResponseHead {
2045
+ encoding?: PreviewBodyEncoding & string;
2046
+ headers: [string, string][];
2047
+ status: number;
2048
+ }
2049
+ /**
2050
+ * 一个项目 = 某个 workspace 根目录下的一个一级子文件夹,或一个关联的本机目录(`kind = linked`)。
1465
2051
  * 元数据全部推导;只有「关联了哪些目录」存在 daemon 的库里。
1466
2052
  */
1467
2053
  export interface Project {
@@ -1483,13 +2069,18 @@ export interface Project {
1483
2069
  missing?: boolean;
1484
2070
  modified_at_ms: number;
1485
2071
  /**
1486
- * 项目名。根目录下的项目和关联的项目共用一个命名空间,客户端的所有操作都用它。
2072
+ * 项目名。所有 workspace 根下的项目和关联的项目共用一个命名空间,客户端的所有操作都用它。
1487
2073
  */
1488
2074
  name: string;
1489
2075
  /**
1490
2076
  * 绝对路径,仅展示用。
1491
2077
  */
1492
2078
  path: string;
2079
+ /**
2080
+ * 文件夹项目所在的 workspace 根(canonical 绝对路径,等于 `node.info.workspace_roots` 里的某一项的 `path`);
2081
+ * 关联项目没有。老版本的 daemon 不给,客户端当作主根。
2082
+ */
2083
+ root?: string | null;
1493
2084
  }
1494
2085
  export interface GitMeta {
1495
2086
  branch?: string | null;
@@ -1612,7 +2203,8 @@ export interface SessionWorktree {
1612
2203
  export interface SessionCreateParams {
1613
2204
  agent: string;
1614
2205
  /**
1615
- * 第一条消息的附件(`blob.put_end` 的结果)。agent 的 `capabilities.attachments` 不含其 mime → `unsupported`。
2206
+ * 第一条消息的附件(`blob.put_end` 的结果)。agent 原生收的 mime(`capabilities.attachments`)交给 adapter,
2207
+ * 其余落到会话工作目录、路径写在交给 agent 的文字里(ADR-44)。
1616
2208
  */
1617
2209
  attachments?: AttachmentRef[];
1618
2210
  /**
@@ -1828,26 +2420,45 @@ export interface SessionRenameParams {
1828
2420
  title: string;
1829
2421
  }
1830
2422
  export interface SessionSearchParams {
2423
+ /**
2424
+ * 最多返回几条命中,默认 20,上限 200。
2425
+ */
1831
2426
  limit?: number | null;
2427
+ /**
2428
+ * 只搜这个项目里的会话。
2429
+ */
1832
2430
  project?: string | null;
2431
+ /**
2432
+ * 空白分隔的若干个词,每个词按前缀匹配、都要出现在同一段文字里;不能为空(`invalid`)。
2433
+ */
1833
2434
  query: string;
1834
2435
  }
1835
2436
  export interface SessionSearchResult {
1836
2437
  hits: SearchHit[];
1837
2438
  }
1838
2439
  export interface SearchHit {
2440
+ /**
2441
+ * 命中的那段文字开始处的事件 seq:用户消息就是 `user_message` 的 seq;assistant 文字是那一段第一个 `text_delta` 的 seq
2442
+ * (长文字每 32 KiB 切一段索引,所以同一条回复可以有几个不同的 seq)。
2443
+ */
1839
2444
  seq: number;
1840
2445
  session_id: string;
1841
2446
  /**
1842
- * 带 `<mark>` 的片段。
2447
+ * 命中处的片段。除了包住命中词的字面 `<mark>` / `</mark>`,里面没有 HTML:会话文字里原有的
2448
+ * `<` `>` `&` 已转义成 `&lt;` `&gt;` `&amp;`,客户端按 `<mark>` 切开后把这三个实体还原成字符、
2449
+ * 当纯文本显示即可,不要当 HTML 解析。
1843
2450
  */
1844
2451
  snippet: string;
2452
+ /**
2453
+ * 会话当前的标题。
2454
+ */
1845
2455
  title: string;
1846
2456
  ts_ms: number;
1847
2457
  }
1848
2458
  export interface SessionSendParams {
1849
2459
  /**
1850
- * `blob.put_end` 的结果,每条至多 20 个。agent 的 `capabilities.attachments` 不含其 mime → `unsupported`。
2460
+ * `blob.put_end` 的结果,每条至多 20 个。agent 原生收的 mime(`capabilities.attachments`)交给 adapter,
2461
+ * 其余落到会话工作目录、路径写在交给 agent 的文字里(ADR-44)。
1851
2462
  */
1852
2463
  attachments?: AttachmentRef[];
1853
2464
  /**
@@ -1912,10 +2523,14 @@ export interface SessionSyncBaseResult {
1912
2523
  export interface TrashEntry {
1913
2524
  bytes: number;
1914
2525
  /**
1915
- * `.trash/` 下的目录名,如 `my-app-20261011T120000Z`。
2526
+ * `.trash/` 下的目录名,如 `my-app-20261011T120000Z`。每个根有自己的 `.trash/`,id 在所有根之间唯一。
1916
2527
  */
1917
2528
  id: string;
1918
2529
  original_name: string;
2530
+ /**
2531
+ * 条目所在(也是 `restore` 还原到)的 workspace 根。老版本的 daemon 不给,客户端当作主根。
2532
+ */
2533
+ root?: string | null;
1919
2534
  trashed_at_ms: number;
1920
2535
  }
1921
2536
  /**
@@ -2012,6 +2627,10 @@ export interface RenamedProject {
2012
2627
  }
2013
2628
  export interface WorkspaceCloneParams {
2014
2629
  name?: string | null;
2630
+ /**
2631
+ * 克隆到哪个 workspace 根下,规则同 `WorkspaceCreateParams.root`。
2632
+ */
2633
+ root?: string | null;
2015
2634
  /**
2016
2635
  * 只允许 `https://`、`ssh://`、`git@host:path` 三种形式。
2017
2636
  */
@@ -2020,6 +2639,11 @@ export interface WorkspaceCloneParams {
2020
2639
  export interface WorkspaceCreateParams {
2021
2640
  git_init?: boolean;
2022
2641
  name: string;
2642
+ /**
2643
+ * 在哪个 workspace 根下新建。必须是 `node.info.workspace_roots` 里的某一项的 `path`;缺省 = 主根;
2644
+ * 不在列表里 → `invalid`,在列表里但现在不可用(`available = false`)→ `not_found`。
2645
+ */
2646
+ root?: string | null;
2023
2647
  }
2024
2648
  /**
2025
2649
  * `workspace.link`:把本机一个已有目录关联为项目。
@@ -2037,6 +2661,9 @@ export interface WorkspaceLinkParams {
2037
2661
  }
2038
2662
  export interface WorkspaceListResult {
2039
2663
  projects: Project[];
2664
+ /**
2665
+ * 主根(`node.info.workspace_roots` 里 `primary` 的那一项)。其余根下的项目看 `Project.root`。
2666
+ */
2040
2667
  root: string;
2041
2668
  }
2042
2669
  export interface WorkspaceNameParams {