@ouro.bot/cli 0.1.0-alpha.1010 → 0.1.0-alpha.1011

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.
package/changelog.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
+ {
5
+ "version": "0.1.0-alpha.1011",
6
+ "changes": [
7
+ "Daemons read the vault without the bw CLI: a native client does the Bitwarden prelogin, PBKDF2-SHA256 password login, sync and AES-256-CBC + HMAC decryption over HTTPS with Node's crypto, shared by every store in a process. Runtime config and provider credentials load even when endpoint security quarantines files inside bw, and no bw process starts on the read path. Writes still use bw; vaults this client does not support (Argon2id, two-step login) fall back to bw, and OURO_VAULT_NATIVE_READS=0 turns it off."
8
+ ]
9
+ },
4
10
  {
5
11
  "version": "0.1.0-alpha.1010",
6
12
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1010",
2
+ "runtimeVersion": "0.1.0-alpha.1011",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0"?>
2
2
  <Container version="2">
3
3
  <Name>ouro-butler</Name>
4
- <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1010</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1011</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ /**
3
+ * Reads an agent's Bitwarden/Vaultwarden vault over HTTPS with Node's own crypto, so a daemon
4
+ * reading its runtime config and provider credentials never runs the `bw` CLI.
5
+ *
6
+ * Protocol (Bitwarden security whitepaper): prelogin for the KDF, PBKDF2-SHA256 master key,
7
+ * a password-grant login with the master password hash, the user key unwrapped with the
8
+ * HKDF-stretched master key, then /api/sync and AES-256-CBC + HMAC-SHA256 decryption of each item.
9
+ * Reads only: writes stay on `bw`. Anything this reader does not handle (Argon2id, two-step login,
10
+ * other cipher types) raises NativeVaultUnsupportedError so the caller can fall back to `bw`.
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.NativeVaultReader = exports.NATIVE_VAULT_LOGIN_FAILURE_RETRY_MS = exports.NATIVE_VAULT_ITEMS_FRESH_MS = exports.NativeVaultUnsupportedError = void 0;
47
+ exports.nodeVaultRequest = nodeVaultRequest;
48
+ exports.decryptCipherString = decryptCipherString;
49
+ exports.decryptSyncItems = decryptSyncItems;
50
+ exports.sharedNativeVaultReader = sharedNativeVaultReader;
51
+ const crypto = __importStar(require("node:crypto"));
52
+ const http = __importStar(require("node:http"));
53
+ const https = __importStar(require("node:https"));
54
+ const os = __importStar(require("node:os"));
55
+ const runtime_1 = require("../nerves/runtime");
56
+ const vault_setup_1 = require("./vault-setup");
57
+ /** The vault uses something this reader does not implement; `bw` may still read it. */
58
+ class NativeVaultUnsupportedError extends Error {
59
+ constructor(reason) {
60
+ super(`native vault reads do not support ${reason}`);
61
+ this.name = "NativeVaultUnsupportedError";
62
+ }
63
+ }
64
+ exports.NativeVaultUnsupportedError = NativeVaultUnsupportedError;
65
+ const REQUEST_TIMEOUT_MS = 30_000;
66
+ /** One request with node:http(s): global fetch would load undici, about 7 MB more per process. */
67
+ function nodeVaultRequest(url, init, timeoutMs = REQUEST_TIMEOUT_MS) {
68
+ return new Promise((resolve, reject) => {
69
+ const client = url.startsWith("https:") ? https : http;
70
+ const request = client.request(url, { method: init.method, headers: init.headers }, (response) => {
71
+ const chunks = [];
72
+ response.on("data", (chunk) => chunks.push(chunk));
73
+ response.on("end", () => resolve({ status: Number(response.statusCode), body: Buffer.concat(chunks).toString("utf8") }));
74
+ response.on("error", reject);
75
+ });
76
+ request.setTimeout(timeoutMs, () => request.destroy(Object.assign(new Error("request timed out"), { name: "TimeoutError" })));
77
+ request.on("error", reject);
78
+ request.end(init.body);
79
+ });
80
+ }
81
+ const defaultDeps = {
82
+ request: (url, init) => nodeVaultRequest(url, init),
83
+ now: () => Date.now(),
84
+ hostname: () => os.hostname(),
85
+ platform: process.platform,
86
+ };
87
+ const KDF_PBKDF2 = 0;
88
+ /** How long one sync answers reads before the next read syncs again. */
89
+ exports.NATIVE_VAULT_ITEMS_FRESH_MS = 30_000;
90
+ /** A rejected secret is not retried against the server for this long, as the bw path does. */
91
+ exports.NATIVE_VAULT_LOGIN_FAILURE_RETRY_MS = 5 * 60_000;
92
+ const TOKEN_EXPIRY_MARGIN_MS = 60_000;
93
+ /** Bitwarden answers some objects in PascalCase and Vaultwarden in camelCase; read either. */
94
+ function field(source, name) {
95
+ if (!source || typeof source !== "object")
96
+ return undefined;
97
+ const record = source;
98
+ return record[name] ?? record[name.charAt(0).toUpperCase() + name.slice(1)];
99
+ }
100
+ function stringField(source, name) {
101
+ const value = field(source, name);
102
+ return typeof value === "string" ? value : undefined;
103
+ }
104
+ function deviceType(platform) {
105
+ // Bitwarden's DeviceType: WindowsCLI 23, MacOsCLI 24, LinuxCLI 25.
106
+ if (platform === "win32")
107
+ return "23";
108
+ if (platform === "darwin")
109
+ return "24";
110
+ return "25";
111
+ }
112
+ /** One stable device per agent and host, so the server does not see a new device on every start. */
113
+ function deviceIdentifier(email, serverUrl, hostname) {
114
+ const hex = crypto.createHash("sha256").update(`ouro-native-vault\n${email.toLowerCase()}\n${serverUrl}\n${hostname}`).digest("hex");
115
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-8${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
116
+ }
117
+ /** Decrypt a type-2 cipher string ("2.<iv>|<ct>|<mac>") with a 64-byte key (32 enc + 32 mac). */
118
+ function decryptCipherString(value, key) {
119
+ const dot = value.indexOf(".");
120
+ const type = dot > 0 ? value.slice(0, dot) : "";
121
+ if (type !== "2")
122
+ throw new NativeVaultUnsupportedError(`cipher strings of type ${type || "unknown"}`);
123
+ const parts = value.slice(dot + 1).split("|");
124
+ if (parts.length !== 3)
125
+ throw new Error("malformed cipher string");
126
+ const [iv, ct, mac] = parts.map((part) => Buffer.from(part, "base64"));
127
+ if (iv.length !== 16 || mac.length !== 32 || ct.length === 0)
128
+ throw new Error("malformed cipher string");
129
+ const expected = crypto.createHmac("sha256", key.subarray(32, 64)).update(iv).update(ct).digest();
130
+ if (!crypto.timingSafeEqual(expected, mac))
131
+ throw new Error("cipher string failed its integrity check");
132
+ const decipher = crypto.createDecipheriv("aes-256-cbc", key.subarray(0, 32), iv);
133
+ return Buffer.concat([decipher.update(ct), decipher.final()]);
134
+ }
135
+ function decryptText(value, key) {
136
+ return typeof value === "string" && value.length > 0 ? decryptCipherString(value, key).toString("utf8") : undefined;
137
+ }
138
+ function decryptKey(value, key, what) {
139
+ const decrypted = decryptCipherString(value, key);
140
+ if (decrypted.length !== 64)
141
+ throw new NativeVaultUnsupportedError(`a ${decrypted.length}-byte ${what}`);
142
+ return decrypted;
143
+ }
144
+ /** Decrypt the personal, non-deleted items of a sync response; items in organizations are left out. */
145
+ function decryptSyncItems(sync, userKey) {
146
+ const ciphers = field(sync, "ciphers");
147
+ if (!Array.isArray(ciphers))
148
+ throw new Error("vault sync returned no item list");
149
+ const items = [];
150
+ let skipped = 0;
151
+ let unreadable = 0;
152
+ for (const cipher of ciphers) {
153
+ if (field(cipher, "organizationId") || field(cipher, "deletedDate")) {
154
+ skipped += 1;
155
+ continue;
156
+ }
157
+ try {
158
+ const itemKeyString = stringField(cipher, "key");
159
+ const key = itemKeyString ? decryptKey(itemKeyString, userKey, "item key") : userKey;
160
+ const login = field(cipher, "login");
161
+ const uris = field(login, "uris");
162
+ items.push({
163
+ id: String(field(cipher, "id")),
164
+ name: decryptText(field(cipher, "name"), key) ?? "",
165
+ ...(login
166
+ ? {
167
+ login: {
168
+ username: decryptText(field(login, "username"), key),
169
+ password: decryptText(field(login, "password"), key),
170
+ uris: Array.isArray(uris)
171
+ ? uris.map((entry) => decryptText(field(entry, "uri"), key)).filter((uri) => uri !== undefined).map((uri) => ({ uri }))
172
+ : [],
173
+ },
174
+ }
175
+ : {}),
176
+ notes: decryptText(field(cipher, "notes"), key) ?? null,
177
+ revisionDate: stringField(cipher, "revisionDate"),
178
+ });
179
+ }
180
+ catch (error) {
181
+ if (error instanceof NativeVaultUnsupportedError)
182
+ throw error;
183
+ unreadable += 1;
184
+ }
185
+ }
186
+ return { items, skipped, unreadable };
187
+ }
188
+ class NativeVaultReader {
189
+ email;
190
+ masterPassword;
191
+ deps;
192
+ serverUrl;
193
+ keys = null;
194
+ session = null;
195
+ cache = null;
196
+ loginFailure = null;
197
+ constructor(serverUrl, email, masterPassword, deps = defaultDeps) {
198
+ this.email = email;
199
+ this.masterPassword = masterPassword;
200
+ this.deps = deps;
201
+ this.serverUrl = serverUrl.replace(/\/+$/, "");
202
+ }
203
+ /** Forget the synced items, so the next read syncs (after this process wrote to the vault). */
204
+ invalidate() {
205
+ this.cache = null;
206
+ }
207
+ async items() {
208
+ if (this.cache && this.deps.now() - this.cache.at < exports.NATIVE_VAULT_ITEMS_FRESH_MS)
209
+ return this.cache.items;
210
+ (0, runtime_1.emitNervesEvent)({
211
+ component: "repertoire",
212
+ event: "repertoire.native_vault_sync_start",
213
+ message: "reading the vault natively",
214
+ meta: { email: this.email, serverUrl: this.serverUrl },
215
+ });
216
+ let session = await this.ensureSession();
217
+ let sync = await this.requestSync(session);
218
+ if (sync === null) {
219
+ // The token was revoked or expired early: one fresh login, then give up.
220
+ this.session = null;
221
+ session = await this.ensureSession();
222
+ sync = await this.requestSync(session);
223
+ if (sync === null)
224
+ throw new Error("vault sync rejected a fresh access token (HTTP 401)");
225
+ }
226
+ const { items, skipped, unreadable } = decryptSyncItems(sync, session.userKey);
227
+ this.cache = { items, at: this.deps.now() };
228
+ (0, runtime_1.emitNervesEvent)({
229
+ component: "repertoire",
230
+ event: "repertoire.native_vault_sync_end",
231
+ message: "read the vault natively",
232
+ meta: { email: this.email, items: items.length, skipped, unreadable },
233
+ });
234
+ return items;
235
+ }
236
+ async ensureSession() {
237
+ if (this.session && this.deps.now() < this.session.expiresAt - TOKEN_EXPIRY_MARGIN_MS)
238
+ return this.session;
239
+ if (this.loginFailure && this.deps.now() - this.loginFailure.at < exports.NATIVE_VAULT_LOGIN_FAILURE_RETRY_MS)
240
+ throw this.loginFailure.error;
241
+ this.loginFailure = null;
242
+ const keys = this.keys ?? (this.keys = await this.deriveKeys());
243
+ const body = new URLSearchParams({
244
+ grant_type: "password",
245
+ username: this.email,
246
+ password: keys.hash,
247
+ scope: "api offline_access",
248
+ client_id: "cli",
249
+ deviceType: deviceType(this.deps.platform),
250
+ deviceIdentifier: deviceIdentifier(this.email, this.serverUrl, this.deps.hostname()),
251
+ deviceName: "ouro",
252
+ });
253
+ const response = await this.request("/identity/connect/token", {
254
+ method: "POST",
255
+ headers: {
256
+ "content-type": "application/x-www-form-urlencoded",
257
+ "auth-email": Buffer.from(this.email).toString("base64url"),
258
+ },
259
+ body: body.toString(),
260
+ });
261
+ const token = readJson(response);
262
+ if (!ok(response)) {
263
+ if (field(token, "twoFactorProviders") || field(token, "twoFactorProviders2"))
264
+ throw new NativeVaultUnsupportedError("two-step login");
265
+ const message = stringField(field(token, "errorModel"), "message") ?? stringField(token, "error_description") ?? stringField(token, "error") ?? "";
266
+ if (/device/i.test(message))
267
+ throw new NativeVaultUnsupportedError("new-device verification");
268
+ const error = response.status === 400 && (stringField(token, "error") === "invalid_grant" || /username or password is incorrect/i.test(message))
269
+ ? new Error(`vault login for ${this.email} failed: username or password is incorrect (the saved vault unlock secret was rejected)`)
270
+ : new Error(`vault login for ${this.email} failed: HTTP ${response.status}${message ? ` ${message}` : ""}`);
271
+ if (response.status === 400)
272
+ this.loginFailure = { error, at: this.deps.now() };
273
+ throw error;
274
+ }
275
+ const accessToken = stringField(token, "access_token");
276
+ const protectedKey = stringField(token, "key");
277
+ if (!accessToken || !protectedKey)
278
+ throw new Error("vault login returned no access token or user key");
279
+ const expiresIn = Number(field(token, "expires_in"));
280
+ const userKey = decryptKey(protectedKey, keys.stretched, "user key");
281
+ this.session = { accessToken, expiresAt: this.deps.now() + (Number.isFinite(expiresIn) && expiresIn > 0 ? expiresIn : 3600) * 1000, userKey };
282
+ return this.session;
283
+ }
284
+ async deriveKeys() {
285
+ const response = await this.request("/identity/accounts/prelogin", {
286
+ method: "POST",
287
+ headers: { "content-type": "application/json" },
288
+ body: JSON.stringify({ email: this.email }),
289
+ });
290
+ if (!ok(response))
291
+ throw new Error(`vault prelogin for ${this.email} failed: HTTP ${response.status}`);
292
+ const prelogin = readJson(response);
293
+ const kdf = Number(field(prelogin, "kdf"));
294
+ const iterations = Number(field(prelogin, "kdfIterations"));
295
+ if (kdf !== KDF_PBKDF2)
296
+ throw new NativeVaultUnsupportedError(`KDF ${Number.isFinite(kdf) ? kdf : "unknown"} (only PBKDF2-SHA256)`);
297
+ if (!Number.isInteger(iterations) || iterations < 1)
298
+ throw new Error("vault prelogin returned no KDF iteration count");
299
+ const masterKey = await (0, vault_setup_1.deriveMasterKey)(this.masterPassword, this.email, iterations);
300
+ return { hash: await (0, vault_setup_1.deriveMasterPasswordHash)(masterKey, this.masterPassword), stretched: (0, vault_setup_1.deriveStretchedMasterKey)(masterKey) };
301
+ }
302
+ /** The sync body, or null when the server rejected the access token. */
303
+ async requestSync(session) {
304
+ const response = await this.request("/api/sync?excludeDomains=true", {
305
+ method: "GET",
306
+ headers: { authorization: `Bearer ${session.accessToken}` },
307
+ });
308
+ if (response.status === 401)
309
+ return null;
310
+ if (!ok(response))
311
+ throw new Error(`vault sync for ${this.email} failed: HTTP ${response.status}`);
312
+ return readJson(response);
313
+ }
314
+ async request(pathname, init) {
315
+ const endpoint = pathname.split("?")[0];
316
+ try {
317
+ return await this.deps.request(`${this.serverUrl}${pathname}`, init);
318
+ }
319
+ catch (error) {
320
+ // Worded so the store's transient-error check retries it.
321
+ if (error instanceof Error && error.name === "TimeoutError")
322
+ throw new Error(`vault request to ${endpoint} timed out`);
323
+ const cause = error instanceof Error && error.cause instanceof Error ? `: ${error.cause.message}` : "";
324
+ throw new Error(`vault request to ${endpoint} failed: ${error instanceof Error ? error.message : String(error)}${cause}`);
325
+ }
326
+ }
327
+ }
328
+ exports.NativeVaultReader = NativeVaultReader;
329
+ function readJson(response) {
330
+ try {
331
+ const parsed = JSON.parse(response.body);
332
+ return parsed && typeof parsed === "object" ? parsed : {};
333
+ }
334
+ catch {
335
+ return {};
336
+ }
337
+ }
338
+ const ok = (response) => response.status >= 200 && response.status < 300;
339
+ const sharedReaders = new Map();
340
+ /** One reader per vault account and secret in a process, so its stores share one login and one sync. */
341
+ function sharedNativeVaultReader(serverUrl, email, masterPassword) {
342
+ const key = crypto.createHash("sha256").update(`${serverUrl.replace(/\/+$/, "")}\n${email.toLowerCase()}\n${masterPassword}`).digest("hex");
343
+ let reader = sharedReaders.get(key);
344
+ if (!reader) {
345
+ reader = new NativeVaultReader(serverUrl, email, masterPassword);
346
+ sharedReaders.set(key, reader);
347
+ }
348
+ return reader;
349
+ }
@@ -49,6 +49,7 @@ const fs = __importStar(require("node:fs"));
49
49
  const path = __importStar(require("node:path"));
50
50
  const runtime_1 = require("../nerves/runtime");
51
51
  const bw_installer_1 = require("./bw-installer");
52
+ const bitwarden_native_1 = require("./bitwarden-native");
52
53
  const MAX_ERROR_DETAIL_LENGTH = 500;
53
54
  const LONG_ENCODED_TOKEN_PATTERN = /[A-Za-z0-9+/=]{32,}/g;
54
55
  const BW_PASSWORD_ENV = "OURO_BW_MASTER_PASSWORD";
@@ -550,6 +551,12 @@ function parseBwItemId(stdout) {
550
551
  return null;
551
552
  }
552
553
  }
554
+ /** Reads go over HTTPS unless OURO_VAULT_NATIVE_READS=0; tests inject a reader or read through bw. */
555
+ function defaultNativeReader(serverUrl, email, masterPassword) {
556
+ if (process.env.OURO_VAULT_NATIVE_READS === "0" || process.env.VITEST !== undefined)
557
+ return null;
558
+ return (0, bitwarden_native_1.sharedNativeVaultReader)(serverUrl, email, masterPassword);
559
+ }
553
560
  // ---------------------------------------------------------------------------
554
561
  // BitwardenCredentialStore
555
562
  // ---------------------------------------------------------------------------
@@ -569,6 +576,8 @@ class BitwardenCredentialStore {
569
576
  terminalLoginErrorAt = 0;
570
577
  bwBinaryPath = "bw";
571
578
  structuredItemCache = null;
579
+ /** Reads the vault over HTTPS without bw; null once it reports the vault unsupported, or when off. */
580
+ nativeReader;
572
581
  constructor(serverUrl, email, masterPassword, options = {}) {
573
582
  this.serverUrl = serverUrl;
574
583
  this.email = email;
@@ -578,6 +587,7 @@ class BitwardenCredentialStore {
578
587
  this.onInvalidUnlockSecret = options.onInvalidUnlockSecret;
579
588
  this.onLoginSuccess = options.onLoginSuccess;
580
589
  this.onProgress = options.onProgress;
590
+ this.nativeReader = options.nativeReader !== undefined ? options.nativeReader : defaultNativeReader(serverUrl, email, masterPassword);
581
591
  }
582
592
  isReady() {
583
593
  return true;
@@ -994,7 +1004,7 @@ class BitwardenCredentialStore {
994
1004
  message: `getting credential via bw for ${domain}`,
995
1005
  meta: { domain, backend: "bitwarden" },
996
1006
  });
997
- const item = await this.withTransientRetry(() => this.withSessionRetry((session) => this.findItemByDomain(domain, session)));
1007
+ const item = await this.withTransientRetry(() => this.readItemByDomain(domain));
998
1008
  if (!item) {
999
1009
  (0, runtime_1.emitNervesEvent)({
1000
1010
  event: "repertoire.bw_credential_get_end",
@@ -1018,7 +1028,7 @@ class BitwardenCredentialStore {
1018
1028
  };
1019
1029
  }
1020
1030
  async getRawSecret(domain, field) {
1021
- const item = await this.withTransientRetry(() => this.withSessionRetry((session) => this.findItemByDomain(domain, session)));
1031
+ const item = await this.withTransientRetry(() => this.readItemByDomain(domain));
1022
1032
  if (!item) {
1023
1033
  throw new Error(`no credential found for domain "${domain}"`);
1024
1034
  }
@@ -1079,6 +1089,7 @@ class BitwardenCredentialStore {
1079
1089
  this.assertStoredCredentialMatches(domain, data, savedItem);
1080
1090
  });
1081
1091
  this.structuredItemCache = null;
1092
+ this.nativeReader?.invalidate();
1082
1093
  (0, runtime_1.emitNervesEvent)({
1083
1094
  event: "repertoire.bw_credential_store_end",
1084
1095
  component: "repertoire",
@@ -1093,8 +1104,7 @@ class BitwardenCredentialStore {
1093
1104
  message: "listing bw credentials",
1094
1105
  meta: { backend: "bitwarden" },
1095
1106
  });
1096
- const stdout = await this.withTransientRetry(() => this.withSessionRetry((session) => this.execBw(["list", "items"], session)));
1097
- const items = parseBwItems(stdout, "bw list items");
1107
+ const items = await this.withTransientRetry(async () => (await this.nativeItems()) ?? parseBwItems(await this.withSessionRetry((session) => this.execBw(["list", "items"], session)), "bw list items"));
1098
1108
  const results = items.map((item) => ({
1099
1109
  domain: item.name,
1100
1110
  username: item.login?.username,
@@ -1128,6 +1138,7 @@ class BitwardenCredentialStore {
1128
1138
  }
1129
1139
  await this.withSessionRetry((session) => this.execBw(["delete", "item", item.id], session));
1130
1140
  this.structuredItemCache = null;
1141
+ this.nativeReader?.invalidate();
1131
1142
  (0, runtime_1.emitNervesEvent)({
1132
1143
  event: "repertoire.bw_credential_delete_end",
1133
1144
  component: "repertoire",
@@ -1137,6 +1148,40 @@ class BitwardenCredentialStore {
1137
1148
  return true;
1138
1149
  }
1139
1150
  // --- Private ---
1151
+ /** One item by name: from the native reader when it serves this vault, else through bw. */
1152
+ async readItemByDomain(domain) {
1153
+ const native = await this.nativeItems();
1154
+ if (native)
1155
+ return native.find((item) => item.name === domain) ?? null;
1156
+ return this.withSessionRetry((session) => this.findItemByDomain(domain, session));
1157
+ }
1158
+ /** Every item through the native reader, or null when reads go through bw. */
1159
+ async nativeItems() {
1160
+ const reader = this.nativeReader;
1161
+ if (!reader)
1162
+ return null;
1163
+ try {
1164
+ return await reader.items();
1165
+ }
1166
+ catch (error) {
1167
+ /* v8 ignore next -- defensive: the reader always throws Error instances @preserve */
1168
+ const err = error instanceof Error ? error : new Error(String(error));
1169
+ if (err instanceof bitwarden_native_1.NativeVaultUnsupportedError) {
1170
+ this.nativeReader = null;
1171
+ (0, runtime_1.emitNervesEvent)({
1172
+ level: "warn",
1173
+ event: "repertoire.native_vault_fallback",
1174
+ component: "repertoire",
1175
+ message: "reading this vault through bw instead",
1176
+ meta: { email: this.email, serverUrl: this.serverUrl, reason: err.message },
1177
+ });
1178
+ return null;
1179
+ }
1180
+ if (isBwInvalidUnlockSecretMessage(err.message))
1181
+ await this.notifyInvalidUnlockSecret(err);
1182
+ throw err;
1183
+ }
1184
+ }
1140
1185
  async findItemByDomain(domain, session) {
1141
1186
  if (shouldUseStructuredItemLookup(domain)) {
1142
1187
  const cache = await this.readStructuredItemCache(session);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1010",
3
+ "version": "0.1.0-alpha.1011",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ouro.bot/cli",
9
- "version": "0.1.0-alpha.1010",
9
+ "version": "0.1.0-alpha.1011",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.78.0",
12
12
  "@azure/identity": "^4.13.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1010",
3
+ "version": "0.1.0-alpha.1011",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },