@ouro.bot/cli 0.1.0-alpha.1061 → 0.1.0-alpha.1066
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 +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/cli-parse.js +4 -4
- package/dist/heart/providers/account-pool.js +39 -0
- package/dist/heart/providers/github-copilot.js +1 -0
- package/dist/repertoire/vault-unlock.js +119 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
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.1066",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Account pool: the pool saves its last quota readings to state/account-readings.json after each load and reads them at startup, so a freshly started process chooses its first account with what the fleet last knew. Before, the first turn after a restart chose with no readings and spent one request on an account the fleet already knew was out, got a 429, and only then switched."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1062",
|
|
12
|
+
"changes": [
|
|
13
|
+
"Vault unlock: a sealed-file store for headless hosts without a keychain"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1061",
|
|
6
18
|
"changes": [
|
|
@@ -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.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1066</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -354,8 +354,8 @@ function usage() {
|
|
|
354
354
|
" ouro vault create [--agent <name>] --email <email> [--server <url>] [--store <store>]",
|
|
355
355
|
" ouro vault replace [--agent <name>] [--email <email>] [--server <url>] [--store <store>]",
|
|
356
356
|
" ouro vault recover [--agent <name>] --from <json> [--from <json>] [--email <email>] [--server <url>] [--store <store>]",
|
|
357
|
-
" ouro vault unlock [--agent <name>] [--store auto|macos-keychain|windows-dpapi|linux-secret-service|plaintext-file]",
|
|
358
|
-
" ouro vault status [--agent <name>] [--store auto|macos-keychain|windows-dpapi|linux-secret-service|plaintext-file]",
|
|
357
|
+
" ouro vault unlock [--agent <name>] [--store auto|macos-keychain|windows-dpapi|linux-secret-service|plaintext-file|sealed-file]",
|
|
358
|
+
" ouro vault status [--agent <name>] [--store auto|macos-keychain|windows-dpapi|linux-secret-service|plaintext-file|sealed-file]",
|
|
359
359
|
" ouro vault config set [--agent <name>] --key <path> [--value <value> | --value-file <path>] [--scope agent|machine]",
|
|
360
360
|
" ouro vault config status [--agent <name>] [--scope agent|machine|all]",
|
|
361
361
|
" ouro vault item set [--agent <name>] --item <path> --secret-field <name> [--public-field <key=value>] [--note <text>]",
|
|
@@ -991,7 +991,7 @@ function parseAuthCommand(args) {
|
|
|
991
991
|
};
|
|
992
992
|
}
|
|
993
993
|
function isVaultUnlockStoreKind(value) {
|
|
994
|
-
return value === "auto" || value === "macos-keychain" || value === "windows-dpapi" || value === "linux-secret-service" || value === "plaintext-file";
|
|
994
|
+
return value === "auto" || value === "macos-keychain" || value === "windows-dpapi" || value === "linux-secret-service" || value === "plaintext-file" || value === "sealed-file";
|
|
995
995
|
}
|
|
996
996
|
function parseVaultCommand(args) {
|
|
997
997
|
const sub = args[0];
|
|
@@ -1023,7 +1023,7 @@ function parseVaultCommand(args) {
|
|
|
1023
1023
|
if (token === "--store") {
|
|
1024
1024
|
const value = rest[i + 1];
|
|
1025
1025
|
if (!isVaultUnlockStoreKind(value)) {
|
|
1026
|
-
throw new Error("vault --store must be auto|macos-keychain|windows-dpapi|linux-secret-service|plaintext-file");
|
|
1026
|
+
throw new Error("vault --store must be auto|macos-keychain|windows-dpapi|linux-secret-service|plaintext-file|sealed-file");
|
|
1027
1027
|
}
|
|
1028
1028
|
store = value;
|
|
1029
1029
|
i += 1;
|
|
@@ -312,6 +312,44 @@ class AccountPool {
|
|
|
312
312
|
this.accounts = accounts;
|
|
313
313
|
this.options = options;
|
|
314
314
|
this.loadSharedRefusals();
|
|
315
|
+
this.loadSavedReadings();
|
|
316
|
+
}
|
|
317
|
+
/** Start from the readings an earlier process saved; each keeps its own `at`, so fresher loads still win. */
|
|
318
|
+
loadSavedReadings() {
|
|
319
|
+
const file = this.options.readingsFile;
|
|
320
|
+
if (!file)
|
|
321
|
+
return;
|
|
322
|
+
try {
|
|
323
|
+
const saved = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
324
|
+
if (!Array.isArray(saved))
|
|
325
|
+
return;
|
|
326
|
+
this.setReadings(saved.filter((reading) => !!reading && typeof reading === "object" && typeof reading.key === "string"
|
|
327
|
+
&& (reading.leftPct === null || typeof reading.leftPct === "number")));
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// No file yet, or another process is mid-write: start without saved readings.
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
saveReadings() {
|
|
334
|
+
const file = this.options.readingsFile;
|
|
335
|
+
if (!file)
|
|
336
|
+
return;
|
|
337
|
+
try {
|
|
338
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
339
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
340
|
+
fs.writeFileSync(temp, JSON.stringify(this.readings));
|
|
341
|
+
fs.renameSync(temp, file);
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
(0, runtime_1.emitNervesEvent)({
|
|
345
|
+
level: "warn",
|
|
346
|
+
component: "engine",
|
|
347
|
+
event: "engine.account_readings_save_failed",
|
|
348
|
+
message: "could not save account pool readings for the agent's next process",
|
|
349
|
+
// fs only throws Errors.
|
|
350
|
+
meta: { agent: this.options.agent, error: error.message },
|
|
351
|
+
});
|
|
352
|
+
}
|
|
315
353
|
}
|
|
316
354
|
/** Take in refusals another of the agent's processes recorded; the later end wins. */
|
|
317
355
|
loadSharedRefusals() {
|
|
@@ -381,6 +419,7 @@ class AccountPool {
|
|
|
381
419
|
.then((readings) => {
|
|
382
420
|
this.setReadings(readings);
|
|
383
421
|
this.loadedReadings = true;
|
|
422
|
+
this.saveReadings();
|
|
384
423
|
this.publishIfDue();
|
|
385
424
|
})
|
|
386
425
|
.catch((error) => {
|
|
@@ -87,6 +87,7 @@ function createGithubCopilotPooledCaller(config, owner) {
|
|
|
87
87
|
burnDir: path.join(owner.agentRoot, "state", "account-burn"),
|
|
88
88
|
refusalsFile: path.join(owner.agentRoot, "state", "account-refusals.json"),
|
|
89
89
|
publishedFile: path.join(owner.agentRoot, "state", "account-burn-published.json"),
|
|
90
|
+
readingsFile: path.join(owner.agentRoot, "state", "account-readings.json"),
|
|
90
91
|
/* v8 ignore start -- network readers and publisher: each is tested in its own module @preserve */
|
|
91
92
|
loadReadings: async () => (0, fleet_readings_1.mergeReadings)(await (0, fleet_readings_1.loadFleetQuota)(gist), await (0, account_pool_1.fetchDirectReadings)(accounts)),
|
|
92
93
|
publishBurn: gist ? (burn) => (0, fleet_readings_1.publishAgentBurn)(gist, burn) : undefined,
|
|
@@ -62,7 +62,9 @@ const VAULT_UNLOCK_SERVICE = "ouro.vault";
|
|
|
62
62
|
const CREDENTIAL_VAULT_NOT_CONFIGURED_PREFIX = "credential vault is not configured in ";
|
|
63
63
|
const PLAINTEXT_UNLOCK_DIR = path.join(".ouro-cli", "vault-unlock");
|
|
64
64
|
const WINDOWS_DPAPI_UNLOCK_DIR = path.join(".ouro-cli", "vault-unlock-dpapi");
|
|
65
|
-
const
|
|
65
|
+
const SEALED_UNLOCK_DIR = path.join(".ouro-cli", "vault-unlock-sealed");
|
|
66
|
+
const SUPPORTED_STORES = ["auto", "macos-keychain", "windows-dpapi", "linux-secret-service", "plaintext-file", "sealed-file"];
|
|
67
|
+
const STORE_NAMES = SUPPORTED_STORES.join("|");
|
|
66
68
|
function platform(deps) {
|
|
67
69
|
return deps.platform ?? process.platform;
|
|
68
70
|
}
|
|
@@ -101,6 +103,48 @@ function plaintextUnlockPath(config, deps) {
|
|
|
101
103
|
const digest = crypto.createHash("sha256").update(vaultKey(config)).digest("hex").slice(0, 24);
|
|
102
104
|
return path.join(homeDir(deps), PLAINTEXT_UNLOCK_DIR, `${digest}.secret`);
|
|
103
105
|
}
|
|
106
|
+
function sealedUnlockPath(config, deps) {
|
|
107
|
+
const digest = crypto.createHash("sha256").update(vaultKey(config)).digest("hex").slice(0, 24);
|
|
108
|
+
return path.join(homeDir(deps), SEALED_UNLOCK_DIR, `${digest}.sealed`);
|
|
109
|
+
}
|
|
110
|
+
const MACHINE_IDENTITY_SOURCES = {
|
|
111
|
+
// A device-tree serial or DMI UUID is burned into the hardware; machine-id files can be regenerated at boot on a
|
|
112
|
+
// read-only root filesystem, so they come last.
|
|
113
|
+
linux: ["device-tree-serial", "dmi-product-uuid", "machine-id", "dbus-machine-id"],
|
|
114
|
+
darwin: ["io-platform-uuid"],
|
|
115
|
+
};
|
|
116
|
+
const MACHINE_IDENTITY_FILES = {
|
|
117
|
+
"device-tree-serial": "/proc/device-tree/serial-number",
|
|
118
|
+
"dmi-product-uuid": "/sys/class/dmi/id/product_uuid",
|
|
119
|
+
"machine-id": "/etc/machine-id",
|
|
120
|
+
"dbus-machine-id": "/var/lib/dbus/machine-id",
|
|
121
|
+
};
|
|
122
|
+
/* v8 ignore start -- real hardware reads; tests inject readMachineIdentity @preserve */
|
|
123
|
+
function readMachineIdentityFromHost(source, deps) {
|
|
124
|
+
if (source === "io-platform-uuid") {
|
|
125
|
+
const result = spawnSync(deps)("ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"], { encoding: "utf8" });
|
|
126
|
+
const match = typeof result.stdout === "string" ? /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(result.stdout) : null;
|
|
127
|
+
return match ? match[1] : null;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return fs.readFileSync(MACHINE_IDENTITY_FILES[source], "utf8").replace(/\0/g, "").trim() || null;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/* v8 ignore stop */
|
|
137
|
+
function machineIdentity(source, deps) {
|
|
138
|
+
/* v8 ignore next -- tests inject readMachineIdentity; the host reader is hardware wiring @preserve */
|
|
139
|
+
const value = (deps.readMachineIdentity ?? ((candidate) => readMachineIdentityFromHost(candidate, deps)))(source);
|
|
140
|
+
return value && value.trim() ? value.trim() : null;
|
|
141
|
+
}
|
|
142
|
+
/** The key a sealed-file secret is encrypted under: this machine's identity, this user and this vault. */
|
|
143
|
+
function sealedKey(config, identity) {
|
|
144
|
+
/* v8 ignore next -- process.getuid exists on every platform sealed-file runs on (Linux, macOS) @preserve */
|
|
145
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : 0;
|
|
146
|
+
return Buffer.from(crypto.hkdfSync("sha256", identity, "ouro.vault.sealed-file.v1", `${vaultKey(config)}\0${uid}`, 32));
|
|
147
|
+
}
|
|
104
148
|
function windowsDpapiUnlockPath(config, deps) {
|
|
105
149
|
const digest = crypto.createHash("sha256").update(vaultKey(config)).digest("hex").slice(0, 24);
|
|
106
150
|
const localAppData = process.env.LOCALAPPDATA;
|
|
@@ -203,7 +247,7 @@ function lockedMessage(config, store) {
|
|
|
203
247
|
}
|
|
204
248
|
function validateStoreKind(requested) {
|
|
205
249
|
if (!SUPPORTED_STORES.includes(requested)) {
|
|
206
|
-
throw new Error(`unknown vault unlock store '${requested}'. Use
|
|
250
|
+
throw new Error(`unknown vault unlock store '${requested}'. Use ${STORE_NAMES}.`);
|
|
207
251
|
}
|
|
208
252
|
return requested;
|
|
209
253
|
}
|
|
@@ -214,7 +258,7 @@ function requestedStoreKind(deps) {
|
|
|
214
258
|
if (!fromEnv)
|
|
215
259
|
return "auto";
|
|
216
260
|
if (!SUPPORTED_STORES.includes(fromEnv)) {
|
|
217
|
-
throw new Error(`${exports.VAULT_UNLOCK_STORE_ENV}='${fromEnv}' is not a vault unlock store. Use
|
|
261
|
+
throw new Error(`${exports.VAULT_UNLOCK_STORE_ENV}='${fromEnv}' is not a vault unlock store. Use ${STORE_NAMES}.`);
|
|
218
262
|
}
|
|
219
263
|
return fromEnv;
|
|
220
264
|
}
|
|
@@ -246,6 +290,12 @@ function resolveVaultUnlockStore(config, deps = {}) {
|
|
|
246
290
|
if (requested === "plaintext-file") {
|
|
247
291
|
return { kind: "plaintext-file", secure: false, location: plaintextUnlockPath(canonicalConfig, deps) };
|
|
248
292
|
}
|
|
293
|
+
if (requested === "sealed-file") {
|
|
294
|
+
if (currentPlatform !== "linux" && currentPlatform !== "darwin") {
|
|
295
|
+
throw new Error(`sealed-file unlock store is available on Linux and macOS; this machine is ${currentPlatform}. Use windows-dpapi.`);
|
|
296
|
+
}
|
|
297
|
+
return { kind: "sealed-file", secure: false, location: sealedUnlockPath(canonicalConfig, deps) };
|
|
298
|
+
}
|
|
249
299
|
if (currentPlatform === "darwin") {
|
|
250
300
|
return { kind: "macos-keychain", secure: true, location: "macOS Keychain" };
|
|
251
301
|
}
|
|
@@ -456,6 +506,64 @@ function writeToPlaintextFile(config, secret, deps) {
|
|
|
456
506
|
fs.chmodSync(filePath, 0o600);
|
|
457
507
|
}
|
|
458
508
|
}
|
|
509
|
+
function readFromSealedFileExact(config, deps) {
|
|
510
|
+
const filePath = sealedUnlockPath(config, deps);
|
|
511
|
+
if (!fs.existsSync(filePath))
|
|
512
|
+
return null;
|
|
513
|
+
const mode = fs.statSync(filePath).mode & 0o777;
|
|
514
|
+
if ((mode & 0o077) !== 0) {
|
|
515
|
+
throw new Error(`refusing to read sealed vault unlock file at ${filePath} because permissions are too broad; run chmod 600 ${filePath}`);
|
|
516
|
+
}
|
|
517
|
+
let sealed;
|
|
518
|
+
try {
|
|
519
|
+
sealed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
520
|
+
}
|
|
521
|
+
catch {
|
|
522
|
+
throw new Error(`sealed vault unlock file at ${filePath} is not readable JSON; run \`ouro vault unlock --store sealed-file\` again`);
|
|
523
|
+
}
|
|
524
|
+
const knownSource = sealed.source === "io-platform-uuid" || Object.hasOwn(MACHINE_IDENTITY_FILES, sealed.source);
|
|
525
|
+
const identity = sealed.schemaVersion === 1 && knownSource ? machineIdentity(sealed.source, deps) : null;
|
|
526
|
+
try {
|
|
527
|
+
if (!identity)
|
|
528
|
+
throw new Error("machine identity unavailable");
|
|
529
|
+
const decipher = crypto.createDecipheriv("aes-256-gcm", sealedKey(config, identity), Buffer.from(sealed.iv, "base64"));
|
|
530
|
+
decipher.setAuthTag(Buffer.from(sealed.tag, "base64"));
|
|
531
|
+
return Buffer.concat([decipher.update(Buffer.from(sealed.ciphertext, "base64")), decipher.final()]).toString("utf8");
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
throw new Error(`sealed vault unlock file at ${filePath} was sealed on another machine (or this machine's ${sealed.source ?? "identity"} changed); run \`ouro vault unlock --store sealed-file\` on this machine`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function readFromSealedFile(config, deps) {
|
|
538
|
+
for (const candidate of vaultConfigCandidates(config)) {
|
|
539
|
+
const secret = readFromSealedFileExact(candidate, deps);
|
|
540
|
+
if (secret)
|
|
541
|
+
return { secret, source: exactVaultConfig(candidate) };
|
|
542
|
+
}
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
function writeToSealedFile(config, secret, deps) {
|
|
546
|
+
const sources = MACHINE_IDENTITY_SOURCES[platform(deps) === "darwin" ? "darwin" : "linux"];
|
|
547
|
+
const source = sources.find((candidate) => machineIdentity(candidate, deps) !== null);
|
|
548
|
+
if (!source) {
|
|
549
|
+
throw new Error(`sealed-file unlock store needs a machine identity (${sources.join(", ")}) and none is readable here; use plaintext-file`);
|
|
550
|
+
}
|
|
551
|
+
const iv = crypto.randomBytes(12);
|
|
552
|
+
const cipher = crypto.createCipheriv("aes-256-gcm", sealedKey(config, machineIdentity(source, deps)), iv);
|
|
553
|
+
const ciphertext = Buffer.concat([cipher.update(secret, "utf8"), cipher.final()]);
|
|
554
|
+
const sealed = { schemaVersion: 1, source, iv: iv.toString("base64"), tag: cipher.getAuthTag().toString("base64"), ciphertext: ciphertext.toString("base64") };
|
|
555
|
+
const filePath = sealedUnlockPath(config, deps);
|
|
556
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
557
|
+
fs.writeFileSync(filePath, `${JSON.stringify(sealed)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
558
|
+
fs.chmodSync(path.dirname(filePath), 0o700);
|
|
559
|
+
fs.chmodSync(filePath, 0o600);
|
|
560
|
+
}
|
|
561
|
+
function deleteFromSealedFileExact(config, deps) {
|
|
562
|
+
const filePath = sealedUnlockPath(config, deps);
|
|
563
|
+
const existed = fs.existsSync(filePath);
|
|
564
|
+
fs.rmSync(filePath, { force: true });
|
|
565
|
+
return existed;
|
|
566
|
+
}
|
|
459
567
|
function readFromStore(config, store, deps) {
|
|
460
568
|
if (store.kind === "macos-keychain")
|
|
461
569
|
return readFromMacosKeychain(config, deps);
|
|
@@ -463,6 +571,8 @@ function readFromStore(config, store, deps) {
|
|
|
463
571
|
return readFromWindowsDpapi(config, deps);
|
|
464
572
|
if (store.kind === "linux-secret-service")
|
|
465
573
|
return readFromLinuxSecretService(config, deps);
|
|
574
|
+
if (store.kind === "sealed-file")
|
|
575
|
+
return readFromSealedFile(config, deps);
|
|
466
576
|
return readFromPlaintextFile(config, deps);
|
|
467
577
|
}
|
|
468
578
|
function writeToStore(config, store, secret, deps) {
|
|
@@ -478,6 +588,10 @@ function writeToStore(config, store, secret, deps) {
|
|
|
478
588
|
writeToWindowsDpapi(config, secret, deps);
|
|
479
589
|
return;
|
|
480
590
|
}
|
|
591
|
+
if (store.kind === "sealed-file") {
|
|
592
|
+
writeToSealedFile(config, secret, deps);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
481
595
|
writeToPlaintextFile(config, secret, deps);
|
|
482
596
|
}
|
|
483
597
|
function deleteFromMacosKeychainExact(config, deps) {
|
|
@@ -533,6 +647,8 @@ function deleteFromStoreExact(config, store, deps) {
|
|
|
533
647
|
return deleteFromLinuxSecretServiceExact(config, deps);
|
|
534
648
|
if (store.kind === "windows-dpapi")
|
|
535
649
|
return deleteFromWindowsDpapiExact(config, deps);
|
|
650
|
+
if (store.kind === "sealed-file")
|
|
651
|
+
return deleteFromSealedFileExact(config, deps);
|
|
536
652
|
return deleteFromPlaintextFileExact(config, deps);
|
|
537
653
|
}
|
|
538
654
|
function readFromAutoPlaintextFallback(config, deps) {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1066",
|
|
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.
|
|
9
|
+
"version": "0.1.0-alpha.1066",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|