@mrpatronz/nexusflow 0.2.18 → 0.2.19
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.
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +37 -50
- package/dist/commands/sync.js.map +1 -1
- package/dist/core/sync.d.ts +44 -0
- package/dist/core/sync.d.ts.map +1 -0
- package/dist/core/sync.js +82 -0
- package/dist/core/sync.js.map +1 -0
- package/dist/core/workspace-state.d.ts +51 -0
- package/dist/core/workspace-state.d.ts.map +1 -0
- package/dist/core/workspace-state.js +108 -0
- package/dist/core/workspace-state.js.map +1 -0
- package/dist/core/workspace-state.test.d.ts +2 -0
- package/dist/core/workspace-state.test.d.ts.map +1 -0
- package/dist/core/workspace-state.test.js +84 -0
- package/dist/core/workspace-state.test.js.map +1 -0
- package/dist/gui/assets/index-Bdbld6yY.css +1 -0
- package/dist/gui/assets/index-D8iJPvnk.js +26 -0
- package/dist/gui/index.html +2 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +42 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +94 -13
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/multi-git.d.ts +33 -8
- package/dist/utils/multi-git.d.ts.map +1 -1
- package/dist/utils/multi-git.js +91 -19
- package/dist/utils/multi-git.js.map +1 -1
- package/dist/utils/multi-git.test.d.ts +2 -0
- package/dist/utils/multi-git.test.d.ts.map +1 -0
- package/dist/utils/multi-git.test.js +125 -0
- package/dist/utils/multi-git.test.js.map +1 -0
- package/gui/e2e/dashboard.spec.ts +61 -0
- package/gui/e2e/wizard.spec.ts +2 -2
- package/gui/package-lock.json +62 -4
- package/gui/package.json +2 -1
- package/gui/src/App.tsx +168 -227
- package/gui/src/app/AppSidebar.tsx +69 -0
- package/gui/src/components/AddRepoPicker.tsx +81 -0
- package/gui/src/components/ui/Button.tsx +40 -0
- package/gui/src/components/ui/Card.tsx +6 -0
- package/gui/src/components/ui/EmptyState.tsx +22 -0
- package/gui/src/components/ui/Input.tsx +21 -0
- package/gui/src/components/ui/Menu.tsx +71 -0
- package/gui/src/components/ui/Modal.tsx +39 -0
- package/gui/src/components/ui/PageHeader.tsx +21 -0
- package/gui/src/components/ui/RepoStatusStrip.tsx +33 -0
- package/gui/src/components/ui/Skeleton.tsx +5 -0
- package/gui/src/components/ui/StatusPill.tsx +36 -0
- package/gui/src/components/ui/Tabs.tsx +40 -0
- package/gui/src/components/ui/cn.ts +4 -0
- package/gui/src/components/ui/index.ts +16 -0
- package/gui/src/features/services/ServiceConsole.tsx +4 -39
- package/gui/src/index.css +140 -125
- package/gui/src/lib/status.ts +24 -0
- package/gui/src/pages/DashboardPage.tsx +129 -0
- package/gui/src/pages/WorkspacesPage.tsx +352 -0
- package/gui/src/types.ts +19 -0
- package/package.json +1 -1
- package/src/commands/sync.ts +36 -58
- package/src/core/sync.ts +121 -0
- package/src/core/workspace-state.test.ts +108 -0
- package/src/core/workspace-state.ts +130 -0
- package/src/mcp/server.ts +44 -0
- package/src/server.ts +103 -15
- package/src/types.ts +36 -0
- package/src/utils/multi-git.test.ts +158 -0
- package/src/utils/multi-git.ts +117 -25
- package/dist/gui/assets/index-CB-jWded.css +0 -1
- package/dist/gui/assets/index-DDXpZZu3.js +0 -25
- package/gui/src/features/workspace/WorkspaceList.tsx +0 -666
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
}
|
package/src/mcp/server.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as fs from 'node:fs/promises';
|
|
|
9
9
|
import * as path from 'node:path';
|
|
10
10
|
import { loadConfig } from '../core/config.js';
|
|
11
11
|
import { loadFeatureConfig } from '../core/workspace.js';
|
|
12
|
+
import { syncWorkspace } from '../core/sync.js';
|
|
12
13
|
import { callLocalLlm } from '../utils/local-ai.js';
|
|
13
14
|
|
|
14
15
|
export async function startMcpServer(workspacePath?: string) {
|
|
@@ -45,6 +46,19 @@ export async function startMcpServer(workspacePath?: string) {
|
|
|
45
46
|
required: ['query'],
|
|
46
47
|
},
|
|
47
48
|
},
|
|
49
|
+
{
|
|
50
|
+
name: 'sync_workspace',
|
|
51
|
+
description: 'Rebase every repository in the NexusFlow workspace onto its base branch. Safe to call non-interactively: dirty working trees are auto-stashed and restored, so a dirty tree is never mis-reported as a conflict. Returns structured per-repo results (status: up-to-date | rebased | conflict | stash-conflict | error) and records them to the workspace state file.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
workspaceId: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'Optional ID/branchName of the workspace to sync. If omitted, uses the currently active workspace.',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
48
62
|
{
|
|
49
63
|
name: 'get_service_logs',
|
|
50
64
|
description: 'Get the recent logs for a specific running service in the workspace to debug runtime issues.',
|
|
@@ -239,6 +253,36 @@ export async function startMcpServer(workspacePath?: string) {
|
|
|
239
253
|
}
|
|
240
254
|
}
|
|
241
255
|
|
|
256
|
+
if (name === 'sync_workspace') {
|
|
257
|
+
try {
|
|
258
|
+
const feature = await loadFeatureConfig(resolvedWorkspacePath);
|
|
259
|
+
if (!feature) {
|
|
260
|
+
throw new Error(`Workspace not found at ${resolvedWorkspacePath}. Make sure you are in a NexusFlow workspace or provide a valid workspaceId.`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const report = await syncWorkspace(resolvedWorkspacePath);
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
content: [
|
|
267
|
+
{
|
|
268
|
+
type: 'text',
|
|
269
|
+
text: JSON.stringify(report, null, 2),
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
};
|
|
273
|
+
} catch (error: any) {
|
|
274
|
+
return {
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: 'text',
|
|
278
|
+
text: `Error syncing workspace: ${error.message}`,
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
isError: true,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
242
286
|
if (name === 'get_service_logs') {
|
|
243
287
|
const serviceName = (args as any).serviceName;
|
|
244
288
|
const lines = (args as any).lines || 50;
|
package/src/server.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { loadConfig, saveConfig, getConfigDir } from './core/config.js';
|
|
|
21
21
|
import { listStorageProviders } from './core/adapters/registry.js';
|
|
22
22
|
import { scanForRepos } from './core/scanner.js';
|
|
23
23
|
import { createWorkspace, listWorkspaces, loadFeatureConfig, deleteWorkspace, addRepoToWorkspace } from './core/workspace.js';
|
|
24
|
+
import { loadWorkspaceState } from './core/workspace-state.js';
|
|
24
25
|
import { analyzeAllRepos } from './analyzers/index.js';
|
|
25
26
|
import { generateContextFiles } from './generators/index.js';
|
|
26
27
|
import { isOllamaModelAvailable, getOpenAiCompatibleUrl, callLocalLlm } from './utils/local-ai.js';
|
|
@@ -28,7 +29,8 @@ import { detectAIAssistants } from './utils/detect-ai.js';
|
|
|
28
29
|
import { detectEditors } from './utils/detect-editors.js';
|
|
29
30
|
import { findSessions, getSessionTranscript } from './utils/session-finder.js';
|
|
30
31
|
import { scanSystemSpecs } from './utils/system-scanner.js';
|
|
31
|
-
import { getWorkspaceRepos,
|
|
32
|
+
import { getWorkspaceRepos, commitAndPush, getRepoStatus } from './utils/multi-git.js';
|
|
33
|
+
import { syncWorkspace } from './core/sync.js';
|
|
32
34
|
import {
|
|
33
35
|
detectAllServices,
|
|
34
36
|
detectOrchestrationTools,
|
|
@@ -38,7 +40,7 @@ import {
|
|
|
38
40
|
} from './orchestration/index.js';
|
|
39
41
|
import { checkForUpdates, getCurrentVersion, getToolsStatus } from './utils/update-check.js';
|
|
40
42
|
import { getWorkflowTemplates, saveWorkflowTemplate, deleteWorkflowTemplate } from './utils/workflows.js';
|
|
41
|
-
import type { Feature, RepoInfo, WorkspaceContext } from './types.js';
|
|
43
|
+
import type { Feature, RepoInfo, WorkspaceContext, SyncStatus, RepoSyncState } from './types.js';
|
|
42
44
|
import { suggestWorkflow } from './utils/workflow-advisor.js';
|
|
43
45
|
|
|
44
46
|
// Resolve static files directory
|
|
@@ -149,6 +151,91 @@ app.get('/api/workspaces', async (c) => {
|
|
|
149
151
|
}
|
|
150
152
|
});
|
|
151
153
|
|
|
154
|
+
// Severity ranking for picking the worst per-repo sync outcome in a workspace.
|
|
155
|
+
const SYNC_SEVERITY: Record<SyncStatus, number> = {
|
|
156
|
+
conflict: 4,
|
|
157
|
+
'stash-conflict': 3,
|
|
158
|
+
error: 2,
|
|
159
|
+
rebased: 1,
|
|
160
|
+
'up-to-date': 0,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/** Returns the most severe recorded sync status across a workspace's repos. */
|
|
164
|
+
function worstSyncStatus(states: RepoSyncState[]): SyncStatus | 'unknown' {
|
|
165
|
+
let worst: SyncStatus | 'unknown' = 'unknown';
|
|
166
|
+
let worstSeverity = -1;
|
|
167
|
+
for (const s of states) {
|
|
168
|
+
if (!s.lastSyncStatus) continue;
|
|
169
|
+
const severity = SYNC_SEVERITY[s.lastSyncStatus];
|
|
170
|
+
if (severity > worstSeverity) {
|
|
171
|
+
worstSeverity = severity;
|
|
172
|
+
worst = s.lastSyncStatus;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return worst;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 4b. Aggregate at-a-glance status for every workspace (for the listing overview).
|
|
179
|
+
// Cheap on purpose: git status + cached running/sync state only — never fetch/rebase.
|
|
180
|
+
app.get('/api/workspaces/status', async (c) => {
|
|
181
|
+
try {
|
|
182
|
+
const config = await loadConfig();
|
|
183
|
+
const workspaces = await listWorkspaces(config.workspacesDir);
|
|
184
|
+
|
|
185
|
+
const entries = await Promise.all(
|
|
186
|
+
workspaces.map(async (ws) => {
|
|
187
|
+
const workspacePath =
|
|
188
|
+
ws.workspacePath || path.join(config.workspacesDir, ws.branchName);
|
|
189
|
+
const status = {
|
|
190
|
+
id: ws.id,
|
|
191
|
+
branchName: ws.branchName,
|
|
192
|
+
changedFiles: 0,
|
|
193
|
+
dirtyRepos: 0,
|
|
194
|
+
runningServices: 0,
|
|
195
|
+
syncStatus: 'unknown' as SyncStatus | 'unknown',
|
|
196
|
+
pendingValidation: false,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
// Uncommitted changes across the workspace's repo worktrees.
|
|
201
|
+
for (const repoPath of ws.repos) {
|
|
202
|
+
const worktreePath = path.join(workspacePath, path.basename(repoPath));
|
|
203
|
+
const repoStatus = await getRepoStatus(worktreePath);
|
|
204
|
+
if (repoStatus.hasChanges) {
|
|
205
|
+
status.dirtyRepos += 1;
|
|
206
|
+
status.changedFiles += repoStatus.changedFiles.length;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Running services (cached running-state, PM2-verified — same source as
|
|
211
|
+
// the Services tab; only workspaces that ever started services touch PM2).
|
|
212
|
+
const runningState = await loadRunningState(workspacePath);
|
|
213
|
+
status.runningServices = runningState?.services?.length ?? 0;
|
|
214
|
+
|
|
215
|
+
// Sync state: worst-case classification + any repo pending validation.
|
|
216
|
+
const wsState = await loadWorkspaceState(workspacePath);
|
|
217
|
+
const repoStates = Object.values(wsState.repos);
|
|
218
|
+
status.syncStatus = worstSyncStatus(repoStates);
|
|
219
|
+
status.pendingValidation = repoStates.some((r) => r.pendingValidation);
|
|
220
|
+
} catch {
|
|
221
|
+
// Leave defaults on any per-workspace failure so one bad repo doesn't
|
|
222
|
+
// fail the whole response.
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return status;
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// Keyed by branchName to match how the GUI looks up a workspace.
|
|
230
|
+
const byWorkspace: Record<string, (typeof entries)[number]> = {};
|
|
231
|
+
for (const entry of entries) byWorkspace[entry.branchName] = entry;
|
|
232
|
+
return c.json(byWorkspace);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
235
|
+
return c.json({ error: msg }, 500);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
152
239
|
// 5. Detect available AI assistants
|
|
153
240
|
app.get('/api/ai-detect', async (c) => {
|
|
154
241
|
try {
|
|
@@ -861,20 +948,21 @@ app.post('/api/workspace/:id/sync', async (c) => {
|
|
|
861
948
|
const config = await loadConfig();
|
|
862
949
|
const workspacePath = path.join(config.workspacesDir, id);
|
|
863
950
|
|
|
864
|
-
const
|
|
865
|
-
const results =
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
message: result.message,
|
|
873
|
-
conflict: result.conflict,
|
|
874
|
-
});
|
|
875
|
-
}
|
|
951
|
+
const report = await syncWorkspace(workspacePath);
|
|
952
|
+
const results = report.repos.map((repo) => ({
|
|
953
|
+
repoName: repo.name,
|
|
954
|
+
success: repo.status !== 'conflict' && repo.status !== 'error',
|
|
955
|
+
status: repo.status,
|
|
956
|
+
message: repo.message,
|
|
957
|
+
conflict: repo.conflict,
|
|
958
|
+
}));
|
|
876
959
|
|
|
877
|
-
return c.json({
|
|
960
|
+
return c.json({
|
|
961
|
+
results,
|
|
962
|
+
syncedCount: report.syncedCount,
|
|
963
|
+
conflictCount: report.conflictCount,
|
|
964
|
+
errorCount: report.errorCount,
|
|
965
|
+
});
|
|
878
966
|
} catch (error) {
|
|
879
967
|
const msg = error instanceof Error ? error.message : String(error);
|
|
880
968
|
return c.json({ error: msg }, 500);
|
package/src/types.ts
CHANGED
|
@@ -397,6 +397,42 @@ export interface RunningState {
|
|
|
397
397
|
updatedAt: string;
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
// ─── Per-Repo Sync State ──────────────────────────────────────────────────
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Classified outcome of a sync/rebase attempt for a single repo.
|
|
404
|
+
* See `utils/multi-git.ts` for the meaning of each value.
|
|
405
|
+
*/
|
|
406
|
+
export type SyncStatus = 'up-to-date' | 'rebased' | 'conflict' | 'stash-conflict' | 'error';
|
|
407
|
+
|
|
408
|
+
/** Persisted sync/validation state for a single repo in a workspace. */
|
|
409
|
+
export interface RepoSyncState {
|
|
410
|
+
/** Directory name of the repo. */
|
|
411
|
+
repoName: string;
|
|
412
|
+
/** ISO timestamp of the last sync attempt. */
|
|
413
|
+
lastSyncedAt?: string;
|
|
414
|
+
/** Classified result of the last sync. */
|
|
415
|
+
lastSyncStatus?: SyncStatus;
|
|
416
|
+
/** Human-readable message from the last sync. */
|
|
417
|
+
lastSyncMessage?: string;
|
|
418
|
+
/** True when the repo pulled in new commits and has not yet been re-validated. */
|
|
419
|
+
pendingValidation?: boolean;
|
|
420
|
+
/** Result of the last validation run (e.g. test/e2e), if any. */
|
|
421
|
+
lastValidationResult?: 'pass' | 'fail' | null;
|
|
422
|
+
/** ISO timestamp of the last validation run. */
|
|
423
|
+
lastValidatedAt?: string;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** State file saved to track per-repo sync/validation status (`.nexusflow-state.json`). */
|
|
427
|
+
export interface WorkspaceState {
|
|
428
|
+
/** Workspace path this state belongs to. */
|
|
429
|
+
workspacePath: string;
|
|
430
|
+
/** Per-repo state, keyed by repo name. */
|
|
431
|
+
repos: Record<string, RepoSyncState>;
|
|
432
|
+
/** Timestamp when the state was last updated. */
|
|
433
|
+
updatedAt: string;
|
|
434
|
+
}
|
|
435
|
+
|
|
400
436
|
// ─── Phase 3: Dependency Graph Types ──────────────────────────────────────
|
|
401
437
|
|
|
402
438
|
/** A node in the workspace dependency graph. */
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { rebaseRepo } from './multi-git.js';
|
|
4
|
+
|
|
5
|
+
vi.mock('execa');
|
|
6
|
+
|
|
7
|
+
/** Builds an execa-style error carrying stderr (as execa does on non-zero exit). */
|
|
8
|
+
function gitError(stderr: string): Error {
|
|
9
|
+
return Object.assign(new Error('git failed'), { stderr });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface GitMockOpts {
|
|
13
|
+
fetchError?: Error;
|
|
14
|
+
statusStdout?: string; // output of `git status --porcelain` ('' = clean)
|
|
15
|
+
stashPushError?: Error;
|
|
16
|
+
stashPopError?: Error;
|
|
17
|
+
rebaseError?: Error;
|
|
18
|
+
rebaseStdout?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Resolves a single mocked `git` call by subcommand. */
|
|
22
|
+
async function routeGit(a: string[], opts: GitMockOpts): Promise<{ stdout: string }> {
|
|
23
|
+
const sub = a[0];
|
|
24
|
+
if (sub === 'fetch') {
|
|
25
|
+
if (opts.fetchError) throw opts.fetchError;
|
|
26
|
+
return { stdout: '' };
|
|
27
|
+
}
|
|
28
|
+
if (sub === 'status') {
|
|
29
|
+
return { stdout: opts.statusStdout ?? '' };
|
|
30
|
+
}
|
|
31
|
+
if (sub === 'stash' && a[1] === 'push') {
|
|
32
|
+
if (opts.stashPushError) throw opts.stashPushError;
|
|
33
|
+
return { stdout: '' };
|
|
34
|
+
}
|
|
35
|
+
if (sub === 'stash' && a[1] === 'pop') {
|
|
36
|
+
if (opts.stashPopError) throw opts.stashPopError;
|
|
37
|
+
return { stdout: '' };
|
|
38
|
+
}
|
|
39
|
+
if (sub === 'rebase' && a[1] === '--abort') {
|
|
40
|
+
return { stdout: '' };
|
|
41
|
+
}
|
|
42
|
+
if (sub === 'rebase') {
|
|
43
|
+
if (opts.rebaseError) throw opts.rebaseError;
|
|
44
|
+
return { stdout: opts.rebaseStdout ?? 'Successfully rebased.' };
|
|
45
|
+
}
|
|
46
|
+
return { stdout: '' };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Routes mocked `git` calls by subcommand so each test declares only what matters. */
|
|
50
|
+
function mockGit(opts: GitMockOpts): void {
|
|
51
|
+
vi.mocked(execa).mockImplementation(((_file: any, args: any) =>
|
|
52
|
+
routeGit(args as string[], opts)) as any);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Returns the recorded execa calls as arrays of git args. */
|
|
56
|
+
function gitCalls(): string[][] {
|
|
57
|
+
return vi.mocked(execa).mock.calls.map((c) => c[1] as string[]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('rebaseRepo', () => {
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
vi.clearAllMocks();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('reports "rebased" for a clean tree with new base commits', async () => {
|
|
66
|
+
mockGit({ statusStdout: '', rebaseStdout: 'Successfully rebased and updated.' });
|
|
67
|
+
|
|
68
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
69
|
+
|
|
70
|
+
expect(result.success).toBe(true);
|
|
71
|
+
expect(result.status).toBe('rebased');
|
|
72
|
+
expect(result.stashed).toBeFalsy();
|
|
73
|
+
// No stash should be created for a clean tree.
|
|
74
|
+
expect(gitCalls().some((c) => c[0] === 'stash')).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('reports "up-to-date" when already current', async () => {
|
|
78
|
+
mockGit({ statusStdout: '', rebaseStdout: 'Current branch feature is up to date.' });
|
|
79
|
+
|
|
80
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
81
|
+
|
|
82
|
+
expect(result.success).toBe(true);
|
|
83
|
+
expect(result.status).toBe('up-to-date');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('auto-stashes a dirty tree and restores it (the regression fix)', async () => {
|
|
87
|
+
mockGit({ statusStdout: ' M src/app.ts\n', rebaseStdout: 'Successfully rebased.' });
|
|
88
|
+
|
|
89
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
90
|
+
|
|
91
|
+
expect(result.success).toBe(true);
|
|
92
|
+
expect(result.status).toBe('rebased');
|
|
93
|
+
expect(result.stashed).toBe(true);
|
|
94
|
+
|
|
95
|
+
const calls = gitCalls();
|
|
96
|
+
// Stash push (with untracked) before rebase, stash pop after.
|
|
97
|
+
expect(calls).toContainEqual(['stash', 'push', '-u', '-m', 'nexusflow-autostash']);
|
|
98
|
+
expect(calls).toContainEqual(['stash', 'pop']);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('classifies a fetch failure as "error", not a conflict', async () => {
|
|
102
|
+
mockGit({ fetchError: gitError('fatal: unable to access origin: Could not resolve host') });
|
|
103
|
+
|
|
104
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
105
|
+
|
|
106
|
+
expect(result.success).toBe(false);
|
|
107
|
+
expect(result.status).toBe('error');
|
|
108
|
+
expect(result.message).toMatch(/^Fetch failed:/);
|
|
109
|
+
expect(result.conflict).toBeUndefined();
|
|
110
|
+
// Should never attempt a rebase if fetch failed.
|
|
111
|
+
expect(gitCalls().some((c) => c[0] === 'rebase')).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('classifies a real merge conflict as "conflict" and aborts', async () => {
|
|
115
|
+
mockGit({
|
|
116
|
+
statusStdout: '',
|
|
117
|
+
rebaseError: gitError('CONFLICT (content): Merge conflict in src/app.ts'),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
121
|
+
|
|
122
|
+
expect(result.success).toBe(false);
|
|
123
|
+
expect(result.status).toBe('conflict');
|
|
124
|
+
expect(result.conflict).toContain('CONFLICT');
|
|
125
|
+
expect(gitCalls()).toContainEqual(['rebase', '--abort']);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('restores the stash after aborting a conflicting rebase on a dirty tree', async () => {
|
|
129
|
+
mockGit({
|
|
130
|
+
statusStdout: ' M src/app.ts\n',
|
|
131
|
+
rebaseError: gitError('CONFLICT (content): Merge conflict'),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
135
|
+
|
|
136
|
+
expect(result.status).toBe('conflict');
|
|
137
|
+
expect(result.stashed).toBe(true);
|
|
138
|
+
const calls = gitCalls();
|
|
139
|
+
expect(calls).toContainEqual(['rebase', '--abort']);
|
|
140
|
+
expect(calls).toContainEqual(['stash', 'pop']); // local work restored
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('reports "stash-conflict" when the rebase lands but the stash pop conflicts', async () => {
|
|
144
|
+
mockGit({
|
|
145
|
+
statusStdout: ' M src/app.ts\n',
|
|
146
|
+
rebaseStdout: 'Successfully rebased.',
|
|
147
|
+
stashPopError: gitError('CONFLICT (content): Merge conflict in src/app.ts'),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const result = await rebaseRepo('/repo', 'main');
|
|
151
|
+
|
|
152
|
+
// The rebase itself succeeded, so success is true, but it needs attention.
|
|
153
|
+
expect(result.success).toBe(true);
|
|
154
|
+
expect(result.status).toBe('stash-conflict');
|
|
155
|
+
expect(result.stashed).toBe(true);
|
|
156
|
+
expect(result.message).toMatch(/stash preserved/i);
|
|
157
|
+
});
|
|
158
|
+
});
|