Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
language-stats.ts11.4 KB · 449 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/**
 * Block J30 — Repository language breakdown.
 *
 * Pure helpers that map file paths to a language (via extension + a handful
 * of filename-only special cases like `Dockerfile`, `Makefile`), compute
 * per-language byte totals + percentages, and can fold low-share languages
 * into an "Other" bucket.
 *
 * We also ship a compact `LANGUAGE_COLORS` map so the route can render a
 * stacked bar matching common colour conventions (GitHub-ish).
 *
 * This deliberately lives outside any linguist-style heuristic soup —
 * we don't auto-detect by content, we trust extensions + filenames. It's
 * lightweight and good enough for the breakdown UI.
 */

/**
 * Extension → language. Keys are without leading dot, lowercased.
 * A deliberately opinionated subset — no one-off exotic languages.
 */
export const EXTENSION_MAP: ReadonlyMap<string, string> = new Map(
  Object.entries({
    ts: "TypeScript",
    tsx: "TypeScript",
    js: "JavaScript",
    jsx: "JavaScript",
    mjs: "JavaScript",
    cjs: "JavaScript",
    py: "Python",
    rb: "Ruby",
    go: "Go",
    rs: "Rust",
    java: "Java",
    kt: "Kotlin",
    kts: "Kotlin",
    swift: "Swift",
    c: "C",
    h: "C",
    cpp: "C++",
    cxx: "C++",
    cc: "C++",
    hpp: "C++",
    hh: "C++",
    cs: "C#",
    php: "PHP",
    pl: "Perl",
    pm: "Perl",
    r: "R",
    scala: "Scala",
    clj: "Clojure",
    ex: "Elixir",
    exs: "Elixir",
    erl: "Erlang",
    hs: "Haskell",
    lua: "Lua",
    ml: "OCaml",
    mli: "OCaml",
    dart: "Dart",
    sh: "Shell",
    bash: "Shell",
    zsh: "Shell",
    fish: "Shell",
    ps1: "PowerShell",
    sql: "SQL",
    html: "HTML",
    htm: "HTML",
    css: "CSS",
    scss: "SCSS",
    sass: "Sass",
    less: "Less",
    vue: "Vue",
    svelte: "Svelte",
    astro: "Astro",
    md: "Markdown",
    mdx: "MDX",
    rst: "reStructuredText",
    tex: "TeX",
    yaml: "YAML",
    yml: "YAML",
    json: "JSON",
    json5: "JSON",
    toml: "TOML",
    xml: "XML",
    ini: "INI",
    conf: "INI",
    proto: "Protocol Buffers",
    graphql: "GraphQL",
    gql: "GraphQL",
    zig: "Zig",
    nim: "Nim",
    vim: "Vim script",
    vb: "Visual Basic",
    asm: "Assembly",
    s: "Assembly",
    dockerfile: "Dockerfile",
  })
);

/** Filename → language for files that traditionally have no extension. */
export const FILENAME_MAP: ReadonlyMap<string, string> = new Map(
  Object.entries({
    dockerfile: "Dockerfile",
    makefile: "Makefile",
    gnumakefile: "Makefile",
    rakefile: "Ruby",
    gemfile: "Ruby",
    procfile: "Procfile",
    jenkinsfile: "Groovy",
    "cmakelists.txt": "CMake",
    "meson.build": "Meson",
    "build.gradle": "Groovy",
    "build.gradle.kts": "Kotlin",
    "pom.xml": "XML",
    "package.json": "JSON",
    "tsconfig.json": "JSON",
  })
);

/**
 * GitHub-ish language colours. Omitted entries render with a neutral grey.
 * Only widely-used languages get a brand colour here.
 */
export const LANGUAGE_COLORS: ReadonlyMap<string, string> = new Map(
  Object.entries({
    TypeScript: "#3178c6",
    JavaScript: "#f1e05a",
    Python: "#3572A5",
    Ruby: "#701516",
    Go: "#00ADD8",
    Rust: "#dea584",
    Java: "#b07219",
    Kotlin: "#A97BFF",
    Swift: "#F05138",
    C: "#555555",
    "C++": "#f34b7d",
    "C#": "#178600",
    PHP: "#4F5D95",
    Scala: "#c22d40",
    Clojure: "#db5855",
    Elixir: "#6e4a7e",
    Haskell: "#5e5086",
    Lua: "#000080",
    Shell: "#89e051",
    PowerShell: "#012456",
    HTML: "#e34c26",
    CSS: "#563d7c",
    SCSS: "#c6538c",
    Vue: "#41b883",
    Svelte: "#ff3e00",
    Astro: "#ff5d01",
    Markdown: "#083fa1",
    YAML: "#cb171e",
    JSON: "#292929",
    TOML: "#9c4221",
    GraphQL: "#e10098",
    Dockerfile: "#384d54",
    Makefile: "#427819",
    SQL: "#e38c00",
    Dart: "#00B4AB",
    Zig: "#ec915c",
    Other: "#888888",
  })
);

/** Fallback colour when a language has no LANGUAGE_COLORS entry. */
export const DEFAULT_LANGUAGE_COLOR = "#888888";

/**
 * Paths we never want in the breakdown: vendored + generated + lock files.
 * Callers can opt out by passing `ignoreVendored: false`.
 */
export const VENDORED_PREFIXES: readonly string[] = [
  "node_modules/",
  "vendor/",
  "dist/",
  "build/",
  ".next/",
  ".nuxt/",
  "coverage/",
  ".git/",
  "target/",
  "bin/",
];

export const GENERATED_SUFFIXES: readonly string[] = [
  "package-lock.json",
  "yarn.lock",
  "pnpm-lock.yaml",
  "bun.lockb",
  "Cargo.lock",
  "composer.lock",
  "Gemfile.lock",
  "poetry.lock",
];

export interface LanguageFileEntry {
  path: string;
  size: number;
}

export interface LanguageBucket {
  language: string;
  bytes: number;
  fileCount: number;
  percent: number;
  color: string;
}

export interface LanguageReport {
  totalBytes: number;
  totalFiles: number;
  countedFiles: number;
  /** Non-"Other" per-language rollup, sorted by bytes desc. */
  buckets: LanguageBucket[];
  primary: LanguageBucket | null;
}

function lastSegment(p: string): string {
  const i = p.lastIndexOf("/");
  return i >= 0 ? p.slice(i + 1) : p;
}

function extensionOf(basename: string): string | null {
  const i = basename.lastIndexOf(".");
  if (i <= 0) return null;
  return basename.slice(i + 1).toLowerCase();
}

/**
 * Return the language for a path, or null if it can't be classified.
 * Tries `FILENAME_MAP` on the basename first (for extensionless files
 * like `Dockerfile`), then `EXTENSION_MAP`.
 */
export function detectLanguage(path: string): string | null {
  if (typeof path !== "string" || path.length === 0) return null;
  const base = lastSegment(path).toLowerCase();
  const byName = FILENAME_MAP.get(base);
  if (byName) return byName;
  const ext = extensionOf(base);
  if (!ext) return null;
  return EXTENSION_MAP.get(ext) ?? null;
}

export function isVendoredOrGenerated(path: string): boolean {
  if (typeof path !== "string") return false;
  const normal = path.startsWith("/") ? path.slice(1) : path;
  for (const pref of VENDORED_PREFIXES) {
    if (normal.startsWith(pref) || normal.includes("/" + pref)) return true;
  }
  const base = lastSegment(normal);
  for (const sfx of GENERATED_SUFFIXES) {
    if (base === sfx) return true;
  }
  return false;
}

export interface StatsOptions {
  /** Exclude `node_modules/`, `dist/`, lock files, etc. Default true. */
  ignoreVendored?: boolean;
  /** Cap the per-file size we'll count (prevents a 500MB blob biasing the pie). */
  maxFileSize?: number;
  /** Minimum bytes for a language to avoid being folded into "Other". Default 0 (= keep all). */
  minLanguageBytes?: number;
}

function colorFor(lang: string): string {
  return LANGUAGE_COLORS.get(lang) ?? DEFAULT_LANGUAGE_COLOR;
}

/**
 * Walk the entries, bucket by detected language, compute percentages.
 * Paths that can't be classified are ignored (they don't count against
 * the total). Returns a sorted `buckets` array.
 */
export function computeLanguageStats(
  entries: readonly LanguageFileEntry[],
  opts: StatsOptions = {}
): LanguageReport {
  const ignoreVendored = opts.ignoreVendored !== false;
  const maxFileSize =
    opts.maxFileSize !== undefined && opts.maxFileSize > 0
      ? opts.maxFileSize
      : Number.POSITIVE_INFINITY;
  const minLanguageBytes = opts.minLanguageBytes ?? 0;

  let totalFiles = 0;
  let countedFiles = 0;
  const byLang = new Map<string, { bytes: number; fileCount: number }>();

  for (const e of entries) {
    totalFiles++;
    if (!e || typeof e.path !== "string") continue;
    if (ignoreVendored && isVendoredOrGenerated(e.path)) continue;
    const lang = detectLanguage(e.path);
    if (!lang) continue;
    const sz = Math.min(
      Math.max(0, Number.isFinite(e.size) ? e.size : 0),
      maxFileSize
    );
    if (sz === 0) continue;
    countedFiles++;
    const agg = byLang.get(lang) ?? { bytes: 0, fileCount: 0 };
    agg.bytes += sz;
    agg.fileCount++;
    byLang.set(lang, agg);
  }

  const totalBytes = Array.from(byLang.values()).reduce(
    (acc, v) => acc + v.bytes,
    0
  );

  const buckets: LanguageBucket[] = [];
  let otherBytes = 0;
  let otherFiles = 0;
  for (const [language, { bytes, fileCount }] of byLang) {
    if (bytes < minLanguageBytes) {
      otherBytes += bytes;
      otherFiles += fileCount;
      continue;
    }
    buckets.push({
      language,
      bytes,
      fileCount,
      percent: totalBytes === 0 ? 0 : (bytes / totalBytes) * 100,
      color: colorFor(language),
    });
  }
  if (otherBytes > 0) {
    buckets.push({
      language: "Other",
      bytes: otherBytes,
      fileCount: otherFiles,
      percent: totalBytes === 0 ? 0 : (otherBytes / totalBytes) * 100,
      color: colorFor("Other"),
    });
  }

  buckets.sort((a, b) => {
    if (a.language === "Other" && b.language !== "Other") return 1;
    if (b.language === "Other" && a.language !== "Other") return -1;
    if (a.bytes !== b.bytes) return b.bytes - a.bytes;
    return a.language.localeCompare(b.language);
  });

  const primary = buckets.find((b) => b.language !== "Other") ?? null;
  return {
    totalBytes,
    totalFiles,
    countedFiles,
    buckets,
    primary,
  };
}

/**
 * Fold languages under `thresholdPercent` into an "Other" bucket.
 * Only rebucketing — re-running on the output is idempotent.
 */
export function foldIntoOther(
  report: LanguageReport,
  thresholdPercent: number
): LanguageReport {
  if (thresholdPercent <= 0) return report;
  const keep: LanguageBucket[] = [];
  let otherBytes = 0;
  let otherFiles = 0;
  for (const b of report.buckets) {
    if (b.language === "Other" || b.percent < thresholdPercent) {
      otherBytes += b.bytes;
      otherFiles += b.fileCount;
    } else {
      keep.push(b);
    }
  }
  if (otherBytes > 0) {
    keep.push({
      language: "Other",
      bytes: otherBytes,
      fileCount: otherFiles,
      percent:
        report.totalBytes === 0 ? 0 : (otherBytes / report.totalBytes) * 100,
      color: colorFor("Other"),
    });
  }
  keep.sort((a, b) => {
    if (a.language === "Other" && b.language !== "Other") return 1;
    if (b.language === "Other" && a.language !== "Other") return -1;
    if (a.bytes !== b.bytes) return b.bytes - a.bytes;
    return a.language.localeCompare(b.language);
  });
  return {
    ...report,
    buckets: keep,
    primary: keep.find((b) => b.language !== "Other") ?? null,
  };
}

const SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"] as const;

export function formatBytes(n: number): string {
  if (!Number.isFinite(n) || n < 0) return "0 B";
  if (n < 1024) return `${n} B`;
  let v = n;
  let u = 0;
  while (v >= 1024 && u < SIZE_UNITS.length - 1) {
    v /= 1024;
    u++;
  }
  return `${v.toFixed(v >= 10 || u === 0 ? 0 : 1)} ${SIZE_UNITS[u]}`;
}

export function formatPercent(p: number, digits = 1): string {
  if (!Number.isFinite(p)) return "0%";
  const v = Math.max(0, Math.min(100, p));
  return `${v.toFixed(digits)}%`;
}

export interface BuildReportOptions extends StatsOptions {
  entries: readonly LanguageFileEntry[];
  /** After rollup, fold any language under this percentage into Other. */
  foldUnderPercent?: number;
}

export function buildLanguageReport(opts: BuildReportOptions): LanguageReport {
  const base = computeLanguageStats(opts.entries, opts);
  if (opts.foldUnderPercent && opts.foldUnderPercent > 0) {
    return foldIntoOther(base, opts.foldUnderPercent);
  }
  return base;
}

export const __internal = {
  EXTENSION_MAP,
  FILENAME_MAP,
  LANGUAGE_COLORS,
  DEFAULT_LANGUAGE_COLOR,
  VENDORED_PREFIXES,
  GENERATED_SUFFIXES,
  detectLanguage,
  isVendoredOrGenerated,
  computeLanguageStats,
  foldIntoOther,
  formatBytes,
  formatPercent,
  buildLanguageReport,
  colorFor,
};