openprompt-lang 1.2.7 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +62 -8
  2. package/bin/cli.js +2 -0
  3. package/docs/00-ARCHITECTURE/OPL-BOOST-MULTI-AGENT.md +406 -0
  4. package/docs/02-STANDARDS/AGENTS.template.md +89 -0
  5. package/docs/02-STANDARDS/ticket-driven-development.md +99 -0
  6. package/docs/04-TICKETS/BOOST-001-profile-registry.md +66 -0
  7. package/docs/04-TICKETS/BOOST-002-context-compression.md +58 -0
  8. package/docs/04-TICKETS/BOOST-003-template-hydration.md +69 -0
  9. package/docs/04-TICKETS/BOOST-004-fewshot-engine.md +58 -0
  10. package/docs/04-TICKETS/BOOST-005-agent-pool.md +69 -0
  11. package/docs/04-TICKETS/BOOST-006-specialized-agents.md +53 -0
  12. package/docs/04-TICKETS/BOOST-007-validation-loop.md +56 -0
  13. package/docs/04-TICKETS/BOOST-008-orchestrator.md +71 -0
  14. package/docs/04-TICKETS/BOOST-009-cache-system.md +56 -0
  15. package/docs/04-TICKETS/BOOST-010-cli-mcp.md +67 -0
  16. package/docs/04-TICKETS/BOOST-011-self-learning.md +50 -0
  17. package/docs/04-TICKETS/BOOST-012-prompt-preamble.md +109 -0
  18. package/docs/04-TICKETS/BOOST-013-hydrator-duplicate-code.md +132 -0
  19. package/docs/04-TICKETS/BOOST-014-multiagent-missing-parts.md +87 -0
  20. package/docs/04-TICKETS/BOOST-015-skeleton-type-missing.md +76 -0
  21. package/docs/04-TICKETS/BOOST-016-output-path-duplicate.md +68 -0
  22. package/docs/04-TICKETS/INDEX.md +89 -0
  23. package/docs/04-TICKETS/_archive/BOOST-005-micro-tasking.md +67 -0
  24. package/docs/04-TICKETS/_archive/BOOST-006-validation-loop.md +66 -0
  25. package/docs/04-TICKETS/_archive/BOOST-007-progressive-pipeline.md +69 -0
  26. package/docs/04-TICKETS/_archive/BOOST-008-cli-mcp-integration.md +74 -0
  27. package/docs/AI_CONTEXT.md +16 -0
  28. package/docs/EMBEDDINGS.md +214 -0
  29. package/docs/ONBOARDING_WORKFLOW.md +151 -0
  30. package/docs/OPL_ACADEMIC_ISSUES.md +158 -0
  31. package/docs/WEB_SCRAPER_PLAN.md +454 -0
  32. package/package.json +9 -2
  33. package/scripts/postinstall.js +37 -0
  34. package/src/boost/agent-pool.js +442 -0
  35. package/src/boost/agents/index.js +79 -0
  36. package/src/boost/cache.js +241 -0
  37. package/src/boost/context-compressor.js +354 -0
  38. package/src/boost/fewshot-retriever.js +332 -0
  39. package/src/boost/hardware-detector.js +486 -0
  40. package/src/boost/hydrator.js +398 -0
  41. package/src/boost/index.js +60 -0
  42. package/src/boost/orchestrator.js +615 -0
  43. package/src/boost/preamble.js +217 -0
  44. package/src/boost/profile-registry.js +264 -0
  45. package/src/boost/self-learn.js +247 -0
  46. package/src/boost/skeletons/component.skeleton.js +24 -0
  47. package/src/boost/skeletons/hook.skeleton.js +27 -0
  48. package/src/boost/skeletons/index.js +67 -0
  49. package/src/boost/skeletons/page.skeleton.js +22 -0
  50. package/src/boost/skeletons/service.skeleton.js +20 -0
  51. package/src/boost/skeletons/store.skeleton.js +18 -0
  52. package/src/boost/skeletons/type.skeleton.js +11 -0
  53. package/src/boost/task-dispatcher.js +142 -0
  54. package/src/boost/validation-loop.js +495 -0
  55. package/src/cli/commands-boost.js +394 -0
  56. package/src/cli/commands-knowledge.js +1 -0
  57. package/src/cli/commands-opl.js +79 -1
  58. package/src/cli/commands-workflow.js +125 -6
  59. package/src/commands/init-core.js +169 -5
  60. package/src/commands/knowledge-ops.js +52 -0
  61. package/src/commands/opl-embeddings.js +556 -0
  62. package/src/commands/opl-help.js +26 -2
  63. package/src/commands/opl-search.js +106 -2
  64. package/src/commands/opl-webscrape.js +390 -0
  65. package/src/commands/workflow/epic-cli.js +192 -0
  66. package/src/commands/workflow/select.js +146 -0
  67. package/src/commands/workflow/sprint-cli.js +174 -0
  68. package/src/core/webscrape/analyzer.js +481 -0
  69. package/src/core/webscrape/deep-scraper.js +1027 -0
  70. package/src/core/workflow/epic-manager.js +845 -0
  71. package/src/core/workflow/gates.js +180 -1
  72. package/src/core/workflow/selector.js +707 -0
  73. package/src/embeddings/chunker.js +450 -0
  74. package/src/embeddings/embedder.js +431 -0
  75. package/src/embeddings/index-pipeline.js +320 -0
  76. package/src/embeddings/vector-store.js +505 -0
  77. package/src/mcp-refactor/handlers/boost.js +295 -0
  78. package/src/mcp-refactor/router.js +19 -0
  79. package/src/mcp-refactor/tools.js +113 -0
@@ -14,6 +14,10 @@ export async function init(options) {
14
14
  const interactive = options.interactive !== false && !!process.stdin.isTTY
15
15
  const dryRun = options.dryRun || false
16
16
 
17
+ // Stack y extensiones (se actualizan si selectFullStack se ejecuta)
18
+ const finalStack = options.stack ? options.stack.split(",").map((s) => s.trim()) : []
19
+ const finalExtensions = []
20
+
17
21
  const cwd = process.cwd()
18
22
  const isInitialized =
19
23
  existsSync(join(cwd, "prompt-lang.json")) || existsSync(join(cwd, ".openprompt"))
@@ -140,6 +144,21 @@ export async function init(options) {
140
144
  // ── Verificar OpenCode ──
141
145
  await checkAndInstallOpencode(interactive)
142
146
 
147
+ // ── Generar ONBOARDING_WORKFLOW.md ──
148
+ if (!dryRun) {
149
+ try {
150
+ const onboardingPath = join(finalBaseDir, "docs", "ONBOARDING_WORKFLOW.md")
151
+ const onboardingContent = generateOnboardingMd(finalName, finalStack, finalExtensions)
152
+ if (!existsSync(join(finalBaseDir, "docs"))) {
153
+ mkdirSync(join(finalBaseDir, "docs"), { recursive: true })
154
+ }
155
+ writeFileSync(onboardingPath, onboardingContent, "utf-8")
156
+ console.log(chalk.green(` ✅ docs/ONBOARDING_WORKFLOW.md — Guía para tu IA`))
157
+ } catch {
158
+ // No crítico si falla
159
+ }
160
+ }
161
+
143
162
  // ── Handoff a la IA ──
144
163
  console.log(chalk.cyan("\n✨ OPL Init: Estructura base lista."))
145
164
  console.log(chalk.yellow("OPL delega ahora la inicialización estratégica a tu Agente IA."))
@@ -149,19 +168,164 @@ export async function init(options) {
149
168
  )
150
169
  )
151
170
 
171
+ const stackStr = finalStack ? finalStack.join(", ") : "por definir"
172
+ const extStr = finalExtensions?.length ? `\nExtensiones: ${finalExtensions.join(", ")}` : ""
173
+
152
174
  console.log(
153
175
  chalk.bgGray.white(`
154
176
  "Asume el rol de Arquitecto Principal OPL. Acabo de ejecutar opl init para un proyecto NUEVO llamado '${finalName}'.
177
+ Stack base: ${stackStr}${extStr}
155
178
 
156
179
  Tu proceso obligatorio es:
157
180
  1. Ejecuta 'analyze_project' para inspeccionar el directorio base.
158
- 2. Hazme preguntas para entender el contexto del proyecto (dominio, stack preferido, funcionalidades clave).
159
- 3. Decide el stack óptimo con base en mis respuestas.
160
- 4. Usa 'init_project' y 'scaffold_project' para configurar el proyecto.
161
- 5. Genera los archivos canónicos: AGENTS.md, prompt-lang.json, .openprompt/FRAMEWORK.md.
162
- 6. Confirma explícitamente que el proyecto quedó estabilizado e indícame el siguiente paso operativo."
181
+ 2. Lee el archivo 'docs/ONBOARDING_WORKFLOW.md' (recién generado).
182
+ 3. Hazme preguntas para entender el contexto del proyecto (dominio, stack preferido, funcionalidades clave).
183
+ 4. Decide el stack óptimo con base en mis respuestas.
184
+ 5. Usa 'init_project' y 'scaffold_project' para configurar el proyecto.
185
+ 6. Genera los archivos canónicos: AGENTS.md, prompt-lang.json, .openprompt/FRAMEWORK.md.
186
+ 7. Confirma explícitamente que el proyecto quedó estabilizado e indícame el siguiente paso operativo."
163
187
  `)
164
188
  )
165
189
 
166
190
  return finalBaseDir
167
191
  }
192
+
193
+ /**
194
+ * Genera el contenido de ONBOARDING_WORKFLOW.md para un proyecto nuevo.
195
+ *
196
+ * @param {string} projectName
197
+ * @param {string[]} stack
198
+ * @param {string[]} extensions
199
+ * @returns {string}
200
+ */
201
+ function generateOnboardingMd(projectName, stack, extensions) {
202
+ const stackSection = stack?.length
203
+ ? stack.map((s) => ` - ${s}`).join("\n")
204
+ : " - Por definir durante la inicialización"
205
+
206
+ const extSection = extensions?.length
207
+ ? extensions.map((e) => ` - ${e}`).join("\n")
208
+ : " - (ninguna por ahora)"
209
+
210
+ return `# ONBOARDING WORKFLOW — ${projectName}
211
+
212
+ Generado automáticamente por \`opl init\`.
213
+
214
+ ## 🎯 Propósito
215
+
216
+ Este documento le indica a la IA qué pasos seguir al ser invocada en este proyecto por primera vez. Reduce la fricción de onboarding y asegura que la IA entienda el stack, la estructura y el workflow del proyecto.
217
+
218
+ ## 📋 Stack Detectado
219
+
220
+ ${stackSection}
221
+
222
+ ## 🔌 Extensiones
223
+
224
+ ${extSection}
225
+
226
+ ## 🏗️ Estructura del Proyecto
227
+
228
+ \`\`\`
229
+ .
230
+ ├── AGENTS.md → Contexto para IA (stack, convenciones, reglas)
231
+ ├── prompt-lang.json → Configuración OPL
232
+ ├── docs/
233
+ │ ├── AI_CONTEXT.md → Contexto extendido
234
+ │ ├── FRAMEWORK.md → Referencia canónica del framework
235
+ │ ├── ONBOARDING_WORKFLOW.md → Este archivo
236
+ │ └── ...
237
+ ├── .openprompt/
238
+ │ └── FRAMEWORK.md → Manual completo de OPL
239
+ ├── .opencode/
240
+ │ └── work-context/ → Sesiones, planes, logs
241
+ └── src/
242
+ └── ...
243
+ \`\`\`
244
+
245
+ ## 🔄 Workflow Obligatorio para la IA (v1.3.0)
246
+
247
+ Siempre que se te pida trabajar en este proyecto, SIGUE ESTE FLUJO ESTRICTAMENTE.
248
+ No hay excepciones. Los gates bloquean herramientas si se omiten pasos.
249
+
250
+ ### ⚠️ REGLAS INQUEBRANTABLES
251
+
252
+ 1. **workflow select primero**: Sin workflow seleccionado no hay implementación
253
+ 2. **ticket create antes de código**: Sin ticket abierto no se escribe código
254
+ 3. **docs_updated antes de cerrar**: Sin documentación no se cierra sesión
255
+
256
+ ### Flujo Completo (8 pasos, siempre en este orden)
257
+
258
+ \`\`\`
259
+ PASO 1 → workflow_select
260
+ "opl workflow select <descripción de la tarea>"
261
+ La IA describe qué necesita hacer, el sistema selecciona el workflow óptimo
262
+ (feature, bugfix, refactor, docs, research, etc.)
263
+
264
+ PASO 2 → create_ticket
265
+ "opl ticket create --title ... --severity ..."
266
+ TODO cambio requiere ticket ANTES de tocar código
267
+
268
+ PASO 3 → check_gates
269
+ Verificar: workflow_selected ✓, ticket_created ✓, plan_approved ✓
270
+
271
+ PASO 4 → work_context_plan
272
+ Planificar implementación con búsqueda de conocimiento
273
+
274
+ PASO 5 → implement
275
+ Anotaciones OPL primero (@kind → @contract → @limit → @deps)
276
+ Luego implementar lógica
277
+
278
+ PASO 6 → validate
279
+ "opl validate" — verificar anotaciones antes de cerrar
280
+
281
+ PASO 7 → docs_updated
282
+ Actualizar documentación. OBLIGATORIO antes de cerrar sesión.
283
+
284
+ PASO 8 → work_context_close
285
+ Cerrar sesión y generar reporte con aprendizajes
286
+ \`\`\`
287
+
288
+ ### Para features grandes: Épicas y Sprints
289
+
290
+ \`\`\`
291
+ # Crear épica (agrupa tickets automáticamente desde la descripción)
292
+ opl epic create --title "Sistema de Reportes" --desc "Dashboard + exportación PDF + filtros"
293
+
294
+ # Crear sprint con objetivo y duración
295
+ opl sprint create "Sprint 1" --goal "Implementar core del sistema"
296
+
297
+ # Planificar sprint automáticamente desde épicas activas
298
+ opl sprint plan SPRINT-001 --capacity 10
299
+
300
+ # Ver estado del proyecto
301
+ opl epic status
302
+ \`\`\`
303
+
304
+ ## ⚙️ Comandos Rápidos
305
+
306
+ | Comando | Descripción |
307
+ |---------|-------------|
308
+ | \`opl workflow select <desc>\` | 🥇 Seleccionar workflow óptimo (USAR SIEMPRE PRIMERO) |
309
+ | \`opl ticket create --title "..."\` | 🥇 Crear ticket (USAR SIEMPRE ANTES DE CÓDIGO) |
310
+ | \`opl epic create --title "..." --desc "..."\` | Crear épica con tickets automáticos |
311
+ | \`opl epic list\` | Listar épicas con progreso |
312
+ | \`opl sprint create <name> --goal "..."\` | Crear sprint |
313
+ | \`opl sprint plan <id> --capacity N\` | Planificar sprint automáticamente |
314
+ | \`opl index\` | Navegar conocimiento |
315
+ | \`opl search <q>\` | Buscar en conocimiento (--mode vector para semántica) |
316
+ | \`opl read <d>/<id>\` | Leer documento |
317
+ | \`opl system <name>\` | Explorar sistemas |
318
+ | \`opl assess\` | Production Readiness Assessment |
319
+ | \`opl embeddings status\` | Estado del índice vectorial |
320
+ | \`opl knowledge ingest <file>\` | Ingestar PDF |
321
+ | \`opl webscrape <url>\` | Extraer contenido web e indexar |
322
+
323
+ ## 📚 Documentación Vinculada
324
+
325
+ - \`docs/AI_CONTEXT.md\` → Stack técnico y módulos
326
+ - \`docs/FRAMEWORK.md\` → Especificación del framework
327
+ - \`docs/EMBEDDINGS.md\` → Sistema de embeddings vectoriales
328
+ - \`AGENTS.md\` → Contexto completo para IA
329
+ - \`.openprompt/FRAMEWORK.md\` → Manual canónico de OPL
330
+ `
331
+ }
@@ -287,9 +287,61 @@ export async function ingest(filePath, options = {}) {
287
287
  rebuildIndex()
288
288
 
289
289
  console.log(chalk.cyan(`\n✅ PDF procesado: ${shortName}\n`))
290
+
291
+ // ── Auto-embedding hook (TICKET-007) ─────────────────────
292
+ if (options.embed !== false) {
293
+ await autoEmbedPdf(pdfId, entry, chapters)
294
+ }
290
295
  }
291
296
 
292
297
  export async function rebuild(_options = {}) {
293
298
  const count = rebuildIndex()
294
299
  console.log(chalk.cyan(`\n✅ Índice reconstruido: ${count.length} PDFs\n`))
295
300
  }
301
+
302
+ /**
303
+ * Auto-embedding hook: después de ingestar un PDF, indexa sus embeddings.
304
+ *
305
+ * @param {string} pdfId - ID del PDF procesado
306
+ * @param {Object} entry - Metadatos del PDF
307
+ * @param {Array} chapters - Capítulos detectados
308
+ */
309
+ async function autoEmbedPdf(pdfId, entry, chapters) {
310
+ try {
311
+ const { indexDocument } = await import("../embeddings/index-pipeline.js")
312
+
313
+ // Construir documento en formato OPL
314
+ const doc = {
315
+ id: pdfId,
316
+ title: entry.title || pdfId,
317
+ chapters: chapters.map((ch, i) => ({
318
+ index: ch.index ?? i,
319
+ title: ch.title || "",
320
+ content: ch.content || "",
321
+ })),
322
+ }
323
+
324
+ if (doc.chapters.length === 0) {
325
+ console.log(chalk.gray(" ⏭️ Sin capítulos para indexar (embedding omitido)."))
326
+ return
327
+ }
328
+
329
+ console.log(chalk.blue(" 🧠 Indexando embeddings..."))
330
+
331
+ const result = await indexDocument(doc, { strategy: "section" })
332
+
333
+ if (result.success) {
334
+ console.log(
335
+ chalk.green(` ✅ Embeddings: ${result.indexedChunks} chunks · ${result.durationMs}ms`)
336
+ )
337
+ } else {
338
+ console.log(
339
+ chalk.yellow(
340
+ ` ⚠️ Embedding parcial: ${result.indexedChunks}/${result.totalChunks} chunks`
341
+ )
342
+ )
343
+ }
344
+ } catch (error) {
345
+ console.log(chalk.gray(` ⏭️ Embedding no disponible (${error.message})`))
346
+ }
347
+ }