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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexakit",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Asistente por pasos de skills verificadas por SHA-256, coordinación entre agentes y memoria por proyecto para Claude Code y Codex.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,3 +1,4 @@
1
+ import { sinSecretos } from './redact.js';
1
2
  // Lógica pura del panel: reduce los eventos de la sesión a un estado que el panel dibuja. Sin datos inventados:
2
3
  // todo sale de lo que el motor informa (pasos, subagentes, llamadas del servidor, herramientas).
3
4
  export const MAX_REGISTRO = 60;
@@ -223,14 +224,7 @@ export function registrarRecomendacion(estado, { modelo, esfuerzo, motivo }) {
223
224
  return { ...estado, recomendacion: { modelo, esfuerzo, motivo } };
224
225
  }
225
226
 
226
- // Tacha los secretos evidentes de un detalle antes de mostrarlo o guardarlo en disco.
227
- export function sinSecretos(texto) {
228
- return String(texto)
229
- .replace(/\b([A-Za-z0-9_]*(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD)[A-Za-z0-9_]*)=([^\s"']+)/giu, '$1=***')
230
- .replace(/(Bearer\s+)[^\s"']+/giu, '$1***')
231
- .replace(/(--?(?:password|passwd|token|secret|api-key)[= ])[^\s"']+/giu, '$1***');
232
- }
233
-
227
+ export { sinSecretos } from './redact.js';
234
228
  // --- Revisiones que la sesión manda a otra IA con `nexakit revision --con <ia>` -----------------------------------
235
229
  export function esRevision(comando) {
236
230
  const c = String(comando ?? '');
@@ -0,0 +1,9 @@
1
+ // Tacha los secretos evidentes de un detalle antes de mostrarlo o guardarlo en disco.
2
+ export function sinSecretos(texto) {
3
+ return String(texto)
4
+ .replace(/([a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:)[^\s@]+@/giu, '$1***@')
5
+ .replace(/\b([A-Za-z0-9_]*(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD)[A-Za-z0-9_]*)=([^\s"']+)/giu, '$1=***')
6
+ .replace(/(Bearer\s+)[^\s"']+/giu, '$1***')
7
+ .replace(/(--?(?:password|passwd|token|secret|api-key)[= ])[^\s"']+/giu, '$1***');
8
+ }
9
+
@@ -0,0 +1,299 @@
1
+ {
2
+ "type": "object",
3
+ "additionalProperties": false,
4
+ "properties": {
5
+ "schemaVersion": {
6
+ "const": "1.0.0"
7
+ },
8
+ "generators": {
9
+ "type": "array",
10
+ "minItems": 1,
11
+ "items": {
12
+ "type": "object",
13
+ "additionalProperties": false,
14
+ "properties": {
15
+ "id": {
16
+ "type": "string",
17
+ "pattern": "^[a-z0-9-]+$"
18
+ },
19
+ "part": {
20
+ "enum": [
21
+ "frontend",
22
+ "backend",
23
+ "database",
24
+ "mobile"
25
+ ]
26
+ },
27
+ "label": {
28
+ "type": "string",
29
+ "minLength": 1
30
+ },
31
+ "signals": {
32
+ "type": "array",
33
+ "uniqueItems": true,
34
+ "items": {
35
+ "type": "string",
36
+ "minLength": 1
37
+ }
38
+ },
39
+ "requires": {
40
+ "type": "array",
41
+ "items": {
42
+ "type": "object",
43
+ "additionalProperties": false,
44
+ "properties": {
45
+ "program": {
46
+ "enum": [
47
+ "node",
48
+ "python"
49
+ ]
50
+ },
51
+ "minVersion": {
52
+ "type": "string",
53
+ "pattern": "^\\d+\\.\\d+$"
54
+ }
55
+ },
56
+ "required": [
57
+ "program",
58
+ "minVersion"
59
+ ]
60
+ }
61
+ },
62
+ "steps": {
63
+ "type": "array",
64
+ "items": {
65
+ "oneOf": [
66
+ {
67
+ "type": "object",
68
+ "additionalProperties": false,
69
+ "properties": {
70
+ "kind": {
71
+ "const": "run"
72
+ },
73
+ "argv": {
74
+ "type": "array",
75
+ "minItems": 1,
76
+ "items": {
77
+ "type": "string",
78
+ "minLength": 1
79
+ }
80
+ },
81
+ "cwd": {
82
+ "enum": [
83
+ "parent",
84
+ "dir"
85
+ ]
86
+ }
87
+ },
88
+ "required": [
89
+ "kind",
90
+ "argv",
91
+ "cwd"
92
+ ]
93
+ },
94
+ {
95
+ "type": "object",
96
+ "additionalProperties": false,
97
+ "properties": {
98
+ "kind": {
99
+ "const": "write"
100
+ },
101
+ "path": {
102
+ "type": "string",
103
+ "minLength": 1
104
+ },
105
+ "content": {
106
+ "type": "string"
107
+ }
108
+ },
109
+ "required": [
110
+ "kind",
111
+ "path",
112
+ "content"
113
+ ]
114
+ }
115
+ ]
116
+ }
117
+ },
118
+ "install": {
119
+ "type": "array",
120
+ "items": {
121
+ "oneOf": [
122
+ {
123
+ "type": "object",
124
+ "additionalProperties": false,
125
+ "properties": {
126
+ "kind": {
127
+ "const": "run"
128
+ },
129
+ "argv": {
130
+ "type": "array",
131
+ "minItems": 1,
132
+ "items": {
133
+ "type": "string",
134
+ "minLength": 1
135
+ }
136
+ },
137
+ "cwd": {
138
+ "enum": [
139
+ "parent",
140
+ "dir"
141
+ ]
142
+ }
143
+ },
144
+ "required": [
145
+ "kind",
146
+ "argv",
147
+ "cwd"
148
+ ]
149
+ },
150
+ {
151
+ "type": "object",
152
+ "additionalProperties": false,
153
+ "properties": {
154
+ "kind": {
155
+ "const": "write"
156
+ },
157
+ "path": {
158
+ "type": "string",
159
+ "minLength": 1
160
+ },
161
+ "content": {
162
+ "type": "string"
163
+ }
164
+ },
165
+ "required": [
166
+ "kind",
167
+ "path",
168
+ "content"
169
+ ]
170
+ }
171
+ ]
172
+ }
173
+ },
174
+ "check": {
175
+ "type": "object",
176
+ "additionalProperties": false,
177
+ "properties": {
178
+ "argv": {
179
+ "type": "array",
180
+ "minItems": 1,
181
+ "items": {
182
+ "type": "string",
183
+ "minLength": 1
184
+ }
185
+ },
186
+ "cwd": {
187
+ "const": "dir"
188
+ }
189
+ },
190
+ "required": [
191
+ "argv",
192
+ "cwd"
193
+ ]
194
+ },
195
+ "database": {
196
+ "type": "object",
197
+ "additionalProperties": false,
198
+ "properties": {
199
+ "backends": {
200
+ "type": "object",
201
+ "additionalProperties": {
202
+ "type": "object",
203
+ "additionalProperties": false,
204
+ "properties": {
205
+ "install": {
206
+ "type": "array",
207
+ "items": {
208
+ "oneOf": [
209
+ {
210
+ "type": "object",
211
+ "additionalProperties": false,
212
+ "properties": {
213
+ "kind": {
214
+ "const": "run"
215
+ },
216
+ "argv": {
217
+ "type": "array",
218
+ "minItems": 1,
219
+ "items": {
220
+ "type": "string",
221
+ "minLength": 1
222
+ }
223
+ },
224
+ "cwd": {
225
+ "enum": [
226
+ "parent",
227
+ "dir"
228
+ ]
229
+ }
230
+ },
231
+ "required": [
232
+ "kind",
233
+ "argv",
234
+ "cwd"
235
+ ]
236
+ },
237
+ {
238
+ "type": "object",
239
+ "additionalProperties": false,
240
+ "properties": {
241
+ "kind": {
242
+ "const": "write"
243
+ },
244
+ "path": {
245
+ "type": "string",
246
+ "minLength": 1
247
+ },
248
+ "content": {
249
+ "type": "string"
250
+ }
251
+ },
252
+ "required": [
253
+ "kind",
254
+ "path",
255
+ "content"
256
+ ]
257
+ }
258
+ ]
259
+ }
260
+ },
261
+ "envExample": {
262
+ "type": "string",
263
+ "minLength": 1
264
+ }
265
+ },
266
+ "required": [
267
+ "install"
268
+ ]
269
+ }
270
+ }
271
+ },
272
+ "required": [
273
+ "backends"
274
+ ]
275
+ },
276
+ "source": {
277
+ "type": "string",
278
+ "minLength": 1
279
+ }
280
+ },
281
+ "required": [
282
+ "id",
283
+ "part",
284
+ "label",
285
+ "signals",
286
+ "requires",
287
+ "steps",
288
+ "install",
289
+ "check"
290
+ ]
291
+ }
292
+ }
293
+ },
294
+ "required": [
295
+ "schemaVersion",
296
+ "generators"
297
+ ],
298
+ "$schema": "https://json-schema.org/draft/2020-12/schema"
299
+ }
@@ -4,3 +4,6 @@ import fs from 'node:fs/promises';
4
4
  // for the artifact verifier; this copy is generated on every pack, never edited.
5
5
  await fs.mkdir(new URL('../assets/runtime/', import.meta.url), { recursive: true });
6
6
  await fs.copyFile(new URL('../package-lock.json', import.meta.url), new URL('../assets/runtime/package-lock.json', import.meta.url));
7
+
8
+ // Bundle the shared redactor so a standalone plugin needs no parent package.
9
+ await fs.copyFile(new URL('../src/redact.js', import.meta.url), new URL('../plugins/nexakit-panel/hooks/redact.js', import.meta.url));
@@ -0,0 +1,29 @@
1
+ import { spawn, execFile } from 'node:child_process';
2
+ import { resolveCliInvocation } from './cli-executable.js';
3
+
4
+ // No shell, bounded output, stdin closed. The abort signal ends the process tree.
5
+ export async function runCleanCommand(command, args, { cwd, signal, env = process.env, onOutput = () => {} } = {}) {
6
+ if (process.platform === 'win32' && ['npm','npx'].includes(command)) {
7
+ const invocation = await resolveCliInvocation({ name: command, environment: env });
8
+ command = invocation.executable; args = [...invocation.argsPrefix, ...args];
9
+ }
10
+ return new Promise((resolve, reject) => {
11
+ const child = spawn(command, args, { cwd, env, shell:false, detached:process.platform !== 'win32', windowsHide:true, stdio:['ignore','pipe','pipe'] });
12
+ let stdout = '', stderr = '', size = 0;
13
+ const stop = () => {
14
+ if (!child.pid) return;
15
+ if (process.platform === 'win32') execFile('taskkill.exe', ['/pid', String(child.pid), '/t', '/f'], () => {});
16
+ else { try { process.kill(-child.pid, 'SIGKILL'); } catch {} }
17
+ };
18
+ const collect = key => chunk => {
19
+ size += chunk.length;
20
+ if (size > 16 * 1024 * 1024) { stop(); return; }
21
+ onOutput(String(chunk), key === 'out' ? 'stdout' : 'stderr');
22
+ if (key === 'out') stdout += chunk; else stderr += chunk;
23
+ };
24
+ child.stdout.on('data', collect('out')); child.stderr.on('data', collect('err'));
25
+ signal?.addEventListener('abort', stop, {once:true}); if (signal?.aborted) stop();
26
+ child.once('error', error => { signal?.removeEventListener('abort', stop); reject(error); });
27
+ child.once('close', status => { signal?.removeEventListener('abort', stop); resolve({status,stdout,stderr}); });
28
+ });
29
+ }
@@ -0,0 +1,105 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { loadGeneratorsCatalog } from './generators-catalog.js';
4
+ import {
5
+ planCleanProject,
6
+ checkRequirements,
7
+ runCleanProject,
8
+ initGit,
9
+ ensureCleanIgnore,
10
+ appendCleanLog,
11
+ } from './clean-project.js';
12
+ import { runCleanCommand } from './clean-command.js';
13
+ import { acquireLock } from './install-lock.js';
14
+ import { readCleanProjectAnswers, writeCleanProjectAnswers } from './skill-recommendations.js';
15
+ import { gatherSetupState } from './setup-state.js';
16
+
17
+ export async function createCleanProject(
18
+ { folder, choice, git, insideGit },
19
+ {
20
+ options = {},
21
+ runCommand = runCleanCommand,
22
+ onProgress = () => {},
23
+ gather = gatherSetupState,
24
+ timeoutMs,
25
+ platform = process.platform,
26
+ signal,
27
+ } = {},
28
+ ) {
29
+ const catalog = await loadGeneratorsCatalog();
30
+ const plan = planCleanProject({ choice, catalog, name: path.basename(folder), platform });
31
+ const requirements = await checkRequirements(plan, catalog, { runCommand, platform, signal });
32
+ if (requirements.some((r) => !r.ok))
33
+ return {
34
+ ok: false,
35
+ failed: { part: 'proyecto', argv: [], output: 'Faltan requisitos para crear el proyecto.' },
36
+ };
37
+ const stat = await fs.lstat(folder).catch((e) => {
38
+ if (e.code === 'ENOENT') return null;
39
+ throw e;
40
+ });
41
+ if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
42
+ throw Error('La carpeta del proyecto no es segura.');
43
+ if (!stat) await fs.mkdir(folder);
44
+ const root = await fs.realpath(folder),
45
+ saved = await readCleanProjectAnswers(root);
46
+ if (saved)
47
+ return {
48
+ ok: saved.status === 'creado',
49
+ state: await gather({ ...options, start: root }),
50
+ failed: {
51
+ part: 'proyecto',
52
+ argv: [],
53
+ output: 'La creación ya fue registrada; no se ejecutará sobre archivos existentes.',
54
+ },
55
+ };
56
+ const save = async (status) => {
57
+ const lock = await acquireLock(path.join(root, '.agent-toolkit'));
58
+ try {
59
+ await writeCleanProjectAnswers(root, { choice, git, ...status }, lock);
60
+ } finally {
61
+ await lock.release();
62
+ }
63
+ };
64
+ let confirmed = false;
65
+ const result = await runCleanProject(plan, {
66
+ projectRoot: root,
67
+ runCommand,
68
+ onProgress,
69
+ timeoutMs,
70
+ platform,
71
+ signal,
72
+ onCreated: async () => {
73
+ if (!confirmed) {
74
+ await save({ status: 'confirmado' });
75
+ confirmed = true;
76
+ }
77
+ },
78
+ });
79
+ if (!result.ok) {
80
+ await ensureCleanIgnore(root, plan.gitignore);
81
+ await save({ status: 'fallido', failedPart: result.failed.part });
82
+ return { ...result, state: await gather({ ...options, start: root }) };
83
+ }
84
+ let gitResult = 'omitido';
85
+ try {
86
+ await ensureCleanIgnore(root, plan.gitignore);
87
+ if (git && !insideGit)
88
+ gitResult = await initGit(root, {
89
+ runCommand,
90
+ insideGit,
91
+ gitignore: plan.gitignore,
92
+ onCommand: (argv, output) => appendCleanLog(root, `${argv.join(' ')}\n${output}`),
93
+ });
94
+ await save({ status: 'creado' });
95
+ return { ...result, gitResult, state: await gather({ ...options, start: root }) };
96
+ } catch (error) {
97
+ await save({ status: 'fallido', failedPart: 'proyecto' });
98
+ return {
99
+ ok: false,
100
+ done: result.done,
101
+ state: await gather({ ...options, start: root }),
102
+ failed: { part: 'proyecto', argv: error.argv ?? ['git'], output: error.message },
103
+ };
104
+ }
105
+ }