up-cc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/agents/up-depurador.md +357 -0
  2. package/agents/up-executor.md +409 -0
  3. package/agents/up-pesquisador-projeto.md +358 -0
  4. package/agents/up-planejador.md +390 -0
  5. package/agents/up-roteirista.md +401 -0
  6. package/agents/up-sintetizador.md +232 -0
  7. package/agents/up-verificador.md +357 -0
  8. package/bin/install.js +709 -0
  9. package/bin/lib/core.cjs +270 -0
  10. package/bin/up-tools.cjs +1361 -0
  11. package/commands/adicionar-fase.md +33 -0
  12. package/commands/ajuda.md +131 -0
  13. package/commands/discutir-fase.md +35 -0
  14. package/commands/executar-fase.md +40 -0
  15. package/commands/novo-projeto.md +39 -0
  16. package/commands/pausar.md +33 -0
  17. package/commands/planejar-fase.md +43 -0
  18. package/commands/progresso.md +33 -0
  19. package/commands/rapido.md +40 -0
  20. package/commands/remover-fase.md +34 -0
  21. package/commands/retomar.md +35 -0
  22. package/commands/verificar-trabalho.md +35 -0
  23. package/package.json +32 -0
  24. package/references/checkpoints.md +358 -0
  25. package/references/git-integration.md +208 -0
  26. package/references/questioning.md +156 -0
  27. package/references/ui-brand.md +124 -0
  28. package/templates/config.json +6 -0
  29. package/templates/continue-here.md +78 -0
  30. package/templates/project.md +184 -0
  31. package/templates/requirements.md +129 -0
  32. package/templates/roadmap.md +131 -0
  33. package/templates/state.md +130 -0
  34. package/templates/summary.md +174 -0
  35. package/workflows/discutir-fase.md +324 -0
  36. package/workflows/executar-fase.md +277 -0
  37. package/workflows/executar-plano.md +192 -0
  38. package/workflows/novo-projeto.md +561 -0
  39. package/workflows/pausar.md +111 -0
  40. package/workflows/planejar-fase.md +208 -0
  41. package/workflows/progresso.md +226 -0
  42. package/workflows/rapido.md +209 -0
  43. package/workflows/retomar.md +231 -0
  44. package/workflows/verificar-trabalho.md +261 -0
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Core — Shared utilities, constants, and internal helpers for UP CLI
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { execSync } = require('child_process');
8
+
9
+ // --- Path helpers ---
10
+
11
+ /** Normalize a relative path to always use forward slashes (cross-platform). */
12
+ function toPosixPath(p) {
13
+ return p.split(path.sep).join('/');
14
+ }
15
+
16
+ // --- Output helpers ---
17
+
18
+ function output(result, raw, rawValue) {
19
+ if (raw && rawValue !== undefined) {
20
+ process.stdout.write(String(rawValue));
21
+ } else {
22
+ const json = JSON.stringify(result, null, 2);
23
+ if (json.length > 50000) {
24
+ const tmpPath = path.join(require('os').tmpdir(), `up-${Date.now()}.json`);
25
+ fs.writeFileSync(tmpPath, json, 'utf-8');
26
+ process.stdout.write('@file:' + tmpPath);
27
+ } else {
28
+ process.stdout.write(json);
29
+ }
30
+ }
31
+ process.exit(0);
32
+ }
33
+
34
+ function error(message) {
35
+ process.stderr.write('Error: ' + message + '\n');
36
+ process.exit(1);
37
+ }
38
+
39
+ // --- File & Config utilities ---
40
+
41
+ function safeReadFile(filePath) {
42
+ try {
43
+ return fs.readFileSync(filePath, 'utf-8');
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+
49
+ function loadConfig(cwd) {
50
+ const configPath = path.join(cwd, '.plano', 'config.json');
51
+ const defaults = {
52
+ modo: 'solo',
53
+ paralelizacao: true,
54
+ commit_docs: true,
55
+ auto_advance: false,
56
+ };
57
+
58
+ try {
59
+ const raw = fs.readFileSync(configPath, 'utf-8');
60
+ const parsed = JSON.parse(raw);
61
+
62
+ return {
63
+ modo: parsed.modo ?? defaults.modo,
64
+ paralelizacao: parsed.paralelizacao ?? defaults.paralelizacao,
65
+ commit_docs: parsed.commit_docs ?? defaults.commit_docs,
66
+ auto_advance: parsed.auto_advance ?? defaults.auto_advance,
67
+ };
68
+ } catch {
69
+ return defaults;
70
+ }
71
+ }
72
+
73
+ // --- Git utilities ---
74
+
75
+ function isGitIgnored(cwd, targetPath) {
76
+ try {
77
+ execSync('git check-ignore -q --no-index -- ' + targetPath.replace(/[^a-zA-Z0-9._\-/]/g, ''), {
78
+ cwd,
79
+ stdio: 'pipe',
80
+ });
81
+ return true;
82
+ } catch {
83
+ return false;
84
+ }
85
+ }
86
+
87
+ function execGit(cwd, args) {
88
+ try {
89
+ const escaped = args.map(a => {
90
+ if (/^[a-zA-Z0-9._\-/=:@]+$/.test(a)) return a;
91
+ return "'" + a.replace(/'/g, "'\\''") + "'";
92
+ });
93
+ const stdout = execSync('git ' + escaped.join(' '), {
94
+ cwd,
95
+ stdio: 'pipe',
96
+ encoding: 'utf-8',
97
+ });
98
+ return { exitCode: 0, stdout: stdout.trim(), stderr: '' };
99
+ } catch (err) {
100
+ return {
101
+ exitCode: err.status ?? 1,
102
+ stdout: (err.stdout ?? '').toString().trim(),
103
+ stderr: (err.stderr ?? '').toString().trim(),
104
+ };
105
+ }
106
+ }
107
+
108
+ // --- Phase utilities ---
109
+
110
+ function escapeRegex(value) {
111
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
112
+ }
113
+
114
+ function normalizePhaseName(phase) {
115
+ const match = String(phase).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
116
+ if (!match) return phase;
117
+ const padded = match[1].padStart(2, '0');
118
+ const letter = match[2] ? match[2].toUpperCase() : '';
119
+ const decimal = match[3] || '';
120
+ return padded + letter + decimal;
121
+ }
122
+
123
+ function comparePhaseNum(a, b) {
124
+ const pa = String(a).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
125
+ const pb = String(b).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
126
+ if (!pa || !pb) return String(a).localeCompare(String(b));
127
+ const intDiff = parseInt(pa[1], 10) - parseInt(pb[1], 10);
128
+ if (intDiff !== 0) return intDiff;
129
+ const la = (pa[2] || '').toUpperCase();
130
+ const lb = (pb[2] || '').toUpperCase();
131
+ if (la !== lb) {
132
+ if (!la) return -1;
133
+ if (!lb) return 1;
134
+ return la < lb ? -1 : 1;
135
+ }
136
+ const aDecParts = pa[3] ? pa[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
137
+ const bDecParts = pb[3] ? pb[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
138
+ const maxLen = Math.max(aDecParts.length, bDecParts.length);
139
+ if (aDecParts.length === 0 && bDecParts.length > 0) return -1;
140
+ if (bDecParts.length === 0 && aDecParts.length > 0) return 1;
141
+ for (let i = 0; i < maxLen; i++) {
142
+ const av = Number.isFinite(aDecParts[i]) ? aDecParts[i] : 0;
143
+ const bv = Number.isFinite(bDecParts[i]) ? bDecParts[i] : 0;
144
+ if (av !== bv) return av - bv;
145
+ }
146
+ return 0;
147
+ }
148
+
149
+ function searchPhaseInDir(baseDir, relBase, normalized) {
150
+ try {
151
+ const entries = fs.readdirSync(baseDir, { withFileTypes: true });
152
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
153
+ const match = dirs.find(d => d.startsWith(normalized));
154
+ if (!match) return null;
155
+
156
+ const dirMatch = match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
157
+ const phaseNumber = dirMatch ? dirMatch[1] : normalized;
158
+ const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
159
+ const phaseDir = path.join(baseDir, match);
160
+ const phaseFiles = fs.readdirSync(phaseDir);
161
+
162
+ const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
163
+ const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
164
+ const hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
165
+ const hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
166
+
167
+ const completedPlanIds = new Set(
168
+ summaries.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', ''))
169
+ );
170
+ const incompletePlans = plans.filter(p => {
171
+ const planId = p.replace('-PLAN.md', '').replace('PLAN.md', '');
172
+ return !completedPlanIds.has(planId);
173
+ });
174
+
175
+ return {
176
+ found: true,
177
+ directory: toPosixPath(path.join(relBase, match)),
178
+ phase_number: phaseNumber,
179
+ phase_name: phaseName,
180
+ phase_slug: phaseName ? phaseName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') : null,
181
+ plans,
182
+ summaries,
183
+ incomplete_plans: incompletePlans,
184
+ has_research: hasResearch,
185
+ has_context: hasContext,
186
+ };
187
+ } catch {
188
+ return null;
189
+ }
190
+ }
191
+
192
+ function findPhaseInternal(cwd, phase) {
193
+ if (!phase) return null;
194
+
195
+ const phasesDir = path.join(cwd, '.plano', 'fases');
196
+ const normalized = normalizePhaseName(phase);
197
+
198
+ return searchPhaseInDir(phasesDir, '.plano/fases', normalized);
199
+ }
200
+
201
+ // --- Roadmap utilities ---
202
+
203
+ function getRoadmapPhaseInternal(cwd, phaseNum) {
204
+ if (!phaseNum) return null;
205
+ const roadmapPath = path.join(cwd, '.plano', 'ROADMAP.md');
206
+ if (!fs.existsSync(roadmapPath)) return null;
207
+
208
+ try {
209
+ const content = fs.readFileSync(roadmapPath, 'utf-8');
210
+ const escapedPhase = escapeRegex(phaseNum.toString());
211
+ const phasePattern = new RegExp(`#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`, 'i');
212
+ const headerMatch = content.match(phasePattern);
213
+ if (!headerMatch) return null;
214
+
215
+ const phaseName = headerMatch[1].trim();
216
+ const headerIndex = headerMatch.index;
217
+ const restOfContent = content.slice(headerIndex);
218
+ const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
219
+ const sectionEnd = nextHeaderMatch ? headerIndex + nextHeaderMatch.index : content.length;
220
+ const section = content.slice(headerIndex, sectionEnd).trim();
221
+
222
+ const goalMatch = section.match(/\*\*Goal:\*\*\s*([^\n]+)/i);
223
+ const goal = goalMatch ? goalMatch[1].trim() : null;
224
+
225
+ return {
226
+ found: true,
227
+ phase_number: phaseNum.toString(),
228
+ phase_name: phaseName,
229
+ goal,
230
+ section,
231
+ };
232
+ } catch {
233
+ return null;
234
+ }
235
+ }
236
+
237
+ // --- Misc utilities ---
238
+
239
+ function pathExistsInternal(cwd, targetPath) {
240
+ const fullPath = path.isAbsolute(targetPath) ? targetPath : path.join(cwd, targetPath);
241
+ try {
242
+ fs.statSync(fullPath);
243
+ return true;
244
+ } catch {
245
+ return false;
246
+ }
247
+ }
248
+
249
+ function generateSlugInternal(text) {
250
+ if (!text) return null;
251
+ return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
252
+ }
253
+
254
+ module.exports = {
255
+ output,
256
+ error,
257
+ safeReadFile,
258
+ loadConfig,
259
+ isGitIgnored,
260
+ execGit,
261
+ escapeRegex,
262
+ normalizePhaseName,
263
+ comparePhaseNum,
264
+ searchPhaseInDir,
265
+ findPhaseInternal,
266
+ getRoadmapPhaseInternal,
267
+ pathExistsInternal,
268
+ generateSlugInternal,
269
+ toPosixPath,
270
+ };