@aiready/doc-drift 0.13.12 → 0.13.13

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,5 +1,5 @@
1
1
 
2
- > @aiready/doc-drift@0.13.12 build /Users/pengcao/projects/aiready/packages/doc-drift
2
+ > @aiready/doc-drift@0.13.13 build /Users/pengcao/projects/aiready/packages/doc-drift
3
3
  > tsup src/index.ts src/cli.ts --format cjs,esm --dts
4
4
 
5
5
  CLI Building entry: src/cli.ts, src/index.ts
@@ -8,15 +8,15 @@ CLI tsup v8.5.1
8
8
  CLI Target: es2020
9
9
  CJS Build start
10
10
  ESM Build start
11
- CJS dist/cli.js 7.11 KB
12
- CJS dist/index.js 7.71 KB
13
- CJS ⚡️ Build success in 125ms
14
- ESM dist/chunk-MAPV5YQR.mjs 4.40 KB
11
+ CJS dist/cli.js 7.10 KB
12
+ CJS dist/index.js 7.70 KB
13
+ CJS ⚡️ Build success in 370ms
14
+ ESM dist/chunk-DEXSCXHS.mjs 4.39 KB
15
15
  ESM dist/cli.mjs 1.39 KB
16
16
  ESM dist/index.mjs 2.59 KB
17
- ESM ⚡️ Build success in 126ms
17
+ ESM ⚡️ Build success in 371ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 7746ms
19
+ DTS ⚡️ Build success in 10196ms
20
20
  DTS dist/cli.d.ts 108.00 B
21
21
  DTS dist/index.d.ts 2.83 KB
22
22
  DTS dist/cli.d.mts 108.00 B
@@ -1,16 +1,17 @@
1
1
 
2
- > @aiready/doc-drift@0.13.11 test /Users/pengcao/projects/aiready/packages/doc-drift
2
+ > @aiready/doc-drift@0.13.12 test /Users/pengcao/projects/aiready/packages/doc-drift
3
3
  > vitest run
4
4
 
5
5
 
6
6
   RUN  v4.0.18 /Users/pengcao/projects/aiready/packages/doc-drift
7
7
 
8
- ✓ src/__tests__/scoring.test.ts (2 tests) 2ms
9
- ✓ src/__tests__/provider.test.ts (2 tests) 31ms
10
- ✓ src/__tests__/analyzer.test.ts (1 test) 159ms
8
+ ✓ src/__tests__/provider.test.ts (2 tests) 2ms
9
+ ✓ src/__tests__/scoring.test.ts (2 tests) 5ms
10
+ ✓ src/__tests__/analyzer.test.ts (1 test) 583ms
11
+ ✓ detects missing param documentation and uncommented complexity  576ms
11
12
 
12
13
   Test Files  3 passed (3)
13
14
   Tests  5 passed (5)
14
-  Start at  16:30:25
15
-  Duration  3.52s (transform 1.87s, setup 0ms, import 7.55s, tests 192ms, environment 0ms)
15
+  Start at  10:44:29
16
+  Duration  3.24s (transform 1.08s, setup 0ms, import 6.97s, tests 590ms, environment 0ms)
16
17
 
@@ -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 = 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
@@ -83,7 +83,7 @@ async function analyzeDocDrift(options) {
83
83
  if (exp.type === "function" && exp.parameters) {
84
84
  const params = exp.parameters;
85
85
  const missingParams = params.filter((p) => {
86
- const regex = new RegExp(`\\b${p}\\b`, "i");
86
+ const regex = new RegExp(`\\b${p}\\b`);
87
87
  return !regex.test(docContent);
88
88
  });
89
89
  if (missingParams.length > 0) {
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __require,
3
3
  analyzeDocDrift
4
- } from "./chunk-MAPV5YQR.mjs";
4
+ } from "./chunk-DEXSCXHS.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { Command } from "commander";
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ async function analyzeDocDrift(options) {
78
78
  if (exp.type === "function" && exp.parameters) {
79
79
  const params = exp.parameters;
80
80
  const missingParams = params.filter((p) => {
81
- const regex = new RegExp(`\\b${p}\\b`, "i");
81
+ const regex = new RegExp(`\\b${p}\\b`);
82
82
  return !regex.test(docContent);
83
83
  });
84
84
  if (missingParams.length > 0) {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  analyzeDocDrift
3
- } from "./chunk-MAPV5YQR.mjs";
3
+ } from "./chunk-DEXSCXHS.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.12",
3
+ "version": "0.13.13",
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.13"
13
+ "@aiready/core": "0.23.14"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "^24.0.0",
package/src/analyzer.ts CHANGED
@@ -87,7 +87,7 @@ export async function analyzeDocDrift(
87
87
  const params = exp.parameters;
88
88
  // Check if params mentioned in doc (standard @param or simple mention)
89
89
  const missingParams = params.filter((p) => {
90
- const regex = new RegExp(`\\b${p}\\b`, 'i');
90
+ const regex = new RegExp(`\\b${p}\\b`);
91
91
  return !regex.test(docContent);
92
92
  });
93
93