Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
ci / node suites (push) Has been cancelled
- New service apps/rithub-device-auth (pm2, 127.0.0.1:3357, proxied at rithub.dev /device* and /api/rit/device*): RFC-8628-shaped device authorization flow (POST /api/rit/device/code, GET /device, POST /api/rit/device/token) wrapping the forge core's own real OAuth2 "Rit CLI" application via PKCE (no client secret). Only a SHA-256 hash of each device_code is stored, codes expire in 10 minutes and are single-use, polling is rate-limited. The /device confirmation page reuses the real site chrome and shows the exact scopes being granted. - Extended the engine's own "Rit CLI" OAuth2 app with a second redirect_uri for the new callback, and bumped [oauth2] ACCESS_TOKEN_EXPIRATION_TIME to 30 days (was the 1h default) so a `rit login` session behaves like a normal long-lived token. - packages/rithub-cli: `rit login` on a TTY now runs the real device flow by default (src/deviceLogin.mjs); `--paste-token` keeps the old paste-a-PAT fallback. Fixed two real bugs found while verifying this: apiCallRaw() never merged a caller's extra headers (broke `rit api` with --method/--input, e.g. the Content-Type needed to PATCH the OAuth2 app above), and issue close/reopen only accepted HTTP 200 when this engine build answers 201. Bumped 0.3.0 -> 0.3.1, published to npm. - Full-scope admin token minted for caelum0x (RITHUB_CAELUM0X_FULL_TOKEN in products/.env) and the previously-403ing commands (issue, label, milestone, status, change comment, org) re-verified live against a throwaway repo, then deleted. - End-to-end proved live: a mail.tm test account signed in through the real /device page in a real browser session, `rit login` in a fresh HOME completed, `rit whoami`/`rit issue create`/`rit clone` all worked off the resulting token. Test repo, issue, and account deleted after. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
97 lines
3.4 KiB
JavaScript
Executable File
97 lines
3.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
import { execFileSync } from "node:child_process";
|
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, chmodSync, rmSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { homedir } from "node:os";
|
|
|
|
import { main } from "../src/cli.mjs";
|
|
import { openUrl } from "../src/open-browser.mjs";
|
|
|
|
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8"));
|
|
|
|
/** Reads a token from the terminal with the input hidden -- used by `rit
|
|
* login` when no `--token`/`RITHUB_TOKEN` was given. Piped/non-interactive
|
|
* stdin (CI, another process) is read whole instead of char-by-char, so
|
|
* `echo $TOKEN | rit login` works without a TTY. Never echoes what was
|
|
* typed, not even as `*` (simplest correct thing; avoids cursor-position
|
|
* bugs entirely). */
|
|
function promptHidden(message) {
|
|
return new Promise((resolve) => {
|
|
if (!process.stdin.isTTY) {
|
|
let data = "";
|
|
process.stdin.setEncoding("utf8");
|
|
process.stdin.on("data", (chunk) => (data += chunk));
|
|
process.stdin.on("end", () => resolve(data));
|
|
process.stdin.on("error", () => resolve(data));
|
|
return;
|
|
}
|
|
process.stdout.write(message);
|
|
const { stdin } = process;
|
|
stdin.resume();
|
|
stdin.setRawMode(true);
|
|
stdin.setEncoding("utf8");
|
|
let value = "";
|
|
const finish = (result) => {
|
|
stdin.setRawMode(false);
|
|
stdin.pause();
|
|
stdin.removeListener("data", onData);
|
|
process.stdout.write("\n");
|
|
resolve(result);
|
|
};
|
|
function onData(char) {
|
|
if (char === "\n" || char === "\r" || char === "\u0004") {
|
|
finish(value);
|
|
} else if (char === "\u0003") {
|
|
finish(value); // Ctrl+C: stop reading, let the caller fail on an empty token
|
|
} else if (char === "\u007f" || char === "\b") {
|
|
value = value.slice(0, -1);
|
|
} else {
|
|
value += char;
|
|
}
|
|
}
|
|
stdin.on("data", onData);
|
|
});
|
|
}
|
|
|
|
const code = await main(process.argv.slice(2), {
|
|
env: process.env,
|
|
cwd: process.cwd(),
|
|
homeDir: homedir(),
|
|
version: pkg.version,
|
|
out: (s) => process.stdout.write(`${s}\n`),
|
|
err: (s) => process.stderr.write(`${s}\n`),
|
|
now: () => Date.now(),
|
|
fetchImpl: fetch,
|
|
promptHidden,
|
|
isTTY: process.stdin.isTTY === true,
|
|
openUrl,
|
|
exists: (path) => existsSync(path),
|
|
readFile: (path) => (existsSync(path) ? readFileSync(path, "utf8") : null),
|
|
writeFile: (path, contents, opts) => {
|
|
mkdirSync(dirname(path), { recursive: true });
|
|
writeFileSync(path, contents);
|
|
if (opts?.mode !== undefined) chmodSync(path, opts.mode);
|
|
},
|
|
unlink: (path) => {
|
|
try {
|
|
rmSync(path, { force: true });
|
|
} catch {
|
|
// best-effort: logout must not crash if the file is already gone or unreadable
|
|
}
|
|
},
|
|
run: (command, args, cwd) => {
|
|
try {
|
|
// GIT_TERMINAL_PROMPT=0: a credential prompt in a non-interactive CLI
|
|
// (an agent, CI) would otherwise hang forever instead of failing with
|
|
// a message we can print. Interactive logins go through `rit login`,
|
|
// not a git credential prompt.
|
|
const output = execFileSync(command, args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
return { ok: true, output };
|
|
} catch (err) {
|
|
return { ok: false, output: `${err.stdout ?? ""}${err.stderr ?? err.message ?? ""}` };
|
|
}
|
|
},
|
|
});
|
|
process.exit(code);
|