Skip to content

Commit 225477d

Browse files
committed
feat: add efctl usage instructions to AGENTS.md and implement --ai flag for init
1 parent 37fbffb commit 225477d

5 files changed

Lines changed: 130 additions & 2 deletions

File tree

.agents/instructions.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- EFCTL_INSTRUCTIONS_START -->
2+
# efctl Context
3+
You are working on a project using 'efctl', the EVE Frontier CLI.
4+
Reference AGENTS.md for core principles.
5+
6+
## efctl Commands
7+
- Init: efctl init
8+
- Up: efctl env up
9+
- Down: efctl env down
10+
- Status: efctl env status
11+
- Publish Extension: efctl env extension publish [path]
12+
- Query World: efctl world query [object_id]
13+
<!-- EFCTL_INSTRUCTIONS_END -->
14+
Extra text

AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ To maintain a non-breaking flow and avoid permission requests:
4646
- Keep terminal usage limited to short operational commands such as `git`, `mkdir`, `rm`, `mv`, `cd`, `ls`, and install commands.
4747
- Keep responses concise and write substantial artifacts to files instead of long inline output.
4848
- Utility commands: `ctx stats`, `ctx doctor`, `ctx upgrade`.
49+
50+
## 8. Development Cheat Sheet
51+
52+
Quick reference for common `efctl` operations:
53+
54+
- **Initialize configuration**: `efctl init` (or `efctl init --ai [agent]`)
55+
- **Environment Lifecycle**:
56+
- Up: `efctl env up`
57+
- Down: `efctl env down`
58+
- **Status Check**: `efctl env status`
59+
- **Deploy Extension**: `efctl env extension publish [contract-path]` (path defaults to `./my-extension`)
60+
- **Query World**: `efctl world query [object_id]` (queries the Sui GraphQL RPC)

cmd/init.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88
"path/filepath"
99
"strings"
1010

11+
"efctl/pkg/builder"
1112
"efctl/pkg/config"
1213
"efctl/pkg/ui"
1314
"github.com/spf13/cobra"
1415
)
1516

1617
var initForce bool
18+
var initAiAgent string
1719

1820
var initCmd = &cobra.Command{
1921
Use: "init",
@@ -74,6 +76,15 @@ var initCmd = &cobra.Command{
7476
ui.Success.Println("Created example extension directory")
7577
}
7678

79+
// 4. AI Instructions
80+
if initAiAgent != "" {
81+
if err := builder.SetupAIInstructions(initAiAgent, targetDir); err != nil {
82+
ui.Warn.Printf("Failed to setup AI instructions: %v\n", err)
83+
} else {
84+
ui.Success.Printf("Setup AI instructions for %s\n", initAiAgent)
85+
}
86+
}
87+
7788
return nil
7889
},
7990
}
@@ -137,5 +148,6 @@ func readGitignore(path string) (map[string]bool, error) {
137148

138149
func init() {
139150
initCmd.Flags().BoolVar(&initForce, "force", false, "Overwrite an existing config file")
151+
initCmd.Flags().StringVar(&initAiAgent, "ai", "", "Setup AI instructions for a specific agent (copilot, claude, gemini)")
140152
rootCmd.AddCommand(initCmd)
141153
}

docs/efctl_init.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ efctl init [flags]
1313
### Options
1414

1515
```
16-
--force Overwrite an existing config file
17-
-h, --help help for init
16+
--ai string Setup AI instructions for a specific agent (copilot, claude, gemini)
17+
--force Overwrite an existing config file
18+
-h, --help help for init
1819
```
1920

2021
### Options inherited from parent commands

pkg/builder/ai.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package builder
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
)
9+
10+
const (
11+
MarkerStart = "<!-- EFCTL_INSTRUCTIONS_START -->"
12+
MarkerEnd = "<!-- EFCTL_INSTRUCTIONS_END -->"
13+
)
14+
15+
// SetupAIInstructions configures instructions for various AI agents idempotently.
16+
func SetupAIInstructions(agentName string, workspace string) error {
17+
var targetFile string
18+
var instructions string
19+
20+
agentName = strings.ToLower(agentName)
21+
22+
switch agentName {
23+
case "copilot", "cursor":
24+
targetFile = ".cursorrules"
25+
instructions = getCopilotInstructions()
26+
case "claude":
27+
targetFile = ".clauderules"
28+
instructions = getClaudeInstructions()
29+
case "gemini":
30+
targetFile = filepath.Join(".agents", "instructions.md")
31+
instructions = getGeminiInstructions()
32+
default:
33+
return fmt.Errorf("unsupported agent: %s; supported agents are: copilot, claude, gemini", agentName)
34+
}
35+
36+
absPath := filepath.Join(workspace, targetFile)
37+
targetDir := filepath.Dir(absPath)
38+
if err := os.MkdirAll(targetDir, 0750); err != nil {
39+
return fmt.Errorf("failed to create directory for %s: %w", targetFile, err)
40+
}
41+
42+
content := fmt.Sprintf("\n%s\n%s\n%s\n", MarkerStart, strings.TrimSpace(instructions), MarkerEnd)
43+
44+
existing, err := os.ReadFile(absPath) // #nosec G304
45+
if err != nil {
46+
if os.IsNotExist(err) {
47+
return os.WriteFile(absPath, []byte(strings.TrimSpace(content)+"\n"), 0600) // #nosec G306 G703
48+
}
49+
return err
50+
}
51+
52+
existingStr := string(existing)
53+
startIdx := strings.Index(existingStr, MarkerStart)
54+
endIdx := strings.Index(existingStr, MarkerEnd)
55+
56+
if startIdx != -1 && endIdx != -1 && endIdx > startIdx {
57+
// Replace existing block
58+
newContent := existingStr[:startIdx] + strings.TrimSpace(content) + existingStr[endIdx+len(MarkerEnd):]
59+
return os.WriteFile(absPath, []byte(newContent), 0600) // #nosec G306 G703
60+
}
61+
62+
// Append to file
63+
newContent := strings.TrimRight(existingStr, "\n") + "\n" + strings.TrimSpace(content) + "\n"
64+
return os.WriteFile(absPath, []byte(newContent), 0600) // #nosec G306 G703
65+
}
66+
67+
func getCopilotInstructions() string {
68+
return `
69+
# efctl Context
70+
You are working on a project using 'efctl', the EVE Frontier CLI.
71+
Reference AGENTS.md for core principles.
72+
73+
## efctl Commands
74+
- Init: efctl init
75+
- Up: efctl env up
76+
- Down: efctl env down
77+
- Status: efctl env status
78+
- Publish Extension: efctl env extension publish [contract-path]
79+
- Query World: efctl world query [object_id]
80+
`
81+
}
82+
83+
func getClaudeInstructions() string {
84+
return getCopilotInstructions()
85+
}
86+
87+
func getGeminiInstructions() string {
88+
return getCopilotInstructions()
89+
}

0 commit comments

Comments
 (0)