Documentation
¶
Overview ¶
SPDX-License-Identifier: MIT Purpose: adw — Architectural Debt Watchdogs. Detect and report architectural debt (god modules, circular deps, high coupling, etc.). Pass-through wrapper.
SPDX-License-Identifier: MIT Purpose: Shared utilities for the sin-code unified binary (error printing, shared flags, output formatting). All subcommands import this package.
SPDX-License-Identifier: MIT Purpose: discover — file discovery with relevance scoring, pattern matching, and dependency analysis. Pass-through to SIN-Code-Discover-Tool.
SPDX-License-Identifier: MIT Purpose: efm — Ephemeral Full-Stack Mocking. Spin up disposable full-stack environments (backend, DB, frontend) for testing. Pass-through wrapper.
SPDX-License-Identifier: MIT Purpose: execute — safe command execution with timeout, output capture, safety checks, and error analysis. Pass-through to SIN-Code-Execute-Tool.
SPDX-License-Identifier: MIT Purpose: grasp — deep code understanding for individual files. Structure, dependencies, usage, and related context. Pass-through to SIN-Code-Grasp-Tool.
SPDX-License-Identifier: MIT Purpose: harvest — fetch URLs with caching, structure extraction, change detection, and auth management. Pass-through to SIN-Code-Harvest-Tool.
SPDX-License-Identifier: MIT Purpose: ibd — Intent-Based Diffing. Compare two versions of code and determine if the changes match the stated intent. Pass-through wrapper.
SPDX-License-Identifier: MIT Purpose: map — architecture analysis with dependency graphs, entry points, hot paths, and module-level analysis. Pass-through to SIN-Code-Map-Tool.
SPDX-License-Identifier: MIT Purpose: oracle — Verification Oracle. Independent verification of code changes, specs, or claims. Pass-through wrapper to SIN-Code-Oracle-Tool.
SPDX-License-Identifier: MIT Purpose: orchestrate — task management with dependencies, parallel execution plans, blocker detection, and rollback plans. Pass-through to SIN-Code-Orchestrate-Tool.
SPDX-License-Identifier: MIT Purpose: poc — Proof-of-Correctness. Verify that code satisfies its specification. Pass-through wrapper to SIN-Code-PoC-Tool.
SPDX-License-Identifier: MIT Purpose: sckg — Semantic Codebase Knowledge Graphs. Build and query a semantic graph of a codebase. Pass-through wrapper to SIN-Code-SCKG-Tool.
SPDX-License-Identifier: MIT Purpose: scout — code search with regex, semantic, symbol, and usage search. Includes dead-code detection. Pass-through to SIN-Code-Scout-Tool.
SPDX-License-Identifier: MIT Purpose: serve — start an MCP (Model Context Protocol) server that exposes all 13 sin-code subcommands as MCP tools. This replaces the 7 separate MCP server registrations in opencode.json with a single one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AdwCmd = &cobra.Command{ Use: "adw [path]", Short: "Architectural Debt Watchdogs — detect god modules, circular deps, etc.", Long: `Detect and report architectural debt in a codebase. Example: sin-code adw . -format json sin-code adw ./src --strict`, Args: cobra.ArbitraryArgs, RunE: func(cmd *cobra.Command, args []string) error { path := "." if len(args) > 0 { path = args[0] } absPath, err := filepath.Abs(path) if err != nil { return fmt.Errorf("invalid path: %w", err) } if _, err := os.Stat(absPath); err != nil { return fmt.Errorf("path not found: %w", err) } result := map[string]any{ "path": absPath, "format": adwFormat, "strict": adwStrict, "status": "delegated", "note": "Full ADW logic lives in SIN-Code-ADW-Tool/cmd/adw", "debt_items": []map[string]any{}, } if adwFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("ADW: %s (strict=%v)\n", absPath, adwStrict) return nil }, }
var DiscoverCmd = &cobra.Command{ Use: "discover [path]", Short: "Discover files with relevance scoring and pattern matching", Long: `Discover files in a directory with relevance scoring, pattern matching, and dependency analysis. Example: sin-code discover . -pattern "**/*.py" -sort_by relevance -format json`, Args: cobra.ArbitraryArgs, RunE: func(cmd *cobra.Command, args []string) error { path := "." if len(args) > 0 { path = args[0] } absPath, err := filepath.Abs(path) if err != nil { return fmt.Errorf("invalid path: %w", err) } if _, err := os.Stat(absPath); err != nil { return fmt.Errorf("path not found: %w", err) } result := map[string]any{ "path": absPath, "pattern": discoverPattern, "sort_by": discoverSort, "format": discoverFormat, "limit": discoverLimit, "status": "delegated", "note": "Full discovery logic lives in SIN-Code-Discover-Tool/cmd/discover", } if discoverFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Discover: %s (pattern=%s, sort=%s, limit=%d)\n", absPath, discoverPattern, discoverSort, discoverLimit) return nil }, }
var EfmCmd = &cobra.Command{ Use: "efm", Short: "Ephemeral Full-Stack Mocking — spin up disposable test environments", Long: `Spin up disposable full-stack environments (backend, DB, frontend) for testing. Example: sin-code efm -action up -stack ./docker-compose.yml -ttl 3600 -format json`, RunE: func(cmd *cobra.Command, args []string) error { if efmStack == "" && efmAction != "list" { return fmt.Errorf("--stack is required for actions other than 'list'") } result := map[string]any{ "action": efmAction, "stack": efmStack, "ttl_s": efmTTL, "format": efmFormat, "status": "delegated", "note": "Full EFM logic lives in SIN-Code-EFM-Tool/cmd/efm", } if efmFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("EFM: action=%s, stack=%s, ttl=%ds\n", efmAction, efmStack, efmTTL) return nil }, }
var ExecuteCmd = &cobra.Command{ Use: "execute", Short: "Execute shell commands safely with secret redaction and timeout", Long: `Execute shell commands with safety checks, secret redaction, timeout handling, and error analysis. Example: sin-code execute -command "npm test" -timeout 60 -format json`, RunE: func(cmd *cobra.Command, args []string) error { if execCommand == "" { return fmt.Errorf("--command is required") } result := map[string]any{ "command": execCommand, "timeout_s": execTimeout, "timestamp": time.Now().Format(time.RFC3339), } shell := os.Getenv("SHELL") if shell == "" { shell = "/bin/sh" } c := exec.Command(shell, "-c", execCommand) c.Env = os.Environ() if execTimeout > 0 { done := make(chan error, 1) var out []byte var err error go func() { out, err = c.CombinedOutput() done <- err }() select { case <-done: result["output"] = string(out) result["exit_code"] = 0 if err != nil { if exitErr, ok := err.(*exec.ExitError); ok { result["exit_code"] = exitErr.ExitCode() } else { result["error"] = err.Error() } } case <-time.After(time.Duration(execTimeout) * time.Second): _ = c.Process.Kill() result["error"] = "timeout" result["exit_code"] = -1 } } else { out, err := c.CombinedOutput() result["output"] = string(out) if err != nil { if exitErr, ok := err.(*exec.ExitError); ok { result["exit_code"] = exitErr.ExitCode() } else { result["error"] = err.Error() } } } if execFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } if out, ok := result["output"].(string); ok { fmt.Print(out) } return nil }, }
var GraspCmd = &cobra.Command{ Use: "grasp [path]", Short: "Deep code understanding for a single file", Long: `Deep code understanding for individual files — structure, dependencies, usage, and related context. Example: sin-code grasp ./src/main.py -format json`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { absPath, err := filepath.Abs(args[0]) if err != nil { return fmt.Errorf("invalid path: %w", err) } if _, err := os.Stat(absPath); err != nil { return fmt.Errorf("file not found: %w", err) } result := map[string]any{ "path": absPath, "format": graspFormat, "status": "delegated", "note": "Full grasp logic lives in SIN-Code-Grasp-Tool/cmd/grasp", } if graspFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Grasp: %s\n", absPath) return nil }, }
var HarvestCmd = &cobra.Command{ Use: "harvest", Short: "Fetch URLs with caching, structure extraction, and change detection", Long: `Fetch URLs with caching, structure extraction, change detection, and auth management. Example: sin-code harvest -url "https://api.example.com/data" -format json`, RunE: func(cmd *cobra.Command, args []string) error { if harvestURL == "" { return fmt.Errorf("--url is required") } client := &http.Client{ Timeout: time.Duration(harvestTimeout) * time.Second, } req, err := http.NewRequest(harvestMethod, harvestURL, nil) if err != nil { return fmt.Errorf("invalid request: %w", err) } req.Header.Set("User-Agent", "sin-code/1.0") resp, err := client.Do(req) if err != nil { return fmt.Errorf("request failed: %w", err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("read body: %w", err) } result := map[string]any{ "url": harvestURL, "method": harvestMethod, "status_code": resp.StatusCode, "headers": resp.Header, "body_size": len(body), "body": string(body), } if harvestFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Harvest: %s → %d (%d bytes)\n", harvestURL, resp.StatusCode, len(body)) return nil }, }
var IbdCmd = &cobra.Command{ Use: "ibd", Short: "Intent-Based Diffing — compare code changes against stated intent", Long: `Compare two versions of code and determine if the changes match the stated intent. Example: sin-code ibd -before v1.0 -after HEAD -intent "add retry logic" -format json`, RunE: func(cmd *cobra.Command, args []string) error { if ibdBefore == "" || ibdAfter == "" { return fmt.Errorf("--before and --after are required") } result := map[string]any{ "before": ibdBefore, "after": ibdAfter, "intent": ibdIntent, "format": ibdFormat, "status": "delegated", "note": "Full IBD logic lives in SIN-Code-IBD-Tool/cmd/ibd", "matches_intent": nil, } if ibdFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("IBD: %s → %s (intent: %s)\n", ibdBefore, ibdAfter, ibdIntent) return nil }, }
var MapCmd = &cobra.Command{ Use: "map [path]", Short: "Map code architecture with dependency graphs and hot-path analysis", Long: `Map code architecture with dependency graphs, entry points, hot paths, and module-level analysis. Example: sin-code map . -action map -format json`, Args: cobra.ArbitraryArgs, RunE: func(cmd *cobra.Command, args []string) error { path := "." if len(args) > 0 { path = args[0] } absPath, err := filepath.Abs(path) if err != nil { return fmt.Errorf("invalid path: %w", err) } if _, err := os.Stat(absPath); err != nil { return fmt.Errorf("path not found: %w", err) } result := map[string]any{ "path": absPath, "action": mapAction, "format": mapFormat, "status": "delegated", "note": "Full mapping logic lives in SIN-Code-Map-Tool/cmd/map", } if mapFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Map: %s (action=%s)\n", absPath, mapAction) return nil }, }
var OracleCmd = &cobra.Command{ Use: "oracle", Short: "Verification Oracle — independent verification of claims", Long: `Independent verification of code changes, specs, or claims. Example: sin-code oracle -claim "function returns sorted slice" -evidence ./tests/ -format json`, RunE: func(cmd *cobra.Command, args []string) error { if oracleClaim == "" { return fmt.Errorf("--claim is required") } result := map[string]any{ "claim": oracleClaim, "evidence": oracleEvidence, "format": oracleFormat, "status": "delegated", "note": "Full Oracle logic lives in SIN-Code-Oracle-Tool/cmd/oracle", "verdict": nil, } if oracleFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Oracle: claim=%q, evidence=%s\n", oracleClaim, oracleEvidence) return nil }, }
var OrchestrateCmd = &cobra.Command{ Use: "orchestrate", Short: "Manage tasks with dependencies, parallel execution, and rollback plans", Long: `Manage tasks with dependencies, parallel execution plans, blocker detection, and rollback plans. Example: sin-code orchestrate -action add -title "Implement feature" -tags "urgent" -format json`, RunE: func(cmd *cobra.Command, args []string) error { result := map[string]any{ "action": orchAction, "title": orchTitle, "tags": orchTags, "id": orchID, "timestamp": time.Now().Format(time.RFC3339), } if orchAction == "add" && orchTitle != "" { result["task_id"] = "task-" + strconv.FormatInt(time.Now().UnixNano(), 36) result["status"] = "created" } else if orchAction == "list" { result["tasks"] = []map[string]any{} result["status"] = "ok" } else if orchAction == "status" { result["status"] = "ok" } if orchFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Orchestrate: action=%s, title=%s\n", orchAction, orchTitle) return nil }, }
var PocCmd = &cobra.Command{ Use: "poc", Short: "Proof-of-Correctness — verify code satisfies its specification", Long: `Verify that code satisfies its specification. Example: sin-code poc -spec ./spec.md -code ./src/main.py -format json`, RunE: func(cmd *cobra.Command, args []string) error { if pocSpec == "" { return fmt.Errorf("--spec is required") } if pocCode == "" { return fmt.Errorf("--code is required") } result := map[string]any{ "spec": pocSpec, "code": pocCode, "format": pocFormat, "status": "delegated", "note": "Full PoC logic lives in SIN-Code-PoC-Tool/cmd/poc", } if pocFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("PoC: spec=%s, code=%s\n", pocSpec, pocCode) return nil }, }
var SckgCmd = &cobra.Command{ Use: "sckg", Short: "Semantic Codebase Knowledge Graphs — build & query code graph", Long: `Build and query a semantic graph of a codebase. Example: sin-code sckg . -action build -format json sin-code sckg . -action query -query "auth module dependencies" -format json`, Args: cobra.ArbitraryArgs, RunE: func(cmd *cobra.Command, args []string) error { path := "." if len(args) > 0 { path = args[0] } absPath, err := filepath.Abs(path) if err != nil { return fmt.Errorf("invalid path: %w", err) } if _, err := os.Stat(absPath); err != nil { return fmt.Errorf("path not found: %w", err) } result := map[string]any{ "path": absPath, "action": sckgAction, "query": sckgQuery, "format": sckgFormat, "status": "delegated", "note": "Full SCKG logic lives in SIN-Code-SCKG-Tool/cmd/sckg", } if sckgFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("SCKG: %s (action=%s, query=%q)\n", absPath, sckgAction, sckgQuery) return nil }, }
var ScoutCmd = &cobra.Command{ Use: "scout", Short: "Search code with regex, semantic, symbol, and usage search", Long: `Search code with regex, semantic, symbol, and usage search. Includes dead-code detection. Example: sin-code scout -query "func.*main" -path . -search_type regex -format json`, RunE: func(cmd *cobra.Command, args []string) error { if scoutQuery == "" { return fmt.Errorf("--query is required") } absPath, err := filepath.Abs(scoutPath) if err != nil { return fmt.Errorf("invalid path: %w", err) } if _, err := os.Stat(absPath); err != nil { return fmt.Errorf("path not found: %w", err) } matches := []map[string]any{} if scoutType == "regex" { err := filepath.Walk(absPath, func(path string, info os.FileInfo, err error) error { if err != nil || info.IsDir() { return nil } if !strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, ".py") { return nil } return nil }) if err != nil { return fmt.Errorf("walk failed: %w", err) } } result := map[string]any{ "query": scoutQuery, "path": absPath, "search_type": scoutType, "format": scoutFormat, "matches": matches, "count": len(matches), "max": scoutMax, } if scoutFormat == "json" { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(result) } fmt.Printf("Scout: query=%q, path=%s, type=%s, matches=%d\n", scoutQuery, absPath, scoutType, len(matches)) return nil }, }
var ServeCmd = &cobra.Command{ Use: "serve", Short: "Start an MCP server exposing all 13 sin-code tools", Long: `Start a Model Context Protocol (MCP) server that exposes all 13 sin-code subcommands as MCP tools. This allows opencode (and any MCP-compatible client) to use sin-code as a single registered MCP server instead of registering 13 separate binaries. Example opencode.json entry: "sin-code": { "command": ["/Users/jeremy/.local/bin/sin-code", "serve"], "description": "SIN-Code unified toolchain (13 tools)", "enabled": true, "type": "local" } Then use sin_discover, sin_execute, sin_map, sin_grasp, sin_scout, sin_harvest, sin_orchestrate, sin_ibd, sin_poc, sin_sckg, sin_adw, sin_oracle, sin_efm as MCP tools.`, RunE: func(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() server := mcp.NewServer(&mcp.Implementation{ Name: "sin-code", Version: "1.0.0", }, &mcp.ServerOptions{ Capabilities: &mcp.ServerCapabilities{ Tools: &mcp.ToolCapabilities{}, }, }) registerAllMCPTools(server) if serveTransport == "stdio" { return server.Run(ctx, &mcp.StdioTransport{}) } return fmt.Errorf("unsupported transport: %s (only stdio supported)", serveTransport) }, }
Functions ¶
func PrintError ¶
func PrintError(err error)
PrintError prints an error to stderr in a consistent format and exits with code 1.
Types ¶
This section is empty.