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:
2026-05-07 19:47:14 -04:00
parent a5e508bcb6
commit 176e788f67
8 changed files with 902 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
package cmd
import (
"path/filepath"
"github.com/spf13/cobra"
"github.com/warrenronsiek/ctask/internal/config"
"github.com/warrenronsiek/ctask/internal/workspace"
)
// completionFilter selects which workspaces a command's tab-completion should
// surface. It does not affect lookup — that's still the resolver's job — only
// what the user sees as candidates while typing.
type completionFilter int
const (
completionActive completionFilter = iota
completionArchived
completionAny
)
// completeWorkspaces returns a Cobra ValidArgsFunction that enumerates
// workspace directory basenames matching the requested filter. Basenames are
// emitted (not bare slugs) because the resolver's exact-match step accepts
// basenames unambiguously, while bare slugs can collide across categories or
// dates.
//
// On any internal error we surface ShellCompDirectiveError so the shell shows
// nothing rather than a partial / misleading list.
func completeWorkspaces(filter completionFilter) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// Only the first positional argument is a workspace name.
if len(args) > 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
roots := config.SearchRoots()
results, err := workspace.ListWorkspaces(roots, workspace.ListOpts{
IncludeArchived: filter != completionActive,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, ws := range results {
switch filter {
case completionActive:
if ws.Meta.Status == "archived" {
continue
}
case completionArchived:
if ws.Meta.Status != "archived" {
continue
}
case completionAny:
// no filter
}
names = append(names, filepath.Base(ws.Path))
}
return names, cobra.ShellCompDirectiveNoFileComp
}
}