@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,348 +0,0 @@
1
- // Copyright (c) 2026 Massu. All rights reserved.
2
- // Licensed under BSL 1.1 - see LICENSE file for details.
3
-
4
- /**
5
- * Monorepo Detector (P1-004)
6
- * ==========================
7
- *
8
- * Detects the presence and kind of monorepo layout at `projectRoot`:
9
- * - turbo (turbo.json)
10
- * - nx (nx.json)
11
- * - lerna (lerna.json)
12
- * - pnpm (pnpm-workspace.yaml)
13
- * - yarn (package.json `workspaces`)
14
- * - bazel (WORKSPACE / WORKSPACE.bazel / MODULE.bazel)
15
- * - generic (any of apps/*, packages/*, services/*, libs/*, modules/*
16
- * subdirs with their own manifests)
17
- * - single (no monorepo signals)
18
- *
19
- * Nested schemes: when the outer has a primary manager AND an inner scheme is
20
- * present (e.g., turbo-outer + pnpm-inner), `nested[]` lists the inner scheme.
21
- *
22
- * Usage:
23
- * ```ts
24
- * import { detectMonorepo } from './detect/monorepo-detector.ts';
25
- * const info = detectMonorepo('/repo');
26
- * ```
27
- */
28
-
29
- import { readFileSync, existsSync, statSync, lstatSync, readdirSync } from 'fs';
30
- import { join, relative } from 'path';
31
- import { parse as parseYaml } from 'yaml';
32
- import { parse as parseToml } from 'smol-toml';
33
-
34
- export type MonorepoKind =
35
- | 'turbo'
36
- | 'nx'
37
- | 'lerna'
38
- | 'pnpm'
39
- | 'yarn'
40
- | 'bazel'
41
- | 'generic'
42
- | 'single';
43
-
44
- export interface WorkspacePackage {
45
- /** Path relative to projectRoot, forward-slash normalized. */
46
- path: string;
47
- /** Name from the manifest (null if not present). */
48
- name: string | null;
49
- /** The manifest file that declares the workspace. */
50
- manifest:
51
- | 'package.json'
52
- | 'pyproject.toml'
53
- | 'Cargo.toml'
54
- | 'go.mod'
55
- | 'build.gradle'
56
- | 'pom.xml'
57
- | 'Gemfile'
58
- | 'Package.swift'
59
- | 'unknown';
60
- }
61
-
62
- export interface MonorepoInfo {
63
- type: MonorepoKind;
64
- /** Workspace packages discovered. Empty for 'single'. */
65
- packages: WorkspacePackage[];
66
- /** Secondary monorepo schemes nested inside the primary. */
67
- nested: MonorepoInfo[];
68
- }
69
-
70
- const MANIFEST_PRIORITY: WorkspacePackage['manifest'][] = [
71
- 'package.json',
72
- 'pyproject.toml',
73
- 'Cargo.toml',
74
- 'go.mod',
75
- 'build.gradle',
76
- 'pom.xml',
77
- 'Gemfile',
78
- 'Package.swift',
79
- ];
80
-
81
- const IGNORED_DIRS = new Set([
82
- 'node_modules',
83
- '.venv',
84
- 'venv',
85
- '__pycache__',
86
- 'dist',
87
- 'build',
88
- '.build',
89
- 'target',
90
- '.next',
91
- '.nuxt',
92
- 'coverage',
93
- '.git',
94
- '.massu',
95
- '.turbo',
96
- '.cache',
97
- ]);
98
-
99
- const CONVENTIONAL_WORKSPACE_PARENTS = [
100
- 'apps',
101
- 'packages',
102
- 'services',
103
- 'libs',
104
- 'modules',
105
- ];
106
-
107
- function safeReadText(path: string): string | null {
108
- try {
109
- if (!existsSync(path)) return null;
110
- // Reject symlinks — defence in depth against manifest-forged escape paths
111
- // or credential exposure via symlinked files (parity with package-detector.ts).
112
- // lstatSync does NOT follow symlinks; statSync would return the target's stat.
113
- const ls = lstatSync(path);
114
- if (ls.isSymbolicLink()) return null;
115
- const st = statSync(path);
116
- if (!st.isFile()) return null;
117
- return readFileSync(path, 'utf-8');
118
- } catch {
119
- return null;
120
- }
121
- }
122
-
123
- function firstManifestIn(dir: string): WorkspacePackage['manifest'] | null {
124
- for (const m of MANIFEST_PRIORITY) {
125
- if (existsSync(join(dir, m))) return m;
126
- }
127
- return null;
128
- }
129
-
130
- function manifestName(dir: string, manifest: WorkspacePackage['manifest']): string | null {
131
- try {
132
- if (manifest === 'package.json') {
133
- const raw = safeReadText(join(dir, 'package.json'));
134
- if (!raw) return null;
135
- const pkg = JSON.parse(raw) as { name?: unknown };
136
- return typeof pkg.name === 'string' ? pkg.name : null;
137
- }
138
- if (manifest === 'pyproject.toml') {
139
- const raw = safeReadText(join(dir, 'pyproject.toml'));
140
- if (!raw) return null;
141
- const toml = parseToml(raw) as Record<string, unknown>;
142
- const project = toml.project as Record<string, unknown> | undefined;
143
- if (project && typeof project.name === 'string') return project.name;
144
- const tool = toml.tool as Record<string, unknown> | undefined;
145
- const poetry = tool?.poetry as Record<string, unknown> | undefined;
146
- if (poetry && typeof poetry.name === 'string') return poetry.name;
147
- return null;
148
- }
149
- if (manifest === 'Cargo.toml') {
150
- const raw = safeReadText(join(dir, 'Cargo.toml'));
151
- if (!raw) return null;
152
- const toml = parseToml(raw) as Record<string, unknown>;
153
- const pkg = toml.package as Record<string, unknown> | undefined;
154
- if (pkg && typeof pkg.name === 'string') return pkg.name;
155
- return null;
156
- }
157
- if (manifest === 'go.mod') {
158
- const raw = safeReadText(join(dir, 'go.mod'));
159
- if (!raw) return null;
160
- for (const line of raw.split(/\r?\n/)) {
161
- const trimmed = line.trim();
162
- if (trimmed.startsWith('module ')) return trimmed.slice(7).trim();
163
- }
164
- return null;
165
- }
166
- return null;
167
- } catch {
168
- return null;
169
- }
170
- }
171
-
172
- function pkgFromDir(root: string, dir: string): WorkspacePackage | null {
173
- const m = firstManifestIn(dir);
174
- if (!m) return null;
175
- return {
176
- path: relative(root, dir).split(/[/\\]/).join('/'),
177
- name: manifestName(dir, m),
178
- manifest: m,
179
- };
180
- }
181
-
182
- function listSubdirs(dir: string): string[] {
183
- try {
184
- return readdirSync(dir, { withFileTypes: true })
185
- .filter((e) => e.isDirectory() && !IGNORED_DIRS.has(e.name))
186
- .map((e) => join(dir, e.name));
187
- } catch {
188
- return [];
189
- }
190
- }
191
-
192
- /**
193
- * Collect generic conventional workspaces (any manifested package under
194
- * apps/*, packages/*, services/*, libs/*, modules/*).
195
- */
196
- function genericWorkspaces(root: string): WorkspacePackage[] {
197
- const out: WorkspacePackage[] = [];
198
- for (const parent of CONVENTIONAL_WORKSPACE_PARENTS) {
199
- const p = join(root, parent);
200
- if (!existsSync(p)) continue;
201
- for (const sub of listSubdirs(p)) {
202
- const pkg = pkgFromDir(root, sub);
203
- if (pkg) out.push(pkg);
204
- }
205
- }
206
- return out;
207
- }
208
-
209
- function detectYarnWorkspaces(root: string): WorkspacePackage[] | null {
210
- const raw = safeReadText(join(root, 'package.json'));
211
- if (!raw) return null;
212
- let pkg: { workspaces?: unknown };
213
- try {
214
- pkg = JSON.parse(raw) as { workspaces?: unknown };
215
- } catch {
216
- return null;
217
- }
218
- const ws = pkg.workspaces;
219
- if (!ws) return null;
220
- // Can be array of strings OR { packages: [...] }
221
- const globs: string[] = Array.isArray(ws)
222
- ? (ws.filter((x) => typeof x === 'string') as string[])
223
- : typeof ws === 'object' && ws !== null &&
224
- Array.isArray((ws as { packages?: unknown }).packages)
225
- ? (((ws as { packages: unknown[] }).packages).filter((x) => typeof x === 'string') as string[])
226
- : [];
227
- if (globs.length === 0) return null;
228
- return expandWorkspaceGlobs(root, globs);
229
- }
230
-
231
- function detectPnpmWorkspaces(root: string): WorkspacePackage[] | null {
232
- const raw = safeReadText(join(root, 'pnpm-workspace.yaml'));
233
- if (!raw) return null;
234
- try {
235
- // pattern-scanner-allow: yaml-parse — reason: Phase 1 auto-detection parses pnpm-workspace.yaml to discover workspace packages BEFORE any massu config exists. This runs PRE-getConfig in the init flow, so getConfig() is unavailable by definition.
236
- const parsed = parseYaml(raw) as { packages?: unknown } | null;
237
- const list = Array.isArray(parsed?.packages)
238
- ? (parsed!.packages as unknown[]).filter((x) => typeof x === 'string') as string[]
239
- : [];
240
- return expandWorkspaceGlobs(root, list);
241
- } catch {
242
- return null;
243
- }
244
- }
245
-
246
- function expandWorkspaceGlobs(root: string, globs: string[]): WorkspacePackage[] {
247
- // Minimal brace/star expansion: support `foo/*` and `foo/**` by one level only.
248
- // For simplicity and no-dep, expand each pattern manually.
249
- const out: WorkspacePackage[] = [];
250
- const seen = new Set<string>();
251
- for (const pattern of globs) {
252
- // Handle `apps/*`, `packages/*`, `services/*`, `apps/**`
253
- const parts = pattern.split('/');
254
- if (parts.length === 2 && (parts[1] === '*' || parts[1] === '**')) {
255
- const parent = join(root, parts[0]);
256
- if (!existsSync(parent)) continue;
257
- for (const sub of listSubdirs(parent)) {
258
- const pkg = pkgFromDir(root, sub);
259
- if (pkg && !seen.has(pkg.path)) {
260
- seen.add(pkg.path);
261
- out.push(pkg);
262
- }
263
- }
264
- continue;
265
- }
266
- // Direct path (no glob)
267
- const direct = join(root, pattern);
268
- if (existsSync(direct)) {
269
- const pkg = pkgFromDir(root, direct);
270
- if (pkg && !seen.has(pkg.path)) {
271
- seen.add(pkg.path);
272
- out.push(pkg);
273
- }
274
- }
275
- }
276
- return out;
277
- }
278
-
279
- function hasTurbo(root: string): boolean {
280
- return existsSync(join(root, 'turbo.json'));
281
- }
282
- function hasNx(root: string): boolean {
283
- return existsSync(join(root, 'nx.json'));
284
- }
285
- function hasLerna(root: string): boolean {
286
- return existsSync(join(root, 'lerna.json'));
287
- }
288
- function hasBazel(root: string): boolean {
289
- return (
290
- existsSync(join(root, 'WORKSPACE')) ||
291
- existsSync(join(root, 'WORKSPACE.bazel')) ||
292
- existsSync(join(root, 'MODULE.bazel'))
293
- );
294
- }
295
-
296
- /**
297
- * Detect the monorepo layout (or lack thereof) at `projectRoot`.
298
- */
299
- export function detectMonorepo(projectRoot: string): MonorepoInfo {
300
- const nested: MonorepoInfo[] = [];
301
-
302
- const pnpm = detectPnpmWorkspaces(projectRoot);
303
- const yarn = detectYarnWorkspaces(projectRoot);
304
-
305
- // Determine primary by priority: turbo > nx > lerna > pnpm > yarn > bazel > generic > single
306
- let primary: MonorepoKind = 'single';
307
- let primaryPackages: WorkspacePackage[] = [];
308
-
309
- if (hasTurbo(projectRoot)) {
310
- primary = 'turbo';
311
- // Turbo reuses an underlying manager's workspaces list.
312
- primaryPackages = pnpm ?? yarn ?? genericWorkspaces(projectRoot);
313
- // Record nested inner scheme (the actual workspace manager)
314
- if (pnpm && pnpm.length) {
315
- nested.push({ type: 'pnpm', packages: pnpm, nested: [] });
316
- } else if (yarn && yarn.length) {
317
- nested.push({ type: 'yarn', packages: yarn, nested: [] });
318
- }
319
- } else if (hasNx(projectRoot)) {
320
- primary = 'nx';
321
- primaryPackages = yarn ?? pnpm ?? genericWorkspaces(projectRoot);
322
- if (pnpm && pnpm.length) nested.push({ type: 'pnpm', packages: pnpm, nested: [] });
323
- else if (yarn && yarn.length) nested.push({ type: 'yarn', packages: yarn, nested: [] });
324
- } else if (hasLerna(projectRoot)) {
325
- primary = 'lerna';
326
- primaryPackages = yarn ?? pnpm ?? genericWorkspaces(projectRoot);
327
- } else if (pnpm && pnpm.length) {
328
- primary = 'pnpm';
329
- primaryPackages = pnpm;
330
- } else if (yarn && yarn.length) {
331
- primary = 'yarn';
332
- primaryPackages = yarn;
333
- } else if (hasBazel(projectRoot)) {
334
- primary = 'bazel';
335
- primaryPackages = genericWorkspaces(projectRoot);
336
- } else {
337
- const gen = genericWorkspaces(projectRoot);
338
- if (gen.length > 0) {
339
- primary = 'generic';
340
- primaryPackages = gen;
341
- } else {
342
- primary = 'single';
343
- primaryPackages = [];
344
- }
345
- }
346
-
347
- return { type: primary, packages: primaryPackages, nested };
348
- }