@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
@@ -1,74 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import * as fs from 'node:fs/promises';
3
- import * as path from 'node:path';
4
- import { execa } from 'execa';
5
- import { isGitRepo, gitFetch, detectDefaultBranch } from './git.js';
6
-
7
- vi.mock('node:fs/promises');
8
- vi.mock('execa');
9
-
10
- describe('git utilities', () => {
11
- beforeEach(() => {
12
- vi.clearAllMocks();
13
- });
14
-
15
- describe('isGitRepo', () => {
16
- it('should return true if .git directory exists and is accessible', async () => {
17
- vi.mocked(fs.access).mockResolvedValue(undefined);
18
-
19
- const result = await isGitRepo('/mock/repo');
20
-
21
- expect(result).toBe(true);
22
- expect(fs.access).toHaveBeenCalledWith(path.join('/mock/repo', '.git'));
23
- });
24
-
25
- it('should return false if .git directory is not accessible', async () => {
26
- vi.mocked(fs.access).mockRejectedValue(new Error('ENOENT'));
27
-
28
- const result = await isGitRepo('/mock/repo');
29
-
30
- expect(result).toBe(false);
31
- });
32
- });
33
-
34
- describe('gitFetch', () => {
35
- it('should run git fetch origin', async () => {
36
- vi.mocked(execa).mockResolvedValue({} as any);
37
-
38
- await gitFetch('/mock/repo');
39
-
40
- expect(execa).toHaveBeenCalledWith('git', ['fetch', 'origin'], { cwd: '/mock/repo' });
41
- });
42
- });
43
-
44
- describe('detectDefaultBranch', () => {
45
- it('should prefer main over master', async () => {
46
- vi.mocked(execa).mockResolvedValue({
47
- stdout: ' origin/master\n origin/main\n'
48
- } as any);
49
-
50
- const branch = await detectDefaultBranch('/mock/repo');
51
-
52
- expect(branch).toBe('main');
53
- expect(execa).toHaveBeenCalledWith('git', ['branch', '-r'], { cwd: '/mock/repo' });
54
- });
55
-
56
- it('should match master if main is not present', async () => {
57
- vi.mocked(execa).mockResolvedValue({
58
- stdout: ' origin/master\n origin/feature-branch\n'
59
- } as any);
60
-
61
- const branch = await detectDefaultBranch('/mock/repo');
62
-
63
- expect(branch).toBe('master');
64
- });
65
-
66
- it('should fallback to main if neither is present or command fails', async () => {
67
- vi.mocked(execa).mockRejectedValue(new Error('git command failed'));
68
-
69
- const branch = await detectDefaultBranch('/mock/repo');
70
-
71
- expect(branch).toBe('main');
72
- });
73
- });
74
- });
package/src/utils/git.ts DELETED
@@ -1,117 +0,0 @@
1
- /**
2
- * @module utils/git
3
- * Low-level git helper functions used throughout NexusFlow.
4
- */
5
-
6
- import * as fs from 'node:fs/promises';
7
- import * as path from 'node:path';
8
- import { execa } from 'execa';
9
-
10
- /**
11
- * Checks whether the given directory is a git repository
12
- * by testing for the presence of a `.git` entry.
13
- *
14
- * @param dirPath - Absolute path to the directory.
15
- * @returns `true` if a `.git` file or directory exists.
16
- */
17
- export async function isGitRepo(dirPath: string): Promise<boolean> {
18
- try {
19
- const gitPath = path.join(dirPath, '.git');
20
- await fs.access(gitPath);
21
- return true;
22
- } catch {
23
- return false;
24
- }
25
- }
26
-
27
- /**
28
- * Runs `git fetch origin` inside the given repository.
29
- *
30
- * @param repoPath - Absolute path to the repo root.
31
- */
32
- export async function gitFetch(repoPath: string): Promise<void> {
33
- await execa('git', ['fetch', 'origin'], { cwd: repoPath });
34
- }
35
-
36
- /**
37
- * Detects the default branch of a repository by inspecting remote branches.
38
- * Prefers `main` over `master`. Falls back to `'main'` when neither is found.
39
- *
40
- * @param repoPath - Absolute path to the repo root.
41
- * @returns The name of the default branch.
42
- */
43
- export async function detectDefaultBranch(repoPath: string): Promise<string> {
44
- try {
45
- const { stdout } = await execa('git', ['branch', '-r'], { cwd: repoPath });
46
- const branches = stdout.split('\n').map((b) => b.trim());
47
-
48
- if (branches.some((b) => b === 'origin/main' || b.endsWith('/origin/main'))) {
49
- return 'main';
50
- }
51
-
52
- if (branches.some((b) => b === 'origin/master' || b.endsWith('/origin/master'))) {
53
- return 'master';
54
- }
55
-
56
- // Fallback — assume main.
57
- return 'main';
58
- } catch {
59
- return 'main';
60
- }
61
- }
62
-
63
- /**
64
- * Checks if the given branch name matches Git branch conventions (based on git-check-ref-format):
65
- * - No spaces, backslashes, or control characters.
66
- * - At least 1 character long.
67
- * - Is not exactly '@'.
68
- * - Does not start with a dash.
69
- * - Does not start or end with a forward slash.
70
- * - Does not contain consecutive dots, consecutive slashes, or '@{'.
71
- * - Does not end with '.'.
72
- * - Does not contain forbidden characters: ~, ^, :, ?, *, [
73
- * - No component starts with a dot, ends with '.lock', or is exactly 'HEAD'.
74
- *
75
- * @param name - The branch name to validate.
76
- * @returns `true` if the branch name is valid.
77
- */
78
- export function isValidBranchName(name: string): boolean {
79
- if (!name || name.length === 0) {
80
- return false;
81
- }
82
- if (name === '@') {
83
- return false;
84
- }
85
- if (name.startsWith('-')) {
86
- return false;
87
- }
88
- const forbiddenCharsOrSpaces = /[\x00-\x20\x7F~^:?*[\\]/;
89
- if (forbiddenCharsOrSpaces.test(name)) {
90
- return false;
91
- }
92
- if (name.includes('..') || name.includes('@{') || name.includes('//')) {
93
- return false;
94
- }
95
- if (name.startsWith('/') || name.endsWith('/')) {
96
- return false;
97
- }
98
- if (name.endsWith('.')) {
99
- return false;
100
- }
101
-
102
- const components = name.split('/');
103
- for (const component of components) {
104
- if (component.startsWith('.')) {
105
- return false;
106
- }
107
- if (component.endsWith('.lock')) {
108
- return false;
109
- }
110
- if (component === 'HEAD') {
111
- return false;
112
- }
113
- }
114
-
115
- return true;
116
- }
117
-
@@ -1,130 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { callLocalLlm, isOllamaModelAvailable, getOpenAiCompatibleUrl } from './local-ai.js';
3
-
4
- describe('local-ai utilities', () => {
5
- beforeEach(() => {
6
- vi.stubGlobal('fetch', vi.fn());
7
- });
8
-
9
- afterEach(() => {
10
- vi.restoreAllMocks();
11
- });
12
-
13
- describe('isOllamaModelAvailable', () => {
14
- it('should match exact model names and tag variations', () => {
15
- const models = [{ name: 'qwen2.5-coder:1.5b' }, { name: 'llama3:latest' }];
16
- expect(isOllamaModelAvailable(models, 'qwen2.5-coder:1.5b')).toBe(true);
17
- expect(isOllamaModelAvailable(models, 'llama3')).toBe(true);
18
- expect(isOllamaModelAvailable(models, 'llama3:latest')).toBe(true);
19
- expect(isOllamaModelAvailable(models, 'non-existent')).toBe(false);
20
- });
21
- });
22
-
23
- describe('getOpenAiCompatibleUrl', () => {
24
- it('should properly format endpoint URLs', () => {
25
- expect(getOpenAiCompatibleUrl('http://localhost:11434', '/v1/chat/completions')).toBe('http://localhost:11434/v1/chat/completions');
26
- expect(getOpenAiCompatibleUrl('http://localhost:11434/', '/v1/chat/completions')).toBe('http://localhost:11434/v1/chat/completions');
27
- expect(getOpenAiCompatibleUrl('http://localhost:1234/v1', '/v1/chat/completions')).toBe('http://localhost:1234/v1/chat/completions');
28
- expect(getOpenAiCompatibleUrl('http://localhost:1234/v1/', '/v1/chat/completions')).toBe('http://localhost:1234/v1/chat/completions');
29
- });
30
- });
31
-
32
- describe('callLocalLlm', () => {
33
- const configOllama = {
34
- enabled: true,
35
- provider: 'ollama' as const,
36
- endpoint: 'http://localhost:11434',
37
- model: 'qwen2.5-coder:1.5b',
38
- };
39
-
40
- const configOpenAi = {
41
- enabled: true,
42
- provider: 'openai-compatible' as const,
43
- endpoint: 'http://localhost:1234/v1',
44
- model: 'custom-model',
45
- };
46
-
47
- const messages = [{ role: 'user' as const, content: 'Hello' }];
48
-
49
- it('should request and return message content for Ollama provider', async () => {
50
- const mockResponse = {
51
- message: {
52
- content: 'Hello from Ollama!',
53
- },
54
- };
55
-
56
- vi.mocked(fetch).mockResolvedValue({
57
- ok: true,
58
- json: () => Promise.resolve(mockResponse),
59
- } as any);
60
-
61
- const response = await callLocalLlm(configOllama, messages);
62
-
63
- expect(response).toBe('Hello from Ollama!');
64
- expect(fetch).toHaveBeenCalledWith('http://localhost:11434/api/chat', {
65
- method: 'POST',
66
- headers: { 'Content-Type': 'application/json' },
67
- body: JSON.stringify({
68
- model: 'qwen2.5-coder:1.5b',
69
- messages,
70
- stream: false,
71
- }),
72
- signal: expect.any(AbortSignal),
73
- });
74
- });
75
-
76
- it('should throw an error if Ollama response is not ok', async () => {
77
- vi.mocked(fetch).mockResolvedValue({
78
- ok: false,
79
- status: 500,
80
- text: () => Promise.resolve('Internal server error'),
81
- } as any);
82
-
83
- await expect(callLocalLlm(configOllama, messages)).rejects.toThrow(
84
- 'Ollama request failed with status 500: Internal server error'
85
- );
86
- });
87
-
88
- it('should request and return message content for OpenAI provider', async () => {
89
- const mockResponse = {
90
- choices: [
91
- {
92
- message: {
93
- content: 'Hello from OpenAI!',
94
- },
95
- },
96
- ],
97
- };
98
-
99
- vi.mocked(fetch).mockResolvedValue({
100
- ok: true,
101
- json: () => Promise.resolve(mockResponse),
102
- } as any);
103
-
104
- const response = await callLocalLlm(configOpenAi, messages);
105
-
106
- expect(response).toBe('Hello from OpenAI!');
107
- expect(fetch).toHaveBeenCalledWith('http://localhost:1234/v1/chat/completions', {
108
- method: 'POST',
109
- headers: { 'Content-Type': 'application/json' },
110
- body: JSON.stringify({
111
- model: 'custom-model',
112
- messages,
113
- stream: false,
114
- }),
115
- signal: expect.any(AbortSignal),
116
- });
117
- });
118
-
119
- it('should throw an error if OpenAI response has invalid format', async () => {
120
- vi.mocked(fetch).mockResolvedValue({
121
- ok: true,
122
- json: () => Promise.resolve({}),
123
- } as any);
124
-
125
- await expect(callLocalLlm(configOpenAi, messages)).rejects.toThrow(
126
- 'Invalid response format received from OpenAI-compatible endpoint'
127
- );
128
- });
129
- });
130
- });
@@ -1,116 +0,0 @@
1
- /**
2
- * @module utils/local-ai
3
- * Handles requests to local LLM servers (Ollama or OpenAI-compatible like LM Studio).
4
- */
5
-
6
- import type { LocalLlmConfig } from '../types.js';
7
-
8
- export interface LocalLlmMessage {
9
- role: 'system' | 'user' | 'assistant';
10
- content: string;
11
- }
12
-
13
- /**
14
- * Sends a chat completion request to the configured local LLM provider.
15
- * Supports Ollama-specific API and standard OpenAI-compatible endpoints.
16
- */
17
- export async function callLocalLlm(
18
- config: LocalLlmConfig,
19
- messages: LocalLlmMessage[],
20
- ): Promise<string> {
21
- const { provider, endpoint, model } = config;
22
- const cleanEndpoint = endpoint.replace(/\/$/, '');
23
- const controller = new AbortController();
24
- const timeout = setTimeout(() => controller.abort(), 60_000);
25
-
26
- try {
27
- if (provider === 'ollama') {
28
- const url = `${cleanEndpoint}/api/chat`;
29
- const response = await fetch(url, {
30
- method: 'POST',
31
- headers: {
32
- 'Content-Type': 'application/json',
33
- },
34
- body: JSON.stringify({
35
- model,
36
- messages,
37
- stream: false,
38
- }),
39
- signal: controller.signal,
40
- });
41
-
42
- if (!response.ok) {
43
- const text = await response.text();
44
- throw new Error(`Ollama request failed with status ${response.status}: ${text}`);
45
- }
46
-
47
- const data: any = await response.json();
48
- if (data?.message?.content) {
49
- return data.message.content;
50
- }
51
- throw new Error('Invalid response format received from Ollama');
52
- } else {
53
- // OpenAI-compatible provider
54
- const url = getOpenAiCompatibleUrl(cleanEndpoint, '/v1/chat/completions');
55
-
56
- const headers: Record<string, string> = {
57
- 'Content-Type': 'application/json',
58
- };
59
- if (config.apiKey) {
60
- headers['Authorization'] = `Bearer ${config.apiKey}`;
61
- }
62
-
63
- const response = await fetch(url, {
64
- method: 'POST',
65
- headers,
66
- body: JSON.stringify({
67
- model,
68
- messages,
69
- stream: false,
70
- }),
71
- signal: controller.signal,
72
- });
73
-
74
- if (!response.ok) {
75
- const text = await response.text();
76
- throw new Error(`OpenAI-compatible request failed with status ${response.status}: ${text}`);
77
- }
78
-
79
- const data: any = await response.json();
80
- if (data?.choices?.[0]?.message?.content) {
81
- return data.choices[0].message.content;
82
- }
83
- throw new Error('Invalid response format received from OpenAI-compatible endpoint');
84
- }
85
- } catch (error: any) {
86
- if (error.name === 'AbortError') {
87
- throw new Error('Local LLM request timed out after 60 seconds');
88
- }
89
- throw error;
90
- } finally {
91
- clearTimeout(timeout);
92
- }
93
- }
94
-
95
- /**
96
- * Checks whether a target model name matches any model in an Ollama model list.
97
- * Handles tag variations like 'model' vs 'model:latest' vs 'model:7b'.
98
- */
99
- export function isOllamaModelAvailable(models: { name: string }[], targetModel: string): boolean {
100
- const normalize = (name: string) => name.includes(':') ? name : `${name}:latest`;
101
- const targetNorm = normalize(targetModel);
102
- return models.some((m) => normalize(m.name) === targetNorm);
103
- }
104
-
105
- /**
106
- * Helper to build standard OpenAI compatible URLs.
107
- * Handles cases where the configured endpoint already has or does not have `/v1`.
108
- */
109
- export function getOpenAiCompatibleUrl(endpoint: string, suffix: string): string {
110
- const cleanEndpoint = endpoint.replace(/\/$/, '');
111
- const hasV1 = /\/v1\/?$/.test(cleanEndpoint);
112
- if (hasV1) {
113
- return `${cleanEndpoint.replace(/\/v1\/?$/, '')}${suffix}`;
114
- }
115
- return `${cleanEndpoint}${suffix}`;
116
- }
@@ -1,158 +0,0 @@
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
- });