@recoder.xyz/rithub 0.3.5 → 0.4.0

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/README.md CHANGED
@@ -87,23 +87,38 @@ a cached OS credential can't silently swap in a different account) —
87
87
  verified live against a private repo that the resulting `.git/config`
88
88
  has no token or header in it.
89
89
 
90
- ## No account, no sign-in, no human: `rit init`
90
+ ## No browser, no CAPTCHA, ever: `rit signup`
91
91
 
92
92
  One command gives an AI coding agent (or a person) a real Rithub
93
93
  account, an access token scoped to one repo, and a first repo — then
94
- `git push` works, with no login step at all:
94
+ `git push` works, with no login step and no browser at all:
95
95
 
96
96
  ```
97
- $ npx @recoder.xyz/rithub init
97
+ $ npx @recoder.xyz/rithub signup
98
98
  Live in 0.9s: agent-lwlvjdtj -> https://rithub.dev/agent-lwlvjdtj/first-repo
99
99
  git remote 'origin' set to agent-lwlvjdtj/first-repo. Next: git add -A && git commit -m "first commit" && git push -u origin main
100
- Unclaimed: a small repo quota applies. Keep this account: rithub claim --email you@example.com
100
+ Unclaimed: a small repo quota applies. Keep this account: rithub claim --email you@example.com (or next time, `rit signup --email you@x.com`)
101
101
  ```
102
102
 
103
- Re-running `rit init` in the same directory reuses the account from
103
+ Re-running `rit signup` in the same directory reuses the account from
104
104
  `.rithub/agent.json` (gitignored automatically) instead of signing up again.
105
+ `rit init` still works too — `signup` with no flags does exactly the same
106
+ thing; it's just the name an agent discovering this CLI is more likely to
107
+ reach for.
105
108
 
106
- A small repo quota applies until a human claims the account:
109
+ Have a real mailbox and want the account bound to it from the start
110
+ (no quota, no separate `claim` step)? Use the email-verified shape — a
111
+ one-time code is mailed, no browser step either:
112
+
113
+ ```
114
+ $ npx @recoder.xyz/rithub signup --email you@x.com
115
+ Code sent to you@x.com -- check your inbox, then run: rit signup --verify <code>
116
+ $ npx @recoder.xyz/rithub signup --verify 482913
117
+ Live in 0.4s: you (you@x.com) -> https://rithub.dev/you/first-repo
118
+ git remote 'origin' set to you/first-repo. Next: git add -A && git commit -m "first commit" && git push -u origin main
119
+ ```
120
+
121
+ Or stick with the original two-step flow if you'd rather claim later:
107
122
 
108
123
  ```
109
124
  npx @recoder.xyz/rithub claim --email you@example.com
@@ -114,12 +129,13 @@ This sets the account's real email and lifts the quota. Afterward, open
114
129
  real password and sign in as the account in a browser — no separate
115
130
  claim-token system, just Rithub's own password-reset mail.
116
131
 
117
- ## How `init`/`claim` work
132
+ ## How `signup`/`init`/`claim` work
118
133
 
119
- `init` solves a small proof-of-work challenge (cheap for a machine,
120
- expensive for mass abuse — no CAPTCHA, since an agent cannot solve one),
121
- then calls the signup route that [`apps/rithub-mcp`](../../apps/rithub-mcp)
122
- already exposes at `rithub.dev` next to its MCP endpoint:
134
+ Bare `signup` (and `init`) solve a small proof-of-work challenge (cheap
135
+ for a machine, expensive for mass abuse — no CAPTCHA, since an agent
136
+ cannot solve one), then call the signup route that
137
+ [`apps/rithub-mcp`](../../apps/rithub-mcp) already exposes at
138
+ `rithub.dev` next to its MCP endpoint:
123
139
 
124
140
  ```
125
141
  GET https://rithub.dev/agent-signup/challenge -> { challenge, bits }
@@ -127,8 +143,20 @@ POST https://rithub.dev/agent-signup { challenge, nonce, rep
127
143
  POST https://rithub.dev/agent-signup/claim (Bearer <token>) { email }
128
144
  ```
129
145
 
146
+ `signup --email`/`--verify` instead proves control of a real mailbox (a
147
+ mailed one-time code) and skips the proof-of-work step entirely:
148
+
149
+ ```
150
+ POST https://rithub.dev/agent-signup/email/start { email } -> 202, mails a 6-digit code (10 min TTL)
151
+ POST https://rithub.dev/agent-signup/email/verify { email, code, repo_name? } -> 201, same account/token/repo shape as /agent-signup
152
+ ```
153
+
154
+ Known disposable/temp-mail domains are rejected on `/email/start` with a
155
+ 422 — proof-of-work (`rit signup` with no `--email`) is the right tool
156
+ for a caller with no real mailbox, not a borrowed disposable one.
157
+
130
158
  An agent that would rather skip the CLI and call the API directly can do
131
- exactly that — same two JSON endpoints, no SDK required. Everything
159
+ exactly that — same JSON endpoints, no SDK required. Everything
132
160
  else (`login`/`clone`/`repo create`/`push`) talks to Rithub's own
133
161
  REST API at `/api/v1` with a plain `fetch` — no SDK there either.
134
162
 
@@ -137,6 +165,7 @@ REST API at `/api/v1` with a plain `fetch` — no SDK there either.
137
165
  The original surface (unchanged):
138
166
 
139
167
  ```
168
+ rit signup [--email <you@x.com>] [--verify <code>] [--repo <name>] [--api-url <url>] [--json]
140
169
  rit init [--repo <name>] [--api-url <url>] [--json]
141
170
  rit claim --email <you@example.com> [--json]
142
171
  rit login [--token <token>] [--agent] [--paste-token] [--api-url <url>] [--json]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@recoder.xyz/rithub",
3
- "version": "0.3.5",
4
- "description": "A gh-style CLI for Rithub: full gh parity -- issue/change(pr)/release/branch/label/milestone/key/secret/webhook/org/user/search/status/browse/api, plus login/clone/repo/push and `rit init`'s no-human agent signup. One command, zero deps.",
3
+ "version": "0.4.0",
4
+ "description": "A gh-style CLI for Rithub: full gh parity -- issue/change(pr)/release/branch/label/milestone/key/secret/webhook/org/user/search/status/browse/api, plus login/clone/repo/push and `rit signup`'s no-browser, no-CAPTCHA account creation (zero-human device flow, or an email-verified one-time code). One command, zero deps.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "engines": { "node": ">=18" },
package/src/cli.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { runInit, runClaim, CliError, DEFAULT_API_URL } from "./init.mjs";
2
+ import { runSignup } from "./signup.mjs";
2
3
  import { runLogin, runLogout, runWhoami } from "./auth.mjs";
3
4
  import { runClone, runRepoCreate, runPush } from "./repo.mjs";
4
5
  import { runWorkCommand, runRepoWorkCommand } from "./cli-work.mjs";
@@ -7,6 +8,14 @@ import { runExport } from "./export.mjs";
7
8
 
8
9
  const USAGE = `rit <command> [options] (alias: rithub)
9
10
 
11
+ signup no browser, no CAPTCHA, ever. Bare: same
12
+ as \`init\` below (zero-human, a proof-
13
+ of-work challenge, no email). With
14
+ --email <you@x.com>: mails a one-time
15
+ code (no account yet). With --verify
16
+ <code>: completes that email, mints a
17
+ real account bound to it, no \`claim\`
18
+ step needed afterward.
10
19
  init no account needed -- provisions a Rithub
11
20
  account, token and first repo, points
12
21
  this directory's git remote at it
@@ -124,6 +133,26 @@ export async function main(argv, io) {
124
133
  return 0;
125
134
  }
126
135
 
136
+ if (command === "signup") {
137
+ const args = parseFlags(rest, { valueFlags: ["--repo", "--email", "--verify", "--api-url"], boolFlags: ["--json"] });
138
+ const { kind, result } = await runSignup({ repoName: args.repo, email: args.email, code: args.verify, apiUrl: args.apiUrl ?? io.env.RITHUB_API_URL ?? DEFAULT_API_URL, cwd: io.cwd }, io);
139
+ if (args.json) {
140
+ io.out(JSON.stringify(result));
141
+ } else if (kind === "email-start") {
142
+ io.out(`Code sent to ${result.email} -- check your inbox, then run: rit signup --verify <code>`);
143
+ } else if (kind === "verify") {
144
+ io.out(`Live in ${result.solved_in_seconds ?? "?"}s: ${result.username} (${result.email}) -> ${result.html_url}`);
145
+ io.out(`git remote 'origin' set to ${result.repo}. Next: git add -A && git commit -m "first commit" && git push -u origin ${result.branch ?? "main"}`);
146
+ } else {
147
+ io.out(result.reused ? `Reusing ${result.username}/${result.repo?.split("/")?.[1] ?? "first-repo"} (from ${".rithub/agent.json"}).` : `Live in ${result.solved_in_seconds ?? "?"}s: ${result.username} -> ${result.html_url}`);
148
+ io.out(`git remote 'origin' set to ${result.repo}. Next: git add -A && git commit -m "first commit" && git push -u origin ${result.branch ?? "main"}`);
149
+ if (!result.reused) {
150
+ io.out(`Unclaimed: a small repo quota applies. Keep this account: rithub claim --email you@example.com (or next time, \`rit signup --email you@x.com\`)`);
151
+ }
152
+ }
153
+ return 0;
154
+ }
155
+
127
156
  if (command === "init") {
128
157
  const args = parseFlags(rest, { valueFlags: ["--repo", "--api-url"], boolFlags: ["--json"] });
129
158
  const result = await runInit({ repoName: args.repo, apiUrl: args.apiUrl ?? io.env.RITHUB_API_URL ?? DEFAULT_API_URL, cwd: io.cwd }, io);
package/src/init.mjs CHANGED
@@ -8,7 +8,7 @@ import { solveChallenge } from "./pow.mjs";
8
8
 
9
9
  export const DEFAULT_API_URL = "https://rithub.dev";
10
10
  const STATE_DIR = ".rithub";
11
- const STATE_FILE = `${STATE_DIR}/agent.json`;
11
+ export const STATE_FILE = `${STATE_DIR}/agent.json`;
12
12
 
13
13
  export class CliError extends Error {
14
14
  constructor(message, { code = "error" } = {}) {
@@ -17,11 +17,14 @@ export class CliError extends Error {
17
17
  }
18
18
  }
19
19
 
20
- function join(root, relative) {
20
+ export function join(root, relative) {
21
21
  return `${root.replace(/\/+$/, "")}/${relative}`;
22
22
  }
23
23
 
24
- async function callJson(io, baseUrl, path, init) {
24
+ /** Shared by `rit init`/`rit signup` (this file) and `rit signup --email`/`--verify`
25
+ * (src/signup.mjs) -- one small JSON-fetch helper so both paths talk to the
26
+ * same `/agent-signup*` family of routes the same way. */
27
+ export async function callJson(io, baseUrl, path, init) {
25
28
  const res = await io.fetchImpl(`${baseUrl}${path}`, {
26
29
  ...init,
27
30
  headers: { accept: "application/json", "user-agent": "rithub-cli", ...(init?.body ? { "content-type": "application/json" } : {}), ...(init?.headers ?? {}) },
@@ -36,7 +39,7 @@ async function callJson(io, baseUrl, path, init) {
36
39
  return { status: res.status, body };
37
40
  }
38
41
 
39
- function readState(io, cwd) {
42
+ export function readState(io, cwd) {
40
43
  const text = io.readFile(join(cwd, STATE_FILE));
41
44
  if (!text) return null;
42
45
  try {
@@ -47,7 +50,7 @@ function readState(io, cwd) {
47
50
  }
48
51
  }
49
52
 
50
- function ensureGitignored(io, cwd) {
53
+ export function ensureGitignored(io, cwd) {
51
54
  const path = join(cwd, ".gitignore");
52
55
  const current = io.readFile(path) ?? "";
53
56
  if (current.split("\n").some((line) => line.trim() === STATE_DIR || line.trim() === `${STATE_DIR}/`)) return;
package/src/signup.mjs ADDED
@@ -0,0 +1,100 @@
1
+ // `rit signup` -- the agent/CI-facing front door, no browser, no CAPTCHA,
2
+ // ever. Two shapes, same end state (a real account + a repo-scoped token
3
+ // stored in `.rithub/agent.json`, exactly like `rit init` writes today):
4
+ //
5
+ // rit signup -- bare, zero-human: delegates straight
6
+ // to `runInit` (proof-of-work challenge,
7
+ // see pow.mjs/agentSignup.mjs). The
8
+ // right default for a CI runner or an
9
+ // agent with no mailbox to check.
10
+ // rit signup --email you@x.com -- for a caller that DOES have a real
11
+ // mailbox (a human on a headless
12
+ // session, or an agent acting on a
13
+ // team's behalf): a one-time code is
14
+ // mailed via the server's existing
15
+ // mailer (apps/rithub-mcp/src/mailer.mjs),
16
+ // no browser step either.
17
+ // rit signup --verify <code> -- completes the email path: reads the
18
+ // email cached by the --email call
19
+ // (.rithub/pending-signup.json) so the
20
+ // caller doesn't have to repeat it,
21
+ // mints the token, writes agent.json.
22
+ //
23
+ // Why not a browser device-code flow (the other shape `rit login` already
24
+ // uses for *existing* accounts, see rithub-device-auth)? That flow's
25
+ // consent screen is the engine's own real /user/login + the signup
26
+ // equivalent sits behind Cloudflare Turnstile (apps/rithub-server/custom/
27
+ // templates/user/auth/captcha.tmpl) -- reintroducing a browser here would
28
+ // reintroduce the one thing an agent can't do. The proof-of-work and
29
+ // email-code paths both stay server-API-only, so neither ever touches
30
+ // that captcha.
31
+ import { CliError, DEFAULT_API_URL, callJson, join, readState, ensureGitignored, STATE_FILE, setGitRemote, currentBranch, runInit } from "./init.mjs";
32
+
33
+ const PENDING_FILE = ".rithub/pending-signup.json";
34
+
35
+ function readPending(io, cwd) {
36
+ const text = io.readFile(join(cwd, PENDING_FILE));
37
+ if (!text) return null;
38
+ try {
39
+ const value = JSON.parse(text);
40
+ return value?.email ? value : null;
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
46
+ /** `rit signup --email you@x.com`: asks the server to mail a one-time code. No account exists yet. */
47
+ export async function runSignupEmailStart(options, io) {
48
+ const cwd = options.cwd ?? io.cwd;
49
+ const baseUrl = (options.apiUrl ?? io.env.RITHUB_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, "");
50
+ const existing = readState(io, cwd);
51
+ if (existing) {
52
+ throw new CliError(`this directory is already signed up as ${existing.username} -- run \`rit whoami\`/\`rit logout\`, or run \`rit signup\` from a different directory.`, { code: "already_signed_up" });
53
+ }
54
+ const call = await callJson(io, baseUrl, "/agent-signup/email/start", {
55
+ method: "POST",
56
+ body: JSON.stringify({ email: options.email }),
57
+ });
58
+ if (call.status !== 202) {
59
+ throw new CliError(`could not send a code to ${options.email} (HTTP ${call.status}): ${call.body?.error ?? "unknown error"}`, { code: "email_start_failed" });
60
+ }
61
+ io.writeFile(join(cwd, PENDING_FILE), `${JSON.stringify({ email: options.email, api_url: baseUrl, repo_name: options.repoName ?? null }, null, 2)}\n`);
62
+ ensureGitignored(io, cwd);
63
+ return { email: options.email, expires_in_seconds: call.body?.expires_in_seconds ?? 600 };
64
+ }
65
+
66
+ /** `rit signup --verify <code>`: completes a pending `--email` signup -- real account, real email, no placeholder, no later `rit claim` needed. */
67
+ export async function runSignupVerify(options, io) {
68
+ const cwd = options.cwd ?? io.cwd;
69
+ const pending = readPending(io, cwd);
70
+ const email = options.email ?? pending?.email;
71
+ if (!email) {
72
+ throw new CliError("no pending signup here -- run `rit signup --email you@x.com` first (or pass --email again with --verify).", { code: "no_pending_signup" });
73
+ }
74
+ const baseUrl = (options.apiUrl ?? pending?.api_url ?? io.env.RITHUB_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, "");
75
+ const startedAt = (io.now ?? Date.now)();
76
+
77
+ const call = await callJson(io, baseUrl, "/agent-signup/email/verify", {
78
+ method: "POST",
79
+ body: JSON.stringify({ email, code: options.code, repo_name: options.repoName ?? pending?.repo_name ?? (cwd.split("/").pop() || "first-repo") }),
80
+ });
81
+ if (call.status !== 201) {
82
+ throw new CliError(`verification failed (HTTP ${call.status}): ${call.body?.error ?? "unknown error"}`, { code: "verify_failed" });
83
+ }
84
+ const account = call.body;
85
+ const liveInSeconds = Math.max(0, Math.round(((io.now ?? Date.now)() - startedAt) / 100) / 10);
86
+
87
+ io.writeFile(join(cwd, STATE_FILE), `${JSON.stringify({ ...account, api_url: baseUrl }, null, 2)}\n`);
88
+ ensureGitignored(io, cwd);
89
+ setGitRemote(io, cwd, account.git_remote);
90
+ io.unlink?.(join(cwd, PENDING_FILE));
91
+
92
+ return { ...account, api_url: baseUrl, reused: false, solved_in_seconds: liveInSeconds, branch: currentBranch(io, cwd) };
93
+ }
94
+
95
+ /** Entry point for `rit signup`: routes to the three shapes above based on which flags were passed. */
96
+ export async function runSignup(options, io) {
97
+ if (options.code) return { kind: "verify", result: await runSignupVerify(options, io) };
98
+ if (options.email) return { kind: "email-start", result: await runSignupEmailStart(options, io) };
99
+ return { kind: "device", result: await runInit(options, io) };
100
+ }