@mrpatronz/nexusflow 0.2.13 → 0.2.18

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 (228) hide show
  1. package/.agents/skills/ccc/SKILL.md +71 -0
  2. package/.agents/skills/ccc/references/management.md +110 -0
  3. package/.agents/skills/ccc/references/settings.md +126 -0
  4. package/.github/workflows/ci.yml +44 -0
  5. package/.github/workflows/dependabot-merge.yml +53 -0
  6. package/.github/workflows/release-desktop.yml +67 -0
  7. package/.github/workflows/release-npm.yml +65 -0
  8. package/.github/workflows/release-vscode.yml +61 -0
  9. package/GETTING_STARTED.md +5 -0
  10. package/README.md +53 -0
  11. package/desktop/build-installer.js +228 -0
  12. package/desktop/build.js +118 -0
  13. package/desktop/installer/nexusflow.iss +35 -0
  14. package/desktop/neutralino.config.json +39 -0
  15. package/desktop/package-lock.json +1060 -0
  16. package/desktop/package.json +14 -0
  17. package/dist/commands/adapter.d.ts +27 -0
  18. package/dist/commands/adapter.d.ts.map +1 -0
  19. package/dist/commands/adapter.js +318 -0
  20. package/dist/commands/adapter.js.map +1 -0
  21. package/dist/commands/add-repo.d.ts.map +1 -1
  22. package/dist/commands/add-repo.js +0 -1
  23. package/dist/commands/add-repo.js.map +1 -1
  24. package/dist/commands/commands.test.js +2 -2
  25. package/dist/commands/commands.test.js.map +1 -1
  26. package/dist/commands/config.d.ts +22 -0
  27. package/dist/commands/config.d.ts.map +1 -0
  28. package/dist/commands/config.js +50 -0
  29. package/dist/commands/config.js.map +1 -0
  30. package/dist/commands/create.d.ts.map +1 -1
  31. package/dist/commands/create.js +14 -17
  32. package/dist/commands/create.js.map +1 -1
  33. package/dist/commands/desktop.d.ts +12 -0
  34. package/dist/commands/desktop.d.ts.map +1 -0
  35. package/dist/commands/desktop.js +119 -0
  36. package/dist/commands/desktop.js.map +1 -0
  37. package/dist/commands/doctor.d.ts.map +1 -1
  38. package/dist/commands/doctor.js +11 -0
  39. package/dist/commands/doctor.js.map +1 -1
  40. package/dist/commands/refresh.d.ts +1 -0
  41. package/dist/commands/refresh.d.ts.map +1 -1
  42. package/dist/commands/refresh.js +2 -14
  43. package/dist/commands/refresh.js.map +1 -1
  44. package/dist/commands/sync.d.ts.map +1 -1
  45. package/dist/commands/sync.js +1 -8
  46. package/dist/commands/sync.js.map +1 -1
  47. package/dist/commands/tui.d.ts +8 -0
  48. package/dist/commands/tui.d.ts.map +1 -0
  49. package/dist/commands/tui.js +439 -0
  50. package/dist/commands/tui.js.map +1 -0
  51. package/dist/commands/ui.d.ts +3 -1
  52. package/dist/commands/ui.d.ts.map +1 -1
  53. package/dist/commands/ui.js +76 -19
  54. package/dist/commands/ui.js.map +1 -1
  55. package/dist/core/adapters/local-storage.d.ts +14 -0
  56. package/dist/core/adapters/local-storage.d.ts.map +1 -0
  57. package/dist/core/adapters/local-storage.js +58 -0
  58. package/dist/core/adapters/local-storage.js.map +1 -0
  59. package/dist/core/adapters/obsidian-storage.d.ts +28 -0
  60. package/dist/core/adapters/obsidian-storage.d.ts.map +1 -0
  61. package/dist/core/adapters/obsidian-storage.js +135 -0
  62. package/dist/core/adapters/obsidian-storage.js.map +1 -0
  63. package/dist/core/adapters/registry.d.ts +8 -0
  64. package/dist/core/adapters/registry.d.ts.map +1 -0
  65. package/dist/core/adapters/registry.js +37 -0
  66. package/dist/core/adapters/registry.js.map +1 -0
  67. package/dist/core/adapters/storage.test.d.ts +2 -0
  68. package/dist/core/adapters/storage.test.d.ts.map +1 -0
  69. package/dist/core/adapters/storage.test.js +106 -0
  70. package/dist/core/adapters/storage.test.js.map +1 -0
  71. package/dist/core/adapters/vault-storage.d.ts +16 -0
  72. package/dist/core/adapters/vault-storage.d.ts.map +1 -0
  73. package/dist/core/adapters/vault-storage.js +77 -0
  74. package/dist/core/adapters/vault-storage.js.map +1 -0
  75. package/dist/core/config.d.ts.map +1 -1
  76. package/dist/core/config.js +28 -4
  77. package/dist/core/config.js.map +1 -1
  78. package/dist/core/plugins/index.d.ts +14 -0
  79. package/dist/core/plugins/index.d.ts.map +1 -0
  80. package/dist/core/plugins/index.js +2 -0
  81. package/dist/core/plugins/index.js.map +1 -0
  82. package/dist/core/plugins/loader.d.ts +2 -0
  83. package/dist/core/plugins/loader.d.ts.map +1 -0
  84. package/dist/core/plugins/loader.js +34 -0
  85. package/dist/core/plugins/loader.js.map +1 -0
  86. package/dist/core/ports/storage.d.ts +59 -0
  87. package/dist/core/ports/storage.d.ts.map +1 -0
  88. package/dist/core/ports/storage.js +10 -0
  89. package/dist/core/ports/storage.js.map +1 -0
  90. package/dist/core/storage.d.ts +10 -0
  91. package/dist/core/storage.d.ts.map +1 -0
  92. package/dist/core/storage.js +29 -0
  93. package/dist/core/storage.js.map +1 -0
  94. package/dist/core/workspace.d.ts.map +1 -1
  95. package/dist/core/workspace.js +110 -16
  96. package/dist/core/workspace.js.map +1 -1
  97. package/dist/generators/base.d.ts.map +1 -1
  98. package/dist/generators/base.js +19 -6
  99. package/dist/generators/base.js.map +1 -1
  100. package/dist/generators/diff-context.d.ts +6 -0
  101. package/dist/generators/diff-context.d.ts.map +1 -0
  102. package/dist/generators/diff-context.js +68 -0
  103. package/dist/generators/diff-context.js.map +1 -0
  104. package/dist/generators/index.d.ts +1 -1
  105. package/dist/generators/index.d.ts.map +1 -1
  106. package/dist/generators/index.js +75 -18
  107. package/dist/generators/index.js.map +1 -1
  108. package/dist/generators/map-generator.d.ts.map +1 -1
  109. package/dist/generators/map-generator.js +7 -11
  110. package/dist/generators/map-generator.js.map +1 -1
  111. package/dist/generators/plan-generator.d.ts.map +1 -1
  112. package/dist/generators/plan-generator.js +3 -5
  113. package/dist/generators/plan-generator.js.map +1 -1
  114. package/dist/gui/app_logo.png +0 -0
  115. package/dist/gui/assets/index-CB-jWded.css +1 -0
  116. package/dist/gui/assets/index-DDXpZZu3.js +25 -0
  117. package/dist/gui/index.html +2 -2
  118. package/dist/index.js +174 -20
  119. package/dist/index.js.map +1 -1
  120. package/dist/server.d.ts.map +1 -1
  121. package/dist/server.js +212 -28
  122. package/dist/server.js.map +1 -1
  123. package/dist/server.test.js +173 -38
  124. package/dist/server.test.js.map +1 -1
  125. package/dist/types.d.ts +11 -2
  126. package/dist/types.d.ts.map +1 -1
  127. package/dist/utils/git.d.ts +16 -0
  128. package/dist/utils/git.d.ts.map +1 -1
  129. package/dist/utils/git.js +52 -0
  130. package/dist/utils/git.js.map +1 -1
  131. package/dist/utils/local-ai.d.ts.map +1 -1
  132. package/dist/utils/local-ai.js +7 -3
  133. package/dist/utils/local-ai.js.map +1 -1
  134. package/dist/utils/multi-git.d.ts +2 -0
  135. package/dist/utils/multi-git.d.ts.map +1 -1
  136. package/dist/utils/multi-git.js +5 -2
  137. package/dist/utils/multi-git.js.map +1 -1
  138. package/dist/utils/update-check.d.ts +3 -1
  139. package/dist/utils/update-check.d.ts.map +1 -1
  140. package/dist/utils/update-check.js +23 -34
  141. package/dist/utils/update-check.js.map +1 -1
  142. package/dist/utils/workflow-advisor.d.ts +16 -0
  143. package/dist/utils/workflow-advisor.d.ts.map +1 -0
  144. package/dist/utils/workflow-advisor.js +100 -0
  145. package/dist/utils/workflow-advisor.js.map +1 -0
  146. package/dist/utils/workflows.d.ts +11 -0
  147. package/dist/utils/workflows.d.ts.map +1 -0
  148. package/dist/utils/workflows.js +156 -0
  149. package/dist/utils/workflows.js.map +1 -0
  150. package/dist/utils/workflows.test.d.ts +2 -0
  151. package/dist/utils/workflows.test.d.ts.map +1 -0
  152. package/dist/utils/workflows.test.js +86 -0
  153. package/dist/utils/workflows.test.js.map +1 -0
  154. package/extension/media/icon.svg +1 -0
  155. package/extension/package-lock.json +4893 -1660
  156. package/extension/package.json +58 -11
  157. package/extension/src/extension.ts +476 -27
  158. package/extension/tsconfig.json +4 -2
  159. package/gui/e2e/wizard.spec.ts +19 -0
  160. package/gui/package-lock.json +342 -381
  161. package/gui/package.json +12 -12
  162. package/gui/public/app_logo.png +0 -0
  163. package/gui/src/App.tsx +991 -81
  164. package/gui/src/features/workspace/WorkspaceList.tsx +30 -30
  165. package/gui/src/index.css +64 -22
  166. package/gui/src/main.tsx +89 -5
  167. package/package.json +11 -12
  168. package/resources/workflows/plan-implement-review.md +8 -0
  169. package/resources/workflows/research-verify.md +6 -0
  170. package/resources/workflows/solo-developer.md +3 -0
  171. package/skills-lock.json +11 -0
  172. package/src/commands/adapter.ts +348 -0
  173. package/src/commands/add-repo.ts +0 -1
  174. package/src/commands/commands.test.ts +3 -2
  175. package/src/commands/config.ts +52 -0
  176. package/src/commands/create.ts +14 -17
  177. package/src/commands/desktop.ts +128 -0
  178. package/src/commands/doctor.ts +13 -0
  179. package/src/commands/mcp.ts +2 -0
  180. package/src/commands/refresh.ts +4 -14
  181. package/src/commands/sync.ts +2 -8
  182. package/src/commands/tui.ts +484 -0
  183. package/src/commands/ui.ts +83 -19
  184. package/src/core/adapters/local-storage.ts +66 -0
  185. package/src/core/adapters/obsidian-storage.ts +151 -0
  186. package/src/core/adapters/registry.ts +44 -0
  187. package/src/core/adapters/storage.test.ts +174 -0
  188. package/src/core/adapters/vault-storage.ts +86 -0
  189. package/src/core/config.ts +29 -4
  190. package/src/core/plugins/index.ts +17 -0
  191. package/src/core/plugins/loader.ts +36 -0
  192. package/src/core/ports/storage.ts +71 -0
  193. package/src/core/storage.ts +37 -0
  194. package/src/core/workspace.ts +122 -15
  195. package/src/generators/base.ts +21 -5
  196. package/src/generators/diff-context.ts +75 -0
  197. package/src/generators/index.ts +93 -21
  198. package/src/generators/map-generator.ts +7 -10
  199. package/src/generators/plan-generator.ts +6 -4
  200. package/src/index.ts +178 -21
  201. package/src/server.test.ts +193 -39
  202. package/src/server.ts +238 -28
  203. package/src/types.ts +14 -2
  204. package/src/utils/git.ts +56 -0
  205. package/src/utils/local-ai.ts +8 -3
  206. package/src/utils/multi-git.ts +16 -9
  207. package/src/utils/update-check.ts +42 -31
  208. package/src/utils/workflow-advisor.ts +118 -0
  209. package/src/utils/workflows.test.ts +114 -0
  210. package/src/utils/workflows.ts +178 -0
  211. package/.github/workflows/release.yml +0 -100
  212. package/dist/commands/pack.d.ts +0 -7
  213. package/dist/commands/pack.d.ts.map +0 -1
  214. package/dist/commands/pack.js +0 -64
  215. package/dist/commands/pack.js.map +0 -1
  216. package/dist/core/packer.d.ts +0 -14
  217. package/dist/core/packer.d.ts.map +0 -1
  218. package/dist/core/packer.js +0 -87
  219. package/dist/core/packer.js.map +0 -1
  220. package/dist/core/packer.test.d.ts +0 -2
  221. package/dist/core/packer.test.d.ts.map +0 -1
  222. package/dist/core/packer.test.js +0 -82
  223. package/dist/core/packer.test.js.map +0 -1
  224. package/dist/gui/assets/index-CFWwqFux.js +0 -23
  225. package/dist/gui/assets/index-Dvc9QMvl.css +0 -2
  226. package/src/commands/pack.ts +0 -73
  227. package/src/core/packer.test.ts +0 -99
  228. package/src/core/packer.ts +0 -107
@@ -0,0 +1,66 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ import type { StoragePort, StorageAdapterMeta } from '../ports/storage.js';
4
+
5
+ export class LocalStorageAdapter implements StoragePort {
6
+ readonly meta: StorageAdapterMeta = {
7
+ name: 'local',
8
+ displayName: 'Local Workspace',
9
+ description: 'Write context files directly into the workspace directory.',
10
+ configFields: [],
11
+ };
12
+
13
+ async writeWorkspaceFile(workspacePath: string, featureId: string, filename: string, content: string): Promise<void> {
14
+ const filePath = path.join(workspacePath, filename);
15
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
16
+ await fs.writeFile(filePath, content, 'utf8');
17
+ }
18
+
19
+ async readWorkspaceFile(workspacePath: string, featureId: string, filename: string): Promise<string> {
20
+ const filePath = path.join(workspacePath, filename);
21
+ return await fs.readFile(filePath, 'utf8');
22
+ }
23
+
24
+ async workspaceFileExists(workspacePath: string, featureId: string, filename: string): Promise<boolean> {
25
+ const filePath = path.join(workspacePath, filename);
26
+ try {
27
+ await fs.access(filePath);
28
+ return true;
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+
34
+ resolveWorkspaceFileUrl(workspacePath: string, featureId: string, filename: string): string {
35
+ return path.join(workspacePath, filename).replace(/\\/g, '/');
36
+ }
37
+
38
+ async writeBaseFile(workspacePath: string, repoName: string, filename: string, content: string): Promise<void> {
39
+ const filePath = path.join(workspacePath, filename);
40
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
41
+ await fs.writeFile(filePath, content, 'utf8');
42
+ }
43
+
44
+ async readBaseFile(workspacePath: string, repoName: string, filename: string): Promise<string> {
45
+ const filePath = path.join(workspacePath, filename);
46
+ return await fs.readFile(filePath, 'utf8');
47
+ }
48
+
49
+ async baseFileExists(workspacePath: string, repoName: string, filename: string): Promise<boolean> {
50
+ const filePath = path.join(workspacePath, filename);
51
+ try {
52
+ await fs.access(filePath);
53
+ return true;
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+
59
+ resolveBaseFileUrl(workspacePath: string, repoName: string, filename: string): string {
60
+ return path.join(workspacePath, filename).replace(/\\/g, '/');
61
+ }
62
+
63
+ async deleteWorkspace(workspacePath: string, featureId: string): Promise<void> {
64
+ // NOP - local files are inside workspacePath, which is deleted directly on workspace removal.
65
+ }
66
+ }
@@ -0,0 +1,151 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
+ import type { StoragePort, StorageAdapterMeta } from '../ports/storage.js';
5
+
6
+ /**
7
+ * Obsidian-native storage adapter.
8
+ *
9
+ * Writes markdown files to a configurable Obsidian vault path with optional
10
+ * YAML frontmatter (tags, dates, type). Uses the same two-layer structure
11
+ * as CentralVaultAdapter (_base/<repo>/ + <workspace>/).
12
+ */
13
+ export class ObsidianStorageAdapter implements StoragePort {
14
+ readonly meta: StorageAdapterMeta = {
15
+ name: 'obsidian',
16
+ displayName: 'Obsidian Vault',
17
+ description: 'Store context in an Obsidian vault with YAML frontmatter and wikilinks.',
18
+ configFields: [
19
+ {
20
+ key: 'vaultPath',
21
+ label: 'Obsidian Vault Path',
22
+ type: 'path',
23
+ required: true,
24
+ description: 'Absolute path to your Obsidian vault folder (e.g. ~/Obsidian/Dev)',
25
+ },
26
+ {
27
+ key: 'addFrontmatter',
28
+ label: 'Add YAML Frontmatter',
29
+ type: 'boolean',
30
+ default: true,
31
+ description: 'Add tags, created date, and type metadata to each file',
32
+ },
33
+ ],
34
+ };
35
+
36
+ private vaultPath: string = '';
37
+ private addFrontmatter: boolean = true;
38
+
39
+ constructor() {
40
+ try {
41
+ const home = os.homedir();
42
+ if (home) {
43
+ this.vaultPath = path.join(home, 'Obsidian', 'NexusFlow');
44
+ }
45
+ } catch {}
46
+ }
47
+
48
+ configure(settings: Record<string, unknown>): void {
49
+ if (settings.vaultPath && typeof settings.vaultPath === 'string') {
50
+ this.vaultPath = settings.vaultPath.startsWith('~')
51
+ ? path.join(os.homedir(), settings.vaultPath.slice(1))
52
+ : settings.vaultPath;
53
+ }
54
+ if (typeof settings.addFrontmatter === 'boolean') {
55
+ this.addFrontmatter = settings.addFrontmatter;
56
+ }
57
+ }
58
+
59
+ // ── Frontmatter helpers ──────────────────────────────────
60
+
61
+ private wrapWithFrontmatter(content: string, tags: string[], type: string): string {
62
+ if (!this.addFrontmatter) return content;
63
+
64
+ const now = new Date().toISOString();
65
+ const fm = [
66
+ '---',
67
+ `tags: [${tags.map(t => `"${t}"`).join(', ')}]`,
68
+ `type: ${type}`,
69
+ `created: ${now}`,
70
+ `modified: ${now}`,
71
+ `generator: nexusflow`,
72
+ '---',
73
+ '',
74
+ ].join('\n');
75
+
76
+ // Strip existing frontmatter if present
77
+ const stripped = content.replace(/^---\n[\s\S]*?\n---\n*/, '');
78
+ return fm + stripped;
79
+ }
80
+
81
+ // ── Workspace (feature) layer ────────────────────────────
82
+
83
+ private getFeaturePath(featureId: string): string {
84
+ return path.join(this.vaultPath, 'nexusflow', 'workspaces', featureId);
85
+ }
86
+
87
+ async writeWorkspaceFile(workspacePath: string, featureId: string, filename: string, content: string): Promise<void> {
88
+ const dir = this.getFeaturePath(featureId);
89
+ const filePath = path.join(dir, filename);
90
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
91
+ const wrapped = this.wrapWithFrontmatter(content, [featureId, 'workspace'], 'workspace-context');
92
+ await fs.writeFile(filePath, wrapped, 'utf8');
93
+ }
94
+
95
+ async readWorkspaceFile(workspacePath: string, featureId: string, filename: string): Promise<string> {
96
+ const dir = this.getFeaturePath(featureId);
97
+ return await fs.readFile(path.join(dir, filename), 'utf8');
98
+ }
99
+
100
+ async workspaceFileExists(workspacePath: string, featureId: string, filename: string): Promise<boolean> {
101
+ try {
102
+ await fs.access(path.join(this.getFeaturePath(featureId), filename));
103
+ return true;
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
108
+
109
+ resolveWorkspaceFileUrl(workspacePath: string, featureId: string, filename: string): string {
110
+ return path.join(this.getFeaturePath(featureId), filename).replace(/\\/g, '/');
111
+ }
112
+
113
+ // ── Base (repo) layer ────────────────────────────────────
114
+
115
+ private getBasePath(repoName: string): string {
116
+ return path.join(this.vaultPath, 'nexusflow', '_base', repoName);
117
+ }
118
+
119
+ async writeBaseFile(workspacePath: string, repoName: string, filename: string, content: string): Promise<void> {
120
+ const dir = this.getBasePath(repoName);
121
+ const filePath = path.join(dir, filename);
122
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
123
+ const wrapped = this.wrapWithFrontmatter(content, [repoName, 'base'], 'base-knowledge');
124
+ await fs.writeFile(filePath, wrapped, 'utf8');
125
+ }
126
+
127
+ async readBaseFile(workspacePath: string, repoName: string, filename: string): Promise<string> {
128
+ const dir = this.getBasePath(repoName);
129
+ return await fs.readFile(path.join(dir, filename), 'utf8');
130
+ }
131
+
132
+ async baseFileExists(workspacePath: string, repoName: string, filename: string): Promise<boolean> {
133
+ try {
134
+ await fs.access(path.join(this.getBasePath(repoName), filename));
135
+ return true;
136
+ } catch {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ resolveBaseFileUrl(workspacePath: string, repoName: string, filename: string): string {
142
+ return path.join(this.getBasePath(repoName), filename).replace(/\\/g, '/');
143
+ }
144
+
145
+ async deleteWorkspace(workspacePath: string, featureId: string): Promise<void> {
146
+ const dir = this.getFeaturePath(featureId);
147
+ try {
148
+ await fs.rm(dir, { recursive: true, force: true });
149
+ } catch {}
150
+ }
151
+ }
@@ -0,0 +1,44 @@
1
+ import type { StoragePort, StorageAdapterMeta } from '../ports/storage.js';
2
+ import { LocalStorageAdapter } from './local-storage.js';
3
+ import { CentralVaultAdapter } from './vault-storage.js';
4
+ import { ObsidianStorageAdapter } from './obsidian-storage.js';
5
+
6
+ const storageProviders = new Map<string, StoragePort>();
7
+ let activeProvider: StoragePort | null = null;
8
+
9
+ export function registerStorageProvider(name: string, provider: StoragePort) {
10
+ storageProviders.set(name, provider);
11
+ }
12
+
13
+ // Auto-register built-in adapters
14
+ registerStorageProvider('local', new LocalStorageAdapter());
15
+ registerStorageProvider('central-vault', new CentralVaultAdapter());
16
+ registerStorageProvider('obsidian', new ObsidianStorageAdapter());
17
+
18
+ /** Returns metadata for all registered storage providers. */
19
+ export function listStorageProviders(): StorageAdapterMeta[] {
20
+ return Array.from(storageProviders.values()).map(p => p.meta);
21
+ }
22
+
23
+ export function getStorageProvider(name: string): StoragePort {
24
+ const provider = storageProviders.get(name);
25
+ if (!provider) {
26
+ throw new Error(`Storage provider "${name}" is not registered.`);
27
+ }
28
+ return provider;
29
+ }
30
+
31
+ export function setActiveStorageProvider(provider: StoragePort) {
32
+ activeProvider = provider;
33
+ }
34
+
35
+ export function getActiveStorageProvider(): StoragePort {
36
+ if (!activeProvider) {
37
+ const local = storageProviders.get('local');
38
+ if (!local) {
39
+ throw new Error('No storage providers registered.');
40
+ }
41
+ return local;
42
+ }
43
+ return activeProvider;
44
+ }
@@ -0,0 +1,174 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import * as fs from 'node:fs/promises';
3
+ import * as os from 'node:os';
4
+ import * as path from 'node:path';
5
+
6
+ import { LocalStorageAdapter } from './local-storage.js';
7
+ import { CentralVaultAdapter } from './vault-storage.js';
8
+ import { ObsidianStorageAdapter } from './obsidian-storage.js';
9
+
10
+ vi.mock('node:fs/promises');
11
+ vi.mock('node:os', async () => {
12
+ const actual = await vi.importActual<typeof import('node:os')>('node:os');
13
+ return {
14
+ ...actual,
15
+ homedir: vi.fn().mockReturnValue('/mock/home'),
16
+ };
17
+ });
18
+
19
+ describe('Storage Adapters', () => {
20
+ beforeEach(() => {
21
+ vi.clearAllMocks();
22
+ vi.mocked(os.homedir).mockReturnValue('/mock/home');
23
+ });
24
+
25
+ describe('LocalStorageAdapter', () => {
26
+ const adapter = new LocalStorageAdapter();
27
+
28
+ it('should declare correct meta', () => {
29
+ expect(adapter.meta.name).toBe('local');
30
+ expect(adapter.meta.configFields.length).toBe(0);
31
+ });
32
+
33
+ it('should write workspace files directly to the workspace path', async () => {
34
+ vi.mocked(fs.mkdir).mockResolvedValue(undefined);
35
+ vi.mocked(fs.writeFile).mockResolvedValue(undefined);
36
+
37
+ await adapter.writeWorkspaceFile('/ws/path', 'feature-1', 'test.txt', 'hello');
38
+
39
+ expect(fs.mkdir).toHaveBeenCalledWith(expect.stringContaining(path.normalize('/ws/path')), { recursive: true });
40
+ expect(fs.writeFile).toHaveBeenCalledWith(
41
+ path.normalize('/ws/path/test.txt'),
42
+ 'hello',
43
+ 'utf8'
44
+ );
45
+ });
46
+
47
+ it('should resolve local workspace paths', () => {
48
+ const resolved = adapter.resolveWorkspaceFileUrl('/ws/path', 'feature-1', 'test.txt');
49
+ expect(resolved).toContain('/ws/path/test.txt');
50
+ });
51
+
52
+ it('should delete workspace as NOP', async () => {
53
+ await adapter.deleteWorkspace('/ws/path', 'feature-1');
54
+ expect(fs.rm).not.toHaveBeenCalled();
55
+ });
56
+ });
57
+
58
+ describe('CentralVaultAdapter', () => {
59
+ const adapter = new CentralVaultAdapter();
60
+
61
+ it('should declare correct meta', () => {
62
+ expect(adapter.meta.name).toBe('central-vault');
63
+ });
64
+
65
+ it('should write workspace files to ~/.nexusflow/vault/<featureId>', async () => {
66
+ vi.mocked(fs.mkdir).mockResolvedValue(undefined);
67
+ vi.mocked(fs.writeFile).mockResolvedValue(undefined);
68
+
69
+ await adapter.writeWorkspaceFile('/ws/path', 'feature-1', 'test.txt', 'hello');
70
+
71
+ expect(fs.writeFile).toHaveBeenCalledWith(
72
+ expect.stringContaining(path.normalize('.nexusflow/vault/feature-1/test.txt')),
73
+ 'hello',
74
+ 'utf8'
75
+ );
76
+ });
77
+
78
+ it('should write base files to ~/.nexusflow/vault/_base/<repoName>', async () => {
79
+ vi.mocked(fs.mkdir).mockResolvedValue(undefined);
80
+ vi.mocked(fs.writeFile).mockResolvedValue(undefined);
81
+
82
+ await adapter.writeBaseFile('/ws/path', 'RepoName', 'map.md', 'content');
83
+
84
+ expect(fs.writeFile).toHaveBeenCalledWith(
85
+ expect.stringContaining(path.normalize('.nexusflow/vault/_base/RepoName/map.md')),
86
+ 'content',
87
+ 'utf8'
88
+ );
89
+ });
90
+
91
+ it('should delete workspace folder from ~/.nexusflow/vault', async () => {
92
+ vi.mocked(fs.rm).mockResolvedValue(undefined);
93
+ await adapter.deleteWorkspace('/ws/path', 'feature-1');
94
+ expect(fs.rm).toHaveBeenCalledWith(
95
+ expect.stringContaining(path.normalize('.nexusflow/vault/feature-1')),
96
+ { recursive: true, force: true }
97
+ );
98
+ });
99
+ });
100
+
101
+ describe('ObsidianStorageAdapter', () => {
102
+ it('should declare correct meta and configuration settings', () => {
103
+ const adapter = new ObsidianStorageAdapter();
104
+ expect(adapter.meta.name).toBe('obsidian');
105
+ expect(adapter.meta.configFields.some(f => f.key === 'vaultPath')).toBe(true);
106
+ });
107
+
108
+ it('should respect custom vaultPath configuration', async () => {
109
+ const adapter = new ObsidianStorageAdapter();
110
+ adapter.configure({ vaultPath: '/custom/obsidian/vault' });
111
+
112
+ vi.mocked(fs.mkdir).mockResolvedValue(undefined);
113
+ vi.mocked(fs.writeFile).mockResolvedValue(undefined);
114
+
115
+ await adapter.writeWorkspaceFile('/ws/path', 'feature-1', 'test.txt', 'hello');
116
+
117
+ expect(fs.writeFile).toHaveBeenCalledWith(
118
+ path.normalize('/custom/obsidian/vault/nexusflow/workspaces/feature-1/test.txt'),
119
+ expect.any(String),
120
+ 'utf8'
121
+ );
122
+ });
123
+
124
+ it('should wrap content with YAML frontmatter by default', async () => {
125
+ const adapter = new ObsidianStorageAdapter();
126
+ adapter.configure({ vaultPath: '/custom/obsidian/vault', addFrontmatter: true });
127
+
128
+ vi.mocked(fs.mkdir).mockResolvedValue(undefined);
129
+ vi.mocked(fs.writeFile).mockResolvedValue(undefined);
130
+
131
+ await adapter.writeWorkspaceFile('/ws/path', 'feature-1', 'test.txt', 'hello');
132
+
133
+ expect(fs.writeFile).toHaveBeenCalledWith(
134
+ expect.any(String),
135
+ expect.stringContaining('tags: ["feature-1", "workspace"]'),
136
+ 'utf8'
137
+ );
138
+ expect(fs.writeFile).toHaveBeenCalledWith(
139
+ expect.any(String),
140
+ expect.stringContaining('generator: nexusflow'),
141
+ 'utf8'
142
+ );
143
+ });
144
+
145
+ it('should not wrap content with frontmatter if addFrontmatter is disabled', async () => {
146
+ const adapter = new ObsidianStorageAdapter();
147
+ adapter.configure({ vaultPath: '/custom/obsidian/vault', addFrontmatter: false });
148
+
149
+ vi.mocked(fs.mkdir).mockResolvedValue(undefined);
150
+ vi.mocked(fs.writeFile).mockResolvedValue(undefined);
151
+
152
+ await adapter.writeWorkspaceFile('/ws/path', 'feature-1', 'test.txt', 'hello');
153
+
154
+ expect(fs.writeFile).toHaveBeenCalledWith(
155
+ expect.any(String),
156
+ 'hello',
157
+ 'utf8'
158
+ );
159
+ });
160
+
161
+ it('should delete workspace folder from custom vault path under nexusflow', async () => {
162
+ const adapter = new ObsidianStorageAdapter();
163
+ adapter.configure({ vaultPath: '/custom/obsidian/vault' });
164
+ vi.mocked(fs.rm).mockResolvedValue(undefined);
165
+
166
+ await adapter.deleteWorkspace('/ws/path', 'feature-1');
167
+
168
+ expect(fs.rm).toHaveBeenCalledWith(
169
+ path.normalize('/custom/obsidian/vault/nexusflow/workspaces/feature-1'),
170
+ { recursive: true, force: true }
171
+ );
172
+ });
173
+ });
174
+ });
@@ -0,0 +1,86 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
+ import type { StoragePort, StorageAdapterMeta } from '../ports/storage.js';
5
+
6
+ export class CentralVaultAdapter implements StoragePort {
7
+ readonly meta: StorageAdapterMeta = {
8
+ name: 'central-vault',
9
+ displayName: 'Central Vault',
10
+ description: 'Store context in ~/.nexusflow/vault/ — keeps repos clean, Obsidian-compatible.',
11
+ configFields: [],
12
+ };
13
+
14
+ private getVaultPath(featureId: string): string {
15
+ return path.join(os.homedir(), '.nexusflow', 'vault', featureId);
16
+ }
17
+
18
+ async writeWorkspaceFile(workspacePath: string, featureId: string, filename: string, content: string): Promise<void> {
19
+ const vaultDir = this.getVaultPath(featureId);
20
+ const filePath = path.join(vaultDir, filename);
21
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
22
+ await fs.writeFile(filePath, content, 'utf8');
23
+ }
24
+
25
+ async readWorkspaceFile(workspacePath: string, featureId: string, filename: string): Promise<string> {
26
+ const vaultDir = this.getVaultPath(featureId);
27
+ const filePath = path.join(vaultDir, filename);
28
+ return await fs.readFile(filePath, 'utf8');
29
+ }
30
+
31
+ async workspaceFileExists(workspacePath: string, featureId: string, filename: string): Promise<boolean> {
32
+ const vaultDir = this.getVaultPath(featureId);
33
+ const filePath = path.join(vaultDir, filename);
34
+ try {
35
+ await fs.access(filePath);
36
+ return true;
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ resolveWorkspaceFileUrl(workspacePath: string, featureId: string, filename: string): string {
43
+ const vaultDir = this.getVaultPath(featureId);
44
+ return path.join(vaultDir, filename).replace(/\\/g, '/');
45
+ }
46
+
47
+ private getBaseVaultPath(repoName: string): string {
48
+ return path.join(os.homedir(), '.nexusflow', 'vault', '_base', repoName);
49
+ }
50
+
51
+ async writeBaseFile(workspacePath: string, repoName: string, filename: string, content: string): Promise<void> {
52
+ const baseDir = this.getBaseVaultPath(repoName);
53
+ const filePath = path.join(baseDir, filename);
54
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
55
+ await fs.writeFile(filePath, content, 'utf8');
56
+ }
57
+
58
+ async readBaseFile(workspacePath: string, repoName: string, filename: string): Promise<string> {
59
+ const baseDir = this.getBaseVaultPath(repoName);
60
+ const filePath = path.join(baseDir, filename);
61
+ return await fs.readFile(filePath, 'utf8');
62
+ }
63
+
64
+ async baseFileExists(workspacePath: string, repoName: string, filename: string): Promise<boolean> {
65
+ const baseDir = this.getBaseVaultPath(repoName);
66
+ const filePath = path.join(baseDir, filename);
67
+ try {
68
+ await fs.access(filePath);
69
+ return true;
70
+ } catch {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ resolveBaseFileUrl(workspacePath: string, repoName: string, filename: string): string {
76
+ const baseDir = this.getBaseVaultPath(repoName);
77
+ return path.join(baseDir, filename).replace(/\\/g, '/');
78
+ }
79
+
80
+ async deleteWorkspace(workspacePath: string, featureId: string): Promise<void> {
81
+ const dir = this.getVaultPath(featureId);
82
+ try {
83
+ await fs.rm(dir, { recursive: true, force: true });
84
+ } catch {}
85
+ }
86
+ }
@@ -8,6 +8,7 @@ import * as path from 'node:path';
8
8
  import * as os from 'node:os';
9
9
 
10
10
  import type { NexusFlowConfig } from '../types.js';
11
+ import { getStorageProvider, setActiveStorageProvider } from './adapters/registry.js';
11
12
 
12
13
  /** Name of the config directory under the user's home folder. */
13
14
  const CONFIG_DIR_NAME = '.nexusflow';
@@ -33,7 +34,6 @@ export function getDefaultConfig(): NexusFlowConfig {
33
34
  defaultAssistant: null,
34
35
  defaultEditor: null,
35
36
  scanDepth: 2,
36
- packContextXml: false,
37
37
  excludePatterns: [
38
38
  '**/node_modules/**',
39
39
  '**/bin/**',
@@ -84,20 +84,34 @@ export async function ensureConfigDir(): Promise<void> {
84
84
  export async function loadConfig(): Promise<NexusFlowConfig> {
85
85
  const configPath = path.join(getConfigDir(), CONFIG_FILE_NAME);
86
86
 
87
+ let merged: NexusFlowConfig;
87
88
  try {
88
89
  const raw = await fs.readFile(configPath, 'utf-8');
89
90
  const parsed = JSON.parse(raw) as Partial<NexusFlowConfig>;
90
91
 
91
92
  // Merge with defaults so newly-added keys are always present.
92
- const merged = { ...getDefaultConfig(), ...parsed };
93
+ merged = { ...getDefaultConfig(), ...parsed };
93
94
  if (parsed.localLlm) {
94
95
  merged.localLlm = { ...getDefaultConfig().localLlm, ...parsed.localLlm };
95
96
  }
96
- return merged;
97
97
  } catch {
98
98
  // File doesn't exist or is unreadable — return defaults.
99
- return getDefaultConfig();
99
+ merged = getDefaultConfig();
100
100
  }
101
+
102
+ // Set the active storage provider based on configuration
103
+ try {
104
+ const providerName = merged.storageProvider || 'local';
105
+ const provider = getStorageProvider(providerName);
106
+ // Pass per-adapter settings if available
107
+ const adapterSettings = merged.adapterConfig?.[providerName] ?? {};
108
+ if (provider.configure) {
109
+ provider.configure(adapterSettings);
110
+ }
111
+ setActiveStorageProvider(provider);
112
+ } catch {}
113
+
114
+ return merged;
101
115
  }
102
116
 
103
117
  /**
@@ -112,4 +126,15 @@ export async function saveConfig(config: NexusFlowConfig): Promise<void> {
112
126
  const configPath = path.join(getConfigDir(), CONFIG_FILE_NAME);
113
127
  const data = JSON.stringify(config, null, 2) + '\n';
114
128
  await fs.writeFile(configPath, data, 'utf-8');
129
+
130
+ // Set the active storage provider based on configuration
131
+ try {
132
+ const providerName = config.storageProvider || 'local';
133
+ const provider = getStorageProvider(providerName);
134
+ const adapterSettings = config.adapterConfig?.[providerName] ?? {};
135
+ if (provider.configure) {
136
+ provider.configure(adapterSettings);
137
+ }
138
+ setActiveStorageProvider(provider);
139
+ } catch {}
115
140
  }
@@ -0,0 +1,17 @@
1
+ import type { StoragePort } from '../ports/storage.js';
2
+
3
+ export type { StoragePort, StorageAdapterMeta, AdapterConfigField } from '../ports/storage.js';
4
+
5
+ export interface PluginRegistryContext {
6
+ /** Registers a custom storage provider/adapter. The provider must include a `meta` property. */
7
+ registerStorageProvider(name: string, provider: StoragePort): void;
8
+
9
+ /** Registers a custom commander CLI subcommand. */
10
+ registerCommand(commandBuilder: (program: any) => void): void;
11
+ }
12
+
13
+ export interface NexusFlowPlugin {
14
+ name: string;
15
+ version: string;
16
+ register(context: PluginRegistryContext): void | Promise<void>;
17
+ }
@@ -0,0 +1,36 @@
1
+ import * as path from 'node:path';
2
+ import type { PluginRegistryContext, NexusFlowPlugin } from './index.js';
3
+ import { registerStorageProvider } from '../adapters/registry.js';
4
+
5
+ export async function loadPlugins(program: any, pluginsList: string[]): Promise<void> {
6
+ const context: PluginRegistryContext = {
7
+ registerStorageProvider(name, provider) {
8
+ registerStorageProvider(name, provider);
9
+ },
10
+ registerCommand(commandBuilder) {
11
+ commandBuilder(program);
12
+ }
13
+ };
14
+
15
+ for (const pluginPath of pluginsList) {
16
+ try {
17
+ let resolvedPath = pluginPath;
18
+ if (pluginPath.startsWith('.') || path.isAbsolute(pluginPath)) {
19
+ resolvedPath = path.resolve(pluginPath);
20
+ }
21
+
22
+ // Dynamic import works with file:// URLs on Windows
23
+ const fileUrl = resolvedPath.startsWith('file://') ? resolvedPath : `file:///${resolvedPath.replace(/\\/g, '/')}`;
24
+ const module = await import(fileUrl);
25
+ const plugin: NexusFlowPlugin = module.default || module.plugin;
26
+
27
+ if (plugin && typeof plugin.register === 'function') {
28
+ await plugin.register(context);
29
+ } else {
30
+ console.warn(`Warning: Plugin at "${pluginPath}" does not export a valid NexusFlowPlugin.`);
31
+ }
32
+ } catch (error: any) {
33
+ console.error(`Failed to load plugin "${pluginPath}":`, error.message);
34
+ }
35
+ }
36
+ }