Documentation
¶
Overview ¶
Package packagemanager resolves, installs and reads the Packages that settings configure. The CLI's package commands and startup, and the SDK's default resource loader, share it.
Index ¶
- Constants
- Variables
- func AmbientSourceEnabled(ambientScopes *[]string, source string) bool
- func ApplyPackageAutoloadStates(pkg ConfiguredPackage, items []tui.ResourceItem) []tui.ResourceItem
- func CleanAndInstallGitDependencies(checkout, packageRoot, marker string, sm *codingagent.SettingsManager) error
- func CollectEnabledPackagePaths(cwd, agentDir string, sm *codingagent.SettingsManager, ...) []string
- func CollectPackageResourceItems(root string, pkg ConfiguredPackage, inspect bool, ...) ([]tui.ResourceItem, error)
- func CollectResolvedPackageResourceItems(cwd, agentDir string, sm *codingagent.SettingsManager, ambientScopes *[]string, ...) ([]tui.ResourceItem, error)
- func ConfiguredExtensionResolver(resolvers []extsource.ResolveFunc) extsource.ResolveFunc
- func ConfiguredPackageFilters(source codingagent.PackageSource) map[packagecontent.Kind][]string
- func ConfiguredPackageNeedsInstall(pkg ConfiguredPackage) bool
- func DefaultNpmCommand(sm *codingagent.SettingsManager) []string
- func DetectSourceKind(source string) string
- func EmitProgress(callback ProgressCallback, event ProgressEvent)
- func EnsureConfiguredPackagesInstalled(cwd, agentDir string, sm *codingagent.SettingsManager) (reinstalled, missing []string)
- func EnsureGitRef(checkout, packageRoot string, sm *codingagent.SettingsManager, ...) error
- func EnsureManagedCheckoutRoot(root string) error
- func EnsureManagedPackageRoot(root string) error
- func FinishPackageProgress(callback ProgressCallback, action, source string, err error) error
- func GetGitDependencyInstallArgs(sm *codingagent.SettingsManager) []string
- func GetGlobalNpmRoot(sm *codingagent.SettingsManager) (string, error)
- func GetLegacyGlobalNpmInstallPath(sm *codingagent.SettingsManager, packageName string) string
- func GetNpmVersionRange(version string) string
- func GetPnpmGlobalPackagePath(sm *codingagent.SettingsManager, packageName string) (string, error)
- func GitCheckoutPath(cwd, agentDir, source string, local bool) (string, error)
- func GitCheckoutRelative(goos, root string, ref sourceref.Ref) (string, error)
- func GitCloneRepo(goos, repo string) string
- func GitInstallPath(cwd, agentDir, source string, local bool) (string, error)
- func GitUpdateMarkerPath(checkout string) string
- func InstallGitCheckout(sm *codingagent.SettingsManager, ref sourceref.Ref, ...) (err error)
- func InstallGitDependencies(packageRoot string, sm *codingagent.SettingsManager) error
- func InstallManagedGit(cwd, agentDir string, sm *codingagent.SettingsManager, source string, ...) (err error)
- func InstallManagedNPM(cwd, agentDir string, sm *codingagent.SettingsManager, source string, ...) error
- func InstallMissingPackages(cwd, agentDir string, sm *codingagent.SettingsManager) error
- func InstallPackageArtifacts(cwd, agentDir string, sm *codingagent.SettingsManager, ...) error
- func InstalledNpmMatchesConfiguredVersion(source sourceref.Ref, installedPath string) bool
- func InstalledPackageMatchesConfiguredVersion(pkg ConfiguredPackage) bool
- func InstalledPathForConfiguredSource(cwd, agentDir string, sm *codingagent.SettingsManager, source string, ...) string
- func InstalledPathForSource(cwd, agentDir string, sm *codingagent.SettingsManager, source string, ...) string
- func IsDriveSegment(segment string) bool
- func IsOfflineModeEnabled() bool
- func IsProjectPackageDelta(pkg codingagent.PackageSource) bool
- func IsWithin(path, base string) bool
- func NpmCommandName(cmd []string) string
- func NpmInstallArgs(manager, spec, installRoot, registry string) []string
- func NpmInstallPath(cwd, agentDir string, sm *codingagent.SettingsManager, ref sourceref.Ref, ...) string
- func NpmInstallRoot(cwd, agentDir string, ref sourceref.Ref, local bool) string
- func PackageCaptureExitStatus(state *os.ProcessState) string
- func PackageResourceItemsFromInventory(root string, pkg ConfiguredPackage, resources packagecontent.Resources, ...) []tui.ResourceItem
- func PackageScopeEnabled(ambientScopes *[]string, scope string) bool
- func PackageSourceIdentity(baseDir, raw string) string
- func PackageSourceIdentityChecked(baseDir, raw string) (string, error)
- func PackageSourcesMatch(cwd, baseDir, stored, input string) (bool, error)
- func ParseNpmInstallRef(source string) (sourceref.Ref, error)
- func PruneEmptyGitParents(checkout, root string) error
- func ReadInstalledNpmVersion(installedPath string) string
- func RemoveGitUpdateMarker(marker string) error
- func RepairMissingGitDependencies(packageRoot string, sm *codingagent.SettingsManager) error
- func RequireGitSubdirectoryWithinCheckout(checkout, packageRoot string) error
- func ResolveInputPackageSourceRoot(cwd, agentDir string, sm *codingagent.SettingsManager, source string) (string, error)
- func ResolveLocalPackageRoot(baseDir, source string) (string, error)
- func ResolveManagedPackagePath(root string, parts ...string) (string, error)
- func RunCmd(name string, args ...string) (string, error)
- func RunCmdInDir(dir, name string, args ...string) (string, error)
- func RunPackageCapture(dir, name string, args ...string) (string, error)
- func RunPackageProcess(dir, name string, args ...string) error
- func SettingsBaseDir(cwd, agentDir string, local bool) string
- func SourceRootForResources(cwd, agentDir string, sm *codingagent.SettingsManager, source string, ...) (string, error)
- func TerminatePackageCapture(process *os.Process)
- func ValidateConfiguredPackageSources(cwd, agentDir string, sm *codingagent.SettingsManager) error
- func ValidateConfiguredResourceEntries(cwd, agentDir string, sm *codingagent.SettingsManager) error
- func WithProgress(callback ProgressCallback, action, source, message string, ...) error
- type ConfiguredPackage
- type GitUpdateTarget
- type GlobalNpmRoot
- type ProgressCallback
- type ProgressEvent
Constants ¶
const UpdateCheckNetworkTimeout = 10 * time.Second
Network timeout for update checks. Mirrors upstream NETWORK_TIMEOUT_MS (package-manager.ts).
Variables ¶
var GlobalNpmRoots struct { // contains filtered or unexported fields }
Functions ¶
func AmbientSourceEnabled ¶
func ApplyPackageAutoloadStates ¶
func ApplyPackageAutoloadStates(pkg ConfiguredPackage, items []tui.ResourceItem) []tui.ResourceItem
ApplyPackageAutoloadStates keeps only touched resources in first-match order, including disabled resources that shadow inherited entries.
func CleanAndInstallGitDependencies ¶
func CleanAndInstallGitDependencies(checkout, packageRoot, marker string, sm *codingagent.SettingsManager) error
func CollectEnabledPackagePaths ¶
func CollectEnabledPackagePaths(cwd, agentDir string, sm *codingagent.SettingsManager, kind packagecontent.Kind, ambientScopes *[]string, resolvers ...extsource.ResolveFunc) []string
CollectEnabledPackagePaths lists the enabled paths of one resource kind that the configured Packages expose, in resolution order.
func CollectPackageResourceItems ¶
func CollectPackageResourceItems(root string, pkg ConfiguredPackage, inspect bool, resolvers ...extsource.ResolveFunc) ([]tui.ResourceItem, error)
func CollectResolvedPackageResourceItems ¶
func CollectResolvedPackageResourceItems(cwd, agentDir string, sm *codingagent.SettingsManager, ambientScopes *[]string, inspect bool, resolvers ...extsource.ResolveFunc) ([]tui.ResourceItem, error)
CollectResolvedPackageResourceItems preserves addResource's first entry, including its enabled state and metadata. Project deltas are resolved before inherited user packages, not merged into user filters.
func ConfiguredExtensionResolver ¶
func ConfiguredExtensionResolver(resolvers []extsource.ResolveFunc) extsource.ResolveFunc
func ConfiguredPackageFilters ¶
func ConfiguredPackageFilters(source codingagent.PackageSource) map[packagecontent.Kind][]string
func ConfiguredPackageNeedsInstall ¶
func ConfiguredPackageNeedsInstall(pkg ConfiguredPackage) bool
ConfiguredPackageNeedsInstall reports whether the Package has no installation or an installation that does not satisfy its configured version.
func DefaultNpmCommand ¶
func DefaultNpmCommand(sm *codingagent.SettingsManager) []string
DefaultNpmCommand uses the caller's resolved trust and overrides; helper calls must not reload project settings.
func DetectSourceKind ¶
func EmitProgress ¶
func EmitProgress(callback ProgressCallback, event ProgressEvent)
func EnsureConfiguredPackagesInstalled ¶
func EnsureConfiguredPackagesInstalled(cwd, agentDir string, sm *codingagent.SettingsManager) (reinstalled, missing []string)
EnsureConfiguredPackagesInstalled reinstalls missing installations and npm packages whose local manifest does not satisfy the configured version or range. Offline mode reports these sources as missing without installing them.
Returns the source strings that were reinstalled and the sources that remain unavailable because installation failed or offline mode prevented it. upstream: packages/coding-agent/src/core/package-manager.ts:resolvePackageSources
func EnsureGitRef ¶
func EnsureGitRef(checkout, packageRoot string, sm *codingagent.SettingsManager, target GitUpdateTarget) error
func FinishPackageProgress ¶
func FinishPackageProgress(callback ProgressCallback, action, source string, err error) error
func GetGitDependencyInstallArgs ¶
func GetGitDependencyInstallArgs(sm *codingagent.SettingsManager) []string
func GetGlobalNpmRoot ¶
func GetGlobalNpmRoot(sm *codingagent.SettingsManager) (string, error)
GetGlobalNpmRoot is Pi's getGlobalNpmRoot: the selected command's global root, reused until the npmCommand argv changes. An empty root is not reused, and a failed lookup keeps the previous entry.
func GetLegacyGlobalNpmInstallPath ¶
func GetLegacyGlobalNpmInstallPath(sm *codingagent.SettingsManager, packageName string) string
GetLegacyGlobalNpmInstallPath follows Pi's pnpm lookup, then its global-root fallback.
func GetNpmVersionRange ¶
GetNpmVersionRange is Pi's getNpmVersionRange: the node-semver range a selector denotes, or "" when it is absent or not a valid npm range, such as a dist tag.
func GetPnpmGlobalPackagePath ¶
func GetPnpmGlobalPackagePath(sm *codingagent.SettingsManager, packageName string) (string, error)
func GitCheckoutPath ¶
func GitCheckoutRelative ¶
GitCheckoutRelative is a Git source's checkout directory below the install root: its host, then its repository path. Windows cannot name a directory with ':', so there a file:// source's leading drive (C:) becomes the segment C, and any other segment containing ':' is refused, since NTFS reads name:stream as an alternate data stream.
func GitCloneRepo ¶
GitCloneRepo is the URL git clones for repo. Git for Windows reads file://localhost/C:/... as the UNC path //localhost/C:/..., so there a localhost file URL with a drive becomes the equivalent file:///C:/....
func GitUpdateMarkerPath ¶
func InstallGitCheckout ¶
func InstallGitCheckout(sm *codingagent.SettingsManager, ref sourceref.Ref, checkout, packageRoot, root string) (err error)
InstallGitCheckout shares update, dependency repair, and failed-clone cleanup between installed and temporary sources. An empty root leaves temporary-cache parents intact, as Pi does.
func InstallGitDependencies ¶
func InstallGitDependencies(packageRoot string, sm *codingagent.SettingsManager) error
func InstallManagedGit ¶
func InstallManagedGit(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool) (err error)
func InstallManagedNPM ¶
func InstallManagedNPM(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool) error
func InstallMissingPackages ¶
func InstallMissingPackages(cwd, agentDir string, sm *codingagent.SettingsManager) error
InstallMissingPackages installs each configured npm and git Package whose installation is absent or does not satisfy its configured version, as DefaultPackageManager.resolve installs a source when it has no onMissing callback (package-manager.ts:1251-1305). The first failed installation is returned. A local Package that does not exist is skipped, as resolveLocalExtensionSource skips it, and offline mode installs nothing.
func InstallPackageArtifacts ¶
func InstallPackageArtifacts(cwd, agentDir string, sm *codingagent.SettingsManager, pkg codingagent.PackageSource, local bool, progress ProgressCallback) error
func InstalledNpmMatchesConfiguredVersion ¶
InstalledNpmMatchesConfiguredVersion checks the local manifest only; dist tags and omitted versions never trigger registry lookups during resolution. upstream: packages/coding-agent/src/core/package-manager.ts:installedNpmMatchesConfiguredVersion
func InstalledPackageMatchesConfiguredVersion ¶
func InstalledPackageMatchesConfiguredVersion(pkg ConfiguredPackage) bool
InstalledPackageMatchesConfiguredVersion checks configured and temporary npm packages with the same local manifest rule. Inherited deltas use the source that owns their installation.
func InstalledPathForConfiguredSource ¶
func InstalledPathForConfiguredSource(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool) string
func InstalledPathForSource ¶
func InstalledPathForSource(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool) string
func IsDriveSegment ¶
IsDriveSegment reports whether segment is a Windows drive such as C:.
func IsOfflineModeEnabled ¶
func IsOfflineModeEnabled() bool
IsOfflineModeEnabled returns true when the PIG_OFFLINE (or legacy PI_OFFLINE) env var is set to a truthy value. Mirrors upstream isOfflineModeEnabled (package-manager.ts:29).
func IsProjectPackageDelta ¶
func IsProjectPackageDelta(pkg codingagent.PackageSource) bool
func IsWithin ¶
IsWithin is resource-loader.ts isUnderPath on the resolved path: the root itself, or a path under it, where a root that already ends in a separator (a drive or filesystem root) is not given another.
func NpmCommandName ¶
NpmCommandName uses the executable after the last --, preserves case, and removes only .cmd/.exe suffixes without spawning the command (Pi package-manager.ts:1760-1764).
func NpmInstallArgs ¶
func NpmInstallPath ¶
func NpmInstallPath(cwd, agentDir string, sm *codingagent.SettingsManager, ref sourceref.Ref, local bool) string
func NpmInstallRoot ¶
func PackageCaptureExitStatus ¶
func PackageCaptureExitStatus(state *os.ProcessState) string
func PackageResourceItemsFromInventory ¶
func PackageResourceItemsFromInventory(root string, pkg ConfiguredPackage, resources packagecontent.Resources, missing []packagecontent.MissingMember, filters map[packagecontent.Kind][]string) []tui.ResourceItem
func PackageScopeEnabled ¶
func PackageSourceIdentity ¶
PackageSourceIdentity centralizes upstream package identity and Pig contributed scheme identity. Identity matching follows upstream parseSource: an unprefixed value is local.
pig additive (D18): registered contributed source schemes participate in the same deterministic identity contract as upstream npm/git/local sources.
func PackageSourceIdentityChecked ¶
PackageSourceIdentityChecked is PackageSourceIdentity, except that a local file: URL fileURLToPath rejects returns that error unwrapped, as Pi's getPackageIdentity and getSourceMatchKey* throw it (package-manager.ts:1373-1393,1690-1705).
func PackageSourcesMatch ¶
PackageSourcesMatch ports package-manager.ts:1428-1433: the stored settings key, then the input key. Either throws fileURLToPath's error for an invalid file: URL.
func PruneEmptyGitParents ¶
func ReadInstalledNpmVersion ¶
func RemoveGitUpdateMarker ¶
func RepairMissingGitDependencies ¶
func RepairMissingGitDependencies(packageRoot string, sm *codingagent.SettingsManager) error
func ResolveInputPackageSourceRoot ¶
func ResolveInputPackageSourceRoot(cwd, agentDir string, sm *codingagent.SettingsManager, source string) (string, error)
func ResolveLocalPackageRoot ¶
func ResolveManagedPackagePath ¶
ResolveManagedPackagePath is package-manager.ts resolveManagedPath: path.resolve(resolve(root), ...parts), so an absolute component replaces the preceding root, then a check that the result is the root or starts with the root and a separator. Ports packages/coding-agent/src/core/package-manager.ts.
func RunCmdInDir ¶
RunCmdInDir is Pi's runCommandSync. It starts the command as upstream's spawnProcess does, so a Windows .cmd shim such as npm.cmd receives its arguments exactly, and returns the trimmed stdout, or stderr when stdout is empty, so a warning on stderr cannot corrupt a reported path.
func RunPackageCapture ¶
RunPackageCapture bounds metadata queries by Pi's network timeout and keeps their output off the command's inherited streams.
func RunPackageProcess ¶
Ports packages/coding-agent/src/core/package-manager.ts (spawnCommand, runCommand). RunPackageProcess inherits child output without retaining it. When the host owns stdout, both streams go to stderr and stdin is ignored. The caller waits for completion before reporting an error or persisting settings.
func SettingsBaseDir ¶
SettingsBaseDir is the directory a scope's package sources resolve against: the project config directory below cwd, or the agent directory (package-manager.ts getBaseDirForScope).
func SourceRootForResources ¶
func SourceRootForResources(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool) (string, error)
func TerminatePackageCapture ¶
Node child.kill() defaults to SIGTERM and leaves settlement to the close event.
func ValidateConfiguredPackageSources ¶
func ValidateConfiguredPackageSources(cwd, agentDir string, sm *codingagent.SettingsManager) error
ValidateConfiguredPackageSources resolves every local Package source against its scope's settings directory, Project Packages first, and returns the first resolution error. Pi's DefaultPackageManager.resolve dedupes the Packages with getPackageIdentity, which calls resolvePathFromBase outside any catch, before it installs or collects any, so a malformed file URL throws instead of being skipped (package-manager.ts:912-928, 1687-1717; utils/paths.ts:95-106). The settings manager exposes Project settings only for a trusted Project, so an untrusted Project contributes none.
func ValidateConfiguredResourceEntries ¶
func ValidateConfiguredResourceEntries(cwd, agentDir string, sm *codingagent.SettingsManager) error
ValidateConfiguredResourceEntries resolves every plain extension, skill, prompt and theme settings entry against its scope's settings directory and returns the first resolution error. Pi's resolve runs resolveLocalEntries after it has installed and collected the Packages, for each resource type in RESOURCE_TYPES order with the Project entries before the user ones, and its resolvePathFromBase throws on a malformed file URL (package-manager.ts:204, 933-959, 2340).
func WithProgress ¶
func WithProgress(callback ProgressCallback, action, source, message string, operation func() error) error
Types ¶
type ConfiguredPackage ¶
type ConfiguredPackage struct {
Source codingagent.PackageSource
Scope string
InstalledPath string
// ResolvedSource owns the inherited installation when a project delta retains a different metadata source.
ResolvedSource string
}
func ConfiguredPackagesForResolution ¶
func ConfiguredPackagesForResolution(cwd, agentDir string, sm *codingagent.SettingsManager) []ConfiguredPackage
func ResolvedConfiguredPackageSources ¶
func ResolvedConfiguredPackageSources(cwd, agentDir string, sm *codingagent.SettingsManager, resourceEntries bool) []ConfiguredPackage
ResolvedConfiguredPackageSources keeps separate project deltas for resource accumulation; installation consumers share the inherited user package.
type GitUpdateTarget ¶
type GitUpdateTarget struct {
// contains filtered or unexported fields
}
Ports packages/coding-agent/src/core/package-manager.ts (getLocalGitUpdateTarget, ensureGitRef, cleanAndInstallGitDependencies, repairMissingGitDependencies).
func GetLocalGitUpdateTarget ¶
func GetLocalGitUpdateTarget(checkout string) (GitUpdateTarget, error)
type GlobalNpmRoot ¶
type GlobalNpmRoot struct {
// contains filtered or unexported fields
}
GlobalNpmRoot is Pi's DefaultPackageManager globalNpmRoot and globalNpmRootCommandKey. Pi keeps that cache on each DefaultPackageManager, and creates fresh managers (with empty caches) around the same SettingsManager, for example for every interactive package-update check (interactive-mode.ts:1202-1206). Pig threads the SettingsManager itself through package resolution, so each SettingsManager owns one entry until it is collected; a later lookup with an unchanged command reuses the root where Pi would run it again. The mutex also holds concurrent lookups while the first runs the command, as Pi's synchronous spawn does.
func GlobalNpmRootFor ¶
func GlobalNpmRootFor(sm *codingagent.SettingsManager) *GlobalNpmRoot
type ProgressCallback ¶
type ProgressCallback func(ProgressEvent)
ProgressCallback runs synchronously before an operation starts and before its result returns.