/**
 * SF Extension — Shared Constants
 *
 * Centralized timeout and cache-size constants used across the SF 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;
// ─── Tool Scoping ─────────────────────────────────────────────────────────────
/**
 * SF tools allowed during discuss flows (#2949).
 *
 * xAI/Grok (and potentially other providers with grammar-based constrained
 * decoding) return "Grammar is too complex" (HTTP 400) when the combined
 * tool schemas exceed their internal grammar limit. The full SF tool set
 * registers ~33 tools with deeply nested schemas; discuss flows only need
 * a small subset.
 *
 * By scoping tools to this allowlist during discuss dispatches, the grammar
 * sent to the provider stays well under provider limits.
 *
 * Included tools and why:
 *   - save_summary: writes CONTEXT.md artifacts (all discuss prompts)
 *   - save_decision: records decisions (discuss.md output phase)
 *   - plan_milestone: writes roadmap (discuss.md single/multi milestone)
 *   - new_milestone_id: generates milestone IDs (discuss.md multi-milestone)
 *   - update_requirement: updates requirements during discuss
 */
export const DISCUSS_TOOLS_ALLOWLIST = [
	// Context / summary writing
	"save_summary",
	// Decision recording
	"save_decision",
	// Milestone planning (needed for discuss.md output phase)
	"plan_milestone",
	// Milestone ID generation (multi-milestone flow)
	"new_milestone_id",
	// Requirement updates
	"update_requirement",
];
/**
 * SF tools allowed during research units.
 *
 * Purpose: keep research turns in their lane. A research agent writes a
 * RESEARCH artifact and may report SF friction, but planning tools belong to
 * later planner units. Allowing milestone/slice planning tools in research
 * turns lets a saved research artifact drift into speculative planning and
 * can keep the unit alive until runaway supervision pauses it.
 *
 * Consumer: guided-flow.ts and auto/run-unit.ts when narrowing SF tools for
 * research-milestone and research-slice turns.
 */
export const RESEARCH_TOOLS_ALLOWLIST = ["save_summary", "report_issue"];
/**
 * Return the SF tool allowlist for a workflow unit, or null when the full SF
 * tool set is appropriate.
 *
 * Purpose: centralize per-unit active-tool narrowing so guided and auto
 * dispatches enforce the same phase boundaries.
 *
 * Consumer: guided-flow.ts and auto/run-unit.ts before sending a unit prompt.
 */
export function getSfToolsAllowlistForUnitType(unitType) {
	if (!unitType) return null;
	if (unitType.startsWith("discuss-")) return DISCUSS_TOOLS_ALLOWLIST;
	if (unitType === "research-milestone" || unitType === "research-slice") {
		return RESEARCH_TOOLS_ALLOWLIST;
	}
	return null;
}
/**
 * Narrow active tools to the SF tools allowed for the current unit while
 * preserving all non-SF tools.
 *
 * Purpose: hide out-of-phase SF mutation tools from the model without
 * removing builtin or third-party tools needed to complete the unit.
 *
 * Consumer: guided-flow.ts and auto/run-unit.ts tool-scope guards.
 */
export function scopeActiveToolsForUnitType(unitType, currentTools) {
	const allowlist = getSfToolsAllowlistForUnitType(unitType);
	if (!allowlist) return [...currentTools];
	return currentTools.filter(
		(t) => !t.startsWith("sf_") || allowlist.includes(t),
	);
}
