@shgroup/dsh-serenity-hooks 1.32.0 → 1.34.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.
Files changed (100) hide show
  1. package/README.md +12 -11
  2. package/dsh.plugin.json +5 -5
  3. package/lib/acp-core.d.ts +2 -22
  4. package/lib/acp-http.d.ts +8 -0
  5. package/lib/api.d.ts +12 -4
  6. package/lib/autopilot-chain.d.ts +76 -0
  7. package/lib/autopilot-core-DCRkiWEe.js +229 -0
  8. package/lib/autopilot-core.d.ts +132 -0
  9. package/lib/autopilot-ops.d.ts +48 -0
  10. package/lib/autopilot-trajectory-D9Znxo75.js +782 -0
  11. package/lib/autopilot-trajectory.d.ts +79 -83
  12. package/lib/{ccc-DAsSHsub.js → ccc-NlLr_sxy.js} +18 -2
  13. package/lib/ccc-roots-Bd_SjEs7.js +152 -0
  14. package/lib/ccc-roots.d.ts +105 -0
  15. package/lib/ccc.d.ts +23 -6
  16. package/lib/client.js +30 -10
  17. package/lib/clock-runtime.d.ts +197 -0
  18. package/lib/config-ops.d.ts +9 -14
  19. package/lib/constants.d.ts +0 -2
  20. package/lib/container-status.d.ts +183 -0
  21. package/lib/diag-ops.d.ts +76 -0
  22. package/lib/face-host.d.ts +110 -0
  23. package/lib/fs-ops.d.ts +3 -2
  24. package/lib/gateway-auth.d.ts +2 -5
  25. package/lib/gateway.d.ts +0 -34
  26. package/lib/git-ops.d.ts +3 -2
  27. package/lib/handyman-ops.d.ts +3 -2
  28. package/lib/handyman-preset-inherit.d.ts +2 -1
  29. package/lib/host/access.d.ts +8 -7
  30. package/lib/host/contract.d.ts +17 -6
  31. package/lib/host/type-contract.d.ts +1 -2
  32. package/lib/im-bridge.d.ts +6 -5
  33. package/lib/index.d.ts +1 -1
  34. package/lib/index.js +11053 -8305
  35. package/lib/invariant.d.ts +5 -16
  36. package/lib/invariant.js +8 -4
  37. package/lib/json.d.ts +1 -1
  38. package/lib/kit-ops.d.ts +11 -31
  39. package/lib/localstore-ops.d.ts +3 -17
  40. package/lib/msm-ops.d.ts +34 -52
  41. package/lib/opencode-provider.d.ts +4 -5
  42. package/lib/output-guard-seam.d.ts +1 -4
  43. package/lib/output-guard.d.ts +12 -3
  44. package/lib/ports.d.ts +59 -0
  45. package/lib/rebuild.d.ts +5 -4
  46. package/lib/seams/bootstrap.d.ts +4 -3
  47. package/lib/seams/compact.d.ts +2 -1
  48. package/lib/seams/context.d.ts +2 -4
  49. package/lib/seams/env.d.ts +2 -1
  50. package/lib/seams/guards.d.ts +22 -34
  51. package/lib/seams/keeper.d.ts +4 -4
  52. package/lib/seams/system-prompt.d.ts +1 -5
  53. package/lib/session-cleanup.d.ts +3 -2
  54. package/lib/{settings-section-Bm-xG-NR.js → settings-section-DTYZjwUs.js} +70 -15
  55. package/lib/settings-section.d.ts +14 -35
  56. package/lib/skiff-core.d.ts +5 -10
  57. package/lib/skiff-debug.d.ts +15 -21
  58. package/lib/skiff-registry-FTjoWQTQ.js +25 -0
  59. package/lib/skiff-registry.d.ts +2 -1
  60. package/lib/{skiff-role-BYvNnwv1.js → skiff-role-CEHL5cek.js} +1 -1
  61. package/lib/skiff-role.d.ts +2 -2
  62. package/lib/skills/opencode-scan.d.ts +3 -2
  63. package/lib/skills-discovery.d.ts +15 -2
  64. package/lib/status.d.ts +2 -1
  65. package/lib/tools/acc-diag.d.ts +22 -0
  66. package/lib/tools/cce.d.ts +1 -2
  67. package/lib/tools/container-admin.d.ts +7 -3
  68. package/lib/tools/eap.d.ts +2 -3
  69. package/lib/tools/handyman.d.ts +0 -29
  70. package/lib/tools/msm.d.ts +0 -4
  71. package/lib/tools/neat.d.ts +1 -2
  72. package/lib/tools/praxis.d.ts +0 -1
  73. package/lib/tools/skiff-admin.d.ts +2 -2
  74. package/lib/tools/{session.d.ts → trajectory.d.ts} +25 -17
  75. package/lib/totp.d.ts +0 -4
  76. package/lib/trajectory-assistant.d.ts +2 -1
  77. package/lib/trajectory-bound-Cax1p9ut.js +190 -0
  78. package/lib/{session-bound.d.ts → trajectory-bound.d.ts} +5 -6
  79. package/lib/trajectory-ops-mrXK0H0I.js +410 -0
  80. package/lib/{session-ops.d.ts → trajectory-ops.d.ts} +27 -36
  81. package/lib/trajectory-skills.d.ts +71 -0
  82. package/lib/wake-registry-CYxIb484.js +257 -0
  83. package/lib/wake-registry.d.ts +3 -11
  84. package/lib/wake-scheduler.d.ts +23 -20
  85. package/lib/web-fetch-provider.d.ts +0 -21
  86. package/lib/{weixin-api-PjEhmjlZ.js → weixin-api-CtFYm53S.js} +3 -9
  87. package/lib/weixin-api.d.ts +6 -37
  88. package/lib/weixin-bridge.d.ts +5 -24
  89. package/lib/weixin-hook.d.ts +6 -12
  90. package/lib/weixin-output-guard.d.ts +2 -1
  91. package/lib/{weixin-route-wWk4AIwV.js → weixin-route-B2ajFypI.js} +4 -5
  92. package/lib/weixin-route.d.ts +0 -2
  93. package/lib/weixin-send-api.d.ts +15 -6
  94. package/package.json +3 -5
  95. package/experiments/autopilot-trajectory/SKILL.md +0 -115
  96. package/experiments/autopilot-trajectory/scripts/autopilot-trajectory.ts +0 -522
  97. package/lib/session-bound-NHozeLFc.js +0 -822
  98. package/lib/skiff-debug-K2k1JnGj.js +0 -2867
  99. package/lib/tools/autopilot-trajectory.d.ts +0 -25
  100. package/lib/{session-cleanup-CMT4mHWt.js → session-cleanup-B6IHZgww.js} +1 -1
@@ -1,9 +1,8 @@
1
1
  /**
2
- * cce.ts — CCE 认知连续性工程工具(渐进式披露,ACC 标准工具化)
2
+ * cce.ts — CCE 内容源(认知连续性工程;v1.30 三工具合并为 praxis 后只保留内容常量)
3
3
  *
4
4
  * 内容:认知连续性工程(Cognitive Continuity Engineering)——在有限资源与
5
5
  * 不可逆不确定性约束下,维持认知实体身份、可达性与演化能力的工程学科。
6
6
  * 来源:home-serenity `.opencode/skills/cce/SKILL.md` + CCE 理论。
7
7
  */
8
8
  export declare const CCE_CONTENT = "# CCE \u2014 Cognitive Continuity Engineering\n\n> **Cognitive Continuity Engineering is the engineering discipline of maintaining a cognitive entity's identity, accessibility, and capacity to evolve under the constraints of bounded resources and irreversible uncertainty.**\n> CCE does not optimize cognition. It preserves the conditions under which cognition can continue. \u2014 Persistence Engineering, not performance engineering\n\n## Core Propositions\n- **Continuity belongs to the container, not to any individual participant** \u2014 agents come and go, but the CCC's cognitive trajectory persists\n- **Organization must at minimum keep pace with accumulation** \u2014 otherwise operational cognitive entropy (H_op) grows unboundedly and accessibility is lost\n- **Reconstruction over preservation** \u2014 an artifact's value is determined by its ability to let future agents rebuild the original reasoning\n\n## Cognitive Container\nA bounded cognitive space in which cognition can accumulate, reorganize, and evolve. 5 defining properties:\n| Property | Function |\n|----------|----------|\n| Identity | Distinguishes this cognitive system from others |\n| Boundaries | Define what is inside/outside the cognitive space |\n| Persistent Memory | Retains accumulated cognition across time |\n| Operational Constraints | Define which operations are allowed inside the container |\n| Evolutionary History | Records the trajectory of cognitive change, making reconstruction possible |\n\n## Operational Cognitive Entropy (H_op)\nDoes not measure total entropy (not operational); it measures only the **excess cognitive cost** for agents to complete tasks inside the container:\n> H_op(C, t) = cost(task | C, t) \u2212 cost(task | ideal)\nContinuity condition: **H_op(C, t) \u2264 H_critical** \u2014 agents can still complete tasks at reasonable cost\n\n## Continuity Maintenance Condition\n> **\u0394H_org \u2265 \u0394H_in** \u2014 organization must at minimum keep pace with accumulation\n\n## Six-Phase Lifecycle\nExperience \u2192 Accumulation \u2192 Organization \u2192 Abstraction \u2192 Reconstruction \u2192 Evolution \u2192\uFF08loop\uFF09\n| Phase | Engineering Concern |\n|-------|---------------------|\n| Experience | Does input carry enough structure |\n| Accumulation | Is information stored losslessly |\n| Organization | Entropy management \u2014 \u0394H_org offsets \u0394H_in |\n| Abstraction | Is abstraction explicitly encoded |\n| Reconstruction | Can reasoning structure be recovered from artifacts |\n| Evolution | Does evolution stay coherent or introduce drift |\n\n## Relationship with EAP\nEAP answers \"how a piece of knowledge should be structured\" (explicitness E\u2191 / reconstructability R\u2193 / stability S\u2191);\nCCE answers \"how structured knowledge should keep evolving across time without losing coherence\". They complement each other: EAP is static quality, CCE is dynamic persistence.\n\n## Relationship with Serenity\nSerenity's session system, session tracking, and entropy management mechanisms (SQC quality loop) are all engineering implementations of CCE;\nthe behavioral constraints embedded in CCC system prompts come from CCE.";
9
- export declare const cceTool: import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -11,7 +11,11 @@
11
11
  * 类比 The Manifest(清单维护——工具注册表)+ Crew(角色管理)+ 机务(配置/手册)。
12
12
  *
13
13
  * 参数极简(LLM 直觉):domain(管理域)+ action(该域子命令)+ 少量业务参数。
14
+ *
15
+ * v1.34.1(⑥ C6a):由 `export const containerAdminTool` 改为**工厂**
16
+ * `createContainerAdminTool(ctx)`——autopilot 域搬进进程内后,`status` 必须读只有进程内
17
+ * 能看到的事实(全局闸 / live 会话 / agent 可解析性,见 `../autopilot-ops.js`)。
18
+ * 这是本轮唯一为"取 ctx"而做的形态改动(其余域不依赖 ctx,行为不变)。
14
19
  */
15
- /** 管理域(container_admin 一级参数) */
16
- export type AdminDomain = 'role' | 'msm' | 'config';
17
- export declare const containerAdminTool: import("@deepseek-ai/dsh-tools").ToolDefinition;
20
+ import type { Context } from 'cordis';
21
+ export declare function createContainerAdminTool(ctx: Context): import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -1,7 +1,6 @@
1
1
  /**
2
- * eap.ts — EAP 认知质量框架工具(渐进式披露,ACC 标准工具化)
2
+ * eap.ts — EAP 内容源(认知质量框架;v1.30 三工具合并为 praxis 后只保留内容常量)
3
3
  *
4
- * 内嵌框架内容(自包含,不依赖已安装技能);可选 section 参数聚焦某原则。
4
+ * 内嵌框架内容(自包含,不依赖已安装技能)。
5
5
  */
6
6
  export declare const EAP_CONTENT = "# EAP Cognitive Quality Framework (Explicit Abstraction Principle)\n\n> \"The functional value of a thought is proportional to its external reconstructability.\"\n\n## Three Variables\n| Variable | Meaning | How to improve |\n|----------|---------|----------------|\n| E\u2191 Explicitness | Degree to which variables/entities/relations are clearly defined | Define variables, state relationship direction & cardinality, draw boundaries |\n| R\u2193 Reconstructability | Cost of rebuilding the original reasoning later | Record decision rationale, context, constraints, alternatives |\n| S\u2191 Stability | Degree to which the same input repeatedly produces consistent output | Fix structures, protocolize, avoid relying on implicit context |\n\n## Pre-Output Self-Check Checklist\n- [ ] Variables/entities clearly defined (E\u2191)\n- [ ] Relationships state direction/cardinality (E\u2191)\n- [ ] Boundaries drawn \u2014 what is in scope / what is not (E\u2191)\n- [ ] No ambiguous words: \"handle\" \"optimize\" \"problem\" \u2192 be specific (E\u2191)\n- [ ] Key decisions record rationale and alternatives (R\u2193)\n- [ ] No level-skipping \u2014 align the upper layer before descending (R\u2193)\n- [ ] Structures can be regenerated repeatably (S\u2191)\n\n## Relationship with ACC\nACC (plugin/template) encodes structure as code (E\u2191); generating a CCC from ACC is deterministic (R\u2193); consistent across multiple CCCs (S\u2191).\nCCC (home-serenity etc.) encodes cognitive content as skills/SESSIONs/design docs. Use this checklist to self-check outputs.\n\n## Reference\nhttps://github.com/tellmewhattodo/theory-eap";
7
- export declare const eapTool: import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -20,34 +20,5 @@
20
20
  */
21
21
  import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
22
22
  import type { Context } from 'cordis';
23
- /** 非正常停止时重启 agent 的次数上限(防死循环保险阀):对话轮次有上限,重启有上限 */
24
- export declare const HANDYMAN_MAX_RESTARTS = 100;
25
- /** 对话轮次上限(对齐 osp loop-runner 的 round>=100 强制 done 保险阀) */
26
- export declare const HANDYMAN_MAX_ROUNDS = 100;
27
- export interface HandymanJob {
28
- task: string;
29
- label: string;
30
- model?: string;
31
- }
32
- export interface HandymanJobResult {
33
- label: string;
34
- done: boolean;
35
- rounds: number;
36
- finishReason: 'done' | 'max_rounds' | 'restart_exceeded';
37
- restarts: number;
38
- model: string;
39
- lastResponse: string;
40
- progressFile: string;
41
- }
42
- /** foreground 模式结果(一次调用一次结果;无循环、无进度文件) */
43
- export interface HandymanForegroundResult {
44
- mode: 'foreground';
45
- done: boolean;
46
- model: string;
47
- stopReason: string;
48
- output: string;
49
- childId?: string;
50
- diagnostic?: string;
51
- }
52
23
  /** 创建 handyman 工具(闭包捕获插件 ctx → 可访问 ctx.agents) */
53
24
  export declare function createHandymanTool(ctx: Context): ToolDefinition;
@@ -15,8 +15,4 @@
15
15
  * 管理面(register/deregister/check/guide/catalog/ccc-config)已移入 container_admin。
16
16
  * 底层 runMsmAsync/prepareExec 全复用;未命中候选为新增 findSuggestions。
17
17
  */
18
- /** 精简目录(无参调用返回;替代全量 list 的巨输出)——按 skill 分组统计 + 顶部指引 */
19
- export declare function buildMsmIndex(root: string): string;
20
- /** 模糊候选:name/description 子串匹配(未精确命中时返回 top-K,供 LLM 下轮选对) */
21
- export declare function suggestMsm(root: string, query: string, limit?: number): string;
22
18
  export declare const msmTool: import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -1,5 +1,4 @@
1
1
  /**
2
- * neat.ts — Neat 设计协作协议工具(渐进式披露,ACC 标准工具化)
2
+ * neat.ts — Neat 内容源(设计协作协议;v1.30 三工具合并为 praxis 后只保留内容常量)
3
3
  */
4
4
  export declare const NEAT_CONTENT = "# Neat Design Collaboration Protocol\n\n> Complex design is not thought up at once \u2014 it is walked out in small aligned steps.\n\n## Four Iron Rules\n| Rule | Meaning | Anti-example |\n|------|---------|--------------|\n| Small-step alignment | Advance one decision at a time; confirm before the next step | Presenting 10 options at once |\n| Explicit decisions | Every choice records rationale and alternatives | \"I feel this is good\" (no rationale) |\n| Document-driven | Conclusions land in named files (<subject>-<scope>-<type>.md) | Conclusions exist only in conversation |\n| No level-skipping | Advance strictly through the layers | Writing implementation before requirements are aligned |\n\n## Five-Layer Progression (no skipping)\nRequirements \u2192 Scope \u2192 Solution \u2192 Interface \u2192 Implementation\n| Layer | Artifact | Question |\n|-------|----------|----------|\n| Requirements | Requirements description | \"What problem are we solving?\" |\n| Scope | Scope list (in/out) | \"What is in, explicitly what is out?\" |\n| Solution | Solution comparison + selection | \"How? Which one? Why?\" |\n| Interface | Interface/protocol definition | \"How do the boundaries interact?\" |\n| Implementation | Code/docs | \"Land it layer by layer\" |\n\n## Collaboration Rhythm\n1. Raise one decision point of the current layer (with context + suggestion + rationale)\n2. Wait for confirmation or correction (small step)\n3. After confirmation, record the decision (into session SESSION.md or a design doc)\n4. Move to the next decision point";
5
- export declare const neatTool: import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -8,7 +8,6 @@
8
8
  *
9
9
  * section 参数渐进披露:不传 = 返回精简目录;传 = 返回对应框架全文/章节。
10
10
  */
11
- export type PraxisSection = 'eap' | 'neat' | 'cce';
12
11
  /** 框架清单(无参调用时返回的精简目录) */
13
12
  export declare const PRAXIS_INDEX = "praxis \u2014 \u53EF\u5B9E\u8DF5\u7406\u8BBA\u6CE8\u5165\uFF08\u8BA4\u77E5\u6846\u67B6\uFF0C\u6309\u9700\u52A0\u8F7D\uFF09\n\u9009\u62E9\u6846\u67B6\uFF1Apraxis eap\uFF08\u8BA4\u77E5\u8D28\u91CF\u2014\u2014E\u2191/R\u2193/S\u2191 \u4E09\u53D8\u91CF + \u8F93\u51FA\u524D\u81EA\u68C0\uFF09\n praxis neat\uFF08Neat \u534F\u4F5C\u534F\u8BAE\u2014\u2014\u5C0F\u6B65\u5BF9\u9F50/\u663E\u5F0F\u51B3\u7B56/\u6587\u6863\u9A71\u52A8\uFF09\n praxis cce\uFF08\u8BA4\u77E5\u8FDE\u7EED\u6027\u5DE5\u7A0B\u2014\u2014\u5BB9\u5668 5 \u884C\u4E3A\u7EA6\u675F + H_op \u64CD\u4F5C\u71B5\uFF09\n\u65E0\u53C2\u8FD4\u56DE\u672C\u76EE\u5F55\uFF1B\u8BE6\u60C5\u4EE5\u5BF9\u5E94\u6846\u67B6\u539F\u6587\u4E3A\u51C6\uFF08\u5355\u4E00\u771F\u76F8\u6E90\uFF09\u3002\n";
14
13
  export declare const praxisTool: import("@deepseek-ai/dsh-tools").ToolDefinition;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * skiff-admin.ts — Skiff 角色逻辑层(v1.30:skiff_admin 工具已并入 container_admin role 域)
3
3
  *
4
- * 教 CCC 如何定义 Skiff 角色(仿 session 工具 hook-develop-guide 的 SEP 教学模式,
5
- * 用户拍板 2026-08-28:guide 定义教程 / validate 配置校验 / list 角色摘要)。
4
+ * 教 CCC 如何定义 Skiff 角色(用户拍板 2026-08-28 的三动作分工:
5
+ * guide 定义教程 / validate 配置校验 / list 角色摘要)。
6
6
  *
7
7
  * 归属:ACC 机制(教会 + 校验),角色内容仍归 CCC 配置(.opencode/serenity.json skiff.roles)。
8
8
  * 公开入口 = container_admin(domain: role → guide/validate/apply/list);本文件保留纯逻辑。
@@ -1,23 +1,30 @@
1
1
  /**
2
- * session.ts — session 真实 DSH 工具定义(defineTool)
2
+ * trajectory.ts — `container_trajectory` 真实 DSH 工具定义(defineTool)
3
3
  *
4
- * AGENT_SESSIONS/ 全周期管理:list/show/create/use/close/health/qa/archive/summary。
5
- * 行为对齐 osp(opencode-serenity-plugin/src/session/session-tool.ts)——osp 是 ACC 工具 spec:
6
- * - create:--desc <desc> [--goal <goal>] 或 --issue <id>(二选一)
7
- * - close:需 --confirm 防误关
8
- * - archive:name 可缺省(批量归档)
9
- * - hook-develop-guide 子命令 + CCC session-tool MSM 扩展提示(extHint)
10
- * CCC 扩展采用 osp 的"钩子后处理"模型(create-transform),而非整命令委派。
11
- * 活跃会话跟踪:写内存 Map(.dsh/active-sessions/<scope> 语义)+ events 恢复(S134)。
4
+ * v1.33(S142 §32 用户裁决):由 `logbook` **更名并收敛为 `trajectory`**(v1.34:工具名再硬切为
5
+ * `container_trajectory`,无别名)——trajectory 是一等概念
6
+ * (SESSION.md 是它的持久身体),本工具管它的**载体生命周期 + 一次性时间安排**。
7
+ * 动作收敛为 **6 个**:list / show / create / use / rebuild / wake-later。
12
8
  *
13
- * v1.21 F3(用户逻辑修正):SESSION 是对话过程中创建的——**use 激活宁静号会话时,
14
- * 同步把当前 dsh 会话重命名为该 SESSION 目录名**(sessionTitle.rename,user source
15
- * pin 住标题)。非创建时预命名。
9
+ * 与旧面(logbook 11 动作 + trajectory 12 动作)的对应(用户逐条裁决,R↓):
10
+ * · `summary` → 并入 `list`(全库统计随清单一起给)
11
+ * · `health`/`qa` → **淘汰**:其判据是"旧六节模板合规",而 ACC 层的编写标准已升级为 EAP
12
+ * ⇒ 只把**不依赖模板**的两项并入 `use`:空壳 / 长期无活动(**提示,不阻断**)
13
+ * · `close`/`archive` → 删:`completed` 本就由 SESSION.md 的 `[x]` 推导(不靠 close 写);
14
+ * 归档能力由 `container_fs mv → _archived/` 承担
15
+ * · `hook-develop-guide` → **淘汰**(v1.34.1:SEP 整体废除——「能落 harness 已有原语,
16
+ * 就不要自造协议 + 脚本管道」;轨迹挂哪些 skill 改由 SESSION.md frontmatter 声明 +
17
+ * `systemPrompt.section` 注入,见 `docs/trajectory-skill-injection.md`)
18
+ * · autopilot 面(all/init/random/diag/doc/check/status/guide)→ `container_admin` 的 autopilot 域
19
+ * · `wake-add`/`wake-list`/`wake-rm` → **`wake-later`**(一次登记;**不可回收、无面板**——用户明示接受)
20
+ *
21
+ * 保留 osp 对齐语义的部分:create 的 `--desc`/`--issue` 二选一、use 激活即重命名 dsh 会话标题(F3)。
22
+ * 活跃会话跟踪:内存 Map(按 dsh 会话 id 隔离)+ 从 events 恢复(S134)。
16
23
  */
17
24
  import { defineTool } from '@deepseek-ai/dsh-tools';
18
25
  import type { Context } from 'cordis';
19
- import { type ActiveSessionInfo, type CreateSessionResult } from '../session-ops.js';
20
- export interface RenameOnUseDeps {
26
+ import { type ActiveSessionInfo, type CreateSessionResult } from '../trajectory-ops.js';
27
+ interface RenameOnUseDeps {
21
28
  /** sessionTitle 服务可用性 */
22
29
  sessionTitleAvailable: boolean;
23
30
  }
@@ -87,7 +94,8 @@ export declare function renameDshSessionForActive(ctx: Context, exec: {
87
94
  };
88
95
  }, info: ActiveSessionInfo, summary?: string): void;
89
96
  /**
90
- * 创建 session 工具(闭包捕获插件 ctx → use 后可调 ctx.sessionTitle.rename)。
91
- * v1.21 F3:use 激活宁静号会话 → 当前 dsh 会话重命名为该 SESSION 目录名。
97
+ * 创建 trajectory 工具(原 logbook;v1.33 S142 §32 更名 + 动作收敛)。
98
+ * 闭包捕获插件 ctx → use 后可调 ctx.sessionTitle.rename。
92
99
  */
93
- export declare function createSessionTool(ctx: Context): ReturnType<typeof defineTool>;
100
+ export declare function createTrajectoryTool(ctx: Context): ReturnType<typeof defineTool>;
101
+ export {};
package/lib/totp.d.ts CHANGED
@@ -11,10 +11,6 @@
11
11
  */
12
12
  /** 时步(秒)——RFC 6238 默认 30 */
13
13
  export declare const TOTP_STEP_SECONDS = 30;
14
- /** 验证窗口:当前时步 ± 1(容忍时钟漂移/生成延迟) */
15
- export declare const TOTP_WINDOW = 1;
16
- /** 输出位数(标准 6 位) */
17
- export declare const TOTP_DIGITS = 6;
18
14
  /** 字节 → base32(无填充)。secret 显示/otpauth URI 用。 */
19
15
  export declare function base32Encode(bytes: Uint8Array): string;
20
16
  /** base32(无填充,大小写不敏感)→ 字节;非法字符抛错。 */
@@ -52,7 +52,7 @@ export declare const ACK_SKIP_PREFIX = "TRAJECTORY-ASSISTANT-skipped";
52
52
  */
53
53
  export declare const IN_FLIGHT_HEADING = "## In-flight (rebuild handover)";
54
54
  /** 风格档位:plain(默认,精确文本)/ metaphor(借星舰词——产品隐喻非游戏词) */
55
- export type TrajectoryStyle = 'plain' | 'metaphor';
55
+ type TrajectoryStyle = 'plain' | 'metaphor';
56
56
  /**
57
57
  * 按风格生成前缀 token。plain = eventToken()(原样);metaphor 仅当有
58
58
  * 星舰化变体时替换用词(当前等价保留——星舰词库隐喻域的既有措辞即
@@ -65,3 +65,4 @@ export declare function styledToken(event: keyof typeof EVENT_LABEL, style?: Tra
65
65
  * 尚无可靠自动检测(D2 用户拍板记录为未解问题),实现留待仪式落地。
66
66
  */
67
67
  export declare function onSettlement(_cb: (sessionId: string) => void): void;
68
+ export {};
@@ -0,0 +1,190 @@
1
+ import { r as cccRootForCwd } from "./ccc-roots-Bd_SjEs7.js";
2
+ import { c as getLastActiveSessionInfo, p as sessionEvents, s as getActiveSessionInfo } from "./trajectory-ops-mrXK0H0I.js";
3
+ import { dirname, join } from "node:path";
4
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
5
+ //#region src/trajectory-bound.ts
6
+ /**
7
+ * trajectory-bound.ts — SESSION 绑定持久化(CCC 内 `AGENT_SESSIONS/.bindings.json`)
8
+ *
9
+ * 目标(S142 用户拍板,方案 v1.0):让「dsh 会话(载体)↔ SESSION(宁静号轨迹)」
10
+ * 的绑定坚固——LLM 不能因智力因素(幻觉/理解偏差)在过程中或 container_trajectory rebuild 后
11
+ * 自行更换 SESSION。
12
+ *
13
+ * 存储形态(v1.30.6 起,S142 review F-01):绑定**不再写入 dsh 会话日志**。
14
+ * 原因(宿主契约实证):dsp 的自定义事件 `serenity/bound` 既不在宿主的
15
+ * `KNOWN_SESSION_EVENT_TYPES`(生成静态集,明确说明 out-of-repo 插件事件不在其中),
16
+ * 而 `Session.append` 构造事件时只写 `{type,seq,time,data,surfaceOp?,sourceEventSeqs?}`
17
+ * ——**没有写入 envelope `ignorable` 标记的通道**;宿主的 `assertEventsSupported`
18
+ * (session-persistence/coordinator.ts:1248-1252,调用点含恢复/HMR 路径)会拒绝任何
19
+ * "未知且非 ignorable" 的事件 → 含该事件的会话在冷加载时可能抛
20
+ * `SessionFormatUnsupportedError`。v1.29.1~v1.30.5 的设计文档虽写明要带
21
+ * `ignorable: true`(docs/session-binding-hardening-research.md:53),但类型层声明
22
+ * 不等于持久层标记,实际从未落盘。
23
+ *
24
+ * 现形态:每 CCC 一个 JSON 文件 `AGENT_SESSIONS/.bindings.json`(原子写:tmp + rename),
25
+ * 以 dsh 会话 id 为键,latest-wins 覆盖。**向后兼容**:读取时若文件中无该会话记录,
26
+ * 仍回落到扫描会话日志中的旧 `serenity/bound` 事件(老会话的绑定不丢)。
27
+ *
28
+ * 编码无关(U4):绑定锚 = **完整 AGENT_SESSIONS 目录名**(磁盘唯一存在),
29
+ * sessionId(S###/apaas-xxx/自定义)仅是派生展示字段——绝不假设 S 前缀。
30
+ */
31
+ /** 旧形态事件类型(v1.29.1~v1.30.5 写入会话日志;v1.30.6 起只读不写——兼容存量绑定) */
32
+ const SESSION_BOUND_EVENT = "serenity/bound";
33
+ /** 绑定文件相对 CCC 根的路径 */
34
+ const BINDINGS_REL_PATH = "AGENT_SESSIONS/.bindings.json";
35
+ const BINDINGS_VERSION = 1;
36
+ function sessionHeader(session) {
37
+ const header = session?.header;
38
+ if (!header || typeof header !== "object") return null;
39
+ return header;
40
+ }
41
+ /** 绑定文件绝对路径(由会话 cwd 上溯 .serenity 定位 CCC 根);无法定位返回 null */
42
+ function bindingsPathFor(session) {
43
+ const header = sessionHeader(session);
44
+ if (typeof header?.cwd !== "string") return null;
45
+ const root = cccRootForCwd(header.cwd);
46
+ if (!root) return null;
47
+ return join(root, BINDINGS_REL_PATH);
48
+ }
49
+ function readBindingsFile(path) {
50
+ if (!existsSync(path)) return {
51
+ version: BINDINGS_VERSION,
52
+ sessions: {}
53
+ };
54
+ try {
55
+ const sessions = JSON.parse(readFileSync(path, "utf-8")).sessions;
56
+ if (!sessions || typeof sessions !== "object") return {
57
+ version: BINDINGS_VERSION,
58
+ sessions: {}
59
+ };
60
+ return {
61
+ version: BINDINGS_VERSION,
62
+ sessions
63
+ };
64
+ } catch {
65
+ return {
66
+ version: BINDINGS_VERSION,
67
+ sessions: {}
68
+ };
69
+ }
70
+ }
71
+ /** 原子写:同目录 tmp + rename(避免半写文件被后续读取) */
72
+ function writeBindingsFile(path, data) {
73
+ mkdirSync(dirname(path), { recursive: true });
74
+ const tmp = `${path}.tmp`;
75
+ writeFileSync(tmp, `${JSON.stringify(data, null, 2)}\n`, "utf-8");
76
+ renameSync(tmp, path);
77
+ }
78
+ /** 记录形状校验(容忍手改/旧数据) */
79
+ function asBoundRecord(value) {
80
+ const r = value;
81
+ if (!r || typeof r.dirName !== "string" || typeof r.mdPath !== "string") return null;
82
+ return r;
83
+ }
84
+ /** 旧形态:从会话日志扫最后一条 `serenity/bound`(兼容 v1.30.5 及更早写入的绑定) */
85
+ function readLegacyBoundFromEvents(session) {
86
+ const events = sessionEvents(session);
87
+ for (let i = events.length - 1; i >= 0; i--) {
88
+ const ev = events[i];
89
+ if (!ev || ev.type !== SESSION_BOUND_EVENT) continue;
90
+ const rec = asBoundRecord(ev.data);
91
+ if (rec) return rec;
92
+ }
93
+ return null;
94
+ }
95
+ /**
96
+ * 读取会话当前绑定(权威,latest-wins):文件记录优先,无则回落旧事件形态。
97
+ * 无绑定返回 null。
98
+ */
99
+ function readLastBound(session) {
100
+ const path = bindingsPathFor(session);
101
+ const id = sessionHeader(session)?.id;
102
+ if (path && typeof id === "string") {
103
+ const rec = asBoundRecord(readBindingsFile(path).sessions[id]);
104
+ if (rec) return rec;
105
+ }
106
+ return readLegacyBoundFromEvents(session);
107
+ }
108
+ /** 目录名 → 轨迹标签(`--S###--` 命中取 `S###`;未命中原样返回——编码无关 U4) */
109
+ function trajectoryLabel(dirName) {
110
+ const m = dirName.match(/--S(\d{3,})--/);
111
+ return m ? `S${m[1]}` : dirName;
112
+ }
113
+ /**
114
+ * **调用方自身**所属 trajectory 的标签(审计字段 `createdBy` 的唯一正解)。
115
+ *
116
+ * 三级来源,逐级回退(R↓:为什么不用单一来源):
117
+ * 1. `readLastBound(session)` —— **持久 bound**,权威(重启存活、不受别的会话激活污染)
118
+ * 2. `getActiveSessionInfo(scope)` —— 本 dsh 会话的**内存**激活(按 scope 隔离)
119
+ * 3. `getLastActiveSessionInfo()` —— **全局**最近激活指针(无绑定的会话兼容回退)
120
+ *
121
+ * ⚠️ 为何单列成本函数(S142 §30.12.1 实测缺陷):唤醒注册表的 `createdBy` 原先直接取第 3 级
122
+ * 全局指针,而它记录的是"**进程内最近一次被激活的 trajectory**"——多会话并发时必然张冠李戴
123
+ * (实测:S142 登记唤醒被写成 `by=S060`)。`createdBy` 是 D60「以可审计替代入口栅」的**唯一凭证**,
124
+ * 失真即替代控制失效 ⇒ 必须以"调用方自己是谁"为准,全局指针只作最后兜底。
125
+ *
126
+ * @param session 调用方 dsh 会话对象(需 `header.id` + `header.cwd`)
127
+ * @param scope 调用方 dsh 会话 id(取不到传空串)
128
+ * @returns 轨迹标签(`S###` 或完整目录名);三级全落空 → 空串(渲染为 `?`)
129
+ */
130
+ function resolveSessionTrajectoryLabel(session, scope) {
131
+ const bound = session ? readLastBound(session) : null;
132
+ if (bound?.dirName) return trajectoryLabel(bound.dirName);
133
+ const scoped = scope !== "" ? getActiveSessionInfo(scope) : null;
134
+ if (scoped) return scoped.sessionId;
135
+ return getLastActiveSessionInfo()?.sessionId ?? "";
136
+ }
137
+ /**
138
+ * 反向查:绑定到某 trajectory 目录名的 dsh 会话 id(**按绑定时间倒序,最新在前**)。
139
+ *
140
+ * 用途(wake-scheduler 冷唤醒):.bindings.json 以 **sessionId 为键**,而唤醒条目的
141
+ * target 是**目录名**——需要值侧扫描做反向索引。冷会话被唤醒时必须先知道"哪个 dsh
142
+ * 会话承载这条轨迹",这是唯一的权威来源(标题只作回退,见 v1.29.2 R2)。
143
+ *
144
+ * @param root CCC 根
145
+ * @param dirName AGENT_SESSIONS 目录名(完整名,如 `2026-09-01--S151--x--auto`)
146
+ * @returns 会话 id 列表(最新绑定在前);无绑定 → `[]`
147
+ */
148
+ function listBoundSessionIds(root, dirName) {
149
+ const file = readBindingsFile(join(root, BINDINGS_REL_PATH));
150
+ const hits = [];
151
+ for (const [id, raw] of Object.entries(file.sessions)) {
152
+ const rec = asBoundRecord(raw);
153
+ if (!rec || rec.dirName !== dirName) continue;
154
+ hits.push({
155
+ id,
156
+ at: typeof rec.at === "number" ? rec.at : 0
157
+ });
158
+ }
159
+ return hits.sort((a, b) => b.at - a.at).map((h) => h.id);
160
+ }
161
+ /**
162
+ * 写入绑定(latest-wins 覆盖该会话记录)。
163
+ *
164
+ * 绑定持久化尽力而为:无法定位 CCC 根 / 无会话 id / 写盘失败 → 返回 false,不阻断主流程。
165
+ * @param session 目标 dsh 会话(需 `header.id` + `header.cwd` 可定位 CCC 根)
166
+ * @param action 绑定动作
167
+ * @param rec 绑定记录(dirName + mdPath 必填;sessionId 可选展示码)
168
+ */
169
+ function appendBound(session, action, rec) {
170
+ const path = bindingsPathFor(session);
171
+ const id = sessionHeader(session)?.id;
172
+ if (!path || typeof id !== "string") return false;
173
+ try {
174
+ const file = readBindingsFile(path);
175
+ file.sessions[id] = {
176
+ dirName: rec.dirName,
177
+ mdPath: rec.mdPath,
178
+ ...rec.sessionId ? { sessionId: rec.sessionId } : {},
179
+ action,
180
+ at: Date.now(),
181
+ ...rec.note ? { note: rec.note } : {}
182
+ };
183
+ writeBindingsFile(path, file);
184
+ return true;
185
+ } catch {
186
+ return false;
187
+ }
188
+ }
189
+ //#endregion
190
+ export { resolveSessionTrajectoryLabel as i, listBoundSessionIds as n, readLastBound as r, appendBound as t };
@@ -1,8 +1,8 @@
1
1
  /**
2
- * session-bound.ts — SESSION 绑定持久化(CCC 内 `AGENT_SESSIONS/.bindings.json`)
2
+ * trajectory-bound.ts — SESSION 绑定持久化(CCC 内 `AGENT_SESSIONS/.bindings.json`)
3
3
  *
4
4
  * 目标(S142 用户拍板,方案 v1.0):让「dsh 会话(载体)↔ SESSION(宁静号轨迹)」
5
- * 的绑定坚固——LLM 不能因智力因素(幻觉/理解偏差)在过程中或 logbook rebuild 后
5
+ * 的绑定坚固——LLM 不能因智力因素(幻觉/理解偏差)在过程中或 container_trajectory rebuild 后
6
6
  * 自行更换 SESSION。
7
7
  *
8
8
  * 存储形态(v1.30.6 起,S142 review F-01):绑定**不再写入 dsh 会话日志**。
@@ -23,8 +23,8 @@
23
23
  * 编码无关(U4):绑定锚 = **完整 AGENT_SESSIONS 目录名**(磁盘唯一存在),
24
24
  * sessionId(S###/apaas-xxx/自定义)仅是派生展示字段——绝不假设 S 前缀。
25
25
  */
26
- export type SessionBoundAction = 'activate' | 'switch' | 'create' | 'rebuild' | 'reconcile' | 'release';
27
- export interface SessionBoundRecord {
26
+ type SessionBoundAction = 'activate' | 'switch' | 'create' | 'rebuild' | 'reconcile' | 'release';
27
+ interface SessionBoundRecord {
28
28
  dirName: string;
29
29
  mdPath: string;
30
30
  sessionId?: string;
@@ -32,8 +32,6 @@ export interface SessionBoundRecord {
32
32
  at: number;
33
33
  note?: string;
34
34
  }
35
- /** 旧形态事件类型(v1.29.1~v1.30.5 写入会话日志;v1.30.6 起只读不写——兼容存量绑定) */
36
- export declare const SESSION_BOUND_EVENT: "serenity/bound";
37
35
  /** 绑定文件相对 CCC 根的路径 */
38
36
  export declare const BINDINGS_REL_PATH = "AGENT_SESSIONS/.bindings.json";
39
37
  /** 绑定文件绝对路径(由会话 cwd 上溯 .serenity 定位 CCC 根);无法定位返回 null */
@@ -89,3 +87,4 @@ export declare function appendBound(session: unknown, action: SessionBoundAction
89
87
  sessionId?: string;
90
88
  note?: string;
91
89
  }): boolean;
90
+ export {};