create-principles-disciple 1.150.2 → 1.150.4

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 (267) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/ingestion/admission.js +2 -0
  3. package/codex-adapter/dist/pd-hook.d.ts +7 -5
  4. package/codex-adapter/dist/pd-hook.js +18 -7
  5. package/codex-adapter/dist/tool-semantics.js +5 -1
  6. package/codex-adapter/dist/worker/workspace-worker.js +4 -2
  7. package/codex-adapter/package.json +1 -1
  8. package/console/dist/lib/utils.js +16 -1
  9. package/console/dist/web/assets/app.css +147 -46
  10. package/console/dist/web/assets/app.js +35 -32
  11. package/console/package.json +2 -0
  12. package/core/dist/runtime/activation/adaptive-selection-output.d.ts +35 -0
  13. package/core/dist/runtime/activation/adaptive-selection-output.d.ts.map +1 -0
  14. package/core/dist/runtime/activation/adaptive-selection-output.js +38 -0
  15. package/core/dist/runtime/activation/adaptive-selection-output.js.map +1 -0
  16. package/core/dist/runtime/activation-compatibility-read-model.d.ts.map +1 -1
  17. package/core/dist/runtime/activation-compatibility-read-model.js +2 -1
  18. package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
  19. package/core/dist/runtime/adapter/artificer-l2-adapter.d.ts.map +1 -1
  20. package/core/dist/runtime/adapter/artificer-l2-adapter.js +89 -27
  21. package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
  22. package/core/dist/runtime/adapter/context-budget.d.ts +49 -0
  23. package/core/dist/runtime/adapter/context-budget.d.ts.map +1 -0
  24. package/core/dist/runtime/adapter/context-budget.js +127 -0
  25. package/core/dist/runtime/adapter/context-budget.js.map +1 -0
  26. package/core/dist/runtime/adapter/output-schema-registry.d.ts.map +1 -1
  27. package/core/dist/runtime/adapter/output-schema-registry.js +7 -0
  28. package/core/dist/runtime/adapter/output-schema-registry.js.map +1 -1
  29. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +30 -7
  30. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  31. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +559 -211
  32. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  33. package/core/dist/runtime/candidate-audit.d.ts.map +1 -1
  34. package/core/dist/runtime/candidate-audit.js +2 -1
  35. package/core/dist/runtime/candidate-audit.js.map +1 -1
  36. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  37. package/core/dist/runtime/config/pd-config-effective.js +2 -0
  38. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  39. package/core/dist/runtime/config/pd-config-types.d.ts +52 -0
  40. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  41. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  42. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  43. package/core/dist/runtime/config/pd-config-validate.js +134 -0
  44. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  45. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  46. package/core/dist/runtime/feature-flags/feature-flag-contract.js +8 -0
  47. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  48. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  49. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +24 -0
  50. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  51. package/core/dist/runtime/index.d.ts +2 -0
  52. package/core/dist/runtime/index.d.ts.map +1 -1
  53. package/core/dist/runtime/index.js +2 -0
  54. package/core/dist/runtime/index.js.map +1 -1
  55. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +16 -0
  56. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  57. package/core/dist/runtime/internalization/rule-host-input-builder.js +18 -0
  58. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  59. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +8 -0
  60. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  61. package/core/dist/runtime/internalization/split-diagnostician-runner.js +24 -2
  62. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  63. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts +26 -0
  64. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts.map +1 -1
  65. package/core/dist/runtime/internalization/tool-semantic-registry.js +55 -5
  66. package/core/dist/runtime/internalization/tool-semantic-registry.js.map +1 -1
  67. package/core/dist/runtime/internalization-chain-integrity-read-model.d.ts.map +1 -1
  68. package/core/dist/runtime/internalization-chain-integrity-read-model.js +2 -2
  69. package/core/dist/runtime/internalization-chain-integrity-read-model.js.map +1 -1
  70. package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
  71. package/core/dist/runtime/internalization-integrity-remediation.js +2 -2
  72. package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
  73. package/core/dist/runtime/operator-health-read-model.d.ts.map +1 -1
  74. package/core/dist/runtime/operator-health-read-model.js +2 -2
  75. package/core/dist/runtime/operator-health-read-model.js.map +1 -1
  76. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  77. package/core/dist/runtime/pain-recall-read-model.js +4 -3
  78. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  79. package/core/dist/runtime/pruning-read-model.d.ts.map +1 -1
  80. package/core/dist/runtime/pruning-read-model.js +3 -2
  81. package/core/dist/runtime/pruning-read-model.js.map +1 -1
  82. package/core/dist/runtime/risk/risk-calculator-policy.d.ts +12 -2
  83. package/core/dist/runtime/risk/risk-calculator-policy.d.ts.map +1 -1
  84. package/core/dist/runtime/risk/risk-calculator-policy.js +33 -22
  85. package/core/dist/runtime/risk/risk-calculator-policy.js.map +1 -1
  86. package/core/dist/runtime/schema-conformance-read-model.js +2 -2
  87. package/core/dist/runtime/schema-conformance-read-model.js.map +1 -1
  88. package/core/dist/runtime/store/sqlite-connection.d.ts +0 -5
  89. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  90. package/core/dist/runtime/store/sqlite-connection.js +4 -12
  91. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  92. package/core/dist/runtime/store/storage-paths.d.ts +17 -0
  93. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -0
  94. package/core/dist/runtime/store/storage-paths.js +52 -0
  95. package/core/dist/runtime/store/storage-paths.js.map +1 -0
  96. package/core/dist/runtime/trajectory-retention.d.ts +257 -0
  97. package/core/dist/runtime/trajectory-retention.d.ts.map +1 -0
  98. package/core/dist/runtime/trajectory-retention.js +598 -0
  99. package/core/dist/runtime/trajectory-retention.js.map +1 -0
  100. package/core/dist/telemetry-event.d.ts +2 -2
  101. package/core/dist/telemetry-event.d.ts.map +1 -1
  102. package/core/dist/telemetry-event.js +5 -0
  103. package/core/dist/telemetry-event.js.map +1 -1
  104. package/core/dist/trajectory-store.d.ts +9 -9
  105. package/core/dist/trajectory-store.d.ts.map +1 -1
  106. package/core/dist/trajectory-store.js +9 -12
  107. package/core/dist/trajectory-store.js.map +1 -1
  108. package/core/package.json +1 -1
  109. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  110. package/dist/installers/codex-host-installer.js +92 -5
  111. package/dist/installers/codex-host-installer.js.map +1 -1
  112. package/dist/installers/mcp-binding-shape-mirror.d.ts +27 -0
  113. package/dist/installers/mcp-binding-shape-mirror.d.ts.map +1 -0
  114. package/dist/installers/mcp-binding-shape-mirror.js +105 -0
  115. package/dist/installers/mcp-binding-shape-mirror.js.map +1 -0
  116. package/dist/skill-catalog.d.ts +35 -0
  117. package/dist/skill-catalog.d.ts.map +1 -0
  118. package/dist/skill-catalog.js +85 -0
  119. package/dist/skill-catalog.js.map +1 -0
  120. package/dist/skill-delivery-parity.d.ts +22 -0
  121. package/dist/skill-delivery-parity.d.ts.map +1 -0
  122. package/dist/skill-delivery-parity.js +31 -0
  123. package/dist/skill-delivery-parity.js.map +1 -0
  124. package/host-runtime/dist/active-principle-prompt.d.ts +8 -0
  125. package/host-runtime/dist/active-principle-prompt.js +15 -5
  126. package/host-runtime/dist/adaptive-decision-protocol.d.ts +142 -0
  127. package/host-runtime/dist/adaptive-decision-protocol.js +190 -0
  128. package/host-runtime/dist/adaptive-priority-provider.d.ts +37 -13
  129. package/host-runtime/dist/adaptive-priority-provider.js +65 -62
  130. package/host-runtime/dist/adaptive-selection.d.ts +67 -62
  131. package/host-runtime/dist/adaptive-selection.js +218 -301
  132. package/host-runtime/dist/adaptive-skip-decision.d.ts +26 -14
  133. package/host-runtime/dist/adaptive-skip-decision.js +33 -29
  134. package/host-runtime/dist/codex-rule-context-provider.js +4 -1
  135. package/host-runtime/dist/governance-observation-store.d.ts +40 -1
  136. package/host-runtime/dist/governance-observation-store.js +188 -9
  137. package/host-runtime/dist/governance-signal-admission.d.ts +19 -3
  138. package/host-runtime/dist/governance-signal-admission.js +12 -4
  139. package/host-runtime/dist/host-tool-declaration.d.ts +18 -2
  140. package/host-runtime/dist/host-tool-declaration.js +67 -11
  141. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +7 -0
  142. package/host-runtime/dist/host-tool-semantic-resolver.js +22 -2
  143. package/host-runtime/dist/index.d.ts +3 -0
  144. package/host-runtime/dist/index.js +14 -0
  145. package/host-runtime/dist/production-rulehost-gate.js +36 -4
  146. package/host-runtime/dist/trajectory-retention.d.ts +147 -0
  147. package/host-runtime/dist/trajectory-retention.js +907 -0
  148. package/host-runtime/package.json +1 -1
  149. package/install-layout/dist/index.d.ts +9 -2
  150. package/install-layout/dist/index.js +26 -9
  151. package/install-layout/dist/mcp-binding-contract.d.ts +91 -0
  152. package/install-layout/dist/mcp-binding-contract.js +230 -0
  153. package/install-layout/package.json +1 -1
  154. package/package.json +4 -4
  155. package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
  156. package/pd-cli/dist/commands/build-trajectory-evidence.js +17 -11
  157. package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
  158. package/pd-cli/dist/commands/codex-reconcile.d.ts +7 -0
  159. package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -1
  160. package/pd-cli/dist/commands/codex-reconcile.js +11 -2
  161. package/pd-cli/dist/commands/codex-reconcile.js.map +1 -1
  162. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  163. package/pd-cli/dist/commands/codex-worker.js +35 -0
  164. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  165. package/pd-cli/dist/commands/command-helpers.d.ts +1 -1
  166. package/pd-cli/dist/commands/command-helpers.js +1 -1
  167. package/pd-cli/dist/commands/errors-list.d.ts +1 -1
  168. package/pd-cli/dist/commands/errors-list.js +1 -1
  169. package/pd-cli/dist/commands/health-mcp.d.ts +23 -1
  170. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  171. package/pd-cli/dist/commands/health-mcp.js +81 -22
  172. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  173. package/pd-cli/dist/commands/health.d.ts +1 -1
  174. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  175. package/pd-cli/dist/commands/health.js +12 -5
  176. package/pd-cli/dist/commands/health.js.map +1 -1
  177. package/pd-cli/dist/commands/principles-stats.d.ts +1 -1
  178. package/pd-cli/dist/commands/principles-stats.js +1 -1
  179. package/pd-cli/dist/commands/trajectory-retention.d.ts +23 -0
  180. package/pd-cli/dist/commands/trajectory-retention.d.ts.map +1 -0
  181. package/pd-cli/dist/commands/trajectory-retention.js +159 -0
  182. package/pd-cli/dist/commands/trajectory-retention.js.map +1 -0
  183. package/pd-cli/dist/commands/workbuddy-setup.d.ts +69 -0
  184. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -0
  185. package/pd-cli/dist/commands/workbuddy-setup.js +379 -0
  186. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -0
  187. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  188. package/pd-cli/dist/commands/workbuddy-worker.js +42 -6
  189. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  190. package/pd-cli/dist/index.d.ts +1 -7
  191. package/pd-cli/dist/index.d.ts.map +1 -1
  192. package/pd-cli/dist/index.js +15 -1201
  193. package/pd-cli/dist/index.js.map +1 -1
  194. package/pd-cli/dist/program.d.ts +17 -0
  195. package/pd-cli/dist/program.d.ts.map +1 -0
  196. package/pd-cli/dist/program.js +1263 -0
  197. package/pd-cli/dist/program.js.map +1 -0
  198. package/pd-cli/dist/services/delivery-surfaces.d.ts.map +1 -1
  199. package/pd-cli/dist/services/delivery-surfaces.js +7 -5
  200. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  201. package/pd-cli/dist/services/version-report.d.ts.map +1 -1
  202. package/pd-cli/dist/services/version-report.js +30 -4
  203. package/pd-cli/dist/services/version-report.js.map +1 -1
  204. package/pd-cli/package.json +1 -1
  205. package/pd-mcp-server/dist/version.d.ts +1 -1
  206. package/pd-mcp-server/dist/version.js +1 -1
  207. package/pd-mcp-server/package.json +3 -1
  208. package/plugin/dist/bundle.js +477 -471
  209. package/plugin/dist/constants/tools.d.ts +8 -1
  210. package/plugin/dist/core/trajectory-retention-trigger.d.ts +13 -0
  211. package/plugin/dist/core/trajectory.d.ts +14 -0
  212. package/plugin/dist/hooks/gate-block-helper.d.ts +17 -0
  213. package/plugin/dist/hooks/gate.d.ts +7 -2
  214. package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +1 -0
  215. package/plugin/dist/index.d.ts +5 -0
  216. package/plugin/dist/openclaw.plugin.json +1 -1
  217. package/plugin/dist/rulehost-evidence.js +29 -23
  218. package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  219. package/plugin/dist/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  220. package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  221. package/plugin/dist/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  222. package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  223. package/plugin/dist/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  224. package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  225. package/plugin/dist/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  226. package/plugin/openclaw.plugin.json +1 -1
  227. package/plugin/package.json +1 -1
  228. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  229. package/plugin/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  230. package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  231. package/plugin/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  232. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  233. package/plugin/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  234. package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  235. package/plugin/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  236. package/release-manager/dist/installers/codex-host-installer.js +92 -5
  237. package/release-manager/dist/installers/mcp-binding-shape-mirror.js +105 -0
  238. package/release-manager/package.json +1 -1
  239. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +10 -0
  240. package/workbuddy-adapter/dist/codec/input-decoder.js +62 -5
  241. package/workbuddy-adapter/dist/host-adapter.js +1 -0
  242. package/workbuddy-adapter/dist/index.d.ts +1 -0
  243. package/workbuddy-adapter/dist/index.js +1 -0
  244. package/workbuddy-adapter/dist/ingestion/catch-up.d.ts +25 -0
  245. package/workbuddy-adapter/dist/ingestion/catch-up.js +161 -0
  246. package/workbuddy-adapter/dist/ingestion/encode-cwd.d.ts +6 -0
  247. package/workbuddy-adapter/dist/ingestion/encode-cwd.js +39 -0
  248. package/workbuddy-adapter/dist/ingestion/index.d.ts +13 -0
  249. package/workbuddy-adapter/dist/ingestion/index.js +13 -0
  250. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +46 -0
  251. package/workbuddy-adapter/dist/ingestion/ingestion.js +135 -0
  252. package/workbuddy-adapter/dist/ingestion/transcript-decoder.d.ts +70 -0
  253. package/workbuddy-adapter/dist/ingestion/transcript-decoder.js +554 -0
  254. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +39 -0
  255. package/workbuddy-adapter/dist/ingestion/transcript-path.js +117 -0
  256. package/workbuddy-adapter/dist/ingestion/transcript-source.d.ts +15 -0
  257. package/workbuddy-adapter/dist/ingestion/transcript-source.js +152 -0
  258. package/workbuddy-adapter/dist/pd-hook.d.ts +8 -0
  259. package/workbuddy-adapter/dist/pd-hook.js +59 -2
  260. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -0
  261. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -17
  262. package/workbuddy-adapter/package.json +1 -1
  263. package/workbuddy-adapter/plugin/hooks/hooks.json +11 -0
  264. package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +57 -19
  265. package/workbuddy-adapter/plugin/skills/pd-control/SKILL.md +21 -9
  266. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +72 -61
  267. package/workbuddy-adapter/plugin/skills/pd-review/SKILL.md +27 -12
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Trajectory retention — policy resolution, cutoff arithmetic and the batched
3
+ * delete engine (SPEC-PD-TR-001).
4
+ *
5
+ * Ownership:
6
+ * - owns: the `trajectoryRetention` config→policy mapping (including every
7
+ * fail-closed/degraded rule), the monotonic cutoff computation, the table
8
+ * plan set, and the batch loop that performs deletes.
9
+ * - owns: `ensureTrajectoryRetentionIndexes` — the ONLY place that creates the
10
+ * retention indexes. It is never called from a hook/open path: the
11
+ * maintenance entry point calls it explicitly (SPEC §5.2).
12
+ * - does NOT own: path resolution, file locks, the marker file, the export
13
+ * list, DB open/WAL assertions. Those are host I/O and live in
14
+ * `@principles/host-runtime` (`trajectory-retention.ts` there).
15
+ * - does NOT own: blob-file deletion (`openclaw-plugin` trajectory store).
16
+ *
17
+ * Every function here is pure with respect to the filesystem: the only I/O is
18
+ * the `Database` handle the caller passes in. That keeps core's I/O seam
19
+ * registry unchanged.
20
+ */
21
+ import type { Database } from 'better-sqlite3';
22
+ export declare const TRAJECTORY_RETENTION_DEFAULTS: Readonly<{
23
+ enabled: true;
24
+ retentionDays: 90;
25
+ intervalHours: 6;
26
+ batchSize: 2000;
27
+ runBudgetMs: 3000;
28
+ }>;
29
+ /** `retentionDays = 0` disables retention; 1..6 is rejected (never "delete all"). */
30
+ export declare const RETENTION_MIN_ACCEPTED_DAYS = 7;
31
+ export declare const RETENTION_MAX_ACCEPTED_DAYS = 3650;
32
+ export declare const RETENTION_BATCH_SIZE_MIN = 100;
33
+ export declare const RETENTION_BATCH_SIZE_MAX = 10000;
34
+ export declare const RETENTION_RUN_BUDGET_MIN_MS = 500;
35
+ export declare const RETENTION_RUN_BUDGET_MAX_MS = 10000;
36
+ export declare const RETENTION_INTERVAL_HOURS_MIN = 1;
37
+ export declare const RETENTION_INTERVAL_HOURS_MAX = 168;
38
+ /** 单批墙钟上限;超过即提交后停止本次运行(SPEC §4.3)。 */
39
+ export declare const RETENTION_BATCH_BUDGET_MS = 250;
40
+ /** 截止线每次最多前进 7 天,防止一次时钟前跳清空历史(SPEC §3.3)。 */
41
+ export declare const RETENTION_MAX_CUTOFF_ADVANCE_MS: number;
42
+ /** 系统时间后跳容差。 */
43
+ export declare const RETENTION_CLOCK_BACKWARDS_TOLERANCE_MS: number;
44
+ /** busy 让路后的指数退避序列,最后一档封顶(SPEC §4.4)。 */
45
+ export declare const RETENTION_BUSY_BACKOFF_MS: readonly number[];
46
+ export interface TrajectoryRetentionPolicy {
47
+ enabled: boolean;
48
+ retentionDays: number;
49
+ intervalHours: number;
50
+ batchSize: number;
51
+ runBudgetMs: number;
52
+ /**
53
+ * Present ⇒ the configured values are unusable. The runner MUST delete
54
+ * nothing while this is set (SPEC §3.1 fail-closed, A10).
55
+ */
56
+ degradedReason?: string;
57
+ /**
58
+ * True when `retentionDays: 0` deliberately switched retention off. This is
59
+ * NOT a degraded state: the Owner asked for no sweeping.
60
+ */
61
+ disabledByZeroDays?: boolean;
62
+ }
63
+ /**
64
+ * Map the raw `trajectoryRetention` config section to an effective policy.
65
+ *
66
+ * Three distinct states, deliberately separated:
67
+ * - absent → defaults, sweeping enabled;
68
+ * - valid → the configured values;
69
+ * - unusable → `degradedReason` set, sweeping must delete 0 rows.
70
+ *
71
+ * A missing section never degrades; a present-but-wrong section never falls
72
+ * back to "delete with defaults" (that would turn a config typo into
73
+ * irreversible deletion).
74
+ */
75
+ export declare function resolveTrajectoryRetentionPolicy(raw: unknown): TrajectoryRetentionPolicy;
76
+ /**
77
+ * `<workspace>/.state/trajectory-retention.json` — durable retention control
78
+ * state, not a cache.
79
+ *
80
+ * It is the ONLY record of how far the cutoff has advanced and when the clock
81
+ * baseline was last observed. That is why losing it must be handled
82
+ * conservatively (the host re-derives a baseline from the oldest stored row
83
+ * instead of treating it as a first run) and why it is written atomically.
84
+ *
85
+ * It is also the ledger for the run named by `lastOutcome`: `deletedByTable`,
86
+ * `durationMs` and `totalDurationMs` always describe THAT run, including a run
87
+ * that failed midway (the host writes the committed counts before returning).
88
+ */
89
+ export interface TrajectoryRetentionMarker {
90
+ lastRunAt: string | null;
91
+ lastCutoff: string | null;
92
+ lastOutcome: string | null;
93
+ /** Rows committed for the run named by `lastOutcome` (never cumulative). */
94
+ deletedByTable: Record<string, number>;
95
+ /** Batch-engine duration only (kept for backward-compatible readers). */
96
+ durationMs: number | null;
97
+ /** Wall clock of the whole maintenance run, including DB open/DDL/marker. */
98
+ totalDurationMs: number | null;
99
+ partial: boolean;
100
+ backoffUntil: string | null;
101
+ consecutiveBusy: number;
102
+ reason: string | null;
103
+ }
104
+ export declare const EMPTY_RETENTION_MARKER: TrajectoryRetentionMarker;
105
+ /**
106
+ * Coerce any parsed JSON into a usable marker.
107
+ *
108
+ * Returns `damaged: true` when a field was missing or malformed. Unparseable
109
+ * timestamps are normalised to `null` instead of being preserved, so a single
110
+ * bad value can never wedge retention forever (review finding P1-2).
111
+ */
112
+ export declare function normalizeRetentionMarker(value: unknown): {
113
+ marker: TrajectoryRetentionMarker;
114
+ damaged: boolean;
115
+ };
116
+ export declare function isRetentionMarker(value: unknown): value is TrajectoryRetentionMarker;
117
+ export type RetentionCutoffDecision = {
118
+ kind: 'run';
119
+ cutoff: string;
120
+ computedCutoff: string;
121
+ advanceCapped: boolean;
122
+ /** A stored lastCutoff was outside the window and was discarded (F1). */
123
+ discardedMarkerCutoff: boolean;
124
+ } | {
125
+ kind: 'skip';
126
+ reason: 'clock_backwards' | 'clock_forward_anomaly' | 'marker_timestamp_invalid';
127
+ };
128
+ /**
129
+ * Whether a stored `lastCutoff` may be used as a lower bound.
130
+ *
131
+ * A surviving cutoff is only meaningful while it lies inside the current
132
+ * retention window. A future value can arrive from a clock that ran fast (the
133
+ * cutoff advanced while the clock was wrong) or from a hand-edited marker.
134
+ * Such a value must be DISCARDED, not clamped: clamping still leaves a cutoff
135
+ * inside the window and deletes rows that should be kept (F1).
136
+ */
137
+ export declare function isRetentionCutoffInWindow(args: {
138
+ lastCutoff: string | null;
139
+ nowMs: number;
140
+ retentionDays: number;
141
+ }): boolean;
142
+ /**
143
+ * Compute this run's cutoff.
144
+ *
145
+ * Deletion is irreversible, so every ambiguity resolves to "delete less":
146
+ * - the cutoff never moves backwards;
147
+ * - it advances at most `RETENTION_MAX_CUTOFF_ADVANCE_MS` per run;
148
+ * - a backwards clock tick (> 1 h) and an implausible forward jump skip the
149
+ * run entirely instead of deleting a range that may be wrong.
150
+ */
151
+ export declare function computeRetentionCutoff(args: {
152
+ nowMs: number;
153
+ retentionDays: number;
154
+ intervalHours: number;
155
+ marker: TrajectoryRetentionMarker;
156
+ }): RetentionCutoffDecision;
157
+ export declare function nextBackoffUntil(nowMs: number, consecutiveBusy: number): string;
158
+ export interface TrajectoryRetentionTablePlan {
159
+ readonly table: string;
160
+ readonly timeColumn: 'created_at' | 'expired_at';
161
+ /**
162
+ * Fixed predicate — never user input. `governance_observations` only ever
163
+ * loses rows that are already de-identified AND terminal (SPEC §2.1).
164
+ */
165
+ readonly extraPredicate?: string;
166
+ }
167
+ export declare const TRAJECTORY_RETENTION_TABLES: readonly TrajectoryRetentionTablePlan[];
168
+ /**
169
+ * Retention indexes.
170
+ *
171
+ * Kept out of `applyTrajectorySchemaBase` on purpose: creating an index on a
172
+ * million-row table costs seconds, and that function runs every time a host
173
+ * opens the database. Only the maintenance entry point calls this (SPEC §5.2).
174
+ *
175
+ * `idx_assistant_turns_session_id` / `idx_user_turns_session_id` /
176
+ * `idx_tool_calls_created_at` / `idx_assistant_turns_created_at` already exist
177
+ * in the canonical schema; only the genuinely missing ones are here.
178
+ */
179
+ export declare const TRAJECTORY_RETENTION_INDEXES: readonly string[];
180
+ export interface RetentionIndexReport {
181
+ /**
182
+ * Statements the maintenance entry actually executed. `IF NOT EXISTS` means
183
+ * this is "applied", not "newly created" — an index that already existed is
184
+ * still applied (review finding 9).
185
+ */
186
+ applied: string[];
187
+ skipped: string[];
188
+ }
189
+ /**
190
+ * Create the retention indexes if their tables exist. Idempotent.
191
+ * `skipped` names indexes whose table is absent (Profile A databases do not
192
+ * carry governance tables, for example) — never an error.
193
+ */
194
+ export declare function ensureTrajectoryRetentionIndexes(db: Database): RetentionIndexReport;
195
+ /**
196
+ * Read-only existence check for the retention indexes. The regular sweep must
197
+ * never create them: `CREATE INDEX` on a busy database can block for seconds,
198
+ * which is exactly the host stall F2 forbids. Index creation is an explicit
199
+ * maintenance action (`pd trajectory vacuum --yes`).
200
+ */
201
+ export declare function missingTrajectoryRetentionIndexes(db: Database): string[];
202
+ export interface RetentionBatchRow {
203
+ id: number;
204
+ at: string;
205
+ }
206
+ export interface TrajectoryRetentionHooks {
207
+ /** Injectable clock: batch budgets and the run budget must be measurable. */
208
+ now(): number;
209
+ /**
210
+ * Called AFTER the batch ids are selected and BEFORE the delete
211
+ * transaction, i.e. with no write lock held. The export list is written from
212
+ * here.
213
+ *
214
+ * Return a non-null reason to abort the run WITHOUT deleting this batch: the
215
+ * audit trail must exist before irreversible deletion (SPEC §8.2). Returning
216
+ * `null` means "audit committed, proceed".
217
+ */
218
+ onBatchPrepared?(batch: {
219
+ table: string;
220
+ rows: RetentionBatchRow[];
221
+ }): string | null;
222
+ /** Called after a batch commits, with the ids that were actually eligible. */
223
+ onBatchCommitted?(batch: {
224
+ table: string;
225
+ rows: RetentionBatchRow[];
226
+ changes: number;
227
+ }): void;
228
+ }
229
+ export type TrajectoryRetentionOutcome = 'completed' | 'partial' | 'deferred_busy' | 'invariant_violation' | 'deadline';
230
+ export interface TrajectoryRetentionRunResult {
231
+ outcome: TrajectoryRetentionOutcome;
232
+ cutoff: string;
233
+ deletedByTable: Record<string, number>;
234
+ batches: number;
235
+ maxBatchDurationMs: number;
236
+ /** Batch-engine wall clock only; the host also measures totalDurationMs. */
237
+ durationMs: number;
238
+ reason?: string;
239
+ }
240
+ /**
241
+ * Delete expired rows in bounded batches.
242
+ *
243
+ * Contract:
244
+ * - select (plain read) → audit (outside any lock) → one
245
+ * `BEGIN IMMEDIATE`/`COMMIT` per batch, so a kill loses at most one batch;
246
+ * - an audit failure stops before the delete: no trace, no deletion;
247
+ * - busy ⇒ yield immediately (never retry the same batch in this run);
248
+ * - `runBudgetMs` is a hard budget: a batch starts only when at least
249
+ * `RETENTION_BATCH_BUDGET_MS` remains.
250
+ */
251
+ export interface TrajectoryRetentionBatchRequest {
252
+ policy: Pick<TrajectoryRetentionPolicy, 'batchSize' | 'runBudgetMs'>;
253
+ cutoff: string;
254
+ hooks: TrajectoryRetentionHooks;
255
+ }
256
+ export declare function runTrajectoryRetentionBatches(db: Database, request: TrajectoryRetentionBatchRequest): TrajectoryRetentionRunResult;
257
+ //# sourceMappingURL=trajectory-retention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trajectory-retention.d.ts","sourceRoot":"","sources":["../../src/runtime/trajectory-retention.ts"],"names":[],"mappings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