internal

package
v1.0.1-sin-code Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

SPDX-License-Identifier: MIT Purpose: adw — Architectural Debt Watchdogs. Delegates to the Python `adw` module in SIN-Code-ADW-Tool (source of truth).

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. Thin wrapper that calls the standalone SIN-Code-Discover-Tool binary if installed (preserves its Go implementation without duplicating logic).

SPDX-License-Identifier: MIT Purpose: efm — Ephemeral Full-Stack Mocking. Delegates to the Python `efm` module in SIN-Code-Ephemeral-Full-Stack-Mocking-Orchestration (source of truth).

SPDX-License-Identifier: MIT Purpose: execute — safe command execution. Thin wrapper around the standalone SIN-Code-Execute-Tool binary if installed.

SPDX-License-Identifier: MIT Purpose: grasp — deep code understanding. Thin wrapper around standalone SIN-Code-Grasp-Tool binary if installed.

SPDX-License-Identifier: MIT Purpose: harvest — URL fetching. Thin wrapper around standalone SIN-Code-Harvest-Tool.

SPDX-License-Identifier: MIT Purpose: ibd — Intent-Based Diffing. Delegates to the Python `ibd` module in SIN-Code-IBD-Tool (source of truth). Provides Go CLI surface + MCP registration.

SPDX-License-Identifier: MIT Purpose: map — architecture analysis. Thin wrapper around standalone SIN-Code-Map-Tool binary if installed.

SPDX-License-Identifier: MIT Purpose: oracle — Verification Oracle. Delegates to the Python `oracle` module in SIN-Code-Oracle-Tool (source of truth). The Python oracle actually checks test coverage of a source file against an existing test file (subcommand: check).

SPDX-License-Identifier: MIT Purpose: orchestrate — task management. Thin wrapper around standalone SIN-Code-Orchestrate-Tool.

SPDX-License-Identifier: MIT Purpose: poc — Proof-of-Correctness. Delegates to the Python `poc` module in SIN-Code-PoC-Tool (source of truth).

SPDX-License-Identifier: MIT Purpose: sckg — Semantic Codebase Knowledge Graphs. Delegates to the Python `sckg` module in SIN-Code-SCKG-Tool (source of truth).

SPDX-License-Identifier: MIT Purpose: scout — code search. Thin wrapper around standalone 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

View Source
var AdwCmd = &cobra.Command{
	Use:   "adw",
	Short: "Architectural Debt Watchdogs — detect god modules, circular deps, etc.",
	Long: `Detect and report architectural debt in a codebase. Delegates to the Python
` + "`adw`" + ` module.

Examples:
  sin-code adw .
  sin-code adw ./src --strict
  sin-code adw . --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)
		}

		pythonArgs := []string{"-m", "adw.cli", "scan", absPath}
		if adwStrict {
			pythonArgs = append(pythonArgs, "--strict")
		}

		c := exec.Command("python3", pythonArgs...)
		c.Stderr = os.Stderr
		out, err := c.Output()
		if err != nil {
			return fmt.Errorf("adw execution failed: %w", err)
		}

		if adwFormat == "json" {
			var pretty map[string]any
			if err := json.Unmarshal(out, &pretty); err == nil {
				enc := json.NewEncoder(os.Stdout)
				enc.SetIndent("", "  ")
				return enc.Encode(pretty)
			}
		}
		fmt.Print(string(out))
		return nil
	},
}
View Source
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. Delegates to the standalone SIN-Code-Discover-Tool
binary if installed; otherwise uses built-in implementation.

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)
		}

		binary, err := lookupStandalone("discover")
		if err != nil {
			return err
		}

		cArgs := []string{
			"-path", absPath,
			"-pattern", discoverPattern,
			"-sort_by", discoverSort,
			"-format", discoverFormat,
			"-max_results", fmt.Sprintf("%d", discoverLimit),
		}
		c := exec.Command(binary, cArgs...)
		c.Stderr = os.Stderr
		c.Stdout = os.Stdout
		return c.Run()
	},
}
View Source
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. Delegates to the Python ` + "`efm`" + ` module.

Examples:
  sin-code efm --action list
  sin-code efm --action up --stack docker-compose.yml --ttl 3600
  sin-code efm --action down
  sin-code efm --action status`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if efmStack == "" && efmAction != "list" {
			return fmt.Errorf("--stack is required for actions other than 'list'")
		}

		pythonArgs := []string{"-m", "efm.cli"}
		switch efmAction {
		case "up":
			pythonArgs = append(pythonArgs, "up", efmStack, "--ttl", fmt.Sprintf("%d", efmTTL))
		case "down":
			pythonArgs = append(pythonArgs, "down")
		case "list":
			pythonArgs = append(pythonArgs, "status")
		case "status":
			pythonArgs = append(pythonArgs, "status")
		default:
			return fmt.Errorf("unknown action: %s (use up|down|list|status)", efmAction)
		}

		c := exec.Command("python3", pythonArgs...)
		c.Stderr = os.Stderr
		out, err := c.Output()
		if err != nil {
			return fmt.Errorf("efm execution failed: %w", err)
		}

		if efmFormat == "json" {
			var pretty map[string]any
			if err := json.Unmarshal(out, &pretty); err == nil {
				enc := json.NewEncoder(os.Stdout)
				enc.SetIndent("", "  ")
				return enc.Encode(pretty)
			}
		}
		fmt.Print(string(out))
		return nil
	},
}
View Source
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. Delegates to standalone SIN-Code-Execute-Tool.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if execCommand == "" {
			return fmt.Errorf("--command is required")
		}
		binary, err := lookupStandalone("execute")
		if err != nil {
			return err
		}
		cArgs := []string{
			"-command", execCommand,
			"-timeout", fmt.Sprintf("%d", execTimeout),
			"-format", execFormat,
		}
		if execStream {
			cArgs = append(cArgs, "-stream")
		}
		c := exec.Command(binary, cArgs...)
		c.Stderr = os.Stderr
		c.Stdout = os.Stdout
		return c.Run()
	},
}
View Source
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. Delegates to standalone SIN-Code-Grasp-Tool.`,
	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)
		}
		binary, err := lookupStandalone("grasp")
		if err != nil {
			return err
		}
		cArgs := []string{"-file", absPath, "-format", graspFormat}
		c := exec.Command(binary, cArgs...)
		c.Stderr = os.Stderr
		c.Stdout = os.Stdout
		return c.Run()
	},
}
View Source
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. Delegates to standalone SIN-Code-Harvest-Tool.

If the standalone binary is not installed, falls back to a built-in HTTP client.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if harvestURL == "" {
			return fmt.Errorf("--url is required")
		}

		binary, binErr := lookupStandalone("harvest")
		if binErr == nil {
			cArgs := []string{
				"-url", harvestURL,
				"-method", harvestMethod,
				"-format", harvestFormat,
			}
			c := exec.Command(binary, cArgs...)
			c.Stderr = os.Stderr
			c.Stdout = os.Stdout
			return c.Run()
		}

		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()
		_, err = io.Copy(os.Stdout, resp.Body)
		return err
	},
}
View Source
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. Delegates to the Python ` + "`ibd`" + ` module.

Examples:
  sin-code ibd --before v1.0 --after HEAD --intent "add retry logic"
  sin-code ibd path/to/file.py --from main --to feature-branch
  sin-code ibd --before old.py --after new.py --intent "refactor"`,
	RunE: func(cmd *cobra.Command, args []string) error {
		pythonModule := "ibd.cli"
		pythonArgs := []string{"-m", pythonModule, "diff"}

		if ibdBefore != "" && ibdAfter != "" {
			pythonArgs = append(pythonArgs, ibdBefore, "--before", ibdBefore, "--after", ibdAfter)
		} else if len(args) > 0 {
			pythonArgs = append(pythonArgs, args[0])
			if ibdFrom != "" {
				pythonArgs = append(pythonArgs, "--from", ibdFrom)
			}
			if ibdTo != "" {
				pythonArgs = append(pythonArgs, "--to", ibdTo)
			}
		} else {
			return fmt.Errorf("either --before/--after or a target path with --from/--to is required")
		}

		if ibdIntent != "" {
			pythonArgs = append(pythonArgs, "--intent", ibdIntent)
		}
		if ibdOutput != "" {
			pythonArgs = append(pythonArgs, "--output", ibdOutput)
		}

		c := exec.Command("python3", pythonArgs...)
		c.Env = append(os.Environ(), "PYTHONPATH=pythonPath")
		c.Stderr = os.Stderr
		out, err := c.Output()
		if err != nil {
			return fmt.Errorf("ibd execution failed: %w", err)
		}

		if ibdFormat == "json" {
			var pretty map[string]any
			if err := json.Unmarshal(out, &pretty); err == nil {
				enc := json.NewEncoder(os.Stdout)
				enc.SetIndent("", "  ")
				return enc.Encode(pretty)
			}
		}
		fmt.Print(string(out))
		return nil
	},
}
View Source
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. Delegates to standalone SIN-Code-Map-Tool.`,
	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)
		}
		binary, err := lookupStandalone("map")
		if err != nil {
			return err
		}
		cArgs := []string{"-path", absPath, "-action", mapAction, "-format", mapFormat}
		c := exec.Command(binary, cArgs...)
		c.Stderr = os.Stderr
		c.Stdout = os.Stdout
		return c.Run()
	},
}
View Source
var OracleCmd = &cobra.Command{
	Use:   "oracle",
	Short: "Verification Oracle — test coverage check (delegates to oracle.cli check)",
	Long: `The Python oracle module checks test coverage of a source file against
an existing test file. Use --claim to specify the source file and
--evidence to specify the test file.

Examples:
  sin-code oracle --claim src/main.py --evidence tests/test_main.py
  sin-code oracle --claim src/auth.py --evidence tests/test_auth.py`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if oracleClaim == "" {
			return fmt.Errorf("--claim (source file) is required")
		}
		if oracleEvidence == "" {
			return fmt.Errorf("--evidence (test file) is required")
		}

		pythonArgs := []string{"-m", "oracle.cli", "check", oracleClaim, "--against", oracleEvidence}

		c := exec.Command("python3", pythonArgs...)
		c.Stderr = os.Stderr
		out, err := c.Output()
		if err != nil {
			return fmt.Errorf("oracle execution failed: %w", err)
		}

		if oracleFormat == "json" {
			var pretty map[string]any
			if err := json.Unmarshal(out, &pretty); err == nil {
				enc := json.NewEncoder(os.Stdout)
				enc.SetIndent("", "  ")
				return enc.Encode(pretty)
			}
		}
		fmt.Print(string(out))
		return nil
	},
}
View Source
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. Delegates to standalone SIN-Code-Orchestrate-Tool.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		binary, err := lookupStandalone("orchestrate")
		if err != nil {
			return err
		}
		cArgs := []string{"-action", orchAction, "-format", orchFormat}
		if orchTitle != "" {
			cArgs = append(cArgs, "-title", orchTitle)
		}
		if orchTags != "" {
			cArgs = append(cArgs, "-tags", orchTags)
		}
		if orchID != "" {
			cArgs = append(cArgs, "-id", orchID)
		}
		c := exec.Command(binary, cArgs...)
		c.Stderr = os.Stderr
		c.Stdout = os.Stdout
		return c.Run()
	},
}
View Source
var PocCmd = &cobra.Command{
	Use:   "poc",
	Short: "Proof-of-Correctness — verify code satisfies its specification",
	Long: `Verify that code satisfies its specification. Delegates to the Python
` + "`poc`" + ` module.

Examples:
  sin-code poc --spec spec.md --code src/main.py
  sin-code poc --spec spec.json --code src/`,
	RunE: func(cmd *cobra.Command, args []string) error {
		target := pocCode
		if target == "" {
			target = pocSpec
		}
		if target == "" {
			return fmt.Errorf("--code (or --spec for back-compat) is required")
		}

		pythonArgs := []string{"-m", "poc.cli", "verify", target}
		if pocSpec != "" && pocSpec != target {
			pythonArgs = append(pythonArgs, "--config", pocSpec)
		}

		c := exec.Command("python3", pythonArgs...)
		c.Stderr = os.Stderr
		out, err := c.Output()
		if err != nil {
			return fmt.Errorf("poc execution failed: %w", err)
		}

		if pocFormat == "json" {
			var pretty map[string]any
			if err := json.Unmarshal(out, &pretty); err == nil {
				enc := json.NewEncoder(os.Stdout)
				enc.SetIndent("", "  ")
				return enc.Encode(pretty)
			}
		}
		fmt.Print(string(out))
		return nil
	},
}
View Source
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. Delegates to the Python
` + "`sckg`" + ` module.

Examples:
  sin-code sckg . --action build
  sin-code sckg . --action query --query "auth module dependencies"
  sin-code sckg . --action stats
  sin-code sckg . --action export --output graph.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)
		}

		pythonArgs := []string{"-m", "sckg.cli"}
		switch sckgAction {
		case "build":
			pythonArgs = append(pythonArgs, "build", absPath)
		case "query":
			if sckgQuery == "" {
				return fmt.Errorf("--query is required for action=query")
			}
			pythonArgs = append(pythonArgs, "query", sckgQuery)
		case "stats":
			pythonArgs = append(pythonArgs, "stats", absPath)
		case "export":
			pythonArgs = append(pythonArgs, "export", absPath)
		default:
			return fmt.Errorf("unknown action: %s (use build|query|stats|export)", sckgAction)
		}

		c := exec.Command("python3", pythonArgs...)
		c.Stderr = os.Stderr
		out, err := c.Output()
		if err != nil {
			return fmt.Errorf("sckg execution failed: %w", err)
		}

		if sckgFormat == "json" {
			var pretty map[string]any
			if err := json.Unmarshal(out, &pretty); err == nil {
				enc := json.NewEncoder(os.Stdout)
				enc.SetIndent("", "  ")
				return enc.Encode(pretty)
			}
		}
		fmt.Print(string(out))
		return nil
	},
}
View Source
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. Delegates to standalone SIN-Code-Scout-Tool.`,
	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)
		}
		binary, err := lookupStandalone("scout")
		if err != nil {
			return err
		}
		cArgs := []string{
			"-query", scoutQuery,
			"-path", absPath,
			"-search_type", scoutType,
			"-format", scoutFormat,
			"-max_results", fmt.Sprintf("%d", scoutMax),
		}
		c := exec.Command(binary, cArgs...)
		c.Stderr = os.Stderr
		c.Stdout = os.Stdout
		return c.Run()
	},
}
View Source
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL