orquestra-mcp 1.86.0 → 1.87.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": "orquestra-mcp",
3
- "version": "1.86.0",
3
+ "version": "1.87.0",
4
4
  "description": "Servidor MCP de Orquestra -- 161 tools para leer y escribir tareas, ideas, changelog, infraestructura, contenido, QA y más desde un agente de IA",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.mjs CHANGED
@@ -75,8 +75,9 @@ function buildUrl(config, path, params) {
75
75
  const auth = config => ({ Authorization: `Bearer ${config.apiToken}`, 'x-orquestra-client': 'mcp' })
76
76
  const jsonHeaders = config => ({ ...auth(config), 'Content-Type': 'application/json' })
77
77
 
78
- export async function apiGet(config, path, params = {}) {
79
- return request(buildUrl(config, path, params), { headers: auth(config) })
78
+ // `opts` (ORQ-661) pasa plazo/reintentos propios a request(), p. ej. para una lectura best-effort con plazo corto.
79
+ export async function apiGet(config, path, params = {}, opts = {}) {
80
+ return request(buildUrl(config, path, params), { headers: auth(config) }, opts)
80
81
  }
81
82
 
82
83
  export async function apiPost(config, path, { projectId, ...body }, query = {}) {
@@ -0,0 +1,67 @@
1
+ // ORQ-661: contexto de código del proyecto (GET /v1/coding-context, infra ORQ-660) dentro de las tools.
2
+ // `get_coding_context` lo expone completo; `get_task` agrega solo un índice corto y `create_task_branch` el
3
+ // contexto completo. Las dos inyecciones son best-effort: con un plazo corto y sin reintentos, y si fallan la
4
+ // tool responde igual sin el campo (mismo criterio que withRecommendedSkills).
5
+
6
+ export const CONTEXT_TIMEOUT_MS = 1500
7
+ const MAX_TITLES = 8
8
+ const TITLE_MAX = 50 // 8 títulos + hint caben en < 600 caracteres (criterio 8 de la spec)
9
+ export const CODING_CONTEXT_HINT = 'Léelas con get_coding_context antes de codificar.'
10
+
11
+ const shortTitle = t => {
12
+ const s = String(t || '').trim()
13
+ return s.length > TITLE_MAX ? `${s.slice(0, TITLE_MAX - 1)}…` : s
14
+ }
15
+
16
+ /** Convenciones (incluido el conocimiento con tag convencion) que aplican, contando también las que no
17
+ * cupieron en el presupuesto (vienen en `truncated`). */
18
+ function conventionEntries(ctx) {
19
+ const included = [...(ctx?.conventions || []), ...(ctx?.knowledge || [])]
20
+ const cut = (ctx?.truncated || []).filter(t => t.block === 'conventions' || t.block === 'knowledge')
21
+ return [...included, ...cut]
22
+ }
23
+
24
+ /** Índice corto para get_task: `{ count, titles (máx 8 de 50 caracteres), hint }`, o null si no hay convenciones. */
25
+ export function summarizeCodingContext(ctx) {
26
+ const entries = conventionEntries(ctx)
27
+ if (!entries.length) return null
28
+ return { count: entries.length, titles: entries.slice(0, MAX_TITLES).map(e => shortTitle(e.title)), hint: CODING_CONTEXT_HINT }
29
+ }
30
+
31
+ function taskOf(data) {
32
+ return data && typeof data === 'object' && data.task && typeof data.task === 'object' ? data.task : null
33
+ }
34
+
35
+ /**
36
+ * get_task: agrega `task.codingContext` (índice) si la tarea tiene convenciones que aplican.
37
+ * `load(taskId)` trae la respuesta de /v1/coding-context; cualquier error o plazo vencido deja `data` tal cual.
38
+ */
39
+ export async function withCodingContextIndex(data, load) {
40
+ try {
41
+ const task = taskOf(data)
42
+ if (!task?.id) return data
43
+ const summary = summarizeCodingContext(await load(task.id))
44
+ if (!summary) return data
45
+ return { ...data, task: { ...task, codingContext: summary } }
46
+ } catch (err) {
47
+ console.error('codingContext omitido:', err?.message || err)
48
+ return data
49
+ }
50
+ }
51
+
52
+ /** create_task_branch: agrega `codingContext` con la respuesta completa. Nunca bloquea la rama ya creada. */
53
+ export async function withCodingContext(data, taskId, load) {
54
+ try {
55
+ if (!taskId || !data || typeof data !== 'object') return data
56
+ return { ...data, codingContext: await load(taskId) }
57
+ } catch (err) {
58
+ console.error('codingContext omitido:', err?.message || err)
59
+ return data
60
+ }
61
+ }
62
+
63
+ /** Query de GET /v1/coding-context a partir de los parámetros de la tool (listas como texto separado por comas). */
64
+ export function codingContextQuery({ taskId, distributionIds, stack, q, budget } = {}) {
65
+ const list = v => (Array.isArray(v) && v.length ? v.join(',') : undefined)
66
+ return { taskId, distributionIds: list(distributionIds), stack: list(stack), q, budget }
67
+ }
package/src/server.mjs CHANGED
@@ -12,6 +12,7 @@ import { FOUNDATIONS } from './foundations.mjs'
12
12
  import { PLATFORM_PLAYBOOKS, TRACKING_TOOLS } from './platformPlaybooks.mjs'
13
13
  import { SKILLS_CATALOG } from './skillsCatalog.mjs'
14
14
  import { withRecommendedSkills } from './skillRecommend.mjs'
15
+ import { withCodingContextIndex, withCodingContext, codingContextQuery, CONTEXT_TIMEOUT_MS } from './codingContext.mjs'
15
16
  import { parseSource, previewSkill, installSkill } from './skillInstall.mjs'
16
17
  import { normalizeStatuses, findClosePath } from './closePath.mjs'
17
18
  import { TOOL_GUIDES, GUIDE_TOPICS } from './toolGuides.mjs'
@@ -81,7 +82,7 @@ const CHANGELOG_SECTIONS = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed'
81
82
  // 'postmortem' faltaba aquí (gap preexistente, encontrado 12 ago 2026) --
82
83
  // mismo fix del lado de write.mjs en orquestra-infra.
83
84
  // 'spec'/'specs' (ORQ-643): specs del flujo /orquestra-spec en su propio tipo y carpeta.
84
- const DOC_TYPES = ['readme', 'usecase', 'diagram', 'env', 'adr', 'runbook', 'postmortem', 'api', 'spec']
85
+ const DOC_TYPES = ['readme', 'usecase', 'diagram', 'env', 'adr', 'runbook', 'postmortem', 'api', 'spec', 'convention']
85
86
  const ADR_STATUSES = ['propuesto', 'aceptado', 'deprecado', 'rechazado']
86
87
  const SPEC_STATUSES = ['borrador', 'en_revision', 'aprobada'] // ORQ-637
87
88
  const IDEA_ASSESSMENTS = ['go', 'needs-clarification', 'kill'] // ORQ-637
@@ -1485,7 +1486,7 @@ export function createServer() {
1485
1486
  server.registerTool(
1486
1487
  'create_task_branch',
1487
1488
  {
1488
- description: 'Crea una rama en GitHub para esta tarea (ej. "ORQ-123-arregla-el-login") desde la rama base de la integración, y la guarda en task.branch. Idempotente: si la rama ya existe, no falla. Si el proyecto tiene varios repos conectados, pasa integrationId (list_github_integrations).',
1489
+ description: 'Crea una rama en GitHub para esta tarea (ej. "ORQ-123-arregla-el-login") desde la rama base de la integración, y la guarda en task.branch. Idempotente: si la rama ya existe, no falla. Si el proyecto tiene varios repos conectados, pasa integrationId (list_github_integrations). La respuesta trae `codingContext` con las convenciones que aplican a la tarea (si se pudieron leer): respétalas al escribir el código.',
1489
1490
  inputSchema: {
1490
1491
  projectId: z.string().optional().describe(PROJECT_ID_DESC),
1491
1492
  taskId: z.string().describe('ID de la tarea'),
@@ -1495,7 +1496,11 @@ export function createServer() {
1495
1496
  },
1496
1497
  async ({ projectId, taskId, integrationId, branchName }) => {
1497
1498
  try {
1498
- return textResult(await apiPost(config, `/v1/tasks/${taskId}/github-branch`, { projectId: resolveProjectId(projectId), ...(integrationId ? { integrationId } : {}), ...(branchName ? { branchName } : {}) }))
1499
+ const pid = resolveProjectId(projectId)
1500
+ const data = await apiPost(config, `/v1/tasks/${taskId}/github-branch`, { projectId: pid, ...(integrationId ? { integrationId } : {}), ...(branchName ? { branchName } : {}) })
1501
+ // ORQ-661: el inicio del código trae las convenciones completas (best-effort, nunca bloquea la rama).
1502
+ return textResult(await withCodingContext(data, taskId, id =>
1503
+ apiGet(config, '/v1/coding-context', { projectId: pid, taskId: id }, { timeoutMs: CONTEXT_TIMEOUT_MS, retries: 0 })))
1499
1504
  } catch (err) {
1500
1505
  return errorResult(err)
1501
1506
  }
@@ -2011,7 +2016,7 @@ export function createServer() {
2011
2016
  server.registerTool(
2012
2017
  'get_task',
2013
2018
  {
2014
- description: 'Trae UNA tarea completa (con checklist y verificaciones) por `code` (folio ORQ-N, o el código de módulo/grupo como AUTH-3 / V2-3) o por `id`. Úsala en vez de list_tasks cuando ya sabes cuál tarea quieres: es mucho más barata en contexto. Respuesta: { task }; si trae `activeAgents` ([{ label, branch?, since, lastSeenAt }]) hay agentes trabajando esa tarea ahora (caduca a los 15 min): antes de empezar, si hay otro, avisa al usuario. Da 404 si no existe y 409 si el código es ambiguo (usa entonces el id, de list_tasks).',
2019
+ description: 'Trae UNA tarea completa (con checklist y verificaciones) por `code` (folio ORQ-N, o el código de módulo/grupo como AUTH-3 / V2-3) o por `id`. Úsala en vez de list_tasks cuando ya sabes cuál tarea quieres: es mucho más barata en contexto. Respuesta: { task }; si trae `activeAgents` ([{ label, branch?, since, lastSeenAt }]) hay agentes trabajando esa tarea ahora (caduca a los 15 min): antes de empezar, si hay otro, avisa al usuario. Da 404 si no existe y 409 si el código es ambiguo (usa entonces el id, de list_tasks). Si trae `task.codingContext` ({ count, titles, hint }), el proyecto tiene convenciones para esta tarea: léelas con get_coding_context antes de escribir código.',
2015
2020
  inputSchema: {
2016
2021
  projectId: z.string().optional().describe(PROJECT_ID_DESC),
2017
2022
  code: z.string().min(1).optional().describe('Folio o código de la tarea (ej. "ORQ-123", "AUTH-3")'),
@@ -2026,8 +2031,11 @@ export function createServer() {
2026
2031
  ? await apiGet(config, `/v1/tasks/${encodeURIComponent(id)}`, { projectId: pid })
2027
2032
  : await apiGet(config, '/v1/tasks', { projectId: pid, code })
2028
2033
  // ORQ-634: sugerencia de orquestra-spec en tareas grandes sin spec (nunca rompe la respuesta)
2029
- return textResult(await withRecommendedSkills(data, async () => new Set(
2030
- normalizeStatuses(await apiGet(config, '/v1/statuses', { projectId: pid })).filter(s => s.isFinal || s.isCancel || s.isArchive).map(s => s.id))))
2034
+ const withSkills = await withRecommendedSkills(data, async () => new Set(
2035
+ normalizeStatuses(await apiGet(config, '/v1/statuses', { projectId: pid })).filter(s => s.isFinal || s.isCancel || s.isArchive).map(s => s.id)))
2036
+ // ORQ-661: índice de convenciones que aplican (solo títulos; nunca rompe la respuesta).
2037
+ return textResult(await withCodingContextIndex(withSkills, id =>
2038
+ apiGet(config, '/v1/coding-context', { projectId: pid, taskId: id }, { timeoutMs: CONTEXT_TIMEOUT_MS, retries: 0 })))
2031
2039
  } catch (err) {
2032
2040
  return errorResult(err)
2033
2041
  }
@@ -2765,6 +2773,13 @@ export function createServer() {
2765
2773
  }
2766
2774
  )
2767
2775
 
2776
+ // ORQ-661: alcance de una convención (solo type='convention'); vacío = todo el proyecto.
2777
+ const APPLIES_TO = z.object({
2778
+ distributionIds: z.array(z.string()).optional().describe('Distribuciones a las que aplica (list_distributions)'),
2779
+ stack: z.array(z.string()).optional().describe('Tecnologías a las que aplica (ej. "react", "swift"; deben estar en el catálogo)'),
2780
+ })
2781
+ const APPLIES_TO_DESC = 'Solo para type=\'convention\': a qué distribuciones o stack aplica (una regla aplica si comparte al menos una). Sin esto = todo el proyecto.'
2782
+
2768
2783
  registerCreate(
2769
2784
  'create_doc',
2770
2785
  '/v1/docs',
@@ -2786,6 +2801,7 @@ export function createServer() {
2786
2801
  visibility: z.enum(DOC_VISIBILITY).optional().describe('"team" (default) | "workspace" | "public". "public" expone el doc sin sesión en una URL propia.'),
2787
2802
  reviewOwnerUid: z.string().optional().describe('uid de quién recibe el aviso cuando el doc queda desactualizado.'),
2788
2803
  reviewIntervalDays: z.number().optional().describe('Cada cuántos días revisar por calendario (30/90/180) -- sin esto, solo se detecta vencimiento por actividad del módulo vinculado, nunca por fecha.'),
2804
+ appliesTo: APPLIES_TO.optional().describe(APPLIES_TO_DESC),
2789
2805
  }
2790
2806
  )
2791
2807
 
@@ -2818,6 +2834,30 @@ export function createServer() {
2818
2834
  reviewOwnerUid: z.string().optional(),
2819
2835
  reviewIntervalDays: z.number().optional(),
2820
2836
  archived: z.boolean().optional().describe('true archiva (sale de la lista de Docs, sigue en búsqueda y wikilinks, se puede editar); false lo regresa. Idempotente; solo con este campo no crea versión ni cuenta como edición.'),
2837
+ appliesTo: APPLIES_TO.nullable().optional().describe(APPLIES_TO_DESC + ' null lo quita; reemplaza el alcance completo.'),
2838
+ }
2839
+ )
2840
+
2841
+ // ORQ-661: lo que un agente debe saber del proyecto antes de escribir código (GET /v1/coding-context, infra ORQ-660).
2842
+ server.registerTool(
2843
+ 'get_coding_context',
2844
+ {
2845
+ description: 'Convenciones del proyecto que aplican a una tarea (o a unas distribuciones/stack), más el conocimiento del workspace con tag "convencion", los ADR aceptados y un índice de docs de API. Llámala ANTES de escribir código en una tarea y respeta lo que diga: son reglas del equipo. Con taskId usa el alcance y el stack de la tarea. Respuesta: { conventions, knowledge, adrs, apiDocs, truncated, orphans, budget, used }; lo que no cupo en el presupuesto sale en truncated (léelo con get_doc o get_knowledge si hace falta).',
2846
+ inputSchema: {
2847
+ projectId: z.string().optional().describe(PROJECT_ID_DESC),
2848
+ taskId: z.string().optional().describe('Tarea: toma su alcance (scope) y su stack'),
2849
+ distributionIds: z.array(z.string()).optional().describe('Distribuciones extra (se suman a las de la tarea)'),
2850
+ stack: z.array(z.string()).optional().describe('Tecnologías extra (se suman a las de la tarea)'),
2851
+ q: z.string().optional().describe('Filtra por texto en título y contenido'),
2852
+ budget: z.number().int().optional().describe('Tope en caracteres (default 6000, 500-20000)'),
2853
+ },
2854
+ },
2855
+ async ({ projectId, ...params }) => {
2856
+ try {
2857
+ return textResult(await apiGet(config, '/v1/coding-context', { projectId: resolveProjectId(projectId), ...codingContextQuery(params) }))
2858
+ } catch (err) {
2859
+ return errorResult(err)
2860
+ }
2821
2861
  }
2822
2862
  )
2823
2863