@haaaiawd/second-nature 0.1.50 → 0.1.51

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 (947) hide show
  1. package/SKILL.md +22 -320
  2. package/{docs/claw-second-nature-inner-guide.md → agent-inner-guide.md} +43 -0
  3. package/openclaw.plugin.json +29 -0
  4. package/package.json +32 -61
  5. package/{dist/src → runtime}/cli/commands/index.js +325 -325
  6. package/{dist/src → runtime}/cli/ops/heartbeat-surface.d.ts +84 -84
  7. package/{dist/src → runtime}/cli/ops/heartbeat-surface.js +100 -100
  8. package/{dist/src → runtime}/cli/ops/ops-router.js +1482 -1482
  9. package/{dist/src → runtime}/cli/ops/workspace-heartbeat-runner.d.ts +85 -85
  10. package/{dist/src → runtime}/cli/ops/workspace-heartbeat-runner.js +242 -242
  11. package/{dist/src → runtime}/connectors/base/contract.d.ts +111 -111
  12. package/{dist/src → runtime}/connectors/base/failure-taxonomy.d.ts +13 -13
  13. package/{dist/src → runtime}/connectors/base/failure-taxonomy.js +186 -186
  14. package/{dist/src → runtime}/connectors/base/map-life-evidence.js +137 -137
  15. package/{dist/src → runtime}/connectors/base/policy-layer.js +202 -202
  16. package/{dist/src → runtime}/connectors/manifest/manifest-schema.d.ts +152 -152
  17. package/{dist/src → runtime}/connectors/manifest/manifest-schema.js +54 -54
  18. package/{dist/src → runtime}/connectors/services/connector-executor-adapter.d.ts +20 -20
  19. package/{dist/src → runtime}/connectors/services/connector-executor-adapter.js +645 -645
  20. package/{dist/src → runtime}/core/second-nature/heartbeat/goal-lifecycle-policy.d.ts +24 -24
  21. package/{dist/src → runtime}/core/second-nature/heartbeat/goal-lifecycle-policy.js +61 -61
  22. package/{dist/src → runtime}/core/second-nature/heartbeat/heartbeat-loop.d.ts +97 -97
  23. package/{dist/src → runtime}/core/second-nature/heartbeat/heartbeat-loop.js +397 -397
  24. package/{dist/src → runtime}/core/second-nature/orchestrator/platform-capability-router.js +149 -149
  25. package/HEARTBEAT.md +0 -44
  26. package/LICENSE +0 -176
  27. package/README.md +0 -136
  28. package/README.zh-CN.md +0 -120
  29. package/dist/data/observability.db +0 -0
  30. package/dist/data/state.db +0 -0
  31. package/dist/plugin/index.d.ts +0 -31
  32. package/dist/plugin/workspace-ops-bridge.d.ts +0 -15
  33. package/dist/scripts/build-plugin-package.d.ts +0 -12
  34. package/dist/scripts/build-plugin-package.js +0 -220
  35. package/dist/scripts/build-plugin-runtime.d.ts +0 -10
  36. package/dist/scripts/build-plugin-runtime.js +0 -198
  37. package/dist/scripts/packaging-feasibility-poc.d.ts +0 -1
  38. package/dist/scripts/packaging-feasibility-poc.js +0 -127
  39. package/dist/scripts/plugin-smoke-check.d.ts +0 -1
  40. package/dist/scripts/plugin-smoke-check.js +0 -124
  41. package/dist/src/cli/action-bridge.d.ts +0 -11
  42. package/dist/src/cli/index.d.ts +0 -65
  43. package/dist/tests/integration/cli/cli-ops-surface.test.d.ts +0 -1
  44. package/dist/tests/integration/cli/cli-ops-surface.test.js +0 -380
  45. package/dist/tests/integration/cli/heartbeat-surface-workspace.test.d.ts +0 -1
  46. package/dist/tests/integration/cli/heartbeat-surface-workspace.test.js +0 -61
  47. package/dist/tests/integration/cli/host-capability-probe.test.d.ts +0 -1
  48. package/dist/tests/integration/cli/host-capability-probe.test.js +0 -37
  49. package/dist/tests/integration/cli/host-smoke-heartbeat-tool.test.d.ts +0 -1
  50. package/dist/tests/integration/cli/host-smoke-heartbeat-tool.test.js +0 -34
  51. package/dist/tests/integration/cli/plugin-packaging-walkthrough.test.d.ts +0 -1
  52. package/dist/tests/integration/cli/plugin-packaging-walkthrough.test.js +0 -79
  53. package/dist/tests/integration/cli/plugin-runtime-registration.test.d.ts +0 -1
  54. package/dist/tests/integration/cli/plugin-runtime-registration.test.js +0 -285
  55. package/dist/tests/integration/cli/plugin-workspace-ops-bridge.test.d.ts +0 -1
  56. package/dist/tests/integration/cli/plugin-workspace-ops-bridge.test.js +0 -487
  57. package/dist/tests/integration/cli/t1-2-1-explain-read-models.test.d.ts +0 -1
  58. package/dist/tests/integration/cli/t1-2-1-explain-read-models.test.js +0 -58
  59. package/dist/tests/integration/cli/t1-2-1-narrative-command.test.d.ts +0 -1
  60. package/dist/tests/integration/cli/t1-2-1-narrative-command.test.js +0 -194
  61. package/dist/tests/integration/cli/t1-2-2-dream-recent.test.d.ts +0 -1
  62. package/dist/tests/integration/cli/t1-2-2-dream-recent.test.js +0 -100
  63. package/dist/tests/integration/cli/t1-2-3-status-observability-writeback.test.d.ts +0 -1
  64. package/dist/tests/integration/cli/t1-2-3-status-observability-writeback.test.js +0 -71
  65. package/dist/tests/integration/cli/t1-2-4-quiet-report-read-canonical.test.d.ts +0 -1
  66. package/dist/tests/integration/cli/t1-2-4-quiet-report-read-canonical.test.js +0 -206
  67. package/dist/tests/integration/cli/t1-2-5-cycle-recent.test.d.ts +0 -1
  68. package/dist/tests/integration/cli/t1-2-5-cycle-recent.test.js +0 -156
  69. package/dist/tests/integration/cli/t1-2-5-status-delivery-posture-audit-store.test.d.ts +0 -1
  70. package/dist/tests/integration/cli/t1-2-5-status-delivery-posture-audit-store.test.js +0 -95
  71. package/dist/tests/integration/cli/t1-2-6-policy-show-non-shell.test.d.ts +0 -1
  72. package/dist/tests/integration/cli/t1-2-6-policy-show-non-shell.test.js +0 -74
  73. package/dist/tests/integration/cli/t1-2-6-status-aggregate.test.d.ts +0 -1
  74. package/dist/tests/integration/cli/t1-2-6-status-aggregate.test.js +0 -223
  75. package/dist/tests/integration/cli/t1-2-7-audit-command-minimal-closure.test.d.ts +0 -1
  76. package/dist/tests/integration/cli/t1-2-7-audit-command-minimal-closure.test.js +0 -101
  77. package/dist/tests/integration/cli/t1-2-8-capability-probe-ops-surface.test.d.ts +0 -1
  78. package/dist/tests/integration/cli/t1-2-8-capability-probe-ops-surface.test.js +0 -74
  79. package/dist/tests/integration/cli/t1-2-9-decision-denied-not-degraded.test.d.ts +0 -1
  80. package/dist/tests/integration/cli/t1-2-9-decision-denied-not-degraded.test.js +0 -79
  81. package/dist/tests/integration/cli/t1-4-1-runtime-secret-bootstrap.test.d.ts +0 -1
  82. package/dist/tests/integration/cli/t1-4-1-runtime-secret-bootstrap.test.js +0 -139
  83. package/dist/tests/integration/cli/t1-4-2-activation-ux-contract.test.d.ts +0 -1
  84. package/dist/tests/integration/cli/t1-4-2-activation-ux-contract.test.js +0 -143
  85. package/dist/tests/integration/cli/t2-2-2-snapshot-life-evidence.test.d.ts +0 -1
  86. package/dist/tests/integration/cli/t2-2-2-snapshot-life-evidence.test.js +0 -116
  87. package/dist/tests/integration/cli/t3-3-2-near-real-smoke-cli-bridge.test.d.ts +0 -1
  88. package/dist/tests/integration/cli/t3-3-2-near-real-smoke-cli-bridge.test.js +0 -69
  89. package/dist/tests/integration/connectors/connector-base.test.d.ts +0 -1
  90. package/dist/tests/integration/connectors/connector-base.test.js +0 -211
  91. package/dist/tests/integration/connectors/connector-executor-adapter-honest-failure.test.d.ts +0 -1
  92. package/dist/tests/integration/connectors/connector-executor-adapter-honest-failure.test.js +0 -311
  93. package/dist/tests/integration/connectors/credential-optional-regression.test.d.ts +0 -1
  94. package/dist/tests/integration/connectors/credential-optional-regression.test.js +0 -117
  95. package/dist/tests/integration/connectors/declarative-http-runner.test.d.ts +0 -7
  96. package/dist/tests/integration/connectors/declarative-http-runner.test.js +0 -229
  97. package/dist/tests/integration/connectors/evomap-secret-port.test.d.ts +0 -1
  98. package/dist/tests/integration/connectors/evomap-secret-port.test.js +0 -83
  99. package/dist/tests/integration/connectors/life-evidence-chain.test.d.ts +0 -1
  100. package/dist/tests/integration/connectors/life-evidence-chain.test.js +0 -188
  101. package/dist/tests/integration/connectors/moltbook-client.test.d.ts +0 -1
  102. package/dist/tests/integration/connectors/moltbook-client.test.js +0 -274
  103. package/dist/tests/integration/connectors/moltbook-mock-runner.test.d.ts +0 -7
  104. package/dist/tests/integration/connectors/moltbook-mock-runner.test.js +0 -108
  105. package/dist/tests/integration/connectors/near-real-connector-smoke.test.d.ts +0 -1
  106. package/dist/tests/integration/connectors/near-real-connector-smoke.test.js +0 -38
  107. package/dist/tests/integration/connectors/platform-adapters.test.d.ts +0 -1
  108. package/dist/tests/integration/connectors/platform-adapters.test.js +0 -189
  109. package/dist/tests/integration/connectors/policy-layer.test.d.ts +0 -1
  110. package/dist/tests/integration/connectors/policy-layer.test.js +0 -249
  111. package/dist/tests/integration/connectors/scriptable-node-e2e.test.d.ts +0 -1
  112. package/dist/tests/integration/connectors/scriptable-node-e2e.test.js +0 -228
  113. package/dist/tests/integration/connectors/t3-3-1-real-connector-evidence.test.d.ts +0 -1
  114. package/dist/tests/integration/connectors/t3-3-1-real-connector-evidence.test.js +0 -171
  115. package/dist/tests/integration/control-plane/_helpers/decision-cycle-harness.d.ts +0 -40
  116. package/dist/tests/integration/control-plane/_helpers/decision-cycle-harness.js +0 -116
  117. package/dist/tests/integration/control-plane/decision-loop-validation.test.d.ts +0 -1
  118. package/dist/tests/integration/control-plane/decision-loop-validation.test.js +0 -319
  119. package/dist/tests/integration/control-plane/delivery-failed-fallback.test.d.ts +0 -1
  120. package/dist/tests/integration/control-plane/delivery-failed-fallback.test.js +0 -118
  121. package/dist/tests/integration/control-plane/dream-projection-heartbeat.test.d.ts +0 -1
  122. package/dist/tests/integration/control-plane/dream-projection-heartbeat.test.js +0 -109
  123. package/dist/tests/integration/control-plane/effect-dispatcher.test.d.ts +0 -1
  124. package/dist/tests/integration/control-plane/effect-dispatcher.test.js +0 -157
  125. package/dist/tests/integration/control-plane/guidance-request.test.d.ts +0 -1
  126. package/dist/tests/integration/control-plane/guidance-request.test.js +0 -63
  127. package/dist/tests/integration/control-plane/heartbeat-executor.test.d.ts +0 -1
  128. package/dist/tests/integration/control-plane/heartbeat-executor.test.js +0 -363
  129. package/dist/tests/integration/control-plane/heartbeat-loop.test.d.ts +0 -1
  130. package/dist/tests/integration/control-plane/heartbeat-loop.test.js +0 -190
  131. package/dist/tests/integration/control-plane/heartbeat-quiet-orchestration.test.d.ts +0 -1
  132. package/dist/tests/integration/control-plane/heartbeat-quiet-orchestration.test.js +0 -133
  133. package/dist/tests/integration/control-plane/heartbeat-spine-integration.test.d.ts +0 -1
  134. package/dist/tests/integration/control-plane/heartbeat-spine-integration.test.js +0 -342
  135. package/dist/tests/integration/control-plane/heartbeat-spine.test.d.ts +0 -1
  136. package/dist/tests/integration/control-plane/heartbeat-spine.test.js +0 -216
  137. package/dist/tests/integration/control-plane/int-s3-outreach-delivery-quiet-closure.test.d.ts +0 -1
  138. package/dist/tests/integration/control-plane/int-s3-outreach-delivery-quiet-closure.test.js +0 -241
  139. package/dist/tests/integration/control-plane/outreach-resume.test.d.ts +0 -1
  140. package/dist/tests/integration/control-plane/outreach-resume.test.js +0 -158
  141. package/dist/tests/integration/control-plane/outreach-style.test.d.ts +0 -1
  142. package/dist/tests/integration/control-plane/outreach-style.test.js +0 -46
  143. package/dist/tests/integration/control-plane/quiet-reflection.test.d.ts +0 -1
  144. package/dist/tests/integration/control-plane/quiet-reflection.test.js +0 -73
  145. package/dist/tests/integration/control-plane/rhythm-intent-guard.test.d.ts +0 -1
  146. package/dist/tests/integration/control-plane/rhythm-intent-guard.test.js +0 -99
  147. package/dist/tests/integration/control-plane/run-heartbeat-cycle.test.d.ts +0 -1
  148. package/dist/tests/integration/control-plane/run-heartbeat-cycle.test.js +0 -80
  149. package/dist/tests/integration/control-plane/t2-3-1-outreach-v6.test.d.ts +0 -1
  150. package/dist/tests/integration/control-plane/t2-3-1-outreach-v6.test.js +0 -208
  151. package/dist/tests/integration/control-plane/t2-4-1-heartbeat-platform-intent.test.d.ts +0 -1
  152. package/dist/tests/integration/control-plane/t2-4-1-heartbeat-platform-intent.test.js +0 -156
  153. package/dist/tests/integration/control-plane/t2-4-2-source-backed-outreach-loop.test.d.ts +0 -1
  154. package/dist/tests/integration/control-plane/t2-4-2-source-backed-outreach-loop.test.js +0 -188
  155. package/dist/tests/integration/control-plane/v7c-evidence-body-feedback.test.d.ts +0 -11
  156. package/dist/tests/integration/control-plane/v7c-evidence-body-feedback.test.js +0 -213
  157. package/dist/tests/integration/control-plane/v7c-heartbeat-unlock-e2e.test.d.ts +0 -9
  158. package/dist/tests/integration/control-plane/v7c-heartbeat-unlock-e2e.test.js +0 -134
  159. package/dist/tests/integration/dream/quiet-dream-trigger.test.d.ts +0 -1
  160. package/dist/tests/integration/dream/quiet-dream-trigger.test.js +0 -86
  161. package/dist/tests/integration/dream/t7-1-1-dream-pipeline.test.d.ts +0 -1
  162. package/dist/tests/integration/dream/t7-1-1-dream-pipeline.test.js +0 -378
  163. package/dist/tests/integration/dream/t7-1-2-dream-scheduler.test.d.ts +0 -1
  164. package/dist/tests/integration/dream/t7-1-2-dream-scheduler.test.js +0 -124
  165. package/dist/tests/integration/dream/v7c-rhythm-loop.test.d.ts +0 -10
  166. package/dist/tests/integration/dream/v7c-rhythm-loop.test.js +0 -185
  167. package/dist/tests/integration/guidance/assembler-and-fallback.test.d.ts +0 -1
  168. package/dist/tests/integration/guidance/assembler-and-fallback.test.js +0 -86
  169. package/dist/tests/integration/guidance/outreach-draft-contract.test.d.ts +0 -1
  170. package/dist/tests/integration/guidance/outreach-draft-contract.test.js +0 -106
  171. package/dist/tests/integration/guidance/persona-selection.test.d.ts +0 -1
  172. package/dist/tests/integration/guidance/persona-selection.test.js +0 -70
  173. package/dist/tests/integration/guidance/template-review.test.d.ts +0 -1
  174. package/dist/tests/integration/guidance/template-review.test.js +0 -26
  175. package/dist/tests/integration/guidance/user-reply-continuity.test.d.ts +0 -1
  176. package/dist/tests/integration/guidance/user-reply-continuity.test.js +0 -96
  177. package/dist/tests/integration/guidance/v7c-guidance-chain.test.d.ts +0 -1
  178. package/dist/tests/integration/guidance/v7c-guidance-chain.test.js +0 -190
  179. package/dist/tests/integration/guidance/v7c-guidance-semantics.test.d.ts +0 -1
  180. package/dist/tests/integration/guidance/v7c-guidance-semantics.test.js +0 -146
  181. package/dist/tests/integration/observability/digest-delivery.test.d.ts +0 -14
  182. package/dist/tests/integration/observability/digest-delivery.test.js +0 -160
  183. package/dist/tests/integration/observability/evidence-query-engine.test.d.ts +0 -1
  184. package/dist/tests/integration/observability/evidence-query-engine.test.js +0 -219
  185. package/dist/tests/integration/observability/explain-query-export.test.d.ts +0 -1
  186. package/dist/tests/integration/observability/explain-query-export.test.js +0 -92
  187. package/dist/tests/integration/observability/guidance-audit.test.d.ts +0 -1
  188. package/dist/tests/integration/observability/guidance-audit.test.js +0 -55
  189. package/dist/tests/integration/observability/heartbeat-decision-record.test.d.ts +0 -1
  190. package/dist/tests/integration/observability/heartbeat-decision-record.test.js +0 -223
  191. package/dist/tests/integration/observability/heartbeat-narrative-trace.test.d.ts +0 -1
  192. package/dist/tests/integration/observability/heartbeat-narrative-trace.test.js +0 -230
  193. package/dist/tests/integration/observability/lived-experience-audit-chain.test.d.ts +0 -1
  194. package/dist/tests/integration/observability/lived-experience-audit-chain.test.js +0 -43
  195. package/dist/tests/integration/observability/observability-gates.test.d.ts +0 -1
  196. package/dist/tests/integration/observability/observability-gates.test.js +0 -224
  197. package/dist/tests/integration/observability/observability-retention-cleanup.test.d.ts +0 -1
  198. package/dist/tests/integration/observability/observability-retention-cleanup.test.js +0 -94
  199. package/dist/tests/integration/observability/observability-services.test.d.ts +0 -1
  200. package/dist/tests/integration/observability/observability-services.test.js +0 -219
  201. package/dist/tests/integration/observability/projections.test.d.ts +0 -1
  202. package/dist/tests/integration/observability/projections.test.js +0 -36
  203. package/dist/tests/integration/observability/t5-1-1-dream-trace-audit.test.d.ts +0 -1
  204. package/dist/tests/integration/observability/t5-1-1-dream-trace-audit.test.js +0 -115
  205. package/dist/tests/integration/plugin/plugin-registration.test.d.ts +0 -16
  206. package/dist/tests/integration/plugin/plugin-registration.test.js +0 -151
  207. package/dist/tests/integration/runtime-ops/commands.test.d.ts +0 -16
  208. package/dist/tests/integration/runtime-ops/commands.test.js +0 -662
  209. package/dist/tests/integration/s3-exit/int-s3-body-heartbeat.test.d.ts +0 -15
  210. package/dist/tests/integration/s3-exit/int-s3-body-heartbeat.test.js +0 -462
  211. package/dist/tests/integration/s5-exit/int-s5-observability.test.d.ts +0 -17
  212. package/dist/tests/integration/s5-exit/int-s5-observability.test.js +0 -402
  213. package/dist/tests/integration/state/t4-2-1-owner-reply-relationship-loop.test.d.ts +0 -1
  214. package/dist/tests/integration/state/t4-2-1-owner-reply-relationship-loop.test.js +0 -132
  215. package/dist/tests/integration/state/v7c-identity-goal-hygiene.test.d.ts +0 -9
  216. package/dist/tests/integration/state/v7c-identity-goal-hygiene.test.js +0 -240
  217. package/dist/tests/integration/storage/packaged-runtime-smoke.test.d.ts +0 -1
  218. package/dist/tests/integration/storage/packaged-runtime-smoke.test.js +0 -17
  219. package/dist/tests/integration/storage/persona-candidate-loader.test.d.ts +0 -1
  220. package/dist/tests/integration/storage/persona-candidate-loader.test.js +0 -23
  221. package/dist/tests/integration/storage/quiet-artifact-writer.test.d.ts +0 -1
  222. package/dist/tests/integration/storage/quiet-artifact-writer.test.js +0 -66
  223. package/dist/tests/integration/storage/repair-and-backup.test.d.ts +0 -1
  224. package/dist/tests/integration/storage/repair-and-backup.test.js +0 -125
  225. package/dist/tests/integration/storage/schema-migration.test.d.ts +0 -11
  226. package/dist/tests/integration/storage/schema-migration.test.js +0 -183
  227. package/dist/tests/integration/storage/storage-mode-smoke.test.d.ts +0 -1
  228. package/dist/tests/integration/storage/storage-mode-smoke.test.js +0 -18
  229. package/dist/tests/integration/storage/t4-1-5-memory-store-lifecycle.test.d.ts +0 -1
  230. package/dist/tests/integration/storage/t4-1-5-memory-store-lifecycle.test.js +0 -118
  231. package/dist/tests/unit/body/affordance-assembler.test.d.ts +0 -14
  232. package/dist/tests/unit/body/affordance-assembler.test.js +0 -259
  233. package/dist/tests/unit/body/affordance-context-scope.test.d.ts +0 -12
  234. package/dist/tests/unit/body/affordance-context-scope.test.js +0 -73
  235. package/dist/tests/unit/body/behavior-promotion-loop.test.d.ts +0 -15
  236. package/dist/tests/unit/body/behavior-promotion-loop.test.js +0 -130
  237. package/dist/tests/unit/body/circuit-breaker-manager.test.d.ts +0 -13
  238. package/dist/tests/unit/body/circuit-breaker-manager.test.js +0 -160
  239. package/dist/tests/unit/body/experience-writer.test.d.ts +0 -11
  240. package/dist/tests/unit/body/experience-writer.test.js +0 -77
  241. package/dist/tests/unit/body/pain-signal-query.test.d.ts +0 -11
  242. package/dist/tests/unit/body/pain-signal-query.test.js +0 -104
  243. package/dist/tests/unit/cli/connector-init-manifest.test.d.ts +0 -9
  244. package/dist/tests/unit/cli/connector-init-manifest.test.js +0 -68
  245. package/dist/tests/unit/cli/delivery-target-probe.test.d.ts +0 -1
  246. package/dist/tests/unit/cli/delivery-target-probe.test.js +0 -108
  247. package/dist/tests/unit/cli/host-capability.test.d.ts +0 -1
  248. package/dist/tests/unit/cli/host-capability.test.js +0 -50
  249. package/dist/tests/unit/cli/operator-fallback-view.test.d.ts +0 -1
  250. package/dist/tests/unit/cli/operator-fallback-view.test.js +0 -60
  251. package/dist/tests/unit/cli/runtime-artifact-boundary.test.d.ts +0 -1
  252. package/dist/tests/unit/cli/runtime-artifact-boundary.test.js +0 -57
  253. package/dist/tests/unit/cli/t1-2-3-connector-status.test.d.ts +0 -1
  254. package/dist/tests/unit/cli/t1-2-3-connector-status.test.js +0 -214
  255. package/dist/tests/unit/cli/t1-2-4-goal-command.test.d.ts +0 -1
  256. package/dist/tests/unit/cli/t1-2-4-goal-command.test.js +0 -207
  257. package/dist/tests/unit/cli/t1-3-1-connector-init.test.d.ts +0 -1
  258. package/dist/tests/unit/cli/t1-3-1-connector-init.test.js +0 -212
  259. package/dist/tests/unit/connectors/connector-manifest-and-evidence-map.test.d.ts +0 -1
  260. package/dist/tests/unit/connectors/connector-manifest-and-evidence-map.test.js +0 -71
  261. package/dist/tests/unit/connectors/effect-commit-ledger-sqlite.test.d.ts +0 -10
  262. package/dist/tests/unit/connectors/effect-commit-ledger-sqlite.test.js +0 -101
  263. package/dist/tests/unit/connectors/evomap-runner.test.d.ts +0 -1
  264. package/dist/tests/unit/connectors/evomap-runner.test.js +0 -136
  265. package/dist/tests/unit/connectors/execution-policy.test.d.ts +0 -1
  266. package/dist/tests/unit/connectors/execution-policy.test.js +0 -71
  267. package/dist/tests/unit/connectors/instreet-registration.test.d.ts +0 -1
  268. package/dist/tests/unit/connectors/instreet-registration.test.js +0 -102
  269. package/dist/tests/unit/connectors/manifest-v7-schema.test.d.ts +0 -9
  270. package/dist/tests/unit/connectors/manifest-v7-schema.test.js +0 -165
  271. package/dist/tests/unit/connectors/scriptable-node-runner.test.d.ts +0 -1
  272. package/dist/tests/unit/connectors/scriptable-node-runner.test.js +0 -246
  273. package/dist/tests/unit/connectors/structured-unavailable-reason.test.d.ts +0 -11
  274. package/dist/tests/unit/connectors/structured-unavailable-reason.test.js +0 -76
  275. package/dist/tests/unit/connectors/t3-1-1-dynamic-registry.test.d.ts +0 -1
  276. package/dist/tests/unit/connectors/t3-1-1-dynamic-registry.test.js +0 -178
  277. package/dist/tests/unit/connectors/t3-1-2-capability-registry.test.d.ts +0 -1
  278. package/dist/tests/unit/connectors/t3-1-2-capability-registry.test.js +0 -105
  279. package/dist/tests/unit/connectors/t3-2-1-v5-parity.test.d.ts +0 -1
  280. package/dist/tests/unit/connectors/t3-2-1-v5-parity.test.js +0 -103
  281. package/dist/tests/unit/connectors/t3-3-1-evidence-mapper.test.d.ts +0 -1
  282. package/dist/tests/unit/connectors/t3-3-1-evidence-mapper.test.js +0 -198
  283. package/dist/tests/unit/connectors/t3-3-1-evidence-redaction.test.d.ts +0 -1
  284. package/dist/tests/unit/connectors/t3-3-1-evidence-redaction.test.js +0 -95
  285. package/dist/tests/unit/connectors/wet-probe-runner.test.d.ts +0 -11
  286. package/dist/tests/unit/connectors/wet-probe-runner.test.js +0 -84
  287. package/dist/tests/unit/control-plane/decision-trace-emitter.test.d.ts +0 -1
  288. package/dist/tests/unit/control-plane/decision-trace-emitter.test.js +0 -51
  289. package/dist/tests/unit/control-plane/downstream-intent-orchestrator.test.d.ts +0 -1
  290. package/dist/tests/unit/control-plane/downstream-intent-orchestrator.test.js +0 -57
  291. package/dist/tests/unit/control-plane/embodied-context-assembler.test.d.ts +0 -13
  292. package/dist/tests/unit/control-plane/embodied-context-assembler.test.js +0 -182
  293. package/dist/tests/unit/control-plane/goal-lifecycle-policy.test.d.ts +0 -1
  294. package/dist/tests/unit/control-plane/goal-lifecycle-policy.test.js +0 -75
  295. package/dist/tests/unit/control-plane/hard-guard-evaluator.test.d.ts +0 -1
  296. package/dist/tests/unit/control-plane/hard-guard-evaluator.test.js +0 -113
  297. package/dist/tests/unit/control-plane/idle-curiosity-policy.test.d.ts +0 -1
  298. package/dist/tests/unit/control-plane/idle-curiosity-policy.test.js +0 -69
  299. package/dist/tests/unit/control-plane/intent-planner-source-ref-fallback.test.d.ts +0 -7
  300. package/dist/tests/unit/control-plane/intent-planner-source-ref-fallback.test.js +0 -124
  301. package/dist/tests/unit/control-plane/rhythm-policy-snapshot-window.test.d.ts +0 -1
  302. package/dist/tests/unit/control-plane/rhythm-policy-snapshot-window.test.js +0 -64
  303. package/dist/tests/unit/control-plane/run-heartbeat-cycle-v7.test.d.ts +0 -1
  304. package/dist/tests/unit/control-plane/run-heartbeat-cycle-v7.test.js +0 -165
  305. package/dist/tests/unit/control-plane/t2-1-4-goal-priority.test.d.ts +0 -1
  306. package/dist/tests/unit/control-plane/t2-1-4-goal-priority.test.js +0 -185
  307. package/dist/tests/unit/control-plane/t2-1-5-narrative-update.test.d.ts +0 -1
  308. package/dist/tests/unit/control-plane/t2-1-5-narrative-update.test.js +0 -313
  309. package/dist/tests/unit/control-plane/t2-4-1-credential-route.test.d.ts +0 -1
  310. package/dist/tests/unit/control-plane/t2-4-1-credential-route.test.js +0 -75
  311. package/dist/tests/unit/control-plane/t2-4-1-platform-intent.test.d.ts +0 -1
  312. package/dist/tests/unit/control-plane/t2-4-1-platform-intent.test.js +0 -168
  313. package/dist/tests/unit/core/outreach-judgment.test.d.ts +0 -1
  314. package/dist/tests/unit/core/outreach-judgment.test.js +0 -109
  315. package/dist/tests/unit/core/resolve-allowed-intent.test.d.ts +0 -1
  316. package/dist/tests/unit/core/resolve-allowed-intent.test.js +0 -69
  317. package/dist/tests/unit/core/t2-2-3-connector-action-honest-result.test.d.ts +0 -1
  318. package/dist/tests/unit/core/t2-2-3-connector-action-honest-result.test.js +0 -130
  319. package/dist/tests/unit/core/t2-2-3-connector-dispatch-wired.test.d.ts +0 -1
  320. package/dist/tests/unit/core/t2-2-3-connector-dispatch-wired.test.js +0 -99
  321. package/dist/tests/unit/dream/dream-input-loader.test.d.ts +0 -15
  322. package/dist/tests/unit/dream/dream-input-loader.test.js +0 -424
  323. package/dist/tests/unit/dream/dream-scheduler.test.d.ts +0 -1
  324. package/dist/tests/unit/dream/dream-scheduler.test.js +0 -57
  325. package/dist/tests/unit/dream/t-dqs-c3-redacted-evidence.test.d.ts +0 -11
  326. package/dist/tests/unit/dream/t-dqs-c3-redacted-evidence.test.js +0 -298
  327. package/dist/tests/unit/dream/t7-1-3-insight-extraction.test.d.ts +0 -1
  328. package/dist/tests/unit/dream/t7-1-3-insight-extraction.test.js +0 -79
  329. package/dist/tests/unit/dream/t7-1-4-narrative-update.test.d.ts +0 -1
  330. package/dist/tests/unit/dream/t7-1-4-narrative-update.test.js +0 -93
  331. package/dist/tests/unit/dream/t7-1-5-relationship-update.test.d.ts +0 -1
  332. package/dist/tests/unit/dream/t7-1-5-relationship-update.test.js +0 -116
  333. package/dist/tests/unit/feedback/t4-2-1-owner-reply-inference.test.d.ts +0 -1
  334. package/dist/tests/unit/feedback/t4-2-1-owner-reply-inference.test.js +0 -58
  335. package/dist/tests/unit/guidance/capability-class.test.d.ts +0 -1
  336. package/dist/tests/unit/guidance/capability-class.test.js +0 -96
  337. package/dist/tests/unit/guidance/channel-feedback-ingestion.test.d.ts +0 -1
  338. package/dist/tests/unit/guidance/channel-feedback-ingestion.test.js +0 -163
  339. package/dist/tests/unit/guidance/evidence-guidance.test.d.ts +0 -1
  340. package/dist/tests/unit/guidance/evidence-guidance.test.js +0 -40
  341. package/dist/tests/unit/guidance/guidance-draft-service.test.d.ts +0 -1
  342. package/dist/tests/unit/guidance/guidance-draft-service.test.js +0 -140
  343. package/dist/tests/unit/guidance/impulse-assembler.test.d.ts +0 -1
  344. package/dist/tests/unit/guidance/impulse-assembler.test.js +0 -169
  345. package/dist/tests/unit/guidance/outreach-draft-schema.test.d.ts +0 -1
  346. package/dist/tests/unit/guidance/outreach-draft-schema.test.js +0 -56
  347. package/dist/tests/unit/guidance/outreach-strategy-selector.test.d.ts +0 -1
  348. package/dist/tests/unit/guidance/outreach-strategy-selector.test.js +0 -208
  349. package/dist/tests/unit/guidance/outreach-style-fixtures.test.d.ts +0 -1
  350. package/dist/tests/unit/guidance/outreach-style-fixtures.test.js +0 -81
  351. package/dist/tests/unit/guidance/t6-1-1-narrative-outreach.test.d.ts +0 -1
  352. package/dist/tests/unit/guidance/t6-1-1-narrative-outreach.test.js +0 -256
  353. package/dist/tests/unit/observability/audit-envelope.test.d.ts +0 -1
  354. package/dist/tests/unit/observability/audit-envelope.test.js +0 -169
  355. package/dist/tests/unit/observability/connector-inventory-ledger.test.d.ts +0 -1
  356. package/dist/tests/unit/observability/connector-inventory-ledger.test.js +0 -128
  357. package/dist/tests/unit/observability/family-registry.test.d.ts +0 -12
  358. package/dist/tests/unit/observability/family-registry.test.js +0 -105
  359. package/dist/tests/unit/observability/governance-plane-recorder.test.d.ts +0 -1
  360. package/dist/tests/unit/observability/governance-plane-recorder.test.js +0 -72
  361. package/dist/tests/unit/observability/heartbeat-digest-assembler.test.d.ts +0 -1
  362. package/dist/tests/unit/observability/heartbeat-digest-assembler.test.js +0 -227
  363. package/dist/tests/unit/observability/lived-experience-audit.test.d.ts +0 -1
  364. package/dist/tests/unit/observability/lived-experience-audit.test.js +0 -105
  365. package/dist/tests/unit/observability/narrative-timeline-query.test.d.ts +0 -18
  366. package/dist/tests/unit/observability/narrative-timeline-query.test.js +0 -239
  367. package/dist/tests/unit/observability/restore-audit-service.test.d.ts +0 -16
  368. package/dist/tests/unit/observability/restore-audit-service.test.js +0 -186
  369. package/dist/tests/unit/observability/runtime-decision-recorder.test.d.ts +0 -1
  370. package/dist/tests/unit/observability/runtime-decision-recorder.test.js +0 -66
  371. package/dist/tests/unit/observability/runtime-secret-anchor-view.test.d.ts +0 -18
  372. package/dist/tests/unit/observability/runtime-secret-anchor-view.test.js +0 -209
  373. package/dist/tests/unit/observability/self-health-snapshot.test.d.ts +0 -1
  374. package/dist/tests/unit/observability/self-health-snapshot.test.js +0 -223
  375. package/dist/tests/unit/observability/verify-audit-hash-chain.test.d.ts +0 -1
  376. package/dist/tests/unit/observability/verify-audit-hash-chain.test.js +0 -93
  377. package/dist/tests/unit/ops/manual-run-dispatcher.test.d.ts +0 -13
  378. package/dist/tests/unit/ops/manual-run-dispatcher.test.js +0 -219
  379. package/dist/tests/unit/quiet/claim-synthesizer.test.d.ts +0 -17
  380. package/dist/tests/unit/quiet/claim-synthesizer.test.js +0 -289
  381. package/dist/tests/unit/quiet/daily-diary-writer.test.d.ts +0 -12
  382. package/dist/tests/unit/quiet/daily-diary-writer.test.js +0 -108
  383. package/dist/tests/unit/shared/v7-entities.test.d.ts +0 -13
  384. package/dist/tests/unit/shared/v7-entities.test.js +0 -306
  385. package/dist/tests/unit/storage/delivery-attempt.test.d.ts +0 -1
  386. package/dist/tests/unit/storage/delivery-attempt.test.js +0 -72
  387. package/dist/tests/unit/storage/diary-dream-store.test.d.ts +0 -12
  388. package/dist/tests/unit/storage/diary-dream-store.test.js +0 -118
  389. package/dist/tests/unit/storage/embodied-context-state-port.test.d.ts +0 -4
  390. package/dist/tests/unit/storage/embodied-context-state-port.test.js +0 -77
  391. package/dist/tests/unit/storage/goal-lifecycle-store.test.d.ts +0 -4
  392. package/dist/tests/unit/storage/goal-lifecycle-store.test.js +0 -143
  393. package/dist/tests/unit/storage/history-digest-store.test.d.ts +0 -10
  394. package/dist/tests/unit/storage/history-digest-store.test.js +0 -126
  395. package/dist/tests/unit/storage/identity-profile-store.test.d.ts +0 -4
  396. package/dist/tests/unit/storage/identity-profile-store.test.js +0 -48
  397. package/dist/tests/unit/storage/life-evidence-snapshot.test.d.ts +0 -1
  398. package/dist/tests/unit/storage/life-evidence-snapshot.test.js +0 -60
  399. package/dist/tests/unit/storage/life-evidence.test.d.ts +0 -1
  400. package/dist/tests/unit/storage/life-evidence.test.js +0 -54
  401. package/dist/tests/unit/storage/migration-runner.test.d.ts +0 -12
  402. package/dist/tests/unit/storage/migration-runner.test.js +0 -197
  403. package/dist/tests/unit/storage/repair-gate.test.d.ts +0 -1
  404. package/dist/tests/unit/storage/repair-gate.test.js +0 -41
  405. package/dist/tests/unit/storage/restore-snapshot-store.test.d.ts +0 -11
  406. package/dist/tests/unit/storage/restore-snapshot-store.test.js +0 -161
  407. package/dist/tests/unit/storage/rhythm-policy-snapshot.test.d.ts +0 -1
  408. package/dist/tests/unit/storage/rhythm-policy-snapshot.test.js +0 -31
  409. package/dist/tests/unit/storage/runtime-secret-anchor-store.test.d.ts +0 -10
  410. package/dist/tests/unit/storage/runtime-secret-anchor-store.test.js +0 -81
  411. package/dist/tests/unit/storage/t1-4-1-credential-health-mapper.test.d.ts +0 -1
  412. package/dist/tests/unit/storage/t1-4-1-credential-health-mapper.test.js +0 -83
  413. package/dist/tests/unit/storage/t4-1-1-session-chronicle.test.d.ts +0 -1
  414. package/dist/tests/unit/storage/t4-1-1-session-chronicle.test.js +0 -112
  415. package/dist/tests/unit/storage/t4-1-2-narrative-state.test.d.ts +0 -1
  416. package/dist/tests/unit/storage/t4-1-2-narrative-state.test.js +0 -80
  417. package/dist/tests/unit/storage/t4-1-3-relationship-memory.test.d.ts +0 -1
  418. package/dist/tests/unit/storage/t4-1-3-relationship-memory.test.js +0 -65
  419. package/dist/tests/unit/storage/t4-1-4-agent-goal.test.d.ts +0 -1
  420. package/dist/tests/unit/storage/t4-1-4-agent-goal.test.js +0 -166
  421. package/dist/tests/unit/storage/tool-experience-store.test.d.ts +0 -4
  422. package/dist/tests/unit/storage/tool-experience-store.test.js +0 -92
  423. package/dist/tests/unit/storage/user-interest-snapshot.test.d.ts +0 -1
  424. package/dist/tests/unit/storage/user-interest-snapshot.test.js +0 -48
  425. package/dist/tests/unit/storage/write-queue.test.d.ts +0 -12
  426. package/dist/tests/unit/storage/write-queue.test.js +0 -177
  427. package/dist/tests/unit/storage/write-validation-gate.test.d.ts +0 -9
  428. package/dist/tests/unit/storage/write-validation-gate.test.js +0 -153
  429. /package/{dist/plugin/index.js → index.js} +0 -0
  430. /package/{dist/src → runtime}/cli/action-bridge.js +0 -0
  431. /package/{dist/src → runtime}/cli/commands/connector-behavior.d.ts +0 -0
  432. /package/{dist/src → runtime}/cli/commands/connector-behavior.js +0 -0
  433. /package/{dist/src → runtime}/cli/commands/connector-init.d.ts +0 -0
  434. /package/{dist/src → runtime}/cli/commands/connector-init.js +0 -0
  435. /package/{dist/src → runtime}/cli/commands/connector-status.d.ts +0 -0
  436. /package/{dist/src → runtime}/cli/commands/connector-status.js +0 -0
  437. /package/{dist/src → runtime}/cli/commands/credential.d.ts +0 -0
  438. /package/{dist/src → runtime}/cli/commands/credential.js +0 -0
  439. /package/{dist/src → runtime}/cli/commands/goal.d.ts +0 -0
  440. /package/{dist/src → runtime}/cli/commands/goal.js +0 -0
  441. /package/{dist/src → runtime}/cli/commands/index.d.ts +0 -0
  442. /package/{dist/src → runtime}/cli/commands/policy.d.ts +0 -0
  443. /package/{dist/src → runtime}/cli/commands/policy.js +0 -0
  444. /package/{dist/src → runtime}/cli/explain/explain-surface-subject.d.ts +0 -0
  445. /package/{dist/src → runtime}/cli/explain/explain-surface-subject.js +0 -0
  446. /package/{dist/src → runtime}/cli/explain/format-explanation.d.ts +0 -0
  447. /package/{dist/src → runtime}/cli/explain/format-explanation.js +0 -0
  448. /package/{dist/src → runtime}/cli/explain/resolve-subject.d.ts +0 -0
  449. /package/{dist/src → runtime}/cli/explain/resolve-subject.js +0 -0
  450. /package/{dist/src → runtime}/cli/host-capability/classify-delivery.d.ts +0 -0
  451. /package/{dist/src → runtime}/cli/host-capability/classify-delivery.js +0 -0
  452. /package/{dist/src → runtime}/cli/host-capability/probe-host-capability.d.ts +0 -0
  453. /package/{dist/src → runtime}/cli/host-capability/probe-host-capability.js +0 -0
  454. /package/{dist/src → runtime}/cli/host-capability/record-host-capability.d.ts +0 -0
  455. /package/{dist/src → runtime}/cli/host-capability/record-host-capability.js +0 -0
  456. /package/{dist/src → runtime}/cli/host-capability/types.d.ts +0 -0
  457. /package/{dist/src → runtime}/cli/host-capability/types.js +0 -0
  458. /package/{dist/src → runtime}/cli/host-smoke/run-host-smoke.d.ts +0 -0
  459. /package/{dist/src → runtime}/cli/host-smoke/run-host-smoke.js +0 -0
  460. /package/{dist/src → runtime}/cli/host-smoke/types.d.ts +0 -0
  461. /package/{dist/src → runtime}/cli/host-smoke/types.js +0 -0
  462. /package/{dist/src → runtime}/cli/index.js +0 -0
  463. /package/{dist/src → runtime}/cli/ops/manual-run-dispatcher.d.ts +0 -0
  464. /package/{dist/src → runtime}/cli/ops/manual-run-dispatcher.js +0 -0
  465. /package/{dist/src → runtime}/cli/ops/ops-router.d.ts +0 -0
  466. /package/{dist/src → runtime}/cli/ops/show-operator-fallback.d.ts +0 -0
  467. /package/{dist/src → runtime}/cli/ops/show-operator-fallback.js +0 -0
  468. /package/{dist/src → runtime}/cli/read-models/index.d.ts +0 -0
  469. /package/{dist/src → runtime}/cli/read-models/index.js +0 -0
  470. /package/{dist/src → runtime}/cli/read-models/operator-explain-map.d.ts +0 -0
  471. /package/{dist/src → runtime}/cli/read-models/operator-explain-map.js +0 -0
  472. /package/{dist/src → runtime}/cli/read-models/types.d.ts +0 -0
  473. /package/{dist/src → runtime}/cli/read-models/types.js +0 -0
  474. /package/{dist/src → runtime}/cli/runtime/runtime-artifact-boundary.d.ts +0 -0
  475. /package/{dist/src → runtime}/cli/runtime/runtime-artifact-boundary.js +0 -0
  476. /package/{dist/src → runtime}/connectors/agent-network/agent-world/adapter.d.ts +0 -0
  477. /package/{dist/src → runtime}/connectors/agent-network/agent-world/adapter.js +0 -0
  478. /package/{dist/src → runtime}/connectors/agent-network/agent-world/index.d.ts +0 -0
  479. /package/{dist/src → runtime}/connectors/agent-network/agent-world/index.js +0 -0
  480. /package/{dist/src → runtime}/connectors/agent-network/agent-world/manifest.d.ts +0 -0
  481. /package/{dist/src → runtime}/connectors/agent-network/agent-world/manifest.js +0 -0
  482. /package/{dist/src → runtime}/connectors/agent-network/evomap/adapter.d.ts +0 -0
  483. /package/{dist/src → runtime}/connectors/agent-network/evomap/adapter.js +0 -0
  484. /package/{dist/src → runtime}/connectors/agent-network/evomap/index.d.ts +0 -0
  485. /package/{dist/src → runtime}/connectors/agent-network/evomap/index.js +0 -0
  486. /package/{dist/src → runtime}/connectors/agent-network/evomap/manifest.d.ts +0 -0
  487. /package/{dist/src → runtime}/connectors/agent-network/evomap/manifest.js +0 -0
  488. /package/{dist/src → runtime}/connectors/base/channel-health.d.ts +0 -0
  489. /package/{dist/src → runtime}/connectors/base/channel-health.js +0 -0
  490. /package/{dist/src → runtime}/connectors/base/contract.js +0 -0
  491. /package/{dist/src → runtime}/connectors/base/effect-commit-ledger-sqlite.d.ts +0 -0
  492. /package/{dist/src → runtime}/connectors/base/effect-commit-ledger-sqlite.js +0 -0
  493. /package/{dist/src → runtime}/connectors/base/execution-policy.d.ts +0 -0
  494. /package/{dist/src → runtime}/connectors/base/execution-policy.js +0 -0
  495. /package/{dist/src → runtime}/connectors/base/index.d.ts +0 -0
  496. /package/{dist/src → runtime}/connectors/base/index.js +0 -0
  497. /package/{dist/src → runtime}/connectors/base/manifest-v7.d.ts +0 -0
  498. /package/{dist/src → runtime}/connectors/base/manifest-v7.js +0 -0
  499. /package/{dist/src → runtime}/connectors/base/manifest.d.ts +0 -0
  500. /package/{dist/src → runtime}/connectors/base/manifest.js +0 -0
  501. /package/{dist/src → runtime}/connectors/base/map-life-evidence.d.ts +0 -0
  502. /package/{dist/src → runtime}/connectors/base/policy-layer.d.ts +0 -0
  503. /package/{dist/src → runtime}/connectors/base/route-planner.d.ts +0 -0
  504. /package/{dist/src → runtime}/connectors/base/route-planner.js +0 -0
  505. /package/{dist/src → runtime}/connectors/base/structured-unavailable-reason.d.ts +0 -0
  506. /package/{dist/src → runtime}/connectors/base/structured-unavailable-reason.js +0 -0
  507. /package/{dist/src → runtime}/connectors/base/wet-probe-runner.d.ts +0 -0
  508. /package/{dist/src → runtime}/connectors/base/wet-probe-runner.js +0 -0
  509. /package/{dist/src → runtime}/connectors/index.d.ts +0 -0
  510. /package/{dist/src → runtime}/connectors/index.js +0 -0
  511. /package/{dist/src → runtime}/connectors/manifest/manifest-parser.d.ts +0 -0
  512. /package/{dist/src → runtime}/connectors/manifest/manifest-parser.js +0 -0
  513. /package/{dist/src → runtime}/connectors/near-real/near-real-connector-smoke.d.ts +0 -0
  514. /package/{dist/src → runtime}/connectors/near-real/near-real-connector-smoke.js +0 -0
  515. /package/{dist/src → runtime}/connectors/registry/dynamic-connector-registry.d.ts +0 -0
  516. /package/{dist/src → runtime}/connectors/registry/dynamic-connector-registry.js +0 -0
  517. /package/{dist/src → runtime}/connectors/registry/index.d.ts +0 -0
  518. /package/{dist/src → runtime}/connectors/registry/index.js +0 -0
  519. /package/{dist/src → runtime}/connectors/registry/manifest-scanner.d.ts +0 -0
  520. /package/{dist/src → runtime}/connectors/registry/manifest-scanner.js +0 -0
  521. /package/{dist/src → runtime}/connectors/registry/trust-policy.d.ts +0 -0
  522. /package/{dist/src → runtime}/connectors/registry/trust-policy.js +0 -0
  523. /package/{dist/src → runtime}/connectors/services/credential-route-context.d.ts +0 -0
  524. /package/{dist/src → runtime}/connectors/services/credential-route-context.js +0 -0
  525. /package/{dist/src → runtime}/connectors/social-community/instreet/adapter.d.ts +0 -0
  526. /package/{dist/src → runtime}/connectors/social-community/instreet/adapter.js +0 -0
  527. /package/{dist/src → runtime}/connectors/social-community/instreet/index.d.ts +0 -0
  528. /package/{dist/src → runtime}/connectors/social-community/instreet/index.js +0 -0
  529. /package/{dist/src → runtime}/connectors/social-community/instreet/manifest.d.ts +0 -0
  530. /package/{dist/src → runtime}/connectors/social-community/instreet/manifest.js +0 -0
  531. /package/{dist/src → runtime}/connectors/social-community/moltbook/adapter.d.ts +0 -0
  532. /package/{dist/src → runtime}/connectors/social-community/moltbook/adapter.js +0 -0
  533. /package/{dist/src → runtime}/connectors/social-community/moltbook/api-client.d.ts +0 -0
  534. /package/{dist/src → runtime}/connectors/social-community/moltbook/api-client.js +0 -0
  535. /package/{dist/src → runtime}/connectors/social-community/moltbook/index.d.ts +0 -0
  536. /package/{dist/src → runtime}/connectors/social-community/moltbook/index.js +0 -0
  537. /package/{dist/src → runtime}/connectors/social-community/moltbook/manifest.d.ts +0 -0
  538. /package/{dist/src → runtime}/connectors/social-community/moltbook/manifest.js +0 -0
  539. /package/{dist/src → runtime}/core/second-nature/body/behavior-promotion/behavior-promotion-loop.d.ts +0 -0
  540. /package/{dist/src → runtime}/core/second-nature/body/behavior-promotion/behavior-promotion-loop.js +0 -0
  541. /package/{dist/src → runtime}/core/second-nature/body/circuit-breaker/circuit-breaker-manager.d.ts +0 -0
  542. /package/{dist/src → runtime}/core/second-nature/body/circuit-breaker/circuit-breaker-manager.js +0 -0
  543. /package/{dist/src → runtime}/core/second-nature/body/probe-signal-adapter.d.ts +0 -0
  544. /package/{dist/src → runtime}/core/second-nature/body/probe-signal-adapter.js +0 -0
  545. /package/{dist/src → runtime}/core/second-nature/body/tool-affordance/affordance-assembler.d.ts +0 -0
  546. /package/{dist/src → runtime}/core/second-nature/body/tool-affordance/affordance-assembler.js +0 -0
  547. /package/{dist/src → runtime}/core/second-nature/body/tool-affordance/affordance-context-scope.d.ts +0 -0
  548. /package/{dist/src → runtime}/core/second-nature/body/tool-affordance/affordance-context-scope.js +0 -0
  549. /package/{dist/src → runtime}/core/second-nature/body/tool-experience/experience-writer.d.ts +0 -0
  550. /package/{dist/src → runtime}/core/second-nature/body/tool-experience/experience-writer.js +0 -0
  551. /package/{dist/src → runtime}/core/second-nature/body/tool-experience/pain-signal-query.d.ts +0 -0
  552. /package/{dist/src → runtime}/core/second-nature/body/tool-experience/pain-signal-query.js +0 -0
  553. /package/{dist/src → runtime}/core/second-nature/feedback/owner-reply-feedback.d.ts +0 -0
  554. /package/{dist/src → runtime}/core/second-nature/feedback/owner-reply-feedback.js +0 -0
  555. /package/{dist/src → runtime}/core/second-nature/guidance/apply-guidance.d.ts +0 -0
  556. /package/{dist/src → runtime}/core/second-nature/guidance/apply-guidance.js +0 -0
  557. /package/{dist/src → runtime}/core/second-nature/guidance/request-guidance.d.ts +0 -0
  558. /package/{dist/src → runtime}/core/second-nature/guidance/request-guidance.js +0 -0
  559. /package/{dist/src → runtime}/core/second-nature/guidance/user-reply-continuity.d.ts +0 -0
  560. /package/{dist/src → runtime}/core/second-nature/guidance/user-reply-continuity.js +0 -0
  561. /package/{dist/src → runtime}/core/second-nature/heartbeat/decision-trace-emitter.d.ts +0 -0
  562. /package/{dist/src → runtime}/core/second-nature/heartbeat/decision-trace-emitter.js +0 -0
  563. /package/{dist/src → runtime}/core/second-nature/heartbeat/embodied-context-assembler.d.ts +0 -0
  564. /package/{dist/src → runtime}/core/second-nature/heartbeat/embodied-context-assembler.js +0 -0
  565. /package/{dist/src → runtime}/core/second-nature/heartbeat/heartbeat-executor.d.ts +0 -0
  566. /package/{dist/src → runtime}/core/second-nature/heartbeat/heartbeat-executor.js +0 -0
  567. /package/{dist/src → runtime}/core/second-nature/heartbeat/idle-curiosity-policy.d.ts +0 -0
  568. /package/{dist/src → runtime}/core/second-nature/heartbeat/idle-curiosity-policy.js +0 -0
  569. /package/{dist/src → runtime}/core/second-nature/heartbeat/index.d.ts +0 -0
  570. /package/{dist/src → runtime}/core/second-nature/heartbeat/index.js +0 -0
  571. /package/{dist/src → runtime}/core/second-nature/heartbeat/run-heartbeat-cycle-v7.d.ts +0 -0
  572. /package/{dist/src → runtime}/core/second-nature/heartbeat/run-heartbeat-cycle-v7.js +0 -0
  573. /package/{dist/src → runtime}/core/second-nature/heartbeat/run-heartbeat-cycle.d.ts +0 -0
  574. /package/{dist/src → runtime}/core/second-nature/heartbeat/run-heartbeat-cycle.js +0 -0
  575. /package/{dist/src → runtime}/core/second-nature/heartbeat/runtime-snapshot.d.ts +0 -0
  576. /package/{dist/src → runtime}/core/second-nature/heartbeat/runtime-snapshot.js +0 -0
  577. /package/{dist/src → runtime}/core/second-nature/heartbeat/scope-router.d.ts +0 -0
  578. /package/{dist/src → runtime}/core/second-nature/heartbeat/scope-router.js +0 -0
  579. /package/{dist/src → runtime}/core/second-nature/heartbeat/signal.d.ts +0 -0
  580. /package/{dist/src → runtime}/core/second-nature/heartbeat/signal.js +0 -0
  581. /package/{dist/src → runtime}/core/second-nature/heartbeat/snapshot-builder.d.ts +0 -0
  582. /package/{dist/src → runtime}/core/second-nature/heartbeat/snapshot-builder.js +0 -0
  583. /package/{dist/src → runtime}/core/second-nature/index.d.ts +0 -0
  584. /package/{dist/src → runtime}/core/second-nature/index.js +0 -0
  585. /package/{dist/src → runtime}/core/second-nature/orchestrator/downstream-intent-orchestrator.d.ts +0 -0
  586. /package/{dist/src → runtime}/core/second-nature/orchestrator/downstream-intent-orchestrator.js +0 -0
  587. /package/{dist/src → runtime}/core/second-nature/orchestrator/effect-dispatcher.d.ts +0 -0
  588. /package/{dist/src → runtime}/core/second-nature/orchestrator/effect-dispatcher.js +0 -0
  589. /package/{dist/src → runtime}/core/second-nature/orchestrator/goal-priority.d.ts +0 -0
  590. /package/{dist/src → runtime}/core/second-nature/orchestrator/goal-priority.js +0 -0
  591. /package/{dist/src → runtime}/core/second-nature/orchestrator/guard-layer.d.ts +0 -0
  592. /package/{dist/src → runtime}/core/second-nature/orchestrator/guard-layer.js +0 -0
  593. /package/{dist/src → runtime}/core/second-nature/orchestrator/hard-guard-evaluator.d.ts +0 -0
  594. /package/{dist/src → runtime}/core/second-nature/orchestrator/hard-guard-evaluator.js +0 -0
  595. /package/{dist/src → runtime}/core/second-nature/orchestrator/index.d.ts +0 -0
  596. /package/{dist/src → runtime}/core/second-nature/orchestrator/index.js +0 -0
  597. /package/{dist/src → runtime}/core/second-nature/orchestrator/intent-planner.d.ts +0 -0
  598. /package/{dist/src → runtime}/core/second-nature/orchestrator/intent-planner.js +0 -0
  599. /package/{dist/src → runtime}/core/second-nature/orchestrator/lease-manager.d.ts +0 -0
  600. /package/{dist/src → runtime}/core/second-nature/orchestrator/lease-manager.js +0 -0
  601. /package/{dist/src → runtime}/core/second-nature/orchestrator/narrative-update.d.ts +0 -0
  602. /package/{dist/src → runtime}/core/second-nature/orchestrator/narrative-update.js +0 -0
  603. /package/{dist/src → runtime}/core/second-nature/orchestrator/platform-capability-router.d.ts +0 -0
  604. /package/{dist/src → runtime}/core/second-nature/orchestrator/resume-from-checkpoint.d.ts +0 -0
  605. /package/{dist/src → runtime}/core/second-nature/orchestrator/resume-from-checkpoint.js +0 -0
  606. /package/{dist/src → runtime}/core/second-nature/outreach/build-message.d.ts +0 -0
  607. /package/{dist/src → runtime}/core/second-nature/outreach/build-message.js +0 -0
  608. /package/{dist/src → runtime}/core/second-nature/outreach/build-outreach-draft-request.d.ts +0 -0
  609. /package/{dist/src → runtime}/core/second-nature/outreach/build-outreach-draft-request.js +0 -0
  610. /package/{dist/src → runtime}/core/second-nature/outreach/delivery-target.d.ts +0 -0
  611. /package/{dist/src → runtime}/core/second-nature/outreach/delivery-target.js +0 -0
  612. /package/{dist/src → runtime}/core/second-nature/outreach/dispatch-user-outreach.d.ts +0 -0
  613. /package/{dist/src → runtime}/core/second-nature/outreach/dispatch-user-outreach.js +0 -0
  614. /package/{dist/src → runtime}/core/second-nature/outreach/evaluate-outreach.d.ts +0 -0
  615. /package/{dist/src → runtime}/core/second-nature/outreach/evaluate-outreach.js +0 -0
  616. /package/{dist/src → runtime}/core/second-nature/outreach/judge-input-from-snapshot.d.ts +0 -0
  617. /package/{dist/src → runtime}/core/second-nature/outreach/judge-input-from-snapshot.js +0 -0
  618. /package/{dist/src → runtime}/core/second-nature/outreach/judge-outreach.d.ts +0 -0
  619. /package/{dist/src → runtime}/core/second-nature/outreach/judge-outreach.js +0 -0
  620. /package/{dist/src → runtime}/core/second-nature/quiet/claim-synthesizer.d.ts +0 -0
  621. /package/{dist/src → runtime}/core/second-nature/quiet/claim-synthesizer.js +0 -0
  622. /package/{dist/src → runtime}/core/second-nature/quiet/daily-diary-writer.d.ts +0 -0
  623. /package/{dist/src → runtime}/core/second-nature/quiet/daily-diary-writer.js +0 -0
  624. /package/{dist/src → runtime}/core/second-nature/quiet/index.d.ts +0 -0
  625. /package/{dist/src → runtime}/core/second-nature/quiet/index.js +0 -0
  626. /package/{dist/src → runtime}/core/second-nature/quiet/quiet-pipeline.d.ts +0 -0
  627. /package/{dist/src → runtime}/core/second-nature/quiet/quiet-pipeline.js +0 -0
  628. /package/{dist/src → runtime}/core/second-nature/quiet/run-source-backed-quiet.d.ts +0 -0
  629. /package/{dist/src → runtime}/core/second-nature/quiet/run-source-backed-quiet.js +0 -0
  630. /package/{dist/src → runtime}/core/second-nature/reflection/run-narrative-reflection.d.ts +0 -0
  631. /package/{dist/src → runtime}/core/second-nature/reflection/run-narrative-reflection.js +0 -0
  632. /package/{dist/src → runtime}/core/second-nature/rhythm/planner-rhythm-window.d.ts +0 -0
  633. /package/{dist/src → runtime}/core/second-nature/rhythm/planner-rhythm-window.js +0 -0
  634. /package/{dist/src → runtime}/core/second-nature/rhythm/policy-bridge.d.ts +0 -0
  635. /package/{dist/src → runtime}/core/second-nature/rhythm/policy-bridge.js +0 -0
  636. /package/{dist/src → runtime}/core/second-nature/rhythm/rhythm-policy.d.ts +0 -0
  637. /package/{dist/src → runtime}/core/second-nature/rhythm/rhythm-policy.js +0 -0
  638. /package/{dist/src → runtime}/core/second-nature/rhythm/select-window.d.ts +0 -0
  639. /package/{dist/src → runtime}/core/second-nature/rhythm/select-window.js +0 -0
  640. /package/{dist/src → runtime}/core/second-nature/runtime/lifecycle-service.d.ts +0 -0
  641. /package/{dist/src → runtime}/core/second-nature/runtime/lifecycle-service.js +0 -0
  642. /package/{dist/src → runtime}/core/second-nature/runtime/service-entry.d.ts +0 -0
  643. /package/{dist/src → runtime}/core/second-nature/runtime/service-entry.js +0 -0
  644. /package/{dist/src → runtime}/core/second-nature/types.d.ts +0 -0
  645. /package/{dist/src → runtime}/core/second-nature/types.js +0 -0
  646. /package/{dist/src → runtime}/dream/dream-engine.d.ts +0 -0
  647. /package/{dist/src → runtime}/dream/dream-engine.js +0 -0
  648. /package/{dist/src → runtime}/dream/dream-input-loader.d.ts +0 -0
  649. /package/{dist/src → runtime}/dream/dream-input-loader.js +0 -0
  650. /package/{dist/src → runtime}/dream/dream-scheduler.d.ts +0 -0
  651. /package/{dist/src → runtime}/dream/dream-scheduler.js +0 -0
  652. /package/{dist/src → runtime}/dream/index.d.ts +0 -0
  653. /package/{dist/src → runtime}/dream/index.js +0 -0
  654. /package/{dist/src → runtime}/dream/insight-extractor.d.ts +0 -0
  655. /package/{dist/src → runtime}/dream/insight-extractor.js +0 -0
  656. /package/{dist/src → runtime}/dream/memory-consolidator.d.ts +0 -0
  657. /package/{dist/src → runtime}/dream/memory-consolidator.js +0 -0
  658. /package/{dist/src → runtime}/dream/narrative-update-proposal.d.ts +0 -0
  659. /package/{dist/src → runtime}/dream/narrative-update-proposal.js +0 -0
  660. /package/{dist/src → runtime}/dream/output-validator.d.ts +0 -0
  661. /package/{dist/src → runtime}/dream/output-validator.js +0 -0
  662. /package/{dist/src → runtime}/dream/redaction-gate.d.ts +0 -0
  663. /package/{dist/src → runtime}/dream/redaction-gate.js +0 -0
  664. /package/{dist/src → runtime}/dream/relationship-update-proposal.d.ts +0 -0
  665. /package/{dist/src → runtime}/dream/relationship-update-proposal.js +0 -0
  666. /package/{dist/src → runtime}/dream/sampler.d.ts +0 -0
  667. /package/{dist/src → runtime}/dream/sampler.js +0 -0
  668. /package/{dist/src → runtime}/dream/types.d.ts +0 -0
  669. /package/{dist/src → runtime}/dream/types.js +0 -0
  670. /package/{dist/src → runtime}/guidance/capability-class.d.ts +0 -0
  671. /package/{dist/src → runtime}/guidance/capability-class.js +0 -0
  672. /package/{dist/src → runtime}/guidance/channel-feedback-ingestion-service.d.ts +0 -0
  673. /package/{dist/src → runtime}/guidance/channel-feedback-ingestion-service.js +0 -0
  674. /package/{dist/src → runtime}/guidance/contracts.d.ts +0 -0
  675. /package/{dist/src → runtime}/guidance/contracts.js +0 -0
  676. /package/{dist/src → runtime}/guidance/draft-narrative-outreach.d.ts +0 -0
  677. /package/{dist/src → runtime}/guidance/draft-narrative-outreach.js +0 -0
  678. /package/{dist/src → runtime}/guidance/draft-outreach-message.d.ts +0 -0
  679. /package/{dist/src → runtime}/guidance/draft-outreach-message.js +0 -0
  680. /package/{dist/src → runtime}/guidance/evidence-guidance.d.ts +0 -0
  681. /package/{dist/src → runtime}/guidance/evidence-guidance.js +0 -0
  682. /package/{dist/src → runtime}/guidance/fallback.d.ts +0 -0
  683. /package/{dist/src → runtime}/guidance/fallback.js +0 -0
  684. /package/{dist/src → runtime}/guidance/guidance-assembler.d.ts +0 -0
  685. /package/{dist/src → runtime}/guidance/guidance-assembler.js +0 -0
  686. /package/{dist/src → runtime}/guidance/guidance-draft-service.d.ts +0 -0
  687. /package/{dist/src → runtime}/guidance/guidance-draft-service.js +0 -0
  688. /package/{dist/src → runtime}/guidance/impulse-assembler.d.ts +0 -0
  689. /package/{dist/src → runtime}/guidance/impulse-assembler.js +0 -0
  690. /package/{dist/src → runtime}/guidance/index.d.ts +0 -0
  691. /package/{dist/src → runtime}/guidance/index.js +0 -0
  692. /package/{dist/src → runtime}/guidance/output-guard.d.ts +0 -0
  693. /package/{dist/src → runtime}/guidance/output-guard.js +0 -0
  694. /package/{dist/src → runtime}/guidance/outreach-draft-schema.d.ts +0 -0
  695. /package/{dist/src → runtime}/guidance/outreach-draft-schema.js +0 -0
  696. /package/{dist/src → runtime}/guidance/outreach-strategy-selector.d.ts +0 -0
  697. /package/{dist/src → runtime}/guidance/outreach-strategy-selector.js +0 -0
  698. /package/{dist/src → runtime}/guidance/persona-selection.d.ts +0 -0
  699. /package/{dist/src → runtime}/guidance/persona-selection.js +0 -0
  700. /package/{dist/src → runtime}/guidance/review-workflow.d.ts +0 -0
  701. /package/{dist/src → runtime}/guidance/review-workflow.js +0 -0
  702. /package/{dist/src → runtime}/guidance/template-registry.d.ts +0 -0
  703. /package/{dist/src → runtime}/guidance/template-registry.js +0 -0
  704. /package/{dist/src → runtime}/guidance/types.d.ts +0 -0
  705. /package/{dist/src → runtime}/guidance/types.js +0 -0
  706. /package/{dist/src → runtime}/observability/audit/append-only-audit-store.d.ts +0 -0
  707. /package/{dist/src → runtime}/observability/audit/append-only-audit-store.js +0 -0
  708. /package/{dist/src → runtime}/observability/audit/audit-envelope.d.ts +0 -0
  709. /package/{dist/src → runtime}/observability/audit/audit-envelope.js +0 -0
  710. /package/{dist/src → runtime}/observability/audit/audit-family-registry.json +0 -0
  711. /package/{dist/src → runtime}/observability/audit/family-registry.d.ts +0 -0
  712. /package/{dist/src → runtime}/observability/audit/family-registry.js +0 -0
  713. /package/{dist/src → runtime}/observability/audit/verify-audit-hash-chain.d.ts +0 -0
  714. /package/{dist/src → runtime}/observability/audit/verify-audit-hash-chain.js +0 -0
  715. /package/{dist/src → runtime}/observability/connector-inventory-ledger.d.ts +0 -0
  716. /package/{dist/src → runtime}/observability/connector-inventory-ledger.js +0 -0
  717. /package/{dist/src → runtime}/observability/db/index.d.ts +0 -0
  718. /package/{dist/src → runtime}/observability/db/index.js +0 -0
  719. /package/{dist/src → runtime}/observability/db/schema/connector-inventory.d.ts +0 -0
  720. /package/{dist/src → runtime}/observability/db/schema/connector-inventory.js +0 -0
  721. /package/{dist/src → runtime}/observability/db/schema/host-capability-reports.d.ts +0 -0
  722. /package/{dist/src → runtime}/observability/db/schema/host-capability-reports.js +0 -0
  723. /package/{dist/src → runtime}/observability/db/schema/index.d.ts +0 -0
  724. /package/{dist/src → runtime}/observability/db/schema/index.js +0 -0
  725. /package/{dist/src → runtime}/observability/index.d.ts +0 -0
  726. /package/{dist/src → runtime}/observability/index.js +0 -0
  727. /package/{dist/src → runtime}/observability/projections/guidance-audit.d.ts +0 -0
  728. /package/{dist/src → runtime}/observability/projections/guidance-audit.js +0 -0
  729. /package/{dist/src → runtime}/observability/projections/outreach-quality-audit.d.ts +0 -0
  730. /package/{dist/src → runtime}/observability/projections/outreach-quality-audit.js +0 -0
  731. /package/{dist/src → runtime}/observability/projections/reflection-audit.d.ts +0 -0
  732. /package/{dist/src → runtime}/observability/projections/reflection-audit.js +0 -0
  733. /package/{dist/src → runtime}/observability/query/compose-evidence.d.ts +0 -0
  734. /package/{dist/src → runtime}/observability/query/compose-evidence.js +0 -0
  735. /package/{dist/src → runtime}/observability/query/evidence-query-engine.d.ts +0 -0
  736. /package/{dist/src → runtime}/observability/query/evidence-query-engine.js +0 -0
  737. /package/{dist/src → runtime}/observability/query/explain-query.d.ts +0 -0
  738. /package/{dist/src → runtime}/observability/query/explain-query.js +0 -0
  739. /package/{dist/src → runtime}/observability/query/export-audit-bundle.d.ts +0 -0
  740. /package/{dist/src → runtime}/observability/query/export-audit-bundle.js +0 -0
  741. /package/{dist/src → runtime}/observability/redaction/manifest.d.ts +0 -0
  742. /package/{dist/src → runtime}/observability/redaction/manifest.js +0 -0
  743. /package/{dist/src → runtime}/observability/redaction/policy.d.ts +0 -0
  744. /package/{dist/src → runtime}/observability/redaction/policy.js +0 -0
  745. /package/{dist/src → runtime}/observability/services/decision-ledger.d.ts +0 -0
  746. /package/{dist/src → runtime}/observability/services/decision-ledger.js +0 -0
  747. /package/{dist/src → runtime}/observability/services/execution-telemetry.d.ts +0 -0
  748. /package/{dist/src → runtime}/observability/services/execution-telemetry.js +0 -0
  749. /package/{dist/src → runtime}/observability/services/governance-audit.d.ts +0 -0
  750. /package/{dist/src → runtime}/observability/services/governance-audit.js +0 -0
  751. /package/{dist/src → runtime}/observability/services/governance-plane-recorder.d.ts +0 -0
  752. /package/{dist/src → runtime}/observability/services/governance-plane-recorder.js +0 -0
  753. /package/{dist/src → runtime}/observability/services/heartbeat-digest-assembler.d.ts +0 -0
  754. /package/{dist/src → runtime}/observability/services/heartbeat-digest-assembler.js +0 -0
  755. /package/{dist/src → runtime}/observability/services/lived-experience-audit.d.ts +0 -0
  756. /package/{dist/src → runtime}/observability/services/lived-experience-audit.js +0 -0
  757. /package/{dist/src → runtime}/observability/services/narrative-timeline-query-service.d.ts +0 -0
  758. /package/{dist/src → runtime}/observability/services/narrative-timeline-query-service.js +0 -0
  759. /package/{dist/src → runtime}/observability/services/observability-retention.d.ts +0 -0
  760. /package/{dist/src → runtime}/observability/services/observability-retention.js +0 -0
  761. /package/{dist/src → runtime}/observability/services/redaction-store.d.ts +0 -0
  762. /package/{dist/src → runtime}/observability/services/redaction-store.js +0 -0
  763. /package/{dist/src → runtime}/observability/services/restore-audit-service.d.ts +0 -0
  764. /package/{dist/src → runtime}/observability/services/restore-audit-service.js +0 -0
  765. /package/{dist/src → runtime}/observability/services/runtime-decision-recorder.d.ts +0 -0
  766. /package/{dist/src → runtime}/observability/services/runtime-decision-recorder.js +0 -0
  767. /package/{dist/src → runtime}/observability/services/runtime-secret-anchor-view.d.ts +0 -0
  768. /package/{dist/src → runtime}/observability/services/runtime-secret-anchor-view.js +0 -0
  769. /package/{dist/src → runtime}/observability/services/self-health-snapshot.d.ts +0 -0
  770. /package/{dist/src → runtime}/observability/services/self-health-snapshot.js +0 -0
  771. /package/{dist/src → runtime}/shared/types/continuity.d.ts +0 -0
  772. /package/{dist/src → runtime}/shared/types/continuity.js +0 -0
  773. /package/{dist/src → runtime}/shared/types/credential.d.ts +0 -0
  774. /package/{dist/src → runtime}/shared/types/credential.js +0 -0
  775. /package/{dist/src → runtime}/shared/types/goal.d.ts +0 -0
  776. /package/{dist/src → runtime}/shared/types/goal.js +0 -0
  777. /package/{dist/src → runtime}/shared/types/index.d.ts +0 -0
  778. /package/{dist/src → runtime}/shared/types/index.js +0 -0
  779. /package/{dist/src → runtime}/shared/types/outreach.d.ts +0 -0
  780. /package/{dist/src → runtime}/shared/types/outreach.js +0 -0
  781. /package/{dist/src → runtime}/shared/types/source-ref.d.ts +0 -0
  782. /package/{dist/src → runtime}/shared/types/source-ref.js +0 -0
  783. /package/{dist/src → runtime}/shared/types/v7-entities.d.ts +0 -0
  784. /package/{dist/src → runtime}/shared/types/v7-entities.js +0 -0
  785. /package/{dist/src → runtime}/storage/bootstrap/native-sqlite-probe.d.ts +0 -0
  786. /package/{dist/src → runtime}/storage/bootstrap/native-sqlite-probe.js +0 -0
  787. /package/{dist/src → runtime}/storage/bootstrap/repair-gate.d.ts +0 -0
  788. /package/{dist/src → runtime}/storage/bootstrap/repair-gate.js +0 -0
  789. /package/{dist/src → runtime}/storage/bootstrap/repair.d.ts +0 -0
  790. /package/{dist/src → runtime}/storage/bootstrap/repair.js +0 -0
  791. /package/{dist/src → runtime}/storage/bootstrap/storage-mode-smoke.d.ts +0 -0
  792. /package/{dist/src → runtime}/storage/bootstrap/storage-mode-smoke.js +0 -0
  793. /package/{dist/src → runtime}/storage/chronicle/session-chronicle-store.d.ts +0 -0
  794. /package/{dist/src → runtime}/storage/chronicle/session-chronicle-store.js +0 -0
  795. /package/{dist/src → runtime}/storage/db/index.d.ts +0 -0
  796. /package/{dist/src → runtime}/storage/db/index.js +0 -0
  797. /package/{dist/src → runtime}/storage/db/migration-runner.d.ts +0 -0
  798. /package/{dist/src → runtime}/storage/db/migration-runner.js +0 -0
  799. /package/{dist/src → runtime}/storage/db/migrations/index.d.ts +0 -0
  800. /package/{dist/src → runtime}/storage/db/migrations/index.js +0 -0
  801. /package/{dist/src → runtime}/storage/db/migrations/v7-001-foundation.d.ts +0 -0
  802. /package/{dist/src → runtime}/storage/db/migrations/v7-001-foundation.js +0 -0
  803. /package/{dist/src → runtime}/storage/db/migrations/v7-002-effect-commit-ledger.d.ts +0 -0
  804. /package/{dist/src → runtime}/storage/db/migrations/v7-002-effect-commit-ledger.js +0 -0
  805. /package/{dist/src → runtime}/storage/db/migrations/v7-003-circuit-breaker.d.ts +0 -0
  806. /package/{dist/src → runtime}/storage/db/migrations/v7-003-circuit-breaker.js +0 -0
  807. /package/{dist/src → runtime}/storage/db/migrations/v7-004-behavior-promotion.d.ts +0 -0
  808. /package/{dist/src → runtime}/storage/db/migrations/v7-004-behavior-promotion.js +0 -0
  809. /package/{dist/src → runtime}/storage/db/schema/agent-goal.d.ts +0 -0
  810. /package/{dist/src → runtime}/storage/db/schema/agent-goal.js +0 -0
  811. /package/{dist/src → runtime}/storage/db/schema/assets.d.ts +0 -0
  812. /package/{dist/src → runtime}/storage/db/schema/assets.js +0 -0
  813. /package/{dist/src → runtime}/storage/db/schema/credentials.d.ts +0 -0
  814. /package/{dist/src → runtime}/storage/db/schema/credentials.js +0 -0
  815. /package/{dist/src → runtime}/storage/db/schema/delivery-attempts.d.ts +0 -0
  816. /package/{dist/src → runtime}/storage/db/schema/delivery-attempts.js +0 -0
  817. /package/{dist/src → runtime}/storage/db/schema/index.d.ts +0 -0
  818. /package/{dist/src → runtime}/storage/db/schema/index.js +0 -0
  819. /package/{dist/src → runtime}/storage/db/schema/intent-commits.d.ts +0 -0
  820. /package/{dist/src → runtime}/storage/db/schema/intent-commits.js +0 -0
  821. /package/{dist/src → runtime}/storage/db/schema/life-evidence-index.d.ts +0 -0
  822. /package/{dist/src → runtime}/storage/db/schema/life-evidence-index.js +0 -0
  823. /package/{dist/src → runtime}/storage/db/schema/memory-store.d.ts +0 -0
  824. /package/{dist/src → runtime}/storage/db/schema/memory-store.js +0 -0
  825. /package/{dist/src → runtime}/storage/db/schema/narrative-state.d.ts +0 -0
  826. /package/{dist/src → runtime}/storage/db/schema/narrative-state.js +0 -0
  827. /package/{dist/src → runtime}/storage/db/schema/operator-fallback-artifacts.d.ts +0 -0
  828. /package/{dist/src → runtime}/storage/db/schema/operator-fallback-artifacts.js +0 -0
  829. /package/{dist/src → runtime}/storage/db/schema/policies.d.ts +0 -0
  830. /package/{dist/src → runtime}/storage/db/schema/policies.js +0 -0
  831. /package/{dist/src → runtime}/storage/db/schema/proposals.d.ts +0 -0
  832. /package/{dist/src → runtime}/storage/db/schema/proposals.js +0 -0
  833. /package/{dist/src → runtime}/storage/db/schema/provenance.d.ts +0 -0
  834. /package/{dist/src → runtime}/storage/db/schema/provenance.js +0 -0
  835. /package/{dist/src → runtime}/storage/db/schema/relationship-memory.d.ts +0 -0
  836. /package/{dist/src → runtime}/storage/db/schema/relationship-memory.js +0 -0
  837. /package/{dist/src → runtime}/storage/db/schema/session-chronicle.d.ts +0 -0
  838. /package/{dist/src → runtime}/storage/db/schema/session-chronicle.js +0 -0
  839. /package/{dist/src → runtime}/storage/db/transaction-utils.d.ts +0 -0
  840. /package/{dist/src → runtime}/storage/db/transaction-utils.js +0 -0
  841. /package/{dist/src → runtime}/storage/db/write-queue.d.ts +0 -0
  842. /package/{dist/src → runtime}/storage/db/write-queue.js +0 -0
  843. /package/{dist/src → runtime}/storage/delivery/query-delivery-attempts.d.ts +0 -0
  844. /package/{dist/src → runtime}/storage/delivery/query-delivery-attempts.js +0 -0
  845. /package/{dist/src → runtime}/storage/delivery/types.d.ts +0 -0
  846. /package/{dist/src → runtime}/storage/delivery/types.js +0 -0
  847. /package/{dist/src → runtime}/storage/delivery/write-delivery-attempt.d.ts +0 -0
  848. /package/{dist/src → runtime}/storage/delivery/write-delivery-attempt.js +0 -0
  849. /package/{dist/src → runtime}/storage/fallback/load-operator-fallback.d.ts +0 -0
  850. /package/{dist/src → runtime}/storage/fallback/load-operator-fallback.js +0 -0
  851. /package/{dist/src → runtime}/storage/fallback/operator-fallback-types.d.ts +0 -0
  852. /package/{dist/src → runtime}/storage/fallback/operator-fallback-types.js +0 -0
  853. /package/{dist/src → runtime}/storage/fallback/operator-fallback-view.d.ts +0 -0
  854. /package/{dist/src → runtime}/storage/fallback/operator-fallback-view.js +0 -0
  855. /package/{dist/src → runtime}/storage/fallback/write-operator-fallback.d.ts +0 -0
  856. /package/{dist/src → runtime}/storage/fallback/write-operator-fallback.js +0 -0
  857. /package/{dist/src → runtime}/storage/goal/agent-goal-store.d.ts +0 -0
  858. /package/{dist/src → runtime}/storage/goal/agent-goal-store.js +0 -0
  859. /package/{dist/src → runtime}/storage/index.d.ts +0 -0
  860. /package/{dist/src → runtime}/storage/index.js +0 -0
  861. /package/{dist/src → runtime}/storage/life-evidence/append-life-evidence.d.ts +0 -0
  862. /package/{dist/src → runtime}/storage/life-evidence/append-life-evidence.js +0 -0
  863. /package/{dist/src → runtime}/storage/life-evidence/types.d.ts +0 -0
  864. /package/{dist/src → runtime}/storage/life-evidence/types.js +0 -0
  865. /package/{dist/src → runtime}/storage/memory/workspace/paths.d.ts +0 -0
  866. /package/{dist/src → runtime}/storage/memory/workspace/paths.js +0 -0
  867. /package/{dist/src → runtime}/storage/memory/workspace/store.d.ts +0 -0
  868. /package/{dist/src → runtime}/storage/memory/workspace/store.js +0 -0
  869. /package/{dist/src → runtime}/storage/memory/workspace/types.d.ts +0 -0
  870. /package/{dist/src → runtime}/storage/memory/workspace/types.js +0 -0
  871. /package/{dist/src → runtime}/storage/memory-store/memory-store-lifecycle.d.ts +0 -0
  872. /package/{dist/src → runtime}/storage/memory-store/memory-store-lifecycle.js +0 -0
  873. /package/{dist/src → runtime}/storage/narrative/narrative-state-store.d.ts +0 -0
  874. /package/{dist/src → runtime}/storage/narrative/narrative-state-store.js +0 -0
  875. /package/{dist/src → runtime}/storage/quiet/persist-quiet-artifact.d.ts +0 -0
  876. /package/{dist/src → runtime}/storage/quiet/persist-quiet-artifact.js +0 -0
  877. /package/{dist/src → runtime}/storage/quiet/quiet-artifact-types.d.ts +0 -0
  878. /package/{dist/src → runtime}/storage/quiet/quiet-artifact-types.js +0 -0
  879. /package/{dist/src → runtime}/storage/quiet/quiet-artifact-writer.d.ts +0 -0
  880. /package/{dist/src → runtime}/storage/quiet/quiet-artifact-writer.js +0 -0
  881. /package/{dist/src → runtime}/storage/relationship/relationship-memory-store.d.ts +0 -0
  882. /package/{dist/src → runtime}/storage/relationship/relationship-memory-store.js +0 -0
  883. /package/{dist/src → runtime}/storage/repositories/asset-repository.d.ts +0 -0
  884. /package/{dist/src → runtime}/storage/repositories/asset-repository.js +0 -0
  885. /package/{dist/src → runtime}/storage/repositories/credential-repository.d.ts +0 -0
  886. /package/{dist/src → runtime}/storage/repositories/credential-repository.js +0 -0
  887. /package/{dist/src → runtime}/storage/repositories/index.d.ts +0 -0
  888. /package/{dist/src → runtime}/storage/repositories/index.js +0 -0
  889. /package/{dist/src → runtime}/storage/repositories/intent-commit-repository.d.ts +0 -0
  890. /package/{dist/src → runtime}/storage/repositories/intent-commit-repository.js +0 -0
  891. /package/{dist/src → runtime}/storage/repositories/policy-repository.d.ts +0 -0
  892. /package/{dist/src → runtime}/storage/repositories/policy-repository.js +0 -0
  893. /package/{dist/src → runtime}/storage/repositories/proposal-repository.d.ts +0 -0
  894. /package/{dist/src → runtime}/storage/repositories/proposal-repository.js +0 -0
  895. /package/{dist/src → runtime}/storage/repositories/provenance-repository.d.ts +0 -0
  896. /package/{dist/src → runtime}/storage/repositories/provenance-repository.js +0 -0
  897. /package/{dist/src → runtime}/storage/rhythm/rhythm-policy-snapshot.d.ts +0 -0
  898. /package/{dist/src → runtime}/storage/rhythm/rhythm-policy-snapshot.js +0 -0
  899. /package/{dist/src → runtime}/storage/services/credential-vault.d.ts +0 -0
  900. /package/{dist/src → runtime}/storage/services/credential-vault.js +0 -0
  901. /package/{dist/src → runtime}/storage/services/daily-log-pipeline.d.ts +0 -0
  902. /package/{dist/src → runtime}/storage/services/daily-log-pipeline.js +0 -0
  903. /package/{dist/src → runtime}/storage/services/diary-dream-store.d.ts +0 -0
  904. /package/{dist/src → runtime}/storage/services/diary-dream-store.js +0 -0
  905. /package/{dist/src → runtime}/storage/services/effect-commit-store.d.ts +0 -0
  906. /package/{dist/src → runtime}/storage/services/effect-commit-store.js +0 -0
  907. /package/{dist/src → runtime}/storage/services/embodied-context-state-port.d.ts +0 -0
  908. /package/{dist/src → runtime}/storage/services/embodied-context-state-port.js +0 -0
  909. /package/{dist/src → runtime}/storage/services/goal-lifecycle-store.d.ts +0 -0
  910. /package/{dist/src → runtime}/storage/services/goal-lifecycle-store.js +0 -0
  911. /package/{dist/src → runtime}/storage/services/governance-layer.d.ts +0 -0
  912. /package/{dist/src → runtime}/storage/services/governance-layer.js +0 -0
  913. /package/{dist/src → runtime}/storage/services/history-digest-store.d.ts +0 -0
  914. /package/{dist/src → runtime}/storage/services/history-digest-store.js +0 -0
  915. /package/{dist/src → runtime}/storage/services/identity-profile-store.d.ts +0 -0
  916. /package/{dist/src → runtime}/storage/services/identity-profile-store.js +0 -0
  917. /package/{dist/src → runtime}/storage/services/interaction-snapshot-projector.d.ts +0 -0
  918. /package/{dist/src → runtime}/storage/services/interaction-snapshot-projector.js +0 -0
  919. /package/{dist/src → runtime}/storage/services/persona-candidate-loader.d.ts +0 -0
  920. /package/{dist/src → runtime}/storage/services/persona-candidate-loader.js +0 -0
  921. /package/{dist/src → runtime}/storage/services/provenance-service.d.ts +0 -0
  922. /package/{dist/src → runtime}/storage/services/provenance-service.js +0 -0
  923. /package/{dist/src → runtime}/storage/services/quiet-input-loader.d.ts +0 -0
  924. /package/{dist/src → runtime}/storage/services/quiet-input-loader.js +0 -0
  925. /package/{dist/src → runtime}/storage/services/repair-and-backup.d.ts +0 -0
  926. /package/{dist/src → runtime}/storage/services/repair-and-backup.js +0 -0
  927. /package/{dist/src → runtime}/storage/services/restore-snapshot-store.d.ts +0 -0
  928. /package/{dist/src → runtime}/storage/services/restore-snapshot-store.js +0 -0
  929. /package/{dist/src → runtime}/storage/services/runtime-secret-anchor-store.d.ts +0 -0
  930. /package/{dist/src → runtime}/storage/services/runtime-secret-anchor-store.js +0 -0
  931. /package/{dist/src → runtime}/storage/services/tool-experience-store.d.ts +0 -0
  932. /package/{dist/src → runtime}/storage/services/tool-experience-store.js +0 -0
  933. /package/{dist/src → runtime}/storage/services/write-validation-gate.d.ts +0 -0
  934. /package/{dist/src → runtime}/storage/services/write-validation-gate.js +0 -0
  935. /package/{dist/src → runtime}/storage/snapshots/continuity-snapshot.d.ts +0 -0
  936. /package/{dist/src → runtime}/storage/snapshots/continuity-snapshot.js +0 -0
  937. /package/{dist/src → runtime}/storage/snapshots/life-evidence-snapshot.d.ts +0 -0
  938. /package/{dist/src → runtime}/storage/snapshots/life-evidence-snapshot.js +0 -0
  939. /package/{dist/src → runtime}/storage/snapshots/types.d.ts +0 -0
  940. /package/{dist/src → runtime}/storage/snapshots/types.js +0 -0
  941. /package/{dist/src → runtime}/storage/state-api.d.ts +0 -0
  942. /package/{dist/src → runtime}/storage/state-api.js +0 -0
  943. /package/{dist/src → runtime}/storage/user-interest/load-user-interest-snapshot.d.ts +0 -0
  944. /package/{dist/src → runtime}/storage/user-interest/load-user-interest-snapshot.js +0 -0
  945. /package/{dist/src → runtime}/storage/user-interest/types.d.ts +0 -0
  946. /package/{dist/src → runtime}/storage/user-interest/types.js +0 -0
  947. /package/{dist/plugin/workspace-ops-bridge.js → workspace-ops-bridge.js} +0 -0
@@ -1,1482 +1,1482 @@
1
- /**
2
- * Shared ops command dispatch for CLI + tool surfaces (T1.1.3, T1.2.2).
3
- *
4
- * v7 additions (T-ROS.C.1): self_health, tool_affordance, connector_test --wet,
5
- * heartbeat_digest, narrative:diff, timeline, restore, runtime_secret_bootstrap.
6
- * All commands return RuntimeOpsEnvelope.
7
- */
8
- import { createHash } from "node:crypto";
9
- import fs from "node:fs";
10
- import path from "node:path";
11
- import { heartbeatCheck, } from "./heartbeat-surface.js";
12
- import { showOperatorFallback, OperatorFallbackNotFoundError, } from "./show-operator-fallback.js";
13
- import { probeHostCapability } from "../host-capability/probe-host-capability.js";
14
- import { recordHostCapability } from "../host-capability/record-host-capability.js";
15
- import { runNearRealConnectorSmoke } from "../../connectors/near-real/near-real-connector-smoke.js";
16
- import { scanConnectorManifests } from "../../connectors/registry/manifest-scanner.js";
17
- import { parseConnectorManifestV6 } from "../../connectors/manifest/manifest-parser.js";
18
- import { connectorInit } from "../commands/connector-init.js";
19
- import { connectorBehaviorAdd } from "../commands/connector-behavior.js";
20
- import { connectorStatus, connectorTest } from "../commands/connector-status.js";
21
- import { goalCommand } from "../commands/goal.js";
22
- // v7 observability services (T-ROS.C.1)
23
- import { getSelfHealthSnapshot, ensureMinimumProbes, } from "../../observability/services/self-health-snapshot.js";
24
- import { generateHeartbeatDigest, } from "../../observability/services/heartbeat-digest-assembler.js";
25
- import { queryNarrativeTimeline, queryNarrativeDiff, NarrativeVersionNotFoundError, } from "../../observability/services/narrative-timeline-query-service.js";
26
- import { viewSecretAnchor, } from "../../observability/services/runtime-secret-anchor-view.js";
27
- import { writeRestoreAudit, } from "../../observability/services/restore-audit-service.js";
28
- import { createHistoryDigestStore } from "../../storage/services/history-digest-store.js";
29
- // T-ROS.C.3: ManualRunDispatcher and its deps
30
- import { createManualRunDispatcher, } from "./manual-run-dispatcher.js";
31
- import { createExperienceWriter } from "../../core/second-nature/body/tool-experience/experience-writer.js";
32
- import { createCapabilityProbeResultStore, createToolExperienceStore, } from "../../storage/services/tool-experience-store.js";
33
- import { createWetProbeRunner } from "../../connectors/base/wet-probe-runner.js";
34
- import { CapabilityContractRegistryV7 } from "../../connectors/base/manifest-v7.js";
35
- // v7 T-V7C.C.6: Dream scheduling deps for heartbeat_check quiet→dream auto-trigger
36
- import { scheduleDream } from "../../dream/dream-scheduler.js";
37
- import { createDreamInputLoader } from "../../dream/dream-input-loader.js";
38
- import { createDiaryDreamStore } from "../../storage/services/diary-dream-store.js";
39
- // v7 T-CP.C.3 / T-BTS.C.5: heartbeat loop policies and breaker
40
- import { createGoalLifecyclePolicy } from "../../core/second-nature/heartbeat/goal-lifecycle-policy.js";
41
- import { createIdleCuriosityPolicy } from "../../core/second-nature/heartbeat/idle-curiosity-policy.js";
42
- import { createCircuitBreakerManager } from "../../core/second-nature/body/circuit-breaker/circuit-breaker-manager.js";
43
- import { createProbeSignalAdapter } from "../../core/second-nature/body/probe-signal-adapter.js";
44
- function coerceProbeOnlyFlag(input) {
45
- const v = input?.probeOnly;
46
- return v === true || v === "true" || v === 1 || v === "1";
47
- }
48
- /**
49
- * v7 T-V7C.C.6: Build a minimal QuietDreamSchedulePort backed by the state DB.
50
- * When a source-backed Quiet write completes, this port triggers Dream scheduling
51
- * via the standard scheduleDream path (rules-only mode when no model port).
52
- */
53
- function createQuietDreamSchedulePort(state) {
54
- return {
55
- async scheduleDream({ triggerKind, runId, traceId }) {
56
- const dreamStore = createDiaryDreamStore(state);
57
- const inputLoader = createDreamInputLoader({ database: state });
58
- const statePort = {
59
- async loadDreamInputs(query) {
60
- return inputLoader.loadDreamInputs(query);
61
- },
62
- async writeDreamOutput(output) {
63
- // Bridge: dream-engine emits dream/types DreamOutput; diary-dream-store expects shared/types.
64
- // Structures are identical at runtime; TS strictness requires the cast.
65
- await dreamStore.appendDreamOutput(output);
66
- return { outputId: output.outputId, status: "acknowledged" };
67
- },
68
- async markDreamOutputLifecycle(input) {
69
- // transitionDreamOutputLifecycle only accepts accepted|archived.
70
- if (input.newStatus !== "accepted" && input.newStatus !== "archived") {
71
- return { outputId: input.outputId, status: "degraded" };
72
- }
73
- await dreamStore.transitionDreamOutputLifecycle(input.outputId, input.newStatus);
74
- return { outputId: input.outputId, status: "acknowledged" };
75
- },
76
- };
77
- const result = await scheduleDream({
78
- triggerKind,
79
- runId,
80
- traceId,
81
- statePort,
82
- windowKey: "quiet_completion",
83
- });
84
- return { status: result.status, reason: result.reason };
85
- },
86
- };
87
- }
88
- const SNAPSHOT_TABLE_BY_KIND = {
89
- identity_profile: "identity_profile",
90
- agent_goal: "agent_goal",
91
- tool_experience: "tool_experience",
92
- daily_diary: "daily_diary_index",
93
- dream_output: "dream_output_index",
94
- narrative_timeline: "narrative_timeline",
95
- };
96
- const DEFAULT_SNAPSHOT_KINDS = [
97
- "identity_profile",
98
- "agent_goal",
99
- "tool_experience",
100
- "daily_diary",
101
- "dream_output",
102
- "narrative_timeline",
103
- ];
104
- function coerceRestorableKinds(value) {
105
- if (!Array.isArray(value))
106
- return undefined;
107
- const valid = new Set(DEFAULT_SNAPSHOT_KINDS);
108
- return value.filter((item) => typeof item === "string" && valid.has(item));
109
- }
110
- function tableExists(state, table) {
111
- const result = state.sqlite.exec(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1`, [table]);
112
- return result.length > 0 && result[0].values.length > 0;
113
- }
114
- function readRowsFromTable(state, table) {
115
- const result = state.sqlite.exec(`SELECT * FROM ${table}`);
116
- if (result.length === 0 || result[0].values.length === 0)
117
- return [];
118
- const columns = result[0].columns;
119
- return result[0].values.map((row) => {
120
- const out = {};
121
- columns.forEach((column, index) => {
122
- out[column] = row[index];
123
- });
124
- return out;
125
- });
126
- }
127
- function stringArray(value) {
128
- return Array.isArray(value)
129
- ? value.filter((item) => typeof item === "string")
130
- : [];
131
- }
132
- function textInput(input, key) {
133
- const value = input?.[key];
134
- if (typeof value !== "string")
135
- return undefined;
136
- const trimmed = value.trim();
137
- return trimmed.length > 0 ? trimmed : undefined;
138
- }
139
- function buildSnapshotNarrativeDelta(input, snapshotId, rowCounts) {
140
- const explicit = input?.narrativeSnapshot &&
141
- typeof input.narrativeSnapshot === "object" &&
142
- !Array.isArray(input.narrativeSnapshot)
143
- ? input.narrativeSnapshot
144
- : {};
145
- const from = (key) => input?.[key] ?? explicit[key];
146
- const sourceRefs = stringArray(from("sourceRefs"));
147
- return {
148
- focus: from("focus") ?? "workspace_state",
149
- progress: from("progress") ??
150
- `snapshot_captured:${Object.entries(rowCounts)
151
- .map(([kind, count]) => `${kind}=${count}`)
152
- .join(",")}`,
153
- nextIntent: from("nextIntent") ?? "restore_ready",
154
- toneSignal: from("toneSignal") ?? "system_maintenance",
155
- acceptedGoalId: from("acceptedGoalId") ?? undefined,
156
- sourceRefs: sourceRefs.length > 0
157
- ? sourceRefs
158
- : [`restore_snapshot:${snapshotId}`, "runtime_ops:snapshot_capture"],
159
- reasonCode: from("reasonCode") ?? "snapshot_captured",
160
- summaryText: from("summaryText") ?? `Captured restore snapshot ${snapshotId}`,
161
- };
162
- }
163
- function hashNarrativeSnapshot(input) {
164
- return createHash("sha256")
165
- .update(JSON.stringify({
166
- previousHash: input.previousHash,
167
- snapshotId: input.snapshotId,
168
- delta: input.delta,
169
- createdAt: input.createdAt,
170
- }))
171
- .digest("hex");
172
- }
173
- function resolveManifestPath(manifestPath, workspaceRoot) {
174
- if (path.isAbsolute(manifestPath))
175
- return manifestPath;
176
- return path.join(workspaceRoot ?? process.cwd(), manifestPath);
177
- }
178
- function registerConnectorForWetProbe(input) {
179
- if (input.entry.manifestPath) {
180
- try {
181
- const manifestText = fs.readFileSync(resolveManifestPath(input.entry.manifestPath, input.workspaceRoot), "utf-8");
182
- const parsed = JSON.parse(manifestText);
183
- const registered = input.registryV7.register(parsed);
184
- if (registered.ok && input.registryV7.hasCapability(input.entry.platformId, input.selectedCapabilityId)) {
185
- return;
186
- }
187
- }
188
- catch {
189
- // Non-v7 or YAML workspace manifests are projected below.
190
- }
191
- }
192
- input.registryV7.register({
193
- platformId: input.entry.platformId,
194
- capabilities: input.entry.capabilities.map((capabilityId) => ({
195
- capabilityId,
196
- intent: capabilityId,
197
- probeConfig: capabilityId === input.selectedCapabilityId && input.safeEndpoint
198
- ? {
199
- safeEndpoint: input.safeEndpoint,
200
- idempotencyClass: "read_only",
201
- }
202
- : undefined,
203
- })),
204
- channelPriority: ["runtime_ops"],
205
- credentialTypes: ["runtime_ops_probe"],
206
- });
207
- }
208
- async function captureRuntimeSnapshot(deps, input) {
209
- const generatedAt = new Date().toISOString();
210
- if (!deps.state || !deps.restoreSnapshotStore) {
211
- return {
212
- ok: false,
213
- command: "snapshot:capture",
214
- runtimeMode: "unavailable",
215
- surfaceMode: "cli",
216
- generatedAt,
217
- error: {
218
- code: "SNAPSHOT_CAPTURE_DEPS_UNAVAILABLE",
219
- message: "snapshot:capture requires state DB and RestoreSnapshotStore in OpsRouterDeps",
220
- nextStep: "wire_state_and_restore_snapshot_store_into_ops_router",
221
- },
222
- warnings: [],
223
- sourceRefs: [],
224
- };
225
- }
226
- const snapshotId = textInput(input, "snapshotId") ??
227
- `snapshot:${Date.now()}:${Math.random().toString(36).slice(2, 8)}`;
228
- const requestedKinds = coerceRestorableKinds(input?.entityWhitelist) ?? [...DEFAULT_SNAPSHOT_KINDS];
229
- const rowCounts = {};
230
- const warnings = [];
231
- for (const kind of requestedKinds) {
232
- const table = SNAPSHOT_TABLE_BY_KIND[kind];
233
- if (!tableExists(deps.state, table)) {
234
- rowCounts[kind] = 0;
235
- warnings.push(`table_missing:${kind}:${table}`);
236
- continue;
237
- }
238
- rowCounts[kind] = readRowsFromTable(deps.state, table).length;
239
- }
240
- const historyStore = createHistoryDigestStore(deps.state);
241
- const previousHash = (await historyStore.listNarrativeTimeline({ limit: 1 }))[0]?.currentHash ?? "";
242
- const delta = buildSnapshotNarrativeDelta(input, snapshotId, rowCounts);
243
- const currentHash = hashNarrativeSnapshot({
244
- previousHash,
245
- snapshotId,
246
- delta,
247
- createdAt: generatedAt,
248
- });
249
- await historyStore.appendNarrativeTimeline({
250
- timelineId: snapshotId,
251
- entryType: "owner.override",
252
- subjectId: textInput(input, "subjectId") ?? snapshotId,
253
- delta,
254
- previousHash,
255
- currentHash,
256
- createdAt: generatedAt,
257
- });
258
- const payload = {};
259
- const capturedKinds = [];
260
- for (const kind of requestedKinds) {
261
- const table = SNAPSHOT_TABLE_BY_KIND[kind];
262
- if (!tableExists(deps.state, table))
263
- continue;
264
- const rows = readRowsFromTable(deps.state, table);
265
- rowCounts[kind] = rows.length;
266
- if (rows.length > 0) {
267
- payload[kind] = rows;
268
- capturedKinds.push(kind);
269
- }
270
- }
271
- const snapshot = await deps.restoreSnapshotStore.captureSnapshot({
272
- snapshotId,
273
- entityWhitelist: requestedKinds,
274
- payload,
275
- capturedAt: generatedAt,
276
- });
277
- return {
278
- ok: true,
279
- command: "snapshot:capture",
280
- runtimeMode: "workspace_full_runtime",
281
- surfaceMode: "cli",
282
- generatedAt,
283
- data: {
284
- snapshotId: snapshot.snapshotId,
285
- capturedAt: snapshot.capturedAt,
286
- entityWhitelist: snapshot.entityWhitelist,
287
- capturedKinds,
288
- rowCounts,
289
- narrativeVersion: snapshotId,
290
- },
291
- warnings,
292
- sourceRefs: [
293
- "storage/services/restore-snapshot-store.ts",
294
- "storage/services/history-digest-store.ts",
295
- ],
296
- };
297
- }
298
- /**
299
- * T1.2.8 — static local adapter: all checks return `unknown` when no real host is available.
300
- * Allows `capability_probe` to be called from CLI / workspace bridge without requiring a live host.
301
- */
302
- function createStaticUnknownAdapter(workspaceRoot) {
303
- const now = new Date().toISOString();
304
- const unknownResult = (name) => ({
305
- name,
306
- verdict: "unknown",
307
- observedAt: now,
308
- reason: "static_local_probe_no_host_context",
309
- evidenceRefs: [],
310
- });
311
- function checkDeliveryTarget() {
312
- if (!workspaceRoot) {
313
- return { status: "target_none", evidenceRefs: [], reason: "no_workspace_root_provided" };
314
- }
315
- const deliveryCapabilities = ["message.send", "comment.reply"];
316
- const scanned = scanConnectorManifests(workspaceRoot);
317
- for (const manifestFile of scanned) {
318
- const parsed = parseConnectorManifestV6(manifestFile.content, manifestFile.path);
319
- if (parsed.ok && parsed.manifest.capabilities.some((cap) => deliveryCapabilities.includes(cap.id))) {
320
- return {
321
- status: "target_available",
322
- evidenceRefs: [
323
- {
324
- id: `delivery:${parsed.manifest.platformId}`,
325
- kind: "workspace_artifact",
326
- uri: `workspace://connectors/${parsed.manifest.platformId}/manifest.yaml`,
327
- observedAt: now,
328
- },
329
- ],
330
- };
331
- }
332
- }
333
- return { status: "target_none", evidenceRefs: [], reason: "no_delivery_connector_found_in_workspace" };
334
- }
335
- return {
336
- checkPluginLoad: () => unknownResult("plugin_load"),
337
- checkHeartbeatBridge: () => unknownResult("heartbeat_bridge"),
338
- checkHeartbeatToolInvocation: () => unknownResult("heartbeat_tool_invocation"),
339
- checkDeliveryTarget,
340
- checkAckDropBehavior: () => unknownResult("ack_drop"),
341
- checkHookSupport: () => [],
342
- };
343
- }
344
- export function createOpsRouter(deps) {
345
- return {
346
- heartbeatCheck: (input) => heartbeatCheck({
347
- ...input,
348
- runtimeAvailable: input.runtimeAvailable ?? deps.runtimeAvailable,
349
- readModels: input.readModels ?? deps.readModels,
350
- runtimeRecorder: input.runtimeRecorder ?? deps.runtimeRecorder,
351
- state: input.state ?? deps.state,
352
- workspaceRoot: input.workspaceRoot ?? deps.workspaceRoot,
353
- connectorExecutor: input.connectorExecutor ?? deps.connectorExecutor,
354
- connectorRegistry: input
355
- ?.connectorRegistry ?? deps.connectorRegistry,
356
- digestOpts: input.digestOpts,
357
- dreamSchedulePort: input.dreamSchedulePort,
358
- }),
359
- async dispatch(command, input) {
360
- if (command === "heartbeat_check") {
361
- const runtimeAvailable = typeof input?.runtimeAvailable === "boolean"
362
- ? input.runtimeAvailable
363
- : deps.runtimeAvailable;
364
- // v7 T-V7C.C.2: assemble affordance map and experience writer for breaker-aware heartbeat.
365
- let affordanceMap;
366
- if (deps.toolAffordancePort) {
367
- try {
368
- affordanceMap = await deps.toolAffordancePort.assembleAffordanceMap({});
369
- }
370
- catch {
371
- // degrade gracefully; guard-layer will skip breaker check without affordanceMap
372
- }
373
- }
374
- let experienceWriter;
375
- if (deps.state) {
376
- experienceWriter = createExperienceWriter(createToolExperienceStore(deps.state));
377
- }
378
- // v7 T-V7C.C.6: assemble digest opts when auditStore is wired.
379
- let digestOpts;
380
- if (deps.auditStore) {
381
- digestOpts = {
382
- assemblerDeps: {
383
- auditStore: deps.auditStore,
384
- ...deps.heartbeatDigestDeps,
385
- },
386
- };
387
- }
388
- // v7 T-V7C.C.6: assemble dream schedule port when state DB is wired.
389
- let dreamSchedulePort;
390
- if (deps.state) {
391
- dreamSchedulePort = createQuietDreamSchedulePort(deps.state);
392
- }
393
- // v7 T-CP.C.3: assemble goal lifecycle and idle curiosity policies.
394
- const goalLifecyclePolicy = createGoalLifecyclePolicy();
395
- const idleCuriosityPolicy = createIdleCuriosityPolicy();
396
- // v7 T-BTS.C.5: assemble circuit breaker manager when state DB is wired.
397
- let circuitBreakerManager;
398
- if (deps.state) {
399
- const probeResultStore = createCapabilityProbeResultStore(deps.state);
400
- const toolExpStore = createToolExperienceStore(deps.state);
401
- const probeAdapter = createProbeSignalAdapter({
402
- wetProbeRunner: createWetProbeRunner(),
403
- probeResultStore,
404
- toolExperienceStore: toolExpStore,
405
- });
406
- const registryV7 = new CapabilityContractRegistryV7();
407
- circuitBreakerManager = createCircuitBreakerManager({
408
- database: deps.state,
409
- probeAdapter,
410
- registry: registryV7,
411
- });
412
- }
413
- try {
414
- const result = await heartbeatCheck({
415
- probeOnly: coerceProbeOnlyFlag(input),
416
- runtimeAvailable,
417
- fakeControlPlanePassthrough: input?.fakeControlPlanePassthrough &&
418
- typeof input.fakeControlPlanePassthrough === "object"
419
- ? input.fakeControlPlanePassthrough
420
- : undefined,
421
- readModels: input?.readModels ??
422
- deps.readModels,
423
- runtimeRecorder: input
424
- ?.runtimeRecorder ?? deps.runtimeRecorder,
425
- state: input?.state ??
426
- deps.state,
427
- workspaceRoot: input
428
- ?.workspaceRoot ?? deps.workspaceRoot,
429
- timestamp: typeof input?.timestamp === "string" ? input.timestamp : undefined,
430
- sessionContext: typeof input?.sessionContext === "string"
431
- ? input.sessionContext
432
- : undefined,
433
- scopeHint: input?.scopeHint,
434
- connectorExecutor: input
435
- ?.connectorExecutor ?? deps.connectorExecutor,
436
- connectorRegistry: input
437
- ?.connectorRegistry ?? deps.connectorRegistry,
438
- affordanceMap,
439
- experienceWriter,
440
- digestOpts,
441
- dreamSchedulePort,
442
- goalLifecyclePolicy,
443
- idleCuriosityPolicy,
444
- circuitBreakerManager,
445
- });
446
- if (result.ok &&
447
- result.surfaceMode === "workspace_full_runtime" &&
448
- !coerceProbeOnlyFlag(input) &&
449
- deps.state &&
450
- deps.restoreSnapshotStore) {
451
- try {
452
- const capture = await captureRuntimeSnapshot(deps, {
453
- snapshotId: `heartbeat:${result.decisionId ?? "cycle"}:${Date.now()}`,
454
- subjectId: result.decisionId ?? "heartbeat_check",
455
- reasonCode: "heartbeat_check",
456
- summaryText: `Heartbeat ${result.status} captured bounded restore snapshot`,
457
- focus: result.status,
458
- progress: result.reasons.join(",") || "heartbeat_completed",
459
- nextIntent: "continue_runtime_loop",
460
- sourceRefs: result.decisionId
461
- ? [`heartbeat:${result.decisionId}`]
462
- : ["heartbeat:runtime"],
463
- });
464
- if (capture.ok) {
465
- result.reasons = [...result.reasons, "restore_snapshot_captured"];
466
- }
467
- }
468
- catch (err) {
469
- const msg = err instanceof Error ? err.message : String(err);
470
- result.reasons = [...result.reasons, `restore_snapshot_capture_failed:${msg}`];
471
- }
472
- }
473
- return result;
474
- }
475
- catch (err) {
476
- const msg = err instanceof Error ? err.message : String(err);
477
- const envelope = {
478
- ok: false,
479
- command: "heartbeat_check",
480
- runtimeMode: runtimeAvailable ? "workspace_full_runtime" : "unavailable",
481
- surfaceMode: "cli",
482
- generatedAt: new Date().toISOString(),
483
- error: {
484
- code: "HEARTBEAT_CYCLE_EXCEPTION",
485
- message: `heartbeat_check cycle threw unexpectedly: ${msg.slice(0, 200)}`,
486
- nextStep: "check_logs_and_report",
487
- },
488
- warnings: [],
489
- sourceRefs: [],
490
- };
491
- return envelope;
492
- }
493
- }
494
- if (command === "fallback") {
495
- const ref = typeof input?.ref === "string" ? input.ref.trim() : "";
496
- if (!ref) {
497
- return {
498
- ok: false,
499
- error: {
500
- code: "MISSING_FALLBACK_REF",
501
- message: "fallback requires args.ref (e.g. fallback:…)",
502
- requiredUserInput: ["ref"],
503
- nextStep: "reinvoke_with_ref",
504
- },
505
- };
506
- }
507
- if (!deps.readModels?.loadFallbackView) {
508
- return {
509
- ok: false,
510
- error: {
511
- code: "FALLBACK_READ_MODEL_UNAVAILABLE",
512
- message: "Operator fallback view requires workspace read models",
513
- requiredUserInput: ["ref"],
514
- nextStep: "wire_read_models_into_ops_router",
515
- },
516
- };
517
- }
518
- return (async () => {
519
- try {
520
- const data = await showOperatorFallback(ref, deps.readModels);
521
- return { ok: true, command: "fallback", data };
522
- }
523
- catch (error) {
524
- if (error instanceof OperatorFallbackNotFoundError) {
525
- return {
526
- ok: false,
527
- command: "fallback",
528
- error: {
529
- code: error.code,
530
- message: error.message,
531
- requiredUserInput: ["ref"],
532
- nextStep: "verify_fallback_ref_from_delivery_audit",
533
- },
534
- };
535
- }
536
- throw error;
537
- }
538
- })();
539
- }
540
- if (command === "capability_probe") {
541
- // T1.2.8 (SN-CODE-03): run host capability probe with static unknown adapter (CLI context).
542
- // Persists report when observabilityDb is available; returns safe JSON subset.
543
- return (async () => {
544
- const adapter = createStaticUnknownAdapter(deps.workspaceRoot);
545
- const docCheckedAt = new Date().toISOString();
546
- const report = probeHostCapability({
547
- adapter,
548
- docLinks: [],
549
- docCheckedAt,
550
- });
551
- if (deps.observabilityDb) {
552
- await recordHostCapability(deps.observabilityDb, report);
553
- }
554
- return {
555
- ok: true,
556
- command: "capability_probe",
557
- data: {
558
- reportId: report.reportId,
559
- generatedAt: report.generatedAt,
560
- deliveryTarget: report.deliveryTarget,
561
- pluginLoad: { verdict: report.pluginLoad.verdict },
562
- heartbeatBridge: { verdict: report.heartbeatBridge.verdict },
563
- heartbeatToolInvocation: {
564
- verdict: report.heartbeatToolInvocation.verdict,
565
- },
566
- ackDropBehavior: { verdict: report.ackDropBehavior.verdict },
567
- conflictCount: report.conflictRecords.length,
568
- recommendedNextStep: report.recommendedNextStep,
569
- note: "static_local_probe: all verdicts are unknown without live host context",
570
- },
571
- };
572
- })();
573
- }
574
- if (command === "near_real_smoke") {
575
- // T3.3.2 (SN-CODE-05): wrap runNearRealConnectorSmoke as an ops surface command.
576
- // Requires state + observabilityDb + workspaceRoot to be wired into OpsRouterDeps.
577
- if (!deps.state || !deps.observabilityDb || !deps.workspaceRoot) {
578
- return {
579
- ok: false,
580
- command: "near_real_smoke",
581
- error: {
582
- code: "NEAR_REAL_SMOKE_DEPS_UNAVAILABLE",
583
- message: "near_real_smoke requires state, observabilityDb, and workspaceRoot in OpsRouterDeps",
584
- nextStep: "wire_deps_into_ops_router",
585
- },
586
- };
587
- }
588
- return (async () => {
589
- const result = await runNearRealConnectorSmoke({
590
- state: deps.state,
591
- observabilityDb: deps.observabilityDb,
592
- workspaceRoot: deps.workspaceRoot,
593
- });
594
- return {
595
- ok: true,
596
- command: "near_real_smoke",
597
- data: result,
598
- };
599
- })();
600
- }
601
- if (command === "connector_init") {
602
- // T1.3.1 (SN-CODE-06): generate connector manifest stub.
603
- return (async () => {
604
- const result = await connectorInit({
605
- platformId: typeof input?.platformId === "string" ? input.platformId : "",
606
- family: typeof input?.family === "string"
607
- ? input.family
608
- : undefined,
609
- displayName: typeof input?.displayName === "string" ? input.displayName : undefined,
610
- runnerKind: typeof input?.runnerKind === "string"
611
- ? input.runnerKind
612
- : undefined,
613
- force: Boolean(input?.force),
614
- workspaceRoot: deps.workspaceRoot,
615
- });
616
- return result;
617
- })();
618
- }
619
- if (command === "connector_behavior_add") {
620
- return connectorBehaviorAdd({
621
- platformId: typeof input?.platformId === "string" ? input.platformId : "",
622
- behaviorId: typeof input?.behaviorId === "string"
623
- ? input.behaviorId
624
- : typeof input?.capabilityId === "string"
625
- ? input.capabilityId
626
- : "",
627
- description: typeof input?.description === "string" ? input.description : undefined,
628
- channel: typeof input?.channel === "string" ? input.channel : undefined,
629
- sourceRefs: input?.sourceRefs,
630
- observedCount: typeof input?.observedCount === "number" ? input.observedCount : undefined,
631
- workspaceRoot: typeof input?.workspaceRoot === "string"
632
- ? input.workspaceRoot
633
- : deps.workspaceRoot,
634
- });
635
- }
636
- if (command === "connector_status") {
637
- return connectorStatus(deps.registry, undefined, {
638
- includeHealth: Boolean(input?.includeHealth),
639
- workspaceRoot: typeof input?.workspaceRoot === "string"
640
- ? input.workspaceRoot
641
- : deps.workspaceRoot,
642
- });
643
- }
644
- if (command === "connector_test") {
645
- // v7 T-V7C.C.1: dryRun=false is the canonical wet probe switch.
646
- const isWet = input?.wet === true ||
647
- input?.wet === "true" ||
648
- input?.dryRun === false ||
649
- input?.dryRun === "false";
650
- const result = await connectorTest(deps.registry, {
651
- platformId: typeof input?.platformId === "string" ? input.platformId : "",
652
- dryRun: isWet ? false : (input?.dryRun === false ? false : true),
653
- workspaceRoot: typeof input?.workspaceRoot === "string"
654
- ? input.workspaceRoot
655
- : deps.workspaceRoot,
656
- });
657
- if (!isWet || !result.ok) {
658
- return result;
659
- }
660
- const data = result.data && typeof result.data === "object"
661
- ? result.data
662
- : {};
663
- const capabilities = Array.isArray(data.capabilities)
664
- ? data.capabilities.filter((item) => typeof item === "string")
665
- : [];
666
- const capabilityId = textInput(input, "capabilityId") ?? capabilities[0] ?? "";
667
- if (!capabilityId) {
668
- return {
669
- ok: false,
670
- command: "connector_test",
671
- error: {
672
- code: "MISSING_CAPABILITY_ID",
673
- message: "wet connector_test requires capabilityId or at least one connector capability",
674
- requiredUserInput: ["capabilityId"],
675
- nextStep: "reinvoke_with_capability_id",
676
- },
677
- };
678
- }
679
- const platformId = String(data.platformId ?? input?.platformId ?? "");
680
- const registryEntry = deps.registry?.describeConnector(platformId);
681
- if (!registryEntry) {
682
- return result;
683
- }
684
- const registryV7 = new CapabilityContractRegistryV7();
685
- registerConnectorForWetProbe({
686
- registryV7,
687
- entry: {
688
- platformId: registryEntry.platformId,
689
- capabilities: registryEntry.capabilities,
690
- manifestPath: registryEntry.manifestPath,
691
- },
692
- workspaceRoot: typeof input?.workspaceRoot === "string"
693
- ? input.workspaceRoot
694
- : deps.workspaceRoot,
695
- selectedCapabilityId: capabilityId,
696
- safeEndpoint: textInput(input, "safeEndpoint"),
697
- });
698
- const wetResult = await createWetProbeRunner().runWetProbe(platformId, capabilityId, registryV7);
699
- const warnings = [];
700
- let persistedProbeResult = false;
701
- if (deps.state) {
702
- await createCapabilityProbeResultStore(deps.state).appendProbeResult(wetResult.probeResult);
703
- persistedProbeResult = true;
704
- }
705
- else {
706
- warnings.push("state_db_unavailable:capability_probe_result_not_persisted");
707
- }
708
- return {
709
- // T-V7C.C.5: only "available" (HTTP 200-299) counts as success;
710
- // "degraded" (429/503) and "unavailable" both result in ok=false.
711
- ok: wetResult.probeResult.actualStatus === "available",
712
- command: "connector_test",
713
- data: {
714
- ...data,
715
- dryRun: false,
716
- capabilityId,
717
- actualStatus: wetResult.probeResult.actualStatus,
718
- httpStatus: wetResult.probeResult.httpStatus ?? wetResult.httpStatus,
719
- probeResultId: wetResult.probeResult.probeResultId,
720
- probeConfigRef: wetResult.probeResult.probeConfigRef,
721
- sampleResponseRef: wetResult.probeResult.sampleResponseRef,
722
- persistedProbeResult,
723
- triggerSource: "manual_run",
724
- affectsHeartbeatCadence: false,
725
- note: "wet probe mode: executed safe probe endpoint and persisted capability_probe_result when state DB is available",
726
- },
727
- warnings,
728
- };
729
- }
730
- if (command === "connector:run") {
731
- // T-ROS.C.3: manual connector execution — isolated from heartbeat cadence
732
- const platformId = typeof input?.platformId === "string" ? input.platformId : "";
733
- const capabilityId = typeof input?.capabilityId === "string" ? input.capabilityId : "";
734
- if (!platformId || !capabilityId) {
735
- return {
736
- ok: false,
737
- command: "connector:run",
738
- error: {
739
- code: "MISSING_PLATFORM_OR_CAPABILITY_ID",
740
- message: "connector:run requires platformId and capabilityId",
741
- requiredUserInput: ["platformId", "capabilityId"],
742
- nextStep: "reinvoke_with_platform_and_capability_id",
743
- },
744
- };
745
- }
746
- if (!deps.connectorExecutor || !deps.state) {
747
- return {
748
- ok: false,
749
- command: "connector:run",
750
- error: {
751
- code: "MANUAL_RUN_DEPS_UNAVAILABLE",
752
- message: "connector:run requires connectorExecutor and state database",
753
- nextStep: "wire_connector_executor_and_state_into_ops_router",
754
- },
755
- };
756
- }
757
- const toolExperienceStore = createToolExperienceStore(deps.state);
758
- const experienceWriter = createExperienceWriter(toolExperienceStore);
759
- const wetProbeRunner = createWetProbeRunner();
760
- const registryV7 = new CapabilityContractRegistryV7();
761
- // Populate V7 registry from dynamic registry if available (best-effort)
762
- if (deps.registry) {
763
- for (const entry of deps.registry.listConnectors()) {
764
- if (entry.manifestPath) {
765
- try {
766
- const manifestText = fs.readFileSync(entry.manifestPath, "utf-8");
767
- const manifest = JSON.parse(manifestText);
768
- registryV7.register(manifest);
769
- }
770
- catch {
771
- // Skip manifests that can't be read or don't validate as V7
772
- }
773
- }
774
- }
775
- }
776
- const dispatcher = createManualRunDispatcher({
777
- connectorExecutor: deps.connectorExecutor,
778
- experienceWriter,
779
- wetProbeRunner,
780
- registryV7,
781
- });
782
- return dispatcher.runConnector({
783
- platformId,
784
- capabilityId,
785
- payload: typeof input?.payload === "object" && input?.payload !== null
786
- ? input.payload
787
- : undefined,
788
- caller: typeof input?.caller === "string" ? input.caller : undefined,
789
- reason: typeof input?.reason === "string" ? input.reason : undefined,
790
- });
791
- }
792
- if (command === "goal") {
793
- const rawAction = typeof input?.action === "string" ? input.action : "list";
794
- const action = ["set", "list", "accept", "reject"].includes(rawAction)
795
- ? rawAction
796
- : "list";
797
- const sanitizeText = (v, maxLen = 1000) => {
798
- if (typeof v !== "string")
799
- return undefined;
800
- const trimmed = v.trim();
801
- if (trimmed.length === 0)
802
- return undefined;
803
- return trimmed.slice(0, maxLen);
804
- };
805
- return goalCommand(deps.state, {
806
- action,
807
- goalId: typeof input?.goalId === "string" ? input.goalId.trim().slice(0, 128) : undefined,
808
- description: sanitizeText(input?.description),
809
- completionCriteria: sanitizeText(input?.completionCriteria),
810
- // T1.4.2: criteria alias for completionCriteria
811
- criteria: sanitizeText(input?.criteria),
812
- risk: typeof input?.risk === "string"
813
- ? input.risk
814
- : undefined,
815
- kind: typeof input?.kind === "string"
816
- ? input.kind
817
- : undefined,
818
- statusFilter: typeof input?.statusFilter === "string" ? input.statusFilter : undefined,
819
- originFilter: typeof input?.originFilter === "string" ? input.originFilter : undefined,
820
- limit: typeof input?.limit === "number" ? input.limit : undefined,
821
- });
822
- }
823
- if (command === "dream:recent") {
824
- if (!deps.readModels) {
825
- return {
826
- ok: false,
827
- error: {
828
- code: "READ_MODELS_UNAVAILABLE",
829
- message: "dream:recent requires workspace read models",
830
- nextStep: "wire_read_models_into_ops_router",
831
- },
832
- };
833
- }
834
- const limit = typeof input?.limit === "number" ? input.limit : 5;
835
- const data = await deps.readModels.loadDreamRecent(limit);
836
- return { ok: true, data };
837
- }
838
- if (command === "cycle:recent") {
839
- if (!deps.readModels) {
840
- return {
841
- ok: false,
842
- error: {
843
- code: "READ_MODELS_UNAVAILABLE",
844
- message: "cycle:recent requires workspace read models",
845
- nextStep: "wire_read_models_into_ops_router",
846
- },
847
- };
848
- }
849
- const limit = typeof input?.limit === "number" ? input.limit : 5;
850
- const data = await deps.readModels.loadCycleRecent(limit);
851
- return { ok: true, data };
852
- }
853
- // ─── v7 commands (T-ROS.C.1) ─────────────────────────────────────────
854
- /** [G2] self_health — transparent pass-through from SelfHealthSnapshot (DR-042). */
855
- if (command === "self_health") {
856
- const generatedAt = new Date().toISOString();
857
- try {
858
- ensureMinimumProbes();
859
- const snap = await getSelfHealthSnapshot();
860
- const degraded_dimensions = Object.entries(snap.dimensions)
861
- .filter(([, d]) => d.status === "degraded")
862
- .map(([k]) => k);
863
- const envelope = {
864
- ok: true,
865
- command: "self_health",
866
- runtimeMode: "workspace_full_runtime",
867
- surfaceMode: "cli",
868
- generatedAt,
869
- data: {
870
- overall: snap.overall,
871
- generatedAt: snap.generatedAt,
872
- degraded_dimensions,
873
- dimensions: snap.dimensions,
874
- },
875
- warnings: [],
876
- sourceRefs: ["observability/services/self-health-snapshot.ts"],
877
- };
878
- return envelope;
879
- }
880
- catch (err) {
881
- const msg = err instanceof Error ? err.message : String(err);
882
- const envelope = {
883
- ok: false,
884
- command: "self_health",
885
- runtimeMode: "unavailable",
886
- surfaceMode: "cli",
887
- generatedAt,
888
- error: { code: "SELF_HEALTH_PROBE_FAILED", message: msg },
889
- warnings: [],
890
- sourceRefs: [],
891
- };
892
- return envelope;
893
- }
894
- }
895
- /**
896
- * [G3] tool_affordance — body-tool AffordanceMap pass-through.
897
- * Port not yet wired in this wave; returns degraded view with clear next-step.
898
- */
899
- if (command === "tool_affordance") {
900
- const generatedAt = new Date().toISOString();
901
- if (deps.toolAffordancePort) {
902
- const allStatuses = [
903
- "safe",
904
- "exploratory",
905
- "needs_auth",
906
- "painful",
907
- "unavailable",
908
- ];
909
- const platformIds = Array.isArray(input?.platformIds)
910
- ? input.platformIds.filter((item) => typeof item === "string")
911
- : typeof input?.platformId === "string"
912
- ? [input.platformId]
913
- : undefined;
914
- const data = await deps.toolAffordancePort.assembleAffordanceMap({
915
- platformIds,
916
- allowedStatuses: allStatuses,
917
- goalKind: typeof input?.goalKind === "string" ? input.goalKind : undefined,
918
- });
919
- const envelope = {
920
- ok: true,
921
- command: "tool_affordance",
922
- runtimeMode: "workspace_full_runtime",
923
- surfaceMode: "cli",
924
- generatedAt,
925
- data,
926
- warnings: [],
927
- sourceRefs: [
928
- "core/second-nature/body/tool-affordance/affordance-assembler.ts",
929
- ],
930
- };
931
- return envelope;
932
- }
933
- const envelope = {
934
- ok: false,
935
- command: "tool_affordance",
936
- runtimeMode: "unavailable",
937
- surfaceMode: "cli",
938
- generatedAt,
939
- error: {
940
- code: "TOOL_AFFORDANCE_PORT_UNWIRED",
941
- message: "tool_affordance requires body-tool AffordanceMap port (T-BTS.C.1) to be wired into OpsRouterDeps",
942
- nextStep: "wire_body_tool_port_into_ops_router_deps",
943
- },
944
- warnings: [],
945
- sourceRefs: [],
946
- };
947
- return envelope;
948
- }
949
- /**
950
- * [G6] heartbeat_digest — wraps generateHeartbeatDigest.
951
- * Requires auditStore in deps; degrades if unavailable.
952
- */
953
- if (command === "heartbeat_digest") {
954
- const generatedAt = new Date().toISOString();
955
- if (!deps.auditStore) {
956
- const envelope = {
957
- ok: false,
958
- command: "heartbeat_digest",
959
- runtimeMode: "unavailable",
960
- surfaceMode: "cli",
961
- generatedAt,
962
- error: {
963
- code: "AUDIT_STORE_UNAVAILABLE",
964
- message: "heartbeat_digest requires auditStore in OpsRouterDeps",
965
- nextStep: "wire_audit_store_into_ops_router",
966
- },
967
- warnings: [],
968
- sourceRefs: [],
969
- };
970
- return envelope;
971
- }
972
- const date = typeof input?.date === "string" && input.date
973
- ? input.date
974
- : new Date().toISOString().slice(0, 10);
975
- try {
976
- const digestDeps = {
977
- auditStore: deps.auditStore,
978
- ...deps.heartbeatDigestDeps,
979
- };
980
- const digest = await generateHeartbeatDigest(date, digestDeps);
981
- const envelope = {
982
- ok: true,
983
- command: "heartbeat_digest",
984
- runtimeMode: "workspace_full_runtime",
985
- surfaceMode: "cli",
986
- generatedAt,
987
- data: digest,
988
- warnings: [],
989
- sourceRefs: ["observability/services/heartbeat-digest-assembler.ts"],
990
- };
991
- return envelope;
992
- }
993
- catch (err) {
994
- const msg = err instanceof Error ? err.message : String(err);
995
- const envelope = {
996
- ok: false,
997
- command: "heartbeat_digest",
998
- runtimeMode: "unavailable",
999
- surfaceMode: "cli",
1000
- generatedAt,
1001
- error: { code: "DIGEST_GENERATION_FAILED", message: msg },
1002
- warnings: [],
1003
- sourceRefs: [],
1004
- };
1005
- return envelope;
1006
- }
1007
- }
1008
- /**
1009
- * [G6] snapshot:capture — production capture path for RestoreSnapshot +
1010
- * NarrativeTimeline. This gives restore and narrative:diff real state to consume.
1011
- */
1012
- if (command === "snapshot:capture") {
1013
- return captureRuntimeSnapshot(deps, input);
1014
- }
1015
- /**
1016
- * [G6] narrative:diff — queryNarrativeDiff between two versions.
1017
- * Requires narrativeTimelineDeps in OpsRouterDeps.
1018
- */
1019
- if (command === "narrative:diff") {
1020
- const generatedAt = new Date().toISOString();
1021
- if (!deps.narrativeTimelineDeps) {
1022
- const envelope = {
1023
- ok: false,
1024
- command: "narrative:diff",
1025
- runtimeMode: "unavailable",
1026
- surfaceMode: "cli",
1027
- generatedAt,
1028
- error: {
1029
- code: "NARRATIVE_TIMELINE_PORT_UNAVAILABLE",
1030
- message: "narrative:diff requires narrativeTimelineDeps in OpsRouterDeps",
1031
- nextStep: "wire_narrative_timeline_deps_into_ops_router",
1032
- },
1033
- warnings: [],
1034
- sourceRefs: [],
1035
- };
1036
- return envelope;
1037
- }
1038
- const fromVersion = typeof input?.from === "string" ? input.from : "";
1039
- const toVersion = typeof input?.to === "string" ? input.to : "";
1040
- if (!fromVersion || !toVersion) {
1041
- const envelope = {
1042
- ok: false,
1043
- command: "narrative:diff",
1044
- runtimeMode: "workspace_full_runtime",
1045
- surfaceMode: "cli",
1046
- generatedAt,
1047
- error: {
1048
- code: "MISSING_VERSIONS",
1049
- message: "narrative:diff requires 'from' and 'to' version arguments",
1050
- nextStep: "reinvoke_with_from_and_to",
1051
- },
1052
- warnings: [],
1053
- sourceRefs: [],
1054
- };
1055
- return envelope;
1056
- }
1057
- try {
1058
- const diff = await queryNarrativeDiff(fromVersion, toVersion, deps.narrativeTimelineDeps);
1059
- const envelope = {
1060
- ok: true,
1061
- command: "narrative:diff",
1062
- runtimeMode: "workspace_full_runtime",
1063
- surfaceMode: "cli",
1064
- generatedAt,
1065
- data: diff,
1066
- warnings: [],
1067
- sourceRefs: ["observability/services/narrative-timeline-query-service.ts"],
1068
- };
1069
- return envelope;
1070
- }
1071
- catch (err) {
1072
- if (err instanceof NarrativeVersionNotFoundError) {
1073
- const envelope = {
1074
- ok: false,
1075
- command: "narrative:diff",
1076
- runtimeMode: "workspace_full_runtime",
1077
- surfaceMode: "cli",
1078
- generatedAt,
1079
- error: {
1080
- code: "NARRATIVE_VERSION_NOT_FOUND",
1081
- message: err.message,
1082
- nextStep: "verify_version_exists_in_timeline",
1083
- },
1084
- warnings: [],
1085
- sourceRefs: [],
1086
- };
1087
- return envelope;
1088
- }
1089
- const msg = err instanceof Error ? err.message : String(err);
1090
- const envelope = {
1091
- ok: false,
1092
- command: "narrative:diff",
1093
- runtimeMode: "unavailable",
1094
- surfaceMode: "cli",
1095
- generatedAt,
1096
- error: { code: "NARRATIVE_DIFF_FAILED", message: msg },
1097
- warnings: [],
1098
- sourceRefs: [],
1099
- };
1100
- return envelope;
1101
- }
1102
- }
1103
- /**
1104
- * [G6] timeline — queryNarrativeTimeline with cursor pagination.
1105
- * Requires narrativeTimelineDeps in OpsRouterDeps.
1106
- */
1107
- if (command === "timeline") {
1108
- const generatedAt = new Date().toISOString();
1109
- if (!deps.narrativeTimelineDeps) {
1110
- const envelope = {
1111
- ok: false,
1112
- command: "timeline",
1113
- runtimeMode: "unavailable",
1114
- surfaceMode: "cli",
1115
- generatedAt,
1116
- error: {
1117
- code: "NARRATIVE_TIMELINE_PORT_UNAVAILABLE",
1118
- message: "timeline requires narrativeTimelineDeps in OpsRouterDeps",
1119
- nextStep: "wire_narrative_timeline_deps_into_ops_router",
1120
- },
1121
- warnings: [],
1122
- sourceRefs: [],
1123
- };
1124
- return envelope;
1125
- }
1126
- const now = new Date();
1127
- const to = typeof input?.to === "string" ? input.to : now.toISOString();
1128
- const from = typeof input?.from === "string"
1129
- ? input.from
1130
- : new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000).toISOString();
1131
- const limit = typeof input?.limit === "number" ? input.limit : 20;
1132
- const cursor = typeof input?.cursor === "string" ? input.cursor : undefined;
1133
- try {
1134
- const page = await queryNarrativeTimeline(from, to, { limit, cursor }, deps.narrativeTimelineDeps);
1135
- const envelope = {
1136
- ok: true,
1137
- command: "timeline",
1138
- runtimeMode: "workspace_full_runtime",
1139
- surfaceMode: "cli",
1140
- generatedAt,
1141
- data: page,
1142
- warnings: [],
1143
- sourceRefs: ["observability/services/narrative-timeline-query-service.ts"],
1144
- };
1145
- return envelope;
1146
- }
1147
- catch (err) {
1148
- const msg = err instanceof Error ? err.message : String(err);
1149
- const code = err.name === "NarrativeQueryRangeError"
1150
- ? "NARRATIVE_RANGE_EXCEEDED"
1151
- : "TIMELINE_QUERY_FAILED";
1152
- const envelope = {
1153
- ok: false,
1154
- command: "timeline",
1155
- runtimeMode: "unavailable",
1156
- surfaceMode: "cli",
1157
- generatedAt,
1158
- error: { code, message: msg },
1159
- warnings: [],
1160
- sourceRefs: [],
1161
- };
1162
- return envelope;
1163
- }
1164
- }
1165
- /**
1166
- * [G6] restore — bounded state restoration via RestoreSnapshotStore + audit (T-ROS.C.1, T-OBS.C.6).
1167
- * When restoreSnapshotStore is wired, attempts to apply the snapshot payload back to state.
1168
- * Always writes RestoreAudit. Never restores credential fields.
1169
- */
1170
- if (command === "restore") {
1171
- const generatedAt = new Date().toISOString();
1172
- if (!deps.auditStore) {
1173
- const envelope = {
1174
- ok: false,
1175
- command: "restore",
1176
- runtimeMode: "unavailable",
1177
- surfaceMode: "cli",
1178
- generatedAt,
1179
- error: {
1180
- code: "AUDIT_STORE_UNAVAILABLE",
1181
- message: "restore requires auditStore in OpsRouterDeps",
1182
- nextStep: "wire_audit_store_into_ops_router",
1183
- },
1184
- warnings: [],
1185
- sourceRefs: [],
1186
- };
1187
- return envelope;
1188
- }
1189
- let restoreTarget;
1190
- let fromVersion;
1191
- let toVersion;
1192
- // T-V7C.C.5: snapshotId operator-friendly parameter takes precedence over legacy fields.
1193
- // When snapshotId is provided, resolve restoreTarget/fromVersion/toVersion from the
1194
- // matching snapshot row; otherwise fall back to explicit legacy parameters.
1195
- const snapshotId = textInput(input, "snapshotId");
1196
- if (snapshotId) {
1197
- if (!deps.restoreSnapshotStore) {
1198
- const envelope = {
1199
- ok: false,
1200
- command: "restore",
1201
- runtimeMode: "unavailable",
1202
- surfaceMode: "cli",
1203
- generatedAt,
1204
- error: {
1205
- code: "RESTORE_SNAPSHOT_STORE_UNAVAILABLE",
1206
- message: "snapshotId restore requires restoreSnapshotStore in OpsRouterDeps",
1207
- nextStep: "wire_restore_snapshot_store_into_ops_router",
1208
- },
1209
- warnings: [],
1210
- sourceRefs: [],
1211
- };
1212
- return envelope;
1213
- }
1214
- const snapshots = await deps.restoreSnapshotStore.listSnapshots();
1215
- const match = snapshots.find((s) => s.snapshotId === snapshotId);
1216
- if (match) {
1217
- restoreTarget = snapshotId;
1218
- fromVersion = match.capturedAt;
1219
- toVersion = snapshotId;
1220
- }
1221
- else {
1222
- const envelope = {
1223
- ok: false,
1224
- command: "restore",
1225
- runtimeMode: "workspace_full_runtime",
1226
- surfaceMode: "cli",
1227
- generatedAt,
1228
- error: {
1229
- code: "SNAPSHOT_NOT_FOUND",
1230
- message: `snapshotId ${snapshotId} not found in restore_snapshot table`,
1231
- nextStep: "list_available_snapshots_or_verify_snapshotId",
1232
- },
1233
- warnings: [],
1234
- sourceRefs: [],
1235
- };
1236
- return envelope;
1237
- }
1238
- }
1239
- else {
1240
- const missingFields = [];
1241
- if (typeof input?.restoreTarget !== "string")
1242
- missingFields.push("restoreTarget");
1243
- if (typeof input?.fromVersion !== "string")
1244
- missingFields.push("fromVersion");
1245
- if (typeof input?.toVersion !== "string")
1246
- missingFields.push("toVersion");
1247
- if (missingFields.length > 0) {
1248
- const envelope = {
1249
- ok: false,
1250
- command: "restore",
1251
- runtimeMode: "workspace_full_runtime",
1252
- surfaceMode: "cli",
1253
- generatedAt,
1254
- error: {
1255
- code: "MISSING_RESTORE_FIELDS",
1256
- message: `restore requires: ${missingFields.join(", ")}`,
1257
- nextStep: "reinvoke_with_required_fields",
1258
- },
1259
- warnings: [],
1260
- sourceRefs: [],
1261
- };
1262
- return envelope;
1263
- }
1264
- restoreTarget = input.restoreTarget;
1265
- fromVersion = input.fromVersion;
1266
- toVersion = input.toVersion;
1267
- }
1268
- // [NEW] Invoke bounded restore via RestoreSnapshotStore when wired
1269
- let restoreResult = {
1270
- ok: false,
1271
- completedEntities: [],
1272
- failedEntities: [],
1273
- warnings: ["restore_snapshot_store_unavailable"],
1274
- };
1275
- if (deps.restoreSnapshotStore) {
1276
- restoreResult = await deps.restoreSnapshotStore.applyBoundedRestore({
1277
- restoreTarget: restoreTarget,
1278
- fromVersion: fromVersion,
1279
- toVersion: toVersion,
1280
- });
1281
- }
1282
- const event = {
1283
- id: `restore-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
1284
- restoreTarget: restoreTarget,
1285
- fromVersion: fromVersion,
1286
- toVersion: toVersion,
1287
- triggeredBy: input?.triggeredBy ?? "operator",
1288
- reason: typeof input?.reason === "string" ? input.reason : "manual_restore",
1289
- completedEntities: restoreResult.completedEntities,
1290
- failedEntities: restoreResult.failedEntities,
1291
- // credentials are always excluded from restore audit
1292
- excludedFields: Array.isArray(input?.excludedFields)
1293
- ? input.excludedFields.filter((f) => typeof f === "string")
1294
- : ["credential", "encryptionKey"],
1295
- restoredFieldCount: restoreResult.completedEntities.length,
1296
- createdAt: generatedAt,
1297
- traceId: typeof input?.traceId === "string" ? input.traceId : `trace-restore-${Date.now()}`,
1298
- };
1299
- const auditResult = await writeRestoreAudit(event, deps.auditStore);
1300
- const envelope = {
1301
- ok: restoreResult.ok && auditResult.ok,
1302
- command: "restore",
1303
- runtimeMode: "workspace_full_runtime",
1304
- surfaceMode: "cli",
1305
- generatedAt,
1306
- data: {
1307
- auditWritten: auditResult.warnings.length === 0,
1308
- fromVersion: event.fromVersion,
1309
- toVersion: event.toVersion,
1310
- restoreTarget: event.restoreTarget,
1311
- isPartialRestore: event.failedEntities.length > 0,
1312
- failedEntities: event.failedEntities,
1313
- completedEntities: event.completedEntities,
1314
- restoreSnapshotStoreAvailable: !!deps.restoreSnapshotStore,
1315
- },
1316
- warnings: [...restoreResult.warnings, ...auditResult.warnings],
1317
- sourceRefs: [
1318
- "observability/services/restore-audit-service.ts",
1319
- "storage/services/restore-snapshot-store.ts",
1320
- ],
1321
- };
1322
- return envelope;
1323
- }
1324
- /**
1325
- * [G7] runtime_secret_bootstrap — RuntimeSecretAnchorView pass-through.
1326
- * Requires secretAnchorDeps in OpsRouterDeps; never returns key plaintext.
1327
- */
1328
- if (command === "runtime_secret_bootstrap") {
1329
- const generatedAt = new Date().toISOString();
1330
- if (!deps.secretAnchorDeps) {
1331
- const envelope = {
1332
- ok: false,
1333
- command: "runtime_secret_bootstrap",
1334
- runtimeMode: "unavailable",
1335
- surfaceMode: "cli",
1336
- generatedAt,
1337
- error: {
1338
- code: "SECRET_ANCHOR_DEPS_UNAVAILABLE",
1339
- message: "runtime_secret_bootstrap requires secretAnchorDeps in OpsRouterDeps",
1340
- nextStep: "wire_secret_anchor_deps_into_ops_router",
1341
- },
1342
- warnings: [],
1343
- sourceRefs: [],
1344
- };
1345
- return envelope;
1346
- }
1347
- try {
1348
- const view = await viewSecretAnchor(deps.secretAnchorDeps);
1349
- // Map to RuntimeSecretBootstrapView (design model §6.1)
1350
- const data = {
1351
- status: view.status === "verified" || view.status === "ok"
1352
- ? "ok"
1353
- : view.status === "missing"
1354
- ? "runtime_secret_anchor_missing"
1355
- : view.status === "wrong_key"
1356
- ? "credential_recovery_required"
1357
- : view.status === "decryption_failed"
1358
- ? "runtime_secret_unavailable"
1359
- : "unknown",
1360
- keyHealth: view.status === "verified" || view.status === "ok"
1361
- ? "ok"
1362
- : view.status === "missing"
1363
- ? "missing_key"
1364
- : view.status === "wrong_key"
1365
- ? "wrong_key"
1366
- : "unknown",
1367
- anchorLocation: view.keyPath,
1368
- recoveryPrincipleRef: view.recoveryDocRef,
1369
- plaintextKeyExposed: false,
1370
- reasonCode: view.reasonCode,
1371
- recoverySteps: view.recoverySteps,
1372
- };
1373
- const envelope = {
1374
- ok: true,
1375
- command: "runtime_secret_bootstrap",
1376
- runtimeMode: "workspace_full_runtime",
1377
- surfaceMode: "cli",
1378
- generatedAt,
1379
- data,
1380
- warnings: [],
1381
- sourceRefs: ["observability/services/runtime-secret-anchor-view.ts"],
1382
- };
1383
- return envelope;
1384
- }
1385
- catch (err) {
1386
- const msg = err instanceof Error ? err.message : String(err);
1387
- const envelope = {
1388
- ok: false,
1389
- command: "runtime_secret_bootstrap",
1390
- runtimeMode: "unavailable",
1391
- surfaceMode: "cli",
1392
- generatedAt,
1393
- error: { code: "SECRET_ANCHOR_PROBE_FAILED", message: msg },
1394
- warnings: [],
1395
- sourceRefs: [],
1396
- };
1397
- return envelope;
1398
- }
1399
- }
1400
- // ─── T-V7C.C.4R: guidance_payload ──────────────────────────────────────
1401
- // Returns the assembled impulse + atmosphere for a given scene context.
1402
- // Useful for Claw to inspect what guidance content would be injected before
1403
- // a real heartbeat cycle, and to verify platform-specific impulse overrides.
1404
- if (command === "guidance_payload") {
1405
- const generatedAt = new Date().toISOString();
1406
- const { assembleImpulseSync } = await import("../../guidance/impulse-assembler.js");
1407
- const { getBaselineAtmosphereTemplate } = await import("../../guidance/template-registry.js");
1408
- const sceneType = input?.sceneType ?? "social";
1409
- const capabilityIntent = typeof input?.capabilityIntent === "string"
1410
- ? input.capabilityIntent
1411
- : undefined;
1412
- const platformId = typeof input?.platformId === "string"
1413
- ? input.platformId
1414
- : undefined;
1415
- const validSceneTypes = ["social", "reply", "outreach", "quiet", "explain", "user_reply"];
1416
- if (!validSceneTypes.includes(sceneType)) {
1417
- const envelope = {
1418
- ok: false,
1419
- command: "guidance_payload",
1420
- runtimeMode: "unavailable",
1421
- surfaceMode: "cli",
1422
- generatedAt,
1423
- error: {
1424
- code: "INVALID_SCENE_TYPE",
1425
- message: `sceneType must be one of: ${validSceneTypes.join(", ")}`,
1426
- nextStep: "reinvoke_with_valid_scene_type",
1427
- },
1428
- warnings: [],
1429
- sourceRefs: [],
1430
- };
1431
- return envelope;
1432
- }
1433
- const impulseResult = assembleImpulseSync({
1434
- sceneType: sceneType,
1435
- capabilityIntent,
1436
- platformId,
1437
- });
1438
- const { buildExpressionBoundary } = await import("../../guidance/output-guard.js");
1439
- const { getShortAtmosphereTemplate } = await import("../../guidance/template-registry.js");
1440
- const atmosphere = getShortAtmosphereTemplate("active", "low");
1441
- const expressionBoundary = buildExpressionBoundary(sceneType);
1442
- const envelope = {
1443
- ok: true,
1444
- command: "guidance_payload",
1445
- runtimeMode: deps.runtimeAvailable ? "workspace_full_runtime" : "host_safe_carrier",
1446
- surfaceMode: "cli",
1447
- generatedAt,
1448
- data: {
1449
- sceneType,
1450
- capabilityIntent: capabilityIntent ?? null,
1451
- platformId: platformId ?? null,
1452
- capabilityClass: impulseResult.capabilityClass,
1453
- impulseSource: impulseResult.source,
1454
- impulseText: impulseResult.impulse?.text ?? null,
1455
- impulseReviewStatus: impulseResult.impulse?.reviewStatus ?? null,
1456
- atmosphereText: atmosphere.text,
1457
- atmosphereReviewStatus: atmosphere.reviewStatus,
1458
- expressionBoundaryConstraints: expressionBoundary.constraints,
1459
- expressionBoundaryStyle: expressionBoundary.style,
1460
- },
1461
- warnings: impulseResult.source === "none"
1462
- ? ["no_impulse_available_for_this_scene_and_capability"]
1463
- : [],
1464
- sourceRefs: [
1465
- "guidance/capability-class.ts",
1466
- "guidance/impulse-assembler.ts",
1467
- "guidance/template-registry.ts",
1468
- "guidance/output-guard.ts",
1469
- ],
1470
- };
1471
- return envelope;
1472
- }
1473
- return {
1474
- ok: false,
1475
- error: {
1476
- code: "unknown_ops_command",
1477
- message: `Unknown ops command: ${command}`,
1478
- },
1479
- };
1480
- },
1481
- };
1482
- }
1
+ /**
2
+ * Shared ops command dispatch for CLI + tool surfaces (T1.1.3, T1.2.2).
3
+ *
4
+ * v7 additions (T-ROS.C.1): self_health, tool_affordance, connector_test --wet,
5
+ * heartbeat_digest, narrative:diff, timeline, restore, runtime_secret_bootstrap.
6
+ * All commands return RuntimeOpsEnvelope.
7
+ */
8
+ import { createHash } from "node:crypto";
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import { heartbeatCheck, } from "./heartbeat-surface.js";
12
+ import { showOperatorFallback, OperatorFallbackNotFoundError, } from "./show-operator-fallback.js";
13
+ import { probeHostCapability } from "../host-capability/probe-host-capability.js";
14
+ import { recordHostCapability } from "../host-capability/record-host-capability.js";
15
+ import { runNearRealConnectorSmoke } from "../../connectors/near-real/near-real-connector-smoke.js";
16
+ import { scanConnectorManifests } from "../../connectors/registry/manifest-scanner.js";
17
+ import { parseConnectorManifestV6 } from "../../connectors/manifest/manifest-parser.js";
18
+ import { connectorInit } from "../commands/connector-init.js";
19
+ import { connectorBehaviorAdd } from "../commands/connector-behavior.js";
20
+ import { connectorStatus, connectorTest } from "../commands/connector-status.js";
21
+ import { goalCommand } from "../commands/goal.js";
22
+ // v7 observability services (T-ROS.C.1)
23
+ import { getSelfHealthSnapshot, ensureMinimumProbes, } from "../../observability/services/self-health-snapshot.js";
24
+ import { generateHeartbeatDigest, } from "../../observability/services/heartbeat-digest-assembler.js";
25
+ import { queryNarrativeTimeline, queryNarrativeDiff, NarrativeVersionNotFoundError, } from "../../observability/services/narrative-timeline-query-service.js";
26
+ import { viewSecretAnchor, } from "../../observability/services/runtime-secret-anchor-view.js";
27
+ import { writeRestoreAudit, } from "../../observability/services/restore-audit-service.js";
28
+ import { createHistoryDigestStore } from "../../storage/services/history-digest-store.js";
29
+ // T-ROS.C.3: ManualRunDispatcher and its deps
30
+ import { createManualRunDispatcher, } from "./manual-run-dispatcher.js";
31
+ import { createExperienceWriter } from "../../core/second-nature/body/tool-experience/experience-writer.js";
32
+ import { createCapabilityProbeResultStore, createToolExperienceStore, } from "../../storage/services/tool-experience-store.js";
33
+ import { createWetProbeRunner } from "../../connectors/base/wet-probe-runner.js";
34
+ import { CapabilityContractRegistryV7 } from "../../connectors/base/manifest-v7.js";
35
+ // v7 T-V7C.C.6: Dream scheduling deps for heartbeat_check quiet→dream auto-trigger
36
+ import { scheduleDream } from "../../dream/dream-scheduler.js";
37
+ import { createDreamInputLoader } from "../../dream/dream-input-loader.js";
38
+ import { createDiaryDreamStore } from "../../storage/services/diary-dream-store.js";
39
+ // v7 T-CP.C.3 / T-BTS.C.5: heartbeat loop policies and breaker
40
+ import { createGoalLifecyclePolicy } from "../../core/second-nature/heartbeat/goal-lifecycle-policy.js";
41
+ import { createIdleCuriosityPolicy } from "../../core/second-nature/heartbeat/idle-curiosity-policy.js";
42
+ import { createCircuitBreakerManager } from "../../core/second-nature/body/circuit-breaker/circuit-breaker-manager.js";
43
+ import { createProbeSignalAdapter } from "../../core/second-nature/body/probe-signal-adapter.js";
44
+ function coerceProbeOnlyFlag(input) {
45
+ const v = input?.probeOnly;
46
+ return v === true || v === "true" || v === 1 || v === "1";
47
+ }
48
+ /**
49
+ * v7 T-V7C.C.6: Build a minimal QuietDreamSchedulePort backed by the state DB.
50
+ * When a source-backed Quiet write completes, this port triggers Dream scheduling
51
+ * via the standard scheduleDream path (rules-only mode when no model port).
52
+ */
53
+ function createQuietDreamSchedulePort(state) {
54
+ return {
55
+ async scheduleDream({ triggerKind, runId, traceId }) {
56
+ const dreamStore = createDiaryDreamStore(state);
57
+ const inputLoader = createDreamInputLoader({ database: state });
58
+ const statePort = {
59
+ async loadDreamInputs(query) {
60
+ return inputLoader.loadDreamInputs(query);
61
+ },
62
+ async writeDreamOutput(output) {
63
+ // Bridge: dream-engine emits dream/types DreamOutput; diary-dream-store expects shared/types.
64
+ // Structures are identical at runtime; TS strictness requires the cast.
65
+ await dreamStore.appendDreamOutput(output);
66
+ return { outputId: output.outputId, status: "acknowledged" };
67
+ },
68
+ async markDreamOutputLifecycle(input) {
69
+ // transitionDreamOutputLifecycle only accepts accepted|archived.
70
+ if (input.newStatus !== "accepted" && input.newStatus !== "archived") {
71
+ return { outputId: input.outputId, status: "degraded" };
72
+ }
73
+ await dreamStore.transitionDreamOutputLifecycle(input.outputId, input.newStatus);
74
+ return { outputId: input.outputId, status: "acknowledged" };
75
+ },
76
+ };
77
+ const result = await scheduleDream({
78
+ triggerKind,
79
+ runId,
80
+ traceId,
81
+ statePort,
82
+ windowKey: "quiet_completion",
83
+ });
84
+ return { status: result.status, reason: result.reason };
85
+ },
86
+ };
87
+ }
88
+ const SNAPSHOT_TABLE_BY_KIND = {
89
+ identity_profile: "identity_profile",
90
+ agent_goal: "agent_goal",
91
+ tool_experience: "tool_experience",
92
+ daily_diary: "daily_diary_index",
93
+ dream_output: "dream_output_index",
94
+ narrative_timeline: "narrative_timeline",
95
+ };
96
+ const DEFAULT_SNAPSHOT_KINDS = [
97
+ "identity_profile",
98
+ "agent_goal",
99
+ "tool_experience",
100
+ "daily_diary",
101
+ "dream_output",
102
+ "narrative_timeline",
103
+ ];
104
+ function coerceRestorableKinds(value) {
105
+ if (!Array.isArray(value))
106
+ return undefined;
107
+ const valid = new Set(DEFAULT_SNAPSHOT_KINDS);
108
+ return value.filter((item) => typeof item === "string" && valid.has(item));
109
+ }
110
+ function tableExists(state, table) {
111
+ const result = state.sqlite.exec(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1`, [table]);
112
+ return result.length > 0 && result[0].values.length > 0;
113
+ }
114
+ function readRowsFromTable(state, table) {
115
+ const result = state.sqlite.exec(`SELECT * FROM ${table}`);
116
+ if (result.length === 0 || result[0].values.length === 0)
117
+ return [];
118
+ const columns = result[0].columns;
119
+ return result[0].values.map((row) => {
120
+ const out = {};
121
+ columns.forEach((column, index) => {
122
+ out[column] = row[index];
123
+ });
124
+ return out;
125
+ });
126
+ }
127
+ function stringArray(value) {
128
+ return Array.isArray(value)
129
+ ? value.filter((item) => typeof item === "string")
130
+ : [];
131
+ }
132
+ function textInput(input, key) {
133
+ const value = input?.[key];
134
+ if (typeof value !== "string")
135
+ return undefined;
136
+ const trimmed = value.trim();
137
+ return trimmed.length > 0 ? trimmed : undefined;
138
+ }
139
+ function buildSnapshotNarrativeDelta(input, snapshotId, rowCounts) {
140
+ const explicit = input?.narrativeSnapshot &&
141
+ typeof input.narrativeSnapshot === "object" &&
142
+ !Array.isArray(input.narrativeSnapshot)
143
+ ? input.narrativeSnapshot
144
+ : {};
145
+ const from = (key) => input?.[key] ?? explicit[key];
146
+ const sourceRefs = stringArray(from("sourceRefs"));
147
+ return {
148
+ focus: from("focus") ?? "workspace_state",
149
+ progress: from("progress") ??
150
+ `snapshot_captured:${Object.entries(rowCounts)
151
+ .map(([kind, count]) => `${kind}=${count}`)
152
+ .join(",")}`,
153
+ nextIntent: from("nextIntent") ?? "restore_ready",
154
+ toneSignal: from("toneSignal") ?? "system_maintenance",
155
+ acceptedGoalId: from("acceptedGoalId") ?? undefined,
156
+ sourceRefs: sourceRefs.length > 0
157
+ ? sourceRefs
158
+ : [`restore_snapshot:${snapshotId}`, "runtime_ops:snapshot_capture"],
159
+ reasonCode: from("reasonCode") ?? "snapshot_captured",
160
+ summaryText: from("summaryText") ?? `Captured restore snapshot ${snapshotId}`,
161
+ };
162
+ }
163
+ function hashNarrativeSnapshot(input) {
164
+ return createHash("sha256")
165
+ .update(JSON.stringify({
166
+ previousHash: input.previousHash,
167
+ snapshotId: input.snapshotId,
168
+ delta: input.delta,
169
+ createdAt: input.createdAt,
170
+ }))
171
+ .digest("hex");
172
+ }
173
+ function resolveManifestPath(manifestPath, workspaceRoot) {
174
+ if (path.isAbsolute(manifestPath))
175
+ return manifestPath;
176
+ return path.join(workspaceRoot ?? process.cwd(), manifestPath);
177
+ }
178
+ function registerConnectorForWetProbe(input) {
179
+ if (input.entry.manifestPath) {
180
+ try {
181
+ const manifestText = fs.readFileSync(resolveManifestPath(input.entry.manifestPath, input.workspaceRoot), "utf-8");
182
+ const parsed = JSON.parse(manifestText);
183
+ const registered = input.registryV7.register(parsed);
184
+ if (registered.ok && input.registryV7.hasCapability(input.entry.platformId, input.selectedCapabilityId)) {
185
+ return;
186
+ }
187
+ }
188
+ catch {
189
+ // Non-v7 or YAML workspace manifests are projected below.
190
+ }
191
+ }
192
+ input.registryV7.register({
193
+ platformId: input.entry.platformId,
194
+ capabilities: input.entry.capabilities.map((capabilityId) => ({
195
+ capabilityId,
196
+ intent: capabilityId,
197
+ probeConfig: capabilityId === input.selectedCapabilityId && input.safeEndpoint
198
+ ? {
199
+ safeEndpoint: input.safeEndpoint,
200
+ idempotencyClass: "read_only",
201
+ }
202
+ : undefined,
203
+ })),
204
+ channelPriority: ["runtime_ops"],
205
+ credentialTypes: ["runtime_ops_probe"],
206
+ });
207
+ }
208
+ async function captureRuntimeSnapshot(deps, input) {
209
+ const generatedAt = new Date().toISOString();
210
+ if (!deps.state || !deps.restoreSnapshotStore) {
211
+ return {
212
+ ok: false,
213
+ command: "snapshot:capture",
214
+ runtimeMode: "unavailable",
215
+ surfaceMode: "cli",
216
+ generatedAt,
217
+ error: {
218
+ code: "SNAPSHOT_CAPTURE_DEPS_UNAVAILABLE",
219
+ message: "snapshot:capture requires state DB and RestoreSnapshotStore in OpsRouterDeps",
220
+ nextStep: "wire_state_and_restore_snapshot_store_into_ops_router",
221
+ },
222
+ warnings: [],
223
+ sourceRefs: [],
224
+ };
225
+ }
226
+ const snapshotId = textInput(input, "snapshotId") ??
227
+ `snapshot:${Date.now()}:${Math.random().toString(36).slice(2, 8)}`;
228
+ const requestedKinds = coerceRestorableKinds(input?.entityWhitelist) ?? [...DEFAULT_SNAPSHOT_KINDS];
229
+ const rowCounts = {};
230
+ const warnings = [];
231
+ for (const kind of requestedKinds) {
232
+ const table = SNAPSHOT_TABLE_BY_KIND[kind];
233
+ if (!tableExists(deps.state, table)) {
234
+ rowCounts[kind] = 0;
235
+ warnings.push(`table_missing:${kind}:${table}`);
236
+ continue;
237
+ }
238
+ rowCounts[kind] = readRowsFromTable(deps.state, table).length;
239
+ }
240
+ const historyStore = createHistoryDigestStore(deps.state);
241
+ const previousHash = (await historyStore.listNarrativeTimeline({ limit: 1 }))[0]?.currentHash ?? "";
242
+ const delta = buildSnapshotNarrativeDelta(input, snapshotId, rowCounts);
243
+ const currentHash = hashNarrativeSnapshot({
244
+ previousHash,
245
+ snapshotId,
246
+ delta,
247
+ createdAt: generatedAt,
248
+ });
249
+ await historyStore.appendNarrativeTimeline({
250
+ timelineId: snapshotId,
251
+ entryType: "owner.override",
252
+ subjectId: textInput(input, "subjectId") ?? snapshotId,
253
+ delta,
254
+ previousHash,
255
+ currentHash,
256
+ createdAt: generatedAt,
257
+ });
258
+ const payload = {};
259
+ const capturedKinds = [];
260
+ for (const kind of requestedKinds) {
261
+ const table = SNAPSHOT_TABLE_BY_KIND[kind];
262
+ if (!tableExists(deps.state, table))
263
+ continue;
264
+ const rows = readRowsFromTable(deps.state, table);
265
+ rowCounts[kind] = rows.length;
266
+ if (rows.length > 0) {
267
+ payload[kind] = rows;
268
+ capturedKinds.push(kind);
269
+ }
270
+ }
271
+ const snapshot = await deps.restoreSnapshotStore.captureSnapshot({
272
+ snapshotId,
273
+ entityWhitelist: requestedKinds,
274
+ payload,
275
+ capturedAt: generatedAt,
276
+ });
277
+ return {
278
+ ok: true,
279
+ command: "snapshot:capture",
280
+ runtimeMode: "workspace_full_runtime",
281
+ surfaceMode: "cli",
282
+ generatedAt,
283
+ data: {
284
+ snapshotId: snapshot.snapshotId,
285
+ capturedAt: snapshot.capturedAt,
286
+ entityWhitelist: snapshot.entityWhitelist,
287
+ capturedKinds,
288
+ rowCounts,
289
+ narrativeVersion: snapshotId,
290
+ },
291
+ warnings,
292
+ sourceRefs: [
293
+ "storage/services/restore-snapshot-store.ts",
294
+ "storage/services/history-digest-store.ts",
295
+ ],
296
+ };
297
+ }
298
+ /**
299
+ * T1.2.8 — static local adapter: all checks return `unknown` when no real host is available.
300
+ * Allows `capability_probe` to be called from CLI / workspace bridge without requiring a live host.
301
+ */
302
+ function createStaticUnknownAdapter(workspaceRoot) {
303
+ const now = new Date().toISOString();
304
+ const unknownResult = (name) => ({
305
+ name,
306
+ verdict: "unknown",
307
+ observedAt: now,
308
+ reason: "static_local_probe_no_host_context",
309
+ evidenceRefs: [],
310
+ });
311
+ function checkDeliveryTarget() {
312
+ if (!workspaceRoot) {
313
+ return { status: "target_none", evidenceRefs: [], reason: "no_workspace_root_provided" };
314
+ }
315
+ const deliveryCapabilities = ["message.send", "comment.reply"];
316
+ const scanned = scanConnectorManifests(workspaceRoot);
317
+ for (const manifestFile of scanned) {
318
+ const parsed = parseConnectorManifestV6(manifestFile.content, manifestFile.path);
319
+ if (parsed.ok && parsed.manifest.capabilities.some((cap) => deliveryCapabilities.includes(cap.id))) {
320
+ return {
321
+ status: "target_available",
322
+ evidenceRefs: [
323
+ {
324
+ id: `delivery:${parsed.manifest.platformId}`,
325
+ kind: "workspace_artifact",
326
+ uri: `workspace://connectors/${parsed.manifest.platformId}/manifest.yaml`,
327
+ observedAt: now,
328
+ },
329
+ ],
330
+ };
331
+ }
332
+ }
333
+ return { status: "target_none", evidenceRefs: [], reason: "no_delivery_connector_found_in_workspace" };
334
+ }
335
+ return {
336
+ checkPluginLoad: () => unknownResult("plugin_load"),
337
+ checkHeartbeatBridge: () => unknownResult("heartbeat_bridge"),
338
+ checkHeartbeatToolInvocation: () => unknownResult("heartbeat_tool_invocation"),
339
+ checkDeliveryTarget,
340
+ checkAckDropBehavior: () => unknownResult("ack_drop"),
341
+ checkHookSupport: () => [],
342
+ };
343
+ }
344
+ export function createOpsRouter(deps) {
345
+ return {
346
+ heartbeatCheck: (input) => heartbeatCheck({
347
+ ...input,
348
+ runtimeAvailable: input.runtimeAvailable ?? deps.runtimeAvailable,
349
+ readModels: input.readModels ?? deps.readModels,
350
+ runtimeRecorder: input.runtimeRecorder ?? deps.runtimeRecorder,
351
+ state: input.state ?? deps.state,
352
+ workspaceRoot: input.workspaceRoot ?? deps.workspaceRoot,
353
+ connectorExecutor: input.connectorExecutor ?? deps.connectorExecutor,
354
+ connectorRegistry: input
355
+ ?.connectorRegistry ?? deps.connectorRegistry,
356
+ digestOpts: input.digestOpts,
357
+ dreamSchedulePort: input.dreamSchedulePort,
358
+ }),
359
+ async dispatch(command, input) {
360
+ if (command === "heartbeat_check") {
361
+ const runtimeAvailable = typeof input?.runtimeAvailable === "boolean"
362
+ ? input.runtimeAvailable
363
+ : deps.runtimeAvailable;
364
+ // v7 T-V7C.C.2: assemble affordance map and experience writer for breaker-aware heartbeat.
365
+ let affordanceMap;
366
+ if (deps.toolAffordancePort) {
367
+ try {
368
+ affordanceMap = await deps.toolAffordancePort.assembleAffordanceMap({});
369
+ }
370
+ catch {
371
+ // degrade gracefully; guard-layer will skip breaker check without affordanceMap
372
+ }
373
+ }
374
+ let experienceWriter;
375
+ if (deps.state) {
376
+ experienceWriter = createExperienceWriter(createToolExperienceStore(deps.state));
377
+ }
378
+ // v7 T-V7C.C.6: assemble digest opts when auditStore is wired.
379
+ let digestOpts;
380
+ if (deps.auditStore) {
381
+ digestOpts = {
382
+ assemblerDeps: {
383
+ auditStore: deps.auditStore,
384
+ ...deps.heartbeatDigestDeps,
385
+ },
386
+ };
387
+ }
388
+ // v7 T-V7C.C.6: assemble dream schedule port when state DB is wired.
389
+ let dreamSchedulePort;
390
+ if (deps.state) {
391
+ dreamSchedulePort = createQuietDreamSchedulePort(deps.state);
392
+ }
393
+ // v7 T-CP.C.3: assemble goal lifecycle and idle curiosity policies.
394
+ const goalLifecyclePolicy = createGoalLifecyclePolicy();
395
+ const idleCuriosityPolicy = createIdleCuriosityPolicy();
396
+ // v7 T-BTS.C.5: assemble circuit breaker manager when state DB is wired.
397
+ let circuitBreakerManager;
398
+ if (deps.state) {
399
+ const probeResultStore = createCapabilityProbeResultStore(deps.state);
400
+ const toolExpStore = createToolExperienceStore(deps.state);
401
+ const probeAdapter = createProbeSignalAdapter({
402
+ wetProbeRunner: createWetProbeRunner(),
403
+ probeResultStore,
404
+ toolExperienceStore: toolExpStore,
405
+ });
406
+ const registryV7 = new CapabilityContractRegistryV7();
407
+ circuitBreakerManager = createCircuitBreakerManager({
408
+ database: deps.state,
409
+ probeAdapter,
410
+ registry: registryV7,
411
+ });
412
+ }
413
+ try {
414
+ const result = await heartbeatCheck({
415
+ probeOnly: coerceProbeOnlyFlag(input),
416
+ runtimeAvailable,
417
+ fakeControlPlanePassthrough: input?.fakeControlPlanePassthrough &&
418
+ typeof input.fakeControlPlanePassthrough === "object"
419
+ ? input.fakeControlPlanePassthrough
420
+ : undefined,
421
+ readModels: input?.readModels ??
422
+ deps.readModels,
423
+ runtimeRecorder: input
424
+ ?.runtimeRecorder ?? deps.runtimeRecorder,
425
+ state: input?.state ??
426
+ deps.state,
427
+ workspaceRoot: input
428
+ ?.workspaceRoot ?? deps.workspaceRoot,
429
+ timestamp: typeof input?.timestamp === "string" ? input.timestamp : undefined,
430
+ sessionContext: typeof input?.sessionContext === "string"
431
+ ? input.sessionContext
432
+ : undefined,
433
+ scopeHint: input?.scopeHint,
434
+ connectorExecutor: input
435
+ ?.connectorExecutor ?? deps.connectorExecutor,
436
+ connectorRegistry: input
437
+ ?.connectorRegistry ?? deps.connectorRegistry,
438
+ affordanceMap,
439
+ experienceWriter,
440
+ digestOpts,
441
+ dreamSchedulePort,
442
+ goalLifecyclePolicy,
443
+ idleCuriosityPolicy,
444
+ circuitBreakerManager,
445
+ });
446
+ if (result.ok &&
447
+ result.surfaceMode === "workspace_full_runtime" &&
448
+ !coerceProbeOnlyFlag(input) &&
449
+ deps.state &&
450
+ deps.restoreSnapshotStore) {
451
+ try {
452
+ const capture = await captureRuntimeSnapshot(deps, {
453
+ snapshotId: `heartbeat:${result.decisionId ?? "cycle"}:${Date.now()}`,
454
+ subjectId: result.decisionId ?? "heartbeat_check",
455
+ reasonCode: "heartbeat_check",
456
+ summaryText: `Heartbeat ${result.status} captured bounded restore snapshot`,
457
+ focus: result.status,
458
+ progress: result.reasons.join(",") || "heartbeat_completed",
459
+ nextIntent: "continue_runtime_loop",
460
+ sourceRefs: result.decisionId
461
+ ? [`heartbeat:${result.decisionId}`]
462
+ : ["heartbeat:runtime"],
463
+ });
464
+ if (capture.ok) {
465
+ result.reasons = [...result.reasons, "restore_snapshot_captured"];
466
+ }
467
+ }
468
+ catch (err) {
469
+ const msg = err instanceof Error ? err.message : String(err);
470
+ result.reasons = [...result.reasons, `restore_snapshot_capture_failed:${msg}`];
471
+ }
472
+ }
473
+ return result;
474
+ }
475
+ catch (err) {
476
+ const msg = err instanceof Error ? err.message : String(err);
477
+ const envelope = {
478
+ ok: false,
479
+ command: "heartbeat_check",
480
+ runtimeMode: runtimeAvailable ? "workspace_full_runtime" : "unavailable",
481
+ surfaceMode: "cli",
482
+ generatedAt: new Date().toISOString(),
483
+ error: {
484
+ code: "HEARTBEAT_CYCLE_EXCEPTION",
485
+ message: `heartbeat_check cycle threw unexpectedly: ${msg.slice(0, 200)}`,
486
+ nextStep: "check_logs_and_report",
487
+ },
488
+ warnings: [],
489
+ sourceRefs: [],
490
+ };
491
+ return envelope;
492
+ }
493
+ }
494
+ if (command === "fallback") {
495
+ const ref = typeof input?.ref === "string" ? input.ref.trim() : "";
496
+ if (!ref) {
497
+ return {
498
+ ok: false,
499
+ error: {
500
+ code: "MISSING_FALLBACK_REF",
501
+ message: "fallback requires args.ref (e.g. fallback:…)",
502
+ requiredUserInput: ["ref"],
503
+ nextStep: "reinvoke_with_ref",
504
+ },
505
+ };
506
+ }
507
+ if (!deps.readModels?.loadFallbackView) {
508
+ return {
509
+ ok: false,
510
+ error: {
511
+ code: "FALLBACK_READ_MODEL_UNAVAILABLE",
512
+ message: "Operator fallback view requires workspace read models",
513
+ requiredUserInput: ["ref"],
514
+ nextStep: "wire_read_models_into_ops_router",
515
+ },
516
+ };
517
+ }
518
+ return (async () => {
519
+ try {
520
+ const data = await showOperatorFallback(ref, deps.readModels);
521
+ return { ok: true, command: "fallback", data };
522
+ }
523
+ catch (error) {
524
+ if (error instanceof OperatorFallbackNotFoundError) {
525
+ return {
526
+ ok: false,
527
+ command: "fallback",
528
+ error: {
529
+ code: error.code,
530
+ message: error.message,
531
+ requiredUserInput: ["ref"],
532
+ nextStep: "verify_fallback_ref_from_delivery_audit",
533
+ },
534
+ };
535
+ }
536
+ throw error;
537
+ }
538
+ })();
539
+ }
540
+ if (command === "capability_probe") {
541
+ // T1.2.8 (SN-CODE-03): run host capability probe with static unknown adapter (CLI context).
542
+ // Persists report when observabilityDb is available; returns safe JSON subset.
543
+ return (async () => {
544
+ const adapter = createStaticUnknownAdapter(deps.workspaceRoot);
545
+ const docCheckedAt = new Date().toISOString();
546
+ const report = probeHostCapability({
547
+ adapter,
548
+ docLinks: [],
549
+ docCheckedAt,
550
+ });
551
+ if (deps.observabilityDb) {
552
+ await recordHostCapability(deps.observabilityDb, report);
553
+ }
554
+ return {
555
+ ok: true,
556
+ command: "capability_probe",
557
+ data: {
558
+ reportId: report.reportId,
559
+ generatedAt: report.generatedAt,
560
+ deliveryTarget: report.deliveryTarget,
561
+ pluginLoad: { verdict: report.pluginLoad.verdict },
562
+ heartbeatBridge: { verdict: report.heartbeatBridge.verdict },
563
+ heartbeatToolInvocation: {
564
+ verdict: report.heartbeatToolInvocation.verdict,
565
+ },
566
+ ackDropBehavior: { verdict: report.ackDropBehavior.verdict },
567
+ conflictCount: report.conflictRecords.length,
568
+ recommendedNextStep: report.recommendedNextStep,
569
+ note: "static_local_probe: all verdicts are unknown without live host context",
570
+ },
571
+ };
572
+ })();
573
+ }
574
+ if (command === "near_real_smoke") {
575
+ // T3.3.2 (SN-CODE-05): wrap runNearRealConnectorSmoke as an ops surface command.
576
+ // Requires state + observabilityDb + workspaceRoot to be wired into OpsRouterDeps.
577
+ if (!deps.state || !deps.observabilityDb || !deps.workspaceRoot) {
578
+ return {
579
+ ok: false,
580
+ command: "near_real_smoke",
581
+ error: {
582
+ code: "NEAR_REAL_SMOKE_DEPS_UNAVAILABLE",
583
+ message: "near_real_smoke requires state, observabilityDb, and workspaceRoot in OpsRouterDeps",
584
+ nextStep: "wire_deps_into_ops_router",
585
+ },
586
+ };
587
+ }
588
+ return (async () => {
589
+ const result = await runNearRealConnectorSmoke({
590
+ state: deps.state,
591
+ observabilityDb: deps.observabilityDb,
592
+ workspaceRoot: deps.workspaceRoot,
593
+ });
594
+ return {
595
+ ok: true,
596
+ command: "near_real_smoke",
597
+ data: result,
598
+ };
599
+ })();
600
+ }
601
+ if (command === "connector_init") {
602
+ // T1.3.1 (SN-CODE-06): generate connector manifest stub.
603
+ return (async () => {
604
+ const result = await connectorInit({
605
+ platformId: typeof input?.platformId === "string" ? input.platformId : "",
606
+ family: typeof input?.family === "string"
607
+ ? input.family
608
+ : undefined,
609
+ displayName: typeof input?.displayName === "string" ? input.displayName : undefined,
610
+ runnerKind: typeof input?.runnerKind === "string"
611
+ ? input.runnerKind
612
+ : undefined,
613
+ force: Boolean(input?.force),
614
+ workspaceRoot: deps.workspaceRoot,
615
+ });
616
+ return result;
617
+ })();
618
+ }
619
+ if (command === "connector_behavior_add") {
620
+ return connectorBehaviorAdd({
621
+ platformId: typeof input?.platformId === "string" ? input.platformId : "",
622
+ behaviorId: typeof input?.behaviorId === "string"
623
+ ? input.behaviorId
624
+ : typeof input?.capabilityId === "string"
625
+ ? input.capabilityId
626
+ : "",
627
+ description: typeof input?.description === "string" ? input.description : undefined,
628
+ channel: typeof input?.channel === "string" ? input.channel : undefined,
629
+ sourceRefs: input?.sourceRefs,
630
+ observedCount: typeof input?.observedCount === "number" ? input.observedCount : undefined,
631
+ workspaceRoot: typeof input?.workspaceRoot === "string"
632
+ ? input.workspaceRoot
633
+ : deps.workspaceRoot,
634
+ });
635
+ }
636
+ if (command === "connector_status") {
637
+ return connectorStatus(deps.registry, undefined, {
638
+ includeHealth: Boolean(input?.includeHealth),
639
+ workspaceRoot: typeof input?.workspaceRoot === "string"
640
+ ? input.workspaceRoot
641
+ : deps.workspaceRoot,
642
+ });
643
+ }
644
+ if (command === "connector_test") {
645
+ // v7 T-V7C.C.1: dryRun=false is the canonical wet probe switch.
646
+ const isWet = input?.wet === true ||
647
+ input?.wet === "true" ||
648
+ input?.dryRun === false ||
649
+ input?.dryRun === "false";
650
+ const result = await connectorTest(deps.registry, {
651
+ platformId: typeof input?.platformId === "string" ? input.platformId : "",
652
+ dryRun: isWet ? false : (input?.dryRun === false ? false : true),
653
+ workspaceRoot: typeof input?.workspaceRoot === "string"
654
+ ? input.workspaceRoot
655
+ : deps.workspaceRoot,
656
+ });
657
+ if (!isWet || !result.ok) {
658
+ return result;
659
+ }
660
+ const data = result.data && typeof result.data === "object"
661
+ ? result.data
662
+ : {};
663
+ const capabilities = Array.isArray(data.capabilities)
664
+ ? data.capabilities.filter((item) => typeof item === "string")
665
+ : [];
666
+ const capabilityId = textInput(input, "capabilityId") ?? capabilities[0] ?? "";
667
+ if (!capabilityId) {
668
+ return {
669
+ ok: false,
670
+ command: "connector_test",
671
+ error: {
672
+ code: "MISSING_CAPABILITY_ID",
673
+ message: "wet connector_test requires capabilityId or at least one connector capability",
674
+ requiredUserInput: ["capabilityId"],
675
+ nextStep: "reinvoke_with_capability_id",
676
+ },
677
+ };
678
+ }
679
+ const platformId = String(data.platformId ?? input?.platformId ?? "");
680
+ const registryEntry = deps.registry?.describeConnector(platformId);
681
+ if (!registryEntry) {
682
+ return result;
683
+ }
684
+ const registryV7 = new CapabilityContractRegistryV7();
685
+ registerConnectorForWetProbe({
686
+ registryV7,
687
+ entry: {
688
+ platformId: registryEntry.platformId,
689
+ capabilities: registryEntry.capabilities,
690
+ manifestPath: registryEntry.manifestPath,
691
+ },
692
+ workspaceRoot: typeof input?.workspaceRoot === "string"
693
+ ? input.workspaceRoot
694
+ : deps.workspaceRoot,
695
+ selectedCapabilityId: capabilityId,
696
+ safeEndpoint: textInput(input, "safeEndpoint"),
697
+ });
698
+ const wetResult = await createWetProbeRunner().runWetProbe(platformId, capabilityId, registryV7);
699
+ const warnings = [];
700
+ let persistedProbeResult = false;
701
+ if (deps.state) {
702
+ await createCapabilityProbeResultStore(deps.state).appendProbeResult(wetResult.probeResult);
703
+ persistedProbeResult = true;
704
+ }
705
+ else {
706
+ warnings.push("state_db_unavailable:capability_probe_result_not_persisted");
707
+ }
708
+ return {
709
+ // T-V7C.C.5: only "available" (HTTP 200-299) counts as success;
710
+ // "degraded" (429/503) and "unavailable" both result in ok=false.
711
+ ok: wetResult.probeResult.actualStatus === "available",
712
+ command: "connector_test",
713
+ data: {
714
+ ...data,
715
+ dryRun: false,
716
+ capabilityId,
717
+ actualStatus: wetResult.probeResult.actualStatus,
718
+ httpStatus: wetResult.probeResult.httpStatus ?? wetResult.httpStatus,
719
+ probeResultId: wetResult.probeResult.probeResultId,
720
+ probeConfigRef: wetResult.probeResult.probeConfigRef,
721
+ sampleResponseRef: wetResult.probeResult.sampleResponseRef,
722
+ persistedProbeResult,
723
+ triggerSource: "manual_run",
724
+ affectsHeartbeatCadence: false,
725
+ note: "wet probe mode: executed safe probe endpoint and persisted capability_probe_result when state DB is available",
726
+ },
727
+ warnings,
728
+ };
729
+ }
730
+ if (command === "connector:run") {
731
+ // T-ROS.C.3: manual connector execution — isolated from heartbeat cadence
732
+ const platformId = typeof input?.platformId === "string" ? input.platformId : "";
733
+ const capabilityId = typeof input?.capabilityId === "string" ? input.capabilityId : "";
734
+ if (!platformId || !capabilityId) {
735
+ return {
736
+ ok: false,
737
+ command: "connector:run",
738
+ error: {
739
+ code: "MISSING_PLATFORM_OR_CAPABILITY_ID",
740
+ message: "connector:run requires platformId and capabilityId",
741
+ requiredUserInput: ["platformId", "capabilityId"],
742
+ nextStep: "reinvoke_with_platform_and_capability_id",
743
+ },
744
+ };
745
+ }
746
+ if (!deps.connectorExecutor || !deps.state) {
747
+ return {
748
+ ok: false,
749
+ command: "connector:run",
750
+ error: {
751
+ code: "MANUAL_RUN_DEPS_UNAVAILABLE",
752
+ message: "connector:run requires connectorExecutor and state database",
753
+ nextStep: "wire_connector_executor_and_state_into_ops_router",
754
+ },
755
+ };
756
+ }
757
+ const toolExperienceStore = createToolExperienceStore(deps.state);
758
+ const experienceWriter = createExperienceWriter(toolExperienceStore);
759
+ const wetProbeRunner = createWetProbeRunner();
760
+ const registryV7 = new CapabilityContractRegistryV7();
761
+ // Populate V7 registry from dynamic registry if available (best-effort)
762
+ if (deps.registry) {
763
+ for (const entry of deps.registry.listConnectors()) {
764
+ if (entry.manifestPath) {
765
+ try {
766
+ const manifestText = fs.readFileSync(entry.manifestPath, "utf-8");
767
+ const manifest = JSON.parse(manifestText);
768
+ registryV7.register(manifest);
769
+ }
770
+ catch {
771
+ // Skip manifests that can't be read or don't validate as V7
772
+ }
773
+ }
774
+ }
775
+ }
776
+ const dispatcher = createManualRunDispatcher({
777
+ connectorExecutor: deps.connectorExecutor,
778
+ experienceWriter,
779
+ wetProbeRunner,
780
+ registryV7,
781
+ });
782
+ return dispatcher.runConnector({
783
+ platformId,
784
+ capabilityId,
785
+ payload: typeof input?.payload === "object" && input?.payload !== null
786
+ ? input.payload
787
+ : undefined,
788
+ caller: typeof input?.caller === "string" ? input.caller : undefined,
789
+ reason: typeof input?.reason === "string" ? input.reason : undefined,
790
+ });
791
+ }
792
+ if (command === "goal") {
793
+ const rawAction = typeof input?.action === "string" ? input.action : "list";
794
+ const action = ["set", "list", "accept", "reject"].includes(rawAction)
795
+ ? rawAction
796
+ : "list";
797
+ const sanitizeText = (v, maxLen = 1000) => {
798
+ if (typeof v !== "string")
799
+ return undefined;
800
+ const trimmed = v.trim();
801
+ if (trimmed.length === 0)
802
+ return undefined;
803
+ return trimmed.slice(0, maxLen);
804
+ };
805
+ return goalCommand(deps.state, {
806
+ action,
807
+ goalId: typeof input?.goalId === "string" ? input.goalId.trim().slice(0, 128) : undefined,
808
+ description: sanitizeText(input?.description),
809
+ completionCriteria: sanitizeText(input?.completionCriteria),
810
+ // T1.4.2: criteria alias for completionCriteria
811
+ criteria: sanitizeText(input?.criteria),
812
+ risk: typeof input?.risk === "string"
813
+ ? input.risk
814
+ : undefined,
815
+ kind: typeof input?.kind === "string"
816
+ ? input.kind
817
+ : undefined,
818
+ statusFilter: typeof input?.statusFilter === "string" ? input.statusFilter : undefined,
819
+ originFilter: typeof input?.originFilter === "string" ? input.originFilter : undefined,
820
+ limit: typeof input?.limit === "number" ? input.limit : undefined,
821
+ });
822
+ }
823
+ if (command === "dream:recent") {
824
+ if (!deps.readModels) {
825
+ return {
826
+ ok: false,
827
+ error: {
828
+ code: "READ_MODELS_UNAVAILABLE",
829
+ message: "dream:recent requires workspace read models",
830
+ nextStep: "wire_read_models_into_ops_router",
831
+ },
832
+ };
833
+ }
834
+ const limit = typeof input?.limit === "number" ? input.limit : 5;
835
+ const data = await deps.readModels.loadDreamRecent(limit);
836
+ return { ok: true, data };
837
+ }
838
+ if (command === "cycle:recent") {
839
+ if (!deps.readModels) {
840
+ return {
841
+ ok: false,
842
+ error: {
843
+ code: "READ_MODELS_UNAVAILABLE",
844
+ message: "cycle:recent requires workspace read models",
845
+ nextStep: "wire_read_models_into_ops_router",
846
+ },
847
+ };
848
+ }
849
+ const limit = typeof input?.limit === "number" ? input.limit : 5;
850
+ const data = await deps.readModels.loadCycleRecent(limit);
851
+ return { ok: true, data };
852
+ }
853
+ // ─── v7 commands (T-ROS.C.1) ─────────────────────────────────────────
854
+ /** [G2] self_health — transparent pass-through from SelfHealthSnapshot (DR-042). */
855
+ if (command === "self_health") {
856
+ const generatedAt = new Date().toISOString();
857
+ try {
858
+ ensureMinimumProbes();
859
+ const snap = await getSelfHealthSnapshot();
860
+ const degraded_dimensions = Object.entries(snap.dimensions)
861
+ .filter(([, d]) => d.status === "degraded")
862
+ .map(([k]) => k);
863
+ const envelope = {
864
+ ok: true,
865
+ command: "self_health",
866
+ runtimeMode: "workspace_full_runtime",
867
+ surfaceMode: "cli",
868
+ generatedAt,
869
+ data: {
870
+ overall: snap.overall,
871
+ generatedAt: snap.generatedAt,
872
+ degraded_dimensions,
873
+ dimensions: snap.dimensions,
874
+ },
875
+ warnings: [],
876
+ sourceRefs: ["observability/services/self-health-snapshot.ts"],
877
+ };
878
+ return envelope;
879
+ }
880
+ catch (err) {
881
+ const msg = err instanceof Error ? err.message : String(err);
882
+ const envelope = {
883
+ ok: false,
884
+ command: "self_health",
885
+ runtimeMode: "unavailable",
886
+ surfaceMode: "cli",
887
+ generatedAt,
888
+ error: { code: "SELF_HEALTH_PROBE_FAILED", message: msg },
889
+ warnings: [],
890
+ sourceRefs: [],
891
+ };
892
+ return envelope;
893
+ }
894
+ }
895
+ /**
896
+ * [G3] tool_affordance — body-tool AffordanceMap pass-through.
897
+ * Port not yet wired in this wave; returns degraded view with clear next-step.
898
+ */
899
+ if (command === "tool_affordance") {
900
+ const generatedAt = new Date().toISOString();
901
+ if (deps.toolAffordancePort) {
902
+ const allStatuses = [
903
+ "safe",
904
+ "exploratory",
905
+ "needs_auth",
906
+ "painful",
907
+ "unavailable",
908
+ ];
909
+ const platformIds = Array.isArray(input?.platformIds)
910
+ ? input.platformIds.filter((item) => typeof item === "string")
911
+ : typeof input?.platformId === "string"
912
+ ? [input.platformId]
913
+ : undefined;
914
+ const data = await deps.toolAffordancePort.assembleAffordanceMap({
915
+ platformIds,
916
+ allowedStatuses: allStatuses,
917
+ goalKind: typeof input?.goalKind === "string" ? input.goalKind : undefined,
918
+ });
919
+ const envelope = {
920
+ ok: true,
921
+ command: "tool_affordance",
922
+ runtimeMode: "workspace_full_runtime",
923
+ surfaceMode: "cli",
924
+ generatedAt,
925
+ data,
926
+ warnings: [],
927
+ sourceRefs: [
928
+ "core/second-nature/body/tool-affordance/affordance-assembler.ts",
929
+ ],
930
+ };
931
+ return envelope;
932
+ }
933
+ const envelope = {
934
+ ok: false,
935
+ command: "tool_affordance",
936
+ runtimeMode: "unavailable",
937
+ surfaceMode: "cli",
938
+ generatedAt,
939
+ error: {
940
+ code: "TOOL_AFFORDANCE_PORT_UNWIRED",
941
+ message: "tool_affordance requires body-tool AffordanceMap port (T-BTS.C.1) to be wired into OpsRouterDeps",
942
+ nextStep: "wire_body_tool_port_into_ops_router_deps",
943
+ },
944
+ warnings: [],
945
+ sourceRefs: [],
946
+ };
947
+ return envelope;
948
+ }
949
+ /**
950
+ * [G6] heartbeat_digest — wraps generateHeartbeatDigest.
951
+ * Requires auditStore in deps; degrades if unavailable.
952
+ */
953
+ if (command === "heartbeat_digest") {
954
+ const generatedAt = new Date().toISOString();
955
+ if (!deps.auditStore) {
956
+ const envelope = {
957
+ ok: false,
958
+ command: "heartbeat_digest",
959
+ runtimeMode: "unavailable",
960
+ surfaceMode: "cli",
961
+ generatedAt,
962
+ error: {
963
+ code: "AUDIT_STORE_UNAVAILABLE",
964
+ message: "heartbeat_digest requires auditStore in OpsRouterDeps",
965
+ nextStep: "wire_audit_store_into_ops_router",
966
+ },
967
+ warnings: [],
968
+ sourceRefs: [],
969
+ };
970
+ return envelope;
971
+ }
972
+ const date = typeof input?.date === "string" && input.date
973
+ ? input.date
974
+ : new Date().toISOString().slice(0, 10);
975
+ try {
976
+ const digestDeps = {
977
+ auditStore: deps.auditStore,
978
+ ...deps.heartbeatDigestDeps,
979
+ };
980
+ const digest = await generateHeartbeatDigest(date, digestDeps);
981
+ const envelope = {
982
+ ok: true,
983
+ command: "heartbeat_digest",
984
+ runtimeMode: "workspace_full_runtime",
985
+ surfaceMode: "cli",
986
+ generatedAt,
987
+ data: digest,
988
+ warnings: [],
989
+ sourceRefs: ["observability/services/heartbeat-digest-assembler.ts"],
990
+ };
991
+ return envelope;
992
+ }
993
+ catch (err) {
994
+ const msg = err instanceof Error ? err.message : String(err);
995
+ const envelope = {
996
+ ok: false,
997
+ command: "heartbeat_digest",
998
+ runtimeMode: "unavailable",
999
+ surfaceMode: "cli",
1000
+ generatedAt,
1001
+ error: { code: "DIGEST_GENERATION_FAILED", message: msg },
1002
+ warnings: [],
1003
+ sourceRefs: [],
1004
+ };
1005
+ return envelope;
1006
+ }
1007
+ }
1008
+ /**
1009
+ * [G6] snapshot:capture — production capture path for RestoreSnapshot +
1010
+ * NarrativeTimeline. This gives restore and narrative:diff real state to consume.
1011
+ */
1012
+ if (command === "snapshot:capture") {
1013
+ return captureRuntimeSnapshot(deps, input);
1014
+ }
1015
+ /**
1016
+ * [G6] narrative:diff — queryNarrativeDiff between two versions.
1017
+ * Requires narrativeTimelineDeps in OpsRouterDeps.
1018
+ */
1019
+ if (command === "narrative:diff") {
1020
+ const generatedAt = new Date().toISOString();
1021
+ if (!deps.narrativeTimelineDeps) {
1022
+ const envelope = {
1023
+ ok: false,
1024
+ command: "narrative:diff",
1025
+ runtimeMode: "unavailable",
1026
+ surfaceMode: "cli",
1027
+ generatedAt,
1028
+ error: {
1029
+ code: "NARRATIVE_TIMELINE_PORT_UNAVAILABLE",
1030
+ message: "narrative:diff requires narrativeTimelineDeps in OpsRouterDeps",
1031
+ nextStep: "wire_narrative_timeline_deps_into_ops_router",
1032
+ },
1033
+ warnings: [],
1034
+ sourceRefs: [],
1035
+ };
1036
+ return envelope;
1037
+ }
1038
+ const fromVersion = typeof input?.from === "string" ? input.from : "";
1039
+ const toVersion = typeof input?.to === "string" ? input.to : "";
1040
+ if (!fromVersion || !toVersion) {
1041
+ const envelope = {
1042
+ ok: false,
1043
+ command: "narrative:diff",
1044
+ runtimeMode: "workspace_full_runtime",
1045
+ surfaceMode: "cli",
1046
+ generatedAt,
1047
+ error: {
1048
+ code: "MISSING_VERSIONS",
1049
+ message: "narrative:diff requires 'from' and 'to' version arguments",
1050
+ nextStep: "reinvoke_with_from_and_to",
1051
+ },
1052
+ warnings: [],
1053
+ sourceRefs: [],
1054
+ };
1055
+ return envelope;
1056
+ }
1057
+ try {
1058
+ const diff = await queryNarrativeDiff(fromVersion, toVersion, deps.narrativeTimelineDeps);
1059
+ const envelope = {
1060
+ ok: true,
1061
+ command: "narrative:diff",
1062
+ runtimeMode: "workspace_full_runtime",
1063
+ surfaceMode: "cli",
1064
+ generatedAt,
1065
+ data: diff,
1066
+ warnings: [],
1067
+ sourceRefs: ["observability/services/narrative-timeline-query-service.ts"],
1068
+ };
1069
+ return envelope;
1070
+ }
1071
+ catch (err) {
1072
+ if (err instanceof NarrativeVersionNotFoundError) {
1073
+ const envelope = {
1074
+ ok: false,
1075
+ command: "narrative:diff",
1076
+ runtimeMode: "workspace_full_runtime",
1077
+ surfaceMode: "cli",
1078
+ generatedAt,
1079
+ error: {
1080
+ code: "NARRATIVE_VERSION_NOT_FOUND",
1081
+ message: err.message,
1082
+ nextStep: "verify_version_exists_in_timeline",
1083
+ },
1084
+ warnings: [],
1085
+ sourceRefs: [],
1086
+ };
1087
+ return envelope;
1088
+ }
1089
+ const msg = err instanceof Error ? err.message : String(err);
1090
+ const envelope = {
1091
+ ok: false,
1092
+ command: "narrative:diff",
1093
+ runtimeMode: "unavailable",
1094
+ surfaceMode: "cli",
1095
+ generatedAt,
1096
+ error: { code: "NARRATIVE_DIFF_FAILED", message: msg },
1097
+ warnings: [],
1098
+ sourceRefs: [],
1099
+ };
1100
+ return envelope;
1101
+ }
1102
+ }
1103
+ /**
1104
+ * [G6] timeline — queryNarrativeTimeline with cursor pagination.
1105
+ * Requires narrativeTimelineDeps in OpsRouterDeps.
1106
+ */
1107
+ if (command === "timeline") {
1108
+ const generatedAt = new Date().toISOString();
1109
+ if (!deps.narrativeTimelineDeps) {
1110
+ const envelope = {
1111
+ ok: false,
1112
+ command: "timeline",
1113
+ runtimeMode: "unavailable",
1114
+ surfaceMode: "cli",
1115
+ generatedAt,
1116
+ error: {
1117
+ code: "NARRATIVE_TIMELINE_PORT_UNAVAILABLE",
1118
+ message: "timeline requires narrativeTimelineDeps in OpsRouterDeps",
1119
+ nextStep: "wire_narrative_timeline_deps_into_ops_router",
1120
+ },
1121
+ warnings: [],
1122
+ sourceRefs: [],
1123
+ };
1124
+ return envelope;
1125
+ }
1126
+ const now = new Date();
1127
+ const to = typeof input?.to === "string" ? input.to : now.toISOString();
1128
+ const from = typeof input?.from === "string"
1129
+ ? input.from
1130
+ : new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000).toISOString();
1131
+ const limit = typeof input?.limit === "number" ? input.limit : 20;
1132
+ const cursor = typeof input?.cursor === "string" ? input.cursor : undefined;
1133
+ try {
1134
+ const page = await queryNarrativeTimeline(from, to, { limit, cursor }, deps.narrativeTimelineDeps);
1135
+ const envelope = {
1136
+ ok: true,
1137
+ command: "timeline",
1138
+ runtimeMode: "workspace_full_runtime",
1139
+ surfaceMode: "cli",
1140
+ generatedAt,
1141
+ data: page,
1142
+ warnings: [],
1143
+ sourceRefs: ["observability/services/narrative-timeline-query-service.ts"],
1144
+ };
1145
+ return envelope;
1146
+ }
1147
+ catch (err) {
1148
+ const msg = err instanceof Error ? err.message : String(err);
1149
+ const code = err.name === "NarrativeQueryRangeError"
1150
+ ? "NARRATIVE_RANGE_EXCEEDED"
1151
+ : "TIMELINE_QUERY_FAILED";
1152
+ const envelope = {
1153
+ ok: false,
1154
+ command: "timeline",
1155
+ runtimeMode: "unavailable",
1156
+ surfaceMode: "cli",
1157
+ generatedAt,
1158
+ error: { code, message: msg },
1159
+ warnings: [],
1160
+ sourceRefs: [],
1161
+ };
1162
+ return envelope;
1163
+ }
1164
+ }
1165
+ /**
1166
+ * [G6] restore — bounded state restoration via RestoreSnapshotStore + audit (T-ROS.C.1, T-OBS.C.6).
1167
+ * When restoreSnapshotStore is wired, attempts to apply the snapshot payload back to state.
1168
+ * Always writes RestoreAudit. Never restores credential fields.
1169
+ */
1170
+ if (command === "restore") {
1171
+ const generatedAt = new Date().toISOString();
1172
+ if (!deps.auditStore) {
1173
+ const envelope = {
1174
+ ok: false,
1175
+ command: "restore",
1176
+ runtimeMode: "unavailable",
1177
+ surfaceMode: "cli",
1178
+ generatedAt,
1179
+ error: {
1180
+ code: "AUDIT_STORE_UNAVAILABLE",
1181
+ message: "restore requires auditStore in OpsRouterDeps",
1182
+ nextStep: "wire_audit_store_into_ops_router",
1183
+ },
1184
+ warnings: [],
1185
+ sourceRefs: [],
1186
+ };
1187
+ return envelope;
1188
+ }
1189
+ let restoreTarget;
1190
+ let fromVersion;
1191
+ let toVersion;
1192
+ // T-V7C.C.5: snapshotId operator-friendly parameter takes precedence over legacy fields.
1193
+ // When snapshotId is provided, resolve restoreTarget/fromVersion/toVersion from the
1194
+ // matching snapshot row; otherwise fall back to explicit legacy parameters.
1195
+ const snapshotId = textInput(input, "snapshotId");
1196
+ if (snapshotId) {
1197
+ if (!deps.restoreSnapshotStore) {
1198
+ const envelope = {
1199
+ ok: false,
1200
+ command: "restore",
1201
+ runtimeMode: "unavailable",
1202
+ surfaceMode: "cli",
1203
+ generatedAt,
1204
+ error: {
1205
+ code: "RESTORE_SNAPSHOT_STORE_UNAVAILABLE",
1206
+ message: "snapshotId restore requires restoreSnapshotStore in OpsRouterDeps",
1207
+ nextStep: "wire_restore_snapshot_store_into_ops_router",
1208
+ },
1209
+ warnings: [],
1210
+ sourceRefs: [],
1211
+ };
1212
+ return envelope;
1213
+ }
1214
+ const snapshots = await deps.restoreSnapshotStore.listSnapshots();
1215
+ const match = snapshots.find((s) => s.snapshotId === snapshotId);
1216
+ if (match) {
1217
+ restoreTarget = snapshotId;
1218
+ fromVersion = match.capturedAt;
1219
+ toVersion = snapshotId;
1220
+ }
1221
+ else {
1222
+ const envelope = {
1223
+ ok: false,
1224
+ command: "restore",
1225
+ runtimeMode: "workspace_full_runtime",
1226
+ surfaceMode: "cli",
1227
+ generatedAt,
1228
+ error: {
1229
+ code: "SNAPSHOT_NOT_FOUND",
1230
+ message: `snapshotId ${snapshotId} not found in restore_snapshot table`,
1231
+ nextStep: "list_available_snapshots_or_verify_snapshotId",
1232
+ },
1233
+ warnings: [],
1234
+ sourceRefs: [],
1235
+ };
1236
+ return envelope;
1237
+ }
1238
+ }
1239
+ else {
1240
+ const missingFields = [];
1241
+ if (typeof input?.restoreTarget !== "string")
1242
+ missingFields.push("restoreTarget");
1243
+ if (typeof input?.fromVersion !== "string")
1244
+ missingFields.push("fromVersion");
1245
+ if (typeof input?.toVersion !== "string")
1246
+ missingFields.push("toVersion");
1247
+ if (missingFields.length > 0) {
1248
+ const envelope = {
1249
+ ok: false,
1250
+ command: "restore",
1251
+ runtimeMode: "workspace_full_runtime",
1252
+ surfaceMode: "cli",
1253
+ generatedAt,
1254
+ error: {
1255
+ code: "MISSING_RESTORE_FIELDS",
1256
+ message: `restore requires: ${missingFields.join(", ")}`,
1257
+ nextStep: "reinvoke_with_required_fields",
1258
+ },
1259
+ warnings: [],
1260
+ sourceRefs: [],
1261
+ };
1262
+ return envelope;
1263
+ }
1264
+ restoreTarget = input.restoreTarget;
1265
+ fromVersion = input.fromVersion;
1266
+ toVersion = input.toVersion;
1267
+ }
1268
+ // [NEW] Invoke bounded restore via RestoreSnapshotStore when wired
1269
+ let restoreResult = {
1270
+ ok: false,
1271
+ completedEntities: [],
1272
+ failedEntities: [],
1273
+ warnings: ["restore_snapshot_store_unavailable"],
1274
+ };
1275
+ if (deps.restoreSnapshotStore) {
1276
+ restoreResult = await deps.restoreSnapshotStore.applyBoundedRestore({
1277
+ restoreTarget: restoreTarget,
1278
+ fromVersion: fromVersion,
1279
+ toVersion: toVersion,
1280
+ });
1281
+ }
1282
+ const event = {
1283
+ id: `restore-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
1284
+ restoreTarget: restoreTarget,
1285
+ fromVersion: fromVersion,
1286
+ toVersion: toVersion,
1287
+ triggeredBy: input?.triggeredBy ?? "operator",
1288
+ reason: typeof input?.reason === "string" ? input.reason : "manual_restore",
1289
+ completedEntities: restoreResult.completedEntities,
1290
+ failedEntities: restoreResult.failedEntities,
1291
+ // credentials are always excluded from restore audit
1292
+ excludedFields: Array.isArray(input?.excludedFields)
1293
+ ? input.excludedFields.filter((f) => typeof f === "string")
1294
+ : ["credential", "encryptionKey"],
1295
+ restoredFieldCount: restoreResult.completedEntities.length,
1296
+ createdAt: generatedAt,
1297
+ traceId: typeof input?.traceId === "string" ? input.traceId : `trace-restore-${Date.now()}`,
1298
+ };
1299
+ const auditResult = await writeRestoreAudit(event, deps.auditStore);
1300
+ const envelope = {
1301
+ ok: restoreResult.ok && auditResult.ok,
1302
+ command: "restore",
1303
+ runtimeMode: "workspace_full_runtime",
1304
+ surfaceMode: "cli",
1305
+ generatedAt,
1306
+ data: {
1307
+ auditWritten: auditResult.warnings.length === 0,
1308
+ fromVersion: event.fromVersion,
1309
+ toVersion: event.toVersion,
1310
+ restoreTarget: event.restoreTarget,
1311
+ isPartialRestore: event.failedEntities.length > 0,
1312
+ failedEntities: event.failedEntities,
1313
+ completedEntities: event.completedEntities,
1314
+ restoreSnapshotStoreAvailable: !!deps.restoreSnapshotStore,
1315
+ },
1316
+ warnings: [...restoreResult.warnings, ...auditResult.warnings],
1317
+ sourceRefs: [
1318
+ "observability/services/restore-audit-service.ts",
1319
+ "storage/services/restore-snapshot-store.ts",
1320
+ ],
1321
+ };
1322
+ return envelope;
1323
+ }
1324
+ /**
1325
+ * [G7] runtime_secret_bootstrap — RuntimeSecretAnchorView pass-through.
1326
+ * Requires secretAnchorDeps in OpsRouterDeps; never returns key plaintext.
1327
+ */
1328
+ if (command === "runtime_secret_bootstrap") {
1329
+ const generatedAt = new Date().toISOString();
1330
+ if (!deps.secretAnchorDeps) {
1331
+ const envelope = {
1332
+ ok: false,
1333
+ command: "runtime_secret_bootstrap",
1334
+ runtimeMode: "unavailable",
1335
+ surfaceMode: "cli",
1336
+ generatedAt,
1337
+ error: {
1338
+ code: "SECRET_ANCHOR_DEPS_UNAVAILABLE",
1339
+ message: "runtime_secret_bootstrap requires secretAnchorDeps in OpsRouterDeps",
1340
+ nextStep: "wire_secret_anchor_deps_into_ops_router",
1341
+ },
1342
+ warnings: [],
1343
+ sourceRefs: [],
1344
+ };
1345
+ return envelope;
1346
+ }
1347
+ try {
1348
+ const view = await viewSecretAnchor(deps.secretAnchorDeps);
1349
+ // Map to RuntimeSecretBootstrapView (design model §6.1)
1350
+ const data = {
1351
+ status: view.status === "verified" || view.status === "ok"
1352
+ ? "ok"
1353
+ : view.status === "missing"
1354
+ ? "runtime_secret_anchor_missing"
1355
+ : view.status === "wrong_key"
1356
+ ? "credential_recovery_required"
1357
+ : view.status === "decryption_failed"
1358
+ ? "runtime_secret_unavailable"
1359
+ : "unknown",
1360
+ keyHealth: view.status === "verified" || view.status === "ok"
1361
+ ? "ok"
1362
+ : view.status === "missing"
1363
+ ? "missing_key"
1364
+ : view.status === "wrong_key"
1365
+ ? "wrong_key"
1366
+ : "unknown",
1367
+ anchorLocation: view.keyPath,
1368
+ recoveryPrincipleRef: view.recoveryDocRef,
1369
+ plaintextKeyExposed: false,
1370
+ reasonCode: view.reasonCode,
1371
+ recoverySteps: view.recoverySteps,
1372
+ };
1373
+ const envelope = {
1374
+ ok: true,
1375
+ command: "runtime_secret_bootstrap",
1376
+ runtimeMode: "workspace_full_runtime",
1377
+ surfaceMode: "cli",
1378
+ generatedAt,
1379
+ data,
1380
+ warnings: [],
1381
+ sourceRefs: ["observability/services/runtime-secret-anchor-view.ts"],
1382
+ };
1383
+ return envelope;
1384
+ }
1385
+ catch (err) {
1386
+ const msg = err instanceof Error ? err.message : String(err);
1387
+ const envelope = {
1388
+ ok: false,
1389
+ command: "runtime_secret_bootstrap",
1390
+ runtimeMode: "unavailable",
1391
+ surfaceMode: "cli",
1392
+ generatedAt,
1393
+ error: { code: "SECRET_ANCHOR_PROBE_FAILED", message: msg },
1394
+ warnings: [],
1395
+ sourceRefs: [],
1396
+ };
1397
+ return envelope;
1398
+ }
1399
+ }
1400
+ // ─── T-V7C.C.4R: guidance_payload ──────────────────────────────────────
1401
+ // Returns the assembled impulse + atmosphere for a given scene context.
1402
+ // Useful for Claw to inspect what guidance content would be injected before
1403
+ // a real heartbeat cycle, and to verify platform-specific impulse overrides.
1404
+ if (command === "guidance_payload") {
1405
+ const generatedAt = new Date().toISOString();
1406
+ const { assembleImpulseSync } = await import("../../guidance/impulse-assembler.js");
1407
+ const { getBaselineAtmosphereTemplate } = await import("../../guidance/template-registry.js");
1408
+ const sceneType = input?.sceneType ?? "social";
1409
+ const capabilityIntent = typeof input?.capabilityIntent === "string"
1410
+ ? input.capabilityIntent
1411
+ : undefined;
1412
+ const platformId = typeof input?.platformId === "string"
1413
+ ? input.platformId
1414
+ : undefined;
1415
+ const validSceneTypes = ["social", "reply", "outreach", "quiet", "explain", "user_reply"];
1416
+ if (!validSceneTypes.includes(sceneType)) {
1417
+ const envelope = {
1418
+ ok: false,
1419
+ command: "guidance_payload",
1420
+ runtimeMode: "unavailable",
1421
+ surfaceMode: "cli",
1422
+ generatedAt,
1423
+ error: {
1424
+ code: "INVALID_SCENE_TYPE",
1425
+ message: `sceneType must be one of: ${validSceneTypes.join(", ")}`,
1426
+ nextStep: "reinvoke_with_valid_scene_type",
1427
+ },
1428
+ warnings: [],
1429
+ sourceRefs: [],
1430
+ };
1431
+ return envelope;
1432
+ }
1433
+ const impulseResult = assembleImpulseSync({
1434
+ sceneType: sceneType,
1435
+ capabilityIntent,
1436
+ platformId,
1437
+ });
1438
+ const { buildExpressionBoundary } = await import("../../guidance/output-guard.js");
1439
+ const { getShortAtmosphereTemplate } = await import("../../guidance/template-registry.js");
1440
+ const atmosphere = getShortAtmosphereTemplate("active", "low");
1441
+ const expressionBoundary = buildExpressionBoundary(sceneType);
1442
+ const envelope = {
1443
+ ok: true,
1444
+ command: "guidance_payload",
1445
+ runtimeMode: deps.runtimeAvailable ? "workspace_full_runtime" : "host_safe_carrier",
1446
+ surfaceMode: "cli",
1447
+ generatedAt,
1448
+ data: {
1449
+ sceneType,
1450
+ capabilityIntent: capabilityIntent ?? null,
1451
+ platformId: platformId ?? null,
1452
+ capabilityClass: impulseResult.capabilityClass,
1453
+ impulseSource: impulseResult.source,
1454
+ impulseText: impulseResult.impulse?.text ?? null,
1455
+ impulseReviewStatus: impulseResult.impulse?.reviewStatus ?? null,
1456
+ atmosphereText: atmosphere.text,
1457
+ atmosphereReviewStatus: atmosphere.reviewStatus,
1458
+ expressionBoundaryConstraints: expressionBoundary.constraints,
1459
+ expressionBoundaryStyle: expressionBoundary.style,
1460
+ },
1461
+ warnings: impulseResult.source === "none"
1462
+ ? ["no_impulse_available_for_this_scene_and_capability"]
1463
+ : [],
1464
+ sourceRefs: [
1465
+ "guidance/capability-class.ts",
1466
+ "guidance/impulse-assembler.ts",
1467
+ "guidance/template-registry.ts",
1468
+ "guidance/output-guard.ts",
1469
+ ],
1470
+ };
1471
+ return envelope;
1472
+ }
1473
+ return {
1474
+ ok: false,
1475
+ error: {
1476
+ code: "unknown_ops_command",
1477
+ message: `Unknown ops command: ${command}`,
1478
+ },
1479
+ };
1480
+ },
1481
+ };
1482
+ }