@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoCtE"}
|
package/dist/commands/sync.js
CHANGED
|
@@ -8,9 +8,7 @@ import * as path from 'node:path';
|
|
|
8
8
|
import * as fs from 'node:fs/promises';
|
|
9
9
|
import { loadConfig } from '../core/config.js';
|
|
10
10
|
import { listWorkspaces, loadFeatureConfig } from '../core/workspace.js';
|
|
11
|
-
import {
|
|
12
|
-
import { analyzeAllRepos } from '../analyzers/index.js';
|
|
13
|
-
import { generateContextFiles } from '../generators/index.js';
|
|
11
|
+
import { syncWorkspace } from '../core/sync.js';
|
|
14
12
|
/**
|
|
15
13
|
* Executes the sync command.
|
|
16
14
|
*
|
|
@@ -28,60 +26,49 @@ export async function syncCommand(workspaceArg) {
|
|
|
28
26
|
}
|
|
29
27
|
console.log(chalk.bold(`Syncing workspace: ${chalk.cyan(feature.branchName)}`));
|
|
30
28
|
console.log(chalk.dim(`Path: ${workspacePath}\n`));
|
|
31
|
-
let
|
|
29
|
+
let report;
|
|
32
30
|
try {
|
|
33
|
-
|
|
31
|
+
report = await syncWorkspace(workspacePath);
|
|
34
32
|
}
|
|
35
33
|
catch (error) {
|
|
36
|
-
console.error(chalk.red(`✖ Failed to
|
|
34
|
+
console.error(chalk.red(`✖ Failed to sync: ${error instanceof Error ? error.message : String(error)}`));
|
|
37
35
|
return;
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
let conflictCount = 0;
|
|
41
|
-
for (const repo of repos) {
|
|
37
|
+
for (const repo of report.repos) {
|
|
42
38
|
console.log(`Repository: ${chalk.bold(repo.name)}`);
|
|
43
|
-
|
|
44
|
-
const spinner = chalk.dim(' Rebasing...');
|
|
45
|
-
process.stdout.write(spinner);
|
|
46
|
-
const result = await rebaseRepo(repo.path, defaultBranch);
|
|
47
|
-
// Clear rebase message line
|
|
48
|
-
process.stdout.write('\r' + ' '.repeat(spinner.length) + '\r');
|
|
49
|
-
if (result.success) {
|
|
50
|
-
console.log(` ${chalk.green('✅')} Synced (${result.message})`);
|
|
51
|
-
syncedCount++;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
console.log(` ${chalk.red('⚠️')} Conflict: ${result.message}`);
|
|
55
|
-
if (result.conflict) {
|
|
56
|
-
console.log(chalk.dim(result.conflict.split('\n').map(l => ` ${l}`).slice(0, 5).join('\n')));
|
|
57
|
-
}
|
|
58
|
-
conflictCount++;
|
|
59
|
-
}
|
|
39
|
+
renderRepoResult(repo);
|
|
60
40
|
}
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
41
|
+
const parts = [`${report.syncedCount} synced`];
|
|
42
|
+
if (report.conflictCount > 0)
|
|
43
|
+
parts.push(`${report.conflictCount} conflict(s)`);
|
|
44
|
+
if (report.errorCount > 0)
|
|
45
|
+
parts.push(`${report.errorCount} error(s)`);
|
|
46
|
+
console.log(`\n📊 ${chalk.bold('Summary:')} ${parts.join(', ')}\n`);
|
|
47
|
+
if (report.syncedCount > 0) {
|
|
48
|
+
console.log(chalk.green('✅ Workspace maps and contexts updated.\n'));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Prints a single repo's sync outcome with status-appropriate styling.
|
|
53
|
+
*/
|
|
54
|
+
function renderRepoResult(repo) {
|
|
55
|
+
switch (repo.status) {
|
|
56
|
+
case 'up-to-date':
|
|
57
|
+
case 'rebased':
|
|
58
|
+
console.log(` ${chalk.green('✅')} Synced (${repo.message})`);
|
|
59
|
+
break;
|
|
60
|
+
case 'stash-conflict':
|
|
61
|
+
console.log(` ${chalk.yellow('⚠️')} ${repo.message}`);
|
|
62
|
+
break;
|
|
63
|
+
case 'conflict':
|
|
64
|
+
console.log(` ${chalk.red('❌')} Conflict: ${repo.message}`);
|
|
65
|
+
if (repo.conflict) {
|
|
66
|
+
console.log(chalk.dim(repo.conflict.split('\n').map(l => ` ${l}`).slice(0, 5).join('\n')));
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'error':
|
|
70
|
+
console.log(` ${chalk.red('🔌')} ${repo.message}`);
|
|
71
|
+
break;
|
|
85
72
|
}
|
|
86
73
|
}
|
|
87
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AAErE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,YAAqB;IACrD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC,CAAC;IAErE,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC3D,IAAI,CAAC,aAAa;QAAE,OAAO;IAE3B,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,aAAa,CAAC,CAAC;IACvD,IAAI,C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UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAC3C,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CACjD,CAAC;YACF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC3B,IAAI,EAAE,GAAG,EAAE,CAAC,UAAU,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,EAAE;gBACnE,KAAK,EAAE,EAAE,CAAC,aAAa;aACxB,CAAC,CAAC,CAAC;QACN,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
import type { SyncStatus } from '../types.js';
|
|
9
|
+
/** Sync outcome for a single repo. */
|
|
10
|
+
export interface RepoSyncReport {
|
|
11
|
+
/** Directory name of the repo. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Classified outcome. */
|
|
14
|
+
status: SyncStatus;
|
|
15
|
+
/** Human-readable message. */
|
|
16
|
+
message: string;
|
|
17
|
+
/** Conflict stderr — populated only for `status === 'conflict'`. */
|
|
18
|
+
conflict?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Aggregated result of syncing an entire workspace. */
|
|
21
|
+
export interface SyncReport {
|
|
22
|
+
/** Absolute path to the workspace. */
|
|
23
|
+
workspacePath: string;
|
|
24
|
+
/** Feature branch name being synced. */
|
|
25
|
+
branchName: string;
|
|
26
|
+
/** Per-repo outcomes, in workspace order. */
|
|
27
|
+
repos: RepoSyncReport[];
|
|
28
|
+
/** Count of repos that landed cleanly (up-to-date, rebased, or stash-conflict). */
|
|
29
|
+
syncedCount: number;
|
|
30
|
+
/** Count of repos with a genuine merge conflict. */
|
|
31
|
+
conflictCount: number;
|
|
32
|
+
/** Count of repos that failed for infrastructure reasons (fetch/auth, etc.). */
|
|
33
|
+
errorCount: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Syncs all repos in a workspace. Throws if the workspace configuration cannot
|
|
37
|
+
* be loaded; individual repo failures are captured in the returned report
|
|
38
|
+
* rather than thrown.
|
|
39
|
+
*
|
|
40
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
41
|
+
* @returns A structured report of every repo's outcome.
|
|
42
|
+
*/
|
|
43
|
+
export declare function syncWorkspace(workspacePath: string): Promise<SyncReport>;
|
|
44
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/core/sync.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAEhE,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wDAAwD;AACxD,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,mFAAmF;IACnF,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;CACpB;AAOD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA8D9E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
import * as path from 'node:path';
|
|
9
|
+
import { loadFeatureConfig } from './workspace.js';
|
|
10
|
+
import { recordRepoSync } from './workspace-state.js';
|
|
11
|
+
import { getWorkspaceRepos, rebaseRepo } from '../utils/multi-git.js';
|
|
12
|
+
import { analyzeAllRepos } from '../analyzers/index.js';
|
|
13
|
+
import { generateContextFiles } from '../generators/index.js';
|
|
14
|
+
/** A sync status counts as "synced" when the rebase itself landed. */
|
|
15
|
+
function isSynced(status) {
|
|
16
|
+
return status === 'up-to-date' || status === 'rebased' || status === 'stash-conflict';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Syncs all repos in a workspace. Throws if the workspace configuration cannot
|
|
20
|
+
* be loaded; individual repo failures are captured in the returned report
|
|
21
|
+
* rather than thrown.
|
|
22
|
+
*
|
|
23
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
24
|
+
* @returns A structured report of every repo's outcome.
|
|
25
|
+
*/
|
|
26
|
+
export async function syncWorkspace(workspacePath) {
|
|
27
|
+
const feature = await loadFeatureConfig(workspacePath);
|
|
28
|
+
if (!feature) {
|
|
29
|
+
throw new Error(`Failed to load workspace configuration. Ensure nexusflow.json exists at ${workspacePath}.`);
|
|
30
|
+
}
|
|
31
|
+
const repos = await getWorkspaceRepos(workspacePath);
|
|
32
|
+
const repoReports = [];
|
|
33
|
+
let syncedCount = 0;
|
|
34
|
+
let conflictCount = 0;
|
|
35
|
+
let errorCount = 0;
|
|
36
|
+
for (const repo of repos) {
|
|
37
|
+
const defaultBranch = repo.defaultBranch || 'main';
|
|
38
|
+
const result = await rebaseRepo(repo.path, defaultBranch);
|
|
39
|
+
await recordRepoSync(workspacePath, repo.name, {
|
|
40
|
+
status: result.status,
|
|
41
|
+
message: result.message,
|
|
42
|
+
});
|
|
43
|
+
repoReports.push({
|
|
44
|
+
name: repo.name,
|
|
45
|
+
status: result.status,
|
|
46
|
+
message: result.message,
|
|
47
|
+
conflict: result.conflict,
|
|
48
|
+
});
|
|
49
|
+
if (isSynced(result.status))
|
|
50
|
+
syncedCount++;
|
|
51
|
+
else if (result.status === 'conflict')
|
|
52
|
+
conflictCount++;
|
|
53
|
+
else
|
|
54
|
+
errorCount++;
|
|
55
|
+
}
|
|
56
|
+
// Regenerate maps/context when anything synced. A regen failure must never
|
|
57
|
+
// fail the sync itself — the rebases already happened.
|
|
58
|
+
if (syncedCount > 0) {
|
|
59
|
+
try {
|
|
60
|
+
const allRepos = feature.repos.map((r) => ({
|
|
61
|
+
name: path.basename(r),
|
|
62
|
+
path: r,
|
|
63
|
+
defaultBranch: 'main',
|
|
64
|
+
}));
|
|
65
|
+
const analysis = await analyzeAllRepos(allRepos);
|
|
66
|
+
const ctx = { feature, repos: allRepos, analysis };
|
|
67
|
+
await generateContextFiles(ctx, feature.assistants, workspacePath);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Best-effort regeneration; ignore failures.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
workspacePath,
|
|
75
|
+
branchName: feature.branchName,
|
|
76
|
+
repos: repoReports,
|
|
77
|
+
syncedCount,
|
|
78
|
+
conflictCount,
|
|
79
|
+
errorCount,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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
@@ -0,0 +1,51 @@
|
|
|
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
|
+
import type { RepoSyncState, SyncStatus, WorkspaceState } from '../types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Loads the workspace state from disk, returning an empty skeleton when the
|
|
14
|
+
* file does not exist or cannot be parsed.
|
|
15
|
+
*
|
|
16
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
17
|
+
*/
|
|
18
|
+
export declare function loadWorkspaceState(workspacePath: string): Promise<WorkspaceState>;
|
|
19
|
+
/**
|
|
20
|
+
* Saves the workspace state to disk.
|
|
21
|
+
*
|
|
22
|
+
* @param state - The state to persist. Its `updatedAt` is refreshed on write.
|
|
23
|
+
*/
|
|
24
|
+
export declare function saveWorkspaceState(state: WorkspaceState): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Records the outcome of a sync attempt for a single repo and persists it.
|
|
27
|
+
*
|
|
28
|
+
* Sets `pendingValidation` to true when new commits were pulled in
|
|
29
|
+
* (`status === 'rebased'`), signalling that the repo should be re-validated.
|
|
30
|
+
*
|
|
31
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
32
|
+
* @param repoName - Directory name of the repo.
|
|
33
|
+
* @param result - The classified sync status and message.
|
|
34
|
+
* @returns The updated per-repo state entry.
|
|
35
|
+
*/
|
|
36
|
+
export declare function recordRepoSync(workspacePath: string, repoName: string, result: {
|
|
37
|
+
status: SyncStatus;
|
|
38
|
+
message: string;
|
|
39
|
+
}): Promise<RepoSyncState>;
|
|
40
|
+
/**
|
|
41
|
+
* Records the result of a validation run (e.g. tests/e2e) for a repo and clears
|
|
42
|
+
* its pending-validation flag. Provided for the validation flow that consumes
|
|
43
|
+
* `pendingValidation`.
|
|
44
|
+
*
|
|
45
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
46
|
+
* @param repoName - Directory name of the repo.
|
|
47
|
+
* @param result - Whether validation passed or failed.
|
|
48
|
+
* @returns The updated per-repo state entry.
|
|
49
|
+
*/
|
|
50
|
+
export declare function markValidated(workspacePath: string, repoName: string, result: 'pass' | 'fail'): Promise<RepoSyncState>;
|
|
51
|
+
//# sourceMappingURL=workspace-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-state.d.ts","sourceRoot":"","sources":["../../src/core/workspace-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAY7E;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,CAAC,CAiBzB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAI7E;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,aAAa,CAAC,CAmBxB;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,GACtB,OAAO,CAAC,aAAa,CAAC,CAexB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
import * as fs from 'node:fs/promises';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
/** Name of the per-repo state file, written at the workspace root. */
|
|
14
|
+
const STATE_FILE = '.nexusflow-state.json';
|
|
15
|
+
/**
|
|
16
|
+
* Returns the path to the workspace state file.
|
|
17
|
+
*/
|
|
18
|
+
function getStatePath(workspacePath) {
|
|
19
|
+
return path.join(workspacePath, STATE_FILE);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Loads the workspace state from disk, returning an empty skeleton when the
|
|
23
|
+
* file does not exist or cannot be parsed.
|
|
24
|
+
*
|
|
25
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
26
|
+
*/
|
|
27
|
+
export async function loadWorkspaceState(workspacePath) {
|
|
28
|
+
try {
|
|
29
|
+
const raw = await fs.readFile(getStatePath(workspacePath), 'utf-8');
|
|
30
|
+
const state = JSON.parse(raw);
|
|
31
|
+
// Defend against a malformed/legacy file lacking the repos map.
|
|
32
|
+
if (!state.repos || typeof state.repos !== 'object') {
|
|
33
|
+
state.repos = {};
|
|
34
|
+
}
|
|
35
|
+
state.workspacePath = workspacePath;
|
|
36
|
+
return state;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return {
|
|
40
|
+
workspacePath,
|
|
41
|
+
repos: {},
|
|
42
|
+
updatedAt: new Date().toISOString(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Saves the workspace state to disk.
|
|
48
|
+
*
|
|
49
|
+
* @param state - The state to persist. Its `updatedAt` is refreshed on write.
|
|
50
|
+
*/
|
|
51
|
+
export async function saveWorkspaceState(state) {
|
|
52
|
+
const toWrite = { ...state, updatedAt: new Date().toISOString() };
|
|
53
|
+
const data = JSON.stringify(toWrite, null, 2) + '\n';
|
|
54
|
+
await fs.writeFile(getStatePath(state.workspacePath), data, 'utf-8');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Records the outcome of a sync attempt for a single repo and persists it.
|
|
58
|
+
*
|
|
59
|
+
* Sets `pendingValidation` to true when new commits were pulled in
|
|
60
|
+
* (`status === 'rebased'`), signalling that the repo should be re-validated.
|
|
61
|
+
*
|
|
62
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
63
|
+
* @param repoName - Directory name of the repo.
|
|
64
|
+
* @param result - The classified sync status and message.
|
|
65
|
+
* @returns The updated per-repo state entry.
|
|
66
|
+
*/
|
|
67
|
+
export async function recordRepoSync(workspacePath, repoName, result) {
|
|
68
|
+
const state = await loadWorkspaceState(workspacePath);
|
|
69
|
+
const existing = state.repos[repoName] ?? { repoName };
|
|
70
|
+
const updated = {
|
|
71
|
+
...existing,
|
|
72
|
+
repoName,
|
|
73
|
+
lastSyncedAt: new Date().toISOString(),
|
|
74
|
+
lastSyncStatus: result.status,
|
|
75
|
+
lastSyncMessage: result.message,
|
|
76
|
+
// New commits landed → the repo needs re-validation. Preserve an existing
|
|
77
|
+
// pending flag otherwise (a no-op sync doesn't clear prior pending work).
|
|
78
|
+
pendingValidation: result.status === 'rebased' ? true : existing.pendingValidation ?? false,
|
|
79
|
+
};
|
|
80
|
+
state.repos[repoName] = updated;
|
|
81
|
+
await saveWorkspaceState(state);
|
|
82
|
+
return updated;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Records the result of a validation run (e.g. tests/e2e) for a repo and clears
|
|
86
|
+
* its pending-validation flag. Provided for the validation flow that consumes
|
|
87
|
+
* `pendingValidation`.
|
|
88
|
+
*
|
|
89
|
+
* @param workspacePath - Absolute path to the workspace root.
|
|
90
|
+
* @param repoName - Directory name of the repo.
|
|
91
|
+
* @param result - Whether validation passed or failed.
|
|
92
|
+
* @returns The updated per-repo state entry.
|
|
93
|
+
*/
|
|
94
|
+
export async function markValidated(workspacePath, repoName, result) {
|
|
95
|
+
const state = await loadWorkspaceState(workspacePath);
|
|
96
|
+
const existing = state.repos[repoName] ?? { repoName };
|
|
97
|
+
const updated = {
|
|
98
|
+
...existing,
|
|
99
|
+
repoName,
|
|
100
|
+
lastValidationResult: result,
|
|
101
|
+
lastValidatedAt: new Date().toISOString(),
|
|
102
|
+
pendingValidation: false,
|
|
103
|
+
};
|
|
104
|
+
state.repos[repoName] = updated;
|
|
105
|
+
await saveWorkspaceState(state);
|
|
106
|
+
return updated;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=workspace-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-state.js","sourceRoot":"","sources":["../../src/core/workspace-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC,sEAAsE;AACtE,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C;;GAEG;AACH,SAAS,YAAY,CAAC,aAAqB;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,aAAqB;IAErB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;QACpE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAmB,CAAC;QAChD,gEAAgE;QAChE,IA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QAC1E,iBAAiB,EACf,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,iBAAiB,IAAI,KAAK;KAC3E,CAAC;IAEF,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;IAChC,MAAM,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,aAAqB,EACrB,QAAgB,EAChB,MAAuB;IAEvB,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,aAAa,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;IAEvD,MAAM,OAAO,GAAkB;QAC7B,GAAG,QAAQ;QACX,QAAQ;QACR,oBAAoB,EAAE,MAAM;QAC5B,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACzC,iBAAiB,EAAE,KAAK;KACzB,CAAC;IAEF,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;IAChC,MAAM,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-state.test.d.ts","sourceRoot":"","sources":["../../src/core/workspace-state.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { loadWorkspaceState, recordRepoSync, markValidated, } from './workspace-state.js';
|
|
4
|
+
vi.mock('node:fs/promises');
|
|
5
|
+
/** Parses the JSON written by the most recent writeFile call. */
|
|
6
|
+
function lastWritten() {
|
|
7
|
+
const calls = vi.mocked(fs.writeFile).mock.calls;
|
|
8
|
+
const data = calls[calls.length - 1][1];
|
|
9
|
+
return JSON.parse(data);
|
|
10
|
+
}
|
|
11
|
+
describe('workspace-state', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
vi.clearAllMocks();
|
|
14
|
+
vi.mocked(fs.writeFile).mockResolvedValue(undefined);
|
|
15
|
+
});
|
|
16
|
+
describe('loadWorkspaceState', () => {
|
|
17
|
+
it('returns an empty skeleton when the file is absent', async () => {
|
|
18
|
+
vi.mocked(fs.readFile).mockRejectedValue(new Error('ENOENT'));
|
|
19
|
+
const state = await loadWorkspaceState('/ws');
|
|
20
|
+
expect(state.workspacePath).toBe('/ws');
|
|
21
|
+
expect(state.repos).toEqual({});
|
|
22
|
+
});
|
|
23
|
+
it('round-trips an existing state file', async () => {
|
|
24
|
+
const existing = {
|
|
25
|
+
workspacePath: '/ws',
|
|
26
|
+
repos: { api: { repoName: 'api', lastSyncStatus: 'rebased' } },
|
|
27
|
+
updatedAt: '2026-01-01T00:00:00.000Z',
|
|
28
|
+
};
|
|
29
|
+
vi.mocked(fs.readFile).mockResolvedValue(JSON.stringify(existing));
|
|
30
|
+
const state = await loadWorkspaceState('/ws');
|
|
31
|
+
expect(state.repos.api.lastSyncStatus).toBe('rebased');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('recordRepoSync', () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
vi.mocked(fs.readFile).mockRejectedValue(new Error('ENOENT'));
|
|
37
|
+
});
|
|
38
|
+
it('sets pendingValidation when a repo was rebased', async () => {
|
|
39
|
+
const entry = await recordRepoSync('/ws', 'api', {
|
|
40
|
+
status: 'rebased',
|
|
41
|
+
message: 'Rebased onto latest base',
|
|
42
|
+
});
|
|
43
|
+
expect(entry.pendingValidation).toBe(true);
|
|
44
|
+
expect(entry.lastSyncStatus).toBe('rebased');
|
|
45
|
+
expect(entry.lastSyncedAt).toBeTruthy();
|
|
46
|
+
expect(lastWritten().repos.api.pendingValidation).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('does not set pendingValidation for an up-to-date repo', async () => {
|
|
49
|
+
const entry = await recordRepoSync('/ws', 'api', {
|
|
50
|
+
status: 'up-to-date',
|
|
51
|
+
message: 'Up to date',
|
|
52
|
+
});
|
|
53
|
+
expect(entry.pendingValidation).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
it('preserves a prior pending flag on a later no-op sync', async () => {
|
|
56
|
+
const existing = {
|
|
57
|
+
workspacePath: '/ws',
|
|
58
|
+
repos: { api: { repoName: 'api', pendingValidation: true } },
|
|
59
|
+
updatedAt: '2026-01-01T00:00:00.000Z',
|
|
60
|
+
};
|
|
61
|
+
vi.mocked(fs.readFile).mockResolvedValue(JSON.stringify(existing));
|
|
62
|
+
const entry = await recordRepoSync('/ws', 'api', {
|
|
63
|
+
status: 'up-to-date',
|
|
64
|
+
message: 'Up to date',
|
|
65
|
+
});
|
|
66
|
+
expect(entry.pendingValidation).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('markValidated', () => {
|
|
70
|
+
it('records the result and clears the pending flag', async () => {
|
|
71
|
+
const existing = {
|
|
72
|
+
workspacePath: '/ws',
|
|
73
|
+
repos: { api: { repoName: 'api', pendingValidation: true } },
|
|
74
|
+
updatedAt: '2026-01-01T00:00:00.000Z',
|
|
75
|
+
};
|
|
76
|
+
vi.mocked(fs.readFile).mockResolvedValue(JSON.stringify(existing));
|
|
77
|
+
const entry = await markValidated('/ws', 'api', 'pass');
|
|
78
|
+
expect(entry.lastValidationResult).toBe('pass');
|
|
79
|
+
expect(entry.pendingValidation).toBe(false);
|
|
80
|
+
expect(entry.lastValidatedAt).toBeTruthy();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=workspace-state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-state.test.js","sourceRo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