@pi-unipi/workflow 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/commands.ts +28 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -97,6 +97,8 @@ For small tasks that skip the full flow:
97
97
  /unipi:worktree-merge feat/new-feature
98
98
  ```
99
99
 
100
+ Worktree command arguments autocomplete from `.unipi/worktrees`. Suggestions are cached after the first scan in a Pi session so large worktree directories do not slow down repeated `/unipi:worktree-merge` completions.
101
+
100
102
  ## Special Triggers
101
103
 
102
104
  Workflow skills detect installed packages and enhance their behavior automatically. This is the coexists system — each package adds capabilities without requiring configuration.
package/commands.ts CHANGED
@@ -10,6 +10,8 @@ import { readFileSync, readdirSync, existsSync, statSync } from "fs";
10
10
  import { join, basename } from "path";
11
11
  import { UNIPI_PREFIX, WORKFLOW_COMMANDS, getToolsForCommand, getSandboxLevel, type SandboxLevel } from "@pi-unipi/core";
12
12
 
13
+ type CompletionItem = { value: string; label: string; description: string };
14
+
13
15
  /** Options for command registration */
14
16
  export interface WorkflowCommandOptions {
15
17
  /** Check if ralph module is detected */
@@ -36,7 +38,7 @@ interface WorkflowCommand {
36
38
  /**
37
39
  * Suggest spec files from .unipi/docs/specs/ for plan command.
38
40
  */
39
- function suggestSpecFiles(prefix: string): { value: string; label: string; description: string }[] {
41
+ function suggestSpecFiles(prefix: string): CompletionItem[] {
40
42
  const specsDir = join(process.cwd(), ".unipi", "docs", "specs");
41
43
  if (!existsSync(specsDir)) return [];
42
44
 
@@ -61,7 +63,7 @@ function suggestSpecFiles(prefix: string): { value: string; label: string; descr
61
63
  /**
62
64
  * Suggest plan files from .unipi/docs/plans/ for work and review-work commands.
63
65
  */
64
- function suggestPlanFiles(prefix: string): { value: string; label: string; description: string }[] {
66
+ function suggestPlanFiles(prefix: string): CompletionItem[] {
65
67
  const plansDir = join(process.cwd(), ".unipi", "docs", "plans");
66
68
  if (!existsSync(plansDir)) return [];
67
69
 
@@ -86,7 +88,7 @@ function suggestPlanFiles(prefix: string): { value: string; label: string; descr
86
88
  /**
87
89
  * Suggest debug files from .unipi/docs/debug/ for fix command.
88
90
  */
89
- function suggestDebugFiles(prefix: string): { value: string; label: string; description: string }[] {
91
+ function suggestDebugFiles(prefix: string): CompletionItem[] {
90
92
  const debugDir = join(process.cwd(), ".unipi", "docs", "debug");
91
93
  if (!existsSync(debugDir)) return [];
92
94
 
@@ -111,7 +113,7 @@ function suggestDebugFiles(prefix: string): { value: string; label: string; desc
111
113
  /**
112
114
  * Suggest chore files from .unipi/docs/chore/ for chore-execute command.
113
115
  */
114
- function suggestChoreFiles(prefix: string): { value: string; label: string; description: string }[] {
116
+ function suggestChoreFiles(prefix: string): CompletionItem[] {
115
117
  const choreDir = join(process.cwd(), ".unipi", "docs", "chore");
116
118
  if (!existsSync(choreDir)) return [];
117
119
 
@@ -133,16 +135,29 @@ function suggestChoreFiles(prefix: string): { value: string; label: string; desc
133
135
  }
134
136
  }
135
137
 
138
+ /** Cached per-cwd worktree suggestions. Worktree autocomplete can be invoked on every
139
+ * keystroke, so the recursive scan is intentionally paid only once per session/cwd.
140
+ */
141
+ let worktreeSuggestionsCache: { cwd: string; items: CompletionItem[] } | null = null;
142
+
136
143
  /**
137
144
  * Suggest existing worktree names for merge/list commands.
138
145
  * Recursively scans for actual git worktrees (directories containing .git files).
139
146
  */
140
- function suggestWorktrees(): { value: string; label: string; description: string }[] {
141
- const worktreesDir = join(process.cwd(), ".unipi", "worktrees");
142
- if (!existsSync(worktreesDir)) return [];
147
+ function suggestWorktrees(): CompletionItem[] {
148
+ const cwd = process.cwd();
149
+ if (worktreeSuggestionsCache?.cwd === cwd) {
150
+ return worktreeSuggestionsCache.items;
151
+ }
152
+
153
+ const worktreesDir = join(cwd, ".unipi", "worktrees");
154
+ if (!existsSync(worktreesDir)) {
155
+ worktreeSuggestionsCache = { cwd, items: [] };
156
+ return worktreeSuggestionsCache.items;
157
+ }
143
158
 
144
159
  try {
145
- const results: { value: string; label: string; description: string }[] = [];
160
+ const results: CompletionItem[] = [];
146
161
 
147
162
  /**
148
163
  * Recursively find worktree directories (those containing a .git file).
@@ -176,9 +191,11 @@ function suggestWorktrees(): { value: string; label: string; description: string
176
191
  }
177
192
 
178
193
  findWorktrees(worktreesDir, "");
179
- return results;
194
+ worktreeSuggestionsCache = { cwd, items: results };
195
+ return worktreeSuggestionsCache.items;
180
196
  } catch {
181
- return [];
197
+ worktreeSuggestionsCache = { cwd, items: [] };
198
+ return worktreeSuggestionsCache.items;
182
199
  }
183
200
  }
184
201
 
@@ -334,7 +351,7 @@ export function registerWorkflowCommands(
334
351
  pi.registerCommand(fullCommand, {
335
352
  description: cmd.description,
336
353
  getArgumentCompletions: (prefix: string) => {
337
- let items: { value: string; label: string; description: string }[] | null = null;
354
+ let items: CompletionItem[] | null = null;
338
355
 
339
356
  // Plan command: suggest spec files
340
357
  if (cmd.name === WORKFLOW_COMMANDS.PLAN) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/workflow",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Structured development workflow commands for Pi coding agent",
5
5
  "type": "module",
6
6
  "license": "MIT",