@aiready/doc-drift 0.13.19 → 0.13.20

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > @aiready/doc-drift@0.13.19 build /Users/pengcao/projects/aiready/packages/doc-drift
3
+ > @aiready/doc-drift@0.13.20 build /Users/pengcao/projects/aiready/packages/doc-drift
4
4
  > tsup src/index.ts src/cli.ts --format cjs,esm --dts
5
5
 
6
6
  CLI Building entry: src/cli.ts, src/index.ts
@@ -9,15 +9,15 @@
9
9
  CLI Target: es2020
10
10
  CJS Build start
11
11
  ESM Build start
12
- ESM dist/index.mjs 2.59 KB
13
- ESM dist/chunk-DEXSCXHS.mjs 4.39 KB
12
+ CJS dist/cli.js 7.11 KB
13
+ CJS dist/index.js 7.71 KB
14
+ CJS ⚡️ Build success in 538ms
15
+ ESM dist/chunk-GZDN7B4K.mjs 4.40 KB
14
16
  ESM dist/cli.mjs 1.39 KB
15
- ESM ⚡️ Build success in 209ms
16
- CJS dist/index.js 7.70 KB
17
- CJS dist/cli.js 7.10 KB
18
- CJS ⚡️ Build success in 209ms
17
+ ESM dist/index.mjs 2.59 KB
18
+ ESM ⚡️ Build success in 538ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 5549ms
20
+ DTS ⚡️ Build success in 11801ms
21
21
  DTS dist/cli.d.ts 108.00 B
22
22
  DTS dist/index.d.ts 2.83 KB
23
23
  DTS dist/cli.d.mts 108.00 B
@@ -1,18 +1,19 @@
1
1
 
2
2
  
3
- > @aiready/doc-drift@0.13.18 test /Users/pengcao/projects/aiready/packages/doc-drift
3
+ > @aiready/doc-drift@0.13.19 test /Users/pengcao/projects/aiready/packages/doc-drift
4
4
  > vitest run
5
5
 
6
6
  [?25l
7
7
   RUN  v4.0.18 /Users/pengcao/projects/aiready/packages/doc-drift
8
8
 
9
- ✓ src/__tests__/provider.test.ts (2 tests) 4ms
10
- ✓ src/__tests__/scoring.test.ts (2 tests) 3ms
11
- ✓ src/__tests__/analyzer.test.ts (1 test) 205ms
9
+ ✓ src/__tests__/scoring.test.ts (2 tests) 4ms
10
+ ✓ src/__tests__/analyzer.test.ts (1 test) 708ms
11
+ ✓ detects missing param documentation and uncommented complexity  462ms
12
+ ✓ src/__tests__/provider.test.ts (2 tests) 137ms
12
13
 
13
14
   Test Files  3 passed (3)
14
15
   Tests  5 passed (5)
15
-  Start at  13:03:36
16
-  Duration  4.40s (transform 1.07s, setup 0ms, import 9.17s, tests 213ms, environment 0ms)
16
+  Start at  23:31:08
17
+  Duration  11.40s (transform 5.06s, setup 0ms, import 27.10s, tests 848ms, environment 0ms)
17
18
 
18
19
  [?25h
@@ -0,0 +1,142 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/analyzer.ts
9
+ import {
10
+ scanFiles,
11
+ calculateDocDrift,
12
+ getFileCommitTimestamps,
13
+ getLineRangeLastModifiedCached,
14
+ Severity,
15
+ IssueType,
16
+ emitProgress,
17
+ getParser
18
+ } from "@aiready/core";
19
+ import { readFileSync } from "fs";
20
+ async function analyzeDocDrift(options) {
21
+ const files = await scanFiles(options);
22
+ const issues = [];
23
+ let uncommentedExports = 0;
24
+ let totalExports = 0;
25
+ let outdatedComments = 0;
26
+ let undocumentedComplexity = 0;
27
+ let actualDrift = 0;
28
+ let processed = 0;
29
+ for (const file of files) {
30
+ processed++;
31
+ emitProgress(
32
+ processed,
33
+ files.length,
34
+ "doc-drift",
35
+ "analyzing files",
36
+ options.onProgress
37
+ );
38
+ const parser = await getParser(file);
39
+ if (!parser) continue;
40
+ let code;
41
+ try {
42
+ code = readFileSync(file, "utf-8");
43
+ } catch {
44
+ continue;
45
+ }
46
+ try {
47
+ await parser.initialize();
48
+ const parseResult = parser.parse(code, file);
49
+ let fileLineStamps;
50
+ for (const exp of parseResult.exports) {
51
+ if (exp.type === "function" || exp.type === "class") {
52
+ totalExports++;
53
+ if (!exp.documentation) {
54
+ uncommentedExports++;
55
+ if (exp.loc) {
56
+ const lines = exp.loc.end.line - exp.loc.start.line;
57
+ if (lines > 20) undocumentedComplexity++;
58
+ }
59
+ } else {
60
+ const doc = exp.documentation;
61
+ const docContent = doc.content;
62
+ if (exp.type === "function" && exp.parameters) {
63
+ const params = exp.parameters;
64
+ const missingParams = params.filter((p) => {
65
+ const regex = new RegExp(`\\b${p}\\b`);
66
+ return !regex.test(docContent);
67
+ });
68
+ if (missingParams.length > 0) {
69
+ outdatedComments++;
70
+ issues.push({
71
+ type: IssueType.DocDrift,
72
+ severity: Severity.Major,
73
+ message: `Documentation mismatch: function parameters (${missingParams.join(", ")}) are not mentioned in the docs.`,
74
+ location: { file, line: exp.loc?.start.line || 1 }
75
+ });
76
+ }
77
+ }
78
+ if (exp.loc && doc.loc) {
79
+ if (!fileLineStamps) {
80
+ fileLineStamps = getFileCommitTimestamps(file);
81
+ }
82
+ const bodyModified = getLineRangeLastModifiedCached(
83
+ fileLineStamps,
84
+ exp.loc.start.line,
85
+ exp.loc.end.line
86
+ );
87
+ const docModified = getLineRangeLastModifiedCached(
88
+ fileLineStamps,
89
+ doc.loc.start.line,
90
+ doc.loc.end.line
91
+ );
92
+ if (bodyModified > 0 && docModified > 0) {
93
+ const DRIFT_THRESHOLD_SECONDS = 24 * 60 * 60;
94
+ if (bodyModified - docModified > DRIFT_THRESHOLD_SECONDS) {
95
+ actualDrift++;
96
+ issues.push({
97
+ type: IssueType.DocDrift,
98
+ severity: Severity.Major,
99
+ message: `Documentation drift: logic was modified on ${new Date(bodyModified * 1e3).toLocaleDateString()} but documentation was last updated on ${new Date(docModified * 1e3).toLocaleDateString()}.`,
100
+ location: { file, line: doc.loc.start.line }
101
+ });
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+ } catch (error) {
109
+ console.warn(`Doc-drift: Failed to parse ${file}: ${error}`);
110
+ continue;
111
+ }
112
+ }
113
+ const riskResult = calculateDocDrift({
114
+ uncommentedExports,
115
+ totalExports,
116
+ outdatedComments,
117
+ undocumentedComplexity,
118
+ actualDrift
119
+ });
120
+ return {
121
+ summary: {
122
+ filesAnalyzed: files.length,
123
+ functionsAnalyzed: totalExports,
124
+ score: riskResult.score,
125
+ rating: riskResult.rating
126
+ },
127
+ issues,
128
+ rawData: {
129
+ uncommentedExports,
130
+ totalExports,
131
+ outdatedComments,
132
+ undocumentedComplexity,
133
+ actualDrift
134
+ },
135
+ recommendations: riskResult.recommendations
136
+ };
137
+ }
138
+
139
+ export {
140
+ __require,
141
+ analyzeDocDrift
142
+ };
package/dist/cli.js CHANGED
@@ -56,7 +56,7 @@ async function analyzeDocDrift(options) {
56
56
  "analyzing files",
57
57
  options.onProgress
58
58
  );
59
- const parser = (0, import_core.getParser)(file);
59
+ const parser = await (0, import_core.getParser)(file);
60
60
  if (!parser) continue;
61
61
  let code;
62
62
  try {
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __require,
3
3
  analyzeDocDrift
4
- } from "./chunk-DEXSCXHS.mjs";
4
+ } from "./chunk-GZDN7B4K.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { Command } from "commander";
package/dist/index.js CHANGED
@@ -51,7 +51,7 @@ async function analyzeDocDrift(options) {
51
51
  "analyzing files",
52
52
  options.onProgress
53
53
  );
54
- const parser = (0, import_core.getParser)(file);
54
+ const parser = await (0, import_core.getParser)(file);
55
55
  if (!parser) continue;
56
56
  let code;
57
57
  try {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  analyzeDocDrift
3
- } from "./chunk-DEXSCXHS.mjs";
3
+ } from "./chunk-GZDN7B4K.mjs";
4
4
 
5
5
  // src/index.ts
6
6
  import { ToolRegistry } from "@aiready/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/doc-drift",
3
- "version": "0.13.19",
3
+ "version": "0.13.20",
4
4
  "description": "AI-Readiness: Documentation Drift Detection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -10,7 +10,7 @@
10
10
  "commander": "^14.0.0",
11
11
  "glob": "^13.0.0",
12
12
  "picocolors": "^1.0.0",
13
- "@aiready/core": "0.23.20"
13
+ "@aiready/core": "0.23.21"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "^24.0.0",
package/src/analyzer.ts CHANGED
@@ -48,7 +48,7 @@ export async function analyzeDocDrift(
48
48
  options.onProgress
49
49
  );
50
50
 
51
- const parser = getParser(file);
51
+ const parser = await getParser(file);
52
52
  if (!parser) continue;
53
53
 
54
54
  let code: string;