create-claude-context 1.0.0 → 1.2.1

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 (117) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +169 -146
  3. package/bin/create-claude-context.js +75 -61
  4. package/lib/ai-orchestrator.js +423 -0
  5. package/lib/call-tracer.js +444 -0
  6. package/lib/detector.js +456 -373
  7. package/lib/environment-detector.js +239 -0
  8. package/lib/index.js +271 -170
  9. package/lib/installer.js +371 -362
  10. package/lib/placeholder.js +269 -208
  11. package/lib/prompts.js +287 -287
  12. package/lib/spinner.js +60 -60
  13. package/lib/static-analyzer.js +729 -0
  14. package/lib/template-populator.js +835 -0
  15. package/lib/validate.js +147 -147
  16. package/package.json +59 -59
  17. package/templates/CLAUDE.md.template +235 -235
  18. package/templates/base/README.md +257 -257
  19. package/templates/base/RPI_WORKFLOW_PLAN.md +320 -320
  20. package/templates/base/agents/api-developer.md +76 -76
  21. package/templates/base/agents/context-engineer.md +525 -525
  22. package/templates/base/agents/core-architect.md +76 -76
  23. package/templates/base/agents/database-ops.md +76 -76
  24. package/templates/base/agents/deployment-ops.md +76 -76
  25. package/templates/base/agents/integration-hub.md +76 -76
  26. package/templates/base/analytics/README.md +114 -114
  27. package/templates/base/automation/config.json +58 -0
  28. package/templates/base/automation/generators/code-mapper.js +308 -0
  29. package/templates/base/automation/generators/index-builder.js +321 -0
  30. package/templates/base/automation/hooks/post-commit.sh +83 -0
  31. package/templates/base/automation/hooks/pre-commit.sh +103 -0
  32. package/templates/base/ci-templates/README.md +108 -108
  33. package/templates/base/ci-templates/github-actions/context-check.yml +144 -144
  34. package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -105
  35. package/templates/base/commands/analytics.md +238 -238
  36. package/templates/base/commands/auto-sync.md +172 -0
  37. package/templates/base/commands/collab.md +194 -194
  38. package/templates/base/commands/help.md +450 -450
  39. package/templates/base/commands/rpi-implement.md +115 -115
  40. package/templates/base/commands/rpi-plan.md +93 -93
  41. package/templates/base/commands/rpi-research.md +88 -88
  42. package/templates/base/commands/session-resume.md +144 -0
  43. package/templates/base/commands/session-save.md +112 -0
  44. package/templates/base/commands/validate-all.md +77 -77
  45. package/templates/base/commands/verify-docs-current.md +86 -86
  46. package/templates/base/config/base.json +57 -57
  47. package/templates/base/config/environments/development.json +13 -13
  48. package/templates/base/config/environments/production.json +17 -17
  49. package/templates/base/config/environments/staging.json +13 -13
  50. package/templates/base/config/local.json.example +21 -21
  51. package/templates/base/context/.meta/generated-at.json +18 -0
  52. package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -156
  53. package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -94
  54. package/templates/base/context/FILE_OWNERSHIP.md +57 -0
  55. package/templates/base/context/INTEGRATION_POINTS.md +92 -0
  56. package/templates/base/context/KNOWN_GOTCHAS.md +195 -195
  57. package/templates/base/context/TESTING_MAP.md +95 -0
  58. package/templates/base/context/WORKFLOW_INDEX.md +129 -129
  59. package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -294
  60. package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -255
  61. package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -44
  62. package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -38
  63. package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -39
  64. package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -39
  65. package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -38
  66. package/templates/base/knowledge/README.md +98 -98
  67. package/templates/base/knowledge/sessions/README.md +88 -88
  68. package/templates/base/knowledge/sessions/TEMPLATE.md +150 -150
  69. package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -144
  70. package/templates/base/knowledge/shared/decisions/README.md +49 -49
  71. package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -123
  72. package/templates/base/knowledge/shared/patterns/README.md +62 -62
  73. package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -120
  74. package/templates/base/plans/PLAN_TEMPLATE.md +250 -250
  75. package/templates/base/research/RESEARCH_TEMPLATE.md +153 -153
  76. package/templates/base/schemas/agent.schema.json +141 -141
  77. package/templates/base/schemas/anchors.schema.json +54 -0
  78. package/templates/base/schemas/automation.schema.json +93 -0
  79. package/templates/base/schemas/command.schema.json +134 -134
  80. package/templates/base/schemas/hashes.schema.json +40 -0
  81. package/templates/base/schemas/manifest.schema.json +117 -117
  82. package/templates/base/schemas/plan.schema.json +136 -136
  83. package/templates/base/schemas/research.schema.json +115 -115
  84. package/templates/base/schemas/roles.schema.json +34 -0
  85. package/templates/base/schemas/session.schema.json +77 -0
  86. package/templates/base/schemas/settings.schema.json +244 -244
  87. package/templates/base/schemas/staleness.schema.json +53 -0
  88. package/templates/base/schemas/team-config.schema.json +42 -0
  89. package/templates/base/schemas/workflow.schema.json +126 -126
  90. package/templates/base/session/checkpoints/.gitkeep +2 -0
  91. package/templates/base/session/current/state.json +20 -0
  92. package/templates/base/session/history/.gitkeep +2 -0
  93. package/templates/base/settings.json +3 -57
  94. package/templates/base/standards/COMPATIBILITY.md +219 -219
  95. package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -280
  96. package/templates/base/standards/QUALITY_CHECKLIST.md +211 -211
  97. package/templates/base/standards/README.md +66 -66
  98. package/templates/base/sync/anchors.json +6 -0
  99. package/templates/base/sync/hashes.json +6 -0
  100. package/templates/base/sync/staleness.json +10 -0
  101. package/templates/base/team/README.md +168 -168
  102. package/templates/base/team/config.json +79 -79
  103. package/templates/base/team/roles.json +145 -145
  104. package/templates/base/tools/bin/claude-context.js +151 -151
  105. package/templates/base/tools/lib/anchor-resolver.js +276 -0
  106. package/templates/base/tools/lib/config-loader.js +363 -363
  107. package/templates/base/tools/lib/detector.js +350 -350
  108. package/templates/base/tools/lib/diagnose.js +206 -206
  109. package/templates/base/tools/lib/drift-detector.js +373 -0
  110. package/templates/base/tools/lib/errors.js +199 -199
  111. package/templates/base/tools/lib/index.js +36 -24
  112. package/templates/base/tools/lib/init.js +192 -192
  113. package/templates/base/tools/lib/logger.js +230 -230
  114. package/templates/base/tools/lib/placeholder.js +201 -201
  115. package/templates/base/tools/lib/session-manager.js +354 -0
  116. package/templates/base/tools/lib/validate.js +521 -521
  117. package/templates/base/tools/package.json +49 -49
@@ -0,0 +1,423 @@
1
+ /**
2
+ * AI Orchestrator
3
+ *
4
+ * Coordinates with @context-engineer agent for full AI-powered analysis.
5
+ * Creates initialization requests and generates agent instructions.
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ /**
12
+ * Marker file for pending initialization
13
+ */
14
+ const INIT_MARKER = '.init-pending';
15
+
16
+ /**
17
+ * Instruction file for agent
18
+ */
19
+ const INIT_REQUEST_FILE = 'INIT_REQUEST.md';
20
+
21
+ /**
22
+ * Progress tracking file
23
+ */
24
+ const PROGRESS_FILE = 'INIT_PROGRESS.json';
25
+
26
+ /**
27
+ * Create an initialization request marker
28
+ * @param {string} claudeDir - .claude directory path
29
+ * @param {object} config - Configuration from CLI
30
+ * @returns {object} Request object
31
+ */
32
+ function createInitializationRequest(claudeDir, config) {
33
+ const request = {
34
+ version: '1.0.0',
35
+ createdAt: new Date().toISOString(),
36
+ projectName: config.projectName || path.basename(path.dirname(claudeDir)),
37
+ config: {
38
+ techStack: config.techStack,
39
+ features: config.features,
40
+ installPlugin: config.installPlugin
41
+ },
42
+ phases: [
43
+ { id: 'repository-analysis', name: 'Repository Analysis', status: 'pending', progress: 0 },
44
+ { id: 'workflow-discovery', name: 'Workflow Discovery', status: 'pending', progress: 0 },
45
+ { id: 'template-population', name: 'Template Population', status: 'pending', progress: 0 },
46
+ { id: 'index-generation', name: 'Index Generation', status: 'pending', progress: 0 },
47
+ { id: 'validation', name: 'Validation', status: 'pending', progress: 0 },
48
+ { id: 'finalization', name: 'Finalization', status: 'pending', progress: 0 }
49
+ ],
50
+ status: 'pending',
51
+ completedAt: null
52
+ };
53
+
54
+ const markerPath = path.join(claudeDir, INIT_MARKER);
55
+ fs.writeFileSync(markerPath, JSON.stringify(request, null, 2));
56
+
57
+ return request;
58
+ }
59
+
60
+ /**
61
+ * Generate agent instruction file with pre-analysis results
62
+ * @param {string} claudeDir - .claude directory path
63
+ * @param {object} analysis - Pre-analysis results from static analyzer
64
+ * @param {object} config - Configuration from CLI
65
+ */
66
+ function generateAgentInstructions(claudeDir, analysis, config) {
67
+ const projectName = config.projectName || path.basename(path.dirname(claudeDir));
68
+ const pkgVersion = getPackageVersion();
69
+
70
+ const instructions = `# Context Engineering Initialization Request
71
+
72
+ > **Auto-generated by \`create-claude-context\` v${pkgVersion}**
73
+ > Generated: ${new Date().toISOString()}
74
+
75
+ ## Status: Awaiting AI Completion
76
+
77
+ The CLI has performed static pre-analysis and prepared the template structure.
78
+ Full AI-powered context engineering is requested to complete initialization.
79
+
80
+ ---
81
+
82
+ ## Project Overview
83
+
84
+ | Property | Value |
85
+ |----------|-------|
86
+ | **Project Name** | ${projectName} |
87
+ | **Tech Stack** | ${analysis.techStack?.summary || 'Detected during analysis'} |
88
+ | **Source Files** | ${analysis.sourceFiles || 'TBD'} |
89
+ | **Lines of Code** | ${analysis.linesOfCode?.total || 'TBD'} |
90
+
91
+ ---
92
+
93
+ ## Pre-Analysis Results
94
+
95
+ ### Entry Points Discovered (${analysis.entryPoints?.length || 0})
96
+
97
+ ${formatEntryPoints(analysis.entryPoints)}
98
+
99
+ ### Workflow Candidates (${analysis.workflows?.length || 0})
100
+
101
+ ${formatWorkflows(analysis.workflows)}
102
+
103
+ ### Architecture Layers
104
+
105
+ ${formatLayers(analysis.architecture?.layers)}
106
+
107
+ ### Dependencies (${analysis.dependencies?.length || 0})
108
+
109
+ ${formatDependencies(analysis.dependencies)}
110
+
111
+ ---
112
+
113
+ ## Requested Actions
114
+
115
+ Please complete the context engineering initialization by:
116
+
117
+ ### Phase 1: Verify Pre-Analysis
118
+ - [ ] Review discovered entry points for accuracy
119
+ - [ ] Confirm workflow candidates are valid
120
+ - [ ] Identify any missed entry points or workflows
121
+
122
+ ### Phase 2: Deep Workflow Discovery
123
+ - [ ] Trace call chains for each workflow (3 levels deep)
124
+ - [ ] Identify database operations per workflow
125
+ - [ ] Map external API calls per workflow
126
+ - [ ] Document error handling patterns
127
+
128
+ ### Phase 3: Template Population
129
+ - [ ] Fill ARCHITECTURE_SNAPSHOT.md with real architecture
130
+ - [ ] Create individual workflow files (8-15 total)
131
+ - [ ] Populate CODE_TO_WORKFLOW_MAP.md with file references
132
+ - [ ] Update WORKFLOW_INDEX.md with all workflows
133
+
134
+ ### Phase 4: Index Generation
135
+ - [ ] Generate proper category indexes
136
+ - [ ] Create semantic anchors for key functions
137
+ - [ ] Build reverse lookup indexes
138
+
139
+ ### Phase 5: Validation
140
+ - [ ] Verify line number accuracy (target: 60%+)
141
+ - [ ] Check all internal links
142
+ - [ ] Confirm no placeholder values remain
143
+
144
+ ### Phase 6: Finalization
145
+ - [ ] Generate summary report
146
+ - [ ] Update CLAUDE.md with project-specific info
147
+ - [ ] Create maintenance schedule
148
+
149
+ ---
150
+
151
+ ## Quick Start Command
152
+
153
+ \`\`\`bash
154
+ @context-engineer "Complete initialization for ${projectName} using the pre-analysis in INIT_REQUEST.md"
155
+ \`\`\`
156
+
157
+ Or use the dedicated command:
158
+
159
+ \`\`\`bash
160
+ /rpi-research "Complete context engineering initialization"
161
+ \`\`\`
162
+
163
+ ---
164
+
165
+ ## Files to Update
166
+
167
+ | File | Action |
168
+ |------|--------|
169
+ | \`context/ARCHITECTURE_SNAPSHOT.md\` | Populate with real architecture |
170
+ | \`context/WORKFLOW_INDEX.md\` | Add all discovered workflows |
171
+ | \`context/CODE_TO_WORKFLOW_MAP.md\` | Map files to workflows |
172
+ | \`context/workflows/*.md\` | Create individual workflow docs |
173
+ | \`indexes/workflows/CATEGORY_INDEX.md\` | Generate category index |
174
+ | \`../CLAUDE.md\` | Finalize with project info |
175
+
176
+ ---
177
+
178
+ ## Pre-Analysis Data
179
+
180
+ The following JSON contains the full pre-analysis for programmatic use:
181
+
182
+ \`\`\`json
183
+ ${JSON.stringify(analysis.summary || {}, null, 2)}
184
+ \`\`\`
185
+
186
+ ---
187
+
188
+ *This file will be deleted automatically after successful initialization.*
189
+ *Generated by create-claude-context v${pkgVersion}*
190
+ `;
191
+
192
+ const instructionPath = path.join(claudeDir, INIT_REQUEST_FILE);
193
+ fs.writeFileSync(instructionPath, instructions);
194
+
195
+ return instructionPath;
196
+ }
197
+
198
+ /**
199
+ * Format entry points for markdown
200
+ * @param {object[]} entryPoints - Entry points array
201
+ * @returns {string}
202
+ */
203
+ function formatEntryPoints(entryPoints) {
204
+ if (!entryPoints || entryPoints.length === 0) {
205
+ return '*No entry points discovered during pre-analysis. AI analysis will discover them.*\n';
206
+ }
207
+
208
+ const limited = entryPoints.slice(0, 15);
209
+ let output = '| File | Line | Route | Method |\n|------|------|-------|--------|\n';
210
+
211
+ for (const ep of limited) {
212
+ output += `| \`${ep.file}\` | ${ep.line} | ${ep.route || '-'} | ${ep.method || '-'} |\n`;
213
+ }
214
+
215
+ if (entryPoints.length > 15) {
216
+ output += `\n*...and ${entryPoints.length - 15} more entry points*\n`;
217
+ }
218
+
219
+ return output;
220
+ }
221
+
222
+ /**
223
+ * Format workflows for markdown
224
+ * @param {object[]} workflows - Workflows array
225
+ * @returns {string}
226
+ */
227
+ function formatWorkflows(workflows) {
228
+ if (!workflows || workflows.length === 0) {
229
+ return '*No workflows discovered during pre-analysis. AI analysis will discover them.*\n';
230
+ }
231
+
232
+ let output = '| Workflow | Category | Complexity | Files | Confidence |\n|----------|----------|------------|-------|------------|\n';
233
+
234
+ for (const wf of workflows) {
235
+ output += `| **${wf.name}** | ${wf.category} | ${wf.complexity} | ${wf.fileCount || wf.files?.length || 0} | ${wf.confidence || '-'}% |\n`;
236
+ }
237
+
238
+ return output;
239
+ }
240
+
241
+ /**
242
+ * Format architecture layers for markdown
243
+ * @param {object[]} layers - Layers array
244
+ * @returns {string}
245
+ */
246
+ function formatLayers(layers) {
247
+ if (!layers || layers.length === 0) {
248
+ return '*Architecture layers will be determined during AI analysis.*\n';
249
+ }
250
+
251
+ let output = '| Layer | Directories | Purpose |\n|-------|-------------|----------|\n';
252
+
253
+ for (const layer of layers) {
254
+ output += `| **${layer.name}** | ${layer.directories?.join(', ') || '-'} | ${layer.purpose || '-'} |\n`;
255
+ }
256
+
257
+ return output;
258
+ }
259
+
260
+ /**
261
+ * Format dependencies for markdown
262
+ * @param {object[]} dependencies - Dependencies array
263
+ * @returns {string}
264
+ */
265
+ function formatDependencies(dependencies) {
266
+ if (!dependencies || dependencies.length === 0) {
267
+ return '*No dependencies detected.*\n';
268
+ }
269
+
270
+ // Group by ecosystem
271
+ const byEcosystem = {};
272
+ for (const dep of dependencies) {
273
+ const eco = dep.ecosystem || 'unknown';
274
+ if (!byEcosystem[eco]) byEcosystem[eco] = [];
275
+ byEcosystem[eco].push(dep);
276
+ }
277
+
278
+ let output = '';
279
+ for (const [ecosystem, deps] of Object.entries(byEcosystem)) {
280
+ output += `\n**${ecosystem.toUpperCase()}** (${deps.length}):\n`;
281
+ const topDeps = deps.slice(0, 10);
282
+ output += topDeps.map(d => `- ${d.name}@${d.version}`).join('\n') + '\n';
283
+ if (deps.length > 10) {
284
+ output += `- *...and ${deps.length - 10} more*\n`;
285
+ }
286
+ }
287
+
288
+ return output;
289
+ }
290
+
291
+ /**
292
+ * Get package version
293
+ * @returns {string}
294
+ */
295
+ function getPackageVersion() {
296
+ try {
297
+ const pkgPath = path.join(__dirname, '..', 'package.json');
298
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
299
+ return pkg.version || '1.0.0';
300
+ } catch {
301
+ return '1.0.0';
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Check initialization status
307
+ * @param {string} claudeDir - .claude directory path
308
+ * @returns {object}
309
+ */
310
+ function checkInitializationStatus(claudeDir) {
311
+ const markerPath = path.join(claudeDir, INIT_MARKER);
312
+
313
+ if (!fs.existsSync(markerPath)) {
314
+ return { status: 'not-started', request: null };
315
+ }
316
+
317
+ try {
318
+ const request = JSON.parse(fs.readFileSync(markerPath, 'utf-8'));
319
+ const completedPhases = request.phases.filter(p => p.status === 'completed').length;
320
+ const totalPhases = request.phases.length;
321
+
322
+ return {
323
+ status: completedPhases === totalPhases ? 'completed' : 'in-progress',
324
+ progress: Math.round((completedPhases / totalPhases) * 100),
325
+ completedPhases,
326
+ totalPhases,
327
+ request
328
+ };
329
+ } catch {
330
+ return { status: 'error', request: null };
331
+ }
332
+ }
333
+
334
+ /**
335
+ * Update initialization progress
336
+ * @param {string} claudeDir - .claude directory path
337
+ * @param {string} phaseId - Phase ID to update
338
+ * @param {string} status - New status ('in-progress', 'completed', 'failed')
339
+ * @param {number} progress - Progress percentage (0-100)
340
+ */
341
+ function updateInitializationProgress(claudeDir, phaseId, status, progress = 0) {
342
+ const markerPath = path.join(claudeDir, INIT_MARKER);
343
+
344
+ if (!fs.existsSync(markerPath)) {
345
+ return false;
346
+ }
347
+
348
+ try {
349
+ const request = JSON.parse(fs.readFileSync(markerPath, 'utf-8'));
350
+ const phase = request.phases.find(p => p.id === phaseId);
351
+
352
+ if (phase) {
353
+ phase.status = status;
354
+ phase.progress = progress;
355
+ phase.updatedAt = new Date().toISOString();
356
+ }
357
+
358
+ // Check if all phases are completed
359
+ const allCompleted = request.phases.every(p => p.status === 'completed');
360
+ if (allCompleted) {
361
+ request.status = 'completed';
362
+ request.completedAt = new Date().toISOString();
363
+ } else {
364
+ request.status = 'in-progress';
365
+ }
366
+
367
+ fs.writeFileSync(markerPath, JSON.stringify(request, null, 2));
368
+ return true;
369
+ } catch {
370
+ return false;
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Mark initialization as complete and clean up
376
+ * @param {string} claudeDir - .claude directory path
377
+ * @param {boolean} removeMarker - Whether to remove the marker file
378
+ */
379
+ function completeInitialization(claudeDir, removeMarker = true) {
380
+ const markerPath = path.join(claudeDir, INIT_MARKER);
381
+ const instructionPath = path.join(claudeDir, INIT_REQUEST_FILE);
382
+
383
+ if (fs.existsSync(markerPath)) {
384
+ const request = JSON.parse(fs.readFileSync(markerPath, 'utf-8'));
385
+ request.status = 'completed';
386
+ request.completedAt = new Date().toISOString();
387
+
388
+ // Archive to progress file
389
+ const progressPath = path.join(claudeDir, PROGRESS_FILE);
390
+ fs.writeFileSync(progressPath, JSON.stringify(request, null, 2));
391
+
392
+ if (removeMarker) {
393
+ fs.unlinkSync(markerPath);
394
+ }
395
+ }
396
+
397
+ // Remove instruction file
398
+ if (removeMarker && fs.existsSync(instructionPath)) {
399
+ fs.unlinkSync(instructionPath);
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Check if initialization is pending
405
+ * @param {string} claudeDir - .claude directory path
406
+ * @returns {boolean}
407
+ */
408
+ function isInitializationPending(claudeDir) {
409
+ const markerPath = path.join(claudeDir, INIT_MARKER);
410
+ return fs.existsSync(markerPath);
411
+ }
412
+
413
+ module.exports = {
414
+ createInitializationRequest,
415
+ generateAgentInstructions,
416
+ checkInitializationStatus,
417
+ updateInitializationProgress,
418
+ completeInitialization,
419
+ isInitializationPending,
420
+ INIT_MARKER,
421
+ INIT_REQUEST_FILE,
422
+ PROGRESS_FILE
423
+ };