@ouro.bot/cli 0.1.0-alpha.56 → 0.1.0-alpha.561

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 (396) hide show
  1. package/README.md +127 -23
  2. package/RepairGuide.ouro/agent.json +5 -0
  3. package/RepairGuide.ouro/psyche/IDENTITY.md +19 -0
  4. package/RepairGuide.ouro/psyche/SOUL.md +55 -0
  5. package/RepairGuide.ouro/skills/diagnose-broken-remote.md +63 -0
  6. package/RepairGuide.ouro/skills/diagnose-stacked-typed-issues.md +35 -0
  7. package/RepairGuide.ouro/skills/diagnose-sync-blocked.md +54 -0
  8. package/RepairGuide.ouro/skills/diagnose-vault-expired.md +60 -0
  9. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +4 -2
  10. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
  11. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
  12. package/changelog.json +3604 -0
  13. package/dist/arc/attention-types.js +8 -0
  14. package/dist/arc/cares.js +140 -0
  15. package/dist/arc/episodes.js +117 -0
  16. package/dist/arc/intentions.js +133 -0
  17. package/dist/arc/json-store.js +117 -0
  18. package/dist/arc/obligations.js +237 -0
  19. package/dist/arc/packets.js +193 -0
  20. package/dist/arc/presence.js +185 -0
  21. package/dist/arc/task-lifecycle.js +65 -0
  22. package/dist/heart/active-work.js +837 -26
  23. package/dist/heart/agent-entry.js +58 -3
  24. package/dist/heart/attachments/image-normalize.js +194 -0
  25. package/dist/heart/attachments/materialize.js +97 -0
  26. package/dist/heart/attachments/originals.js +88 -0
  27. package/dist/heart/attachments/render.js +29 -0
  28. package/dist/heart/attachments/sources/adapter.js +2 -0
  29. package/dist/heart/attachments/sources/bluebubbles.js +156 -0
  30. package/dist/heart/attachments/sources/cli-local-file.js +78 -0
  31. package/dist/heart/attachments/sources/index.js +16 -0
  32. package/dist/heart/attachments/store.js +103 -0
  33. package/dist/heart/attachments/types.js +93 -0
  34. package/dist/heart/auth/auth-flow.js +479 -0
  35. package/dist/heart/background-operations.js +281 -0
  36. package/dist/heart/bundle-state.js +168 -0
  37. package/dist/heart/commitments.js +111 -0
  38. package/dist/heart/config-registry.js +322 -0
  39. package/dist/heart/config.js +114 -118
  40. package/dist/heart/core.js +913 -246
  41. package/dist/heart/cross-chat-delivery.js +3 -18
  42. package/dist/heart/daemon/agent-config-check.js +419 -0
  43. package/dist/heart/daemon/agent-discovery.js +102 -3
  44. package/dist/heart/daemon/agent-service.js +522 -0
  45. package/dist/heart/daemon/agentic-repair.js +547 -0
  46. package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
  47. package/dist/heart/daemon/boot-sync-probe.js +197 -0
  48. package/dist/heart/daemon/cadence.js +70 -0
  49. package/dist/heart/daemon/cli-defaults.js +776 -0
  50. package/dist/heart/daemon/cli-exec.js +7457 -0
  51. package/dist/heart/daemon/cli-help.js +498 -0
  52. package/dist/heart/daemon/cli-parse.js +1592 -0
  53. package/dist/heart/daemon/cli-render-doctor.js +57 -0
  54. package/dist/heart/daemon/cli-render.js +763 -0
  55. package/dist/heart/daemon/cli-types.js +8 -0
  56. package/dist/heart/daemon/connect-bay.js +323 -0
  57. package/dist/heart/daemon/daemon-cli.js +29 -1698
  58. package/dist/heart/daemon/daemon-entry.js +387 -2
  59. package/dist/heart/daemon/daemon-health.js +176 -0
  60. package/dist/heart/daemon/daemon-rollup.js +57 -0
  61. package/dist/heart/daemon/daemon-runtime-sync.js +88 -13
  62. package/dist/heart/daemon/daemon-tombstone.js +236 -0
  63. package/dist/heart/daemon/daemon.js +796 -71
  64. package/dist/heart/daemon/dns-workflow.js +394 -0
  65. package/dist/heart/daemon/doctor-types.js +8 -0
  66. package/dist/heart/daemon/doctor.js +826 -0
  67. package/dist/heart/daemon/health-monitor.js +122 -1
  68. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  69. package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
  70. package/dist/heart/daemon/http-health-probe.js +80 -0
  71. package/dist/heart/daemon/human-command-screens.js +234 -0
  72. package/dist/heart/daemon/human-readiness.js +114 -0
  73. package/dist/heart/daemon/inner-status.js +89 -0
  74. package/dist/heart/daemon/interactive-repair.js +394 -0
  75. package/dist/heart/daemon/launchd.js +37 -8
  76. package/dist/heart/daemon/log-tailer.js +82 -12
  77. package/dist/heart/daemon/logs-prune.js +110 -0
  78. package/dist/heart/daemon/mcp-canary.js +297 -0
  79. package/dist/heart/daemon/message-router.js +2 -2
  80. package/dist/heart/daemon/os-cron-deps.js +135 -0
  81. package/dist/heart/daemon/os-cron.js +14 -12
  82. package/dist/heart/daemon/ouro-bot-entry.js +4 -2
  83. package/dist/heart/daemon/ouro-entry.js +3 -1
  84. package/dist/heart/daemon/process-manager.js +375 -33
  85. package/dist/heart/daemon/provider-discovery.js +137 -0
  86. package/dist/heart/daemon/provider-ping-progress.js +83 -0
  87. package/dist/heart/daemon/pulse.js +475 -0
  88. package/dist/heart/daemon/readiness-repair.js +365 -0
  89. package/dist/heart/daemon/run-hooks.js +2 -0
  90. package/dist/heart/daemon/runtime-logging.js +67 -16
  91. package/dist/heart/daemon/runtime-metadata.js +3 -31
  92. package/dist/heart/daemon/safe-mode.js +161 -0
  93. package/dist/heart/daemon/sense-manager.js +389 -38
  94. package/dist/heart/daemon/session-id-resolver.js +131 -0
  95. package/dist/heart/daemon/skill-management-installer.js +94 -0
  96. package/dist/heart/daemon/socket-client.js +158 -11
  97. package/dist/heart/daemon/stale-bundle-prune.js +96 -0
  98. package/dist/heart/daemon/startup-tui.js +330 -0
  99. package/dist/heart/daemon/task-scheduler.js +3 -25
  100. package/dist/heart/daemon/terminal-ui.js +499 -0
  101. package/dist/heart/daemon/thoughts.js +162 -17
  102. package/dist/heart/daemon/up-progress.js +366 -0
  103. package/dist/heart/daemon/vault-items.js +56 -0
  104. package/dist/heart/delegation.js +1 -1
  105. package/dist/heart/habits/habit-migration.js +189 -0
  106. package/dist/heart/habits/habit-parser.js +140 -0
  107. package/dist/heart/habits/habit-runtime-state.js +100 -0
  108. package/dist/heart/habits/habit-scheduler.js +372 -0
  109. package/dist/heart/{daemon → hatch}/hatch-flow.js +32 -56
  110. package/dist/heart/{daemon → hatch}/hatch-specialist.js +6 -8
  111. package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
  112. package/dist/heart/{daemon → hatch}/specialist-tools.js +35 -12
  113. package/dist/heart/identity.js +203 -57
  114. package/dist/heart/kept-notes.js +357 -0
  115. package/dist/heart/kicks.js +1 -1
  116. package/dist/heart/machine-identity.js +161 -0
  117. package/dist/heart/mail-import-discovery.js +353 -0
  118. package/dist/heart/mailbox/mailbox-http-hooks.js +66 -0
  119. package/dist/heart/mailbox/mailbox-http-response.js +7 -0
  120. package/dist/heart/mailbox/mailbox-http-routes.js +246 -0
  121. package/dist/heart/mailbox/mailbox-http-static.js +103 -0
  122. package/dist/heart/mailbox/mailbox-http-transport.js +116 -0
  123. package/dist/heart/mailbox/mailbox-http.js +99 -0
  124. package/dist/heart/mailbox/mailbox-read.js +31 -0
  125. package/dist/heart/mailbox/mailbox-types.js +27 -0
  126. package/dist/heart/mailbox/mailbox-view.js +195 -0
  127. package/dist/heart/mailbox/readers/agent-machine.js +382 -0
  128. package/dist/heart/mailbox/readers/continuity-readers.js +338 -0
  129. package/dist/heart/mailbox/readers/mail.js +362 -0
  130. package/dist/heart/mailbox/readers/runtime-readers.js +651 -0
  131. package/dist/heart/mailbox/readers/sessions.js +232 -0
  132. package/dist/heart/mailbox/readers/shared.js +111 -0
  133. package/dist/heart/mcp/mcp-server.js +683 -0
  134. package/dist/heart/migrate-config.js +100 -0
  135. package/dist/heart/model-capabilities.js +19 -0
  136. package/dist/heart/platform.js +81 -0
  137. package/dist/heart/provider-attempt.js +134 -0
  138. package/dist/heart/provider-binding-resolver.js +267 -0
  139. package/dist/heart/provider-credentials.js +425 -0
  140. package/dist/heart/provider-failover.js +301 -0
  141. package/dist/heart/provider-models.js +81 -0
  142. package/dist/heart/provider-ping.js +262 -0
  143. package/dist/heart/provider-readiness-cache.js +40 -0
  144. package/dist/heart/provider-visibility.js +188 -0
  145. package/dist/heart/providers/anthropic-token.js +131 -0
  146. package/dist/heart/providers/anthropic.js +139 -52
  147. package/dist/heart/providers/azure.js +97 -13
  148. package/dist/heart/providers/error-classification.js +127 -0
  149. package/dist/heart/providers/github-copilot.js +145 -0
  150. package/dist/heart/providers/minimax-vlm.js +189 -0
  151. package/dist/heart/providers/minimax.js +26 -8
  152. package/dist/heart/providers/openai-codex.js +55 -40
  153. package/dist/heart/runtime-capability-check.js +170 -0
  154. package/dist/heart/runtime-credentials.js +367 -0
  155. package/dist/heart/runtime-cwd.js +87 -0
  156. package/dist/heart/sense-truth.js +13 -4
  157. package/dist/heart/session-activity.js +43 -22
  158. package/dist/heart/session-events.js +1149 -0
  159. package/dist/heart/session-playback-cli-main.js +5 -0
  160. package/dist/heart/session-playback-cli.js +36 -0
  161. package/dist/heart/session-playback.js +231 -0
  162. package/dist/heart/session-stats-cli-main.js +5 -0
  163. package/dist/heart/session-stats.js +182 -0
  164. package/dist/heart/session-transcript.js +243 -0
  165. package/dist/heart/start-of-turn-packet.js +345 -0
  166. package/dist/heart/streaming.js +44 -27
  167. package/dist/heart/sync-classification.js +176 -0
  168. package/dist/heart/sync.js +449 -0
  169. package/dist/heart/target-resolution.js +9 -5
  170. package/dist/heart/tempo.js +93 -0
  171. package/dist/heart/temporal-view.js +41 -0
  172. package/dist/heart/timeouts.js +101 -0
  173. package/dist/heart/tool-activity-callbacks.js +59 -0
  174. package/dist/heart/tool-description.js +139 -0
  175. package/dist/heart/tool-friction.js +55 -0
  176. package/dist/heart/tool-loop.js +200 -0
  177. package/dist/heart/turn-context.js +389 -0
  178. package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +6 -5
  179. package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
  180. package/dist/heart/versioning/ouro-path-installer.js +426 -0
  181. package/dist/heart/versioning/ouro-version-manager.js +295 -0
  182. package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
  183. package/dist/heart/{daemon → versioning}/update-checker.js +6 -1
  184. package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
  185. package/dist/mailbox-ui/assets/index-B-461hes.js +61 -0
  186. package/dist/mailbox-ui/assets/index-BPr5vNuM.css +1 -0
  187. package/dist/mailbox-ui/index.html +15 -0
  188. package/dist/mailroom/attention.js +167 -0
  189. package/dist/mailroom/autonomy.js +209 -0
  190. package/dist/mailroom/blob-store.js +674 -0
  191. package/dist/mailroom/body-cache.js +61 -0
  192. package/dist/mailroom/core.js +720 -0
  193. package/dist/mailroom/entry.js +160 -0
  194. package/dist/mailroom/file-store.js +430 -0
  195. package/dist/mailroom/mbox-import.js +383 -0
  196. package/dist/mailroom/outbound.js +380 -0
  197. package/dist/mailroom/policy.js +263 -0
  198. package/dist/mailroom/reader.js +233 -0
  199. package/dist/mailroom/search-cache.js +256 -0
  200. package/dist/mailroom/search-relevance.js +319 -0
  201. package/dist/mailroom/smtp-ingress.js +176 -0
  202. package/dist/mailroom/source-state.js +176 -0
  203. package/dist/mailroom/thread.js +109 -0
  204. package/dist/mailroom/travel-extract.js +89 -0
  205. package/dist/mind/bundle-manifest.js +7 -1
  206. package/dist/mind/context.js +165 -101
  207. package/dist/mind/diary-integrity.js +60 -0
  208. package/dist/mind/{memory.js → diary.js} +62 -75
  209. package/dist/mind/embedding-provider.js +60 -0
  210. package/dist/mind/file-state.js +179 -0
  211. package/dist/mind/friends/channel.js +39 -0
  212. package/dist/mind/friends/resolver.js +54 -2
  213. package/dist/mind/friends/store-file.js +39 -3
  214. package/dist/mind/friends/types.js +2 -2
  215. package/dist/mind/journal-index.js +161 -0
  216. package/dist/mind/note-search.js +268 -0
  217. package/dist/mind/obligation-steering.js +221 -0
  218. package/dist/mind/pending.js +4 -0
  219. package/dist/mind/prompt-refresh.js +3 -2
  220. package/dist/mind/prompt.js +1011 -123
  221. package/dist/mind/provenance-trust.js +26 -0
  222. package/dist/mind/scrutiny.js +173 -0
  223. package/dist/nerves/cli-logging.js +7 -1
  224. package/dist/nerves/coverage/audit-rules.js +15 -6
  225. package/dist/nerves/coverage/audit.js +28 -2
  226. package/dist/nerves/coverage/cli.js +1 -1
  227. package/dist/nerves/coverage/contract.js +5 -5
  228. package/dist/nerves/coverage/file-completeness.js +129 -5
  229. package/dist/nerves/coverage/run-artifacts.js +1 -1
  230. package/dist/nerves/event-buffer.js +111 -0
  231. package/dist/nerves/index.js +224 -4
  232. package/dist/nerves/observation.js +20 -0
  233. package/dist/nerves/redact.js +79 -0
  234. package/dist/nerves/review/cli-main.js +5 -0
  235. package/dist/nerves/review/cli.js +156 -0
  236. package/dist/nerves/review/core.js +152 -0
  237. package/dist/nerves/runtime.js +5 -1
  238. package/dist/repertoire/ado-client.js +15 -56
  239. package/dist/repertoire/ado-semantic.js +11 -10
  240. package/dist/repertoire/api-client.js +97 -0
  241. package/dist/repertoire/bitwarden-store.js +963 -0
  242. package/dist/repertoire/bundle-templates.js +72 -0
  243. package/dist/repertoire/bw-installer.js +180 -0
  244. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  245. package/dist/repertoire/coding/context-pack.js +330 -0
  246. package/dist/repertoire/coding/feedback.js +197 -30
  247. package/dist/repertoire/coding/manager.js +158 -9
  248. package/dist/repertoire/coding/spawner.js +55 -9
  249. package/dist/repertoire/coding/tools.js +170 -7
  250. package/dist/repertoire/commerce-errors.js +109 -0
  251. package/dist/repertoire/commerce-self-test.js +156 -0
  252. package/dist/repertoire/credential-access.js +178 -0
  253. package/dist/repertoire/duffel-client.js +185 -0
  254. package/dist/repertoire/github-client.js +14 -55
  255. package/dist/repertoire/graph-client.js +11 -52
  256. package/dist/repertoire/guardrails.js +396 -0
  257. package/dist/repertoire/mcp-client.js +295 -0
  258. package/dist/repertoire/mcp-manager.js +362 -0
  259. package/dist/repertoire/mcp-tools.js +63 -0
  260. package/dist/repertoire/shell-sessions.js +133 -0
  261. package/dist/repertoire/skills.js +15 -24
  262. package/dist/repertoire/stripe-client.js +131 -0
  263. package/dist/repertoire/tasks/board.js +31 -5
  264. package/dist/repertoire/tasks/fix.js +182 -0
  265. package/dist/repertoire/tasks/index.js +16 -4
  266. package/dist/repertoire/tasks/lifecycle.js +2 -2
  267. package/dist/repertoire/tasks/parser.js +3 -2
  268. package/dist/repertoire/tasks/scanner.js +194 -37
  269. package/dist/repertoire/tasks/transitions.js +16 -78
  270. package/dist/repertoire/tool-results.js +29 -0
  271. package/dist/repertoire/tools-attachments.js +317 -0
  272. package/dist/repertoire/tools-base.js +47 -1075
  273. package/dist/repertoire/tools-bluebubbles.js +1 -0
  274. package/dist/repertoire/tools-bridge.js +142 -0
  275. package/dist/repertoire/tools-bundle.js +984 -0
  276. package/dist/repertoire/tools-config.js +185 -0
  277. package/dist/repertoire/tools-continuity.js +248 -0
  278. package/dist/repertoire/tools-credential.js +381 -0
  279. package/dist/repertoire/tools-files.js +342 -0
  280. package/dist/repertoire/tools-flight.js +224 -0
  281. package/dist/repertoire/tools-flow.js +119 -0
  282. package/dist/repertoire/tools-github.js +1 -7
  283. package/dist/repertoire/tools-mail.js +1857 -0
  284. package/dist/repertoire/tools-notes.js +421 -0
  285. package/dist/repertoire/tools-session.js +750 -0
  286. package/dist/repertoire/tools-shell.js +120 -0
  287. package/dist/repertoire/tools-stripe.js +180 -0
  288. package/dist/repertoire/tools-surface.js +243 -0
  289. package/dist/repertoire/tools-teams.js +9 -39
  290. package/dist/repertoire/tools-travel.js +125 -0
  291. package/dist/repertoire/tools-trip.js +604 -0
  292. package/dist/repertoire/tools-user-profile.js +144 -0
  293. package/dist/repertoire/tools-vault.js +40 -0
  294. package/dist/repertoire/tools.js +108 -100
  295. package/dist/repertoire/travel-api-client.js +360 -0
  296. package/dist/repertoire/user-profile.js +131 -0
  297. package/dist/repertoire/vault-setup.js +246 -0
  298. package/dist/repertoire/vault-unlock.js +594 -0
  299. package/dist/scripts/claude-code-hook.js +41 -0
  300. package/dist/scripts/claude-code-stop-hook.js +47 -0
  301. package/dist/senses/attention-queue.js +116 -0
  302. package/dist/senses/bluebubbles/active-turns.js +216 -0
  303. package/dist/senses/bluebubbles/attachment-cache.js +53 -0
  304. package/dist/senses/bluebubbles/attachment-download.js +137 -0
  305. package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +219 -18
  306. package/dist/senses/bluebubbles/entry.js +77 -0
  307. package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +20 -3
  308. package/dist/senses/bluebubbles/index.js +2305 -0
  309. package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
  310. package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
  311. package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +3 -3
  312. package/dist/senses/bluebubbles/processed-log.js +133 -0
  313. package/dist/senses/bluebubbles/replay.js +137 -0
  314. package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +30 -2
  315. package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
  316. package/dist/senses/cli/bracketed-paste.js +82 -0
  317. package/dist/senses/cli/image-paste.js +287 -0
  318. package/dist/senses/cli/image-ref-navigation.js +75 -0
  319. package/dist/senses/cli/ink-app.js +156 -0
  320. package/dist/senses/cli/inline-diff.js +64 -0
  321. package/dist/senses/cli/input-keys.js +174 -0
  322. package/dist/senses/cli/kill-ring.js +86 -0
  323. package/dist/senses/cli/message-list.js +51 -0
  324. package/dist/senses/cli/ouro-tui.js +607 -0
  325. package/dist/senses/cli/spinner-imperative.js +135 -0
  326. package/dist/senses/cli/spinner.js +101 -0
  327. package/dist/senses/cli/status-line.js +60 -0
  328. package/dist/senses/cli/streaming-markdown.js +526 -0
  329. package/dist/senses/cli/tool-display.js +85 -0
  330. package/dist/senses/cli/tool-render.js +85 -0
  331. package/dist/senses/cli/tui-store.js +240 -0
  332. package/dist/senses/cli/virtual-list.js +35 -0
  333. package/dist/senses/cli-entry.js +60 -8
  334. package/dist/senses/cli-layout.js +187 -0
  335. package/dist/senses/cli.js +520 -209
  336. package/dist/senses/commands.js +66 -3
  337. package/dist/senses/habit-turn-message.js +108 -0
  338. package/dist/senses/inner-dialog-worker.js +175 -21
  339. package/dist/senses/inner-dialog.js +330 -27
  340. package/dist/senses/mail-entry.js +66 -0
  341. package/dist/senses/mail.js +379 -0
  342. package/dist/senses/pipeline.js +549 -181
  343. package/dist/senses/proactive-content-guard.js +51 -0
  344. package/dist/senses/shared-turn.js +251 -0
  345. package/dist/senses/surface-tool.js +68 -0
  346. package/dist/senses/teams-entry.js +60 -8
  347. package/dist/senses/teams.js +387 -98
  348. package/dist/senses/trust-gate.js +100 -5
  349. package/dist/senses/voice/audio-routing.js +119 -0
  350. package/dist/senses/voice/elevenlabs.js +178 -0
  351. package/dist/senses/voice/golden-path.js +116 -0
  352. package/dist/senses/voice/index.js +26 -0
  353. package/dist/senses/voice/meeting.js +113 -0
  354. package/dist/senses/voice/playback.js +139 -0
  355. package/dist/senses/voice/transcript.js +70 -0
  356. package/dist/senses/voice/turn.js +85 -0
  357. package/dist/senses/voice/types.js +2 -0
  358. package/dist/senses/voice/whisper.js +161 -0
  359. package/dist/senses/voice-entry.js +80 -0
  360. package/dist/trips/core.js +138 -0
  361. package/dist/trips/store.js +146 -0
  362. package/package.json +38 -7
  363. package/skills/agent-commerce.md +106 -0
  364. package/skills/browser-navigation.md +117 -0
  365. package/skills/commerce-setup-guide.md +116 -0
  366. package/skills/commerce-setup.md +84 -0
  367. package/skills/configure-dev-tools.md +101 -0
  368. package/skills/travel-planning.md +138 -0
  369. package/dist/heart/daemon/auth-flow.js +0 -351
  370. package/dist/heart/daemon/ouro-path-installer.js +0 -178
  371. package/dist/heart/daemon/subagent-installer.js +0 -166
  372. package/dist/heart/session-recall.js +0 -116
  373. package/dist/mind/associative-recall.js +0 -209
  374. package/dist/senses/bluebubbles-entry.js +0 -13
  375. package/dist/senses/bluebubbles.js +0 -1177
  376. package/dist/senses/debug-activity.js +0 -148
  377. package/subagents/README.md +0 -86
  378. package/subagents/work-doer.md +0 -237
  379. package/subagents/work-merger.md +0 -618
  380. package/subagents/work-planner.md +0 -390
  381. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  382. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  383. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  384. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  385. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  386. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  387. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  388. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  389. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  390. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  391. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  392. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
  393. /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
  394. /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
  395. /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
  396. /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
@@ -0,0 +1,963 @@
1
+ "use strict";
2
+ /**
3
+ * Bitwarden CLI credential store — wraps `bw` CLI for the agent's own vault.
4
+ *
5
+ * This store authenticates directly as the agent using its own master password.
6
+ * The agent owns the vault, so no human-in-the-loop is needed.
7
+ *
8
+ * Requires the `bw` CLI to be installed. Session tokens are cached process-local.
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.BitwardenCredentialStore = void 0;
45
+ exports.sanitizeCredentialErrorDetail = sanitizeCredentialErrorDetail;
46
+ const node_child_process_1 = require("node:child_process");
47
+ const fs = __importStar(require("node:fs"));
48
+ const path = __importStar(require("node:path"));
49
+ const runtime_1 = require("../nerves/runtime");
50
+ const bw_installer_1 = require("./bw-installer");
51
+ const MAX_ERROR_DETAIL_LENGTH = 500;
52
+ const LONG_ENCODED_TOKEN_PATTERN = /[A-Za-z0-9+/=]{32,}/g;
53
+ const BW_PASSWORD_ENV = "OURO_BW_MASTER_PASSWORD";
54
+ function uniqueSecrets(secrets) {
55
+ return [...new Set(secrets.filter((value) => typeof value === "string" && value.length >= 4))].sort((left, right) => right.length - left.length);
56
+ }
57
+ function sanitizeCredentialErrorDetail(message, options = {}) {
58
+ const filtered = message
59
+ .split(/\r?\n/)
60
+ .filter((line) => {
61
+ const trimmed = line.trim();
62
+ if (trimmed.startsWith("Command failed:"))
63
+ return false;
64
+ if (trimmed.includes("[input is hidden]"))
65
+ return false;
66
+ return true;
67
+ })
68
+ .join("\n")
69
+ .trim();
70
+ let sanitized = filtered || "command failed";
71
+ for (const secret of uniqueSecrets(options.secrets ?? [])) {
72
+ sanitized = sanitized.split(secret).join("[redacted]");
73
+ }
74
+ sanitized = sanitized.replace(LONG_ENCODED_TOKEN_PATTERN, "[redacted]");
75
+ if (sanitized.replace(/\[redacted\]/g, "").trim().length === 0) {
76
+ return "command failed";
77
+ }
78
+ return sanitized.slice(0, MAX_ERROR_DETAIL_LENGTH);
79
+ }
80
+ // ---------------------------------------------------------------------------
81
+ // bw CLI wrapper
82
+ // ---------------------------------------------------------------------------
83
+ function isBwSessionUnavailableMessage(message) {
84
+ return (/master password/i.test(message) ||
85
+ /vault is locked/i.test(message) ||
86
+ /not logged in/i.test(message) ||
87
+ /session key/i.test(message) ||
88
+ /local bitwarden session/i.test(message));
89
+ }
90
+ function isBwInvalidUnlockSecretMessage(message) {
91
+ return (/invalid master password/i.test(message) ||
92
+ /saved vault unlock secret/i.test(message) ||
93
+ /username or password is incorrect/i.test(message));
94
+ }
95
+ function isBwTimeoutError(err) {
96
+ const timeoutErr = err;
97
+ const message = err.message.toLowerCase();
98
+ return (timeoutErr.code === "ETIMEDOUT" ||
99
+ timeoutErr.killed === true ||
100
+ timeoutErr.signal === "SIGTERM" ||
101
+ message.includes("timed out"));
102
+ }
103
+ function formatBwOperation(args) {
104
+ const [command, target] = args;
105
+ /* v8 ignore next -- defensive: all execBw call sites pass a concrete bw subcommand @preserve */
106
+ if (!command)
107
+ return "bw command";
108
+ return [command, target].filter(Boolean).join(" ");
109
+ }
110
+ function sanitizeBwErrorDetail(message) {
111
+ if (isBwInvalidUnlockSecretMessage(message)) {
112
+ return "bw CLI rejected the saved vault unlock secret for this machine";
113
+ }
114
+ if (isBwSessionUnavailableMessage(message)) {
115
+ return "bw CLI could not use the local Bitwarden session because it is locked, missing, or expired";
116
+ }
117
+ return sanitizeCredentialErrorDetail(message);
118
+ }
119
+ function formatBwCliError(err, stderr = "", args = []) {
120
+ const operation = formatBwOperation(args);
121
+ if (isBwTimeoutError(err)) {
122
+ return new Error(`bw CLI error: ${operation} timed out -- usually resolves on retry. If it persists, check network connectivity to the vault server.`);
123
+ }
124
+ const detail = sanitizeBwErrorDetail(stderr.trim() || err.message);
125
+ if (detail === "command failed") {
126
+ return new Error(`bw CLI error: ${operation} failed without error detail`);
127
+ }
128
+ return new Error(`bw CLI error: ${detail}`);
129
+ }
130
+ function isBwSessionAuthError(err) {
131
+ return isBwSessionUnavailableMessage(err.message) || isBwInvalidUnlockSecretMessage(err.message);
132
+ }
133
+ function isBwConfigLogoutRequired(err) {
134
+ const message = err.message.toLowerCase();
135
+ return message.includes("logout") && message.includes("required");
136
+ }
137
+ function isBwAlreadyLoggedInError(err) {
138
+ return err.message.toLowerCase().includes("already logged in");
139
+ }
140
+ function isBwLoggedOutOrUnauthenticatedError(err) {
141
+ const message = err.message.toLowerCase();
142
+ return (message.includes("not logged in") ||
143
+ message.includes("not authenticated") ||
144
+ message.includes("unauthenticated") ||
145
+ message.includes("local bitwarden session because it is locked, missing, or expired"));
146
+ }
147
+ function shouldUseStructuredItemLookup(domain) {
148
+ return domain.includes("/");
149
+ }
150
+ function shouldUseFullListForStructuredLookup(domain, appDataDir) {
151
+ return domain.includes("/") && !appDataDir;
152
+ }
153
+ function isBwItemNotFoundError(error) {
154
+ const message = error.message.toLowerCase();
155
+ return message.includes("not found") || message.includes("no item");
156
+ }
157
+ // ---------------------------------------------------------------------------
158
+ // Cross-process bw CLI lock
159
+ // ---------------------------------------------------------------------------
160
+ // The bw CLI cannot handle concurrent access to the same app data directory.
161
+ // Two processes (e.g. daemon worker + ouro up CLI) hitting the same dir
162
+ // simultaneously corrupt bw's local state, producing empty/garbled output.
163
+ //
164
+ // We use two layers:
165
+ // 1. In-process async mutex: a Map<string, Promise<void>> keyed by appDataDir
166
+ // serializes calls within a single Node.js process.
167
+ // 2. Cross-process file lock: fs.openSync(lockPath, 'wx') with PID stale
168
+ // detection serializes across processes.
169
+ // ---------------------------------------------------------------------------
170
+ const BW_LOCK_FILENAME = ".ouro-bw.lock";
171
+ const BW_LOCK_TIMEOUT_MS = 30_000;
172
+ const BW_LOCK_POLL_MS = 100;
173
+ const BW_DATA_FILENAME = "data.json";
174
+ const BW_SYNC_MARKER_FILENAME = ".ouro-last-sync";
175
+ const BW_SYNC_FRESH_MS = 60_000;
176
+ /** In-process async mutex keyed by appDataDir. */
177
+ const inProcessLocks = new Map();
178
+ function isPidAlive(pid) {
179
+ try {
180
+ process.kill(pid, 0);
181
+ return true;
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ }
187
+ async function acquireFileLock(lockPath) {
188
+ const content = `${process.pid}\n`;
189
+ const deadline = Date.now() + BW_LOCK_TIMEOUT_MS;
190
+ while (true) {
191
+ try {
192
+ const fd = fs.openSync(lockPath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL);
193
+ fs.writeSync(fd, content);
194
+ fs.closeSync(fd);
195
+ return;
196
+ }
197
+ catch (err) {
198
+ if (err.code !== "EEXIST") {
199
+ throw err;
200
+ }
201
+ // Lock file exists -- check for stale lock
202
+ try {
203
+ const existing = fs.readFileSync(lockPath, "utf8").trim();
204
+ const pid = parseInt(existing, 10);
205
+ if (!isNaN(pid) && !isPidAlive(pid)) {
206
+ // Stale lock -- remove and retry immediately
207
+ try {
208
+ fs.unlinkSync(lockPath);
209
+ }
210
+ catch { /* race with another cleaner is fine */ }
211
+ continue;
212
+ }
213
+ }
214
+ catch { /* v8 ignore next -- race: lock file disappeared between openSync and readFileSync @preserve */
215
+ continue;
216
+ }
217
+ if (Date.now() >= deadline) {
218
+ throw new Error(`bw CLI lock timeout: could not acquire ${lockPath} within ${BW_LOCK_TIMEOUT_MS}ms`);
219
+ }
220
+ // Yield to the event loop before retrying
221
+ await delay(BW_LOCK_POLL_MS);
222
+ }
223
+ }
224
+ }
225
+ function releaseFileLock(lockPath) {
226
+ try {
227
+ fs.unlinkSync(lockPath);
228
+ }
229
+ catch {
230
+ // Already removed or never created -- safe to ignore
231
+ }
232
+ }
233
+ async function withBwLock(appDataDir, fn) {
234
+ if (!appDataDir) {
235
+ // No appDataDir means the default bw data location. Still need in-process
236
+ // serialization but cannot do cross-process file lock without a dir.
237
+ return fn();
238
+ }
239
+ const lockKey = appDataDir;
240
+ const lockPath = path.join(appDataDir, BW_LOCK_FILENAME);
241
+ // In-process serialization: chain onto the previous promise for this key
242
+ const previous = inProcessLocks.get(lockKey) ?? Promise.resolve();
243
+ let releaseLock;
244
+ const current = new Promise((resolve) => { releaseLock = resolve; });
245
+ inProcessLocks.set(lockKey, current);
246
+ await previous;
247
+ let fileLockAcquired = false;
248
+ try {
249
+ // Cross-process file lock
250
+ await acquireFileLock(lockPath);
251
+ fileLockAcquired = true;
252
+ return await fn();
253
+ }
254
+ finally {
255
+ if (fileLockAcquired) {
256
+ releaseFileLock(lockPath);
257
+ }
258
+ releaseLock();
259
+ // Clean up the map entry if we are the latest
260
+ if (inProcessLocks.get(lockKey) === current) {
261
+ inProcessLocks.delete(lockKey);
262
+ }
263
+ }
264
+ }
265
+ function execBw(args, sessionToken, appDataDir, stdin, bwBinaryPath = "bw", extraEnv = {}) {
266
+ const env = {
267
+ ...process.env,
268
+ ...(sessionToken ? { BW_SESSION: sessionToken } : {}),
269
+ ...(appDataDir ? { BITWARDENCLI_APPDATA_DIR: appDataDir } : {}),
270
+ ...extraEnv,
271
+ };
272
+ const runCommand = () => new Promise((resolve, reject) => {
273
+ const child = (0, node_child_process_1.execFile)(bwBinaryPath, args, { timeout: 30_000, env }, (err, stdout, stderr) => {
274
+ if (err) {
275
+ if (isBwNotInstalled(err)) {
276
+ reject(new Error("bw CLI not found. Install from https://bitwarden.com/help/cli/"));
277
+ return;
278
+ }
279
+ reject(formatBwCliError(err, stderr, args));
280
+ return;
281
+ }
282
+ resolve(stdout);
283
+ });
284
+ if (stdin !== undefined) {
285
+ child?.stdin?.end(stdin);
286
+ }
287
+ });
288
+ return withBwLock(appDataDir, runCommand);
289
+ }
290
+ /** Check if the error indicates the bw CLI binary is not installed. */
291
+ function isBwNotInstalled(err) {
292
+ const msg = err.message.toLowerCase();
293
+ const code = err.code;
294
+ return code === "ENOENT" || /\bspawn\b.*\benoent\b/.test(msg) || msg.includes("command not found");
295
+ }
296
+ /** Check if the error is transient (network/timeout) and worth retrying. */
297
+ function isTransientError(err) {
298
+ const msg = err.message.toLowerCase();
299
+ return (msg.includes("econnrefused") ||
300
+ msg.includes("etimedout") ||
301
+ msg.includes("enotfound") ||
302
+ msg.includes("socket hang up") ||
303
+ msg.includes("503") ||
304
+ msg.includes("server unavailable") ||
305
+ msg.includes("timed out"));
306
+ }
307
+ const MAX_RETRIES = 3;
308
+ const BASE_BACKOFF_MS = 1000;
309
+ const TRANSIENT_MAX_RETRIES = 3;
310
+ const TRANSIENT_RETRY_BASE_MS = 500;
311
+ function delay(ms) {
312
+ return new Promise((resolve) => setTimeout(resolve, ms));
313
+ }
314
+ function isBwLoginItem(value) {
315
+ if (!value || typeof value !== "object" || Array.isArray(value))
316
+ return false;
317
+ const item = value;
318
+ if (typeof item.id !== "string" || item.id.trim().length === 0)
319
+ return false;
320
+ if (typeof item.name !== "string" || item.name.trim().length === 0)
321
+ return false;
322
+ if (item.login !== undefined) {
323
+ if (!item.login || typeof item.login !== "object" || Array.isArray(item.login))
324
+ return false;
325
+ const login = item.login;
326
+ if (login.username !== undefined && typeof login.username !== "string")
327
+ return false;
328
+ if (login.password !== undefined && typeof login.password !== "string")
329
+ return false;
330
+ if (login.uris !== undefined) {
331
+ if (!Array.isArray(login.uris))
332
+ return false;
333
+ for (const uri of login.uris) {
334
+ if (!uri || typeof uri !== "object" || Array.isArray(uri))
335
+ return false;
336
+ const uriRecord = uri;
337
+ if (uriRecord.uri !== undefined && typeof uriRecord.uri !== "string")
338
+ return false;
339
+ }
340
+ }
341
+ }
342
+ if (item.notes !== undefined && item.notes !== null && typeof item.notes !== "string")
343
+ return false;
344
+ if (item.revisionDate !== undefined && typeof item.revisionDate !== "string")
345
+ return false;
346
+ return true;
347
+ }
348
+ function parseBwItems(stdout, context) {
349
+ let parsed;
350
+ try {
351
+ parsed = JSON.parse(stdout);
352
+ if (!Array.isArray(parsed)) {
353
+ throw new Error("expected item array");
354
+ }
355
+ const items = parsed;
356
+ if (!items.every(isBwLoginItem)) {
357
+ throw new Error("expected login items");
358
+ }
359
+ return items;
360
+ }
361
+ catch {
362
+ if (Array.isArray(parsed)) {
363
+ throw new Error(`bw CLI error: invalid item from ${context}`);
364
+ }
365
+ throw new Error(`bw CLI error: invalid JSON from ${context}`);
366
+ }
367
+ }
368
+ function parseBwItem(stdout, context) {
369
+ let parsed;
370
+ try {
371
+ parsed = JSON.parse(stdout);
372
+ if (!isBwLoginItem(parsed)) {
373
+ throw new Error("expected login item");
374
+ }
375
+ return parsed;
376
+ }
377
+ catch {
378
+ if (parsed !== undefined) {
379
+ throw new Error(`bw CLI error: invalid item from ${context}`);
380
+ }
381
+ throw new Error(`bw CLI error: invalid JSON from ${context}`);
382
+ }
383
+ }
384
+ function parseBwItemId(stdout) {
385
+ try {
386
+ const parsed = JSON.parse(stdout);
387
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
388
+ return null;
389
+ const id = parsed.id;
390
+ return typeof id === "string" && id.trim().length > 0 ? id : null;
391
+ }
392
+ catch {
393
+ return null;
394
+ }
395
+ }
396
+ // ---------------------------------------------------------------------------
397
+ // BitwardenCredentialStore
398
+ // ---------------------------------------------------------------------------
399
+ class BitwardenCredentialStore {
400
+ serverUrl;
401
+ email;
402
+ masterPassword;
403
+ appDataDir;
404
+ onInvalidUnlockSecret;
405
+ onLoginSuccess;
406
+ sessionToken = null;
407
+ terminalLoginError = null;
408
+ bwBinaryPath = "bw";
409
+ structuredItemCache = null;
410
+ constructor(serverUrl, email, masterPassword, options = {}) {
411
+ this.serverUrl = serverUrl;
412
+ this.email = email;
413
+ this.masterPassword = masterPassword;
414
+ this.appDataDir = options.appDataDir;
415
+ this.onInvalidUnlockSecret = options.onInvalidUnlockSecret;
416
+ this.onLoginSuccess = options.onLoginSuccess;
417
+ }
418
+ isReady() {
419
+ return true;
420
+ }
421
+ execBw(args, sessionToken, stdin) {
422
+ return execBw(args, sessionToken, this.appDataDir, stdin, this.bwBinaryPath);
423
+ }
424
+ execBwWithPasswordEnv(args) {
425
+ return execBw([...args, "--passwordenv", BW_PASSWORD_ENV], undefined, this.appDataDir, undefined, this.bwBinaryPath, { [BW_PASSWORD_ENV]: this.masterPassword });
426
+ }
427
+ async notifyInvalidUnlockSecret(error) {
428
+ if (!this.onInvalidUnlockSecret)
429
+ return;
430
+ try {
431
+ await this.onInvalidUnlockSecret(error);
432
+ }
433
+ catch (callbackError) {
434
+ (0, runtime_1.emitNervesEvent)({
435
+ level: "warn",
436
+ event: "repertoire.bw_invalid_unlock_cleanup_failed",
437
+ component: "repertoire",
438
+ message: "failed to clean up rejected local vault unlock material",
439
+ meta: {
440
+ email: this.email,
441
+ serverUrl: this.serverUrl,
442
+ error: callbackError instanceof Error ? callbackError.message : String(callbackError),
443
+ originalError: error.message,
444
+ },
445
+ });
446
+ }
447
+ }
448
+ /**
449
+ * Ensure the bw CLI is authenticated and unlocked.
450
+ * Handles three states: logged out → login, locked → unlock, already unlocked → no-op.
451
+ * Retries transient failures (network/timeout) up to MAX_RETRIES with exponential backoff.
452
+ */
453
+ async login() {
454
+ if (this.terminalLoginError) {
455
+ throw this.terminalLoginError;
456
+ }
457
+ // Ensure bw CLI is installed before any bw commands
458
+ this.bwBinaryPath = await (0, bw_installer_1.ensureBwCli)();
459
+ if (this.appDataDir) {
460
+ fs.mkdirSync(this.appDataDir, { recursive: true, mode: 0o700 });
461
+ }
462
+ let lastError;
463
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
464
+ try {
465
+ await this.loginAttempt();
466
+ await this.onLoginSuccess?.();
467
+ return;
468
+ }
469
+ catch (err) {
470
+ /* v8 ignore next -- defensive: loginAttempt always throws Error instances @preserve */
471
+ lastError = err instanceof Error ? err : new Error(String(err));
472
+ // Don't retry non-transient errors (auth failures, bw not installed)
473
+ if (!isTransientError(lastError)) {
474
+ this.terminalLoginError = lastError;
475
+ if (isBwInvalidUnlockSecretMessage(lastError.message)) {
476
+ await this.notifyInvalidUnlockSecret(lastError);
477
+ }
478
+ throw lastError;
479
+ }
480
+ // Don't retry after final attempt
481
+ if (attempt === MAX_RETRIES - 1)
482
+ break;
483
+ const backoffMs = BASE_BACKOFF_MS * Math.pow(2, attempt);
484
+ (0, runtime_1.emitNervesEvent)({
485
+ event: "repertoire.bw_login_retry",
486
+ component: "repertoire",
487
+ message: `bw login attempt ${attempt + 1} failed, retrying in ${backoffMs}ms`,
488
+ meta: { attempt: attempt + 1, backoffMs, reason: lastError.message },
489
+ });
490
+ await delay(backoffMs);
491
+ }
492
+ }
493
+ this.terminalLoginError = lastError;
494
+ /* v8 ignore next -- invalid unlock errors are non-transient and exit through the non-retry path above @preserve */
495
+ if (isBwInvalidUnlockSecretMessage(lastError.message)) {
496
+ await this.notifyInvalidUnlockSecret(lastError);
497
+ }
498
+ throw lastError;
499
+ }
500
+ /** Single login attempt — called by login() retry loop. */
501
+ async loginAttempt() {
502
+ let status = await this.readStatus();
503
+ if (this.shouldRebuildLocalProfile(status)) {
504
+ await this.rebuildLocalProfile("local bw profile did not match requested vault", status);
505
+ status = { status: "unlocked", serverUrl: this.serverUrl, userEmail: this.email };
506
+ }
507
+ // Configure server URL if needed (only works when logged out)
508
+ if (status.status === "unauthenticated" || !status.serverUrl) {
509
+ try {
510
+ await this.execBw(["config", "server", this.serverUrl]);
511
+ }
512
+ catch (error) {
513
+ const err = error;
514
+ if (!isBwConfigLogoutRequired(err))
515
+ throw err;
516
+ // "Logout required" means bw already has local auth state; keep the
517
+ // existing behavior and proceed to login/unlock below.
518
+ }
519
+ }
520
+ if (!this.sessionToken) {
521
+ if (status.status === "locked") {
522
+ // Already logged in, just needs unlock.
523
+ const unlockOutput = await this.execWithLocalProfileRebuild("unlock rejected saved local unlock material", status, () => this.execBwWithPasswordEnv(["unlock", "--raw"]));
524
+ this.sessionToken = unlockOutput.trim();
525
+ }
526
+ else if (status.status === "unauthenticated" || !status.status) {
527
+ // Not logged in -- full login.
528
+ this.sessionToken = this.sessionTokenFromLoginOutput(await this.loginWithPassword());
529
+ }
530
+ else {
531
+ // Status is "unlocked" -- already good, just need the session token.
532
+ const unlockOutput = await this.execWithLocalProfileRebuild("unlocked bw profile rejected saved local unlock material", status, () => this.execBwWithPasswordEnv(["unlock", "--raw"]));
533
+ this.sessionToken = unlockOutput.trim();
534
+ }
535
+ }
536
+ if (this.shouldSyncVaultAfterSession(status)) {
537
+ /* v8 ignore next -- defensive: loginAttempt always sets sessionToken before sync @preserve */
538
+ await this.execBw(["sync"], this.sessionToken ?? undefined);
539
+ this.writeSyncMarker();
540
+ }
541
+ else {
542
+ (0, runtime_1.emitNervesEvent)({
543
+ event: "repertoire.bw_sync_skipped",
544
+ component: "repertoire",
545
+ message: "skipping bw sync because local vault cache is still fresh",
546
+ meta: { email: this.email, serverUrl: this.serverUrl, freshnessWindowMs: BW_SYNC_FRESH_MS },
547
+ });
548
+ }
549
+ this.terminalLoginError = null;
550
+ }
551
+ async readStatus() {
552
+ try {
553
+ const raw = await this.execBw(["status"]);
554
+ const parsed = JSON.parse(raw);
555
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
556
+ return {};
557
+ const record = parsed;
558
+ return {
559
+ ...(typeof record.status === "string" ? { status: record.status } : {}),
560
+ ...(typeof record.serverUrl === "string" ? { serverUrl: record.serverUrl } : {}),
561
+ ...(typeof record.userEmail === "string" ? { userEmail: record.userEmail } : {}),
562
+ };
563
+ }
564
+ catch (err) {
565
+ // If bw CLI is not installed or a transient error, propagate it for retry.
566
+ if (err instanceof Error && (isBwNotInstalled(err) || isTransientError(err))) {
567
+ throw err;
568
+ }
569
+ // CLI not configured or broken -- proceed with full setup.
570
+ return {};
571
+ }
572
+ }
573
+ normalizedServerUrl(value) {
574
+ return value.trim().replace(/\/+$/, "").toLowerCase();
575
+ }
576
+ shouldRebuildLocalProfile(status) {
577
+ if (status.status !== "locked" && status.status !== "unlocked")
578
+ return false;
579
+ if (status.serverUrl && this.normalizedServerUrl(status.serverUrl) !== this.normalizedServerUrl(this.serverUrl))
580
+ return true;
581
+ if (status.userEmail && status.userEmail.trim().toLowerCase() !== this.email.trim().toLowerCase())
582
+ return true;
583
+ return false;
584
+ }
585
+ sessionTokenFromLoginOutput(loginOutput) {
586
+ try {
587
+ const parsed = JSON.parse(loginOutput);
588
+ return typeof parsed.access_token === "string" && parsed.access_token.trim()
589
+ ? parsed.access_token.trim()
590
+ : loginOutput.trim();
591
+ }
592
+ catch {
593
+ return loginOutput.trim();
594
+ }
595
+ }
596
+ async loginWithPassword() {
597
+ try {
598
+ return await this.execBwWithPasswordEnv(["login", this.email, "--raw"]);
599
+ }
600
+ catch (error) {
601
+ const err = error;
602
+ if (!isBwAlreadyLoggedInError(err))
603
+ throw err;
604
+ return this.execBwWithPasswordEnv(["unlock", "--raw"]);
605
+ }
606
+ }
607
+ forgetLocalSyncMarker() {
608
+ if (!this.appDataDir)
609
+ return;
610
+ try {
611
+ fs.rmSync(path.join(this.appDataDir, BW_SYNC_MARKER_FILENAME), { force: true });
612
+ }
613
+ catch {
614
+ // A stale sync marker is only a cache hint; failure to remove it should not block auth repair.
615
+ }
616
+ }
617
+ async logoutLocalProfile(reason, status, cause) {
618
+ this.sessionToken = null;
619
+ this.structuredItemCache = null;
620
+ this.forgetLocalSyncMarker();
621
+ (0, runtime_1.emitNervesEvent)({
622
+ level: "warn",
623
+ event: "repertoire.bw_local_profile_rebuild",
624
+ component: "repertoire",
625
+ message: "rebuilding local bw profile for agent vault",
626
+ meta: {
627
+ email: this.email,
628
+ serverUrl: this.serverUrl,
629
+ reason,
630
+ /* v8 ignore next -- defensive: every profile rebuild path starts from a locked/unlocked bw status @preserve */
631
+ previousStatus: status.status ?? "unknown",
632
+ previousServerUrl: status.serverUrl ?? null,
633
+ previousUserEmail: status.userEmail ?? null,
634
+ /* v8 ignore next -- defensive: internal rebuild callers pass Error or undefined causes @preserve */
635
+ error: cause instanceof Error ? cause.message : cause ? String(cause) : undefined,
636
+ },
637
+ });
638
+ try {
639
+ await this.execBw(["logout"]);
640
+ }
641
+ catch (error) {
642
+ const err = error;
643
+ if (isBwLoggedOutOrUnauthenticatedError(err))
644
+ return;
645
+ (0, runtime_1.emitNervesEvent)({
646
+ level: "warn",
647
+ event: "repertoire.bw_local_profile_logout_failed",
648
+ component: "repertoire",
649
+ message: "failed to logout local bw profile before rebuild",
650
+ meta: { email: this.email, serverUrl: this.serverUrl, error: err.message },
651
+ });
652
+ }
653
+ }
654
+ async rebuildLocalProfile(reason, status, cause) {
655
+ await this.logoutLocalProfile(reason, status, cause);
656
+ await this.execBw(["config", "server", this.serverUrl]);
657
+ this.sessionToken = this.sessionTokenFromLoginOutput(await this.loginWithPassword());
658
+ }
659
+ async execWithLocalProfileRebuild(reason, status, operation) {
660
+ try {
661
+ return await operation();
662
+ }
663
+ catch (error) {
664
+ const err = error;
665
+ if (!isBwInvalidUnlockSecretMessage(err.message))
666
+ throw err;
667
+ await this.rebuildLocalProfile(reason, status, err);
668
+ /* v8 ignore next -- defensive: rebuildLocalProfile always stores a string session token on success @preserve */
669
+ return this.sessionToken ?? "";
670
+ }
671
+ }
672
+ async ensureSession() {
673
+ if (!this.sessionToken) {
674
+ await this.login();
675
+ }
676
+ /* v8 ignore next -- defensive: login() always sets sessionToken on success @preserve */
677
+ return this.sessionToken ?? undefined;
678
+ }
679
+ async withSessionRetry(operation) {
680
+ let attemptedFreshSession = false;
681
+ while (true) {
682
+ const session = await this.ensureSession();
683
+ try {
684
+ return await operation(session);
685
+ }
686
+ catch (error) {
687
+ const err = error;
688
+ if (attemptedFreshSession || !isBwSessionAuthError(err)) {
689
+ throw err;
690
+ }
691
+ this.sessionToken = null;
692
+ this.structuredItemCache = null;
693
+ attemptedFreshSession = true;
694
+ }
695
+ }
696
+ }
697
+ async withTransientRetry(operation) {
698
+ let lastError;
699
+ for (let attempt = 0; attempt < TRANSIENT_MAX_RETRIES; attempt++) {
700
+ try {
701
+ return await operation();
702
+ }
703
+ catch (err) {
704
+ /* v8 ignore next -- defensive: operation always throws Error instances @preserve */
705
+ lastError = err instanceof Error ? err : new Error(String(err));
706
+ if (!isTransientError(lastError)) {
707
+ throw lastError;
708
+ }
709
+ if (attempt === TRANSIENT_MAX_RETRIES - 1)
710
+ break;
711
+ const backoffMs = TRANSIENT_RETRY_BASE_MS * Math.pow(2, attempt);
712
+ (0, runtime_1.emitNervesEvent)({
713
+ event: "repertoire.bw_transient_retry",
714
+ component: "repertoire",
715
+ message: `transient bw error, retrying in ${backoffMs}ms`,
716
+ meta: { attempt: attempt + 1, backoffMs, reason: lastError.message },
717
+ });
718
+ await delay(backoffMs);
719
+ }
720
+ }
721
+ throw lastError;
722
+ }
723
+ async get(domain) {
724
+ (0, runtime_1.emitNervesEvent)({
725
+ event: "repertoire.bw_credential_get_start",
726
+ component: "repertoire",
727
+ message: `getting credential via bw for ${domain}`,
728
+ meta: { domain, backend: "bitwarden" },
729
+ });
730
+ const item = await this.withTransientRetry(() => this.withSessionRetry((session) => this.findItemByDomain(domain, session, { preferExactStructured: true })));
731
+ if (!item) {
732
+ (0, runtime_1.emitNervesEvent)({
733
+ event: "repertoire.bw_credential_get_end",
734
+ component: "repertoire",
735
+ message: `no bw credential for ${domain}`,
736
+ meta: { domain, found: false, backend: "bitwarden" },
737
+ });
738
+ return null;
739
+ }
740
+ (0, runtime_1.emitNervesEvent)({
741
+ event: "repertoire.bw_credential_get_end",
742
+ component: "repertoire",
743
+ message: `bw credential found for ${domain}`,
744
+ meta: { domain, found: true, backend: "bitwarden" },
745
+ });
746
+ return {
747
+ domain: item.name,
748
+ username: item.login?.username,
749
+ notes: item.notes ?? undefined,
750
+ createdAt: item.revisionDate ?? new Date().toISOString(),
751
+ };
752
+ }
753
+ async getRawSecret(domain, field) {
754
+ const item = await this.withTransientRetry(() => this.withSessionRetry((session) => this.findItemByDomain(domain, session, { preferExactStructured: true })));
755
+ if (!item) {
756
+ throw new Error(`no credential found for domain "${domain}"`);
757
+ }
758
+ // Map common field names to bw item structure
759
+ let value;
760
+ if (field === "password") {
761
+ value = item.login?.password;
762
+ }
763
+ else if (field === "username") {
764
+ value = item.login?.username;
765
+ }
766
+ else {
767
+ value = item[field];
768
+ }
769
+ if (value === undefined || value === null) {
770
+ throw new Error(`field "${field}" not found for domain "${domain}"`);
771
+ }
772
+ return String(value);
773
+ }
774
+ async store(domain, data) {
775
+ (0, runtime_1.emitNervesEvent)({
776
+ event: "repertoire.bw_credential_store_start",
777
+ component: "repertoire",
778
+ message: `storing credential via bw for ${domain}`,
779
+ meta: { domain, backend: "bitwarden" },
780
+ });
781
+ await this.withSessionRetry(async (session) => {
782
+ const existing = await this.findItemByDomain(domain, session);
783
+ const item = {
784
+ ...(existing ?? {}),
785
+ type: 1, // Login type
786
+ name: domain,
787
+ login: {
788
+ username: data.username ?? "",
789
+ password: data.password,
790
+ uris: [{ match: null, uri: `https://${domain}` }],
791
+ },
792
+ notes: data.notes ?? null,
793
+ };
794
+ const encoded = Buffer.from(JSON.stringify(item)).toString("base64");
795
+ this.structuredItemCache = null;
796
+ let savedItem;
797
+ if (existing) {
798
+ const stdout = await this.execBw(["edit", "item", existing.id], session, encoded);
799
+ const savedItemId = parseBwItemId(stdout) ?? existing.id;
800
+ savedItem = await this.findItemById(savedItemId, session);
801
+ }
802
+ else {
803
+ const stdout = await this.execBw(["create", "item"], session, encoded);
804
+ const savedItemId = parseBwItemId(stdout);
805
+ savedItem = savedItemId
806
+ ? await this.findItemById(savedItemId, session)
807
+ : await this.findItemByDomain(domain, session);
808
+ }
809
+ this.assertStoredCredentialMatches(domain, data, savedItem);
810
+ });
811
+ this.structuredItemCache = null;
812
+ (0, runtime_1.emitNervesEvent)({
813
+ event: "repertoire.bw_credential_store_end",
814
+ component: "repertoire",
815
+ message: `credential stored via bw for ${domain}`,
816
+ meta: { domain, backend: "bitwarden" },
817
+ });
818
+ }
819
+ async list() {
820
+ (0, runtime_1.emitNervesEvent)({
821
+ event: "repertoire.bw_credential_list_start",
822
+ component: "repertoire",
823
+ message: "listing bw credentials",
824
+ meta: { backend: "bitwarden" },
825
+ });
826
+ const stdout = await this.withTransientRetry(() => this.withSessionRetry((session) => this.execBw(["list", "items"], session)));
827
+ const items = parseBwItems(stdout, "bw list items");
828
+ const results = items.map((item) => ({
829
+ domain: item.name,
830
+ username: item.login?.username,
831
+ notes: item.notes ?? undefined,
832
+ createdAt: item.revisionDate ?? new Date().toISOString(),
833
+ }));
834
+ (0, runtime_1.emitNervesEvent)({
835
+ event: "repertoire.bw_credential_list_end",
836
+ component: "repertoire",
837
+ message: "bw credentials listed",
838
+ meta: { backend: "bitwarden", count: results.length },
839
+ });
840
+ return results;
841
+ }
842
+ async delete(domain) {
843
+ (0, runtime_1.emitNervesEvent)({
844
+ event: "repertoire.bw_credential_delete_start",
845
+ component: "repertoire",
846
+ message: `deleting credential via bw for ${domain}`,
847
+ meta: { domain, backend: "bitwarden" },
848
+ });
849
+ const item = await this.withSessionRetry((session) => this.findItemByDomain(domain, session));
850
+ if (!item) {
851
+ (0, runtime_1.emitNervesEvent)({
852
+ event: "repertoire.bw_credential_delete_end",
853
+ component: "repertoire",
854
+ message: `no bw credential to delete for ${domain}`,
855
+ meta: { domain, deleted: false, backend: "bitwarden" },
856
+ });
857
+ return false;
858
+ }
859
+ await this.withSessionRetry((session) => this.execBw(["delete", "item", item.id], session));
860
+ this.structuredItemCache = null;
861
+ (0, runtime_1.emitNervesEvent)({
862
+ event: "repertoire.bw_credential_delete_end",
863
+ component: "repertoire",
864
+ message: `credential deleted via bw for ${domain}`,
865
+ meta: { domain, deleted: true, backend: "bitwarden" },
866
+ });
867
+ return true;
868
+ }
869
+ // --- Private ---
870
+ async findItemByDomain(domain, session, options = {}) {
871
+ if (options.preferExactStructured && shouldUseStructuredItemLookup(domain)) {
872
+ return this.findStructuredItemByName(domain, session);
873
+ }
874
+ if (shouldUseFullListForStructuredLookup(domain, this.appDataDir)) {
875
+ const items = await this.readStructuredItemCache(session);
876
+ return items.get(domain) ?? null;
877
+ }
878
+ const stdout = await this.execBw(["list", "items", "--search", domain], session);
879
+ const items = parseBwItems(stdout, "bw list items --search");
880
+ // Find exact match by name
881
+ return items.find((item) => item.name === domain) ?? null;
882
+ }
883
+ async findStructuredItemByName(domain, session) {
884
+ try {
885
+ const stdout = await this.execBw(["get", "item", domain], session);
886
+ const item = parseBwItem(stdout, "bw get item");
887
+ return item.name === domain ? item : null;
888
+ }
889
+ catch (error) {
890
+ /* v8 ignore next -- defensive: execBw rejects with Error instances @preserve */
891
+ const err = error instanceof Error ? error : new Error(String(error));
892
+ if (isBwItemNotFoundError(err))
893
+ return null;
894
+ throw err;
895
+ }
896
+ }
897
+ shouldSyncVaultAfterSession(status) {
898
+ if (status.status === "unauthenticated" || !status.status)
899
+ return true;
900
+ if (!this.appDataDir)
901
+ return true;
902
+ const freshnessTimestamp = this.latestLocalSyncTimestamp();
903
+ if (freshnessTimestamp !== null) {
904
+ return Date.now() - freshnessTimestamp > BW_SYNC_FRESH_MS;
905
+ }
906
+ return true;
907
+ }
908
+ latestLocalSyncTimestamp() {
909
+ const files = [BW_SYNC_MARKER_FILENAME, BW_DATA_FILENAME];
910
+ let latest = null;
911
+ for (const name of files) {
912
+ try {
913
+ const mtimeMs = fs.statSync(path.join(this.appDataDir, name)).mtimeMs;
914
+ latest = latest === null ? mtimeMs : Math.max(latest, mtimeMs);
915
+ }
916
+ catch {
917
+ // Missing freshness file is fine; use any other available timestamp.
918
+ }
919
+ }
920
+ return latest;
921
+ }
922
+ writeSyncMarker() {
923
+ if (!this.appDataDir)
924
+ return;
925
+ try {
926
+ fs.writeFileSync(path.join(this.appDataDir, BW_SYNC_MARKER_FILENAME), `${Date.now()}\n`, { mode: 0o600 });
927
+ }
928
+ catch {
929
+ // If the marker cannot be written, fall back to syncing next time.
930
+ }
931
+ }
932
+ async findItemById(id, session) {
933
+ const stdout = await this.execBw(["get", "item", id], session);
934
+ return parseBwItem(stdout, "bw get item");
935
+ }
936
+ async readStructuredItemCache(session) {
937
+ if (this.structuredItemCache)
938
+ return this.structuredItemCache;
939
+ const stdout = await this.execBw(["list", "items"], session);
940
+ const items = parseBwItems(stdout, "bw list items");
941
+ this.structuredItemCache = new Map(items.map((item) => [item.name, item]));
942
+ return this.structuredItemCache;
943
+ }
944
+ assertStoredCredentialMatches(domain, data, item) {
945
+ if (!item) {
946
+ throw new Error(`bw CLI error: credential save verification failed for ${domain}: saved item could not be read back after write`);
947
+ }
948
+ const mismatches = [];
949
+ if (item.name !== domain)
950
+ mismatches.push("name");
951
+ if ((item.login?.username ?? "") !== (data.username ?? ""))
952
+ mismatches.push("username");
953
+ if ((item.login?.password ?? "") !== data.password)
954
+ mismatches.push("password");
955
+ if ((item.notes ?? null) !== (data.notes ?? null))
956
+ mismatches.push("notes");
957
+ if (mismatches.length > 0) {
958
+ const label = mismatches.length === 1 ? "field" : "fields";
959
+ throw new Error(`bw CLI error: credential save verification failed for ${domain}: saved item did not match requested ${label} ${mismatches.join(", ")}`);
960
+ }
961
+ }
962
+ }
963
+ exports.BitwardenCredentialStore = BitwardenCredentialStore;