Skip to content

Commit 426133d

Browse files
committed
feat: status shows Current Project; bind profile per GitHub origin
Drop Source from human status; show Host and Current Project as github.com/owner/repo. Login binds that origin to the profile so parallel Cursor windows can stay on different orgs.
1 parent 5c85083 commit 426133d

7 files changed

Lines changed: 176 additions & 21 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ See [packaging/README.md](packaging/README.md) for apt, dnf, Scoop, and winget.
2727

2828
```bash
2929
autodevelop login # prompts for repo dir (default: git root / cwd)
30-
autodevelop login --dir /path/to/repo --no-open
31-
autodevelop status
30+
autodevelop login --dir /path/to/repo --profile acme --no-open
31+
autodevelop status # Profile / Host / Current Project (github.com/owner/repo)
32+
autodevelop profiles
3233
autodevelop install --slug <instance>
3334
autodevelop mcp # host stdio shim (loopback)
3435
autodevelop kit-mcp # kit tools stdio
3536
autodevelop hook guard-shell # editor hook
3637
```
3738

39+
Multiple orgs: `login --profile <name>` stores another credential. Login also binds the repo’s GitHub origin (`github.com/owner/repo`) to that profile, so another Cursor window in a different repo picks its org from cwd without fighting a single global active profile. Override with `AUTODEVELOP_PROFILE` or `--profile` when needed.
40+
3841
## Develop
3942

4043
```bash

‎internal/cli/root.go‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Autodevelop CLI
3434
3535
AUTODEVELOP_TOKEN wins over the credentials file when set.
3636
AUTODEVELOP_PROFILE selects a stored login for one process.
37+
Login binds the current GitHub origin (github.com/owner/repo) to that profile
38+
so other Cursor windows can stay on a different org.
3739
`) + "\n"
3840
}
3941

@@ -110,6 +112,10 @@ func Run(argv []string) int {
110112
fmt.Fprintln(os.Stderr, err)
111113
return 1
112114
}
115+
active, _ := credentials.ResolveProfileName(env, profile, "")
116+
if project := repo.GitHubProject(root); project != "" && active != "" {
117+
_ = credentials.BindProject(creds, project, active)
118+
}
113119
if !hasFlag(args, "no-install") {
114120
if err := install.Run(install.Options{
115121
Env: env,
@@ -142,15 +148,18 @@ func Run(argv []string) int {
142148
return 0
143149
case "status":
144150
root, _ := repo.Resolve(dirFlag, "", false, nil, nil)
145-
stored := credentials.ReadFile(creds, env, profile)
146-
src := credentials.TokenSource(env, creds, profile)
147-
origin := credentials.ResolveHost(env, hostFlag, creds, profile)
151+
project := repo.GitHubProject(root)
152+
active, _ := credentials.ResolveEffectiveProfile(env, profile, creds, project)
153+
stored := credentials.ReadFile(creds, env, active)
154+
src := credentials.TokenSource(env, creds, active)
155+
origin := credentials.ResolveHost(env, hostFlag, creds, active)
148156
out := map[string]any{
149157
"signed_in": src != "",
150-
"source": src,
151158
"host": origin,
159+
"project": project,
152160
"root": root,
153161
"version": version.Version,
162+
"profile": active,
154163
}
155164
if stored != nil {
156165
if stored.IssuedAt != nil {
@@ -160,8 +169,6 @@ func Run(argv []string) int {
160169
out["org_id"] = *stored.OrgID
161170
}
162171
}
163-
active, _ := credentials.ResolveProfileName(env, profile, credentials.ReadStore(creds).Active)
164-
out["profile"] = active
165172
if hasFlag(args, "json") {
166173
enc, _ := json.MarshalIndent(out, "", " ")
167174
fmt.Println(string(enc))
@@ -173,9 +180,12 @@ func Run(argv []string) int {
173180
}
174181
fmt.Println("Signed in.")
175182
fmt.Println("Profile:", active)
176-
fmt.Println("Source:", src)
177183
fmt.Println("Host:", origin)
178-
fmt.Println("Root:", root)
184+
if project != "" {
185+
fmt.Println("Current Project:", project)
186+
} else if root != "" {
187+
fmt.Println("Current Project:", root)
188+
}
179189
return 0
180190
case "profiles", "profile":
181191
for _, p := range credentials.ListSummaries(creds, env) {

‎internal/credentials/credentials.go‎

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type Entry struct {
3333
type Store struct {
3434
Active string `json:"active"`
3535
Profiles map[string]*Entry `json:"profiles"`
36+
// Projects maps github.com/owner/repo → profile so parallel workspaces
37+
// (different Cursor windows) keep their org without fighting Active.
38+
Projects map[string]string `json:"projects,omitempty"`
3639
}
3740

3841
func DefaultPath(env map[string]string) string {
@@ -83,6 +86,61 @@ func ResolveProfileName(env map[string]string, profile, active string) (string,
8386
return DefaultProfile, nil
8487
}
8588

89+
// ResolveEffectiveProfile prefers --profile / AUTODEVELOP_PROFILE, then a
90+
// project binding (github.com/owner/repo), then the store active profile.
91+
// Parallel Cursor windows can each login under a different profile; cwd's
92+
// origin remote selects the right org without mutating global Active alone.
93+
func ResolveEffectiveProfile(env map[string]string, profileFlag, path, project string) (string, error) {
94+
if env == nil {
95+
env = map[string]string{}
96+
}
97+
if v := strings.TrimSpace(profileFlag); v != "" {
98+
return AssertProfileName(v)
99+
}
100+
if v := strings.TrimSpace(env["AUTODEVELOP_PROFILE"]); v != "" {
101+
return AssertProfileName(v)
102+
}
103+
if b := BoundProfile(path, project); b != "" {
104+
return AssertProfileName(b)
105+
}
106+
store := ReadStore(path)
107+
if v := strings.TrimSpace(store.Active); v != "" {
108+
return AssertProfileName(v)
109+
}
110+
return DefaultProfile, nil
111+
}
112+
113+
// BoundProfile returns the profile bound to github.com/owner/repo, or "".
114+
func BoundProfile(path, project string) string {
115+
project = strings.TrimSpace(project)
116+
if project == "" {
117+
return ""
118+
}
119+
store := ReadStore(path)
120+
if store.Projects == nil {
121+
return ""
122+
}
123+
return strings.TrimSpace(store.Projects[project])
124+
}
125+
126+
// BindProject records github.com/owner/repo → profile for cwd-scoped login.
127+
func BindProject(path, project, profile string) error {
128+
project = strings.TrimSpace(project)
129+
if project == "" {
130+
return nil
131+
}
132+
name, err := AssertProfileName(profile)
133+
if err != nil {
134+
return err
135+
}
136+
store := ReadStore(path)
137+
if store.Projects == nil {
138+
store.Projects = map[string]string{}
139+
}
140+
store.Projects[project] = name
141+
return writeStore(path, store)
142+
}
143+
86144
func ReadStore(path string) Store {
87145
empty := Store{Active: DefaultProfile, Profiles: map[string]*Entry{}}
88146
raw, err := os.ReadFile(path)
@@ -104,7 +162,15 @@ func ReadStore(path string) Store {
104162
if strings.TrimSpace(active) == "" {
105163
active = DefaultProfile
106164
}
107-
return Store{Active: active, Profiles: profiles}
165+
projects := map[string]string{}
166+
if projectsRaw, ok := data["projects"].(map[string]any); ok {
167+
for k, v := range projectsRaw {
168+
if s, ok := v.(string); ok && strings.TrimSpace(s) != "" {
169+
projects[strings.TrimSpace(k)] = strings.TrimSpace(s)
170+
}
171+
}
172+
}
173+
return Store{Active: active, Profiles: profiles, Projects: projects}
108174
}
109175
if e := normalizeEntry(data); e != nil {
110176
return Store{Active: DefaultProfile, Profiles: map[string]*Entry{DefaultProfile: e}}

‎internal/credentials/credentials_test.go‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,32 @@ func TestWriteReadProfile(t *testing.T) {
3434
}
3535
}
3636

37-
func TestResolveHostFallsBackToActive(t *testing.T) {
37+
func TestBindProjectSelectsProfile(t *testing.T) {
3838
dir := t.TempDir()
3939
path := filepath.Join(dir, "credentials.json")
4040
env := map[string]string{}
41-
host := "https://example.test"
41+
hostA := "https://a.test"
42+
hostB := "https://b.test"
4243
issued := "2026-09-28T00:00:00Z"
43-
_ = credentials.WriteFile(path, "ad_a", nil, &issued, &host, "default", env)
44-
got := credentials.ResolveHost(env, "", path, "newprofile")
45-
// new profile has no entry — should still use flag/env/default, not leap incorrectly when active has host
46-
// With empty flag and no AUTODEVELOP_HOST, active profile host is used via ResolveHost logic when profile miss
47-
if got == "" {
48-
t.Fatal("empty host")
44+
_ = credentials.WriteFile(path, "ad_a", nil, &issued, &hostA, "acme", env)
45+
_ = credentials.WriteFile(path, "ad_b", nil, &issued, &hostB, "devrecated", env)
46+
if err := credentials.BindProject(path, "github.com/acme/app", "acme"); err != nil {
47+
t.Fatal(err)
48+
}
49+
if err := credentials.BindProject(path, "github.com/devrecated/autodevelop", "devrecated"); err != nil {
50+
t.Fatal(err)
51+
}
52+
got, err := credentials.ResolveEffectiveProfile(env, "", path, "github.com/acme/app")
53+
if err != nil || got != "acme" {
54+
t.Fatalf("acme project → %q (%v)", got, err)
55+
}
56+
got, err = credentials.ResolveEffectiveProfile(env, "", path, "github.com/devrecated/autodevelop")
57+
if err != nil || got != "devrecated" {
58+
t.Fatalf("devrecated project → %q (%v)", got, err)
59+
}
60+
env["AUTODEVELOP_PROFILE"] = "acme"
61+
got, err = credentials.ResolveEffectiveProfile(env, "", path, "github.com/devrecated/autodevelop")
62+
if err != nil || got != "acme" {
63+
t.Fatalf("env override → %q (%v)", got, err)
4964
}
5065
}

‎internal/mcphost/mcphost.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/devrecated/autodevelop-cli/internal/credentials"
1616
"github.com/devrecated/autodevelop-cli/internal/host"
17+
"github.com/devrecated/autodevelop-cli/internal/repo"
1718
)
1819

1920
func rpcError(id any, message string) map[string]any {
@@ -88,7 +89,9 @@ func Run(opts Options) error {
8889
if path == "" {
8990
path = credentials.DefaultPath(opts.Env)
9091
}
91-
stored := credentials.ReadFile(path, opts.Env, "")
92+
project := repo.GitHubProject(repo.FindRoot(""))
93+
profile, _ := credentials.ResolveEffectiveProfile(opts.Env, "", path, project)
94+
stored := credentials.ReadFile(path, opts.Env, profile)
9295
var storedHost string
9396
if stored != nil && stored.Host != nil {
9497
storedHost = *stored.Host
@@ -113,7 +116,7 @@ func Run(opts Options) error {
113116
if message["id"] == nil {
114117
continue
115118
}
116-
credential := credentials.ReadToken(opts.Env, path, "")
119+
credential := credentials.ReadToken(opts.Env, path, profile)
117120
reply, err := Post(opts.Client, origin, credential, message)
118121
if err != nil {
119122
return err

‎internal/repo/repo.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ import (
77
"os"
88
"os/exec"
99
"path/filepath"
10+
"regexp"
1011
"strings"
1112
)
1213

14+
var (
15+
githubSSHRE = regexp.MustCompile(`(?i)^(?:ssh://)?git@github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?/?$`)
16+
githubHTTPRE = regexp.MustCompile(`(?i)^https?://(?:www\.)?github\.com/([^/]+)/([^/]+?)(?:\.git)?/?$`)
17+
)
18+
1319
// FindRoot returns git toplevel from start, else start.
1420
func FindRoot(start string) string {
1521
start = filepath.Clean(start)
@@ -29,6 +35,35 @@ func FindRoot(start string) string {
2935
return top
3036
}
3137

38+
// NormalizeGitHubRemote turns a git remote URL into "github.com/owner/repo", or "".
39+
func NormalizeGitHubRemote(remote string) string {
40+
remote = strings.TrimSpace(remote)
41+
if remote == "" {
42+
return ""
43+
}
44+
if m := githubSSHRE.FindStringSubmatch(remote); len(m) == 3 {
45+
return "github.com/" + m[1] + "/" + strings.TrimSuffix(m[2], ".git")
46+
}
47+
if m := githubHTTPRE.FindStringSubmatch(remote); len(m) == 3 {
48+
return "github.com/" + m[1] + "/" + strings.TrimSuffix(m[2], ".git")
49+
}
50+
return ""
51+
}
52+
53+
// GitHubProject returns github.com/owner/repo for origin in root, or "".
54+
func GitHubProject(root string) string {
55+
if root == "" {
56+
root, _ = os.Getwd()
57+
}
58+
cmd := exec.Command("git", "remote", "get-url", "origin")
59+
cmd.Dir = root
60+
out, err := cmd.Output()
61+
if err != nil {
62+
return ""
63+
}
64+
return NormalizeGitHubRemote(strings.TrimSpace(string(out)))
65+
}
66+
3267
// Resolve picks --dir, else prompts on TTY with default = FindRoot(cwd), else that default.
3368
func Resolve(dirFlag, cwd string, interactive bool, stdin *os.File, stdout *os.File) (string, error) {
3469
if cwd == "" {

‎internal/repo/repo_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2026 Devrecated.
2+
package repo
3+
4+
import "testing"
5+
6+
func TestNormalizeGitHubRemote(t *testing.T) {
7+
cases := []struct {
8+
in, want string
9+
}{
10+
{"git@github.com:devrecated/autodevelop.git", "github.com/devrecated/autodevelop"},
11+
{"git@github.com:devrecated/autodevelop", "github.com/devrecated/autodevelop"},
12+
{"https://github.com/devrecated/autodevelop.git", "github.com/devrecated/autodevelop"},
13+
{"https://github.com/devrecated/autodevelop", "github.com/devrecated/autodevelop"},
14+
{"ssh://git@github.com/devrecated/autodevelop.git", "github.com/devrecated/autodevelop"},
15+
{"https://gitlab.com/foo/bar.git", ""},
16+
{"", ""},
17+
}
18+
for _, c := range cases {
19+
if got := NormalizeGitHubRemote(c.in); got != c.want {
20+
t.Errorf("NormalizeGitHubRemote(%q) = %q, want %q", c.in, got, c.want)
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)