@kt3k/tku 1.2.1 → 1.2.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 CHANGED
@@ -23,14 +23,16 @@ npx @kt3k/tku [options] [path]
23
23
 
24
24
  ### Options
25
25
 
26
- | Flag | Description | Default |
27
- | ------------------------- | ---------------------------------------------------- | -------------------- |
28
- | `--encoding <encoding>` | Tiktoken encoding (e.g. `o200k_base`, `cl100k_base`) | `o200k_base` |
29
- | `-e, --exclude <glob...>` | Additional glob patterns to exclude | none |
30
- | `--no-gitignore` | Do not respect `.gitignore` rules | respect `.gitignore` |
31
- | `--json` | Output results as JSON | false |
32
- | `--top <n>` | Show only the top N files by token count | show all |
33
- | `--sort <field>` | Sort by `tokens` or `path` | `tokens` |
26
+ | Flag | Description | Default |
27
+ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------- |
28
+ | `--encoding <encoding>` | Tiktoken encoding (e.g. `o200k_base`, `cl100k_base`) | `o200k_base` |
29
+ | `-e, --exclude <glob...>` | Additional glob patterns to exclude | none |
30
+ | `--no-gitignore` | Do not respect `.gitignore` rules | respect `.gitignore` |
31
+ | `--json` | Output results as JSON | false |
32
+ | `--top <n>` | Show only the top N files by token count | show all |
33
+ | `--sort <field>` | Sort by `tokens` or `path` | `tokens` |
34
+ | `-t, --tree` | Display results as a directory tree (ignores `--top`, `--json`, `--sort`) | false |
35
+ | `--dirs` | Summarize by directory. With `--tree`, shows only directories. Without `--tree`, shows a flat directory summary table. | false |
34
36
 
35
37
  ### Examples
36
38
 
@@ -46,6 +48,15 @@ npx @kt3k/tku --json
46
48
 
47
49
  # Exclude test files
48
50
  npx @kt3k/tku --exclude "**/*.test.*" --exclude "**/fixtures/**"
51
+
52
+ # Directory tree view
53
+ npx @kt3k/tku --tree
54
+
55
+ # Directory tree, directories only
56
+ npx @kt3k/tku --tree --dirs
57
+
58
+ # Flat directory summary
59
+ npx @kt3k/tku --dirs
49
60
  ```
50
61
 
51
62
  ## Output
@@ -76,6 +87,34 @@ tokens path
76
87
  }
77
88
  ```
78
89
 
90
+ ### Tree (`--tree`)
91
+
92
+ ```
93
+ tokens path
94
+ 2.4 K .
95
+ 2.1 K ├── src/
96
+ 1.2 K │ ├── index.ts
97
+ 892 │ └── utils.ts
98
+ 345 └── README.md
99
+ ```
100
+
101
+ ### Tree, directories only (`--tree --dirs`)
102
+
103
+ ```
104
+ tokens path
105
+ 2.4 K .
106
+ 2.1 K └── src/
107
+ ```
108
+
109
+ ### Directory summary (`--dirs`)
110
+
111
+ ```
112
+ tokens path
113
+ 2.1 K src
114
+ ────────
115
+ 2.4 K total (3 files)
116
+ ```
117
+
79
118
  ## License
80
119
 
81
120
  MIT
package/dist/main.js CHANGED
@@ -238,10 +238,12 @@ function formatTree(result, options = {}) {
238
238
  function summarizeByDir(result) {
239
239
  const dirMap = /* @__PURE__ */ new Map();
240
240
  for (const file of result.files) {
241
- const slashIdx = file.path.indexOf("/");
242
- if (slashIdx === -1) continue;
243
- const dir = file.path.slice(0, slashIdx);
244
- dirMap.set(dir, (dirMap.get(dir) ?? 0) + file.tokens);
241
+ const parts = file.path.split("/");
242
+ if (parts.length < 2) continue;
243
+ for (let i = 1; i < parts.length; i++) {
244
+ const dir = parts.slice(0, i).join("/");
245
+ dirMap.set(dir, (dirMap.get(dir) ?? 0) + file.tokens);
246
+ }
245
247
  }
246
248
  const files = [
247
249
  ...dirMap.entries()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kt3k/tku",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "dist/main.js",
6
6
  "bin": {