@luanpdd/kit-mcp 1.19.0 → 1.21.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 +1 -1
- package/gates/dept-cycle-prevention.md +179 -0
- package/gates/multi-tenant-rls-coverage.md +102 -0
- package/gates/service-role-not-in-user-facing.md +113 -0
- package/kit/agents/audit-log-implementer.md +175 -0
- package/kit/agents/b2b-saas-architect.md +156 -0
- package/kit/agents/crm-pipeline-implementer.md +150 -0
- package/kit/agents/evolution-go-integrator.md +179 -0
- package/kit/agents/invite-flow-implementer.md +137 -0
- package/kit/agents/lgpd-compliance-auditor.md +206 -0
- package/kit/agents/multi-tenant-isolation-auditor.md +243 -0
- package/kit/agents/multi-tenant-rls-writer.md +262 -0
- package/kit/agents/org-onboarding-implementer.md +202 -0
- package/kit/agents/super-admin-implementer.md +182 -0
- package/kit/commands/burn-rate-status.md +237 -121
- package/kit/commands/multi-tenant.md +163 -0
- package/kit/file-manifest.json +31 -4
- package/kit/skills/_shared-multi-tenant/glossary.md +186 -0
- package/kit/skills/audit-log-multi-tenant/SKILL.md +334 -0
- package/kit/skills/b2b-saas-architecture/SKILL.md +300 -0
- package/kit/skills/crm-lead-pipeline-patterns/SKILL.md +326 -0
- package/kit/skills/evolution-go-whatsapp-integration/SKILL.md +322 -0
- package/kit/skills/lgpd-multi-tenant-compliance/SKILL.md +340 -0
- package/kit/skills/member-invite-flow/SKILL.md +305 -0
- package/kit/skills/member-management-react-shadcn/SKILL.md +328 -0
- package/kit/skills/multi-tenant-performance-scaling/SKILL.md +312 -0
- package/kit/skills/multi-tenant-rls-hierarchy/SKILL.md +338 -0
- package/kit/skills/org-onboarding-flow/SKILL.md +257 -0
- package/kit/skills/org-switcher-react-pattern/SKILL.md +349 -0
- package/kit/skills/permission-gate-react-pattern/SKILL.md +271 -0
- package/kit/skills/rbac-permissions-matrix-supabase/SKILL.md +301 -0
- package/kit/skills/super-admin-platform-pattern/SKILL.md +322 -0
- package/kit/skills/whatsapp-conversation-state-machine/SKILL.md +287 -0
- package/package.json +6 -2
- package/src/mcp-server/index.js +34 -3
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: whatsapp-conversation-state-machine
|
|
3
|
+
description: Use ao modelar conversação WhatsApp como state machine xstate v5 + persistência em PG — estados conversation_started → opted_in → engaged → action_taken → closed, persiste estado em conversations table, integra com lead pipeline.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# WhatsApp Conversation State Machine — xstate v5 + Postgres
|
|
7
|
+
|
|
8
|
+
## Quando usar
|
|
9
|
+
|
|
10
|
+
LLM carrega esta skill ao modelar fluxo de conversação WhatsApp em B2B (atendimento, vendas, automação). Trigger phrases:
|
|
11
|
+
|
|
12
|
+
- "WhatsApp conversation state", "fluxo conversa whatsapp"
|
|
13
|
+
- "xstate v5 conversation", "state machine xstate"
|
|
14
|
+
- "conversation persisted Postgres"
|
|
15
|
+
- "conversation handoff bot human"
|
|
16
|
+
- "WhatsApp opt-in opt-out flow"
|
|
17
|
+
|
|
18
|
+
## Regras absolutas
|
|
19
|
+
|
|
20
|
+
**REGRA #1 (state persistido em PG, não em memória):** State da conversa **SEMPRE** persistido em `conversations.state` (JSONB). Memória in-process = state perdido em restart de Edge Function ou cold start. Conversa multi-turn quebra.
|
|
21
|
+
|
|
22
|
+
**REGRA #2 (state machine declarativo via xstate v5):** Use `setup({...}).createMachine({...})` do xstate v5 para definir transições explicitamente. Substitui `if/else` espalhados por regras de transição auditáveis.
|
|
23
|
+
|
|
24
|
+
**REGRA #3 (transições registradas em audit_log):** Toda transição de state emite evento `custom_conversation_transition` em `audit_logs` com `from_state`, `to_state`, `trigger_message_id`, `org_id`.
|
|
25
|
+
|
|
26
|
+
**REGRA #4 (timeout para abandono):** Conversa em estado intermediário (`waiting_user_reply`) por > 24h transiciona automaticamente para `abandoned` via `pg_cron`. Reset a partir de nova mensagem do user.
|
|
27
|
+
|
|
28
|
+
**REGRA #5 (handoff bot→human explícito):** Transition `bot_handling` → `human_handoff` é evento explícito (palavra-chave do user, escalação automática, ou button click). Marca `assigned_to_user_id` no conversation. Bot para de responder.
|
|
29
|
+
|
|
30
|
+
## Patterns canônicos
|
|
31
|
+
|
|
32
|
+
### Tabela `conversations`
|
|
33
|
+
|
|
34
|
+
```sql
|
|
35
|
+
create table public.conversations (
|
|
36
|
+
id uuid primary key default gen_random_uuid(),
|
|
37
|
+
org_id uuid not null references public.organizations(id) on delete cascade,
|
|
38
|
+
contact_phone text not null,
|
|
39
|
+
contact_name text,
|
|
40
|
+
state text not null default 'started'
|
|
41
|
+
check (state in (
|
|
42
|
+
'started', -- primeira mensagem inbound recebida
|
|
43
|
+
'opted_in', -- user explicitamente opt-in para automação
|
|
44
|
+
'engaged', -- user respondeu pelo menos 1×
|
|
45
|
+
'bot_handling', -- bot está processando
|
|
46
|
+
'waiting_user_reply',-- bot enviou pergunta, espera resposta
|
|
47
|
+
'human_handoff', -- atendente humano assumiu
|
|
48
|
+
'action_taken', -- conversa gerou ação (lead criado, agendamento, etc.)
|
|
49
|
+
'abandoned', -- timeout 24h sem resposta
|
|
50
|
+
'closed' -- conversa explicitamente encerrada
|
|
51
|
+
)),
|
|
52
|
+
state_data jsonb default '{}'::jsonb, -- xstate context (variables, accumulated data)
|
|
53
|
+
assigned_to_user_id uuid references auth.users(id) on delete set null,
|
|
54
|
+
lead_id uuid, -- FK lazy para leads (criado on action_taken)
|
|
55
|
+
started_at timestamptz not null default now(),
|
|
56
|
+
last_message_at timestamptz not null default now(),
|
|
57
|
+
closed_at timestamptz,
|
|
58
|
+
unique (org_id, contact_phone, started_at)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
create index conversations_org_phone_idx on public.conversations (org_id, contact_phone);
|
|
62
|
+
create index conversations_state_idx on public.conversations (state) where state in ('waiting_user_reply', 'bot_handling');
|
|
63
|
+
create index conversations_assigned_idx on public.conversations (assigned_to_user_id) where assigned_to_user_id is not null;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### State machine em xstate v5 (Edge Function)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// supabase/functions/whatsapp-process/conversation-machine.ts
|
|
70
|
+
import { setup, createActor } from 'jsr:xstate@5'
|
|
71
|
+
|
|
72
|
+
export const conversationMachine = setup({
|
|
73
|
+
types: {
|
|
74
|
+
context: {} as {
|
|
75
|
+
orgId: string
|
|
76
|
+
contactPhone: string
|
|
77
|
+
contactName?: string
|
|
78
|
+
lastMessageContent?: string
|
|
79
|
+
collectedFields: Record<string, string>
|
|
80
|
+
},
|
|
81
|
+
events: {} as
|
|
82
|
+
| { type: 'INBOUND_MESSAGE'; content: string }
|
|
83
|
+
| { type: 'OPT_IN_KEYWORD' }
|
|
84
|
+
| { type: 'OPT_OUT_KEYWORD' }
|
|
85
|
+
| { type: 'BOT_REPLIED'; question?: string }
|
|
86
|
+
| { type: 'USER_REPLIED'; content: string }
|
|
87
|
+
| { type: 'HUMAN_HANDOFF_REQUESTED'; reason?: string }
|
|
88
|
+
| { type: 'ACTION_TAKEN'; actionType: string; leadId?: string }
|
|
89
|
+
| { type: 'TIMEOUT_24H' }
|
|
90
|
+
| { type: 'CLOSE' }
|
|
91
|
+
},
|
|
92
|
+
guards: {
|
|
93
|
+
isOptInKeyword: ({ event }) => {
|
|
94
|
+
if (event.type !== 'INBOUND_MESSAGE') return false
|
|
95
|
+
return /^(sim|aceito|comecar|start|opt-in)$/i.test(event.content.trim())
|
|
96
|
+
},
|
|
97
|
+
isOptOutKeyword: ({ event }) => {
|
|
98
|
+
if (event.type !== 'INBOUND_MESSAGE') return false
|
|
99
|
+
return /^(nao|sair|stop|opt-out|cancelar)$/i.test(event.content.trim())
|
|
100
|
+
},
|
|
101
|
+
isHandoffKeyword: ({ event }) => {
|
|
102
|
+
if (event.type !== 'INBOUND_MESSAGE') return false
|
|
103
|
+
return /(atendente|humano|falar com pessoa|human)/i.test(event.content)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}).createMachine({
|
|
107
|
+
id: 'conversation',
|
|
108
|
+
initial: 'started',
|
|
109
|
+
context: ({ input }) => input,
|
|
110
|
+
states: {
|
|
111
|
+
started: {
|
|
112
|
+
on: {
|
|
113
|
+
INBOUND_MESSAGE: [
|
|
114
|
+
{ guard: 'isOptInKeyword', target: 'opted_in' },
|
|
115
|
+
{ guard: 'isHandoffKeyword', target: 'human_handoff' },
|
|
116
|
+
{ target: 'engaged' }
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
opted_in: {
|
|
121
|
+
on: {
|
|
122
|
+
BOT_REPLIED: { target: 'waiting_user_reply' }
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
engaged: {
|
|
126
|
+
on: {
|
|
127
|
+
BOT_REPLIED: { target: 'waiting_user_reply' },
|
|
128
|
+
HUMAN_HANDOFF_REQUESTED: { target: 'human_handoff' }
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
waiting_user_reply: {
|
|
132
|
+
on: {
|
|
133
|
+
USER_REPLIED: { target: 'bot_handling' },
|
|
134
|
+
TIMEOUT_24H: { target: 'abandoned' },
|
|
135
|
+
HUMAN_HANDOFF_REQUESTED: { target: 'human_handoff' }
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
bot_handling: {
|
|
139
|
+
on: {
|
|
140
|
+
BOT_REPLIED: { target: 'waiting_user_reply' },
|
|
141
|
+
ACTION_TAKEN: { target: 'action_taken' },
|
|
142
|
+
HUMAN_HANDOFF_REQUESTED: { target: 'human_handoff' }
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
human_handoff: {
|
|
146
|
+
on: {
|
|
147
|
+
ACTION_TAKEN: { target: 'action_taken' },
|
|
148
|
+
CLOSE: { target: 'closed' }
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
action_taken: {
|
|
152
|
+
on: {
|
|
153
|
+
INBOUND_MESSAGE: { target: 'engaged' },
|
|
154
|
+
CLOSE: { target: 'closed' }
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
abandoned: {
|
|
158
|
+
on: {
|
|
159
|
+
INBOUND_MESSAGE: { target: 'engaged' } // re-engaja
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
closed: {
|
|
163
|
+
type: 'final'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Persistência — load + transition + save
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// PT-BR: hydrate state machine do PG, processa evento, persiste novo state
|
|
173
|
+
async function processConversationEvent(orgId: string, contactPhone: string, event: ConversationEvent) {
|
|
174
|
+
// 1. Load existing conversation
|
|
175
|
+
const { data: conv } = await admin
|
|
176
|
+
.from('conversations')
|
|
177
|
+
.select('*')
|
|
178
|
+
.eq('org_id', orgId)
|
|
179
|
+
.eq('contact_phone', contactPhone)
|
|
180
|
+
.order('started_at', { ascending: false })
|
|
181
|
+
.limit(1)
|
|
182
|
+
.single()
|
|
183
|
+
|
|
184
|
+
// 2. Hydrate xstate actor com state persistido
|
|
185
|
+
const actor = createActor(conversationMachine, {
|
|
186
|
+
input: { orgId, contactPhone, contactName: conv?.contact_name, collectedFields: conv?.state_data || {} },
|
|
187
|
+
snapshot: conv ? { value: conv.state, context: conv.state_data, status: 'active' } : undefined
|
|
188
|
+
})
|
|
189
|
+
actor.start()
|
|
190
|
+
|
|
191
|
+
// 3. Send event
|
|
192
|
+
actor.send(event)
|
|
193
|
+
|
|
194
|
+
// 4. Get new state
|
|
195
|
+
const snapshot = actor.getSnapshot()
|
|
196
|
+
const newState = snapshot.value as string
|
|
197
|
+
|
|
198
|
+
// 5. Persist (REGRA #1)
|
|
199
|
+
await admin.from('conversations').upsert({
|
|
200
|
+
id: conv?.id,
|
|
201
|
+
org_id: orgId,
|
|
202
|
+
contact_phone: contactPhone,
|
|
203
|
+
state: newState,
|
|
204
|
+
state_data: snapshot.context,
|
|
205
|
+
last_message_at: new Date().toISOString()
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// 6. Audit transition (REGRA #3)
|
|
209
|
+
if (conv?.state !== newState) {
|
|
210
|
+
await admin.rpc('audit_log', {
|
|
211
|
+
p_event_type: 'custom_conversation_transition',
|
|
212
|
+
p_tenant_id: orgId,
|
|
213
|
+
p_payload: {
|
|
214
|
+
from_state: conv?.state,
|
|
215
|
+
to_state: newState,
|
|
216
|
+
contact_phone: contactPhone
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return snapshot
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Cron timeout 24h (REGRA #4)
|
|
226
|
+
|
|
227
|
+
```sql
|
|
228
|
+
select cron.schedule(
|
|
229
|
+
'conversation-timeout-24h',
|
|
230
|
+
'*/30 * * * *', -- a cada 30min
|
|
231
|
+
$$
|
|
232
|
+
update public.conversations
|
|
233
|
+
set state = 'abandoned',
|
|
234
|
+
last_message_at = now()
|
|
235
|
+
where state = 'waiting_user_reply'
|
|
236
|
+
and last_message_at < now() - interval '24 hours';
|
|
237
|
+
$$
|
|
238
|
+
);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Anti-patterns
|
|
242
|
+
|
|
243
|
+
### Anti-pattern 1: State em variável global da Edge Function
|
|
244
|
+
|
|
245
|
+
**Errado:**
|
|
246
|
+
```typescript
|
|
247
|
+
const conversationStates = new Map<string, string>() // in-memory
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Por quê:** Edge Function reinicia (cold start) → Map vazio → conversa perdida.
|
|
251
|
+
|
|
252
|
+
**Certo:** REGRA #1 — `conversations.state` em PG, hydrate xstate actor com snapshot.
|
|
253
|
+
|
|
254
|
+
### Anti-pattern 2: if/else aninhado em vez de state machine
|
|
255
|
+
|
|
256
|
+
**Errado:**
|
|
257
|
+
```typescript
|
|
258
|
+
if (conv.state === 'started') {
|
|
259
|
+
if (msg.includes('sim')) { ... }
|
|
260
|
+
else if (msg.includes('atendente')) { ... }
|
|
261
|
+
// 50 lines of nested ifs
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Por quê:** transições implícitas, hard to audit, bug silencioso quando adiciona novo estado.
|
|
266
|
+
|
|
267
|
+
**Certo:** REGRA #2 — xstate `setup({...}).createMachine({...})` declarativo.
|
|
268
|
+
|
|
269
|
+
### Anti-pattern 3: Sem timeout para abandono
|
|
270
|
+
|
|
271
|
+
**Errado:**
|
|
272
|
+
```sql
|
|
273
|
+
-- Nenhum cron — conversas em waiting_user_reply ficam para sempre
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Por quê:** dashboards lotados de conversas "abertas" que na verdade abandonadas. Métricas de conversion erradas.
|
|
277
|
+
|
|
278
|
+
**Certo:** REGRA #4 — pg_cron 30min checa timeout 24h.
|
|
279
|
+
|
|
280
|
+
## Ver também
|
|
281
|
+
|
|
282
|
+
- [evolution-go-whatsapp-integration](../evolution-go-whatsapp-integration/SKILL.md) — sibling, webhook handler integra com state machine
|
|
283
|
+
- [crm-lead-pipeline-patterns](../crm-lead-pipeline-patterns/SKILL.md) — Phase 113, conversa.action_taken → lead criado
|
|
284
|
+
- [audit-log-multi-tenant](../audit-log-multi-tenant/SKILL.md) — eventos `custom_conversation_transition`
|
|
285
|
+
- [supabase-cron-queues](../supabase-cron-queues/SKILL.md) — pg_cron timeout 24h
|
|
286
|
+
- [_shared-multi-tenant/glossary.md](../_shared-multi-tenant/glossary.md) — `conversation state machine`
|
|
287
|
+
- [xstate v5 docs](https://stately.ai/docs/xstate) — biblioteca canônica
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luanpdd/kit-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Generic infrastructure to ship YOUR personal kit of agents/commands/skills as an MCP server, with cross-IDE sync (Claude Code, Cursor, Codex, Gemini, Windsurf, Antigravity, Copilot, Trae).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
"cli": "node bin/cli.js",
|
|
43
43
|
"smoke": "node bin/cli.js kit list-agents | head -5",
|
|
44
44
|
"test": "node test/run.mjs test/unit",
|
|
45
|
-
"test:integration": "node test/run.mjs test/integration",
|
|
46
45
|
"test:all": "node test/run.mjs test",
|
|
46
|
+
"test:integration": "node test/run.mjs test/integration",
|
|
47
|
+
"test:mutation": "stryker run",
|
|
47
48
|
"prepublishOnly": "node scripts/regen-manifest.js && node scripts/update-readme-counts.js && node test/run.mjs test/unit && node test/run.mjs test/integration"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
@@ -55,5 +56,8 @@
|
|
|
55
56
|
"@inquirer/prompts": "^8.4.2",
|
|
56
57
|
"chokidar": "^5.0.0",
|
|
57
58
|
"open": "^11.0.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@stryker-mutator/core": "9.6.1"
|
|
58
62
|
}
|
|
59
63
|
}
|
package/src/mcp-server/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { readFileSync } from 'node:fs';
|
|
|
17
17
|
import { fileURLToPath } from 'node:url';
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
|
|
20
|
-
import { listKit, searchKit, findItem } from '../core/kit.js';
|
|
20
|
+
import { listKit, searchKit, findItem, BUNDLED_KIT_ROOT } from '../core/kit.js';
|
|
21
21
|
import { listTargets } from '../core/registry.js';
|
|
22
22
|
import { syncTo, statusOf, removeFrom, summarize } from '../core/sync.js';
|
|
23
23
|
import { detectReverse, applyReverse } from '../core/reverse-sync.js';
|
|
@@ -31,7 +31,7 @@ import { recordReplay, listReplays, loadReplay, annotateReplay } from '../core/r
|
|
|
31
31
|
import { installMcp, listInstallTargets } from './install.js';
|
|
32
32
|
import { ensureSidecar } from '../ui/auto-spawn.js';
|
|
33
33
|
import { wrapProgressForUi } from '../ui/wrapper.js';
|
|
34
|
-
import { incrementInvocation, recordLatency, snapshot as metricsSnapshot } from '../core/metrics.js';
|
|
34
|
+
import { incrementInvocation, recordLatency, snapshot as metricsSnapshot, persistSnapshot } from '../core/metrics.js';
|
|
35
35
|
|
|
36
36
|
const TOOLS = [
|
|
37
37
|
{
|
|
@@ -308,8 +308,29 @@ async function handleInstall(args) {
|
|
|
308
308
|
// OBS-18 (Phase 94.01): metrics-snapshot is parameterless and read-only.
|
|
309
309
|
// Returns the live snapshot synchronously — no auth, no projectRoot guard
|
|
310
310
|
// (no disk reads, no shell). Wraps in an async fn for handler-API uniformity.
|
|
311
|
+
//
|
|
312
|
+
// OBS-20-01 (Phase 102): auto-persist throttle — clients polling rapidly
|
|
313
|
+
// shouldn't create N files per second. 1s is generous vs typical 30s+ polls.
|
|
314
|
+
// State is in-memory; resets on server restart. Closes the operational gap
|
|
315
|
+
// where snapshots dir was empty until someone manually triggered persist.
|
|
316
|
+
let _lastAutoPersistTs = 0;
|
|
317
|
+
const AUTO_PERSIST_THROTTLE_MS = 1000;
|
|
318
|
+
|
|
311
319
|
async function handleMetricsSnapshot() {
|
|
312
|
-
|
|
320
|
+
const payload = metricsSnapshot();
|
|
321
|
+
const now = Date.now();
|
|
322
|
+
if (now - _lastAutoPersistTs >= AUTO_PERSIST_THROTTLE_MS) {
|
|
323
|
+
try {
|
|
324
|
+
await persistSnapshot();
|
|
325
|
+
_lastAutoPersistTs = now;
|
|
326
|
+
} catch (err) {
|
|
327
|
+
// OBS-20-01: graceful — log to stderr, do NOT fail the handler.
|
|
328
|
+
// In-memory snapshot still returned normally so the client tool call
|
|
329
|
+
// contract is preserved even when fs is read-only or quota-exhausted.
|
|
330
|
+
process.stderr.write(`[kit-mcp] auto-snapshot persist failed: ${err.message}\n`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return payload;
|
|
313
334
|
}
|
|
314
335
|
|
|
315
336
|
const HANDLERS = {
|
|
@@ -393,4 +414,14 @@ export async function startStdio() {
|
|
|
393
414
|
const server = await createServer();
|
|
394
415
|
const transport = new StdioServerTransport();
|
|
395
416
|
await server.connect(transport);
|
|
417
|
+
|
|
418
|
+
// SRE-20-02 (Phase 105): pre-warm the kit cache to push MCP dispatch p95
|
|
419
|
+
// below 100ms. Without this, the very first tools/call against `kit` pays
|
|
420
|
+
// the full disk read (~144ms baseline on the v1.17 reference machine; ~96ms
|
|
421
|
+
// on faster hardware). Fire-and-forget: failure here is non-fatal — the
|
|
422
|
+
// next dispatch will lazily populate via the same listKit code path.
|
|
423
|
+
// This shifts the cold-path work from the first user-visible request to
|
|
424
|
+
// the boot path, where it's invisible behind IDE startup. See skill
|
|
425
|
+
// production-readiness-review (Performance axe) for the rationale.
|
|
426
|
+
listKit(BUNDLED_KIT_ROOT).catch(() => {});
|
|
396
427
|
}
|