@sanqianx/claude-ai-workbench 0.11.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 (90) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +129 -0
  3. package/apps/agent-terminal/app.css +567 -0
  4. package/apps/agent-terminal/app.js +2392 -0
  5. package/apps/agent-terminal/index.html +158 -0
  6. package/apps/ai-profile-settings-host/index.html +25 -0
  7. package/apps/ai-profile-settings-host/page.css +1 -0
  8. package/apps/ai-profile-settings-host/page.js +113 -0
  9. package/apps/minimal-test-host/README.md +15 -0
  10. package/apps/minimal-test-host/host.css +2 -0
  11. package/apps/minimal-test-host/host.js +35 -0
  12. package/apps/minimal-test-host/index.html +58 -0
  13. package/apps/minimal-test-host/optional-mock/fault-injection.js +15 -0
  14. package/docs/sdk/FILE_LAYOUT.md +31 -0
  15. package/docs/sdk/INTEGRATION.md +126 -0
  16. package/docs/sdk/README.md +21 -0
  17. package/docs/sdk/openapi.yaml +760 -0
  18. package/package.json +51 -0
  19. package/packages/client/README.md +11 -0
  20. package/packages/client/index.d.ts +81 -0
  21. package/packages/client/index.js +198 -0
  22. package/packages/client/package.json +29 -0
  23. package/packages/contracts/README.md +9 -0
  24. package/packages/contracts/index.d.ts +252 -0
  25. package/packages/contracts/index.js +295 -0
  26. package/packages/contracts/package.json +24 -0
  27. package/packages/core/README.md +8 -0
  28. package/packages/core/index.d.ts +76 -0
  29. package/packages/core/index.js +214 -0
  30. package/packages/core/package.json +29 -0
  31. package/packages/server/README.md +17 -0
  32. package/packages/server/bin/agent-terminal-server.js +36 -0
  33. package/packages/server/bin/claude-workbench-server.js +46 -0
  34. package/packages/server/bin/claude-workbench.js +225 -0
  35. package/packages/server/index.d.ts +145 -0
  36. package/packages/server/index.js +183 -0
  37. package/packages/server/lib/agent-discovery.js +112 -0
  38. package/packages/server/lib/agent-registry.js +98 -0
  39. package/packages/server/lib/attachment-store.js +78 -0
  40. package/packages/server/lib/bridges/app-server-bridge.js +372 -0
  41. package/packages/server/lib/bridges/opencode-server-bridge.js +490 -0
  42. package/packages/server/lib/capture-settings-store.js +34 -0
  43. package/packages/server/lib/context-resolver.js +40 -0
  44. package/packages/server/lib/drivers/cli-json-runner.js +960 -0
  45. package/packages/server/lib/drivers/codex-driver.js +1413 -0
  46. package/packages/server/lib/drivers/opencode-driver.js +1527 -0
  47. package/packages/server/lib/drivers/zcode-driver.js +1167 -0
  48. package/packages/server/lib/event-stream.js +35 -0
  49. package/packages/server/lib/folder-picker.js +623 -0
  50. package/packages/server/lib/http-handler.js +254 -0
  51. package/packages/server/lib/json-file.js +19 -0
  52. package/packages/server/lib/model-detection.js +295 -0
  53. package/packages/server/lib/profile-store.js +149 -0
  54. package/packages/server/lib/project-store.js +102 -0
  55. package/packages/server/lib/session-archive-store.js +53 -0
  56. package/packages/server/lib/system-doctor.js +119 -0
  57. package/packages/server/lib/ui-preferences-store.js +48 -0
  58. package/packages/server/lib/workbench-service.js +620 -0
  59. package/packages/server/package.json +34 -0
  60. package/packages/ui/README.md +30 -0
  61. package/packages/ui/ai-profile-settings.d.ts +45 -0
  62. package/packages/ui/ai-profile-settings.js +283 -0
  63. package/packages/ui/claude-terminal.d.ts +31 -0
  64. package/packages/ui/claude-terminal.js +343 -0
  65. package/packages/ui/index.d.ts +18 -0
  66. package/packages/ui/index.js +51 -0
  67. package/packages/ui/package.json +42 -0
  68. package/packages/ui/theme.css +13 -0
  69. package/src/assets/claude-prompts.json +21 -0
  70. package/src/backend/http/ai-profile-routes.js +61 -0
  71. package/src/backend/http/claude-routes.js +170 -0
  72. package/src/backend/http/node-helpers.js +45 -0
  73. package/src/backend/index.js +21 -0
  74. package/src/backend/lib/ai-adapter.js +144 -0
  75. package/src/backend/lib/ai-profile-store.js +259 -0
  76. package/src/backend/lib/ai-vendor-presets.js +83 -0
  77. package/src/backend/lib/ai-workspace.js +140 -0
  78. package/src/backend/lib/automation-config.js +253 -0
  79. package/src/backend/lib/claude-cli-runner.js +1749 -0
  80. package/src/backend/lib/data-dir.js +169 -0
  81. package/src/backend/lib/llm-client.js +176 -0
  82. package/src/backend/lib/model-context-windows.js +82 -0
  83. package/src/backend/lib/prompt-registry.js +166 -0
  84. package/src/backend/lib/runtime-config.js +121 -0
  85. package/src/index.js +7 -0
  86. package/src/sdk-wave-a.ts +1 -0
  87. package/src/sdk-wave-b.ts +1 -0
  88. package/src/sdk-wave-c.ts +1 -0
  89. package/src/sdk-wave-d.ts +1 -0
  90. package/src/sdk-wave-e.ts +1 -0
@@ -0,0 +1,259 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { getDataDir } = require('./data-dir');
4
+ const { completeText } = require('./llm-client');
5
+
6
+ const SCHEMA = 'ai-profiles/v1';
7
+ const DEFAULT_TIMEOUT_MS = 300000;
8
+ const DEFAULT_CONTEXT_WINDOW = 200000;
9
+
10
+ function readJsonOrDefault(filePath, fallback) {
11
+ try {
12
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
13
+ } catch {
14
+ return fallback;
15
+ }
16
+ }
17
+
18
+ function writeJson(filePath, value) {
19
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
20
+ fs.writeFileSync(filePath, JSON.stringify(value, null, 2) + '\n', 'utf8');
21
+ }
22
+
23
+ function maskSecret(value) {
24
+ if (!value) return '';
25
+ const text = String(value);
26
+ if (text.length <= 8) return '********';
27
+ return `${text.slice(0, 4)}...${text.slice(-4)}`;
28
+ }
29
+
30
+ function toPositiveInteger(value, fallback) {
31
+ const n = Number(value);
32
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : fallback;
33
+ }
34
+
35
+ function normalizeSystemPrompt(value) {
36
+ if (value && typeof value === 'object') return value;
37
+ if (typeof value === 'string' && value.trim()) {
38
+ try {
39
+ return JSON.parse(value);
40
+ } catch {
41
+ return value;
42
+ }
43
+ }
44
+ return { type: 'preset', preset: 'claude_code' };
45
+ }
46
+
47
+ function isBlankAiProfileDraft(profile) {
48
+ return ![
49
+ profile.provider,
50
+ profile.baseUrl,
51
+ profile.apiBaseUrl,
52
+ profile.anthropicBaseUrl,
53
+ profile.apiKey,
54
+ profile.authToken,
55
+ profile.anthropicAuthToken,
56
+ profile.mainModel,
57
+ profile.model,
58
+ profile.website,
59
+ profile.notes,
60
+ ].some(value => String(value || '').trim());
61
+ }
62
+
63
+ function profileImplementation(profile) {
64
+ return profile && (profile.implementation || profile.adapter || 'claude-code-agent') || 'claude-code-agent';
65
+ }
66
+
67
+ function normalizeProfilesConfig(profiles, existingCfg = { profiles: [] }, activeAiProfileId = null, options = {}) {
68
+ const existingById = new Map((existingCfg.profiles || []).filter(p => p && p.id).map(p => [p.id, p]));
69
+ const seen = new Set();
70
+ const normalized = [];
71
+ for (const raw of profiles || []) {
72
+ if (!raw || typeof raw !== 'object') continue;
73
+ const id = String(raw.id || '').trim();
74
+ if (id && id !== activeAiProfileId && options.dropBlankDrafts !== false && isBlankAiProfileDraft(raw)) continue;
75
+ if (!id) throw new Error('AI profile is missing id');
76
+ if (seen.has(id)) throw new Error(`duplicate AI profile id: ${id}`);
77
+ seen.add(id);
78
+ const existing = existingById.get(id) || {};
79
+ const provider = String(raw.provider || raw.name || existing.provider || existing.name || id).trim() || id;
80
+ const profile = {
81
+ ...existing,
82
+ ...raw,
83
+ id,
84
+ name: String(raw.name || raw.provider || existing.name || provider || id).trim() || id,
85
+ provider,
86
+ enabled: raw.enabled !== false,
87
+ implementation: 'claude-code-agent',
88
+ baseUrl: String(raw.baseUrl || raw.apiBaseUrl || raw.anthropicBaseUrl || '').trim(),
89
+ notes: String(raw.notes || '').trim(),
90
+ website: String(raw.website || '').trim(),
91
+ mainModel: String(raw.mainModel || raw.model || '').trim(),
92
+ thinkingModel: String(raw.thinkingModel || raw.mainModel || raw.model || '').trim(),
93
+ haikuModel: String(raw.haikuModel || raw.mainModel || raw.model || '').trim(),
94
+ sonnetModel: String(raw.sonnetModel || raw.mainModel || raw.model || '').trim(),
95
+ opusModel: String(raw.opusModel || raw.mainModel || raw.model || '').trim(),
96
+ model: String(raw.model || raw.mainModel || '').trim(),
97
+ timeoutMs: toPositiveInteger(raw.timeoutMs, DEFAULT_TIMEOUT_MS),
98
+ contextWindow: toPositiveInteger(raw.contextWindow, DEFAULT_CONTEXT_WINDOW),
99
+ runner: 'sdk',
100
+ systemPrompt: normalizeSystemPrompt(raw.systemPrompt),
101
+ };
102
+ for (const key of ['apiKey', 'authToken', 'anthropicAuthToken']) {
103
+ profile[key] = raw[key] ? String(raw[key]) : existing[key] || '';
104
+ }
105
+ delete profile.hasApiKey;
106
+ delete profile.apiKeyMasked;
107
+ normalized.push(profile);
108
+ }
109
+ return { schema: SCHEMA, profiles: normalized };
110
+ }
111
+
112
+ function validateProfile(profile, id = profile && profile.id) {
113
+ if (!id) return { ok: false, error: 'AI profile id is required' };
114
+ if (!profile) return { ok: false, error: `AI profile not found: ${id}` };
115
+ if (profile.enabled === false) return { ok: false, error: `AI profile is disabled: ${id}` };
116
+ if (profileImplementation(profile) !== 'claude-code-agent') {
117
+ return { ok: false, error: `unsupported AI implementation: ${profileImplementation(profile)}` };
118
+ }
119
+ if (!(profile.apiKey || profile.authToken || profile.anthropicAuthToken)) {
120
+ return { ok: false, error: `AI profile is missing API key: ${id}` };
121
+ }
122
+ if (!(profile.mainModel || profile.model)) {
123
+ return { ok: false, error: `AI profile is missing model: ${id}` };
124
+ }
125
+ if (!(profile.baseUrl || profile.apiBaseUrl || profile.anthropicBaseUrl)) {
126
+ return { ok: false, error: `AI profile is missing baseUrl: ${id}` };
127
+ }
128
+ return { ok: true, profile, implementation: profileImplementation(profile) };
129
+ }
130
+
131
+ function validateProfileConfig(cfg) {
132
+ const errors = [];
133
+ if (!cfg || typeof cfg !== 'object') return ['config must be an object'];
134
+ if (cfg.schema && cfg.schema !== SCHEMA) errors.push(`schema must be ${SCHEMA}`);
135
+ if (!Array.isArray(cfg.profiles)) errors.push('profiles must be an array');
136
+ const ids = new Set();
137
+ for (const profile of cfg.profiles || []) {
138
+ const id = profile && profile.id;
139
+ if (!id) {
140
+ errors.push('profile id is required');
141
+ continue;
142
+ }
143
+ if (ids.has(id)) errors.push(`duplicate profile id: ${id}`);
144
+ ids.add(id);
145
+ const check = validateProfile(profile, id);
146
+ if (!check.ok) errors.push(check.error);
147
+ }
148
+ return errors;
149
+ }
150
+
151
+ function publicProfile(profile) {
152
+ const secret = profile.apiKey || profile.authToken || profile.anthropicAuthToken || '';
153
+ return {
154
+ ...profile,
155
+ apiKey: '',
156
+ authToken: '',
157
+ anthropicAuthToken: '',
158
+ hasApiKey: !!secret,
159
+ apiKeyMasked: maskSecret(secret),
160
+ };
161
+ }
162
+
163
+ class AiProfileStore {
164
+ constructor(options = {}) {
165
+ this.profilesPath = options.profilesPath || path.join(getDataDir(), 'ai-profiles.json');
166
+ this.activeProfileId = options.activeProfileId || null;
167
+ this.dropBlankDrafts = options.dropBlankDrafts !== false;
168
+ }
169
+
170
+ readConfig() {
171
+ const cfg = readJsonOrDefault(this.profilesPath, { schema: SCHEMA, profiles: [] });
172
+ if (cfg && cfg.schema === SCHEMA && Array.isArray(cfg.profiles)) return cfg;
173
+ return { schema: SCHEMA, profiles: [] };
174
+ }
175
+
176
+ writeConfig(cfg) {
177
+ const normalized = normalizeProfilesConfig(
178
+ Array.isArray(cfg && cfg.profiles) ? cfg.profiles : [],
179
+ this.readConfig(),
180
+ cfg && (cfg.activeAiProfileId || cfg.defaultProviderId || this.activeProfileId),
181
+ { dropBlankDrafts: this.dropBlankDrafts }
182
+ );
183
+ const errors = validateProfileConfig(normalized);
184
+ if (errors.length) {
185
+ const err = new Error(errors[0]);
186
+ err.errors = errors;
187
+ throw err;
188
+ }
189
+ writeJson(this.profilesPath, normalized);
190
+ return normalized;
191
+ }
192
+
193
+ publicConfig() {
194
+ const cfg = this.readConfig();
195
+ const profiles = (cfg.profiles || []).map(publicProfile);
196
+ return {
197
+ ok: true,
198
+ aiProfilesPath: this.profilesPath,
199
+ config: { schema: SCHEMA, profiles },
200
+ profiles,
201
+ activeAiProfileId: this.activeProfileId || (profiles.find(p => p.enabled !== false) || {}).id || null,
202
+ };
203
+ }
204
+
205
+ profileById(id) {
206
+ return (this.readConfig().profiles || []).find(profile => profile && profile.id === id) || null;
207
+ }
208
+
209
+ firstUsableProfileId() {
210
+ return ((this.readConfig().profiles || []).find(profile => validateProfile(profile).ok) || {}).id || null;
211
+ }
212
+
213
+ activeProfile() {
214
+ return this.profileById(this.activeProfileId) || this.profileById(this.firstUsableProfileId());
215
+ }
216
+
217
+ validateProfile(idOrProfile) {
218
+ const profile = typeof idOrProfile === 'string' ? this.profileById(idOrProfile) : idOrProfile;
219
+ const id = typeof idOrProfile === 'string' ? idOrProfile : profile && profile.id;
220
+ return validateProfile(profile, id);
221
+ }
222
+
223
+ async testProfile({ profileId, profile, prompt = 'what model are you?', maxTokens = 128 } = {}) {
224
+ const resolved = profile || this.profileById(profileId);
225
+ const id = profileId || resolved && resolved.id;
226
+ const check = validateProfile(resolved, id);
227
+ if (!check.ok) {
228
+ const err = new Error(check.error);
229
+ err.status = 400;
230
+ throw err;
231
+ }
232
+ const result = await completeText({
233
+ profileId: id,
234
+ profile: resolved,
235
+ user: prompt,
236
+ maxTokens,
237
+ });
238
+ return {
239
+ ok: true,
240
+ profileId: id,
241
+ model: result.model,
242
+ text: result.text,
243
+ usage: result.usage,
244
+ };
245
+ }
246
+ }
247
+
248
+ module.exports = {
249
+ AiProfileStore,
250
+ SCHEMA,
251
+ DEFAULT_TIMEOUT_MS,
252
+ DEFAULT_CONTEXT_WINDOW,
253
+ maskSecret,
254
+ publicProfile,
255
+ profileImplementation,
256
+ normalizeProfilesConfig,
257
+ validateProfile,
258
+ validateProfileConfig,
259
+ };
@@ -0,0 +1,83 @@
1
+ // Built-in vendor presets for common Anthropic-compatible providers.
2
+ // baseUrl and model names verified against each vendor's public docs (2026-06).
3
+ // When a user picks one of these vendor names in the profile form, all fields
4
+ // below are auto-filled — they only need to supply an API key.
5
+ //
6
+ // baseUrl MUST be the /anthropic-compatible endpoint, not the OpenAI-compatible
7
+ // one, because the runner speaks the Anthropic Messages API. Wrong path → 404.
8
+ const AI_VENDOR_PRESETS = [
9
+ {
10
+ id: 'anthropic',
11
+ name: 'Anthropic Claude',
12
+ baseUrl: 'https://api.anthropic.com',
13
+ mainModel: 'claude-sonnet-4-5',
14
+ thinkingModel: 'claude-opus-4-7',
15
+ haikuModel: 'claude-haiku-4-5',
16
+ sonnetModel: 'claude-sonnet-4-5',
17
+ opusModel: 'claude-opus-4-7',
18
+ contextWindow: 200000,
19
+ website: 'https://www.anthropic.com',
20
+ },
21
+ {
22
+ id: 'minimax',
23
+ name: 'MiniMax',
24
+ // Domestic (China) endpoint. minimax.io is the overseas domain with a
25
+ // separate account system — API keys are NOT interchangeable. Domestic
26
+ // users register at minimaxi.com, so we default to that.
27
+ baseUrl: 'https://api.minimaxi.com/anthropic',
28
+ mainModel: 'MiniMax-M3',
29
+ thinkingModel: 'MiniMax-M3',
30
+ haikuModel: 'MiniMax-M3',
31
+ sonnetModel: 'MiniMax-M3',
32
+ opusModel: 'MiniMax-M3',
33
+ contextWindow: 1048576,
34
+ website: 'https://platform.minimaxi.com',
35
+ },
36
+ {
37
+ id: 'zhipu',
38
+ name: '智谱 GLM',
39
+ // Anthropic-compatible endpoint, not the OpenAI-style /api/paas/v4.
40
+ baseUrl: 'https://open.bigmodel.cn/api/anthropic',
41
+ mainModel: 'glm-4.6',
42
+ thinkingModel: 'glm-4.6',
43
+ haikuModel: 'glm-4.5-air',
44
+ sonnetModel: 'glm-4.6',
45
+ opusModel: 'glm-4.6',
46
+ contextWindow: 1048576,
47
+ website: 'https://open.bigmodel.cn',
48
+ },
49
+ {
50
+ id: 'deepseek',
51
+ name: 'DeepSeek',
52
+ // Anthropic-compatible endpoint at /anthropic, not the bare domain.
53
+ baseUrl: 'https://api.deepseek.com/anthropic',
54
+ mainModel: 'deepseek-chat',
55
+ thinkingModel: 'deepseek-reasoner',
56
+ haikuModel: 'deepseek-chat',
57
+ sonnetModel: 'deepseek-chat',
58
+ opusModel: 'deepseek-reasoner',
59
+ contextWindow: 128000,
60
+ website: 'https://platform.deepseek.com',
61
+ },
62
+ ];
63
+
64
+ function listVendorPresetNames() {
65
+ return AI_VENDOR_PRESETS.map(v => v.name);
66
+ }
67
+
68
+ // Match by name (case-insensitive) or id (case-insensitive). Returns the
69
+ // preset object or null. Custom vendor names that don't match return null —
70
+ // the caller then leaves the user-typed value alone.
71
+ function findVendorPresetByName(name) {
72
+ const norm = String(name || '').trim().toLowerCase();
73
+ if (!norm) return null;
74
+ return AI_VENDOR_PRESETS.find(v =>
75
+ v.name.toLowerCase() === norm || v.id.toLowerCase() === norm
76
+ ) || null;
77
+ }
78
+
79
+ module.exports = {
80
+ AI_VENDOR_PRESETS,
81
+ listVendorPresetNames,
82
+ findVendorPresetByName,
83
+ };
@@ -0,0 +1,140 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { getDataDir } = require('./data-dir');
4
+ const { getWorkbenchConfig } = require('./runtime-config');
5
+
6
+ const SITE_ROOT = path.resolve(__dirname, '..');
7
+
8
+ function appRoot() {
9
+ return getDataDir();
10
+ }
11
+
12
+ function aiRoot() {
13
+ const cfg = getWorkbenchConfig();
14
+ return path.join(appRoot(), cfg.aiRootDirName || '_ai');
15
+ }
16
+
17
+ function standardSubdirs() {
18
+ const cfg = getWorkbenchConfig();
19
+ const dirs = Array.isArray(cfg.standardSubdirs) && cfg.standardSubdirs.length
20
+ ? cfg.standardSubdirs.slice()
21
+ : ['drafts', 'runs', 'context-packs', 'backups'];
22
+ if (cfg.sessionDirName && !dirs.includes(cfg.sessionDirName)) dirs.push(cfg.sessionDirName);
23
+ return dirs;
24
+ }
25
+
26
+ function safeSlug(slug) {
27
+ return typeof slug === 'string' && /^[a-z0-9][a-z0-9-]{0,40}$/.test(slug);
28
+ }
29
+
30
+ function projectAIPath(slug) {
31
+ if (!safeSlug(slug)) throw new Error(`invalid slug for AI workspace: ${slug}`);
32
+ return path.join(aiRoot(), slug);
33
+ }
34
+
35
+ function ensureProjectAIPath(slug) {
36
+ const root = projectAIPath(slug);
37
+ for (const sub of standardSubdirs()) {
38
+ fs.mkdirSync(path.join(root, sub), { recursive: true });
39
+ }
40
+ return root;
41
+ }
42
+
43
+ function legacyAIPath(kbPath) {
44
+ return path.join(kbPath, '_ai');
45
+ }
46
+
47
+ function copyDir(src, dest) {
48
+ fs.mkdirSync(dest, { recursive: true });
49
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
50
+ const from = path.join(src, entry.name);
51
+ const to = path.join(dest, entry.name);
52
+ if (entry.isDirectory()) copyDir(from, to);
53
+ else if (entry.isFile()) fs.copyFileSync(from, to);
54
+ }
55
+ }
56
+
57
+ function migrateAIWorkspace({ slug, kbPath, preserveOriginal = true }) {
58
+ const legacy = legacyAIPath(kbPath);
59
+ const target = ensureProjectAIPath(slug);
60
+ const result = {
61
+ ok: true,
62
+ slug,
63
+ legacyPath: legacy,
64
+ targetPath: target,
65
+ copied: false,
66
+ preservedOriginal: preserveOriginal,
67
+ };
68
+ if (!fs.existsSync(legacy)) return result;
69
+ copyDir(legacy, target);
70
+ result.copied = true;
71
+ if (!preserveOriginal) {
72
+ fs.rmSync(legacy, { recursive: true, force: true });
73
+ result.preservedOriginal = false;
74
+ }
75
+ return result;
76
+ }
77
+
78
+ function runPath(slug, runId) {
79
+ return path.join(projectAIPath(slug), 'runs', `${runId}.json`);
80
+ }
81
+
82
+ function draftDir(slug, runId) {
83
+ return path.join(projectAIPath(slug), 'drafts', runId);
84
+ }
85
+
86
+ function contextPackDir(slug, runId) {
87
+ return path.join(projectAIPath(slug), 'context-packs', runId);
88
+ }
89
+
90
+ function findExistingRunPath({ slug, kbPath, runId }) {
91
+ const primary = path.join(projectAIPath(slug), 'runs', `${runId}.json`);
92
+ return primary;
93
+ }
94
+
95
+ function findExistingDraftDir({ slug, kbPath, runId }) {
96
+ const primary = path.join(projectAIPath(slug), 'drafts', runId);
97
+ return primary;
98
+ }
99
+
100
+ function listProjectDirs(projectSlug = null, projects = null) {
101
+ if (projectSlug) return [projectAIPath(projectSlug)];
102
+ const dirs = [];
103
+ const root = aiRoot();
104
+ if (fs.existsSync(root)) {
105
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
106
+ if (entry.isDirectory() && safeSlug(entry.name)) dirs.push(path.join(root, entry.name));
107
+ }
108
+ }
109
+ if (projects) {
110
+ for (const [slug] of Object.entries(projects)) {
111
+ if (safeSlug(slug)) dirs.push(projectAIPath(slug));
112
+ }
113
+ }
114
+ return [...new Set(dirs.map(d => path.resolve(d)))];
115
+ }
116
+
117
+ const exported = {
118
+ SITE_ROOT,
119
+ appRoot,
120
+ aiRoot,
121
+ standardSubdirs,
122
+ projectAIPath,
123
+ ensureProjectAIPath,
124
+ legacyAIPath,
125
+ migrateAIWorkspace,
126
+ runPath,
127
+ draftDir,
128
+ contextPackDir,
129
+ findExistingRunPath,
130
+ findExistingDraftDir,
131
+ listProjectDirs,
132
+ };
133
+
134
+ Object.defineProperties(exported, {
135
+ APP_ROOT: { enumerable: true, get: appRoot },
136
+ AI_ROOT: { enumerable: true, get: aiRoot },
137
+ STANDARD_SUBDIRS: { enumerable: true, get: standardSubdirs },
138
+ });
139
+
140
+ module.exports = exported;