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