@massu/core 1.10.8 → 1.12.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 (178) hide show
  1. package/CHANGELOG.md +1303 -0
  2. package/dist/adapter.js +6 -4
  3. package/dist/cli.js +517 -397
  4. package/dist/detect/adapters/.bundle-shasums.json +4 -7
  5. package/dist/detect/adapters/rails.js +6 -4
  6. package/dist/detect/adapters/spring.js +6 -4
  7. package/dist/detect/adapters/tree-sitter-loader.js +6 -4
  8. package/dist/hooks/auto-learning-pipeline.js +24 -1
  9. package/dist/hooks/classify-failure.js +32 -3
  10. package/dist/hooks/cost-tracker.js +24 -0
  11. package/dist/hooks/fix-detector.js +97 -1
  12. package/dist/hooks/incident-pipeline.js +30 -1
  13. package/dist/hooks/intent-suggester.js +6 -3
  14. package/dist/hooks/post-edit-context.js +24 -1
  15. package/dist/hooks/post-tool-use.js +66 -18
  16. package/dist/hooks/pre-compact.js +27 -2
  17. package/dist/hooks/pre-delete-check.js +48 -22
  18. package/dist/hooks/pre-tool-use-gate.js +962 -0
  19. package/dist/hooks/quality-event.js +24 -0
  20. package/dist/hooks/rule-enforcement-pipeline.js +24 -1
  21. package/dist/hooks/security-gate.js +29 -16
  22. package/dist/hooks/session-end.js +24 -0
  23. package/dist/hooks/session-start.js +8710 -8460
  24. package/dist/hooks/user-prompt.js +24 -0
  25. package/package.json +15 -18
  26. package/commands/README.md +0 -134
  27. package/src/adapter.ts +0 -121
  28. package/src/adr-generator.ts +0 -292
  29. package/src/analytics.ts +0 -373
  30. package/src/audit-trail.ts +0 -450
  31. package/src/backfill-sessions.ts +0 -182
  32. package/src/changelog-generator.ts +0 -178
  33. package/src/cli.ts +0 -246
  34. package/src/cloud-sync.ts +0 -234
  35. package/src/commands/adapters.ts +0 -824
  36. package/src/commands/changelog.ts +0 -165
  37. package/src/commands/config-check-drift.ts +0 -133
  38. package/src/commands/config-refresh.ts +0 -396
  39. package/src/commands/config-upgrade.ts +0 -127
  40. package/src/commands/doctor.ts +0 -485
  41. package/src/commands/hook-runner.ts +0 -145
  42. package/src/commands/init.ts +0 -1823
  43. package/src/commands/install-commands.ts +0 -692
  44. package/src/commands/install-hooks.ts +0 -27
  45. package/src/commands/permissions.ts +0 -150
  46. package/src/commands/refresh-log.ts +0 -37
  47. package/src/commands/show-template.ts +0 -65
  48. package/src/commands/template-engine.ts +0 -301
  49. package/src/commands/watch.ts +0 -430
  50. package/src/config.ts +0 -765
  51. package/src/cost-tracker.ts +0 -355
  52. package/src/db.ts +0 -370
  53. package/src/dependency-scorer.ts +0 -337
  54. package/src/detect/adapters/aspnet.ts +0 -4
  55. package/src/detect/adapters/discover.ts +0 -469
  56. package/src/detect/adapters/file-sampler.ts +0 -225
  57. package/src/detect/adapters/go-chi.ts +0 -4
  58. package/src/detect/adapters/index.ts +0 -51
  59. package/src/detect/adapters/nextjs-trpc.ts +0 -166
  60. package/src/detect/adapters/parse-guard.ts +0 -133
  61. package/src/detect/adapters/phoenix.ts +0 -4
  62. package/src/detect/adapters/python-django.ts +0 -208
  63. package/src/detect/adapters/python-fastapi.ts +0 -223
  64. package/src/detect/adapters/python-flask.ts +0 -235
  65. package/src/detect/adapters/query-helpers.ts +0 -170
  66. package/src/detect/adapters/rails.ts +0 -4
  67. package/src/detect/adapters/runner.ts +0 -284
  68. package/src/detect/adapters/spring.ts +0 -4
  69. package/src/detect/adapters/swift-swiftui.ts +0 -171
  70. package/src/detect/adapters/tree-sitter-loader.ts +0 -517
  71. package/src/detect/adapters/types.ts +0 -191
  72. package/src/detect/codebase-introspector.ts +0 -210
  73. package/src/detect/domain-inferrer.ts +0 -197
  74. package/src/detect/drift.ts +0 -199
  75. package/src/detect/framework-detector.ts +0 -307
  76. package/src/detect/index.ts +0 -209
  77. package/src/detect/manifest-registry.ts +0 -261
  78. package/src/detect/migrate.ts +0 -362
  79. package/src/detect/monorepo-detector.ts +0 -348
  80. package/src/detect/package-detector.ts +0 -828
  81. package/src/detect/passthrough.ts +0 -108
  82. package/src/detect/regex-fallback.ts +0 -449
  83. package/src/detect/source-dir-detector.ts +0 -297
  84. package/src/detect/vr-command-map.ts +0 -167
  85. package/src/docs-map.json +0 -100
  86. package/src/docs-tools.ts +0 -519
  87. package/src/domains.ts +0 -182
  88. package/src/hooks/auto-learning-pipeline.ts +0 -228
  89. package/src/hooks/classify-failure.ts +0 -259
  90. package/src/hooks/cost-tracker.ts +0 -66
  91. package/src/hooks/fix-detector.ts +0 -186
  92. package/src/hooks/incident-pipeline.ts +0 -190
  93. package/src/hooks/intent-suggester.ts +0 -131
  94. package/src/hooks/post-edit-context.ts +0 -91
  95. package/src/hooks/post-tool-use.ts +0 -413
  96. package/src/hooks/pre-compact.ts +0 -168
  97. package/src/hooks/pre-delete-check.ts +0 -243
  98. package/src/hooks/quality-event.ts +0 -127
  99. package/src/hooks/rule-enforcement-pipeline.ts +0 -159
  100. package/src/hooks/security-gate.ts +0 -153
  101. package/src/hooks/session-end.ts +0 -467
  102. package/src/hooks/session-start.ts +0 -436
  103. package/src/hooks/user-prompt.ts +0 -157
  104. package/src/import-resolver.ts +0 -226
  105. package/src/knowledge-db.ts +0 -176
  106. package/src/knowledge-indexer.ts +0 -708
  107. package/src/knowledge-tools.ts +0 -1414
  108. package/src/lib/fileLock.ts +0 -203
  109. package/src/lib/framework-supports.ts +0 -85
  110. package/src/lib/gitToplevel.ts +0 -22
  111. package/src/lib/hook-registry.ts +0 -43
  112. package/src/lib/installLock.ts +0 -66
  113. package/src/lib/memory-path.ts +0 -49
  114. package/src/lib/pidLiveness.ts +0 -67
  115. package/src/lib/settings-local.ts +0 -110
  116. package/src/lib/sql-table-names.ts +0 -71
  117. package/src/license.ts +0 -547
  118. package/src/lsp/auto-detect.ts +0 -98
  119. package/src/lsp/client.ts +0 -776
  120. package/src/lsp/enrich.ts +0 -127
  121. package/src/lsp/types.ts +0 -221
  122. package/src/memory-db.ts +0 -1614
  123. package/src/memory-file-ingest.ts +0 -128
  124. package/src/memory-tools.ts +0 -424
  125. package/src/middleware-tree.ts +0 -71
  126. package/src/observability-tools.ts +0 -343
  127. package/src/observation-extractor.ts +0 -418
  128. package/src/page-deps.ts +0 -285
  129. package/src/permissions.ts +0 -422
  130. package/src/prompt-analyzer.ts +0 -332
  131. package/src/python/coupling-detector.ts +0 -125
  132. package/src/python/domain-enforcer.ts +0 -84
  133. package/src/python/impact-analyzer.ts +0 -96
  134. package/src/python/import-parser.ts +0 -244
  135. package/src/python/import-resolver.ts +0 -136
  136. package/src/python/migration-indexer.ts +0 -116
  137. package/src/python/migration-parser.ts +0 -332
  138. package/src/python/model-indexer.ts +0 -71
  139. package/src/python/model-parser.ts +0 -279
  140. package/src/python/route-indexer.ts +0 -59
  141. package/src/python/route-parser.ts +0 -317
  142. package/src/python-tools.ts +0 -630
  143. package/src/regression-detector.ts +0 -319
  144. package/src/rules.ts +0 -57
  145. package/src/schema-mapper.ts +0 -232
  146. package/src/security/adapter-origin.ts +0 -130
  147. package/src/security/adapter-verifier.ts +0 -319
  148. package/src/security/atomic-write.ts +0 -164
  149. package/src/security/fetcher.ts +0 -200
  150. package/src/security/install-tracking.ts +0 -319
  151. package/src/security/license-pubkey.generated.ts +0 -30
  152. package/src/security/license-response-verifier.ts +0 -149
  153. package/src/security/local-fingerprint.ts +0 -225
  154. package/src/security/manifest-cache.ts +0 -333
  155. package/src/security/manifest-schema.ts +0 -129
  156. package/src/security/registry-pubkey.generated.ts +0 -35
  157. package/src/security/telemetry.ts +0 -320
  158. package/src/security-scorer.ts +0 -405
  159. package/src/security-utils.ts +0 -133
  160. package/src/sentinel-db.ts +0 -580
  161. package/src/sentinel-scanner.ts +0 -406
  162. package/src/sentinel-tools.ts +0 -513
  163. package/src/sentinel-types.ts +0 -140
  164. package/src/server-dispatch.ts +0 -225
  165. package/src/server.ts +0 -107
  166. package/src/session-archiver.ts +0 -111
  167. package/src/session-state-generator.ts +0 -174
  168. package/src/team-knowledge.ts +0 -407
  169. package/src/tool-db-needs.ts +0 -232
  170. package/src/tools.ts +0 -1206
  171. package/src/transcript-parser.ts +0 -458
  172. package/src/trpc-index.ts +0 -215
  173. package/src/validate-features-runner.ts +0 -107
  174. package/src/validation-engine.ts +0 -358
  175. package/src/watch/daemon.ts +0 -385
  176. package/src/watch/lockfile-detector.ts +0 -65
  177. package/src/watch/paths.ts +0 -279
  178. package/src/watch/state.ts +0 -178
@@ -1,513 +0,0 @@
1
- // Copyright (c) 2026 Massu. All rights reserved.
2
- // Licensed under BSL 1.1 - see LICENSE file for details.
3
-
4
- import type Database from 'better-sqlite3';
5
- import type { ToolDefinition, ToolResult } from './tools.ts';
6
- import {
7
- searchFeatures,
8
- getFeatureDetail,
9
- getFeatureImpact,
10
- validateFeatures,
11
- upsertFeature,
12
- linkComponent,
13
- linkProcedure,
14
- linkPage,
15
- logChange,
16
- checkParity,
17
- } from './sentinel-db.ts';
18
- import type { ComponentRole, FeatureStatus, FeaturePriority } from './sentinel-types.ts';
19
- import { getConfig } from './config.ts';
20
- import { t } from './lib/sql-table-names.ts';
21
-
22
- /** Prefix a base tool name with the configured tool prefix. */
23
- function p(baseName: string): string {
24
- return `${getConfig().toolPrefix}_${baseName}`;
25
- }
26
-
27
- // ============================================================
28
- // Sentinel: MCP Tool Definitions & Handlers
29
- // ============================================================
30
-
31
- function text(content: string): ToolResult {
32
- return { content: [{ type: 'text', text: content }] };
33
- }
34
-
35
- export function getSentinelToolDefinitions(): ToolDefinition[] {
36
- return [
37
- // P2-001: sentinel_search
38
- {
39
- name: p('sentinel_search'),
40
- description: 'Search and list features in the Sentinel feature registry. Supports FTS5 full-text search and domain/status/portal filters.',
41
- inputSchema: {
42
- type: 'object',
43
- properties: {
44
- query: { type: 'string', description: 'Full-text search query (FTS5 syntax)' },
45
- domain: { type: 'string', description: 'Filter by domain (e.g., production, design, crm)' },
46
- subdomain: { type: 'string', description: 'Filter by subdomain (e.g., factory-review)' },
47
- status: { type: 'string', description: 'Filter by status: planned, active, deprecated, removed' },
48
- portal: { type: 'string', description: 'Filter by portal scope: internal, factory, designer, customer' },
49
- page_route: { type: 'string', description: 'Filter by page route (e.g., /production/factory-reviews/[id])' },
50
- },
51
- required: [],
52
- },
53
- },
54
- // P2-002: sentinel_detail
55
- {
56
- name: p('sentinel_detail'),
57
- description: 'Get full feature details including all linked components, procedures, pages, dependencies, and changelog.',
58
- inputSchema: {
59
- type: 'object',
60
- properties: {
61
- feature_key: { type: 'string', description: 'Feature key (e.g., factory-review.pdf-export)' },
62
- feature_id: { type: 'number', description: 'Feature ID (alternative to feature_key)' },
63
- },
64
- required: [],
65
- },
66
- },
67
- // P2-003: sentinel_impact
68
- {
69
- name: p('sentinel_impact'),
70
- description: 'Pre-deletion impact analysis. Shows which features would be orphaned, degraded, or unaffected if specified files are deleted. BLOCKS if critical features would be orphaned.',
71
- inputSchema: {
72
- type: 'object',
73
- properties: {
74
- files: {
75
- type: 'array',
76
- items: { type: 'string' },
77
- description: 'Array of file paths to analyze (relative to project root)',
78
- },
79
- },
80
- required: ['files'],
81
- },
82
- },
83
- // P2-004: sentinel_validate
84
- {
85
- name: p('sentinel_validate'),
86
- description: 'Validate all active features have living implementation files. Reports alive, orphaned, and degraded features.',
87
- inputSchema: {
88
- type: 'object',
89
- properties: {
90
- domain: { type: 'string', description: 'Optional: only validate features in this domain' },
91
- fix: { type: 'boolean', description: 'If true, auto-mark dead features as deprecated' },
92
- },
93
- required: [],
94
- },
95
- },
96
- // P2-005: sentinel_register
97
- {
98
- name: p('sentinel_register'),
99
- description: 'Register or update a feature in the sentinel registry. Links components, procedures, and pages.',
100
- inputSchema: {
101
- type: 'object',
102
- properties: {
103
- feature_key: { type: 'string', description: 'Unique feature key (e.g., factory-review.pdf-export)' },
104
- domain: { type: 'string', description: 'Domain (e.g., production, design, crm)' },
105
- title: { type: 'string', description: 'Human-readable title' },
106
- description: { type: 'string', description: 'Feature description / user story' },
107
- status: { type: 'string', description: 'planned | active | deprecated | removed' },
108
- priority: { type: 'string', description: 'critical | standard | nice-to-have' },
109
- portal_scope: { type: 'array', items: { type: 'string' }, description: 'Portal scope array' },
110
- components: {
111
- type: 'array',
112
- items: {
113
- type: 'object',
114
- properties: {
115
- file: { type: 'string' },
116
- name: { type: 'string' },
117
- role: { type: 'string' },
118
- is_primary: { type: 'boolean' },
119
- },
120
- required: ['file'],
121
- },
122
- description: 'Component files to link',
123
- },
124
- procedures: {
125
- type: 'array',
126
- items: {
127
- type: 'object',
128
- properties: {
129
- router: { type: 'string' },
130
- procedure: { type: 'string' },
131
- type: { type: 'string' },
132
- },
133
- required: ['router', 'procedure'],
134
- },
135
- description: 'tRPC procedures to link',
136
- },
137
- pages: {
138
- type: 'array',
139
- items: {
140
- type: 'object',
141
- properties: {
142
- route: { type: 'string' },
143
- portal: { type: 'string' },
144
- },
145
- required: ['route'],
146
- },
147
- description: 'Page routes to link',
148
- },
149
- },
150
- required: ['feature_key', 'domain', 'title'],
151
- },
152
- },
153
- // P2-006: sentinel_parity
154
- {
155
- name: p('sentinel_parity'),
156
- description: 'Compare two sets of files for feature parity. Shows features in old but not new (GAPs), features in both (DONE), and features only in new (NEW).',
157
- inputSchema: {
158
- type: 'object',
159
- properties: {
160
- old_files: {
161
- type: 'array',
162
- items: { type: 'string' },
163
- description: 'Old implementation files',
164
- },
165
- new_files: {
166
- type: 'array',
167
- items: { type: 'string' },
168
- description: 'New implementation files',
169
- },
170
- },
171
- required: ['old_files', 'new_files'],
172
- },
173
- },
174
- ];
175
- }
176
-
177
- // ============================================================
178
- // Tool Handler Router
179
- // ============================================================
180
-
181
- export function handleSentinelToolCall(
182
- name: string,
183
- args: Record<string, unknown>,
184
- dataDb: Database.Database
185
- ): ToolResult {
186
- const prefix = getConfig().toolPrefix + '_';
187
- const baseName = name.startsWith(prefix) ? name.slice(prefix.length) : name;
188
-
189
- switch (baseName) {
190
- case 'sentinel_search':
191
- return handleSearch(args, dataDb);
192
- case 'sentinel_detail':
193
- return handleDetail(args, dataDb);
194
- case 'sentinel_impact':
195
- return handleImpact(args, dataDb);
196
- case 'sentinel_validate':
197
- return handleValidate(args, dataDb);
198
- case 'sentinel_register':
199
- return handleRegister(args, dataDb);
200
- case 'sentinel_parity':
201
- return handleParityCheck(args, dataDb);
202
- default:
203
- return text(`Unknown sentinel tool: ${name}`);
204
- }
205
- }
206
-
207
- // ============================================================
208
- // Individual Handlers
209
- // ============================================================
210
-
211
- function handleSearch(args: Record<string, unknown>, db: Database.Database): ToolResult {
212
- const query = (args.query as string) || '';
213
- const filters = {
214
- domain: args.domain as string | undefined,
215
- subdomain: args.subdomain as string | undefined,
216
- status: args.status as string | undefined,
217
- portal: args.portal as string | undefined,
218
- page_route: args.page_route as string | undefined,
219
- };
220
-
221
- const results = searchFeatures(db, query, filters);
222
- const lines: string[] = [];
223
-
224
- lines.push(`## Sentinel Search Results (${results.length} features)`);
225
- if (query) lines.push(`Query: "${query}"`);
226
- const activeFilters = Object.entries(filters).filter(([, v]) => v);
227
- if (activeFilters.length > 0) {
228
- lines.push(`Filters: ${activeFilters.map(([k, v]) => `${k}=${v}`).join(', ')}`);
229
- }
230
- lines.push('');
231
-
232
- if (results.length === 0) {
233
- lines.push('No features found matching criteria.');
234
- return text(lines.join('\n'));
235
- }
236
-
237
- let currentDomain = '';
238
- for (const f of results) {
239
- if (f.domain !== currentDomain) {
240
- currentDomain = f.domain;
241
- lines.push(`### ${currentDomain}`);
242
- }
243
- const sub = f.subdomain ? `[${f.subdomain}]` : '';
244
- const priority = f.priority === 'critical' ? ' [CRITICAL]' : '';
245
- lines.push(`- **${f.feature_key}** ${sub}${priority}: ${f.title} (${f.component_count}C/${f.procedure_count}P/${f.page_count}R) [${f.status}]`);
246
- }
247
-
248
- return text(lines.join('\n'));
249
- }
250
-
251
- function handleDetail(args: Record<string, unknown>, db: Database.Database): ToolResult {
252
- const key = args.feature_key as string | undefined;
253
- const id = args.feature_id as number | undefined;
254
-
255
- if (!key && !id) {
256
- return text('Error: Provide either feature_key or feature_id');
257
- }
258
-
259
- const detail = getFeatureDetail(db, id || key!);
260
- if (!detail) {
261
- return text(`Feature not found: ${key || id}`);
262
- }
263
-
264
- const lines: string[] = [];
265
- lines.push(`## Feature: ${detail.feature_key}`);
266
- lines.push(`- **Title**: ${detail.title}`);
267
- lines.push(`- **Domain**: ${detail.domain}${detail.subdomain ? '/' + detail.subdomain : ''}`);
268
- lines.push(`- **Status**: ${detail.status}`);
269
- lines.push(`- **Priority**: ${detail.priority}`);
270
- if (detail.description) lines.push(`- **Description**: ${detail.description}`);
271
- if (detail.portal_scope.length > 0) lines.push(`- **Portals**: ${detail.portal_scope.join(', ')}`);
272
- lines.push('');
273
-
274
- if (detail.components.length > 0) {
275
- lines.push(`### Components (${detail.components.length})`);
276
- for (const c of detail.components) {
277
- const primary = c.is_primary ? ' [PRIMARY]' : '';
278
- lines.push(`- ${c.component_file}${c.component_name ? ':' + c.component_name : ''} (${c.role})${primary}`);
279
- }
280
- lines.push('');
281
- }
282
-
283
- if (detail.procedures.length > 0) {
284
- lines.push(`### Procedures (${detail.procedures.length})`);
285
- for (const p of detail.procedures) {
286
- lines.push(`- ${p.router_name}.${p.procedure_name}${p.procedure_type ? ' (' + p.procedure_type + ')' : ''}`);
287
- }
288
- lines.push('');
289
- }
290
-
291
- if (detail.pages.length > 0) {
292
- lines.push(`### Pages (${detail.pages.length})`);
293
- for (const p of detail.pages) {
294
- lines.push(`- ${p.page_route}${p.portal ? ' (' + p.portal + ')' : ''}`);
295
- }
296
- lines.push('');
297
- }
298
-
299
- if (detail.dependencies.length > 0) {
300
- lines.push(`### Dependencies (${detail.dependencies.length})`);
301
- for (const d of detail.dependencies) {
302
- lines.push(`- ${d.dependency_type}: feature #${d.depends_on_feature_id}`);
303
- }
304
- lines.push('');
305
- }
306
-
307
- if (detail.changelog.length > 0) {
308
- lines.push(`### Changelog (last ${detail.changelog.length})`);
309
- for (const c of detail.changelog.slice(0, 10)) {
310
- lines.push(`- [${c.created_at}] ${c.change_type}: ${c.change_detail || '(no detail)'}${c.commit_hash ? ' @' + c.commit_hash.substring(0, 8) : ''}`);
311
- }
312
- }
313
-
314
- return text(lines.join('\n'));
315
- }
316
-
317
- function handleImpact(args: Record<string, unknown>, db: Database.Database): ToolResult {
318
- const files = args.files as string[];
319
- if (!files || files.length === 0) {
320
- return text('Error: Provide files array');
321
- }
322
-
323
- const report = getFeatureImpact(db, files);
324
- const lines: string[] = [];
325
-
326
- lines.push(`## Feature Impact Analysis`);
327
- lines.push(`Files analyzed: ${report.files_analyzed.length}`);
328
- lines.push('');
329
-
330
- if (report.blocked) {
331
- lines.push(`### ${report.block_reason}`);
332
- lines.push('');
333
- }
334
-
335
- lines.push(`### Summary`);
336
- lines.push(`- Orphaned: ${report.orphaned.length} (no primary components left)`);
337
- lines.push(`- Degraded: ${report.degraded.length} (some components removed)`);
338
- lines.push(`- Unaffected: ${report.unaffected.length}`);
339
- lines.push('');
340
-
341
- if (report.orphaned.length > 0) {
342
- lines.push('### Orphaned Features (BLOCKING)');
343
- for (const item of report.orphaned) {
344
- lines.push(`- **${item.feature.feature_key}** [${item.feature.priority}]: ${item.feature.title}`);
345
- lines.push(` Files being deleted: ${item.affected_files.join(', ')}`);
346
- if (item.remaining_files.length > 0) {
347
- lines.push(` Remaining (non-primary): ${item.remaining_files.join(', ')}`);
348
- }
349
- }
350
- lines.push('');
351
- }
352
-
353
- if (report.degraded.length > 0) {
354
- lines.push('### Degraded Features (Warning)');
355
- for (const item of report.degraded) {
356
- lines.push(`- **${item.feature.feature_key}**: ${item.feature.title}`);
357
- lines.push(` Removed: ${item.affected_files.join(', ')}`);
358
- lines.push(` Remaining: ${item.remaining_files.join(', ')}`);
359
- }
360
- lines.push('');
361
- }
362
-
363
- return text(lines.join('\n'));
364
- }
365
-
366
- function handleValidate(args: Record<string, unknown>, db: Database.Database): ToolResult {
367
- const domain = args.domain as string | undefined;
368
- const fix = args.fix as boolean | undefined;
369
-
370
- const report = validateFeatures(db, domain);
371
- const lines: string[] = [];
372
-
373
- lines.push(`## Feature Validation Report`);
374
- if (domain) lines.push(`Domain filter: ${domain}`);
375
- lines.push('');
376
-
377
- lines.push(`### Summary`);
378
- lines.push(`- Alive: ${report.alive}`);
379
- lines.push(`- Orphaned: ${report.orphaned}`);
380
- lines.push(`- Degraded: ${report.degraded}`);
381
- lines.push(`- Total: ${report.alive + report.orphaned + report.degraded}`);
382
- lines.push('');
383
-
384
- const issues = report.details.filter(d => d.status !== 'alive');
385
- if (issues.length > 0) {
386
- lines.push('### Issues');
387
- for (const item of issues) {
388
- lines.push(`- **${item.feature.feature_key}** [${item.status.toUpperCase()}]`);
389
- if (item.missing_components.length > 0) {
390
- lines.push(` Missing components: ${item.missing_components.join(', ')}`);
391
- }
392
- if (item.missing_procedures.length > 0) {
393
- lines.push(` Missing procedures: ${item.missing_procedures.map(p => `${p.router}.${p.procedure}`).join(', ')}`);
394
- }
395
- if (item.missing_pages.length > 0) {
396
- lines.push(` Missing pages: ${item.missing_pages.join(', ')}`);
397
- }
398
- }
399
- lines.push('');
400
-
401
- if (fix) {
402
- lines.push('### Auto-Fix Applied');
403
- for (const item of issues.filter(i => i.status === 'orphaned')) {
404
- db.prepare(`UPDATE ${t('sentinel')} SET status = 'deprecated', updated_at = datetime('now') WHERE id = ?`).run(item.feature.id);
405
- logChange(db, item.feature.id, 'deprecated', 'Auto-deprecated: all primary components missing');
406
- lines.push(`- Deprecated: ${item.feature.feature_key}`);
407
- }
408
- }
409
- } else {
410
- lines.push('All active features are alive. No issues found.');
411
- }
412
-
413
- const result = report.orphaned === 0 ? 'PASS' : 'FAIL';
414
- lines.push(`### RESULT: ${result}`);
415
-
416
- return text(lines.join('\n'));
417
- }
418
-
419
- function handleRegister(args: Record<string, unknown>, db: Database.Database): ToolResult {
420
- const featureKey = args.feature_key as string;
421
- const domain = args.domain as string;
422
- const title = args.title as string;
423
-
424
- if (!featureKey || !domain || !title) {
425
- return text('Error: feature_key, domain, and title are required');
426
- }
427
-
428
- const featureId = upsertFeature(db, {
429
- feature_key: featureKey,
430
- domain,
431
- subdomain: args.subdomain as string | undefined,
432
- title,
433
- description: args.description as string | undefined,
434
- status: args.status as FeatureStatus | undefined,
435
- priority: args.priority as FeaturePriority | undefined,
436
- portal_scope: args.portal_scope as string[] | undefined,
437
- });
438
-
439
- // Link components
440
- const components = args.components as { file: string; name?: string; role?: string; is_primary?: boolean }[] | undefined;
441
- if (components) {
442
- for (const c of components) {
443
- linkComponent(db, featureId, c.file, c.name || null, (c.role as ComponentRole) || 'implementation', c.is_primary || false);
444
- }
445
- }
446
-
447
- // Link procedures
448
- const procedures = args.procedures as { router: string; procedure: string; type?: string }[] | undefined;
449
- if (procedures) {
450
- for (const p of procedures) {
451
- linkProcedure(db, featureId, p.router, p.procedure, p.type);
452
- }
453
- }
454
-
455
- // Link pages
456
- const pages = args.pages as { route: string; portal?: string }[] | undefined;
457
- if (pages) {
458
- for (const p of pages) {
459
- linkPage(db, featureId, p.route, p.portal);
460
- }
461
- }
462
-
463
- logChange(db, featureId, 'created', `Registered via ${p('sentinel_register')}`);
464
-
465
- return text(`Feature registered: ${featureKey} (ID: ${featureId})\nComponents: ${components?.length || 0}, Procedures: ${procedures?.length || 0}, Pages: ${pages?.length || 0}`);
466
- }
467
-
468
- function handleParityCheck(args: Record<string, unknown>, db: Database.Database): ToolResult {
469
- const oldFiles = args.old_files as string[];
470
- const newFiles = args.new_files as string[];
471
-
472
- if (!oldFiles || !newFiles) {
473
- return text('Error: Provide both old_files and new_files arrays');
474
- }
475
-
476
- const report = checkParity(db, oldFiles, newFiles);
477
- const lines: string[] = [];
478
-
479
- lines.push(`## Feature Parity Report`);
480
- lines.push(`Old files: ${oldFiles.length}, New files: ${newFiles.length}`);
481
- lines.push(`**Parity: ${report.parity_percentage}%**`);
482
- lines.push('');
483
-
484
- if (report.done.length > 0) {
485
- lines.push(`### DONE (${report.done.length} features carried forward)`);
486
- for (const item of report.done) {
487
- lines.push(`- ${item.feature_key}: ${item.title}`);
488
- }
489
- lines.push('');
490
- }
491
-
492
- if (report.gaps.length > 0) {
493
- lines.push(`### GAPS (${report.gaps.length} features MISSING in new implementation)`);
494
- for (const item of report.gaps) {
495
- lines.push(`- **${item.feature_key}**: ${item.title}`);
496
- lines.push(` Old: ${item.old_files.join(', ')}`);
497
- }
498
- lines.push('');
499
- }
500
-
501
- if (report.new_features.length > 0) {
502
- lines.push(`### NEW (${report.new_features.length} features only in new)`);
503
- for (const item of report.new_features) {
504
- lines.push(`- ${item.feature_key}: ${item.title}`);
505
- }
506
- lines.push('');
507
- }
508
-
509
- const result = report.gaps.length === 0 ? 'PASS' : `FAIL (${report.gaps.length} gaps)`;
510
- lines.push(`### RESULT: ${result}`);
511
-
512
- return text(lines.join('\n'));
513
- }
@@ -1,140 +0,0 @@
1
- // Copyright (c) 2026 Massu. All rights reserved.
2
- // Licensed under BSL 1.1 - see LICENSE file for details.
3
-
4
- // ============================================================
5
- // Sentinel: Feature Registry Type Definitions
6
- // ============================================================
7
-
8
- export type FeatureStatus = 'planned' | 'active' | 'deprecated' | 'removed';
9
- export type FeaturePriority = 'critical' | 'standard' | 'nice-to-have';
10
- export type ComponentRole = 'implementation' | 'ui' | 'data' | 'utility';
11
- export type DependencyType = 'requires' | 'enhances' | 'replaces';
12
- export type ChangeType = 'created' | 'updated' | 'deprecated' | 'removed' | 'restored';
13
-
14
- export interface Feature {
15
- id: number;
16
- feature_key: string;
17
- domain: string;
18
- subdomain: string | null;
19
- title: string;
20
- description: string | null;
21
- status: FeatureStatus;
22
- priority: FeaturePriority;
23
- portal_scope: string[]; // Parsed from JSON
24
- created_at: string;
25
- updated_at: string;
26
- removed_at: string | null;
27
- removed_reason: string | null;
28
- }
29
-
30
- export interface FeatureInput {
31
- feature_key: string;
32
- domain: string;
33
- subdomain?: string;
34
- title: string;
35
- description?: string;
36
- status?: FeatureStatus;
37
- priority?: FeaturePriority;
38
- portal_scope?: string[];
39
- }
40
-
41
- export interface FeatureComponent {
42
- id: number;
43
- feature_id: number;
44
- component_file: string;
45
- component_name: string | null;
46
- role: ComponentRole;
47
- is_primary: boolean;
48
- }
49
-
50
- export interface FeatureProcedure {
51
- id: number;
52
- feature_id: number;
53
- router_name: string;
54
- procedure_name: string;
55
- procedure_type: string | null;
56
- }
57
-
58
- export interface FeaturePage {
59
- id: number;
60
- feature_id: number;
61
- page_route: string;
62
- portal: string | null;
63
- }
64
-
65
- export interface FeatureDep {
66
- id: number;
67
- feature_id: number;
68
- depends_on_feature_id: number;
69
- dependency_type: DependencyType;
70
- }
71
-
72
- export interface FeatureChangeLog {
73
- id: number;
74
- feature_id: number;
75
- change_type: ChangeType;
76
- changed_by: string | null;
77
- change_detail: string | null;
78
- commit_hash: string | null;
79
- created_at: string;
80
- }
81
-
82
- export interface FeatureWithCounts extends Feature {
83
- component_count: number;
84
- procedure_count: number;
85
- page_count: number;
86
- }
87
-
88
- export interface FeatureDetail extends Feature {
89
- components: FeatureComponent[];
90
- procedures: FeatureProcedure[];
91
- pages: FeaturePage[];
92
- dependencies: FeatureDep[];
93
- changelog: FeatureChangeLog[];
94
- }
95
-
96
- export interface ImpactItem {
97
- feature: Feature;
98
- affected_files: string[];
99
- remaining_files: string[];
100
- status: 'orphaned' | 'degraded' | 'unaffected';
101
- }
102
-
103
- export interface ImpactReport {
104
- files_analyzed: string[];
105
- orphaned: ImpactItem[];
106
- degraded: ImpactItem[];
107
- unaffected: ImpactItem[];
108
- blocked: boolean;
109
- block_reason: string | null;
110
- }
111
-
112
- export interface ValidationItem {
113
- feature: Feature;
114
- missing_components: string[];
115
- missing_procedures: { router: string; procedure: string }[];
116
- missing_pages: string[];
117
- status: 'alive' | 'orphaned' | 'degraded';
118
- }
119
-
120
- export interface ValidationReport {
121
- alive: number;
122
- orphaned: number;
123
- degraded: number;
124
- details: ValidationItem[];
125
- }
126
-
127
- export interface ParityItem {
128
- feature_key: string;
129
- title: string;
130
- status: 'DONE' | 'GAP' | 'NEW';
131
- old_files: string[];
132
- new_files: string[];
133
- }
134
-
135
- export interface ParityReport {
136
- done: ParityItem[];
137
- gaps: ParityItem[];
138
- new_features: ParityItem[];
139
- parity_percentage: number;
140
- }