create-principles-disciple 1.150.3 → 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 (248) 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-compatibility-read-model.d.ts.map +1 -1
  13. package/core/dist/runtime/activation-compatibility-read-model.js +2 -1
  14. package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
  15. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  16. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +106 -19
  17. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  18. package/core/dist/runtime/candidate-audit.d.ts.map +1 -1
  19. package/core/dist/runtime/candidate-audit.js +2 -1
  20. package/core/dist/runtime/candidate-audit.js.map +1 -1
  21. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  22. package/core/dist/runtime/config/pd-config-effective.js +2 -0
  23. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  24. package/core/dist/runtime/config/pd-config-types.d.ts +52 -0
  25. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  26. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  27. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  28. package/core/dist/runtime/config/pd-config-validate.js +134 -0
  29. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  30. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  31. package/core/dist/runtime/feature-flags/feature-flag-contract.js +8 -0
  32. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  33. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  34. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +24 -0
  35. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  36. package/core/dist/runtime/index.d.ts +2 -0
  37. package/core/dist/runtime/index.d.ts.map +1 -1
  38. package/core/dist/runtime/index.js +2 -0
  39. package/core/dist/runtime/index.js.map +1 -1
  40. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +16 -0
  41. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  42. package/core/dist/runtime/internalization/rule-host-input-builder.js +18 -0
  43. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  44. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +8 -0
  45. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  46. package/core/dist/runtime/internalization/split-diagnostician-runner.js +24 -2
  47. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  48. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts +26 -0
  49. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts.map +1 -1
  50. package/core/dist/runtime/internalization/tool-semantic-registry.js +55 -5
  51. package/core/dist/runtime/internalization/tool-semantic-registry.js.map +1 -1
  52. package/core/dist/runtime/internalization-chain-integrity-read-model.d.ts.map +1 -1
  53. package/core/dist/runtime/internalization-chain-integrity-read-model.js +2 -2
  54. package/core/dist/runtime/internalization-chain-integrity-read-model.js.map +1 -1
  55. package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
  56. package/core/dist/runtime/internalization-integrity-remediation.js +2 -2
  57. package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
  58. package/core/dist/runtime/operator-health-read-model.d.ts.map +1 -1
  59. package/core/dist/runtime/operator-health-read-model.js +2 -2
  60. package/core/dist/runtime/operator-health-read-model.js.map +1 -1
  61. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  62. package/core/dist/runtime/pain-recall-read-model.js +4 -3
  63. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  64. package/core/dist/runtime/pruning-read-model.d.ts.map +1 -1
  65. package/core/dist/runtime/pruning-read-model.js +3 -2
  66. package/core/dist/runtime/pruning-read-model.js.map +1 -1
  67. package/core/dist/runtime/risk/risk-calculator-policy.d.ts +12 -2
  68. package/core/dist/runtime/risk/risk-calculator-policy.d.ts.map +1 -1
  69. package/core/dist/runtime/risk/risk-calculator-policy.js +33 -22
  70. package/core/dist/runtime/risk/risk-calculator-policy.js.map +1 -1
  71. package/core/dist/runtime/schema-conformance-read-model.js +2 -2
  72. package/core/dist/runtime/schema-conformance-read-model.js.map +1 -1
  73. package/core/dist/runtime/store/sqlite-connection.d.ts +0 -5
  74. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  75. package/core/dist/runtime/store/sqlite-connection.js +4 -12
  76. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  77. package/core/dist/runtime/store/storage-paths.d.ts +17 -0
  78. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -0
  79. package/core/dist/runtime/store/storage-paths.js +52 -0
  80. package/core/dist/runtime/store/storage-paths.js.map +1 -0
  81. package/core/dist/runtime/trajectory-retention.d.ts +257 -0
  82. package/core/dist/runtime/trajectory-retention.d.ts.map +1 -0
  83. package/core/dist/runtime/trajectory-retention.js +598 -0
  84. package/core/dist/runtime/trajectory-retention.js.map +1 -0
  85. package/core/dist/trajectory-store.d.ts +9 -9
  86. package/core/dist/trajectory-store.d.ts.map +1 -1
  87. package/core/dist/trajectory-store.js +9 -12
  88. package/core/dist/trajectory-store.js.map +1 -1
  89. package/core/package.json +1 -1
  90. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  91. package/dist/installers/codex-host-installer.js +92 -5
  92. package/dist/installers/codex-host-installer.js.map +1 -1
  93. package/dist/installers/mcp-binding-shape-mirror.d.ts +27 -0
  94. package/dist/installers/mcp-binding-shape-mirror.d.ts.map +1 -0
  95. package/dist/installers/mcp-binding-shape-mirror.js +105 -0
  96. package/dist/installers/mcp-binding-shape-mirror.js.map +1 -0
  97. package/dist/skill-catalog.d.ts +35 -0
  98. package/dist/skill-catalog.d.ts.map +1 -0
  99. package/dist/skill-catalog.js +85 -0
  100. package/dist/skill-catalog.js.map +1 -0
  101. package/dist/skill-delivery-parity.d.ts +22 -0
  102. package/dist/skill-delivery-parity.d.ts.map +1 -0
  103. package/dist/skill-delivery-parity.js +31 -0
  104. package/dist/skill-delivery-parity.js.map +1 -0
  105. package/host-runtime/dist/active-principle-prompt.d.ts +8 -0
  106. package/host-runtime/dist/active-principle-prompt.js +15 -5
  107. package/host-runtime/dist/adaptive-decision-protocol.d.ts +142 -0
  108. package/host-runtime/dist/adaptive-decision-protocol.js +190 -0
  109. package/host-runtime/dist/adaptive-priority-provider.d.ts +37 -13
  110. package/host-runtime/dist/adaptive-priority-provider.js +65 -62
  111. package/host-runtime/dist/adaptive-selection.d.ts +67 -64
  112. package/host-runtime/dist/adaptive-selection.js +215 -327
  113. package/host-runtime/dist/adaptive-skip-decision.d.ts +26 -14
  114. package/host-runtime/dist/adaptive-skip-decision.js +33 -29
  115. package/host-runtime/dist/codex-rule-context-provider.js +4 -1
  116. package/host-runtime/dist/governance-observation-store.d.ts +40 -1
  117. package/host-runtime/dist/governance-observation-store.js +188 -9
  118. package/host-runtime/dist/governance-signal-admission.d.ts +19 -3
  119. package/host-runtime/dist/governance-signal-admission.js +12 -4
  120. package/host-runtime/dist/host-tool-declaration.d.ts +18 -2
  121. package/host-runtime/dist/host-tool-declaration.js +67 -11
  122. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +7 -0
  123. package/host-runtime/dist/host-tool-semantic-resolver.js +22 -2
  124. package/host-runtime/dist/index.d.ts +3 -0
  125. package/host-runtime/dist/index.js +14 -0
  126. package/host-runtime/dist/production-rulehost-gate.js +15 -3
  127. package/host-runtime/dist/trajectory-retention.d.ts +147 -0
  128. package/host-runtime/dist/trajectory-retention.js +907 -0
  129. package/host-runtime/package.json +1 -1
  130. package/install-layout/dist/index.d.ts +9 -2
  131. package/install-layout/dist/index.js +26 -9
  132. package/install-layout/dist/mcp-binding-contract.d.ts +91 -0
  133. package/install-layout/dist/mcp-binding-contract.js +230 -0
  134. package/install-layout/package.json +1 -1
  135. package/package.json +4 -4
  136. package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
  137. package/pd-cli/dist/commands/build-trajectory-evidence.js +17 -11
  138. package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
  139. package/pd-cli/dist/commands/codex-reconcile.d.ts +7 -0
  140. package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -1
  141. package/pd-cli/dist/commands/codex-reconcile.js +11 -2
  142. package/pd-cli/dist/commands/codex-reconcile.js.map +1 -1
  143. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  144. package/pd-cli/dist/commands/codex-worker.js +35 -0
  145. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  146. package/pd-cli/dist/commands/command-helpers.d.ts +1 -1
  147. package/pd-cli/dist/commands/command-helpers.js +1 -1
  148. package/pd-cli/dist/commands/errors-list.d.ts +1 -1
  149. package/pd-cli/dist/commands/errors-list.js +1 -1
  150. package/pd-cli/dist/commands/health-mcp.d.ts +23 -1
  151. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  152. package/pd-cli/dist/commands/health-mcp.js +81 -22
  153. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  154. package/pd-cli/dist/commands/health.d.ts +1 -1
  155. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  156. package/pd-cli/dist/commands/health.js +12 -5
  157. package/pd-cli/dist/commands/health.js.map +1 -1
  158. package/pd-cli/dist/commands/principles-stats.d.ts +1 -1
  159. package/pd-cli/dist/commands/principles-stats.js +1 -1
  160. package/pd-cli/dist/commands/trajectory-retention.d.ts +23 -0
  161. package/pd-cli/dist/commands/trajectory-retention.d.ts.map +1 -0
  162. package/pd-cli/dist/commands/trajectory-retention.js +159 -0
  163. package/pd-cli/dist/commands/trajectory-retention.js.map +1 -0
  164. package/pd-cli/dist/commands/workbuddy-setup.d.ts +69 -0
  165. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -0
  166. package/pd-cli/dist/commands/workbuddy-setup.js +379 -0
  167. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -0
  168. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  169. package/pd-cli/dist/commands/workbuddy-worker.js +42 -6
  170. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  171. package/pd-cli/dist/index.d.ts +1 -7
  172. package/pd-cli/dist/index.d.ts.map +1 -1
  173. package/pd-cli/dist/index.js +15 -1201
  174. package/pd-cli/dist/index.js.map +1 -1
  175. package/pd-cli/dist/program.d.ts +17 -0
  176. package/pd-cli/dist/program.d.ts.map +1 -0
  177. package/pd-cli/dist/program.js +1263 -0
  178. package/pd-cli/dist/program.js.map +1 -0
  179. package/pd-cli/dist/services/delivery-surfaces.d.ts.map +1 -1
  180. package/pd-cli/dist/services/delivery-surfaces.js +7 -5
  181. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  182. package/pd-cli/dist/services/version-report.d.ts.map +1 -1
  183. package/pd-cli/dist/services/version-report.js +30 -4
  184. package/pd-cli/dist/services/version-report.js.map +1 -1
  185. package/pd-cli/package.json +1 -1
  186. package/pd-mcp-server/dist/version.d.ts +1 -1
  187. package/pd-mcp-server/dist/version.js +1 -1
  188. package/pd-mcp-server/package.json +3 -1
  189. package/plugin/dist/bundle.js +544 -494
  190. package/plugin/dist/constants/tools.d.ts +8 -1
  191. package/plugin/dist/core/trajectory-retention-trigger.d.ts +13 -0
  192. package/plugin/dist/core/trajectory.d.ts +14 -0
  193. package/plugin/dist/hooks/gate-block-helper.d.ts +17 -0
  194. package/plugin/dist/hooks/gate.d.ts +6 -1
  195. package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +1 -0
  196. package/plugin/dist/index.d.ts +5 -0
  197. package/plugin/dist/openclaw.plugin.json +1 -1
  198. package/plugin/dist/rulehost-evidence.js +29 -23
  199. package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  200. package/plugin/dist/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  201. package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  202. package/plugin/dist/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  203. package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  204. package/plugin/dist/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  205. package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  206. package/plugin/dist/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  207. package/plugin/openclaw.plugin.json +1 -1
  208. package/plugin/package.json +1 -1
  209. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  210. package/plugin/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  211. package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  212. package/plugin/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  213. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  214. package/plugin/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  215. package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  216. package/plugin/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  217. package/release-manager/dist/installers/codex-host-installer.js +92 -5
  218. package/release-manager/dist/installers/mcp-binding-shape-mirror.js +105 -0
  219. package/release-manager/package.json +1 -1
  220. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +10 -0
  221. package/workbuddy-adapter/dist/codec/input-decoder.js +62 -5
  222. package/workbuddy-adapter/dist/host-adapter.js +1 -0
  223. package/workbuddy-adapter/dist/index.d.ts +1 -0
  224. package/workbuddy-adapter/dist/index.js +1 -0
  225. package/workbuddy-adapter/dist/ingestion/catch-up.d.ts +25 -0
  226. package/workbuddy-adapter/dist/ingestion/catch-up.js +161 -0
  227. package/workbuddy-adapter/dist/ingestion/encode-cwd.d.ts +6 -0
  228. package/workbuddy-adapter/dist/ingestion/encode-cwd.js +39 -0
  229. package/workbuddy-adapter/dist/ingestion/index.d.ts +13 -0
  230. package/workbuddy-adapter/dist/ingestion/index.js +13 -0
  231. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +46 -0
  232. package/workbuddy-adapter/dist/ingestion/ingestion.js +135 -0
  233. package/workbuddy-adapter/dist/ingestion/transcript-decoder.d.ts +70 -0
  234. package/workbuddy-adapter/dist/ingestion/transcript-decoder.js +554 -0
  235. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +39 -0
  236. package/workbuddy-adapter/dist/ingestion/transcript-path.js +117 -0
  237. package/workbuddy-adapter/dist/ingestion/transcript-source.d.ts +15 -0
  238. package/workbuddy-adapter/dist/ingestion/transcript-source.js +152 -0
  239. package/workbuddy-adapter/dist/pd-hook.d.ts +8 -0
  240. package/workbuddy-adapter/dist/pd-hook.js +59 -2
  241. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -0
  242. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -17
  243. package/workbuddy-adapter/package.json +1 -1
  244. package/workbuddy-adapter/plugin/hooks/hooks.json +11 -0
  245. package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +57 -19
  246. package/workbuddy-adapter/plugin/skills/pd-control/SKILL.md +21 -9
  247. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +72 -61
  248. package/workbuddy-adapter/plugin/skills/pd-review/SKILL.md +27 -12
@@ -0,0 +1,25 @@
1
+ export interface WorkbuddyCatchUpOptions {
2
+ readonly workspaceDir: string;
3
+ /** Resolved BEFORE any I/O: host.workbuddy AND workbuddy_conversation_ingestion. */
4
+ readonly ingestionEnabled: boolean;
5
+ readonly now?: Date;
6
+ readonly home?: string;
7
+ readonly maxRollouts?: number;
8
+ }
9
+ export interface WorkbuddyCatchUpResult {
10
+ readonly status: 'ok' | 'skipped' | 'degraded';
11
+ readonly reason?: string;
12
+ readonly nextAction?: string;
13
+ readonly examined: number;
14
+ readonly ingested: number;
15
+ readonly warnings: readonly string[];
16
+ }
17
+ /**
18
+ * Re-enter the gated ingestion pipeline for every durable WorkBuddy
19
+ * checkpoint, at most `maxRollouts` sessions per cycle.
20
+ *
21
+ * Flag-off and unreadable checkpoints return before any transcript scan.
22
+ * Per-session locate/validate/ingest failures become bounded warnings and the
23
+ * cycle reports `degraded`; a revoked consent is an intentional skip.
24
+ */
25
+ export declare function catchUpWorkbuddyIngestion(options: WorkbuddyCatchUpOptions): WorkbuddyCatchUpResult;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * WorkBuddy transcript catch-up (PRI-1171 P2, ticket ⑤).
3
+ *
4
+ * The Stop hook is the primary ingestion trigger, but a hook can time out or
5
+ * a single 1 MiB bounded window can leave lag behind. The worker calls this
6
+ * once per cycle: it walks the DURABLE workbuddy checkpoints (the exact set of
7
+ * sessions the authenticated hook already delivered), locates each transcript
8
+ * by its exact session id, and re-enters the SAME gated pipeline through
9
+ * `ingestWorkbuddyConversation` (so consent is re-read and revocation takes
10
+ * effect immediately).
11
+ *
12
+ * "No session discovery" means it never INVENTS an identity: it does not pick
13
+ * a "latest" or "most interesting" session. It does enumerate the projects
14
+ * directory (`readdirSync`) to find the one file whose name equals an already
15
+ * checkpointed session id, because the host stores each project in a separate
16
+ * directory and the checkpoint does not record which one.
17
+ *
18
+ * Locating is deterministic, not a "latest file" guess: only
19
+ * `<projectsRoot>/<any-project>/<sessionId>.jsonl` with EXACTLY one match is
20
+ * accepted, and `validateWorkbuddyTranscriptPath` re-applies containment,
21
+ * main-session shape and regular-file checks before any read. No schema
22
+ * change, no second source of truth — checkpoints stay the authority.
23
+ */
24
+ import fs from 'node:fs';
25
+ import os from 'node:os';
26
+ import path from 'node:path';
27
+ import { deferGovernanceCheckpoint, listGovernanceCheckpoints, readConversationIngestionConsent } from '@principles/host-runtime';
28
+ import { ingestWorkbuddyConversation } from './ingestion.js';
29
+ import { validateWorkbuddyTranscriptPath, workbuddyProjectsRoot } from './transcript-path.js';
30
+ const DEFAULT_MAX_ROLLOUTS = 8;
31
+ /** Mirrors the locator's main-session file-name contract; refuse odd identities. */
32
+ const SESSION_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
33
+ /**
34
+ * Find the ONE transcript file whose name equals an already checkpointed
35
+ * session identity inside the projects root. Returns null for a non-contract
36
+ * identity, an unreadable root, or zero/multiple matches — never a guess.
37
+ */
38
+ function locateCheckpointTranscript(projectsRoot, rolloutIdentity) {
39
+ if (!SESSION_ID_PATTERN.test(rolloutIdentity))
40
+ return null;
41
+ let entries;
42
+ try {
43
+ entries = fs.readdirSync(projectsRoot, { withFileTypes: true });
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ const fileName = `${rolloutIdentity}.jsonl`;
49
+ const matches = [];
50
+ for (const entry of entries) {
51
+ if (!entry.isDirectory())
52
+ continue;
53
+ const candidate = path.join(projectsRoot, entry.name, fileName);
54
+ try {
55
+ if (fs.statSync(candidate).isFile())
56
+ matches.push(candidate);
57
+ }
58
+ catch {
59
+ // This project does not carry that session — keep looking, never guess.
60
+ }
61
+ }
62
+ return matches.length === 1 ? (matches[0] ?? null) : null;
63
+ }
64
+ /**
65
+ * Re-enter the gated ingestion pipeline for every durable WorkBuddy
66
+ * checkpoint, at most `maxRollouts` sessions per cycle.
67
+ *
68
+ * Flag-off and unreadable checkpoints return before any transcript scan.
69
+ * Per-session locate/validate/ingest failures become bounded warnings and the
70
+ * cycle reports `degraded`; a revoked consent is an intentional skip.
71
+ */
72
+ export function catchUpWorkbuddyIngestion(options) {
73
+ // Flag gate FIRST — before checkpoint listing or any filesystem scan.
74
+ if (!options.ingestionEnabled) {
75
+ return {
76
+ status: 'skipped',
77
+ reason: 'feature_disabled',
78
+ nextAction: 'Enable workbuddy_conversation_ingestion (and host.workbuddy) plus a granted consent record to start transcript catch-up.',
79
+ examined: 0, ingested: 0, warnings: [],
80
+ };
81
+ }
82
+ // Consent gate BEFORE any transcript I/O (P2 review): a revoked or absent
83
+ // consent must not locate transcripts, stat them, or defer checkpoints. The
84
+ // flag alone is not authority to touch the host's files.
85
+ const consent = readConversationIngestionConsent(options.workspaceDir, 'workbuddy');
86
+ if (!consent.ok) {
87
+ return {
88
+ status: 'degraded', reason: `consent_unreadable:${consent.reason}`, nextAction: consent.nextAction,
89
+ examined: 0, ingested: 0, warnings: [],
90
+ };
91
+ }
92
+ const consentDecision = consent.record?.decision ?? 'not_present';
93
+ if (consentDecision !== 'granted') {
94
+ return {
95
+ status: 'skipped', reason: `consent_not_granted:${consentDecision}`,
96
+ nextAction: 'Record consent with `pd workbuddy setup --accept` to start transcript catch-up. Nothing was read.',
97
+ examined: 0, ingested: 0, warnings: [],
98
+ };
99
+ }
100
+ const listed = listGovernanceCheckpoints({ workspaceDir: options.workspaceDir, hostKind: 'workbuddy' });
101
+ if (!listed.ok) {
102
+ return {
103
+ status: 'degraded', reason: listed.reason, nextAction: listed.nextAction,
104
+ examined: 0, ingested: 0, warnings: [],
105
+ };
106
+ }
107
+ const projectsRoot = workbuddyProjectsRoot(options.home ?? os.homedir());
108
+ const limit = Math.max(1, Math.min(options.maxRollouts ?? DEFAULT_MAX_ROLLOUTS, 32));
109
+ const checkpoints = listed.checkpoints.slice(0, limit);
110
+ let ingested = 0;
111
+ const warnings = [];
112
+ const nowIso = (options.now ?? new Date()).toISOString();
113
+ // A failed session must not hold the oldest-first prefix forever (P2 review):
114
+ // bump ONLY its retry position so the next cycle can reach the rollouts
115
+ // behind it. Byte offset/ordinal stay untouched, so the work is still
116
+ // pending and retryable.
117
+ const defer = (rolloutIdentity, reason) => {
118
+ // A failed defer leaves the checkpoint at the head of the queue; report it
119
+ // instead of silently promising a retry-slot rotation (P2 review).
120
+ const deferred = deferGovernanceCheckpoint({ workspaceDir: options.workspaceDir, hostKind: 'workbuddy', rolloutIdentity, reason, now: nowIso });
121
+ if (!deferred.ok)
122
+ warnings.push(`checkpoint_defer_failed:${rolloutIdentity}:${deferred.reason}`);
123
+ };
124
+ for (const checkpoint of checkpoints) {
125
+ const located = locateCheckpointTranscript(projectsRoot, checkpoint.rolloutIdentity);
126
+ if (located === null) {
127
+ warnings.push(`transcript_unavailable:${checkpoint.rolloutIdentity}`);
128
+ defer(checkpoint.rolloutIdentity, 'transcript_unavailable');
129
+ continue;
130
+ }
131
+ const validated = validateWorkbuddyTranscriptPath(located, projectsRoot);
132
+ if (!validated.ok) {
133
+ warnings.push(`${validated.reason}:${checkpoint.rolloutIdentity}`);
134
+ defer(checkpoint.rolloutIdentity, validated.reason);
135
+ continue;
136
+ }
137
+ const outcome = ingestWorkbuddyConversation({
138
+ workspaceDir: options.workspaceDir,
139
+ rawPayload: { transcript_path: validated.canonicalPath },
140
+ sessionId: checkpoint.rolloutIdentity,
141
+ ingestionEnabled: true,
142
+ ...(options.now !== undefined ? { now: options.now } : {}),
143
+ ...(options.home !== undefined ? { home: options.home } : {}),
144
+ });
145
+ if (outcome.status === 'ingested')
146
+ ingested += outcome.inserted;
147
+ else if (outcome.status === 'degraded') {
148
+ warnings.push(`${outcome.reason}:${checkpoint.rolloutIdentity}`);
149
+ defer(checkpoint.rolloutIdentity, outcome.reason);
150
+ }
151
+ // 'skipped' = consent revoked/absent: intentional, never a warning.
152
+ }
153
+ if (warnings.length > 0) {
154
+ return {
155
+ status: 'degraded', reason: 'catch_up_degraded',
156
+ nextAction: 'Inspect the WorkBuddy transcript store and the governance trajectory checkpoints; the worker retries on the next cycle.',
157
+ examined: checkpoints.length, ingested, warnings,
158
+ };
159
+ }
160
+ return { status: 'ok', examined: checkpoints.length, ingested, warnings };
161
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Encode a host cwd into the single project-directory segment WorkBuddy uses:
3
+ * lowercase the drive letter, collapse each run of `:`/`\`/`/` into one `-`,
4
+ * and keep every other character byte-for-byte (fixtures in encode-cwd.test.ts).
5
+ */
6
+ export declare function encodeWorkbuddyCwd(cwd: string): string;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WorkBuddy project-directory cwd encoding (PRI-1171 P2; SPEC v0.2 §4.4,
3
+ * tech design §5.1).
4
+ *
5
+ * WorkBuddy stores every session transcript under
6
+ * `<home>/.workbuddy/projects/<encoded-cwd>/<sessionId>.jsonl`. The encoding
7
+ * rule is locked to FORENSIC SAMPLES from this machine's real directory
8
+ * names × the `cwd` fields inside their records (docs/plans/
9
+ * 2026-08-28-workbuddy-session-transcript-access.md §2, re-verified
10
+ * 2026-11-11), not to a prose transcription:
11
+ *
12
+ * `d:\Code\principles` → `d-Code-principles`
13
+ * `d:\Code\principles-private\aze` → `d-Code-principles-private-aze`
14
+ * `c:\Users\Administrator\Desktop\车险` → `c-Users-Administrator-Desktop-车险`
15
+ * `c:\Users\Administrator\WorkBuddy\2026-09-01…` → `c-Users-Administrator-WorkBuddy-2026-09-01…`
16
+ *
17
+ * Verified properties: the drive letter lowercases; every RUN of `:`, `\`
18
+ * and `/` collapses to a SINGLE `-` (the `d:\` prefix therefore yields one
19
+ * dash, never two); everything else — dashes, dots, underscores, CJK — is
20
+ * preserved byte-for-byte. No collision-suffix or escaping mechanism was
21
+ * observed on disk. The engine-side rule itself is not documented by the
22
+ * host; the fixtures table in tests/ingestion/encode-cwd.test.ts freezes
23
+ * these pairs against regression.
24
+ */
25
+ const SEPARATOR_RUN = /[\\/:]+/g;
26
+ /**
27
+ * Encode a host cwd into the single project-directory segment WorkBuddy uses:
28
+ * lowercase the drive letter, collapse each run of `:`/`\`/`/` into one `-`,
29
+ * and keep every other character byte-for-byte (fixtures in encode-cwd.test.ts).
30
+ */
31
+ export function encodeWorkbuddyCwd(cwd) {
32
+ if (cwd.length === 0)
33
+ return '';
34
+ // Drive-letter prefix: lowercase it before separator collapsing so `D:\x`
35
+ // and `d:\x` encode identically (records carry the lowercase form, hook
36
+ // payloads may carry either).
37
+ const drivePrefixed = /^[A-Za-z]:/.test(cwd) ? cwd.charAt(0).toLowerCase() + cwd.slice(1) : cwd;
38
+ return drivePrefixed.replace(SEPARATOR_RUN, '-');
39
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * WorkBuddy conversation-ingestion surface (PRI-1171 P2).
3
+ *
4
+ * The per-host thin half of the unified seam: cwd encoding, deterministic
5
+ * transcript location/validation, the flat-record decoder, and the
6
+ * TranscriptSourceAdapter the shared host-runtime pipeline drives.
7
+ */
8
+ export { encodeWorkbuddyCwd } from './encode-cwd.js';
9
+ export { deriveWorkbuddyTranscriptPath, validateWorkbuddyTranscriptPath, workbuddyProjectsRoot, type WorkbuddyTranscriptFileIdentity, type WorkbuddyTranscriptPathValidation, } from './transcript-path.js';
10
+ export { decodeWorkbuddyTranscriptWindow, type DecodedWorkbuddyDelta, type DecodeWorkbuddyWindowInput, } from './transcript-decoder.js';
11
+ export { createWorkbuddyTranscriptSource, WORKBUDDY_SINGLE_SESSION_ALERT_BYTES, type WorkbuddyTranscriptSourceContext, } from './transcript-source.js';
12
+ export { ingestWorkbuddyConversation, workbuddyIngestionHints, type WorkbuddyIngestionOptions, type WorkbuddyIngestionOutcome, } from './ingestion.js';
13
+ export { catchUpWorkbuddyIngestion, type WorkbuddyCatchUpOptions, type WorkbuddyCatchUpResult, } from './catch-up.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * WorkBuddy conversation-ingestion surface (PRI-1171 P2).
3
+ *
4
+ * The per-host thin half of the unified seam: cwd encoding, deterministic
5
+ * transcript location/validation, the flat-record decoder, and the
6
+ * TranscriptSourceAdapter the shared host-runtime pipeline drives.
7
+ */
8
+ export { encodeWorkbuddyCwd } from './encode-cwd.js';
9
+ export { deriveWorkbuddyTranscriptPath, validateWorkbuddyTranscriptPath, workbuddyProjectsRoot, } from './transcript-path.js';
10
+ export { decodeWorkbuddyTranscriptWindow, } from './transcript-decoder.js';
11
+ export { createWorkbuddyTranscriptSource, WORKBUDDY_SINGLE_SESSION_ALERT_BYTES, } from './transcript-source.js';
12
+ export { ingestWorkbuddyConversation, workbuddyIngestionHints, } from './ingestion.js';
13
+ export { catchUpWorkbuddyIngestion, } from './catch-up.js';
@@ -0,0 +1,46 @@
1
+ import { type HookHints, type TranscriptPort } from '@principles/host-runtime';
2
+ export interface WorkbuddyIngestionOptions {
3
+ /** Governance workspace (OD-07) — the v3 ledger and trajectory.db live here. */
4
+ readonly workspaceDir: string;
5
+ /** Original, undecoded hook payload: the hint source. */
6
+ readonly rawPayload: unknown;
7
+ readonly sessionId: string;
8
+ /** Host cwd when the payload carries one; Stop does not. */
9
+ readonly cwd?: string;
10
+ /** Resolved BEFORE any I/O by the caller (both flags). */
11
+ readonly ingestionEnabled: boolean;
12
+ readonly now?: Date;
13
+ readonly port?: TranscriptPort;
14
+ readonly home?: string;
15
+ }
16
+ export type WorkbuddyIngestionOutcome = {
17
+ status: 'ingested';
18
+ inserted: number;
19
+ warnings: readonly string[];
20
+ } | {
21
+ status: 'skipped';
22
+ reason: string;
23
+ nextAction: string;
24
+ } | {
25
+ status: 'degraded';
26
+ reason: string;
27
+ nextAction: string;
28
+ warnings: readonly string[];
29
+ };
30
+ /**
31
+ * Bridge the WorkBuddy snake_case hook payload to the host-neutral
32
+ * `HookHints` contract. Both Stop variants are mapped because the capability
33
+ * matrix names `agent_transcript_path` while the official hooks reference
34
+ * names `transcript_path`; the source adapter already prefers whichever is
35
+ * non-empty. Null / empty hints are dropped (InstructionsLoaded carries "").
36
+ */
37
+ export declare function workbuddyIngestionHints(rawPayload: unknown): HookHints;
38
+ /**
39
+ * Run the gated WorkBuddy ingestion pipeline for one hook invocation.
40
+ *
41
+ * Order is the privacy invariant: resolved flag → real consent ledger →
42
+ * transcript read. A flag-off or non-granted state returns before the port is
43
+ * ever touched, and a Stop re-entry is skipped to avoid a recursive read loop.
44
+ * Unexpected failures degrade with a bounded reason instead of throwing.
45
+ */
46
+ export declare function ingestWorkbuddyConversation(options: WorkbuddyIngestionOptions): WorkbuddyIngestionOutcome;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * WorkBuddy conversation-ingestion orchestrator (PRI-1171 P2, ticket ⑤).
3
+ *
4
+ * Connects the EXISTING pieces — the unified host-runtime pipeline, the
5
+ * WorkBuddy TranscriptSourceAdapter from ticket ④, the v3 consent ledger and
6
+ * the workspace feature flags — without introducing a new subsystem. The hook
7
+ * calls `ingestWorkbuddyConversation` on `turn_complete`; the worker calls the
8
+ * catch-up sibling. Both go through this same gate ordering.
9
+ *
10
+ * Gate order is a hard privacy invariant (SPEC §8.2 / §10):
11
+ * 1. resolved flags (host.workbuddy AND workbuddy_conversation_ingestion);
12
+ * 2. the REAL v3 consent record for hostKind='workbuddy';
13
+ * 3. only then any transcript filesystem read (pipeline's port).
14
+ * Steps 1 and 2 perform ZERO transcript port calls. Unlike the Codex path
15
+ * (which still hard-codes `consent: 'granted'` from its setup-flow invariant),
16
+ * this host reads the ledger at runtime, so revoking consent takes effect
17
+ * immediately.
18
+ */
19
+ import os from 'node:os';
20
+ import { readConversationIngestionConsent, runConversationIngestion, } from '@principles/host-runtime';
21
+ import { createWorkbuddyTranscriptSource } from './transcript-source.js';
22
+ /** Runtime-contract guard (rc-1): a non-null, non-array object is the only trusted payload shape. */
23
+ function isRecord(value) {
24
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
25
+ }
26
+ /** Read an OWN property only (rc-5): inherited names must never look like payload fields. */
27
+ function own(value, key) {
28
+ return Object.hasOwn(value, key) ? Object.getOwnPropertyDescriptor(value, key)?.value : undefined;
29
+ }
30
+ /** Accept a non-blank string only; empty/whitespace values are treated as absent. */
31
+ function nonEmptyString(value) {
32
+ return typeof value === 'string' && value.trim().length > 0 ? value : null;
33
+ }
34
+ /**
35
+ * Bridge the WorkBuddy snake_case hook payload to the host-neutral
36
+ * `HookHints` contract. Both Stop variants are mapped because the capability
37
+ * matrix names `agent_transcript_path` while the official hooks reference
38
+ * names `transcript_path`; the source adapter already prefers whichever is
39
+ * non-empty. Null / empty hints are dropped (InstructionsLoaded carries "").
40
+ */
41
+ export function workbuddyIngestionHints(rawPayload) {
42
+ if (!isRecord(rawPayload))
43
+ return {};
44
+ const transcriptPath = nonEmptyString(own(rawPayload, 'transcript_path'));
45
+ const agentTranscriptPath = nonEmptyString(own(rawPayload, 'agent_transcript_path'));
46
+ const generationId = nonEmptyString(own(rawPayload, 'generation_id'));
47
+ return {
48
+ ...(transcriptPath !== null ? { transcriptPath } : {}),
49
+ ...(agentTranscriptPath !== null ? { agentTranscriptPath } : {}),
50
+ ...(generationId !== null ? { generationId } : {}),
51
+ };
52
+ }
53
+ /**
54
+ * Run the gated WorkBuddy ingestion pipeline for one hook invocation.
55
+ *
56
+ * Order is the privacy invariant: resolved flag → real consent ledger →
57
+ * transcript read. A flag-off or non-granted state returns before the port is
58
+ * ever touched, and a Stop re-entry is skipped to avoid a recursive read loop.
59
+ * Unexpected failures degrade with a bounded reason instead of throwing.
60
+ */
61
+ export function ingestWorkbuddyConversation(options) {
62
+ // 1. Flag gate FIRST — before the consent read and before any port call.
63
+ // A flag-off host behaves exactly as before this capability existed.
64
+ if (!options.ingestionEnabled) {
65
+ return {
66
+ status: 'skipped',
67
+ reason: 'ingestion_disabled',
68
+ nextAction: 'Enable workbuddy_conversation_ingestion (and host.workbuddy) in the governance workspace .pd/config.yaml, then record consent with `pd workbuddy setup --accept`.',
69
+ };
70
+ }
71
+ // 2. Real v3 consent ledger — never a hard-coded grant.
72
+ const consent = readConversationIngestionConsent(options.workspaceDir, 'workbuddy');
73
+ if (!consent.ok) {
74
+ return {
75
+ status: 'degraded',
76
+ reason: `consent_unreadable:${consent.reason}`,
77
+ nextAction: consent.nextAction,
78
+ warnings: [],
79
+ };
80
+ }
81
+ const decision = consent.record?.decision ?? 'not_present';
82
+ if (decision !== 'granted') {
83
+ return {
84
+ status: 'skipped',
85
+ reason: `consent_not_granted:${decision}`,
86
+ nextAction: 'Record a granted WorkBuddy ingestion decision with `pd workbuddy setup --accept` before any transcript is read.',
87
+ };
88
+ }
89
+ // 3. Never ingest from a recursively-triggered Stop hook.
90
+ if (isRecord(options.rawPayload) && own(options.rawPayload, 'stop_hook_active') === true) {
91
+ return {
92
+ status: 'skipped',
93
+ reason: 'stop_hook_recursion',
94
+ nextAction: 'The host re-entered the Stop hook; ingestion is skipped to avoid a recursive read loop.',
95
+ };
96
+ }
97
+ const now = options.now ?? new Date();
98
+ const session = {
99
+ sessionId: options.sessionId,
100
+ ...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
101
+ };
102
+ try {
103
+ const outcome = runConversationIngestion({
104
+ workspaceDir: options.workspaceDir,
105
+ source: createWorkbuddyTranscriptSource({ now }),
106
+ session,
107
+ hints: workbuddyIngestionHints(options.rawPayload),
108
+ env: { home: options.home ?? os.homedir() },
109
+ // The pipeline re-checks both gates; passing the real decision keeps a
110
+ // single source of truth and makes the port-spy invariant observable.
111
+ flags: { ingestionEnabled: true },
112
+ consent: { decision },
113
+ now,
114
+ ...(options.port !== undefined ? { port: options.port } : {}),
115
+ });
116
+ if (outcome.status === 'degraded') {
117
+ return {
118
+ status: 'degraded',
119
+ reason: outcome.reason,
120
+ nextAction: outcome.nextAction,
121
+ warnings: outcome.warnings,
122
+ };
123
+ }
124
+ return { status: 'ingested', inserted: outcome.inserted, warnings: outcome.warnings };
125
+ }
126
+ catch (error) {
127
+ const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
128
+ return {
129
+ status: 'degraded',
130
+ reason: `workbuddy_ingestion_unexpected:${detail}`,
131
+ nextAction: 'Inspect the WorkBuddy transcript and the governance workspace state; the checkpoint was not advanced past failed work.',
132
+ warnings: [],
133
+ };
134
+ }
135
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * WorkBuddy session-transcript incremental decoder (PRI-1171 P2; SPEC v0.2
3
+ * §4.4, tech design §5.2–§5.4).
4
+ *
5
+ * WorkBuddy appends flat JSONL records (one record per line, no envelope
6
+ * wrapper) under `~/.workbuddy/projects/<encoded-cwd>/<sessionId>.jsonl`.
7
+ * The record-type baseline is frozen from the cross-period forensics in
8
+ * docs/plans/2026-08-28-workbuddy-session-transcript-access.md §8.1
9
+ * (message ×5 variants, function_call ×3, reasoning ×2,
10
+ * function_call_result / file-history-snapshot / ai-title / resend-fork-notice
11
+ * ×1) plus the `session-meta` head record observed on 2026-11-11 (absent
12
+ * from the Aug-28 census — tolerated as a known skip, see the mapping in
13
+ * projectRecord).
14
+ *
15
+ * Failure classes inherit the seam taxonomy (host-runtime
16
+ * conversation-ingestion/source.ts): an incomplete final line at EOF is a
17
+ * transient append boundary (checkpoint holds); a newline-terminated line
18
+ * that does not parse is a stable malformed record (stop, never advance
19
+ * past it); unknown-but-well-formed types are skipped with an aggregated,
20
+ * bounded warning and DO advance (rc-9: no silent skips).
21
+ *
22
+ * Privacy/semantics guardrails from the tech design:
23
+ * - `compactionTimestamp` is ALWAYS null — WorkBuddy compaction only
24
+ * APPENDS a summary record (forensics §8.2); history stays valid on
25
+ * disk, and the store treats that parameter as an active tombstone
26
+ * (tech design §5.4), so passing it would destroy live evidence.
27
+ * Markers surface as the aggregated `wb_compaction_marker` warning.
28
+ * - reasoning attribution never guesses: the parentId chain resolves
29
+ * within the decoded window or the observation lands
30
+ * partial + phase `unattributed` (tech design §4.8).
31
+ * - Ordinals are synthesized (the host file carries none): the caller
32
+ * seeds `startOrdinal` from the committed checkpoint so replays are
33
+ * stable; the durable replay identity is byte-based
34
+ * (`wb|<sessionId>|<byteOffset>`, tech design §5.3).
35
+ * - Host context is NOT Owner conversation: a user record wraps the real
36
+ * utterance in `<system-reminder>...</system-reminder>` blocks followed by
37
+ * `<user_query>...</user_query>` (forensic samples, 2026-11-11). Only the
38
+ * Owner utterance may become `visibleText`. Projecting the whole blob
39
+ * would persist host prompts as Owner behavior evidence, and the store's
40
+ * 200-char head-only bound would truncate the actual utterance away.
41
+ */
42
+ import { type GovernanceObservationInput, type TranscriptDecodeStop } from '@principles/host-runtime';
43
+ export interface DecodedWorkbuddyDelta {
44
+ readonly observations: readonly GovernanceObservationInput[];
45
+ readonly stop: TranscriptDecodeStop;
46
+ readonly nextByteOffset: number;
47
+ readonly lastOrdinal: number;
48
+ readonly warnings: readonly string[];
49
+ }
50
+ export interface DecodeWorkbuddyWindowInput {
51
+ readonly bytes: Buffer;
52
+ readonly fileOffset: number;
53
+ /** True when bytes.length did not reach EOF — the window was cut by the bounded read. */
54
+ readonly byteBoundReached: boolean;
55
+ /** Durable session identity from the locator (file uuid) — keys are ALWAYS built from this, never from record.sessionId. */
56
+ readonly sessionIdentity: string;
57
+ /** Synthesized-ordinal seed: committed checkpoint's lastOrdinal + 1 (0 when no checkpoint). */
58
+ readonly startOrdinal: number;
59
+ readonly nowIso: string;
60
+ }
61
+ /**
62
+ * Decode one byte window of a WorkBuddy transcript into governance
63
+ * observations plus a byte-exact resume cursor.
64
+ *
65
+ * Newline-terminated lines advance the ordinal/offset; an incomplete EOF tail
66
+ * holds the checkpoint (transient append boundary); a malformed terminated
67
+ * line stops BEFORE itself; unknown types advance with a warning. The batch
68
+ * cap applies to both terminated lines and the EOF tail.
69
+ */
70
+ export declare function decodeWorkbuddyTranscriptWindow(input: DecodeWorkbuddyWindowInput): DecodedWorkbuddyDelta;