the-crew 0.1.0 → 0.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/README.md +141 -58
- package/core/agents/README.md +1 -1
- package/core/agents/desenvolve/frontend-dev.md +4 -3
- package/core/agents/planeja/ux-ui-design.md +2 -1
- package/core/skills/crew-gates/SKILL.md +1 -1
- package/core/skills/crew-obsidian/SKILL.md +2 -2
- package/core/skills/db-organizer/SKILL.md +1 -1
- package/core/skills/manifest.json +791 -0
- package/core/skills/new-project/SKILL.md +27 -0
- package/core/skills/po-backlog/SKILL.md +1 -1
- package/core/skills/projects/SKILL.md +10 -0
- package/dist/src/cli/commands/exec.js +1 -1
- package/dist/src/cli/commands/install.js +300 -0
- package/dist/src/cli/commands/new-project.js +86 -0
- package/dist/src/cli/commands/projects.js +24 -0
- package/dist/src/cli/commands/uninstall.js +308 -0
- package/dist/src/cli/commands/validate.js +6 -5
- package/dist/src/cli/index.js +26 -21
- package/dist/src/cli/lib/args.js +99 -41
- package/dist/src/cli/lib/common.js +120 -0
- package/dist/src/cli/lib/credentials.js +26 -0
- package/dist/src/cli/lib/github.js +36 -0
- package/dist/src/cli/lib/install-record.js +39 -0
- package/dist/src/cli/lib/legacy.js +230 -0
- package/dist/src/cli/lib/plans.js +251 -0
- package/dist/src/cli/lib/registry.js +21 -0
- package/dist/src/cli/lib/skills.js +186 -0
- package/dist/src/cli/lib/writer.js +13 -2
- package/package.json +10 -3
- package/templates/obsidian/{00 Painel.md → project/00 Painel.md } +4 -6
- package/templates/obsidian/team/00 Time.md +20 -0
- package/templates/office/AGENTS.md +12 -0
- package/templates/office/README.md +15 -0
- package/templates/project/AGENTS.md +5 -0
- package/templates/project/PROJECT.md +31 -0
- package/templates/rules/team.md +14 -0
- package/core/skills/catalog.json +0 -30
- package/dist/src/cli/commands/init.js +0 -185
- package/dist/src/cli/lib/plan.js +0 -300
- package/templates/docs/PROJECT.md +0 -36
- package/templates/entrypoints/crew-block.md +0 -28
- package/templates/entrypoints/cursor.mdc +0 -6
- package/templates/entrypoints/obsidian-rules.md +0 -18
- package/templates/entrypoints/windsurf.md +0 -5
- package/templates/workflows/crew-integrity.yml +0 -24
- /package/templates/obsidian/{_templates → team/_templates}/ADR.md +0 -0
- /package/templates/obsidian/{_templates → team/_templates}/Achado de seguranca.md +0 -0
- /package/templates/obsidian/{_templates → team/_templates}/Bug.md +0 -0
- /package/templates/obsidian/{_templates → team/_templates}/Handoff.md +0 -0
- /package/templates/obsidian/{_templates → team/_templates}/Historia.md +0 -0
- /package/templates/obsidian/{_templates → team/_templates}/Release.md +0 -0
- /package/templates/obsidian/{_templates → team/_templates}/Run.md +0 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
export const IDE_OPTIONS = [
|
|
4
|
+
{ value: 'claude-code', label: 'Claude Code (agentes, skills e /comandos globais em ~/.claude)' },
|
|
5
|
+
{ value: 'codex', label: 'Codex (~/.codex/AGENTS.md e skills globais)' },
|
|
6
|
+
{ value: 'cursor', label: 'Cursor (MCP global; /comandos no escritório e em cada projeto)' },
|
|
7
|
+
{ value: 'windsurf', label: 'Windsurf (workflows /comandos no escritório e em cada projeto)' },
|
|
8
|
+
{ value: 'other', label: 'Outro (Gemini CLI, Copilot…: AGENTS.md)' },
|
|
9
|
+
];
|
|
10
|
+
export const MCP_OPTIONS = [
|
|
11
|
+
{ value: 'github', label: 'GitHub MCP (oficial, remoto; usa o token)' },
|
|
12
|
+
{ value: 'context7', label: 'Context7 (documentação atualizada de bibliotecas)' },
|
|
13
|
+
{ value: 'playwright', label: 'Playwright MCP (navegador para QA e testers)' },
|
|
14
|
+
];
|
|
15
|
+
export function render(template, vars) {
|
|
16
|
+
return template.replace(/\{\{(\w+)\}\}/g, (m, k) => (k in vars ? vars[k] : m));
|
|
17
|
+
}
|
|
18
|
+
export function slugify(s) {
|
|
19
|
+
return (s
|
|
20
|
+
.normalize('NFD')
|
|
21
|
+
.replace(/[̀-ͯ]/g, '')
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
24
|
+
.replace(/^-+|-+$/g, '') || 'projeto');
|
|
25
|
+
}
|
|
26
|
+
/** Nome de nota do Obsidian: sem caracteres proibidos em nomes de arquivo (/ \ : * ? " < > |). */
|
|
27
|
+
export function noteName(name) {
|
|
28
|
+
return name.replace(/[\\/:*?"<>|]/g, '-').trim();
|
|
29
|
+
}
|
|
30
|
+
export function specMission(spec) {
|
|
31
|
+
return /^\|\s*Missão\s*\|\s*(.+?)\s*\|\s*$/m.exec(spec)?.[1] ?? '';
|
|
32
|
+
}
|
|
33
|
+
/** Seção 11 (versão compacta) de uma spec, sem o título. */
|
|
34
|
+
export function specCompact(spec) {
|
|
35
|
+
const m = /^## 11\. Versão compacta[^\n]*\n([\s\S]*?)(?=^## |$(?![\s\S]))/m.exec(spec);
|
|
36
|
+
return (m?.[1] ?? '').trim();
|
|
37
|
+
}
|
|
38
|
+
export function listFiles(dir) {
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const name of readdirSync(dir)) {
|
|
41
|
+
const p = join(dir, name);
|
|
42
|
+
if (statSync(p).isDirectory())
|
|
43
|
+
out.push(...listFiles(p));
|
|
44
|
+
else
|
|
45
|
+
out.push(p);
|
|
46
|
+
}
|
|
47
|
+
return out.sort();
|
|
48
|
+
}
|
|
49
|
+
export function toPosix(p) {
|
|
50
|
+
return p.split(sep).join('/');
|
|
51
|
+
}
|
|
52
|
+
export function yamlString(s) {
|
|
53
|
+
return `"${s.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
54
|
+
}
|
|
55
|
+
/** Caminho para exibir em arquivos: `~/x` quando está dentro da home (portável entre máquinas). */
|
|
56
|
+
export function displayPath(abs, home) {
|
|
57
|
+
const rel = relative(home, abs);
|
|
58
|
+
if (rel === '')
|
|
59
|
+
return '~';
|
|
60
|
+
if (!rel.startsWith('..') && !rel.startsWith(sep) && !/^[A-Za-z]:/.test(rel))
|
|
61
|
+
return `~/${toPosix(rel)}`;
|
|
62
|
+
return toPosix(abs);
|
|
63
|
+
}
|
|
64
|
+
export function teamName(t, id) {
|
|
65
|
+
return t.teams.find((x) => x.id === id)?.name ?? id;
|
|
66
|
+
}
|
|
67
|
+
export function owned(t, agentId) {
|
|
68
|
+
return t.artifacts.filter((a) => a.owner === agentId);
|
|
69
|
+
}
|
|
70
|
+
export function written(t, agentId) {
|
|
71
|
+
return t.artifacts.filter((a) => (a.writers ?? []).includes(agentId));
|
|
72
|
+
}
|
|
73
|
+
export function agentById(t) {
|
|
74
|
+
return new Map(t.agents.map((a) => [a.id, a]));
|
|
75
|
+
}
|
|
76
|
+
export function agentTable(t, officeDisplay) {
|
|
77
|
+
const rows = t.agents.map((a) => `| ${teamName(t, a.team)} | ${a.name}${a.entrypoint ? ' **(entrada)**' : ''} | \`${officeDisplay}/agents/${a.team}/${a.id}.md\` |`);
|
|
78
|
+
return ['| Time | Agente | Spec |', '|---|---|---|', ...rows].join('\n');
|
|
79
|
+
}
|
|
80
|
+
export function officeDisplay(ctx) {
|
|
81
|
+
return displayPath(ctx.officeDir, ctx.home);
|
|
82
|
+
}
|
|
83
|
+
/** Comando para rodar o CLI de dentro de um assistente. */
|
|
84
|
+
export function crewCli(ctx) {
|
|
85
|
+
return `npx -y the-crew@${ctx.version}`;
|
|
86
|
+
}
|
|
87
|
+
export function tpl(ctx, ...parts) {
|
|
88
|
+
return readFileSync(join(ctx.pkgRoot, 'templates', ...parts), 'utf8');
|
|
89
|
+
}
|
|
90
|
+
export function teamRules(ctx) {
|
|
91
|
+
return render(tpl(ctx, 'rules', 'team.md'), { officeDir: officeDisplay(ctx) });
|
|
92
|
+
}
|
|
93
|
+
/** Variáveis usadas nas skills e comandos. */
|
|
94
|
+
export function skillVars(ctx) {
|
|
95
|
+
return {
|
|
96
|
+
officeDir: officeDisplay(ctx),
|
|
97
|
+
projectsDir: displayPath(ctx.projectsDir, ctx.home),
|
|
98
|
+
crewCli: crewCli(ctx),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function mcpServers(ide, mcp) {
|
|
102
|
+
const tokenRef = ide === 'cursor' ? '${env:GITHUB_PERSONAL_ACCESS_TOKEN}' : '${GITHUB_PERSONAL_ACCESS_TOKEN}';
|
|
103
|
+
const all = {
|
|
104
|
+
github: { type: 'http', url: 'https://api.githubcopilot.com/mcp/', headers: { Authorization: `Bearer ${tokenRef}` } },
|
|
105
|
+
context7: { command: 'npx', args: ['-y', '@upstash/context7-mcp@latest'] },
|
|
106
|
+
playwright: { command: 'npx', args: ['-y', '@playwright/mcp@latest'] },
|
|
107
|
+
};
|
|
108
|
+
return Object.fromEntries(mcp.map((id) => [id, all[id]]));
|
|
109
|
+
}
|
|
110
|
+
export const GITIGNORE_BLOCK = [
|
|
111
|
+
'# Arquivo local do the-crew (caminhos desta máquina); o token fica fora do repo',
|
|
112
|
+
'.the-crew/local.json',
|
|
113
|
+
'*.crew-new',
|
|
114
|
+
'# Segredos',
|
|
115
|
+
'.env',
|
|
116
|
+
'.env.*',
|
|
117
|
+
'!.env.example',
|
|
118
|
+
'*.pem',
|
|
119
|
+
'*.key',
|
|
120
|
+
].join('\n');
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
/** Home do usuário. THE_CREW_HOME sobrescreve (testes e instalações portáteis). */
|
|
5
|
+
export function userHome(env = process.env) {
|
|
6
|
+
return env.THE_CREW_HOME ?? homedir();
|
|
7
|
+
}
|
|
4
8
|
export function configDir(env = process.env, platform = process.platform) {
|
|
5
9
|
if (env.THE_CREW_CONFIG_DIR)
|
|
6
10
|
return env.THE_CREW_CONFIG_DIR;
|
|
11
|
+
if (env.THE_CREW_HOME)
|
|
12
|
+
return join(env.THE_CREW_HOME, '.config', 'the-crew');
|
|
7
13
|
if (platform === 'win32')
|
|
8
14
|
return join(env.APPDATA ?? join(homedir(), 'AppData', 'Roaming'), 'the-crew');
|
|
9
15
|
return join(env.XDG_CONFIG_HOME ?? join(homedir(), '.config'), 'the-crew');
|
|
10
16
|
}
|
|
17
|
+
export function globalConfigPath(env = process.env) {
|
|
18
|
+
return join(configDir(env), 'config.json');
|
|
19
|
+
}
|
|
20
|
+
export function readGlobalConfig(env = process.env) {
|
|
21
|
+
const p = globalConfigPath(env);
|
|
22
|
+
if (!existsSync(p))
|
|
23
|
+
return undefined;
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(readFileSync(p, 'utf8'));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function writeGlobalConfig(cfg, env = process.env) {
|
|
32
|
+
mkdirSync(configDir(env), { recursive: true, mode: 0o700 });
|
|
33
|
+
const p = globalConfigPath(env);
|
|
34
|
+
writeFileSync(p, JSON.stringify(cfg, null, 2) + '\n', 'utf8');
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
11
37
|
export function credentialsPath(env = process.env) {
|
|
12
38
|
return join(configDir(env), 'credentials.json');
|
|
13
39
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cria um repositório na conta do dono do token (POST /user/repos).
|
|
3
|
+
* Fine-grained tokens precisam de acesso a "All repositories" com
|
|
4
|
+
* Administration: write para criar repositórios.
|
|
5
|
+
*/
|
|
6
|
+
export async function createGithubRepo(token, opts, fetchImpl = fetch) {
|
|
7
|
+
let res;
|
|
8
|
+
try {
|
|
9
|
+
res = await fetchImpl('https://api.github.com/user/repos', {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: `Bearer ${token}`,
|
|
13
|
+
Accept: 'application/vnd.github+json',
|
|
14
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
15
|
+
'User-Agent': 'the-crew-cli',
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({ name: opts.name, description: opts.description.slice(0, 350), private: opts.private, auto_init: false }),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
throw new Error(`sem conexão com api.github.com (${e.name})`);
|
|
23
|
+
}
|
|
24
|
+
if (res.status === 201) {
|
|
25
|
+
const b = (await res.json());
|
|
26
|
+
return { fullName: b.full_name, htmlUrl: b.html_url, cloneUrl: b.clone_url };
|
|
27
|
+
}
|
|
28
|
+
if (res.status === 401)
|
|
29
|
+
throw new Error('token inválido ou expirado (401). Rode `the-crew login`.');
|
|
30
|
+
if (res.status === 403 || res.status === 404) {
|
|
31
|
+
throw new Error('o token não pode criar repositórios. No fine-grained token, dê acesso a "All repositories" com Administration: write, ou crie o repositório no GitHub e rode `git remote add origin <url>`.');
|
|
32
|
+
}
|
|
33
|
+
if (res.status === 422)
|
|
34
|
+
throw new Error(`já existe um repositório chamado "${opts.name}" nessa conta.`);
|
|
35
|
+
throw new Error(`GitHub respondeu ${res.status}.`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { configDir } from './credentials.js';
|
|
5
|
+
export function installRecordPath(env) {
|
|
6
|
+
return join(configDir(env), 'install-record.json');
|
|
7
|
+
}
|
|
8
|
+
export function sha256(text) {
|
|
9
|
+
return createHash('sha256').update(text).digest('hex');
|
|
10
|
+
}
|
|
11
|
+
export function readInstallRecord(env) {
|
|
12
|
+
const p = installRecordPath(env);
|
|
13
|
+
if (existsSync(p)) {
|
|
14
|
+
try {
|
|
15
|
+
const r = JSON.parse(readFileSync(p, 'utf8'));
|
|
16
|
+
return { version: 1, files: r.files ?? {}, jsonKeys: r.jsonKeys ?? {} };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
/* registro corrompido: recomeça */
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { version: 1, files: {}, jsonKeys: {} };
|
|
23
|
+
}
|
|
24
|
+
/** Acrescenta ao registro os arquivos que agora têm o conteúdo do the-crew. */
|
|
25
|
+
export function updateInstallRecord(env, plan, results) {
|
|
26
|
+
const rec = readInstallRecord(env);
|
|
27
|
+
const byPath = new Map(results.map((r) => [r.path, r]));
|
|
28
|
+
for (const w of plan) {
|
|
29
|
+
const r = byPath.get(w.path);
|
|
30
|
+
if (!r)
|
|
31
|
+
continue;
|
|
32
|
+
if (w.kind === 'file' && ['created', 'overwritten', 'unchanged'].includes(r.outcome))
|
|
33
|
+
rec.files[w.path] = sha256(w.content);
|
|
34
|
+
if (w.kind === 'json-merge' && r.added?.length)
|
|
35
|
+
rec.jsonKeys[w.path] = [...new Set([...(rec.jsonKeys[w.path] ?? []), ...r.added])];
|
|
36
|
+
}
|
|
37
|
+
mkdirSync(configDir(env), { recursive: true, mode: 0o700 });
|
|
38
|
+
writeFileSync(installRecordPath(env), JSON.stringify(rec, null, 2) + '\n', 'utf8');
|
|
39
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, rmdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
3
|
+
import { mcpServers } from './common.js';
|
|
4
|
+
import { packageRoot } from './paths.js';
|
|
5
|
+
import { sha256 } from './install-record.js';
|
|
6
|
+
import { removeBlock } from './writer.js';
|
|
7
|
+
/**
|
|
8
|
+
* Restos da versão 0.1.0, que instalava o time dentro de cada projeto
|
|
9
|
+
* (`npx the-crew` numa pasta). Ela não gravava registro de instalação, então
|
|
10
|
+
* a detecção usa nomes que só o the-crew usa e, quando o arquivo pode ter sido
|
|
11
|
+
* editado, o hash do conteúdo original da 0.1.0.
|
|
12
|
+
*/
|
|
13
|
+
const LEGACY_SKILLS = {
|
|
14
|
+
'crew-gates': 'dffda559750e310982edcdf895c223f0e948e3de942ef33902fb7fe3f5eb9cc7',
|
|
15
|
+
'crew-handoff': '99bdc8f028439ddbb0bd404ca1e53b99a153685ceb386de6288c06ae6af5724a',
|
|
16
|
+
'crew-obsidian': '591afb527e9b18d21f70497e9528d724df178992b3315e1961c3c7bf2b8445be',
|
|
17
|
+
'db-organizer': 'e456e31ba49da0f5c30c1fb8cdf192763aea43bc7f170f9b71438bc7958e44ba',
|
|
18
|
+
'po-backlog': 'aa0d41d2ccaea13c9e3dbb16be9673ad8d9f815722323c2f3c99f0296c7c20fc',
|
|
19
|
+
};
|
|
20
|
+
/** PROJECT.md da 0.1.0 sem a primeira linha (o título varia com o nome). */
|
|
21
|
+
const LEGACY_PROJECT_TAIL = '78725493f62c99e4b006471f4e9a276f5cbc8c50e5cb7b972409629c89a783b7';
|
|
22
|
+
const LEGACY_WORKFLOW = 'a04bf9ed54836d21e4e2030f98f38a6d8df13c04a97f44f5dbe9a29fb9bc284f';
|
|
23
|
+
function readJson(p) {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(readFileSync(p, 'utf8'));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function isFile(p) {
|
|
32
|
+
try {
|
|
33
|
+
return lstatSync(p).isFile();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function text(p) {
|
|
40
|
+
return readFileSync(p, 'utf8');
|
|
41
|
+
}
|
|
42
|
+
/** Pasta onde a 0.1.0 foi instalada: tem `.the-crew/config.json` com `projectName` e `integrations`. */
|
|
43
|
+
export function isLegacyProject(dir) {
|
|
44
|
+
const cfg = readJson(join(dir, '.the-crew', 'config.json'));
|
|
45
|
+
return Boolean(cfg && typeof cfg.projectName === 'string' && cfg.integrations);
|
|
46
|
+
}
|
|
47
|
+
const SKIP = new Set(['node_modules', 'Library', 'AppData', 'Applications', 'vendor', 'dist', 'build']);
|
|
48
|
+
/** Procura instalações da 0.1.0 a partir das pastas dadas, até `depth` níveis. */
|
|
49
|
+
export function findLegacyProjects(roots, depth = 4, limit = 20000) {
|
|
50
|
+
const found = new Set();
|
|
51
|
+
const self = packageRoot();
|
|
52
|
+
let visited = 0;
|
|
53
|
+
const walk = (dir, level) => {
|
|
54
|
+
if (visited++ > limit || dir === self)
|
|
55
|
+
return;
|
|
56
|
+
if (isLegacyProject(dir)) {
|
|
57
|
+
found.add(dir);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (level >= depth)
|
|
61
|
+
return;
|
|
62
|
+
let entries;
|
|
63
|
+
try {
|
|
64
|
+
entries = readdirSync(dir);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const name of entries) {
|
|
70
|
+
if (name.startsWith('.') || SKIP.has(name))
|
|
71
|
+
continue;
|
|
72
|
+
const p = join(dir, name);
|
|
73
|
+
try {
|
|
74
|
+
if (lstatSync(p).isDirectory())
|
|
75
|
+
walk(p, level + 1);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
/* sem permissão */
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
for (const r of roots)
|
|
83
|
+
walk(r, 0);
|
|
84
|
+
return [...found].sort();
|
|
85
|
+
}
|
|
86
|
+
export function planLegacy(dir, agentIds) {
|
|
87
|
+
const cfg = readJson(join(dir, '.the-crew', 'config.json')) ?? {};
|
|
88
|
+
const local = readJson(join(dir, '.the-crew', 'local.json'));
|
|
89
|
+
const current = Boolean(local && 'project' in local);
|
|
90
|
+
const p = {
|
|
91
|
+
dir,
|
|
92
|
+
projectName: String(cfg.projectName ?? basename(dir)),
|
|
93
|
+
current,
|
|
94
|
+
vaultProjectDir: !current && typeof local?.vaultProjectDir === 'string' ? local.vaultProjectDir : null,
|
|
95
|
+
remove: [],
|
|
96
|
+
keep: [],
|
|
97
|
+
blocks: [],
|
|
98
|
+
jsonKeys: [],
|
|
99
|
+
};
|
|
100
|
+
const at = (...r) => join(dir, ...r);
|
|
101
|
+
const add = (path) => existsSync(path) && p.remove.push(path);
|
|
102
|
+
for (const d of ['agents', 'contracts', 'skills'])
|
|
103
|
+
add(at('.the-crew', d));
|
|
104
|
+
add(at('.the-crew', 'config.json'));
|
|
105
|
+
if (local && !current)
|
|
106
|
+
add(at('.the-crew', 'local.json'));
|
|
107
|
+
for (const id of agentIds) {
|
|
108
|
+
const f = at('.claude', 'agents', `crew-${id}.md`);
|
|
109
|
+
if (!isFile(f))
|
|
110
|
+
continue;
|
|
111
|
+
const t = text(f);
|
|
112
|
+
if (t.includes(' do the-crew ') && t.includes('.the-crew/agents/'))
|
|
113
|
+
p.remove.push(f);
|
|
114
|
+
else
|
|
115
|
+
p.keep.push({ path: f, why: 'não tem o texto gerado pela 0.1.0' });
|
|
116
|
+
}
|
|
117
|
+
for (const [name, hash] of Object.entries(LEGACY_SKILLS)) {
|
|
118
|
+
const f = at('.claude', 'skills', name, 'SKILL.md');
|
|
119
|
+
if (!isFile(f))
|
|
120
|
+
continue;
|
|
121
|
+
if (sha256(text(f)) === hash)
|
|
122
|
+
p.remove.push(f);
|
|
123
|
+
else
|
|
124
|
+
p.keep.push({ path: f, why: 'foi modificado' });
|
|
125
|
+
}
|
|
126
|
+
const wf = at('.github', 'workflows', 'crew-integrity.yml');
|
|
127
|
+
if (isFile(wf)) {
|
|
128
|
+
if (sha256(text(wf)) === LEGACY_WORKFLOW)
|
|
129
|
+
p.remove.push(wf);
|
|
130
|
+
else
|
|
131
|
+
p.keep.push({ path: wf, why: 'foi modificado' });
|
|
132
|
+
}
|
|
133
|
+
for (const d of ['plan', 'runs', 'handoffs'])
|
|
134
|
+
add(at('.agents', d, '.gitkeep'));
|
|
135
|
+
const proj = at('PROJECT.md');
|
|
136
|
+
if (isFile(proj)) {
|
|
137
|
+
const t = text(proj);
|
|
138
|
+
if (!current && sha256(t.slice(t.indexOf('\n'))) === LEGACY_PROJECT_TAIL)
|
|
139
|
+
p.remove.push(proj);
|
|
140
|
+
else
|
|
141
|
+
p.keep.push({ path: proj, why: 'tem conteúdo seu' });
|
|
142
|
+
}
|
|
143
|
+
// O que a versão atual também usa nos projetos dela fica, se o projeto for atual.
|
|
144
|
+
if (!current) {
|
|
145
|
+
for (const f of [at('.cursor', 'rules', 'the-crew.mdc'), at('.windsurf', 'rules', 'the-crew.md')]) {
|
|
146
|
+
if (isFile(f) && text(f).includes('the-crew'))
|
|
147
|
+
p.remove.push(f);
|
|
148
|
+
}
|
|
149
|
+
for (const [f, comment] of [
|
|
150
|
+
[at('AGENTS.md'), 'html'],
|
|
151
|
+
[at('CLAUDE.md'), 'html'],
|
|
152
|
+
[at('.gitignore'), 'hash'],
|
|
153
|
+
]) {
|
|
154
|
+
if (isFile(f) && removeBlock(text(f), comment).found)
|
|
155
|
+
p.blocks.push({ path: f, comment });
|
|
156
|
+
}
|
|
157
|
+
for (const [f, ide] of [
|
|
158
|
+
[at('.mcp.json'), 'claude-code'],
|
|
159
|
+
[at('.cursor', 'mcp.json'), 'cursor'],
|
|
160
|
+
]) {
|
|
161
|
+
const data = isFile(f) ? readJson(f) : undefined;
|
|
162
|
+
const servers = (data?.mcpServers ?? {});
|
|
163
|
+
const ours = mcpServers(ide, ['github', 'context7', 'playwright']);
|
|
164
|
+
const keys = Object.keys(servers).filter((k) => JSON.stringify(servers[k]) === JSON.stringify(ours[k]));
|
|
165
|
+
if (keys.length)
|
|
166
|
+
p.jsonKeys.push({ path: f, keys });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return p;
|
|
170
|
+
}
|
|
171
|
+
function pruneUp(start, stop) {
|
|
172
|
+
let d = start;
|
|
173
|
+
while (d !== stop && relative(stop, d) && !relative(stop, d).startsWith('..')) {
|
|
174
|
+
try {
|
|
175
|
+
if (readdirSync(d).length > 0)
|
|
176
|
+
return;
|
|
177
|
+
rmdirSync(d);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
d = dirname(d);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/** Aplica a limpeza de um projeto. Nada fora de `p.dir` é tocado, exceto a pasta do vault se pedida. */
|
|
186
|
+
export function applyLegacy(p, removeVault) {
|
|
187
|
+
const touched = new Set();
|
|
188
|
+
for (const f of p.remove) {
|
|
189
|
+
rmSync(f, { recursive: true, force: true });
|
|
190
|
+
touched.add(dirname(f));
|
|
191
|
+
}
|
|
192
|
+
for (const b of p.blocks) {
|
|
193
|
+
const { text: rest } = removeBlock(text(b.path), b.comment);
|
|
194
|
+
if (rest.trim() === '')
|
|
195
|
+
rmSync(b.path, { force: true });
|
|
196
|
+
else
|
|
197
|
+
writeFileSync(b.path, rest, 'utf8');
|
|
198
|
+
}
|
|
199
|
+
for (const j of p.jsonKeys) {
|
|
200
|
+
const data = readJson(j.path);
|
|
201
|
+
for (const k of j.keys)
|
|
202
|
+
delete data.mcpServers[k];
|
|
203
|
+
if (Object.keys(data.mcpServers).length === 0 && Object.keys(data).length === 1) {
|
|
204
|
+
rmSync(j.path, { force: true });
|
|
205
|
+
touched.add(dirname(j.path));
|
|
206
|
+
}
|
|
207
|
+
else
|
|
208
|
+
writeFileSync(j.path, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
209
|
+
}
|
|
210
|
+
for (const d of touched)
|
|
211
|
+
pruneUp(d, p.dir);
|
|
212
|
+
if (removeVault && p.vaultProjectDir && basename(dirname(p.vaultProjectDir)) === 'the-crew') {
|
|
213
|
+
rmSync(p.vaultProjectDir, { recursive: true, force: true });
|
|
214
|
+
pruneUp(dirname(p.vaultProjectDir), dirname(dirname(p.vaultProjectDir)));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Depois da limpeza: a pasta ficou só com o .git (projeto criado só para testar)? */
|
|
218
|
+
export function onlyGitLeft(dir) {
|
|
219
|
+
try {
|
|
220
|
+
const rest = readdirSync(dir).filter((n) => n !== '.git');
|
|
221
|
+
return rest.length === 0;
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export function displayRel(p, base) {
|
|
228
|
+
const r = relative(base, p);
|
|
229
|
+
return r && !r.startsWith('..') ? r.split(sep).join('/') : p;
|
|
230
|
+
}
|