@zhushanwen/extension-protocol 0.15.0 → 0.17.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/dist/index.d.ts +325 -12
- package/dist/index.js +226 -27
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -183,27 +183,45 @@ interface PlanDocMeta {
|
|
|
183
183
|
/**
|
|
184
184
|
* submit-review 挂起审批时的 select payload(序列化为 options[0] JSON)。
|
|
185
185
|
* extension 侧解析失败走 E5(logger.warn + tool result 报错提示重挂,垃圾数据不进对话流)。
|
|
186
|
+
*
|
|
187
|
+
* selfReview(自审结论,D9①③):agent 提交审批前的自审摘要,投影面到审批请求帧为止
|
|
188
|
+
* (不进 PlanStateView / session.planState 帧);有界性由写侧 4KB 单点截断保证
|
|
189
|
+
* (canonical 上限与截断 = src/extensions/plan/review-contract.ts,R3)。**optional 是兼容契约**:
|
|
190
|
+
* 旧扩展不携带 → 宿主自审行不渲染的降级形态;submit-review 的必填硬门在 tool 层执行
|
|
191
|
+
* (缺失/空 → tool result 错误纠偏,不 throw),wire 帧不设必填。
|
|
186
192
|
*/
|
|
187
193
|
interface PlanReviewRequest {
|
|
188
194
|
docs: PlanDocMeta[];
|
|
195
|
+
selfReview?: string;
|
|
189
196
|
}
|
|
190
|
-
/**
|
|
191
|
-
|
|
197
|
+
/**
|
|
198
|
+
* 审批三键裁决(D3):approve 确认执行 / revise 提交修订(必带评论)/ dismiss 搁置
|
|
199
|
+
* (非破坏:不杀 turn、不丢状态,计划进度保留)。revise 携带评论、approve/dismiss
|
|
200
|
+
* 不携带(结构上不可混带)。值域守卫 canonical 版 = src/extensions/plan/review-contract.ts
|
|
201
|
+
* (运行时判别 TS 穷尽性管不到——未知值域降级语义见该模块「降级双分源」)。
|
|
202
|
+
*/
|
|
203
|
+
type PlanReviewDecision = 'approve' | 'revise' | 'dismiss';
|
|
192
204
|
/** 用户对某文档划选段落的一条评论:quote 是划选引文(agent 定位段落用),comment 是评语。 */
|
|
193
205
|
interface PlanReviewComment {
|
|
194
206
|
quote: string;
|
|
195
207
|
comment: string;
|
|
196
208
|
}
|
|
197
209
|
/**
|
|
198
|
-
* 审批条 respond 回传(判别联合:approve 无评论字段,revise 必带评论数组)。
|
|
199
|
-
* extension 消费:approve →
|
|
200
|
-
*
|
|
210
|
+
* 审批条 respond 回传(判别联合:approve/dismiss 无评论字段,revise 必带评论数组)。
|
|
211
|
+
* extension 消费:approve → 走 complete 执行方式 select(transfer:reviewing→dispatching);
|
|
212
|
+
* revise → 评论清单以显式 deliverAs:'steer' 注入 + 转移 reviewing→revising;
|
|
213
|
+
* dismiss(D3 搁置)→ 转移 reviewing→planning 落盘,tool result 告知 agent「用户搁置了
|
|
214
|
+
* 本次审阅:plan 模式保持、文档与进度不变;简短告知用户已搁置并询问下一步,不要实施改动」。
|
|
215
|
+
* 未知 decision 值域降级 = 版本错配信号:与 malformed 同款 bad-response 出口引导重挂,
|
|
216
|
+
* 消费方额外 logger.warn 留痕(D3①)——判别与降级枚举见 src/extensions/plan/review-contract.ts。
|
|
201
217
|
*/
|
|
202
218
|
type PlanReviewResponse = {
|
|
203
219
|
decision: 'approve';
|
|
204
220
|
} | {
|
|
205
221
|
decision: 'revise';
|
|
206
222
|
comments: PlanReviewComment[];
|
|
223
|
+
} | {
|
|
224
|
+
decision: 'dismiss';
|
|
207
225
|
};
|
|
208
226
|
|
|
209
227
|
/**
|
|
@@ -803,6 +821,183 @@ declare function isScheduleFormResult(value: unknown): value is ScheduleFormResu
|
|
|
803
821
|
declare function dateToOnceCron(date: Date): string;
|
|
804
822
|
declare function onceCronToDate(cron: string, now?: Date): Date | null;
|
|
805
823
|
|
|
824
|
+
/**
|
|
825
|
+
* plan 模式生命周期状态机(plan 模式状态机显式化 D1)——纯数据 + 纯函数,零依赖。
|
|
826
|
+
*
|
|
827
|
+
* plan 模式的状态散落在 pi 扩展 entry / runtime 挂起注册表 / renderer 派生公式三处时,
|
|
828
|
+
* 任意两者漂移即产「僵尸/谎言」UI(F1-F5)。本模块是全链路共享的单一状态契约:
|
|
829
|
+
* 8 值状态集 + 9 事件边表 + `transition` 纯函数(守卫集中一处)+ `derivePhase` 呈现映射。
|
|
830
|
+
*
|
|
831
|
+
* 语义要点(设计 D1 逐条锚定):
|
|
832
|
+
* - 非法转移返回 `{ ok: false }`,由调用方降级(**不 throw 炸 turn**);副作用不进返回值
|
|
833
|
+
* (effects-as-data 无已登记消费方属投机间接层),各 action 在转移成功后内联执行自身副作用。
|
|
834
|
+
* - `reviewing --dismiss--> planning`:用户「搁置」(协议级 dismiss 决策,D3)——落盘即
|
|
835
|
+
* planning,被搁置的审批不复活(F1/F2/F3 构造性消除)。
|
|
836
|
+
* - `reviewing --review_aborted--> planning`:挂起期外部 turn abort / TUI 取消(D3 连带)。
|
|
837
|
+
* - `dispatching --review_aborted--> approved`:批准事实保留——任一「无选择解散」出口
|
|
838
|
+
* (外部 turn abort 级联 / 表单取消 / 超时 / 交互通道故障折叠)统一落 approved,
|
|
839
|
+
* 不把「已批准」打回规划期(F5 不复活)。
|
|
840
|
+
* - `dispatching --later--> approved`:用户显式选「暂不执行」——是明确选择不是解散,
|
|
841
|
+
* 不得进 review_aborted 文案桶(A9 反向)。
|
|
842
|
+
* - `dispatching --exec_chosen--> completed`:选定执行方式并派发执行(终态)。
|
|
843
|
+
* - `approved --approve--> dispatching`:批准后 agent 再调 `complete` 重新选择执行方式
|
|
844
|
+
* (D1「approved 上 agent 再调 complete → dispatching」)。事件命名裁决:9 事件表无
|
|
845
|
+
* `complete` 员,本边取「执行确认」语义族最近员 `approve`(用户点确认执行与批准后重选
|
|
846
|
+
* 执行方式同为「确认执行、进入执行方式选择」的决策事件)——消费面接线见 consumers.md。
|
|
847
|
+
* - `approved` 其余转移仅 `exit`;活跃族非终态 `--exit--> exited`;idle 从未进入,
|
|
848
|
+
* exit 非法(防从未进 plan 的会话落噪音 exited entry);终态 `--enter--> planning`
|
|
849
|
+
* (新一轮);`revising` 保留独立态(E3 恢复文案分叉依赖,前提 P-7)。
|
|
850
|
+
* - `reviewing --submit--> reviewing`:审批重挂自环(E3 会话重启恢复 / D8「重新提交审批」
|
|
851
|
+
* 按钮——重提交不推进生命周期,落盘回 reviewing 重挂即等价于旧调用方特判放行形态)。
|
|
852
|
+
*
|
|
853
|
+
* 呈现映射(derivePhase):用户视角四主态 + idle 缺省——四主态是呈现,不是存储
|
|
854
|
+
* (用户口述模型 = 呈现层,reviewing/dispatching 两个挂起态是崩溃恢复的真实分叉点,
|
|
855
|
+
* 存储层保留 8 值)。终态两值(completed = 批准并派发执行 / exited = 主动退出)共享
|
|
856
|
+
* 全部终态规则,呈现层同映 'terminal'(诊断/审计语义保留存储区分)。
|
|
857
|
+
*/
|
|
858
|
+
type PlanLifecycleState = 'idle' | 'planning' | 'reviewing' | 'revising' | 'approved' | 'dispatching' | 'completed' | 'exited';
|
|
859
|
+
/** 状态穷举表(运行时消费:E3 恢复查表 / 测试穷举基座)——顺序 = 生命周期自然序。 */
|
|
860
|
+
declare const PLAN_LIFECYCLE_STATES: readonly ["idle", "planning", "reviewing", "revising", "approved", "dispatching", "completed", "exited"];
|
|
861
|
+
type PlanLifecycleEvent = 'enter' | 'submit' | 'revise' | 'dismiss' | 'review_aborted' | 'approve' | 'exec_chosen' | 'later' | 'exit';
|
|
862
|
+
/** 事件穷举表——顺序 = 设计 D1 枚举序。 */
|
|
863
|
+
declare const PLAN_LIFECYCLE_EVENTS: readonly ["enter", "submit", "revise", "dismiss", "review_aborted", "approve", "exec_chosen", "later", "exit"];
|
|
864
|
+
type PlanTransitionResult = {
|
|
865
|
+
ok: true;
|
|
866
|
+
next: PlanLifecycleState;
|
|
867
|
+
} | {
|
|
868
|
+
ok: false;
|
|
869
|
+
};
|
|
870
|
+
/**
|
|
871
|
+
* 纯函数转移:`(state, event) → { ok: true, next } | { ok: false }`。
|
|
872
|
+
*
|
|
873
|
+
* 非法转移(含运行时垃圾 state/event 值——跨版本帧、坏反序列化)返回 `{ ok: false }`
|
|
874
|
+
* 且**不携带 next 键**,由调用方降级(不 throw 炸 turn)。调用方义务:`ok:false` 时
|
|
875
|
+
* 不落盘、不执行副作用(终态上 `ok:false` 不落盘即 D3 归口点的兜底保险)。
|
|
876
|
+
*
|
|
877
|
+
* 入口白名单守卫(与 derivePhase 同一机制):普通对象字面量查表会沿原型链命中继承键——
|
|
878
|
+
* `transition('reviewing', '__proto__')` 取出 Object.prototype、`('__proto__', 'valueOf')`
|
|
879
|
+
* 取出函数,均被误判为合法 next(违背本契约)。故垃圾键必须先挡在查表前。
|
|
880
|
+
* **选「枚举 includes 白名单」而非 null-prototype 表 / Object.hasOwn**:① transition 与
|
|
881
|
+
* derivePhase 共用同一守卫形态(单一机制,不并存两种写法);② PLAN_LIFECYCLE_STATES /
|
|
882
|
+
* PLAN_LIFECYCLE_EVENTS 就是值域 SSOT(测试穷举同源),includes 判定与之同源,
|
|
883
|
+
* 原型键天然不在白名单内。
|
|
884
|
+
*/
|
|
885
|
+
declare function transition(state: PlanLifecycleState, event: PlanLifecycleEvent): PlanTransitionResult;
|
|
886
|
+
/**
|
|
887
|
+
* 用户视角呈现相位(四主态 + idle):
|
|
888
|
+
* - 'planning'(规划中)= planning | revising
|
|
889
|
+
* - 'reviewing'(待审批)= reviewing
|
|
890
|
+
* - 'approved'(已批准)= approved | dispatching(dispatching 呈「③审阅确认 · 已完成」,
|
|
891
|
+
* 阶段不倒退——F5 修正;细化渲染由消费方查 state,不另造相位)
|
|
892
|
+
* - 'terminal'(终态)= completed | exited(两值同映,区分只留存储/审计层)
|
|
893
|
+
* - 'idle'(无 plan)= idle
|
|
894
|
+
*/
|
|
895
|
+
type PlanPhase = 'idle' | 'planning' | 'reviewing' | 'approved' | 'terminal';
|
|
896
|
+
/**
|
|
897
|
+
* 8 存储态 → 5 呈现相位的单点映射(renderer 阶段指示/状态带共用,禁止消费方各自 if 拼)。
|
|
898
|
+
* 运行时垃圾 state(混装格坏帧)降级 'idle'(无 plan 缺省,fail-safe 不误示进行中)。
|
|
899
|
+
*
|
|
900
|
+
* 入口白名单守卫(理由同 transition,见彼处):裸查表对继承键 'constructor' / 'toString'
|
|
901
|
+
* 会取出 Object 构造函数等并经 `?? 'idle'` 流出(非 nullish 不落兜底)——垃圾 state
|
|
902
|
+
* 必须精确落 'idle',函数/对象不得作为相位流入 renderer。
|
|
903
|
+
*/
|
|
904
|
+
declare function derivePhase(state: PlanLifecycleState): PlanPhase;
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* plan 审阅回传值域契约(plan 模式状态机显式化 D3①⑤ / D9③)——纯函数守卫,零依赖。
|
|
908
|
+
*
|
|
909
|
+
* 为什么守卫是契约级承重:TS 判别联合的穷尽性(switch/never 断言)管不到运行时值域——
|
|
910
|
+
* respond 通道透传的是任意字符串 parse 出的 unknown(P-2),值域守卫漏改即「搁置应答被判
|
|
911
|
+
* 垃圾 → bad-response 引导重挂」再入循环(F1 复活路径)。canonical 守卫与判别联合同住
|
|
912
|
+
* 契约包,消费面(extensions/universal/plan tool.ts)接线见同目录 consumers.md。
|
|
913
|
+
*
|
|
914
|
+
* 降级双分源(D3①)——parse 失败必须区分两类(envelope 判别保留),消费面出口同款:
|
|
915
|
+
* - `unknown-decision`(对象合法但 decision 不在值域):版本错配信号(R2),消费方
|
|
916
|
+
* 额外 logger.warn 留痕;出口与文案与 malformed 同款——bad-response 报错提示重挂。
|
|
917
|
+
* 裁决与重审触发(候选替代 = 恢复独立 version-mismatch 不重挂出口)登记于消费方
|
|
918
|
+
* extensions/universal/plan/src/tool.ts「条目 7 降级」注释段。
|
|
919
|
+
* - `malformed`(非对象 / 缺 decision / 形状不合法):垃圾数据(E5 判据),bad-response
|
|
920
|
+
* 报错提示重挂。
|
|
921
|
+
*
|
|
922
|
+
* selfReview 有界字段(D9③ / R3):有界性由**写侧单点截断**保证(截断点 = 扩展 payload
|
|
923
|
+
* 构造处),4KB 上限与 UTF-8 字节界安全截断的唯一权威在本模块;透传层(runtime)不截、
|
|
924
|
+
* 入站守卫不二次截(上限已在写侧达成)。
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
/** selfReview 上限:4KB(UTF-8 字节)。超限即截(全文可要求 agent 贴对话流,R3)。 */
|
|
928
|
+
declare const PLAN_SELF_REVIEW_MAX_BYTES = 4096;
|
|
929
|
+
/**
|
|
930
|
+
* selfReview 写侧单点截断:按 UTF-8 字节预算截到**完整码点边界**(多字节字符不截半,
|
|
931
|
+
* 无替换字符噪音)。预算内原样返回;不追加省略号(消费方渲染时自行提示截断)。
|
|
932
|
+
*/
|
|
933
|
+
declare function truncateSelfReview(text: string): string;
|
|
934
|
+
/**
|
|
935
|
+
* `PlanReviewRequest` 形状守卫(E5 垃圾数据判据):
|
|
936
|
+
* docs 必为 `PlanDocMeta[]`(逐项形状);selfReview 缺省或 string——**optional 是兼容契约**
|
|
937
|
+
* (旧扩展不携带 → 自审行不渲染的降级形态,D9③),值域上限不在此拒绝(写侧截断已界)。
|
|
938
|
+
* 空载荷(undefined/null/非对象/缺 docs)与非法形态(docs 非数组 / 元素形状不合法 /
|
|
939
|
+
* selfReview 非 string)一律 false,不 throw。
|
|
940
|
+
*/
|
|
941
|
+
declare function isPlanReviewRequest(value: unknown): value is PlanReviewRequest;
|
|
942
|
+
/**
|
|
943
|
+
* respond 回传解析结果(error envelope 单源):
|
|
944
|
+
* - ok:归一化后的合法 `PlanReviewResponse`(多余键已剥——approve/dismiss 不携带评论是
|
|
945
|
+
* 结构保证,不信任宿主回传的附加形态)。
|
|
946
|
+
* - `unknown-decision`:decision 是 string 但不在值域 → 版本错配信号(消费方额外
|
|
947
|
+
* logger.warn 留痕;出口与 malformed 同款 bad-response 引导重挂,见文件头「降级双分源」)。
|
|
948
|
+
* - `malformed`:空载荷 / 非对象 / 形状不合法 → E5 判据,报错提示重挂。
|
|
949
|
+
*/
|
|
950
|
+
type PlanReviewResponseEnvelope = {
|
|
951
|
+
ok: true;
|
|
952
|
+
response: PlanReviewResponse;
|
|
953
|
+
} | {
|
|
954
|
+
ok: false;
|
|
955
|
+
code: 'unknown-decision';
|
|
956
|
+
decision: string;
|
|
957
|
+
} | {
|
|
958
|
+
ok: false;
|
|
959
|
+
code: 'malformed';
|
|
960
|
+
};
|
|
961
|
+
/**
|
|
962
|
+
* respond 回传解析(值域守卫的判别版):dismiss 样本必通(D3 主干),未知 decision 值域
|
|
963
|
+
* 落降级枚举而非垃圾(两类降级可判别分离;消费面出口同款引导重挂,见文件头「降级双分源」)。
|
|
964
|
+
*/
|
|
965
|
+
declare function parsePlanReviewResponse(value: unknown): PlanReviewResponseEnvelope;
|
|
966
|
+
/**
|
|
967
|
+
* `PlanReviewResponse` 值域守卫(含 dismiss 员,D3①)——`parsePlanReviewResponse` 的谓词形。
|
|
968
|
+
* 消费方需要区分 unknown-decision / malformed 两类降级时用 parse 版。
|
|
969
|
+
*/
|
|
970
|
+
declare function isPlanReviewResponse(value: unknown): value is PlanReviewResponse;
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* plan-state entry 的 customType(pi appendEntry custom entry 判别键)。磁盘形态冻结:
|
|
974
|
+
* 扩展写读两侧(persistPlanState / isPlanStateEntry)与 runtime 投影链(plan-state-extractor /
|
|
975
|
+
* session-records)均消费本常量,值同源——改值即历史会话全部失联,禁改(冻结锚测试见
|
|
976
|
+
* 本目录 legacy-entries.test.ts)。
|
|
977
|
+
*/
|
|
978
|
+
declare const PLAN_STATE_CUSTOM_TYPE = "plan-state";
|
|
979
|
+
/**
|
|
980
|
+
* 生命周期状态读取(D2 读方①②共用映射,原扩展 state.ts / runtime extractor 内联拷贝的
|
|
981
|
+
* 单源归并):
|
|
982
|
+
* ① 新字段直读(值域守卫:PLAN_LIFECYCLE_STATES 之外的垃圾值按缺失处理,落映射——
|
|
983
|
+
* 不信任外部写入);
|
|
984
|
+
* ② 旧 entry 无 state(或垃圾 state)时映射 reviewState(awaiting→reviewing /
|
|
985
|
+
* revising→revising / 其余值→planning|idle 按 isActive)。
|
|
986
|
+
*/
|
|
987
|
+
declare function readLifecycleState(data: {
|
|
988
|
+
state?: unknown;
|
|
989
|
+
reviewState?: unknown;
|
|
990
|
+
}, isActive: boolean): PlanLifecycleState;
|
|
991
|
+
/**
|
|
992
|
+
* resumeHint 读取(D2 读方①②共用映射):新字段直读(只认 'resubmit' 一字面量)+
|
|
993
|
+
* 旧 reviewStateSource 同义映射('explain' 等存量值归无值——explain 交互已删);
|
|
994
|
+
* resumeHint 存在但非法(垃圾值)时不挡 reviewStateSource 映射(与原两份拷贝逐字同构)。
|
|
995
|
+
*/
|
|
996
|
+
declare function readResumeHint(data: {
|
|
997
|
+
resumeHint?: unknown;
|
|
998
|
+
reviewStateSource?: unknown;
|
|
999
|
+
}): 'resubmit' | undefined;
|
|
1000
|
+
|
|
806
1001
|
/**
|
|
807
1002
|
* 统一提问表单协议(ui-form)的类型定义。
|
|
808
1003
|
*
|
|
@@ -981,20 +1176,25 @@ declare function isFormAnswers(value: unknown): value is FormAnswers;
|
|
|
981
1176
|
*/
|
|
982
1177
|
declare const SESSION_MANAGER_MARKER = "\0TAIJI_SESSION_MANAGER";
|
|
983
1178
|
/**
|
|
984
|
-
*
|
|
1179
|
+
* 7 个 action 的运行时集合(与 SessionManagerAction 类型同源——types.ts 从此派生)。
|
|
985
1180
|
* event-adapter 用它把 JSON 解析出的 action 字符串收窄为联合类型,
|
|
986
1181
|
* 非法值折叠为 '__malformed__' 哨兵(与 handler default 分支同走 cancelled)。
|
|
1182
|
+
*
|
|
1183
|
+
* 'watch'(notify-once D6):通知债权的纯应答通道——单键 params={notifyId} 寻址、
|
|
1184
|
+
* 不传 timeout、fire-and-forget 长挂 select;必须在本集合内,否则 event-adapter
|
|
1185
|
+
* 把它折叠成 '__malformed__'(旧 runtime 兼容象限的静默降级形态),watch 永远到不了
|
|
1186
|
+
* handler 路由。
|
|
987
1187
|
*/
|
|
988
|
-
declare const SESSION_MANAGER_ACTIONS: readonly ["create", "send", "history", "status", "list", "abort"];
|
|
1188
|
+
declare const SESSION_MANAGER_ACTIONS: readonly ["create", "send", "history", "status", "list", "abort", "watch"];
|
|
989
1189
|
|
|
990
1190
|
/**
|
|
991
1191
|
* session-manager extension 的类型定义。
|
|
992
1192
|
*
|
|
993
|
-
*
|
|
1193
|
+
* 7 个 action 的请求 params 和结果类型,供 handler 和 extension 共用。
|
|
994
1194
|
* marker 检测后按 action 分发到对应 handler 分支。
|
|
995
1195
|
*/
|
|
996
1196
|
|
|
997
|
-
/** session-manager 支持的
|
|
1197
|
+
/** session-manager 支持的 7 个 action(从 SESSION_MANAGER_ACTIONS 集合派生,值与类型同源) */
|
|
998
1198
|
type SessionManagerAction = (typeof SESSION_MANAGER_ACTIONS)[number];
|
|
999
1199
|
/** 各 action 的请求参数映射 */
|
|
1000
1200
|
interface SessionManagerParams {
|
|
@@ -1004,6 +1204,7 @@ interface SessionManagerParams {
|
|
|
1004
1204
|
status: SessionManagerStatusParams;
|
|
1005
1205
|
list: SessionManagerListParams;
|
|
1006
1206
|
abort: SessionManagerAbortParams;
|
|
1207
|
+
watch: SessionManagerWatchParams;
|
|
1007
1208
|
}
|
|
1008
1209
|
/** create action 参数 */
|
|
1009
1210
|
interface SessionManagerCreateParams {
|
|
@@ -1013,11 +1214,21 @@ interface SessionManagerCreateParams {
|
|
|
1013
1214
|
label?: string;
|
|
1014
1215
|
/** 初始 prompt(可选;提供时 create 后立即注入——设计文档 §5.2 原子性决策) */
|
|
1015
1216
|
prompt?: string;
|
|
1217
|
+
/**
|
|
1218
|
+
* 完成通知债权的幂等键(optional,notify-once D2/D6):extension 侧
|
|
1219
|
+
* `crypto.randomUUID()` 前缀 `sm-` 生成。缺省/畸形 → runtime 不 arm、
|
|
1220
|
+
* `willNotify:false`、零完成通知——兼容判据从版本二分改为字段有无。
|
|
1221
|
+
* 形态判定不在 params 守卫(畸形不构成 params 错误、动作照常执行),
|
|
1222
|
+
* 由 runtime 受理点消费 `isSessionManagerNotifyId` 作 arm 判据。
|
|
1223
|
+
*/
|
|
1224
|
+
notifyId?: string;
|
|
1016
1225
|
}
|
|
1017
1226
|
/** send action 参数 */
|
|
1018
1227
|
interface SessionManagerSendParams {
|
|
1019
1228
|
sessionId: string;
|
|
1020
1229
|
prompt: string;
|
|
1230
|
+
/** 完成通知债权的幂等键(optional,语义同 create:缺省/畸形 → 不 arm + willNotify:false) */
|
|
1231
|
+
notifyId?: string;
|
|
1021
1232
|
}
|
|
1022
1233
|
/** history action 参数 */
|
|
1023
1234
|
interface SessionManagerHistoryParams {
|
|
@@ -1035,9 +1246,20 @@ type SessionManagerListParams = Record<string, never>;
|
|
|
1035
1246
|
interface SessionManagerAbortParams {
|
|
1036
1247
|
sessionId: string;
|
|
1037
1248
|
}
|
|
1038
|
-
/**
|
|
1249
|
+
/**
|
|
1250
|
+
* watch action 参数(notify-once D2/D6):通知债权的纯应答通道,**单键寻址**——
|
|
1251
|
+
* runtime 按 `(调用方 parentSid, notifyId)` 反查 claim,parentSid 取自调用方连接身份、
|
|
1252
|
+
* **协议面不定义不携带**(可推导字段免传,多余字段被守卫拒绝)。不传 timeout、
|
|
1253
|
+
* fire-and-forget 长挂 select;每 claim 单 watch 槽(新覆盖旧,runtime 只 respond 最新)。
|
|
1254
|
+
*/
|
|
1255
|
+
interface SessionManagerWatchParams {
|
|
1256
|
+
/** 目标 claim/lifetime 的幂等键(`sm-` 前缀 UUID,形态自检见 isSessionManagerNotifyId) */
|
|
1257
|
+
notifyId: string;
|
|
1258
|
+
}
|
|
1259
|
+
declare function isSessionManagerNotifyId(v: unknown): v is string;
|
|
1260
|
+
/** create:字段可选 string + optional notifyId(类型面,sm- 形态判定归 arm 判据) */
|
|
1039
1261
|
declare function isSessionManagerCreateParams(v: unknown): v is SessionManagerCreateParams;
|
|
1040
|
-
/** send:sessionId + prompt
|
|
1262
|
+
/** send:sessionId + prompt 必填,notifyId optional(类型面校验同 create) */
|
|
1041
1263
|
declare function isSessionManagerSendParams(v: unknown): v is SessionManagerSendParams;
|
|
1042
1264
|
/** history:sessionId 必填、tailTurns 可选 number */
|
|
1043
1265
|
declare function isSessionManagerHistoryParams(v: unknown): v is SessionManagerHistoryParams;
|
|
@@ -1046,11 +1268,31 @@ declare function isSessionManagerStatusParams(v: unknown): v is SessionManagerSt
|
|
|
1046
1268
|
declare function isSessionManagerAbortParams(v: unknown): v is SessionManagerAbortParams;
|
|
1047
1269
|
/** list:无参数(过滤由 handler 固化,params 不携带任何过滤字段) */
|
|
1048
1270
|
declare function isSessionManagerListParams(v: unknown): v is SessionManagerListParams;
|
|
1271
|
+
/**
|
|
1272
|
+
* watch:**封闭单键** `{notifyId}` 守卫(notify-once D2 形态入站自检)——
|
|
1273
|
+
* 空载荷 / 缺字段 / 夹带任何额外字段(如 parentSid:归属由 runtime 取连接身份,
|
|
1274
|
+
* 协议面不定义)/ notifyId 非 string / 形态不符(缺 `sm-` 前缀、非 UUID 体、超长)
|
|
1275
|
+
* → false → handler dispatch 抛错走 respond({error}) 错误闭环(error envelope)。
|
|
1276
|
+
* 形态函数与 lifetimeNotifyId 同一实现(防自检拒掉 runtime 生成的 lifetime watch)。
|
|
1277
|
+
*/
|
|
1278
|
+
declare function isSessionManagerWatchParams(v: unknown): v is SessionManagerWatchParams;
|
|
1049
1279
|
/** create 结果 */
|
|
1050
1280
|
interface SessionManagerCreateResult {
|
|
1051
1281
|
sessionId: string;
|
|
1052
1282
|
status: 'created';
|
|
1053
1283
|
modelId?: string;
|
|
1284
|
+
/**
|
|
1285
|
+
* 完成通知债权是否已 arm(notify-once D6,LLM 契约面显式化):create 无 prompt /
|
|
1286
|
+
* notifyId 缺省或畸形 → false(零完成通知);true 时首次完成恰回一条通知。
|
|
1287
|
+
* 注意与 lifetimeNotifyId 正交——后者恒存在(死亡通知与债权无关)。
|
|
1288
|
+
*/
|
|
1289
|
+
willNotify: boolean;
|
|
1290
|
+
/**
|
|
1291
|
+
* runtime 在 handleCreate 自动 arm 的 lifetime(死亡)通知幂等键(notify-once D2/D5):
|
|
1292
|
+
* create 成恒返回、`sm-` 同形态同校验;与 params.notifyId(claim 键)双键独立,
|
|
1293
|
+
* 杜绝撞幂等键。extension 据此注册 pending(register id = 本键)并开终身 watch。
|
|
1294
|
+
*/
|
|
1295
|
+
lifetimeNotifyId: string;
|
|
1054
1296
|
}
|
|
1055
1297
|
/**
|
|
1056
1298
|
* send 结果(sd-u5 起):消息已入队/已投递——目标 busy 时在下一 turn 边界注入。
|
|
@@ -1058,6 +1300,8 @@ interface SessionManagerCreateResult {
|
|
|
1058
1300
|
*/
|
|
1059
1301
|
interface SessionManagerSendResult {
|
|
1060
1302
|
queued: true;
|
|
1303
|
+
/** 完成通知债权是否已 arm(notify-once D6):notifyId 缺省/畸形 → false(零完成通知) */
|
|
1304
|
+
willNotify: boolean;
|
|
1061
1305
|
}
|
|
1062
1306
|
/** history 结果 */
|
|
1063
1307
|
interface SessionManagerHistoryResult {
|
|
@@ -1068,10 +1312,18 @@ interface SessionManagerHistoryResult {
|
|
|
1068
1312
|
interface SessionManagerStatusResult {
|
|
1069
1313
|
status: string;
|
|
1070
1314
|
modelId?: string;
|
|
1315
|
+
/**
|
|
1316
|
+
* 「未送达结果」事实计数(notify-once D6/D7,非警示布尔):orphaned 与
|
|
1317
|
+
* fulfilled-no-watch(TTL 清扫转入)两态的在册总数。天然无清除语义问题、无
|
|
1318
|
+
* cry-wolf;持久化二期补投时递减自洽。ownership 校验同其余按 sessionId 寻址的 action。
|
|
1319
|
+
*/
|
|
1320
|
+
undeliveredResults: number;
|
|
1071
1321
|
}
|
|
1072
1322
|
/** list 结果 */
|
|
1073
1323
|
interface SessionManagerListResult {
|
|
1074
1324
|
sessions: SessionManagerSessionSummary[];
|
|
1325
|
+
/** 「未送达结果」事实计数(语义同 status:发起方名下全量在册数) */
|
|
1326
|
+
undeliveredResults: number;
|
|
1075
1327
|
}
|
|
1076
1328
|
/** list 返回的 session 摘要(精简版) */
|
|
1077
1329
|
interface SessionManagerSessionSummary {
|
|
@@ -1086,6 +1338,60 @@ interface SessionManagerSessionSummary {
|
|
|
1086
1338
|
interface SessionManagerAbortResult {
|
|
1087
1339
|
success: boolean;
|
|
1088
1340
|
}
|
|
1341
|
+
/**
|
|
1342
|
+
* watch 应答 reason 词表(封闭 7 值)——与 pending-entries `mapReasonToStatus` 的
|
|
1343
|
+
* 4 个新 case 同词形(stopped→aborted、exited/deleted/orphaned→cancelled),
|
|
1344
|
+
* **不扩共享词表**:精确状态由通知正文与 `get_session_status` 承载。
|
|
1345
|
+
*/
|
|
1346
|
+
type SessionManagerWatchReason =
|
|
1347
|
+
/** settle 兑现 / catch-up 快照(outcome 映射 completed/failed/stopped) */
|
|
1348
|
+
'completed' | 'failed' | 'stopped'
|
|
1349
|
+
/** 终局死亡(delete/forceQuit/不可恢复 crash;respawn 链静默不发声) */
|
|
1350
|
+
| 'exited' | 'deleted'
|
|
1351
|
+
/** 静默折叠(主 abort / 二次校验归属失效 / fail-closed 查无 claim / 旧 runtime 兼容象限) */
|
|
1352
|
+
| 'cancelled'
|
|
1353
|
+
/** orphan 吸收态(父 pi 死亡批量转移 / TTL 清扫 / respond 失败) */
|
|
1354
|
+
| 'orphaned';
|
|
1355
|
+
/**
|
|
1356
|
+
* watch respond payload(notify-once D6,全 additive)——extension 侧 watch 响应的
|
|
1357
|
+
* 唯一权威形状。旧 runtime 象限 respond `null`(不识 watch action),由 extension
|
|
1358
|
+
* 折叠 cancelled——null 不在本类型内,消费方须同时处理。
|
|
1359
|
+
*/
|
|
1360
|
+
interface SessionManagerWatchRespondPayload {
|
|
1361
|
+
/** 分拣键 (sessionId, reason) 的 reason 腿(D3 两层模型:cancelled/orphaned → 仅
|
|
1362
|
+
* unregister;exited/deleted → 死亡新闻槽;completed/failed/stopped → 结果新闻) */
|
|
1363
|
+
reason: SessionManagerWatchReason;
|
|
1364
|
+
/**
|
|
1365
|
+
* claim 所属子会话 id 回带——D3 槽键 (sessionId, deathSeq) / 分拣键 (sessionId,
|
|
1366
|
+
* reason) / D9 文案 `<sid>` 的唯一数据源(收口腿闭包仅有父 sid,缺此字段则同父
|
|
1367
|
+
* 多子 deathSeq 跨 child 碰撞)。claim 命中路径(settle/death/orphaned/二次校验)
|
|
1368
|
+
* 恒带;fail-closed(查无 claim)无 claim 可回带 → 缺席——该路径 reason 恒
|
|
1369
|
+
* 'cancelled',extension 静默收口不消费 sessionId。
|
|
1370
|
+
*/
|
|
1371
|
+
sessionId?: string;
|
|
1372
|
+
/** death 批身份(per session 递增;同一死亡事件循环 respond 时 runtime 直供) */
|
|
1373
|
+
deathSeq?: number;
|
|
1374
|
+
/** settle 批身份(per session 递增;批身份 = settleSeq/deathSeq——同批身份才合一条 record) */
|
|
1375
|
+
settleSeq?: number;
|
|
1376
|
+
/** 本批兑现总笔数(同批每条应答携带同值);death 侧 = 同 deathSeq 的 claim 数(D3 合批口径,runtime 直供,死亡/结果新闻正文消费 fulfills N) */
|
|
1377
|
+
fulfillsN?: number;
|
|
1378
|
+
/** death 应答携带:exit 腿诊断数据通路复刻(400 字截尾沿用现值),extension 文案构造消费 */
|
|
1379
|
+
exitCode?: number | null;
|
|
1380
|
+
stderrTail?: string;
|
|
1381
|
+
/**
|
|
1382
|
+
* 会话文件绝对路径(additive optional,notify-once D9):通知正文 `Full transcript:`
|
|
1383
|
+
* 指针行的唯一数据源(`~/.taiji/agent/sessions/.../<sid>.jsonl` 形态)。死亡/settle
|
|
1384
|
+
* 应答携带(正文构造消费);fail-closed 等无 claim 应答不携(该路径静默无文案)。
|
|
1385
|
+
*/
|
|
1386
|
+
sessionFilePath?: string;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* watch respond payload 运行时守卫(extension 读侧不信任外部格式——AGENTS 关键规则 5):
|
|
1390
|
+
* null(旧 runtime 象限)/ 非 record / reason 缺失、非 string 或词表外 / 可选 meta
|
|
1391
|
+
* 类型不符 → false(可选字段缺席一律放行——含 sessionFilePath)。消费方对 false 与
|
|
1392
|
+
* null 同路折叠静默 unregister(fail-safe:未知 reason 不得落 default 误标)。
|
|
1393
|
+
*/
|
|
1394
|
+
declare function isSessionManagerWatchRespondPayload(v: unknown): v is SessionManagerWatchRespondPayload;
|
|
1089
1395
|
/** 错误响应形状(send 同步失败时 = { error, hint };create 已成功时另附 sessionId)。
|
|
1090
1396
|
* D8 单源化:交集扩展 alias——error/hint 单源于 core 的 ChannelErrorResult,sessionId
|
|
1091
1397
|
* 为本协议独有扩展(runtime session-manager-handler 活构造:create 已成功但后续步骤
|
|
@@ -1382,6 +1688,13 @@ declare function collectActivePendingIds(entries: unknown[], opts?: CollectPendi
|
|
|
1382
1688
|
* reopened → completed)——防新词落 default 被记为 completed 的误标(cancelled 同族
|
|
1383
1689
|
* 事故先例:新枚举值漏映射静默落兜底)。
|
|
1384
1690
|
*
|
|
1691
|
+
* [notify-once D3 族映射] session-manager watch 应答的 4 个新 reason 同族接入:
|
|
1692
|
+
* stopped→aborted(用户 UI 掐断含债权轮)、exited/deleted/orphaned→cancelled
|
|
1693
|
+
* (终局死亡/删除/orphan 吸收态)。**不扩 MappedPendingStatus/PendingStatus 词表**——
|
|
1694
|
+
* 四个新 reason 全仓零读方按 status 分流(countActiveFromEntries 只用 register−unregister
|
|
1695
|
+
* 差集、notify-summary outcome 读 details 不读 entry.status),精确状态由通知正文与
|
|
1696
|
+
* get_session_status 承载,高于 G2 感知线。
|
|
1697
|
+
*
|
|
1385
1698
|
* 返回值 MappedPendingStatus(本文件封闭字面量联合):PendingStatus 枚举留在
|
|
1386
1699
|
* pending-notifications(本包不引 extension 侧类型),本联合是其终态子集——消费方
|
|
1387
1700
|
* 免 as 收窄直接赋值。
|
|
@@ -1392,4 +1705,4 @@ declare function collectActivePendingIds(entries: unknown[], opts?: CollectPendi
|
|
|
1392
1705
|
type MappedPendingStatus = 'completed' | 'failed' | 'cancelled' | 'expired' | 'time_limited' | 'aborted';
|
|
1393
1706
|
declare function mapReasonToStatus(reason: string): MappedPendingStatus;
|
|
1394
1707
|
|
|
1395
|
-
export { ASK_USER_MARKER, type AskUserAnswers, type AskUserOption, type AskUserQuestion, BRIDGE_MARKER, BRIDGE_METHODS, type BridgeErrorResponse, type BridgeInterceptResponse, type BridgeMethod, type BridgeRequest, type BridgeSyncPayload, type BridgeToolExecuteResponse, type ChannelErrorResult, type ChoiceQuestion, type CollectPendingIdsOptions, type DualWidgetContent, type ExecutionRecord, type FormAnswers, type FormOption, type FormQuestion, GUI_WIDGET_MARKER, type GuiComponent, type GuiComponentProps, type GuiComponentType, type GuiContext, type GuiRenderResult, HISTORY_LIMIT, INFLIGHT_REPORT_ACK, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, type MappedPendingStatus, type MarkerRpcOptions, type MarkerRpcResult, PENDING_REGISTER_ENTRY_TYPE, PENDING_UNREGISTER_ENTRY_TYPE, PLAN_REVIEW_MARKER, PROTOCOL_VERSION, type PendingEntriesScan, type PlanDocMeta, type PlanReviewComment, type PlanReviewDecision, type PlanReviewRequest, type PlanReviewResponse, type ReplayFoldOptions, SCHEDULE_CREATE_MARKER, SESSION_MANAGER_ACTIONS, SESSION_MANAGER_MARKER, SUBAGENTS_ENGINES_FILENAME, SUBAGENT_BG_NOTIFY_CUSTOM_TYPE, SUBAGENT_DIRECTIVE_CUSTOM_TYPE, SUBAGENT_INFLIGHT_MARKER, type ScheduleDraft, type ScheduleFormResult, type ScheduleKind, type ScheduleQuestion, type ScheduleSpec, type ScheduledTask, type SchedulerEntryLike, type SchedulerEntryOp, type SessionManagerAbortParams, type SessionManagerAbortResult, type SessionManagerAction, type SessionManagerCreateParams, type SessionManagerCreateResult, type SessionManagerErrorResult, type SessionManagerHistoryParams, type SessionManagerHistoryResult, type SessionManagerListParams, type SessionManagerListResult, type SessionManagerParams, type SessionManagerSendParams, type SessionManagerSendResult, type SessionManagerSessionSummary, type SessionManagerStatusParams, type SessionManagerStatusResult, type StatItem, type SubagentEngineConfigView, type SubagentEnginesFile, type SubagentInFlightReport, TASK_ENTRY_TYPE, type TaskKind, type TaskSnapshot, type TaskStatus, type TextQuestion, type TreeItem, type TreeItemIcon, UI_FORM_MARKER, type UiFormInteractOptions, type UiFormInteractResult, WORKFLOW_RESULT_CUSTOM_TYPE, type WidgetIconPathsRejection, type WidgetIconPathsValidation, type WidgetMeta, appendExecutionRecord, applyPendingDiff, callMarkerRpc, collectActivePendingIds, dateToOnceCron, extractGui, firstContentText, formatChannelErrorText, formatDuration, formatRelativeTime, formatSchedule, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isAskUserQuestion, isBridgeErrorResponse, isBridgeInterceptResponse, isBridgeSyncPayload, isBridgeToolExecuteResponse, isChannelErrorResult, isFormAnswers, isFormQuestion, isGuiCapable, isGuiComponent, isGuiRenderResult, isInFlightReportAck, isScheduleDraft, isScheduleFormResult, isSessionManagerAbortParams, isSessionManagerCreateParams, isSessionManagerHistoryParams, isSessionManagerListParams, isSessionManagerSendParams, isSessionManagerStatusParams, isSubagentInFlightReport, isSyncedTool, mapReasonToStatus, onceCronToDate, replayFoldEntries, scanPendingEntries, setWidgetDual, snapshotToTask, uiFormInteract, validateWidgetIconPaths };
|
|
1708
|
+
export { ASK_USER_MARKER, type AskUserAnswers, type AskUserOption, type AskUserQuestion, BRIDGE_MARKER, BRIDGE_METHODS, type BridgeErrorResponse, type BridgeInterceptResponse, type BridgeMethod, type BridgeRequest, type BridgeSyncPayload, type BridgeToolExecuteResponse, type ChannelErrorResult, type ChoiceQuestion, type CollectPendingIdsOptions, type DualWidgetContent, type ExecutionRecord, type FormAnswers, type FormOption, type FormQuestion, GUI_WIDGET_MARKER, type GuiComponent, type GuiComponentProps, type GuiComponentType, type GuiContext, type GuiRenderResult, HISTORY_LIMIT, INFLIGHT_REPORT_ACK, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, type MappedPendingStatus, type MarkerRpcOptions, type MarkerRpcResult, PENDING_REGISTER_ENTRY_TYPE, PENDING_UNREGISTER_ENTRY_TYPE, PLAN_LIFECYCLE_EVENTS, PLAN_LIFECYCLE_STATES, PLAN_REVIEW_MARKER, PLAN_SELF_REVIEW_MAX_BYTES, PLAN_STATE_CUSTOM_TYPE, PROTOCOL_VERSION, type PendingEntriesScan, type PlanDocMeta, type PlanLifecycleEvent, type PlanLifecycleState, type PlanPhase, type PlanReviewComment, type PlanReviewDecision, type PlanReviewRequest, type PlanReviewResponse, type PlanReviewResponseEnvelope, type PlanTransitionResult, type ReplayFoldOptions, SCHEDULE_CREATE_MARKER, SESSION_MANAGER_ACTIONS, SESSION_MANAGER_MARKER, SUBAGENTS_ENGINES_FILENAME, SUBAGENT_BG_NOTIFY_CUSTOM_TYPE, SUBAGENT_DIRECTIVE_CUSTOM_TYPE, SUBAGENT_INFLIGHT_MARKER, type ScheduleDraft, type ScheduleFormResult, type ScheduleKind, type ScheduleQuestion, type ScheduleSpec, type ScheduledTask, type SchedulerEntryLike, type SchedulerEntryOp, type SessionManagerAbortParams, type SessionManagerAbortResult, type SessionManagerAction, type SessionManagerCreateParams, type SessionManagerCreateResult, type SessionManagerErrorResult, type SessionManagerHistoryParams, type SessionManagerHistoryResult, type SessionManagerListParams, type SessionManagerListResult, type SessionManagerParams, type SessionManagerSendParams, type SessionManagerSendResult, type SessionManagerSessionSummary, type SessionManagerStatusParams, type SessionManagerStatusResult, type SessionManagerWatchParams, type SessionManagerWatchReason, type SessionManagerWatchRespondPayload, type StatItem, type SubagentEngineConfigView, type SubagentEnginesFile, type SubagentInFlightReport, TASK_ENTRY_TYPE, type TaskKind, type TaskSnapshot, type TaskStatus, type TextQuestion, type TreeItem, type TreeItemIcon, UI_FORM_MARKER, type UiFormInteractOptions, type UiFormInteractResult, WORKFLOW_RESULT_CUSTOM_TYPE, type WidgetIconPathsRejection, type WidgetIconPathsValidation, type WidgetMeta, appendExecutionRecord, applyPendingDiff, callMarkerRpc, collectActivePendingIds, dateToOnceCron, derivePhase, extractGui, firstContentText, formatChannelErrorText, formatDuration, formatRelativeTime, formatSchedule, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isAskUserQuestion, isBridgeErrorResponse, isBridgeInterceptResponse, isBridgeSyncPayload, isBridgeToolExecuteResponse, isChannelErrorResult, isFormAnswers, isFormQuestion, isGuiCapable, isGuiComponent, isGuiRenderResult, isInFlightReportAck, isPlanReviewRequest, isPlanReviewResponse, isScheduleDraft, isScheduleFormResult, isSessionManagerAbortParams, isSessionManagerCreateParams, isSessionManagerHistoryParams, isSessionManagerListParams, isSessionManagerNotifyId, isSessionManagerSendParams, isSessionManagerStatusParams, isSessionManagerWatchParams, isSessionManagerWatchRespondPayload, isSubagentInFlightReport, isSyncedTool, mapReasonToStatus, onceCronToDate, parsePlanReviewResponse, readLifecycleState, readResumeHint, replayFoldEntries, scanPendingEntries, setWidgetDual, snapshotToTask, transition, truncateSelfReview, uiFormInteract, validateWidgetIconPaths };
|
package/dist/index.js
CHANGED
|
@@ -413,6 +413,157 @@ function onceCronToDate(cron, now = /* @__PURE__ */ new Date()) {
|
|
|
413
413
|
return null;
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
+
// src/extensions/plan/state-machine.ts
|
|
417
|
+
var PLAN_LIFECYCLE_STATES = [
|
|
418
|
+
"idle",
|
|
419
|
+
"planning",
|
|
420
|
+
"reviewing",
|
|
421
|
+
"revising",
|
|
422
|
+
"approved",
|
|
423
|
+
"dispatching",
|
|
424
|
+
"completed",
|
|
425
|
+
"exited"
|
|
426
|
+
];
|
|
427
|
+
var PLAN_LIFECYCLE_EVENTS = [
|
|
428
|
+
"enter",
|
|
429
|
+
"submit",
|
|
430
|
+
"revise",
|
|
431
|
+
"dismiss",
|
|
432
|
+
"review_aborted",
|
|
433
|
+
"approve",
|
|
434
|
+
"exec_chosen",
|
|
435
|
+
"later",
|
|
436
|
+
"exit"
|
|
437
|
+
];
|
|
438
|
+
var TRANSITION_TABLE = {
|
|
439
|
+
idle: { enter: "planning" },
|
|
440
|
+
planning: { submit: "reviewing", exit: "exited" },
|
|
441
|
+
reviewing: {
|
|
442
|
+
submit: "reviewing",
|
|
443
|
+
revise: "revising",
|
|
444
|
+
dismiss: "planning",
|
|
445
|
+
review_aborted: "planning",
|
|
446
|
+
approve: "dispatching",
|
|
447
|
+
exit: "exited"
|
|
448
|
+
},
|
|
449
|
+
revising: { submit: "reviewing", exit: "exited" },
|
|
450
|
+
approved: { approve: "dispatching", exit: "exited" },
|
|
451
|
+
dispatching: {
|
|
452
|
+
review_aborted: "approved",
|
|
453
|
+
exec_chosen: "completed",
|
|
454
|
+
later: "approved",
|
|
455
|
+
exit: "exited"
|
|
456
|
+
},
|
|
457
|
+
completed: { enter: "planning" },
|
|
458
|
+
exited: { enter: "planning" }
|
|
459
|
+
};
|
|
460
|
+
function transition(state, event) {
|
|
461
|
+
if (!PLAN_LIFECYCLE_STATES.includes(state) || !PLAN_LIFECYCLE_EVENTS.includes(event)) {
|
|
462
|
+
return { ok: false };
|
|
463
|
+
}
|
|
464
|
+
const next = TRANSITION_TABLE[state][event];
|
|
465
|
+
return next === void 0 ? { ok: false } : { ok: true, next };
|
|
466
|
+
}
|
|
467
|
+
var PHASE_OF_STATE = {
|
|
468
|
+
idle: "idle",
|
|
469
|
+
planning: "planning",
|
|
470
|
+
reviewing: "reviewing",
|
|
471
|
+
revising: "planning",
|
|
472
|
+
approved: "approved",
|
|
473
|
+
dispatching: "approved",
|
|
474
|
+
completed: "terminal",
|
|
475
|
+
exited: "terminal"
|
|
476
|
+
};
|
|
477
|
+
function derivePhase(state) {
|
|
478
|
+
if (!PLAN_LIFECYCLE_STATES.includes(state)) return "idle";
|
|
479
|
+
return PHASE_OF_STATE[state];
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/extensions/plan/review-contract.ts
|
|
483
|
+
var PLAN_SELF_REVIEW_MAX_BYTES = 4096;
|
|
484
|
+
var UTF8_1_BYTE_CP_MAX = 127;
|
|
485
|
+
var UTF8_2_BYTE_CP_MAX = 2047;
|
|
486
|
+
var UTF8_3_BYTE_CP_MAX = 65535;
|
|
487
|
+
function utf8ByteLengthOfCodePoint(cp) {
|
|
488
|
+
if (cp <= UTF8_1_BYTE_CP_MAX) return 1;
|
|
489
|
+
if (cp <= UTF8_2_BYTE_CP_MAX) return 2;
|
|
490
|
+
if (cp <= UTF8_3_BYTE_CP_MAX) return 3;
|
|
491
|
+
return 4;
|
|
492
|
+
}
|
|
493
|
+
function truncateSelfReview(text) {
|
|
494
|
+
let bytes = 0;
|
|
495
|
+
let i = 0;
|
|
496
|
+
while (i < text.length) {
|
|
497
|
+
const cp = text.codePointAt(i);
|
|
498
|
+
if (cp === void 0) break;
|
|
499
|
+
const size = utf8ByteLengthOfCodePoint(cp);
|
|
500
|
+
if (bytes + size > PLAN_SELF_REVIEW_MAX_BYTES) break;
|
|
501
|
+
bytes += size;
|
|
502
|
+
i += cp > UTF8_3_BYTE_CP_MAX ? 2 : 1;
|
|
503
|
+
}
|
|
504
|
+
return text.slice(0, i);
|
|
505
|
+
}
|
|
506
|
+
function isPlanDocMeta(value) {
|
|
507
|
+
if (typeof value !== "object" || value === null) return false;
|
|
508
|
+
const doc = value;
|
|
509
|
+
return typeof doc.fileName === "string" && typeof doc.absPath === "string" && typeof doc.sourceSkill === "string" && typeof doc.version === "number";
|
|
510
|
+
}
|
|
511
|
+
function isPlanReviewRequest(value) {
|
|
512
|
+
if (typeof value !== "object" || value === null) return false;
|
|
513
|
+
const req = value;
|
|
514
|
+
if (!Array.isArray(req.docs) || !req.docs.every(isPlanDocMeta)) return false;
|
|
515
|
+
if (req.selfReview !== void 0 && typeof req.selfReview !== "string") return false;
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
function normalizeComments(value) {
|
|
519
|
+
if (!Array.isArray(value)) return null;
|
|
520
|
+
const comments = [];
|
|
521
|
+
for (const item of value) {
|
|
522
|
+
if (typeof item !== "object" || item === null) return null;
|
|
523
|
+
const c = item;
|
|
524
|
+
if (typeof c.quote !== "string" || typeof c.comment !== "string") return null;
|
|
525
|
+
comments.push({ quote: c.quote, comment: c.comment });
|
|
526
|
+
}
|
|
527
|
+
return { decision: "revise", comments };
|
|
528
|
+
}
|
|
529
|
+
function parsePlanReviewResponse(value) {
|
|
530
|
+
if (typeof value !== "object" || value === null) return { ok: false, code: "malformed" };
|
|
531
|
+
const raw = value;
|
|
532
|
+
const decision = raw.decision;
|
|
533
|
+
if (typeof decision !== "string") return { ok: false, code: "malformed" };
|
|
534
|
+
switch (decision) {
|
|
535
|
+
case "approve":
|
|
536
|
+
return { ok: true, response: { decision: "approve" } };
|
|
537
|
+
case "dismiss":
|
|
538
|
+
return { ok: true, response: { decision: "dismiss" } };
|
|
539
|
+
case "revise": {
|
|
540
|
+
const response = normalizeComments(raw.comments);
|
|
541
|
+
return response === null ? { ok: false, code: "malformed" } : { ok: true, response };
|
|
542
|
+
}
|
|
543
|
+
default:
|
|
544
|
+
return { ok: false, code: "unknown-decision", decision };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function isPlanReviewResponse(value) {
|
|
548
|
+
return parsePlanReviewResponse(value).ok;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// src/extensions/plan/legacy-entries.ts
|
|
552
|
+
var PLAN_STATE_CUSTOM_TYPE = "plan-state";
|
|
553
|
+
function readLifecycleState(data, isActive) {
|
|
554
|
+
const raw = data.state;
|
|
555
|
+
if (typeof raw === "string" && PLAN_LIFECYCLE_STATES.includes(raw)) {
|
|
556
|
+
return raw;
|
|
557
|
+
}
|
|
558
|
+
if (data.reviewState === "awaiting") return "reviewing";
|
|
559
|
+
if (data.reviewState === "revising") return "revising";
|
|
560
|
+
return isActive ? "planning" : "idle";
|
|
561
|
+
}
|
|
562
|
+
function readResumeHint(data) {
|
|
563
|
+
if (data.resumeHint === "resubmit") return "resubmit";
|
|
564
|
+
return data.reviewStateSource === "resubmit" ? "resubmit" : void 0;
|
|
565
|
+
}
|
|
566
|
+
|
|
416
567
|
// src/extensions/ui-form/marker.ts
|
|
417
568
|
var UI_FORM_MARKER = "\0TAIJI_UI_FORM";
|
|
418
569
|
|
|
@@ -517,14 +668,27 @@ function isRecord(v) {
|
|
|
517
668
|
function isOptionalString2(v) {
|
|
518
669
|
return v === void 0 || typeof v === "string";
|
|
519
670
|
}
|
|
671
|
+
function isOptionalNumber(v) {
|
|
672
|
+
return v === void 0 || typeof v === "number";
|
|
673
|
+
}
|
|
674
|
+
function isOptionalNumberOrNull(v) {
|
|
675
|
+
return v === void 0 || v === null || typeof v === "number";
|
|
676
|
+
}
|
|
677
|
+
var NOTIFY_ID_PATTERN = /^sm-[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
678
|
+
function isSessionManagerNotifyId(v) {
|
|
679
|
+
return typeof v === "string" && NOTIFY_ID_PATTERN.test(v);
|
|
680
|
+
}
|
|
681
|
+
function isOptionalNotifyId(v) {
|
|
682
|
+
return v === void 0 || typeof v === "string";
|
|
683
|
+
}
|
|
520
684
|
function isSessionIdParams(v) {
|
|
521
685
|
return isRecord(v) && typeof v.sessionId === "string";
|
|
522
686
|
}
|
|
523
687
|
function isSessionManagerCreateParams(v) {
|
|
524
|
-
return isRecord(v) && isOptionalString2(v.cwd) && isOptionalString2(v.label) && isOptionalString2(v.prompt);
|
|
688
|
+
return isRecord(v) && isOptionalString2(v.cwd) && isOptionalString2(v.label) && isOptionalString2(v.prompt) && isOptionalNotifyId(v.notifyId);
|
|
525
689
|
}
|
|
526
690
|
function isSessionManagerSendParams(v) {
|
|
527
|
-
return isRecord(v) && typeof v.sessionId === "string" && typeof v.prompt === "string";
|
|
691
|
+
return isRecord(v) && typeof v.sessionId === "string" && typeof v.prompt === "string" && isOptionalNotifyId(v.notifyId);
|
|
528
692
|
}
|
|
529
693
|
function isSessionManagerHistoryParams(v) {
|
|
530
694
|
return isRecord(v) && typeof v.sessionId === "string" && (v.tailTurns === void 0 || typeof v.tailTurns === "number");
|
|
@@ -538,10 +702,36 @@ function isSessionManagerAbortParams(v) {
|
|
|
538
702
|
function isSessionManagerListParams(v) {
|
|
539
703
|
return isRecord(v);
|
|
540
704
|
}
|
|
705
|
+
function isSessionManagerWatchParams(v) {
|
|
706
|
+
if (!isRecord(v)) return false;
|
|
707
|
+
const keys = Object.keys(v);
|
|
708
|
+
return keys.length === 1 && keys[0] === "notifyId" && isSessionManagerNotifyId(v.notifyId);
|
|
709
|
+
}
|
|
710
|
+
var WATCH_REASON_SET = /* @__PURE__ */ new Set([
|
|
711
|
+
"completed",
|
|
712
|
+
"failed",
|
|
713
|
+
"stopped",
|
|
714
|
+
"exited",
|
|
715
|
+
"deleted",
|
|
716
|
+
"cancelled",
|
|
717
|
+
"orphaned"
|
|
718
|
+
]);
|
|
719
|
+
function isSessionManagerWatchRespondPayload(v) {
|
|
720
|
+
if (!isRecord(v)) return false;
|
|
721
|
+
if (typeof v.reason !== "string" || !WATCH_REASON_SET.has(v.reason)) return false;
|
|
722
|
+
if (!isOptionalString2(v.sessionId)) return false;
|
|
723
|
+
if (!isOptionalNumber(v.deathSeq)) return false;
|
|
724
|
+
if (!isOptionalNumber(v.settleSeq)) return false;
|
|
725
|
+
if (!isOptionalNumber(v.fulfillsN)) return false;
|
|
726
|
+
if (!isOptionalNumberOrNull(v.exitCode)) return false;
|
|
727
|
+
if (!isOptionalString2(v.stderrTail)) return false;
|
|
728
|
+
if (!isOptionalString2(v.sessionFilePath)) return false;
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
541
731
|
|
|
542
732
|
// src/extensions/session-manager/marker.ts
|
|
543
733
|
var SESSION_MANAGER_MARKER = "\0TAIJI_SESSION_MANAGER";
|
|
544
|
-
var SESSION_MANAGER_ACTIONS = ["create", "send", "history", "status", "list", "abort"];
|
|
734
|
+
var SESSION_MANAGER_ACTIONS = ["create", "send", "history", "status", "list", "abort", "watch"];
|
|
545
735
|
|
|
546
736
|
// src/extensions/subagent-inflight/marker.ts
|
|
547
737
|
var SUBAGENT_INFLIGHT_MARKER = "\0TAIJI_SUBAGENT_INFLIGHT";
|
|
@@ -633,31 +823,25 @@ function collectActivePendingIds(entries, opts) {
|
|
|
633
823
|
}
|
|
634
824
|
return ids;
|
|
635
825
|
}
|
|
826
|
+
var REASON_STATUS_MAP = {
|
|
827
|
+
completed: "completed",
|
|
828
|
+
failed: "failed",
|
|
829
|
+
cancelled: "cancelled",
|
|
830
|
+
expired: "expired",
|
|
831
|
+
time_limited: "time_limited",
|
|
832
|
+
budget_limited: "failed",
|
|
833
|
+
aborted: "aborted",
|
|
834
|
+
interrupted: "aborted",
|
|
835
|
+
"interrupted-by-restart": "aborted",
|
|
836
|
+
"interrupted-by-parent": "aborted",
|
|
837
|
+
reopened: "completed",
|
|
838
|
+
stopped: "aborted",
|
|
839
|
+
exited: "cancelled",
|
|
840
|
+
deleted: "cancelled",
|
|
841
|
+
orphaned: "cancelled"
|
|
842
|
+
};
|
|
636
843
|
function mapReasonToStatus(reason) {
|
|
637
|
-
|
|
638
|
-
case "completed":
|
|
639
|
-
return "completed";
|
|
640
|
-
case "failed":
|
|
641
|
-
return "failed";
|
|
642
|
-
case "cancelled":
|
|
643
|
-
return "cancelled";
|
|
644
|
-
case "expired":
|
|
645
|
-
return "expired";
|
|
646
|
-
case "time_limited":
|
|
647
|
-
return "time_limited";
|
|
648
|
-
case "budget_limited":
|
|
649
|
-
return "failed";
|
|
650
|
-
case "aborted":
|
|
651
|
-
return "aborted";
|
|
652
|
-
case "interrupted":
|
|
653
|
-
case "interrupted-by-restart":
|
|
654
|
-
case "interrupted-by-parent":
|
|
655
|
-
return "aborted";
|
|
656
|
-
case "reopened":
|
|
657
|
-
return "completed";
|
|
658
|
-
default:
|
|
659
|
-
return "completed";
|
|
660
|
-
}
|
|
844
|
+
return REASON_STATUS_MAP[reason] ?? "completed";
|
|
661
845
|
}
|
|
662
846
|
export {
|
|
663
847
|
ASK_USER_MARKER,
|
|
@@ -677,7 +861,11 @@ export {
|
|
|
677
861
|
MS_PER_SECOND,
|
|
678
862
|
PENDING_REGISTER_ENTRY_TYPE,
|
|
679
863
|
PENDING_UNREGISTER_ENTRY_TYPE,
|
|
864
|
+
PLAN_LIFECYCLE_EVENTS,
|
|
865
|
+
PLAN_LIFECYCLE_STATES,
|
|
680
866
|
PLAN_REVIEW_MARKER,
|
|
867
|
+
PLAN_SELF_REVIEW_MAX_BYTES,
|
|
868
|
+
PLAN_STATE_CUSTOM_TYPE,
|
|
681
869
|
PROTOCOL_VERSION,
|
|
682
870
|
SCHEDULE_CREATE_MARKER,
|
|
683
871
|
SESSION_MANAGER_ACTIONS,
|
|
@@ -694,6 +882,7 @@ export {
|
|
|
694
882
|
callMarkerRpc,
|
|
695
883
|
collectActivePendingIds,
|
|
696
884
|
dateToOnceCron,
|
|
885
|
+
derivePhase,
|
|
697
886
|
extractGui,
|
|
698
887
|
firstContentText,
|
|
699
888
|
formatChannelErrorText,
|
|
@@ -719,23 +908,33 @@ export {
|
|
|
719
908
|
isGuiComponent,
|
|
720
909
|
isGuiRenderResult,
|
|
721
910
|
isInFlightReportAck,
|
|
911
|
+
isPlanReviewRequest,
|
|
912
|
+
isPlanReviewResponse,
|
|
722
913
|
isScheduleDraft,
|
|
723
914
|
isScheduleFormResult,
|
|
724
915
|
isSessionManagerAbortParams,
|
|
725
916
|
isSessionManagerCreateParams,
|
|
726
917
|
isSessionManagerHistoryParams,
|
|
727
918
|
isSessionManagerListParams,
|
|
919
|
+
isSessionManagerNotifyId,
|
|
728
920
|
isSessionManagerSendParams,
|
|
729
921
|
isSessionManagerStatusParams,
|
|
922
|
+
isSessionManagerWatchParams,
|
|
923
|
+
isSessionManagerWatchRespondPayload,
|
|
730
924
|
isSubagentInFlightReport,
|
|
731
925
|
isSyncedTool,
|
|
732
926
|
isTerminalBackgroundTaskState,
|
|
733
927
|
mapReasonToStatus,
|
|
734
928
|
onceCronToDate,
|
|
929
|
+
parsePlanReviewResponse,
|
|
930
|
+
readLifecycleState,
|
|
931
|
+
readResumeHint,
|
|
735
932
|
replayFoldEntries,
|
|
736
933
|
scanPendingEntries,
|
|
737
934
|
setWidgetDual,
|
|
738
935
|
snapshotToTask,
|
|
936
|
+
transition,
|
|
937
|
+
truncateSelfReview,
|
|
739
938
|
uiFormInteract,
|
|
740
939
|
validateWidgetIconPaths
|
|
741
940
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/extension-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Cross-layer pi extension contract package: dual-mode (TUI/GUI) rendering helpers, session/background-task/pending-entries protocols, and shared behavior primitives",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|