@recoder.xyz/rithub 0.1.0 → 0.1.1

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
@@ -1,15 +1,20 @@
1
- # rithub
1
+ # @recoder.xyz/rithub
2
2
 
3
3
  ```
4
- npx rithub init
4
+ npx @recoder.xyz/rithub init
5
5
  ```
6
6
 
7
+ (npm refuses the bare name `rithub` outright — "too similar to existing
8
+ package github" — so the published package is scoped; the CLI itself is
9
+ still the `rithub` command, e.g. after `npm install -g
10
+ @recoder.xyz/rithub` it's just `rithub init`.)
11
+
7
12
  No account, no sign-in, no human. One command gives an AI coding agent (or
8
13
  a person) a real [Rithub](https://rithub.dev) account, an access token
9
14
  scoped to one repo, and a first repo — then `git push` works.
10
15
 
11
16
  ```
12
- $ npx rithub init
17
+ $ npx @recoder.xyz/rithub init
13
18
  Live in 0.9s: agent-lwlvjdtj -> https://rithub.dev/agent-lwlvjdtj/first-repo
14
19
  git remote 'origin' set to agent-lwlvjdtj/first-repo. Next: git add -A && git commit -m "first commit" && git push -u origin main
15
20
  Unclaimed: a small repo quota applies. Keep this account: rithub claim --email you@example.com
@@ -21,7 +26,7 @@ Re-running `rithub init` in the same directory reuses the account from
21
26
  A small repo quota applies until a human claims the account:
22
27
 
23
28
  ```
24
- npx rithub claim --email you@example.com
29
+ npx @recoder.xyz/rithub claim --email you@example.com
25
30
  ```
26
31
 
27
32
  This sets the account's real email and lifts the quota. Afterward, open
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recoder.xyz/rithub",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "npx rithub init: an AI agent gets a real Rithub account, an access token and a first repo with no human, then git push works. One command.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/cli.mjs CHANGED
@@ -34,7 +34,7 @@ export async function main(argv, io) {
34
34
  io.out(JSON.stringify(result));
35
35
  } else {
36
36
  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}`);
37
- io.out(`git remote 'origin' set to ${result.repo}. Next: git add -A && git commit -m "first commit" && git push -u origin main`);
37
+ 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"}`);
38
38
  if (!result.reused) {
39
39
  io.out(`Unclaimed: a small repo quota applies. Keep this account: rithub claim --email you@example.com`);
40
40
  }
package/src/init.mjs CHANGED
@@ -60,6 +60,11 @@ function setGitRemote(io, cwd, gitRemote) {
60
60
  if (!inGitRepo) {
61
61
  const init = io.run("git", ["init"], cwd);
62
62
  if (!init.ok) throw new CliError(`git init failed: ${init.output.slice(-400)}`, { code: "git_failed" });
63
+ // Normalize a freshly-created repo to `main` regardless of this machine's
64
+ // `git init.defaultBranch` (plenty of installs still default to `master`,
65
+ // which breaks the push instruction we print below). Safe pre-first-commit:
66
+ // rewrites the symbolic ref, not an existing branch object.
67
+ io.run("git", ["symbolic-ref", "HEAD", "refs/heads/main"], cwd);
63
68
  }
64
69
  const remotes = io.run("git", ["remote"], cwd);
65
70
  const hasOrigin = remotes.ok && remotes.output.split("\n").map((l) => l.trim()).includes("origin");
@@ -67,6 +72,16 @@ function setGitRemote(io, cwd, gitRemote) {
67
72
  if (!result.ok) throw new CliError(`could not set the git remote: ${result.output.slice(-400)}`, { code: "git_failed" });
68
73
  }
69
74
 
75
+ /** The real current branch name, so printed instructions never claim `main`
76
+ * when this directory's git (pre-existing or just-initialized on an old git
77
+ * that ignored symbolic-ref) is actually on something else. Falls back to
78
+ * `main` only if git itself can't answer (e.g. no git on PATH). */
79
+ function currentBranch(io, cwd) {
80
+ const result = io.run("git", ["branch", "--show-current"], cwd);
81
+ const name = result.ok ? result.output.trim() : "";
82
+ return name || "main";
83
+ }
84
+
70
85
  /** `rithub init`: provisions (or reuses) an agent account and points this directory's git remote at its first repo. */
71
86
  export async function runInit(options, io) {
72
87
  const cwd = options.cwd ?? io.cwd;
@@ -75,7 +90,7 @@ export async function runInit(options, io) {
75
90
 
76
91
  if (existing) {
77
92
  setGitRemote(io, cwd, existing.git_remote);
78
- return { ...existing, reused: true };
93
+ return { ...existing, reused: true, branch: currentBranch(io, cwd) };
79
94
  }
80
95
 
81
96
  const challengeCall = await callJson(io, baseUrl, "/agent-signup/challenge", { method: "GET" });
@@ -100,7 +115,7 @@ export async function runInit(options, io) {
100
115
  ensureGitignored(io, cwd);
101
116
  setGitRemote(io, cwd, account.git_remote);
102
117
 
103
- return { ...account, api_url: baseUrl, reused: false, solved_in_seconds: liveInSeconds };
118
+ return { ...account, api_url: baseUrl, reused: false, solved_in_seconds: liveInSeconds, branch: currentBranch(io, cwd) };
104
119
  }
105
120
 
106
121
  /** `rithub claim --email you@example.com`: hands a human account ownership of this directory's agent account (see agentSignup.mjs's claimAgent). */