@ouro.bot/cli 0.1.0-alpha.1049 → 0.1.0-alpha.1056

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,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.1056",
6
+ "changes": [
7
+ "Edge runtime defaults: CLI compile cache, doctor MemAvailable"
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1055",
12
+ "changes": [
13
+ "Account pool: a 401 (rejected or revoked credential) benches the account for an hour, is logged as a 401 switch, and the request is retried once on the next account."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1049",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1049",
2
+ "runtimeVersion": "0.1.0-alpha.1056",
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.1049</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1056</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,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ouroCompileCacheDirectory = void 0;
37
+ exports.enableOuroCompileCache = enableOuroCompileCache;
38
+ const nodeModule = __importStar(require("node:module"));
39
+ const os = __importStar(require("node:os"));
40
+ const path = __importStar(require("node:path"));
41
+ /* v8 ignore next -- only Node 22.0 lacks it; tests pass null for that case @preserve */
42
+ const nodeEnableCompileCache = nodeModule.enableCompileCache ?? null;
43
+ /**
44
+ * Turns on Node's on-disk compile cache for a short-lived CLI process, so `ouro` commands do not recompile the
45
+ * harness on every run. The cache lives under ~/.ouro-cli rather than Node's default in the OS temp directory, which
46
+ * is RAM-backed (tmpfs) on small Linux devices. NODE_COMPILE_CACHE picks another directory and
47
+ * NODE_DISABLE_COMPILE_CACHE turns it off, as with Node itself. Returns the directory in use, or null.
48
+ *
49
+ * Only the CLI entry points load this. The daemon and agent processes are long-lived, where a code cache costs more
50
+ * resident memory (about 5 MiB idle, 9 MiB at a turn's peak in the edge benchmark) than its one-time startup saving
51
+ * is worth on a 1 GB device; so the directory is deliberately not exported to child processes.
52
+ *
53
+ * Kept free of project imports: entry points import it first, before any other module is compiled.
54
+ */
55
+ function enableOuroCompileCache(env = process.env, homeDir = os.homedir(), enable = nodeEnableCompileCache) {
56
+ if (env.NODE_DISABLE_COMPILE_CACHE || !enable)
57
+ return null;
58
+ const directory = env.NODE_COMPILE_CACHE || path.join(homeDir, ".ouro-cli", "cache", "node-compile");
59
+ let result;
60
+ try {
61
+ result = enable(directory);
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ return result.directory ?? null;
67
+ }
68
+ /** The compile cache directory this process uses, or null; the entry point reports it in its start event. */
69
+ exports.ouroCompileCacheDirectory = enableOuroCompileCache();
@@ -7,7 +7,7 @@
7
7
  * "fail" check and the remaining categories still run.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.KNOWN_DOCTOR_CATEGORIES = exports.DEFAULT_SENSE_DELIVERY_THRESHOLDS = exports.DEFAULT_MAIL_INGEST_THRESHOLDS = void 0;
10
+ exports.KNOWN_DOCTOR_CATEGORIES = exports.DEFAULT_MEMORY_FLOOR_MB = exports.DEFAULT_SENSE_DELIVERY_THRESHOLDS = exports.DEFAULT_MAIL_INGEST_THRESHOLDS = void 0;
11
11
  exports.checkCliPath = checkCliPath;
12
12
  exports.checkDaemon = checkDaemon;
13
13
  exports.senseInboundDeliveryCheck = senseInboundDeliveryCheck;
@@ -19,6 +19,7 @@ exports.checkSecurity = checkSecurity;
19
19
  exports.checkTrips = checkTrips;
20
20
  exports.checkMailroom = checkMailroom;
21
21
  exports.checkFriends = checkFriends;
22
+ exports.checkMemory = checkMemory;
22
23
  exports.checkDisk = checkDisk;
23
24
  exports.checkLifecycle = checkLifecycle;
24
25
  exports.runDoctorChecks = runDoctorChecks;
@@ -31,6 +32,7 @@ const runtime_credentials_1 = require("../runtime-credentials");
31
32
  const machine_identity_1 = require("../machine-identity");
32
33
  const habit_parser_1 = require("../habits/habit-parser");
33
34
  const cadence_1 = require("./cadence");
35
+ const linux_service_1 = require("./linux-service");
34
36
  const nerves_1 = require("../../nerves");
35
37
  const config_1 = require("../../rsvp/config");
36
38
  const cutover_1 = require("../../rsvp/cutover");
@@ -1444,6 +1446,53 @@ function checkFriends(deps) {
1444
1446
  }
1445
1447
  return { name: "Friends", checks };
1446
1448
  }
1449
+ /** MemAvailable below this is worth a warning when no service floor is configured; the 1 GB device profile's floor. */
1450
+ exports.DEFAULT_MEMORY_FLOOR_MB = 250;
1451
+ /**
1452
+ * Linux only: MemAvailable from /proc/meminfo against a floor, so a small device shows how close it is to the point
1453
+ * where the supervisor holds back starts. The floor is the installed sysv service's --min-mem-available-mb when set,
1454
+ * otherwise DEFAULT_MEMORY_FLOOR_MB.
1455
+ */
1456
+ function checkMemory(deps) {
1457
+ const label = "available memory";
1458
+ if (deps.platform !== "linux")
1459
+ return { name: "Memory", checks: [{ label, status: "pass", detail: `MemAvailable is measured on Linux only (this host is ${deps.platform})` }] };
1460
+ let meminfo;
1461
+ try {
1462
+ meminfo = deps.readFileSync("/proc/meminfo");
1463
+ }
1464
+ catch (error) {
1465
+ return { name: "Memory", checks: [{ label, status: "warn", detail: `cannot read /proc/meminfo: ${error instanceof Error ? error.message : String(error)}` }] };
1466
+ }
1467
+ const kilobytes = (key) => {
1468
+ const match = new RegExp(`^${key}:\\s+(\\d+) kB$`, "m").exec(meminfo);
1469
+ return match ? Number(match[1]) : null;
1470
+ };
1471
+ const available = kilobytes("MemAvailable");
1472
+ const total = kilobytes("MemTotal");
1473
+ if (available === null)
1474
+ return { name: "Memory", checks: [{ label, status: "warn", detail: "/proc/meminfo has no MemAvailable line" }] };
1475
+ let floorMb = exports.DEFAULT_MEMORY_FLOOR_MB;
1476
+ let floorSource = "default";
1477
+ try {
1478
+ const serviceFloorKb = Number(/^MIN_MEM_AVAILABLE_KB=(\d+)$/m.exec(deps.readFileSync((0, linux_service_1.defaultServicePath)("sysv", deps.homedir, true)))?.[1] ?? 0);
1479
+ if (serviceFloorKb > 0) {
1480
+ floorMb = Math.round(serviceFloorKb / 1024);
1481
+ floorSource = "service floor";
1482
+ }
1483
+ }
1484
+ catch {
1485
+ // no sysv service installed: keep the default floor
1486
+ }
1487
+ const availableMb = Math.round(available / 1024);
1488
+ const of = total === null ? "" : ` of ${Math.round(total / 1024)} MB`;
1489
+ return {
1490
+ name: "Memory",
1491
+ checks: [availableMb < floorMb
1492
+ ? { label, status: "warn", detail: `${availableMb} MB available${of}, below the ${floorMb} MB ${floorSource}; the supervisor waits for memory before starting the daemon` }
1493
+ : { label, status: "pass", detail: `${availableMb} MB available${of} (${floorSource} ${floorMb} MB)` }],
1494
+ };
1495
+ }
1447
1496
  function checkDisk(deps) {
1448
1497
  const checks = [];
1449
1498
  const isActiveLogStream = (name) => {
@@ -1730,6 +1779,7 @@ const CATEGORY_CHECKERS = [
1730
1779
  { name: "Mailroom", fn: checkMailroom },
1731
1780
  { name: "Friends", fn: checkFriends },
1732
1781
  { name: "Disk", fn: checkDisk },
1782
+ { name: "Memory", fn: checkMemory },
1733
1783
  ];
1734
1784
  exports.KNOWN_DOCTOR_CATEGORIES = CATEGORY_CHECKERS.map((c) => c.name);
1735
1785
  async function runDoctorChecks(deps, options = {}) {
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ // First, so every later module can come from the compile cache.
5
+ const compile_cache_1 = require("./compile-cache");
4
6
  const cli_arg_redaction_1 = require("./cli-arg-redaction");
5
7
  const runtime_1 = require("../../nerves/runtime");
6
8
  const runtime_logging_1 = require("./runtime-logging");
@@ -10,7 +12,7 @@ const ouro_bot_wrapper_1 = require("../versioning/ouro-bot-wrapper");
10
12
  component: "daemon",
11
13
  event: "daemon.ouro_bot_entry_start",
12
14
  message: "starting ouro.bot wrapper entrypoint",
13
- meta: { args: (0, cli_arg_redaction_1.redactCliArgs)(process.argv.slice(2)) },
15
+ meta: { args: (0, cli_arg_redaction_1.redactCliArgs)(process.argv.slice(2)), compileCache: compile_cache_1.ouroCompileCacheDirectory },
14
16
  });
15
17
  void (0, ouro_bot_wrapper_1.runOuroBotWrapper)(process.argv.slice(2)).catch((error) => {
16
18
  const message = error instanceof Error ? error.message : String(error);
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ // First, so every later module can come from the compile cache.
5
+ const compile_cache_1 = require("./compile-cache");
4
6
  const runtime_1 = require("../../nerves/runtime");
5
7
  const cli_arg_redaction_1 = require("./cli-arg-redaction");
6
8
  const daemon_cli_1 = require("./daemon-cli");
@@ -13,7 +15,7 @@ else
13
15
  component: "daemon",
14
16
  event: "daemon.cli_entry_start",
15
17
  message: "starting ouro CLI entrypoint",
16
- meta: { args: (0, cli_arg_redaction_1.redactCliArgs)(process.argv.slice(2)) },
18
+ meta: { args: (0, cli_arg_redaction_1.redactCliArgs)(process.argv.slice(2)), compileCache: compile_cache_1.ouroCompileCacheDirectory },
17
19
  });
18
20
  void (0, daemon_cli_1.runOuroCli)(process.argv.slice(2)).catch((error) => {
19
21
  const message = error instanceof Error ? error.message : String(error);
@@ -58,6 +58,7 @@ const path = __importStar(require("path"));
58
58
  const runtime_1 = require("../../nerves/runtime");
59
59
  const tranche_1 = require("../quota/tranche");
60
60
  const fleet_readings_1 = require("../quota/fleet-readings");
61
+ const HOUR_MS = 60 * 60 * 1000;
61
62
  const accountKey = (account) => `${account.login}@${account.host}`;
62
63
  exports.accountKey = accountKey;
63
64
  /**
@@ -262,7 +263,11 @@ function chooseAccount(pool, readings, options = {}) {
262
263
  ?? eligible.find((candidate) => (0, tranche_1.usedPct)(map.get(candidate)) === null);
263
264
  return pool.find((account) => (0, exports.accountKey)(account) === key) ?? null;
264
265
  }
265
- /** Until when an account refuses requests: Retry-After when given, the quota reset for a spent quota, else 5 minutes. */
266
+ /**
267
+ * Until when an account refuses requests: Retry-After when given; the quota reset for a spent quota; an hour for a
268
+ * rejected credential (401), so a revoked token costs one request an hour, not one a turn, and a re-stored credential
269
+ * comes back on its own; else 5 minutes.
270
+ */
266
271
  function refusalUntil(status, error, reset, now) {
267
272
  const headers = error?.headers;
268
273
  const retryAfter = headers && typeof headers.get === "function"
@@ -271,6 +276,8 @@ function refusalUntil(status, error, reset, now) {
271
276
  const seconds = Number(retryAfter);
272
277
  if (retryAfter && Number.isFinite(seconds) && seconds > 0)
273
278
  return now + seconds * 1000;
279
+ if (status === 401)
280
+ return now + HOUR_MS;
274
281
  const message = error instanceof Error ? error.message : String(error);
275
282
  // Only a spent quota waits for the reset; a plain "rate limit exceeded" is a short throttle.
276
283
  if (status === 402 || /quota|billing/i.test(message)) {
@@ -286,7 +293,6 @@ function defaultAppendLine(file, line) {
286
293
  fs.mkdirSync(path.dirname(file), { recursive: true });
287
294
  fs.appendFileSync(file, line, "utf8");
288
295
  }
289
- const HOUR_MS = 60 * 60 * 1000;
290
296
  class AccountPool {
291
297
  accounts;
292
298
  readings = [];
@@ -408,7 +414,7 @@ class AccountPool {
408
414
  return next;
409
415
  }
410
416
  /**
411
- * The account `key` refused a request with a 402 or 429: mark it refused until it can serve again and
417
+ * The account `key` refused a request with a 401, 402 or 429: mark it refused until it can serve again and
412
418
  * move to the next account. Returns the account to retry on, or null when no other account can serve.
413
419
  */
414
420
  onRefusal(key, status, error) {
@@ -642,7 +648,7 @@ function createPooledCaller(pool, makeClient) {
642
648
  }
643
649
  catch (error) {
644
650
  const status = error?.status;
645
- if (status !== 402 && status !== 429)
651
+ if (status !== 401 && status !== 402 && status !== 429)
646
652
  throw error;
647
653
  const next = pool.onRefusal((0, exports.accountKey)(account), status, error);
648
654
  if (!next)
@@ -162,6 +162,9 @@ const DISPATCH_EXEMPT_PATTERNS = [
162
162
  // daemon.migrate_to_desk_* events around the runMigrateToDesk() entry
163
163
  // points.
164
164
  "repertoire/desk/classifier",
165
+ // Loaded first by the CLI entry points, before any project module, so it cannot import nerves; the entry's own
166
+ // start event reports the compile cache directory it chose.
167
+ "daemon/compile-cache",
165
168
  ];
166
169
  function isDispatchExempt(filePath) {
167
170
  return DISPATCH_EXEMPT_PATTERNS.some((pattern) => filePath.includes(pattern));
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1049",
3
+ "version": "0.1.0-alpha.1056",
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.1049",
9
+ "version": "0.1.0-alpha.1056",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.78.0",
12
12
  "@ouro.bot/friends": "0.1.0-alpha.18",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1049",
3
+ "version": "0.1.0-alpha.1056",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },