2026-03-23 14:20:35 -05:00
|
|
|
/**
|
|
|
|
|
* GSD Command — /gsd codebase
|
|
|
|
|
*
|
|
|
|
|
* Generate and manage the codebase map (.gsd/CODEBASE.md).
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
* Subcommands: generate, update, stats, help
|
2026-03-23 14:20:35 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
generateCodebaseMap,
|
|
|
|
|
updateCodebaseMap,
|
|
|
|
|
writeCodebaseMap,
|
|
|
|
|
getCodebaseMapStats,
|
|
|
|
|
readCodebaseMap,
|
|
|
|
|
} from "./codebase-generator.js";
|
2026-04-04 14:51:51 -05:00
|
|
|
import { loadEffectiveGSDPreferences } from "./preferences.js";
|
|
|
|
|
import type { CodebaseMapOptions } from "./codebase-generator.js";
|
2026-03-23 14:20:35 -05:00
|
|
|
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
const USAGE =
|
|
|
|
|
"Usage: /gsd codebase [generate|update|stats]\n\n" +
|
2026-04-04 14:51:51 -05:00
|
|
|
" generate [--max-files N] [--collapse-threshold N] — Generate or regenerate CODEBASE.md\n" +
|
|
|
|
|
" update [--max-files N] [--collapse-threshold N] — Incremental update (preserves descriptions)\n" +
|
|
|
|
|
" stats — Show file count, coverage, and generation time\n" +
|
|
|
|
|
" help — Show this help\n\n" +
|
|
|
|
|
"With no subcommand, shows stats if a map exists or help if not.\n\n" +
|
|
|
|
|
"Configure defaults via preferences.md:\n" +
|
|
|
|
|
" codebase:\n" +
|
|
|
|
|
" exclude_patterns: [\"docs/\", \"fixtures/\"]\n" +
|
|
|
|
|
" max_files: 1000\n" +
|
|
|
|
|
" collapse_threshold: 15";
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
|
2026-03-23 14:20:35 -05:00
|
|
|
export async function handleCodebase(
|
|
|
|
|
args: string,
|
|
|
|
|
ctx: ExtensionCommandContext,
|
|
|
|
|
_pi: ExtensionAPI,
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
const basePath = process.cwd();
|
|
|
|
|
const parts = args.trim().split(/\s+/);
|
|
|
|
|
const sub = parts[0] ?? "";
|
|
|
|
|
|
|
|
|
|
switch (sub) {
|
|
|
|
|
case "generate": {
|
2026-04-04 14:51:51 -05:00
|
|
|
const options = resolveCodebaseOptions(args, ctx);
|
|
|
|
|
if (options === false) return; // validation failed, message already shown
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
|
|
|
|
|
const existing = readCodebaseMap(basePath);
|
|
|
|
|
const existingDescriptions = existing
|
|
|
|
|
? (await import("./codebase-generator.js")).parseCodebaseMap(existing)
|
|
|
|
|
: undefined;
|
|
|
|
|
|
2026-04-04 14:51:51 -05:00
|
|
|
const result = generateCodebaseMap(basePath, options, existingDescriptions);
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
|
|
|
|
|
if (result.fileCount === 0) {
|
|
|
|
|
ctx.ui.notify(
|
|
|
|
|
"Codebase map generated with 0 files.\n" +
|
|
|
|
|
"Is this a git repository? Run 'git ls-files' to verify.",
|
|
|
|
|
"warning",
|
|
|
|
|
);
|
|
|
|
|
return;
|
2026-03-23 14:20:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const outPath = writeCodebaseMap(basePath, result.content);
|
|
|
|
|
ctx.ui.notify(
|
|
|
|
|
`Codebase map generated: ${result.fileCount} files\n` +
|
|
|
|
|
`Written to: ${outPath}` +
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
(result.truncated ? `\n⚠ Truncated — increase --max-files to include all files` : ""),
|
2026-03-23 14:20:35 -05:00
|
|
|
"success",
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "update": {
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
const existing = readCodebaseMap(basePath);
|
|
|
|
|
if (!existing) {
|
|
|
|
|
ctx.ui.notify(
|
|
|
|
|
"No codebase map found. Run /gsd codebase generate to create one.",
|
|
|
|
|
"warning",
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 14:51:51 -05:00
|
|
|
const options = resolveCodebaseOptions(args, ctx);
|
|
|
|
|
if (options === false) return;
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
|
2026-04-04 14:51:51 -05:00
|
|
|
const result = updateCodebaseMap(basePath, options);
|
2026-03-23 14:20:35 -05:00
|
|
|
writeCodebaseMap(basePath, result.content);
|
|
|
|
|
|
|
|
|
|
ctx.ui.notify(
|
|
|
|
|
`Codebase map updated: ${result.fileCount} files\n` +
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
` Added: ${result.added} | Removed: ${result.removed} | Unchanged: ${result.unchanged}` +
|
|
|
|
|
(result.truncated ? `\n⚠ Truncated — increase --max-files to include all files` : ""),
|
2026-03-23 14:20:35 -05:00
|
|
|
"success",
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "stats": {
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
showStats(basePath, ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-23 14:20:35 -05:00
|
|
|
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
case "help":
|
|
|
|
|
ctx.ui.notify(USAGE, "info");
|
|
|
|
|
return;
|
2026-03-23 14:20:35 -05:00
|
|
|
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
case "": {
|
|
|
|
|
// Safe default: show stats if map exists, help if not
|
|
|
|
|
const existing = readCodebaseMap(basePath);
|
|
|
|
|
if (existing) {
|
|
|
|
|
showStats(basePath, ctx);
|
|
|
|
|
} else {
|
|
|
|
|
ctx.ui.notify(USAGE, "info");
|
|
|
|
|
}
|
2026-03-23 14:20:35 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
ctx.ui.notify(
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
`Unknown subcommand "${sub}".\n\n${USAGE}`,
|
2026-03-23 14:20:35 -05:00
|
|
|
"warning",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
function showStats(basePath: string, ctx: ExtensionCommandContext): void {
|
|
|
|
|
const stats = getCodebaseMapStats(basePath);
|
|
|
|
|
if (!stats.exists) {
|
|
|
|
|
ctx.ui.notify("No codebase map found. Run /gsd codebase generate to create one.", "info");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const coverage = stats.fileCount > 0
|
|
|
|
|
? Math.round((stats.describedCount / stats.fileCount) * 100)
|
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
|
|
ctx.ui.notify(
|
|
|
|
|
`Codebase Map Stats:\n` +
|
|
|
|
|
` Files: ${stats.fileCount}\n` +
|
|
|
|
|
` Described: ${stats.describedCount} (${coverage}%)\n` +
|
|
|
|
|
` Undescribed: ${stats.undescribedCount}\n` +
|
|
|
|
|
` Generated: ${stats.generatedAt ?? "unknown"}\n\n` +
|
|
|
|
|
(stats.undescribedCount > 0
|
|
|
|
|
? `Tip: Run /gsd codebase update to refresh after file changes.`
|
|
|
|
|
: `Coverage is complete.`),
|
|
|
|
|
"info",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-04 14:51:51 -05:00
|
|
|
* Resolve codebase map options by merging preferences with CLI flags.
|
|
|
|
|
* CLI flags override preferences; preferences override built-in defaults.
|
|
|
|
|
* Returns false if validation failed (error already shown to user).
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
*/
|
2026-04-04 14:51:51 -05:00
|
|
|
function resolveCodebaseOptions(args: string, ctx: ExtensionCommandContext): CodebaseMapOptions | false {
|
|
|
|
|
// Load preferences defaults
|
|
|
|
|
const prefs = loadEffectiveGSDPreferences()?.preferences?.codebase;
|
|
|
|
|
|
|
|
|
|
// Parse CLI flags
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
const maxFilesStr = extractFlag(args, "--max-files");
|
2026-04-04 14:51:51 -05:00
|
|
|
const collapseStr = extractFlag(args, "--collapse-threshold");
|
|
|
|
|
|
|
|
|
|
// Validate --max-files
|
|
|
|
|
let maxFiles: number | undefined;
|
|
|
|
|
if (maxFilesStr) {
|
|
|
|
|
maxFiles = parseInt(maxFilesStr, 10);
|
|
|
|
|
if (isNaN(maxFiles) || maxFiles < 1) {
|
|
|
|
|
ctx.ui.notify("--max-files must be a positive integer (e.g. --max-files 200).", "warning");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
|
2026-04-04 14:51:51 -05:00
|
|
|
// Validate --collapse-threshold
|
|
|
|
|
let collapseThreshold: number | undefined;
|
|
|
|
|
if (collapseStr) {
|
|
|
|
|
collapseThreshold = parseInt(collapseStr, 10);
|
|
|
|
|
if (isNaN(collapseThreshold) || collapseThreshold < 1) {
|
|
|
|
|
ctx.ui.notify("--collapse-threshold must be a positive integer (e.g. --collapse-threshold 15).", "warning");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
}
|
2026-04-04 14:51:51 -05:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
// CLI flags override preferences
|
|
|
|
|
maxFiles: maxFiles ?? prefs?.max_files,
|
|
|
|
|
collapseThreshold: collapseThreshold ?? prefs?.collapse_threshold,
|
|
|
|
|
excludePatterns: prefs?.exclude_patterns,
|
|
|
|
|
};
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-23 14:20:35 -05:00
|
|
|
function extractFlag(args: string, flag: string): string | undefined {
|
fix(gsd): harden codebase-map — bug fixes, UX polish, and expanded tests
Generator (codebase-generator.ts):
- Fix truncation off-by-one: use filtered.length > maxFiles (not >=)
- Fix collapsed-directory round-trip: emit <!-- gsd:collapsed-descriptions -->
comment blocks so incremental updates recover descriptions for collapsed dirs
- Fix double-enumeration race in updateCodebaseMap: reuse files array from
generateCodebaseMap instead of calling enumerateFiles a second time
- Propagate truncated flag through updateCodebaseMap return type
- Fix getCodebaseMapStats to read Files: N from header (accurate for collapsed dirs)
- Remove redundant dead catch around lsFiles() in enumerateFiles
- parseCodebaseMap: use else-if for bare match (avoid unnecessary double-check)
- parseCodebaseMap: scan gsd:collapsed-descriptions comment blocks
Command handler (commands-codebase.ts):
- Bare /gsd codebase now shows stats (if map exists) or help (if no map)
instead of silently running generate
- Add explicit help subcommand with info-level output
- Guard update: warn if no CODEBASE.md exists instead of silently generating
- Validate --max-files: reject NaN, zero, and negative values with clear message
- Emit warning (not success) when generate produces 0 files
- Propagate truncated flag warning in both generate and update output
- Fix extractFlag regex: escape flag name and support --flag=value syntax
- Add actionable tip to stats output
Catalog (commands/catalog.ts):
- Add --max-files and help to codebase tab-completion entries
System context (bootstrap/system-context.ts):
- Cap CODEBASE.md injection at 8 000 chars (~2 000 tokens) per request
- Add generation timestamp and staleness notice to the injected block header
Paths (paths.ts):
- Fix LEGACY_GSD_ROOT_FILES.CODEBASE to use lowercase codebase.md (matches
the pattern of all other legacy root file names)
Tests (codebase-generator.test.ts):
- 15 new test cases: custom excludePatterns, collapseThreshold option,
truncation boundary conditions (below/at/above limit), non-git directory,
empty repo, collapsed-description round-trip, removed file tracking,
binary/lock exclusions, truncated flag propagation, collapsed-dir stats
accuracy, .gsd/ auto-creation, corrupted input, parseCodebaseMap comment blocks
- Fix collapse assertion to verify individual entries are absent from main body
- Fix git rm test to commit first so git rm succeeds
- 29/29 tests passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:51:31 -05:00
|
|
|
const escaped = flag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
|
|
|
const regex = new RegExp(`${escaped}[=\\s]+(\\S+)`);
|
2026-03-23 14:20:35 -05:00
|
|
|
const match = args.match(regex);
|
|
|
|
|
return match?.[1];
|
|
|
|
|
}
|