@omfalos/mokosh 0.1.4 → 0.1.6

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.
@@ -0,0 +1,19 @@
1
+ // mokosh.config.js — auto-discovered by the mokosh CLI and MCP server (no flag needed).
2
+ // Note: the MCP server only loads mokosh.config.json (JS execution is disabled there for
3
+ // safety) — rename this to mokosh.config.json (stripping comments) if you need MCP to pick it up.
4
+ // Full field reference: https://github.com/Omfalos/mokosh/blob/main/docs/usage.md#configuration-file
5
+ module.exports = {
6
+ // entryPoints: ["src/index.ts"],
7
+ // ignoreDirs: ["vendor", "generated"],
8
+ // extensions: [".graphql"],
9
+ // cachePath: "mokosh-cache/graph.json",
10
+ // configMatchers: [],
11
+ // testPatterns: [],
12
+ // testLibraries: [],
13
+ // barrelThreshold: 0.8,
14
+ // gitStats: false,
15
+ // coverageReportPath: "coverage/coverage-summary.json",
16
+ // coverageThreshold: 80,
17
+ // tagApplier: { framework: "vitest" },
18
+ // parallelParsing: false, // disable the worker-pool parser (see docs/adr-010-parallel-parsing.md)
19
+ };
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: mokosh
3
+ description: Use when answering questions about this project's dependency graph — what a file imports or is imported by, blast radius / impact of a change, unused files, complexity hotspots, test coverage gaps, which tests to run after a diff, API surface, type usage, or monorepo package dependencies. Triggers on phrases like "what depends on", "blast radius", "affected tests", "unused files", "who calls", "circular dependency", "dependency graph".
4
+ ---
5
+
6
+ # mokosh — Dependency Graph Analysis
7
+
8
+ mokosh is a dependency-graph analysis tool for this project, available either as an MCP server or a CLI. Detect which is available and use that.
9
+
10
+ ## Which mode is active?
11
+
12
+ - **MCP available** — if tools named `mcp__mokosh__*` (e.g. `mcp__mokosh__analyze`, `mcp__mokosh__get_affected`) are visible in this session, use them directly. They return targeted results without loading the full graph into context.
13
+ - **MCP not available** — fall back to the CLI. Run `npx mokosh <entry-point> [flags]` (or bare `mokosh` if it's a project devDependency). Use `npx mokosh --help` and `npx mokosh --query-help` to see the full flag/filter reference.
14
+
15
+ Prefer MCP over the CLI whenever both are available — it's cheaper in tokens and doesn't require picking entry points manually. Only fall back to the CLI for full-graph visualizations (Mermaid diagrams) the user will read directly.
16
+
17
+ ## MCP: tool call order
18
+
19
+ `analyze` must be called once per session before any other tool (except `find_unused` and `query` with explicit `entryPoints`, which can build their own graph). It builds and caches the graph, keyed by `root`.
20
+
21
+ ```
22
+ analyze({ root: "<abs-path>", entryPoints: ["src/index.ts"] })
23
+ ```
24
+
25
+ Returns a one-line summary (node count, categories, cycles) — that's all you need from it.
26
+
27
+ For monorepos, pass `entryPoints: []` to auto-detect the workspace layout (Turborepo/Nx/pnpm/Yarn/npm) and build one graph per package — then use `get_workspace_packages` / `get_workspace_affected`.
28
+
29
+ If source files are edited mid-session, call `clear_cache({ root })` before re-querying — otherwise every tool reasons from the stale pre-edit graph.
30
+
31
+ ## Use case → tool (MCP) / flag (CLI)
32
+
33
+ ### Dependency traversal
34
+
35
+ | Goal | MCP call | CLI equivalent |
36
+ |------|----------|-----------------|
37
+ | What does file X import? | `get_dependencies({ root, file, depth: 1 })` | `mokosh <entry> --query "path:X"` then inspect `importsFiles` |
38
+ | Full transitive deps of X | `get_dependencies({ root, file })` | — |
39
+ | Who imports file X directly? | `get_dependents({ root, file })` | — |
40
+ | Full blast radius if X changes | `get_affected({ root, file })` | — |
41
+ | Blast radius, faster on repeat | `get_affected({ root, file, cached: true })` | — |
42
+ | Blast radius for specific symbols | `get_affected({ root, file, changedSymbols: [...] })` | — |
43
+ | Tests affected by X | `get_affected({ root, file, testsOnly: true })` | `mokosh --affected-tests <file>` |
44
+ | Who **calls into** X at runtime? | `get_callers({ root, file, depth: 1, withEdgeDetail: true })` | `mokosh --callers <file>` |
45
+ | Callers/callees of a named function | `get_call_graph({ root, function: "name" })` | TS/JS only |
46
+ | Unused files | `find_unused({ root, entryPoints: [...] })` | `mokosh --find-unused <entry>` |
47
+ | Circular dependencies | — | `mokosh <entry> --check-cycles` |
48
+
49
+ ### Quality signals
50
+
51
+ | Goal | MCP call | CLI equivalent |
52
+ |------|----------|-----------------|
53
+ | Undertested files | `find_uncovered({ root, coverageThreshold })` | `mokosh --find-uncovered <entry>` |
54
+ | Complexity hotspots | `find_complex_functions({ root, metric, threshold, limit })` | — |
55
+ | High-degree hubs / orchestrators | `detect_features({ root })` | `mokosh <entry> --detect-features` |
56
+ | What does each file own? | `get_module_responsibility({ root, paths? })` | — |
57
+ | Group files by owning feature | `get_feature_graph({ root, minOutDegree })` | — |
58
+
59
+ ### Types and API surface
60
+
61
+ | Goal | MCP call |
62
+ |------|----------|
63
+ | Inventory of all types | `get_type_graph({ root })` |
64
+ | Who uses type T? | `get_type_graph({ root, type: "TypeName" })` |
65
+ | Resolved public API of a library | `get_api_surface({ root, entryPoints? })` |
66
+
67
+ ### Monorepo
68
+
69
+ | Goal | MCP call |
70
+ |------|----------|
71
+ | List packages + inter-package deps | `get_workspace_packages({ root })` (requires prior `analyze({ root, entryPoints: [] })`) |
72
+ | Cross-package blast radius | `get_workspace_affected({ root, file })` |
73
+
74
+ ### Tags & CI
75
+
76
+ | Goal | MCP call | CLI equivalent |
77
+ |------|----------|-----------------|
78
+ | Tags to run after git diff | `propose_tags({ root })` | `mokosh --propose-tags <entry>` |
79
+ | Test paths after git diff | `propose_tags({ root, format: "paths" })` | — |
80
+ | Write `@tag` annotations into test files | `apply_tags({ root, dryRun? })` | — |
81
+
82
+ ### Ad-hoc graph queries
83
+
84
+ | Goal | MCP call | CLI equivalent |
85
+ |------|----------|-----------------|
86
+ | Filter graph by category/tag/etc. | `query({ root, filter: "category:logic" })` | `mokosh <entry> --query "category:logic"` |
87
+
88
+ ## Query filter reference
89
+
90
+ Use with `query({ root, filter: "..." })` via MCP or `--query "..."` via CLI. All keys are case-insensitive; multiple keys are AND'd together.
91
+
92
+ | Key | Example |
93
+ |-----|---------|
94
+ | `category` | `category:logic`, `category:!test` |
95
+ | `type` | `type:typescript`, `type:!css` |
96
+ | `tag` (OR/exclude) | `tag:auth`, `tag:!generated` |
97
+ | `tag` (AND) | `tag:auth+core` |
98
+ | `path` | `path:src/api`, `path:!__tests__` |
99
+ | `external` | `external:true` |
100
+ | `importsFile` | `importsFile:src/utils` |
101
+ | `importedBy` | `importedBy:src/index` |
102
+ | `minImports` / `maxImports` | `minImports:5`, `maxImports:2` |
103
+ | `minSize` / `maxSize` | `minSize:1024`, `maxSize:4096` |
104
+ | `hasDocstring` | `hasDocstring:false` |
105
+ | `minCoverage` / `maxCoverage` | `minCoverage:80`, `maxCoverage:50` |
106
+ | `minExportUsage` / `maxExportUsage` | `minExportUsage:0.5`, `maxExportUsage:0.1` |
107
+ | `sort` | `sort:imports`, `sort:size`, `sort:commitCount90d`, `sort:exportUsage` |
108
+ | `limit` | `limit:20` |
109
+
110
+ `category` values: `logic` · `ui` · `test` · `config` · `barrel` · `type-only` · `other`.
111
+
112
+ `query` (MCP) defaults to `slim: true` — compact nodes with flat `importsFiles`, export names, and meaningful tags only. Pass `slim: false` only when full edge metadata is needed.
113
+
114
+ Run `mokosh --query-help` (CLI) for the full reference at any time.
115
+
116
+ ## Reading results
117
+
118
+ - `get_affected` / `get_dependents` / `get_callers` return a flat list of paths — use it directly, don't re-read the graph.
119
+ - `analyze`'s one-line summary is enough to confirm the graph built.
120
+ - `tags` on nodes are `{ name, kind }` objects — match by `tag.name`.
121
+ - `exports` on nodes are `{ name, doc?, flags?, signature? }` objects.
122
+ - Call `clear_cache({ root })` (MCP) after editing files mid-session, before the next query.
@@ -0,0 +1,117 @@
1
+ # mokosh — Dependency Graph Analysis
2
+
3
+ mokosh is a dependency-graph analysis tool for this project, available either as an MCP server or a CLI. Detect which is available and use that.
4
+
5
+ ## Which mode is active?
6
+
7
+ - **MCP available** — if tools named `mcp__mokosh__*` (e.g. `mcp__mokosh__analyze`, `mcp__mokosh__get_affected`) are visible in this session, use them directly. They return targeted results without loading the full graph into context.
8
+ - **MCP not available** — fall back to the CLI. Run `npx mokosh <entry-point> [flags]` (or bare `mokosh` if it's a project devDependency). Use `npx mokosh --help` and `npx mokosh --query-help` to see the full flag/filter reference.
9
+
10
+ Prefer MCP over the CLI whenever both are available — it's cheaper in tokens and doesn't require picking entry points manually. Only fall back to the CLI for full-graph visualizations (Mermaid diagrams) the user will read directly.
11
+
12
+ ## MCP: tool call order
13
+
14
+ `analyze` must be called once per session before any other tool (except `find_unused` and `query` with explicit `entryPoints`, which can build their own graph). It builds and caches the graph, keyed by `root`.
15
+
16
+ ```
17
+ analyze({ root: "<abs-path>", entryPoints: ["src/index.ts"] })
18
+ ```
19
+
20
+ Returns a one-line summary (node count, categories, cycles) — that's all you need from it.
21
+
22
+ For monorepos, pass `entryPoints: []` to auto-detect the workspace layout (Turborepo/Nx/pnpm/Yarn/npm) and build one graph per package — then use `get_workspace_packages` / `get_workspace_affected`.
23
+
24
+ If source files are edited mid-session, call `clear_cache({ root })` before re-querying — otherwise every tool reasons from the stale pre-edit graph.
25
+
26
+ ## Use case → tool (MCP) / flag (CLI)
27
+
28
+ ### Dependency traversal
29
+
30
+ | Goal | MCP call | CLI equivalent |
31
+ |------|----------|-----------------|
32
+ | What does file X import? | `get_dependencies({ root, file, depth: 1 })` | `mokosh <entry> --query "path:X"` then inspect `importsFiles` |
33
+ | Full transitive deps of X | `get_dependencies({ root, file })` | — |
34
+ | Who imports file X directly? | `get_dependents({ root, file })` | — |
35
+ | Full blast radius if X changes | `get_affected({ root, file })` | — |
36
+ | Blast radius, faster on repeat | `get_affected({ root, file, cached: true })` | — |
37
+ | Blast radius for specific symbols | `get_affected({ root, file, changedSymbols: [...] })` | — |
38
+ | Tests affected by X | `get_affected({ root, file, testsOnly: true })` | `mokosh --affected-tests <file>` |
39
+ | Who **calls into** X at runtime? | `get_callers({ root, file, depth: 1, withEdgeDetail: true })` | `mokosh --callers <file>` |
40
+ | Callers/callees of a named function | `get_call_graph({ root, function: "name" })` | TS/JS only |
41
+ | Unused files | `find_unused({ root, entryPoints: [...] })` | `mokosh --find-unused <entry>` |
42
+ | Circular dependencies | — | `mokosh <entry> --check-cycles` |
43
+
44
+ ### Quality signals
45
+
46
+ | Goal | MCP call | CLI equivalent |
47
+ |------|----------|-----------------|
48
+ | Undertested files | `find_uncovered({ root, coverageThreshold })` | `mokosh --find-uncovered <entry>` |
49
+ | Complexity hotspots | `find_complex_functions({ root, metric, threshold, limit })` | — |
50
+ | High-degree hubs / orchestrators | `detect_features({ root })` | `mokosh <entry> --detect-features` |
51
+ | What does each file own? | `get_module_responsibility({ root, paths? })` | — |
52
+ | Group files by owning feature | `get_feature_graph({ root, minOutDegree })` | — |
53
+
54
+ ### Types and API surface
55
+
56
+ | Goal | MCP call |
57
+ |------|----------|
58
+ | Inventory of all types | `get_type_graph({ root })` |
59
+ | Who uses type T? | `get_type_graph({ root, type: "TypeName" })` |
60
+ | Resolved public API of a library | `get_api_surface({ root, entryPoints? })` |
61
+
62
+ ### Monorepo
63
+
64
+ | Goal | MCP call |
65
+ |------|----------|
66
+ | List packages + inter-package deps | `get_workspace_packages({ root })` (requires prior `analyze({ root, entryPoints: [] })`) |
67
+ | Cross-package blast radius | `get_workspace_affected({ root, file })` |
68
+
69
+ ### Tags & CI
70
+
71
+ | Goal | MCP call | CLI equivalent |
72
+ |------|----------|-----------------|
73
+ | Tags to run after git diff | `propose_tags({ root })` | `mokosh --propose-tags <entry>` |
74
+ | Test paths after git diff | `propose_tags({ root, format: "paths" })` | — |
75
+ | Write `@tag` annotations into test files | `apply_tags({ root, dryRun? })` | — |
76
+
77
+ ### Ad-hoc graph queries
78
+
79
+ | Goal | MCP call | CLI equivalent |
80
+ |------|----------|-----------------|
81
+ | Filter graph by category/tag/etc. | `query({ root, filter: "category:logic" })` | `mokosh <entry> --query "category:logic"` |
82
+
83
+ ## Query filter reference
84
+
85
+ Use with `query({ root, filter: "..." })` via MCP or `--query "..."` via CLI. All keys are case-insensitive; multiple keys are AND'd together.
86
+
87
+ | Key | Example |
88
+ |-----|---------|
89
+ | `category` | `category:logic`, `category:!test` |
90
+ | `type` | `type:typescript`, `type:!css` |
91
+ | `tag` (OR/exclude) | `tag:auth`, `tag:!generated` |
92
+ | `tag` (AND) | `tag:auth+core` |
93
+ | `path` | `path:src/api`, `path:!__tests__` |
94
+ | `external` | `external:true` |
95
+ | `importsFile` | `importsFile:src/utils` |
96
+ | `importedBy` | `importedBy:src/index` |
97
+ | `minImports` / `maxImports` | `minImports:5`, `maxImports:2` |
98
+ | `minSize` / `maxSize` | `minSize:1024`, `maxSize:4096` |
99
+ | `hasDocstring` | `hasDocstring:false` |
100
+ | `minCoverage` / `maxCoverage` | `minCoverage:80`, `maxCoverage:50` |
101
+ | `minExportUsage` / `maxExportUsage` | `minExportUsage:0.5`, `maxExportUsage:0.1` |
102
+ | `sort` | `sort:imports`, `sort:size`, `sort:commitCount90d`, `sort:exportUsage` |
103
+ | `limit` | `limit:20` |
104
+
105
+ `category` values: `logic` · `ui` · `test` · `config` · `barrel` · `type-only` · `other`.
106
+
107
+ `query` (MCP) defaults to `slim: true` — compact nodes with flat `importsFiles`, export names, and meaningful tags only. Pass `slim: false` only when full edge metadata is needed.
108
+
109
+ Run `mokosh --query-help` (CLI) for the full reference at any time.
110
+
111
+ ## Reading results
112
+
113
+ - `get_affected` / `get_dependents` / `get_callers` return a flat list of paths — use it directly, don't re-read the graph.
114
+ - `analyze`'s one-line summary is enough to confirm the graph built.
115
+ - `tags` on nodes are `{ name, kind }` objects — match by `tag.name`.
116
+ - `exports` on nodes are `{ name, doc?, flags?, signature? }` objects.
117
+ - Call `clear_cache({ root })` (MCP) after editing files mid-session, before the next query.