@ouro.bot/cli 0.1.0-alpha.1062 → 0.1.0-alpha.1067

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.1067",
6
+ "changes": [
7
+ "Portable git for hosts without one: ouro git install, clone and doctor"
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1066",
12
+ "changes": [
13
+ "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."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1062",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1062",
2
+ "runtimeVersion": "0.1.0-alpha.1067",
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.1062</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1067</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -87,6 +87,7 @@ const cli_parse_1 = require("./cli-parse");
87
87
  const provider_discovery_1 = require("./provider-discovery");
88
88
  const provider_credentials_1 = require("../provider-credentials");
89
89
  const startup_tui_1 = require("./startup-tui");
90
+ const portable_git_1 = require("./portable-git");
90
91
  const daemon_tombstone_1 = require("./daemon-tombstone");
91
92
  // ── Default implementations ──
92
93
  function spawnDetachedDaemonProcess(socketPath, environment = process.env) {
@@ -126,6 +127,12 @@ function linuxServiceDeps() {
126
127
  isRoot: process.getuid?.() === 0,
127
128
  };
128
129
  }
130
+ /* v8 ignore start -- host default: downloads and installs into the real ~/.ouro-cli @preserve */
131
+ async function defaultInstallPortableGit(options) {
132
+ const { installPortableGit, createDefaultPortableGitInstallDeps } = await Promise.resolve().then(() => __importStar(require("./portable-git-install")));
133
+ return installPortableGit(createDefaultPortableGitInstallDeps(), options);
134
+ }
135
+ /* v8 ignore stop */
129
136
  function defaultLinuxService(socketPath) {
130
137
  // Resolve the home lazily: building the CLI deps must not consult the home directory.
131
138
  const options = (homeDir, supervision) => ({
@@ -916,6 +923,9 @@ function createDefaultOuroCliDeps(socketPath = socket_client_1.DEFAULT_DAEMON_SO
916
923
  syncGlobalOuroBotWrapper: ouro_bot_global_installer_1.syncGlobalOuroBotWrapper,
917
924
  pruneDaemonLogs: logs_prune_1.pruneDaemonLogs,
918
925
  linuxService: defaultLinuxService(socketPath),
926
+ ...((0, portable_git_1.portableGitAsset)(process.platform, process.arch) ? { installPortableGit: defaultInstallPortableGit } : {}),
927
+ /* v8 ignore next -- host default: reads this machine's PATH and ~/.ouro-cli @preserve */
928
+ describeGit: async () => (await Promise.resolve().then(() => __importStar(require("./portable-git-install")))).describeGitAvailability(),
919
929
  ensureSkillManagement: skill_management_installer_1.ensureSkillManagement,
920
930
  prepareDaemonRuntimeReplacement: defaultPrepareDaemonRuntimeReplacement,
921
931
  ensureDaemonBootPersistence: defaultEnsureDaemonBootPersistence,
@@ -136,6 +136,7 @@ const connect_bay_1 = require("./connect-bay");
136
136
  const runtime_capability_check_1 = require("../runtime-capability-check");
137
137
  const vault_items_1 = require("./vault-items");
138
138
  const mcp_canary_1 = require("./mcp-canary");
139
+ const portable_git_1 = require("./portable-git");
139
140
  const bluebubbles_cli_integration_1 = require("./bluebubbles-cli-integration");
140
141
  // ── ensureDaemonRunning ──
141
142
  const DEFAULT_DAEMON_STARTUP_TIMEOUT_MS = 60_000;
@@ -1538,6 +1539,25 @@ async function checkManualCloneBundles(deps) {
1538
1539
  }
1539
1540
  }
1540
1541
  }
1542
+ // ── portable git ──
1543
+ async function installPortableGitForCli(deps, force) {
1544
+ if (!deps.installPortableGit) {
1545
+ return { ok: false, text: `no portable git for ${process.platform}-${process.arch}; install git with the host's package manager` };
1546
+ }
1547
+ try {
1548
+ const result = await deps.installPortableGit({ force });
1549
+ (0, portable_git_1.activatePortableGit)();
1550
+ return {
1551
+ ok: true,
1552
+ text: result.status === "installed"
1553
+ ? `installed ${result.marker.gitVersion} at ${result.root}\nOuro uses it whenever this host has no git of its own.`
1554
+ : `portable git is already installed: ${result.marker.gitVersion} at ${result.root}`,
1555
+ };
1556
+ }
1557
+ catch (error) {
1558
+ return { ok: false, text: error instanceof Error ? error.message : String(error) };
1559
+ }
1560
+ }
1541
1561
  // ── toDaemonCommand ──
1542
1562
  function toDaemonCommand(command) {
1543
1563
  if (command.kind === "habit.probe") {
@@ -6844,6 +6864,19 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
6844
6864
  deps.writeStdout(message);
6845
6865
  return message;
6846
6866
  }
6867
+ if (command.kind === "git.status") {
6868
+ const { renderGitAvailability } = await Promise.resolve().then(() => __importStar(require("./portable-git-install")));
6869
+ const message = deps.describeGit ? renderGitAvailability(await deps.describeGit()) : "ouro git status is unavailable here (dep not wired)";
6870
+ deps.writeStdout(message);
6871
+ return message;
6872
+ }
6873
+ if (command.kind === "git.install") {
6874
+ const message = await installPortableGitForCli(deps, command.force);
6875
+ deps.writeStdout(message.text);
6876
+ if (!message.ok)
6877
+ deps.setExitCode?.(1);
6878
+ return message.text;
6879
+ }
6847
6880
  // Pure: no daemon, no network, no bundle. The cutover runs it in a container with --network none.
6848
6881
  if (command.kind === "sanctuary.git-exclude") {
6849
6882
  const text = (0, sanctuary_bundle_migration_1.sanctuaryGitExcludeText)();
@@ -9346,9 +9379,19 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
9346
9379
  (0, child_process_1.execFileSync)("git", ["--version"], { stdio: "pipe" });
9347
9380
  }
9348
9381
  catch (err) {
9349
- const message = "git is not installed -- install it from https://git-scm.com\nOn macOS: brew install git\nOn Ubuntu/Debian: sudo apt install git\nOn Windows: download from https://git-scm.com/download/win";
9350
- deps.writeStdout(message);
9351
- return message;
9382
+ const guide = "git is not installed -- install it from https://git-scm.com\nOn macOS: brew install git\nOn Ubuntu/Debian: sudo apt install git\nOn Windows: download from https://git-scm.com/download/win";
9383
+ if (!deps.installPortableGit) {
9384
+ deps.writeStdout(guide);
9385
+ return guide;
9386
+ }
9387
+ deps.writeStdout("git is not installed; installing a portable git (ouro git install)...");
9388
+ const installed = await installPortableGitForCli(deps, false);
9389
+ if (!installed.ok) {
9390
+ const message = `${installed.text}\n${guide}`;
9391
+ deps.writeStdout(message);
9392
+ return message;
9393
+ }
9394
+ deps.writeStdout(installed.text);
9352
9395
  }
9353
9396
  // 2. Infer agent name
9354
9397
  const agentName = command.agent ?? (0, cli_parse_1.inferAgentNameFromRemote)(command.remote);
@@ -51,6 +51,13 @@ exports.COMMAND_REGISTRY = {
51
51
  example: "ouro service install --init sysv --min-mem-available-mb 250 --max-old-space-size 160 --oom-score-adj 900",
52
52
  subcommands: ["install", "uninstall"],
53
53
  },
54
+ git: {
55
+ category: "Lifecycle",
56
+ description: "Install a portable git on a Linux host that has none (bundle sync and `ouro clone` need git), or show which git is in use",
57
+ usage: "ouro git install [--force] | ouro git status",
58
+ example: "ouro git install",
59
+ subcommands: ["install", "status"],
60
+ },
54
61
  dev: {
55
62
  category: "Lifecycle",
56
63
  description: "Start daemon in development mode from a local repo",
@@ -273,6 +273,17 @@ function parseSelfUpdateHostCommand(args) {
273
273
  }
274
274
  return { kind: "self-update.enable", ...options };
275
275
  }
276
+ const GIT_USAGE = "Usage: ouro git install [--force] | ouro git status";
277
+ function parseGitCommand(args) {
278
+ const [sub, ...rest] = args;
279
+ if (sub === "status" && rest.length === 0)
280
+ return { kind: "git.status" };
281
+ if (sub === "install" && rest.length === 0)
282
+ return { kind: "git.install", force: false };
283
+ if (sub === "install" && rest.length === 1 && rest[0] === "--force")
284
+ return { kind: "git.install", force: true };
285
+ throw new Error(GIT_USAGE);
286
+ }
276
287
  function parseLogsCommand(args) {
277
288
  if (args.length === 0)
278
289
  return { kind: "daemon.logs" };
@@ -3454,6 +3465,8 @@ function parseOuroCommand(args) {
3454
3465
  return parseNervesReviewCommand(args.slice(1));
3455
3466
  if (head === "service")
3456
3467
  return parseServiceCommand(args.slice(1));
3468
+ if (head === "git")
3469
+ return parseGitCommand(args.slice(1));
3457
3470
  if (head === "sanctuary") {
3458
3471
  if (args.length === 3 && args[1] === "git-exclude" && args[2] === "--print")
3459
3472
  return { kind: "sanctuary.git-exclude" };
@@ -66,6 +66,7 @@ const daemon_tombstone_1 = require("./daemon-tombstone");
66
66
  const agent_config_check_1 = require("./agent-config-check");
67
67
  const pulse_1 = require("./pulse");
68
68
  const socket_client_1 = require("./socket-client");
69
+ const portable_git_1 = require("./portable-git");
69
70
  const home_filesystem_1 = require("./home-filesystem");
70
71
  const ouro_version_manager_1 = require("../versioning/ouro-version-manager");
71
72
  const await_private_wake_1 = require("./await-private-wake");
@@ -101,6 +102,8 @@ function parseSocketPath(argv) {
101
102
  }
102
103
  const socketPath = parseSocketPath(process.argv);
103
104
  (0, runtime_logging_1.configureDaemonRuntimeLogger)("daemon");
105
+ // Before anything spawns git: bundle sync and agent workers inherit this PATH.
106
+ (0, portable_git_1.activatePortableGit)();
104
107
  /* v8 ignore start -- refuses to start on a FAT or exFAT home; the check is unit-tested in home-filesystem.test.ts @preserve */
105
108
  const homeFilesystemProblem = (0, home_filesystem_1.unsupportedHomeFilesystem)((0, ouro_version_manager_1.getOuroCliHome)());
106
109
  if (homeFilesystemProblem) {
@@ -6,6 +6,39 @@
6
6
  * Each category checker is isolated: if one throws, it produces a single
7
7
  * "fail" check and the remaining categories still run.
8
8
  */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
9
42
  Object.defineProperty(exports, "__esModule", { value: true });
10
43
  exports.KNOWN_DOCTOR_CATEGORIES = exports.DEFAULT_MEMORY_FLOOR_MB = exports.DEFAULT_SENSE_DELIVERY_THRESHOLDS = exports.DEFAULT_MAIL_INGEST_THRESHOLDS = void 0;
11
44
  exports.checkCliPath = checkCliPath;
@@ -22,7 +55,10 @@ exports.checkFriends = checkFriends;
22
55
  exports.checkMemory = checkMemory;
23
56
  exports.checkDisk = checkDisk;
24
57
  exports.checkLifecycle = checkLifecycle;
58
+ exports.checkGit = checkGit;
25
59
  exports.runDoctorChecks = runDoctorChecks;
60
+ const path = __importStar(require("path"));
61
+ const portable_git_1 = require("./portable-git");
26
62
  const runtime_1 = require("../../nerves/runtime");
27
63
  const bluebubbles_health_diagnostics_1 = require("./bluebubbles-health-diagnostics");
28
64
  const webhook_registration_1 = require("../../senses/bluebubbles/webhook-registration");
@@ -1766,10 +1802,48 @@ function checkLifecycle(deps) {
1766
1802
  }
1767
1803
  return { name: "Lifecycle", checks };
1768
1804
  }
1805
+ /**
1806
+ * Bundle sync and `ouro clone` need git. A host without one (a BusyBox
1807
+ * appliance) can use the portable git from `ouro git install`.
1808
+ */
1809
+ function checkGit(deps) {
1810
+ const portableBinary = (0, portable_git_1.portableGitBinary)(deps.homedir);
1811
+ const portableBin = path.dirname(portableBinary);
1812
+ const systemGit = (deps.envPath ?? "").split(path.delimiter)
1813
+ .filter((dir) => dir && dir !== portableBin)
1814
+ .map((dir) => path.join(dir, "git"))
1815
+ .find((candidate) => deps.existsSync(candidate));
1816
+ if (systemGit)
1817
+ return { name: "Git", checks: [{ label: "git", status: "pass", detail: `system git: ${systemGit}` }] };
1818
+ if (deps.existsSync(portableBinary)) {
1819
+ return { name: "Git", checks: [{ label: "git", status: "pass", detail: `portable git: ${(0, portable_git_1.portableGitRoot)(deps.homedir)} (this host has no git of its own)` }] };
1820
+ }
1821
+ const syncAgents = discoverAgents(deps).filter((bundle) => {
1822
+ try {
1823
+ const sync = asRecord(asRecord(JSON.parse(deps.readFileSync(`${deps.bundlesRoot}/${bundle}/agent.json`)))?.sync);
1824
+ return sync?.enabled === true;
1825
+ }
1826
+ catch {
1827
+ return false;
1828
+ }
1829
+ }).map((bundle) => bundle.replace(/\.ouro$/, ""));
1830
+ const fix = (0, portable_git_1.portableGitAsset)(deps.platform, process.arch) ? "ouro git install" : "install git with the host's package manager";
1831
+ return {
1832
+ name: "Git",
1833
+ checks: [{
1834
+ label: "git",
1835
+ status: syncAgents.length > 0 ? "fail" : "warn",
1836
+ detail: syncAgents.length > 0
1837
+ ? `no git on this host, and bundle sync needs it for ${syncAgents.join(", ")}; fix: ${fix}`
1838
+ : `no git on this host; bundle sync and \`ouro clone\` need it; fix: ${fix}`,
1839
+ }],
1840
+ };
1841
+ }
1769
1842
  const CATEGORY_CHECKERS = [
1770
1843
  { name: "CLI", fn: checkCliPath },
1771
1844
  { name: "Daemon", fn: checkDaemon },
1772
1845
  { name: "Lifecycle", fn: checkLifecycle },
1846
+ { name: "Git", fn: checkGit },
1773
1847
  { name: "Agents", fn: checkAgents },
1774
1848
  { name: "Senses", fn: checkSenses },
1775
1849
  { name: "Habits", fn: checkHabits },
@@ -7,10 +7,12 @@ const runtime_1 = require("../../nerves/runtime");
7
7
  const cli_arg_redaction_1 = require("./cli-arg-redaction");
8
8
  const daemon_cli_1 = require("./daemon-cli");
9
9
  const runtime_logging_1 = require("./runtime-logging");
10
+ const portable_git_1 = require("./portable-git");
10
11
  if (process.argv[2] === "shepherd" && process.argv[3] !== "chat")
11
12
  (0, runtime_logging_1.configureDaemonRuntimeLogger)("ouro", { machine: true });
12
13
  else
13
14
  (0, runtime_logging_1.configureDaemonRuntimeLogger)("ouro");
15
+ (0, portable_git_1.activatePortableGit)();
14
16
  (0, runtime_1.emitNervesEvent)({
15
17
  component: "daemon",
16
18
  event: "daemon.cli_entry_start",
@@ -0,0 +1,265 @@
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.PORTABLE_GIT_DOWNLOAD_TIMEOUT_MS = exports.PORTABLE_GIT_MIN_FREE_BYTES = void 0;
37
+ exports.readPortableGitMarker = readPortableGitMarker;
38
+ exports.removeTree = removeTree;
39
+ exports.installPortableGit = installPortableGit;
40
+ exports.describeGitAvailability = describeGitAvailability;
41
+ exports.renderGitAvailability = renderGitAvailability;
42
+ exports.createDefaultPortableGitInstallDeps = createDefaultPortableGitInstallDeps;
43
+ const crypto = __importStar(require("crypto"));
44
+ const fs = __importStar(require("fs"));
45
+ const os = __importStar(require("os"));
46
+ const path = __importStar(require("path"));
47
+ const child_process_1 = require("child_process");
48
+ const runtime_1 = require("../../nerves/runtime");
49
+ const portable_git_1 = require("./portable-git");
50
+ /** Room for the archive (about 25 MB) and the extracted tree (about 57 MB) together. */
51
+ exports.PORTABLE_GIT_MIN_FREE_BYTES = 128 * 1024 * 1024;
52
+ exports.PORTABLE_GIT_DOWNLOAD_TIMEOUT_MS = 10 * 60 * 1000;
53
+ const MARKER_FILE = "ouro-portable-git.json";
54
+ function releaseDir(toolsDir) {
55
+ return path.join(toolsDir, `git-${portable_git_1.PORTABLE_GIT_RELEASE}`);
56
+ }
57
+ function readPortableGitMarker(root) {
58
+ try {
59
+ const parsed = JSON.parse(fs.readFileSync(path.join(root, MARKER_FILE), "utf8"));
60
+ if (typeof parsed.release !== "string" || typeof parsed.gitVersion !== "string")
61
+ return null;
62
+ return parsed;
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ }
68
+ function linkTarget(linkPath) {
69
+ try {
70
+ const stat = fs.lstatSync(linkPath);
71
+ if (!stat.isSymbolicLink()) {
72
+ throw new Error(`${linkPath} exists and is not the portable git link; move it aside and run \`ouro git install\` again`);
73
+ }
74
+ return fs.readlinkSync(linkPath);
75
+ }
76
+ catch (error) {
77
+ if (error.code === "ENOENT")
78
+ return null;
79
+ throw error;
80
+ }
81
+ }
82
+ async function download(deps, url, archivePath) {
83
+ const response = await deps.fetch(url, { redirect: "follow", signal: AbortSignal.timeout(exports.PORTABLE_GIT_DOWNLOAD_TIMEOUT_MS) });
84
+ if (!response.ok || !response.body)
85
+ throw new Error(`portable git download failed: HTTP ${response.status} from ${url}`);
86
+ const hash = crypto.createHash("sha256");
87
+ const fd = fs.openSync(archivePath, "w", 0o600);
88
+ try {
89
+ for await (const chunk of response.body) {
90
+ hash.update(chunk);
91
+ fs.writeSync(fd, chunk);
92
+ }
93
+ }
94
+ finally {
95
+ fs.closeSync(fd);
96
+ }
97
+ return hash.digest("hex");
98
+ }
99
+ function verifyTree(deps, tree) {
100
+ const git = deps.run(path.join(tree, "bin", "git"), ["--version"]);
101
+ if (git.status !== 0)
102
+ throw new Error(`portable git does not run on this host: ${(git.stderr || git.stdout).trim()}`);
103
+ // Through git, as sync will run it: with no URL the HTTPS helper prints its
104
+ // usage and exits 129. A missing libcurl stops it before that, and a git
105
+ // that cannot find its helpers says "not a git command".
106
+ const helper = deps.run(path.join(tree, "bin", "git"), ["remote-https"], (0, portable_git_1.portableGitEnv)(tree));
107
+ if (/is not a git command/.test(helper.stderr)) {
108
+ throw new Error(`portable git cannot find its helpers under ${tree}: ${helper.stderr.trim()}`);
109
+ }
110
+ if (helper.status === 127 || /error while loading shared libraries/.test(helper.stderr)) {
111
+ const reason = helper.stderr.split("\n").find((line) => /shared librar/.test(line)) ?? helper.stderr.trim();
112
+ throw new Error(`portable git's HTTPS helper cannot load on this host (${reason}); install libcurl (libcurl.so.4) or a system git`);
113
+ }
114
+ return git.stdout.trim();
115
+ }
116
+ /**
117
+ * Remove a tree we created by enumerating it: unlink each file and link (links
118
+ * are never followed), then rmdir bottom-up. Agent-callable code doesn't use
119
+ * recursive rm (test-isolation.contract Directive A). A missing path is fine.
120
+ */
121
+ function removeTree(target) {
122
+ let stat;
123
+ try {
124
+ stat = fs.lstatSync(target);
125
+ }
126
+ catch {
127
+ return;
128
+ }
129
+ if (!stat.isDirectory()) {
130
+ fs.rmSync(target, { force: true });
131
+ return;
132
+ }
133
+ for (const entry of fs.readdirSync(target))
134
+ removeTree(path.join(target, entry));
135
+ fs.rmdirSync(target);
136
+ }
137
+ function pruneOthers(toolsDir, keep) {
138
+ for (const entry of fs.readdirSync(toolsDir)) {
139
+ const isOurs = /^git-v/.test(entry) || /^\.git-.*\.(partial|tar\.gz)$/.test(entry);
140
+ if (!isOurs || entry === keep)
141
+ continue;
142
+ removeTree(path.join(toolsDir, entry));
143
+ }
144
+ }
145
+ /**
146
+ * Download, verify and install the pinned portable git, then point
147
+ * ~/.ouro-cli/tools/git at it. The archive must match its pinned sha256, and
148
+ * the unpacked git must run here before it replaces anything.
149
+ */
150
+ async function installPortableGit(deps, options = {}) {
151
+ const asset = (deps.resolveAsset ?? portable_git_1.portableGitAsset)(deps.platform, deps.arch);
152
+ if (!asset) {
153
+ throw new Error(`no portable git for ${deps.platform}-${deps.arch}; it covers Linux arm64, x64 and arm. Install git with the host's package manager.`);
154
+ }
155
+ const toolsDir = (0, portable_git_1.portableGitToolsDir)(deps.homeDir);
156
+ const root = (0, portable_git_1.portableGitRoot)(deps.homeDir);
157
+ const target = releaseDir(toolsDir);
158
+ fs.mkdirSync(toolsDir, { recursive: true, mode: 0o700 });
159
+ const currentLink = linkTarget(root);
160
+ const installed = readPortableGitMarker(target);
161
+ if (!options.force && installed?.release === portable_git_1.PORTABLE_GIT_RELEASE && currentLink === path.basename(target)) {
162
+ return { status: "already-installed", root, marker: installed };
163
+ }
164
+ const free = deps.freeBytes(toolsDir);
165
+ if (free < exports.PORTABLE_GIT_MIN_FREE_BYTES) {
166
+ throw new Error(`portable git needs ${Math.ceil(exports.PORTABLE_GIT_MIN_FREE_BYTES / 1048576)} MiB free under ${toolsDir}; ${Math.floor(free / 1048576)} MiB is free`);
167
+ }
168
+ const url = (deps.assetUrl ?? portable_git_1.portableGitAssetUrl)(asset);
169
+ const archive = path.join(toolsDir, `.git-${portable_git_1.PORTABLE_GIT_RELEASE}.tar.gz`);
170
+ const staging = path.join(toolsDir, `.git-${portable_git_1.PORTABLE_GIT_RELEASE}.partial`);
171
+ (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.portable_git_install_start", message: "installing the portable git", meta: { url, toolsDir } });
172
+ try {
173
+ const digest = await download(deps, url, archive);
174
+ if (digest !== asset.sha256)
175
+ throw new Error(`portable git archive failed its checksum: expected ${asset.sha256}, got ${digest}`);
176
+ removeTree(staging);
177
+ fs.mkdirSync(staging, { recursive: true });
178
+ deps.extract(archive, staging);
179
+ const gitVersion = verifyTree(deps, staging);
180
+ const marker = { release: portable_git_1.PORTABLE_GIT_RELEASE, asset: asset.name, sha256: asset.sha256, gitVersion, installedAt: deps.now().toISOString() };
181
+ fs.writeFileSync(path.join(staging, MARKER_FILE), `${JSON.stringify(marker, null, 2)}\n`);
182
+ removeTree(target);
183
+ fs.renameSync(staging, target);
184
+ const tempLink = path.join(toolsDir, `.git-link-${process.pid}`);
185
+ fs.rmSync(tempLink, { force: true });
186
+ fs.symlinkSync(path.basename(target), tempLink);
187
+ fs.renameSync(tempLink, root);
188
+ pruneOthers(toolsDir, path.basename(target));
189
+ (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.portable_git_installed", message: "portable git installed", meta: { root, gitVersion, release: portable_git_1.PORTABLE_GIT_RELEASE } });
190
+ return { status: "installed", root, marker };
191
+ }
192
+ catch (error) {
193
+ fs.rmSync(archive, { force: true });
194
+ removeTree(staging);
195
+ (0, runtime_1.emitNervesEvent)({
196
+ level: "error",
197
+ component: "daemon",
198
+ event: "daemon.portable_git_install_error",
199
+ message: "portable git install failed",
200
+ meta: { error: error instanceof Error ? error.message : String(error) },
201
+ });
202
+ throw error;
203
+ }
204
+ }
205
+ function describeGitAvailability(options = {}) {
206
+ const env = options.env ?? process.env;
207
+ const binary = (0, portable_git_1.portableGitBinary)(options.homeDir);
208
+ const portableBin = path.dirname(binary);
209
+ const hostPath = (env.PATH ?? "").split(path.delimiter).filter((dir) => dir !== portableBin).join(path.delimiter);
210
+ const systemGit = (0, portable_git_1.findGitOnPath)(hostPath);
211
+ const root = (0, portable_git_1.portableGitRoot)(options.homeDir);
212
+ const portable = fs.existsSync(binary) ? { root, binary, marker: readPortableGitMarker(root) } : null;
213
+ return {
214
+ systemGit,
215
+ portable,
216
+ portableSupported: (0, portable_git_1.portableGitAsset)(options.platform ?? process.platform, options.arch ?? process.arch) !== null,
217
+ };
218
+ }
219
+ function renderGitAvailability(availability) {
220
+ const lines = [];
221
+ lines.push(availability.systemGit ? `system git: ${availability.systemGit}` : "system git: none");
222
+ if (availability.portable) {
223
+ const marker = availability.portable.marker;
224
+ lines.push(`portable git: ${availability.portable.root}${marker ? ` (${marker.gitVersion}, ${marker.release})` : ""}`);
225
+ lines.push(availability.systemGit ? "in use: system git" : "in use: portable git");
226
+ }
227
+ else if (availability.systemGit) {
228
+ lines.push("in use: system git");
229
+ }
230
+ else if (availability.portableSupported) {
231
+ lines.push("in use: none; run `ouro git install`");
232
+ }
233
+ else {
234
+ lines.push("in use: none; install git with the host's package manager");
235
+ }
236
+ return lines.join("\n");
237
+ }
238
+ /* v8 ignore start -- host defaults: real network, statfs, tar and process spawning @preserve */
239
+ function createDefaultPortableGitInstallDeps(homeDir = os.homedir()) {
240
+ return {
241
+ platform: process.platform,
242
+ arch: process.arch,
243
+ homeDir,
244
+ fetch: globalThis.fetch,
245
+ freeBytes: (dir) => {
246
+ const stats = fs.statfsSync(dir);
247
+ return Number(stats.bavail) * Number(stats.bsize);
248
+ },
249
+ extract: (archive, dest) => {
250
+ const run = (0, child_process_1.spawnSync)("tar", ["-xzf", archive, "-C", dest], { stdio: ["ignore", "pipe", "pipe"] });
251
+ if (run.error)
252
+ throw run.error;
253
+ if (run.status !== 0)
254
+ throw new Error(`tar failed: ${run.stderr.toString().trim()}`);
255
+ },
256
+ run: (file, args, env) => {
257
+ const run = (0, child_process_1.spawnSync)(file, args, { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"], timeout: 30_000 });
258
+ if (run.error)
259
+ return { status: null, stdout: "", stderr: run.error.message };
260
+ return { status: run.status, stdout: run.stdout.toString(), stderr: run.stderr.toString() };
261
+ },
262
+ now: () => new Date(),
263
+ };
264
+ }
265
+ /* v8 ignore stop */
@@ -0,0 +1,144 @@
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.PORTABLE_GIT_ASSETS = exports.PORTABLE_GIT_BUILD = exports.PORTABLE_GIT_RELEASE = void 0;
37
+ exports.portableGitAsset = portableGitAsset;
38
+ exports.portableGitAssetUrl = portableGitAssetUrl;
39
+ exports.portableGitToolsDir = portableGitToolsDir;
40
+ exports.portableGitRoot = portableGitRoot;
41
+ exports.portableGitBinary = portableGitBinary;
42
+ exports.findGitOnPath = findGitOnPath;
43
+ exports.portableGitEnv = portableGitEnv;
44
+ exports.activatePortableGit = activatePortableGit;
45
+ const fs = __importStar(require("fs"));
46
+ const os = __importStar(require("os"));
47
+ const path = __importStar(require("path"));
48
+ const runtime_1 = require("../../nerves/runtime");
49
+ /**
50
+ * A portable git for hosts that have none (a BusyBox appliance has no package
51
+ * manager to install one). The build is GitHub Desktop's dugite-native: git
52
+ * with a relocatable prefix that links only libc, zlib and, for HTTPS, the
53
+ * host's libcurl. It is installed under ~/.ouro-cli/tools/git and used only
54
+ * when the host has no git of its own.
55
+ */
56
+ exports.PORTABLE_GIT_RELEASE = "v2.56.0-2";
57
+ exports.PORTABLE_GIT_BUILD = "v2.56.0-a44aeca";
58
+ exports.PORTABLE_GIT_ASSETS = {
59
+ "linux-arm64": { name: `dugite-native-${exports.PORTABLE_GIT_BUILD}-ubuntu-arm64.tar.gz`, sha256: "d5ce120515bf3013a014e6a918aa87ec0f7a6f5f9687c48d50127e637cb9b6c2" },
60
+ "linux-x64": { name: `dugite-native-${exports.PORTABLE_GIT_BUILD}-ubuntu-x64.tar.gz`, sha256: "1efd8ce0516b670b6b6d0f49ecaf395ceb8cf7fff3f5857259763d97a1238df9" },
61
+ "linux-arm": { name: `dugite-native-${exports.PORTABLE_GIT_BUILD}-ubuntu-arm.tar.gz`, sha256: "7a14edae189f791e64f8d037c8e3830acd648cd1ad891db40c8d6469d33b36cd" },
62
+ };
63
+ function portableGitAsset(platform, arch) {
64
+ return exports.PORTABLE_GIT_ASSETS[`${platform}-${arch}`] ?? null;
65
+ }
66
+ function portableGitAssetUrl(asset) {
67
+ return `https://github.com/desktop/dugite-native/releases/download/${exports.PORTABLE_GIT_RELEASE}/${asset.name}`;
68
+ }
69
+ function portableGitToolsDir(homeDir = os.homedir()) {
70
+ return path.join(homeDir, ".ouro-cli", "tools");
71
+ }
72
+ /** The stable path: a symlink to the installed release directory. */
73
+ function portableGitRoot(homeDir = os.homedir()) {
74
+ return path.join(portableGitToolsDir(homeDir), "git");
75
+ }
76
+ function portableGitBinary(homeDir = os.homedir()) {
77
+ return path.join(portableGitRoot(homeDir), "bin", "git");
78
+ }
79
+ function isExecutableFile(filePath) {
80
+ try {
81
+ fs.accessSync(filePath, fs.constants.X_OK);
82
+ return fs.statSync(filePath).isFile();
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ }
88
+ /** The first `git` on a PATH value, or null. */
89
+ function findGitOnPath(pathValue, isExecutable = isExecutableFile) {
90
+ for (const dir of (pathValue ?? "").split(path.delimiter)) {
91
+ if (!dir)
92
+ continue;
93
+ const candidate = path.join(dir, "git");
94
+ if (isExecutable(candidate))
95
+ return candidate;
96
+ }
97
+ return null;
98
+ }
99
+ /**
100
+ * What a dugite-native git needs to find its helpers, templates and CA bundle
101
+ * when it runs from an arbitrary directory (dugite's own wrapper sets the
102
+ * same). `PREFIX` is left out: npm reads it too.
103
+ */
104
+ function portableGitEnv(root, exists = fs.existsSync) {
105
+ const env = {
106
+ GIT_EXEC_PATH: path.join(root, "libexec", "git-core"),
107
+ GIT_TEMPLATE_DIR: path.join(root, "share", "git-core", "templates"),
108
+ };
109
+ const caBundle = path.join(root, "ssl", "cacert.pem");
110
+ if (exists(caBundle))
111
+ env.GIT_SSL_CAINFO = caBundle;
112
+ return env;
113
+ }
114
+ /**
115
+ * Put the portable git's bin directory first on PATH when it is installed and
116
+ * the host has no git, so every `git` this process or its children run (bundle
117
+ * sync, clone, the agent's own shell) finds it. Hosts without a portable git
118
+ * pay one failed access check.
119
+ */
120
+ function activatePortableGit(options = {}) {
121
+ const env = options.env ?? process.env;
122
+ const isExecutable = options.isExecutable ?? isExecutableFile;
123
+ const binary = portableGitBinary(options.homeDir);
124
+ if (!isExecutable(binary))
125
+ return { status: "absent" };
126
+ const binDir = path.dirname(binary);
127
+ const systemGit = findGitOnPath(env.PATH, isExecutable);
128
+ if (systemGit === binary)
129
+ return { status: "activated", binDir };
130
+ if (systemGit)
131
+ return { status: "system", git: systemGit };
132
+ env.PATH = env.PATH ? `${binDir}${path.delimiter}${env.PATH}` : binDir;
133
+ for (const [key, value] of Object.entries(portableGitEnv(path.dirname(binDir)))) {
134
+ if (env[key] === undefined)
135
+ env[key] = value;
136
+ }
137
+ (0, runtime_1.emitNervesEvent)({
138
+ component: "daemon",
139
+ event: "daemon.portable_git_activated",
140
+ message: "the host has no git; using the portable git",
141
+ meta: { binDir },
142
+ });
143
+ return { status: "activated", binDir };
144
+ }
@@ -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,
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1062",
3
+ "version": "0.1.0-alpha.1067",
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.1062",
9
+ "version": "0.1.0-alpha.1067",
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.1062",
3
+ "version": "0.1.0-alpha.1067",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },