@ouro.bot/cli 0.1.0-alpha.1003 → 0.1.0-alpha.1006
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/auth/auth-flow.js +11 -0
- package/dist/heart/auth/github-device-login.js +104 -0
- package/dist/heart/awaiting/await-scheduler.js +12 -0
- package/dist/heart/daemon/daemon-entry.js +2 -2
- package/dist/heart/daemon/doctor.js +1 -1
- package/dist/heart/daemon/os-cron.js +23 -1
- package/dist/heart/habits/habit-scheduler.js +14 -0
- 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.1006",
|
|
6
|
+
"changes": [
|
|
7
|
+
"On Linux outside a container, habits and awaits fire from the daemon's own timers instead of writing launchd plists and spawning launchctl, and are no longer reported as degraded. macOS keeps launchd and containers keep supercronic."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1005",
|
|
12
|
+
"changes": [
|
|
13
|
+
"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."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1003",
|
|
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.1006</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
|
+
}
|
|
@@ -253,6 +253,18 @@ class AwaitScheduler {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
verifyCronAndCreateFallbacks(jobs) {
|
|
256
|
+
if (this.osCronManager.firesInProcess) {
|
|
257
|
+
// Nothing is registered with the OS: every await runs on an in-process timer, which is not degraded.
|
|
258
|
+
for (const job of jobs) {
|
|
259
|
+
const bareName = job.taskId.slice(exports.AWAIT_CRON_LABEL_PREFIX_MARKER.length + 1);
|
|
260
|
+
const ms = (0, cadence_1.parseCadenceToMs)(this.getAwaitFile(bareName)?.cadence);
|
|
261
|
+
if (ms !== null)
|
|
262
|
+
this.createTimerFallback(bareName, ms);
|
|
263
|
+
else
|
|
264
|
+
this.degradedAwaitNames.set(bareName, "cadence cannot be scheduled with an in-process timer");
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
256
268
|
if (!this.execForVerify && !this.verifyJobs)
|
|
257
269
|
return;
|
|
258
270
|
const verifiedLabels = this.verifyJobs?.(jobs)
|
|
@@ -748,7 +748,7 @@ void (0, daemon_bootstrap_startup_1.startDaemonAfterContainerCredentialBootstrap
|
|
|
748
748
|
(0, habit_migration_1.migrateHabitsFromTaskSystem)(bundleRoot);
|
|
749
749
|
const osCronManager = supercronicSupervisor
|
|
750
750
|
? supercronicSupervisor.namespace(`habit:${agent}`)
|
|
751
|
-
: new os_cron_1.LaunchdCronManager(osCronDeps, { ownsLabel: habitCronLabelOwner(agent) });
|
|
751
|
+
: (0, os_cron_1.hostOsCronManager)(process.platform, () => new os_cron_1.LaunchdCronManager(osCronDeps, { ownsLabel: habitCronLabelOwner(agent) }));
|
|
752
752
|
const scheduler = new habit_scheduler_1.HabitScheduler({
|
|
753
753
|
agent,
|
|
754
754
|
habitsDir,
|
|
@@ -847,7 +847,7 @@ void (0, daemon_bootstrap_startup_1.startDaemonAfterContainerCredentialBootstrap
|
|
|
847
847
|
try {
|
|
848
848
|
const awaitOsCronManager = supercronicSupervisor
|
|
849
849
|
? supercronicSupervisor.namespace(`await:${agent}`)
|
|
850
|
-
: new os_cron_1.LaunchdCronManager(osCronDeps, { ownsLabel: awaitCronLabelOwner(agent) });
|
|
850
|
+
: (0, os_cron_1.hostOsCronManager)(process.platform, () => new os_cron_1.LaunchdCronManager(osCronDeps, { ownsLabel: awaitCronLabelOwner(agent) }));
|
|
851
851
|
const awaitScheduler = new await_scheduler_1.AwaitScheduler({
|
|
852
852
|
agent,
|
|
853
853
|
awaitsDir,
|
|
@@ -641,7 +641,7 @@ function checkHabits(deps) {
|
|
|
641
641
|
checks.push({
|
|
642
642
|
label: `${agentDir} launchd plists`,
|
|
643
643
|
status: "pass",
|
|
644
|
-
detail: `launchd not applicable on ${platform}; scheduled habits
|
|
644
|
+
detail: `launchd not applicable on ${platform}; scheduled habits fire from the daemon's timers, or supercronic in a container`,
|
|
645
645
|
});
|
|
646
646
|
continue;
|
|
647
647
|
}
|
|
@@ -33,7 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.CrontabCronManager = exports.LaunchdCronManager = void 0;
|
|
36
|
+
exports.InProcessCronManager = exports.CrontabCronManager = exports.LaunchdCronManager = void 0;
|
|
37
|
+
exports.hostOsCronManager = hostOsCronManager;
|
|
37
38
|
exports.createOsCronManager = createOsCronManager;
|
|
38
39
|
exports.cadenceToSeconds = cadenceToSeconds;
|
|
39
40
|
exports.scheduleToCalendarInterval = scheduleToCalendarInterval;
|
|
@@ -240,6 +241,27 @@ class CrontabCronManager {
|
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
exports.CrontabCronManager = CrontabCronManager;
|
|
244
|
+
/**
|
|
245
|
+
* For hosts with no per-user scheduler we can own: the daemon's in-process
|
|
246
|
+
* timers fire every job, so nothing is written to the OS. A Linux appliance's
|
|
247
|
+
* crontab is shared with the system, and a supervised daemon (`ouro service`)
|
|
248
|
+
* is already running whenever a timer is due.
|
|
249
|
+
*/
|
|
250
|
+
class InProcessCronManager {
|
|
251
|
+
firesInProcess = true;
|
|
252
|
+
sync(jobs) {
|
|
253
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.os_cron_in_process", message: "scheduled jobs fire from in-process timers", meta: { jobCount: jobs.length } });
|
|
254
|
+
}
|
|
255
|
+
removeAll() { }
|
|
256
|
+
list() {
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.InProcessCronManager = InProcessCronManager;
|
|
261
|
+
/** launchd on macOS; in-process timers on every other host outside a container. */
|
|
262
|
+
function hostOsCronManager(platform, launchd) {
|
|
263
|
+
return platform === "darwin" ? launchd() : new InProcessCronManager();
|
|
264
|
+
}
|
|
243
265
|
function createOsCronManager(options = {}) {
|
|
244
266
|
const platform = options.platform ?? process.platform;
|
|
245
267
|
if (platform === "darwin") {
|
|
@@ -270,6 +270,8 @@ class HabitScheduler {
|
|
|
270
270
|
}, intervalMs);
|
|
271
271
|
}
|
|
272
272
|
verifyCronAndCreateFallbacks(state) {
|
|
273
|
+
if (this.osCronManager.firesInProcess)
|
|
274
|
+
return this.scheduleInProcess(state);
|
|
273
275
|
if ((!this.execForVerify && !this.verifyJobs) || state.jobs.length === 0)
|
|
274
276
|
return state;
|
|
275
277
|
let currentState = state;
|
|
@@ -335,6 +337,18 @@ class HabitScheduler {
|
|
|
335
337
|
});
|
|
336
338
|
return null;
|
|
337
339
|
}
|
|
340
|
+
/** Nothing is registered with the OS, so every job runs on an in-process timer; that is not degraded. */
|
|
341
|
+
scheduleInProcess(state) {
|
|
342
|
+
for (const job of state.jobs) {
|
|
343
|
+
const cadence = state.habits.find((habit) => habit.name === job.taskId).cadence;
|
|
344
|
+
const ms = (0, cadence_1.cadenceFallbackDelayMs)(cadence, this.deps.now());
|
|
345
|
+
if (ms !== null)
|
|
346
|
+
this.createTimerFallback(job.taskId, cadence, ms);
|
|
347
|
+
else
|
|
348
|
+
this.degradedHabitNames.set(job.taskId, "cadence cannot be scheduled with an in-process timer");
|
|
349
|
+
}
|
|
350
|
+
return state;
|
|
351
|
+
}
|
|
338
352
|
verifyCronEntries() {
|
|
339
353
|
const verified = new Set();
|
|
340
354
|
try {
|
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.1006",
|
|
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.1006",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@azure/identity": "^4.13.0",
|