Documentation
¶
Index ¶
- Variables
- func AddFileToZip(zipData []byte, filename string, content []byte) ([]byte, error)
- func CleanupMarkdownSpacing(content string) string
- func CompareZipContents(zipData1, zipData2 []byte) (bool, error)
- func ComputeFileSHA256(filePath string) (string, error)
- func ComputeFileSHA512(filePath string) (string, error)
- func ComputeSHA256(data []byte) string
- func ComputeSHA512(data []byte) string
- func ComputeZipHash(zipData []byte) ([]byte, error)
- func CreateZip(sourceDir string) ([]byte, error)
- func CreateZipFromContent(filename string, content []byte) ([]byte, error)
- func EnsureDir(path string) error
- func ExpandTilde(path string) (string, error)
- func ExtractZip(zipData []byte, targetDir string) error
- func FileExists(path string) bool
- func GetClaudeDir() (string, error)
- func GetConfigDir() (string, error)
- func GetConfigFile() (string, error)
- func HasContentFiles(zipData []byte) (bool, error)
- func IsDirectory(path string) bool
- func IsZipFile(data []byte) bool
- func ListZipFiles(zipData []byte) ([]string, error)
- func NormalizePath(path string) (string, error)
- func Portabilize(path string) string
- func ReadZipFile(zipData []byte, filename string) ([]byte, error)
- func RemoveFileFromZip(zipData []byte, filename string) ([]byte, error)
- func RemoveMarkdownSections(content string, headingsToRemove []string) string
- func ReplaceFileInZip(zipData []byte, filename string, content []byte) ([]byte, error)
- func ResolveArgs(args []string, installPath string) []string
- func ResolveCommand(command string, installPath string) string
- func ResolveCommandAndArgs(command string, args []string, installPath string) (string, []any)
- func Slugify(s string) string
- func StringsToAny(s []string) []any
- func URLHash(url string) string
- func UnmarshalJSONC(data []byte, v any) error
- func VerifyHash(data []byte, algorithm, expected string) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type MarkdownSection
Constants ¶
This section is empty.
Variables ¶
var ZipMagicBytes = []byte{0x50, 0x4B, 0x03, 0x04}
ZipMagicBytes are the first 4 bytes of a ZIP file
Functions ¶
func AddFileToZip ¶
AddFileToZip adds or updates a file in a zip archive
func CleanupMarkdownSpacing ¶ added in v0.9.0
CleanupMarkdownSpacing reduces multiple consecutive blank lines to a maximum of two
func CompareZipContents ¶
CompareZipContents compares two zip files by computing and comparing their hashes Excludes metadata.toml from comparison to focus on actual content
func ComputeFileSHA256 ¶
ComputeFileSHA256 computes the SHA256 hash of a file
func ComputeFileSHA512 ¶
ComputeFileSHA512 computes the SHA512 hash of a file
func ComputeSHA256 ¶
ComputeSHA256 computes the SHA256 hash of data
func ComputeSHA512 ¶
ComputeSHA512 computes the SHA512 hash of data
func ComputeZipHash ¶
ComputeZipHash computes an MD5 hash of all files in a zip archive Files are hashed individually, then combined in alphabetical order by filename
func CreateZipFromContent ¶ added in v0.5.5
CreateZipFromContent creates a zip archive containing a single file with the given content
func ExpandTilde ¶
ExpandTilde expands a tilde (~) at the beginning of a path to the user's home directory
func ExtractZip ¶
ExtractZip extracts a zip file to a target directory
func GetClaudeDir ¶
GetClaudeDir returns the path to the .claude directory for asset installation This is where global assets are installed
func GetConfigDir ¶
GetConfigDir returns the path to the sx config directory Uses platform-specific config directories: - Linux: ~/.config/sx (or $XDG_CONFIG_HOME/sx) - macOS: ~/Library/Application Support/sx - Windows: %AppData%/sx
func GetConfigFile ¶
GetConfigFile returns the path to the config.json file
func HasContentFiles ¶ added in v0.10.0
HasContentFiles returns true if the zip contains files beyond metadata.toml. This is used to distinguish packaged assets (with server code) from config-only assets.
func ListZipFiles ¶
ListZipFiles returns a list of all files in a zip archive
func NormalizePath ¶
NormalizePath normalizes a file path, expanding tilde and cleaning it
func Portabilize ¶ added in v0.14.9
Portabilize replaces the user's home directory prefix with $HOME so paths remain valid across different environments.
func ReadZipFile ¶
ReadZipFile reads a specific file from a zip archive without extracting
func RemoveFileFromZip ¶
RemoveFileFromZip removes a file from a zip archive
func RemoveMarkdownSections ¶ added in v0.9.0
RemoveMarkdownSections removes specified sections from markdown content
func ReplaceFileInZip ¶
ReplaceFileInZip replaces an existing file in a zip archive This is an alias for AddFileToZip which already handles replacement
func ResolveArgs ¶ added in v0.12.4
ResolveArgs resolves args for a packaged MCP server. Each arg is converted to an absolute path only if it corresponds to an actual file or directory within installPath. Subcommands (e.g. "run" for "uv run"), flags, and other non-file args are left as-is.
func ResolveCommand ¶ added in v0.12.4
ResolveCommand resolves a command for a packaged MCP server. Bare command names (e.g. "node", "uv", "python") are left as-is to be resolved via PATH. Relative paths containing a directory separator (e.g. "./bin/server") are made absolute relative to installPath.
func ResolveCommandAndArgs ¶ added in v0.12.4
ResolveCommandAndArgs resolves a command and its args for a packaged MCP server, returning them as []any suitable for JSON serialization into client configs.
func Slugify ¶ added in v0.9.0
Slugify converts a string to a valid asset name. The result contains only lowercase alphanumeric characters and hyphens, matching the asset name validation pattern ^[a-zA-Z0-9_-]+$.
Transformations:
- Convert to lowercase
- Replace spaces and underscores with hyphens
- Remove all other special characters
- Collapse consecutive hyphens
- Trim leading/trailing hyphens
func StringsToAny ¶ added in v0.12.4
StringsToAny converts a []string to []any.
func UnmarshalJSONC ¶ added in v0.14.4
UnmarshalJSONC parses JSONC (JSON with Comments and trailing commas) into v. VS Code-based editors (Cursor, Kiro, Cline, etc.) treat JSON config files as JSONC, so user-edited config files may contain comments and trailing commas that Go's encoding/json rejects. This function standardizes the input first. For valid JSON input the standardize step is a no-op.
func VerifyHash ¶
VerifyHash verifies that data matches the expected hash
func WriteFileAtomic ¶ added in v0.15.0
WriteFileAtomic writes data to path via a tmp file in the same directory plus rename. On POSIX filesystems the rename is atomic — readers never see a partial write. Used for any file that concurrent readers might slurp while a writer is midway through replacing it.
Types ¶
type MarkdownSection ¶ added in v0.9.0
type MarkdownSection struct {
Heading string // The heading text (without ## prefix)
Content string // The section content (including any sub-headings)
Level int // Heading level (2 for ##, 3 for ###, etc.)
}
MarkdownSection represents a parsed section from a markdown file
func ParseMarkdownSections ¶ added in v0.9.0
func ParseMarkdownSections(content string) []MarkdownSection
ParseMarkdownSections extracts ## sections from markdown content. Returns empty slice for empty content or content without ## headings. Sub-headings (###, ####, etc.) are included in their parent section's content.