@luanpdd/kit-mcp 1.35.0 → 1.36.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 (117) hide show
  1. package/bin/cli.js +2 -2
  2. package/bin/mcp.js +6 -6
  3. package/bin/ui.js +74 -74
  4. package/gates/ai-prompt-stability.md +120 -120
  5. package/gates/budget-description.md +68 -68
  6. package/gates/confidence.md +29 -29
  7. package/gates/dependency-check.md +33 -33
  8. package/gates/dept-cycle-prevention.md +179 -179
  9. package/gates/golden-signals-coverage.md +133 -133
  10. package/gates/legacy-refactor-safety.md +178 -178
  11. package/gates/multi-tenant-rls-coverage.md +102 -102
  12. package/gates/no-personal-uuid.md +72 -72
  13. package/gates/obs-agents-mcp-supabase.md +86 -86
  14. package/gates/obs-skills-frontmatter.md +76 -76
  15. package/gates/observability-coverage.md +151 -151
  16. package/gates/omm-no-regression.md +83 -83
  17. package/gates/postmortem-template-required.md +127 -127
  18. package/gates/prr-checklist-coverage.md +128 -128
  19. package/gates/regression.md +32 -32
  20. package/gates/release-pipeline-policy.md +132 -132
  21. package/gates/secrets-scan.md +33 -33
  22. package/gates/service-role-not-in-user-facing.md +113 -113
  23. package/gates/skill-must-include.md +71 -71
  24. package/gates/sync-idempotent.md +62 -62
  25. package/gates/verify-phase-goal.md +34 -34
  26. package/kit/agents/designer-ui.md +216 -216
  27. package/kit/agents/workflow-generator.md +537 -167
  28. package/kit/commands/adicionar-backlog.md +1 -1
  29. package/kit/commands/adicionar-fase.md +1 -1
  30. package/kit/commands/adicionar-tarefa.md +1 -1
  31. package/kit/commands/auditar-observabilidade.md +103 -103
  32. package/kit/commands/auditar-toil.md +129 -129
  33. package/kit/commands/caracterizar-prompt.md +195 -195
  34. package/kit/commands/criar-workflow.md +158 -158
  35. package/kit/commands/definir-perfil.md +1 -1
  36. package/kit/commands/definir-slo.md +108 -108
  37. package/kit/commands/fio.md +1 -1
  38. package/kit/commands/golden-signals.md +142 -142
  39. package/kit/commands/instrumentar-fase.md +200 -200
  40. package/kit/commands/investigar-producao.md +162 -162
  41. package/kit/commands/observabilidade.md +118 -118
  42. package/kit/commands/postmortem.md +179 -179
  43. package/kit/commands/prr.md +205 -205
  44. package/kit/commands/publicar-rapido.md +207 -207
  45. package/kit/commands/risk-budget.md +220 -220
  46. package/kit/commands/sre.md +230 -230
  47. package/kit/file-manifest.json +424 -424
  48. package/kit/framework/references/output-style.md +22 -22
  49. package/kit/hooks/post-apply-migration.js +199 -199
  50. package/kit/hooks/sidecar-tool-publisher.js +210 -210
  51. package/kit/skills/_shared-dados-distribuidos/glossary.md +224 -224
  52. package/kit/skills/_shared-legacy/glossary.md +389 -389
  53. package/kit/skills/_shared-multi-tenant/glossary.md +186 -186
  54. package/kit/skills/_shared-observability/glossary.md +396 -396
  55. package/kit/skills/_shared-sre/glossary.md +712 -712
  56. package/kit/skills/_shared-supabase/glossary.md +234 -234
  57. package/kit/skills/blameless-postmortems/SKILL.md +340 -340
  58. package/kit/skills/burn-rate-alerting/SKILL.md +258 -258
  59. package/kit/skills/cascading-failures/SKILL.md +311 -311
  60. package/kit/skills/core-analysis-loop/SKILL.md +352 -352
  61. package/kit/skills/distributed-tracing/SKILL.md +362 -362
  62. package/kit/skills/dynamic-workflow-authoring/SKILL.md +327 -223
  63. package/kit/skills/eliminating-toil/SKILL.md +243 -243
  64. package/kit/skills/event-based-slos/SKILL.md +296 -296
  65. package/kit/skills/four-golden-signals/SKILL.md +314 -314
  66. package/kit/skills/hermetic-builds/SKILL.md +323 -323
  67. package/kit/skills/legacy-monster-methods/SKILL.md +444 -444
  68. package/kit/skills/llm-as-dependency/SKILL.md +436 -436
  69. package/kit/skills/load-shedding-graceful-degradation/SKILL.md +396 -396
  70. package/kit/skills/observability-driven-development/SKILL.md +315 -315
  71. package/kit/skills/observability-maturity-model/SKILL.md +222 -222
  72. package/kit/skills/opentelemetry-standard/SKILL.md +351 -351
  73. package/kit/skills/production-readiness-review/SKILL.md +305 -305
  74. package/kit/skills/release-engineering/SKILL.md +367 -367
  75. package/kit/skills/retry-strategies/SKILL.md +372 -372
  76. package/kit/skills/sre-risk-management/SKILL.md +221 -221
  77. package/kit/skills/structured-events/SKILL.md +265 -265
  78. package/kit/skills/supabase-cron-queues/SKILL.md +275 -275
  79. package/kit/skills/supabase-database-functions/SKILL.md +332 -332
  80. package/kit/skills/supabase-declarative-schema/SKILL.md +183 -183
  81. package/kit/skills/supabase-pgvector-rag/SKILL.md +253 -253
  82. package/kit/skills/supabase-postgres-style/SKILL.md +138 -138
  83. package/kit/skills/supabase-storage/SKILL.md +234 -234
  84. package/kit/skills/telemetry-pipelines/SKILL.md +259 -259
  85. package/kit/skills/telemetry-sampling/SKILL.md +256 -256
  86. package/kit/skills/ui-anti-padroes-ia/SKILL.md +261 -261
  87. package/kit/skills/ui-contexto-produto/SKILL.md +248 -248
  88. package/kit/skills/ui-cor-estrategia/SKILL.md +213 -213
  89. package/kit/skills/ui-critica-auditoria/SKILL.md +260 -260
  90. package/kit/skills/ui-motion-funcional/SKILL.md +264 -264
  91. package/kit/skills/ui-ritmo-espacial/SKILL.md +259 -259
  92. package/kit/skills/ui-tipografia/SKILL.md +211 -211
  93. package/package.json +1 -1
  94. package/src/cli/index.js +1114 -1114
  95. package/src/cli/render.js +194 -194
  96. package/src/cli/upgrade-check.js +135 -135
  97. package/src/core/error-redaction.js +76 -76
  98. package/src/core/failures.js +153 -153
  99. package/src/core/gate-runner.js +205 -205
  100. package/src/core/gates.js +82 -82
  101. package/src/core/logger.js +170 -170
  102. package/src/core/manifest-verify.js +174 -174
  103. package/src/core/metrics.js +268 -268
  104. package/src/core/notify.js +60 -60
  105. package/src/core/path-safety.js +141 -141
  106. package/src/core/replays.js +120 -120
  107. package/src/core/ui.js +185 -185
  108. package/src/mcp-server/install.js +149 -149
  109. package/src/mcp-server/roots.js +124 -124
  110. package/src/ui/auto-spawn.js +113 -113
  111. package/src/ui/browser.js +78 -78
  112. package/src/ui/client.js +130 -130
  113. package/src/ui/events.js +65 -65
  114. package/src/ui/lockfile.js +191 -191
  115. package/src/ui/port.js +67 -67
  116. package/src/ui/server.js +547 -547
  117. package/src/ui/wrapper.js +129 -129
package/src/cli/render.js CHANGED
@@ -1,194 +1,194 @@
1
- // Human-readable renderers for each CLI subcommand. The CLI default switched
2
- // from JSON-to-stdout to these in v1.1; --json restores the old behavior
3
- // (still useful for piping to jq, MCP-like consumers, etc.).
4
- //
5
- // Conventions:
6
- // - Render functions write to process.stdout (no trailing newline beyond
7
- // what the formatted output naturally has).
8
- // - They never throw on missing fields — the result objects come from
9
- // core/ which already shape them.
10
- // - Cores happen via src/core/ui.js (which already disables in NO_COLOR
11
- // or when --no-tty etc.).
12
-
13
- import path from 'node:path';
14
- import { c, icons, summary } from '../core/ui.js';
15
-
16
- // --- generic helpers ---
17
-
18
- function table(rows, headers) {
19
- if (rows.length === 0) {
20
- return `${c.dim('(empty)')}\n`;
21
- }
22
- const cols = headers.length;
23
- const widths = new Array(cols).fill(0);
24
- for (let i = 0; i < cols; i++) widths[i] = Math.max(headers[i].length, ...rows.map(r => String(r[i] ?? '').length));
25
- const out = [];
26
- out.push(headers.map((h, i) => c.bold(h.padEnd(widths[i]))).join(' '));
27
- out.push(headers.map((_, i) => c.dim('─'.repeat(widths[i]))).join(' '));
28
- for (const r of rows) {
29
- out.push(r.map((v, i) => String(v ?? '').padEnd(widths[i])).join(' '));
30
- }
31
- return out.join('\n') + '\n';
32
- }
33
-
34
- // --- kit ---
35
-
36
- export function renderKitList(items, kind) {
37
- if (items.length === 0) {
38
- return `${c.dim(`No ${kind}s in kit.`)}\n`;
39
- }
40
- const rows = items.map(x => [x.name, (x.description ?? '').slice(0, 80)]);
41
- return table(rows, ['name', 'description']);
42
- }
43
-
44
- export function renderKitSearch(results) {
45
- if (results.length === 0) {
46
- return `${c.dim('No matches.')}\n`;
47
- }
48
- const rows = results.map(x => [x.kind, x.name, (x.description ?? '').slice(0, 70)]);
49
- return table(rows, ['kind', 'name', 'description']);
50
- }
51
-
52
- // --- sync ---
53
-
54
- export function renderSyncTargets(targets) {
55
- const rows = targets.map(t => [
56
- t.id,
57
- t.label,
58
- Object.entries(t.capabilities).filter(([, v]) => v).map(([k]) => k).join(', '),
59
- ]);
60
- return table(rows, ['id', 'label', 'capabilities']);
61
- }
62
-
63
- export function renderSyncStatus(result) {
64
- const rows = result.checks.map(c => [c.capability, c.path, c.exists ? '✓' : '—']);
65
- return `${c.bold(`Status: ${result.target}`)} ${c.dim(result.projectRoot)}\n` + table(rows, ['cap', 'path', 'present']);
66
- }
67
-
68
- export function renderSyncInstall(result) {
69
- // Tally written paths by capability prefix
70
- const counts = {};
71
- for (const p of result.written) {
72
- const rel = path.relative(result.projectRoot, p).replace(/\\/g, '/');
73
- // Hide internal markers from the user-facing tally (they're a kit-mcp impl detail)
74
- if (rel.endsWith('/.kit-mcp-managed')) continue;
75
- let cap = 'rules';
76
- if (rel.includes('.claude/agents/')) cap = 'agents';
77
- else if (rel.includes('.claude/commands/')) cap = 'commands';
78
- else if (rel.includes('.claude/skills/')) cap = 'skills';
79
- else if (rel.includes('.claude/framework/')) cap = 'framework';
80
- else if (rel.includes('.claude/hooks/')) cap = 'hooks';
81
- counts[cap] = (counts[cap] ?? 0) + 1;
82
- }
83
- const rows = [];
84
- for (const cap of ['rules', 'agents', 'commands', 'skills', 'framework', 'hooks']) {
85
- if (counts[cap] !== undefined) rows.push([cap, counts[cap]]);
86
- }
87
- const visibleTotal = Object.values(counts).reduce((a, b) => a + b, 0);
88
- // Phase 160 (v1.28): append diff tally row if cli attached one.
89
- if (result._tally) {
90
- const w = result._tally.written;
91
- const s = result._tally.skipped;
92
- rows.push(['new / updated', w]);
93
- rows.push(['unchanged', s]);
94
- }
95
- return summary({
96
- title: `Synced kit → ${result.target}${result.dryRun ? ' (dry-run)' : ''}`,
97
- rows,
98
- total: visibleTotal,
99
- hint: c.dim(result.projectRoot),
100
- }) + '\n';
101
- }
102
-
103
- export function renderSyncRemove(result) {
104
- return summary({
105
- title: `Removed kit-mcp stubs from ${result.target}`,
106
- rows: [['Files removed', result.removed.length]],
107
- total: result.removed.length,
108
- hint: c.dim(result.projectRoot),
109
- }) + '\n';
110
- }
111
-
112
- // --- reverse-sync ---
113
-
114
- export function renderReverseDetect(result) {
115
- if (result.candidates.length === 0) {
116
- return `${c.green(icons.check)} No edits to bring back. Canonical kit and ${result.target} are in sync.\n`;
117
- }
118
- const rows = result.candidates.map(x => [x.kind, x.name, x.reason, x.diffSummary ?? '']);
119
- return `${c.bold(`Candidates: ${result.candidates.length}`)} ${c.dim(`(${result.target})`)}\n` +
120
- table(rows, ['kind', 'name', 'reason', 'diff']);
121
- }
122
-
123
- export function renderReverseApply(result) {
124
- const rows = result.results.map(x => [
125
- x.kind,
126
- x.name,
127
- x.action.startsWith('overwrit') || x.action.startsWith('merge') || x.action.startsWith('renamed')
128
- ? c.green(x.action)
129
- : x.action.startsWith('skipped') ? c.dim(x.action) : c.yellow(x.action),
130
- ]);
131
- return `${c.bold(`Applied (strategy=${result.strategy})`)}\n` + table(rows, ['kind', 'name', 'action']);
132
- }
133
-
134
- // --- gates ---
135
-
136
- export function renderGatesList(items) {
137
- const rows = items.map(g => [g.id, g.stage, g.blocking ? c.red('blocking') : c.dim('warn-only'), g.description]);
138
- return table(rows, ['id', 'stage', 'mode', 'description']);
139
- }
140
-
141
- export function renderGateRun(result) {
142
- const verdictColor = result.verdict === 'passed' ? c.green
143
- : result.verdict === 'block' ? c.red
144
- : result.verdict === 'warn' ? c.yellow
145
- : c.dim;
146
- return `${c.bold(`Gate ${result.id}`)}: ${verdictColor(result.verdict)} ${result.exitCode !== undefined ? c.dim(`(exit ${result.exitCode})`) : ''}\n`;
147
- }
148
-
149
- // --- forensics ---
150
-
151
- export function renderForensicsCollect(items) {
152
- if (items.length === 0) return `${c.dim('No failures collected.')}\n`;
153
- const rows = items.map(x => [x.agent ?? '?', x.kind ?? '?', x.absPath ?? x.path ?? '']);
154
- return table(rows, ['agent', 'kind', 'path']);
155
- }
156
-
157
- export function renderForensicsSummarize(byAgent) {
158
- const entries = Object.entries(byAgent ?? {});
159
- if (entries.length === 0) return `${c.dim('No failures.')}\n`;
160
- const rows = entries.map(([agent, items]) => [agent, Array.isArray(items) ? items.length : '?']);
161
- return table(rows, ['agent', 'failures']);
162
- }
163
-
164
- export function renderListReplays(items) {
165
- if (!Array.isArray(items) || items.length === 0) return `${c.dim('No replays recorded.')}\n`;
166
- const rows = items.map(r => [r.id ?? '?', r.agent ?? '?', r.timestamp ?? '?']);
167
- return table(rows, ['id', 'agent', 'recorded']);
168
- }
169
-
170
- // --- install ---
171
-
172
- export function renderInstallTargets(targets) {
173
- const rows = targets.map(t => [t.id, t.label, t.scopes?.join(', ') ?? '?']);
174
- return table(rows, ['id', 'label', 'scopes']);
175
- }
176
-
177
- export function renderInstallResult(result) {
178
- return summary({
179
- title: result.dryRun ? `Install preview (${result.target}, scope=${result.scope})` : `Registered kit-mcp → ${result.target} (scope=${result.scope})`,
180
- rows: [
181
- ['Path', result.path ?? '?'],
182
- ['Name', result.name ?? 'kit'],
183
- ['Via', result.via ?? '?'],
184
- ].map(([k, v]) => [k, v ?? '—']),
185
- hint: result.dryRun ? c.dim('No file written (dry-run)') : undefined,
186
- }) + '\n';
187
- }
188
-
189
- // --- generic fallback ---
190
-
191
- export function renderFallback(value) {
192
- // Used when we don't have a custom renderer yet.
193
- return JSON.stringify(value, null, 2) + '\n';
194
- }
1
+ // Human-readable renderers for each CLI subcommand. The CLI default switched
2
+ // from JSON-to-stdout to these in v1.1; --json restores the old behavior
3
+ // (still useful for piping to jq, MCP-like consumers, etc.).
4
+ //
5
+ // Conventions:
6
+ // - Render functions write to process.stdout (no trailing newline beyond
7
+ // what the formatted output naturally has).
8
+ // - They never throw on missing fields — the result objects come from
9
+ // core/ which already shape them.
10
+ // - Cores happen via src/core/ui.js (which already disables in NO_COLOR
11
+ // or when --no-tty etc.).
12
+
13
+ import path from 'node:path';
14
+ import { c, icons, summary } from '../core/ui.js';
15
+
16
+ // --- generic helpers ---
17
+
18
+ function table(rows, headers) {
19
+ if (rows.length === 0) {
20
+ return `${c.dim('(empty)')}\n`;
21
+ }
22
+ const cols = headers.length;
23
+ const widths = new Array(cols).fill(0);
24
+ for (let i = 0; i < cols; i++) widths[i] = Math.max(headers[i].length, ...rows.map(r => String(r[i] ?? '').length));
25
+ const out = [];
26
+ out.push(headers.map((h, i) => c.bold(h.padEnd(widths[i]))).join(' '));
27
+ out.push(headers.map((_, i) => c.dim('─'.repeat(widths[i]))).join(' '));
28
+ for (const r of rows) {
29
+ out.push(r.map((v, i) => String(v ?? '').padEnd(widths[i])).join(' '));
30
+ }
31
+ return out.join('\n') + '\n';
32
+ }
33
+
34
+ // --- kit ---
35
+
36
+ export function renderKitList(items, kind) {
37
+ if (items.length === 0) {
38
+ return `${c.dim(`No ${kind}s in kit.`)}\n`;
39
+ }
40
+ const rows = items.map(x => [x.name, (x.description ?? '').slice(0, 80)]);
41
+ return table(rows, ['name', 'description']);
42
+ }
43
+
44
+ export function renderKitSearch(results) {
45
+ if (results.length === 0) {
46
+ return `${c.dim('No matches.')}\n`;
47
+ }
48
+ const rows = results.map(x => [x.kind, x.name, (x.description ?? '').slice(0, 70)]);
49
+ return table(rows, ['kind', 'name', 'description']);
50
+ }
51
+
52
+ // --- sync ---
53
+
54
+ export function renderSyncTargets(targets) {
55
+ const rows = targets.map(t => [
56
+ t.id,
57
+ t.label,
58
+ Object.entries(t.capabilities).filter(([, v]) => v).map(([k]) => k).join(', '),
59
+ ]);
60
+ return table(rows, ['id', 'label', 'capabilities']);
61
+ }
62
+
63
+ export function renderSyncStatus(result) {
64
+ const rows = result.checks.map(c => [c.capability, c.path, c.exists ? '✓' : '—']);
65
+ return `${c.bold(`Status: ${result.target}`)} ${c.dim(result.projectRoot)}\n` + table(rows, ['cap', 'path', 'present']);
66
+ }
67
+
68
+ export function renderSyncInstall(result) {
69
+ // Tally written paths by capability prefix
70
+ const counts = {};
71
+ for (const p of result.written) {
72
+ const rel = path.relative(result.projectRoot, p).replace(/\\/g, '/');
73
+ // Hide internal markers from the user-facing tally (they're a kit-mcp impl detail)
74
+ if (rel.endsWith('/.kit-mcp-managed')) continue;
75
+ let cap = 'rules';
76
+ if (rel.includes('.claude/agents/')) cap = 'agents';
77
+ else if (rel.includes('.claude/commands/')) cap = 'commands';
78
+ else if (rel.includes('.claude/skills/')) cap = 'skills';
79
+ else if (rel.includes('.claude/framework/')) cap = 'framework';
80
+ else if (rel.includes('.claude/hooks/')) cap = 'hooks';
81
+ counts[cap] = (counts[cap] ?? 0) + 1;
82
+ }
83
+ const rows = [];
84
+ for (const cap of ['rules', 'agents', 'commands', 'skills', 'framework', 'hooks']) {
85
+ if (counts[cap] !== undefined) rows.push([cap, counts[cap]]);
86
+ }
87
+ const visibleTotal = Object.values(counts).reduce((a, b) => a + b, 0);
88
+ // Phase 160 (v1.28): append diff tally row if cli attached one.
89
+ if (result._tally) {
90
+ const w = result._tally.written;
91
+ const s = result._tally.skipped;
92
+ rows.push(['new / updated', w]);
93
+ rows.push(['unchanged', s]);
94
+ }
95
+ return summary({
96
+ title: `Synced kit → ${result.target}${result.dryRun ? ' (dry-run)' : ''}`,
97
+ rows,
98
+ total: visibleTotal,
99
+ hint: c.dim(result.projectRoot),
100
+ }) + '\n';
101
+ }
102
+
103
+ export function renderSyncRemove(result) {
104
+ return summary({
105
+ title: `Removed kit-mcp stubs from ${result.target}`,
106
+ rows: [['Files removed', result.removed.length]],
107
+ total: result.removed.length,
108
+ hint: c.dim(result.projectRoot),
109
+ }) + '\n';
110
+ }
111
+
112
+ // --- reverse-sync ---
113
+
114
+ export function renderReverseDetect(result) {
115
+ if (result.candidates.length === 0) {
116
+ return `${c.green(icons.check)} No edits to bring back. Canonical kit and ${result.target} are in sync.\n`;
117
+ }
118
+ const rows = result.candidates.map(x => [x.kind, x.name, x.reason, x.diffSummary ?? '']);
119
+ return `${c.bold(`Candidates: ${result.candidates.length}`)} ${c.dim(`(${result.target})`)}\n` +
120
+ table(rows, ['kind', 'name', 'reason', 'diff']);
121
+ }
122
+
123
+ export function renderReverseApply(result) {
124
+ const rows = result.results.map(x => [
125
+ x.kind,
126
+ x.name,
127
+ x.action.startsWith('overwrit') || x.action.startsWith('merge') || x.action.startsWith('renamed')
128
+ ? c.green(x.action)
129
+ : x.action.startsWith('skipped') ? c.dim(x.action) : c.yellow(x.action),
130
+ ]);
131
+ return `${c.bold(`Applied (strategy=${result.strategy})`)}\n` + table(rows, ['kind', 'name', 'action']);
132
+ }
133
+
134
+ // --- gates ---
135
+
136
+ export function renderGatesList(items) {
137
+ const rows = items.map(g => [g.id, g.stage, g.blocking ? c.red('blocking') : c.dim('warn-only'), g.description]);
138
+ return table(rows, ['id', 'stage', 'mode', 'description']);
139
+ }
140
+
141
+ export function renderGateRun(result) {
142
+ const verdictColor = result.verdict === 'passed' ? c.green
143
+ : result.verdict === 'block' ? c.red
144
+ : result.verdict === 'warn' ? c.yellow
145
+ : c.dim;
146
+ return `${c.bold(`Gate ${result.id}`)}: ${verdictColor(result.verdict)} ${result.exitCode !== undefined ? c.dim(`(exit ${result.exitCode})`) : ''}\n`;
147
+ }
148
+
149
+ // --- forensics ---
150
+
151
+ export function renderForensicsCollect(items) {
152
+ if (items.length === 0) return `${c.dim('No failures collected.')}\n`;
153
+ const rows = items.map(x => [x.agent ?? '?', x.kind ?? '?', x.absPath ?? x.path ?? '']);
154
+ return table(rows, ['agent', 'kind', 'path']);
155
+ }
156
+
157
+ export function renderForensicsSummarize(byAgent) {
158
+ const entries = Object.entries(byAgent ?? {});
159
+ if (entries.length === 0) return `${c.dim('No failures.')}\n`;
160
+ const rows = entries.map(([agent, items]) => [agent, Array.isArray(items) ? items.length : '?']);
161
+ return table(rows, ['agent', 'failures']);
162
+ }
163
+
164
+ export function renderListReplays(items) {
165
+ if (!Array.isArray(items) || items.length === 0) return `${c.dim('No replays recorded.')}\n`;
166
+ const rows = items.map(r => [r.id ?? '?', r.agent ?? '?', r.timestamp ?? '?']);
167
+ return table(rows, ['id', 'agent', 'recorded']);
168
+ }
169
+
170
+ // --- install ---
171
+
172
+ export function renderInstallTargets(targets) {
173
+ const rows = targets.map(t => [t.id, t.label, t.scopes?.join(', ') ?? '?']);
174
+ return table(rows, ['id', 'label', 'scopes']);
175
+ }
176
+
177
+ export function renderInstallResult(result) {
178
+ return summary({
179
+ title: result.dryRun ? `Install preview (${result.target}, scope=${result.scope})` : `Registered kit-mcp → ${result.target} (scope=${result.scope})`,
180
+ rows: [
181
+ ['Path', result.path ?? '?'],
182
+ ['Name', result.name ?? 'kit'],
183
+ ['Via', result.via ?? '?'],
184
+ ].map(([k, v]) => [k, v ?? '—']),
185
+ hint: result.dryRun ? c.dim('No file written (dry-run)') : undefined,
186
+ }) + '\n';
187
+ }
188
+
189
+ // --- generic fallback ---
190
+
191
+ export function renderFallback(value) {
192
+ // Used when we don't have a custom renderer yet.
193
+ return JSON.stringify(value, null, 2) + '\n';
194
+ }
@@ -1,135 +1,135 @@
1
- // upgrade-check.js — non-blocking check for newer kit-mcp on npm.
2
- //
3
- // Both `kit doctor` (U1) and `kit ui start` (U4) call this. Result is cached
4
- // to ~/.kit-mcp/version-check.json for 24h so we don't hit the npm registry on
5
- // every boot. Falls back gracefully when offline or when the request fails.
6
-
7
- import fs from 'node:fs/promises';
8
- import os from 'node:os';
9
- import path from 'node:path';
10
- import https from 'node:https';
11
- import { fileURLToPath } from 'node:url';
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = path.dirname(__filename);
15
-
16
- const PACKAGE_NAME = '@luanpdd/kit-mcp';
17
- const CHECK_TTL_MS = 24 * 60 * 60 * 1000; // 24h
18
- const REQUEST_TIMEOUT_MS = 1500;
19
-
20
- function cacheFile() {
21
- return path.join(os.homedir(), '.kit-mcp', 'version-check.json');
22
- }
23
-
24
- async function readCache() {
25
- try {
26
- const raw = await fs.readFile(cacheFile(), 'utf8');
27
- const obj = JSON.parse(raw);
28
- if (typeof obj.checkedAt !== 'number' || typeof obj.latest !== 'string') return null;
29
- if (Date.now() - obj.checkedAt > CHECK_TTL_MS) return null;
30
- return obj;
31
- } catch {
32
- return null;
33
- }
34
- }
35
-
36
- async function writeCache(obj) {
37
- try {
38
- await fs.mkdir(path.dirname(cacheFile()), { recursive: true });
39
- await fs.writeFile(cacheFile(), JSON.stringify(obj), 'utf8');
40
- } catch {
41
- /* cache failures are silent — not critical */
42
- }
43
- }
44
-
45
- function fetchLatest() {
46
- // Use the registry's package endpoint. Falls back to gracefully on any error.
47
- return new Promise((resolve) => {
48
- const req = https.request({
49
- method: 'GET',
50
- hostname: 'registry.npmjs.org',
51
- path: `/${encodeURIComponent(PACKAGE_NAME)}/latest`,
52
- headers: { 'accept': 'application/json' },
53
- timeout: REQUEST_TIMEOUT_MS,
54
- }, (res) => {
55
- if (res.statusCode !== 200) { res.resume(); resolve(null); return; }
56
- let body = '';
57
- res.setEncoding('utf8');
58
- res.on('data', (c) => { body += c; });
59
- res.on('end', () => {
60
- try {
61
- const j = JSON.parse(body);
62
- resolve(typeof j.version === 'string' ? j.version : null);
63
- } catch {
64
- resolve(null);
65
- }
66
- });
67
- });
68
- req.on('error', () => resolve(null));
69
- req.on('timeout', () => { try { req.destroy(); } catch { /* noop */ } resolve(null); });
70
- req.end();
71
- });
72
- }
73
-
74
- export async function getLocalVersion() {
75
- // Read package.json from the kit-mcp install root (parent of src/).
76
- try {
77
- const pkgPath = path.resolve(__dirname, '../../package.json');
78
- const raw = await fs.readFile(pkgPath, 'utf8');
79
- const j = JSON.parse(raw);
80
- return typeof j.version === 'string' ? j.version : null;
81
- } catch {
82
- return null;
83
- }
84
- }
85
-
86
- // Compare semver-like x.y.z lexically by component. Returns -1/0/1.
87
- // Missing components default to 0 ("1.5" === "1.5.0").
88
- function compareVersions(a, b) {
89
- const parse = (v) => {
90
- const parts = v.split('.').map((n) => Number.parseInt(n, 10) || 0);
91
- while (parts.length < 3) parts.push(0);
92
- return parts;
93
- };
94
- const [a1, a2, a3] = parse(a);
95
- const [b1, b2, b3] = parse(b);
96
- if (a1 !== b1) return a1 < b1 ? -1 : 1;
97
- if (a2 !== b2) return a2 < b2 ? -1 : 1;
98
- if (a3 !== b3) return a3 < b3 ? -1 : 1;
99
- return 0;
100
- }
101
-
102
- // checkUpgrade({ force }): returns { local, latest, behind, source } or null on failure.
103
- // force=true bypasses the 24h cache.
104
- export async function checkUpgrade({ force = false } = {}) {
105
- const local = await getLocalVersion();
106
- if (!local) return null;
107
-
108
- if (!force) {
109
- const cached = await readCache();
110
- if (cached?.latest) {
111
- return {
112
- local,
113
- latest: cached.latest,
114
- behind: compareVersions(local, cached.latest) < 0,
115
- source: 'cache',
116
- };
117
- }
118
- }
119
-
120
- const latest = await fetchLatest();
121
- if (!latest) {
122
- // Network failed; surface what we have.
123
- return { local, latest: null, behind: false, source: 'offline' };
124
- }
125
-
126
- await writeCache({ checkedAt: Date.now(), latest });
127
- return {
128
- local,
129
- latest,
130
- behind: compareVersions(local, latest) < 0,
131
- source: 'network',
132
- };
133
- }
134
-
135
- export const __test = { compareVersions, PACKAGE_NAME, CHECK_TTL_MS };
1
+ // upgrade-check.js — non-blocking check for newer kit-mcp on npm.
2
+ //
3
+ // Both `kit doctor` (U1) and `kit ui start` (U4) call this. Result is cached
4
+ // to ~/.kit-mcp/version-check.json for 24h so we don't hit the npm registry on
5
+ // every boot. Falls back gracefully when offline or when the request fails.
6
+
7
+ import fs from 'node:fs/promises';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ import https from 'node:https';
11
+ import { fileURLToPath } from 'node:url';
12
+
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = path.dirname(__filename);
15
+
16
+ const PACKAGE_NAME = '@luanpdd/kit-mcp';
17
+ const CHECK_TTL_MS = 24 * 60 * 60 * 1000; // 24h
18
+ const REQUEST_TIMEOUT_MS = 1500;
19
+
20
+ function cacheFile() {
21
+ return path.join(os.homedir(), '.kit-mcp', 'version-check.json');
22
+ }
23
+
24
+ async function readCache() {
25
+ try {
26
+ const raw = await fs.readFile(cacheFile(), 'utf8');
27
+ const obj = JSON.parse(raw);
28
+ if (typeof obj.checkedAt !== 'number' || typeof obj.latest !== 'string') return null;
29
+ if (Date.now() - obj.checkedAt > CHECK_TTL_MS) return null;
30
+ return obj;
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+
36
+ async function writeCache(obj) {
37
+ try {
38
+ await fs.mkdir(path.dirname(cacheFile()), { recursive: true });
39
+ await fs.writeFile(cacheFile(), JSON.stringify(obj), 'utf8');
40
+ } catch {
41
+ /* cache failures are silent — not critical */
42
+ }
43
+ }
44
+
45
+ function fetchLatest() {
46
+ // Use the registry's package endpoint. Falls back to gracefully on any error.
47
+ return new Promise((resolve) => {
48
+ const req = https.request({
49
+ method: 'GET',
50
+ hostname: 'registry.npmjs.org',
51
+ path: `/${encodeURIComponent(PACKAGE_NAME)}/latest`,
52
+ headers: { 'accept': 'application/json' },
53
+ timeout: REQUEST_TIMEOUT_MS,
54
+ }, (res) => {
55
+ if (res.statusCode !== 200) { res.resume(); resolve(null); return; }
56
+ let body = '';
57
+ res.setEncoding('utf8');
58
+ res.on('data', (c) => { body += c; });
59
+ res.on('end', () => {
60
+ try {
61
+ const j = JSON.parse(body);
62
+ resolve(typeof j.version === 'string' ? j.version : null);
63
+ } catch {
64
+ resolve(null);
65
+ }
66
+ });
67
+ });
68
+ req.on('error', () => resolve(null));
69
+ req.on('timeout', () => { try { req.destroy(); } catch { /* noop */ } resolve(null); });
70
+ req.end();
71
+ });
72
+ }
73
+
74
+ export async function getLocalVersion() {
75
+ // Read package.json from the kit-mcp install root (parent of src/).
76
+ try {
77
+ const pkgPath = path.resolve(__dirname, '../../package.json');
78
+ const raw = await fs.readFile(pkgPath, 'utf8');
79
+ const j = JSON.parse(raw);
80
+ return typeof j.version === 'string' ? j.version : null;
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+
86
+ // Compare semver-like x.y.z lexically by component. Returns -1/0/1.
87
+ // Missing components default to 0 ("1.5" === "1.5.0").
88
+ function compareVersions(a, b) {
89
+ const parse = (v) => {
90
+ const parts = v.split('.').map((n) => Number.parseInt(n, 10) || 0);
91
+ while (parts.length < 3) parts.push(0);
92
+ return parts;
93
+ };
94
+ const [a1, a2, a3] = parse(a);
95
+ const [b1, b2, b3] = parse(b);
96
+ if (a1 !== b1) return a1 < b1 ? -1 : 1;
97
+ if (a2 !== b2) return a2 < b2 ? -1 : 1;
98
+ if (a3 !== b3) return a3 < b3 ? -1 : 1;
99
+ return 0;
100
+ }
101
+
102
+ // checkUpgrade({ force }): returns { local, latest, behind, source } or null on failure.
103
+ // force=true bypasses the 24h cache.
104
+ export async function checkUpgrade({ force = false } = {}) {
105
+ const local = await getLocalVersion();
106
+ if (!local) return null;
107
+
108
+ if (!force) {
109
+ const cached = await readCache();
110
+ if (cached?.latest) {
111
+ return {
112
+ local,
113
+ latest: cached.latest,
114
+ behind: compareVersions(local, cached.latest) < 0,
115
+ source: 'cache',
116
+ };
117
+ }
118
+ }
119
+
120
+ const latest = await fetchLatest();
121
+ if (!latest) {
122
+ // Network failed; surface what we have.
123
+ return { local, latest: null, behind: false, source: 'offline' };
124
+ }
125
+
126
+ await writeCache({ checkedAt: Date.now(), latest });
127
+ return {
128
+ local,
129
+ latest,
130
+ behind: compareVersions(local, latest) < 0,
131
+ source: 'network',
132
+ };
133
+ }
134
+
135
+ export const __test = { compareVersions, PACKAGE_NAME, CHECK_TTL_MS };