@abhinav2203/codeflow-analysis 0.1.0 → 0.1.2

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 (98) hide show
  1. package/dist/app/api/analysis/cycles/route.test.d.ts +2 -0
  2. package/dist/app/api/analysis/cycles/route.test.d.ts.map +1 -0
  3. package/dist/app/api/analysis/cycles/route.test.js +92 -0
  4. package/dist/app/api/analysis/metrics/route.test.d.ts +2 -0
  5. package/dist/app/api/analysis/metrics/route.test.d.ts.map +1 -0
  6. package/dist/app/api/analysis/metrics/route.test.js +82 -0
  7. package/dist/app/api/analysis/smells/route.test.d.ts +2 -0
  8. package/dist/app/api/analysis/smells/route.test.d.ts.map +1 -0
  9. package/dist/app/api/analysis/smells/route.test.js +102 -0
  10. package/dist/app/api/conflicts/route.test.d.ts +2 -0
  11. package/dist/app/api/conflicts/route.test.d.ts.map +1 -0
  12. package/dist/app/api/conflicts/route.test.js +58 -0
  13. package/dist/app/api/refactor/detect/route.test.d.ts +2 -0
  14. package/dist/app/api/refactor/detect/route.test.d.ts.map +1 -0
  15. package/dist/app/api/refactor/detect/route.test.js +61 -0
  16. package/dist/app/api/refactor/heal/route.test.d.ts +2 -0
  17. package/dist/app/api/refactor/heal/route.test.d.ts.map +1 -0
  18. package/dist/app/api/refactor/heal/route.test.js +62 -0
  19. package/dist/bin/cli.js +5 -41
  20. package/dist/conflicts.d.ts +12 -0
  21. package/dist/conflicts.d.ts.map +1 -0
  22. package/dist/conflicts.js +77 -0
  23. package/dist/conflicts.test.d.ts +2 -0
  24. package/dist/conflicts.test.d.ts.map +1 -0
  25. package/dist/conflicts.test.js +98 -0
  26. package/dist/cycles.d.ts +109 -0
  27. package/dist/cycles.d.ts.map +1 -0
  28. package/dist/cycles.js +129 -0
  29. package/dist/cycles.test.d.ts +2 -0
  30. package/dist/cycles.test.d.ts.map +1 -0
  31. package/dist/cycles.test.js +82 -0
  32. package/dist/handlers/conflicts.d.ts +28 -0
  33. package/dist/handlers/conflicts.d.ts.map +1 -0
  34. package/dist/handlers/conflicts.js +24 -0
  35. package/dist/handlers/cycles.d.ts +30 -0
  36. package/dist/handlers/cycles.d.ts.map +1 -0
  37. package/dist/handlers/cycles.js +24 -0
  38. package/dist/handlers/metrics.d.ts +35 -0
  39. package/dist/handlers/metrics.d.ts.map +1 -0
  40. package/dist/handlers/metrics.js +23 -0
  41. package/dist/handlers/refactor-detect.d.ts +15 -0
  42. package/dist/handlers/refactor-detect.d.ts.map +1 -0
  43. package/dist/handlers/refactor-detect.js +23 -0
  44. package/dist/handlers/refactor-heal.d.ts +19 -0
  45. package/dist/handlers/refactor-heal.d.ts.map +1 -0
  46. package/dist/handlers/refactor-heal.js +27 -0
  47. package/dist/handlers/smells.d.ts +27 -0
  48. package/dist/handlers/smells.d.ts.map +1 -0
  49. package/dist/handlers/smells.js +24 -0
  50. package/dist/index.d.ts +10 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +10 -0
  53. package/dist/invoke.d.ts +3 -0
  54. package/dist/invoke.d.ts.map +1 -0
  55. package/dist/invoke.js +162 -0
  56. package/dist/metrics.d.ts +73 -0
  57. package/dist/metrics.d.ts.map +1 -0
  58. package/dist/metrics.js +159 -0
  59. package/dist/metrics.test.d.ts +2 -0
  60. package/dist/metrics.test.d.ts.map +1 -0
  61. package/dist/metrics.test.js +98 -0
  62. package/dist/refactor.d.ts +84 -0
  63. package/dist/refactor.d.ts.map +1 -0
  64. package/dist/refactor.js +183 -0
  65. package/dist/refactor.test.d.ts +2 -0
  66. package/dist/refactor.test.d.ts.map +1 -0
  67. package/dist/refactor.test.js +269 -0
  68. package/dist/smells.d.ts +77 -0
  69. package/dist/smells.d.ts.map +1 -0
  70. package/dist/smells.js +186 -0
  71. package/dist/smells.test.d.ts +2 -0
  72. package/dist/smells.test.d.ts.map +1 -0
  73. package/dist/smells.test.js +120 -0
  74. package/package.json +3 -3
  75. package/src/app/api/analysis/cycles/route.test.ts +2 -2
  76. package/src/app/api/analysis/metrics/route.test.ts +2 -2
  77. package/src/app/api/analysis/smells/route.test.ts +7 -7
  78. package/src/app/api/conflicts/route.test.ts +2 -2
  79. package/src/app/api/refactor/detect/route.test.ts +2 -2
  80. package/src/app/api/refactor/heal/route.test.ts +2 -2
  81. package/src/conflicts.test.ts +2 -2
  82. package/src/conflicts.ts +2 -2
  83. package/src/cycles.test.ts +2 -2
  84. package/src/cycles.ts +1 -1
  85. package/src/handlers/conflicts.ts +1 -1
  86. package/src/handlers/cycles.ts +1 -1
  87. package/src/handlers/metrics.ts +1 -1
  88. package/src/handlers/refactor-detect.ts +1 -1
  89. package/src/handlers/refactor-heal.ts +1 -1
  90. package/src/handlers/smells.ts +1 -1
  91. package/src/invoke.ts +116 -113
  92. package/src/metrics.test.ts +3 -3
  93. package/src/metrics.ts +1 -1
  94. package/src/refactor.test.ts +4 -4
  95. package/src/refactor.ts +1 -1
  96. package/src/smells.test.ts +7 -7
  97. package/src/smells.ts +1 -1
  98. package/vitest.config.ts +0 -8
package/src/invoke.ts CHANGED
@@ -8,102 +8,62 @@ import { detectSmells } from "./smells.js";
8
8
  import { computeGraphMetrics } from "./metrics.js";
9
9
  import { detectDrift, healGraph } from "./refactor.js";
10
10
  import { detectGraphConflicts } from "./conflicts.js";
11
- import { blueprintGraphSchema } from "@/lib/blueprint/schema";
11
+ import { blueprintGraphSchema } from "@abhinav2203/codeflow-core/schema";
12
12
 
13
13
  // ── CLI ─────────────────────────────────────────────────────────────────────
14
14
 
15
- const [command, ...args] = process.argv.slice(2);
15
+ export const runCLI = async () => {
16
+ const [command, ...args] = process.argv.slice(2);
16
17
 
17
- const readBlueprint = (arg: string): ReturnType<typeof readFileSync> => {
18
- const filePath = resolve(arg);
19
- return readFileSync(filePath, "utf-8");
20
- };
21
-
22
- const parseBlueprint = (content: string) => {
23
- return blueprintGraphSchema.parse(JSON.parse(content));
24
- };
18
+ const readBlueprint = (arg: string): string => {
19
+ const filePath = resolve(arg);
20
+ return readFileSync(filePath, "utf-8");
21
+ };
25
22
 
26
- const printJson = (data: unknown) => {
27
- console.log(JSON.stringify(data, null, 2));
28
- };
23
+ const parseBlueprint = (content: string) => blueprintGraphSchema.parse(JSON.parse(content));
29
24
 
30
- const exit = (code: number, message?: string) => {
31
- if (message) console.error(message);
32
- process.exit(code);
33
- };
25
+ const printJson = (data: unknown) => {
26
+ console.log(JSON.stringify(data, null, 2));
27
+ };
34
28
 
35
- const MISSING_ARG = (cmd: string) =>
36
- `codeflow-analysis ${cmd}: missing required argument <blueprint-path>`;
29
+ const exit = (code: number, message?: string) => {
30
+ if (message) console.error(message);
31
+ process.exit(code);
32
+ };
37
33
 
38
- const UNREADABLE = (path: string) =>
39
- `codeflow-analysis: could not read file "${path}"`;
34
+ const MISSING_ARG = (cmd: string) =>
35
+ `codeflow-analysis ${cmd}: missing required argument <blueprint-path>`;
40
36
 
41
- const INVALID_BLUEPRINT = (path: string, error: unknown) =>
42
- `codeflow-analysis: invalid blueprint at "${path}": ${error instanceof Error ? error.message : error}`;
37
+ const UNREADABLE = (path: string) =>
38
+ `codeflow-analysis: could not read file "${path}"`;
43
39
 
44
- try {
45
- switch (command) {
46
- // ── cycles ────────────────────────────────────────────────────────────────
47
- case "cycles": {
48
- const [blueprintPath] = args;
49
- if (!blueprintPath) exit(1, MISSING_ARG("cycles"));
40
+ const INVALID_BLUEPRINT = (path: string, error: unknown) =>
41
+ `codeflow-analysis: invalid blueprint at "${path}": ${error instanceof Error ? error.message : error}`;
50
42
 
51
- let graph;
52
- try {
53
- graph = parseBlueprint(readBlueprint(blueprintPath));
54
- } catch (e: unknown) {
55
- if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
56
- exit(1, INVALID_BLUEPRINT(blueprintPath, e));
57
- }
43
+ try {
44
+ switch (command) {
45
+ // ── cycles ────────────────────────────────────────────────────────────────
46
+ case "cycles": {
47
+ const [blueprintPath] = args;
48
+ if (!blueprintPath) exit(1, MISSING_ARG("cycles"));
58
49
 
59
- const report = detectCycles(graph);
60
- printJson({ report, hasCycles: hasCycles(graph) });
61
- break;
62
- }
63
-
64
- // ── smells ───────────────────────────────────────────────────────────────
65
- case "smells": {
66
- const [blueprintPath] = args;
67
- if (!blueprintPath) exit(1, MISSING_ARG("smells"));
68
-
69
- let graph;
70
- try {
71
- graph = parseBlueprint(readBlueprint(blueprintPath));
72
- } catch (e: unknown) {
73
- if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
74
- exit(1, INVALID_BLUEPRINT(blueprintPath, e));
75
- }
76
-
77
- const report = detectSmells(graph);
78
- printJson({ report });
79
- break;
80
- }
50
+ let graph;
51
+ try {
52
+ graph = parseBlueprint(readBlueprint(blueprintPath));
53
+ } catch (e: unknown) {
54
+ if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
55
+ exit(1, INVALID_BLUEPRINT(blueprintPath, e));
56
+ }
81
57
 
82
- // ── metrics ─────────────────────────────────────────────────────────────
83
- case "metrics": {
84
- const [blueprintPath] = args;
85
- if (!blueprintPath) exit(1, MISSING_ARG("metrics"));
86
-
87
- let graph;
88
- try {
89
- graph = parseBlueprint(readBlueprint(blueprintPath));
90
- } catch (e: unknown) {
91
- if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
92
- exit(1, INVALID_BLUEPRINT(blueprintPath, e));
58
+ const report = detectCycles(graph as Parameters<typeof detectCycles>[0]);
59
+ printJson({ report, hasCycles: hasCycles(graph as Parameters<typeof hasCycles>[0]) });
60
+ break;
93
61
  }
94
62
 
95
- const metrics = computeGraphMetrics(graph);
96
- printJson({ metrics });
97
- break;
98
- }
99
-
100
- // ── refactor detect ──────────────────────────────────────────────────────
101
- case "refactor": {
102
- const sub = args[0];
103
- const [blueprintPath] = args.slice(1);
104
-
105
- if (sub === "detect") {
106
- if (!blueprintPath) exit(1, MISSING_ARG("refactor detect"));
63
+ // ── smells ───────────────────────────────────────────────────────────────
64
+ case "smells": {
65
+ const [blueprintPath] = args;
66
+ if (!blueprintPath) exit(1, MISSING_ARG("smells"));
107
67
 
108
68
  let graph;
109
69
  try {
@@ -113,13 +73,15 @@ try {
113
73
  exit(1, INVALID_BLUEPRINT(blueprintPath, e));
114
74
  }
115
75
 
116
- const report = detectDrift(graph);
76
+ const report = detectSmells(graph as Parameters<typeof detectSmells>[0]);
117
77
  printJson({ report });
118
78
  break;
119
79
  }
120
80
 
121
- if (sub === "heal") {
122
- if (!blueprintPath) exit(1, MISSING_ARG("refactor heal"));
81
+ // ── metrics ─────────────────────────────────────────────────────────────
82
+ case "metrics": {
83
+ const [blueprintPath] = args;
84
+ if (!blueprintPath) exit(1, MISSING_ARG("metrics"));
123
85
 
124
86
  let graph;
125
87
  try {
@@ -129,37 +91,74 @@ try {
129
91
  exit(1, INVALID_BLUEPRINT(blueprintPath, e));
130
92
  }
131
93
 
132
- const report = detectDrift(graph);
133
- const result = healGraph(graph, report);
134
- printJson({ report, result });
94
+ const metrics = computeGraphMetrics(graph as Parameters<typeof computeGraphMetrics>[0]);
95
+ printJson({ metrics });
135
96
  break;
136
97
  }
137
98
 
138
- exit(1, `codeflow-analysis refactor: unknown subcommand "${sub}". Use "detect" or "heal".`);
139
- break;
140
- }
99
+ // ── refactor detect ──────────────────────────────────────────────────────
100
+ case "refactor": {
101
+ const sub = args[0];
102
+ const [blueprintPath] = args.slice(1);
103
+
104
+ if (sub === "detect") {
105
+ if (!blueprintPath) exit(1, MISSING_ARG("refactor detect"));
106
+
107
+ let graph;
108
+ try {
109
+ graph = parseBlueprint(readBlueprint(blueprintPath));
110
+ } catch (e: unknown) {
111
+ if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
112
+ exit(1, INVALID_BLUEPRINT(blueprintPath, e));
113
+ }
114
+
115
+ const report = detectDrift(graph as Parameters<typeof detectDrift>[0]);
116
+ printJson({ report });
117
+ break;
118
+ }
119
+
120
+ if (sub === "heal") {
121
+ if (!blueprintPath) exit(1, MISSING_ARG("refactor heal"));
122
+
123
+ let graph;
124
+ try {
125
+ graph = parseBlueprint(readBlueprint(blueprintPath));
126
+ } catch (e: unknown) {
127
+ if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
128
+ exit(1, INVALID_BLUEPRINT(blueprintPath, e));
129
+ }
130
+
131
+ const report = detectDrift(graph as Parameters<typeof detectDrift>[0]);
132
+ const result = healGraph(graph as Parameters<typeof healGraph>[0], report);
133
+ printJson({ report, result });
134
+ break;
135
+ }
141
136
 
142
- // ── conflicts ────────────────────────────────────────────────────────────
143
- case "conflicts": {
144
- const [blueprintPath, repoPath] = args;
145
- if (!blueprintPath) exit(1, MISSING_ARG("conflicts"));
146
-
147
- let graph;
148
- try {
149
- graph = parseBlueprint(readBlueprint(blueprintPath));
150
- } catch (e: unknown) {
151
- if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
152
- exit(1, INVALID_BLUEPRINT(blueprintPath, e));
137
+ exit(1, `codeflow-analysis refactor: unknown subcommand "${sub}". Use "detect" or "heal".`);
138
+ break;
153
139
  }
154
140
 
155
- const resolvedRepoPath = repoPath ?? process.cwd();
156
- const report = await detectGraphConflicts(graph, resolvedRepoPath);
157
- printJson({ report });
158
- break;
159
- }
141
+ // ── conflicts ────────────────────────────────────────────────────────────
142
+ case "conflicts": {
143
+ const [blueprintPath, repoPath] = args;
144
+ if (!blueprintPath) exit(1, MISSING_ARG("conflicts"));
160
145
 
161
- case undefined:
162
- exit(1, `codeflow-analysis: missing command. Usage:
146
+ let graph;
147
+ try {
148
+ graph = parseBlueprint(readBlueprint(blueprintPath));
149
+ } catch (e: unknown) {
150
+ if ((e as NodeJS.ErrnoException).code === "ENOENT") exit(1, UNREADABLE(blueprintPath));
151
+ exit(1, INVALID_BLUEPRINT(blueprintPath, e));
152
+ }
153
+
154
+ const resolvedRepoPath = repoPath ?? process.cwd();
155
+ const report = await detectGraphConflicts(graph as Parameters<typeof detectGraphConflicts>[0], resolvedRepoPath);
156
+ printJson({ report });
157
+ break;
158
+ }
159
+
160
+ case undefined:
161
+ exit(1, `codeflow-analysis: missing command. Usage:
163
162
 
164
163
  codeflow-analysis cycles <blueprint-path>
165
164
  codeflow-analysis smells <blueprint-path>
@@ -168,9 +167,13 @@ try {
168
167
  codeflow-analysis refactor heal <blueprint-path>
169
168
  codeflow-analysis conflicts <blueprint-path> [repo-path]`);
170
169
 
171
- default:
172
- exit(1, `codeflow-analysis: unknown command "${command}". Use cycles, smells, metrics, refactor, or conflicts.`);
170
+ default:
171
+ exit(1, `codeflow-analysis: unknown command "${command}". Use cycles, smells, metrics, refactor, or conflicts.`);
172
+ }
173
+ } catch (error) {
174
+ exit(1, `codeflow-analysis: unexpected error: ${error instanceof Error ? error.message : error}`);
173
175
  }
174
- } catch (error) {
175
- exit(1, `codeflow-analysis: unexpected error: ${error instanceof Error ? error.message : error}`);
176
- }
176
+ };
177
+
178
+ // Run when executed directly
179
+ runCLI();
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
3
  import { computeGraphMetrics } from "./metrics";
4
- import type { BlueprintGraph } from "@/lib/blueprint/schema";
5
- import { emptyContract } from "@/lib/blueprint/schema";
4
+ import type { BlueprintGraph, BlueprintEdge } from "@abhinav2203/codeflow-core/schema";
5
+ import { emptyContract } from "@abhinav2203/codeflow-core/schema";
6
6
 
7
7
  const node = (id: string, kind: BlueprintGraph["nodes"][number]["kind"] = "function"): BlueprintGraph["nodes"][number] => ({
8
8
  id,
@@ -15,7 +15,7 @@ const node = (id: string, kind: BlueprintGraph["nodes"][number]["kind"] = "funct
15
15
  traceRefs: [],
16
16
  });
17
17
 
18
- const edge = (from: string, to: string, kind = "calls"): BlueprintGraph["edges"][number] => ({
18
+ const edge = (from: string, to: string, kind: BlueprintEdge["kind"] = "calls"): BlueprintGraph["edges"][number] => ({
19
19
  from,
20
20
  to,
21
21
  kind,
package/src/metrics.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
 
3
- import type { BlueprintGraph } from "@/lib/blueprint/schema";
3
+ import type { BlueprintGraph } from "@abhinav2203/codeflow-core/schema";
4
4
 
5
5
  export const graphMetricsSchema = z.object({
6
6
  analyzedAt: z.string(),
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
3
  import { detectDrift, healGraph } from "./refactor";
4
- import type { BlueprintEdge, BlueprintGraph } from "@/lib/blueprint/schema";
5
- import { emptyContract } from "@/lib/blueprint/schema";
4
+ import type { BlueprintEdge, BlueprintGraph, DesignCall } from "@abhinav2203/codeflow-core/schema";
5
+ import { emptyContract } from "@abhinav2203/codeflow-core/schema";
6
6
 
7
7
  // ── Fixtures ───────────────────────────────────────────────────────────────
8
8
 
@@ -29,7 +29,7 @@ const makeNode = (
29
29
  inputs: [] as { name: string; type: string; description?: string }[],
30
30
  outputs: [] as { name: string; type: string; description?: string }[],
31
31
  sideEffects: [] as string[],
32
- calls: [] as { target: string; kind?: string; description?: string }[],
32
+ calls: [] as DesignCall[],
33
33
  },
34
34
  ]
35
35
  : [];
@@ -51,7 +51,7 @@ const makeNode = (
51
51
  };
52
52
  };
53
53
 
54
- const edge = (from: string, to: string, kind = "calls"): BlueprintEdge => ({
54
+ const edge = (from: string, to: string, kind: BlueprintEdge["kind"] = "calls"): BlueprintEdge => ({
55
55
  from,
56
56
  to,
57
57
  kind,
package/src/refactor.ts CHANGED
@@ -5,7 +5,7 @@ import type {
5
5
  BlueprintNode,
6
6
  FeatureMaturity,
7
7
  OutputProvenance,
8
- } from "@/lib/blueprint/schema";
8
+ } from "@abhinav2203/codeflow-core/schema";
9
9
 
10
10
  // ── Types ─────────────────────────────────────────────────────────────────────
11
11
 
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
3
  import { detectSmells } from "./smells";
4
- import type { BlueprintGraph } from "@/lib/blueprint/schema";
5
- import { emptyContract } from "@/lib/blueprint/schema";
4
+ import type { BlueprintGraph, MethodSpec } from "@abhinav2203/codeflow-core/schema";
5
+ import { emptyContract } from "@abhinav2203/codeflow-core/schema";
6
6
 
7
7
  const node = (
8
8
  id: string,
@@ -41,13 +41,13 @@ const graph = (
41
41
  edges,
42
42
  });
43
43
 
44
- const makeMethod = (name: string) => ({
44
+ const makeMethod = (name: string): MethodSpec => ({
45
45
  name,
46
46
  summary: `Does ${name}.`,
47
- inputs: [] as { name: string; type: string; description?: string }[],
48
- outputs: [] as { name: string; type: string; description?: string }[],
49
- sideEffects: [] as string[],
50
- calls: [] as { target: string; kind?: string; description?: string }[],
47
+ inputs: [],
48
+ outputs: [],
49
+ sideEffects: [],
50
+ calls: [],
51
51
  });
52
52
 
53
53
  describe("detectSmells", () => {
package/src/smells.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
 
3
- import type { BlueprintGraph } from "@/lib/blueprint/schema";
3
+ import type { BlueprintGraph } from "@abhinav2203/codeflow-core/schema";
4
4
 
5
5
  export const smellSchema = z.object({
6
6
  code: z.string(),
package/vitest.config.ts CHANGED
@@ -2,7 +2,6 @@ import { defineConfig } from "vitest/config";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
 
5
- const monorepoRoot = path.resolve(fileURLToPath(import.meta.url), "../../..");
6
5
 
7
6
  export default defineConfig({
8
7
  test: {
@@ -12,11 +11,4 @@ export default defineConfig({
12
11
  // Allow tests to run from the package directory
13
12
  cwd: path.resolve(fileURLToPath(import.meta.url), ".."),
14
13
  },
15
- resolve: {
16
- alias: {
17
- // Resolve @/* to the monorepo source so that the package's tests
18
- // can import types from the unextracted codeflow-core modules.
19
- "@": monorepoRoot + "/src",
20
- },
21
- },
22
14
  });