@stackmemoryai/stackmemory 0.2.4 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +353 -83
- package/dist/index.js +382 -0
- package/dist/scripts/cancel-duplicate-tasks.d.ts +7 -0
- package/dist/scripts/cancel-duplicate-tasks.d.ts.map +1 -0
- package/dist/scripts/cancel-duplicate-tasks.js +171 -0
- package/dist/scripts/cancel-duplicate-tasks.js.map +1 -0
- package/dist/scripts/list-linear-tasks.d.ts +6 -0
- package/dist/scripts/list-linear-tasks.d.ts.map +1 -0
- package/dist/scripts/list-linear-tasks.js +122 -0
- package/dist/scripts/list-linear-tasks.js.map +1 -0
- package/dist/scripts/merge-linear-duplicates-safe.d.ts +7 -0
- package/dist/scripts/merge-linear-duplicates-safe.d.ts.map +1 -0
- package/dist/scripts/merge-linear-duplicates-safe.js +265 -0
- package/dist/scripts/merge-linear-duplicates-safe.js.map +1 -0
- package/dist/scripts/merge-linear-duplicates.d.ts +7 -0
- package/dist/scripts/merge-linear-duplicates.d.ts.map +1 -0
- package/dist/scripts/merge-linear-duplicates.js +126 -0
- package/dist/scripts/merge-linear-duplicates.js.map +1 -0
- package/dist/scripts/show-linear-summary.d.ts +6 -0
- package/dist/scripts/show-linear-summary.d.ts.map +1 -0
- package/dist/scripts/show-linear-summary.js +117 -0
- package/dist/scripts/show-linear-summary.js.map +1 -0
- package/dist/src/analytics/api/analytics-api.d.ts +24 -0
- package/dist/src/analytics/api/analytics-api.d.ts.map +1 -0
- package/dist/src/analytics/api/analytics-api.js +279 -0
- package/dist/src/analytics/api/analytics-api.js.map +1 -0
- package/dist/src/analytics/core/analytics-service.d.ts +23 -0
- package/dist/src/analytics/core/analytics-service.d.ts.map +1 -0
- package/dist/src/analytics/core/analytics-service.js +160 -0
- package/dist/src/analytics/core/analytics-service.js.map +1 -0
- package/dist/src/analytics/index.d.ts +12 -0
- package/dist/src/analytics/index.d.ts.map +1 -0
- package/dist/src/analytics/index.js +11 -0
- package/dist/src/analytics/index.js.map +1 -0
- package/dist/src/analytics/queries/metrics-queries.d.ts +11 -0
- package/dist/src/analytics/queries/metrics-queries.d.ts.map +1 -0
- package/dist/src/analytics/queries/metrics-queries.js +179 -0
- package/dist/src/analytics/queries/metrics-queries.js.map +1 -0
- package/dist/src/analytics/types/metrics.d.ts +60 -0
- package/dist/src/analytics/types/metrics.d.ts.map +1 -0
- package/dist/src/analytics/types/metrics.js +2 -0
- package/dist/src/analytics/types/metrics.js.map +1 -0
- package/dist/src/cli/__tests__/index.test.d.ts +5 -0
- package/dist/src/cli/__tests__/index.test.d.ts.map +1 -0
- package/dist/src/cli/__tests__/index.test.js +726 -0
- package/dist/src/cli/__tests__/index.test.js.map +1 -0
- package/dist/src/cli/analytics-viewer.d.ts +3 -0
- package/dist/src/cli/analytics-viewer.d.ts.map +1 -0
- package/dist/src/cli/analytics-viewer.js +89 -0
- package/dist/src/cli/analytics-viewer.js.map +1 -0
- package/dist/src/cli/auto-detect.d.ts +61 -0
- package/dist/src/cli/auto-detect.d.ts.map +1 -0
- package/dist/src/cli/auto-detect.js +350 -0
- package/dist/src/cli/auto-detect.js.map +1 -0
- package/dist/src/cli/browser-test.d.ts +6 -0
- package/dist/src/cli/browser-test.d.ts.map +1 -0
- package/dist/src/cli/browser-test.js +32 -0
- package/dist/src/cli/browser-test.js.map +1 -0
- package/dist/src/cli/claude-sm.d.ts +7 -0
- package/dist/src/cli/claude-sm.d.ts.map +1 -0
- package/dist/src/cli/claude-sm.js +357 -0
- package/dist/src/cli/claude-sm.js.map +1 -0
- package/dist/src/cli/cli.js +157 -0
- package/dist/src/cli/cli.js.map +1 -1
- package/dist/src/cli/commands/context.d.ts +7 -0
- package/dist/src/cli/commands/context.d.ts.map +1 -0
- package/dist/src/cli/commands/context.js +365 -0
- package/dist/src/cli/commands/context.js.map +1 -0
- package/dist/src/cli/commands/linear-test.d.ts +6 -0
- package/dist/src/cli/commands/linear-test.d.ts.map +1 -0
- package/dist/src/cli/commands/linear-test.js +123 -0
- package/dist/src/cli/commands/linear-test.js.map +1 -0
- package/dist/src/cli/commands/linear.d.ts +6 -0
- package/dist/src/cli/commands/linear.d.ts.map +1 -0
- package/dist/src/cli/commands/linear.js +317 -0
- package/dist/src/cli/commands/linear.js.map +1 -0
- package/dist/src/cli/commands/log.d.ts +7 -0
- package/dist/src/cli/commands/log.d.ts.map +1 -0
- package/dist/src/cli/commands/log.js +168 -0
- package/dist/src/cli/commands/log.js.map +1 -0
- package/dist/src/cli/commands/onboard.d.ts +8 -0
- package/dist/src/cli/commands/onboard.d.ts.map +1 -0
- package/dist/src/cli/commands/onboard.js +363 -0
- package/dist/src/cli/commands/onboard.js.map +1 -0
- package/dist/src/cli/commands/projects.d.ts +8 -0
- package/dist/src/cli/commands/projects.d.ts.map +1 -0
- package/dist/src/cli/commands/projects.js +220 -0
- package/dist/src/cli/commands/projects.js.map +1 -0
- package/dist/src/cli/commands/search.d.ts +7 -0
- package/dist/src/cli/commands/search.d.ts.map +1 -0
- package/dist/src/cli/commands/search.js +162 -0
- package/dist/src/cli/commands/search.js.map +1 -0
- package/dist/src/cli/commands/session.d.ts +7 -0
- package/dist/src/cli/commands/session.d.ts.map +1 -0
- package/dist/src/cli/commands/session.js +222 -0
- package/dist/src/cli/commands/session.js.map +1 -0
- package/dist/src/cli/commands/tasks.d.ts +7 -0
- package/dist/src/cli/commands/tasks.d.ts.map +1 -0
- package/dist/src/cli/commands/tasks.js +229 -0
- package/dist/src/cli/commands/tasks.js.map +1 -0
- package/dist/src/cli/commands/webhook.d.ts +3 -0
- package/dist/src/cli/commands/webhook.d.ts.map +1 -0
- package/dist/src/cli/commands/webhook.js +157 -0
- package/dist/src/cli/commands/webhook.js.map +1 -0
- package/dist/src/cli/commands/worktree.d.ts +8 -0
- package/dist/src/cli/commands/worktree.d.ts.map +1 -0
- package/dist/src/cli/commands/worktree.js +339 -0
- package/dist/src/cli/commands/worktree.js.map +1 -0
- package/dist/src/cli/index.d.ts +8 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +944 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/project-commands.d.ts +8 -0
- package/dist/src/cli/project-commands.d.ts.map +1 -0
- package/dist/src/cli/project-commands.js +212 -0
- package/dist/src/cli/project-commands.js.map +1 -0
- package/dist/src/cli/utils/viewer.d.ts +3 -0
- package/dist/src/cli/utils/viewer.d.ts.map +1 -0
- package/dist/src/cli/utils/viewer.js +91 -0
- package/dist/src/cli/utils/viewer.js.map +1 -0
- package/dist/src/core/context/__tests__/frame-manager.test.d.ts +5 -0
- package/dist/src/core/context/__tests__/frame-manager.test.d.ts.map +1 -0
- package/dist/src/core/context/__tests__/frame-manager.test.js +892 -0
- package/dist/src/core/context/__tests__/frame-manager.test.js.map +1 -0
- package/dist/src/core/context/auto-context.d.ts +22 -0
- package/dist/src/core/context/auto-context.d.ts.map +1 -0
- package/dist/src/core/context/auto-context.js +77 -0
- package/dist/src/core/context/auto-context.js.map +1 -0
- package/dist/src/core/context/frame-manager.d.ts +110 -0
- package/dist/src/core/context/frame-manager.d.ts.map +1 -0
- package/dist/src/core/context/frame-manager.js +593 -0
- package/dist/src/core/context/frame-manager.js.map +1 -0
- package/dist/src/core/errors/__tests__/error-handling.test.d.ts +5 -0
- package/dist/src/core/errors/__tests__/error-handling.test.d.ts.map +1 -0
- package/dist/src/core/errors/__tests__/error-handling.test.js +239 -0
- package/dist/src/core/errors/__tests__/error-handling.test.js.map +1 -0
- package/dist/src/core/errors/index.d.ts +135 -0
- package/dist/src/core/errors/index.d.ts.map +1 -0
- package/dist/src/core/errors/index.js +274 -0
- package/dist/src/core/errors/index.js.map +1 -0
- package/dist/src/core/errors/recovery.d.ts +86 -0
- package/dist/src/core/errors/recovery.d.ts.map +1 -0
- package/dist/src/core/errors/recovery.js +274 -0
- package/dist/src/core/errors/recovery.js.map +1 -0
- package/dist/src/core/logger.test.js +1 -1
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/monitoring/error-handler.d.ts +46 -0
- package/dist/src/core/monitoring/error-handler.d.ts.map +1 -0
- package/dist/src/core/monitoring/error-handler.js +212 -0
- package/dist/src/core/monitoring/error-handler.js.map +1 -0
- package/dist/src/core/monitoring/logger.d.ts +24 -0
- package/dist/src/core/monitoring/logger.d.ts.map +1 -0
- package/dist/src/core/monitoring/logger.js +121 -0
- package/dist/src/core/monitoring/logger.js.map +1 -0
- package/dist/src/core/monitoring/metrics.d.ts +7 -0
- package/dist/src/core/monitoring/metrics.d.ts.map +1 -0
- package/dist/src/core/monitoring/metrics.js +13 -0
- package/dist/src/core/monitoring/metrics.js.map +1 -0
- package/dist/src/core/monitoring/progress-tracker.d.ts +95 -0
- package/dist/src/core/monitoring/progress-tracker.d.ts.map +1 -0
- package/dist/src/core/monitoring/progress-tracker.js +178 -0
- package/dist/src/core/monitoring/progress-tracker.js.map +1 -0
- package/dist/src/core/project-manager.d.ts +130 -0
- package/dist/src/core/project-manager.d.ts.map +1 -0
- package/dist/src/core/project-manager.js +582 -0
- package/dist/src/core/project-manager.js.map +1 -0
- package/dist/src/core/projects/project-manager.d.ts +130 -0
- package/dist/src/core/projects/project-manager.d.ts.map +1 -0
- package/dist/src/core/projects/project-manager.js +709 -0
- package/dist/src/core/projects/project-manager.js.map +1 -0
- package/dist/src/core/session/index.d.ts +2 -0
- package/dist/src/core/session/index.d.ts.map +1 -0
- package/dist/src/core/session/index.js +2 -0
- package/dist/src/core/session/index.js.map +1 -0
- package/dist/src/core/session/session-manager.d.ts +69 -0
- package/dist/src/core/session/session-manager.d.ts.map +1 -0
- package/dist/src/core/session/session-manager.js +311 -0
- package/dist/src/core/session/session-manager.js.map +1 -0
- package/dist/src/core/utils/update-checker.d.ts +38 -0
- package/dist/src/core/utils/update-checker.d.ts.map +1 -0
- package/dist/src/core/utils/update-checker.js +213 -0
- package/dist/src/core/utils/update-checker.js.map +1 -0
- package/dist/src/core/worktree/worktree-manager.d.ts +110 -0
- package/dist/src/core/worktree/worktree-manager.d.ts.map +1 -0
- package/dist/src/core/worktree/worktree-manager.js +456 -0
- package/dist/src/core/worktree/worktree-manager.js.map +1 -0
- package/dist/src/features/analytics/api/analytics-api.d.ts +24 -0
- package/dist/src/features/analytics/api/analytics-api.d.ts.map +1 -0
- package/dist/src/features/analytics/api/analytics-api.js +289 -0
- package/dist/src/features/analytics/api/analytics-api.js.map +1 -0
- package/dist/src/features/analytics/core/analytics-service.d.ts +29 -0
- package/dist/src/features/analytics/core/analytics-service.d.ts.map +1 -0
- package/dist/src/features/analytics/core/analytics-service.js +275 -0
- package/dist/src/features/analytics/core/analytics-service.js.map +1 -0
- package/dist/src/features/analytics/index.d.ts +12 -0
- package/dist/src/features/analytics/index.d.ts.map +1 -0
- package/dist/src/features/analytics/index.js +11 -0
- package/dist/src/features/analytics/index.js.map +1 -0
- package/dist/src/features/analytics/queries/metrics-queries.d.ts +11 -0
- package/dist/src/features/analytics/queries/metrics-queries.d.ts.map +1 -0
- package/dist/src/features/analytics/queries/metrics-queries.js +240 -0
- package/dist/src/features/analytics/queries/metrics-queries.js.map +1 -0
- package/dist/src/features/analytics/types/metrics.d.ts +60 -0
- package/dist/src/features/analytics/types/metrics.d.ts.map +1 -0
- package/dist/src/features/analytics/types/metrics.js +2 -0
- package/dist/src/features/analytics/types/metrics.js.map +1 -0
- package/dist/src/features/browser/browser-mcp.d.ts +94 -0
- package/dist/src/features/browser/browser-mcp.d.ts.map +1 -0
- package/dist/src/features/browser/browser-mcp.js +459 -0
- package/dist/src/features/browser/browser-mcp.js.map +1 -0
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.d.ts +5 -0
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.d.ts.map +1 -0
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.js +712 -0
- package/dist/src/features/tasks/__tests__/pebbles-task-store.test.js.map +1 -0
- package/dist/src/features/tasks/pebbles-task-store.d.ts +121 -0
- package/dist/src/features/tasks/pebbles-task-store.d.ts.map +1 -0
- package/dist/src/features/tasks/pebbles-task-store.js +493 -0
- package/dist/src/features/tasks/pebbles-task-store.js.map +1 -0
- package/dist/src/features/tasks/task-aware-context.d.ts +103 -0
- package/dist/src/features/tasks/task-aware-context.d.ts.map +1 -0
- package/dist/src/features/tasks/task-aware-context.js +412 -0
- package/dist/src/features/tasks/task-aware-context.js.map +1 -0
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/integrations/browser-mcp.d.ts +94 -0
- package/dist/src/integrations/browser-mcp.d.ts.map +1 -0
- package/dist/src/integrations/browser-mcp.js +431 -0
- package/dist/src/integrations/browser-mcp.js.map +1 -0
- package/dist/src/integrations/linear/__tests__/auth.test.d.ts +5 -0
- package/dist/src/integrations/linear/__tests__/auth.test.d.ts.map +1 -0
- package/dist/src/integrations/linear/__tests__/auth.test.js +517 -0
- package/dist/src/integrations/linear/__tests__/auth.test.js.map +1 -0
- package/dist/src/integrations/linear/__tests__/sync-service.test.d.ts +5 -0
- package/dist/src/integrations/linear/__tests__/sync-service.test.d.ts.map +1 -0
- package/dist/src/integrations/linear/__tests__/sync-service.test.js +700 -0
- package/dist/src/integrations/linear/__tests__/sync-service.test.js.map +1 -0
- package/dist/src/integrations/linear/auth.d.ts +99 -0
- package/dist/src/integrations/linear/auth.d.ts.map +1 -0
- package/dist/src/integrations/linear/auth.js +319 -0
- package/dist/src/integrations/linear/auth.js.map +1 -0
- package/dist/src/integrations/linear/auto-sync.d.ts +77 -0
- package/dist/src/integrations/linear/auto-sync.d.ts.map +1 -0
- package/dist/src/integrations/linear/auto-sync.js +268 -0
- package/dist/src/integrations/linear/auto-sync.js.map +1 -0
- package/dist/src/integrations/linear/client.d.ts +113 -0
- package/dist/src/integrations/linear/client.d.ts.map +1 -0
- package/dist/src/integrations/linear/client.js +364 -0
- package/dist/src/integrations/linear/client.js.map +1 -0
- package/dist/src/integrations/linear/config.d.ts +51 -0
- package/dist/src/integrations/linear/config.d.ts.map +1 -0
- package/dist/src/integrations/linear/config.js +103 -0
- package/dist/src/integrations/linear/config.js.map +1 -0
- package/dist/src/integrations/linear/sync-service.d.ts +25 -0
- package/dist/src/integrations/linear/sync-service.d.ts.map +1 -0
- package/dist/src/integrations/linear/sync-service.js +198 -0
- package/dist/src/integrations/linear/sync-service.js.map +1 -0
- package/dist/src/integrations/linear/sync.d.ts +119 -0
- package/dist/src/integrations/linear/sync.d.ts.map +1 -0
- package/dist/src/integrations/linear/sync.js +538 -0
- package/dist/src/integrations/linear/sync.js.map +1 -0
- package/dist/src/integrations/linear/types.d.ts +75 -0
- package/dist/src/integrations/linear/types.d.ts.map +1 -0
- package/dist/src/integrations/linear/types.js +2 -0
- package/dist/src/integrations/linear/types.js.map +1 -0
- package/dist/src/integrations/linear/webhook-server.d.ts +32 -0
- package/dist/src/integrations/linear/webhook-server.d.ts.map +1 -0
- package/dist/src/integrations/linear/webhook-server.js +188 -0
- package/dist/src/integrations/linear/webhook-server.js.map +1 -0
- package/dist/src/integrations/linear/webhook.d.ts +95 -0
- package/dist/src/integrations/linear/webhook.d.ts.map +1 -0
- package/dist/src/integrations/linear/webhook.js +204 -0
- package/dist/src/integrations/linear/webhook.js.map +1 -0
- package/dist/src/integrations/mcp/__tests__/server.test.d.ts +5 -0
- package/dist/src/integrations/mcp/__tests__/server.test.d.ts.map +1 -0
- package/dist/src/integrations/mcp/__tests__/server.test.js +790 -0
- package/dist/src/integrations/mcp/__tests__/server.test.js.map +1 -0
- package/dist/src/integrations/mcp/server.d.ts +46 -0
- package/dist/src/integrations/mcp/server.d.ts.map +1 -0
- package/dist/src/integrations/mcp/server.js +1264 -0
- package/dist/src/integrations/mcp/server.js.map +1 -0
- package/dist/src/mcp/mcp-server.d.ts +1 -0
- package/dist/src/mcp/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp/mcp-server.js +11 -0
- package/dist/src/mcp/mcp-server.js.map +1 -1
- package/dist/src/railway/index.d.ts +7 -0
- package/dist/src/railway/index.d.ts.map +1 -0
- package/dist/src/railway/index.js +401 -0
- package/dist/src/railway/index.js.map +1 -0
- package/dist/src/runway/auth/auth-middleware.d.ts +66 -0
- package/dist/src/runway/auth/auth-middleware.d.ts.map +1 -0
- package/dist/src/runway/auth/auth-middleware.js +337 -0
- package/dist/src/runway/auth/auth-middleware.js.map +1 -0
- package/dist/src/runway/server/runway-mcp-server.d.ts +46 -0
- package/dist/src/runway/server/runway-mcp-server.d.ts.map +1 -0
- package/dist/src/runway/server/runway-mcp-server.js +601 -0
- package/dist/src/runway/server/runway-mcp-server.js.map +1 -0
- package/dist/src/runway.bak/auth/auth-middleware.d.ts +66 -0
- package/dist/src/runway.bak/auth/auth-middleware.d.ts.map +1 -0
- package/dist/src/runway.bak/auth/auth-middleware.js +337 -0
- package/dist/src/runway.bak/auth/auth-middleware.js.map +1 -0
- package/dist/src/runway.bak/server/runway-mcp-server.d.ts +46 -0
- package/dist/src/runway.bak/server/runway-mcp-server.d.ts.map +1 -0
- package/dist/src/runway.bak/server/runway-mcp-server.js +601 -0
- package/dist/src/runway.bak/server/runway-mcp-server.js.map +1 -0
- package/dist/src/servers/production/auth-middleware.d.ts +66 -0
- package/dist/src/servers/production/auth-middleware.d.ts.map +1 -0
- package/dist/src/servers/production/auth-middleware.js +346 -0
- package/dist/src/servers/production/auth-middleware.js.map +1 -0
- package/dist/src/servers/railway/index.d.ts +7 -0
- package/dist/src/servers/railway/index.d.ts.map +1 -0
- package/dist/src/servers/railway/index.js +401 -0
- package/dist/src/servers/railway/index.js.map +1 -0
- package/dist/src/services/config-service.d.ts +44 -0
- package/dist/src/services/config-service.d.ts.map +1 -0
- package/dist/src/services/config-service.js +61 -0
- package/dist/src/services/config-service.js.map +1 -0
- package/dist/src/services/context-service.d.ts +17 -0
- package/dist/src/services/context-service.d.ts.map +1 -0
- package/dist/src/services/context-service.js +88 -0
- package/dist/src/services/context-service.js.map +1 -0
- package/dist/src/types/task.d.ts +17 -0
- package/dist/src/types/task.d.ts.map +1 -0
- package/dist/src/types/task.js +2 -0
- package/dist/src/types/task.js.map +1 -0
- package/dist/src/utils/logger.d.ts +13 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +52 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/package.json +40 -5
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatic Project Management for StackMemory
|
|
3
|
+
* Auto-detects and organizes projects based on Git origins
|
|
4
|
+
*/
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
7
|
+
import { join, basename, dirname } from 'path';
|
|
8
|
+
import { homedir } from 'os';
|
|
9
|
+
import Database from 'better-sqlite3';
|
|
10
|
+
import { logger } from '../monitoring/logger.js';
|
|
11
|
+
import { DatabaseError, ProjectError, ErrorCode, createErrorHandler, } from '../errors/index.js';
|
|
12
|
+
import { retry } from '../errors/recovery.js';
|
|
13
|
+
export class ProjectManager {
|
|
14
|
+
static instance;
|
|
15
|
+
db;
|
|
16
|
+
configPath;
|
|
17
|
+
organizations = new Map();
|
|
18
|
+
projectCache = new Map();
|
|
19
|
+
currentProject;
|
|
20
|
+
constructor() {
|
|
21
|
+
this.configPath = join(homedir(), '.stackmemory');
|
|
22
|
+
this.ensureDirectoryStructure();
|
|
23
|
+
this.initializeDatabase();
|
|
24
|
+
this.loadOrganizations();
|
|
25
|
+
this.autoDiscoverOrganizations();
|
|
26
|
+
}
|
|
27
|
+
static getInstance() {
|
|
28
|
+
if (!ProjectManager.instance) {
|
|
29
|
+
ProjectManager.instance = new ProjectManager();
|
|
30
|
+
}
|
|
31
|
+
return ProjectManager.instance;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Auto-detect project from current directory
|
|
35
|
+
*/
|
|
36
|
+
async detectProject(projectPath) {
|
|
37
|
+
const path = projectPath || process.cwd();
|
|
38
|
+
const errorHandler = createErrorHandler({
|
|
39
|
+
operation: 'detectProject',
|
|
40
|
+
projectPath: path,
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
// Check cache first
|
|
44
|
+
const cached = this.projectCache.get(path);
|
|
45
|
+
if (cached && this.isCacheValid(cached)) {
|
|
46
|
+
return cached;
|
|
47
|
+
}
|
|
48
|
+
const project = await this.analyzeProject(path);
|
|
49
|
+
// Auto-categorize based on git origin
|
|
50
|
+
if (project.gitRemote) {
|
|
51
|
+
project.organization = this.extractOrganization(project.gitRemote);
|
|
52
|
+
project.accountType = this.determineAccountType(project.gitRemote, project.organization);
|
|
53
|
+
project.isPrivate = this.isPrivateRepo(project.gitRemote);
|
|
54
|
+
}
|
|
55
|
+
// Detect framework and language
|
|
56
|
+
project.primaryLanguage = this.detectPrimaryLanguage(path);
|
|
57
|
+
project.framework = this.detectFramework(path);
|
|
58
|
+
// Store in database with retry logic
|
|
59
|
+
await retry(() => Promise.resolve(this.saveProject(project)), {
|
|
60
|
+
maxAttempts: 3,
|
|
61
|
+
initialDelay: 100,
|
|
62
|
+
onRetry: (attempt, error) => {
|
|
63
|
+
logger.warn(`Retrying project save (attempt ${attempt})`, {
|
|
64
|
+
projectId: project.id,
|
|
65
|
+
error: error instanceof Error ? error.message : String(error),
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
this.projectCache.set(path, project);
|
|
70
|
+
this.currentProject = project;
|
|
71
|
+
logger.info('Project auto-detected', {
|
|
72
|
+
id: project.id,
|
|
73
|
+
org: project.organization,
|
|
74
|
+
type: project.accountType,
|
|
75
|
+
});
|
|
76
|
+
return project;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const wrappedError = errorHandler(error, {
|
|
80
|
+
projectPath: path,
|
|
81
|
+
operation: 'detectProject',
|
|
82
|
+
});
|
|
83
|
+
throw new ProjectError(`Failed to detect project at path: ${path}`, ErrorCode.PROJECT_INVALID_PATH, {
|
|
84
|
+
projectPath: path,
|
|
85
|
+
operation: 'detectProject',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Analyze project directory
|
|
91
|
+
*/
|
|
92
|
+
async analyzeProject(projectPath) {
|
|
93
|
+
const gitInfo = this.getGitInfo(projectPath);
|
|
94
|
+
const projectName = gitInfo.name || basename(projectPath);
|
|
95
|
+
return {
|
|
96
|
+
id: this.generateProjectId(gitInfo.remote || projectPath),
|
|
97
|
+
name: projectName,
|
|
98
|
+
path: projectPath,
|
|
99
|
+
gitRemote: gitInfo.remote,
|
|
100
|
+
organization: undefined,
|
|
101
|
+
accountType: 'personal',
|
|
102
|
+
isPrivate: false,
|
|
103
|
+
lastAccessed: new Date(),
|
|
104
|
+
metadata: {
|
|
105
|
+
branch: gitInfo.branch,
|
|
106
|
+
lastCommit: gitInfo.lastCommit,
|
|
107
|
+
isDirty: gitInfo.isDirty,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Extract Git information
|
|
113
|
+
*/
|
|
114
|
+
getGitInfo(projectPath) {
|
|
115
|
+
const info = {};
|
|
116
|
+
const errorHandler = createErrorHandler({
|
|
117
|
+
operation: 'getGitInfo',
|
|
118
|
+
projectPath,
|
|
119
|
+
});
|
|
120
|
+
try {
|
|
121
|
+
// Get remote origin
|
|
122
|
+
info.remote = execSync('git config --get remote.origin.url', {
|
|
123
|
+
cwd: projectPath,
|
|
124
|
+
encoding: 'utf-8',
|
|
125
|
+
timeout: 5000, // 5 second timeout
|
|
126
|
+
}).trim();
|
|
127
|
+
// Get current branch
|
|
128
|
+
info.branch = execSync('git branch --show-current', {
|
|
129
|
+
cwd: projectPath,
|
|
130
|
+
encoding: 'utf-8',
|
|
131
|
+
timeout: 5000,
|
|
132
|
+
}).trim();
|
|
133
|
+
// Get last commit
|
|
134
|
+
info.lastCommit = execSync('git log -1 --format=%H', {
|
|
135
|
+
cwd: projectPath,
|
|
136
|
+
encoding: 'utf-8',
|
|
137
|
+
timeout: 5000,
|
|
138
|
+
}).trim();
|
|
139
|
+
// Check if working tree is dirty
|
|
140
|
+
const status = execSync('git status --porcelain', {
|
|
141
|
+
cwd: projectPath,
|
|
142
|
+
encoding: 'utf-8',
|
|
143
|
+
timeout: 5000,
|
|
144
|
+
});
|
|
145
|
+
info.isDirty = status.length > 0;
|
|
146
|
+
// Extract project name from remote
|
|
147
|
+
const match = info.remote.match(/\/([^\/]+?)(\.git)?$/);
|
|
148
|
+
info.name = match ? match[1] : basename(projectPath);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
// Not a git repository or git not available
|
|
152
|
+
logger.debug('Git info extraction failed, using directory name', {
|
|
153
|
+
projectPath,
|
|
154
|
+
error: error instanceof Error ? error.message : String(error),
|
|
155
|
+
});
|
|
156
|
+
info.name = basename(projectPath);
|
|
157
|
+
}
|
|
158
|
+
return info;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Extract organization from Git remote
|
|
162
|
+
*/
|
|
163
|
+
extractOrganization(gitRemote) {
|
|
164
|
+
// GitHub: git@github.com:org/repo.git or https://github.com/org/repo
|
|
165
|
+
const githubMatch = gitRemote.match(/github\.com[:/]([^/]+)\//);
|
|
166
|
+
if (githubMatch)
|
|
167
|
+
return githubMatch[1];
|
|
168
|
+
// GitLab: git@gitlab.com:org/repo.git
|
|
169
|
+
const gitlabMatch = gitRemote.match(/gitlab\.com[:/]([^/]+)\//);
|
|
170
|
+
if (gitlabMatch)
|
|
171
|
+
return gitlabMatch[1];
|
|
172
|
+
// Bitbucket: git@bitbucket.org:org/repo.git
|
|
173
|
+
const bitbucketMatch = gitRemote.match(/bitbucket\.org[:/]([^/]+)\//);
|
|
174
|
+
if (bitbucketMatch)
|
|
175
|
+
return bitbucketMatch[1];
|
|
176
|
+
// Custom domain: git@git.company.com:team/repo.git
|
|
177
|
+
const customMatch = gitRemote.match(/@([^:]+)[:/]([^/]+)\//);
|
|
178
|
+
if (customMatch)
|
|
179
|
+
return customMatch[2];
|
|
180
|
+
return 'unknown';
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Determine account type based on patterns
|
|
184
|
+
*/
|
|
185
|
+
determineAccountType(gitRemote, organization) {
|
|
186
|
+
// Check against known organizations
|
|
187
|
+
for (const [, org] of this.organizations) {
|
|
188
|
+
if (org.githubOrgs.includes(organization || '')) {
|
|
189
|
+
return org.accountType;
|
|
190
|
+
}
|
|
191
|
+
// Check if remote matches any known domain
|
|
192
|
+
for (const domain of org.domains) {
|
|
193
|
+
if (gitRemote.includes(domain)) {
|
|
194
|
+
return org.accountType;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Auto-detection heuristics
|
|
199
|
+
if (organization) {
|
|
200
|
+
// Common work patterns
|
|
201
|
+
if (organization.includes('corp') ||
|
|
202
|
+
organization.includes('company') ||
|
|
203
|
+
organization.includes('team') ||
|
|
204
|
+
organization.includes('work')) {
|
|
205
|
+
return 'work';
|
|
206
|
+
}
|
|
207
|
+
// Common opensource patterns
|
|
208
|
+
if (organization.includes('apache') ||
|
|
209
|
+
organization.includes('mozilla') ||
|
|
210
|
+
organization.includes('foundation') ||
|
|
211
|
+
gitRemote.includes('gitlab.freedesktop')) {
|
|
212
|
+
return 'opensource';
|
|
213
|
+
}
|
|
214
|
+
// Check if it's the user's own org
|
|
215
|
+
const username = this.getCurrentGitUser();
|
|
216
|
+
if (username && organization.toLowerCase() === username.toLowerCase()) {
|
|
217
|
+
return 'personal';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Check if it's a private repo (likely work or personal)
|
|
221
|
+
if (this.isPrivateRepo(gitRemote)) {
|
|
222
|
+
// Use additional heuristics
|
|
223
|
+
const currentPath = process.cwd();
|
|
224
|
+
if (currentPath.includes('/work/') ||
|
|
225
|
+
currentPath.includes('/Work/') ||
|
|
226
|
+
currentPath.includes('/company/') ||
|
|
227
|
+
currentPath.includes('/job/')) {
|
|
228
|
+
return 'work';
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return 'personal';
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Check if repository is private
|
|
235
|
+
*/
|
|
236
|
+
isPrivateRepo(gitRemote) {
|
|
237
|
+
// SSH URLs are typically private
|
|
238
|
+
if (gitRemote.startsWith('git@')) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
// HTTPS with credentials
|
|
242
|
+
if (gitRemote.includes('@')) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
// Try to check GitHub API (requires authentication for private repos)
|
|
246
|
+
// This is a simplified check
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Detect primary programming language
|
|
251
|
+
*/
|
|
252
|
+
detectPrimaryLanguage(projectPath) {
|
|
253
|
+
const checks = [
|
|
254
|
+
{ file: 'package.json', language: 'JavaScript/TypeScript' },
|
|
255
|
+
{ file: 'Cargo.toml', language: 'Rust' },
|
|
256
|
+
{ file: 'go.mod', language: 'Go' },
|
|
257
|
+
{ file: 'pom.xml', language: 'Java' },
|
|
258
|
+
{ file: 'requirements.txt', language: 'Python' },
|
|
259
|
+
{ file: 'Gemfile', language: 'Ruby' },
|
|
260
|
+
{ file: 'composer.json', language: 'PHP' },
|
|
261
|
+
{ file: '*.csproj', language: 'C#' },
|
|
262
|
+
{ file: 'Podfile', language: 'Swift/Objective-C' },
|
|
263
|
+
];
|
|
264
|
+
for (const check of checks) {
|
|
265
|
+
if (check.file.includes('*')) {
|
|
266
|
+
// Glob pattern
|
|
267
|
+
try {
|
|
268
|
+
const files = execSync(`find ${projectPath} -maxdepth 2 -name "${check.file}" 2>/dev/null`, {
|
|
269
|
+
encoding: 'utf-8',
|
|
270
|
+
});
|
|
271
|
+
if (files.trim())
|
|
272
|
+
return check.language;
|
|
273
|
+
}
|
|
274
|
+
catch { }
|
|
275
|
+
}
|
|
276
|
+
else if (existsSync(join(projectPath, check.file))) {
|
|
277
|
+
return check.language;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Detect framework
|
|
284
|
+
*/
|
|
285
|
+
detectFramework(projectPath) {
|
|
286
|
+
const packageJsonPath = join(projectPath, 'package.json');
|
|
287
|
+
if (existsSync(packageJsonPath)) {
|
|
288
|
+
try {
|
|
289
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
290
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
291
|
+
// Check for common frameworks
|
|
292
|
+
if (deps['next'])
|
|
293
|
+
return 'Next.js';
|
|
294
|
+
if (deps['react'])
|
|
295
|
+
return 'React';
|
|
296
|
+
if (deps['vue'])
|
|
297
|
+
return 'Vue';
|
|
298
|
+
if (deps['@angular/core'])
|
|
299
|
+
return 'Angular';
|
|
300
|
+
if (deps['express'])
|
|
301
|
+
return 'Express';
|
|
302
|
+
if (deps['fastify'])
|
|
303
|
+
return 'Fastify';
|
|
304
|
+
if (deps['@nestjs/core'])
|
|
305
|
+
return 'NestJS';
|
|
306
|
+
}
|
|
307
|
+
catch { }
|
|
308
|
+
}
|
|
309
|
+
// Check for other framework indicators
|
|
310
|
+
if (existsSync(join(projectPath, 'Cargo.toml'))) {
|
|
311
|
+
const cargo = readFileSync(join(projectPath, 'Cargo.toml'), 'utf-8');
|
|
312
|
+
if (cargo.includes('actix-web'))
|
|
313
|
+
return 'Actix';
|
|
314
|
+
if (cargo.includes('rocket'))
|
|
315
|
+
return 'Rocket';
|
|
316
|
+
}
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get current Git user
|
|
321
|
+
*/
|
|
322
|
+
getCurrentGitUser() {
|
|
323
|
+
try {
|
|
324
|
+
const email = execSync('git config --global user.email', {
|
|
325
|
+
encoding: 'utf-8',
|
|
326
|
+
}).trim();
|
|
327
|
+
const username = email.split('@')[0];
|
|
328
|
+
return username;
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Generate unique project ID
|
|
336
|
+
*/
|
|
337
|
+
generateProjectId(identifier) {
|
|
338
|
+
// Create a stable ID from the git remote or path
|
|
339
|
+
const cleaned = identifier
|
|
340
|
+
.replace(/\.git$/, '')
|
|
341
|
+
.replace(/[^a-zA-Z0-9-]/g, '-')
|
|
342
|
+
.toLowerCase();
|
|
343
|
+
return cleaned.substring(cleaned.length - 50); // Last 50 chars
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Initialize database
|
|
347
|
+
*/
|
|
348
|
+
initializeDatabase() {
|
|
349
|
+
const dbPath = join(this.configPath, 'projects.db');
|
|
350
|
+
const errorHandler = createErrorHandler({
|
|
351
|
+
operation: 'initializeDatabase',
|
|
352
|
+
dbPath,
|
|
353
|
+
});
|
|
354
|
+
try {
|
|
355
|
+
this.db = new Database(dbPath);
|
|
356
|
+
this.db.exec(`
|
|
357
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
358
|
+
id TEXT PRIMARY KEY,
|
|
359
|
+
name TEXT NOT NULL,
|
|
360
|
+
path TEXT NOT NULL UNIQUE,
|
|
361
|
+
git_remote TEXT,
|
|
362
|
+
organization TEXT,
|
|
363
|
+
account_type TEXT,
|
|
364
|
+
is_private BOOLEAN,
|
|
365
|
+
primary_language TEXT,
|
|
366
|
+
framework TEXT,
|
|
367
|
+
last_accessed DATETIME,
|
|
368
|
+
metadata JSON,
|
|
369
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
370
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
CREATE TABLE IF NOT EXISTS organizations (
|
|
374
|
+
name TEXT PRIMARY KEY,
|
|
375
|
+
type TEXT,
|
|
376
|
+
account_type TEXT,
|
|
377
|
+
config JSON,
|
|
378
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
CREATE TABLE IF NOT EXISTS project_contexts (
|
|
382
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
383
|
+
project_id TEXT NOT NULL,
|
|
384
|
+
context_type TEXT,
|
|
385
|
+
content TEXT,
|
|
386
|
+
metadata JSON,
|
|
387
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
388
|
+
FOREIGN KEY (project_id) REFERENCES projects(id)
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
CREATE INDEX IF NOT EXISTS idx_projects_org ON projects(organization);
|
|
392
|
+
CREATE INDEX IF NOT EXISTS idx_projects_type ON projects(account_type);
|
|
393
|
+
CREATE INDEX IF NOT EXISTS idx_contexts_project ON project_contexts(project_id);
|
|
394
|
+
`);
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
const dbError = errorHandler(error, {
|
|
398
|
+
dbPath,
|
|
399
|
+
operation: 'initializeDatabase',
|
|
400
|
+
});
|
|
401
|
+
throw new DatabaseError('Failed to initialize projects database', ErrorCode.DB_MIGRATION_FAILED, {
|
|
402
|
+
dbPath,
|
|
403
|
+
configPath: this.configPath,
|
|
404
|
+
operation: 'initializeDatabase',
|
|
405
|
+
}, error instanceof Error ? error : undefined);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Save project to database
|
|
410
|
+
*/
|
|
411
|
+
saveProject(project) {
|
|
412
|
+
try {
|
|
413
|
+
const stmt = this.db.prepare(`
|
|
414
|
+
INSERT OR REPLACE INTO projects
|
|
415
|
+
(id, name, path, git_remote, organization, account_type, is_private,
|
|
416
|
+
primary_language, framework, last_accessed, metadata, updated_at)
|
|
417
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
|
418
|
+
`);
|
|
419
|
+
stmt.run(project.id, project.name, project.path, project.gitRemote, project.organization, project.accountType, project.isPrivate ? 1 : 0, project.primaryLanguage, project.framework, project.lastAccessed.toISOString(), JSON.stringify(project.metadata));
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
throw new DatabaseError(`Failed to save project: ${project.name}`, ErrorCode.DB_QUERY_FAILED, {
|
|
423
|
+
projectId: project.id,
|
|
424
|
+
projectName: project.name,
|
|
425
|
+
projectPath: project.path,
|
|
426
|
+
operation: 'saveProject',
|
|
427
|
+
}, error instanceof Error ? error : undefined);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Load organizations configuration
|
|
432
|
+
*/
|
|
433
|
+
loadOrganizations() {
|
|
434
|
+
const configFile = join(this.configPath, 'organizations.json');
|
|
435
|
+
if (existsSync(configFile)) {
|
|
436
|
+
try {
|
|
437
|
+
const config = JSON.parse(readFileSync(configFile, 'utf-8'));
|
|
438
|
+
for (const org of config.organizations || []) {
|
|
439
|
+
this.organizations.set(org.name, org);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
logger.error('Failed to load organizations config', error instanceof Error ? error : undefined);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Auto-discover organizations from existing projects
|
|
449
|
+
*/
|
|
450
|
+
autoDiscoverOrganizations() {
|
|
451
|
+
const errorHandler = createErrorHandler({
|
|
452
|
+
operation: 'autoDiscoverOrganizations',
|
|
453
|
+
});
|
|
454
|
+
try {
|
|
455
|
+
const stmt = this.db.prepare(`
|
|
456
|
+
SELECT DISTINCT organization, account_type, COUNT(*) as project_count
|
|
457
|
+
FROM projects
|
|
458
|
+
WHERE organization IS NOT NULL
|
|
459
|
+
GROUP BY organization, account_type
|
|
460
|
+
`);
|
|
461
|
+
const orgs = stmt.all();
|
|
462
|
+
for (const org of orgs) {
|
|
463
|
+
if (!this.organizations.has(org.organization)) {
|
|
464
|
+
// Auto-create organization config
|
|
465
|
+
this.organizations.set(org.organization, {
|
|
466
|
+
name: org.organization,
|
|
467
|
+
type: org.account_type === 'work' ? 'company' : 'personal',
|
|
468
|
+
domains: [],
|
|
469
|
+
githubOrgs: [org.organization],
|
|
470
|
+
accountType: org.account_type,
|
|
471
|
+
autoPatterns: [],
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
catch (error) {
|
|
477
|
+
const wrappedError = errorHandler(error, {
|
|
478
|
+
operation: 'autoDiscoverOrganizations',
|
|
479
|
+
});
|
|
480
|
+
logger.error('Failed to auto-discover organizations', error instanceof Error ? error : new Error(String(error)), {
|
|
481
|
+
operation: 'autoDiscoverOrganizations',
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Ensure directory structure exists
|
|
487
|
+
*/
|
|
488
|
+
ensureDirectoryStructure() {
|
|
489
|
+
const dirs = [
|
|
490
|
+
this.configPath,
|
|
491
|
+
join(this.configPath, 'accounts'),
|
|
492
|
+
join(this.configPath, 'accounts', 'personal'),
|
|
493
|
+
join(this.configPath, 'accounts', 'work'),
|
|
494
|
+
join(this.configPath, 'accounts', 'opensource'),
|
|
495
|
+
join(this.configPath, 'accounts', 'client'),
|
|
496
|
+
join(this.configPath, 'contexts'),
|
|
497
|
+
join(this.configPath, 'patterns'),
|
|
498
|
+
];
|
|
499
|
+
for (const dir of dirs) {
|
|
500
|
+
if (!existsSync(dir)) {
|
|
501
|
+
mkdirSync(dir, { recursive: true });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Check if cache is still valid
|
|
507
|
+
*/
|
|
508
|
+
isCacheValid(project) {
|
|
509
|
+
const cacheAge = Date.now() - project.lastAccessed.getTime();
|
|
510
|
+
return cacheAge < 5 * 60 * 1000; // 5 minutes
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Get all projects
|
|
514
|
+
*/
|
|
515
|
+
getAllProjects() {
|
|
516
|
+
try {
|
|
517
|
+
const stmt = this.db.prepare(`
|
|
518
|
+
SELECT * FROM projects
|
|
519
|
+
ORDER BY last_accessed DESC
|
|
520
|
+
`);
|
|
521
|
+
const projects = stmt.all();
|
|
522
|
+
return projects.map((p) => ({
|
|
523
|
+
...p,
|
|
524
|
+
isPrivate: p.is_private === 1,
|
|
525
|
+
lastAccessed: new Date(p.last_accessed),
|
|
526
|
+
metadata: JSON.parse(p.metadata || '{}'),
|
|
527
|
+
}));
|
|
528
|
+
}
|
|
529
|
+
catch (error) {
|
|
530
|
+
throw new DatabaseError('Failed to get all projects', ErrorCode.DB_QUERY_FAILED, {
|
|
531
|
+
operation: 'getAllProjects',
|
|
532
|
+
}, error instanceof Error ? error : undefined);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Get projects by organization
|
|
537
|
+
*/
|
|
538
|
+
getProjectsByOrganization(organization) {
|
|
539
|
+
try {
|
|
540
|
+
const stmt = this.db.prepare(`
|
|
541
|
+
SELECT * FROM projects
|
|
542
|
+
WHERE organization = ?
|
|
543
|
+
ORDER BY last_accessed DESC
|
|
544
|
+
`);
|
|
545
|
+
const projects = stmt.all(organization);
|
|
546
|
+
return projects.map((p) => ({
|
|
547
|
+
...p,
|
|
548
|
+
isPrivate: p.is_private === 1,
|
|
549
|
+
lastAccessed: new Date(p.last_accessed),
|
|
550
|
+
metadata: JSON.parse(p.metadata || '{}'),
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
catch (error) {
|
|
554
|
+
throw new DatabaseError(`Failed to get projects by organization: ${organization}`, ErrorCode.DB_QUERY_FAILED, {
|
|
555
|
+
organization,
|
|
556
|
+
operation: 'getProjectsByOrganization',
|
|
557
|
+
}, error instanceof Error ? error : undefined);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Get projects by account type
|
|
562
|
+
*/
|
|
563
|
+
getProjectsByAccountType(accountType) {
|
|
564
|
+
try {
|
|
565
|
+
const stmt = this.db.prepare(`
|
|
566
|
+
SELECT * FROM projects
|
|
567
|
+
WHERE account_type = ?
|
|
568
|
+
ORDER BY last_accessed DESC
|
|
569
|
+
`);
|
|
570
|
+
const projects = stmt.all(accountType);
|
|
571
|
+
return projects.map((p) => ({
|
|
572
|
+
...p,
|
|
573
|
+
isPrivate: p.is_private === 1,
|
|
574
|
+
lastAccessed: new Date(p.last_accessed),
|
|
575
|
+
metadata: JSON.parse(p.metadata || '{}'),
|
|
576
|
+
}));
|
|
577
|
+
}
|
|
578
|
+
catch (error) {
|
|
579
|
+
throw new DatabaseError(`Failed to get projects by account type: ${accountType}`, ErrorCode.DB_QUERY_FAILED, {
|
|
580
|
+
accountType,
|
|
581
|
+
operation: 'getProjectsByAccountType',
|
|
582
|
+
}, error instanceof Error ? error : undefined);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Get current project
|
|
587
|
+
*/
|
|
588
|
+
getCurrentProject() {
|
|
589
|
+
if (!this.currentProject) {
|
|
590
|
+
this.detectProject();
|
|
591
|
+
}
|
|
592
|
+
return this.currentProject;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Save organization config
|
|
596
|
+
*/
|
|
597
|
+
saveOrganization(org) {
|
|
598
|
+
const errorHandler = createErrorHandler({
|
|
599
|
+
operation: 'saveOrganization',
|
|
600
|
+
orgName: org.name,
|
|
601
|
+
});
|
|
602
|
+
try {
|
|
603
|
+
this.organizations.set(org.name, org);
|
|
604
|
+
// Save to file
|
|
605
|
+
const configFile = join(this.configPath, 'organizations.json');
|
|
606
|
+
const config = {
|
|
607
|
+
organizations: Array.from(this.organizations.values()),
|
|
608
|
+
};
|
|
609
|
+
writeFileSync(configFile, JSON.stringify(config, null, 2));
|
|
610
|
+
// Save to database
|
|
611
|
+
const stmt = this.db.prepare(`
|
|
612
|
+
INSERT OR REPLACE INTO organizations (name, type, account_type, config)
|
|
613
|
+
VALUES (?, ?, ?, ?)
|
|
614
|
+
`);
|
|
615
|
+
stmt.run(org.name, org.type, org.accountType, JSON.stringify(org));
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
const wrappedError = errorHandler(error, {
|
|
619
|
+
orgName: org.name,
|
|
620
|
+
operation: 'saveOrganization',
|
|
621
|
+
});
|
|
622
|
+
throw new DatabaseError(`Failed to save organization: ${org.name}`, ErrorCode.DB_QUERY_FAILED, {
|
|
623
|
+
orgName: org.name,
|
|
624
|
+
operation: 'saveOrganization',
|
|
625
|
+
}, error instanceof Error ? error : undefined);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Auto-categorize all Git repositories in home directory
|
|
630
|
+
*/
|
|
631
|
+
async scanAndCategorizeAllProjects(basePaths) {
|
|
632
|
+
const paths = basePaths || [
|
|
633
|
+
join(homedir(), 'Dev'),
|
|
634
|
+
join(homedir(), 'dev'),
|
|
635
|
+
join(homedir(), 'Projects'),
|
|
636
|
+
join(homedir(), 'projects'),
|
|
637
|
+
join(homedir(), 'Work'),
|
|
638
|
+
join(homedir(), 'work'),
|
|
639
|
+
join(homedir(), 'Documents/GitHub'),
|
|
640
|
+
join(homedir(), 'code'),
|
|
641
|
+
];
|
|
642
|
+
logger.info('Scanning for Git repositories...');
|
|
643
|
+
for (const basePath of paths) {
|
|
644
|
+
if (!existsSync(basePath))
|
|
645
|
+
continue;
|
|
646
|
+
try {
|
|
647
|
+
// Find all .git directories with timeout
|
|
648
|
+
const gitDirs = execSync(`find ${basePath} -type d -name .git -maxdepth 4 2>/dev/null`, { encoding: 'utf-8', timeout: 30000 } // 30 second timeout
|
|
649
|
+
)
|
|
650
|
+
.trim()
|
|
651
|
+
.split('\n')
|
|
652
|
+
.filter(Boolean);
|
|
653
|
+
for (const gitDir of gitDirs) {
|
|
654
|
+
const projectPath = dirname(gitDir);
|
|
655
|
+
try {
|
|
656
|
+
await this.detectProject(projectPath);
|
|
657
|
+
logger.info(`Discovered project: ${projectPath}`);
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
logger.warn(`Failed to analyze project: ${projectPath}`, {
|
|
661
|
+
projectPath,
|
|
662
|
+
error: error instanceof Error ? error.message : String(error),
|
|
663
|
+
operation: 'scanAndCategorizeAllProjects',
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
logger.warn(`Failed to scan ${basePath}`, error instanceof Error ? { error } : undefined);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
logger.info(`Scan complete. Found ${this.projectCache.size} projects`);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Generate summary report
|
|
676
|
+
*/
|
|
677
|
+
generateReport() {
|
|
678
|
+
const allProjects = this.getAllProjects();
|
|
679
|
+
const report = {
|
|
680
|
+
total: allProjects.length,
|
|
681
|
+
byAccountType: {},
|
|
682
|
+
byOrganization: {},
|
|
683
|
+
byLanguage: {},
|
|
684
|
+
byFramework: {},
|
|
685
|
+
};
|
|
686
|
+
for (const project of allProjects) {
|
|
687
|
+
// Count by account type
|
|
688
|
+
report.byAccountType[project.accountType] =
|
|
689
|
+
(report.byAccountType[project.accountType] || 0) + 1;
|
|
690
|
+
// Count by organization
|
|
691
|
+
if (project.organization) {
|
|
692
|
+
report.byOrganization[project.organization] =
|
|
693
|
+
(report.byOrganization[project.organization] || 0) + 1;
|
|
694
|
+
}
|
|
695
|
+
// Count by language
|
|
696
|
+
if (project.primaryLanguage) {
|
|
697
|
+
report.byLanguage[project.primaryLanguage] =
|
|
698
|
+
(report.byLanguage[project.primaryLanguage] || 0) + 1;
|
|
699
|
+
}
|
|
700
|
+
// Count by framework
|
|
701
|
+
if (project.framework) {
|
|
702
|
+
report.byFramework[project.framework] =
|
|
703
|
+
(report.byFramework[project.framework] || 0) + 1;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return JSON.stringify(report, null, 2);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
//# sourceMappingURL=project-manager.js.map
|