@mrpatronz/nexusflow 0.2.19 → 1.3.1

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 (294) hide show
  1. package/README.md +37 -7
  2. package/dist/analyzers/index.d.ts +23 -0
  3. package/dist/analyzers/index.d.ts.map +1 -1
  4. package/dist/analyzers/index.js +62 -0
  5. package/dist/analyzers/index.js.map +1 -1
  6. package/dist/commands/add-repo.d.ts +9 -0
  7. package/dist/commands/add-repo.d.ts.map +1 -1
  8. package/dist/commands/add-repo.js +12 -1
  9. package/dist/commands/add-repo.js.map +1 -1
  10. package/dist/commands/add-repo.test.d.ts +2 -0
  11. package/dist/commands/add-repo.test.d.ts.map +1 -0
  12. package/dist/commands/add-repo.test.js +30 -0
  13. package/dist/commands/add-repo.test.js.map +1 -0
  14. package/dist/commands/commands.test.js +26 -6
  15. package/dist/commands/commands.test.js.map +1 -1
  16. package/dist/commands/commit.d.ts +7 -1
  17. package/dist/commands/commit.d.ts.map +1 -1
  18. package/dist/commands/commit.js +31 -8
  19. package/dist/commands/commit.js.map +1 -1
  20. package/dist/commands/commit.test.d.ts +2 -0
  21. package/dist/commands/commit.test.d.ts.map +1 -0
  22. package/dist/commands/commit.test.js +54 -0
  23. package/dist/commands/commit.test.js.map +1 -0
  24. package/dist/commands/diff.d.ts +9 -2
  25. package/dist/commands/diff.d.ts.map +1 -1
  26. package/dist/commands/diff.js +36 -12
  27. package/dist/commands/diff.js.map +1 -1
  28. package/dist/commands/doctor.d.ts.map +1 -1
  29. package/dist/commands/doctor.js +16 -20
  30. package/dist/commands/doctor.js.map +1 -1
  31. package/dist/commands/handoff.d.ts.map +1 -1
  32. package/dist/commands/handoff.js +11 -15
  33. package/dist/commands/handoff.js.map +1 -1
  34. package/dist/commands/refresh.d.ts +4 -2
  35. package/dist/commands/refresh.d.ts.map +1 -1
  36. package/dist/commands/refresh.js +20 -36
  37. package/dist/commands/refresh.js.map +1 -1
  38. package/dist/commands/schedule.d.ts +35 -0
  39. package/dist/commands/schedule.d.ts.map +1 -0
  40. package/dist/commands/schedule.js +151 -0
  41. package/dist/commands/schedule.js.map +1 -0
  42. package/dist/commands/sync.d.ts.map +1 -1
  43. package/dist/commands/sync.js +28 -7
  44. package/dist/commands/sync.js.map +1 -1
  45. package/dist/commands/tui.js +1 -1
  46. package/dist/commands/tui.js.map +1 -1
  47. package/dist/commands/ui.d.ts +1 -0
  48. package/dist/commands/ui.d.ts.map +1 -1
  49. package/dist/commands/ui.js +5 -2
  50. package/dist/commands/ui.js.map +1 -1
  51. package/dist/core/adapters/local-storage.d.ts +7 -0
  52. package/dist/core/adapters/local-storage.d.ts.map +1 -1
  53. package/dist/core/adapters/local-storage.js +13 -4
  54. package/dist/core/adapters/local-storage.js.map +1 -1
  55. package/dist/core/adapters/storage.test.js +18 -0
  56. package/dist/core/adapters/storage.test.js.map +1 -1
  57. package/dist/core/analysis-cache.d.ts +58 -0
  58. package/dist/core/analysis-cache.d.ts.map +1 -0
  59. package/dist/core/analysis-cache.js +116 -0
  60. package/dist/core/analysis-cache.js.map +1 -0
  61. package/dist/core/analysis-cache.test.d.ts +2 -0
  62. package/dist/core/analysis-cache.test.d.ts.map +1 -0
  63. package/dist/core/analysis-cache.test.js +108 -0
  64. package/dist/core/analysis-cache.test.js.map +1 -0
  65. package/dist/core/refresh.d.ts +41 -0
  66. package/dist/core/refresh.d.ts.map +1 -0
  67. package/dist/core/refresh.js +56 -0
  68. package/dist/core/refresh.js.map +1 -0
  69. package/dist/core/scheduler.d.ts +117 -0
  70. package/dist/core/scheduler.d.ts.map +1 -0
  71. package/dist/core/scheduler.js +361 -0
  72. package/dist/core/scheduler.js.map +1 -0
  73. package/dist/core/scheduler.test.d.ts +2 -0
  74. package/dist/core/scheduler.test.d.ts.map +1 -0
  75. package/dist/core/scheduler.test.js +163 -0
  76. package/dist/core/scheduler.test.js.map +1 -0
  77. package/dist/core/sync.d.ts +6 -0
  78. package/dist/core/sync.d.ts.map +1 -1
  79. package/dist/core/sync.js +17 -12
  80. package/dist/core/sync.js.map +1 -1
  81. package/dist/core/workspace.d.ts +6 -0
  82. package/dist/core/workspace.d.ts.map +1 -1
  83. package/dist/core/workspace.js +32 -15
  84. package/dist/core/workspace.js.map +1 -1
  85. package/dist/core/workspace.test.d.ts +2 -0
  86. package/dist/core/workspace.test.d.ts.map +1 -0
  87. package/dist/core/workspace.test.js +42 -0
  88. package/dist/core/workspace.test.js.map +1 -0
  89. package/dist/generators/index.d.ts +7 -1
  90. package/dist/generators/index.d.ts.map +1 -1
  91. package/dist/generators/index.js +14 -1
  92. package/dist/generators/index.js.map +1 -1
  93. package/dist/generators/map-generator.d.ts.map +1 -1
  94. package/dist/generators/map-generator.js +4 -3
  95. package/dist/generators/map-generator.js.map +1 -1
  96. package/dist/generators/map-generator.test.js +4 -2
  97. package/dist/generators/map-generator.test.js.map +1 -1
  98. package/dist/gui/assets/index-ElroPpSP.js +26 -0
  99. package/dist/gui/index.html +1 -1
  100. package/dist/index.js +108 -4
  101. package/dist/index.js.map +1 -1
  102. package/dist/orchestration/index.d.ts +1 -1
  103. package/dist/orchestration/index.d.ts.map +1 -1
  104. package/dist/orchestration/index.js +1 -1
  105. package/dist/orchestration/index.js.map +1 -1
  106. package/dist/orchestration/runner.d.ts +16 -1
  107. package/dist/orchestration/runner.d.ts.map +1 -1
  108. package/dist/orchestration/runner.js +41 -5
  109. package/dist/orchestration/runner.js.map +1 -1
  110. package/dist/orchestration/runner.test.d.ts +2 -0
  111. package/dist/orchestration/runner.test.d.ts.map +1 -0
  112. package/dist/orchestration/runner.test.js +71 -0
  113. package/dist/orchestration/runner.test.js.map +1 -0
  114. package/dist/server.d.ts +17 -1
  115. package/dist/server.d.ts.map +1 -1
  116. package/dist/server.js +275 -114
  117. package/dist/server.js.map +1 -1
  118. package/dist/server.test.js +158 -1
  119. package/dist/server.test.js.map +1 -1
  120. package/dist/utils/multi-git.d.ts +21 -0
  121. package/dist/utils/multi-git.d.ts.map +1 -1
  122. package/dist/utils/multi-git.js +40 -4
  123. package/dist/utils/multi-git.js.map +1 -1
  124. package/dist/utils/prompts.d.ts.map +1 -1
  125. package/dist/utils/prompts.js +8 -2
  126. package/dist/utils/prompts.js.map +1 -1
  127. package/package.json +13 -1
  128. package/.agents/skills/ccc/SKILL.md +0 -71
  129. package/.agents/skills/ccc/references/management.md +0 -110
  130. package/.agents/skills/ccc/references/settings.md +0 -126
  131. package/.github/dependabot.yml +0 -52
  132. package/.github/workflows/ci.yml +0 -44
  133. package/.github/workflows/dependabot-merge.yml +0 -53
  134. package/.github/workflows/release-desktop.yml +0 -67
  135. package/.github/workflows/release-npm.yml +0 -65
  136. package/.github/workflows/release-vscode.yml +0 -61
  137. package/.vscode/launch.json +0 -17
  138. package/.vscode/tasks.json +0 -17
  139. package/GETTING_STARTED.md +0 -114
  140. package/desktop/build-installer.js +0 -228
  141. package/desktop/build.js +0 -118
  142. package/desktop/installer/nexusflow.iss +0 -35
  143. package/desktop/neutralino.config.json +0 -39
  144. package/desktop/package-lock.json +0 -1060
  145. package/desktop/package.json +0 -14
  146. package/dist/gui/assets/index-D8iJPvnk.js +0 -26
  147. package/extension/media/icon.svg +0 -1
  148. package/extension/package-lock.json +0 -6044
  149. package/extension/package.json +0 -117
  150. package/extension/src/extension.ts +0 -653
  151. package/extension/tsconfig.json +0 -21
  152. package/gui/README.md +0 -73
  153. package/gui/e2e/dashboard.spec.ts +0 -61
  154. package/gui/e2e/wizard.spec.ts +0 -346
  155. package/gui/eslint.config.js +0 -26
  156. package/gui/index.html +0 -17
  157. package/gui/package-lock.json +0 -3137
  158. package/gui/package.json +0 -37
  159. package/gui/playwright.config.ts +0 -41
  160. package/gui/public/app_logo.png +0 -0
  161. package/gui/public/favicon.svg +0 -1
  162. package/gui/public/icons.svg +0 -24
  163. package/gui/src/App.css +0 -1
  164. package/gui/src/App.tsx +0 -3573
  165. package/gui/src/app/AppSidebar.tsx +0 -69
  166. package/gui/src/assets/hero.png +0 -0
  167. package/gui/src/assets/react.svg +0 -1
  168. package/gui/src/assets/vite.svg +0 -1
  169. package/gui/src/components/AddRepoPicker.tsx +0 -81
  170. package/gui/src/components/ui/Button.tsx +0 -40
  171. package/gui/src/components/ui/Card.tsx +0 -6
  172. package/gui/src/components/ui/EmptyState.tsx +0 -22
  173. package/gui/src/components/ui/Input.tsx +0 -21
  174. package/gui/src/components/ui/Menu.tsx +0 -71
  175. package/gui/src/components/ui/Modal.tsx +0 -39
  176. package/gui/src/components/ui/PageHeader.tsx +0 -21
  177. package/gui/src/components/ui/RepoStatusStrip.tsx +0 -33
  178. package/gui/src/components/ui/Skeleton.tsx +0 -5
  179. package/gui/src/components/ui/StatusPill.tsx +0 -36
  180. package/gui/src/components/ui/Tabs.tsx +0 -40
  181. package/gui/src/components/ui/cn.ts +0 -4
  182. package/gui/src/components/ui/index.ts +0 -16
  183. package/gui/src/features/changes/ChangesViewer.tsx +0 -388
  184. package/gui/src/features/knowledge/KnowledgeBase.tsx +0 -84
  185. package/gui/src/features/onboarding/OnboardingWizard.tsx +0 -230
  186. package/gui/src/features/plan/ImplementationPlan.tsx +0 -32
  187. package/gui/src/features/services/ServiceConsole.tsx +0 -215
  188. package/gui/src/features/sessions/SessionHistory.tsx +0 -195
  189. package/gui/src/index.css +0 -167
  190. package/gui/src/lib/status.ts +0 -24
  191. package/gui/src/main.tsx +0 -94
  192. package/gui/src/pages/DashboardPage.tsx +0 -129
  193. package/gui/src/pages/WorkspacesPage.tsx +0 -352
  194. package/gui/src/types.ts +0 -81
  195. package/gui/tsconfig.app.json +0 -25
  196. package/gui/tsconfig.json +0 -7
  197. package/gui/tsconfig.node.json +0 -24
  198. package/gui/vite.config.ts +0 -12
  199. package/resources/workflows/plan-implement-review.md +0 -8
  200. package/resources/workflows/research-verify.md +0 -6
  201. package/resources/workflows/solo-developer.md +0 -3
  202. package/scripts/simulate-workspaces.ts +0 -55
  203. package/skills-lock.json +0 -11
  204. package/src/analyzers/detect-apis.ts +0 -290
  205. package/src/analyzers/detect-deps.ts +0 -315
  206. package/src/analyzers/detect-existing.ts +0 -74
  207. package/src/analyzers/detect-ports.ts +0 -110
  208. package/src/analyzers/index.ts +0 -97
  209. package/src/analyzers/messaging-analyzer.ts +0 -254
  210. package/src/analyzers/readme-summarizer.ts +0 -102
  211. package/src/analyzers/run-analyzer.ts +0 -269
  212. package/src/analyzers/tech-stack.ts +0 -283
  213. package/src/commands/adapter.ts +0 -348
  214. package/src/commands/add-repo.ts +0 -156
  215. package/src/commands/commands.test.ts +0 -156
  216. package/src/commands/commit.ts +0 -131
  217. package/src/commands/config.ts +0 -52
  218. package/src/commands/create.ts +0 -204
  219. package/src/commands/desktop.ts +0 -128
  220. package/src/commands/diff.ts +0 -125
  221. package/src/commands/doctor.ts +0 -370
  222. package/src/commands/handoff.ts +0 -266
  223. package/src/commands/init.ts +0 -134
  224. package/src/commands/list.ts +0 -46
  225. package/src/commands/logs.ts +0 -63
  226. package/src/commands/mcp.ts +0 -94
  227. package/src/commands/open.ts +0 -129
  228. package/src/commands/refresh.ts +0 -137
  229. package/src/commands/remove.ts +0 -98
  230. package/src/commands/start.ts +0 -117
  231. package/src/commands/status.ts +0 -54
  232. package/src/commands/stop.ts +0 -55
  233. package/src/commands/sync.ts +0 -125
  234. package/src/commands/tui.ts +0 -484
  235. package/src/commands/ui.ts +0 -111
  236. package/src/core/adapters/local-storage.ts +0 -66
  237. package/src/core/adapters/obsidian-storage.ts +0 -151
  238. package/src/core/adapters/registry.ts +0 -44
  239. package/src/core/adapters/storage.test.ts +0 -174
  240. package/src/core/adapters/vault-storage.ts +0 -86
  241. package/src/core/config.test.ts +0 -96
  242. package/src/core/config.ts +0 -140
  243. package/src/core/graph.ts +0 -344
  244. package/src/core/plugins/index.ts +0 -17
  245. package/src/core/plugins/loader.ts +0 -36
  246. package/src/core/ports/storage.ts +0 -71
  247. package/src/core/scanner.test.ts +0 -61
  248. package/src/core/scanner.ts +0 -91
  249. package/src/core/storage.ts +0 -37
  250. package/src/core/sync.ts +0 -121
  251. package/src/core/workspace-state.test.ts +0 -108
  252. package/src/core/workspace-state.ts +0 -130
  253. package/src/core/workspace.ts +0 -487
  254. package/src/core/worktree.ts +0 -120
  255. package/src/generators/antigravity.ts +0 -32
  256. package/src/generators/base.ts +0 -243
  257. package/src/generators/claude.ts +0 -34
  258. package/src/generators/codex.ts +0 -48
  259. package/src/generators/copilot.ts +0 -56
  260. package/src/generators/cursor.ts +0 -44
  261. package/src/generators/diff-context.ts +0 -75
  262. package/src/generators/index.ts +0 -322
  263. package/src/generators/map-generator.test.ts +0 -159
  264. package/src/generators/map-generator.ts +0 -539
  265. package/src/generators/plan-generator.ts +0 -483
  266. package/src/generators/skills-generator.ts +0 -259
  267. package/src/index.ts +0 -539
  268. package/src/mcp/server.ts +0 -338
  269. package/src/orchestration/detect.ts +0 -313
  270. package/src/orchestration/index.ts +0 -7
  271. package/src/orchestration/runner.ts +0 -283
  272. package/src/server.test.ts +0 -618
  273. package/src/server.ts +0 -1402
  274. package/src/types.ts +0 -451
  275. package/src/utils/detect-ai.test.ts +0 -44
  276. package/src/utils/detect-ai.ts +0 -84
  277. package/src/utils/detect-editors.test.ts +0 -48
  278. package/src/utils/detect-editors.ts +0 -57
  279. package/src/utils/git.test.ts +0 -74
  280. package/src/utils/git.ts +0 -117
  281. package/src/utils/local-ai.test.ts +0 -130
  282. package/src/utils/local-ai.ts +0 -116
  283. package/src/utils/multi-git.test.ts +0 -158
  284. package/src/utils/multi-git.ts +0 -405
  285. package/src/utils/prompts.ts +0 -209
  286. package/src/utils/session-finder.ts +0 -483
  287. package/src/utils/system-scanner.test.ts +0 -89
  288. package/src/utils/system-scanner.ts +0 -96
  289. package/src/utils/update-check.ts +0 -286
  290. package/src/utils/workflow-advisor.ts +0 -118
  291. package/src/utils/workflows.test.ts +0 -114
  292. package/src/utils/workflows.ts +0 -178
  293. package/tsconfig.json +0 -19
  294. package/vitest.config.ts +0 -14
package/src/core/sync.ts DELETED
@@ -1,121 +0,0 @@
1
- /**
2
- * @module core/sync
3
- * Headless workspace sync — rebases every repo in a workspace onto its base
4
- * branch, records the per-repo outcome to workspace state, and regenerates
5
- * context files. Produces no console output, so it can back the CLI, the HTTP
6
- * API, and the MCP tool alike.
7
- */
8
-
9
- import * as path from 'node:path';
10
-
11
- import { loadFeatureConfig } from './workspace.js';
12
- import { recordRepoSync } from './workspace-state.js';
13
- import { getWorkspaceRepos, rebaseRepo } from '../utils/multi-git.js';
14
- import { analyzeAllRepos } from '../analyzers/index.js';
15
- import { generateContextFiles } from '../generators/index.js';
16
- import type { SyncStatus, WorkspaceContext } from '../types.js';
17
-
18
- /** Sync outcome for a single repo. */
19
- export interface RepoSyncReport {
20
- /** Directory name of the repo. */
21
- name: string;
22
- /** Classified outcome. */
23
- status: SyncStatus;
24
- /** Human-readable message. */
25
- message: string;
26
- /** Conflict stderr — populated only for `status === 'conflict'`. */
27
- conflict?: string;
28
- }
29
-
30
- /** Aggregated result of syncing an entire workspace. */
31
- export interface SyncReport {
32
- /** Absolute path to the workspace. */
33
- workspacePath: string;
34
- /** Feature branch name being synced. */
35
- branchName: string;
36
- /** Per-repo outcomes, in workspace order. */
37
- repos: RepoSyncReport[];
38
- /** Count of repos that landed cleanly (up-to-date, rebased, or stash-conflict). */
39
- syncedCount: number;
40
- /** Count of repos with a genuine merge conflict. */
41
- conflictCount: number;
42
- /** Count of repos that failed for infrastructure reasons (fetch/auth, etc.). */
43
- errorCount: number;
44
- }
45
-
46
- /** A sync status counts as "synced" when the rebase itself landed. */
47
- function isSynced(status: SyncStatus): boolean {
48
- return status === 'up-to-date' || status === 'rebased' || status === 'stash-conflict';
49
- }
50
-
51
- /**
52
- * Syncs all repos in a workspace. Throws if the workspace configuration cannot
53
- * be loaded; individual repo failures are captured in the returned report
54
- * rather than thrown.
55
- *
56
- * @param workspacePath - Absolute path to the workspace root.
57
- * @returns A structured report of every repo's outcome.
58
- */
59
- export async function syncWorkspace(workspacePath: string): Promise<SyncReport> {
60
- const feature = await loadFeatureConfig(workspacePath);
61
- if (!feature) {
62
- throw new Error(
63
- `Failed to load workspace configuration. Ensure nexusflow.json exists at ${workspacePath}.`,
64
- );
65
- }
66
-
67
- const repos = await getWorkspaceRepos(workspacePath);
68
-
69
- const repoReports: RepoSyncReport[] = [];
70
- let syncedCount = 0;
71
- let conflictCount = 0;
72
- let errorCount = 0;
73
-
74
- for (const repo of repos) {
75
- const defaultBranch = repo.defaultBranch || 'main';
76
- const result = await rebaseRepo(repo.path, defaultBranch);
77
-
78
- await recordRepoSync(workspacePath, repo.name, {
79
- status: result.status,
80
- message: result.message,
81
- });
82
-
83
- repoReports.push({
84
- name: repo.name,
85
- status: result.status,
86
- message: result.message,
87
- conflict: result.conflict,
88
- });
89
-
90
- if (isSynced(result.status)) syncedCount++;
91
- else if (result.status === 'conflict') conflictCount++;
92
- else errorCount++;
93
- }
94
-
95
- // Regenerate maps/context when anything synced. A regen failure must never
96
- // fail the sync itself — the rebases already happened.
97
- if (syncedCount > 0) {
98
- try {
99
- const allRepos = feature.repos.map((r) => ({
100
- name: path.basename(r),
101
- path: r,
102
- defaultBranch: 'main',
103
- }));
104
-
105
- const analysis = await analyzeAllRepos(allRepos);
106
- const ctx: WorkspaceContext = { feature, repos: allRepos, analysis };
107
- await generateContextFiles(ctx, feature.assistants, workspacePath);
108
- } catch {
109
- // Best-effort regeneration; ignore failures.
110
- }
111
- }
112
-
113
- return {
114
- workspacePath,
115
- branchName: feature.branchName,
116
- repos: repoReports,
117
- syncedCount,
118
- conflictCount,
119
- errorCount,
120
- };
121
- }
@@ -1,108 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import * as fs from 'node:fs/promises';
3
- import {
4
- loadWorkspaceState,
5
- recordRepoSync,
6
- markValidated,
7
- } from './workspace-state.js';
8
- import type { WorkspaceState } from '../types.js';
9
-
10
- vi.mock('node:fs/promises');
11
-
12
- /** Parses the JSON written by the most recent writeFile call. */
13
- function lastWritten(): WorkspaceState {
14
- const calls = vi.mocked(fs.writeFile).mock.calls;
15
- const data = calls[calls.length - 1][1] as string;
16
- return JSON.parse(data) as WorkspaceState;
17
- }
18
-
19
- describe('workspace-state', () => {
20
- beforeEach(() => {
21
- vi.clearAllMocks();
22
- vi.mocked(fs.writeFile).mockResolvedValue(undefined);
23
- });
24
-
25
- describe('loadWorkspaceState', () => {
26
- it('returns an empty skeleton when the file is absent', async () => {
27
- vi.mocked(fs.readFile).mockRejectedValue(new Error('ENOENT'));
28
-
29
- const state = await loadWorkspaceState('/ws');
30
-
31
- expect(state.workspacePath).toBe('/ws');
32
- expect(state.repos).toEqual({});
33
- });
34
-
35
- it('round-trips an existing state file', async () => {
36
- const existing: WorkspaceState = {
37
- workspacePath: '/ws',
38
- repos: { api: { repoName: 'api', lastSyncStatus: 'rebased' } },
39
- updatedAt: '2026-01-01T00:00:00.000Z',
40
- };
41
- vi.mocked(fs.readFile).mockResolvedValue(JSON.stringify(existing) as any);
42
-
43
- const state = await loadWorkspaceState('/ws');
44
-
45
- expect(state.repos.api.lastSyncStatus).toBe('rebased');
46
- });
47
- });
48
-
49
- describe('recordRepoSync', () => {
50
- beforeEach(() => {
51
- vi.mocked(fs.readFile).mockRejectedValue(new Error('ENOENT'));
52
- });
53
-
54
- it('sets pendingValidation when a repo was rebased', async () => {
55
- const entry = await recordRepoSync('/ws', 'api', {
56
- status: 'rebased',
57
- message: 'Rebased onto latest base',
58
- });
59
-
60
- expect(entry.pendingValidation).toBe(true);
61
- expect(entry.lastSyncStatus).toBe('rebased');
62
- expect(entry.lastSyncedAt).toBeTruthy();
63
- expect(lastWritten().repos.api.pendingValidation).toBe(true);
64
- });
65
-
66
- it('does not set pendingValidation for an up-to-date repo', async () => {
67
- const entry = await recordRepoSync('/ws', 'api', {
68
- status: 'up-to-date',
69
- message: 'Up to date',
70
- });
71
-
72
- expect(entry.pendingValidation).toBe(false);
73
- });
74
-
75
- it('preserves a prior pending flag on a later no-op sync', async () => {
76
- const existing: WorkspaceState = {
77
- workspacePath: '/ws',
78
- repos: { api: { repoName: 'api', pendingValidation: true } },
79
- updatedAt: '2026-01-01T00:00:00.000Z',
80
- };
81
- vi.mocked(fs.readFile).mockResolvedValue(JSON.stringify(existing) as any);
82
-
83
- const entry = await recordRepoSync('/ws', 'api', {
84
- status: 'up-to-date',
85
- message: 'Up to date',
86
- });
87
-
88
- expect(entry.pendingValidation).toBe(true);
89
- });
90
- });
91
-
92
- describe('markValidated', () => {
93
- it('records the result and clears the pending flag', async () => {
94
- const existing: WorkspaceState = {
95
- workspacePath: '/ws',
96
- repos: { api: { repoName: 'api', pendingValidation: true } },
97
- updatedAt: '2026-01-01T00:00:00.000Z',
98
- };
99
- vi.mocked(fs.readFile).mockResolvedValue(JSON.stringify(existing) as any);
100
-
101
- const entry = await markValidated('/ws', 'api', 'pass');
102
-
103
- expect(entry.lastValidationResult).toBe('pass');
104
- expect(entry.pendingValidation).toBe(false);
105
- expect(entry.lastValidatedAt).toBeTruthy();
106
- });
107
- });
108
- });
@@ -1,130 +0,0 @@
1
- /**
2
- * @module core/workspace-state
3
- * Persists per-repo sync/validation state for a workspace in a single
4
- * `.nexusflow-state.json` file at the workspace root.
5
- *
6
- * Mirrors the lightweight state-file pattern used by `orchestration/runner.ts`
7
- * for running services. Tracks, per repo: when it was last synced, the
8
- * classified result, whether it is pending re-validation, and the last
9
- * validation outcome — so agents no longer need to hand-roll their own state.
10
- */
11
-
12
- import * as fs from 'node:fs/promises';
13
- import * as path from 'node:path';
14
-
15
- import type { RepoSyncState, SyncStatus, WorkspaceState } from '../types.js';
16
-
17
- /** Name of the per-repo state file, written at the workspace root. */
18
- const STATE_FILE = '.nexusflow-state.json';
19
-
20
- /**
21
- * Returns the path to the workspace state file.
22
- */
23
- function getStatePath(workspacePath: string): string {
24
- return path.join(workspacePath, STATE_FILE);
25
- }
26
-
27
- /**
28
- * Loads the workspace state from disk, returning an empty skeleton when the
29
- * file does not exist or cannot be parsed.
30
- *
31
- * @param workspacePath - Absolute path to the workspace root.
32
- */
33
- export async function loadWorkspaceState(
34
- workspacePath: string,
35
- ): Promise<WorkspaceState> {
36
- try {
37
- const raw = await fs.readFile(getStatePath(workspacePath), 'utf-8');
38
- const state = JSON.parse(raw) as WorkspaceState;
39
- // Defend against a malformed/legacy file lacking the repos map.
40
- if (!state.repos || typeof state.repos !== 'object') {
41
- state.repos = {};
42
- }
43
- state.workspacePath = workspacePath;
44
- return state;
45
- } catch {
46
- return {
47
- workspacePath,
48
- repos: {},
49
- updatedAt: new Date().toISOString(),
50
- };
51
- }
52
- }
53
-
54
- /**
55
- * Saves the workspace state to disk.
56
- *
57
- * @param state - The state to persist. Its `updatedAt` is refreshed on write.
58
- */
59
- export async function saveWorkspaceState(state: WorkspaceState): Promise<void> {
60
- const toWrite: WorkspaceState = { ...state, updatedAt: new Date().toISOString() };
61
- const data = JSON.stringify(toWrite, null, 2) + '\n';
62
- await fs.writeFile(getStatePath(state.workspacePath), data, 'utf-8');
63
- }
64
-
65
- /**
66
- * Records the outcome of a sync attempt for a single repo and persists it.
67
- *
68
- * Sets `pendingValidation` to true when new commits were pulled in
69
- * (`status === 'rebased'`), signalling that the repo should be re-validated.
70
- *
71
- * @param workspacePath - Absolute path to the workspace root.
72
- * @param repoName - Directory name of the repo.
73
- * @param result - The classified sync status and message.
74
- * @returns The updated per-repo state entry.
75
- */
76
- export async function recordRepoSync(
77
- workspacePath: string,
78
- repoName: string,
79
- result: { status: SyncStatus; message: string },
80
- ): Promise<RepoSyncState> {
81
- const state = await loadWorkspaceState(workspacePath);
82
- const existing = state.repos[repoName] ?? { repoName };
83
-
84
- const updated: RepoSyncState = {
85
- ...existing,
86
- repoName,
87
- lastSyncedAt: new Date().toISOString(),
88
- lastSyncStatus: result.status,
89
- lastSyncMessage: result.message,
90
- // New commits landed → the repo needs re-validation. Preserve an existing
91
- // pending flag otherwise (a no-op sync doesn't clear prior pending work).
92
- pendingValidation:
93
- result.status === 'rebased' ? true : existing.pendingValidation ?? false,
94
- };
95
-
96
- state.repos[repoName] = updated;
97
- await saveWorkspaceState(state);
98
- return updated;
99
- }
100
-
101
- /**
102
- * Records the result of a validation run (e.g. tests/e2e) for a repo and clears
103
- * its pending-validation flag. Provided for the validation flow that consumes
104
- * `pendingValidation`.
105
- *
106
- * @param workspacePath - Absolute path to the workspace root.
107
- * @param repoName - Directory name of the repo.
108
- * @param result - Whether validation passed or failed.
109
- * @returns The updated per-repo state entry.
110
- */
111
- export async function markValidated(
112
- workspacePath: string,
113
- repoName: string,
114
- result: 'pass' | 'fail',
115
- ): Promise<RepoSyncState> {
116
- const state = await loadWorkspaceState(workspacePath);
117
- const existing = state.repos[repoName] ?? { repoName };
118
-
119
- const updated: RepoSyncState = {
120
- ...existing,
121
- repoName,
122
- lastValidationResult: result,
123
- lastValidatedAt: new Date().toISOString(),
124
- pendingValidation: false,
125
- };
126
-
127
- state.repos[repoName] = updated;
128
- await saveWorkspaceState(state);
129
- return updated;
130
- }