create-universal-ai-context 2.0.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.
- package/LICENSE +21 -0
- package/README.md +171 -0
- package/bin/create-ai-context.js +337 -0
- package/lib/adapters/antigravity.js +160 -0
- package/lib/adapters/claude.js +122 -0
- package/lib/adapters/cline.js +111 -0
- package/lib/adapters/copilot.js +117 -0
- package/lib/adapters/index.js +69 -0
- package/lib/ai-context-generator.js +234 -0
- package/lib/ai-orchestrator.js +431 -0
- package/lib/call-tracer.js +444 -0
- package/lib/detector.js +726 -0
- package/lib/environment-detector.js +239 -0
- package/lib/index.js +310 -0
- package/lib/installer.js +418 -0
- package/lib/migrate.js +319 -0
- package/lib/placeholder.js +541 -0
- package/lib/prompts.js +287 -0
- package/lib/spinner.js +60 -0
- package/lib/static-analyzer.js +729 -0
- package/lib/template-populator.js +843 -0
- package/lib/template-renderer.js +382 -0
- package/lib/validate.js +155 -0
- package/package.json +70 -0
- package/templates/AI_CONTEXT.md.template +245 -0
- package/templates/base/README.md +257 -0
- package/templates/base/RPI_WORKFLOW_PLAN.md +320 -0
- package/templates/base/agents/api-developer.md +76 -0
- package/templates/base/agents/context-engineer.md +525 -0
- package/templates/base/agents/core-architect.md +76 -0
- package/templates/base/agents/database-ops.md +76 -0
- package/templates/base/agents/deployment-ops.md +76 -0
- package/templates/base/agents/integration-hub.md +76 -0
- package/templates/base/analytics/README.md +114 -0
- package/templates/base/automation/config.json +58 -0
- package/templates/base/automation/generators/code-mapper.js +308 -0
- package/templates/base/automation/generators/index-builder.js +321 -0
- package/templates/base/automation/hooks/post-commit.sh +83 -0
- package/templates/base/automation/hooks/pre-commit.sh +103 -0
- package/templates/base/ci-templates/README.md +108 -0
- package/templates/base/ci-templates/github-actions/context-check.yml +144 -0
- package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -0
- package/templates/base/commands/analytics.md +238 -0
- package/templates/base/commands/auto-sync.md +172 -0
- package/templates/base/commands/collab.md +194 -0
- package/templates/base/commands/help.md +450 -0
- package/templates/base/commands/rpi-implement.md +115 -0
- package/templates/base/commands/rpi-plan.md +93 -0
- package/templates/base/commands/rpi-research.md +88 -0
- package/templates/base/commands/session-resume.md +144 -0
- package/templates/base/commands/session-save.md +112 -0
- package/templates/base/commands/validate-all.md +77 -0
- package/templates/base/commands/verify-docs-current.md +86 -0
- package/templates/base/config/base.json +57 -0
- package/templates/base/config/environments/development.json +13 -0
- package/templates/base/config/environments/production.json +17 -0
- package/templates/base/config/environments/staging.json +13 -0
- package/templates/base/config/local.json.example +21 -0
- package/templates/base/context/.meta/generated-at.json +18 -0
- package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -0
- package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -0
- package/templates/base/context/FILE_OWNERSHIP.md +57 -0
- package/templates/base/context/INTEGRATION_POINTS.md +92 -0
- package/templates/base/context/KNOWN_GOTCHAS.md +195 -0
- package/templates/base/context/TESTING_MAP.md +95 -0
- package/templates/base/context/WORKFLOW_INDEX.md +129 -0
- package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -0
- package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -0
- package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -0
- package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -0
- package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -0
- package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -0
- package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -0
- package/templates/base/knowledge/README.md +98 -0
- package/templates/base/knowledge/sessions/README.md +88 -0
- package/templates/base/knowledge/sessions/TEMPLATE.md +150 -0
- package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -0
- package/templates/base/knowledge/shared/decisions/README.md +49 -0
- package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -0
- package/templates/base/knowledge/shared/patterns/README.md +62 -0
- package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -0
- package/templates/base/plans/PLAN_TEMPLATE.md +250 -0
- package/templates/base/plans/active/.gitkeep +0 -0
- package/templates/base/plans/completed/.gitkeep +0 -0
- package/templates/base/research/RESEARCH_TEMPLATE.md +153 -0
- package/templates/base/research/active/.gitkeep +0 -0
- package/templates/base/research/completed/.gitkeep +0 -0
- package/templates/base/schemas/agent.schema.json +141 -0
- package/templates/base/schemas/anchors.schema.json +54 -0
- package/templates/base/schemas/automation.schema.json +93 -0
- package/templates/base/schemas/command.schema.json +134 -0
- package/templates/base/schemas/hashes.schema.json +40 -0
- package/templates/base/schemas/manifest.schema.json +117 -0
- package/templates/base/schemas/plan.schema.json +136 -0
- package/templates/base/schemas/research.schema.json +115 -0
- package/templates/base/schemas/roles.schema.json +34 -0
- package/templates/base/schemas/session.schema.json +77 -0
- package/templates/base/schemas/settings.schema.json +244 -0
- package/templates/base/schemas/staleness.schema.json +53 -0
- package/templates/base/schemas/team-config.schema.json +42 -0
- package/templates/base/schemas/workflow.schema.json +126 -0
- package/templates/base/session/checkpoints/.gitkeep +2 -0
- package/templates/base/session/current/state.json +20 -0
- package/templates/base/session/history/.gitkeep +2 -0
- package/templates/base/settings.json +3 -0
- package/templates/base/standards/COMPATIBILITY.md +219 -0
- package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -0
- package/templates/base/standards/QUALITY_CHECKLIST.md +211 -0
- package/templates/base/standards/README.md +66 -0
- package/templates/base/sync/anchors.json +6 -0
- package/templates/base/sync/hashes.json +6 -0
- package/templates/base/sync/staleness.json +10 -0
- package/templates/base/team/README.md +168 -0
- package/templates/base/team/config.json +79 -0
- package/templates/base/team/roles.json +145 -0
- package/templates/base/tools/bin/claude-context.js +151 -0
- package/templates/base/tools/lib/anchor-resolver.js +276 -0
- package/templates/base/tools/lib/config-loader.js +363 -0
- package/templates/base/tools/lib/detector.js +350 -0
- package/templates/base/tools/lib/diagnose.js +206 -0
- package/templates/base/tools/lib/drift-detector.js +373 -0
- package/templates/base/tools/lib/errors.js +199 -0
- package/templates/base/tools/lib/index.js +36 -0
- package/templates/base/tools/lib/init.js +192 -0
- package/templates/base/tools/lib/logger.js +230 -0
- package/templates/base/tools/lib/placeholder.js +201 -0
- package/templates/base/tools/lib/session-manager.js +354 -0
- package/templates/base/tools/lib/validate.js +521 -0
- package/templates/base/tools/package.json +49 -0
- package/templates/handlebars/antigravity.hbs +337 -0
- package/templates/handlebars/claude.hbs +184 -0
- package/templates/handlebars/cline.hbs +63 -0
- package/templates/handlebars/copilot.hbs +131 -0
- package/templates/handlebars/partials/gotcha-list.hbs +11 -0
- package/templates/handlebars/partials/header.hbs +3 -0
- package/templates/handlebars/partials/workflow-summary.hbs +16 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Context Engineering - Environment Detector
|
|
3
|
+
*
|
|
4
|
+
* Detects execution context to determine analysis mode:
|
|
5
|
+
* - full-ai: Running inside Claude Code with API access
|
|
6
|
+
* - hybrid: Running inside Claude Code without direct API access
|
|
7
|
+
* - standalone: Running via npx without Claude Code
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const os = require('os');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Environment indicators for Claude Code detection
|
|
16
|
+
*/
|
|
17
|
+
const CLAUDE_INDICATORS = {
|
|
18
|
+
// Environment variables set by Claude Code
|
|
19
|
+
envVars: [
|
|
20
|
+
'CLAUDE_CODE_SESSION',
|
|
21
|
+
'CLAUDE_SESSION_ID',
|
|
22
|
+
'CLAUDE_AGENT_ID',
|
|
23
|
+
'ANTHROPIC_API_KEY',
|
|
24
|
+
'CLAUDE_API_KEY'
|
|
25
|
+
],
|
|
26
|
+
|
|
27
|
+
// Directories that indicate Claude Code presence
|
|
28
|
+
directories: [
|
|
29
|
+
path.join(os.homedir(), '.claude'),
|
|
30
|
+
path.join(os.homedir(), '.claude-code'),
|
|
31
|
+
path.join(os.homedir(), '.config', 'claude-code')
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
// Files that indicate active Claude Code session
|
|
35
|
+
sessionFiles: [
|
|
36
|
+
'.claude-session',
|
|
37
|
+
'.claude-code-session'
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Capability definitions by mode
|
|
43
|
+
*/
|
|
44
|
+
const CAPABILITIES = {
|
|
45
|
+
'full-ai': [
|
|
46
|
+
'workflow-discovery',
|
|
47
|
+
'call-tracing',
|
|
48
|
+
'semantic-analysis',
|
|
49
|
+
'architecture-understanding',
|
|
50
|
+
'smart-documentation'
|
|
51
|
+
],
|
|
52
|
+
'hybrid': [
|
|
53
|
+
'workflow-discovery',
|
|
54
|
+
'basic-analysis',
|
|
55
|
+
'pattern-matching'
|
|
56
|
+
],
|
|
57
|
+
'standalone': [
|
|
58
|
+
'static-analysis',
|
|
59
|
+
'pattern-matching',
|
|
60
|
+
'structure-mapping'
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Detect if running inside a Claude Code session
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
function isClaudeCodeSession() {
|
|
69
|
+
// Check environment variables
|
|
70
|
+
for (const envVar of CLAUDE_INDICATORS.envVars) {
|
|
71
|
+
if (process.env[envVar]) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Check for Claude directories
|
|
77
|
+
for (const dir of CLAUDE_INDICATORS.directories) {
|
|
78
|
+
if (fs.existsSync(dir)) {
|
|
79
|
+
// Directory exists, check for recent session markers
|
|
80
|
+
const sessionMarker = path.join(dir, 'session', 'current', 'state.json');
|
|
81
|
+
if (fs.existsSync(sessionMarker)) {
|
|
82
|
+
try {
|
|
83
|
+
const state = JSON.parse(fs.readFileSync(sessionMarker, 'utf-8'));
|
|
84
|
+
// Check if session is recent (within last 24 hours)
|
|
85
|
+
if (state.startedAt) {
|
|
86
|
+
const sessionStart = new Date(state.startedAt);
|
|
87
|
+
const hoursSinceStart = (Date.now() - sessionStart.getTime()) / (1000 * 60 * 60);
|
|
88
|
+
if (hoursSinceStart < 24) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
// Ignore parse errors
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Even without active session, presence of .claude indicates CLI usage
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Check for session files in current directory
|
|
102
|
+
for (const sessionFile of CLAUDE_INDICATORS.sessionFiles) {
|
|
103
|
+
if (fs.existsSync(path.join(process.cwd(), sessionFile))) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Check if we're in a TTY with Claude Code characteristics
|
|
109
|
+
if (process.stdout.isTTY) {
|
|
110
|
+
// Check for VS Code terminal (common Claude Code environment)
|
|
111
|
+
if (process.env.TERM_PROGRAM === 'vscode') {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Check for Claude Code specific terminal markers
|
|
116
|
+
if (process.env.CLAUDE_CODE_TERMINAL === 'true') {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Check if API access is available
|
|
126
|
+
* @returns {boolean}
|
|
127
|
+
*/
|
|
128
|
+
function hasApiAccess() {
|
|
129
|
+
return !!(
|
|
130
|
+
process.env.ANTHROPIC_API_KEY ||
|
|
131
|
+
process.env.CLAUDE_API_KEY ||
|
|
132
|
+
process.env.CLAUDE_CODE_API_ACCESS === 'true'
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Detect the current execution environment
|
|
138
|
+
* @returns {{mode: string, isClaudeCode: boolean, hasApiAccess: boolean, capabilities: string[], indicators: string[]}}
|
|
139
|
+
*/
|
|
140
|
+
function detectEnvironment() {
|
|
141
|
+
const result = {
|
|
142
|
+
isClaudeCode: false,
|
|
143
|
+
hasApiAccess: false,
|
|
144
|
+
mode: 'standalone',
|
|
145
|
+
capabilities: [],
|
|
146
|
+
indicators: []
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Check for Claude Code session
|
|
150
|
+
result.isClaudeCode = isClaudeCodeSession();
|
|
151
|
+
|
|
152
|
+
// Check for API access
|
|
153
|
+
result.hasApiAccess = hasApiAccess();
|
|
154
|
+
|
|
155
|
+
// Collect detected indicators for debugging
|
|
156
|
+
for (const envVar of CLAUDE_INDICATORS.envVars) {
|
|
157
|
+
if (process.env[envVar]) {
|
|
158
|
+
result.indicators.push(`env:${envVar}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const dir of CLAUDE_INDICATORS.directories) {
|
|
162
|
+
if (fs.existsSync(dir)) {
|
|
163
|
+
result.indicators.push(`dir:${path.basename(dir)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Determine mode based on detection
|
|
168
|
+
if (result.isClaudeCode && result.hasApiAccess) {
|
|
169
|
+
result.mode = 'full-ai';
|
|
170
|
+
} else if (result.isClaudeCode) {
|
|
171
|
+
result.mode = 'hybrid';
|
|
172
|
+
} else {
|
|
173
|
+
result.mode = 'standalone';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Assign capabilities based on mode
|
|
177
|
+
result.capabilities = CAPABILITIES[result.mode] || CAPABILITIES.standalone;
|
|
178
|
+
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get a human-readable description of the environment
|
|
184
|
+
* @param {object} env - Environment detection result
|
|
185
|
+
* @returns {string}
|
|
186
|
+
*/
|
|
187
|
+
function getEnvironmentDescription(env) {
|
|
188
|
+
switch (env.mode) {
|
|
189
|
+
case 'full-ai':
|
|
190
|
+
return 'Claude Code session with AI analysis enabled';
|
|
191
|
+
case 'hybrid':
|
|
192
|
+
return 'Claude Code session (AI analysis available on next run)';
|
|
193
|
+
case 'standalone':
|
|
194
|
+
return 'Standalone mode (static analysis only)';
|
|
195
|
+
default:
|
|
196
|
+
return 'Unknown environment';
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check if a specific capability is available
|
|
202
|
+
* @param {object} env - Environment detection result
|
|
203
|
+
* @param {string} capability - Capability to check
|
|
204
|
+
* @returns {boolean}
|
|
205
|
+
*/
|
|
206
|
+
function hasCapability(env, capability) {
|
|
207
|
+
return env.capabilities.includes(capability);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Force a specific mode (for testing or CLI override)
|
|
212
|
+
* @param {string} mode - Mode to force ('full-ai', 'hybrid', 'standalone')
|
|
213
|
+
* @returns {object} Environment result with forced mode
|
|
214
|
+
*/
|
|
215
|
+
function forceMode(mode) {
|
|
216
|
+
if (!CAPABILITIES[mode]) {
|
|
217
|
+
throw new Error(`Invalid mode: ${mode}. Valid modes: ${Object.keys(CAPABILITIES).join(', ')}`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
isClaudeCode: mode !== 'standalone',
|
|
222
|
+
hasApiAccess: mode === 'full-ai',
|
|
223
|
+
mode,
|
|
224
|
+
capabilities: CAPABILITIES[mode],
|
|
225
|
+
indicators: [`forced:${mode}`],
|
|
226
|
+
forced: true
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module.exports = {
|
|
231
|
+
detectEnvironment,
|
|
232
|
+
isClaudeCodeSession,
|
|
233
|
+
hasApiAccess,
|
|
234
|
+
getEnvironmentDescription,
|
|
235
|
+
hasCapability,
|
|
236
|
+
forceMode,
|
|
237
|
+
CLAUDE_INDICATORS,
|
|
238
|
+
CAPABILITIES
|
|
239
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main orchestrator for create-ai-context
|
|
3
|
+
*
|
|
4
|
+
* Universal AI Context Engineering - supports Claude, Copilot, Cline, Antigravity.
|
|
5
|
+
*
|
|
6
|
+
* Handles the full installation flow:
|
|
7
|
+
* 1. Interactive prompts (or defaults)
|
|
8
|
+
* 2. Directory structure creation
|
|
9
|
+
* 3. Template copying
|
|
10
|
+
* 4. Environment detection (Claude Code or standalone)
|
|
11
|
+
* 5. Tech stack detection
|
|
12
|
+
* 6. Deep codebase analysis
|
|
13
|
+
* 7. Template population with real data
|
|
14
|
+
* 8. Placeholder replacement
|
|
15
|
+
* 9. AI orchestration (if in Claude Code)
|
|
16
|
+
* 10. Validation
|
|
17
|
+
* 11. Plugin installation (optional)
|
|
18
|
+
* 12. Git initialization (optional)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const chalk = require('chalk');
|
|
24
|
+
const { runPrompts, getDefaults } = require('./prompts');
|
|
25
|
+
const { createSpinner } = require('./spinner');
|
|
26
|
+
const {
|
|
27
|
+
createDirectoryStructure,
|
|
28
|
+
copyTemplates,
|
|
29
|
+
createAiContextMd,
|
|
30
|
+
AI_CONTEXT_DIR,
|
|
31
|
+
AI_CONTEXT_FILE
|
|
32
|
+
} = require('./installer');
|
|
33
|
+
const { detectTechStack } = require('./detector');
|
|
34
|
+
const { replacePlaceholders } = require('./placeholder');
|
|
35
|
+
const { validateInstallation } = require('./validate');
|
|
36
|
+
|
|
37
|
+
// New modules for context engineering initialization
|
|
38
|
+
const { detectEnvironment, forceMode, getEnvironmentDescription } = require('./environment-detector');
|
|
39
|
+
const { analyzeCodebase } = require('./static-analyzer');
|
|
40
|
+
const {
|
|
41
|
+
createInitializationRequest,
|
|
42
|
+
generateAgentInstructions,
|
|
43
|
+
isInitializationPending
|
|
44
|
+
} = require('./ai-orchestrator');
|
|
45
|
+
const { populateAllTemplates } = require('./template-populator');
|
|
46
|
+
const { generateAll: generateAllContexts, getSupportedTools } = require('./ai-context-generator');
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Main entry point
|
|
50
|
+
*/
|
|
51
|
+
async function run(options = {}) {
|
|
52
|
+
const {
|
|
53
|
+
projectName,
|
|
54
|
+
skipPrompts = false,
|
|
55
|
+
installPlugin = true,
|
|
56
|
+
template,
|
|
57
|
+
initGit = true,
|
|
58
|
+
dryRun = false,
|
|
59
|
+
verbose = false,
|
|
60
|
+
// AI tool selection
|
|
61
|
+
aiTools = ['claude', 'copilot', 'cline', 'antigravity'],
|
|
62
|
+
// Mode options
|
|
63
|
+
forceAi = false,
|
|
64
|
+
forceStatic = false,
|
|
65
|
+
analyzeOnly = false,
|
|
66
|
+
// Monorepo options
|
|
67
|
+
monorepo = false,
|
|
68
|
+
federate = false
|
|
69
|
+
} = options;
|
|
70
|
+
|
|
71
|
+
// Determine target directory
|
|
72
|
+
const targetDir = projectName
|
|
73
|
+
? path.resolve(process.cwd(), projectName)
|
|
74
|
+
: process.cwd();
|
|
75
|
+
|
|
76
|
+
const projectNameResolved = projectName || path.basename(targetDir);
|
|
77
|
+
const contextDir = path.join(targetDir, AI_CONTEXT_DIR);
|
|
78
|
+
|
|
79
|
+
// Get configuration (prompts or defaults)
|
|
80
|
+
let config;
|
|
81
|
+
if (skipPrompts) {
|
|
82
|
+
config = await getDefaults(targetDir, template);
|
|
83
|
+
} else {
|
|
84
|
+
config = await runPrompts(targetDir, template);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
config.projectName = projectNameResolved;
|
|
88
|
+
config.targetDir = targetDir;
|
|
89
|
+
config.installPlugin = installPlugin && config.installPlugin;
|
|
90
|
+
config.initGit = initGit;
|
|
91
|
+
config.dryRun = dryRun;
|
|
92
|
+
config.verbose = verbose;
|
|
93
|
+
config.aiTools = aiTools;
|
|
94
|
+
config.monorepo = monorepo;
|
|
95
|
+
|
|
96
|
+
if (dryRun) {
|
|
97
|
+
console.log(chalk.yellow('\n--dry-run mode: No changes will be made\n'));
|
|
98
|
+
console.log('Configuration:', JSON.stringify(config, null, 2));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Phase 1: Create target directory if needed
|
|
103
|
+
const spinner = createSpinner();
|
|
104
|
+
|
|
105
|
+
if (projectName && !fs.existsSync(targetDir)) {
|
|
106
|
+
spinner.start('Creating project directory...');
|
|
107
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
108
|
+
spinner.succeed(`Created project directory: ${projectNameResolved}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Phase 2: Detect execution environment
|
|
112
|
+
spinner.start('Detecting execution environment...');
|
|
113
|
+
let env;
|
|
114
|
+
if (forceAi) {
|
|
115
|
+
env = forceMode('full-ai');
|
|
116
|
+
} else if (forceStatic) {
|
|
117
|
+
env = forceMode('standalone');
|
|
118
|
+
} else {
|
|
119
|
+
env = detectEnvironment();
|
|
120
|
+
}
|
|
121
|
+
spinner.succeed(`Environment: ${getEnvironmentDescription(env)}`);
|
|
122
|
+
|
|
123
|
+
// Phase 3: Create .ai-context directory structure
|
|
124
|
+
spinner.start(`Creating ${AI_CONTEXT_DIR} directory structure...`);
|
|
125
|
+
const dirsCreated = await createDirectoryStructure(targetDir, config);
|
|
126
|
+
spinner.succeed(`Created ${AI_CONTEXT_DIR} directory structure (${dirsCreated} directories)`);
|
|
127
|
+
|
|
128
|
+
// Phase 4: Copy template files
|
|
129
|
+
spinner.start('Copying template files...');
|
|
130
|
+
const filesCopied = await copyTemplates(targetDir, config);
|
|
131
|
+
spinner.succeed(`Copied ${filesCopied} template files`);
|
|
132
|
+
|
|
133
|
+
// Phase 5: Detect technology stack
|
|
134
|
+
spinner.start('Detecting technology stack...');
|
|
135
|
+
const techStack = await detectTechStack(targetDir);
|
|
136
|
+
config.techStack = techStack;
|
|
137
|
+
spinner.succeed(`Detected: ${techStack.summary || 'Generic project'}`);
|
|
138
|
+
|
|
139
|
+
// Phase 6: Deep codebase analysis
|
|
140
|
+
spinner.start('Analyzing codebase...');
|
|
141
|
+
let analysis;
|
|
142
|
+
try {
|
|
143
|
+
analysis = await analyzeCodebase(targetDir, { techStack });
|
|
144
|
+
const summary = analysis.summary || {};
|
|
145
|
+
spinner.succeed(
|
|
146
|
+
`Analyzed: ${summary.totalFiles || 0} files, ` +
|
|
147
|
+
`${summary.entryPointCount || 0} entry points, ` +
|
|
148
|
+
`${summary.workflowCount || 0} workflows`
|
|
149
|
+
);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
spinner.warn(`Analysis partial: ${error.message}`);
|
|
152
|
+
analysis = { workflows: [], entryPoints: [], architecture: {}, techStack };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Add tech stack to analysis
|
|
156
|
+
analysis.techStack = techStack;
|
|
157
|
+
|
|
158
|
+
// Phase 7: Create AI_CONTEXT.md at root (before population)
|
|
159
|
+
spinner.start(`Creating ${AI_CONTEXT_FILE}...`);
|
|
160
|
+
await createAiContextMd(targetDir, config, techStack);
|
|
161
|
+
spinner.succeed(`Created ${AI_CONTEXT_FILE} at project root`);
|
|
162
|
+
|
|
163
|
+
// Phase 8: Populate templates with real data
|
|
164
|
+
spinner.start('Populating templates with analysis results...');
|
|
165
|
+
let populationResults;
|
|
166
|
+
try {
|
|
167
|
+
populationResults = await populateAllTemplates(contextDir, analysis, config);
|
|
168
|
+
const counts = {
|
|
169
|
+
populated: populationResults.populated?.length || 0,
|
|
170
|
+
created: populationResults.created?.length || 0,
|
|
171
|
+
errors: populationResults.errors?.length || 0
|
|
172
|
+
};
|
|
173
|
+
if (counts.errors > 0) {
|
|
174
|
+
spinner.warn(`Populated ${counts.populated} files, created ${counts.created} workflows (${counts.errors} errors)`);
|
|
175
|
+
} else {
|
|
176
|
+
spinner.succeed(`Populated ${counts.populated} files, created ${counts.created} workflow docs`);
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
spinner.warn(`Population partial: ${error.message}`);
|
|
180
|
+
populationResults = { populated: [], created: [], errors: [error.message] };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Phase 9: Replace remaining placeholders
|
|
184
|
+
spinner.start('Replacing remaining placeholders...');
|
|
185
|
+
const placeholdersReplaced = await replacePlaceholders(targetDir, {
|
|
186
|
+
...config,
|
|
187
|
+
techStack,
|
|
188
|
+
analysis
|
|
189
|
+
});
|
|
190
|
+
spinner.succeed(`Replaced ${placeholdersReplaced} placeholders`);
|
|
191
|
+
|
|
192
|
+
// Phase 10: AI Orchestration (if in Claude Code environment)
|
|
193
|
+
if (env.mode === 'full-ai' || env.mode === 'hybrid') {
|
|
194
|
+
spinner.start('Preparing AI initialization request...');
|
|
195
|
+
try {
|
|
196
|
+
createInitializationRequest(contextDir, config);
|
|
197
|
+
generateAgentInstructions(contextDir, analysis, config);
|
|
198
|
+
spinner.succeed('Created INIT_REQUEST.md for @context-engineer');
|
|
199
|
+
} catch (error) {
|
|
200
|
+
spinner.warn(`AI setup skipped: ${error.message}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Phase 11: Generate AI tool-specific context files
|
|
205
|
+
spinner.start('Generating AI tool context files...');
|
|
206
|
+
let generationResults;
|
|
207
|
+
try {
|
|
208
|
+
generationResults = await generateAllContexts(analysis, config, targetDir, {
|
|
209
|
+
aiTools: config.aiTools,
|
|
210
|
+
verbose: config.verbose
|
|
211
|
+
});
|
|
212
|
+
const toolsGenerated = generationResults.generated.map(g => g.adapter).join(', ');
|
|
213
|
+
if (generationResults.success) {
|
|
214
|
+
spinner.succeed(`Generated context for: ${toolsGenerated} (${generationResults.summary.files} files)`);
|
|
215
|
+
} else {
|
|
216
|
+
spinner.warn(`Generated ${generationResults.summary.successful}/${generationResults.summary.total} tools`);
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
spinner.warn(`Context generation partial: ${error.message}`);
|
|
220
|
+
generationResults = { generated: [], errors: [error.message] };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Phase 12: Validate installation
|
|
224
|
+
spinner.start('Validating installation...');
|
|
225
|
+
const validation = await validateInstallation(targetDir);
|
|
226
|
+
if (validation.passed) {
|
|
227
|
+
spinner.succeed('All validations passed');
|
|
228
|
+
} else {
|
|
229
|
+
spinner.warn(`Validation completed with ${validation.warnings} warnings`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Phase 13: Install plugin (optional)
|
|
233
|
+
if (config.installPlugin) {
|
|
234
|
+
spinner.start('Plugin ready...');
|
|
235
|
+
spinner.succeed('Plugin ready (install with: /plugin install ai-context-engineering)');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Phase 14: Initialize git (optional)
|
|
239
|
+
if (config.initGit && !fs.existsSync(path.join(targetDir, '.git'))) {
|
|
240
|
+
spinner.start('Initializing git repository...');
|
|
241
|
+
try {
|
|
242
|
+
const { execSync } = require('child_process');
|
|
243
|
+
execSync('git init', { cwd: targetDir, stdio: 'pipe' });
|
|
244
|
+
spinner.succeed('Initialized git repository');
|
|
245
|
+
} catch (e) {
|
|
246
|
+
spinner.warn('Could not initialize git (git may not be installed)');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Success message (mode-aware)
|
|
251
|
+
showSuccess(config, techStack, env, analysis, populationResults, generationResults);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Display success message with next steps
|
|
256
|
+
*/
|
|
257
|
+
function showSuccess(config, techStack, env, analysis, populationResults, generationResults) {
|
|
258
|
+
const boxWidth = 59;
|
|
259
|
+
const isAiMode = env.mode === 'full-ai' || env.mode === 'hybrid';
|
|
260
|
+
const workflowCount = analysis?.workflows?.length || 0;
|
|
261
|
+
const entryPointCount = analysis?.entryPoints?.length || 0;
|
|
262
|
+
const aiTools = config.aiTools || [];
|
|
263
|
+
const generatedTools = generationResults?.generated || [];
|
|
264
|
+
|
|
265
|
+
console.log(`
|
|
266
|
+
${chalk.green('╔' + '═'.repeat(boxWidth) + '╗')}
|
|
267
|
+
${chalk.green('║')} ${chalk.bold.white('✓ AI Context Engineering Initialized Successfully!')} ${chalk.green('║')}
|
|
268
|
+
${chalk.green('╚' + '═'.repeat(boxWidth) + '╝')}
|
|
269
|
+
|
|
270
|
+
${chalk.bold('Analysis Results:')}
|
|
271
|
+
${chalk.cyan('•')} Entry Points: ${chalk.white(entryPointCount)} discovered
|
|
272
|
+
${chalk.cyan('•')} Workflows: ${chalk.white(workflowCount)} documented
|
|
273
|
+
${chalk.cyan('•')} Mode: ${chalk.white(env.mode)}
|
|
274
|
+
|
|
275
|
+
${chalk.bold('Created:')}
|
|
276
|
+
${chalk.cyan('•')} ${AI_CONTEXT_DIR}/ ${chalk.gray('(context engineering system)')}
|
|
277
|
+
${chalk.cyan('•')} ${AI_CONTEXT_FILE} ${chalk.gray('(AI navigation guide)')}
|
|
278
|
+
${workflowCount > 0 ? ` ${chalk.cyan('•')} ${workflowCount} workflow docs ${chalk.gray('(auto-generated)')}` : ''}
|
|
279
|
+
|
|
280
|
+
${chalk.bold('AI Tools Generated:')}
|
|
281
|
+
${generatedTools.find(g => g.adapter === 'claude') ? ` ${chalk.green('✓')} Claude Code ${chalk.gray('(' + AI_CONTEXT_FILE + ')')}` : (aiTools.includes('claude') ? ` ${chalk.yellow('○')} Claude Code ${chalk.gray('(pending)')}` : '')}
|
|
282
|
+
${generatedTools.find(g => g.adapter === 'copilot') ? ` ${chalk.green('✓')} GitHub Copilot ${chalk.gray('(.github/copilot-instructions.md)')}` : (aiTools.includes('copilot') ? ` ${chalk.yellow('○')} GitHub Copilot ${chalk.gray('(pending)')}` : '')}
|
|
283
|
+
${generatedTools.find(g => g.adapter === 'cline') ? ` ${chalk.green('✓')} Cline ${chalk.gray('(.clinerules)')}` : (aiTools.includes('cline') ? ` ${chalk.yellow('○')} Cline ${chalk.gray('(pending)')}` : '')}
|
|
284
|
+
${generatedTools.find(g => g.adapter === 'antigravity') ? ` ${chalk.green('✓')} Antigravity ${chalk.gray('(.agent/ ' + (generatedTools.find(g => g.adapter === 'antigravity')?.files?.length || 0) + ' files)')}` : (aiTools.includes('antigravity') ? ` ${chalk.yellow('○')} Antigravity ${chalk.gray('(pending)')}` : '')}
|
|
285
|
+
|
|
286
|
+
${chalk.bold('Available Commands:')}
|
|
287
|
+
${chalk.cyan('•')} /rpi-research ${chalk.gray('Research a feature')}
|
|
288
|
+
${chalk.cyan('•')} /rpi-plan ${chalk.gray('Create implementation plan')}
|
|
289
|
+
${chalk.cyan('•')} /rpi-implement ${chalk.gray('Execute with documentation')}
|
|
290
|
+
${chalk.cyan('•')} /validate-all ${chalk.gray('Run validation suite')}
|
|
291
|
+
`);
|
|
292
|
+
|
|
293
|
+
if (isAiMode) {
|
|
294
|
+
console.log(`${chalk.bold.yellow('AI Initialization Pending:')}
|
|
295
|
+
${chalk.white('Run this command in Claude Code to complete:')}
|
|
296
|
+
${chalk.cyan('@context-engineer "Complete initialization using INIT_REQUEST.md"')}
|
|
297
|
+
`);
|
|
298
|
+
} else {
|
|
299
|
+
console.log(`${chalk.bold('Next Steps:')}
|
|
300
|
+
${chalk.white('1.')} Review ${chalk.cyan(AI_CONTEXT_FILE)} and customize for your project
|
|
301
|
+
${chalk.white('2.')} Review generated workflow docs in ${chalk.cyan(AI_CONTEXT_DIR + '/context/workflows/')}
|
|
302
|
+
${chalk.white('3.')} Run ${chalk.cyan('@context-engineer "Enhance documentation"')} for AI analysis
|
|
303
|
+
`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
console.log(`${chalk.gray('Documentation: https://github.com/SireJeff/claude-context-engineering-template')}
|
|
307
|
+
`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
module.exports = { run };
|