Skip to content

Commit 04f8e6a

Browse files
committed
fix(rtk): auto-index antigravity rules per project, decoupled from codegraph
1 parent 57e9474 commit 04f8e6a

5 files changed

Lines changed: 49 additions & 10 deletions

File tree

internal/commands/index.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ func RunIndex(opts InitOptions, auto bool) int {
6767
if !looksLikeProject(dir) {
6868
return 0
6969
}
70-
if util.Exists(filepath.Join(dir, ".codegraph")) {
71-
return 0
72-
}
73-
if util.Which("codegraph") == "" {
74-
return 0
75-
}
7670
}
7771

7872
var indexable []*core.ToolManifest
@@ -99,18 +93,17 @@ func RunIndex(opts InitOptions, auto bool) int {
9993
ro := core.RunOpts{DryRun: opts.DryRun}
10094
failed := 0
10195
for _, t := range indexable {
102-
// already indexed: cheap skip, idempotent
103-
if t.ID == "codegraph" && util.Exists(filepath.Join(dir, ".codegraph")) {
96+
if t.Indexed != nil && t.Indexed(dir) {
10497
if !auto {
10598
util.L.Raw(" " + util.C.Green("✔ ") + t.Label + util.C.Gray(" already indexed"))
10699
}
107100
continue
108101
}
109-
if util.Which("codegraph") == "" && t.ID == "codegraph" {
102+
if t.IndexReady != nil && !t.IndexReady() {
110103
if !auto {
111104
util.L.Raw(" " + util.C.Gray("• ") + t.Label + util.C.Gray(" not installed — run tokless first"))
105+
failed++
112106
}
113-
failed++
114107
continue
115108
}
116109
ok, ierr := t.IndexProject(dir, ro)

internal/commands/init_integration_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,44 @@ func TestInitSandboxWiring(t *testing.T) {
151151
}
152152
}
153153

154+
// TestAutoIndexRtkIndependentOfCodegraph proves auto-index creates RTK's
155+
// antigravity rules even when codegraph already indexed the project (regression).
156+
func TestAutoIndexRtkIndependentOfCodegraph(t *testing.T) {
157+
t.Setenv("TOKLESS_TEST", "1")
158+
tempdir := t.TempDir()
159+
for _, d := range []string{".claude", filepath.Join(".config", "opencode"), ".codex", filepath.Join(".gemini", "antigravity")} {
160+
if err := os.MkdirAll(filepath.Join(tempdir, d), 0755); err != nil {
161+
t.Fatalf("mkdir %s: %v", d, err)
162+
}
163+
}
164+
util.SetHomeOverride(tempdir)
165+
t.Setenv("HOME", tempdir)
166+
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tempdir, ".config"))
167+
defer util.SetHomeOverride("")
168+
169+
proj := filepath.Join(tempdir, "proj")
170+
if err := os.MkdirAll(filepath.Join(proj, ".git"), 0755); err != nil {
171+
t.Fatalf("mkdir proj: %v", err)
172+
}
173+
if err := os.MkdirAll(filepath.Join(proj, ".codegraph"), 0755); err != nil {
174+
t.Fatalf("mkdir .codegraph: %v", err)
175+
}
176+
oldWd, _ := os.Getwd()
177+
if err := os.Chdir(proj); err != nil {
178+
t.Fatalf("chdir: %v", err)
179+
}
180+
defer os.Chdir(oldWd)
181+
182+
if code := commands.RunInit(commands.InitOptions{Agents: []string{"claude", "antigravity"}}); code != 0 {
183+
t.Fatalf("RunInit returned non-zero code: %d", code)
184+
}
185+
commands.RunIndex(commands.InitOptions{}, true)
186+
187+
if _, err := os.Stat(filepath.Join(proj, ".agents", "rules", "antigravity-rtk-rules.md")); err != nil {
188+
t.Errorf("auto-index did not write RTK antigravity rules: %v", err)
189+
}
190+
}
191+
154192
func getSHA256(path string) (string, error) {
155193
b, err := os.ReadFile(path)
156194
if err != nil {

internal/core/core.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type ToolManifest struct {
6060
UnwireFor map[string]AgentFn
6161
VerifyFor map[string]VerifyFn
6262
IndexProject func(dir string, opts RunOpts) (bool, error)
63+
Indexed func(dir string) bool
64+
IndexReady func() bool
6365
}
6466

6567
// registries are global and populated at startup by agents/tools packages.

internal/tools/codegraph.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ var codegraph = &core.ToolManifest{
198198
Channel: core.ChannelNpm,
199199
Install: codegraphEnsureInstalled,
200200
IndexProject: codegraphIndexProject,
201+
Indexed: func(dir string) bool { return util.Exists(filepath.Join(dir, ".codegraph")) },
202+
IndexReady: func() bool { return util.Which("codegraph") != "" },
201203
WireFor: map[string]core.AgentFn{
202204
"claude": codegraphWire("claude"),
203205
"opencode": codegraphWire("opencode"),

internal/tools/rtk.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ var rtk = &core.ToolManifest{
243243
r := util.Run("rtk", []string{"init", "--agent", "antigravity"}, util.RunOptions{Cwd: dir, Capture: true})
244244
return r.Code == 0, nil
245245
},
246+
Indexed: func(dir string) bool {
247+
return util.Exists(filepath.Join(dir, ".agents", "rules", "antigravity-rtk-rules.md"))
248+
},
249+
IndexReady: func() bool { return util.Which("rtk") != "" },
246250
UnwireFor: map[string]core.AgentFn{
247251
"claude": func(core.RunOpts) (bool, error) {
248252
util.Run("rtk", []string{"init", "--uninstall", "--agent", "claude"}, util.RunOptions{})

0 commit comments

Comments
 (0)