forjajs 1.2.0 → 1.3.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/.claude/settings.json +7 -7
- package/CHANGELOG.md +25 -0
- package/README.en.md +5 -0
- package/README.md +5 -0
- package/dist/bin/create-memory-nest-kit.d.ts +2 -0
- package/dist/bin/create-memory-nest-kit.js +110 -0
- package/dist/bin/forja.d.ts +13 -0
- package/dist/bin/forja.js +136 -0
- package/dist/bin/init-project.d.ts +2 -0
- package/dist/bin/init-project.js +516 -0
- package/dist/lib/audit.d.ts +67 -0
- package/dist/lib/audit.js +143 -0
- package/dist/lib/context-builder.d.ts +58 -0
- package/dist/lib/context-builder.js +233 -0
- package/dist/lib/core/checks.d.ts +91 -0
- package/dist/lib/core/checks.js +119 -0
- package/dist/lib/core/doc-graph.d.ts +60 -0
- package/dist/lib/core/doc-graph.js +235 -0
- package/dist/lib/core/health.d.ts +103 -0
- package/dist/lib/core/health.js +538 -0
- package/dist/lib/core/registry.d.ts +296 -0
- package/dist/lib/core/registry.js +317 -0
- package/dist/lib/core/release.d.ts +334 -0
- package/dist/lib/core/release.js +465 -0
- package/dist/lib/generators/memory-generator.d.ts +83 -0
- package/{lib → dist/lib}/generators/memory-generator.js +107 -178
- package/dist/lib/generators/nest-generator.d.ts +15 -0
- package/{lib → dist/lib}/generators/nest-generator.js +47 -71
- package/dist/lib/generators/readme-generator.d.ts +15 -0
- package/{lib → dist/lib}/generators/readme-generator.js +9 -14
- package/dist/lib/governance-report.d.ts +49 -0
- package/dist/lib/governance-report.js +170 -0
- package/dist/lib/templates/harness/code-intel.d.mts +2 -0
- package/dist/lib/templates/harness/code-intel.mjs +126 -0
- package/dist/lib/utils/file-helpers.d.ts +9 -0
- package/dist/lib/utils/file-helpers.js +34 -0
- package/dist/lib/validators/structure-validator.d.ts +48 -0
- package/dist/lib/validators/structure-validator.js +232 -0
- package/dist/lib/workspace.d.ts +40 -0
- package/dist/lib/workspace.js +174 -0
- package/dist/scripts/agent-harness.d.ts +2 -0
- package/dist/scripts/agent-harness.js +556 -0
- package/dist/scripts/agent-router.d.ts +30 -0
- package/dist/scripts/agent-router.js +208 -0
- package/dist/scripts/audit-query.d.ts +2 -0
- package/dist/scripts/audit-query.js +43 -0
- package/dist/scripts/audit-sync.d.ts +2 -0
- package/dist/scripts/audit-sync.js +19 -0
- package/dist/scripts/build-smart-context.d.ts +1 -0
- package/dist/scripts/build-smart-context.js +75 -0
- package/dist/scripts/check-standards.d.ts +1 -0
- package/dist/scripts/check-standards.js +87 -0
- package/dist/scripts/compress-memory.d.ts +16 -0
- package/dist/scripts/compress-memory.js +157 -0
- package/dist/scripts/compress-project-memory.d.ts +1 -0
- package/dist/scripts/compress-project-memory.js +48 -0
- package/dist/scripts/context-ops.d.ts +2 -0
- package/dist/scripts/context-ops.js +464 -0
- package/dist/scripts/dev.d.ts +96 -0
- package/dist/scripts/dev.js +312 -0
- package/dist/scripts/extract-global-knowledge.d.ts +1 -0
- package/dist/scripts/extract-global-knowledge.js +43 -0
- package/dist/scripts/generate-dashboard.d.ts +1 -0
- package/dist/scripts/generate-dashboard.js +48 -0
- package/dist/scripts/governance-dashboard.d.ts +2 -0
- package/dist/scripts/governance-dashboard.js +36 -0
- package/dist/scripts/hook-guard-paths.d.ts +17 -0
- package/dist/scripts/hook-guard-paths.js +68 -0
- package/dist/scripts/hook-post-edit.d.ts +20 -0
- package/dist/scripts/hook-post-edit.js +70 -0
- package/dist/scripts/hook-session-start.d.ts +17 -0
- package/dist/scripts/hook-session-start.js +108 -0
- package/dist/scripts/hook-user-prompt.d.ts +22 -0
- package/dist/scripts/hook-user-prompt.js +193 -0
- package/dist/scripts/memory-schema.d.ts +6 -0
- package/{scripts/memory-schema.mjs → dist/scripts/memory-schema.js} +27 -20
- package/dist/scripts/query-universal-memory.d.ts +1 -0
- package/dist/scripts/query-universal-memory.js +44 -0
- package/dist/scripts/release-check.d.ts +14 -0
- package/dist/scripts/release-check.js +48 -0
- package/dist/scripts/spec-cli.d.ts +29 -0
- package/dist/scripts/spec-cli.js +261 -0
- package/dist/scripts/sprint-manager.d.ts +1 -0
- package/dist/scripts/sprint-manager.js +187 -0
- package/dist/scripts/sync-universal-memory.d.ts +1 -0
- package/dist/scripts/sync-universal-memory.js +277 -0
- package/dist/scripts/token-benchmark.d.ts +20 -0
- package/dist/scripts/token-benchmark.js +181 -0
- package/dist/scripts/tools-doctor.d.ts +20 -0
- package/dist/scripts/tools-doctor.js +120 -0
- package/memory/90-decisions/0028-governanca-visivel.md +84 -0
- package/package.json +54 -56
- package/specs/governanca-visivel/plan.md +122 -0
- package/specs/governanca-visivel/spec.md +112 -0
- package/specs/governanca-visivel/tasks.md +60 -0
- package/specs/ts-migration/plan.md +24 -13
- package/bin/create-memory-nest-kit.js +0 -125
- package/bin/forja.mjs +0 -143
- package/bin/init-project.js +0 -612
- package/lib/context-builder.js +0 -257
- package/lib/core/checks.mjs +0 -155
- package/lib/core/doc-graph.mjs +0 -231
- package/lib/core/health.mjs +0 -577
- package/lib/core/registry.mjs +0 -312
- package/lib/core/release.mjs +0 -492
- package/lib/templates/harness/code-intel.mjs +0 -119
- package/lib/templates/harness/mcp.json +0 -10
- package/lib/utils/file-helpers.js +0 -40
- package/lib/validators/structure-validator.js +0 -253
- package/lib/workspace.mjs +0 -213
- package/scripts/agent-harness.mjs +0 -580
- package/scripts/agent-router.mjs +0 -189
- package/scripts/build-smart-context.js +0 -87
- package/scripts/check-standards.js +0 -98
- package/scripts/compress-memory.mjs +0 -198
- package/scripts/compress-project-memory.js +0 -58
- package/scripts/context-ops.mjs +0 -466
- package/scripts/dev.mjs +0 -349
- package/scripts/extract-global-knowledge.js +0 -52
- package/scripts/generate-dashboard.js +0 -59
- package/scripts/hook-guard-paths.mjs +0 -76
- package/scripts/hook-post-edit.mjs +0 -79
- package/scripts/hook-session-start.mjs +0 -104
- package/scripts/hook-user-prompt.mjs +0 -185
- package/scripts/pre-commit.sh +0 -102
- package/scripts/query-universal-memory.js +0 -50
- package/scripts/release-check.mjs +0 -56
- package/scripts/spec-cli.mjs +0 -261
- package/scripts/sprint-manager.js +0 -200
- package/scripts/sync-universal-memory.js +0 -286
- package/scripts/token-benchmark.mjs +0 -203
- package/scripts/tools-doctor.mjs +0 -132
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Funções utilitárias compartilhadas para geração de arquivos
|
|
3
|
+
*/
|
|
4
|
+
export function ensureDir(dirPath: any): void;
|
|
5
|
+
export function writeFileSafe(filePath: any, content: any, options?: {}): void;
|
|
6
|
+
export function maybeGitkeep(dirPath: any, options?: {}): void;
|
|
7
|
+
export function log(message: any): void;
|
|
8
|
+
export function logError(message: any): void;
|
|
9
|
+
export function logSuccess(message: any): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Funções utilitárias compartilhadas para geração de arquivos
|
|
5
|
+
*/
|
|
6
|
+
export function ensureDir(dirPath) {
|
|
7
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
8
|
+
}
|
|
9
|
+
export function writeFileSafe(filePath, content, options = {}) {
|
|
10
|
+
const { force = false } = options;
|
|
11
|
+
if (fs.existsSync(filePath) && !force) {
|
|
12
|
+
throw new Error(`Arquivo ja existe: ${filePath}. Use --force para sobrescrever.`);
|
|
13
|
+
}
|
|
14
|
+
ensureDir(path.dirname(filePath));
|
|
15
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
16
|
+
}
|
|
17
|
+
export function maybeGitkeep(dirPath, options = {}) {
|
|
18
|
+
const { noGitkeep = false } = options;
|
|
19
|
+
if (noGitkeep)
|
|
20
|
+
return;
|
|
21
|
+
const keepFile = path.join(dirPath, '.gitkeep');
|
|
22
|
+
if (!fs.existsSync(keepFile)) {
|
|
23
|
+
fs.writeFileSync(keepFile, '', 'utf8');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function log(message) {
|
|
27
|
+
console.log(message);
|
|
28
|
+
}
|
|
29
|
+
export function logError(message) {
|
|
30
|
+
console.error(`❌ ${message}`);
|
|
31
|
+
}
|
|
32
|
+
export function logSuccess(message) {
|
|
33
|
+
console.log(`✅ ${message}`);
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Valida estrutura de memória
|
|
3
|
+
* @param {string} baseDir - Diretório base
|
|
4
|
+
* @returns {Object} Resultado da validação
|
|
5
|
+
*/
|
|
6
|
+
export function validateMemoryStructure(baseDir: string): any;
|
|
7
|
+
/**
|
|
8
|
+
* Valida estrutura NestJS
|
|
9
|
+
* @param {string} baseDir - Diretório base
|
|
10
|
+
* @returns {Object} Resultado da validação
|
|
11
|
+
*/
|
|
12
|
+
export function validateNestStructure(baseDir: string): any;
|
|
13
|
+
/**
|
|
14
|
+
* Valida estrutura completa do projeto
|
|
15
|
+
* @param {string} baseDir - Diretório base
|
|
16
|
+
* @param {Object} options - Opções { includeNest: boolean }
|
|
17
|
+
* @returns {Object} Resultado completo
|
|
18
|
+
*/
|
|
19
|
+
export function validateProjectStructure(baseDir: string, options?: any): any;
|
|
20
|
+
/**
|
|
21
|
+
* Imprime relatório de validação de forma amigável
|
|
22
|
+
* @param {Object} report - Resultado de validateProjectStructure
|
|
23
|
+
*/
|
|
24
|
+
export function printValidationReport(report: any): void;
|
|
25
|
+
declare namespace _default {
|
|
26
|
+
export { validateProjectStructure };
|
|
27
|
+
export { validateMemoryStructure };
|
|
28
|
+
export { validateNestStructure };
|
|
29
|
+
export { printValidationReport };
|
|
30
|
+
export { CRITICAL_FILES };
|
|
31
|
+
export { CRITICAL_DIRS };
|
|
32
|
+
export { NEST_CRITICAL_FILES };
|
|
33
|
+
export { NEST_CRITICAL_DIRS };
|
|
34
|
+
}
|
|
35
|
+
export default _default;
|
|
36
|
+
/**
|
|
37
|
+
* Lista dos arquivos críticos que devem existir
|
|
38
|
+
*/
|
|
39
|
+
declare const CRITICAL_FILES: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Lista de diretórios críticos
|
|
42
|
+
*/
|
|
43
|
+
declare const CRITICAL_DIRS: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Validações específicas do NestJS backend
|
|
46
|
+
*/
|
|
47
|
+
declare const NEST_CRITICAL_FILES: string[];
|
|
48
|
+
declare const NEST_CRITICAL_DIRS: string[];
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structure Validator - Valida integridade da estrutura gerada
|
|
3
|
+
* Garante que todos os diretórios e arquivos críticos foram criados
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
/**
|
|
8
|
+
* Lista dos arquivos críticos que devem existir
|
|
9
|
+
*/
|
|
10
|
+
const CRITICAL_FILES = [
|
|
11
|
+
'memory/00-global/mission.md',
|
|
12
|
+
'memory/00-global/standards.md',
|
|
13
|
+
'memory/10-product/vision.md',
|
|
14
|
+
'memory/20-architecture/backend.md',
|
|
15
|
+
'memory/40-delivery/current-sprint.md',
|
|
16
|
+
'memory/50-orchestration/topology.md',
|
|
17
|
+
'AGENTS.md',
|
|
18
|
+
'.memoryrc.json',
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Lista de diretórios críticos
|
|
22
|
+
*/
|
|
23
|
+
const CRITICAL_DIRS = [
|
|
24
|
+
'memory',
|
|
25
|
+
'memory/00-global',
|
|
26
|
+
'memory/10-product',
|
|
27
|
+
'memory/20-architecture',
|
|
28
|
+
'memory/30-domains',
|
|
29
|
+
'memory/40-delivery',
|
|
30
|
+
'memory/50-orchestration',
|
|
31
|
+
'memory/60-runs',
|
|
32
|
+
'memory/70-summaries',
|
|
33
|
+
'agents',
|
|
34
|
+
'skills',
|
|
35
|
+
'prompts',
|
|
36
|
+
'.memory/sqlite',
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Validações específicas do NestJS backend
|
|
40
|
+
*/
|
|
41
|
+
const NEST_CRITICAL_FILES = [
|
|
42
|
+
'backend/package.json',
|
|
43
|
+
'backend/src/main.ts',
|
|
44
|
+
'backend/src/app.module.ts',
|
|
45
|
+
'backend/src/app.controller.ts',
|
|
46
|
+
'backend/src/app.service.ts',
|
|
47
|
+
'backend/tsconfig.json',
|
|
48
|
+
];
|
|
49
|
+
const NEST_CRITICAL_DIRS = [
|
|
50
|
+
'backend/src',
|
|
51
|
+
'backend/src/modules/ops',
|
|
52
|
+
'backend/test',
|
|
53
|
+
'backend/scripts',
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Valida estrutura de memória
|
|
57
|
+
* @param {string} baseDir - Diretório base
|
|
58
|
+
* @returns {Object} Resultado da validação
|
|
59
|
+
*/
|
|
60
|
+
export function validateMemoryStructure(baseDir) {
|
|
61
|
+
const errors = [];
|
|
62
|
+
const warnings = [];
|
|
63
|
+
// Validar arquivos críticos
|
|
64
|
+
for (const filePath of CRITICAL_FILES) {
|
|
65
|
+
const abs = path.join(baseDir, filePath);
|
|
66
|
+
if (!fs.existsSync(abs)) {
|
|
67
|
+
errors.push(`Arquivo crítico não encontrado: ${filePath}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Validar diretórios críticos
|
|
71
|
+
for (const dirPath of CRITICAL_DIRS) {
|
|
72
|
+
const abs = path.join(baseDir, dirPath);
|
|
73
|
+
if (!fs.existsSync(abs)) {
|
|
74
|
+
errors.push(`Diretório crítico não encontrado: ${dirPath}`);
|
|
75
|
+
}
|
|
76
|
+
else if (!fs.statSync(abs).isDirectory()) {
|
|
77
|
+
errors.push(`Não é um diretório: ${dirPath}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Validar conteúdo de mission.md
|
|
81
|
+
const missionPath = path.join(baseDir, 'memory/00-global/mission.md');
|
|
82
|
+
if (fs.existsSync(missionPath)) {
|
|
83
|
+
const content = fs.readFileSync(missionPath, 'utf8');
|
|
84
|
+
if (!content.includes('Missao') && !content.includes('Missão')) {
|
|
85
|
+
warnings.push('mission.md parece estar vazio ou incorreto');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Validar .memoryrc.json é JSON válido
|
|
89
|
+
const memoryrcPath = path.join(baseDir, '.memoryrc.json');
|
|
90
|
+
if (fs.existsSync(memoryrcPath)) {
|
|
91
|
+
try {
|
|
92
|
+
const content = fs.readFileSync(memoryrcPath, 'utf8');
|
|
93
|
+
JSON.parse(content);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
errors.push('.memoryrc.json é JSON inválido');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
isValid: errors.length === 0,
|
|
101
|
+
errors,
|
|
102
|
+
warnings,
|
|
103
|
+
checklist: {
|
|
104
|
+
memoryStructure: CRITICAL_DIRS.length,
|
|
105
|
+
memoryFiles: CRITICAL_FILES.length,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Valida estrutura NestJS
|
|
111
|
+
* @param {string} baseDir - Diretório base
|
|
112
|
+
* @returns {Object} Resultado da validação
|
|
113
|
+
*/
|
|
114
|
+
export function validateNestStructure(baseDir) {
|
|
115
|
+
const errors = [];
|
|
116
|
+
const warnings = [];
|
|
117
|
+
// Validar arquivos críticos do NestJS
|
|
118
|
+
for (const filePath of NEST_CRITICAL_FILES) {
|
|
119
|
+
const abs = path.join(baseDir, filePath);
|
|
120
|
+
if (!fs.existsSync(abs)) {
|
|
121
|
+
errors.push(`Arquivo NestJS não encontrado: ${filePath}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Validar diretórios críticos do NestJS
|
|
125
|
+
for (const dirPath of NEST_CRITICAL_DIRS) {
|
|
126
|
+
const abs = path.join(baseDir, dirPath);
|
|
127
|
+
if (!fs.existsSync(abs)) {
|
|
128
|
+
errors.push(`Diretório NestJS não encontrado: ${dirPath}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Validar package.json
|
|
132
|
+
const pkgPath = path.join(baseDir, 'backend/package.json');
|
|
133
|
+
if (fs.existsSync(pkgPath)) {
|
|
134
|
+
try {
|
|
135
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
136
|
+
if (!pkg.dependencies['@nestjs/common']) {
|
|
137
|
+
errors.push('package.json não contém @nestjs/common');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
errors.push('backend/package.json é JSON inválido');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Validar tsconfig.json
|
|
145
|
+
const tsconfigPath = path.join(baseDir, 'backend/tsconfig.json');
|
|
146
|
+
if (fs.existsSync(tsconfigPath)) {
|
|
147
|
+
try {
|
|
148
|
+
JSON.parse(fs.readFileSync(tsconfigPath, 'utf8'));
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
errors.push('backend/tsconfig.json é JSON inválido');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
isValid: errors.length === 0,
|
|
156
|
+
errors,
|
|
157
|
+
warnings,
|
|
158
|
+
checklist: {
|
|
159
|
+
nestDirectories: NEST_CRITICAL_DIRS.length,
|
|
160
|
+
nestFiles: NEST_CRITICAL_FILES.length,
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Valida estrutura completa do projeto
|
|
166
|
+
* @param {string} baseDir - Diretório base
|
|
167
|
+
* @param {Object} options - Opções { includeNest: boolean }
|
|
168
|
+
* @returns {Object} Resultado completo
|
|
169
|
+
*/
|
|
170
|
+
export function validateProjectStructure(baseDir, options = {}) {
|
|
171
|
+
const { includeNest = false } = options;
|
|
172
|
+
const memoryResult = validateMemoryStructure(baseDir);
|
|
173
|
+
const results = { memory: memoryResult };
|
|
174
|
+
if (includeNest) {
|
|
175
|
+
results.nest = validateNestStructure(baseDir);
|
|
176
|
+
}
|
|
177
|
+
const allErrors = [
|
|
178
|
+
...memoryResult.errors,
|
|
179
|
+
...(results.nest?.errors || []),
|
|
180
|
+
];
|
|
181
|
+
return {
|
|
182
|
+
isValid: allErrors.length === 0,
|
|
183
|
+
errors: allErrors,
|
|
184
|
+
warnings: [
|
|
185
|
+
...memoryResult.warnings,
|
|
186
|
+
...(results.nest?.warnings || []),
|
|
187
|
+
],
|
|
188
|
+
results,
|
|
189
|
+
summary: {
|
|
190
|
+
totalErrors: allErrors.length,
|
|
191
|
+
hasNest: includeNest,
|
|
192
|
+
timestamp: new Date().toISOString(),
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Imprime relatório de validação de forma amigável
|
|
198
|
+
* @param {Object} report - Resultado de validateProjectStructure
|
|
199
|
+
*/
|
|
200
|
+
export function printValidationReport(report) {
|
|
201
|
+
if (report.isValid) {
|
|
202
|
+
console.log('✅ Estrutura do projeto é válida!');
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
console.log('❌ Estrutura do projeto tem problemas:');
|
|
206
|
+
console.log('');
|
|
207
|
+
for (const error of report.errors) {
|
|
208
|
+
console.log(` ❌ ${error}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (report.warnings.length > 0) {
|
|
212
|
+
console.log('');
|
|
213
|
+
console.log('⚠️ Avisos:');
|
|
214
|
+
for (const warning of report.warnings) {
|
|
215
|
+
console.log(` ⚠️ ${warning}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (report.summary) {
|
|
219
|
+
console.log('');
|
|
220
|
+
console.log(`📊 Verificado em: ${report.summary.timestamp}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export default {
|
|
224
|
+
validateProjectStructure,
|
|
225
|
+
validateMemoryStructure,
|
|
226
|
+
validateNestStructure,
|
|
227
|
+
printValidationReport,
|
|
228
|
+
CRITICAL_FILES,
|
|
229
|
+
CRITICAL_DIRS,
|
|
230
|
+
NEST_CRITICAL_FILES,
|
|
231
|
+
NEST_CRITICAL_DIRS,
|
|
232
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/workspace.mjs
|
|
3
|
+
*
|
|
4
|
+
* Centraliza a resolução de caminhos do workspace Forja.
|
|
5
|
+
*
|
|
6
|
+
* Regras de prioridade para descobrir o workspace:
|
|
7
|
+
* 1. Variável de ambiente FORJA_WORKSPACE
|
|
8
|
+
* 2. Arquivo ~/.forjarc.json (campo workspaceRoot)
|
|
9
|
+
* 3. Default: ~/forja-workspace
|
|
10
|
+
*
|
|
11
|
+
* O workspace é o "canto fixo" onde projetos de produto vivem:
|
|
12
|
+
* ~/forja-workspace/
|
|
13
|
+
* projects/ # projetos gerados
|
|
14
|
+
* memory/ # memória universal do workspace
|
|
15
|
+
* sqlite/universal.db # SQLite FTS5
|
|
16
|
+
* 30-projects/ # fichas de projetos
|
|
17
|
+
* specs/ # specs de produto
|
|
18
|
+
* .context/ # runbooks GSD de produto
|
|
19
|
+
* .forjarc.json # config local do workspace (opcional)
|
|
20
|
+
*/
|
|
21
|
+
export declare function getUserConfigPath(): string;
|
|
22
|
+
export declare function getWorkspaceRoot(): string;
|
|
23
|
+
export declare function getWorkspaceInfo(): {
|
|
24
|
+
root: string;
|
|
25
|
+
source: string;
|
|
26
|
+
exists: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function getProjectsDir(): string;
|
|
29
|
+
export declare function getWorkspaceMemoryDir(): string;
|
|
30
|
+
export declare function getWorkspaceDbDir(): string;
|
|
31
|
+
export declare function getWorkspaceDbPath(): string;
|
|
32
|
+
export declare function getWorkspaceProjectsMemoryDir(): string;
|
|
33
|
+
export declare function getWorkspaceSpecsDir(): string;
|
|
34
|
+
export declare function getWorkspaceContextDir(): string;
|
|
35
|
+
export declare function resolveProject(name: any): string;
|
|
36
|
+
export declare function listProjects(): string[];
|
|
37
|
+
export declare function ensureDir(dir: any): any;
|
|
38
|
+
export declare function initWorkspace(): any;
|
|
39
|
+
export declare function isInsideFrameworkRepo(filePath: any): boolean;
|
|
40
|
+
export declare function assertOutsideFrameworkRepo(filePath: any, operation?: string): void;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/workspace.mjs
|
|
3
|
+
*
|
|
4
|
+
* Centraliza a resolução de caminhos do workspace Forja.
|
|
5
|
+
*
|
|
6
|
+
* Regras de prioridade para descobrir o workspace:
|
|
7
|
+
* 1. Variável de ambiente FORJA_WORKSPACE
|
|
8
|
+
* 2. Arquivo ~/.forjarc.json (campo workspaceRoot)
|
|
9
|
+
* 3. Default: ~/forja-workspace
|
|
10
|
+
*
|
|
11
|
+
* O workspace é o "canto fixo" onde projetos de produto vivem:
|
|
12
|
+
* ~/forja-workspace/
|
|
13
|
+
* projects/ # projetos gerados
|
|
14
|
+
* memory/ # memória universal do workspace
|
|
15
|
+
* sqlite/universal.db # SQLite FTS5
|
|
16
|
+
* 30-projects/ # fichas de projetos
|
|
17
|
+
* specs/ # specs de produto
|
|
18
|
+
* .context/ # runbooks GSD de produto
|
|
19
|
+
* .forjarc.json # config local do workspace (opcional)
|
|
20
|
+
*/
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import os from 'node:os';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = path.dirname(__filename);
|
|
27
|
+
const DEFAULT_WORKSPACE_NAME = 'forja-workspace';
|
|
28
|
+
function getHomeDir() {
|
|
29
|
+
return os.homedir();
|
|
30
|
+
}
|
|
31
|
+
function readJsonSafe(filePath) {
|
|
32
|
+
try {
|
|
33
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
34
|
+
return JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function getUserConfigPath() {
|
|
41
|
+
return path.join(getHomeDir(), '.forjarc.json');
|
|
42
|
+
}
|
|
43
|
+
export function getWorkspaceRoot() {
|
|
44
|
+
if (process.env.FORJA_WORKSPACE) {
|
|
45
|
+
return path.resolve(process.env.FORJA_WORKSPACE);
|
|
46
|
+
}
|
|
47
|
+
const userConfig = readJsonSafe(getUserConfigPath());
|
|
48
|
+
if (userConfig?.workspaceRoot) {
|
|
49
|
+
return path.resolve(userConfig.workspaceRoot);
|
|
50
|
+
}
|
|
51
|
+
return path.join(getHomeDir(), DEFAULT_WORKSPACE_NAME);
|
|
52
|
+
}
|
|
53
|
+
export function getWorkspaceInfo() {
|
|
54
|
+
const root = getWorkspaceRoot();
|
|
55
|
+
return {
|
|
56
|
+
root,
|
|
57
|
+
source: process.env.FORJA_WORKSPACE
|
|
58
|
+
? 'FORJA_WORKSPACE'
|
|
59
|
+
: fs.existsSync(getUserConfigPath())
|
|
60
|
+
? '~/.forjarc.json'
|
|
61
|
+
: 'default',
|
|
62
|
+
exists: fs.existsSync(root),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function getProjectsDir() {
|
|
66
|
+
return path.join(getWorkspaceRoot(), 'projects');
|
|
67
|
+
}
|
|
68
|
+
export function getWorkspaceMemoryDir() {
|
|
69
|
+
return path.join(getWorkspaceRoot(), 'memory');
|
|
70
|
+
}
|
|
71
|
+
export function getWorkspaceDbDir() {
|
|
72
|
+
return path.join(getWorkspaceMemoryDir(), 'sqlite');
|
|
73
|
+
}
|
|
74
|
+
export function getWorkspaceDbPath() {
|
|
75
|
+
return path.join(getWorkspaceDbDir(), 'universal.db');
|
|
76
|
+
}
|
|
77
|
+
export function getWorkspaceProjectsMemoryDir() {
|
|
78
|
+
return path.join(getWorkspaceMemoryDir(), '30-projects');
|
|
79
|
+
}
|
|
80
|
+
export function getWorkspaceSpecsDir() {
|
|
81
|
+
return path.join(getWorkspaceRoot(), 'specs');
|
|
82
|
+
}
|
|
83
|
+
export function getWorkspaceContextDir() {
|
|
84
|
+
return path.join(getWorkspaceRoot(), '.context');
|
|
85
|
+
}
|
|
86
|
+
export function resolveProject(name) {
|
|
87
|
+
if (!name || typeof name !== 'string') {
|
|
88
|
+
throw new Error('Nome do projeto é obrigatório');
|
|
89
|
+
}
|
|
90
|
+
const safe = name.toLowerCase().replace(/[^a-z0-9._-]+/g, '-');
|
|
91
|
+
if (!safe) {
|
|
92
|
+
throw new Error(`Nome de projeto inválido: ${name}`);
|
|
93
|
+
}
|
|
94
|
+
return path.join(getProjectsDir(), safe);
|
|
95
|
+
}
|
|
96
|
+
export function listProjects() {
|
|
97
|
+
const dir = getProjectsDir();
|
|
98
|
+
if (!fs.existsSync(dir))
|
|
99
|
+
return [];
|
|
100
|
+
return fs
|
|
101
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
102
|
+
.filter((entry) => entry.isDirectory())
|
|
103
|
+
.map((entry) => entry.name);
|
|
104
|
+
}
|
|
105
|
+
export function ensureDir(dir) {
|
|
106
|
+
if (!fs.existsSync(dir)) {
|
|
107
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
108
|
+
}
|
|
109
|
+
return dir;
|
|
110
|
+
}
|
|
111
|
+
export function initWorkspace() {
|
|
112
|
+
const root = ensureDir(getWorkspaceRoot());
|
|
113
|
+
ensureDir(getProjectsDir());
|
|
114
|
+
ensureDir(getWorkspaceMemoryDir());
|
|
115
|
+
ensureDir(getWorkspaceDbDir());
|
|
116
|
+
ensureDir(getWorkspaceProjectsMemoryDir());
|
|
117
|
+
ensureDir(getWorkspaceSpecsDir());
|
|
118
|
+
ensureDir(getWorkspaceContextDir());
|
|
119
|
+
// Cria README de convenção no workspace
|
|
120
|
+
const readmePath = path.join(root, 'README.md');
|
|
121
|
+
if (!fs.existsSync(readmePath)) {
|
|
122
|
+
fs.writeFileSync(readmePath, `# Forja Workspace
|
|
123
|
+
|
|
124
|
+
Este é o workspace de produção do Forja. Aqui vivem projetos gerados, memória universal e specs de produto.
|
|
125
|
+
|
|
126
|
+
## Estrutura
|
|
127
|
+
|
|
128
|
+
- \`projects/\` — projetos gerados pelo Forja.
|
|
129
|
+
- \`memory/sqlite/universal.db\` — memória universal indexada (SQLite + FTS5).
|
|
130
|
+
- \`memory/30-projects/\` — fichas dos projetos.
|
|
131
|
+
- \`specs/\` — specs de produto.
|
|
132
|
+
- \`.context/\` — runbooks GSD de produto.
|
|
133
|
+
|
|
134
|
+
## Configuração
|
|
135
|
+
|
|
136
|
+
O caminho do workspace é resolvido por prioridade:
|
|
137
|
+
|
|
138
|
+
1. Variável \`FORJA_WORKSPACE\`
|
|
139
|
+
2. Campo \`workspaceRoot\` em \`~/.forjarc.json\`
|
|
140
|
+
3. Padrão: \`~/forja-workspace\`
|
|
141
|
+
|
|
142
|
+
## Comandos úteis
|
|
143
|
+
|
|
144
|
+
- \`npm run dev -- workspace:init\` — recria estrutura base.
|
|
145
|
+
- \`npm run dev -- project:new <nome>\` — cria novo projeto.
|
|
146
|
+
- \`npm run dev -- project:list\` — lista projetos.
|
|
147
|
+
- \`npm run dev -- project:check <nome>\` — valida padrões.
|
|
148
|
+
`, 'utf8');
|
|
149
|
+
}
|
|
150
|
+
// Cria .forjarc.json local apenas se não houver config global
|
|
151
|
+
const localConfigPath = path.join(root, '.forjarc.json');
|
|
152
|
+
if (!fs.existsSync(localConfigPath) && !fs.existsSync(getUserConfigPath()) && !process.env.FORJA_WORKSPACE) {
|
|
153
|
+
fs.writeFileSync(localConfigPath, JSON.stringify({ workspaceRoot: root }, null, 2) + '\n', 'utf8');
|
|
154
|
+
}
|
|
155
|
+
// Cria README em 30-projects
|
|
156
|
+
const projectsMemoryReadme = path.join(getWorkspaceProjectsMemoryDir(), 'README.md');
|
|
157
|
+
if (!fs.existsSync(projectsMemoryReadme)) {
|
|
158
|
+
fs.writeFileSync(projectsMemoryReadme, `# Projetos do Workspace
|
|
159
|
+
|
|
160
|
+
Fichas de projetos gerados pelo Forja. Cada arquivo representa um produto ativo ou arquivado.
|
|
161
|
+
`, 'utf8');
|
|
162
|
+
}
|
|
163
|
+
return root;
|
|
164
|
+
}
|
|
165
|
+
export function isInsideFrameworkRepo(filePath) {
|
|
166
|
+
const frameworkRoot = path.resolve(__dirname, '..');
|
|
167
|
+
const resolved = path.resolve(filePath);
|
|
168
|
+
return resolved === frameworkRoot || resolved.startsWith(frameworkRoot + path.sep);
|
|
169
|
+
}
|
|
170
|
+
export function assertOutsideFrameworkRepo(filePath, operation = 'operacao') {
|
|
171
|
+
if (isInsideFrameworkRepo(filePath)) {
|
|
172
|
+
throw new Error(`${operation} não pode ser executada dentro do repositório do framework Forja. Use o workspace externo (~/forja-workspace).`);
|
|
173
|
+
}
|
|
174
|
+
}
|