packagecontent

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Ports packages/coding-agent/src/core/package-manager.ts.

Package packagecontent discovers resources exposed by Pi packages and cross-harness plugin manifests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyConfiguredDelta

func ApplyConfiguredDelta(kind Kind, relativePaths, basePatterns, deltaPatterns []string) ([]string, error)

ApplyConfiguredDelta validates and resolves exact Package-relative selector overrides. Authored autoload-disabled filters use ApplyAutoloadDisabledPatterns.

func ApplyPatterns

func ApplyPatterns(allPaths, patterns []string, baseDir string, kind Kind) []string

ApplyPatterns applies allowlist, exclude, force-include, and force-exclude patterns without changing input order.

func Collect

func Collect(paths []string, kind Kind) []string

Collect expands files or conventional resource directories for kind.

func Deduplicate

func Deduplicate(values []string) []string

Deduplicate removes empty and repeated strings without changing order.

func DiscoverAgentSkillDirs

func DiscoverAgentSkillDirs(dir string) []string

DiscoverAgentSkillDirs applies the cross-agent `.agents/skills` convention: root Markdown files are documentation, while nested Markdown files are standalone skills.

func DiscoverAutomatic

func DiscoverAutomatic(dir string, kind Kind) []string

DiscoverAutomatic returns resources in one conventional resource directory.

func DiscoverSkillDirs

func DiscoverSkillDirs(dir string) []string

DiscoverSkillDirs recursively discovers skill roots and root-level Markdown skills. A directory containing SKILL.md is one skill and is not traversed further. Symlinked files and directories are followed, while hidden entries, node_modules, and paths excluded by .gitignore, .ignore, or .fdignore are skipped.

func EnabledByOverrides

func EnabledByOverrides(resourcePath string, patterns []string, baseDir string, kind Kind) bool

EnabledByOverrides reports whether one automatically discovered path remains active after configured overrides.

func FilterAutomatic

func FilterAutomatic(paths, overrides []string, baseDir string, kind Kind) []string

FilterAutomatic applies configured overrides to automatically discovered paths.

func FindMember

func FindMember(resources Resources, kind Kind, name string) (string, error)

FindMember selects one discovered resource by public kind/name identity. pig additive (D18): named Piglet Package origins require stable member identity across exact and conventional Package resources. Extension source paths and Skill frontmatter are authoritative.

func FindSourceMember

func FindSourceMember(root string, kind Kind, name string) (string, error)

source may itself be one resource or a package/plugin root containing it.

func HasPiManifest

func HasPiManifest(root string) bool

HasPiManifest reports whether root's package.json has a "pi" object, which makes upstream resolve root as a Package (readPiManifest).

func InspectConfigured

func InspectConfigured(root string, filters map[Kind][]string) (Resources, []MissingMember, error)

InspectConfigured returns the discovery inventory, including safe declarations whose files are missing. It uses discovery's tolerant manifest parsing and validates lexical, absolute-path, glob, and symlink boundaries. Missing declarations are data so pig config can disable them; ValidateConfigured remains strict for explicit validation.

func InspectConfiguredWithResolver

func InspectConfiguredWithResolver(root string, filters map[Kind][]string, resolve extsource.ResolveFunc) (Resources, []MissingMember, error)

InspectConfiguredWithResolver returns the configured inventory while using resolve for extension validation. It preserves InspectConfigured semantics while allowing startup to reuse its source-resolution snapshot.

func PublicName

func PublicName(kind Kind, resourcePath, packageName string) (string, error)

PublicName returns the stable kind/name identity for one Package resource. PackageName supplies the fallback identity for a root Dev Container.

func ResolveConfigured

func ResolveConfigured(entries []string, baseDir string, kind Kind) []string

ResolveConfigured expands configured paths and applies their include/exclude patterns relative to baseDir. It returns nil if a path cannot be resolved. Use ResolveConfiguredWithError when resolution errors must be surfaced.

func ResolveConfiguredWithError

func ResolveConfiguredWithError(entries []string, baseDir string, kind Kind) ([]string, error)

ResolveConfiguredWithError expands configured paths and applies their include/exclude patterns relative to baseDir. Invalid file URLs return Node's error, as Pi's resolveLocalEntries does.

func ResourceEnabled

func ResourceEnabled(relativePath string, patterns []string) bool

ResourceEnabled applies the shared include, exclude, exact force-include, and exact force-exclude rules to one package-relative resource path. A nil filter enables the resource; an explicit empty filter disables it.

func SkillFile

func SkillFile(resourcePath string) string

SkillFile returns the Markdown file that defines the skill at resourcePath: resourcePath itself when it is a file, as a declared SKILL.md or a root-level Markdown skill is, else the SKILL.md inside the skill directory.

func SplitPatterns

func SplitPatterns(entries []string) (plain, patterns []string)

SplitPatterns separates literal entries from glob and override entries.

func ValidateConfiguredEntries

func ValidateConfiguredEntries(entries []string, baseDir string) error

ValidateConfiguredEntries resolves the plain entries of a settings resource array without reading the filesystem and returns the first resolution error.

func ValidateConfiguredForStartup

func ValidateConfiguredForStartup(root string, filters map[Kind][]string) (Resources, []MissingMember, []ExtensionIssue, error)

ValidateConfiguredForStartup uses discovery's tolerant manifest parsing, then checks the enabled resources. Invalid JSON falls back to conventions and malformed Pi fields declare no members, without a diagnostic. Missing declarations and unresolvable extensions are returned separately so callers can continue loading other resources. Each enabled extension resolves once.

func ValidateConfiguredForStartupWithResolver

func ValidateConfiguredForStartupWithResolver(root string, filters map[Kind][]string, resolve extsource.ResolveFunc) (Resources, []MissingMember, []ExtensionIssue, error)

ValidateConfiguredForStartupWithResolver applies startup validation using resolve for extension source classification. A startup-owned resolver can therefore share the exact Definition or error with later loading.

func ValidateMember

func ValidateMember(root string, kind Kind, resourcePath string) error

ValidateMember validates one explicitly selected Package member.

func ValidatePackageManifestSyntax

func ValidatePackageManifestSyntax(data []byte) error

ValidatePackageManifestSyntax checks the typed Package manifest boundary without resolving members. It is used before authoring edits so malformed existing fields are never silently discarded or rewritten.

Types

type ExtensionIssue

type ExtensionIssue struct {
	Path string
	Err  error
}

ExtensionIssue is one enabled Package extension whose source does not resolve to a loadable extension.

type Kind

type Kind string

Kind identifies a discoverable package resource class.

const (
	Extensions        Kind = "extensions"
	Skills            Kind = "skills"
	Prompts           Kind = "prompts"
	Themes            Kind = "themes"
	Agents            Kind = "agents"
	MCP               Kind = "mcp"
	Hooks             Kind = "hooks"
	AgentEnvironments Kind = "agent-environments"
)

type MissingMember

type MissingMember struct {
	Kind    Kind
	Path    string
	Pattern string
	Enabled bool
}

MissingMember is one safe authored Package declaration that currently resolves to no file. Configuration UIs use it to recover by disabling the normal Package filter without treating the declaration as a runtime resource.

type PatternState

type PatternState struct {
	Path    string
	Enabled bool
}

PatternState retains the first-match insertion order of upstream's path-to-enabled Map.

func ApplyAutoloadDisabledPatterns

func ApplyAutoloadDisabledPatterns(allPaths, patterns []string, baseDir string, kind Kind) []PatternState

ApplyAutoloadDisabledPatterns returns only paths touched by a pattern, with later patterns replacing their state. Plus/minus match exact paths; other entries use glob matching.

type PiManifest

type PiManifest struct {
	Extensions []string
	Skills     []string
	Prompts    []string
	Themes     []string
}

PiManifest mirrors upstream pi-manifest.ts PiManifest: the resource lists a package.json "pi" object declares. A nil field was absent or malformed.

func ReadPiManifest

func ReadPiManifest(packageJSONPath string) *PiManifest

ReadPiManifest mirrors upstream readPiManifest. It returns nil when the file cannot be read or parsed, or when the package or its "pi" value is not a JSON object. A resource field is kept only when it is an array of strings.

type ResourceState

type ResourceState struct {
	Path    string
	Enabled bool
}

ResourceState is a resource path and whether the configured patterns enable it.

func AutomaticStates

func AutomaticStates(paths, overrides []string, baseDir string, kind Kind) []ResourceState

AutomaticStates lists automatically discovered paths with whether the overrides leave each enabled (package-manager.ts addAutoDiscoveredResources).

func ResolveConfiguredStates

func ResolveConfiguredStates(entries []string, baseDir string, kind Kind) []ResourceState

ResolveConfiguredStates lists every resource the plain entries resolve, in collection order, with whether the patterns keep it (package-manager.ts resolveLocalEntries adds all files, then marks those the patterns enable).

type Resources

type Resources struct {
	PackageName       string
	PromptFiles       []string
	ThemeFiles        []string
	SkillDirs         []string
	ExtensionEntries  []string
	AgentFiles        []string
	MCPFiles          []string
	HookFiles         []string
	AgentEnvironments []string
}

Resources is the resource inventory discovered from one materialized source root.

func Discover

func Discover(root string) (Resources, error)

Discover returns the package and plugin resources exposed by root. A Pi package.json supplies every Pi resource kind when it has a pi block; plugin metadata supplies Pi kinds only without that block. Missing or malformed manifests fall back to conventional directory discovery.

func Validate

func Validate(root string) (Resources, error)

Validate checks a source inventory and its portable local file closure. A source without package.json remains valid for direct-resource installation.

func ValidateConfigured

func ValidateConfigured(root string, filters map[Kind][]string) (Resources, error)

ValidateConfigured validates only resources enabled by installed Package filters. Authored Package validation remains strict through ValidatePackage.

func ValidatePackage

func ValidatePackage(root string) (Resources, error)

ValidatePackage checks a Package manifest, inventory, public identities, and portable local closure. Unlike Validate, package.json and its name are required.

func ValidatePackageManifest

func ValidatePackageManifest(root string, data []byte) (Resources, error)

ValidatePackageManifest validates prospective package.json data without writing it. Package authoring uses this before atomically replacing a manifest so a failed operation cannot leave invalid state behind.

Jump to

Keyboard shortcuts

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