cli/internal/cmd/help/cmd.go

94 lines
2.1 KiB
Go
Raw Normal View History

feat: Batch implementation of Gemini issues (#176) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 04:20:18 +00:00
package help
import (
"fmt"
feat(help): Implement full-text search (#294) * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with markdown bold highlighting. - Optimized search by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. - Ensured all project files are correctly formatted. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections as specified. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. - Verified that `tokenize` is correctly defined and used within `pkg/help`. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized search by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import and added `--repo` flag to `auto-merge` workflow.
2026-02-05 10:26:16 +00:00
"strings"
feat: Batch implementation of Gemini issues (#176) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 04:20:18 +00:00
"github.com/host-uk/core/pkg/cli"
"github.com/host-uk/core/pkg/help"
)
func init() {
cli.RegisterCommands(AddHelpCommands)
}
func AddHelpCommands(root *cli.Command) {
var searchFlag string
helpCmd := &cli.Command{
Use: "help [topic]",
Short: "Display help documentation",
Run: func(cmd *cli.Command, args []string) {
catalog := help.DefaultCatalog()
if searchFlag != "" {
results := catalog.Search(searchFlag)
if len(results) == 0 {
fmt.Println("No topics found.")
return
}
fmt.Println("Search Results:")
for _, res := range results {
feat(help): Implement full-text search (#294) * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with markdown bold highlighting. - Optimized search by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. - Ensured all project files are correctly formatted. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections as specified. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. - Verified that `tokenize` is correctly defined and used within `pkg/help`. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized search by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import and added `--repo` flag to `auto-merge` workflow.
2026-02-05 10:26:16 +00:00
title := res.Topic.Title
if res.Section != nil {
title = fmt.Sprintf("%s > %s", res.Topic.Title, res.Section.Title)
}
// Use bold for title
fmt.Printf(" \033[1m%s\033[0m (%s)\n", title, res.Topic.ID)
if res.Snippet != "" {
// Highlight markdown bold as ANSI bold for CLI output
fmt.Printf(" %s\n", replaceMarkdownBold(res.Snippet))
}
fmt.Println()
feat: Batch implementation of Gemini issues (#176) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 04:20:18 +00:00
}
return
}
if len(args) == 0 {
topics := catalog.List()
fmt.Println("Available Help Topics:")
for _, t := range topics {
fmt.Printf(" %s - %s\n", t.ID, t.Title)
}
return
}
topic, err := catalog.Get(args[0])
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
renderTopic(topic)
},
}
helpCmd.Flags().StringVarP(&searchFlag, "search", "s", "", "Search help topics")
root.AddCommand(helpCmd)
}
feat(help): Implement full-text search (#294) * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with markdown bold highlighting. - Optimized search by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. - Ensured all project files are correctly formatted. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections as specified. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized performance by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import in `internal/cmd/help/cmd.go`. - Verified that `tokenize` is correctly defined and used within `pkg/help`. * feat(help): implement full-text search with ranking and highlighting - Implemented inverted index for help topics and sections. - Added weighted scoring: Title (10.0), Section (5.0), Content (1.0). - Implemented snippet extraction with robust markdown highlighting. - Optimized search by pre-compiling regexes for match finding. - Updated CLI help command to display matched sections and snippets with ANSI bold. - Added comprehensive tests for search accuracy and highlighting. - Fixed missing `strings` import and added `--repo` flag to `auto-merge` workflow.
2026-02-05 10:26:16 +00:00
func replaceMarkdownBold(s string) string {
parts := strings.Split(s, "**")
var result strings.Builder
for i, part := range parts {
result.WriteString(part)
if i < len(parts)-1 {
if i%2 == 0 {
result.WriteString("\033[1m")
} else {
result.WriteString("\033[0m")
}
}
}
return result.String()
}
feat: Batch implementation of Gemini issues (#176) * feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 04:20:18 +00:00
func renderTopic(t *help.Topic) {
// Simple ANSI rendering for now
// Use explicit ANSI codes or just print
fmt.Printf("\n\033[1;34m%s\033[0m\n", t.Title) // Blue bold title
fmt.Println("----------------------------------------")
fmt.Println(t.Content)
fmt.Println()
}