Skip to content

Commit 661fbad

Browse files
committed
feat: add identity, node, peer commands + bounty/task/cert subcommands for gitlawb parity
New commands: - gt identity new/show/export/sign — DID identity management - gt node status/trust/resolve — node info and trust scores - gt peer add/list — peer discovery New subcommands: - gt bounty approve/cancel/stats — full bounty lifecycle - gt task fail — mark tasks as failed - gt cert verify — verify ref-update certificates
1 parent 727e308 commit 661fbad

1 file changed

Lines changed: 378 additions & 0 deletions

File tree

cmd/gitant/gitlawb_parity.go

Lines changed: 378 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/GrayCodeAI/gitant-cli/internal/cli"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// gt identity — manage DID identity (like gl identity)
13+
14+
var identityCmd = &cobra.Command{
15+
Use: "identity",
16+
Short: "Manage your DID identity (like gl identity)",
17+
}
18+
19+
var identityNewCmd = &cobra.Command{
20+
Use: "new",
21+
Short: "Generate a new Ed25519 keypair and DID",
22+
Run: func(cmd *cobra.Command, args []string) {
23+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
24+
25+
client := cli.NewClient(daemonURL)
26+
var result map[string]interface{}
27+
if err := client.Post("/api/v1/identity/generate", nil, &result); err != nil {
28+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
29+
os.Exit(1)
30+
}
31+
32+
fmt.Println("Identity generated!")
33+
if did, ok := result["did"].(string); ok {
34+
fmt.Printf("DID: %s\n", did)
35+
}
36+
if path, ok := result["key_path"].(string); ok {
37+
fmt.Printf("Key saved to: %s\n", path)
38+
}
39+
},
40+
}
41+
42+
var identityShowCmd = &cobra.Command{
43+
Use: "show",
44+
Short: "Show your current DID and identity info",
45+
Run: func(cmd *cobra.Command, args []string) {
46+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
47+
48+
client := cli.NewClient(daemonURL)
49+
var result map[string]interface{}
50+
if err := client.Get("/api/v1/identity", &result); err != nil {
51+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
52+
os.Exit(1)
53+
}
54+
55+
if did, ok := result["did"].(string); ok {
56+
fmt.Println(did)
57+
}
58+
},
59+
}
60+
61+
var identityExportCmd = &cobra.Command{
62+
Use: "export",
63+
Short: "Export your DID document as JSON",
64+
Run: func(cmd *cobra.Command, args []string) {
65+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
66+
67+
client := cli.NewClient(daemonURL)
68+
var result map[string]interface{}
69+
if err := client.Get("/api/v1/identity/export", &result); err != nil {
70+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
71+
os.Exit(1)
72+
}
73+
74+
out, _ := json.MarshalIndent(result, "", " ")
75+
fmt.Println(string(out))
76+
},
77+
}
78+
79+
var identitySignCmd = &cobra.Command{
80+
Use: "sign <message>",
81+
Short: "Sign a message with your Ed25519 private key",
82+
Args: cobra.ExactArgs(1),
83+
Run: func(cmd *cobra.Command, args []string) {
84+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
85+
86+
client := cli.NewClient(daemonURL)
87+
req := map[string]string{"message": args[0]}
88+
var result map[string]interface{}
89+
if err := client.Post("/api/v1/identity/sign", req, &result); err != nil {
90+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
91+
os.Exit(1)
92+
}
93+
94+
if sig, ok := result["signature"].(string); ok {
95+
fmt.Println(sig)
96+
}
97+
},
98+
}
99+
100+
// gt node — node status and network info
101+
102+
var nodeCmd = &cobra.Command{
103+
Use: "node",
104+
Short: "Node status and network info",
105+
}
106+
107+
var nodeStatusCmd = &cobra.Command{
108+
Use: "status",
109+
Short: "Show node status and connectivity",
110+
Run: func(cmd *cobra.Command, args []string) {
111+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
112+
113+
client := cli.NewClient(daemonURL)
114+
var result map[string]interface{}
115+
if err := client.Get("/api/v1/status", &result); err != nil {
116+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
117+
os.Exit(1)
118+
}
119+
120+
out, _ := json.MarshalIndent(result, "", " ")
121+
fmt.Println(string(out))
122+
},
123+
}
124+
125+
var nodeTrustCmd = &cobra.Command{
126+
Use: "trust <did>",
127+
Short: "Show trust score and attestation details for an agent",
128+
Args: cobra.ExactArgs(1),
129+
Run: func(cmd *cobra.Command, args []string) {
130+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
131+
132+
client := cli.NewClient(daemonURL)
133+
var result map[string]interface{}
134+
if err := client.Get(fmt.Sprintf("/api/v1/agents/%s/trust", args[0]), &result); err != nil {
135+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
136+
os.Exit(1)
137+
}
138+
139+
fmt.Printf("DID:\t%s\n", args[0])
140+
fmt.Printf("Score:\t%v\n", result["score"])
141+
if attestations, ok := result["attestations"].(float64); ok {
142+
fmt.Printf("Attestations:\t%.0f\n", attestations)
143+
}
144+
if breakdown, ok := result["breakdown"].(map[string]interface{}); ok {
145+
fmt.Println("\nBreakdown:")
146+
for k, v := range breakdown {
147+
fmt.Printf(" %s:\t%v\n", k, v)
148+
}
149+
}
150+
},
151+
}
152+
153+
var nodeResolveCmd = &cobra.Command{
154+
Use: "resolve <did>",
155+
Short: "Resolve a DID to its document via the DHT",
156+
Args: cobra.ExactArgs(1),
157+
Run: func(cmd *cobra.Command, args []string) {
158+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
159+
160+
client := cli.NewClient(daemonURL)
161+
var result map[string]interface{}
162+
if err := client.Get(fmt.Sprintf("/api/v1/agents/resolve/%s", args[0]), &result); err != nil {
163+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
164+
os.Exit(1)
165+
}
166+
167+
out, _ := json.MarshalIndent(result, "", " ")
168+
fmt.Println(string(out))
169+
},
170+
}
171+
172+
// gt peer — peer discovery
173+
174+
var peerCmd = &cobra.Command{
175+
Use: "peer",
176+
Short: "Peer discovery — add and inspect known nodes",
177+
}
178+
179+
var peerListCmd = &cobra.Command{
180+
Use: "list",
181+
Short: "List known peers",
182+
Run: func(cmd *cobra.Command, args []string) {
183+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
184+
185+
client := cli.NewClient(daemonURL)
186+
var result struct {
187+
Peers []struct {
188+
ID string `json:"id"`
189+
Multiaddrs []string `json:"multiaddrs"`
190+
Connected bool `json:"connected"`
191+
} `json:"peers"`
192+
Total int `json:"total"`
193+
}
194+
if err := client.Get("/api/v1/network/peers", &result); err != nil {
195+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
196+
os.Exit(1)
197+
}
198+
199+
for _, p := range result.Peers {
200+
status := "disconnected"
201+
if p.Connected {
202+
status = "connected"
203+
}
204+
fmt.Printf("%s\t%s\t%s\n", p.ID[:12], status, p.Multiaddrs)
205+
}
206+
fmt.Fprintf(os.Stderr, "%d peer(s)\n", result.Total)
207+
},
208+
}
209+
210+
var peerAddCmd = &cobra.Command{
211+
Use: "add <multiaddr>",
212+
Short: "Add a peer by multiaddr",
213+
Args: cobra.ExactArgs(1),
214+
Run: func(cmd *cobra.Command, args []string) {
215+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
216+
217+
client := cli.NewClient(daemonURL)
218+
req := map[string]string{"multiaddr": args[0]}
219+
var result map[string]interface{}
220+
if err := client.Post("/api/v1/network/peers", req, &result); err != nil {
221+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
222+
os.Exit(1)
223+
}
224+
fmt.Printf("Added peer %s\n", args[0])
225+
},
226+
}
227+
228+
// Bounty subcommands (approve, cancel, stats)
229+
230+
var bountyApproveCmd = &cobra.Command{
231+
Use: "approve <bounty-id>",
232+
Short: "Approve a bounty submission and release payment",
233+
Args: cobra.ExactArgs(1),
234+
Run: func(cmd *cobra.Command, args []string) {
235+
repo, _ := cmd.Flags().GetString("repo")
236+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
237+
238+
client := cli.NewClient(daemonURL)
239+
var result map[string]interface{}
240+
if err := client.Post(fmt.Sprintf("/api/v1/repos/%s/bounties/%s/approve", repo, args[0]), nil, &result); err != nil {
241+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
242+
os.Exit(1)
243+
}
244+
fmt.Printf("Approved bounty %s — payment released\n", args[0])
245+
},
246+
}
247+
248+
var bountyCancelCmd = &cobra.Command{
249+
Use: "cancel <bounty-id>",
250+
Short: "Cancel a bounty and refund the escrow",
251+
Args: cobra.ExactArgs(1),
252+
Run: func(cmd *cobra.Command, args []string) {
253+
repo, _ := cmd.Flags().GetString("repo")
254+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
255+
256+
client := cli.NewClient(daemonURL)
257+
var result map[string]interface{}
258+
if err := client.Post(fmt.Sprintf("/api/v1/repos/%s/bounties/%s/cancel", repo, args[0]), nil, &result); err != nil {
259+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
260+
os.Exit(1)
261+
}
262+
fmt.Printf("Cancelled bounty %s — escrow refunded\n", args[0])
263+
},
264+
}
265+
266+
var bountyStatsCmd = &cobra.Command{
267+
Use: "stats",
268+
Short: "Show bounty statistics for a repository",
269+
Run: func(cmd *cobra.Command, args []string) {
270+
repo, _ := cmd.Flags().GetString("repo")
271+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
272+
273+
client := cli.NewClient(daemonURL)
274+
var result map[string]interface{}
275+
if err := client.Get(fmt.Sprintf("/api/v1/repos/%s/bounties/stats", repo), &result); err != nil {
276+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
277+
os.Exit(1)
278+
}
279+
280+
out, _ := json.MarshalIndent(result, "", " ")
281+
fmt.Println(string(out))
282+
},
283+
}
284+
285+
// Task subcommand (fail)
286+
287+
var taskFailCmd = &cobra.Command{
288+
Use: "fail <task-id>",
289+
Short: "Mark a task as failed",
290+
Args: cobra.ExactArgs(1),
291+
Run: func(cmd *cobra.Command, args []string) {
292+
repo, _ := cmd.Flags().GetString("repo")
293+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
294+
295+
client := cli.NewClient(daemonURL)
296+
var result map[string]interface{}
297+
if err := client.Post(fmt.Sprintf("/api/v1/repos/%s/tasks/%s/fail", repo, args[0]), nil, &result); err != nil {
298+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
299+
os.Exit(1)
300+
}
301+
fmt.Printf("Task %s marked as failed\n", args[0])
302+
},
303+
}
304+
305+
// Cert verify
306+
307+
var certVerifyCmd = &cobra.Command{
308+
Use: "verify <cert-id>",
309+
Short: "Verify a ref-update certificate's signature",
310+
Args: cobra.ExactArgs(1),
311+
Run: func(cmd *cobra.Command, args []string) {
312+
repo, _ := cmd.Flags().GetString("repo")
313+
daemonURL, _ := cmd.Flags().GetString("daemon-url")
314+
315+
client := cli.NewClient(daemonURL)
316+
var result map[string]interface{}
317+
if err := client.Get(fmt.Sprintf("/api/v1/repos/%s/certs/%s/verify", repo, args[0]), &result); err != nil {
318+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
319+
os.Exit(1)
320+
}
321+
322+
if valid, ok := result["valid"].(bool); ok && valid {
323+
fmt.Printf("Certificate %s is VALID\n", args[0])
324+
} else {
325+
fmt.Printf("Certificate %s is INVALID\n", args[0])
326+
}
327+
if reason, ok := result["reason"].(string); ok && reason != "" {
328+
fmt.Printf("Reason: %s\n", reason)
329+
}
330+
},
331+
}
332+
333+
func init() {
334+
// Identity flags
335+
for _, c := range []*cobra.Command{identityNewCmd, identityShowCmd, identityExportCmd, identitySignCmd} {
336+
c.Flags().String("daemon-url", "", "Daemon URL")
337+
}
338+
339+
// Node flags
340+
for _, c := range []*cobra.Command{nodeStatusCmd, nodeTrustCmd, nodeResolveCmd} {
341+
c.Flags().String("daemon-url", "", "Daemon URL")
342+
}
343+
344+
// Peer flags
345+
for _, c := range []*cobra.Command{peerListCmd, peerAddCmd} {
346+
c.Flags().String("daemon-url", "", "Daemon URL")
347+
}
348+
349+
// Bounty flags
350+
for _, c := range []*cobra.Command{bountyApproveCmd, bountyCancelCmd, bountyStatsCmd} {
351+
c.Flags().StringP("repo", "r", "", "Repository name (required)")
352+
c.MarkFlagRequired("repo")
353+
c.Flags().String("daemon-url", "", "Daemon URL")
354+
}
355+
356+
// Task flags
357+
taskFailCmd.Flags().StringP("repo", "r", "", "Repository name (required)")
358+
taskFailCmd.MarkFlagRequired("repo")
359+
taskFailCmd.Flags().String("daemon-url", "", "Daemon URL")
360+
361+
// Cert flags
362+
certVerifyCmd.Flags().StringP("repo", "r", "", "Repository name (required)")
363+
certVerifyCmd.MarkFlagRequired("repo")
364+
certVerifyCmd.Flags().String("daemon-url", "", "Daemon URL")
365+
366+
// Register subcommands
367+
identityCmd.AddCommand(identityNewCmd, identityShowCmd, identityExportCmd, identitySignCmd)
368+
nodeCmd.AddCommand(nodeStatusCmd, nodeTrustCmd, nodeResolveCmd)
369+
peerCmd.AddCommand(peerListCmd, peerAddCmd)
370+
371+
// Add to existing commands
372+
bountyCmd.AddCommand(bountyApproveCmd, bountyCancelCmd, bountyStatsCmd)
373+
taskCmd.AddCommand(taskFailCmd)
374+
certCmd.AddCommand(certVerifyCmd)
375+
376+
// Add new top-level commands
377+
rootCmd.AddCommand(identityCmd, nodeCmd, peerCmd)
378+
}

0 commit comments

Comments
 (0)