@zhushanwen/extension-protocol 0.22.0 → 0.23.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 CHANGED
@@ -404,8 +404,9 @@ declare function firstContentText(result: {
404
404
  * {action,params} / 快照帧,不引入内部 stringify 异常面);
405
405
  * - mode 门控留调用方(inflight 在 attachSession 处 / session-manager 无门控——
406
406
  * 四态 reason 无 non-rpc 语义);
407
- * - `ui.select` 缺席(非 GUI ctx)由调用方前置判定(沿 ask-user askUserInteract 的
408
- * `isGuiCapable(ctx) && ctx.ui?.select` 先例);误用即 throw 明确错误。
407
+ * - `ui.select` 缺席(非 GUI ctx)由调用方前置判定(沿已退役的 ask-user askUserInteract
408
+ * 先例——`isGuiCapable(ctx) && ctx.ui?.select`,git 历史可溯;isGuiCapable 现存于本包
409
+ * core/helpers 并经包入口导出);误用即 throw 明确错误。
409
410
  *
410
411
  * 设计权威源:docs/architecture/ext-simplify-17-shared-extraction.md §3.3 D8(v7 冻结形态)。
411
412
  */
@@ -429,15 +430,24 @@ interface MarkerRpcOptions {
429
430
  }
430
431
  /** 错误回包底层形状:select+marker 通道各协议(session-manager)
431
432
  * runtime 侧异常折叠的共用单源(不裸 reject,error 闭环走同一回包通道)。
432
- * SessionManagerErrorResult 是本形状的 alias(D8 单源化)。 */
433
+ * SessionManagerErrorResult 是本形状的 alias(D8 单源化)。
434
+ *
435
+ * `code`(session-manager-archive-delete U2,additive optional):结构化错误码
436
+ * 透传通道(如 ArchiveError 的 `archive_generating`)——旧 runtime 不产出、旧
437
+ * extension 不消费,只加字段不破坏现有消费方。 */
433
438
  interface ChannelErrorResult {
434
439
  error: string;
435
440
  hint?: string;
441
+ code?: string;
436
442
  }
437
- /** 运行时形状检查:{error: string}(hint 可选,不校验其类型;排数组) */
443
+ /** 运行时形状检查:{error: string}(hint 可选,不校验其类型;code additive 宽容
444
+ * ——缺席放行(旧 runtime 兼容象限)、present 须为 string;排数组) */
438
445
  declare function isChannelErrorResult(v: unknown): v is ChannelErrorResult;
439
- /** error + hint 文本拼接(hint 缺席只回 error)——plugin-bridge errorResult 与
440
- * session-manager 错误闭环文本的共用单源 */
446
+ /** error + code + hint 文本拼接(code/hint 缺席各自省略对应行)——plugin-bridge
447
+ * errorResult 与 session-manager 错误闭环文本的共用单源。code present 时以
448
+ * `error_code: <code>` 行拼入(session-manager-archive-delete 决策 5:结构化错误码
449
+ * 对模型可见——工具 description 教 agent 认的码词在 throw 文本里在场,善后层恢复
450
+ * 指引的第一跳不断链);code 缺席(旧 runtime 回包 / canvas 等无码消费方)行为不变 */
441
451
  declare function formatChannelErrorText(err: ChannelErrorResult): string;
442
452
  /**
443
453
  * 经 select 通道发起一次 marker RPC。
@@ -829,14 +839,20 @@ declare function dateToOnceCron(date: Date): string;
829
839
  declare function onceCronToDate(cron: string, now?: Date): Date | null;
830
840
 
831
841
  /**
832
- * plan 模式生命周期状态机(plan 模式状态机显式化 D1)——纯数据 + 纯函数,零依赖。
842
+ * plan 模式生命周期状态机(plan 模式状态机显式化 D1)——8 值状态集 + 9 事件
843
+ * 边表的单一状态契约。表与判定迁移 @zhushanwen/state-machine 基建承载(M4):
844
+ * 矩阵改行式声明 + errorPolicy:'result'(表外 `{ ok: false }` 不炸 turn)+ 原型链
845
+ * 白名单口径统一到机器 coerceState(域内枚举 includes 白名单先例被基建吸收,
846
+ * V10);对外 `transition` / `derivePhase` 签名与返回形态保形(消费方零改动,
847
+ * 消费方清单 = consumers.md)。
833
848
  *
834
849
  * plan 模式的状态散落在 pi 扩展 entry / runtime 挂起注册表 / renderer 派生公式三处时,
835
850
  * 任意两者漂移即产「僵尸/谎言」UI(F1-F5)。本模块是全链路共享的单一状态契约:
836
851
  * 8 值状态集 + 9 事件边表 + `transition` 纯函数(检查集中一处)+ `derivePhase` 呈现映射。
837
852
  *
838
853
  * 语义要点(设计 D1 逐条锚定):
839
- * - 非法转移返回 `{ ok: false }`,由调用方降级(**不 throw 炸 turn**);副作用不进返回值
854
+ * - 非法转移返回 `{ ok: false }`(机器 errorPolicy:'result' 的表外分支转译——不携带
855
+ * next 键、不 throw),由调用方降级(**不 throw 炸 turn**);副作用不进返回值
840
856
  * (effects-as-data 无已登记消费方属投机间接层),各 action 在转移成功后内联执行自身副作用。
841
857
  * - `reviewing --dismiss--> planning`:用户「搁置」(协议级 dismiss 决策,D3)——落盘即
842
858
  * planning,被搁置的审批不复活(F1/F2/F3 构造性消除)。
@@ -857,10 +873,10 @@ declare function onceCronToDate(cron: string, now?: Date): Date | null;
857
873
  * - `reviewing --submit--> reviewing`:审批重挂自环(E3 会话重启恢复 / D8「重新提交审批」
858
874
  * 按钮——重提交不推进生命周期,落盘回 reviewing 重挂即等价于旧调用方特判放行形态)。
859
875
  *
860
- * 呈现映射(derivePhase):用户视角四主态 + idle 缺省——四主态是呈现,不是存储
861
- * (用户口述模型 = 呈现层,reviewing/dispatching 两个挂起态是崩溃恢复的真实分叉点,
862
- * 存储层保留 8 值)。终态两值(completed = 批准并派发执行 / exited = 主动退出)共享
863
- * 全部终态规则,呈现层同映 'terminal'(诊断/审计语义保留存储区分)。
876
+ * 发布位次登记(D7③):本包(@zhushanwen/extension-protocol)自 M4 起依赖
877
+ * @zhushanwen/state-machine(workspace 协议),npm 发布顺序必须基建包在先——
878
+ * 位次断链时 npm 消费者会装到缺依赖的 extension-protocol(changeset 依赖图
879
+ * 自然保证,发布 PR 人工核对本条)。
864
880
  */
865
881
  type PlanLifecycleState = 'idle' | 'planning' | 'reviewing' | 'revising' | 'approved' | 'dispatching' | 'completed' | 'exited';
866
882
  /** 状态穷举表(运行时消费:E3 恢复查表 / 测试穷举基座)——顺序 = 生命周期自然序。 */
@@ -875,19 +891,20 @@ type PlanTransitionResult = {
875
891
  ok: false;
876
892
  };
877
893
  /**
878
- * 纯函数转移:`(state, event) → { ok: true, next } | { ok: false }`。
894
+ * 纯函数转移:`(state, event) → { ok: true, next } | { ok: false }`——机器
895
+ * errorPolicy:'result' 判定的保形包装(签名与返回形态不变,消费方零改动)。
879
896
  *
880
897
  * 非法转移(含运行时垃圾 state/event 值——跨版本帧、坏反序列化)返回 `{ ok: false }`
881
898
  * 且**不携带 next 键**,由调用方降级(不 throw 炸 turn)。调用方义务:`ok:false` 时
882
899
  * 不落盘、不执行副作用(终态上 `ok:false` 不落盘即 D3 归属划分点的兜底保险)。
883
900
  *
884
- * 入口白名单检查(与 derivePhase 同一机制):普通对象字面量查表会沿原型链命中继承键——
885
- * `transition('reviewing', '__proto__')` 取出 Object.prototype、`('__proto__', 'valueOf')`
886
- * 取出函数,均被误判为合法 next(违背本契约)。故垃圾键必须先挡在查表前。
887
- * **选「枚举 includes 白名单」而非 null-prototype 表 / Object.hasOwn**:① transition 与
888
- * derivePhase 共用同一检查形态(单一机制,不并存两种写法);② PLAN_LIFECYCLE_STATES /
889
- * PLAN_LIFECYCLE_EVENTS 就是值域 SSOT(测试穷举同源),includes 判定与之同源,
890
- * 原型键天然不在白名单内。
901
+ * 垃圾输入的分层判定(原型链白名单口径已统一到基建 coerceState 的同族机制):
902
+ * 词表外 state 由机器词表集合拒绝(Set 查询不走原型链);词表外 event 字符串由
903
+ * 机器 (from, on) 行索引拒绝(Map 复合键查询不走原型链);非字符串 event 由基建
904
+ * 归一 undefined 落入表外拒绝(§5.2 失败路径表第 3 行,不 crash),下方前置守卫
905
+ * 是域内显式等价拒绝(同结果先行返回,「不炸 turn」契约双保险)。plan 表无
906
+ * to:null 消亡行(基建 null 语义 = 实体离开机器,plan 8 态全在机器内),state 为
907
+ * null 的分支运行时不可达,收窄仅为类型完备。
891
908
  */
892
909
  declare function transition(state: PlanLifecycleState, event: PlanLifecycleEvent): PlanTransitionResult;
893
910
  /**
@@ -904,9 +921,10 @@ type PlanPhase = 'idle' | 'planning' | 'reviewing' | 'approved' | 'terminal';
904
921
  * 8 存储态 → 5 呈现相位的单点映射(renderer 阶段指示/状态带共用,禁止消费方各自 if 拼)。
905
922
  * 运行时垃圾 state(混装格坏帧)降级 'idle'(无 plan 缺省,fail-safe 不误示进行中)。
906
923
  *
907
- * 入口白名单检查(理由同 transition,见彼处):裸查表对继承键 'constructor' / 'toString'
908
- * 会取出 Object 构造函数等并经 `?? 'idle'` 流出(非 nullish 不落兜底)——垃圾 state
909
- * 必须精确落 'idle',函数/对象不得作为相位流入 renderer。
924
+ * 入口白名单检查 = 机器 coerceState(原型链白名单口径统一到基建,V10):裸查表对
925
+ * 继承键 'constructor' / 'toString' 会取出 Object 构造函数等并经 `?? 'idle'` 流出
926
+ * (非 nullish 不落兜底)——垃圾 state 必须精确落 'idle',函数/对象不得作为相位
927
+ * 流入 renderer。
910
928
  */
911
929
  declare function derivePhase(state: PlanLifecycleState): PlanPhase;
912
930
 
@@ -986,8 +1004,8 @@ declare const PLAN_STATE_CUSTOM_TYPE = "plan-state";
986
1004
  /**
987
1005
  * 生命周期状态读取(D2 读方①②共用映射,原扩展 state.ts / runtime extractor 内联拷贝的
988
1006
  * 单源归并):
989
- * ① 新字段直读(值域检查:PLAN_LIFECYCLE_STATES 之外的垃圾值按缺失处理,落映射——
990
- * 不信任外部写入);
1007
+ * ① 新字段直读(值域检查 = 机器 coerceState 归化,词表外/原型链键垃圾值按缺失处理,
1008
+ * 落映射——不信任外部写入;M4 白名单口径统一);
991
1009
  * ② 旧 entry 无 state(或垃圾 state)时映射 reviewState(awaiting→reviewing /
992
1010
  * revising→revising / 其余值→planning|idle 按 isActive)。
993
1011
  */
@@ -1183,25 +1201,29 @@ declare function isFormAnswers(value: unknown): value is FormAnswers;
1183
1201
  */
1184
1202
  declare const SESSION_MANAGER_MARKER = "\0TAIJI_SESSION_MANAGER";
1185
1203
  /**
1186
- * 7 个 action 的运行时集合(与 SessionManagerAction 类型同源——types.ts 从此派生)。
1204
+ * 9 个 action 的运行时集合(与 SessionManagerAction 类型同源——types.ts 从此派生)。
1187
1205
  * event-adapter 用它把 JSON 解析出的 action 字符串收窄为联合类型,
1188
1206
  * 非法值折叠为 '__malformed__' 哨兵(与 handler default 分支同走 cancelled)。
1189
1207
  *
1208
+ * 'delete' / 'archive'(session-manager-archive-delete U2):终局操作双 action——
1209
+ * delete 整树废纸篓不可恢复(USER-INITIATED ONLY,约束承载在 extension 工具文案层)、
1210
+ * archive 归档退场可由用户恢复;扩展归属校验在 runtime handler 侧(协议层只定契约)。
1211
+ *
1190
1212
  * 'watch'(notify-once D6):通知债权的纯应答通道——单键 params={notifyId} 寻址、
1191
1213
  * 不传 timeout、fire-and-forget 长挂 select;必须在本集合内,否则 event-adapter
1192
1214
  * 把它折叠成 '__malformed__'(旧 runtime 兼容象限的静默降级形态),watch 永远到不了
1193
1215
  * handler 路由。
1194
1216
  */
1195
- declare const SESSION_MANAGER_ACTIONS: readonly ["create", "send", "history", "status", "list", "abort", "watch"];
1217
+ declare const SESSION_MANAGER_ACTIONS: readonly ["create", "send", "history", "status", "list", "abort", "delete", "archive", "watch"];
1196
1218
 
1197
1219
  /**
1198
1220
  * session-manager extension 的类型定义。
1199
1221
  *
1200
- * 7 个 action 的请求 params 和结果类型,供 handler 和 extension 共用。
1222
+ * 9 个 action 的请求 params 和结果类型,供 handler 和 extension 共用。
1201
1223
  * marker 检测后按 action 分发到对应 handler 分支。
1202
1224
  */
1203
1225
 
1204
- /** session-manager 支持的 7 个 action(从 SESSION_MANAGER_ACTIONS 集合派生,值与类型同源) */
1226
+ /** session-manager 支持的 9 个 action(从 SESSION_MANAGER_ACTIONS 集合派生,值与类型同源) */
1205
1227
  type SessionManagerAction = (typeof SESSION_MANAGER_ACTIONS)[number];
1206
1228
  /** 各 action 的请求参数映射 */
1207
1229
  interface SessionManagerParams {
@@ -1211,6 +1233,8 @@ interface SessionManagerParams {
1211
1233
  status: SessionManagerStatusParams;
1212
1234
  list: SessionManagerListParams;
1213
1235
  abort: SessionManagerAbortParams;
1236
+ delete: SessionManagerDeleteParams;
1237
+ archive: SessionManagerArchiveParams;
1214
1238
  watch: SessionManagerWatchParams;
1215
1239
  }
1216
1240
  /** create action 参数 */
@@ -1253,6 +1277,23 @@ type SessionManagerListParams = Record<string, never>;
1253
1277
  interface SessionManagerAbortParams {
1254
1278
  sessionId: string;
1255
1279
  }
1280
+ /**
1281
+ * delete action 参数(session-manager-archive-delete U2):彻底删除目标会话
1282
+ * (进程 + 历史 + 衍生数据整树废纸篓,不可恢复)。人身约束(USER-INITIATED ONLY)
1283
+ * 承载在 extension 工具文案层,协议层只定契约。归属校验用扩展归属校验
1284
+ * (含磁盘回退)在 runtime handler 侧执行。
1285
+ */
1286
+ interface SessionManagerDeleteParams {
1287
+ sessionId: string;
1288
+ }
1289
+ /**
1290
+ * archive action 参数(session-manager-archive-delete U2):归档目标会话——
1291
+ * 退场进归档区、文件压缩搬移、可由用户恢复。生成中会话拒绝(错误码
1292
+ * archive_generating 经 ChannelErrorResult.code 透传)。
1293
+ */
1294
+ interface SessionManagerArchiveParams {
1295
+ sessionId: string;
1296
+ }
1256
1297
  /**
1257
1298
  * watch action 参数(notify-once D2/D6):通知债权的纯应答通道,**单键寻址**——
1258
1299
  * runtime 按 `(调用方 parentSid, notifyId)` 反查 claim,parentSid 取自调用方连接身份、
@@ -1270,9 +1311,11 @@ declare function isSessionManagerCreateParams(v: unknown): v is SessionManagerCr
1270
1311
  declare function isSessionManagerSendParams(v: unknown): v is SessionManagerSendParams;
1271
1312
  /** history:sessionId 必填、tailTurns 可选 number */
1272
1313
  declare function isSessionManagerHistoryParams(v: unknown): v is SessionManagerHistoryParams;
1273
- /** status / abort:sessionId 必填 */
1314
+ /** status / abort / delete / archive:sessionId 必填 */
1274
1315
  declare function isSessionManagerStatusParams(v: unknown): v is SessionManagerStatusParams;
1275
1316
  declare function isSessionManagerAbortParams(v: unknown): v is SessionManagerAbortParams;
1317
+ declare function isSessionManagerDeleteParams(v: unknown): v is SessionManagerDeleteParams;
1318
+ declare function isSessionManagerArchiveParams(v: unknown): v is SessionManagerArchiveParams;
1276
1319
  /** list:无参数(过滤由 handler 固化,params 不携带任何过滤字段) */
1277
1320
  declare function isSessionManagerListParams(v: unknown): v is SessionManagerListParams;
1278
1321
  /**
@@ -1345,6 +1388,24 @@ interface SessionManagerSessionSummary {
1345
1388
  interface SessionManagerAbortResult {
1346
1389
  success: boolean;
1347
1390
  }
1391
+ /**
1392
+ * delete 结果(session-manager-archive-delete U2):字段名以设计 §3.1 交互样例为权威
1393
+ * ——成功回包 `{sessionId, deleted:true}`。侧栏消失 + 整树废纸篓由 runtime delete 链
1394
+ * 内建,协议回包只做完成陈述。
1395
+ */
1396
+ interface SessionManagerDeleteResult {
1397
+ deleted: true;
1398
+ sessionId: string;
1399
+ }
1400
+ /**
1401
+ * archive 结果(session-manager-archive-delete U2):字段名以设计 §3.1 交互样例为权威
1402
+ * ——成功回包 `{sessionId, archived:true}`。归档成功后该会话全部通知债权由 runtime
1403
+ * handler 三步收尾统一应答 'exited'(协议范围外,契约属 handler 编排)。
1404
+ */
1405
+ interface SessionManagerArchiveResult {
1406
+ archived: true;
1407
+ sessionId: string;
1408
+ }
1348
1409
  /**
1349
1410
  * watch 应答 reason 词表(封闭 7 值)——与 pending-entries `mapReasonToStatus` 的
1350
1411
  * 4 个新 case 同词形(stopped→aborted、exited/deleted/orphaned→cancelled),
@@ -2438,4 +2499,4 @@ declare function mapReasonToStatus(reason: string): MappedPendingStatus;
2438
2499
  */
2439
2500
  declare const MAPPED_PENDING_STATUSES: ReadonlySet<string>;
2440
2501
 
2441
- export { ACTION_EVENT_MAP, ASK_USER_MARKER, type ArgumentMateriality, type ArgumentPolarity, type AskUserAnswers, type AskUserOption, type AskUserQuestion, CANVAS_ACTIONS, CANVAS_ACTOR_MATRIX, CANVAS_ERROR_CODES, CANVAS_ERROR_RECOVERY, CANVAS_EVENT_TYPES, CANVAS_MARKER, CANVAS_MARKER_ACTIONS, CANVAS_TOOL_NAMES, type CanvasAction, type CanvasActionParams, type CanvasActor, type CanvasComment, type CanvasCommentParams, type CanvasCommentRespondParams, type CanvasConvergeCheckParams, type CanvasCreateParams, type CanvasDecideDirectionParams, type CanvasDirectionDecision, type CanvasDispatchParams, type CanvasEdge, type CanvasEdgeType, type CanvasEnterParams, type CanvasError, type CanvasErrorCode, type CanvasEventType, type CanvasExportParams, type CanvasExportTarget, type CanvasGrowItem, type CanvasGrowParams, type CanvasListEntry, type CanvasListParams, type CanvasListReply, type CanvasMarkerAction, type CanvasMarkerParams, type CanvasMarkerRequest, type CanvasMutateReply, type CanvasMutateRequest, type CanvasNode, type CanvasNodeLifecycle, type CanvasNodeType, type CanvasPatchParams, type CanvasReadParams, type CanvasReadReply, type CanvasReviewAppendParams, type CanvasReviewEntryInput, type CanvasReviewRequestParams, type CanvasReviewResolveParams, type CanvasSelectParams, type CanvasState, type CanvasToolName, type CanvasTransitionParams, 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, JOURNAL_REPORT_ACK, MAPPED_PENDING_STATUSES, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, type MappedPendingStatus, type MarkerRpcOptions, type MarkerRpcResult, NON_TOOL_ACTIONS, 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 PendingFieldsScan, type PlanDocMeta, type PlanLifecycleEvent, type PlanLifecycleState, type PlanPhase, type PlanReviewComment, type PlanReviewDecision, type PlanReviewRequest, type PlanReviewResponse, type PlanReviewResponseEnvelope, type PlanTransitionResult, type ReplayFoldOptions, type ReviewDimension, type ReviewEntry, type ReviewReport, type ReviewReportStatus, type ReviewResolutionDisposition, type ReviewSeverity, SCHEDULER_MODAL_VIEW_ID, SCHEDULE_CREATE_MARKER, SESSION_MANAGER_ACTIONS, SESSION_MANAGER_MARKER, SUBAGENTS_ENGINES_FILENAME, SUBAGENT_BG_NOTIFY_CUSTOM_TYPE, SUBAGENT_DIRECTIVE_CUSTOM_TYPE, SUBAGENT_INFLIGHT_MARKER, SUBAGENT_JOURNAL_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 SubagentEngineModelInfo, type SubagentEnginesFile, type SubagentInFlightReport, type SubagentJournalDomain, type SubagentJournalEvent, type SubagentJournalReport, type SupportRating, TASK_ENTRY_TYPE, TOOL_ACTION_MAP, 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, allCanvasActions, allToolActions, appendExecutionRecord, applyPendingDiff, callMarkerRpc, canvasError, collectActivePendingIds, dateToOnceCron, derivePhase, extractGui, firstContentText, formatChannelErrorText, formatDuration, formatRelativeTime, formatSchedule, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isActionAllowed, isArgumentMateriality, isArgumentPolarity, isAskUserQuestion, isCanvasCommentParams, isCanvasCommentRespondParams, isCanvasConvergeCheckParams, isCanvasCreateParams, isCanvasDecideDirectionParams, isCanvasDispatchParams, isCanvasEnterParams, isCanvasExportParams, isCanvasGrowParams, isCanvasListParams, isCanvasMarkerRequest, isCanvasPatchParams, isCanvasReadParams, isCanvasReviewAppendParams, isCanvasReviewRequestParams, isCanvasReviewResolveParams, isCanvasSelectParams, isCanvasTransitionParams, isChannelErrorResult, isFormAnswers, isFormQuestion, isGuiCapable, isGuiComponent, isGuiRenderResult, isInFlightReportAck, isJournalReportAck, isPlanReviewRequest, isPlanReviewResponse, isScheduleDraft, isScheduleFormResult, isSessionManagerAbortParams, isSessionManagerCreateParams, isSessionManagerHistoryParams, isSessionManagerListParams, isSessionManagerNotifyId, isSessionManagerSendParams, isSessionManagerStatusParams, isSessionManagerWatchParams, isSessionManagerWatchRespondPayload, isSubagentInFlightReport, isSubagentJournalReport, mapReasonToStatus, onceCronToDate, parsePlanReviewResponse, readLifecycleState, readResumeHint, replayFoldEntries, scanPendingEntries, scanPendingFields, setWidgetDual, snapshotToTask, toolOfAction, transition, truncateSelfReview, uiFormInteract, validateWidgetIconPaths };
2502
+ export { ACTION_EVENT_MAP, ASK_USER_MARKER, type ArgumentMateriality, type ArgumentPolarity, type AskUserAnswers, type AskUserOption, type AskUserQuestion, CANVAS_ACTIONS, CANVAS_ACTOR_MATRIX, CANVAS_ERROR_CODES, CANVAS_ERROR_RECOVERY, CANVAS_EVENT_TYPES, CANVAS_MARKER, CANVAS_MARKER_ACTIONS, CANVAS_TOOL_NAMES, type CanvasAction, type CanvasActionParams, type CanvasActor, type CanvasComment, type CanvasCommentParams, type CanvasCommentRespondParams, type CanvasConvergeCheckParams, type CanvasCreateParams, type CanvasDecideDirectionParams, type CanvasDirectionDecision, type CanvasDispatchParams, type CanvasEdge, type CanvasEdgeType, type CanvasEnterParams, type CanvasError, type CanvasErrorCode, type CanvasEventType, type CanvasExportParams, type CanvasExportTarget, type CanvasGrowItem, type CanvasGrowParams, type CanvasListEntry, type CanvasListParams, type CanvasListReply, type CanvasMarkerAction, type CanvasMarkerParams, type CanvasMarkerRequest, type CanvasMutateReply, type CanvasMutateRequest, type CanvasNode, type CanvasNodeLifecycle, type CanvasNodeType, type CanvasPatchParams, type CanvasReadParams, type CanvasReadReply, type CanvasReviewAppendParams, type CanvasReviewEntryInput, type CanvasReviewRequestParams, type CanvasReviewResolveParams, type CanvasSelectParams, type CanvasState, type CanvasToolName, type CanvasTransitionParams, 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, JOURNAL_REPORT_ACK, MAPPED_PENDING_STATUSES, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, type MappedPendingStatus, type MarkerRpcOptions, type MarkerRpcResult, NON_TOOL_ACTIONS, 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 PendingFieldsScan, type PlanDocMeta, type PlanLifecycleEvent, type PlanLifecycleState, type PlanPhase, type PlanReviewComment, type PlanReviewDecision, type PlanReviewRequest, type PlanReviewResponse, type PlanReviewResponseEnvelope, type PlanTransitionResult, type ReplayFoldOptions, type ReviewDimension, type ReviewEntry, type ReviewReport, type ReviewReportStatus, type ReviewResolutionDisposition, type ReviewSeverity, SCHEDULER_MODAL_VIEW_ID, SCHEDULE_CREATE_MARKER, SESSION_MANAGER_ACTIONS, SESSION_MANAGER_MARKER, SUBAGENTS_ENGINES_FILENAME, SUBAGENT_BG_NOTIFY_CUSTOM_TYPE, SUBAGENT_DIRECTIVE_CUSTOM_TYPE, SUBAGENT_INFLIGHT_MARKER, SUBAGENT_JOURNAL_MARKER, type ScheduleDraft, type ScheduleFormResult, type ScheduleKind, type ScheduleQuestion, type ScheduleSpec, type ScheduledTask, type SchedulerEntryLike, type SchedulerEntryOp, type SessionManagerAbortParams, type SessionManagerAbortResult, type SessionManagerAction, type SessionManagerArchiveParams, type SessionManagerArchiveResult, type SessionManagerCreateParams, type SessionManagerCreateResult, type SessionManagerDeleteParams, type SessionManagerDeleteResult, 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 SubagentEngineModelInfo, type SubagentEnginesFile, type SubagentInFlightReport, type SubagentJournalDomain, type SubagentJournalEvent, type SubagentJournalReport, type SupportRating, TASK_ENTRY_TYPE, TOOL_ACTION_MAP, 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, allCanvasActions, allToolActions, appendExecutionRecord, applyPendingDiff, callMarkerRpc, canvasError, collectActivePendingIds, dateToOnceCron, derivePhase, extractGui, firstContentText, formatChannelErrorText, formatDuration, formatRelativeTime, formatSchedule, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isActionAllowed, isArgumentMateriality, isArgumentPolarity, isAskUserQuestion, isCanvasCommentParams, isCanvasCommentRespondParams, isCanvasConvergeCheckParams, isCanvasCreateParams, isCanvasDecideDirectionParams, isCanvasDispatchParams, isCanvasEnterParams, isCanvasExportParams, isCanvasGrowParams, isCanvasListParams, isCanvasMarkerRequest, isCanvasPatchParams, isCanvasReadParams, isCanvasReviewAppendParams, isCanvasReviewRequestParams, isCanvasReviewResolveParams, isCanvasSelectParams, isCanvasTransitionParams, isChannelErrorResult, isFormAnswers, isFormQuestion, isGuiCapable, isGuiComponent, isGuiRenderResult, isInFlightReportAck, isJournalReportAck, isPlanReviewRequest, isPlanReviewResponse, isScheduleDraft, isScheduleFormResult, isSessionManagerAbortParams, isSessionManagerArchiveParams, isSessionManagerCreateParams, isSessionManagerDeleteParams, isSessionManagerHistoryParams, isSessionManagerListParams, isSessionManagerNotifyId, isSessionManagerSendParams, isSessionManagerStatusParams, isSessionManagerWatchParams, isSessionManagerWatchRespondPayload, isSubagentInFlightReport, isSubagentJournalReport, mapReasonToStatus, onceCronToDate, parsePlanReviewResponse, readLifecycleState, readResumeHint, replayFoldEntries, scanPendingEntries, scanPendingFields, setWidgetDual, snapshotToTask, toolOfAction, transition, truncateSelfReview, uiFormInteract, validateWidgetIconPaths };
package/dist/index.js CHANGED
@@ -110,11 +110,14 @@ function stripUndefined(obj) {
110
110
  // src/core/select-rpc.ts
111
111
  var RESPONSE_PREVIEW_LENGTH = 200;
112
112
  function isChannelErrorResult(v) {
113
- return typeof v === "object" && v !== null && !Array.isArray(v) && typeof v.error === "string";
113
+ const rec = v;
114
+ return typeof v === "object" && v !== null && !Array.isArray(v) && typeof rec.error === "string" && (rec.code === void 0 || typeof rec.code === "string");
114
115
  }
115
116
  function formatChannelErrorText(err) {
116
- return err.hint ? `${err.error}
117
- hint: ${err.hint}` : err.error;
117
+ const lines = [err.error];
118
+ if (err.code) lines.push(`error_code: ${err.code}`);
119
+ if (err.hint) lines.push(`hint: ${err.hint}`);
120
+ return lines.join("\n");
118
121
  }
119
122
  function emitRpcLog(opts, msg, detail) {
120
123
  opts?.log?.(msg, detail);
@@ -123,7 +126,7 @@ async function callMarkerRpc(ctx, marker, payload, opts) {
123
126
  const select = ctx.ui?.select;
124
127
  if (!select) {
125
128
  throw new Error(
126
- `callMarkerRpc() requires ctx.ui.select (marker ${JSON.stringify(marker)}). Non-GUI ctx must be gated by the caller first \u2014 see askUserInteract precedent (isGuiCapable(ctx) && ctx.ui?.select, or a mode check).`
129
+ `callMarkerRpc() requires ctx.ui.select (marker ${JSON.stringify(marker)}). Non-GUI ctx must be gated by the caller first \u2014 gate with isGuiCapable(ctx) && ctx.ui?.select (exported from @zhushanwen/extension-protocol), or a mode check.`
127
130
  );
128
131
  }
129
132
  let value;
@@ -415,6 +418,7 @@ function onceCronToDate(cron, now = /* @__PURE__ */ new Date()) {
415
418
  }
416
419
 
417
420
  // src/extensions/plan/state-machine.ts
421
+ import { defineStateMachine } from "@zhushanwen/state-machine";
418
422
  var PLAN_LIFECYCLE_STATES = [
419
423
  "idle",
420
424
  "planning",
@@ -436,34 +440,57 @@ var PLAN_LIFECYCLE_EVENTS = [
436
440
  "later",
437
441
  "exit"
438
442
  ];
439
- var TRANSITION_TABLE = {
440
- idle: { enter: "planning" },
441
- planning: { submit: "reviewing", exit: "exited" },
442
- reviewing: {
443
- submit: "reviewing",
444
- revise: "revising",
445
- dismiss: "planning",
446
- review_aborted: "planning",
447
- approve: "dispatching",
448
- exit: "exited"
443
+ var PLAN_MACHINE = defineStateMachine({
444
+ name: "plan-lifecycle",
445
+ states: {
446
+ idle: {},
447
+ planning: {},
448
+ reviewing: {},
449
+ revising: {},
450
+ approved: {},
451
+ dispatching: {},
452
+ completed: { terminal: true },
453
+ exited: { terminal: true }
449
454
  },
450
- revising: { submit: "reviewing", exit: "exited" },
451
- approved: { approve: "dispatching", exit: "exited" },
452
- dispatching: {
453
- review_aborted: "approved",
454
- exec_chosen: "completed",
455
- later: "approved",
456
- exit: "exited"
455
+ initial: "idle",
456
+ events: {
457
+ enter: {},
458
+ submit: {},
459
+ revise: {},
460
+ dismiss: {},
461
+ review_aborted: {},
462
+ approve: {},
463
+ exec_chosen: {},
464
+ later: {},
465
+ exit: {}
457
466
  },
458
- completed: { enter: "planning" },
459
- exited: { enter: "planning" }
460
- };
467
+ transitions: [
468
+ { from: "idle", on: "enter", to: "planning" },
469
+ { from: "planning", on: "submit", to: "reviewing" },
470
+ { from: "planning", on: "exit", to: "exited" },
471
+ { from: "reviewing", on: "submit", to: "reviewing" },
472
+ { from: "reviewing", on: "revise", to: "revising" },
473
+ { from: "reviewing", on: "dismiss", to: "planning" },
474
+ { from: "reviewing", on: "review_aborted", to: "planning" },
475
+ { from: "reviewing", on: "approve", to: "dispatching" },
476
+ { from: "reviewing", on: "exit", to: "exited" },
477
+ { from: "revising", on: "submit", to: "reviewing" },
478
+ { from: "revising", on: "exit", to: "exited" },
479
+ { from: "approved", on: "approve", to: "dispatching" },
480
+ { from: "approved", on: "exit", to: "exited" },
481
+ { from: "dispatching", on: "review_aborted", to: "approved" },
482
+ { from: "dispatching", on: "exec_chosen", to: "completed" },
483
+ { from: "dispatching", on: "later", to: "approved" },
484
+ { from: "dispatching", on: "exit", to: "exited" },
485
+ { from: ["completed", "exited"], on: "enter", to: "planning" }
486
+ ],
487
+ errorPolicy: "result"
488
+ });
461
489
  function transition(state, event) {
462
- if (!PLAN_LIFECYCLE_STATES.includes(state) || !PLAN_LIFECYCLE_EVENTS.includes(event)) {
463
- return { ok: false };
464
- }
465
- const next = TRANSITION_TABLE[state][event];
466
- return next === void 0 ? { ok: false } : { ok: true, next };
490
+ if (typeof event !== "string") return { ok: false };
491
+ const result = PLAN_MACHINE.transition(state, event);
492
+ if (!result.ok) return { ok: false };
493
+ return result.state === null ? { ok: false } : { ok: true, next: result.state };
467
494
  }
468
495
  var PHASE_OF_STATE = {
469
496
  idle: "idle",
@@ -476,8 +503,9 @@ var PHASE_OF_STATE = {
476
503
  exited: "terminal"
477
504
  };
478
505
  function derivePhase(state) {
479
- if (!PLAN_LIFECYCLE_STATES.includes(state)) return "idle";
480
- return PHASE_OF_STATE[state];
506
+ const coerced = PLAN_MACHINE.coerceState(state);
507
+ if (coerced === null) return "idle";
508
+ return PHASE_OF_STATE[coerced];
481
509
  }
482
510
 
483
511
  // src/extensions/plan/review-contract.ts
@@ -552,10 +580,8 @@ function isPlanReviewResponse(value) {
552
580
  // src/extensions/plan/legacy-entries.ts
553
581
  var PLAN_STATE_CUSTOM_TYPE = "plan-state";
554
582
  function readLifecycleState(data, isActive) {
555
- const raw = data.state;
556
- if (typeof raw === "string" && PLAN_LIFECYCLE_STATES.includes(raw)) {
557
- return raw;
558
- }
583
+ const coerced = PLAN_MACHINE.coerceState(data.state);
584
+ if (coerced !== null) return coerced;
559
585
  if (data.reviewState === "awaiting") return "reviewing";
560
586
  if (data.reviewState === "revising") return "revising";
561
587
  return isActive ? "planning" : "idle";
@@ -700,6 +726,12 @@ function isSessionManagerStatusParams(v) {
700
726
  function isSessionManagerAbortParams(v) {
701
727
  return isSessionIdParams(v);
702
728
  }
729
+ function isSessionManagerDeleteParams(v) {
730
+ return isSessionIdParams(v);
731
+ }
732
+ function isSessionManagerArchiveParams(v) {
733
+ return isSessionIdParams(v);
734
+ }
703
735
  function isSessionManagerListParams(v) {
704
736
  return isRecord(v);
705
737
  }
@@ -732,7 +764,17 @@ function isSessionManagerWatchRespondPayload(v) {
732
764
 
733
765
  // src/extensions/session-manager/marker.ts
734
766
  var SESSION_MANAGER_MARKER = "\0TAIJI_SESSION_MANAGER";
735
- var SESSION_MANAGER_ACTIONS = ["create", "send", "history", "status", "list", "abort", "watch"];
767
+ var SESSION_MANAGER_ACTIONS = [
768
+ "create",
769
+ "send",
770
+ "history",
771
+ "status",
772
+ "list",
773
+ "abort",
774
+ "delete",
775
+ "archive",
776
+ "watch"
777
+ ];
736
778
 
737
779
  // src/extensions/subagent-inflight/marker.ts
738
780
  var SUBAGENT_INFLIGHT_MARKER = "\0TAIJI_SUBAGENT_INFLIGHT";
@@ -1284,7 +1326,9 @@ export {
1284
1326
  isScheduleDraft,
1285
1327
  isScheduleFormResult,
1286
1328
  isSessionManagerAbortParams,
1329
+ isSessionManagerArchiveParams,
1287
1330
  isSessionManagerCreateParams,
1331
+ isSessionManagerDeleteParams,
1288
1332
  isSessionManagerHistoryParams,
1289
1333
  isSessionManagerListParams,
1290
1334
  isSessionManagerNotifyId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/extension-protocol",
3
- "version": "0.22.0",
3
+ "version": "0.23.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",
@@ -21,6 +21,9 @@
21
21
  "README.md"
22
22
  ],
23
23
  "license": "MIT",
24
+ "dependencies": {
25
+ "@zhushanwen/state-machine": "0.2.0"
26
+ },
24
27
  "devDependencies": {
25
28
  "@vitest/coverage-v8": "^4.1.9",
26
29
  "tsup": "^8.5.1",