@mrpatronz/nexusflow 0.2.19 → 1.3.0

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 (236) hide show
  1. package/README.md +27 -3
  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/commands.test.js +20 -6
  7. package/dist/commands/commands.test.js.map +1 -1
  8. package/dist/commands/commit.d.ts +2 -0
  9. package/dist/commands/commit.d.ts.map +1 -1
  10. package/dist/commands/commit.js +27 -5
  11. package/dist/commands/commit.js.map +1 -1
  12. package/dist/commands/diff.d.ts +9 -2
  13. package/dist/commands/diff.d.ts.map +1 -1
  14. package/dist/commands/diff.js +36 -12
  15. package/dist/commands/diff.js.map +1 -1
  16. package/dist/commands/doctor.js +2 -2
  17. package/dist/commands/doctor.js.map +1 -1
  18. package/dist/commands/handoff.js +2 -2
  19. package/dist/commands/handoff.js.map +1 -1
  20. package/dist/commands/refresh.d.ts +4 -2
  21. package/dist/commands/refresh.d.ts.map +1 -1
  22. package/dist/commands/refresh.js +20 -36
  23. package/dist/commands/refresh.js.map +1 -1
  24. package/dist/commands/schedule.d.ts +35 -0
  25. package/dist/commands/schedule.d.ts.map +1 -0
  26. package/dist/commands/schedule.js +151 -0
  27. package/dist/commands/schedule.js.map +1 -0
  28. package/dist/commands/sync.d.ts.map +1 -1
  29. package/dist/commands/sync.js +28 -7
  30. package/dist/commands/sync.js.map +1 -1
  31. package/dist/core/analysis-cache.d.ts +58 -0
  32. package/dist/core/analysis-cache.d.ts.map +1 -0
  33. package/dist/core/analysis-cache.js +116 -0
  34. package/dist/core/analysis-cache.js.map +1 -0
  35. package/dist/core/analysis-cache.test.d.ts +2 -0
  36. package/dist/core/analysis-cache.test.d.ts.map +1 -0
  37. package/dist/core/analysis-cache.test.js +108 -0
  38. package/dist/core/analysis-cache.test.js.map +1 -0
  39. package/dist/core/refresh.d.ts +41 -0
  40. package/dist/core/refresh.d.ts.map +1 -0
  41. package/dist/core/refresh.js +60 -0
  42. package/dist/core/refresh.js.map +1 -0
  43. package/dist/core/scheduler.d.ts +117 -0
  44. package/dist/core/scheduler.d.ts.map +1 -0
  45. package/dist/core/scheduler.js +247 -0
  46. package/dist/core/scheduler.js.map +1 -0
  47. package/dist/core/scheduler.test.d.ts +2 -0
  48. package/dist/core/scheduler.test.d.ts.map +1 -0
  49. package/dist/core/scheduler.test.js +111 -0
  50. package/dist/core/scheduler.test.js.map +1 -0
  51. package/dist/core/sync.d.ts +6 -0
  52. package/dist/core/sync.d.ts.map +1 -1
  53. package/dist/core/sync.js +15 -5
  54. package/dist/core/sync.js.map +1 -1
  55. package/dist/generators/index.d.ts +7 -1
  56. package/dist/generators/index.d.ts.map +1 -1
  57. package/dist/generators/index.js +14 -1
  58. package/dist/generators/index.js.map +1 -1
  59. package/dist/index.js +107 -4
  60. package/dist/index.js.map +1 -1
  61. package/dist/server.d.ts.map +1 -1
  62. package/dist/server.js +81 -0
  63. package/dist/server.js.map +1 -1
  64. package/dist/server.test.js +66 -0
  65. package/dist/server.test.js.map +1 -1
  66. package/dist/utils/multi-git.d.ts +21 -0
  67. package/dist/utils/multi-git.d.ts.map +1 -1
  68. package/dist/utils/multi-git.js +40 -4
  69. package/dist/utils/multi-git.js.map +1 -1
  70. package/package.json +13 -1
  71. package/.agents/skills/ccc/SKILL.md +0 -71
  72. package/.agents/skills/ccc/references/management.md +0 -110
  73. package/.agents/skills/ccc/references/settings.md +0 -126
  74. package/.github/dependabot.yml +0 -52
  75. package/.github/workflows/ci.yml +0 -44
  76. package/.github/workflows/dependabot-merge.yml +0 -53
  77. package/.github/workflows/release-desktop.yml +0 -67
  78. package/.github/workflows/release-npm.yml +0 -65
  79. package/.github/workflows/release-vscode.yml +0 -61
  80. package/.vscode/launch.json +0 -17
  81. package/.vscode/tasks.json +0 -17
  82. package/GETTING_STARTED.md +0 -114
  83. package/desktop/build-installer.js +0 -228
  84. package/desktop/build.js +0 -118
  85. package/desktop/installer/nexusflow.iss +0 -35
  86. package/desktop/neutralino.config.json +0 -39
  87. package/desktop/package-lock.json +0 -1060
  88. package/desktop/package.json +0 -14
  89. package/extension/media/icon.svg +0 -1
  90. package/extension/package-lock.json +0 -6044
  91. package/extension/package.json +0 -117
  92. package/extension/src/extension.ts +0 -653
  93. package/extension/tsconfig.json +0 -21
  94. package/gui/README.md +0 -73
  95. package/gui/e2e/dashboard.spec.ts +0 -61
  96. package/gui/e2e/wizard.spec.ts +0 -346
  97. package/gui/eslint.config.js +0 -26
  98. package/gui/index.html +0 -17
  99. package/gui/package-lock.json +0 -3137
  100. package/gui/package.json +0 -37
  101. package/gui/playwright.config.ts +0 -41
  102. package/gui/public/app_logo.png +0 -0
  103. package/gui/public/favicon.svg +0 -1
  104. package/gui/public/icons.svg +0 -24
  105. package/gui/src/App.css +0 -1
  106. package/gui/src/App.tsx +0 -3573
  107. package/gui/src/app/AppSidebar.tsx +0 -69
  108. package/gui/src/assets/hero.png +0 -0
  109. package/gui/src/assets/react.svg +0 -1
  110. package/gui/src/assets/vite.svg +0 -1
  111. package/gui/src/components/AddRepoPicker.tsx +0 -81
  112. package/gui/src/components/ui/Button.tsx +0 -40
  113. package/gui/src/components/ui/Card.tsx +0 -6
  114. package/gui/src/components/ui/EmptyState.tsx +0 -22
  115. package/gui/src/components/ui/Input.tsx +0 -21
  116. package/gui/src/components/ui/Menu.tsx +0 -71
  117. package/gui/src/components/ui/Modal.tsx +0 -39
  118. package/gui/src/components/ui/PageHeader.tsx +0 -21
  119. package/gui/src/components/ui/RepoStatusStrip.tsx +0 -33
  120. package/gui/src/components/ui/Skeleton.tsx +0 -5
  121. package/gui/src/components/ui/StatusPill.tsx +0 -36
  122. package/gui/src/components/ui/Tabs.tsx +0 -40
  123. package/gui/src/components/ui/cn.ts +0 -4
  124. package/gui/src/components/ui/index.ts +0 -16
  125. package/gui/src/features/changes/ChangesViewer.tsx +0 -388
  126. package/gui/src/features/knowledge/KnowledgeBase.tsx +0 -84
  127. package/gui/src/features/onboarding/OnboardingWizard.tsx +0 -230
  128. package/gui/src/features/plan/ImplementationPlan.tsx +0 -32
  129. package/gui/src/features/services/ServiceConsole.tsx +0 -215
  130. package/gui/src/features/sessions/SessionHistory.tsx +0 -195
  131. package/gui/src/index.css +0 -167
  132. package/gui/src/lib/status.ts +0 -24
  133. package/gui/src/main.tsx +0 -94
  134. package/gui/src/pages/DashboardPage.tsx +0 -129
  135. package/gui/src/pages/WorkspacesPage.tsx +0 -352
  136. package/gui/src/types.ts +0 -81
  137. package/gui/tsconfig.app.json +0 -25
  138. package/gui/tsconfig.json +0 -7
  139. package/gui/tsconfig.node.json +0 -24
  140. package/gui/vite.config.ts +0 -12
  141. package/resources/workflows/plan-implement-review.md +0 -8
  142. package/resources/workflows/research-verify.md +0 -6
  143. package/resources/workflows/solo-developer.md +0 -3
  144. package/scripts/simulate-workspaces.ts +0 -55
  145. package/skills-lock.json +0 -11
  146. package/src/analyzers/detect-apis.ts +0 -290
  147. package/src/analyzers/detect-deps.ts +0 -315
  148. package/src/analyzers/detect-existing.ts +0 -74
  149. package/src/analyzers/detect-ports.ts +0 -110
  150. package/src/analyzers/index.ts +0 -97
  151. package/src/analyzers/messaging-analyzer.ts +0 -254
  152. package/src/analyzers/readme-summarizer.ts +0 -102
  153. package/src/analyzers/run-analyzer.ts +0 -269
  154. package/src/analyzers/tech-stack.ts +0 -283
  155. package/src/commands/adapter.ts +0 -348
  156. package/src/commands/add-repo.ts +0 -156
  157. package/src/commands/commands.test.ts +0 -156
  158. package/src/commands/commit.ts +0 -131
  159. package/src/commands/config.ts +0 -52
  160. package/src/commands/create.ts +0 -204
  161. package/src/commands/desktop.ts +0 -128
  162. package/src/commands/diff.ts +0 -125
  163. package/src/commands/doctor.ts +0 -370
  164. package/src/commands/handoff.ts +0 -266
  165. package/src/commands/init.ts +0 -134
  166. package/src/commands/list.ts +0 -46
  167. package/src/commands/logs.ts +0 -63
  168. package/src/commands/mcp.ts +0 -94
  169. package/src/commands/open.ts +0 -129
  170. package/src/commands/refresh.ts +0 -137
  171. package/src/commands/remove.ts +0 -98
  172. package/src/commands/start.ts +0 -117
  173. package/src/commands/status.ts +0 -54
  174. package/src/commands/stop.ts +0 -55
  175. package/src/commands/sync.ts +0 -125
  176. package/src/commands/tui.ts +0 -484
  177. package/src/commands/ui.ts +0 -111
  178. package/src/core/adapters/local-storage.ts +0 -66
  179. package/src/core/adapters/obsidian-storage.ts +0 -151
  180. package/src/core/adapters/registry.ts +0 -44
  181. package/src/core/adapters/storage.test.ts +0 -174
  182. package/src/core/adapters/vault-storage.ts +0 -86
  183. package/src/core/config.test.ts +0 -96
  184. package/src/core/config.ts +0 -140
  185. package/src/core/graph.ts +0 -344
  186. package/src/core/plugins/index.ts +0 -17
  187. package/src/core/plugins/loader.ts +0 -36
  188. package/src/core/ports/storage.ts +0 -71
  189. package/src/core/scanner.test.ts +0 -61
  190. package/src/core/scanner.ts +0 -91
  191. package/src/core/storage.ts +0 -37
  192. package/src/core/sync.ts +0 -121
  193. package/src/core/workspace-state.test.ts +0 -108
  194. package/src/core/workspace-state.ts +0 -130
  195. package/src/core/workspace.ts +0 -487
  196. package/src/core/worktree.ts +0 -120
  197. package/src/generators/antigravity.ts +0 -32
  198. package/src/generators/base.ts +0 -243
  199. package/src/generators/claude.ts +0 -34
  200. package/src/generators/codex.ts +0 -48
  201. package/src/generators/copilot.ts +0 -56
  202. package/src/generators/cursor.ts +0 -44
  203. package/src/generators/diff-context.ts +0 -75
  204. package/src/generators/index.ts +0 -322
  205. package/src/generators/map-generator.test.ts +0 -159
  206. package/src/generators/map-generator.ts +0 -539
  207. package/src/generators/plan-generator.ts +0 -483
  208. package/src/generators/skills-generator.ts +0 -259
  209. package/src/index.ts +0 -539
  210. package/src/mcp/server.ts +0 -338
  211. package/src/orchestration/detect.ts +0 -313
  212. package/src/orchestration/index.ts +0 -7
  213. package/src/orchestration/runner.ts +0 -283
  214. package/src/server.test.ts +0 -618
  215. package/src/server.ts +0 -1402
  216. package/src/types.ts +0 -451
  217. package/src/utils/detect-ai.test.ts +0 -44
  218. package/src/utils/detect-ai.ts +0 -84
  219. package/src/utils/detect-editors.test.ts +0 -48
  220. package/src/utils/detect-editors.ts +0 -57
  221. package/src/utils/git.test.ts +0 -74
  222. package/src/utils/git.ts +0 -117
  223. package/src/utils/local-ai.test.ts +0 -130
  224. package/src/utils/local-ai.ts +0 -116
  225. package/src/utils/multi-git.test.ts +0 -158
  226. package/src/utils/multi-git.ts +0 -405
  227. package/src/utils/prompts.ts +0 -209
  228. package/src/utils/session-finder.ts +0 -483
  229. package/src/utils/system-scanner.test.ts +0 -89
  230. package/src/utils/system-scanner.ts +0 -96
  231. package/src/utils/update-check.ts +0 -286
  232. package/src/utils/workflow-advisor.ts +0 -118
  233. package/src/utils/workflows.test.ts +0 -114
  234. package/src/utils/workflows.ts +0 -178
  235. package/tsconfig.json +0 -19
  236. 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
- });