@litmers/cursorflow-orchestrator 0.1.5 → 0.1.8

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 (45) hide show
  1. package/CHANGELOG.md +15 -6
  2. package/README.md +33 -2
  3. package/commands/cursorflow-doctor.md +24 -0
  4. package/commands/cursorflow-signal.md +19 -0
  5. package/dist/cli/doctor.d.ts +15 -0
  6. package/dist/cli/doctor.js +139 -0
  7. package/dist/cli/doctor.js.map +1 -0
  8. package/dist/cli/index.js +5 -0
  9. package/dist/cli/index.js.map +1 -1
  10. package/dist/cli/monitor.d.ts +1 -1
  11. package/dist/cli/monitor.js +640 -145
  12. package/dist/cli/monitor.js.map +1 -1
  13. package/dist/cli/resume.d.ts +1 -1
  14. package/dist/cli/resume.js +80 -10
  15. package/dist/cli/resume.js.map +1 -1
  16. package/dist/cli/run.js +60 -5
  17. package/dist/cli/run.js.map +1 -1
  18. package/dist/cli/setup-commands.d.ts +4 -0
  19. package/dist/cli/setup-commands.js +16 -0
  20. package/dist/cli/setup-commands.js.map +1 -1
  21. package/dist/cli/signal.d.ts +7 -0
  22. package/dist/cli/signal.js +99 -0
  23. package/dist/cli/signal.js.map +1 -0
  24. package/dist/core/orchestrator.d.ts +4 -2
  25. package/dist/core/orchestrator.js +92 -23
  26. package/dist/core/orchestrator.js.map +1 -1
  27. package/dist/core/runner.d.ts +9 -3
  28. package/dist/core/runner.js +182 -88
  29. package/dist/core/runner.js.map +1 -1
  30. package/dist/utils/doctor.d.ts +63 -0
  31. package/dist/utils/doctor.js +280 -0
  32. package/dist/utils/doctor.js.map +1 -0
  33. package/dist/utils/types.d.ts +3 -0
  34. package/package.json +1 -1
  35. package/src/cli/doctor.ts +127 -0
  36. package/src/cli/index.ts +5 -0
  37. package/src/cli/monitor.ts +693 -185
  38. package/src/cli/resume.ts +94 -12
  39. package/src/cli/run.ts +63 -7
  40. package/src/cli/setup-commands.ts +19 -0
  41. package/src/cli/signal.ts +89 -0
  42. package/src/core/orchestrator.ts +102 -27
  43. package/src/core/runner.ts +203 -99
  44. package/src/utils/doctor.ts +312 -0
  45. package/src/utils/types.ts +3 -0
@@ -0,0 +1,312 @@
1
+ /**
2
+ * CursorFlow Doctor - environment and preflight checks
3
+ *
4
+ * This module provides actionable diagnostics for common run failures:
5
+ * - Not inside a Git work tree
6
+ * - Missing `origin` remote (required for pushing lane branches)
7
+ * - Missing Git worktree support
8
+ * - Missing base branch referenced by lane task files
9
+ * - Missing/invalid tasks directory
10
+ * - Missing Cursor Agent setup (optional)
11
+ */
12
+
13
+ import * as fs from 'fs';
14
+ import * as path from 'path';
15
+
16
+ import * as git from './git';
17
+ import { checkCursorAgentInstalled, checkCursorAuth } from './cursor-agent';
18
+ import { areCommandsInstalled } from '../cli/setup-commands';
19
+
20
+ export type DoctorSeverity = 'error' | 'warn';
21
+
22
+ export interface DoctorIssue {
23
+ /**
24
+ * Stable identifier for machines (NOCC) and tests.
25
+ */
26
+ id: string;
27
+ severity: DoctorSeverity;
28
+ title: string;
29
+ message: string;
30
+ /**
31
+ * Suggested commands or steps to fix the issue.
32
+ */
33
+ fixes?: string[];
34
+ /**
35
+ * Optional technical details (stderr, stdout, etc.)
36
+ */
37
+ details?: string;
38
+ }
39
+
40
+ export interface DoctorContext {
41
+ cwd: string;
42
+ repoRoot?: string;
43
+ tasksDir?: string;
44
+ executor?: string;
45
+ }
46
+
47
+ export interface DoctorReport {
48
+ ok: boolean;
49
+ issues: DoctorIssue[];
50
+ context: DoctorContext;
51
+ }
52
+
53
+ export interface DoctorOptions {
54
+ cwd?: string;
55
+ /**
56
+ * Optional tasks directory (used for `cursorflow run` preflight).
57
+ */
58
+ tasksDir?: string;
59
+ /**
60
+ * Executor type ('cursor-agent' | 'cloud' | ...).
61
+ */
62
+ executor?: string;
63
+ /**
64
+ * When true (default), include Cursor Agent install/auth checks.
65
+ */
66
+ includeCursorAgentChecks?: boolean;
67
+ }
68
+
69
+ function addIssue(issues: DoctorIssue[], issue: DoctorIssue): void {
70
+ issues.push(issue);
71
+ }
72
+
73
+ function resolveRepoRoot(cwd: string): string | null {
74
+ const res = git.runGitResult(['rev-parse', '--show-toplevel'], { cwd });
75
+ if (!res.success || !res.stdout) return null;
76
+ return res.stdout;
77
+ }
78
+
79
+ function isInsideGitWorktree(cwd: string): boolean {
80
+ const res = git.runGitResult(['rev-parse', '--is-inside-work-tree'], { cwd });
81
+ return res.success && res.stdout.trim() === 'true';
82
+ }
83
+
84
+ function hasAtLeastOneCommit(repoRoot: string): boolean {
85
+ const res = git.runGitResult(['rev-parse', '--verify', 'HEAD'], { cwd: repoRoot });
86
+ return res.success;
87
+ }
88
+
89
+ function hasOriginRemote(repoRoot: string): boolean {
90
+ const res = git.runGitResult(['remote', 'get-url', 'origin'], { cwd: repoRoot });
91
+ return res.success && !!res.stdout;
92
+ }
93
+
94
+ function hasWorktreeSupport(repoRoot: string): { ok: boolean; details?: string } {
95
+ const res = git.runGitResult(['worktree', 'list'], { cwd: repoRoot });
96
+ if (res.success) return { ok: true };
97
+ return { ok: false, details: res.stderr || res.stdout || 'git worktree failed' };
98
+ }
99
+
100
+ function branchExists(repoRoot: string, branchName: string): boolean {
101
+ // rev-parse --verify works for both branches and tags; restrict to heads first.
102
+ const headRes = git.runGitResult(['show-ref', '--verify', `refs/heads/${branchName}`], { cwd: repoRoot });
103
+ if (headRes.success) return true;
104
+ const anyRes = git.runGitResult(['rev-parse', '--verify', branchName], { cwd: repoRoot });
105
+ return anyRes.success;
106
+ }
107
+
108
+ function readLaneJsonFiles(tasksDir: string): { path: string; json: any }[] {
109
+ const files = fs
110
+ .readdirSync(tasksDir)
111
+ .filter(f => f.endsWith('.json'))
112
+ .sort()
113
+ .map(f => path.join(tasksDir, f));
114
+
115
+ return files.map(p => {
116
+ const raw = fs.readFileSync(p, 'utf8');
117
+ const json = JSON.parse(raw);
118
+ return { path: p, json };
119
+ });
120
+ }
121
+
122
+ function collectBaseBranchesFromLanes(lanes: { path: string; json: any }[], defaultBaseBranch: string): string[] {
123
+ const set = new Set<string>();
124
+ for (const lane of lanes) {
125
+ const baseBranch = String(lane.json?.baseBranch || defaultBaseBranch || 'main').trim();
126
+ if (baseBranch) set.add(baseBranch);
127
+ }
128
+ return Array.from(set);
129
+ }
130
+
131
+ /**
132
+ * Run doctor checks.
133
+ *
134
+ * If `tasksDir` is provided, additional preflight checks are performed:
135
+ * - tasks directory existence and JSON validity
136
+ * - baseBranch referenced by lanes exists locally
137
+ */
138
+ export function runDoctor(options: DoctorOptions = {}): DoctorReport {
139
+ const cwd = options.cwd || process.cwd();
140
+ const issues: DoctorIssue[] = [];
141
+
142
+ const context: DoctorContext = {
143
+ cwd,
144
+ executor: options.executor,
145
+ };
146
+
147
+ // 1) Git repository checks
148
+ if (!isInsideGitWorktree(cwd)) {
149
+ addIssue(issues, {
150
+ id: 'git.not_repo',
151
+ severity: 'error',
152
+ title: 'Not a Git repository',
153
+ message: 'Current directory is not inside a Git work tree. CursorFlow requires Git to create worktrees and branches.',
154
+ fixes: [
155
+ 'cd into your repository root (or any subdirectory inside it)',
156
+ 'If this is a new project: git init && git commit --allow-empty -m "chore: initial commit"',
157
+ ],
158
+ });
159
+
160
+ return { ok: false, issues, context };
161
+ }
162
+
163
+ const repoRoot = resolveRepoRoot(cwd) || undefined;
164
+ context.repoRoot = repoRoot;
165
+ const gitCwd = repoRoot || cwd;
166
+
167
+ if (!hasAtLeastOneCommit(gitCwd)) {
168
+ addIssue(issues, {
169
+ id: 'git.no_commits',
170
+ severity: 'error',
171
+ title: 'Repository has no commits',
172
+ message: 'CursorFlow needs at least one commit (HEAD) to create worktrees and new branches.',
173
+ fixes: ['git commit --allow-empty -m "chore: initial commit"'],
174
+ });
175
+ }
176
+
177
+ if (!hasOriginRemote(gitCwd)) {
178
+ addIssue(issues, {
179
+ id: 'git.no_origin',
180
+ severity: 'error',
181
+ title: "Missing remote 'origin'",
182
+ message: "Remote 'origin' is not configured. CursorFlow pushes lane branches to 'origin' during execution.",
183
+ fixes: [
184
+ 'git remote add origin <your-repo-url>',
185
+ 'git remote -v # verify remotes',
186
+ ],
187
+ });
188
+ }
189
+
190
+ const wt = hasWorktreeSupport(gitCwd);
191
+ if (!wt.ok) {
192
+ addIssue(issues, {
193
+ id: 'git.worktree_unavailable',
194
+ severity: 'error',
195
+ title: 'Git worktree not available',
196
+ message: 'Git worktree support is required, but `git worktree` failed.',
197
+ fixes: [
198
+ 'Upgrade Git (worktrees require Git >= 2.5)',
199
+ 'Ensure the repository is not corrupted',
200
+ ],
201
+ details: wt.details,
202
+ });
203
+ }
204
+
205
+ // 2) Tasks-dir checks (optional; used by `cursorflow run` preflight)
206
+ if (options.tasksDir) {
207
+ const tasksDirAbs = path.isAbsolute(options.tasksDir)
208
+ ? options.tasksDir
209
+ : path.resolve(cwd, options.tasksDir);
210
+ context.tasksDir = tasksDirAbs;
211
+
212
+ if (!fs.existsSync(tasksDirAbs)) {
213
+ addIssue(issues, {
214
+ id: 'tasks.missing_dir',
215
+ severity: 'error',
216
+ title: 'Tasks directory not found',
217
+ message: `Tasks directory does not exist: ${tasksDirAbs}`,
218
+ fixes: [
219
+ 'Double-check the path you passed to `cursorflow run`',
220
+ 'If needed, run: cursorflow init --example',
221
+ ],
222
+ });
223
+ } else {
224
+ let lanes: { path: string; json: any }[] = [];
225
+ try {
226
+ lanes = readLaneJsonFiles(tasksDirAbs);
227
+ } catch (error: any) {
228
+ addIssue(issues, {
229
+ id: 'tasks.invalid_json',
230
+ severity: 'error',
231
+ title: 'Invalid lane JSON file',
232
+ message: `Failed to read/parse lane JSON files in: ${tasksDirAbs}`,
233
+ details: error?.message ? String(error.message) : String(error),
234
+ fixes: ['Validate JSON syntax for each lane file (*.json)'],
235
+ });
236
+ lanes = [];
237
+ }
238
+
239
+ if (lanes.length === 0) {
240
+ addIssue(issues, {
241
+ id: 'tasks.no_lanes',
242
+ severity: 'error',
243
+ title: 'No lane files found',
244
+ message: `No lane task files (*.json) found in: ${tasksDirAbs}`,
245
+ fixes: ['Ensure the tasks directory contains one or more lane JSON files'],
246
+ });
247
+ } else {
248
+ const baseBranches = collectBaseBranchesFromLanes(lanes, 'main');
249
+ for (const baseBranch of baseBranches) {
250
+ if (!branchExists(gitCwd, baseBranch)) {
251
+ addIssue(issues, {
252
+ id: `git.missing_base_branch.${baseBranch}`,
253
+ severity: 'error',
254
+ title: `Missing base branch: ${baseBranch}`,
255
+ message: `Lane files reference baseBranch "${baseBranch}", but it does not exist locally.`,
256
+ fixes: [
257
+ 'git fetch origin --prune',
258
+ `Or update lane JSON baseBranch to an existing branch`,
259
+ ],
260
+ });
261
+ }
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ // 3) Cursor Agent checks (optional)
268
+ const includeCursor = options.includeCursorAgentChecks !== false;
269
+ if (includeCursor && (options.executor || 'cursor-agent') === 'cursor-agent') {
270
+ if (!checkCursorAgentInstalled()) {
271
+ addIssue(issues, {
272
+ id: 'cursor_agent.missing',
273
+ severity: 'error',
274
+ title: 'cursor-agent CLI not installed',
275
+ message: 'cursor-agent is required for local execution.',
276
+ fixes: ['npm install -g @cursor/agent', 'cursor-agent --version'],
277
+ });
278
+ } else {
279
+ const auth = checkCursorAuth();
280
+ if (!auth.authenticated) {
281
+ addIssue(issues, {
282
+ id: 'cursor_agent.not_authenticated',
283
+ severity: 'error',
284
+ title: 'Cursor authentication required',
285
+ message: auth.message,
286
+ details: auth.details || auth.error,
287
+ fixes: [
288
+ 'Open Cursor IDE and sign in',
289
+ 'Verify AI features work in the IDE',
290
+ 'Re-run: cursorflow doctor',
291
+ ],
292
+ });
293
+ }
294
+ }
295
+ }
296
+
297
+ // 4) IDE Integration checks
298
+ if (!areCommandsInstalled()) {
299
+ addIssue(issues, {
300
+ id: 'ide.commands_missing',
301
+ severity: 'warn',
302
+ title: 'Cursor IDE commands not installed',
303
+ message: 'CursorFlow slash commands (e.g., /cursorflow-run) are missing or outdated.',
304
+ fixes: ['cursorflow-setup --force', 'or run `cursorflow run` to auto-install'],
305
+ });
306
+ }
307
+
308
+ const ok = issues.every(i => i.severity !== 'error');
309
+ return { ok, issues, context };
310
+ }
311
+
312
+
@@ -40,6 +40,7 @@ export interface Task {
40
40
 
41
41
  export interface RunnerConfig {
42
42
  tasks: Task[];
43
+ dependsOn?: string[];
43
44
  pipelineBranch?: string;
44
45
  branchPrefix?: string;
45
46
  worktreeRoot?: string;
@@ -108,6 +109,8 @@ export interface LaneState {
108
109
  error: string | null;
109
110
  dependencyRequest: DependencyRequestPlan | null;
110
111
  updatedAt?: number;
112
+ tasksFile?: string; // Original tasks file path
113
+ dependsOn?: string[];
111
114
  }
112
115
 
113
116
  export interface ConversationEntry {