Documentation
¶
Overview ¶
Package install implements `panda install` / `panda uninstall` / `panda doctor`: placing the binary on PATH (persistently, per-OS), and a whitelist-based uninstall that backs up and removes only OpenPanda-owned state while preserving user assets (projects, memory, skills, work) — unless the user passes --purge and survives its second confirmation.
Safety model: uninstall never walks the filesystem looking for things to delete. Every deletion candidate is derived from explicit inputs (the running executable, the install dir, the loaded config's storage paths) and validated against guardrails in Scan — a candidate that is empty, a filesystem root, the user's home, or overlaps a user-asset directory is flipped to "keep" with a reason. The user sees the full plan and must type `confirm` before anything is touched.
Index ¶
- Constants
- func AddToPATH(dir string) ([]string, error)
- func BackupZip(dest string, targets []Target) (int, error)
- func CopySelf(dst string) error
- func Dir() (string, error)
- func ExeName() string
- func InPATH(dir string) bool
- func PathPersistedAt(dir string) []string
- func RemoveOne(path string) error
- func RemovePATHPersistence(_ string) ([]string, error)
- func RestartDaemon()
- func StopServices()
- func SweepablePrefix(exePath string) (string, bool)
- func Verify(bin string) (string, error)
- type PlanInput
- type StoragePaths
- type Target
- type UninstallOptions
- type UninstallOutcome
Constants ¶
const ( KindBinary = "binary" KindData = "data" KindConfig = "config" KindPath = "path" // PATH persistence entry (rc file / registry) — informational KindMemory = "memory" KindProject = "projects" KindSkill = "skills" KindWork = "work" )
Target kinds. "binary"/"data"/"config"/"path" are OpenPanda-owned; the asset kinds mark user trees that are always kept.
Variables ¶
This section is empty.
Functions ¶
func AddToPATH ¶
AddToPATH appends the marked export block to every existing rc file (or creates ~/.profile when none exist — rare, but a fresh minimal box should still work). Returns the files it touched; an empty slice with nil error means the marker is already present (idempotent re-install).
func BackupZip ¶
BackupZip archives the given targets into a zip so an uninstall is reversible. Which items land in the archive is the caller's decision: a normal uninstall passes the delete-kind targets (data/config), a --purge run also passes the user-asset targets that are about to die. The binary and PATH entries are never archived; files that vanished between Scan and execution are skipped silently. Returns the number of files archived.
func CopySelf ¶
CopySelf copies the running executable to dst (creating parent dirs). The copy goes through a temp file + rename so a half-written binary never sits at the destination. A pre-existing dst is replaced — that is the update path (`panda install` over an older install).
func Dir ¶
Dir returns the default install directory: ~/.local/bin on unix (XDG convention, preconfigured on most Linux distros), %LOCALAPPDATA%\OpenPanda \bin on Windows (per-user, no elevation needed).
func ExeName ¶
func ExeName() string
ExeName is the installed binary's file name ("panda" / "panda.exe").
func InPATH ¶
InPATH reports whether dir is on the current process's PATH. The install flow uses it to decide whether to touch shell startup files at all.
func PathPersistedAt ¶
PathPersistedAt reports which rc files currently carry the marker — doctor shows this as the "will survive reboot" state.
func RemoveOne ¶
RemoveOne deletes a single target. Symlinks remove the link only — never anything they point at. Directories go recursively.
func RemovePATHPersistence ¶
RemovePATHPersistence strips our marked blocks from every rc file. The dir argument is unused on unix (markers identify our lines); it exists so both platforms share one signature. Returns the files that changed; user-authored lines are never touched.
func RestartDaemon ¶ added in v0.0.10
func RestartDaemon()
RestartDaemon best-effort bounces a registered node daemon so it picks up a freshly swapped binary (self-update replaces the file on disk, but a running daemon keeps its old image until the service manager restarts it).
It only ever touches services that are already running: launchd kickstart -k runs only when the agent is loaded and reports "state = running", and systemctl's try-restart is a no-op for inactive or absent units. A daemon started by hand in a terminal is intentionally left alone — there is no service to bounce — so the update surfaces the restart hint instead. Failures are ignored for the same reason as StopServices.
func StopServices ¶
func StopServices()
StopServices best-effort stops a user-level daemon if one is registered (LaunchAgent on macOS, user systemd unit on Linux — the units ship in scripts/ and deploy/). Failures are ignored: an unregistered service, a different init system, or no daemon running are all normal states during uninstall, and the unit files themselves belong to the OS packaging, not to this binary.
func SweepablePrefix ¶ added in v0.0.4
SweepablePrefix reports the distribution prefix when it is safe for the uninstall to sweep it: not a Homebrew Cellar (brew owns those files) and not a source checkout (go.mod / .git beside a locally built bin/panda — the dev repo layout, where adapters/ belongs to git, not to us).
Types ¶
type PlanInput ¶
type PlanInput struct {
Storage *StoragePaths
ConfigFileUsed string // the config file the run resolved to (may not exist)
CapabilityCardUsed string // the capability card the run resolved to (may not exist)
ExePath string
InstallDir string
}
PlanInput collects everything Scan derives deletions from. Storage may be nil (config unreadable) — the binary and PATH entries are still actionable.
type StoragePaths ¶
type StoragePaths struct {
DBPath string
ContextPath string
MemoryPath string
ProjectsPath string
SkillsPath string
WorkPath string
VAPIDKeyPath string
}
StoragePaths mirrors the subset of config.StorageConfig the uninstall needs, decoupled so config changes don't ripple into this package.
type Target ¶
type Target struct {
Path string
Kind string
Delete bool
Reason string // why a kept item is kept; ignored for delete items
Bytes int64
Exists bool
}
Target is one line of the uninstall plan.
type UninstallOptions ¶ added in v0.0.4
type UninstallOptions struct {
// BackupPath is where the backup zip is written; empty skips the backup.
BackupPath string
// Purge additionally deletes the user-asset targets (memory/projects/
// skills/work). The caller owns the double confirmation — this field is
// the result of the second prompt, never a default.
Purge bool
// BackupOnly writes the backup and returns without deleting anything.
BackupOnly bool
}
UninstallOptions drives ExecuteUninstall.
type UninstallOutcome ¶ added in v0.0.4
type UninstallOutcome struct {
BackupFiles int
BackupErr error
Deleted []Target // OpenPanda-owned items removed
Purged []Target // user-asset dirs removed (--purge)
Kept []Target // items the run left on disk
Failed []string // "path (error)" entries
}
UninstallOutcome reports what an ExecuteUninstall run did. Individual failures are collected in Failed rather than aborting the run — the uninstall report surfaces them at the end.
func ExecuteUninstall ¶ added in v0.0.4
func ExecuteUninstall(targets []Target, opt UninstallOptions) UninstallOutcome
ExecuteUninstall runs the backup + deletion phases of an uninstall over a scanned plan. It deletes exactly what the plan marked Delete — minus the PATH entries, which the caller removes through the per-OS rc editors — and, when Purge is set, the user-asset targets. Purge candidates are guarded here as well: an asset path that is empty, a filesystem root, the home directory, or an ancestor of it is kept regardless of the flag. BackupOnly stops after the backup so nothing is removed.