nexakit 0.2.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 +11 -0
- package/assets/runtime/package-lock.json +2 -2
- package/catalogs/generadores.json +936 -0
- package/package.json +1 -1
- package/plugins/nexakit-panel/hooks/panel.js +2 -8
- package/plugins/nexakit-panel/hooks/redact.js +9 -0
- package/schemas/generators.schema.json +299 -0
- package/scripts/prepare-package.js +3 -0
- package/src/clean-command.js +29 -0
- package/src/clean-project-flow.js +105 -0
- package/src/clean-project.js +431 -0
- package/src/cli-executable.js +1 -1
- package/src/gemini-files.js +3 -3
- package/src/gemini-tools.js +23 -8
- package/src/generators-catalog.js +63 -0
- package/src/project-root.js +21 -2
- package/src/project-signals.js +6 -0
- package/src/redact.js +9 -0
- package/src/setup-state.js +7 -0
- package/src/setup-tui.js +98 -6
- package/src/skill-recommendations.js +25 -2
package/src/setup-tui.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { createCleanProject } from './clean-project-flow.js';
|
|
1
2
|
// `npx nexakit`: three questions with the answer already suggested (skills, memory, agents) and one confirmation,
|
|
2
3
|
// in the style of `npm create vite`. Answered questions fold into one ◇ line; the active one uses ◆. The model,
|
|
3
4
|
// the drawing and the keys are pure, so every screen is tested as text; runSetupTui is the only part with I/O.
|
|
4
5
|
import os from 'node:os';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
import { planCleanProject, checkRequirements } from './clean-project.js';
|
|
8
|
+
import { runCleanCommand } from './clean-command.js';
|
|
5
9
|
import path from 'node:path';
|
|
6
10
|
import { applySetup } from './setup-apply.js';
|
|
7
11
|
import { AGENTS, AGENT_NAMES, buildConfirmation, joinNames, shortPath, suggestedAnswers } from './setup-plan.js';
|
|
@@ -64,9 +68,20 @@ export function createSetupModel(state) {
|
|
|
64
68
|
};
|
|
65
69
|
model.memoryChoice = answers.memory.decision === 'later' ? 'later'
|
|
66
70
|
: answers.memory.path === (state.memory.existing?.vaultPath ?? state.memory.suggestedPath) ? memoryOptions(model)[0] : 'other';
|
|
71
|
+
model.cleanChoice = {frontend:null,backend:null,database:null,mobile:null};
|
|
72
|
+
model.cleanGit = true; model.cleanFolder = state.creationRoot ?? state.project.root;
|
|
73
|
+
model.folderInput = ''; model.requirements = null; model.cleanPlan = null;
|
|
74
|
+
if (state.folder && !state.savedAnswers && !state.cleanProject) { model.step = 'mode'; model.cursor = state.folder.empty ? 0 : 1; }
|
|
75
|
+
if (state.cleanProject && state.cleanProject.status !== 'creado') model.step = 'clean-failed';
|
|
67
76
|
return model;
|
|
68
77
|
}
|
|
69
78
|
|
|
79
|
+
const cleanParts = ['frontend','backend','database','mobile'];
|
|
80
|
+
function technologyOptions(model, part) {
|
|
81
|
+
return model.state.generators.generators.filter(g=>g.part===part && (part!=='database' || model.cleanChoice.backend || g.id==='supabase'));
|
|
82
|
+
}
|
|
83
|
+
function goTechnology(model, part) { return go(model, `tech-${part}`, {cursor:part==='frontend'?0:technologyOptions(model,part).length}); }
|
|
84
|
+
|
|
70
85
|
// Leaving the skills question: a suggestion left unchecked is remembered as discarded, so it is not offered again.
|
|
71
86
|
function closeSkills(model) {
|
|
72
87
|
const chosen = model.state.skills.filter(skill => model.answers.skills.chosen.includes(skill.name)).map(skill => skill.name);
|
|
@@ -97,9 +112,20 @@ const previousOf = (model, step) => {
|
|
|
97
112
|
};
|
|
98
113
|
|
|
99
114
|
export function handleSetupKey(model, key) {
|
|
100
|
-
if (key === '\x03') return { model, effect: 'exit' };
|
|
115
|
+
if (key === '\x03') return ['creating','applying'].includes(model.step) ? {model} : { model, effect: 'exit' };
|
|
101
116
|
const { step } = model;
|
|
102
117
|
|
|
118
|
+
if (step === 'clean-folder') {
|
|
119
|
+
if (is(key,'enter')) {
|
|
120
|
+
const name = model.folderInput.trim();
|
|
121
|
+
if (!name || /[\\/:\x00-\x1f]/.test(name) || ['.','..','.git','.agent-toolkit'].includes(name)) return {model:{...model,message:'Escribe el nombre de una subcarpeta nueva.'}};
|
|
122
|
+
return {model,effect:'check-clean-folder',path:path.join(model.cleanFolder,name)};
|
|
123
|
+
}
|
|
124
|
+
if (key==='\x1b') return {model:go(model,'mode')};
|
|
125
|
+
if (key==='\x7f'||key==='\x08') return {model:{...model,folderInput:[...model.folderInput].slice(0,-1).join('')}};
|
|
126
|
+
if (/^[^\x00-\x1f\x7f]+$/u.test(key) && !key.startsWith('\x1b')) return {model:{...model,folderInput:model.folderInput+key,message:null}};
|
|
127
|
+
return {model};
|
|
128
|
+
}
|
|
103
129
|
if (step === 'memory-path') {
|
|
104
130
|
if (is(key, 'enter')) {
|
|
105
131
|
const raw = model.memoryInput.trim();
|
|
@@ -113,7 +139,41 @@ export function handleSetupKey(model, key) {
|
|
|
113
139
|
return { model };
|
|
114
140
|
}
|
|
115
141
|
|
|
116
|
-
if (is(key, 'quit') && !['applying'].includes(step)) return { model, effect: 'exit' };
|
|
142
|
+
if (is(key, 'quit') && !['applying','creating'].includes(step)) return { model, effect: 'exit' };
|
|
143
|
+
|
|
144
|
+
if (step==='mode') {
|
|
145
|
+
if(is(key,'up')||is(key,'down')) return {model:{...model,cursor:model.cursor===0?1:0}};
|
|
146
|
+
if(is(key,'enter')) return {model:model.cursor===1?go(model,'skills'):model.state.folder.empty?goTechnology(model,'frontend'):go(model,'clean-folder')};
|
|
147
|
+
return {model};
|
|
148
|
+
}
|
|
149
|
+
if (step.startsWith('tech-')) {
|
|
150
|
+
const part=step.slice(5), options=technologyOptions(model,part);
|
|
151
|
+
if(is(key,'up')) return {model:{...model,cursor:Math.max(0,model.cursor-1)}};
|
|
152
|
+
if(is(key,'down')) return {model:{...model,cursor:Math.min(options.length,model.cursor+1)}};
|
|
153
|
+
if(is(key,'back')) { const i=cleanParts.indexOf(part);return {model:i?goTechnology(model,cleanParts[i-1]):go(model,'mode')}; }
|
|
154
|
+
if(is(key,'enter')) {
|
|
155
|
+
const next={...model,cleanChoice:{...model.cleanChoice,[part]:options[model.cursor]?.id ?? null}};
|
|
156
|
+
if(part==='backend' && !next.cleanChoice.backend) next.cleanChoice.database=null;
|
|
157
|
+
if(part!=='mobile') return {model:goTechnology(next,cleanParts[cleanParts.indexOf(part)+1])};
|
|
158
|
+
if(!next.cleanChoice.frontend && !next.cleanChoice.backend && !next.cleanChoice.mobile) return {model:{...next,message:'Elige al menos una parte.'}};
|
|
159
|
+
if(next.cleanChoice.database==='supabase' && !next.cleanChoice.frontend && !next.cleanChoice.backend) return {model:{...next,message:'Supabase necesita frontend o backend.'}};
|
|
160
|
+
return next.state.folder.insideGit ? {model:go(next,'clean-confirm'),effect:'prepare-clean'} : {model:go(next,'git')};
|
|
161
|
+
}
|
|
162
|
+
return {model};
|
|
163
|
+
}
|
|
164
|
+
if(step==='git') {
|
|
165
|
+
if(is(key,'toggle')||is(key,'left')||is(key,'right')) return {model:{...model,cleanGit:!model.cleanGit}};
|
|
166
|
+
if(is(key,'enter')) return {model:go(model,'clean-confirm'),effect:'prepare-clean'};
|
|
167
|
+
if(is(key,'back')) return {model:goTechnology(model,'mobile')};
|
|
168
|
+
return {model};
|
|
169
|
+
}
|
|
170
|
+
if(step==='clean-confirm') {
|
|
171
|
+
if(is(key,'back')) return {model:goTechnology(model,'mobile')};
|
|
172
|
+
if(is(key,'enter') && model.cleanPlan && model.requirements && model.requirements.every(r=>r.ok)) return {model,effect:'create-project',choice:model.cleanChoice,git:!model.state.folder.insideGit && model.cleanGit,folder:model.cleanFolder};
|
|
173
|
+
return {model};
|
|
174
|
+
}
|
|
175
|
+
if(step==='clean-failed') return is(key,'enter') ? {model:go(model,'skills')} : {model};
|
|
176
|
+
if(step==='creating') return {model};
|
|
117
177
|
|
|
118
178
|
if (step === 'done' || step === 'detached') return { model, effect: 'exit' };
|
|
119
179
|
if (step === 'applying') return { model };
|
|
@@ -234,7 +294,21 @@ function folded(model) {
|
|
|
234
294
|
function question(model) {
|
|
235
295
|
const { state, answers } = model;
|
|
236
296
|
const home = state.homeDirectory;
|
|
297
|
+
if (model.step.startsWith('tech-')) {
|
|
298
|
+
const part=model.step.slice(5),labels={frontend:'frontend',backend:'backend',database:'base de datos',mobile:'app móvil'};
|
|
299
|
+
const options=[...technologyOptions(model,part).map(g=>g.label),`No quiero ${labels[part]}`];
|
|
300
|
+
return {title:`Elige ${labels[part]}`,body:options.map((text,i)=>({text:`${i===model.cursor?'●':'○'} ${text}`,cursor:i===model.cursor})),info:model.message?[model.message]:[],keys:'↑/↓ elegir · Enter continuar · q salir'};
|
|
301
|
+
}
|
|
237
302
|
switch (model.step) {
|
|
303
|
+
case 'mode': return {title:'¿Proyecto limpio o ya empezado?',body:['Proyecto limpio: crear la base desde cero','Ya empezado: preparar lo que hay'].map((text,i)=>({text:`${i===model.cursor?'●':'○'} ${text}`,cursor:i===model.cursor})),info:[],keys:'↑/↓ elegir · Enter continuar · q salir'};
|
|
304
|
+
case 'clean-folder': return {title:'Nombre de la subcarpeta nueva',body:[{text:model.folderInput+'▌'}],info:model.message?[model.message]:[],keys:'Enter comprobar · Esc volver'};
|
|
305
|
+
case 'git': return {title:'¿Inicio Git con un primer commit?',body:[{text:model.cleanGit?'● Sí / ○ No':'○ Sí / ● No'}],info:[],keys:'←/→ cambiar · Enter continuar · q salir'};
|
|
306
|
+
case 'clean-confirm': return {title:'¿Creo la base del proyecto?',body:(model.cleanPlan?.parts ?? []).flatMap(p=>[
|
|
307
|
+
{text:`${p.part}: ${p.id} → ${p.dir}`},...(p.commands.some(c=>/\.venv[\\/]/.test(c.argv[0]))?[{text:`${p.dir}: ${process.platform==='win32'?'py':'python3'} -m venv .venv`}]:[]),...p.commands.map(c=>({text:`${c.cwd}: ${c.argv.map(a=>JSON.stringify(a)).join(' ')}`})),
|
|
308
|
+
...p.writes.map(w=>({text:`Crear ${w.path}: ${w.content}`})),{text:`Comprobar ${p.check.cwd}: ${p.check.argv.map(a=>JSON.stringify(a)).join(' ')}`}]),
|
|
309
|
+
info:model.requirements===null?['Comprobando requisitos…']:[...(model.state.folder?.insideGit?['El commit queda a tu cargo en el repositorio existente.']:model.cleanGit?['git init','git add -A','git commit -m \"chore: crear la base del proyecto con nexakit\"']:[]),...model.requirements.filter(r=>!r.ok).map(r=>`! Falta ${r.program} ${r.minVersion} o superior (${r.found ?? 'no encontrado'}).`),...(model.message?[model.message]:[])],keys:'Enter crear · retroceso volver · q salir'};
|
|
310
|
+
case 'creating': return {title:'Creando el proyecto…',body:(model.cleanProgress ?? []).map(text=>({text})),info:[],keys:'Espera a que termine la orden'};
|
|
311
|
+
case 'clean-failed': return {title:'La creación no terminó',body:[{text:model.cleanFailure ?? `Revisa el registro en .agent-toolkit/creacion.log.`}],info:['Se conserva lo creado. Enter prepara lo existente.'],keys:'Enter continuar · q salir'};
|
|
238
312
|
case 'skills': {
|
|
239
313
|
const rows = skillRows(model);
|
|
240
314
|
const width = Math.min(28, Math.max(...rows.filter(r => r.skill).map(r => r.skill.name.length), 10));
|
|
@@ -249,7 +323,7 @@ function question(model) {
|
|
|
249
323
|
const missing = state.uncoveredTech?.length
|
|
250
324
|
? ['', ...wrapText(`Sin skill en el catálogo: ${joinNames(state.uncoveredTech.map(item => item.label))}. Para buscar una, pide a tu IA «busca una skill para ${state.uncoveredTech[0].label}».`, 60)]
|
|
251
325
|
: [];
|
|
252
|
-
const info = [...(model.info && current ? ['', ...wrapText(current.summary, 60), ...skillTrust(current)] : []), ...external, ...missing];
|
|
326
|
+
const info = [...(model.message?[model.message]:[]), ...(model.info && current ? ['', ...wrapText(current.summary, 60), ...skillTrust(current)] : []), ...external, ...missing];
|
|
253
327
|
return { title: '¿Qué skills quieres?', body, info, keys: 'espacio marcar · i qué hace · Enter seguir · q salir' };
|
|
254
328
|
}
|
|
255
329
|
case 'memory': {
|
|
@@ -463,12 +537,13 @@ export function renderSetupFrame(model, { columns = 80, rows, color = true } = {
|
|
|
463
537
|
return `${header.join('\n')}\n${body}`;
|
|
464
538
|
}
|
|
465
539
|
|
|
466
|
-
export async function runSetupTui({ input = process.stdin, output = process.stdout, options = {}, applyOptions = {} } = {}) {
|
|
540
|
+
export async function runSetupTui({ input = process.stdin, output = process.stdout, options = {}, applyOptions = {}, gather = gatherSetupState } = {}) {
|
|
467
541
|
const level = colorLevel(output);
|
|
468
542
|
const home = options.homeDirectory ?? os.homedir();
|
|
469
543
|
output.write('Revisando el proyecto…\n');
|
|
470
|
-
let model = createSetupModel(await
|
|
544
|
+
let model = createSetupModel(await gather(options));
|
|
471
545
|
let exitCode = 0;
|
|
546
|
+
let creationController;
|
|
472
547
|
// The questions live on the alternate screen, where moving home and erasing redraws in place: clearing the
|
|
473
548
|
// normal screen pushes a copy of every frame into the scrollback in most terminals. On exit the last frame is
|
|
474
549
|
// printed once on the normal screen, so the result stays readable.
|
|
@@ -499,6 +574,22 @@ export async function runSetupTui({ input = process.stdin, output = process.stdo
|
|
|
499
574
|
kind, mcpName: `${model.state.project.id}-memory` })
|
|
500
575
|
: null;
|
|
501
576
|
model = applyMemoryPathCheck(model, extra.path, kind, connections);
|
|
577
|
+
} else if (effect === 'check-clean-folder') {
|
|
578
|
+
const exists=await fs.lstat(extra.path).catch(e=>{if(e.code==='ENOENT')return null;throw e;});
|
|
579
|
+
model=exists?{...model,message:'Esa carpeta ya existe. Elige otra.'}:goTechnology({...model,cleanFolder:extra.path},'frontend');
|
|
580
|
+
} else if (effect === 'prepare-clean') {
|
|
581
|
+
try {
|
|
582
|
+
const cleanPlan=planCleanProject({choice:model.cleanChoice,catalog:model.state.generators,name:path.basename(model.cleanFolder)});
|
|
583
|
+
const requirements=await checkRequirements(cleanPlan,model.state.generators,{runCommand:options.runCommand ?? runCleanCommand});
|
|
584
|
+
model={...model,cleanPlan,requirements};
|
|
585
|
+
} catch(e) { model={...model,cleanPlan:null,requirements:[],message:e.message}; }
|
|
586
|
+
} else if (effect === 'create-project') {
|
|
587
|
+
model={...model,step:'creating',cleanProgress:[]}; creationController=new AbortController(); render();
|
|
588
|
+
const result=await createCleanProject({...extra,insideGit:model.state.folder.insideGit},{options,gather,signal:creationController.signal,runCommand:options.runCommand ?? runCleanCommand,
|
|
589
|
+
onProgress:(part,argv)=>{model={...model,cleanProgress:[`${part}: ${argv.join(' ')}`]};render();}});
|
|
590
|
+
if(result.state){options={...options,start:result.state.project.root};model=createSetupModel(result.state);}
|
|
591
|
+
if(result.ok){model={...model,step:'skills',flow:'full',message:result.gitResult==='sin-git'?'Git no está instalado; seguimos sin él.':null};}
|
|
592
|
+
else{exitCode=1;model={...model,step:'clean-failed',cleanFailure:`${result.failed.part}: ${result.failed.argv.join(' ')}\n${result.failed.output}\nRegistro: .agent-toolkit/creacion.log`};}
|
|
502
593
|
} else if (effect === 'apply') {
|
|
503
594
|
const labels = Object.fromEntries(buildConfirmation(model.state, model.answers).blocks.map(block => [block.id, block.label]));
|
|
504
595
|
model = { ...model, step: 'applying', progress: [] };
|
|
@@ -533,7 +624,8 @@ export async function runSetupTui({ input = process.stdin, output = process.stdo
|
|
|
533
624
|
};
|
|
534
625
|
const onData = chunk => {
|
|
535
626
|
const key = typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
536
|
-
if
|
|
627
|
+
if(key === '\x03' && model.step==='creating'){creationController?.abort();return;}
|
|
628
|
+
if (key === '\x03' && !['applying','creating'].includes(model.step)) return cleanup(exitCode);
|
|
537
629
|
chain = chain.then(() => handle(key)).catch(error => {
|
|
538
630
|
model = { ...model, step: 'done', result: { ok: false, failed: { message: error instanceof Error ? error.message : String(error) } } };
|
|
539
631
|
exitCode = 1;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import generatorsData from '../catalogs/generadores.json' with { type: 'json' };
|
|
1
2
|
import { ownedReviewInstructions, removeReviewInstructions } from './review-instructions.js';
|
|
2
3
|
import { createHash } from 'node:crypto';
|
|
3
4
|
import fs from 'node:fs/promises';
|
|
@@ -1143,13 +1144,35 @@ export async function applyProjectSkillLinks(plan) {
|
|
|
1143
1144
|
// so a second run knows what was decided and does not ask again.
|
|
1144
1145
|
const isNameList = value => Array.isArray(value) && value.every(item => typeof item === 'string' && SKILL_NAME_RE.test(item));
|
|
1145
1146
|
function validSetupAnswers(answers) {
|
|
1146
|
-
return Boolean(answers && answers.version === 1 &&
|
|
1147
|
+
return Boolean(answers && (answers.cleanProject === undefined || validCleanProject(answers.cleanProject)) && answers.version === 1 &&
|
|
1147
1148
|
isNameList(answers.skills?.chosen) && isNameList(answers.skills?.discarded) &&
|
|
1148
1149
|
Array.isArray(answers.agents) && answers.agents.every(agent => ['claude', 'codex', 'antigravity'].includes(agent)) &&
|
|
1149
1150
|
(answers.memory?.decision === 'later' ||
|
|
1150
1151
|
(answers.memory?.decision === 'path' && typeof answers.memory.path === 'string' && path.isAbsolute(answers.memory.path))));
|
|
1151
1152
|
}
|
|
1152
1153
|
|
|
1154
|
+
function validCleanProject(value) {
|
|
1155
|
+
if (!value || typeof value.git !== 'boolean' || !['confirmado','creado','fallido'].includes(value.status) || !value.choice) return false;
|
|
1156
|
+
const parts = ['frontend','backend','database','mobile'];
|
|
1157
|
+
if (Object.keys(value.choice).some(p=>!parts.includes(p))) return false;
|
|
1158
|
+
return parts.every(part => value.choice[part] === null || generatorsData.generators.some(g=>g.id===value.choice[part] && g.part===part))
|
|
1159
|
+
&& (value.failedPart === undefined || ['frontend','backend','mobile','proyecto'].includes(value.failedPart));
|
|
1160
|
+
}
|
|
1161
|
+
export async function readCleanProjectAnswers(projectRoot) {
|
|
1162
|
+
const value = (await readProjectToolkitManifest(projectRoot))?.answers?.cleanProject;
|
|
1163
|
+
return validCleanProject(value) ? value : null;
|
|
1164
|
+
}
|
|
1165
|
+
export async function writeCleanProjectAnswers(projectRoot, cleanProject, lock) {
|
|
1166
|
+
if (!validCleanProject(cleanProject)) throw new Error('Respuestas del proyecto limpio no válidas.');
|
|
1167
|
+
await lock.assertHeld();
|
|
1168
|
+
const previous = await readProjectToolkitManifest(projectRoot);
|
|
1169
|
+
const result = await writeProjectManifestAndIgnore({projectRoot,mode:previous?.mode ?? 'symlink',
|
|
1170
|
+
gitIgnore:previous?.gitIgnoreStrategy ?? 'gitignore',prevManifest:previous,
|
|
1171
|
+
coupledEntriesMap:new Map((previous?.entries ?? []).map(e=>[e.relativePath,e])),lock,
|
|
1172
|
+
answers:{version:1,...previous?.answers,cleanProject}});
|
|
1173
|
+
if (!result.manifestWritten) throw new Error('No se guardaron las respuestas del proyecto limpio.');
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1153
1176
|
export async function readSetupAnswers(projectRoot) {
|
|
1154
1177
|
const manifest = await readProjectToolkitManifest(projectRoot);
|
|
1155
1178
|
return validSetupAnswers(manifest?.answers) ? manifest.answers : null;
|
|
@@ -1166,7 +1189,7 @@ export async function writeSetupAnswers(projectRoot, answers, lock) {
|
|
|
1166
1189
|
prevManifest,
|
|
1167
1190
|
coupledEntriesMap: new Map((prevManifest?.entries ?? []).map(entry => [entry.relativePath, entry])),
|
|
1168
1191
|
lock,
|
|
1169
|
-
answers
|
|
1192
|
+
answers: { ...answers, ...(prevManifest?.answers?.cleanProject && !answers.cleanProject && {cleanProject:prevManifest.answers.cleanProject}) }
|
|
1170
1193
|
});
|
|
1171
1194
|
if (!result.manifestWritten) throw new Error(`${PROJECT_TOOLKIT_DIR} no es una carpeta normal; no se guardaron las respuestas.`);
|
|
1172
1195
|
}
|