fix: centralize GSD timeout and cache constants (#1038)

Move scattered timeout and cache-size constants (DEFAULT_COMMAND_TIMEOUT_MS,
DEFAULT_BASH_TIMEOUT_SECS, DIR_CACHE_MAX, CACHE_MAX) into a single
constants.ts module within the GSD extension.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
TÂCHES 2026-03-17 18:33:13 -06:00 committed by GitHub
parent 6240926ab6
commit f5bf03c504
5 changed files with 25 additions and 9 deletions

View file

@ -0,0 +1,21 @@
/**
* GSD Extension Shared Constants
*
* Centralized timeout and cache-size constants used across the GSD extension.
*/
// ─── Timeouts ─────────────────────────────────────────────────────────────────
/** Default timeout for verification-gate commands (ms). */
export const DEFAULT_COMMAND_TIMEOUT_MS = 120_000;
/** Default timeout for the dynamic bash tool (seconds). */
export const DEFAULT_BASH_TIMEOUT_SECS = 120;
// ─── Cache Sizes ──────────────────────────────────────────────────────────────
/** Max directory-listing cache entries before eviction (#611). */
export const DIR_CACHE_MAX = 200;
/** Max parse-cache entries before eviction. */
export const CACHE_MAX = 50;

View file

@ -23,11 +23,10 @@ import { checkExistingEnvKeys } from '../get-secrets-from-user.js';
import { parseRoadmapSlices } from './roadmap-slices.js';
import { nativeParseRoadmap, nativeExtractSection, nativeParsePlanFile, nativeParseSummaryFile, NATIVE_UNAVAILABLE } from './native-parser-bridge.js';
import { debugTime, debugCount } from './debug-logger.js';
import { CACHE_MAX } from './constants.js';
// ─── Parse Cache ──────────────────────────────────────────────────────────
const CACHE_MAX = 50;
/** Fast composite key: length + first/mid/last 100 chars. The middle sample
* prevents collisions when only a few characters change in the interior of
* a file (e.g., a checkbox [ ] [x] that doesn't alter length or endpoints). */

View file

@ -62,6 +62,7 @@ import { Text } from "@gsd/pi-tui";
import { pauseAutoForProviderError, classifyProviderError } from "./provider-error-pause.js";
import { toPosixPath } from "../shared/path-display.js";
import { isParallelActive, shutdownParallel } from "./parallel-orchestrator.js";
import { DEFAULT_BASH_TIMEOUT_SECS } from "./constants.js";
// ── Agent Instructions ────────────────────────────────────────────────────
// Lightweight "always follow" files injected into every GSD agent session.
@ -171,7 +172,6 @@ export default function (pi: ExtensionAPI) {
// the timeout parameter, commands run indefinitely, causing hangs on
// Windows where process killing is unreliable (see #40). We wrap execute
// to inject a 120-second default when no timeout is provided.
const DEFAULT_BASH_TIMEOUT_SECS = 120;
const baseBash = createBashTool(process.cwd(), {
spawnHook: (ctx) => ({ ...ctx, cwd: process.cwd() }),
});

View file

@ -12,12 +12,10 @@
import { readdirSync, existsSync, Dirent } from "node:fs";
import { join } from "node:path";
import { nativeScanGsdTree, type GsdTreeEntry } from "./native-parser-bridge.js";
import { DIR_CACHE_MAX } from "./constants.js";
// ─── Directory Listing Cache ──────────────────────────────────────────────────
/** Max entries before eviction. Prevents unbounded growth in long sessions (#611). */
const DIR_CACHE_MAX = 200;
const dirEntryCache = new Map<string, Dirent[]>();
const dirListCache = new Map<string, string[]>();

View file

@ -7,6 +7,7 @@ import { spawnSync } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import { join, basename } from "node:path";
import type { AuditWarning, RuntimeError, VerificationCheck, VerificationResult } from "./types.js";
import { DEFAULT_COMMAND_TIMEOUT_MS } from "./constants.js";
/** Maximum bytes of stdout/stderr to retain per command (10 KB). */
const MAX_OUTPUT_BYTES = 10 * 1024;
@ -152,9 +153,6 @@ function sanitizeCommand(cmd: string): string | null {
return cmd;
}
/** Default timeout for verification commands (ms). */
const DEFAULT_COMMAND_TIMEOUT_MS = 120_000;
export interface RunVerificationGateOptions {
basePath: string;
unitId: string;