packagemanager

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 32 Imported by: 0

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

View Source
const UpdateCheckNetworkTimeout = 10 * time.Second

Network timeout for update checks. Mirrors upstream NETWORK_TIMEOUT_MS (package-manager.ts).

Variables

View Source
var GlobalNpmRoots struct {
	// contains filtered or unexported fields
}

Functions

func AmbientSourceEnabled

func AmbientSourceEnabled(ambientScopes *[]string, source string) bool

func ApplyPackageAutoloadStates

func ApplyPackageAutoloadStates(pkg ConfiguredPackage, items []tui.ResourceItem) ([]tui.ResourceItem, error)

Ports packages/coding-agent/src/core/package-manager.ts (applyPackageDeltaFilter, findAutoloadDeltaBase, addResource). ApplyPackageAutoloadStates keeps only touched resources in first-match order, including disabled resources that shadow inherited entries (applyPackageDeltaFilter, package-manager.ts:2308-2324). A pattern minimatch cannot compile stops at its kind: the items of the kinds before it come back with a *packagecontent.PackagePatternError.

func CleanAndInstallGitDependencies

func CleanAndInstallGitDependencies(checkout, packageRoot, marker string, sm *codingagent.SettingsManager, opts ...InstallOption) error

CleanAndInstallGitDependencies is cleanAndInstallGitDependencies. Pi e3da248e (#11648, fixes #11597) no longer aborts the update when `git clean -fdx` fails (on Windows a file another pi session holds open cannot be deleted). It warns through the progress callback, still installs the dependencies and keeps the update marker so the next update retries the clean.

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 DescribePackageInstallFailure

func DescribePackageInstallFailure(failure PackageInstallFailure) string

DescribePackageInstallFailure describes a Package that was skipped because it could not be installed, including how to drop it: a temporary -e source says to check the source, a configured Package names `<app> remove <source>` (with --local for a project Package).

func DetectSourceKind

func DetectSourceKind(source string) string

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.

Ports packages/coding-agent/src/core/package-manager.ts (isOfflineModeEnabled, resolvePackageSources missing-source installation).

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, opts ...InstallOption) error

func EnsureManagedCheckoutRoot

func EnsureManagedCheckoutRoot(root string) error

func EnsureManagedPackageRoot

func EnsureManagedPackageRoot(root string) error

EnsureManagedPackageRoot creates a managed npm project at root (package-manager.ts ensureNpmProject). root must be absolute.

func FinishPackageProgress

func FinishPackageProgress(callback ProgressCallback, action, source string, err error) error

func FormatPackageInstallWarning

func FormatPackageInstallWarning(failure PackageInstallFailure) string

FormatPackageInstallWarning is the one-line startup warning for a Package that could not be installed.

func FormatPackageUpdates

func FormatPackageUpdates(updates []PackageUpdate) string

FormatPackageUpdates formats a list of available updates for display. Mirrors upstream showPackageUpdateNotification's body.

func GetGitDependencyInstallArgs

func GetGitDependencyInstallArgs(sm *codingagent.SettingsManager, opts ...InstallOption) ([]string, error)

GetGitDependencyInstallArgs selects the install arguments of a Git package's dependencies from the package manager the npmCommand names, without auto-installing peer dependencies. Ports packages/coding-agent/src/core/package-manager.ts (getGitDependencyInstallArgs). Ports .upstream/v0.99.1/packages/coding-agent/src/core/package-manager.ts:1821-1838 (getGitDependencyInstallArgs).

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 GetLatestNpmVersion

func GetLatestNpmVersion(cwd string, sm *codingagent.SettingsManager, source sourceref.Ref, local bool) (string, error)

Ports packages/coding-agent/src/core/package-manager.ts (GetLatestNpmVersion, shouldUpdateNpmSource, npmHasAvailableUpdate). GetLatestNpmVersion retains the selected command and user configuration. D79 isolates user-package lookups from the invoking project's npmrc.

func GetLegacyGlobalNpmInstallPath

func GetLegacyGlobalNpmInstallPath(sm *codingagent.SettingsManager, packageName string) string

GetLegacyGlobalNpmInstallPath follows Pi's pnpm lookup, then its global-root fallback.

func GetNpmVersionRange

func GetNpmVersionRange(version string) string

Ports packages/coding-agent/src/core/package-manager.ts (getNpmVersionRange, installedNpmMatchesConfiguredVersion, getInstalledNpmVersion). 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 GitCheckoutPath(cwd, agentDir, source string, local bool) (string, error)

func GitCheckoutRelative

func GitCheckoutRelative(goos, root string, ref sourceref.Ref) (string, error)

GitCheckoutRelative is a Git source's checkout directory below the install root: its host, then its repository path, as Pi lays it out.

pig additive (D18): a file:// source is not a Pi source, and nesting its whole absolute path under the install root can push $GIT_DIR past Git for Windows' own PATH_MAX, which core.longpaths does not lift. Its checkout is <host>/<12 hex of sha256(absolute repo path)>/<basename> instead; the leaf stays the repository name because a direct extension takes its identity from its directory name. An older nested file:// checkout is not read or migrated; it is cloned again.

Windows cannot name a directory with ':', and NTFS reads name:stream as an alternate data stream, so there any segment containing ':' is refused.

func GitCloneRepo

func GitCloneRepo(goos, repo string) string

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 GitHasAvailableUpdate

func GitHasAvailableUpdate(installedPath string) bool

Ports packages/coding-agent/src/core/package-manager.ts (gitHasAvailableUpdate, getRemoteGitHead, getGitUpstreamRef, runGitRemoteCommand, parseNpmSpec). GitHasAvailableUpdate compares local HEAD against remote HEAD via `git ls-remote`. Mirrors upstream GitHasAvailableUpdate.

func GitInstallPath

func GitInstallPath(cwd, agentDir, source string, local bool) (string, error)

func GitLongPathsEnv

func GitLongPathsEnv(goos string, env []string) []string

GitLongPathsEnv is env with git's core.longpaths enabled for one process on Windows, which limits a path to MAX_PATH (260) unless told otherwise; a local file:// Git source's checkout path embeds the whole source path and can pass it. Git reads the setting from GIT_CONFIG_COUNT/KEY_n/VALUE_n (git 2.31+), so the command line stays Pi's and no config file is written; it is appended after any entries the environment already carries, and elsewhere env is returned unchanged. pig additive (D18): upstream rejects file:// sources.

func GitUpdateMarkerPath

func GitUpdateMarkerPath(checkout string) string

func InstallGitCheckout

func InstallGitCheckout(sm *codingagent.SettingsManager, ref sourceref.Ref, checkout, packageRoot, root string, opts ...InstallOption) (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, opts ...InstallOption) error

func InstallManagedGit

func InstallManagedGit(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool, opts ...InstallOption) (err error)

func InstallManagedNPM

func InstallManagedNPM(cwd, agentDir string, sm *codingagent.SettingsManager, source string, local bool, opts ...InstallOption) 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

func InstalledNpmMatchesConfiguredVersion(source sourceref.Ref, installedPath string) bool

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

func IsDriveSegment(segment string) bool

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 IsPinnedNpm

func IsPinnedNpm(source string) bool

IsPinnedNpm reports whether a source specifies an exact semantic version, rather than a mutable tag or range.

func IsProjectPackageDelta

func IsProjectPackageDelta(pkg codingagent.PackageSource) bool

func IsWithin

func IsWithin(path, base string) bool

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 LatestNpmVersionFromJSON

func LatestNpmVersionFromJSON(data []byte, version string) (string, error)

LatestNpmVersionFromJSON reads npm view's version output as Pi's GetLatestNpmVersion does: a single version is returned as is, and a list yields its maxSatisfying version for a valid range or its highest version otherwise.

func NpmInstallArgs

func NpmInstallArgs(manager, spec, installRoot, registry string, opts ...InstallOption) []string

func NpmInstallPath

func NpmInstallPath(cwd, agentDir string, sm *codingagent.SettingsManager, ref sourceref.Ref, local bool) string

func NpmInstallRoot

func NpmInstallRoot(cwd, agentDir string, ref sourceref.Ref, local bool) string

func NpmPackagePath

func NpmPackagePath(root string, source sourceref.Ref) string

func PackageCaptureExitStatus

func PackageCaptureExitStatus(state *os.ProcessState) string

func PackageInstallWarnings

func PackageInstallWarnings(failures ...[]PackageInstallFailure) []codingagent.ExtensionWarning

PackageInstallWarnings are the extension warnings of the failures, one per Package, keyed by its source (resource-loader.ts collectPackageInstallWarnings).

func PackageManagerName

func PackageManagerName(command []string) (string, error)

PackageManagerName names the package manager an npmCommand argv runs: the command after the last `--`, else the command itself when it is npm, pnpm or bun, else the single supported package manager among its arguments (for example `corepack pnpm`). It only reads the argv and never runs it. An absent or empty argv is npm. Ports .upstream/v0.99.1/packages/coding-agent/src/core/package-manager.ts:1780-1815 (getNpmCommand, getPackageManagerName).

func PackageResourceCount

func PackageResourceCount(r packagecontent.Resources) int

PackageResourceCount counts the resources a package contributes.

func PackageResourceItemsFromInventory

func PackageResourceItemsFromInventory(root string, pkg ConfiguredPackage, resources packagecontent.Resources, missing []packagecontent.MissingMember, filters map[packagecontent.Kind][]string) ([]tui.ResourceItem, error)

PackageResourceItemsFromInventory lists a Package's resources with the enabled state its configured filters give each, kind by kind in Pi's order (collectPackageResources, package-manager.ts:2214-2236). A filter's patterns match each absolute path against the Package root, as applyPackageFilter does; a skill is matched by its SKILL.md. A pattern minimatch cannot compile stops at its kind: the items of the kinds before it come back with a *packagecontent.PackagePatternError.

func PackageScopeEnabled

func PackageScopeEnabled(ambientScopes *[]string, scope string) bool

func PackageSourceIdentity

func PackageSourceIdentity(baseDir, raw string) string

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

func PackageSourceIdentityChecked(baseDir, raw string) (string, error)

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

func PackageSourcesMatch(cwd, baseDir, stored, input string) (bool, error)

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 ParseNpmInstallRef

func ParseNpmInstallRef(source string) (sourceref.Ref, error)

func PruneEmptyGitParents

func PruneEmptyGitParents(checkout, root string) error

func ReadInstalledNpmVersion

func ReadInstalledNpmVersion(installedPath string) string

func RealInstallRoot

func RealInstallRoot(root string) (string, error)

RealInstallRoot is the install root npm gets as --prefix: its real path when it exists, itself otherwise (package-manager.ts getNpmInstallArgs, realpathSync: on Windows the spelling of a component that is not a link, 8.3 short names included, is kept). npm writes broken nested package-lock.json paths when --prefix goes through a symlink, such as a ~/.pi linked into a dotfiles repository; every later install would nest one level deeper.

func RemoveGitUpdateMarker

func RemoveGitUpdateMarker(marker string) error

func RepairMissingGitDependencies

func RepairMissingGitDependencies(packageRoot string, sm *codingagent.SettingsManager, opts ...InstallOption) error

func RequireGitSubdirectoryWithinCheckout

func RequireGitSubdirectoryWithinCheckout(checkout, packageRoot string) error

func ResolveBuiltinExtensionSources

func ResolveBuiltinExtensionSources(sources []string, scope string) (builtin []tui.ResourceItem, others []string)

ResolveBuiltinExtensionSources resolves the `builtin:<name>` entries of sources, the `-e` paths, as enabled built-in extension resources of scope, and returns the other sources unchanged. The resource loader reports an unknown name. Ports .upstream/v0.99.1/packages/coding-agent/src/core/package-manager.ts:996-1006 (resolveExtensionSources).

func ResolveBuiltinExtensions

func ResolveBuiltinExtensions(sm *codingagent.SettingsManager, names []string) ([]tui.ResourceItem, error)

ResolveBuiltinExtensions resolves each built-in extension name as a `builtin:<name>` extension resource, in name order: a matching `+`, `-` or `!` entry of the project setting decides it, and otherwise it is enabled unless the user `extensions` setting excludes it, for example with `-builtin:mcp`. The user setting is read only for a name the project setting leaves alone, so only then can its pattern fail; a pattern minimatch cannot compile returns the items before it with the error Pi's resolve() rejects with. Ports .upstream/v0.99.1/packages/coding-agent/src/core/package-manager.ts:970-986 (DefaultPackageManager.resolve).

func ResolveInputPackageSourceRoot

func ResolveInputPackageSourceRoot(cwd, agentDir string, sm *codingagent.SettingsManager, source string) (string, error)

func ResolveLocalPackageRoot

func ResolveLocalPackageRoot(baseDir, source string) (string, error)

func ResolveManagedPackagePath

func ResolveManagedPackagePath(root string, parts ...string) (string, error)

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 ResolveTemporarySource

func ResolveTemporarySource(cwd, agentDir string, sm *codingagent.SettingsManager, source string, progress ProgressCallback) (string, error)

Ports packages/coding-agent/src/core/package-manager.ts (resolvePackageSources with the temporary scope). ResolveTemporarySource resolves temporary Packages before loading their extensions. Offline sources that need installation contribute no resources. Cached unpinned Git sources, and cached unpinned npm sources whose registry has a newer version, refresh before discovery; a failed refresh retains the cache, while an initial installation failure is surfaced.

func RunCmd

func RunCmd(name string, args ...string) (string, error)

func RunCmdInDir

func RunCmdInDir(dir, name string, args ...string) (string, error)

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

func RunPackageCapture(dir, name string, args ...string) (string, error)

RunPackageCapture bounds metadata queries by Pi's network timeout and keeps their output off the command's inherited streams.

func RunPackageProcess

func RunPackageProcess(dir, name string, args ...string) error

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 RunWithTimeout

func RunWithTimeout(cmd *exec.Cmd, timeout time.Duration) (string, error)

RunWithTimeout captures a command and waits for child/output cleanup before returning, including after a timeout. Mirrors packages/coding-agent/src/core/package-manager.ts:runCommandCapture.

func SettingsBaseDir

func SettingsBaseDir(cwd, agentDir string, local bool) string

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 TemporaryGitCheckoutPath

func TemporaryGitCheckoutPath(agentDir string, ref sourceref.Ref) (string, error)

TemporaryGitCheckoutPath is a temporary Git source's checkout below the agent temporary extension root; paths outside that root are refused. Ports .upstream/v0.99.1/packages/coding-agent/src/core/package-manager.ts:2153-2183 (getGitInstallPath, getTemporaryDir).

func TemporaryPackagePath

func TemporaryPackagePath(agentDir, prefix, suffix string) (string, error)

func TerminatePackageCapture

func TerminatePackageCapture(process *os.Process)

Ports packages/coding-agent/src/core/package-manager.ts (spawnCaptureCommand, runCommandCapture child termination and exit status). Node child.kill() defaults to SIGTERM and leaves settlement to the close event.

func ValidateConfiguredPackagePatterns

func ValidateConfiguredPackagePatterns(cwd, agentDir string, sm *codingagent.SettingsManager) error

ValidateConfiguredPackagePatterns returns the first pattern error of an installed npm or git Package, in Pi's resolution order (Project Packages first): a manifest glob that Node's globSync throws for, or a manifest override or configured filter that minimatch cannot compile. Pi collects such a Package's resources outside any catch (resolvePackageSources, package-manager.ts:1315-1342), so the throw rejects resolve(); a local Package's throw is caught and drops only its own kinds. A Package that still needs installation contributes nothing here.

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, applies each array's patterns, then checks the auto-discovered resources against the arrays' overrides, and returns the first 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 GitPackageSource

type GitPackageSource struct {
	Host   string
	Path   string
	Ref    string
	Pinned bool
}

GitPackageSource is the host, repository path and ref of a Git package source.

func ParseGitPackageSource

func ParseGitPackageSource(source string) (GitPackageSource, bool)

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 InstallFailureError

type InstallFailureError struct{ Err error }

InstallFailureError is the error of an install step of a source that resolving skips instead of failing on (Pi 6dfb54678: installMissing catches installParsedSource).

func (*InstallFailureError) Error

func (e *InstallFailureError) Error() string

func (*InstallFailureError) Unwrap

func (e *InstallFailureError) Unwrap() error

type InstallOption

type InstallOption func(*installOptions)

InstallOption adjusts how one managed install runs its package manager. With no option an install behaves as Pi's does.

func WithIgnoreScripts

func WithIgnoreScripts() InstallOption

WithIgnoreScripts runs the package manager with `--ignore-scripts`, so no lifecycle script of the installed Package or of its dependencies runs during the install. Npm, pnpm and bun accept the same flag.

pig additive (D194): Piglet resolution installs Packages without running lifecycle scripts unless the user opts in.

func WithProgressReporter

func WithProgressReporter(progress ProgressCallback) InstallOption

WithProgressReporter receives the progress events a managed Git install raises while it runs, such as the warning for a failed `git clean`. Pi's package manager emits them through the callback set with setProgressCallback.

type MissingSourceAction

type MissingSourceAction string

MissingSourceAction is what MissingSourceCallback decides for a Package that is not installed (package-manager.ts MissingSourceAction).

const (
	// MissingSourceInstall installs the Package.
	MissingSourceInstall MissingSourceAction = "install"
	// MissingSourceSkip leaves the Package out of the result.
	MissingSourceSkip MissingSourceAction = "skip"
	// MissingSourceError fails the resolution.
	MissingSourceError MissingSourceAction = "error"
)

type MissingSourceCallback

type MissingSourceCallback func(source string) (MissingSourceAction, error)

MissingSourceCallback is the onMissing argument of PackageManager.Resolve.

type PackageInstallFailure

type PackageInstallFailure struct {
	Source string
	// Scope is "user", "project" or "temporary".
	Scope string
	// Path is the resolved directory of a local Package; empty when the source did not resolve to one.
	Path    string
	Message string
}

PackageInstallFailure is a configured Package that could not be installed while resolving resources (package-manager.ts PackageInstallFailure).

func MissingLocalPackages

func MissingLocalPackages(cwd, agentDir string, sm *codingagent.SettingsManager) []PackageInstallFailure

MissingLocalPackages lists each configured local Package whose directory does not exist, resolved against its scope's settings directory, as the install failure the session warns about and `pig install --validate-only` reports (D216). Pi skips such a Package without a word.

type PackageManager

type PackageManager struct {
	CWD             string
	SettingsManager *codingagent.SettingsManager
	// AgentDir is upstream's agentDir option; empty uses the settings manager's agent directory.
	AgentDir string
	// BuiltinExtensions are the names of built-in extensions that Resolve reports as `builtin:<name>` extension resources (upstream's builtinExtensions option).
	BuiltinExtensions []string
	// contains filtered or unexported fields
}

PackageManager is upstream's PackageManager interface and DefaultPackageManager class (package-manager.ts): it installs, removes and lists the packages named in the user and project settings. CWD is the project directory the sources resolve against.

func NewPackageManager

func NewPackageManager(options PackageManagerOptions) *PackageManager

NewPackageManager is upstream's `new DefaultPackageManager(options)` (package-manager.ts:821).

func (*PackageManager) AddSourceToSettings

func (m *PackageManager) AddSourceToSettings(source string, local bool) (bool, error)

AddSourceToSettings is upstream's addSourceToSettings. It reports whether it adds a source or replaces its ref, retaining filters and avoiding writes for identical sources.

func (*PackageManager) CheckForAvailableUpdates

func (m *PackageManager) CheckForAvailableUpdates() []PackageUpdate

CheckForAvailableUpdates queries npm registry and git remotes for updates to installed, unpinned packages with at most five joined workers. It returns a non-nil slice, including when offline or no updates are available. Mirrors upstream DefaultPackageManager.checkForAvailableUpdates (packages/coding-agent/src/core/package-manager.ts:1186-1253). User-package metadata uses managed storage (D79); trusted project packages use cwd.

func (*PackageManager) ConfiguredGitCheckoutInUse

func (m *PackageManager) ConfiguredGitCheckoutInUse(removedSource string, local bool) bool

ConfiguredGitCheckoutInUse reports whether another configured source of the same scope shares the Git checkout of removedSource.

func (*PackageManager) ConfiguredSources

func (m *PackageManager) ConfiguredSources() []ConfiguredPackage

ConfiguredSources lists the configured packages without resolving installed paths: the update path reads sources, not installation paths, so pinned entries must not run legacy-root lookups.

func (*PackageManager) GetInstalledPath

func (m *PackageManager) GetInstalledPath(source, scope string) string

GetInstalledPath is upstream's getInstalledPath: where the source is installed for the scope ("user" or "project"), or "" when it is not.

func (*PackageManager) Install

func (m *PackageManager) Install(source string, local bool) error

Install is upstream's install: it places the package artifacts without recording the source in settings.

func (*PackageManager) InstallAndPersist

func (m *PackageManager) InstallAndPersist(source string, local bool) error

InstallAndPersist is upstream's installAndPersist: install, then record the source in settings.

func (*PackageManager) InstalledSourceRoot

func (m *PackageManager) InstalledSourceRoot(source string, local bool) string

InstalledSourceRoot returns the directory an install of source contributes, or "" when none exists. A local source is still the path as typed, relative to the project directory; only the settings record rebases it onto the settings directory.

func (*PackageManager) ListConfiguredPackages

func (m *PackageManager) ListConfiguredPackages() []ConfiguredPackage

ListConfiguredPackages is upstream's listConfiguredPackages: user then project packages with their installed paths.

func (*PackageManager) NormalizeSourceForSettings

func (m *PackageManager) NormalizeSourceForSettings(baseDir, source string) string

NormalizeSourceForSettings stores a local package path typed relative (`./pkg`, `../pkg`) relative to the settings directory, matching upstream, and one typed absolute (`/abs/pkg`, `~/pkg`, a file:// URL) as typed.

func (*PackageManager) Remove

func (m *PackageManager) Remove(source string, local bool) error

Remove is upstream's remove: it deletes the installed artifacts and keeps the settings entry.

func (*PackageManager) RemoveAndPersist

func (m *PackageManager) RemoveAndPersist(source string, local bool) (bool, error)

RemoveAndPersist is upstream's removeAndPersist. It runs the removal with the caller's settings before persisting, so failures retain both the package record and command overrides.

func (*PackageManager) RemoveSourceFromSettings

func (m *PackageManager) RemoveSourceFromSettings(source string, local bool) (bool, error)

RemoveSourceFromSettings is upstream's removeSourceFromSettings (package-manager.ts:855-871). PackageSourcesMatch (:1428-1433) resolves the stored key and then the input key for each entry, so an invalid file: URL fails the removal with fileURLToPath's error once any package is configured.

func (*PackageManager) Resolve

func (m *PackageManager) Resolve(onMissing MissingSourceCallback) (ResolvedPaths, error)

Resolve is upstream's resolve: it resolves the Packages, settings entries and auto-discovered locations into the resources they enable, per resource type (package-manager.ts:920-985). Each Package that is not installed, or whose installation does not satisfy its configured version, is installed unless onMissing decides otherwise; a nil onMissing installs it, as DefaultPackageManager does. A local Package that does not exist, and every missing Package in offline mode, contributes nothing. The result lists each type's Package resources, settings entries and auto-discovered resources as a first-wins accumulator keyed by path, ordered by resourcePrecedenceRank. A skill is keyed by its SKILL.md file when it has one.

func (*PackageManager) ResolveExtensionSources

func (m *PackageManager) ResolveExtensionSources(sources []string, local, temporary bool) (ResolvedPaths, error)

ResolveExtensionSources is upstream's resolveExtensionSources: it resolves each source, an `-e` argument, into the extensions and other resources it exposes, in the scope "temporary", "project" or "user" that temporary and local select (package-manager.ts:991-1010). A `builtin:<name>` source is an enabled built-in extension. A local source that does not exist contributes nothing; an npm or git source that is not installed installs unless offline mode is on. A temporary source installs below the agent's temporary extension folder, and an unpinned cached git checkout refreshes first.

func (*PackageManager) SetProgressCallback

func (m *PackageManager) SetProgressCallback(callback ProgressCallback)

SetProgressCallback is upstream's setProgressCallback: the callback every later install, remove and update reports to.

func (*PackageManager) Update

func (m *PackageManager) Update(source string) error

Update is upstream's update: it refreshes every configured package that is not pinned, or the packages whose identity matches source.

func (*PackageManager) VerifyContributesResources

func (m *PackageManager) VerifyContributesResources(source string, local bool) error

VerifyContributesResources rejects an npm or Git source that resolves to a proven extension root Package discovery cannot load. A local source is never refused: a local directory that declares no Package resources loads as an extension itself (package-manager.ts:1377-1384).

type PackageManagerOptions

type PackageManagerOptions struct {
	CWD             string
	AgentDir        string
	SettingsManager *codingagent.SettingsManager
	// BuiltinExtensions are the names of built-in extensions, resolved as `builtin:<name>` extension resources.
	BuiltinExtensions []string
}

PackageManagerOptions is upstream's PackageManagerOptions (package-manager.ts:132-138).

type PackageUpdate

type PackageUpdate struct {
	Source      string // configured source string
	DisplayName string // human-readable name (npm package name or git org/repo)
	Type        string // "npm" or "git"
	Scope       string // "user" or "project"
}

PackageUpdate describes an available update for a configured package. Mirrors upstream PackageUpdate (package-manager.ts).

type ProgressCallback

type ProgressCallback func(ProgressEvent)

ProgressCallback runs synchronously before an operation starts and before its result returns.

type ProgressEvent

type ProgressEvent struct {
	Type    string
	Action  string
	Source  string
	Message *string
}

ProgressEvent describes one package operation. Completion omits Message.

type ResolvedPaths

type ResolvedPaths struct {
	Extensions []codingagent.ResolvedResource
	Skills     []codingagent.ResolvedResource
	Prompts    []codingagent.ResolvedResource
	Themes     []codingagent.ResolvedResource
	// InstallFailures lists the configured Packages that were skipped because installing them failed (package-manager.ts ResolvedPaths.installFailures, Pi 6dfb54678).
	InstallFailures []PackageInstallFailure
}

ResolvedPaths are the resources a resolution found, one list per resource type, in precedence order, each with the PathMetadata of its source (package-manager.ts ResolvedPaths).

Jump to

Keyboard shortcuts

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