Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 2x 2x 2x 2x 3x 3x 45x 28x 2x 19x 19x 1x 18x 2x 2x 14x 2x 12x 2x 1x 1x 1x 1x 1x 1x 2x 38x 38x 2x 8x 2x 2x 30x 30x 2x 1x 4x 1x 1x 1x 14x 14x 14x 14x 1x 13x 13x 13x 195x 13x 13x 1x 12x 1x 12x 12x 1x 11x 1x 11x 11x 1x 10x 4x 4x 1x 3x 2x 2x 1x 1x 1x 1x 8x 8x 1x 7x 1x 7x | /**
* Tool selection flow for the setup wizard.
* Handles preset selection, manual tool category selection, and advanced settings.
*/
import * as p from "@clack/prompts";
import { ToolConfig, ToolConfigMode } from "../types";
import { TOOL_CATEGORIES, PRESET_DEFINITIONS, getToolCount, getTotalToolCount } from "../presets";
/**
* Map tool category IDs to USE_* environment variables.
* Used by both local and server flows to apply manual category selection.
*/
const CATEGORY_ENV_MAP: Record<string, string> = {
"merge-requests": "USE_MRS",
"work-items": "USE_WORKITEMS",
pipelines: "USE_PIPELINE",
files: "USE_FILES",
wiki: "USE_GITLAB_WIKI",
snippets: "USE_SNIPPETS",
releases: "USE_RELEASES",
refs: "USE_REFS",
labels: "USE_LABELS",
milestones: "USE_MILESTONE",
members: "USE_MEMBERS",
search: "USE_SEARCH",
variables: "USE_VARIABLES",
webhooks: "USE_WEBHOOKS",
integrations: "USE_INTEGRATIONS",
};
/**
* Apply manual category selections to env vars.
* Disables USE_* flags for categories not in the selection.
*/
export function applyManualCategories(
selectedCategories: string[],
env: Record<string, string>
): void {
const selected = new Set(selectedCategories);
for (const [category, envVar] of Object.entries(CATEGORY_ENV_MAP)) {
if (!selected.has(category)) {
env[envVar] = "false";
}
}
}
/**
* Run the tool configuration flow.
* Presents the user with three options: preset, manual selection, or advanced settings.
*/
export async function runToolSelectionFlow(): Promise<ToolConfig | null> {
// Step 1: Choose configuration mode
const mode = await p.select<ToolConfigMode>({
message: "How do you want to configure tools?",
options: [
{
value: "preset" as ToolConfigMode,
label: "Use preset (recommended)",
hint: "Quick setup with role-based tool selection",
},
{
value: "manual" as ToolConfigMode,
label: "Select tools manually",
hint: "Choose individual tool categories",
},
{
value: "advanced" as ToolConfigMode,
label: "Advanced settings",
hint: "Full control over all environment variables",
},
],
});
if (p.isCancel(mode)) {
return null;
}
switch (mode) {
case "preset":
return runPresetSelection();
case "manual":
return runManualSelection();
case "advanced":
return runAdvancedSettings();
}
}
/**
* Preset selection flow
*/
async function runPresetSelection(): Promise<ToolConfig | null> {
const preset = await p.select({
message: "Select a preset:",
options: PRESET_DEFINITIONS.map(p => ({
value: p.id,
label: p.name,
hint: p.description,
})),
});
if (p.isCancel(preset)) {
return null;
}
const presetDef = PRESET_DEFINITIONS.find(p => p.id === preset);
const toolCount = presetDef ? getToolCount(presetDef.enabledCategories) : 0;
const totalTools = getTotalToolCount();
p.log.info(`Selected: ${toolCount}/${totalTools} tools`);
return {
mode: "preset",
preset,
enabledCategories: presetDef?.enabledCategories,
};
}
/**
* Manual tool category selection flow.
* Only shows categories that can be controlled via USE_* env vars.
* Categories without env var mappings are always enabled.
*/
async function runManualSelection(): Promise<ToolConfig | null> {
const totalTools = getTotalToolCount();
// Only show categories that have corresponding env vars (can actually be toggled)
const configurableCategories = TOOL_CATEGORIES.filter(c => c.id in CATEGORY_ENV_MAP);
const alwaysOnCategories = TOOL_CATEGORIES.filter(c => !(c.id in CATEGORY_ENV_MAP));
Eif (alwaysOnCategories.length > 0) {
const alwaysOnNames = alwaysOnCategories.map(c => c.name).join(", ");
p.log.info(`Always enabled: ${alwaysOnNames}`);
}
const selectedCategories = await p.multiselect({
message: `Select tool categories (${totalTools} tools total):`,
options: configurableCategories.map(category => ({
value: category.id,
label: `${category.name} [${category.tools.length} tools]`,
hint: category.description,
})),
// Pre-select default-enabled categories
initialValues: configurableCategories.filter(c => c.defaultEnabled).map(c => c.id),
required: true,
});
if (p.isCancel(selectedCategories)) {
return null;
}
// Include always-on categories in the result
const categories = [...selectedCategories, ...alwaysOnCategories.map(c => c.id)];
const selectedCount = getToolCount(categories);
p.log.info(`Selected: ${selectedCount}/${totalTools} tools`);
return {
mode: "manual",
enabledCategories: categories,
};
}
/**
* Advanced settings flow - configure environment variables
*/
async function runAdvancedSettings(): Promise<ToolConfig | null> {
const envOverrides: Record<string, string> = {};
// Feature flags
p.log.step("Feature Flags");
const featureFlags = await p.multiselect({
message: "Enable features:",
options: [
{ value: "USE_WORKITEMS", label: "Issues/Work Items", hint: "Issue tracking and epics" },
{ value: "USE_MRS", label: "Merge Requests", hint: "Code review and MR management" },
{ value: "USE_PIPELINE", label: "Pipelines", hint: "CI/CD pipeline management" },
{ value: "USE_FILES", label: "Files", hint: "Repository file operations" },
{ value: "USE_GITLAB_WIKI", label: "Wiki", hint: "Wiki page management" },
{ value: "USE_SNIPPETS", label: "Snippets", hint: "Code snippets" },
{ value: "USE_RELEASES", label: "Releases", hint: "Release management" },
{ value: "USE_REFS", label: "Branches/Tags", hint: "Branch and tag management" },
{ value: "USE_LABELS", label: "Labels", hint: "Label management" },
{ value: "USE_MILESTONE", label: "Milestones", hint: "Milestone management" },
{ value: "USE_MEMBERS", label: "Members", hint: "Team member management" },
{ value: "USE_SEARCH", label: "Search", hint: "Global search" },
{ value: "USE_WEBHOOKS", label: "Webhooks", hint: "Webhook configuration" },
{ value: "USE_INTEGRATIONS", label: "Integrations", hint: "Service integrations" },
{ value: "USE_VARIABLES", label: "Variables", hint: "CI/CD variable management" },
],
initialValues: ["USE_WORKITEMS", "USE_MRS", "USE_PIPELINE", "USE_FILES"],
required: false,
});
if (p.isCancel(featureFlags)) {
return null;
}
// Set all feature flags based on selection (matching src/config.ts USE_* names)
const allFeatures = [
"USE_WORKITEMS",
"USE_MRS",
"USE_PIPELINE",
"USE_FILES",
"USE_GITLAB_WIKI",
"USE_SNIPPETS",
"USE_RELEASES",
"USE_REFS",
"USE_LABELS",
"USE_MILESTONE",
"USE_MEMBERS",
"USE_SEARCH",
"USE_WEBHOOKS",
"USE_INTEGRATIONS",
"USE_VARIABLES",
];
const selectedFeatures = featureFlags;
for (const feature of allFeatures) {
envOverrides[feature] = selectedFeatures.includes(feature) ? "true" : "false";
}
// Read-only mode
const readOnly = await p.confirm({
message: "Enable read-only mode?",
initialValue: false,
});
if (p.isCancel(readOnly)) {
return null;
}
if (readOnly) {
envOverrides.GITLAB_READ_ONLY_MODE = "true";
}
// Cross-reference hints in tool descriptions
const crossRefs = await p.confirm({
message: "Include cross-references in tool descriptions?",
initialValue: true,
});
if (p.isCancel(crossRefs)) {
return null;
}
if (!crossRefs) {
envOverrides.GITLAB_CROSS_REFS = "false";
}
// Scope restrictions
const configureScope = await p.confirm({
message: "Configure scope restrictions?",
initialValue: false,
});
if (p.isCancel(configureScope)) {
return null;
}
if (configureScope) {
const scopeType = await p.select({
message: "Scope type:",
options: [
{ value: "project", label: "Single project", hint: "Restrict to one project" },
{ value: "allowlist", label: "Project allowlist", hint: "Restrict to multiple projects" },
],
});
if (p.isCancel(scopeType)) {
return null;
}
if (scopeType === "project") {
const project = await p.text({
message: "Project ID or path (e.g., group/project):",
validate: v => (!v ? "Project path is required" : undefined),
});
if (p.isCancel(project)) return null;
envOverrides.GITLAB_PROJECT_ID = project;
} else {
const allowlist = await p.text({
message: "Allowed project paths (comma-separated, e.g., group/project1,group/project2):",
validate: v => (!v ? "At least one project path is required" : undefined),
});
Iif (p.isCancel(allowlist)) return null;
envOverrides.GITLAB_ALLOWED_PROJECT_IDS = allowlist;
}
}
// Log level
const logLevel = await p.select({
message: "Log level:",
options: [
{ value: "info", label: "Info (default)" },
{ value: "debug", label: "Debug" },
{ value: "warn", label: "Warn" },
{ value: "error", label: "Error" },
],
});
if (p.isCancel(logLevel)) {
return null;
}
if (logLevel !== "info") {
envOverrides.LOG_LEVEL = logLevel;
}
return {
mode: "advanced",
envOverrides,
};
}
|