feat(v0.5.2): add restore, notes, path commands with completion plumbing
Three new direct-lookup commands per v0.5.2-spec.md:
- ctask restore <ws> un-archive a workspace (metadata-only flip,
mirrors archive's lease guard, refuses to
restore an already-active workspace)
- ctask notes <ws> stream a workspace's notes.md to stdout (raw,
no framing, [ctask]-prefixed stderr on error)
so AI agents can read prior workspace context
through standard shell pipelines
- ctask path <ws> print the absolute filesystem path of a
workspace, OS-native separators, one line
All three resolve archived-inclusive: the user typed a name, so we
find the workspace whether or not it's archived. Listing stays
filtered (active-only by default) per the v0.5.2 design rule
"listing is filtered, direct lookup is comprehensive".
Adds shared completion infrastructure (cmd/completion.go) used by
these commands and wired into the existing workspace-accepting
commands in a follow-up commit. Candidates are workspace directory
basenames (e.g. 2026-04-22_promptvolley) rather than bare slugs
because basenames are unique under the resolver's exact-match step
while slugs can collide across categories or dates.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warrenronsiek/ctask/internal/config"
|
||||
)
|
||||
|
||||
var notesCmd = &cobra.Command{
|
||||
Use: "notes <query>",
|
||||
Short: "Print a workspace's notes.md to stdout",
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: runNotes,
|
||||
}
|
||||
|
||||
func init() {
|
||||
notesCmd.ValidArgsFunction = completeWorkspaces(completionAny)
|
||||
rootCmd.AddCommand(notesCmd)
|
||||
}
|
||||
|
||||
// runNotes streams <workspace>/notes.md to stdout. SilenceErrors is enabled
|
||||
// so the [ctask]-prefixed message we print to stderr is the only diagnostic
|
||||
// the user sees — no Cobra "Error: ..." line on top of it.
|
||||
func runNotes(cmd *cobra.Command, args []string) error {
|
||||
roots := config.SearchRoots()
|
||||
ws := resolveOne(roots, args[0], true)
|
||||
|
||||
notesPath := filepath.Join(ws.Path, "notes.md")
|
||||
f, err := os.Open(notesPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Fprintf(os.Stderr, "[ctask] no notes.md found in workspace %q\n", args[0])
|
||||
return fmt.Errorf("notes.md missing")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "[ctask] error reading notes.md: %v\n", err)
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err := io.Copy(os.Stdout, f); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[ctask] error streaming notes.md: %v\n", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user