@eloquence98/ctx 0.1.2 ā 0.1.3
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/README.md +10 -116
- package/dist/cli.js +6 -1
- package/dist/formatters/ai.d.ts +2 -0
- package/dist/formatters/ai.js +83 -0
- package/dist/formatters/index.d.ts +1 -0
- package/dist/formatters/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,138 +1,32 @@
|
|
|
1
1
|
# ctx
|
|
2
2
|
|
|
3
|
-
Generate AI-ready context from your codebase
|
|
3
|
+
Generate AI-ready context from your codebase.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Why ctx
|
|
10
|
-
|
|
11
|
-
AI assistants do not understand your project unless you explain it.
|
|
12
|
-
|
|
13
|
-
Without ctx, you usually have to:
|
|
14
|
-
|
|
15
|
-
- Manually copy files
|
|
16
|
-
- Describe folder structure
|
|
17
|
-
- Explain what exists and how things connect
|
|
18
|
-
|
|
19
|
-
`ctx` automates this by generating a concise snapshot of your project with a single command.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## What It Does
|
|
24
|
-
|
|
25
|
-
- Recursively scans a directory
|
|
26
|
-
- Detects common project conventions
|
|
27
|
-
- Extracts exported symbols
|
|
28
|
-
- Produces readable, AI-friendly output
|
|
29
|
-
- Requires zero configuration
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
### No install (recommended)
|
|
5
|
+
## Usage
|
|
36
6
|
|
|
37
7
|
```bash
|
|
38
8
|
npx @eloquence98/ctx ./src
|
|
39
9
|
```
|
|
40
10
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm install -g @eloquence98/ctx
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Local install (dev dependency)
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
npm install --save-dev @eloquence98/ctx
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Usage
|
|
56
|
-
|
|
57
|
-
### Scan a directory
|
|
11
|
+
That's it. Copy the output, paste it to ChatGPT/Claude.
|
|
58
12
|
|
|
59
|
-
|
|
60
|
-
ctx ./src
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Scan current directory
|
|
13
|
+
## Options
|
|
64
14
|
|
|
65
15
|
```bash
|
|
66
|
-
|
|
16
|
+
# AI-optimized compact format
|
|
17
|
+
npx @eloquence98/ctx ./src --ai
|
|
67
18
|
```
|
|
68
19
|
|
|
69
|
-
### Output as JSON
|
|
70
|
-
|
|
71
20
|
```bash
|
|
72
|
-
|
|
21
|
+
# JSON output
|
|
22
|
+
npx @eloquence98/ctx ./src -o json
|
|
73
23
|
```
|
|
74
24
|
|
|
75
|
-
### Write output to a file
|
|
76
|
-
|
|
77
25
|
```bash
|
|
78
|
-
|
|
26
|
+
# Save to file
|
|
27
|
+
npx @eloquence98/ctx ./src > context.md
|
|
79
28
|
```
|
|
80
29
|
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## What Gets Extracted
|
|
84
|
-
|
|
85
|
-
### Code Symbols
|
|
86
|
-
|
|
87
|
-
- Functions
|
|
88
|
-
- Constants
|
|
89
|
-
- Types
|
|
90
|
-
- Interfaces
|
|
91
|
-
|
|
92
|
-
### Project Structure
|
|
93
|
-
|
|
94
|
-
- Routes (App Router / Pages Router)
|
|
95
|
-
- Features or modules
|
|
96
|
-
- Components
|
|
97
|
-
- Hooks
|
|
98
|
-
- Utilities and libraries
|
|
99
|
-
|
|
100
|
-
Detection is convention-based and works with most modern JavaScript and TypeScript projects.
|
|
101
|
-
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
## Use Cases
|
|
105
|
-
|
|
106
|
-
- Providing context to ChatGPT, Claude, or Copilot
|
|
107
|
-
- Generating architecture documentation
|
|
108
|
-
- Onboarding new team members
|
|
109
|
-
- Understanding unfamiliar codebases
|
|
110
|
-
- Preparing projects for AI-assisted refactors
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
## Output Philosophy
|
|
115
|
-
|
|
116
|
-
The output is:
|
|
117
|
-
|
|
118
|
-
- Minimal
|
|
119
|
-
- Structured
|
|
120
|
-
- Human-readable
|
|
121
|
-
- Optimized for AI comprehension
|
|
122
|
-
|
|
123
|
-
Only high-signal information is included.
|
|
124
|
-
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
## Roadmap
|
|
128
|
-
|
|
129
|
-
- Clipboard support (`--copy`)
|
|
130
|
-
- Config file support
|
|
131
|
-
- VS Code extension
|
|
132
|
-
- Watch mode
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
30
|
## License
|
|
137
31
|
|
|
138
32
|
MIT
|
package/dist/cli.js
CHANGED
|
@@ -11,6 +11,7 @@ program
|
|
|
11
11
|
.version("0.1.0")
|
|
12
12
|
.argument("[path]", "Path to scan", "./src")
|
|
13
13
|
.option("-o, --output <format>", "Output format: md, json", "md")
|
|
14
|
+
.option("--ai", "Output in AI-optimized compact format")
|
|
14
15
|
.action(async (targetPath, options) => {
|
|
15
16
|
const absolutePath = path.resolve(process.cwd(), targetPath);
|
|
16
17
|
console.log(`\nš Scanning ${absolutePath}...\n`);
|
|
@@ -38,7 +39,11 @@ program
|
|
|
38
39
|
components: groupByFolder(parsedFiles, absolutePath, "components"),
|
|
39
40
|
};
|
|
40
41
|
// Output
|
|
41
|
-
if (options.
|
|
42
|
+
if (options.ai) {
|
|
43
|
+
const { formatAI } = await import("./formatters/ai.js");
|
|
44
|
+
console.log(formatAI(context, absolutePath));
|
|
45
|
+
}
|
|
46
|
+
else if (options.output === "json") {
|
|
42
47
|
console.log(JSON.stringify(contextToJSON(context), null, 2));
|
|
43
48
|
}
|
|
44
49
|
else {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export function formatAI(data, basePath) {
|
|
2
|
+
const lines = [];
|
|
3
|
+
lines.push("# Project Context");
|
|
4
|
+
lines.push("");
|
|
5
|
+
lines.push("Use this to understand the codebase structure.");
|
|
6
|
+
lines.push("");
|
|
7
|
+
// Routes
|
|
8
|
+
if (data.routes.length > 0) {
|
|
9
|
+
lines.push("## Routes");
|
|
10
|
+
lines.push("");
|
|
11
|
+
for (const route of data.routes) {
|
|
12
|
+
const depth = route.search(/\S/); // Count leading spaces
|
|
13
|
+
const name = route.trim();
|
|
14
|
+
const prefix = depth > 0 ? " ".repeat(depth / 2) + "āā " : "- ";
|
|
15
|
+
lines.push(`${prefix}${name}`);
|
|
16
|
+
}
|
|
17
|
+
lines.push("");
|
|
18
|
+
}
|
|
19
|
+
// Features
|
|
20
|
+
if (data.features.size > 0) {
|
|
21
|
+
lines.push("## Features");
|
|
22
|
+
lines.push("");
|
|
23
|
+
lines.push(formatFolderCompact(data.features));
|
|
24
|
+
}
|
|
25
|
+
// Components
|
|
26
|
+
if (data.components.size > 0) {
|
|
27
|
+
lines.push("## Components");
|
|
28
|
+
lines.push("");
|
|
29
|
+
lines.push(formatFolderCompact(data.components));
|
|
30
|
+
}
|
|
31
|
+
// Hooks
|
|
32
|
+
if (data.hooks.length > 0) {
|
|
33
|
+
lines.push("## Hooks");
|
|
34
|
+
lines.push("");
|
|
35
|
+
for (const hook of data.hooks) {
|
|
36
|
+
const exports = getExportsSummary(hook);
|
|
37
|
+
if (exports) {
|
|
38
|
+
lines.push(`- ${hook.fileName}: ${exports}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
lines.push("");
|
|
42
|
+
}
|
|
43
|
+
// Lib
|
|
44
|
+
if (data.lib.size > 0) {
|
|
45
|
+
lines.push("## Lib / Utils");
|
|
46
|
+
lines.push("");
|
|
47
|
+
lines.push(formatFolderCompact(data.lib));
|
|
48
|
+
}
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
}
|
|
51
|
+
function formatFolderCompact(folders) {
|
|
52
|
+
const lines = [];
|
|
53
|
+
for (const [folderName, files] of folders) {
|
|
54
|
+
lines.push(`### ${folderName}`);
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
const exports = getExportsSummary(file);
|
|
57
|
+
if (exports) {
|
|
58
|
+
lines.push(`- ${file.fileName}: ${exports}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
lines.push("");
|
|
62
|
+
}
|
|
63
|
+
return lines.join("\n");
|
|
64
|
+
}
|
|
65
|
+
function getExportsSummary(file) {
|
|
66
|
+
const parts = [];
|
|
67
|
+
if (file.functions.length > 0) {
|
|
68
|
+
const fns = file.functions.map((f) => `${f}()`).join(", ");
|
|
69
|
+
parts.push(fns);
|
|
70
|
+
}
|
|
71
|
+
if (file.constants.length > 0) {
|
|
72
|
+
parts.push(file.constants.join(", "));
|
|
73
|
+
}
|
|
74
|
+
if (file.types.length > 0) {
|
|
75
|
+
const types = file.types.map((t) => `type ${t}`).join(", ");
|
|
76
|
+
parts.push(types);
|
|
77
|
+
}
|
|
78
|
+
if (file.interfaces.length > 0) {
|
|
79
|
+
const ifaces = file.interfaces.map((i) => `interface ${i}`).join(", ");
|
|
80
|
+
parts.push(ifaces);
|
|
81
|
+
}
|
|
82
|
+
return parts.join(" | ");
|
|
83
|
+
}
|
package/dist/formatters/index.js
CHANGED