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 FindConflictCopies(path string) ([]string, error)
- func GetClaudeDir() (string, error)
- func GetConfigDir() (string, error)
- func GetConfigFile() (string, error)
- func HasContentFiles(zipData []byte) (bool, error)
- func IsDirectory(path string) bool
- func IsSyncArtifact(name string) bool
- func IsZipFile(data []byte) bool
- func ListZipFiles(zipData []byte) ([]string, error)
- func NormalizePath(path string) (string, error)
- func NumberedCopyBase(name string) (string, bool)
- func Portabilize(path string) string
- func ProviderForPath(path string, folders []SyncFolder) string
- func ReadZipFile(zipData []byte, filename string) ([]byte, error)
- func RemoveFileFromZip(zipData []byte, filename string) ([]byte, error)
- func RemoveFilesFromZip(zipData []byte, names ...string) ([]byte, error)
- func RemoveMarkdownSections(content string, headingsToRemove []string) string
- func RenameFileInZip(zipData []byte, oldName, newName string) ([]byte, error)
- 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
- type SyncFolder
- type ZipEntry
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 ¶
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 ¶
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 FindConflictCopies ¶
FindConflictCopies returns sibling files that look like sync-conflict copies of the file at path, e.g. for "sx.toml": "sx (Bob's conflicted copy 2026-07-04).toml", "sx.toml (1)", "sx (1).toml", "sx 2.toml". OneDrive's hostname suffix ("sx-HOSTNAME.toml") is deliberately not matched — it is indistinguishable from ordinary hyphenated names.
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 ¶
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 IsSyncArtifact ¶
IsSyncArtifact reports whether a directory entry name is a cloud-sync byproduct rather than user content: conflicted copies, sync temp files, and OS junk.
func ListZipFiles ¶
ListZipFiles returns a list of all file names in a zip archive.
func NormalizePath ¶
NormalizePath normalizes a file path, expanding tilde and cleaning it
func NumberedCopyBase ¶
NumberedCopyBase returns the base name if name looks like a "name (N)" duplicate (e.g. "foo (1)" -> "foo", true). A bare "(1)" is not a copy.
func Portabilize ¶
Portabilize replaces the user's home directory prefix with $HOME so paths remain valid across different environments.
func ProviderForPath ¶
func ProviderForPath(path string, folders []SyncFolder) string
ProviderForPath returns the provider whose sync root contains path, or "" if none does.
func ReadZipFile ¶
ReadZipFile reads a specific file from a zip archive without extracting
func RemoveFileFromZip ¶
RemoveFileFromZip removes a file from a zip archive
func RemoveFilesFromZip ¶
RemoveFilesFromZip returns a copy of zipData with every entry whose name is in names omitted. Unknown names are ignored.
func RemoveMarkdownSections ¶
RemoveMarkdownSections removes specified sections from markdown content
func RenameFileInZip ¶
RenameFileInZip rewrites zipData with oldName renamed to newName. It is a no-op when oldName is absent or already equals newName. If newName already exists alongside oldName, the existing newName entry is dropped in favor of the renamed oldName (matches the "replace if collision" behavior of AddFileToZip).
func ReplaceFileInZip ¶
ReplaceFileInZip replaces an existing file in a zip archive This is an alias for AddFileToZip which already handles replacement
func ResolveArgs ¶
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 ¶
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 ¶
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 ¶
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 UnmarshalJSONC ¶
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 ¶
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 ¶
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 ¶
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.
type SyncFolder ¶
type SyncFolder struct {
Provider string // "Google Drive", "Dropbox", "OneDrive", "iCloud Drive"
Path string // absolute path to the sync root
}
SyncFolder is a detected cloud-synced folder root on this machine.
func DetectSyncFolders ¶
func DetectSyncFolders() []SyncFolder
DetectSyncFolders returns the cloud-sync roots that exist on this machine, in a stable provider order with duplicates removed.
type ZipEntry ¶
ZipEntry summarizes one file in a zip archive without decompressing it. “Size“ is the uncompressed size as recorded in the local file header, suitable for inventory listings that don't need to read the body.
func ListZipEntries ¶
ListZipEntries returns name + uncompressed size for every file in the archive, reading only the central directory. Lets callers build an inventory (e.g. an MCP “bundled_files“ payload) without paying the cost of decompressing every entry.