@ouro.bot/cli 0.1.0-alpha.42 → 0.1.0-alpha.420

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 (334) hide show
  1. package/README.md +118 -15
  2. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
  3. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
  4. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
  5. package/changelog.json +2627 -9
  6. package/dist/arc/attention-types.js +8 -0
  7. package/dist/arc/cares.js +140 -0
  8. package/dist/arc/episodes.js +117 -0
  9. package/dist/arc/intentions.js +133 -0
  10. package/dist/arc/json-store.js +117 -0
  11. package/dist/arc/obligations.js +237 -0
  12. package/dist/arc/packets.js +193 -0
  13. package/dist/arc/presence.js +185 -0
  14. package/dist/arc/task-lifecycle.js +65 -0
  15. package/dist/heart/active-work.js +832 -0
  16. package/dist/heart/agent-entry.js +58 -3
  17. package/dist/heart/attachments/image-normalize.js +194 -0
  18. package/dist/heart/attachments/materialize.js +97 -0
  19. package/dist/heart/attachments/originals.js +88 -0
  20. package/dist/heart/attachments/render.js +29 -0
  21. package/dist/heart/attachments/sources/adapter.js +2 -0
  22. package/dist/heart/attachments/sources/bluebubbles.js +156 -0
  23. package/dist/heart/attachments/sources/cli-local-file.js +78 -0
  24. package/dist/heart/attachments/sources/index.js +16 -0
  25. package/dist/heart/attachments/store.js +103 -0
  26. package/dist/heart/attachments/types.js +93 -0
  27. package/dist/heart/auth/auth-flow.js +424 -0
  28. package/dist/heart/bridges/manager.js +358 -0
  29. package/dist/heart/bridges/state-machine.js +135 -0
  30. package/dist/heart/bridges/store.js +123 -0
  31. package/dist/heart/bundle-state.js +168 -0
  32. package/dist/heart/commitments.js +111 -0
  33. package/dist/heart/config-registry.js +304 -0
  34. package/dist/heart/config.js +110 -128
  35. package/dist/heart/core.js +801 -217
  36. package/dist/heart/cross-chat-delivery.js +131 -0
  37. package/dist/heart/daemon/agent-config-check.js +419 -0
  38. package/dist/heart/daemon/agent-discovery.js +79 -3
  39. package/dist/heart/daemon/agent-service.js +360 -0
  40. package/dist/heart/daemon/agentic-repair.js +214 -0
  41. package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
  42. package/dist/heart/daemon/cadence.js +70 -0
  43. package/dist/heart/daemon/cli-defaults.js +605 -0
  44. package/dist/heart/daemon/cli-exec.js +4140 -0
  45. package/dist/heart/daemon/cli-help.js +413 -0
  46. package/dist/heart/daemon/cli-parse.js +1151 -0
  47. package/dist/heart/daemon/cli-render-doctor.js +57 -0
  48. package/dist/heart/daemon/cli-render.js +561 -0
  49. package/dist/heart/daemon/cli-types.js +8 -0
  50. package/dist/heart/daemon/daemon-cli.js +28 -1582
  51. package/dist/heart/daemon/daemon-entry.js +356 -3
  52. package/dist/heart/daemon/daemon-health.js +141 -0
  53. package/dist/heart/daemon/daemon-runtime-sync.js +171 -12
  54. package/dist/heart/daemon/daemon-tombstone.js +236 -0
  55. package/dist/heart/daemon/daemon.js +684 -58
  56. package/dist/heart/daemon/doctor-types.js +8 -0
  57. package/dist/heart/daemon/doctor.js +427 -0
  58. package/dist/heart/daemon/health-monitor.js +79 -1
  59. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  60. package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
  61. package/dist/heart/daemon/http-health-probe.js +80 -0
  62. package/dist/heart/daemon/inner-status.js +89 -0
  63. package/dist/heart/daemon/interactive-repair.js +307 -0
  64. package/dist/heart/daemon/launchd.js +46 -9
  65. package/dist/heart/daemon/log-tailer.js +82 -12
  66. package/dist/heart/daemon/logs-prune.js +105 -0
  67. package/dist/heart/daemon/message-router.js +2 -2
  68. package/dist/heart/daemon/os-cron-deps.js +134 -0
  69. package/dist/heart/daemon/ouro-bot-entry.js +4 -2
  70. package/dist/heart/daemon/ouro-entry.js +3 -1
  71. package/dist/heart/daemon/process-manager.js +214 -0
  72. package/dist/heart/daemon/provider-discovery.js +137 -0
  73. package/dist/heart/daemon/pulse.js +475 -0
  74. package/dist/heart/daemon/readiness-repair.js +250 -0
  75. package/dist/heart/daemon/run-hooks.js +2 -0
  76. package/dist/heart/daemon/runtime-logging.js +67 -16
  77. package/dist/heart/daemon/runtime-metadata.js +73 -0
  78. package/dist/heart/daemon/runtime-mode.js +67 -0
  79. package/dist/heart/daemon/safe-mode.js +161 -0
  80. package/dist/heart/daemon/sense-manager.js +145 -32
  81. package/dist/heart/daemon/session-id-resolver.js +131 -0
  82. package/dist/heart/daemon/skill-management-installer.js +94 -0
  83. package/dist/heart/daemon/socket-client.js +307 -0
  84. package/dist/heart/daemon/stale-bundle-prune.js +96 -0
  85. package/dist/heart/daemon/startup-tui.js +259 -0
  86. package/dist/heart/daemon/task-scheduler.js +3 -25
  87. package/dist/heart/daemon/thoughts.js +510 -0
  88. package/dist/heart/daemon/up-progress.js +218 -0
  89. package/dist/heart/delegation.js +62 -0
  90. package/dist/heart/habits/habit-migration.js +181 -0
  91. package/dist/heart/habits/habit-parser.js +140 -0
  92. package/dist/heart/habits/habit-scheduler.js +371 -0
  93. package/dist/heart/{daemon → hatch}/hatch-flow.js +53 -117
  94. package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
  95. package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
  96. package/dist/heart/{daemon → hatch}/specialist-tools.js +35 -12
  97. package/dist/heart/identity.js +161 -65
  98. package/dist/heart/kept-notes.js +357 -0
  99. package/dist/heart/kicks.js +1 -1
  100. package/dist/heart/machine-identity.js +161 -0
  101. package/dist/heart/mcp/mcp-server.js +653 -0
  102. package/dist/heart/migrate-config.js +100 -0
  103. package/dist/heart/model-capabilities.js +59 -0
  104. package/dist/heart/outlook/outlook-http-hooks.js +64 -0
  105. package/dist/heart/outlook/outlook-http-response.js +7 -0
  106. package/dist/heart/outlook/outlook-http-routes.js +232 -0
  107. package/dist/heart/outlook/outlook-http-static.js +99 -0
  108. package/dist/heart/outlook/outlook-http-transport.js +116 -0
  109. package/dist/heart/outlook/outlook-http.js +99 -0
  110. package/dist/heart/outlook/outlook-read.js +28 -0
  111. package/dist/heart/outlook/outlook-types.js +27 -0
  112. package/dist/heart/outlook/outlook-view.js +195 -0
  113. package/dist/heart/outlook/readers/agent-machine.js +359 -0
  114. package/dist/heart/outlook/readers/continuity-readers.js +332 -0
  115. package/dist/heart/outlook/readers/runtime-readers.js +660 -0
  116. package/dist/heart/outlook/readers/sessions.js +232 -0
  117. package/dist/heart/outlook/readers/shared.js +111 -0
  118. package/dist/heart/platform.js +81 -0
  119. package/dist/heart/progress-story.js +42 -0
  120. package/dist/heart/provider-attempt.js +133 -0
  121. package/dist/heart/provider-binding-resolver.js +239 -0
  122. package/dist/heart/provider-credentials.js +389 -0
  123. package/dist/heart/provider-failover.js +266 -0
  124. package/dist/heart/provider-models.js +81 -0
  125. package/dist/heart/provider-ping.js +237 -0
  126. package/dist/heart/provider-state.js +216 -0
  127. package/dist/heart/provider-visibility.js +186 -0
  128. package/dist/heart/providers/anthropic-token.js +131 -0
  129. package/dist/heart/providers/anthropic.js +193 -55
  130. package/dist/heart/providers/azure.js +103 -12
  131. package/dist/heart/providers/error-classification.js +63 -0
  132. package/dist/heart/providers/github-copilot.js +145 -0
  133. package/dist/heart/providers/minimax-vlm.js +189 -0
  134. package/dist/heart/providers/minimax.js +29 -7
  135. package/dist/heart/providers/openai-codex.js +62 -38
  136. package/dist/heart/runtime-credentials.js +260 -0
  137. package/dist/heart/sense-truth.js +3 -0
  138. package/dist/heart/session-activity.js +190 -0
  139. package/dist/heart/session-events.js +855 -0
  140. package/dist/heart/session-transcript.js +167 -0
  141. package/dist/heart/start-of-turn-packet.js +345 -0
  142. package/dist/heart/streaming.js +36 -27
  143. package/dist/heart/sync.js +332 -0
  144. package/dist/heart/target-resolution.js +127 -0
  145. package/dist/heart/tempo.js +93 -0
  146. package/dist/heart/temporal-view.js +41 -0
  147. package/dist/heart/tool-activity-callbacks.js +36 -0
  148. package/dist/heart/tool-description.js +135 -0
  149. package/dist/heart/tool-friction.js +55 -0
  150. package/dist/heart/tool-loop.js +200 -0
  151. package/dist/heart/turn-context.js +351 -0
  152. package/dist/heart/turn-coordinator.js +28 -0
  153. package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +1 -1
  154. package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
  155. package/dist/heart/versioning/ouro-path-installer.js +301 -0
  156. package/dist/heart/versioning/ouro-version-manager.js +295 -0
  157. package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
  158. package/dist/heart/{daemon → versioning}/update-checker.js +3 -1
  159. package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
  160. package/dist/mind/bundle-manifest.js +7 -1
  161. package/dist/mind/context.js +134 -87
  162. package/dist/mind/diary-integrity.js +60 -0
  163. package/dist/mind/{memory.js → diary.js} +74 -93
  164. package/dist/mind/embedding-provider.js +60 -0
  165. package/dist/mind/file-state.js +179 -0
  166. package/dist/mind/first-impressions.js +14 -1
  167. package/dist/mind/friends/channel.js +21 -0
  168. package/dist/mind/friends/group-context.js +144 -0
  169. package/dist/mind/friends/resolver.js +38 -1
  170. package/dist/mind/friends/store-file.js +39 -3
  171. package/dist/mind/friends/trust-explanation.js +74 -0
  172. package/dist/mind/friends/types.js +1 -1
  173. package/dist/mind/journal-index.js +161 -0
  174. package/dist/mind/note-search.js +268 -0
  175. package/dist/mind/obligation-steering.js +221 -0
  176. package/dist/mind/pending.js +66 -7
  177. package/dist/mind/prompt-refresh.js +3 -2
  178. package/dist/mind/prompt.js +948 -168
  179. package/dist/mind/provenance-trust.js +26 -0
  180. package/dist/mind/scrutiny.js +173 -0
  181. package/dist/nerves/cli-logging.js +7 -1
  182. package/dist/nerves/coverage/audit-rules.js +15 -6
  183. package/dist/nerves/coverage/audit.js +28 -2
  184. package/dist/nerves/coverage/cli.js +1 -1
  185. package/dist/nerves/coverage/contract.js +5 -5
  186. package/dist/nerves/coverage/file-completeness.js +83 -5
  187. package/dist/nerves/coverage/run-artifacts.js +1 -1
  188. package/dist/nerves/event-buffer.js +111 -0
  189. package/dist/nerves/index.js +224 -4
  190. package/dist/nerves/observation.js +20 -0
  191. package/dist/nerves/redact.js +79 -0
  192. package/dist/nerves/runtime.js +5 -1
  193. package/dist/outlook-ui/assets/index-BAcU08c-.css +1 -0
  194. package/dist/outlook-ui/assets/index-D7l3l4vY.js +61 -0
  195. package/dist/outlook-ui/index.html +15 -0
  196. package/dist/repertoire/ado-client.js +15 -56
  197. package/dist/repertoire/ado-semantic.js +11 -10
  198. package/dist/repertoire/api-client.js +97 -0
  199. package/dist/repertoire/bitwarden-store.js +702 -0
  200. package/dist/repertoire/bundle-templates.js +72 -0
  201. package/dist/repertoire/bw-installer.js +79 -0
  202. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  203. package/dist/repertoire/coding/context-pack.js +330 -0
  204. package/dist/repertoire/coding/feedback.js +197 -30
  205. package/dist/repertoire/coding/manager.js +158 -9
  206. package/dist/repertoire/coding/spawner.js +55 -9
  207. package/dist/repertoire/coding/tools.js +170 -7
  208. package/dist/repertoire/commerce-errors.js +109 -0
  209. package/dist/repertoire/commerce-self-test.js +156 -0
  210. package/dist/repertoire/credential-access.js +111 -0
  211. package/dist/repertoire/duffel-client.js +185 -0
  212. package/dist/repertoire/github-client.js +14 -55
  213. package/dist/repertoire/graph-client.js +11 -52
  214. package/dist/repertoire/guardrails.js +371 -0
  215. package/dist/repertoire/mcp-client.js +255 -0
  216. package/dist/repertoire/mcp-manager.js +305 -0
  217. package/dist/repertoire/mcp-tools.js +63 -0
  218. package/dist/repertoire/shell-sessions.js +133 -0
  219. package/dist/repertoire/skills.js +15 -24
  220. package/dist/repertoire/stripe-client.js +131 -0
  221. package/dist/repertoire/tasks/board.js +43 -5
  222. package/dist/repertoire/tasks/fix.js +182 -0
  223. package/dist/repertoire/tasks/index.js +26 -1
  224. package/dist/repertoire/tasks/lifecycle.js +2 -2
  225. package/dist/repertoire/tasks/parser.js +3 -2
  226. package/dist/repertoire/tasks/scanner.js +194 -37
  227. package/dist/repertoire/tasks/transitions.js +16 -78
  228. package/dist/repertoire/tool-results.js +29 -0
  229. package/dist/repertoire/tools-attachments.js +317 -0
  230. package/dist/repertoire/tools-base.js +42 -687
  231. package/dist/repertoire/tools-bluebubbles.js +1 -0
  232. package/dist/repertoire/tools-bridge.js +141 -0
  233. package/dist/repertoire/tools-bundle.js +984 -0
  234. package/dist/repertoire/tools-config.js +185 -0
  235. package/dist/repertoire/tools-continuity.js +248 -0
  236. package/dist/repertoire/tools-credential.js +361 -0
  237. package/dist/repertoire/tools-files.js +342 -0
  238. package/dist/repertoire/tools-flight.js +224 -0
  239. package/dist/repertoire/tools-flow.js +105 -0
  240. package/dist/repertoire/tools-github.js +1 -7
  241. package/dist/repertoire/tools-notes.js +376 -0
  242. package/dist/repertoire/tools-session.js +739 -0
  243. package/dist/repertoire/tools-shell.js +120 -0
  244. package/dist/repertoire/tools-stripe.js +180 -0
  245. package/dist/repertoire/tools-surface.js +243 -0
  246. package/dist/repertoire/tools-teams.js +9 -39
  247. package/dist/repertoire/tools-travel.js +125 -0
  248. package/dist/repertoire/tools-user-profile.js +144 -0
  249. package/dist/repertoire/tools-vault.js +40 -0
  250. package/dist/repertoire/tools.js +144 -113
  251. package/dist/repertoire/travel-api-client.js +360 -0
  252. package/dist/repertoire/user-profile.js +131 -0
  253. package/dist/repertoire/vault-setup.js +246 -0
  254. package/dist/repertoire/vault-unlock.js +421 -0
  255. package/dist/scripts/claude-code-hook.js +41 -0
  256. package/dist/scripts/claude-code-stop-hook.js +47 -0
  257. package/dist/senses/attention-queue.js +116 -0
  258. package/dist/senses/bluebubbles/attachment-cache.js +53 -0
  259. package/dist/senses/bluebubbles/attachment-download.js +137 -0
  260. package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +260 -9
  261. package/dist/senses/bluebubbles/entry.js +73 -0
  262. package/dist/senses/bluebubbles/inbound-log.js +113 -0
  263. package/dist/senses/bluebubbles/index.js +1620 -0
  264. package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
  265. package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
  266. package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +45 -3
  267. package/dist/senses/bluebubbles/replay.js +129 -0
  268. package/dist/senses/bluebubbles/runtime-state.js +109 -0
  269. package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
  270. package/dist/senses/cli/bracketed-paste.js +82 -0
  271. package/dist/senses/cli/image-paste.js +287 -0
  272. package/dist/senses/cli/image-ref-navigation.js +75 -0
  273. package/dist/senses/cli/ink-app.js +156 -0
  274. package/dist/senses/cli/inline-diff.js +64 -0
  275. package/dist/senses/cli/input-keys.js +174 -0
  276. package/dist/senses/cli/kill-ring.js +86 -0
  277. package/dist/senses/cli/message-list.js +51 -0
  278. package/dist/senses/cli/ouro-tui.js +605 -0
  279. package/dist/senses/cli/spinner-imperative.js +135 -0
  280. package/dist/senses/cli/spinner.js +101 -0
  281. package/dist/senses/cli/status-line.js +60 -0
  282. package/dist/senses/cli/streaming-markdown.js +526 -0
  283. package/dist/senses/cli/tool-display.js +83 -0
  284. package/dist/senses/cli/tool-render.js +85 -0
  285. package/dist/senses/cli/tui-store.js +240 -0
  286. package/dist/senses/cli/virtual-list.js +35 -0
  287. package/dist/senses/cli-entry.js +60 -8
  288. package/dist/senses/cli-layout.js +187 -0
  289. package/dist/senses/cli.js +526 -211
  290. package/dist/senses/commands.js +66 -3
  291. package/dist/senses/continuity.js +94 -0
  292. package/dist/senses/habit-turn-message.js +108 -0
  293. package/dist/senses/inner-dialog-worker.js +112 -19
  294. package/dist/senses/inner-dialog.js +596 -94
  295. package/dist/senses/pipeline.js +539 -61
  296. package/dist/senses/proactive-content-guard.js +51 -0
  297. package/dist/senses/shared-turn.js +205 -0
  298. package/dist/senses/surface-tool.js +68 -0
  299. package/dist/senses/teams-entry.js +60 -8
  300. package/dist/senses/teams.js +569 -237
  301. package/dist/senses/trust-gate.js +5 -5
  302. package/package.json +29 -7
  303. package/skills/agent-commerce.md +106 -0
  304. package/skills/browser-navigation.md +117 -0
  305. package/skills/commerce-setup-guide.md +116 -0
  306. package/skills/commerce-setup.md +84 -0
  307. package/skills/configure-dev-tools.md +101 -0
  308. package/skills/travel-planning.md +138 -0
  309. package/dist/heart/daemon/ouro-path-installer.js +0 -178
  310. package/dist/heart/daemon/subagent-installer.js +0 -134
  311. package/dist/mind/associative-recall.js +0 -209
  312. package/dist/senses/bluebubbles-entry.js +0 -11
  313. package/dist/senses/bluebubbles.js +0 -832
  314. package/dist/senses/debug-activity.js +0 -127
  315. package/subagents/README.md +0 -60
  316. package/subagents/work-doer.md +0 -235
  317. package/subagents/work-merger.md +0 -618
  318. package/subagents/work-planner.md +0 -382
  319. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  320. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  321. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  322. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  323. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  324. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  325. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  326. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  327. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  328. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  329. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  330. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
  331. /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
  332. /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
  333. /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
  334. /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
@@ -0,0 +1,702 @@
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
+ function uniqueSecrets(secrets) {
54
+ return [...new Set(secrets.filter((value) => typeof value === "string" && value.length >= 4))].sort((left, right) => right.length - left.length);
55
+ }
56
+ function sanitizeCredentialErrorDetail(message, options = {}) {
57
+ const filtered = message
58
+ .split(/\r?\n/)
59
+ .filter((line) => {
60
+ const trimmed = line.trim();
61
+ if (trimmed.startsWith("Command failed:"))
62
+ return false;
63
+ if (trimmed.includes("[input is hidden]"))
64
+ return false;
65
+ return true;
66
+ })
67
+ .join("\n")
68
+ .trim();
69
+ let sanitized = filtered || "command failed";
70
+ for (const secret of uniqueSecrets(options.secrets ?? [])) {
71
+ sanitized = sanitized.split(secret).join("[redacted]");
72
+ }
73
+ sanitized = sanitized.replace(LONG_ENCODED_TOKEN_PATTERN, "[redacted]");
74
+ if (sanitized.replace(/\[redacted\]/g, "").trim().length === 0) {
75
+ return "command failed";
76
+ }
77
+ return sanitized.slice(0, MAX_ERROR_DETAIL_LENGTH);
78
+ }
79
+ // ---------------------------------------------------------------------------
80
+ // bw CLI wrapper
81
+ // ---------------------------------------------------------------------------
82
+ function isBwSessionUnavailableMessage(message) {
83
+ return (/master password/i.test(message) ||
84
+ /vault is locked/i.test(message) ||
85
+ /not logged in/i.test(message) ||
86
+ /session key/i.test(message) ||
87
+ /local bitwarden session/i.test(message));
88
+ }
89
+ function isBwInvalidUnlockSecretMessage(message) {
90
+ return /invalid master password/i.test(message) || /saved vault unlock secret/i.test(message);
91
+ }
92
+ function isBwTimeoutError(err) {
93
+ const timeoutErr = err;
94
+ const message = err.message.toLowerCase();
95
+ return (timeoutErr.code === "ETIMEDOUT" ||
96
+ timeoutErr.killed === true ||
97
+ timeoutErr.signal === "SIGTERM" ||
98
+ message.includes("timed out"));
99
+ }
100
+ function formatBwOperation(args) {
101
+ const [command, target] = args;
102
+ /* v8 ignore next -- defensive: all execBw call sites pass a concrete bw subcommand @preserve */
103
+ if (!command)
104
+ return "bw command";
105
+ return [command, target].filter(Boolean).join(" ");
106
+ }
107
+ function sanitizeBwErrorDetail(message) {
108
+ if (isBwInvalidUnlockSecretMessage(message)) {
109
+ return "bw CLI rejected the saved vault unlock secret for this machine";
110
+ }
111
+ if (isBwSessionUnavailableMessage(message)) {
112
+ return "bw CLI could not use the local Bitwarden session because it is locked, missing, or expired";
113
+ }
114
+ return sanitizeCredentialErrorDetail(message);
115
+ }
116
+ function formatBwCliError(err, stderr = "", args = []) {
117
+ const operation = formatBwOperation(args);
118
+ if (isBwTimeoutError(err)) {
119
+ return new Error(`bw CLI error: ${operation} timed out -- usually resolves on retry. If it persists, check network connectivity to the vault server.`);
120
+ }
121
+ const detail = sanitizeBwErrorDetail(stderr.trim() || err.message);
122
+ if (detail === "command failed") {
123
+ return new Error(`bw CLI error: ${operation} failed without error detail`);
124
+ }
125
+ return new Error(`bw CLI error: ${detail}`);
126
+ }
127
+ function isBwSessionAuthError(err) {
128
+ return isBwSessionUnavailableMessage(err.message) || isBwInvalidUnlockSecretMessage(err.message);
129
+ }
130
+ function isBwConfigLogoutRequired(err) {
131
+ const message = err.message.toLowerCase();
132
+ return message.includes("logout") && message.includes("required");
133
+ }
134
+ // ---------------------------------------------------------------------------
135
+ // Cross-process bw CLI lock
136
+ // ---------------------------------------------------------------------------
137
+ // The bw CLI cannot handle concurrent access to the same app data directory.
138
+ // Two processes (e.g. daemon worker + ouro up CLI) hitting the same dir
139
+ // simultaneously corrupt bw's local state, producing empty/garbled output.
140
+ //
141
+ // We use two layers:
142
+ // 1. In-process async mutex: a Map<string, Promise<void>> keyed by appDataDir
143
+ // serializes calls within a single Node.js process.
144
+ // 2. Cross-process file lock: fs.openSync(lockPath, 'wx') with PID stale
145
+ // detection serializes across processes.
146
+ // ---------------------------------------------------------------------------
147
+ const BW_LOCK_FILENAME = ".ouro-bw.lock";
148
+ const BW_LOCK_TIMEOUT_MS = 30_000;
149
+ const BW_LOCK_POLL_MS = 100;
150
+ /** In-process async mutex keyed by appDataDir. */
151
+ const inProcessLocks = new Map();
152
+ function isPidAlive(pid) {
153
+ try {
154
+ process.kill(pid, 0);
155
+ return true;
156
+ }
157
+ catch {
158
+ return false;
159
+ }
160
+ }
161
+ async function acquireFileLock(lockPath) {
162
+ const content = `${process.pid}\n`;
163
+ const deadline = Date.now() + BW_LOCK_TIMEOUT_MS;
164
+ while (true) {
165
+ try {
166
+ const fd = fs.openSync(lockPath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL);
167
+ fs.writeSync(fd, content);
168
+ fs.closeSync(fd);
169
+ return;
170
+ }
171
+ catch (err) {
172
+ if (err.code !== "EEXIST") {
173
+ throw err;
174
+ }
175
+ // Lock file exists -- check for stale lock
176
+ try {
177
+ const existing = fs.readFileSync(lockPath, "utf8").trim();
178
+ const pid = parseInt(existing, 10);
179
+ if (!isNaN(pid) && !isPidAlive(pid)) {
180
+ // Stale lock -- remove and retry immediately
181
+ try {
182
+ fs.unlinkSync(lockPath);
183
+ }
184
+ catch { /* race with another cleaner is fine */ }
185
+ continue;
186
+ }
187
+ }
188
+ catch { /* v8 ignore next -- race: lock file disappeared between openSync and readFileSync @preserve */
189
+ continue;
190
+ }
191
+ if (Date.now() >= deadline) {
192
+ throw new Error(`bw CLI lock timeout: could not acquire ${lockPath} within ${BW_LOCK_TIMEOUT_MS}ms`);
193
+ }
194
+ // Yield to the event loop before retrying
195
+ await delay(BW_LOCK_POLL_MS);
196
+ }
197
+ }
198
+ }
199
+ function releaseFileLock(lockPath) {
200
+ try {
201
+ fs.unlinkSync(lockPath);
202
+ }
203
+ catch {
204
+ // Already removed or never created -- safe to ignore
205
+ }
206
+ }
207
+ async function withBwLock(appDataDir, fn) {
208
+ if (!appDataDir) {
209
+ // No appDataDir means the default bw data location. Still need in-process
210
+ // serialization but cannot do cross-process file lock without a dir.
211
+ return fn();
212
+ }
213
+ const lockKey = appDataDir;
214
+ const lockPath = path.join(appDataDir, BW_LOCK_FILENAME);
215
+ // In-process serialization: chain onto the previous promise for this key
216
+ const previous = inProcessLocks.get(lockKey) ?? Promise.resolve();
217
+ let releaseLock;
218
+ const current = new Promise((resolve) => { releaseLock = resolve; });
219
+ inProcessLocks.set(lockKey, current);
220
+ await previous;
221
+ let fileLockAcquired = false;
222
+ try {
223
+ // Cross-process file lock
224
+ await acquireFileLock(lockPath);
225
+ fileLockAcquired = true;
226
+ return await fn();
227
+ }
228
+ finally {
229
+ if (fileLockAcquired) {
230
+ releaseFileLock(lockPath);
231
+ }
232
+ releaseLock();
233
+ // Clean up the map entry if we are the latest
234
+ if (inProcessLocks.get(lockKey) === current) {
235
+ inProcessLocks.delete(lockKey);
236
+ }
237
+ }
238
+ }
239
+ function execBw(args, sessionToken, appDataDir, stdin) {
240
+ const env = {
241
+ ...process.env,
242
+ ...(sessionToken ? { BW_SESSION: sessionToken } : {}),
243
+ ...(appDataDir ? { BITWARDENCLI_APPDATA_DIR: appDataDir } : {}),
244
+ };
245
+ const runCommand = () => new Promise((resolve, reject) => {
246
+ const child = (0, node_child_process_1.execFile)("bw", args, { timeout: 30_000, env }, (err, stdout, stderr) => {
247
+ if (err) {
248
+ if (isBwNotInstalled(err)) {
249
+ reject(new Error("bw CLI not found. Install from https://bitwarden.com/help/cli/"));
250
+ return;
251
+ }
252
+ reject(formatBwCliError(err, stderr, args));
253
+ return;
254
+ }
255
+ resolve(stdout);
256
+ });
257
+ if (stdin !== undefined) {
258
+ child?.stdin?.end(stdin);
259
+ }
260
+ });
261
+ return withBwLock(appDataDir, runCommand);
262
+ }
263
+ /** Check if the error indicates the bw CLI binary is not installed. */
264
+ function isBwNotInstalled(err) {
265
+ const msg = err.message.toLowerCase();
266
+ const code = err.code;
267
+ return code === "ENOENT" || msg.includes("enoent") || msg.includes("not found") || msg.includes("command not found");
268
+ }
269
+ /** Check if the error is transient (network/timeout) and worth retrying. */
270
+ function isTransientError(err) {
271
+ const msg = err.message.toLowerCase();
272
+ return (msg.includes("econnrefused") ||
273
+ msg.includes("etimedout") ||
274
+ msg.includes("enotfound") ||
275
+ msg.includes("socket hang up") ||
276
+ msg.includes("503") ||
277
+ msg.includes("server unavailable") ||
278
+ msg.includes("timed out"));
279
+ }
280
+ const MAX_RETRIES = 3;
281
+ const BASE_BACKOFF_MS = 1000;
282
+ const TRANSIENT_MAX_RETRIES = 3;
283
+ const TRANSIENT_RETRY_BASE_MS = 500;
284
+ function delay(ms) {
285
+ return new Promise((resolve) => setTimeout(resolve, ms));
286
+ }
287
+ function isBwLoginItem(value) {
288
+ if (!value || typeof value !== "object" || Array.isArray(value))
289
+ return false;
290
+ const item = value;
291
+ if (typeof item.id !== "string" || item.id.trim().length === 0)
292
+ return false;
293
+ if (typeof item.name !== "string" || item.name.trim().length === 0)
294
+ return false;
295
+ if (item.login !== undefined) {
296
+ if (!item.login || typeof item.login !== "object" || Array.isArray(item.login))
297
+ return false;
298
+ const login = item.login;
299
+ if (login.username !== undefined && typeof login.username !== "string")
300
+ return false;
301
+ if (login.password !== undefined && typeof login.password !== "string")
302
+ return false;
303
+ if (login.uris !== undefined) {
304
+ if (!Array.isArray(login.uris))
305
+ return false;
306
+ for (const uri of login.uris) {
307
+ if (!uri || typeof uri !== "object" || Array.isArray(uri))
308
+ return false;
309
+ const uriRecord = uri;
310
+ if (uriRecord.uri !== undefined && typeof uriRecord.uri !== "string")
311
+ return false;
312
+ }
313
+ }
314
+ }
315
+ if (item.notes !== undefined && item.notes !== null && typeof item.notes !== "string")
316
+ return false;
317
+ if (item.revisionDate !== undefined && typeof item.revisionDate !== "string")
318
+ return false;
319
+ return true;
320
+ }
321
+ function parseBwItems(stdout, context) {
322
+ let parsed;
323
+ try {
324
+ parsed = JSON.parse(stdout);
325
+ if (!Array.isArray(parsed)) {
326
+ throw new Error("expected item array");
327
+ }
328
+ const items = parsed;
329
+ if (!items.every(isBwLoginItem)) {
330
+ throw new Error("expected login items");
331
+ }
332
+ return items;
333
+ }
334
+ catch {
335
+ if (Array.isArray(parsed)) {
336
+ throw new Error(`bw CLI error: invalid item from ${context}`);
337
+ }
338
+ throw new Error(`bw CLI error: invalid JSON from ${context}`);
339
+ }
340
+ }
341
+ function parseBwItem(stdout, context) {
342
+ let parsed;
343
+ try {
344
+ parsed = JSON.parse(stdout);
345
+ if (!isBwLoginItem(parsed)) {
346
+ throw new Error("expected login item");
347
+ }
348
+ return parsed;
349
+ }
350
+ catch {
351
+ if (parsed !== undefined) {
352
+ throw new Error(`bw CLI error: invalid item from ${context}`);
353
+ }
354
+ throw new Error(`bw CLI error: invalid JSON from ${context}`);
355
+ }
356
+ }
357
+ function parseBwItemId(stdout) {
358
+ try {
359
+ const parsed = JSON.parse(stdout);
360
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
361
+ return null;
362
+ const id = parsed.id;
363
+ return typeof id === "string" && id.trim().length > 0 ? id : null;
364
+ }
365
+ catch {
366
+ return null;
367
+ }
368
+ }
369
+ // ---------------------------------------------------------------------------
370
+ // BitwardenCredentialStore
371
+ // ---------------------------------------------------------------------------
372
+ class BitwardenCredentialStore {
373
+ serverUrl;
374
+ email;
375
+ masterPassword;
376
+ appDataDir;
377
+ sessionToken = null;
378
+ constructor(serverUrl, email, masterPassword, options = {}) {
379
+ this.serverUrl = serverUrl;
380
+ this.email = email;
381
+ this.masterPassword = masterPassword;
382
+ this.appDataDir = options.appDataDir;
383
+ }
384
+ isReady() {
385
+ return true;
386
+ }
387
+ /**
388
+ * Ensure the bw CLI is authenticated and unlocked.
389
+ * Handles three states: logged out → login, locked → unlock, already unlocked → no-op.
390
+ * Retries transient failures (network/timeout) up to MAX_RETRIES with exponential backoff.
391
+ */
392
+ async login() {
393
+ // Ensure bw CLI is installed before any bw commands
394
+ await (0, bw_installer_1.ensureBwCli)();
395
+ if (this.appDataDir) {
396
+ fs.mkdirSync(this.appDataDir, { recursive: true, mode: 0o700 });
397
+ }
398
+ let lastError;
399
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
400
+ try {
401
+ await this.loginAttempt();
402
+ return;
403
+ }
404
+ catch (err) {
405
+ /* v8 ignore next -- defensive: loginAttempt always throws Error instances @preserve */
406
+ lastError = err instanceof Error ? err : new Error(String(err));
407
+ // Don't retry non-transient errors (auth failures, bw not installed)
408
+ if (!isTransientError(lastError)) {
409
+ throw lastError;
410
+ }
411
+ // Don't retry after final attempt
412
+ if (attempt === MAX_RETRIES - 1)
413
+ break;
414
+ const backoffMs = BASE_BACKOFF_MS * Math.pow(2, attempt);
415
+ (0, runtime_1.emitNervesEvent)({
416
+ event: "repertoire.bw_login_retry",
417
+ component: "repertoire",
418
+ message: `bw login attempt ${attempt + 1} failed, retrying in ${backoffMs}ms`,
419
+ meta: { attempt: attempt + 1, backoffMs, reason: lastError.message },
420
+ });
421
+ await delay(backoffMs);
422
+ }
423
+ }
424
+ throw lastError;
425
+ }
426
+ /** Single login attempt — called by login() retry loop. */
427
+ async loginAttempt() {
428
+ // Check current status
429
+ let status = {};
430
+ try {
431
+ const raw = await execBw(["status"], undefined, this.appDataDir);
432
+ status = JSON.parse(raw);
433
+ }
434
+ catch (err) {
435
+ // If bw CLI is not installed or a transient error, propagate it for retry
436
+ if (err instanceof Error && (isBwNotInstalled(err) || isTransientError(err))) {
437
+ throw err;
438
+ }
439
+ // CLI not configured or broken — proceed with full setup
440
+ }
441
+ // Configure server URL if needed (only works when logged out)
442
+ if (status.status === "unauthenticated" || !status.serverUrl) {
443
+ try {
444
+ await execBw(["config", "server", this.serverUrl], undefined, this.appDataDir);
445
+ }
446
+ catch (error) {
447
+ const err = error;
448
+ // "Logout required" means already logged in — that's fine, skip config.
449
+ if (!isBwConfigLogoutRequired(err)) {
450
+ throw err;
451
+ }
452
+ }
453
+ }
454
+ if (status.status === "locked") {
455
+ // Already logged in, just needs unlock
456
+ const unlockOutput = await execBw(["unlock", this.masterPassword, "--raw"], undefined, this.appDataDir);
457
+ this.sessionToken = unlockOutput.trim();
458
+ }
459
+ else if (status.status === "unauthenticated" || !status.status) {
460
+ // Not logged in — full login
461
+ const loginOutput = await execBw(["login", this.email, this.masterPassword, "--raw"], undefined, this.appDataDir);
462
+ try {
463
+ const parsed = JSON.parse(loginOutput);
464
+ this.sessionToken = parsed.access_token ?? loginOutput.trim();
465
+ }
466
+ catch {
467
+ this.sessionToken = loginOutput.trim();
468
+ }
469
+ }
470
+ else {
471
+ // Status is "unlocked" — already good, just need the session token
472
+ const unlockOutput = await execBw(["unlock", this.masterPassword, "--raw"], undefined, this.appDataDir);
473
+ this.sessionToken = unlockOutput.trim();
474
+ }
475
+ // Sync vault data after obtaining a fresh session token
476
+ /* v8 ignore next -- defensive: loginAttempt always sets sessionToken before sync @preserve */
477
+ await execBw(["sync"], this.sessionToken ?? undefined, this.appDataDir);
478
+ }
479
+ async ensureSession() {
480
+ if (!this.sessionToken) {
481
+ await this.login();
482
+ }
483
+ /* v8 ignore next -- defensive: login() always sets sessionToken on success @preserve */
484
+ return this.sessionToken ?? undefined;
485
+ }
486
+ async withSessionRetry(operation) {
487
+ let attemptedFreshSession = false;
488
+ while (true) {
489
+ const session = await this.ensureSession();
490
+ try {
491
+ return await operation(session);
492
+ }
493
+ catch (error) {
494
+ const err = error;
495
+ if (attemptedFreshSession || !isBwSessionAuthError(err)) {
496
+ throw err;
497
+ }
498
+ this.sessionToken = null;
499
+ attemptedFreshSession = true;
500
+ }
501
+ }
502
+ }
503
+ async withTransientRetry(operation) {
504
+ let lastError;
505
+ for (let attempt = 0; attempt < TRANSIENT_MAX_RETRIES; attempt++) {
506
+ try {
507
+ return await operation();
508
+ }
509
+ catch (err) {
510
+ /* v8 ignore next -- defensive: operation always throws Error instances @preserve */
511
+ lastError = err instanceof Error ? err : new Error(String(err));
512
+ if (!isTransientError(lastError)) {
513
+ throw lastError;
514
+ }
515
+ if (attempt === TRANSIENT_MAX_RETRIES - 1)
516
+ break;
517
+ const backoffMs = TRANSIENT_RETRY_BASE_MS * Math.pow(2, attempt);
518
+ (0, runtime_1.emitNervesEvent)({
519
+ event: "repertoire.bw_transient_retry",
520
+ component: "repertoire",
521
+ message: `transient bw error, retrying in ${backoffMs}ms`,
522
+ meta: { attempt: attempt + 1, backoffMs, reason: lastError.message },
523
+ });
524
+ await delay(backoffMs);
525
+ }
526
+ }
527
+ throw lastError;
528
+ }
529
+ async get(domain) {
530
+ (0, runtime_1.emitNervesEvent)({
531
+ event: "repertoire.bw_credential_get_start",
532
+ component: "repertoire",
533
+ message: `getting credential via bw for ${domain}`,
534
+ meta: { domain, backend: "bitwarden" },
535
+ });
536
+ const item = await this.withTransientRetry(() => this.withSessionRetry((session) => this.findItemByDomain(domain, session)));
537
+ if (!item) {
538
+ (0, runtime_1.emitNervesEvent)({
539
+ event: "repertoire.bw_credential_get_end",
540
+ component: "repertoire",
541
+ message: `no bw credential for ${domain}`,
542
+ meta: { domain, found: false, backend: "bitwarden" },
543
+ });
544
+ return null;
545
+ }
546
+ (0, runtime_1.emitNervesEvent)({
547
+ event: "repertoire.bw_credential_get_end",
548
+ component: "repertoire",
549
+ message: `bw credential found for ${domain}`,
550
+ meta: { domain, found: true, backend: "bitwarden" },
551
+ });
552
+ return {
553
+ domain: item.name,
554
+ username: item.login?.username,
555
+ notes: item.notes ?? undefined,
556
+ createdAt: item.revisionDate ?? new Date().toISOString(),
557
+ };
558
+ }
559
+ async getRawSecret(domain, field) {
560
+ const item = await this.withTransientRetry(() => this.withSessionRetry((session) => this.findItemByDomain(domain, session)));
561
+ if (!item) {
562
+ throw new Error(`no credential found for domain "${domain}"`);
563
+ }
564
+ // Map common field names to bw item structure
565
+ let value;
566
+ if (field === "password") {
567
+ value = item.login?.password;
568
+ }
569
+ else if (field === "username") {
570
+ value = item.login?.username;
571
+ }
572
+ else {
573
+ value = item[field];
574
+ }
575
+ if (value === undefined || value === null) {
576
+ throw new Error(`field "${field}" not found for domain "${domain}"`);
577
+ }
578
+ return String(value);
579
+ }
580
+ async store(domain, data) {
581
+ (0, runtime_1.emitNervesEvent)({
582
+ event: "repertoire.bw_credential_store_start",
583
+ component: "repertoire",
584
+ message: `storing credential via bw for ${domain}`,
585
+ meta: { domain, backend: "bitwarden" },
586
+ });
587
+ await this.withSessionRetry(async (session) => {
588
+ const existing = await this.findItemByDomain(domain, session);
589
+ const item = {
590
+ ...(existing ?? {}),
591
+ type: 1, // Login type
592
+ name: domain,
593
+ login: {
594
+ username: data.username ?? "",
595
+ password: data.password,
596
+ uris: [{ match: null, uri: `https://${domain}` }],
597
+ },
598
+ notes: data.notes ?? null,
599
+ };
600
+ const encoded = Buffer.from(JSON.stringify(item)).toString("base64");
601
+ let savedItem;
602
+ if (existing) {
603
+ const stdout = await execBw(["edit", "item", existing.id], session, this.appDataDir, encoded);
604
+ const savedItemId = parseBwItemId(stdout) ?? existing.id;
605
+ savedItem = await this.findItemById(savedItemId, session);
606
+ }
607
+ else {
608
+ const stdout = await execBw(["create", "item"], session, this.appDataDir, encoded);
609
+ const savedItemId = parseBwItemId(stdout);
610
+ savedItem = savedItemId
611
+ ? await this.findItemById(savedItemId, session)
612
+ : await this.findItemByDomain(domain, session);
613
+ }
614
+ this.assertStoredCredentialMatches(domain, data, savedItem);
615
+ });
616
+ (0, runtime_1.emitNervesEvent)({
617
+ event: "repertoire.bw_credential_store_end",
618
+ component: "repertoire",
619
+ message: `credential stored via bw for ${domain}`,
620
+ meta: { domain, backend: "bitwarden" },
621
+ });
622
+ }
623
+ async list() {
624
+ (0, runtime_1.emitNervesEvent)({
625
+ event: "repertoire.bw_credential_list_start",
626
+ component: "repertoire",
627
+ message: "listing bw credentials",
628
+ meta: { backend: "bitwarden" },
629
+ });
630
+ const stdout = await this.withTransientRetry(() => this.withSessionRetry((session) => execBw(["list", "items"], session, this.appDataDir)));
631
+ const items = parseBwItems(stdout, "bw list items");
632
+ const results = items.map((item) => ({
633
+ domain: item.name,
634
+ username: item.login?.username,
635
+ notes: item.notes ?? undefined,
636
+ createdAt: item.revisionDate ?? new Date().toISOString(),
637
+ }));
638
+ (0, runtime_1.emitNervesEvent)({
639
+ event: "repertoire.bw_credential_list_end",
640
+ component: "repertoire",
641
+ message: "bw credentials listed",
642
+ meta: { backend: "bitwarden", count: results.length },
643
+ });
644
+ return results;
645
+ }
646
+ async delete(domain) {
647
+ (0, runtime_1.emitNervesEvent)({
648
+ event: "repertoire.bw_credential_delete_start",
649
+ component: "repertoire",
650
+ message: `deleting credential via bw for ${domain}`,
651
+ meta: { domain, backend: "bitwarden" },
652
+ });
653
+ const item = await this.withSessionRetry((session) => this.findItemByDomain(domain, session));
654
+ if (!item) {
655
+ (0, runtime_1.emitNervesEvent)({
656
+ event: "repertoire.bw_credential_delete_end",
657
+ component: "repertoire",
658
+ message: `no bw credential to delete for ${domain}`,
659
+ meta: { domain, deleted: false, backend: "bitwarden" },
660
+ });
661
+ return false;
662
+ }
663
+ await this.withSessionRetry((session) => execBw(["delete", "item", item.id], session, this.appDataDir));
664
+ (0, runtime_1.emitNervesEvent)({
665
+ event: "repertoire.bw_credential_delete_end",
666
+ component: "repertoire",
667
+ message: `credential deleted via bw for ${domain}`,
668
+ meta: { domain, deleted: true, backend: "bitwarden" },
669
+ });
670
+ return true;
671
+ }
672
+ // --- Private ---
673
+ async findItemByDomain(domain, session) {
674
+ const stdout = await execBw(["list", "items", "--search", domain], session, this.appDataDir);
675
+ const items = parseBwItems(stdout, "bw list items --search");
676
+ // Find exact match by name
677
+ return items.find((item) => item.name === domain) ?? null;
678
+ }
679
+ async findItemById(id, session) {
680
+ const stdout = await execBw(["get", "item", id], session, this.appDataDir);
681
+ return parseBwItem(stdout, "bw get item");
682
+ }
683
+ assertStoredCredentialMatches(domain, data, item) {
684
+ if (!item) {
685
+ throw new Error(`bw CLI error: credential save verification failed for ${domain}: saved item could not be read back after write`);
686
+ }
687
+ const mismatches = [];
688
+ if (item.name !== domain)
689
+ mismatches.push("name");
690
+ if ((item.login?.username ?? "") !== (data.username ?? ""))
691
+ mismatches.push("username");
692
+ if ((item.login?.password ?? "") !== data.password)
693
+ mismatches.push("password");
694
+ if ((item.notes ?? null) !== (data.notes ?? null))
695
+ mismatches.push("notes");
696
+ if (mismatches.length > 0) {
697
+ const label = mismatches.length === 1 ? "field" : "fields";
698
+ throw new Error(`bw CLI error: credential save verification failed for ${domain}: saved item did not match requested ${label} ${mismatches.join(", ")}`);
699
+ }
700
+ }
701
+ }
702
+ exports.BitwardenCredentialStore = BitwardenCredentialStore;