callograph 0.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 247TechBoss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # Callograph
2
+
3
+ **Callograph** is a static analysis tool for TypeScript projects that builds a program-level call graph and detects side effects, impurity propagation, and unsafe async behavior.
4
+
5
+ It is designed for engineers who want deeper insight into how code behaves — beyond lint rules — by analyzing symbol resolution and cross-file call relationships using the TypeScript Compiler API.
6
+
7
+ ---
8
+
9
+ ## Why Callograph?
10
+
11
+ Modern TypeScript codebases suffer from:
12
+
13
+ * Hidden side effects
14
+ * Implicit mutation
15
+ * Unintended global state access
16
+ * Async misuse
17
+ * Impure utilities leaking into shared modules
18
+ * Lack of deterministic boundaries
19
+
20
+ Callograph provides structural visibility into function relationships and propagates impurity across the call graph to surface real architectural risks.
21
+
22
+ ---
23
+
24
+ ## Core Capabilities (v0.1.0)
25
+
26
+ ### 1. Call Graph Construction
27
+
28
+ Builds a full program-level call graph from your `tsconfig.json`.
29
+
30
+ It identifies:
31
+
32
+ * Function → function relationships
33
+ * Cross-file calls
34
+ * Imported symbol calls
35
+ * Method calls (where statically resolvable)
36
+
37
+ Example output:
38
+
39
+ ```
40
+ Call Graph:
41
+
42
+ calculateTotal → applyDiscount
43
+ applyDiscount → fetchTaxRate
44
+ fetchTaxRate → Date.now
45
+ ```
46
+
47
+ ---
48
+
49
+ ### 2. Function Purity Detection
50
+
51
+ Callograph analyzes whether a function is:
52
+
53
+ * Mutating its parameters
54
+ * Writing to outer scope variables
55
+ * Accessing global state
56
+ * Calling impure functions
57
+
58
+ Example:
59
+
60
+ ```
61
+ src/utils/calc.ts:42
62
+ Function: calculateTotal
63
+ Status: ❌ Impure
64
+
65
+ Reasons:
66
+ - Mutates parameter `items`
67
+ - Calls impure function `fetchTaxRate`
68
+ ```
69
+
70
+ ---
71
+
72
+ ### 3. Impurity Propagation
73
+
74
+ If:
75
+
76
+ ```
77
+ A → calls B
78
+ B → impure
79
+ ```
80
+
81
+ Then:
82
+
83
+ ```
84
+ A becomes impure
85
+ ```
86
+
87
+ This propagation makes Callograph significantly more powerful than simple AST pattern scanning.
88
+
89
+ It reasons about effect chains.
90
+
91
+ ---
92
+
93
+ ### 4. Global State & Non-Determinism Detection
94
+
95
+ Flags usage of:
96
+
97
+ * `process.env`
98
+ * `Date.now()`
99
+ * `Math.random()`
100
+ * `global`
101
+ * `window`
102
+ * Console writes (optional strict mode)
103
+
104
+ Useful for teams enforcing deterministic or pure-core architectures.
105
+
106
+ ---
107
+
108
+ ### 5. Parameter Mutation Detection
109
+
110
+ Detects:
111
+
112
+ * Direct reassignment
113
+ * Deep property mutation
114
+ * Array mutation (`push`, `splice`, etc.)
115
+
116
+ Example:
117
+
118
+ ```
119
+ ❌ Parameter mutation detected:
120
+ updateUser(user) → user.name = "new"
121
+ ```
122
+
123
+ ---
124
+
125
+ ### 6. Async Safety Checks
126
+
127
+ Flags:
128
+
129
+ * Unawaited promises
130
+ * Fire-and-forget async calls
131
+ * Async functions lacking error handling (basic detection)
132
+
133
+ ---
134
+
135
+ ### 7. CI Integration
136
+
137
+ Callograph can fail CI if impure functions are detected.
138
+
139
+ ```
140
+ callograph analyze --fail-on-impure
141
+ ```
142
+
143
+ This allows enforcement of architectural constraints.
144
+
145
+ ---
146
+
147
+ ## Installation
148
+
149
+ ```bash
150
+ npm install --save-dev callograph
151
+ ```
152
+
153
+ Or use directly:
154
+
155
+ ```bash
156
+ npx callograph analyze
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Usage
162
+
163
+ Analyze project based on `tsconfig.json`:
164
+
165
+ ```bash
166
+ callograph analyze
167
+ ```
168
+
169
+ JSON output:
170
+
171
+ ```bash
172
+ callograph analyze --json
173
+ ```
174
+
175
+ Fail CI if impurity detected:
176
+
177
+ ```bash
178
+ callograph analyze --fail-on-impure
179
+ ```
180
+
181
+ Export DOT graph:
182
+
183
+ ```bash
184
+ callograph analyze --dot
185
+ ```
186
+
187
+ ---
188
+
189
+ ## Architecture
190
+
191
+ Callograph uses:
192
+
193
+ * TypeScript Compiler API
194
+ * Program-level symbol resolution
195
+ * TypeChecker-based call resolution
196
+ * AST traversal via `ts.forEachChild`
197
+ * Impurity propagation via call graph traversal
198
+
199
+ Pipeline:
200
+
201
+ ```
202
+ Load tsconfig
203
+
204
+ Create Program
205
+
206
+ Extract function symbols
207
+
208
+ Build call graph
209
+
210
+ Detect side effects
211
+
212
+ Propagate impurity
213
+
214
+ Report results
215
+ ```
216
+
217
+ ---
218
+
219
+ ## Design Philosophy
220
+
221
+ Callograph does not attempt perfect purity inference.
222
+ It aims to provide practical, high-signal diagnostics with minimal noise.
223
+
224
+ It prioritizes:
225
+
226
+ * Deterministic analysis
227
+ * CI compatibility
228
+ * Clear reasoning in output
229
+ * Minimal false positives
230
+ * Performance (<2s on mid-sized codebases)
231
+
232
+ ---
233
+
234
+ ## Limitations (v0.1.0)
235
+
236
+ * Dynamic runtime dispatch cannot always be resolved.
237
+ * Higher-order functions are partially supported.
238
+ * Deep framework-specific analysis is not included.
239
+ * No IDE integration yet.
240
+
241
+ ---
242
+
243
+ ## Roadmap
244
+
245
+ * Shared mutable singleton detection
246
+ * Closure-captured state analysis
247
+ * Circular call detection
248
+ * Effect scoring per module
249
+ * Interactive HTML graph visualization
250
+ * GitHub PR comment bot
251
+ * Monorepo support with project references
252
+
253
+ ---
254
+
255
+ ## License
256
+
257
+ MIT
258
+
259
+ ---
260
+
261
+ ## Contributing
262
+
263
+ Contributions are welcome.
264
+
265
+ * Open an issue to discuss architecture changes.
266
+ * Keep changes deterministic and type-safe.
267
+ * Add tests for new analysis rules.
268
+
269
+ ---
270
+
271
+ ## Vision
272
+
273
+ Callograph aims to become:
274
+
275
+ > A structural analysis tool that gives engineers clarity over side effects, purity, and call relationships in large TypeScript systems.
276
+
277
+ ---
package/dist/index.cjs ADDED
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ version: () => version
23
+ });
24
+ module.exports = __toCommonJS(index_exports);
25
+ var version = "0.0.1";
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ version
29
+ });
30
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const version = \"0.0.1\";"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,UAAU;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare const version = "0.0.1";
2
+
3
+ export { version };
@@ -0,0 +1,3 @@
1
+ declare const version = "0.0.1";
2
+
3
+ export { version };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // src/index.ts
2
+ var version = "0.0.1";
3
+ export {
4
+ version
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const version = \"0.0.1\";"],"mappings":";AAAO,IAAM,UAAU;","names":[]}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "callograph",
3
+ "version": "0.0.1",
4
+ "description": "TypeScript call graph and side-effect analyzer.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsup",
15
+ "dev": "tsup --watch",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "devDependencies": {
19
+ "tsup": "^8.5.1",
20
+ "typescript": "^5.9.3"
21
+ }
22
+ }