@ouro.bot/cli 0.1.0-alpha.1003 → 0.1.0-alpha.1005

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.1005",
6
+ "changes": [
7
+ "ouro auth for github-copilot on a host without gh runs GitHub's device login itself: enter the shown code at github.com/login/device on any device."
8
+ ]
9
+ },
4
10
  {
5
11
  "version": "0.1.0-alpha.1003",
6
12
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1003",
2
+ "runtimeVersion": "0.1.0-alpha.1005",
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.1003</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1005</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -44,6 +44,7 @@ const child_process_1 = require("child_process");
44
44
  const fs = __importStar(require("fs"));
45
45
  const os = __importStar(require("os"));
46
46
  const path = __importStar(require("path"));
47
+ const github_device_login_1 = require("./github-device-login");
47
48
  const runtime_1 = require("../../nerves/runtime");
48
49
  const identity_1 = require("../identity");
49
50
  const migrate_config_1 = require("../migrate-config");
@@ -292,11 +293,21 @@ async function collectRuntimeAuthCredentials(input, deps) {
292
293
  }
293
294
  if (input.provider === "github-copilot") {
294
295
  let token = process.env.GH_TOKEN?.trim() || process.env.GITHUB_TOKEN?.trim() || "";
296
+ let ghInstalled = true;
295
297
  if (!token) {
296
298
  writeAuthProgress(input, "checking GitHub CLI credentials...");
297
299
  const result = spawnSync("gh", ["auth", "token"], { encoding: "utf8" });
300
+ ghInstalled = result.error?.code !== "ENOENT";
298
301
  token = (result.status === 0 && result.stdout ? result.stdout.trim() : "");
299
302
  }
303
+ if (!token && !ghInstalled) {
304
+ // No gh on this host (an appliance, a container): GitHub's device flow needs only a code entered elsewhere.
305
+ writeAuthProgress(input, "starting GitHub device login...");
306
+ const deviceLogin = deps.githubDeviceLogin ?? github_device_login_1.githubDeviceLogin;
307
+ // Callers without a progress view (the cold hatch prompt) still need to see the code.
308
+ const showCode = input.onProgress ?? ((message) => { process.stderr.write(`${message}\n`); });
309
+ token = await deviceLogin(showCode);
310
+ }
300
311
  if (!token) {
301
312
  writeAuthProgress(input, "starting GitHub login...");
302
313
  (0, runtime_1.emitNervesEvent)({
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GITHUB_CLI_DEFAULT_SCOPES = exports.GITHUB_CLI_OAUTH_CLIENT_ID = void 0;
4
+ exports.githubDeviceLogin = githubDeviceLogin;
5
+ const runtime_1 = require("../../nerves/runtime");
6
+ /**
7
+ * GitHub CLI's public OAuth app and its default scopes: the same client and
8
+ * scopes `gh auth login` requests, so the token is the one the `gh` path
9
+ * yields. Used on hosts without `gh`, such as an appliance.
10
+ */
11
+ exports.GITHUB_CLI_OAUTH_CLIENT_ID = "178c6fc778ccc68e1d6a";
12
+ exports.GITHUB_CLI_DEFAULT_SCOPES = "repo read:org gist";
13
+ const DEVICE_CODE_URL = "https://github.com/login/device/code";
14
+ const ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token";
15
+ const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
16
+ const SLOW_DOWN_STEP_MS = 5_000;
17
+ const defaultDeps = {
18
+ fetch: (...args) => fetch(...args),
19
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
20
+ now: () => Date.now(),
21
+ };
22
+ function postForm(deps, url, form) {
23
+ return deps.fetch(url, {
24
+ method: "POST",
25
+ headers: { Accept: "application/json", "Content-Type": "application/x-www-form-urlencoded" },
26
+ body: new URLSearchParams(form).toString(),
27
+ });
28
+ }
29
+ async function readJson(response) {
30
+ try {
31
+ return await response.json();
32
+ }
33
+ catch {
34
+ return {};
35
+ }
36
+ }
37
+ /**
38
+ * GitHub's OAuth device flow: shows a code to enter at github.com/login/device
39
+ * on any device, then polls until it is approved. Needs no browser or `gh` on
40
+ * this host. Returns the access token.
41
+ */
42
+ async function githubDeviceLogin(showCode, deps = defaultDeps) {
43
+ const codeResponse = await postForm(deps, DEVICE_CODE_URL, { client_id: exports.GITHUB_CLI_OAUTH_CLIENT_ID, scope: exports.GITHUB_CLI_DEFAULT_SCOPES });
44
+ if (!codeResponse.ok)
45
+ throw new Error(`GitHub device login could not start (HTTP ${codeResponse.status}).`);
46
+ const code = await readJson(codeResponse);
47
+ if (!code.device_code || !code.user_code || !code.verification_uri) {
48
+ throw new Error("GitHub device login returned no code to enter.");
49
+ }
50
+ showCode(`To sign in to GitHub, open ${code.verification_uri} on any device and enter code ${code.user_code}`);
51
+ (0, runtime_1.emitNervesEvent)({
52
+ component: "daemon",
53
+ event: "daemon.auth_github_device_login_start",
54
+ message: "waiting for GitHub device login approval",
55
+ meta: { verificationUri: code.verification_uri, expiresInSeconds: code.expires_in ?? null },
56
+ });
57
+ try {
58
+ return await pollForToken(code.device_code, code.interval, code.expires_in, deps);
59
+ }
60
+ catch (error) {
61
+ (0, runtime_1.emitNervesEvent)({
62
+ level: "error",
63
+ component: "daemon",
64
+ event: "daemon.auth_github_device_login_error",
65
+ message: "GitHub device login did not complete",
66
+ meta: { error: error.message },
67
+ });
68
+ throw error;
69
+ }
70
+ }
71
+ async function pollForToken(deviceCode, interval, expiresIn, deps) {
72
+ let intervalMs = (interval ?? 5) * 1000;
73
+ const deadline = deps.now() + (expiresIn ?? 900) * 1000;
74
+ while (deps.now() < deadline) {
75
+ await deps.sleep(intervalMs);
76
+ const response = await postForm(deps, ACCESS_TOKEN_URL, {
77
+ client_id: exports.GITHUB_CLI_OAUTH_CLIENT_ID,
78
+ device_code: deviceCode,
79
+ grant_type: DEVICE_GRANT_TYPE,
80
+ });
81
+ const result = await readJson(response);
82
+ if (result.access_token) {
83
+ (0, runtime_1.emitNervesEvent)({
84
+ component: "daemon",
85
+ event: "daemon.auth_github_device_login_end",
86
+ message: "GitHub device login approved",
87
+ meta: {},
88
+ });
89
+ return result.access_token;
90
+ }
91
+ if (result.error === "authorization_pending")
92
+ continue;
93
+ if (result.error === "slow_down") {
94
+ intervalMs = result.interval ? result.interval * 1000 : intervalMs + SLOW_DOWN_STEP_MS;
95
+ continue;
96
+ }
97
+ if (result.error === "expired_token")
98
+ break;
99
+ if (result.error === "access_denied")
100
+ throw new Error("GitHub device login was denied.");
101
+ throw new Error(`GitHub device login failed: ${result.error ?? `HTTP ${response.status}`}.`);
102
+ }
103
+ throw new Error("The GitHub device login code expired before it was approved. Run ouro auth again.");
104
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1003",
3
+ "version": "0.1.0-alpha.1005",
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.1003",
9
+ "version": "0.1.0-alpha.1005",
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.1003",
3
+ "version": "0.1.0-alpha.1005",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },