Documentation
¶
Overview ¶
Package projects makes a project a first-class entity rather than a name that happens to appear on some tasks.
Before this package a "project" was one Markdown file under projects/. Tasks carried a project name, the queue could filter on it, and that was the whole model: there was no record of what a project is, no directory where its work happens, and no notion of the one you are currently in — so every ask had to name it again, and a task delegated to another machine arrived carrying a name that machine had never heard of.
Two things live here. The metadata (name, work dir, description, timestamps) is what makes a project addressable and portable; the work dir in particular is the tree a task runs in and therefore the tree that travels with a delegation. And the active-project pointer, which has to be on disk rather than in memory because `panda ask` is a one-shot process: a pointer held in RAM would be forgotten between two consecutive commands.
The project's *memory* stays where it was, in internal/memory.Projects — this package deliberately does not own it. The isolation wall (design §17.2) is structural, and moving project memory behind a store that also knows about work directories and active state would be the first crack in it.
Index ¶
- Constants
- Variables
- func ValidateApprovalDecision(decision string) error
- func ValidateApprovalMode(mode string) error
- func ValidateApprovalScope(scope string) error
- func ValidateName(name string) error
- func ValidateWorkDir(abs string) error
- type Project
- type Store
- func (s *Store) Active() (string, error)
- func (s *Store) ClearActive() error
- func (s *Store) Create(name, workDir, description string) (Project, error)
- func (s *Store) Delete(name string) error
- func (s *Store) EnsureFromName(name string) (Project, error)
- func (s *Store) FindByWorkDir(dir string) (Project, error)
- func (s *Store) Get(name string) (Project, error)
- func (s *Store) GetFold(name string) (Project, error)
- func (s *Store) List() ([]Project, error)
- func (s *Store) Rename(oldName, newName string) (Project, error)
- func (s *Store) SetActive(name string) error
- func (s *Store) SetApprovalDecision(name, decision string) error
- func (s *Store) SetApprovalPolicy(name, mode, scope string) error
- func (s *Store) Touch(name string) error
- func (s *Store) Update(name, workDir, description string) (Project, error)
Constants ¶
const ( ScopeOnce = "once" ScopeSession = "session" ScopeProject = "project" )
Approval remember scopes: where an approval card's "remember" writes the answer it was given. Once applies the answer to that prompt only.
const ( DecisionApprove = "approve" DecisionDeny = "deny" )
Approval decision values: the remembered answer the tier-2 gate replays.
Variables ¶
var ErrExists = errors.New("projects: project already exists")
ErrExists reports a create/rename onto a name already taken.
var ErrNotFound = errors.New("projects: no such project")
ErrNotFound reports a project name that is not in the table.
var ErrWorkDirTooBroad = errors.New("projects: work dir is too broad")
ErrWorkDirTooBroad reports a work dir that is a filesystem root, the home directory, or a system tree — a tree no task "works in".
Functions ¶
func ValidateApprovalDecision ¶ added in v0.0.9
ValidateApprovalDecision rejects a remembered answer outside approve|deny.
func ValidateApprovalMode ¶ added in v0.0.9
ValidateApprovalMode rejects a project approval mode outside the understood set. "" means "inherit the global gate" and is always legal; the alias words config accepts (strict/auto) are legal here too so a policy can be written in the vocabulary the config file already uses — the engine normalizes either way. Anything else is a typo that must not silently degrade to on-request.
func ValidateApprovalScope ¶ added in v0.0.9
ValidateApprovalScope rejects a remember-scope outside once|session|project.
func ValidateName ¶
ValidateName rejects names that cannot be used as a path segment or a wire value. A project name reaches the filesystem (its memory file), the bus (the delegation payload) and the CLI (as an argument), so the safe set is the intersection of all three rather than whatever SQLite would accept.
func ValidateWorkDir ¶ added in v0.1.1
ValidateWorkDir rejects a work dir that would make the project table a read-anything switch. It exists because the web console treats every project's work dir as a readable root (/api/fs/read, /api/fs/image), so `{"work_dir": "/"}` used to turn one authenticated request into a viewer for the whole disk. The panel's own comment calls that boundary the reason reads stay inside the node's directories; a boundary the same credential can widen is not a boundary.
The rule is deliberately about breadth, not ownership or existence: any directory deep enough to be somebody's project passes, while the roots that mean "the entire machine" — a volume root, the home directory or one of its ancestors, and the system trees every OS keeps — do not. A work dir that does not exist yet stays legal, because a project may be created before its tree.
Types ¶
type Project ¶
type Project struct {
Name string `json:"name"`
WorkDir string `json:"work_dir,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// ApprovalMode is a project-scoped override of the node's approval.mode
// gate (always|on-request|never); empty inherits the global policy.
ApprovalMode string `json:"approval_mode,omitempty"`
// ApprovalScope picks where the "remember" choice on an approval card
// writes its answer by default (once|session|project); empty reads as
// session — narrower than the project row itself.
ApprovalScope string `json:"approval_scope,omitempty"`
// ApprovalDecision is the remembered project-level answer (approve|deny)
// the gate replays instead of prompting again; empty remembers nothing.
ApprovalDecision string `json:"approval_decision,omitempty"`
}
Project is one project's metadata. WorkDir is absolute when set; empty means the project has no tree of its own and its tasks run in the node's work directory, which is how a memory-only project (every project that existed before this table) keeps working.
func (Project) NormalizedScope ¶ added in v0.0.9
NormalizedScope reads the configured remember-scope, defaulting to session: a project that never picked one remembers approvals for the conversation it was granted in — a default narrower than persisting onto the project row.
func (Project) UsableWorkDir ¶ added in v0.1.2
UsableWorkDir is WorkDir when it still answers to the breadth rule, "" when it does not. Rows written before ValidateWorkDir existed can name the home directory (home-directory adoption created them), and every reader that took WorkDir at face value propagated a path the executor refuses — a task then failed at creation with "work dir is too broad" and nothing in the message pointed at the project row that produced it. Readers use this instead: a too-broad row degrades to "no work dir of its own" (the task falls back to its own private directory) rather than poisoning every task under the project. The row itself is left alone — `panda project show` reports it, and the operator fixes or removes it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the projects table plus the settings row that names the active one.
func (*Store) Active ¶
Active returns the current project's name, or "" when none is set. A pointer at a project that has since been deleted reads as "" rather than as an error: the caller's next question is always "which project am I in", and "none" is the honest answer.
func (*Store) ClearActive ¶
ClearActive leaves whatever project was current. Idempotent: leaving when you are not in a project is not an error, it is already true.
func (*Store) Create ¶
Create inserts a project. workDir is resolved to an absolute path so a project created from one directory still points at the same tree when a task runs from another — the daemon's cwd is not the cwd of whoever typed the command.
A named workDir is CREATED when missing. `panda project new feat-a --dir D:/proj/feat-a` reads as "make me a project rooted here", and a project whose directory does not exist yet used to leave every task to discover that at run time: prepareRunDir would mkdir it anyway, but `project show` claimed a path that was not there and an isolate child silently degraded to a plain copy (gitRepoRootOf needs a real repository root). Creating it here makes the row and the filesystem agree the moment the command returns. An existing directory is left untouched — pointing --dir at a live checkout must not disturb it — and a failure to create is reported rather than stored as a project that cannot run.
func (*Store) Delete ¶
Delete removes a project's metadata and clears the active pointer when it named this one. It does not touch the work directory: deleting a project is an act of bookkeeping, and silently removing a tree the user pointed at would be the one irreversible thing in this package.
func (*Store) EnsureFromName ¶
EnsureFromName creates a metadata row for a project that only ever existed as a memory file. Projects predate this table, so a name that appears on a task or in projects/<name>/ must still resolve to a project; this is the adoption path, and it is idempotent.
func (*Store) FindByWorkDir ¶
FindByWorkDir looks up the first project pointing at the given work directory.
func (*Store) GetFold ¶ added in v0.1.0
GetFold reads one project matching the name case-insensitively. Task inputs carry project names from two sources — the operator's flags, which arrive verbatim, and the classifier's spec.project, which arrives in the casing the model inferred from the directory ("Needlen" for a "needlen" row). Both spell the same tree; the registry answers with the canonical stored name so locks, approval policy and the task row agree on one.
func (*Store) Rename ¶
Rename moves a project to a new name, carrying the active pointer with it. The two writes are one transaction: a rename that renamed the row but left the pointer behind would leave the user "inside" a project that no longer exists.
The caller is responsible for the project's memory file and for any tasks that reference the old name — renaming is metadata here, and the CLI wires the rest.
func (*Store) SetActive ¶
SetActive points at a project, which must exist — entering a project that was never created would make every later "which project am I in" answer a lie.
func (*Store) SetApprovalDecision ¶ added in v0.0.9
SetApprovalDecision writes the remembered project-level approval answer — approve|deny, or "" to forget. This is the write the "remember" choice on an approval card lands when its scope is project.
func (*Store) SetApprovalPolicy ¶ added in v0.0.9
SetApprovalPolicy writes a project's approval overrides. mode is always|on-request|never (or the config's alias spellings); "" inherits the global gate. scope is once|session|project; "" restores the session default. Unknown values are rejected rather than normalized away — a typo'd policy silently reading as a different mode is how gates open by accident. The project is adopted when it only exists as a memory file, matching every other path that resolves a name to a project.