@anycon/protocol 0.3.0 → 0.4.1

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
@@ -9,7 +9,15 @@ export type AgentStatus =
9
9
  * 一个目录为什么不能关联为项目(ADR-33 修订,daemon.md § 10)。
10
10
  */
11
11
  export type LinkBlock = "hidden" | "sensitive" | "workspace" | "data_dir" | "filesystem_root";
12
- export type DeviceKind = "daemon" | "web" | "cli" | "sdk";
12
+ /**
13
+ * `rule.update` 的 `clear` 可以清空的可选字段。
14
+ */
15
+ export type ClearableRuleField = "project";
16
+ /**
17
+ * `todo.update` 的 `clear` 可以清空的可选字段。
18
+ */
19
+ export type ClearableTodoField = "project" | "due_ms" | "repeat";
20
+ export type DeviceKind = ("daemon" | "web" | "cli" | "sdk") | "twin" | "unknown";
13
21
  /**
14
22
  * 一项配置能不能被远程客户端改(ADR-43)。
15
23
  */
@@ -236,7 +244,9 @@ export type EnrollRejectReason =
236
244
  | "denied"
237
245
  | "wrong_secret"
238
246
  | "expired"
239
- | "invalid";
247
+ | "invalid"
248
+ | "twin_not_allowed"
249
+ | "unknown";
240
250
  /**
241
251
  * `EnrollReply.status`。
242
252
  */
@@ -559,6 +569,9 @@ export type FsReadEncoding = "text" | "base64";
559
569
  * 信封种类。hub 对每种的处理见 docs/protocol.md § 3。
560
570
  */
561
571
  export type Kind = "handshake" | "data" | "notify" | "control";
572
+ export type JudgeApiFormat = "anthropic" | "openai" | "unknown";
573
+ export type JudgeBackendKind = "api" | "agent" | "unknown";
574
+ export type JudgeProblem = "no_key" | "agent_missing" | "agent_unsupported" | "unknown";
562
575
  /**
563
576
  * 节点配置 `worktree.default` 的取值,也是 `SessionWorkspace` 的两种模式。
564
577
  */
@@ -571,9 +584,20 @@ export type NodeLogLevel = "trace" | "debug" | "info" | "warn" | "error";
571
584
  * `node.security_event.kind`。
572
585
  */
573
586
  export type SecurityEventKind =
574
- "device_enrolled" | "password_failures" | "password_locked" | "password_changed" | "settings_changed";
587
+ | "device_enrolled"
588
+ | "password_failures"
589
+ | "password_locked"
590
+ | "password_changed"
591
+ | "settings_changed"
592
+ | "twin_linked"
593
+ | "twin_unlinked"
594
+ | "unknown";
575
595
  export type NotifyCategory =
576
- ("permission_requested" | "turn_finished" | "error" | "session_idle") | "enroll_requested" | "security";
596
+ | ("permission_requested" | "turn_finished" | "error" | "session_idle")
597
+ | "follow_up"
598
+ | "twin_question"
599
+ | "enroll_requested"
600
+ | "security";
577
601
  /**
578
602
  * 隧道里响应体的编码。`gzip`:`DATA` 帧拼起来是 gzip 流,预览页要先解压;`headers` 里已经去掉
579
603
  * `content-encoding` / `content-length`。
@@ -599,12 +623,55 @@ export type PreviewResetCode =
599
623
  * 项目从哪来。
600
624
  */
601
625
  export type ProjectKind = "folder" | "linked";
626
+ /**
627
+ * 第一条消息里的一段是从哪里来的(`PromptSegment.kind`)。`title` / `body` 是人写的(或照抄模板的),其余是 daemon 加的,
628
+ * 只有 `earlier_reports` 和 `twin_note` 里是 agent / Twin 写的内容。
629
+ */
630
+ export type PromptSegmentKind =
631
+ "title" | "body" | "earlier_reports" | "state_usage" | "closing_report" | "no_push" | "twin_note" | "unknown";
602
632
  export type PullRequestState = "open" | "draft" | "merged" | "closed";
603
633
  /**
604
634
  * 一条内层消息。解码时按字段判别:有 `method` 且有 `id` 是请求,有 `method` 无 `id` 是通知,否则是响应。
605
635
  */
606
636
  export type RpcMessage = RpcRequest | RpcNotification | RpcResponse;
607
637
  export type RpcId = number | string;
638
+ /**
639
+ * 规则是怎么来的。
640
+ */
641
+ export type RuleSourceKind = "manual" | "answer" | "extracted" | "agent" | "unknown";
642
+ /**
643
+ * 规则的状态。
644
+ */
645
+ export type RuleStatus = "pending" | "active" | "disabled" | "rejected" | "unknown";
646
+ /**
647
+ * 规则在节点之间的同步范围,由客户端同步(docs/spec/daemon.md § 23.8)。
648
+ */
649
+ export type RuleSync = "node" | "group" | "unknown";
650
+ /**
651
+ * `rule.add` 的调用方可以声明的来源种类(`extracted` 只有 daemon 自己提炼时才有,`agent` 由 `agent: true` 决定)。
652
+ */
653
+ export type RuleAddSourceKind = "manual" | "answer";
654
+ /**
655
+ * `rule.add` 可以直接给的状态。
656
+ */
657
+ export type RuleAddStatus = "active" | "pending" | "disabled" | "rejected";
658
+ export type JudgeErrorCode =
659
+ | "timeout"
660
+ | "network"
661
+ | "http"
662
+ | "auth"
663
+ | "rate_limited"
664
+ | "bad_output"
665
+ | "agent_failed"
666
+ | "cancelled"
667
+ | "internal"
668
+ | "unknown";
669
+ export type ExtractRunStatus = "running" | "done" | "failed" | "unknown";
670
+ export type ExtractTrigger = "manual" | "auto" | "unknown";
671
+ /**
672
+ * 派发时生效的规则没有注入的原因(`TodoEventData::Dispatched.rules_skipped`)。
673
+ */
674
+ export type RulesSkipped = "unsupported" | "unknown";
608
675
  /**
609
676
  * 归档 / 删除会话时怎么处理它的 worktree。
610
677
  */
@@ -643,6 +710,258 @@ export type SessionWorkspace =
643
710
  export type ClearableSetting =
644
711
  ("thinking" | "mode" | "system_prompt_append" | "max_turns" | "max_budget_usd") | "model" | "env";
645
712
  export type SyncOutcome = "up_to_date" | "merged" | "conflicts" | "aborted";
713
+ /**
714
+ * 清单项派出的会话现在的情况(算出来的,不存;`Todo.activity`)。
715
+ */
716
+ export type TodoActivity = "working" | "waiting" | "review" | "unknown";
717
+ /**
718
+ * 清单项的处理人;旧节点没有这个字段时由人处理。
719
+ */
720
+ export type TodoHandler = "me" | "twin" | "unknown";
721
+ /**
722
+ * `kind = interval` 的规则在哪些日子里生效(`TodoRepeat.days`)。
723
+ */
724
+ export type TodoRepeatDays = "daily" | "weekdays" | "weekly" | "unknown";
725
+ /**
726
+ * 周期项的重复方式(`TodoRepeat.kind`)。
727
+ */
728
+ export type TodoRepeatKind = "daily" | "weekdays" | "weekly" | "interval" | "unknown";
729
+ /**
730
+ * 一项是谁记的。
731
+ */
732
+ export type TodoSourceKind = "device" | "local" | "agent" | "twin" | "repeat" | "unknown";
733
+ /**
734
+ * 清单项的状态。这一步 daemon 不限制状态之间怎么转。
735
+ */
736
+ export type TodoState = "open" | "working" | "waiting" | "review" | "done" | "dropped";
737
+ /**
738
+ * 「经过」里的一条:只追加,没有修改、删除一条的方法;删除这一项时一起删。
739
+ */
740
+ export type TodoEvent = {
741
+ /**
742
+ * 这一项内从 1 递增。
743
+ */
744
+ seq: number;
745
+ ts_ms: number;
746
+ } & TodoEvent1;
747
+ export type TodoEvent1 =
748
+ | {
749
+ agent: string;
750
+ by: TodoActor;
751
+ kind: "dispatched";
752
+ no_push: boolean;
753
+ /**
754
+ * 注入这个会话的系统提示的规则(`rule.*`,docs/spec/daemon.md § 23.5),按在文字里的顺序。没有注入时缺省(旧 daemon 的记录也没有)。
755
+ */
756
+ rules?: string[];
757
+ /**
758
+ * 有生效的规则、但没有注入的原因。
759
+ */
760
+ rules_skipped?: RulesSkipped | null;
761
+ session_id: string;
762
+ workspace_mode: SessionWorkspaceMode;
763
+ }
764
+ | {
765
+ kind: "result";
766
+ session_id: string;
767
+ text: string;
768
+ truncated: boolean;
769
+ turn: number;
770
+ }
771
+ | {
772
+ by: TodoActor;
773
+ from: TodoState;
774
+ kind: "state";
775
+ to: TodoState;
776
+ }
777
+ | {
778
+ done?: boolean;
779
+ kind: "handed_back";
780
+ reason: string;
781
+ run_id?: string | null;
782
+ }
783
+ | {
784
+ by: TodoActor;
785
+ kind: "taken_over";
786
+ node_id?: string | null;
787
+ }
788
+ | {
789
+ action: TwinAction;
790
+ kind: "twin_decision";
791
+ reason: string;
792
+ run_id: string;
793
+ }
794
+ | {
795
+ kind: "twin_question";
796
+ question_id: string;
797
+ }
798
+ | {
799
+ by: TodoActor;
800
+ from: TodoHandler;
801
+ kind: "handler";
802
+ to: TodoHandler;
803
+ }
804
+ | {
805
+ at_ms: number;
806
+ kind: "repeat_created";
807
+ manual?: boolean;
808
+ todo_id: string;
809
+ }
810
+ | {
811
+ at_ms: number;
812
+ kind: "repeat_skipped";
813
+ }
814
+ | {
815
+ kind: "remote_dispatched";
816
+ node_id: string;
817
+ session_id: string;
818
+ todo_id: string;
819
+ }
820
+ | {
821
+ kind: "remote_result";
822
+ node_id: string;
823
+ session_id: string;
824
+ text: string;
825
+ }
826
+ | {
827
+ event: PrEventKind;
828
+ kind: "pr_event";
829
+ session_id: string;
830
+ url?: string | null;
831
+ }
832
+ | {
833
+ kind: "state_usage";
834
+ /**
835
+ * `todo.state_get` / `state_list` / `state_unseen` 的次数。
836
+ */
837
+ reads: number;
838
+ session_id: string;
839
+ turn: number;
840
+ /**
841
+ * `todo.state_set` / `state_delete` 的次数。
842
+ */
843
+ writes: number;
844
+ }
845
+ | {
846
+ kind: "unknown";
847
+ };
848
+ export type TwinAction = "dispatch" | "ask_user" | "ask_advisor" | "wait" | "hand_back" | "done" | "unknown";
849
+ /**
850
+ * [`TodoEventData::PrEvent`] 的种类。
851
+ */
852
+ export type PrEventKind = "merged" | "checks_failed" | "closed" | "reviewed" | "unknown";
853
+ /**
854
+ * 「经过」里的一条的内容;`kind` 是线路上的标签。
855
+ */
856
+ export type TodoEventData =
857
+ | {
858
+ agent: string;
859
+ by: TodoActor;
860
+ kind: "dispatched";
861
+ no_push: boolean;
862
+ /**
863
+ * 注入这个会话的系统提示的规则(`rule.*`,docs/spec/daemon.md § 23.5),按在文字里的顺序。没有注入时缺省(旧 daemon 的记录也没有)。
864
+ */
865
+ rules?: string[];
866
+ /**
867
+ * 有生效的规则、但没有注入的原因。
868
+ */
869
+ rules_skipped?: RulesSkipped | null;
870
+ session_id: string;
871
+ workspace_mode: SessionWorkspaceMode;
872
+ }
873
+ | {
874
+ kind: "result";
875
+ session_id: string;
876
+ text: string;
877
+ truncated: boolean;
878
+ turn: number;
879
+ }
880
+ | {
881
+ by: TodoActor;
882
+ from: TodoState;
883
+ kind: "state";
884
+ to: TodoState;
885
+ }
886
+ | {
887
+ done?: boolean;
888
+ kind: "handed_back";
889
+ reason: string;
890
+ run_id?: string | null;
891
+ }
892
+ | {
893
+ by: TodoActor;
894
+ kind: "taken_over";
895
+ node_id?: string | null;
896
+ }
897
+ | {
898
+ action: TwinAction;
899
+ kind: "twin_decision";
900
+ reason: string;
901
+ run_id: string;
902
+ }
903
+ | {
904
+ kind: "twin_question";
905
+ question_id: string;
906
+ }
907
+ | {
908
+ by: TodoActor;
909
+ from: TodoHandler;
910
+ kind: "handler";
911
+ to: TodoHandler;
912
+ }
913
+ | {
914
+ at_ms: number;
915
+ kind: "repeat_created";
916
+ manual?: boolean;
917
+ todo_id: string;
918
+ }
919
+ | {
920
+ at_ms: number;
921
+ kind: "repeat_skipped";
922
+ }
923
+ | {
924
+ kind: "remote_dispatched";
925
+ node_id: string;
926
+ session_id: string;
927
+ todo_id: string;
928
+ }
929
+ | {
930
+ kind: "remote_result";
931
+ node_id: string;
932
+ session_id: string;
933
+ text: string;
934
+ }
935
+ | {
936
+ event: PrEventKind;
937
+ kind: "pr_event";
938
+ session_id: string;
939
+ url?: string | null;
940
+ }
941
+ | {
942
+ kind: "state_usage";
943
+ /**
944
+ * `todo.state_get` / `state_list` / `state_unseen` 的次数。
945
+ */
946
+ reads: number;
947
+ session_id: string;
948
+ turn: number;
949
+ /**
950
+ * `todo.state_set` / `state_delete` 的次数。
951
+ */
952
+ writes: number;
953
+ }
954
+ | {
955
+ kind: "unknown";
956
+ };
957
+ export type TwinDecisionOutcome = "executed" | "skipped" | "unknown";
958
+ export type TwinSkipReason =
959
+ ("invalid" | "out_of_scope" | "no_capacity" | "budget" | "unknown") | "remote_unavailable" | "remote_refused";
960
+ export type TwinRunResult = "done" | "idle" | "budget" | "failed" | "cancelled" | "unknown";
961
+ export type TwinTrigger = ("todo" | "session" | "answer" | "tick" | "manual" | "unknown") | "pr";
962
+ export type TwinState = "running" | "idle" | "paused" | "disabled" | "not_configured" | "budget" | "unknown";
963
+ export type TwinQuestionStatus = "open" | "answered" | "void" | "unknown";
964
+ export type ClearableTwinField = "agent" | "model" | "mode" | "unknown";
646
965
 
647
966
  /**
648
967
  * 仅用于导出 schema,不在线上传输。字段名即 TS / Python 的类型名。
@@ -661,6 +980,8 @@ export interface ProtocolSchema {
661
980
  blob_put_begin_result: BlobPutBeginResult;
662
981
  blob_put_chunk_params: BlobPutChunkParams;
663
982
  browse_entry: BrowseEntry;
983
+ clearable_rule_field: ClearableRuleField;
984
+ clearable_todo_field: ClearableTodoField;
664
985
  client_info: ClientInfo;
665
986
  config_change: ConfigChange;
666
987
  config_editable: ConfigEditable;
@@ -721,6 +1042,7 @@ export interface ProtocolSchema {
721
1042
  node_set_enroll_enabled_params: NodeSetEnrollEnabledParams;
722
1043
  node_set_enroll_password_params: NodeSetEnrollPasswordParams;
723
1044
  node_stats: NodeStats;
1045
+ node_twin_link_code_result: NodeTwinLinkCodeResult;
724
1046
  node_worktree_settings: NodeWorktreeSettings;
725
1047
  notify_body: NotifyBody;
726
1048
  notify_detail: NotifyDetail;
@@ -752,11 +1074,50 @@ export interface ProtocolSchema {
752
1074
  preview_response_head: PreviewResponseHead;
753
1075
  project: Project;
754
1076
  project_kind: ProjectKind;
1077
+ prompt_segment: PromptSegment;
1078
+ prompt_segment_kind: PromptSegmentKind;
755
1079
  pull_request_info: PullRequestInfo;
756
1080
  pull_request_state: PullRequestState;
757
1081
  quota: Quota;
1082
+ repeat_state_changed: RepeatStateChanged;
1083
+ repeat_state_clear_params: RepeatStateClearParams;
1084
+ repeat_state_clear_result: RepeatStateClearResult;
1085
+ repeat_state_delete_params: RepeatStateDeleteParams;
1086
+ repeat_state_delete_result: RepeatStateDeleteResult;
1087
+ repeat_state_entry: RepeatStateEntry;
1088
+ repeat_state_get_params: RepeatStateGetParams;
1089
+ repeat_state_get_result: RepeatStateGetResult;
1090
+ repeat_state_list_params: RepeatStateListParams;
1091
+ repeat_state_list_result: RepeatStateListResult;
1092
+ repeat_state_set_params: RepeatStateSetParams;
1093
+ repeat_state_set_result: RepeatStateSetResult;
1094
+ repeat_state_unseen_params: RepeatStateUnseenParams;
1095
+ repeat_state_unseen_result: RepeatStateUnseenResult;
758
1096
  rpc_error: RpcError;
759
1097
  rpc_message: RpcMessage;
1098
+ rule: Rule;
1099
+ rule_add_params: RuleAddParams;
1100
+ rule_add_source: RuleAddSource;
1101
+ rule_add_source_kind: RuleAddSourceKind;
1102
+ rule_add_status: RuleAddStatus;
1103
+ rule_budget: RuleBudget;
1104
+ rule_changed: RuleChanged;
1105
+ rule_delete_params: RuleDeleteParams;
1106
+ rule_extract_done: RuleExtractDone;
1107
+ rule_extract_params: RuleExtractParams;
1108
+ rule_extract_result: RuleExtractResult;
1109
+ rule_extract_runs_params: RuleExtractRunsParams;
1110
+ rule_extract_runs_result: RuleExtractRunsResult;
1111
+ rule_list_params: RuleListParams;
1112
+ rule_list_result: RuleListResult;
1113
+ rule_preview_params: RulePreviewParams;
1114
+ rule_preview_result: RulePreviewResult;
1115
+ rule_source: RuleSource;
1116
+ rule_source_kind: RuleSourceKind;
1117
+ rule_status: RuleStatus;
1118
+ rule_sync: RuleSync;
1119
+ rule_update_params: RuleUpdateParams;
1120
+ rules_skipped: RulesSkipped;
760
1121
  security_event_kind: SecurityEventKind;
761
1122
  session_archive_params: SessionArchiveParams;
762
1123
  session_changed: SessionChanged;
@@ -772,12 +1133,14 @@ export interface ProtocolSchema {
772
1133
  session_id_params: SessionIdParams;
773
1134
  session_list_params: SessionListParams;
774
1135
  session_list_result: SessionListResult;
1136
+ session_mark_read_params: SessionMarkReadParams;
775
1137
  session_promote_params: SessionPromoteParams;
776
1138
  session_rename_params: SessionRenameParams;
777
1139
  session_search_params: SessionSearchParams;
778
1140
  session_search_result: SessionSearchResult;
779
1141
  session_send_params: SessionSendParams;
780
1142
  session_send_result: SessionSendResult;
1143
+ session_set_marks_params: SessionSetMarksParams;
781
1144
  session_set_settings_params: SessionSetSettingsParams;
782
1145
  session_set_settings_result: SessionSetSettingsResult;
783
1146
  session_settings: SessionSettings;
@@ -788,7 +1151,60 @@ export interface ProtocolSchema {
788
1151
  session_workspace_mode: SessionWorkspaceMode;
789
1152
  session_worktree: SessionWorktree;
790
1153
  sync_outcome: SyncOutcome;
1154
+ todo: Todo;
1155
+ todo_activity: TodoActivity;
1156
+ todo_actor: TodoActor;
1157
+ todo_add_params: TodoAddParams;
1158
+ todo_changed: TodoChanged;
1159
+ todo_cursor: TodoCursor;
1160
+ todo_delete_params: TodoDeleteParams;
1161
+ todo_dispatch_params: TodoDispatchParams;
1162
+ todo_dispatch_preview_params: TodoDispatchPreviewParams;
1163
+ todo_dispatch_preview_result: TodoDispatchPreviewResult;
1164
+ todo_dispatch_result: TodoDispatchResult;
1165
+ todo_event: TodoEvent;
1166
+ todo_event_data: TodoEventData;
1167
+ todo_event_notice: TodoEventNotice;
1168
+ todo_history_params: TodoHistoryParams;
1169
+ todo_history_result: TodoHistoryResult;
1170
+ todo_id_params: TodoIdParams;
1171
+ todo_list_params: TodoListParams;
1172
+ todo_list_result: TodoListResult;
1173
+ todo_remote: TodoRemote;
1174
+ todo_repeat_preview_params: TodoRepeatPreviewParams;
1175
+ todo_repeat_preview_result: TodoRepeatPreviewResult;
1176
+ todo_source: TodoSource;
1177
+ todo_source_kind: TodoSourceKind;
1178
+ todo_state: TodoState;
1179
+ todo_update_params: TodoUpdateParams;
791
1180
  trash_entry: TrashEntry;
1181
+ twin_answer_params: TwinAnswerParams;
1182
+ twin_changed: TwinChanged;
1183
+ twin_day_stats: TwinDayStats;
1184
+ twin_decision: TwinDecision;
1185
+ twin_dry_run_result: TwinDryRunResult;
1186
+ twin_get_params: TwinGetParams;
1187
+ twin_get_result: TwinGetResult;
1188
+ twin_link: TwinLink;
1189
+ twin_link_params: TwinLinkParams;
1190
+ twin_links_result: TwinLinksResult;
1191
+ twin_peer_agent: TwinPeerAgent;
1192
+ twin_peer_status: TwinPeerStatus;
1193
+ twin_question: TwinQuestion;
1194
+ twin_question_notice: TwinQuestionNotice;
1195
+ twin_questions_params: TwinQuestionsParams;
1196
+ twin_questions_result: TwinQuestionsResult;
1197
+ twin_run: TwinRun;
1198
+ twin_run_brief: TwinRunBrief;
1199
+ twin_runs_params: TwinRunsParams;
1200
+ twin_runs_result: TwinRunsResult;
1201
+ twin_scope: TwinScope;
1202
+ twin_set_params: TwinSetParams;
1203
+ twin_state: TwinState;
1204
+ twin_stats_params: TwinStatsParams;
1205
+ twin_stats_result: TwinStatsResult;
1206
+ twin_today: TwinToday;
1207
+ twin_unlink_params: TwinUnlinkParams;
792
1208
  workspace_branches_params: WorkspaceBranchesParams;
793
1209
  workspace_branches_result: WorkspaceBranchesResult;
794
1210
  workspace_browse_params: WorkspaceBrowseParams;
@@ -865,12 +1281,22 @@ export interface AgentCapabilities {
865
1281
  */
866
1282
  interject: boolean;
867
1283
  interrupt: boolean;
1284
+ /**
1285
+ * 能做一次性调用:不开会话、没有工具,给 `kind = "agent"` 的判断后端用(docs/spec/daemon.md § 25.1)。
1286
+ * 旧 daemon 没有这个字段,按 false。
1287
+ */
1288
+ oneshot?: boolean;
868
1289
  /**
869
1290
  * 进程退出后能否续接。
870
1291
  */
871
1292
  resume: boolean;
872
1293
  rewind: boolean;
873
1294
  structured_output: boolean;
1295
+ /**
1296
+ * 会话的 `system_prompt_append` 真的会交给 agent(docs/spec/daemon.md § 6.3)。为 false(ACP agent、旧 daemon)时,
1297
+ * 决策档案里的规则注入不到它的会话里(§ 23.5)。
1298
+ */
1299
+ system_prompt?: boolean;
874
1300
  /**
875
1301
  * 会不会发 `thinking_delta`。
876
1302
  */
@@ -926,6 +1352,10 @@ export interface ModeInfo {
926
1352
  id: string;
927
1353
  label: string;
928
1354
  risk: ModeRisk;
1355
+ /**
1356
+ * 无人值守时可以使用;由 agent 自己处理自动审批。
1357
+ */
1358
+ unattended?: boolean;
929
1359
  }
930
1360
  /**
931
1361
  * agent 特定的其他选项(Codex fast mode、ACP 自定义 configOptions…)。客户端用通用控件渲染。
@@ -1333,9 +1763,36 @@ export interface Usage {
1333
1763
  cost_usd?: number | null;
1334
1764
  duration_ms: number;
1335
1765
  input_tokens?: number | null;
1766
+ /**
1767
+ * turn 结束时 agent 报过的账号用量窗口(套餐的 5 小时窗口、周窗口…),先账号级后按模型的、短窗口在前。
1768
+ * 这是账号的状态,不是这个会话的:同一个账号的其它会话也在消耗它。agent 不报就为空。
1769
+ */
1770
+ limits?: UsageWindow[];
1336
1771
  model?: string | null;
1337
1772
  output_tokens?: number | null;
1338
1773
  }
1774
+ /**
1775
+ * `Usage.limits` 的一项:agent 报的一个用量窗口的占用。数字都来自上游,adapter 不估算。
1776
+ */
1777
+ export interface UsageWindow {
1778
+ /**
1779
+ * 只对某个模型(或模型系列)计的窗口:它的名字(Claude Code 的 `opus` / `sonnet`,Codex 计量桶的
1780
+ * `normalModelSlug`)。缺省 = 账号级的窗口。
1781
+ */
1782
+ model?: string | null;
1783
+ /**
1784
+ * 窗口恢复(清零)的时间。上游没给就缺省。
1785
+ */
1786
+ resets_at_ms?: number | null;
1787
+ /**
1788
+ * 已用的百分比(四舍五入)。上游报的超过 100 时照报。
1789
+ */
1790
+ used_percent: number;
1791
+ /**
1792
+ * 窗口长度(分钟):300 = 5 小时,10080 = 一周。上游没说就缺省。
1793
+ */
1794
+ window_minutes?: number | null;
1795
+ }
1339
1796
  /**
1340
1797
  * 会话设置。`session.create` 和 `session.set_settings` 都收它;值来自 `AgentInfo`。
1341
1798
  */
@@ -1608,11 +2065,28 @@ export interface NodeInfo {
1608
2065
  */
1609
2066
  attachment_limits?: NodeAttachmentLimits | null;
1610
2067
  capabilities: NodeCapabilities;
2068
+ /**
2069
+ * 分组名(`[hub] group`):名字相同的节点客户端合并显示;是标签,不是访问控制。为空或旧 daemon 时不给。
2070
+ */
2071
+ group?: string | null;
2072
+ /**
2073
+ * 判断后端的脱敏状态。
2074
+ */
2075
+ judge?: JudgeInfo | null;
1611
2076
  name: string;
1612
2077
  node_id: string;
1613
2078
  platform: string;
1614
2079
  protocol_version: number;
1615
2080
  started_at_ms: number;
2081
+ /**
2082
+ * `[twin] accept_links`:这个节点现在接受别的节点的 Twin 连接(docs/spec/daemon.md § 27.2)。旧 daemon 没有这个字段,读作 `false`。
2083
+ */
2084
+ twin_accept_links?: boolean;
2085
+ /**
2086
+ * 更新检查(ADR-57)知道有比这个 daemon 更新的正式版本时给出;没有更新的版本、检查关着、还没检查成功过,
2087
+ * 以及旧 daemon,都不给。
2088
+ */
2089
+ update_available?: NodeUpdateAvailable | null;
1616
2090
  version: string;
1617
2091
  /**
1618
2092
  * 主根。多个根时看 `workspace_roots`。
@@ -1657,7 +2131,46 @@ export interface NodeCapabilities {
1657
2131
  * 支持 dev server 预览(`preview.*`,ADR-39),且节点配置 `preview.enabled = true`。
1658
2132
  */
1659
2133
  preview?: boolean;
2134
+ /**
2135
+ * 支持目录预览(`preview.open { dir }`,ADR-62),且节点开着预览。旧 daemon 没有这个字段,读作 false。
2136
+ */
2137
+ preview_dir?: boolean;
2138
+ /**
2139
+ * 支持规则提炼 RPC;没有该字段时按不支持处理。
2140
+ */
2141
+ rule_extract?: boolean;
2142
+ /**
2143
+ * 支持决策档案(`rule.*`,docs/spec/daemon.md § 23)。旧 daemon 没有这个字段,读作 false。
2144
+ */
2145
+ rules?: boolean;
1660
2146
  search: boolean;
2147
+ /**
2148
+ * 支持清单(`todo.*`,docs/spec/daemon.md § 21)。旧 daemon 没有这个字段,读作 false。
2149
+ */
2150
+ todo?: boolean;
2151
+ /**
2152
+ * 支持周期项(`Todo.repeat`,docs/spec/daemon.md § 26.9)。旧 daemon 没有这个字段,读作 false。
2153
+ */
2154
+ todo_repeat?: boolean;
2155
+ /**
2156
+ * 周期项支持 `kind = interval`、`auto_close`、`todo.repeat_now` 和 `repeat_created.manual`(docs/spec/daemon.md § 26.9)。
2157
+ * 旧 daemon 没有这个字段,读作 false。
2158
+ */
2159
+ todo_repeat_interval?: boolean;
2160
+ /**
2161
+ * 周期项支持跨次状态:`repeat.keep_state` / `state_hint_off`、`todo.state_*`、`todo.state_changed`、`todo.repeat_preview`、
2162
+ * 「经过」的 `state_usage` 和预览的 `segments`(docs/spec/daemon.md § 26.11)。旧 daemon 没有这个字段,读作 false。
2163
+ */
2164
+ todo_repeat_state?: boolean;
2165
+ /**
2166
+ * 支持 Twin 的调度和 RPC。
2167
+ */
2168
+ twin?: boolean;
2169
+ /**
2170
+ * daemon 提供 `twin.stats`,`twin.get` 带 `last_run` / `next_wake_ms` / `queued` / `deferred`,`TwinRun` 带 `usage`
2171
+ * (docs/spec/daemon.md § 26.8)。旧 daemon 没有这个字段,读作 false。
2172
+ */
2173
+ twin_stats?: boolean;
1661
2174
  /**
1662
2175
  * 有 workspace(文件夹即项目)。SDK 节点可能没有。
1663
2176
  */
@@ -1667,6 +2180,39 @@ export interface NodeCapabilities {
1667
2180
  */
1668
2181
  worktree?: boolean;
1669
2182
  }
2183
+ export interface JudgeInfo {
2184
+ advisor?: string | null;
2185
+ backends: JudgeBackendInfo[];
2186
+ daily_calls: number;
2187
+ extract?: string | null;
2188
+ triage?: string | null;
2189
+ }
2190
+ export interface JudgeBackendInfo {
2191
+ agent?: string | null;
2192
+ format?: JudgeApiFormat | null;
2193
+ kind: JudgeBackendKind;
2194
+ model?: string | null;
2195
+ name: string;
2196
+ problem?: JudgeProblem | null;
2197
+ }
2198
+ /**
2199
+ * 有更新的版本(`node.info.update_available`)。daemon 只在 `latest` 是严格的 `X.Y.Z` 且比自己的版本新时给出;
2200
+ * `url` 由 daemon 用版本号拼出来,不取 anycon.ai 回应里的链接。
2201
+ */
2202
+ export interface NodeUpdateAvailable {
2203
+ /**
2204
+ * 得到这个结果的那次检查的时间。
2205
+ */
2206
+ checked_at_ms: number;
2207
+ /**
2208
+ * 最新的正式版本,`X.Y.Z`,不带 `v`。
2209
+ */
2210
+ latest: string;
2211
+ /**
2212
+ * 这个版本的发布页:总是 `https://github.com/anycon-ai/anycon/releases/tag/v<latest>`。
2213
+ */
2214
+ url: string;
2215
+ }
1670
2216
  /**
1671
2217
  * 一个 workspace 根(ADR-45)。每个根下的一级子文件夹都是项目。
1672
2218
  */
@@ -1824,6 +2370,19 @@ export interface SessionCounts {
1824
2370
  running: number;
1825
2371
  waiting_permission: number;
1826
2372
  }
2373
+ /**
2374
+ * `node.twin_link_code` 的结果:B 开了一次只接受 Twin 设备的短码配对。
2375
+ */
2376
+ export interface NodeTwinLinkCodeResult {
2377
+ /**
2378
+ * 16 位短码(`XXXX-XXXX-XXXX-XXXX`)。
2379
+ */
2380
+ code: string;
2381
+ /**
2382
+ * 过期时间(10 分钟后)。
2383
+ */
2384
+ expires_ms: number;
2385
+ }
1827
2386
  /**
1828
2387
  * `kind = notify` 的 body(msgpack)。`category` 是外层唯一有语义的明文字段。
1829
2388
  */
@@ -1922,8 +2481,15 @@ export interface PreviewGoaway {
1922
2481
  * 隧道握手第二条消息(daemon → 预览页)的 payload,JSON。到这一条预览页才确认对端持有票据、是钉住的 daemon。
1923
2482
  */
1924
2483
  export interface PreviewHello {
2484
+ /**
2485
+ * 目录票据的目录。
2486
+ */
2487
+ dir?: string | null;
1925
2488
  expires_at_ms: number;
1926
- port: number;
2489
+ /**
2490
+ * 票据的目标,和 [`PreviewLaunch`] 里的一致才算连对了:端口票据给 `port`,目录票据给 `dir`。
2491
+ */
2492
+ port?: number | null;
1927
2493
  session_id?: string | null;
1928
2494
  }
1929
2495
  /**
@@ -1936,9 +2502,16 @@ export interface PreviewInfo {
1936
2502
  */
1937
2503
  created_by: string;
1938
2504
  created_by_name: string;
2505
+ /**
2506
+ * 目录票据的目录。
2507
+ */
2508
+ dir?: string | null;
1939
2509
  expires_at_ms: number;
1940
2510
  label: string;
1941
- port: number;
2511
+ /**
2512
+ * 端口票据的端口。和 `dir` 正好有一个。
2513
+ */
2514
+ port?: number | null;
1942
2515
  session_id?: string | null;
1943
2516
  ticket_id: string;
1944
2517
  /**
@@ -1952,6 +2525,10 @@ export interface PreviewInfo {
1952
2525
  * IndexedDB,立即从地址栏抹掉。
1953
2526
  */
1954
2527
  export interface PreviewLaunch {
2528
+ /**
2529
+ * 目录票据的目录。
2530
+ */
2531
+ dir?: string | null;
1955
2532
  /**
1956
2533
  * 票据和令牌里较早的那个过期时间。
1957
2534
  */
@@ -1969,7 +2546,10 @@ export interface PreviewLaunch {
1969
2546
  * 打开后先导航到的路径(以 `/` 开头,可带查询串)。
1970
2547
  */
1971
2548
  path: string;
1972
- port: number;
2549
+ /**
2550
+ * 票据的目标:端口或目录,正好有一个(取自 `preview.open` 的结果)。
2551
+ */
2552
+ port?: number | null;
1973
2553
  psk: string;
1974
2554
  ticket_id: string;
1975
2555
  /**
@@ -1985,10 +2565,18 @@ export interface PreviewListResult {
1985
2565
  previews: PreviewInfo[];
1986
2566
  }
1987
2567
  /**
1988
- * `preview.open` 参数:为本机 `port` 签发一张预览票据。
2568
+ * `preview.open` 参数:为本机端口 `port` 或目录 `dir` 签发一张预览票据,两者正好给一个。
1989
2569
  */
1990
2570
  export interface PreviewOpenParams {
1991
- port: number;
2571
+ /**
2572
+ * 目录预览(ADR-62,spec/daemon.md § 19.6):项目名(`fs.list` 路径的第一段,关联项目也是它的名字),
2573
+ * 或 `.scratch`(全部 scratch 会话的工作目录)。要 `capabilities.preview_dir`。
2574
+ */
2575
+ dir?: string | null;
2576
+ /**
2577
+ * 本机端口(dev server)。
2578
+ */
2579
+ port?: number | null;
1992
2580
  /**
1993
2581
  * 从哪个会话发起(只用于界面展示和审计;端口是否允许不看它,见 spec/daemon.md § 19.3)。
1994
2582
  */
@@ -1998,12 +2586,19 @@ export interface PreviewOpenParams {
1998
2586
  * `preview.open` 结果。`psk` 是票据的密钥,只交给预览页(放进 [`PreviewLaunch`]),不要写日志、不要发给 hub。
1999
2587
  */
2000
2588
  export interface PreviewOpenResult {
2589
+ /**
2590
+ * 目录票据的目录(daemon 规整过的写法,预览页的启动参数用这个值)。
2591
+ */
2592
+ dir?: string | null;
2001
2593
  expires_at_ms: number;
2002
2594
  /**
2003
- * 这个端口固定的预览 label(26 位小写 base32),预览 origin 是 `<label>.<预览域名>`。
2595
+ * 这个端口 / 目录固定的预览 label(26 位小写 base32),预览 origin 是 `<label>.<预览域名>`。
2004
2596
  */
2005
2597
  label: string;
2006
- port: number;
2598
+ /**
2599
+ * 端口票据的端口。和 `dir` 正好有一个。
2600
+ */
2601
+ port?: number | null;
2007
2602
  /**
2008
2603
  * 票据密钥,64 个小写 hex(32 字节),Noise PSK。
2009
2604
  */
@@ -2115,6 +2710,13 @@ export interface GitMeta {
2115
2710
  */
2116
2711
  worktree_ready?: boolean;
2117
2712
  }
2713
+ /**
2714
+ * 第一条消息的一段。整条消息是各段的 `text` 按顺序用一个空行(`"\n\n"`)连起来。
2715
+ */
2716
+ export interface PromptSegment {
2717
+ kind: PromptSegmentKind;
2718
+ text: string;
2719
+ }
2118
2720
  /**
2119
2721
  * `gh pr view` 的摘要。
2120
2722
  */
@@ -2134,39 +2736,457 @@ export interface PullRequestInfo {
2134
2736
  title: string;
2135
2737
  url: string;
2136
2738
  }
2137
- export interface RpcError {
2138
- code: number;
2139
- data?: RpcErrorData | null;
2140
- message: string;
2739
+ /**
2740
+ * `todo.state_changed` 通知:一个模板的状态被写、删或清空了。只有模板 id 和条数,不带键和值;客户端要看内容就 `todo.state_list`。
2741
+ */
2742
+ export interface RepeatStateChanged {
2743
+ count: number;
2744
+ /**
2745
+ * 模板的 id。
2746
+ */
2747
+ id: string;
2141
2748
  }
2142
- export interface RpcErrorData {
2143
- code: ErrorCode;
2749
+ /**
2750
+ * `todo.state_clear`:清空这个模板的全部状态。只由人调用。
2751
+ */
2752
+ export interface RepeatStateClearParams {
2144
2753
  /**
2145
- * `invalid_settings` 时的字段名等补充信息。
2754
+ * 带了 `true` → `forbidden`(同自报 `mcp` 的连接)。
2146
2755
  */
2147
- field?: string | null;
2148
- reason?: string | null;
2149
- retry_after_ms?: number | null;
2756
+ agent?: boolean | null;
2757
+ id: string;
2150
2758
  }
2151
- export interface RpcRequest {
2152
- id: RpcId;
2153
- jsonrpc: string;
2154
- method: string;
2155
- params?: unknown;
2759
+ export interface RepeatStateClearResult {
2760
+ removed: number;
2761
+ template_id: string;
2156
2762
  }
2157
- export interface RpcNotification {
2158
- jsonrpc: string;
2159
- method: string;
2160
- params?: unknown;
2763
+ /**
2764
+ * `todo.state_delete`:删一个键;没存着也不是错。
2765
+ */
2766
+ export interface RepeatStateDeleteParams {
2767
+ agent?: boolean | null;
2768
+ id: string;
2769
+ key: string;
2770
+ origin_session?: string | null;
2161
2771
  }
2162
- export interface RpcResponse {
2163
- error?: RpcError | null;
2164
- id: RpcId;
2165
- jsonrpc: string;
2166
- result?: unknown;
2772
+ export interface RepeatStateDeleteResult {
2773
+ count: number;
2774
+ /**
2775
+ * 这个键原来存着。
2776
+ */
2777
+ deleted: boolean;
2778
+ template_id: string;
2167
2779
  }
2168
2780
  /**
2169
- * `session.archive`。没有 worktree 的会话只看 `session_id`。
2781
+ * 状态里的一条。
2782
+ */
2783
+ export interface RepeatStateEntry {
2784
+ /**
2785
+ * 非空,≤ 200 字节,不含控制字符和 U+2028 / U+2029。
2786
+ */
2787
+ key: string;
2788
+ /**
2789
+ * ≤ 1 KiB,可以是空串。
2790
+ */
2791
+ value: string;
2792
+ /**
2793
+ * 最近一次写这个键的时间。
2794
+ */
2795
+ written_ms: number;
2796
+ }
2797
+ /**
2798
+ * `todo.state_get`。
2799
+ */
2800
+ export interface RepeatStateGetParams {
2801
+ /**
2802
+ * 调用方自报「这是 agent」(同 `todo.add`)。
2803
+ */
2804
+ agent?: boolean | null;
2805
+ /**
2806
+ * 模板或它复制出来的某一项。
2807
+ */
2808
+ id: string;
2809
+ key: string;
2810
+ /**
2811
+ * 调用来自哪个会话(CLI 读 `ANYCON_SESSION_ID`)。这个会话存在时,daemon 核对它是从这个模板的某次复制派出的,不是 → `forbidden`。
2812
+ */
2813
+ origin_session?: string | null;
2814
+ }
2815
+ export interface RepeatStateGetResult {
2816
+ /**
2817
+ * 没存着这个键时没有。
2818
+ */
2819
+ entry?: RepeatStateEntry | null;
2820
+ /**
2821
+ * 状态所属的模板。
2822
+ */
2823
+ template_id: string;
2824
+ }
2825
+ /**
2826
+ * `todo.state_list`:按键(按字节)从小到大翻页。
2827
+ */
2828
+ export interface RepeatStateListParams {
2829
+ /**
2830
+ * 只列排在这个键后面的(翻页:上一页最后一条的 `key`)。
2831
+ */
2832
+ after?: string | null;
2833
+ agent?: boolean | null;
2834
+ id: string;
2835
+ /**
2836
+ * 缺省 200,上限 1000(0 按 1)。
2837
+ */
2838
+ limit?: number | null;
2839
+ origin_session?: string | null;
2840
+ /**
2841
+ * 只列以它开头的键。
2842
+ */
2843
+ prefix?: string | null;
2844
+ }
2845
+ export interface RepeatStateListResult {
2846
+ entries: RepeatStateEntry[];
2847
+ has_more: boolean;
2848
+ /**
2849
+ * 匹配 `prefix` 的条数(没给 `prefix` 时等于 `total`)。
2850
+ */
2851
+ matched: number;
2852
+ template_id: string;
2853
+ /**
2854
+ * 这个模板的总条数(不看 `prefix`)。
2855
+ */
2856
+ total: number;
2857
+ }
2858
+ /**
2859
+ * `todo.state_set`:写一个键(已有就覆盖)。满 2 000 条时淘汰最久没被写过的。
2860
+ */
2861
+ export interface RepeatStateSetParams {
2862
+ agent?: boolean | null;
2863
+ id: string;
2864
+ key: string;
2865
+ origin_session?: string | null;
2866
+ /**
2867
+ * 缺省空串。
2868
+ */
2869
+ value?: string;
2870
+ }
2871
+ export interface RepeatStateSetResult {
2872
+ /**
2873
+ * 写完之后的条数。
2874
+ */
2875
+ count: number;
2876
+ /**
2877
+ * 为了不超过上限淘汰了几条(最久没被写过的)。
2878
+ */
2879
+ evicted?: number;
2880
+ template_id: string;
2881
+ }
2882
+ /**
2883
+ * `todo.state_unseen`:给一组键,返回其中没存着的。
2884
+ */
2885
+ export interface RepeatStateUnseenParams {
2886
+ agent?: boolean | null;
2887
+ id: string;
2888
+ /**
2889
+ * 最多 2 000 个;每个的校验同 `key`。
2890
+ */
2891
+ keys: string[];
2892
+ origin_session?: string | null;
2893
+ }
2894
+ export interface RepeatStateUnseenResult {
2895
+ template_id: string;
2896
+ /**
2897
+ * 按请求里的顺序,去重。
2898
+ */
2899
+ unseen: string[];
2900
+ }
2901
+ export interface RpcError {
2902
+ code: number;
2903
+ data?: RpcErrorData | null;
2904
+ message: string;
2905
+ }
2906
+ export interface RpcErrorData {
2907
+ /**
2908
+ * 规则超出注入的字数上限(`rule.add` / `rule.update` 的 `invalid`,`reason = "over_budget"`)时,这次改动之后一个会话拿到的
2909
+ * 规则文字的字节数,和上限(`cap`)。
2910
+ */
2911
+ bytes?: number | null;
2912
+ cap?: number | null;
2913
+ code: ErrorCode;
2914
+ /**
2915
+ * `invalid_settings` 时的字段名等补充信息。
2916
+ */
2917
+ field?: string | null;
2918
+ limit?: number | null;
2919
+ reason?: string | null;
2920
+ retry_after_ms?: number | null;
2921
+ /**
2922
+ * 指向另一项清单项:`todo.repeat_now` 被拒(`reason = "previous_open"`)时,还没关闭的那一份复制出来的项的 id。
2923
+ */
2924
+ todo_id?: string | null;
2925
+ /**
2926
+ * 带条件的写被拒(`todo.delete` 的 `if_updated_ms` 对不上,`reason = "changed"`)时,那一项现在的 `updated_ms`。
2927
+ */
2928
+ updated_ms?: number | null;
2929
+ /**
2930
+ * 判断后端当天已经使用的次数与每日上限(reason = budget)。
2931
+ */
2932
+ used?: number | null;
2933
+ }
2934
+ export interface RpcRequest {
2935
+ id: RpcId;
2936
+ jsonrpc: string;
2937
+ method: string;
2938
+ params?: unknown;
2939
+ }
2940
+ export interface RpcNotification {
2941
+ jsonrpc: string;
2942
+ method: string;
2943
+ params?: unknown;
2944
+ }
2945
+ export interface RpcResponse {
2946
+ error?: RpcError | null;
2947
+ id: RpcId;
2948
+ jsonrpc: string;
2949
+ result?: unknown;
2950
+ }
2951
+ export interface Rule {
2952
+ created_ms: number;
2953
+ /**
2954
+ * 客户端生成的小写带连字符的 UUID;`rule.add` 按它幂等。
2955
+ */
2956
+ id: string;
2957
+ /**
2958
+ * 最近一次被注入某个会话;改它不动 `updated_ms`,也不发 `rule.changed`。
2959
+ */
2960
+ last_injected_ms?: number | null;
2961
+ /**
2962
+ * 最近一次被分拣的决定引用、并且这个决定被执行;改它不动 `updated_ms`,也不发 `rule.changed`(§ 26.10)。
2963
+ */
2964
+ last_referenced_ms?: number | null;
2965
+ /**
2966
+ * 只进这个项目的会话;缺省 = 这个节点上所有项目的会话。
2967
+ */
2968
+ project?: string | null;
2969
+ source: RuleSource;
2970
+ /**
2971
+ * 过期:生效的规则 60 天里没被注入也没被引用,daemon 标上它。过期的规则仍是 `active`,但不注入、不计字数预算;
2972
+ * 只有人能用 `rule.update { stale: false }` 恢复(docs/spec/daemon.md § 23.2、§ 26.10)。缺省 `false`。
2973
+ */
2974
+ stale?: boolean;
2975
+ status: RuleStatus;
2976
+ sync: RuleSync;
2977
+ /**
2978
+ * 1–600 个 Unicode 码点,可以多行;除换行外不含控制字符,不含 U+2028 / U+2029。
2979
+ */
2980
+ text: string;
2981
+ /**
2982
+ * 每次真正的修改严格递增,也是版本号(`if_updated_ms`)。
2983
+ */
2984
+ updated_ms: number;
2985
+ }
2986
+ export interface RuleSource {
2987
+ /**
2988
+ * 经 hub 来的调用带上发起设备的 id(daemon 填)。
2989
+ */
2990
+ device_id?: string | null;
2991
+ kind: RuleSourceKind;
2992
+ /**
2993
+ * `answer`:出自哪个权限请求或提问。
2994
+ */
2995
+ request_id?: string | null;
2996
+ /**
2997
+ * `extracted`:出自会话的哪个事件。
2998
+ */
2999
+ seq?: number | null;
3000
+ /**
3001
+ * `answer` / `extracted`:规则出自哪个会话。
3002
+ */
3003
+ session_id?: string | null;
3004
+ }
3005
+ export interface RuleAddParams {
3006
+ /**
3007
+ * 调用方自报「这是 agent 写的」:状态强制为 `pending`,来源强制为 `agent`。只会让这条规则更不被信任,所以不需要校验。
3008
+ */
3009
+ agent?: boolean | null;
3010
+ /**
3011
+ * UUID。已经存在时原样返回已有的那一条(幂等)。
3012
+ */
3013
+ id: string;
3014
+ /**
3015
+ * 这条规则是哪个会话里的 agent 提的;只在这条规则记成 agent 写的、并且这个会话存在时才记(同 `todo.add` 的 `origin_session`)。
3016
+ */
3017
+ origin_session?: string | null;
3018
+ project?: string | null;
3019
+ /**
3020
+ * 缺省 `{ kind: manual }`。
3021
+ */
3022
+ source?: RuleAddSource | null;
3023
+ /**
3024
+ * 缺省 `active`。
3025
+ */
3026
+ status?: RuleAddStatus | null;
3027
+ /**
3028
+ * 缺省 `node`;agent 写入强制为 `node`。
3029
+ */
3030
+ sync?: RuleSync | null;
3031
+ text: string;
3032
+ }
3033
+ export interface RuleAddSource {
3034
+ kind: RuleAddSourceKind;
3035
+ request_id?: string | null;
3036
+ session_id?: string | null;
3037
+ }
3038
+ /**
3039
+ * 注入的字数预算(docs/spec/daemon.md § 23.4):字节数按**生效**的规则算,不受 `rule.list` 的过滤条件影响。
3040
+ */
3041
+ export interface RuleBudget {
3042
+ /**
3043
+ * 一个会话拿到的规则文字(含模板)的字节上限。
3044
+ */
3045
+ cap: number;
3046
+ /**
3047
+ * 模板的开头加上全节点生效规则的字节数;一条生效的规则都没有时是 0。一个会话拿到的文字是它加上这个会话的项目的 `projects[项目]`
3048
+ * (没有项目规则的会话就是它自己)。只有项目规则生效时,它只是模板的开头。
3049
+ */
3050
+ node_bytes: number;
3051
+ /**
3052
+ * 每个项目的生效规则的字节数(不含 `node_bytes`),键是项目名。一个这个项目的会话拿到的文字是 `node_bytes + projects[项目]`。
3053
+ */
3054
+ projects: {
3055
+ [k: string]: number;
3056
+ };
3057
+ }
3058
+ /**
3059
+ * `rule.changed` 通知:新建、修改、删除后发给所有在线客户端(包括发起的那一台)。`last_injected_ms` 的变化不通知。
3060
+ */
3061
+ export interface RuleChanged {
3062
+ deleted?: boolean;
3063
+ id: string;
3064
+ /**
3065
+ * `deleted = true` 时没有。
3066
+ */
3067
+ rule?: Rule | null;
3068
+ }
3069
+ /**
3070
+ * `rule.delete`:`if_updated_ms` 的语义同 `rule.update`。
3071
+ */
3072
+ export interface RuleDeleteParams {
3073
+ id: string;
3074
+ if_updated_ms?: number | null;
3075
+ }
3076
+ export interface RuleExtractDone {
3077
+ run: ExtractRun;
3078
+ }
3079
+ export interface ExtractRun {
3080
+ added: string[];
3081
+ backend: string;
3082
+ device_id?: string | null;
3083
+ dropped: ExtractDropped;
3084
+ error?: JudgeError | null;
3085
+ finished_ms?: number | null;
3086
+ from_seq: number;
3087
+ id: string;
3088
+ points: number;
3089
+ session_id: string;
3090
+ started_ms: number;
3091
+ status: ExtractRunStatus;
3092
+ to_seq: number;
3093
+ trigger: ExtractTrigger;
3094
+ usage?: JudgeUsage | null;
3095
+ }
3096
+ export interface ExtractDropped {
3097
+ duplicate: number;
3098
+ full: number;
3099
+ invalid: number;
3100
+ }
3101
+ export interface JudgeError {
3102
+ code: JudgeErrorCode;
3103
+ status?: number | null;
3104
+ }
3105
+ export interface JudgeUsage {
3106
+ cost_usd?: number | null;
3107
+ input_tokens?: number | null;
3108
+ output_tokens?: number | null;
3109
+ }
3110
+ export interface RuleExtractParams {
3111
+ session_id: string;
3112
+ }
3113
+ export interface RuleExtractResult {
3114
+ points: number;
3115
+ run?: ExtractRun | null;
3116
+ }
3117
+ export interface RuleExtractRunsParams {
3118
+ limit?: number | null;
3119
+ session_id?: string | null;
3120
+ }
3121
+ export interface RuleExtractRunsResult {
3122
+ daily_calls: number;
3123
+ runs: ExtractRun[];
3124
+ used_today: number;
3125
+ }
3126
+ export interface RuleListParams {
3127
+ /**
3128
+ * 只给 `project` 等于它的规则(去掉首尾空白后比较;不含全节点规则)。
3129
+ */
3130
+ project?: string | null;
3131
+ /**
3132
+ * 只给这个状态的规则。
3133
+ */
3134
+ status?: RuleStatus | null;
3135
+ }
3136
+ export interface RuleListResult {
3137
+ budget: RuleBudget;
3138
+ /**
3139
+ * 按 `created_ms` 从早到晚(同一毫秒的按写入先后)。
3140
+ */
3141
+ rules: Rule[];
3142
+ }
3143
+ export interface RulePreviewParams {
3144
+ /**
3145
+ * 缺省:不属于任何项目的会话(只有全节点规则)。
3146
+ */
3147
+ project?: string | null;
3148
+ }
3149
+ /**
3150
+ * `rule.preview`:现在开一个这个项目的会话会注入的那段文字,和它用到的规则。只读。
3151
+ */
3152
+ export interface RulePreviewResult {
3153
+ /**
3154
+ * `text` 的 UTF-8 字节数。
3155
+ */
3156
+ bytes: number;
3157
+ /**
3158
+ * 写进 `text` 的规则,按它们在 `text` 里的顺序。
3159
+ */
3160
+ rule_ids: string[];
3161
+ /**
3162
+ * 没有生效的规则时为空串。
3163
+ */
3164
+ text: string;
3165
+ }
3166
+ export interface RuleUpdateParams {
3167
+ /**
3168
+ * 要清空的可选字段,在合并之后生效。
3169
+ */
3170
+ clear?: ClearableRuleField[];
3171
+ id: string;
3172
+ /**
3173
+ * 给了而和这条规则现在的 `updated_ms` 不同:什么都不改,`invalid`(`data.reason = "changed"`,`data.updated_ms` 是现在的值)。
3174
+ */
3175
+ if_updated_ms?: number | null;
3176
+ project?: string | null;
3177
+ /**
3178
+ * 只能给 `false`:恢复一条过期的规则(和「变成生效」一样过字数检查)。给 `true` → `invalid`(`data.field = "stale"`)。
3179
+ */
3180
+ stale?: boolean | null;
3181
+ status?: RuleStatus | null;
3182
+ /**
3183
+ * 同组范围仅接受全节点、非待确认的规则。
3184
+ */
3185
+ sync?: RuleSync | null;
3186
+ text?: string | null;
3187
+ }
3188
+ /**
3189
+ * `session.archive`。没有 worktree 的会话只看 `session_id`。
2170
3190
  */
2171
3191
  export interface SessionArchiveParams {
2172
3192
  session_id: string;
@@ -2185,8 +3205,22 @@ export interface SessionChanged {
2185
3205
  * 会话被删除。
2186
3206
  */
2187
3207
  deleted?: boolean;
3208
+ /**
3209
+ * 同 [`SessionSummary::follow_up`]。
3210
+ */
3211
+ follow_up?: boolean;
3212
+ /**
3213
+ * 这条 `session.changed` 是 daemon 因为发了 `follow_up` 通知、消费了 `follow_up` 标记而发的:
3214
+ * 会话刚完成,标记已清成 false。只有这一种情况为 true(出错清标记、`session.set_marks` 都不带);
3215
+ * 它是一次性的事件信号,客户端不存进会话摘要。
3216
+ */
3217
+ follow_up_fired?: boolean;
2188
3218
  last_seq: number;
2189
3219
  pending_permissions: number;
3220
+ /**
3221
+ * 同 [`SessionSummary::read_seq`]。
3222
+ */
3223
+ read_seq?: number;
2190
3224
  session_id: string;
2191
3225
  status: SessionStatus;
2192
3226
  title: string;
@@ -2395,6 +3429,11 @@ export interface SessionSummary {
2395
3429
  */
2396
3430
  background_tasks?: number;
2397
3431
  created_at_ms: number;
3432
+ /**
3433
+ * 用户标了「待处理」(docs/spec/web.md § 4.6.1)。纯标注,不影响会话的行为;只能由 `session.set_marks` 改,
3434
+ * 改它不动 `updated_at_ms`。
3435
+ */
3436
+ follow_up?: boolean;
2398
3437
  id: string;
2399
3438
  /**
2400
3439
  * 最后一个事件的 seq;客户端据此决定要不要拉增量。
@@ -2413,9 +3452,18 @@ export interface SessionSummary {
2413
3452
  * 排队位置(status = queued 时)。
2414
3453
  */
2415
3454
  queue_position?: number | null;
3455
+ /**
3456
+ * 已读水位:用户已经看到的最大 seq(取最大值,只增不减;`session.mark_read` 改)。会话不在运行、且 `last_seq` 大于它时
3457
+ * 客户端显示未读。改它不动 `updated_at_ms`。
3458
+ */
3459
+ read_seq?: number;
2416
3460
  settings: SessionSettings;
2417
3461
  status: SessionStatus;
2418
3462
  title: string;
3463
+ /**
3464
+ * 会话从哪一项派出(`todo.dispatch`,docs/spec/daemon.md § 22.3)。这一项被删除后原样留着,客户端按「来源已删除」显示。
3465
+ */
3466
+ todo_id?: string | null;
2419
3467
  updated_at_ms: number;
2420
3468
  usage?: UsageTotals;
2421
3469
  /**
@@ -2431,6 +3479,13 @@ export interface UsageTotals {
2431
3479
  output_tokens: number;
2432
3480
  turns: number;
2433
3481
  }
3482
+ /**
3483
+ * `session.mark_read`:客户端已经把会话显示到 `seq`。daemon 取 `max(现有水位, min(seq, last_seq))`,所以重复、乱序都无害。
3484
+ */
3485
+ export interface SessionMarkReadParams {
3486
+ seq: number;
3487
+ session_id: string;
3488
+ }
2434
3489
  export interface SessionPromoteParams {
2435
3490
  /**
2436
3491
  * 新项目名。
@@ -2505,6 +3560,13 @@ export interface SessionSendResult {
2505
3560
  */
2506
3561
  turn_id?: number | null;
2507
3562
  }
3563
+ /**
3564
+ * `session.set_marks`:局部更新会话上的用户标注,只改传了的字段。归档不在这里(它有自己的行为约束,见 `session.archive`)。
3565
+ */
3566
+ export interface SessionSetMarksParams {
3567
+ follow_up?: boolean | null;
3568
+ session_id: string;
3569
+ }
2508
3570
  export interface SessionSetSettingsParams {
2509
3571
  /**
2510
3572
  * 要清除(恢复为未设置)的字段,在 `settings` 合并之后生效;两边都出现时以 `clear` 为准。
@@ -2543,18 +3605,735 @@ export interface SessionSyncBaseResult {
2543
3605
  conflicts?: string[];
2544
3606
  outcome: SyncOutcome;
2545
3607
  }
2546
- export interface TrashEntry {
2547
- bytes: number;
3608
+ export interface Todo {
2548
3609
  /**
2549
- * `.trash/` 下的目录名,如 `my-app-20261011T120000Z`。每个根有自己的 `.trash/`,id 在所有根之间唯一。
3610
+ * 派出的会话现在的情况,daemon 每次返回这一项时按会话此刻的状态算出来(docs/spec/daemon.md § 22.3):不存储、不动
3611
+ * `updated_ms`、不进审计。已关闭(`done` / `dropped`)或者没有派发过的项没有这个字段。`state` 只由人设置。
2550
3612
  */
2551
- id: string;
2552
- original_name: string;
3613
+ activity?: TodoActivity | null;
2553
3614
  /**
2554
- * 条目所在(也是 `restore` 还原到)的 workspace 根。老版本的 daemon 不给,客户端当作主根。
3615
+ * Markdown,≤ 16 KiB,可以是空串。
2555
3616
  */
2556
- root?: string | null;
2557
- trashed_at_ms: number;
3617
+ body: string;
3618
+ /**
3619
+ * 进入 `done` / `dropped` 的时间;重新打开时清掉。
3620
+ */
3621
+ closed_ms?: number | null;
3622
+ created_ms: number;
3623
+ /**
3624
+ * 想在什么时候之前处理;只用于显示和排序。
3625
+ */
3626
+ due_ms?: number | null;
3627
+ handler?: TodoHandler & string;
3628
+ /**
3629
+ * 客户端生成的 UUID;`todo.add` 按它幂等。
3630
+ */
3631
+ id: string;
3632
+ /**
3633
+ * 项目名;不校验项目存在,项目改名 / 删除后原样保留。
3634
+ */
3635
+ project?: string | null;
3636
+ /**
3637
+ * 这一项派到别的节点的远程项(docs/spec/daemon.md § 27.4),只追加;没有时缺省为空。由 Twin 连接的 A 侧写。
3638
+ */
3639
+ remote?: TodoRemote[];
3640
+ /**
3641
+ * 周期规则。带它的项是模板:不进分拣、不能派发,到点由 daemon 复制出新的一项(`source.kind = repeat`);只由人设置。
3642
+ */
3643
+ repeat?: TodoRepeat | null;
3644
+ /**
3645
+ * 这一项派出的会话(`todo.dispatch`,docs/spec/daemon.md § 22.3),按派发的先后,最多 20 个。会话被删除后关联留着。
3646
+ */
3647
+ sessions?: string[];
3648
+ source: TodoSource;
3649
+ state: TodoState;
3650
+ /**
3651
+ * 单行,1–200 字符(去掉首尾空白之后)。
3652
+ */
3653
+ title: string;
3654
+ /**
3655
+ * agent 记的、还没有人收下的项。
3656
+ */
3657
+ unreviewed: boolean;
3658
+ updated_ms: number;
3659
+ }
3660
+ /**
3661
+ * 这一项在另一个节点上对应的项(`Todo.remote`)。
3662
+ */
3663
+ export interface TodoRemote {
3664
+ /**
3665
+ * 那个节点的 id。
3666
+ */
3667
+ node_id: string;
3668
+ /**
3669
+ * 那个节点上的项 id。
3670
+ */
3671
+ todo_id: string;
3672
+ }
3673
+ /**
3674
+ * 周期项的规则:按节点的本地时区,每次到点复制出一项新的(docs/spec/daemon.md § 26.9)。
3675
+ */
3676
+ export interface TodoRepeat {
3677
+ /**
3678
+ * `HH:MM`,`00:00`–`23:59`,本地时间。
3679
+ */
3680
+ at: string;
3681
+ /**
3682
+ * Twin 对这个模板复制出来的项执行 `done` 时,daemon 直接把那一项关闭(docs/spec/daemon.md § 26.9);缺省 false,false 时不出现。
3683
+ * 任何一种规则都能带。
3684
+ */
3685
+ auto_close?: boolean;
3686
+ /**
3687
+ * `kind = interval` 时必填(别的种类不能带):在哪些日子里生效。
3688
+ */
3689
+ days?: TodoRepeatDays | null;
3690
+ /**
3691
+ * `kind = interval` 时必填(别的种类不能带):两次之间隔多少分钟,15–720。
3692
+ */
3693
+ every_min?: number | null;
3694
+ /**
3695
+ * 给这个模板一张跨次保留的「键 → 值」小表,由它复制出来的各次会话里的 agent 用 `anycon todo state` 读写
3696
+ * (`todo.state_*`,docs/spec/daemon.md § 26.11)。缺省 false,false 时不出现;只由人设置。关掉不删已有的条目。
3697
+ */
3698
+ keep_state?: boolean;
3699
+ kind: TodoRepeatKind;
3700
+ /**
3701
+ * 下一次复制的时间(节点此刻算出来的,不存;请求里带了也忽略)。模板已关闭时没有。算在 daemon 上,是因为规则按节点的时区。
3702
+ */
3703
+ next_ms?: number | null;
3704
+ /**
3705
+ * `keep_state` 开着时,派发复制出来的项的第一条消息缺省带 daemon 的一段用法说明;这一项为 true 表示不带(用户自己在正文里写)。
3706
+ * 缺省 false,false 时不出现:所以「带说明」是不出现这个字段的那一种,旧客户端没见过它也照常是带说明。只能和 `keep_state` 一起为
3707
+ * true(否则 `invalid`,`data.reason = "state_hint_off"`);只由人设置。
3708
+ */
3709
+ state_hint_off?: boolean;
3710
+ /**
3711
+ * `kind = interval` 时必填(别的种类不能带):当天最后一个时间点不晚于它,`HH:MM`,同一天内严格晚于 `at`。
3712
+ */
3713
+ until?: string | null;
3714
+ /**
3715
+ * 1–7,周一 = 1(ISO);`kind = weekly`、或 `kind = interval` 且 `days = weekly` 时必填,别的情况不能带。
3716
+ */
3717
+ weekday?: number | null;
3718
+ }
3719
+ export interface TodoSource {
3720
+ /**
3721
+ * 经 hub 来的调用带上发起设备的 id;`kind = twin` 时是那台 Twin 设备(另一个节点的 Twin,docs/spec/daemon.md § 27.3)的设备 id。
3722
+ */
3723
+ device_id?: string | null;
3724
+ kind: TodoSourceKind;
3725
+ /**
3726
+ * 这一项是从哪个会话里来的(只有 `kind = agent` 才可能有;会话之后被删,这个字段原样留着)。
3727
+ */
3728
+ session_id?: string | null;
3729
+ /**
3730
+ * `kind = repeat` 时是复制出这一项的周期项(模板)的 id;模板被删后原样留着。
3731
+ */
3732
+ todo_id?: string | null;
3733
+ }
3734
+ /**
3735
+ * 谁做了这件事(审计里的「发起者」,不含会话内容)。
3736
+ */
3737
+ export interface TodoActor {
3738
+ device_id?: string | null;
3739
+ /**
3740
+ * Twin 动作的请求方(local 或设备 id)。
3741
+ */
3742
+ id?: string | null;
3743
+ kind: TodoSourceKind;
3744
+ }
3745
+ export interface TodoAddParams {
3746
+ /**
3747
+ * 调用方自报「这是 agent 加的」。只会让这一项更不被信任,所以不需要校验。
3748
+ */
3749
+ agent?: boolean | null;
3750
+ body?: string | null;
3751
+ due_ms?: number | null;
3752
+ handler?: TodoHandler | null;
3753
+ /**
3754
+ * UUID。已经存在时原样返回已有的那一项(幂等)。
3755
+ */
3756
+ id: string;
3757
+ /**
3758
+ * 这一项从哪个会话里来;daemon 只在这一项记成 `kind = agent`、且这个会话存在时才记。
3759
+ */
3760
+ origin_session?: string | null;
3761
+ project?: string | null;
3762
+ /**
3763
+ * 周期规则(只由人设置:自报 `mcp` 的连接或 `agent: true` → `forbidden`)。
3764
+ */
3765
+ repeat?: TodoRepeat | null;
3766
+ title: string;
3767
+ }
3768
+ /**
3769
+ * `todo.changed` 通知:新建、修改、删除后发给所有在线客户端(包括发起的那一台)。
3770
+ */
3771
+ export interface TodoChanged {
3772
+ deleted?: boolean;
3773
+ id: string;
3774
+ /**
3775
+ * `deleted = true` 时没有。
3776
+ */
3777
+ todo?: Todo | null;
3778
+ }
3779
+ /**
3780
+ * `todo.list` 的翻页游标:上一页最后一项的这两个值。
3781
+ */
3782
+ export interface TodoCursor {
3783
+ id: string;
3784
+ updated_ms: number;
3785
+ }
3786
+ /**
3787
+ * `todo.delete`:`if_updated_ms` 给了、而这一项现在的 `updated_ms` 不是它,就拒绝(`invalid`,`data.reason = "changed"`,
3788
+ * `data.updated_ms` 是现在的值),什么都不删。
3789
+ */
3790
+ export interface TodoDeleteParams {
3791
+ id: string;
3792
+ if_updated_ms?: number | null;
3793
+ }
3794
+ /**
3795
+ * `todo.dispatch`:从一项开一个会话,把会话和这一项关联。
3796
+ */
3797
+ export interface TodoDispatchParams {
3798
+ /**
3799
+ * 同 `session.create`。
3800
+ */
3801
+ agent: string;
3802
+ id: string;
3803
+ /**
3804
+ * 幂等:和 `session.create` 的 `message_id` 一样。同一个值重试(比如回执丢了)返回第一次的结果,不再开第二个会话、
3805
+ * 不多记关联和「经过」;它同时是会话第一条消息的 id。缺省由 daemon 生成(那样就没有幂等)。
3806
+ */
3807
+ message_id?: string | null;
3808
+ /**
3809
+ * 「不 push、不开 PR」(agent 的 `no_push` 选项)。缺省 `true`;所选 agent 没有声明这个选项而它为 `true` → `unsupported`。
3810
+ */
3811
+ no_push?: boolean | null;
3812
+ /**
3813
+ * Twin 的说明(≤ 2048 字节),接在第一条消息后面,不改这一项的正文(docs/spec/daemon.md § 26.4、§ 27.4)。
3814
+ * 只有 Twin 设备(另一个节点的 Twin)能带;别的调用方带了 → `invalid`(`data.field = "note"`,`data.reason = "not_allowed"`)。
3815
+ */
3816
+ note?: string | null;
3817
+ /**
3818
+ * 缺省用这一项的 `project`;两者都没有 → `invalid`(`data.field = "project"`)。给了而且和这一项的不同,派发成功时写回这一项。
3819
+ */
3820
+ project?: string | null;
3821
+ /**
3822
+ * 同 `session.create`。
3823
+ */
3824
+ settings?: SessionSettings;
3825
+ /**
3826
+ * 同 `session.create`。缺省:项目能开 worktree 就用新的 worktree,否则在项目目录里(不看 `worktree.default`)。
3827
+ */
3828
+ workspace?: SessionWorkspace | null;
3829
+ }
3830
+ /**
3831
+ * `todo.dispatch_preview`:这一项现在派发的话,第一条消息会是什么。不改这一项、不开会话;唯一的副作用是先把排着的结果记进「经过」(§ 22.2)。
3832
+ */
3833
+ export interface TodoDispatchPreviewParams {
3834
+ id: string;
3835
+ /**
3836
+ * 同 `todo.dispatch` 的 `no_push`,缺省 `true`(决定第一条消息里有没有「不 push、不开 PR」那一行)。
3837
+ */
3838
+ no_push?: boolean | null;
3839
+ /**
3840
+ * 同 `todo.dispatch` 的 `project`:只影响 `rules_text`(派发会选另一个项目时,那个项目的规则);缺省用这一项自己的项目。
3841
+ */
3842
+ project?: string | null;
3843
+ }
3844
+ export interface TodoDispatchPreviewResult {
3845
+ /**
3846
+ * 此刻派发会发出的第一条消息,一字不差(同一个组装函数、同一套「之前的结果」的选法)。
3847
+ */
3848
+ first_message: string;
3849
+ /**
3850
+ * 此刻开一个这一项的项目的会话会注入的规则文字(docs/spec/daemon.md § 23.5,和 `rule.preview` 同一个函数);这一项没有项目时
3851
+ * 只有全节点规则;没有生效的规则时为空串。不看所选的 agent:它收不收得到由 `AgentInfo.capabilities.system_prompt` 说了算。
3852
+ */
3853
+ rules_text?: string;
3854
+ /**
3855
+ * 同一条消息按来源分段(`first_message` = 各段用 `"\n\n"` 连起来)。旧 daemon 没有,读作空。
3856
+ */
3857
+ segments?: PromptSegment[];
3858
+ }
3859
+ export interface TodoDispatchResult {
3860
+ session: SessionSummary;
3861
+ todo: Todo;
3862
+ }
3863
+ /**
3864
+ * `todo.event` 通知:这一项的「经过」多了一条,发给所有在线客户端。
3865
+ */
3866
+ export interface TodoEventNotice {
3867
+ event: TodoEvent;
3868
+ todo_id: string;
3869
+ }
3870
+ /**
3871
+ * `todo.history` 的参数。
3872
+ */
3873
+ export interface TodoHistoryParams {
3874
+ /**
3875
+ * 只给 `seq` 小于它的事件(翻页用:上一页最后一条的 `seq`)。
3876
+ */
3877
+ before_seq?: number | null;
3878
+ id: string;
3879
+ /**
3880
+ * 缺省 50,上限 200。
3881
+ */
3882
+ limit?: number | null;
3883
+ }
3884
+ export interface TodoHistoryResult {
3885
+ /**
3886
+ * 按 `seq` 从新到旧。
3887
+ */
3888
+ events: TodoEvent[];
3889
+ has_more: boolean;
3890
+ }
3891
+ export interface TodoIdParams {
3892
+ id: string;
3893
+ }
3894
+ export interface TodoListParams {
3895
+ /**
3896
+ * 返回排在这个游标后面的项(按 `(updated_ms, id)` 从新到旧)。
3897
+ */
3898
+ before?: TodoCursor | null;
3899
+ /**
3900
+ * 缺省只给没关闭的;`true` 时也给 `done` / `dropped`。
3901
+ */
3902
+ include_closed?: boolean | null;
3903
+ /**
3904
+ * 缺省 200,上限 1000。
3905
+ */
3906
+ limit?: number | null;
3907
+ project?: string | null;
3908
+ }
3909
+ export interface TodoListResult {
3910
+ /**
3911
+ * 后面还有没给出的项(一页另有 1 MiB 的字节预算,可能少于 `limit`)。
3912
+ */
3913
+ has_more: boolean;
3914
+ todos: Todo[];
3915
+ }
3916
+ /**
3917
+ * `todo.repeat_preview`:一个周期项(模板)复制出来的下一项交给 Twin 时会发出的第一条消息,分段标明来源。
3918
+ * 给了的字段代替存着的值(表单里还没保存的内容)。`id` 还不在库里时,给了 `title` 就按一个还没保存的模板处理
3919
+ * (条数为 0,用法说明里用这个 id:清单项的 id 由客户端生成)。
3920
+ */
3921
+ export interface TodoRepeatPreviewParams {
3922
+ /**
3923
+ * 表单里的正文;校验同 `todo.add`。
3924
+ */
3925
+ body?: string | null;
3926
+ id: string;
3927
+ keep_state?: boolean | null;
3928
+ /**
3929
+ * 缺省 `true`(Twin 派发总是带「不 push、不开 PR」;人手动派发也缺省带)。
3930
+ */
3931
+ no_push?: boolean | null;
3932
+ /**
3933
+ * 表单里的项目,只影响 `rules_text`;空白表示没有项目。
3934
+ */
3935
+ project?: string | null;
3936
+ state_hint_off?: boolean | null;
3937
+ /**
3938
+ * 表单里的标题;校验同 `todo.add`。
3939
+ */
3940
+ title?: string | null;
3941
+ }
3942
+ export interface TodoRepeatPreviewResult {
3943
+ /**
3944
+ * 和真正派发同一个组装函数得到的全文;新复制出来的项还没有之前的报告,所以没有那一段。
3945
+ */
3946
+ first_message: string;
3947
+ /**
3948
+ * 此刻开一个模板所在项目的会话会注入的规则文字(同 `todo.dispatch_preview`)。
3949
+ */
3950
+ rules_text?: string;
3951
+ segments: PromptSegment[];
3952
+ /**
3953
+ * 这个模板现在存着的条数(开关关着时也照实给)。
3954
+ */
3955
+ state_count: number;
3956
+ /**
3957
+ * 状态用法说明的「抄进正文」版本:命令里用模板的 id(对之后每一次复制都有效),不带条数那一行。
3958
+ */
3959
+ state_usage_text: string;
3960
+ }
3961
+ export interface TodoUpdateParams {
3962
+ /**
3963
+ * 调用方自报是 agent;不能把处理人设成 Twin,也不算人收下了这一项。
3964
+ */
3965
+ agent?: boolean | null;
3966
+ body?: string | null;
3967
+ /**
3968
+ * 要清空的可选字段,在合并之后生效。
3969
+ */
3970
+ clear?: ClearableTodoField[];
3971
+ due_ms?: number | null;
3972
+ handler?: TodoHandler | null;
3973
+ id: string;
3974
+ project?: string | null;
3975
+ /**
3976
+ * 设置或替换周期规则(规则变了就从现在起重新算下一次);清掉用 `clear: ["repeat"]`。同 `todo.add`,只由人设置。
3977
+ */
3978
+ repeat?: TodoRepeat | null;
3979
+ /**
3980
+ * `true`:把 `unreviewed` 清掉(`false` 或对已经收下的项会被忽略)。
3981
+ */
3982
+ reviewed?: boolean | null;
3983
+ state?: TodoState | null;
3984
+ title?: string | null;
3985
+ }
3986
+ export interface TrashEntry {
3987
+ bytes: number;
3988
+ /**
3989
+ * `.trash/` 下的目录名,如 `my-app-20261011T120000Z`。每个根有自己的 `.trash/`,id 在所有根之间唯一。
3990
+ */
3991
+ id: string;
3992
+ original_name: string;
3993
+ /**
3994
+ * 条目所在(也是 `restore` 还原到)的 workspace 根。老版本的 daemon 不给,客户端当作主根。
3995
+ */
3996
+ root?: string | null;
3997
+ trashed_at_ms: number;
3998
+ }
3999
+ export interface TwinAnswerParams {
4000
+ answer: string;
4001
+ id: string;
4002
+ }
4003
+ export interface TwinChanged {
4004
+ run?: TwinRun | null;
4005
+ state: TwinState;
4006
+ }
4007
+ export interface TwinRun {
4008
+ decisions: TwinDecision[];
4009
+ dry_run: boolean;
4010
+ error?: JudgeError | null;
4011
+ finished_ms?: number | null;
4012
+ id: string;
4013
+ items: string[];
4014
+ judge_calls: string[];
4015
+ /**
4016
+ * 本机为 local;Twin 连接以设备 id 作请求方。
4017
+ */
4018
+ requester: string;
4019
+ result: TwinRunResult;
4020
+ started_ms: number;
4021
+ triggers: TwinTrigger[];
4022
+ /**
4023
+ * 这次运行所有判断调用的用量之和;调用都没报告的成员缺省。
4024
+ */
4025
+ usage?: JudgeUsage | null;
4026
+ }
4027
+ export interface TwinDecision {
4028
+ action: TwinAction;
4029
+ /**
4030
+ * 派发到哪个节点(节点表里的 id);缺省 = 本机。只用于显示。
4031
+ */
4032
+ node?: string | null;
4033
+ /**
4034
+ * 解析后的动作参数;试跑据此展示计划,不保存原始模型输出。
4035
+ */
4036
+ note?: string | null;
4037
+ options?: string[];
4038
+ outcome: TwinDecisionOutcome;
4039
+ project?: string | null;
4040
+ question?: string | null;
4041
+ question_id?: string | null;
4042
+ reason: string;
4043
+ rules: string[];
4044
+ session_id?: string | null;
4045
+ skip_reason?: TwinSkipReason | null;
4046
+ todo_id: string;
4047
+ }
4048
+ /**
4049
+ * 一个本地日的 Twin 统计。数据来自节点保留的运行记录(90 天)和待办的经过(已删除待办的经过没了),所以旧日子的数字可能变小。
4050
+ */
4051
+ export interface TwinDayStats {
4052
+ /**
4053
+ * 这天由未关闭(非 `done` / `dropped`)变为 `done` 的 `state` 事件数,且本机 Twin 在事件时间或之前派发过这一项。
4054
+ * 已关闭项在 `done` 和 `dropped` 之间改来改去不算;重新打开后再关闭算新的一次。
4055
+ */
4056
+ accepted?: number;
4057
+ /**
4058
+ * 节点本地时间的 `YYYY-MM-DD`。
4059
+ */
4060
+ date: string;
4061
+ decisions?: TwinDecisionCounts;
4062
+ /**
4063
+ * 同 `accepted`,但是变为 `dropped`。
4064
+ */
4065
+ dropped?: number;
4066
+ dry_runs?: number;
4067
+ /**
4068
+ * 这天待办经过里的 `handed_back` 事件数:Twin 没做完就交回给人的次数(`hand_back` 判断、连续 3 次失败、2 小时卡住)。
4069
+ * 不含 `done` 判断(Twin 认为做完了,请人确认)写的那一条。
4070
+ */
4071
+ handed_back?: number;
4072
+ /**
4073
+ * 这天开始的所有运行(含试跑,它们也占预算)发起的判断调用次数。
4074
+ */
4075
+ judge_calls?: number;
4076
+ /**
4077
+ * 这天开始的非试跑运行,按 `result`。
4078
+ */
4079
+ runs?: TwinRunCounts;
4080
+ /**
4081
+ * 非试跑运行里 `outcome = skipped` 的决定数。
4082
+ */
4083
+ skipped?: number;
4084
+ /**
4085
+ * 这一天开始的本地零点。
4086
+ */
4087
+ start_ms: number;
4088
+ /**
4089
+ * 这天的 `taken_over` 事件数,只算本机 Twin 派发过(不晚于事件)的项;Twin 设备派来的会话里的接手不算。
4090
+ */
4091
+ taken_over?: number;
4092
+ /**
4093
+ * 这天每个 `accepted` 事件的(事件时间 - 该项在事件时间或之前最近一次被本机 Twin 派发的时间)之和;平均 = `turnaround_ms / accepted`。
4094
+ */
4095
+ turnaround_ms?: number;
4096
+ /**
4097
+ * 这些调用的用量之和。
4098
+ */
4099
+ usage?: JudgeUsage | null;
4100
+ }
4101
+ /**
4102
+ * 非试跑运行里 `outcome = executed` 的决定按动作的计数。
4103
+ */
4104
+ export interface TwinDecisionCounts {
4105
+ ask_advisor?: number;
4106
+ ask_user?: number;
4107
+ dispatch?: number;
4108
+ done?: number;
4109
+ hand_back?: number;
4110
+ wait?: number;
4111
+ }
4112
+ /**
4113
+ * 非试跑运行按 `result` 的计数。
4114
+ */
4115
+ export interface TwinRunCounts {
4116
+ budget?: number;
4117
+ cancelled?: number;
4118
+ done?: number;
4119
+ failed?: number;
4120
+ idle?: number;
4121
+ }
4122
+ export interface TwinDryRunResult {
4123
+ run: TwinRun;
4124
+ }
4125
+ /**
4126
+ * `twin.get` 的参数。
4127
+ */
4128
+ export interface TwinGetParams {
4129
+ /**
4130
+ * 读谁的范围:缺省 `local`(本机 Twin);也可以是一个已配对的 Twin 设备(`DeviceKind::Twin`)的设备 id,读 B 给这条 Twin 连接
4131
+ * 的设置(docs/spec/daemon.md § 27.3)。不是已存在的 Twin 设备 → `not_found`。
4132
+ */
4133
+ requester?: string | null;
4134
+ }
4135
+ export interface TwinGetResult {
4136
+ configured: boolean;
4137
+ /**
4138
+ * 仍在范围内、但上一次判断放不进输入(§ 26.4 的大小上限)的待办 id。只在内存里,重启后为空。
4139
+ */
4140
+ deferred?: string[];
4141
+ enabled: boolean;
4142
+ /**
4143
+ * 最近一次真实唤醒(不含试跑),按 `started_ms`;可能还在运行(没有 `finished_ms`)。
4144
+ */
4145
+ last_run?: TwinRunBrief | null;
4146
+ /**
4147
+ * 已配置、本机启用且未暂停时:待处理触发的合并截止时间(运行中没有)和下一次兜底 tick 里较早的那个;都没有则缺省。
4148
+ * 读取时的快照,变化时不发通知。
4149
+ */
4150
+ next_wake_ms?: number | null;
4151
+ /**
4152
+ * 在 Twin 范围内(§ 26.1),但既不在 `working` 里也没有未回答的问题的待办 id。
4153
+ */
4154
+ queued?: string[];
4155
+ scope: TwinScope;
4156
+ state: TwinState;
4157
+ today: TwinToday;
4158
+ waiting: string[];
4159
+ working: string[];
4160
+ }
4161
+ /**
4162
+ * 一次运行的摘要(`TwinGetResult.last_run`):不含每项的决定,要看细节用 `twin.runs`。
4163
+ */
4164
+ export interface TwinRunBrief {
4165
+ error?: JudgeError | null;
4166
+ /**
4167
+ * 缺省 = 还在运行。
4168
+ */
4169
+ finished_ms?: number | null;
4170
+ id: string;
4171
+ result: TwinRunResult;
4172
+ started_ms: number;
4173
+ triggers: TwinTrigger[];
4174
+ }
4175
+ export interface TwinScope {
4176
+ agent?: string | null;
4177
+ daily_dispatches: number;
4178
+ max_sessions: number;
4179
+ mode?: string | null;
4180
+ model?: string | null;
4181
+ paused: boolean;
4182
+ projects: string[];
4183
+ }
4184
+ export interface TwinToday {
4185
+ dispatches: number;
4186
+ judge_calls: number;
4187
+ }
4188
+ /**
4189
+ * 一条 Twin 连接(A 记下的,表 `twin_links`)。
4190
+ */
4191
+ export interface TwinLink {
4192
+ /**
4193
+ * B 的静态公钥指纹。
4194
+ */
4195
+ fingerprint: string;
4196
+ group?: string | null;
4197
+ name: string;
4198
+ /**
4199
+ * B 的节点 id。
4200
+ */
4201
+ node_id: string;
4202
+ /**
4203
+ * 这条连接现在在线。
4204
+ */
4205
+ online?: boolean;
4206
+ paired_ms: number;
4207
+ /**
4208
+ * 上一次的 `twin.peer_status`;还没取到过为空。
4209
+ */
4210
+ status?: TwinPeerStatus | null;
4211
+ }
4212
+ /**
4213
+ * B 对这条 Twin 连接开放了什么、还剩多少(`twin.peer_status` 的结果,只给这条连接自己的)。
4214
+ */
4215
+ export interface TwinPeerStatus {
4216
+ /**
4217
+ * B 现在接受 Twin 连接(`[twin] accept_links`)。
4218
+ */
4219
+ accept_links: boolean;
4220
+ agents: TwinPeerAgent[];
4221
+ /**
4222
+ * B 的分组名。
4223
+ */
4224
+ group?: string | null;
4225
+ /**
4226
+ * B 的节点名。
4227
+ */
4228
+ name: string;
4229
+ /**
4230
+ * 这条连接被 B 暂停了。
4231
+ */
4232
+ paused: boolean;
4233
+ /**
4234
+ * 对这条连接开放的项目;空 = 什么都没开放。
4235
+ */
4236
+ projects: string[];
4237
+ /**
4238
+ * 这个本地日还能派发几次。
4239
+ */
4240
+ remaining_dispatches: number;
4241
+ /**
4242
+ * 这条连接还能同时派出几个会话:它的上限和给人留的名额里更紧的那个,减去已在处理中的。
4243
+ */
4244
+ remaining_sessions: number;
4245
+ }
4246
+ export interface TwinPeerAgent {
4247
+ id: string;
4248
+ label: string;
4249
+ /**
4250
+ * agent 现在可用(已安装、已登录)。
4251
+ */
4252
+ ready: boolean;
4253
+ }
4254
+ /**
4255
+ * `twin.link` 的参数:A 的 daemon 用 B 发的短码以 Twin 设备的身份和 B 配对。
4256
+ */
4257
+ export interface TwinLinkParams {
4258
+ /**
4259
+ * B 的 `node.twin_link_code` 发出的短码。
4260
+ */
4261
+ code: string;
4262
+ /**
4263
+ * B 的节点 id:配对完成后核对,对不上就失败并丢掉这次配对。
4264
+ */
4265
+ node_id: string;
4266
+ }
4267
+ export interface TwinLinksResult {
4268
+ links: TwinLink[];
4269
+ }
4270
+ export interface TwinQuestion {
4271
+ answer?: string | null;
4272
+ answered_by?: TodoActor | null;
4273
+ answered_ms?: number | null;
4274
+ created_ms: number;
4275
+ id: string;
4276
+ options?: string[];
4277
+ question: string;
4278
+ status: TwinQuestionStatus;
4279
+ todo_id: string;
4280
+ }
4281
+ export interface TwinQuestionNotice {
4282
+ question: TwinQuestion;
4283
+ }
4284
+ export interface TwinQuestionsParams {
4285
+ open_only?: boolean | null;
4286
+ }
4287
+ export interface TwinQuestionsResult {
4288
+ questions: TwinQuestion[];
4289
+ }
4290
+ export interface TwinRunsParams {
4291
+ before_ms?: number | null;
4292
+ limit?: number | null;
4293
+ }
4294
+ export interface TwinRunsResult {
4295
+ runs: TwinRun[];
4296
+ }
4297
+ export interface TwinSetParams {
4298
+ agent?: string | null;
4299
+ /**
4300
+ * 合并字段之后清空;恢复 agent / model / mode 的缺省选择。
4301
+ */
4302
+ clear?: ClearableTwinField[];
4303
+ daily_dispatches?: number | null;
4304
+ max_sessions?: number | null;
4305
+ mode?: string | null;
4306
+ model?: string | null;
4307
+ paused?: boolean | null;
4308
+ projects?: string[] | null;
4309
+ /**
4310
+ * 改谁的范围,同 [`TwinGetParams::requester`]。
4311
+ */
4312
+ requester?: string | null;
4313
+ }
4314
+ /**
4315
+ * `twin.stats` 的参数。只统计本机 Twin。
4316
+ */
4317
+ export interface TwinStatsParams {
4318
+ /**
4319
+ * 统计最近几个本地日(含今天),1..=90,缺省 7;越界 → `invalid`,`data.field = "days"`。
4320
+ */
4321
+ days?: number | null;
4322
+ }
4323
+ /**
4324
+ * `twin.stats` 的结果。
4325
+ */
4326
+ export interface TwinStatsResult {
4327
+ /**
4328
+ * 节点本地时区的每一天,按日期升序,最后一项是今天;没有活动的日子也在,数字为 0。
4329
+ */
4330
+ days: TwinDayStats[];
4331
+ }
4332
+ /**
4333
+ * `twin.unlink` 的参数:A 忘掉这一条连接(关掉传输、删记录)。B 上的设备记录要在 B 上吊销。
4334
+ */
4335
+ export interface TwinUnlinkParams {
4336
+ node_id: string;
2558
4337
  }
2559
4338
  /**
2560
4339
  * `workspace.branches`:给新建会话的「基于哪个分支」下拉框列分支。