@basetisia/skill-manager 0.1.2 → 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/.claude/skills/habilidades/typescript/SKILL.md +16 -0
- package/bin/index.js +83 -0
- package/package.json +1 -1
- package/src/commands/init.js +94 -91
- package/src/commands/install-bulk.js +170 -0
- package/src/commands/install.js +100 -22
- package/src/commands/list.js +73 -44
- package/src/commands/push.js +104 -0
- package/src/commands/sync.js +20 -0
- package/src/commands/update.js +127 -0
- package/src/utils/api.js +1 -1
- package/src/utils/config.js +12 -1
- package/src/utils/find-skill.js +123 -0
- package/src/utils/installed.js +76 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# TypeScript — Contexto v1.1.0
|
|
2
|
+
|
|
3
|
+
## Reglas
|
|
4
|
+
- Usa TypeScript strict mode siempre
|
|
5
|
+
- ES Modules (import/export), nunca CommonJS
|
|
6
|
+
- Usa const por defecto, let solo cuando sea necesario
|
|
7
|
+
- Nombres de archivos en kebab-case
|
|
8
|
+
- Tipos/interfaces en PascalCase
|
|
9
|
+
- Funciones en camelCase
|
|
10
|
+
- No uses any — tipalo todo
|
|
11
|
+
- Prefiere type sobre interface salvo que necesites extends
|
|
12
|
+
|
|
13
|
+
## NUEVO: Imports
|
|
14
|
+
- Ordena imports: builtins → externos → internos
|
|
15
|
+
- Nunca uses import *
|
|
16
|
+
- Usa import type para tipos
|
package/bin/index.js
CHANGED
|
@@ -4,11 +4,15 @@ import { Command } from "commander";
|
|
|
4
4
|
import { init } from "../src/commands/init.js";
|
|
5
5
|
import { list } from "../src/commands/list.js";
|
|
6
6
|
import { install } from "../src/commands/install.js";
|
|
7
|
+
import { installBulk } from "../src/commands/install-bulk.js";
|
|
7
8
|
import { status } from "../src/commands/status.js";
|
|
8
9
|
import { detect } from "../src/commands/detect.js";
|
|
9
10
|
import { login } from "../src/commands/login.js";
|
|
10
11
|
import { logout } from "../src/commands/logout.js";
|
|
11
12
|
import { whoami } from "../src/commands/whoami.js";
|
|
13
|
+
import { sync } from "../src/commands/sync.js";
|
|
14
|
+
import { push } from "../src/commands/push.js";
|
|
15
|
+
import { update } from "../src/commands/update.js";
|
|
12
16
|
|
|
13
17
|
const program = new Command();
|
|
14
18
|
|
|
@@ -56,6 +60,49 @@ program
|
|
|
56
60
|
}
|
|
57
61
|
});
|
|
58
62
|
|
|
63
|
+
// Bulk install commands: install-project / install-area / install-team / install-sector
|
|
64
|
+
const bulkOpts = (cmd) =>
|
|
65
|
+
cmd
|
|
66
|
+
.option("-t, --tool <herramienta>", "Herramienta(s) destino, separadas por coma")
|
|
67
|
+
.option("-s, --scope <ámbito>", "Ámbito de instalación: global o project")
|
|
68
|
+
.option("-y, --yes", "Asume sí en las confirmaciones");
|
|
69
|
+
|
|
70
|
+
bulkOpts(
|
|
71
|
+
program
|
|
72
|
+
.command("install-project <slug>")
|
|
73
|
+
.description("Instala todas las skills publicadas de un proyecto")
|
|
74
|
+
).action(async (slug, options) => {
|
|
75
|
+
try { await installBulk("project", slug, options); }
|
|
76
|
+
catch (err) { console.error(err.message); process.exit(1); }
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
bulkOpts(
|
|
80
|
+
program
|
|
81
|
+
.command("install-area <slug>")
|
|
82
|
+
.description("Instala todas las skills publicadas de un área")
|
|
83
|
+
).action(async (slug, options) => {
|
|
84
|
+
try { await installBulk("area", slug, options); }
|
|
85
|
+
catch (err) { console.error(err.message); process.exit(1); }
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
bulkOpts(
|
|
89
|
+
program
|
|
90
|
+
.command("install-team <slug>")
|
|
91
|
+
.description("Instala todas las skills publicadas de un team")
|
|
92
|
+
).action(async (slug, options) => {
|
|
93
|
+
try { await installBulk("team", slug, options); }
|
|
94
|
+
catch (err) { console.error(err.message); process.exit(1); }
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
bulkOpts(
|
|
98
|
+
program
|
|
99
|
+
.command("install-sector <slug>")
|
|
100
|
+
.description("Instala todas las skills publicadas de un sector")
|
|
101
|
+
).action(async (slug, options) => {
|
|
102
|
+
try { await installBulk("sector", slug, options); }
|
|
103
|
+
catch (err) { console.error(err.message); process.exit(1); }
|
|
104
|
+
});
|
|
105
|
+
|
|
59
106
|
program
|
|
60
107
|
.command("status")
|
|
61
108
|
.description("Muestra el estado de las skills instaladas vs el catálogo")
|
|
@@ -80,6 +127,42 @@ program
|
|
|
80
127
|
}
|
|
81
128
|
});
|
|
82
129
|
|
|
130
|
+
program
|
|
131
|
+
.command("sync")
|
|
132
|
+
.description("Actualiza el find-skill con tus permisos más recientes")
|
|
133
|
+
.action(async () => {
|
|
134
|
+
try {
|
|
135
|
+
await sync();
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error(err.message);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
program
|
|
143
|
+
.command("push <ruta>")
|
|
144
|
+
.description("Publica los cambios locales de un skill al servidor")
|
|
145
|
+
.action(async (ruta) => {
|
|
146
|
+
try {
|
|
147
|
+
await push(ruta);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
console.error(err.message);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
program
|
|
155
|
+
.command("update")
|
|
156
|
+
.description("Comprueba y aplica actualizaciones de skills instalados")
|
|
157
|
+
.action(async () => {
|
|
158
|
+
try {
|
|
159
|
+
await update();
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(err.message);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
83
166
|
program
|
|
84
167
|
.command("login")
|
|
85
168
|
.description("Inicia sesión con tu cuenta de Basetis (Google)")
|
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -2,16 +2,28 @@ import inquirer from "inquirer";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { loadConfig, saveConfig, getConfigPath } from "../utils/config.js";
|
|
5
|
-
import {
|
|
5
|
+
import { loadCredentials } from "../utils/auth.js";
|
|
6
|
+
import { apiRequest } from "../utils/api.js";
|
|
7
|
+
import { generateFindSkill } from "../utils/find-skill.js";
|
|
8
|
+
import { getAdapter } from "../adapters/index.js";
|
|
6
9
|
|
|
7
10
|
export async function init() {
|
|
11
|
+
// Check auth
|
|
12
|
+
const creds = await loadCredentials();
|
|
13
|
+
if (!creds) {
|
|
14
|
+
console.log(
|
|
15
|
+
chalk.red("No estás autenticado. Ejecuta primero: skill-manager login")
|
|
16
|
+
);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
const existing = await loadConfig();
|
|
9
|
-
if (existing) {
|
|
21
|
+
if (existing?.companyId) {
|
|
10
22
|
const { overwrite } = await inquirer.prompt([
|
|
11
23
|
{
|
|
12
24
|
type: "confirm",
|
|
13
25
|
name: "overwrite",
|
|
14
|
-
message:
|
|
26
|
+
message: `Ya estás configurado para ${existing.companyName || "una empresa"}. ¿Reconfigurar?`,
|
|
15
27
|
default: false,
|
|
16
28
|
},
|
|
17
29
|
]);
|
|
@@ -21,110 +33,101 @@ export async function init() {
|
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
message: "Token de acceso personal (se guardará en ~/.skill-manager/config.json):",
|
|
68
|
-
when: (prev) => prev.type !== "local",
|
|
69
|
-
validate: (val) => (val.trim() ? true : "El token es obligatorio para repos remotos."),
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
type: "input",
|
|
73
|
-
name: "branch",
|
|
74
|
-
message: "Rama del repositorio:",
|
|
75
|
-
default: "main",
|
|
76
|
-
when: (prev) => prev.type !== "local",
|
|
77
|
-
},
|
|
36
|
+
// Fetch user info from API
|
|
37
|
+
const spinner = ora("Conectando con Skillsmanager...").start();
|
|
38
|
+
let me;
|
|
39
|
+
try {
|
|
40
|
+
me = await apiRequest("/api/me");
|
|
41
|
+
spinner.succeed(`Conectado como ${chalk.bold(me.name)} (${me.email})`);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
spinner.fail("No se pudo conectar con la API.");
|
|
44
|
+
console.error(chalk.red(` ${err.message}`));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!me.companies || me.companies.length === 0) {
|
|
49
|
+
console.log(
|
|
50
|
+
chalk.red(
|
|
51
|
+
"\nNo perteneces a ninguna empresa. Contacta con un administrador."
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Select company (if more than one)
|
|
58
|
+
let company;
|
|
59
|
+
if (me.companies.length === 1) {
|
|
60
|
+
company = me.companies[0];
|
|
61
|
+
console.log(chalk.dim(` Empresa: ${company.name} (${company.role})`));
|
|
62
|
+
} else {
|
|
63
|
+
const { companyId } = await inquirer.prompt([
|
|
64
|
+
{
|
|
65
|
+
type: "list",
|
|
66
|
+
name: "companyId",
|
|
67
|
+
message: "Selecciona tu empresa:",
|
|
68
|
+
choices: me.companies.map((c) => ({
|
|
69
|
+
name: `${c.name} (${c.role})`,
|
|
70
|
+
value: c.id,
|
|
71
|
+
})),
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
74
|
+
company = me.companies.find((c) => c.id === companyId);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Select default tool
|
|
78
|
+
const { defaultTool } = await inquirer.prompt([
|
|
78
79
|
{
|
|
79
80
|
type: "list",
|
|
80
81
|
name: "defaultTool",
|
|
81
82
|
message: "Herramienta de IA por defecto:",
|
|
82
83
|
choices: [
|
|
83
84
|
{ name: "Claude Code", value: "claude" },
|
|
84
|
-
{ name: "Gemini CLI", value: "gemini" },
|
|
85
85
|
{ name: "Cursor", value: "cursor" },
|
|
86
86
|
{ name: "Windsurf", value: "windsurf" },
|
|
87
|
-
{ name: "
|
|
87
|
+
{ name: "Gemini CLI", value: "gemini" },
|
|
88
|
+
{ name: "Codex", value: "codex" },
|
|
88
89
|
],
|
|
90
|
+
default: existing?.defaultTool || "claude",
|
|
89
91
|
},
|
|
90
92
|
]);
|
|
91
93
|
|
|
92
94
|
const config = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
token: answers.token || "",
|
|
98
|
-
branch: answers.branch || "main",
|
|
99
|
-
},
|
|
100
|
-
defaultTool: answers.defaultTool,
|
|
95
|
+
companyId: company.id,
|
|
96
|
+
companyName: company.name,
|
|
97
|
+
apiUrl: existing?.apiUrl || "http://localhost:3001",
|
|
98
|
+
defaultTool,
|
|
101
99
|
};
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
]);
|
|
120
|
-
if (!saveAnyway) {
|
|
121
|
-
console.log(chalk.yellow("Operación cancelada."));
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
101
|
+
await saveConfig(config);
|
|
102
|
+
|
|
103
|
+
// Generate and install find-skill
|
|
104
|
+
const findSpinner = ora("Generando find-skill personalizado...").start();
|
|
105
|
+
try {
|
|
106
|
+
const findSkillContent = await generateFindSkill(config);
|
|
107
|
+
const adapter = getAdapter(defaultTool);
|
|
108
|
+
await adapter.install("find-skill", findSkillContent, "personal");
|
|
109
|
+
findSpinner.succeed("Find-skill instalado");
|
|
110
|
+
} catch (err) {
|
|
111
|
+
findSpinner.fail("No se pudo instalar el find-skill");
|
|
112
|
+
console.error(chalk.dim(` ${err.message}`));
|
|
113
|
+
console.log(
|
|
114
|
+
chalk.dim(" Puedes intentarlo más tarde con: skill-manager sync")
|
|
115
|
+
);
|
|
125
116
|
}
|
|
126
117
|
|
|
127
|
-
|
|
128
|
-
console.log(chalk.green("✔ Configuración guardada correctamente."));
|
|
118
|
+
console.log(chalk.green("\n✔ Configuración completa."));
|
|
129
119
|
console.log(chalk.dim(` → ${getConfigPath()}`));
|
|
120
|
+
console.log(
|
|
121
|
+
chalk.dim(
|
|
122
|
+
` Empresa: ${company.name} | Herramienta: ${defaultTool}`
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
console.log(
|
|
126
|
+
chalk.dim(
|
|
127
|
+
"\n El find-skill te recomendará skills cuando trabajes en tu editor."
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
console.log(
|
|
131
|
+
chalk.dim(" Para ver skills disponibles: skill-manager list")
|
|
132
|
+
);
|
|
130
133
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import { requireConfig } from "../utils/config.js";
|
|
5
|
+
import { apiRequest } from "../utils/api.js";
|
|
6
|
+
import { getAdapter, detectInstalledTools } from "../adapters/index.js";
|
|
7
|
+
import { trackInstall } from "../utils/installed.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Bulk install: instala todas las skills publicadas de un proyecto/area/team/sector.
|
|
11
|
+
* @param {string} kind - 'project' | 'area' | 'team' | 'sector'
|
|
12
|
+
* @param {string} slug - Slug de la entidad o proyecto
|
|
13
|
+
*/
|
|
14
|
+
export async function installBulk(kind, slug, options = {}) {
|
|
15
|
+
const config = await requireConfig();
|
|
16
|
+
const validKinds = ["project", "area", "team", "sector"];
|
|
17
|
+
if (!validKinds.includes(kind)) {
|
|
18
|
+
console.error(chalk.red(`Tipo no válido: ${kind}. Debe ser uno de: ${validKinds.join(", ")}`));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const spinner = ora(`Buscando skills del ${kind} '${slug}'...`).start();
|
|
23
|
+
|
|
24
|
+
// Fetch all data needed
|
|
25
|
+
let skills, target;
|
|
26
|
+
try {
|
|
27
|
+
skills = await apiRequest(`/api/companies/${config.companyId}/skills`);
|
|
28
|
+
skills = skills.filter((s) => s.status === "published" && !s.path.endsWith("/_index"));
|
|
29
|
+
|
|
30
|
+
if (kind === "project") {
|
|
31
|
+
const projects = await apiRequest(`/api/companies/${config.companyId}/projects`);
|
|
32
|
+
target = projects.find((p) => p.slug === slug);
|
|
33
|
+
if (!target) {
|
|
34
|
+
spinner.fail(`Proyecto '${slug}' no encontrado.`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
skills = skills.filter((s) => s.project_id === target.id);
|
|
38
|
+
} else {
|
|
39
|
+
const endpoint = { area: "areas", team: "teams", sector: "sectors" }[kind];
|
|
40
|
+
const entities = await apiRequest(`/api/companies/${config.companyId}/${endpoint}`);
|
|
41
|
+
target = entities.find((e) => e.slug === slug);
|
|
42
|
+
if (!target) {
|
|
43
|
+
spinner.fail(`${kind.charAt(0).toUpperCase() + kind.slice(1)} '${slug}' no encontrado.`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
skills = skills.filter((s) => s.entity_id === target.id);
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
spinner.fail("Error al cargar datos.");
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
spinner.stop();
|
|
54
|
+
|
|
55
|
+
if (skills.length === 0) {
|
|
56
|
+
console.log(chalk.yellow(`\n No hay skills publicadas en ${kind} '${target.name}'.\n`));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Show what will be installed
|
|
61
|
+
console.log(
|
|
62
|
+
chalk.blue.bold(
|
|
63
|
+
`\n ${target.name} (${kind}) tiene ${skills.length} skill(s) publicada(s):\n`
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
for (const skill of skills) {
|
|
67
|
+
const desc = skill.description ? chalk.dim(` — ${skill.description}`) : "";
|
|
68
|
+
console.log(` ${chalk.cyan(skill.path)} ${chalk.gray(`v${skill.version}`)}${desc}`);
|
|
69
|
+
}
|
|
70
|
+
console.log();
|
|
71
|
+
|
|
72
|
+
// Confirm
|
|
73
|
+
if (!options.yes) {
|
|
74
|
+
const { confirm } = await inquirer.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: "confirm",
|
|
77
|
+
name: "confirm",
|
|
78
|
+
message: `¿Instalar las ${skills.length} skill(s)?`,
|
|
79
|
+
default: true,
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
if (!confirm) {
|
|
83
|
+
console.log(chalk.dim("Cancelado."));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Determine target tools
|
|
89
|
+
let toolNames = [];
|
|
90
|
+
if (options.tool) {
|
|
91
|
+
toolNames = options.tool.split(",").map((t) => t.trim());
|
|
92
|
+
} else if (config.defaultTool) {
|
|
93
|
+
toolNames = [config.defaultTool];
|
|
94
|
+
} else {
|
|
95
|
+
const detected = await detectInstalledTools();
|
|
96
|
+
if (detected.length === 0) {
|
|
97
|
+
console.error(chalk.red("No se detectó ninguna herramienta de IA instalada."));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
const { selected } = await inquirer.prompt([
|
|
101
|
+
{
|
|
102
|
+
type: "checkbox",
|
|
103
|
+
name: "selected",
|
|
104
|
+
message: "¿En qué herramientas quieres instalar?",
|
|
105
|
+
choices: detected.map((a) => ({
|
|
106
|
+
name: a.displayName,
|
|
107
|
+
value: a.toolName,
|
|
108
|
+
checked: true,
|
|
109
|
+
})),
|
|
110
|
+
validate: (val) => (val.length > 0 ? true : "Selecciona al menos una herramienta."),
|
|
111
|
+
},
|
|
112
|
+
]);
|
|
113
|
+
toolNames = selected;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Determine scope
|
|
117
|
+
let scope = options.scope;
|
|
118
|
+
if (!scope) {
|
|
119
|
+
const { chosen } = await inquirer.prompt([
|
|
120
|
+
{
|
|
121
|
+
type: "list",
|
|
122
|
+
name: "chosen",
|
|
123
|
+
message: "¿Dónde instalar las skills?",
|
|
124
|
+
choices: [
|
|
125
|
+
{ name: "Global (solo para ti, en ~/)", value: "personal" },
|
|
126
|
+
{ name: "Proyecto (en el repo actual)", value: "project" },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
]);
|
|
130
|
+
scope = chosen;
|
|
131
|
+
}
|
|
132
|
+
if (scope === "global") scope = "personal";
|
|
133
|
+
|
|
134
|
+
// Install all
|
|
135
|
+
const adapters = toolNames.map((name) => getAdapter(name));
|
|
136
|
+
let installed = 0;
|
|
137
|
+
let failed = 0;
|
|
138
|
+
|
|
139
|
+
for (const skill of skills) {
|
|
140
|
+
const installSpinner = ora(`Instalando ${skill.path}...`).start();
|
|
141
|
+
try {
|
|
142
|
+
const content = skill.content || "";
|
|
143
|
+
for (const adapter of adapters) {
|
|
144
|
+
await adapter.install(skill.path, content, scope);
|
|
145
|
+
}
|
|
146
|
+
await trackInstall(skill, toolNames[0], scope);
|
|
147
|
+
installed++;
|
|
148
|
+
installSpinner.succeed(`Instalada ${skill.path}`);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
installSpinner.fail(`Error instalando ${skill.path}`);
|
|
151
|
+
console.error(chalk.red(` ${err.message}`));
|
|
152
|
+
failed++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Summary
|
|
157
|
+
console.log();
|
|
158
|
+
const toolList = adapters.map((a) => a.displayName).join(" y ");
|
|
159
|
+
if (failed > 0) {
|
|
160
|
+
console.log(
|
|
161
|
+
chalk.yellow(
|
|
162
|
+
`⚠ ${installed} skill(s) instalada(s), ${failed} fallaron en ${toolList} (${scope})`
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
} else {
|
|
166
|
+
console.log(
|
|
167
|
+
chalk.green(`✔ ${installed} skill(s) instalada(s) en ${toolList} (${scope})`)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/commands/install.js
CHANGED
|
@@ -1,29 +1,105 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import ora from "ora";
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { requireConfig } from "../utils/config.js";
|
|
5
|
+
import { apiRequest } from "../utils/api.js";
|
|
6
6
|
import { getAdapter, detectInstalledTools } from "../adapters/index.js";
|
|
7
|
+
import { trackInstall } from "../utils/installed.js";
|
|
7
8
|
|
|
8
9
|
export async function install(skillPath, options = {}) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const config = await requireConfig();
|
|
11
|
+
|
|
12
|
+
// Fetch all published skills
|
|
13
|
+
const spinner = ora("Cargando skills...").start();
|
|
14
|
+
let skills;
|
|
12
15
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
skills = await apiRequest(`/api/companies/${config.companyId}/skills`);
|
|
17
|
+
skills = skills.filter((s) => s.status === "published");
|
|
15
18
|
} catch (err) {
|
|
16
|
-
spinner.fail("
|
|
17
|
-
|
|
19
|
+
spinner.fail("No se pudieron cargar los skills.");
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Filter out _index skills (auto-generated, not installable)
|
|
24
|
+
skills = skills.filter((s) => !s.path.endsWith("/_index"));
|
|
25
|
+
|
|
26
|
+
// Find the target skill
|
|
27
|
+
const target = skills.find((s) => s.path === skillPath);
|
|
28
|
+
if (!target) {
|
|
29
|
+
spinner.fail(`Skill no encontrado: ${skillPath}`);
|
|
30
|
+
console.log(
|
|
31
|
+
chalk.dim(" Usa 'skill-manager list' para ver los skills disponibles.")
|
|
32
|
+
);
|
|
18
33
|
process.exit(1);
|
|
19
34
|
}
|
|
20
35
|
|
|
36
|
+
// Find children (skills whose path starts with target path)
|
|
37
|
+
const children = skills.filter(
|
|
38
|
+
(s) =>
|
|
39
|
+
s.path !== target.path &&
|
|
40
|
+
s.path.startsWith(target.path + "/") &&
|
|
41
|
+
!s.path.endsWith("/_index")
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
spinner.stop();
|
|
45
|
+
|
|
46
|
+
// Build install list
|
|
47
|
+
const toInstall = [target];
|
|
48
|
+
|
|
49
|
+
if (children.length > 0) {
|
|
50
|
+
console.log(
|
|
51
|
+
chalk.blue.bold(
|
|
52
|
+
`\n ${target.name} tiene ${children.length} skill(s) hijo(s):\n`
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
for (const child of children) {
|
|
56
|
+
const desc = child.description ? chalk.dim(` — ${child.description}`) : "";
|
|
57
|
+
console.log(` ${chalk.cyan(child.path)}${desc}`);
|
|
58
|
+
}
|
|
59
|
+
console.log();
|
|
60
|
+
|
|
61
|
+
const { childAction } = await inquirer.prompt([
|
|
62
|
+
{
|
|
63
|
+
type: "list",
|
|
64
|
+
name: "childAction",
|
|
65
|
+
message: "¿Qué quieres hacer?",
|
|
66
|
+
choices: [
|
|
67
|
+
{ name: "Instalar solo el padre", value: "parent" },
|
|
68
|
+
{ name: "Instalar padre + todos los hijos", value: "all" },
|
|
69
|
+
{ name: "Seleccionar cuáles instalar", value: "select" },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
if (childAction === "all") {
|
|
75
|
+
toInstall.push(...children);
|
|
76
|
+
} else if (childAction === "select") {
|
|
77
|
+
const { selected } = await inquirer.prompt([
|
|
78
|
+
{
|
|
79
|
+
type: "checkbox",
|
|
80
|
+
name: "selected",
|
|
81
|
+
message: "Selecciona los skills a instalar:",
|
|
82
|
+
choices: children.map((c) => ({
|
|
83
|
+
name: `${c.path} ${chalk.dim(c.description || "")}`,
|
|
84
|
+
value: c.path,
|
|
85
|
+
checked: false,
|
|
86
|
+
})),
|
|
87
|
+
},
|
|
88
|
+
]);
|
|
89
|
+
const selectedSkills = children.filter((c) =>
|
|
90
|
+
selected.includes(c.path)
|
|
91
|
+
);
|
|
92
|
+
toInstall.push(...selectedSkills);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
21
96
|
// Show what will be installed
|
|
22
|
-
console.log();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
97
|
+
console.log(chalk.blue.bold("\n Skills a instalar:\n"));
|
|
98
|
+
for (const [i, skill] of toInstall.entries()) {
|
|
99
|
+
const arrow = i < toInstall.length - 1 ? "├─" : "└─";
|
|
100
|
+
console.log(
|
|
101
|
+
` ${arrow} ${skill.path} ${chalk.gray(`v${skill.version}`)}`
|
|
102
|
+
);
|
|
27
103
|
}
|
|
28
104
|
console.log();
|
|
29
105
|
|
|
@@ -31,6 +107,8 @@ export async function install(skillPath, options = {}) {
|
|
|
31
107
|
let toolNames = [];
|
|
32
108
|
if (options.tool) {
|
|
33
109
|
toolNames = options.tool.split(",").map((t) => t.trim());
|
|
110
|
+
} else if (config.defaultTool) {
|
|
111
|
+
toolNames = [config.defaultTool];
|
|
34
112
|
} else {
|
|
35
113
|
const detected = await detectInstalledTools();
|
|
36
114
|
if (detected.length === 0) {
|
|
@@ -66,28 +144,26 @@ export async function install(skillPath, options = {}) {
|
|
|
66
144
|
message: "¿Dónde instalar las skills?",
|
|
67
145
|
choices: [
|
|
68
146
|
{ name: "Global (solo para ti, en ~/)", value: "personal" },
|
|
69
|
-
{ name: "Proyecto (
|
|
147
|
+
{ name: "Proyecto (en el repo actual)", value: "project" },
|
|
70
148
|
],
|
|
71
149
|
},
|
|
72
150
|
]);
|
|
73
151
|
scope = chosen;
|
|
74
152
|
}
|
|
75
|
-
// Normalize "global" to "personal"
|
|
76
153
|
if (scope === "global") scope = "personal";
|
|
77
154
|
|
|
78
|
-
// Install
|
|
155
|
+
// Install
|
|
79
156
|
const adapters = toolNames.map((name) => getAdapter(name));
|
|
80
157
|
let installed = 0;
|
|
81
158
|
|
|
82
|
-
for (const skill of
|
|
159
|
+
for (const skill of toInstall) {
|
|
83
160
|
const installSpinner = ora(`Instalando ${skill.path}...`).start();
|
|
84
161
|
try {
|
|
85
|
-
const
|
|
86
|
-
const content = await fetchFileContent(skillFile);
|
|
87
|
-
|
|
162
|
+
const content = skill.content || "";
|
|
88
163
|
for (const adapter of adapters) {
|
|
89
164
|
await adapter.install(skill.path, content, scope);
|
|
90
165
|
}
|
|
166
|
+
await trackInstall(skill, toolNames[0], scope);
|
|
91
167
|
installed++;
|
|
92
168
|
installSpinner.succeed(`Instalada ${skill.path}`);
|
|
93
169
|
} catch (err) {
|
|
@@ -100,6 +176,8 @@ export async function install(skillPath, options = {}) {
|
|
|
100
176
|
console.log();
|
|
101
177
|
const toolList = adapters.map((a) => a.displayName).join(" y ");
|
|
102
178
|
console.log(
|
|
103
|
-
chalk.green(
|
|
179
|
+
chalk.green(
|
|
180
|
+
`✔ ${installed} skill(s) instalada(s) en ${toolList} (${scope})`
|
|
181
|
+
)
|
|
104
182
|
);
|
|
105
183
|
}
|
package/src/commands/list.js
CHANGED
|
@@ -1,29 +1,58 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import ora from "ora";
|
|
3
|
-
import {
|
|
3
|
+
import { requireConfig } from "../utils/config.js";
|
|
4
|
+
import { apiRequest } from "../utils/api.js";
|
|
5
|
+
import { shouldCheckUpdates } from "../utils/installed.js";
|
|
6
|
+
import { checkUpdatesPassive } from "./update.js";
|
|
4
7
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const LEVEL_ICONS = {
|
|
9
|
+
root: "🏢",
|
|
10
|
+
user: "👤",
|
|
11
|
+
habilidades: "🛠",
|
|
12
|
+
area: "📂",
|
|
13
|
+
team: "👥",
|
|
14
|
+
sector: "🏭",
|
|
15
|
+
proyecto: "📦",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const TYPE_LABELS = {
|
|
19
|
+
contexto: chalk.blue("contexto"),
|
|
20
|
+
habilidad: chalk.magenta("habilidad"),
|
|
21
|
+
agente: chalk.green("agente"),
|
|
22
|
+
};
|
|
10
23
|
|
|
11
24
|
export async function list(options = {}) {
|
|
12
|
-
const
|
|
25
|
+
const config = await requireConfig();
|
|
26
|
+
|
|
27
|
+
// Passive update check (every 5 min)
|
|
28
|
+
if (await shouldCheckUpdates()) {
|
|
29
|
+
await checkUpdatesPassive(config);
|
|
30
|
+
}
|
|
13
31
|
|
|
32
|
+
const spinner = ora("Cargando skills...").start();
|
|
14
33
|
let skills;
|
|
15
34
|
try {
|
|
16
|
-
skills = await
|
|
17
|
-
spinner.
|
|
35
|
+
skills = await apiRequest(`/api/companies/${config.companyId}/skills`);
|
|
36
|
+
spinner.stop();
|
|
18
37
|
} catch (err) {
|
|
19
|
-
spinner.fail("
|
|
20
|
-
|
|
21
|
-
process.exit(1);
|
|
38
|
+
spinner.fail("No se pudieron cargar los skills.");
|
|
39
|
+
throw err;
|
|
22
40
|
}
|
|
23
41
|
|
|
42
|
+
// Filter published only and exclude auto-generated _index skills
|
|
43
|
+
skills = skills.filter(
|
|
44
|
+
(s) => s.status === "published" && !s.path.endsWith("/_index")
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Apply text filter if provided
|
|
24
48
|
if (options.filter) {
|
|
25
|
-
const
|
|
26
|
-
skills = skills.filter(
|
|
49
|
+
const q = options.filter.toLowerCase();
|
|
50
|
+
skills = skills.filter(
|
|
51
|
+
(s) =>
|
|
52
|
+
s.name.toLowerCase().includes(q) ||
|
|
53
|
+
s.path.toLowerCase().includes(q) ||
|
|
54
|
+
(s.description || "").toLowerCase().includes(q)
|
|
55
|
+
);
|
|
27
56
|
}
|
|
28
57
|
|
|
29
58
|
if (skills.length === 0) {
|
|
@@ -31,39 +60,39 @@ export async function list(options = {}) {
|
|
|
31
60
|
return;
|
|
32
61
|
}
|
|
33
62
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
63
|
+
// Group by level
|
|
64
|
+
const groups = {};
|
|
65
|
+
for (const s of skills) {
|
|
66
|
+
const level = s.level || "otro";
|
|
67
|
+
if (!groups[level]) groups[level] = [];
|
|
68
|
+
groups[level].push(s);
|
|
69
|
+
}
|
|
37
70
|
|
|
38
|
-
|
|
39
|
-
console.log(chalk.blue.bold(` ${section.label}`));
|
|
40
|
-
console.log(chalk.blue(" " + "─".repeat(40)));
|
|
71
|
+
console.log(chalk.bold(`\n ${skills.length} skills disponibles\n`));
|
|
41
72
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
73
|
+
const levelOrder = [
|
|
74
|
+
"root",
|
|
75
|
+
"habilidades",
|
|
76
|
+
"area",
|
|
77
|
+
"team",
|
|
78
|
+
"sector",
|
|
79
|
+
"proyecto",
|
|
80
|
+
"user",
|
|
81
|
+
];
|
|
51
82
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.log();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
83
|
+
for (const level of levelOrder) {
|
|
84
|
+
const items = groups[level];
|
|
85
|
+
if (!items) continue;
|
|
86
|
+
|
|
87
|
+
const icon = LEVEL_ICONS[level] || "•";
|
|
88
|
+
console.log(chalk.bold(` ${icon} ${level.toUpperCase()}`));
|
|
89
|
+
|
|
90
|
+
for (const s of items) {
|
|
91
|
+
const type = TYPE_LABELS[s.skill_type] || s.skill_type;
|
|
92
|
+
const path = chalk.cyan(s.path);
|
|
93
|
+
const desc = s.description ? chalk.dim(` — ${s.description}`) : "";
|
|
94
|
+
console.log(` ${path} ${type}${desc}`);
|
|
64
95
|
}
|
|
96
|
+
console.log();
|
|
65
97
|
}
|
|
66
|
-
|
|
67
|
-
console.log();
|
|
68
|
-
console.log(chalk.dim(` Total: ${skills.length} skills`));
|
|
69
98
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { requireConfig } from "../utils/config.js";
|
|
6
|
+
import { apiRequest } from "../utils/api.js";
|
|
7
|
+
import { getInstalledSkills } from "../utils/installed.js";
|
|
8
|
+
import { getAdapter } from "../adapters/index.js";
|
|
9
|
+
|
|
10
|
+
export async function push(skillPath) {
|
|
11
|
+
const config = await requireConfig();
|
|
12
|
+
|
|
13
|
+
// Find the installed skill
|
|
14
|
+
const installed = await getInstalledSkills();
|
|
15
|
+
const entry = installed.find((s) => s.path === skillPath);
|
|
16
|
+
|
|
17
|
+
if (!entry) {
|
|
18
|
+
console.log(chalk.red(`Skill no instalado localmente: ${skillPath}`));
|
|
19
|
+
console.log(chalk.dim(" Solo puedes hacer push de skills que tengas instalados."));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Read local content
|
|
24
|
+
const adapter = getAdapter(entry.tool || config.defaultTool);
|
|
25
|
+
let localContent;
|
|
26
|
+
try {
|
|
27
|
+
const localPath = adapter.getInstallPath(skillPath, entry.scope);
|
|
28
|
+
localContent = await readFile(localPath, "utf-8");
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.log(chalk.red(`No se pudo leer el skill local: ${skillPath}`));
|
|
31
|
+
console.log(chalk.dim(` ${err.message}`));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fetch remote to compare
|
|
36
|
+
const spinner = ora("Comparando con la versión del servidor...").start();
|
|
37
|
+
let remoteSkill;
|
|
38
|
+
try {
|
|
39
|
+
const skills = await apiRequest(`/api/companies/${config.companyId}/skills`);
|
|
40
|
+
remoteSkill = skills.find((s) => s.path === skillPath);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
spinner.fail("No se pudo conectar con la API.");
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!remoteSkill) {
|
|
47
|
+
spinner.fail("Skill no encontrado en el servidor.");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (localContent.trim() === (remoteSkill.content || "").trim()) {
|
|
52
|
+
spinner.succeed("El skill local es idéntico al del servidor. No hay cambios.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
spinner.stop();
|
|
57
|
+
|
|
58
|
+
// Show diff summary
|
|
59
|
+
const localLines = localContent.split("\n").length;
|
|
60
|
+
const remoteLines = (remoteSkill.content || "").split("\n").length;
|
|
61
|
+
console.log(
|
|
62
|
+
chalk.dim(`\n Local: ${localLines} líneas | Servidor: ${remoteLines} líneas`)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// Ask for commit message
|
|
66
|
+
const { message } = await inquirer.prompt([
|
|
67
|
+
{
|
|
68
|
+
type: "input",
|
|
69
|
+
name: "message",
|
|
70
|
+
message: "Describe los cambios:",
|
|
71
|
+
validate: (val) => (val.trim() ? true : "El mensaje es obligatorio."),
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
// Push
|
|
76
|
+
const pushSpinner = ora("Enviando cambios...").start();
|
|
77
|
+
try {
|
|
78
|
+
const result = await apiRequest(
|
|
79
|
+
`/api/companies/${config.companyId}/skills/${remoteSkill.id}/push`,
|
|
80
|
+
{
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: JSON.stringify({ content: localContent, message }),
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (result.action === "pushed") {
|
|
87
|
+
pushSpinner.succeed(
|
|
88
|
+
chalk.green(
|
|
89
|
+
`Cambios publicados directamente (v${result.skill.version})`
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
} else if (result.action === "proposed") {
|
|
93
|
+
pushSpinner.succeed(
|
|
94
|
+
chalk.yellow(
|
|
95
|
+
"Propuesta de cambio creada. Un admin o lead debe aprobarla."
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
console.log(chalk.dim(` ID de propuesta: ${result.proposal.id}`));
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
pushSpinner.fail("Error enviando cambios.");
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import { requireConfig } from "../utils/config.js";
|
|
4
|
+
import { generateFindSkill } from "../utils/find-skill.js";
|
|
5
|
+
import { getAdapter } from "../adapters/index.js";
|
|
6
|
+
|
|
7
|
+
export async function sync() {
|
|
8
|
+
const config = await requireConfig();
|
|
9
|
+
|
|
10
|
+
const spinner = ora("Actualizando find-skill...").start();
|
|
11
|
+
try {
|
|
12
|
+
const findSkillContent = await generateFindSkill(config);
|
|
13
|
+
const adapter = getAdapter(config.defaultTool);
|
|
14
|
+
await adapter.install("find-skill", findSkillContent, "personal");
|
|
15
|
+
spinner.succeed("Find-skill actualizado con tus permisos más recientes");
|
|
16
|
+
} catch (err) {
|
|
17
|
+
spinner.fail("No se pudo actualizar el find-skill");
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import { requireConfig } from "../utils/config.js";
|
|
5
|
+
import { apiRequest } from "../utils/api.js";
|
|
6
|
+
import { getInstalledSkills, updateInstalledVersion, markChecked } from "../utils/installed.js";
|
|
7
|
+
import { getAdapter } from "../adapters/index.js";
|
|
8
|
+
|
|
9
|
+
export async function update() {
|
|
10
|
+
const config = await requireConfig();
|
|
11
|
+
const installed = await getInstalledSkills();
|
|
12
|
+
|
|
13
|
+
if (installed.length === 0) {
|
|
14
|
+
console.log(chalk.dim("No tienes skills instalados."));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const spinner = ora("Comprobando actualizaciones...").start();
|
|
19
|
+
|
|
20
|
+
let updates;
|
|
21
|
+
try {
|
|
22
|
+
const body = installed.map((s) => ({ path: s.path, version: s.version }));
|
|
23
|
+
const result = await apiRequest(
|
|
24
|
+
`/api/companies/${config.companyId}/skills/check-updates`,
|
|
25
|
+
{
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify({ installed: body }),
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
updates = (result.updates || []).filter((u) => !u.path.endsWith("/_index"));
|
|
31
|
+
await markChecked();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
spinner.fail("No se pudo comprobar actualizaciones.");
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (updates.length === 0) {
|
|
38
|
+
spinner.succeed("Todo al día — no hay actualizaciones.");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
spinner.succeed(`${updates.length} actualización(es) disponible(s):\n`);
|
|
43
|
+
|
|
44
|
+
let updated = 0;
|
|
45
|
+
for (const upd of updates) {
|
|
46
|
+
console.log(
|
|
47
|
+
` ${chalk.cyan(upd.path)} ${chalk.gray(upd.currentVersion)} → ${chalk.green(upd.latestVersion)}`
|
|
48
|
+
);
|
|
49
|
+
if (upd.author) console.log(chalk.dim(` Autor: ${upd.author}`));
|
|
50
|
+
if (upd.description) console.log(chalk.dim(` ${upd.description}`));
|
|
51
|
+
|
|
52
|
+
const { doUpdate } = await inquirer.prompt([
|
|
53
|
+
{
|
|
54
|
+
type: "confirm",
|
|
55
|
+
name: "doUpdate",
|
|
56
|
+
message: `¿Actualizar ${upd.path}?`,
|
|
57
|
+
default: true,
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
if (!doUpdate) {
|
|
62
|
+
console.log(chalk.dim(" Omitido.\n"));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const installSpinner = ora(`Actualizando ${upd.path}...`).start();
|
|
67
|
+
try {
|
|
68
|
+
// Fetch full skill content
|
|
69
|
+
const skill = await apiRequest(
|
|
70
|
+
`/api/companies/${config.companyId}/skills/${upd.id}`
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Find installed entry to know tool and scope
|
|
74
|
+
const entry = installed.find((s) => s.path === upd.path);
|
|
75
|
+
const tool = entry?.tool || config.defaultTool;
|
|
76
|
+
const scope = entry?.scope || "project";
|
|
77
|
+
|
|
78
|
+
const adapter = getAdapter(tool);
|
|
79
|
+
await adapter.install(skill.path, skill.content || "", scope);
|
|
80
|
+
await updateInstalledVersion(upd.path, upd.latestVersion);
|
|
81
|
+
|
|
82
|
+
updated++;
|
|
83
|
+
installSpinner.succeed(`Actualizada ${upd.path} a v${upd.latestVersion}`);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
installSpinner.fail(`Error actualizando ${upd.path}`);
|
|
86
|
+
console.error(chalk.red(` ${err.message}`));
|
|
87
|
+
}
|
|
88
|
+
console.log();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(chalk.green(`✔ ${updated} skill(s) actualizado(s)`));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Passive check — called from other commands
|
|
95
|
+
export async function checkUpdatesPassive(config) {
|
|
96
|
+
try {
|
|
97
|
+
const installed = await getInstalledSkills();
|
|
98
|
+
if (installed.length === 0) return;
|
|
99
|
+
|
|
100
|
+
const body = installed.map((s) => ({ path: s.path, version: s.version }));
|
|
101
|
+
const result = await apiRequest(
|
|
102
|
+
`/api/companies/${config.companyId}/skills/check-updates`,
|
|
103
|
+
{
|
|
104
|
+
method: "POST",
|
|
105
|
+
body: JSON.stringify({ installed: body }),
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
await markChecked();
|
|
109
|
+
|
|
110
|
+
const updates = (result.updates || []).filter((u) => !u.path.endsWith("/_index"));
|
|
111
|
+
if (updates.length > 0) {
|
|
112
|
+
console.log(
|
|
113
|
+
chalk.yellow(
|
|
114
|
+
`\n ⚠ ${updates.length} actualización(es) disponible(s):`
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
for (const u of updates) {
|
|
118
|
+
console.log(
|
|
119
|
+
chalk.dim(` ${u.path} ${u.currentVersion} → ${u.latestVersion}`)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
console.log(chalk.dim(" Ejecuta: skill-manager update\n"));
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
// Silent fail — don't break the main command
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/utils/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getValidToken, clearCredentials } from "./auth.js";
|
|
2
2
|
import { loadConfig } from "./config.js";
|
|
3
3
|
|
|
4
|
-
const DEFAULT_API_URL = "
|
|
4
|
+
const DEFAULT_API_URL = "http://localhost:3001";
|
|
5
5
|
|
|
6
6
|
async function getApiUrl() {
|
|
7
7
|
const config = await loadConfig();
|
package/src/utils/config.js
CHANGED
|
@@ -25,8 +25,19 @@ export async function saveConfig(config) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export async function requireConfig() {
|
|
28
|
+
// Check credentials first
|
|
29
|
+
const { homedir } = await import("node:os");
|
|
30
|
+
const credsPath = join(homedir(), ".skill-manager", "credentials.json");
|
|
31
|
+
try {
|
|
32
|
+
await readFile(credsPath, "utf-8");
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"No estás autenticado. Ejecuta primero: skill-manager login"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
const config = await loadConfig();
|
|
29
|
-
if (!config) {
|
|
40
|
+
if (!config || !config.companyId) {
|
|
30
41
|
throw new Error(
|
|
31
42
|
"No se encontró configuración. Ejecuta primero: skill-manager init"
|
|
32
43
|
);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { apiRequest } from "./api.js";
|
|
2
|
+
|
|
3
|
+
export async function generateFindSkill(config) {
|
|
4
|
+
const permissions = await apiRequest("/api/me/permissions");
|
|
5
|
+
|
|
6
|
+
if (!permissions.company) {
|
|
7
|
+
throw new Error("No perteneces a ninguna empresa.");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { company, entities, projects } = permissions;
|
|
11
|
+
const tool = config.defaultTool || "tu herramienta";
|
|
12
|
+
const toolLabel = {
|
|
13
|
+
claude: "Claude Code",
|
|
14
|
+
cursor: "Cursor",
|
|
15
|
+
windsurf: "Windsurf",
|
|
16
|
+
gemini: "Gemini CLI",
|
|
17
|
+
codex: "Codex",
|
|
18
|
+
}[config.defaultTool] || config.defaultTool;
|
|
19
|
+
|
|
20
|
+
const me = await apiRequest("/api/me");
|
|
21
|
+
|
|
22
|
+
let md = `# Skill Finder — ${company.name}
|
|
23
|
+
|
|
24
|
+
Eres un asistente de descubrimiento de skills para ${me.name} (${me.email}).
|
|
25
|
+
Tu función es ayudar al usuario a encontrar e instalar los skills relevantes
|
|
26
|
+
para su proyecto usando el CLI de Basetis Skill Manager.
|
|
27
|
+
|
|
28
|
+
## Tu usuario
|
|
29
|
+
- Nombre: ${me.name}
|
|
30
|
+
- Empresa: ${company.name}
|
|
31
|
+
- Rol: ${company.role}
|
|
32
|
+
- Herramienta: ${toolLabel}
|
|
33
|
+
|
|
34
|
+
## Instrucciones
|
|
35
|
+
|
|
36
|
+
### Cuándo recomendar
|
|
37
|
+
- Cuando el usuario empiece a trabajar en un proyecto nuevo
|
|
38
|
+
- Cuando detectes tecnologías en el proyecto para las que hay skills disponibles
|
|
39
|
+
- Cuando el usuario pregunte por buenas prácticas o configuración
|
|
40
|
+
- Cuando el usuario haga algo que un skill podría mejorar
|
|
41
|
+
|
|
42
|
+
### Cómo recomendar
|
|
43
|
+
- Analiza los ficheros del proyecto (package.json, tsconfig.json, Dockerfile, etc.)
|
|
44
|
+
- Menciona el skill y qué aporta en UNA línea
|
|
45
|
+
- Da el comando exacto para instalar
|
|
46
|
+
- No insistas si el usuario no quiere — menciona una vez y ya
|
|
47
|
+
|
|
48
|
+
### Qué puede instalar este usuario
|
|
49
|
+
|
|
50
|
+
#### Habilidades (cross-cutting, para todos en ${company.name})
|
|
51
|
+
Skills de lenguajes, frameworks, herramientas y buenas prácticas compartidas.
|
|
52
|
+
|
|
53
|
+
\`\`\`bash
|
|
54
|
+
skill-manager list --filter habilidades
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
Ejemplos de cuándo recomendar:
|
|
58
|
+
- Si detectas TypeScript → \`skill-manager install habilidades/typescript\`
|
|
59
|
+
- Si detectas React → \`skill-manager install habilidades/react\`
|
|
60
|
+
- Si detectas Express → \`skill-manager install habilidades/express-api\`
|
|
61
|
+
- Si detectas PostgreSQL → \`skill-manager install habilidades/postgresql\`
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
// Areas
|
|
65
|
+
const areas = entities.filter((e) => e.type === "area");
|
|
66
|
+
if (areas.length > 0) {
|
|
67
|
+
md += `
|
|
68
|
+
#### Áreas: ${areas.map((a) => a.name).join(", ")}
|
|
69
|
+
Skills específicos de las áreas donde eres miembro.
|
|
70
|
+
|
|
71
|
+
${areas.map((a) => `\`\`\`bash\nskill-manager list --filter area/${a.slug}\n\`\`\``).join("\n")}
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Teams
|
|
76
|
+
const teams = entities.filter((e) => e.type === "team");
|
|
77
|
+
if (teams.length > 0) {
|
|
78
|
+
md += `
|
|
79
|
+
#### Equipos: ${teams.map((t) => t.name).join(", ")}
|
|
80
|
+
Skills específicos de tus equipos.
|
|
81
|
+
|
|
82
|
+
${teams.map((t) => `\`\`\`bash\nskill-manager list --filter team/${t.slug}\n\`\`\``).join("\n")}
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Sectors
|
|
87
|
+
const sectors = entities.filter((e) => e.type === "sector");
|
|
88
|
+
if (sectors.length > 0) {
|
|
89
|
+
md += `
|
|
90
|
+
#### Sectores: ${sectors.map((s) => s.name).join(", ")}
|
|
91
|
+
|
|
92
|
+
${sectors.map((s) => `\`\`\`bash\nskill-manager list --filter sector/${s.slug}\n\`\`\``).join("\n")}
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Projects
|
|
97
|
+
if (projects.length > 0) {
|
|
98
|
+
md += `
|
|
99
|
+
#### Proyectos: ${projects.map((p) => p.name).join(", ")}
|
|
100
|
+
Skills específicos de tus proyectos asignados.
|
|
101
|
+
|
|
102
|
+
${projects.map((p) => `\`\`\`bash\nskill-manager list --filter proyecto/${p.slug}\n\`\`\``).join("\n")}
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
md += `
|
|
107
|
+
### Qué NO hacer
|
|
108
|
+
- No menciones skills de áreas, equipos o proyectos que no aparecen en las secciones anteriores
|
|
109
|
+
- No muestres el catálogo completo — recomienda solo lo relevante al contexto actual
|
|
110
|
+
- No expongas emails, tokens ni información interna del sistema
|
|
111
|
+
- No intentes modificar archivos de configuración del skill manager directamente
|
|
112
|
+
- No instales skills tú mismo — siempre recomienda el comando CLI al usuario
|
|
113
|
+
|
|
114
|
+
### Comandos útiles
|
|
115
|
+
- Ver todo lo disponible: \`skill-manager list\`
|
|
116
|
+
- Filtrar: \`skill-manager list --filter <texto>\`
|
|
117
|
+
- Instalar: \`skill-manager install <path>\`
|
|
118
|
+
- Ver quién eres: \`skill-manager whoami\`
|
|
119
|
+
- Actualizar este skill: \`skill-manager sync\`
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
return md;
|
|
123
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
const CONFIG_DIR = join(homedir(), ".skill-manager");
|
|
6
|
+
const INSTALLED_FILE = join(CONFIG_DIR, "installed.json");
|
|
7
|
+
const CHECK_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8
|
+
|
|
9
|
+
async function loadInstalled() {
|
|
10
|
+
try {
|
|
11
|
+
const raw = await readFile(INSTALLED_FILE, "utf-8");
|
|
12
|
+
return JSON.parse(raw);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (err.code === "ENOENT") return { lastCheckAt: null, skills: [] };
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function saveInstalled(data) {
|
|
20
|
+
await mkdir(CONFIG_DIR, { recursive: true });
|
|
21
|
+
await writeFile(INSTALLED_FILE, JSON.stringify(data, null, 2) + "\n");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function trackInstall(skill, tool, scope) {
|
|
25
|
+
// Never track auto-generated _index skills
|
|
26
|
+
if (skill.path.endsWith("/_index")) return;
|
|
27
|
+
|
|
28
|
+
const data = await loadInstalled();
|
|
29
|
+
|
|
30
|
+
// Remove existing entry for same path + projectDir
|
|
31
|
+
const projectDir = scope === "project" ? process.cwd() : null;
|
|
32
|
+
data.skills = data.skills.filter(
|
|
33
|
+
(s) => !(s.path === skill.path && s.projectDir === projectDir)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
data.skills.push({
|
|
37
|
+
path: skill.path,
|
|
38
|
+
version: skill.version,
|
|
39
|
+
skillId: skill.id,
|
|
40
|
+
companyId: skill.company_id,
|
|
41
|
+
installedAt: new Date().toISOString(),
|
|
42
|
+
tool,
|
|
43
|
+
scope,
|
|
44
|
+
projectDir,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
await saveInstalled(data);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function getInstalledSkills() {
|
|
51
|
+
const data = await loadInstalled();
|
|
52
|
+
return data.skills || [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function updateInstalledVersion(path, newVersion) {
|
|
56
|
+
const data = await loadInstalled();
|
|
57
|
+
for (const s of data.skills) {
|
|
58
|
+
if (s.path === path) {
|
|
59
|
+
s.version = newVersion;
|
|
60
|
+
s.installedAt = new Date().toISOString();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await saveInstalled(data);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function shouldCheckUpdates() {
|
|
67
|
+
const data = await loadInstalled();
|
|
68
|
+
if (!data.lastCheckAt) return true;
|
|
69
|
+
return Date.now() - new Date(data.lastCheckAt).getTime() > CHECK_INTERVAL_MS;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function markChecked() {
|
|
73
|
+
const data = await loadInstalled();
|
|
74
|
+
data.lastCheckAt = new Date().toISOString();
|
|
75
|
+
await saveInstalled(data);
|
|
76
|
+
}
|