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 ¶
- Variables
- func ValidateName(name 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) List() ([]Project, error)
- func (s *Store) Rename(oldName, newName string) (Project, error)
- func (s *Store) SetActive(name string) error
- func (s *Store) Touch(name string) error
- func (s *Store) Update(name, workDir, description string) (Project, error)
Constants ¶
This section is empty.
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.
Functions ¶
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.
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"`
}
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.
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.
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) 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.